package q; import android.content.Context; import android.content.res.Resources; import android.graphics.Typeface; import android.os.CancellationSignal; import android.os.ParcelFileDescriptor; import android.system.ErrnoException; import android.system.Os; import android.system.OsConstants; import android.util.Log; import java.io.File; import java.io.FileInputStream; 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 p.e; import w.f; /* loaded from: classes.dex */ class j extends o { /* renamed from: b, reason: collision with root package name */ private static Class f13305b = null; /* renamed from: c, reason: collision with root package name */ private static Constructor f13306c = null; /* renamed from: d, reason: collision with root package name */ private static Method f13307d = null; /* renamed from: e, reason: collision with root package name */ private static Method f13308e = null; /* renamed from: f, reason: collision with root package name */ private static boolean f13309f = false; j() { } private static boolean g(Object obj, String str, int i10, boolean z10) { j(); try { return ((Boolean) f13307d.invoke(obj, str, Integer.valueOf(i10), Boolean.valueOf(z10))).booleanValue(); } catch (IllegalAccessException | InvocationTargetException e10) { throw new RuntimeException(e10); } } private static Typeface h(Object obj) { j(); try { Object newInstance = Array.newInstance((Class) f13305b, 1); Array.set(newInstance, 0, obj); return (Typeface) f13308e.invoke(null, newInstance); } catch (IllegalAccessException | InvocationTargetException e10) { throw new RuntimeException(e10); } } private File i(ParcelFileDescriptor parcelFileDescriptor) { try { String readlink = Os.readlink("/proc/self/fd/" + parcelFileDescriptor.getFd()); if (OsConstants.S_ISREG(Os.stat(readlink).st_mode)) { return new File(readlink); } } catch (ErrnoException unused) { } return null; } private static void j() { Class cls; Method method; Constructor constructor; Method method2; if (f13309f) { return; } f13309f = true; try { cls = Class.forName("android.graphics.FontFamily"); constructor = cls.getConstructor(new Class[0]); method2 = cls.getMethod("addFontWeightStyle", String.class, Integer.TYPE, Boolean.TYPE); method = Typeface.class.getMethod("createFromFamiliesWithDefault", Array.newInstance(cls, 1).getClass()); } catch (ClassNotFoundException | NoSuchMethodException e10) { Log.e("TypefaceCompatApi21Impl", e10.getClass().getName(), e10); cls = null; method = null; constructor = null; method2 = null; } f13306c = constructor; f13305b = cls; f13307d = method2; f13308e = method; } private static Object k() { j(); try { return f13306c.newInstance(new Object[0]); } catch (IllegalAccessException | InstantiationException | InvocationTargetException e10) { throw new RuntimeException(e10); } } @Override // q.o public Typeface a(Context context, e.b bVar, Resources resources, int i10) { Object k10 = k(); for (e.c cVar : bVar.a()) { File e10 = p.e(context); if (e10 == null) { return null; } try { if (!p.c(e10, resources, cVar.b())) { return null; } if (!g(k10, e10.getPath(), cVar.e(), cVar.f())) { return null; } e10.delete(); } catch (RuntimeException unused) { return null; } finally { e10.delete(); } } return h(k10); } @Override // q.o public Typeface b(Context context, CancellationSignal cancellationSignal, f.b[] bVarArr, int i10) { if (bVarArr.length < 1) { return null; } 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 { File i11 = i(openFileDescriptor); if (i11 != null && i11.canRead()) { Typeface createFromFile = Typeface.createFromFile(i11); openFileDescriptor.close(); return createFromFile; } FileInputStream fileInputStream = new FileInputStream(openFileDescriptor.getFileDescriptor()); try { Typeface c10 = super.c(context, fileInputStream); fileInputStream.close(); openFileDescriptor.close(); return c10; } finally { } } finally { } } catch (IOException unused) { return null; } } }