package defpackage;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.net.Uri;
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 java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.util.List;

/* JADX INFO: renamed from: ᵨᵭˉᐧ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C3769 extends ᵸˊʾᵜ {

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

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

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

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

    static {
        Class<?> cls;
        Method method;
        Method method2;
        Constructor<?> constructor = null;
        try {
            cls = Class.forName("android.graphics.FontFamily");
            Constructor<?> constructor2 = cls.getConstructor(null);
            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());
            constructor = constructor2;
        } catch (ClassNotFoundException | NoSuchMethodException unused) {
            cls = null;
            method = null;
            method2 = null;
        }
        f14341 = constructor;
        f14339 = cls;
        f14340 = method2;
        f14342 = method;
    }

    /* JADX INFO: renamed from: ˈⁱᵡ, reason: contains not printable characters */
    public static boolean m8441(Object obj, ByteBuffer byteBuffer, int i, int i2, boolean z) {
        try {
            return ((Boolean) f14340.invoke(obj, byteBuffer, Integer.valueOf(i), null, Integer.valueOf(i2), Boolean.valueOf(z))).booleanValue();
        } catch (IllegalAccessException | InvocationTargetException unused) {
            return false;
        }
    }

    /* JADX INFO: renamed from: ᵨˈʼﹶ, reason: contains not printable characters */
    public static Typeface m8442(Object obj) {
        try {
            Object objNewInstance = Array.newInstance((Class<?>) f14339, 1);
            Array.set(objNewInstance, 0, obj);
            return (Typeface) f14342.invoke(null, objNewInstance);
        } catch (IllegalAccessException | InvocationTargetException unused) {
            return null;
        }
    }

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public final Typeface m8443(Context context, C4821[] c4821Arr, int i) {
        Object objNewInstance;
        try {
            objNewInstance = f14341.newInstance(null);
        } catch (IllegalAccessException | InstantiationException | InvocationTargetException unused) {
            objNewInstance = null;
        }
        if (objNewInstance != null) {
            int i2 = 0;
            C4053 c4053 = new C4053(0);
            int length = c4821Arr.length;
            while (true) {
                if (i2 < length) {
                    C4821 c4821 = c4821Arr[i2];
                    Uri uri = c4821.f18386;
                    ByteBuffer byteBuffer = (ByteBuffer) c4053.get(uri);
                    if (byteBuffer == null) {
                        byteBuffer = ᵟˌᵫ.ˑˊᵲ(context, uri);
                        c4053.put(uri, byteBuffer);
                    }
                    if (byteBuffer == null || !m8441(objNewInstance, byteBuffer, c4821.f18383, c4821.f18384, c4821.f18387)) {
                        break;
                    }
                    i2++;
                } else {
                    Typeface typefaceM8442 = m8442(objNewInstance);
                    if (typefaceM8442 != null) {
                        return Typeface.create(typefaceM8442, i);
                    }
                }
            }
        }
        return null;
    }

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public final Typeface m8444(Context context, C2135 c2135, Resources resources, int i) throws IllegalAccessException, InstantiationException, InvocationTargetException {
        Object objNewInstance;
        MappedByteBuffer map;
        FileInputStream fileInputStream;
        try {
            objNewInstance = f14341.newInstance(null);
        } catch (IllegalAccessException | InstantiationException | InvocationTargetException unused) {
            objNewInstance = null;
        }
        if (objNewInstance != null) {
            for (C2663 c2663 : c2135.f8462) {
                int i2 = c2663.f10308;
                File file = ᵟˌᵫ.ᵶˇᵱ(context);
                if (file != null) {
                    try {
                        if (ᵟˌᵫ.ᵻʽᵯ(file, resources, i2)) {
                            try {
                                fileInputStream = new FileInputStream(file);
                            } catch (IOException unused2) {
                                map = null;
                            }
                            try {
                                FileChannel channel = fileInputStream.getChannel();
                                map = channel.map(FileChannel.MapMode.READ_ONLY, 0L, channel.size());
                                fileInputStream.close();
                                if (map != null && m8441(objNewInstance, map, c2663.f10305, c2663.f10303, c2663.f10304)) {
                                }
                            } finally {
                            }
                        }
                    } finally {
                        file.delete();
                    }
                }
                map = null;
                if (map != null) {
                }
            }
            return m8442(objNewInstance);
        }
        return null;
    }
}
