package q; import android.content.Context; import android.content.res.AssetManager; import android.content.res.Resources; import android.graphics.Typeface; import android.graphics.fonts.FontVariationAxis; import android.os.CancellationSignal; import android.os.ParcelFileDescriptor; import android.util.Log; import java.io.IOException; import java.lang.reflect.Array; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.nio.ByteBuffer; import java.util.Map; import p.e; import w.f; /* loaded from: classes.dex */ public class l extends j { /* renamed from: g, reason: collision with root package name */ protected final Class f13314g; /* renamed from: h, reason: collision with root package name */ protected final Constructor f13315h; /* renamed from: i, reason: collision with root package name */ protected final Method f13316i; /* renamed from: j, reason: collision with root package name */ protected final Method f13317j; /* renamed from: k, reason: collision with root package name */ protected final Method f13318k; /* renamed from: l, reason: collision with root package name */ protected final Method f13319l; /* renamed from: m, reason: collision with root package name */ protected final Method f13320m; public l() { Class cls; Constructor constructor; Method method; Method method2; Method method3; Method method4; Method method5; try { cls = u(); constructor = v(cls); method = r(cls); method2 = s(cls); method3 = w(cls); method4 = q(cls); method5 = t(cls); } catch (ClassNotFoundException | NoSuchMethodException e10) { Log.e("TypefaceCompatApi26Impl", "Unable to collect necessary methods for class " + e10.getClass().getName(), e10); cls = null; constructor = null; method = null; method2 = null; method3 = null; method4 = null; method5 = null; } this.f13314g = cls; this.f13315h = constructor; this.f13316i = method; this.f13317j = method2; this.f13318k = method3; this.f13319l = method4; this.f13320m = method5; } private Object k() { try { return this.f13315h.newInstance(new Object[0]); } catch (IllegalAccessException | InstantiationException | InvocationTargetException unused) { return null; } } private void l(Object obj) { try { this.f13319l.invoke(obj, new Object[0]); } catch (IllegalAccessException | InvocationTargetException unused) { } } private boolean m(Context context, Object obj, String str, int i10, int i11, int i12, FontVariationAxis[] fontVariationAxisArr) { try { return ((Boolean) this.f13316i.invoke(obj, context.getAssets(), str, 0, Boolean.FALSE, Integer.valueOf(i10), Integer.valueOf(i11), Integer.valueOf(i12), fontVariationAxisArr)).booleanValue(); } catch (IllegalAccessException | InvocationTargetException unused) { return false; } } private boolean n(Object obj, ByteBuffer byteBuffer, int i10, int i11, int i12) { try { return ((Boolean) this.f13317j.invoke(obj, byteBuffer, Integer.valueOf(i10), null, Integer.valueOf(i11), Integer.valueOf(i12))).booleanValue(); } catch (IllegalAccessException | InvocationTargetException unused) { return false; } } private boolean o(Object obj) { try { return ((Boolean) this.f13318k.invoke(obj, new Object[0])).booleanValue(); } catch (IllegalAccessException | InvocationTargetException unused) { return false; } } private boolean p() { if (this.f13316i == null) { Log.w("TypefaceCompatApi26Impl", "Unable to collect necessary private methods. Fallback to legacy implementation."); } return this.f13316i != null; } @Override // q.j, q.o public Typeface a(Context context, e.b bVar, Resources resources, int i10) { if (!p()) { return super.a(context, bVar, resources, i10); } Object k10 = k(); if (k10 == null) { return null; } for (e.c cVar : bVar.a()) { if (!m(context, k10, cVar.a(), cVar.c(), cVar.e(), cVar.f() ? 1 : 0, FontVariationAxis.fromFontVariationSettings(cVar.d()))) { l(k10); return null; } } if (o(k10)) { return h(k10); } return null; } @Override // q.j, q.o public Typeface b(Context context, CancellationSignal cancellationSignal, f.b[] bVarArr, int i10) { Typeface h10; if (bVarArr.length < 1) { return null; } if (!p()) { f.b f10 = f(bVarArr, i10); try { ParcelFileDescriptor openFileDescriptor = context.getContentResolver().openFileDescriptor(f10.d(), "r", cancellationSignal); if (openFileDescriptor == null) { if (openFileDescriptor != null) { openFileDescriptor.close(); } return null; } try { Typeface build = new Typeface.Builder(openFileDescriptor.getFileDescriptor()).setWeight(f10.e()).setItalic(f10.f()).build(); openFileDescriptor.close(); return build; } finally { } } catch (IOException unused) { return null; } } Map h11 = p.h(context, bVarArr, cancellationSignal); Object k10 = k(); if (k10 == null) { return null; } boolean z10 = false; for (f.b bVar : bVarArr) { ByteBuffer byteBuffer = (ByteBuffer) h11.get(bVar.d()); if (byteBuffer != null) { if (!n(k10, byteBuffer, bVar.c(), bVar.e(), bVar.f() ? 1 : 0)) { l(k10); return null; } z10 = true; } } if (!z10) { l(k10); return null; } if (o(k10) && (h10 = h(k10)) != null) { return Typeface.create(h10, i10); } return null; } @Override // q.o public Typeface d(Context context, Resources resources, int i10, String str, int i11) { if (!p()) { return super.d(context, resources, i10, str, i11); } Object k10 = k(); if (k10 == null) { return null; } if (!m(context, k10, str, 0, -1, -1, null)) { l(k10); return null; } if (o(k10)) { return h(k10); } return null; } protected Typeface h(Object obj) { try { Object newInstance = Array.newInstance((Class) this.f13314g, 1); Array.set(newInstance, 0, obj); return (Typeface) this.f13320m.invoke(null, newInstance, -1, -1); } catch (IllegalAccessException | InvocationTargetException unused) { return null; } } protected Method q(Class cls) { return cls.getMethod("abortCreation", new Class[0]); } protected Method r(Class cls) { Class cls2 = Integer.TYPE; return cls.getMethod("addFontFromAssetManager", AssetManager.class, String.class, cls2, Boolean.TYPE, cls2, cls2, cls2, FontVariationAxis[].class); } protected Method s(Class cls) { Class cls2 = Integer.TYPE; return cls.getMethod("addFontFromBuffer", ByteBuffer.class, cls2, FontVariationAxis[].class, cls2, cls2); } protected Method t(Class cls) { Class cls2 = Integer.TYPE; Method declaredMethod = Typeface.class.getDeclaredMethod("createFromFamiliesWithDefault", Array.newInstance((Class) cls, 1).getClass(), cls2, cls2); declaredMethod.setAccessible(true); return declaredMethod; } protected Class u() { return Class.forName("android.graphics.FontFamily"); } protected Constructor v(Class cls) { return cls.getConstructor(new Class[0]); } protected Method w(Class cls) { return cls.getMethod("freeze", new Class[0]); } }