package defpackage;

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.net.Uri;
import android.os.ParcelFileDescriptor;
import j$.util.DesugarCollections;
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.HashMap;
import java.util.Map;

/* JADX INFO: renamed from: ᵸᵢˉˆ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public class C4998 extends C0466 {

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public final Class f18949;

    /* JADX INFO: renamed from: ˋˈ, reason: contains not printable characters */
    public final Method f18950;

    /* JADX INFO: renamed from: ᵝᵶ, reason: contains not printable characters */
    public final Method f18951;

    /* JADX INFO: renamed from: ᵮᵣᵗˈ, reason: contains not printable characters */
    public final Method f18952;

    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public final Method f18953;

    /* JADX INFO: renamed from: ᵶᵥᵝ, reason: contains not printable characters */
    public final Method f18954;

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public final Constructor f18955;

    public C4998() throws NoSuchMethodException {
        Method methodMo10338;
        Constructor<?> constructor;
        Method methodM10335;
        Method method;
        Method method2;
        Method method3;
        Class<?> cls = null;
        try {
            Class<?> cls2 = Class.forName("android.graphics.FontFamily");
            constructor = cls2.getConstructor(null);
            methodM10335 = m10335(cls2);
            Class<?> cls3 = Integer.TYPE;
            method = cls2.getMethod("addFontFromBuffer", ByteBuffer.class, cls3, FontVariationAxis[].class, cls3, cls3);
            method2 = cls2.getMethod("freeze", null);
            method3 = cls2.getMethod("abortCreation", null);
            methodMo10338 = mo10338(cls2);
            cls = cls2;
        } catch (ClassNotFoundException | NoSuchMethodException unused) {
            methodMo10338 = null;
            constructor = null;
            methodM10335 = null;
            method = null;
            method2 = null;
            method3 = null;
        }
        this.f18949 = cls;
        this.f18955 = constructor;
        this.f18953 = methodM10335;
        this.f18954 = method;
        this.f18952 = method2;
        this.f18951 = method3;
        this.f18950 = methodMo10338;
    }

    /* JADX INFO: renamed from: ˀᵗ, reason: contains not printable characters */
    public static Method m10335(Class cls) {
        Class<?> cls2 = Integer.TYPE;
        return cls.getMethod("addFontFromAssetManager", AssetManager.class, String.class, cls2, Boolean.TYPE, cls2, cls2, cls2, FontVariationAxis[].class);
    }

    /* JADX INFO: renamed from: ˁʢᵛ, reason: contains not printable characters */
    public final boolean m10336(Object obj) {
        try {
            return ((Boolean) this.f18952.invoke(obj, null)).booleanValue();
        } catch (IllegalAccessException | InvocationTargetException unused) {
            return false;
        }
    }

    /* JADX INFO: renamed from: ˊˌˊ, reason: contains not printable characters */
    public Typeface mo10337(Object obj) {
        try {
            Object objNewInstance = Array.newInstance((Class<?>) this.f18949, 1);
            Array.set(objNewInstance, 0, obj);
            return (Typeface) this.f18950.invoke(null, objNewInstance, -1, -1);
        } catch (IllegalAccessException | InvocationTargetException unused) {
            return null;
        }
    }

    /* JADX INFO: renamed from: ˏᵩʨ, reason: contains not printable characters */
    public Method mo10338(Class cls) throws NoSuchMethodException {
        Class cls2 = Integer.TYPE;
        Method declaredMethod = Typeface.class.getDeclaredMethod("createFromFamiliesWithDefault", Array.newInstance((Class<?>) cls, 1).getClass(), cls2, cls2);
        declaredMethod.setAccessible(true);
        return declaredMethod;
    }

    /* JADX INFO: renamed from: ᵞᵛᵘ, reason: contains not printable characters */
    public final boolean m10339(Context context, Object obj, String str, int i, int i2, int i3, FontVariationAxis[] fontVariationAxisArr) {
        try {
            return ((Boolean) this.f18953.invoke(obj, context.getAssets(), str, 0, Boolean.FALSE, Integer.valueOf(i), Integer.valueOf(i2), Integer.valueOf(i3), fontVariationAxisArr)).booleanValue();
        } catch (IllegalAccessException | InvocationTargetException unused) {
            return false;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:11:0x001f  */
    @Override // defpackage.C0466
    /* JADX INFO: renamed from: ᵵᵽ */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Typeface mo1925(Context context, C4821[] c4821Arr, int i) throws IOException {
        Object objNewInstance;
        Typeface typefaceMo10337;
        boolean zBooleanValue;
        if (c4821Arr.length >= 1) {
            try {
                if (this.f18953 != null) {
                    HashMap map = new HashMap();
                    for (C4821 c4821 : c4821Arr) {
                        if (c4821.f18388 == 0) {
                            Uri uri = c4821.f18386;
                            if (!map.containsKey(uri)) {
                                map.put(uri, ᵟˌᵫ.ˑˊᵲ(context, uri));
                            }
                        }
                    }
                    Map mapUnmodifiableMap = DesugarCollections.unmodifiableMap(map);
                    try {
                        objNewInstance = this.f18955.newInstance(null);
                    } catch (IllegalAccessException | InstantiationException | InvocationTargetException unused) {
                        objNewInstance = null;
                    }
                    if (objNewInstance != null) {
                        int length = c4821Arr.length;
                        int i2 = 0;
                        boolean z = false;
                        while (true) {
                            Method method = this.f18951;
                            if (i2 < length) {
                                C4821 c48212 = c4821Arr[i2];
                                ByteBuffer byteBuffer = (ByteBuffer) mapUnmodifiableMap.get(c48212.f18386);
                                if (byteBuffer != null) {
                                    try {
                                        zBooleanValue = ((Boolean) this.f18954.invoke(objNewInstance, byteBuffer, Integer.valueOf(c48212.f18383), null, Integer.valueOf(c48212.f18384), Integer.valueOf(c48212.f18387 ? 1 : 0))).booleanValue();
                                    } catch (IllegalAccessException | InvocationTargetException unused2) {
                                        zBooleanValue = false;
                                    }
                                    if (!zBooleanValue) {
                                        method.invoke(objNewInstance, null);
                                        break;
                                    }
                                    z = true;
                                }
                                i2++;
                                z = z;
                            } else if (!z) {
                                method.invoke(objNewInstance, null);
                            } else if (m10336(objNewInstance) && (typefaceMo10337 = mo10337(objNewInstance)) != null) {
                                return Typeface.create(typefaceMo10337, i);
                            }
                        }
                    }
                } else {
                    C4821 c48213 = ᵸˊʾᵜ.ᵟᵹᵙ(c4821Arr, i);
                    ParcelFileDescriptor parcelFileDescriptorOpenFileDescriptor = context.getContentResolver().openFileDescriptor(c48213.f18386, "r", null);
                    if (parcelFileDescriptorOpenFileDescriptor != null) {
                        try {
                            Typeface typefaceBuild = new Typeface.Builder(parcelFileDescriptorOpenFileDescriptor.getFileDescriptor()).setWeight(c48213.f18384).setItalic(c48213.f18387).build();
                            parcelFileDescriptorOpenFileDescriptor.close();
                            return typefaceBuild;
                        } finally {
                        }
                    } else if (parcelFileDescriptorOpenFileDescriptor != null) {
                        parcelFileDescriptorOpenFileDescriptor.close();
                        return null;
                    }
                }
            } catch (IOException | IllegalAccessException | InvocationTargetException unused3) {
            }
        }
        return null;
    }

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public final Typeface m10340(Context context, Resources resources, int i, String str, int i2) throws IllegalAccessException, InstantiationException, InvocationTargetException {
        Object objNewInstance;
        if (this.f18953 == null) {
            return super.ᵻʽᵯ(context, resources, i, str, i2);
        }
        try {
            objNewInstance = this.f18955.newInstance(null);
        } catch (IllegalAccessException | InstantiationException | InvocationTargetException unused) {
            objNewInstance = null;
        }
        if (objNewInstance != null) {
            if (!m10339(context, objNewInstance, str, 0, -1, -1, null)) {
                try {
                    this.f18951.invoke(objNewInstance, null);
                } catch (IllegalAccessException | InvocationTargetException unused2) {
                }
            } else if (m10336(objNewInstance)) {
                return mo10337(objNewInstance);
            }
        }
        return null;
    }

    @Override // defpackage.C0466
    /* JADX INFO: renamed from: ᵻˈᵦʼ */
    public final Typeface mo1926(Context context, C2135 c2135, Resources resources, int i) throws IllegalAccessException, InstantiationException, InvocationTargetException {
        Object objNewInstance;
        if (this.f18953 == null) {
            return super.mo1926(context, c2135, resources, i);
        }
        try {
            objNewInstance = this.f18955.newInstance(null);
        } catch (IllegalAccessException | InstantiationException | InvocationTargetException unused) {
            objNewInstance = null;
        }
        if (objNewInstance != null) {
            C2663[] c2663Arr = c2135.f8462;
            int length = c2663Arr.length;
            int i2 = 0;
            while (true) {
                if (i2 < length) {
                    C2663 c2663 = c2663Arr[i2];
                    String str = c2663.f10306;
                    int i3 = c2663.f10305;
                    int i4 = c2663.f10303;
                    boolean z = c2663.f10304;
                    FontVariationAxis[] fontVariationAxisArrFromFontVariationSettings = FontVariationAxis.fromFontVariationSettings(c2663.f10307);
                    C4998 c4998 = this;
                    Context context2 = context;
                    if (c4998.m10339(context2, objNewInstance, str, i3, i4, z ? 1 : 0, fontVariationAxisArrFromFontVariationSettings)) {
                        i2++;
                        this = c4998;
                        context = context2;
                    } else {
                        try {
                            c4998.f18951.invoke(objNewInstance, null);
                            break;
                        } catch (IllegalAccessException | InvocationTargetException unused2) {
                        }
                    }
                } else {
                    C4998 c49982 = this;
                    if (c49982.m10336(objNewInstance)) {
                        return c49982.mo10337(objNewInstance);
                    }
                }
            }
        }
        return null;
    }
}
