package q; import android.content.Context; import android.content.res.Resources; import android.graphics.Typeface; import android.net.Uri; import android.os.CancellationSignal; import android.util.Log; 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.List; import p.e; import w.f; /* loaded from: classes.dex */ class k extends o { /* renamed from: b, reason: collision with root package name */ private static final Class f13310b; /* renamed from: c, reason: collision with root package name */ private static final Constructor f13311c; /* renamed from: d, reason: collision with root package name */ private static final Method f13312d; /* renamed from: e, reason: collision with root package name */ private static final Method f13313e; static { Class cls; Method method; Constructor constructor; Method method2; try { cls = Class.forName("android.graphics.FontFamily"); constructor = cls.getConstructor(new Class[0]); Class cls2 = Integer.TYPE; method2 = cls.getMethod("addFontWeightStyle", ByteBuffer.class, cls2, List.class, cls2, Boolean.TYPE); method = Typeface.class.getMethod("createFromFamiliesWithDefault", Array.newInstance(cls, 1).getClass()); } catch (ClassNotFoundException | NoSuchMethodException e10) { Log.e("TypefaceCompatApi24Impl", e10.getClass().getName(), e10); cls = null; method = null; constructor = null; method2 = null; } f13311c = constructor; f13310b = cls; f13312d = method2; f13313e = method; } k() { } private static boolean g(Object obj, ByteBuffer byteBuffer, int i10, int i11, boolean z10) { try { return ((Boolean) f13312d.invoke(obj, byteBuffer, Integer.valueOf(i10), null, Integer.valueOf(i11), Boolean.valueOf(z10))).booleanValue(); } catch (IllegalAccessException | InvocationTargetException unused) { return false; } } private static Typeface h(Object obj) { try { Object newInstance = Array.newInstance((Class) f13310b, 1); Array.set(newInstance, 0, obj); return (Typeface) f13313e.invoke(null, newInstance); } catch (IllegalAccessException | InvocationTargetException unused) { return null; } } public static boolean i() { Method method = f13312d; if (method == null) { Log.w("TypefaceCompatApi24Impl", "Unable to collect necessary private methods.Fallback to legacy implementation."); } return method != null; } private static Object j() { try { return f13311c.newInstance(new Object[0]); } catch (IllegalAccessException | InstantiationException | InvocationTargetException unused) { return null; } } @Override // q.o public Typeface a(Context context, e.b bVar, Resources resources, int i10) { Object j10 = j(); if (j10 == null) { return null; } for (e.c cVar : bVar.a()) { ByteBuffer b10 = p.b(context, resources, cVar.b()); if (b10 == null || !g(j10, b10, cVar.c(), cVar.e(), cVar.f())) { return null; } } return h(j10); } @Override // q.o public Typeface b(Context context, CancellationSignal cancellationSignal, f.b[] bVarArr, int i10) { Object j10 = j(); if (j10 == null) { return null; } androidx.collection.g gVar = new androidx.collection.g(); for (f.b bVar : bVarArr) { Uri d10 = bVar.d(); ByteBuffer byteBuffer = (ByteBuffer) gVar.get(d10); if (byteBuffer == null) { byteBuffer = p.f(context, cancellationSignal, d10); gVar.put(d10, byteBuffer); } if (byteBuffer == null || !g(j10, byteBuffer, bVar.c(), bVar.e(), bVar.f())) { return null; } } Typeface h10 = h(j10); if (h10 == null) { return null; } return Typeface.create(h10, i10); } }