package o; 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.OsConstants; import com.airbnb.deeplinkdispatch.base.MatchIndex; 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 o.Szw; import o.ubj; /* loaded from: classes.dex */ class vOO extends TMM { private static Constructor a = null; private static boolean b = false; private static Method c; private static Method d; private static Class e; private static void d() { Class cls; Method method; Constructor constructor; Method method2; if (b) { return; } b = 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 unused) { cls = null; method = null; constructor = null; method2 = null; } a = constructor; e = cls; c = method2; d = method; } private File oS_(ParcelFileDescriptor parcelFileDescriptor) { try { StringBuilder sb = new StringBuilder("/proc/self/fd/"); sb.append(parcelFileDescriptor.getFd()); String readlink = android.system.Os.readlink(sb.toString()); if (OsConstants.S_ISREG(android.system.Os.stat(readlink).st_mode)) { return new File(readlink); } return null; } catch (ErrnoException unused) { return null; } } private static Object c() { d(); try { return a.newInstance(new Object[0]); } catch (IllegalAccessException | InstantiationException | InvocationTargetException e2) { throw new RuntimeException(e2); } } private static Typeface oR_(Object obj) { d(); try { Object newInstance = Array.newInstance(e, 1); Array.set(newInstance, 0, obj); return (Typeface) d.invoke(null, newInstance); } catch (IllegalAccessException | InvocationTargetException e2) { throw new RuntimeException(e2); } } private static boolean c(Object obj, String str, int i, boolean z) { d(); try { return ((Boolean) c.invoke(obj, str, Integer.valueOf(i), Boolean.valueOf(z))).booleanValue(); } catch (IllegalAccessException | InvocationTargetException e2) { throw new RuntimeException(e2); } } @Override // o.TMM public Typeface pk_(Context context, CancellationSignal cancellationSignal, ubj.HBt[] hBtArr, int i) { if (hBtArr.length <= 0) { return null; } ubj.HBt a2 = a(hBtArr, i); try { ParcelFileDescriptor openFileDescriptor = context.getContentResolver().openFileDescriptor(a2.qG_(), MatchIndex.ROOT_VALUE, cancellationSignal); if (openFileDescriptor == null) { if (openFileDescriptor != null) { openFileDescriptor.close(); } return null; } try { File oS_ = oS_(openFileDescriptor); if (oS_ != null && oS_.canRead()) { Typeface createFromFile = Typeface.createFromFile(oS_); if (openFileDescriptor != null) { openFileDescriptor.close(); } return createFromFile; } FileInputStream fileInputStream = new FileInputStream(openFileDescriptor.getFileDescriptor()); try { Typeface pl_ = super.pl_(context, fileInputStream); fileInputStream.close(); if (openFileDescriptor != null) { openFileDescriptor.close(); } return pl_; } finally { } } finally { } } catch (IOException unused) { return null; } } @Override // o.TMM public Typeface pj_(Context context, Szw.IeS ieS, Resources resources, int i) { Object c2 = c(); for (Szw.LWm lWm : ieS.c()) { File b2 = ioR.b(context); if (b2 == null) { return null; } try { if (!ioR.pn_(b2, resources, lWm.a())) { return null; } if (!c(c2, b2.getPath(), lWm.c(), lWm.i())) { return null; } b2.delete(); } catch (RuntimeException unused) { return null; } finally { b2.delete(); } } return oR_(c2); } }