package defpackage;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.os.ParcelFileDescriptor;
import android.system.ErrnoException;
import android.system.Os;
import android.system.OsConstants;
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;

/* JADX INFO: renamed from: ʿᵭᵖ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public class C0466 extends ᵸˊʾᵜ {

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public static Class f2555;

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public static Method f2556;

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public static boolean f2557;

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public static Constructor f2558;

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public static Method f2559;

    /* JADX INFO: renamed from: ˈⁱᵡ, reason: contains not printable characters */
    public static boolean m1923(Object obj, String str, int i, boolean z) throws NoSuchMethodException {
        m1924();
        try {
            return ((Boolean) f2556.invoke(obj, str, Integer.valueOf(i), Boolean.valueOf(z))).booleanValue();
        } catch (IllegalAccessException | InvocationTargetException e) {
            C4935.m10238(e);
            return false;
        }
    }

    /* JADX INFO: renamed from: ᵨˈʼﹶ, reason: contains not printable characters */
    public static void m1924() throws NoSuchMethodException {
        Method method;
        Class<?> cls;
        Method method2;
        if (f2557) {
            return;
        }
        f2557 = true;
        Constructor<?> constructor = null;
        try {
            cls = Class.forName("android.graphics.FontFamily");
            Constructor<?> constructor2 = cls.getConstructor(null);
            method2 = cls.getMethod("addFontWeightStyle", String.class, Integer.TYPE, Boolean.TYPE);
            method = Typeface.class.getMethod("createFromFamiliesWithDefault", Array.newInstance(cls, 1).getClass());
            constructor = constructor2;
        } catch (ClassNotFoundException | NoSuchMethodException unused) {
            method = null;
            cls = null;
            method2 = null;
        }
        f2558 = constructor;
        f2555 = cls;
        f2556 = method2;
        f2559 = method;
    }

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public Typeface mo1925(Context context, C4821[] c4821Arr, int i) {
        Typeface typefaceCreateFromFile;
        String str;
        if (c4821Arr.length >= 1) {
            try {
                ParcelFileDescriptor parcelFileDescriptorOpenFileDescriptor = context.getContentResolver().openFileDescriptor(ᵸˊʾᵜ.ᵟᵹᵙ(c4821Arr, i).f18386, "r", null);
                if (parcelFileDescriptorOpenFileDescriptor != null) {
                    try {
                        try {
                            str = Os.readlink("/proc/self/fd/" + parcelFileDescriptorOpenFileDescriptor.getFd());
                        } finally {
                        }
                    } catch (ErrnoException unused) {
                    }
                    File file = OsConstants.S_ISREG(Os.stat(str).st_mode) ? new File(str) : null;
                    if (file != null && file.canRead()) {
                        Typeface typefaceCreateFromFile2 = Typeface.createFromFile(file);
                        parcelFileDescriptorOpenFileDescriptor.close();
                        return typefaceCreateFromFile2;
                    }
                    FileInputStream fileInputStream = new FileInputStream(parcelFileDescriptorOpenFileDescriptor.getFileDescriptor());
                    try {
                        File file2 = ᵟˌᵫ.ᵶˇᵱ(context);
                        if (file2 == null) {
                            typefaceCreateFromFile = null;
                        } else {
                            try {
                                if (ᵟˌᵫ.ᵱᵽʡᵚ(file2, fileInputStream)) {
                                    typefaceCreateFromFile = Typeface.createFromFile(file2.getPath());
                                    file2.delete();
                                }
                            } catch (RuntimeException unused2) {
                            } catch (Throwable th) {
                                file2.delete();
                                throw th;
                            }
                            file2.delete();
                            typefaceCreateFromFile = null;
                        }
                        fileInputStream.close();
                        parcelFileDescriptorOpenFileDescriptor.close();
                        return typefaceCreateFromFile;
                    } finally {
                    }
                }
                if (parcelFileDescriptorOpenFileDescriptor != null) {
                    parcelFileDescriptorOpenFileDescriptor.close();
                    return null;
                }
            } catch (IOException unused3) {
            }
        }
        return null;
    }

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public Typeface mo1926(Context context, C2135 c2135, Resources resources, int i) throws NoSuchMethodException {
        m1924();
        try {
            Object objNewInstance = f2558.newInstance(null);
            for (C2663 c2663 : c2135.f8462) {
                File file = ᵟˌᵫ.ᵶˇᵱ(context);
                if (file == null) {
                    return null;
                }
                try {
                    if (!ᵟˌᵫ.ᵻʽᵯ(file, resources, c2663.f10308)) {
                        return null;
                    }
                    if (!m1923(objNewInstance, file.getPath(), c2663.f10303, c2663.f10304)) {
                        return null;
                    }
                    file.delete();
                } catch (RuntimeException unused) {
                    return null;
                } finally {
                    file.delete();
                }
            }
            m1924();
            try {
                Object objNewInstance2 = Array.newInstance((Class<?>) f2555, 1);
                Array.set(objNewInstance2, 0, objNewInstance);
                return (Typeface) f2559.invoke(null, objNewInstance2);
            } catch (IllegalAccessException | InvocationTargetException e) {
                C4935.m10238(e);
                return null;
            }
        } catch (IllegalAccessException | InstantiationException | InvocationTargetException e2) {
            C4935.m10238(e2);
            return null;
        }
    }
}
