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;

/* renamed from: ˏˋᵤⁱ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C1842 extends ˀʾˀᵛ {

    /* renamed from: ˌᵜᵹᵩ, reason: contains not printable characters */
    public static final Constructor f7455;

    /* renamed from: ᵪʩ, reason: contains not printable characters */
    public static final Method f7456;

    /* renamed from: ᵯٴᵦ, reason: contains not printable characters */
    public static final Method f7457;

    /* renamed from: ᵸˑ, reason: contains not printable characters */
    public static final Class f7458;

    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;
        }
        f7455 = constructor;
        f7458 = cls;
        f7457 = method2;
        f7456 = method;
    }

    /* renamed from: ˁˑᵰ, reason: contains not printable characters */
    public static Typeface m5199(Object obj) throws ArrayIndexOutOfBoundsException, IllegalArgumentException, NegativeArraySizeException {
        try {
            Object objNewInstance = Array.newInstance((Class<?>) f7458, 1);
            Array.set(objNewInstance, 0, obj);
            return (Typeface) f7456.invoke(null, objNewInstance);
        } catch (IllegalAccessException | InvocationTargetException unused) {
            return null;
        }
    }

    /* renamed from: ᵶʔᵢˊ, reason: contains not printable characters */
    public static boolean m5200(Object obj, ByteBuffer byteBuffer, int i, int i2, boolean z) {
        try {
            return ((Boolean) f7457.invoke(obj, byteBuffer, Integer.valueOf(i), null, Integer.valueOf(i2), Boolean.valueOf(z))).booleanValue();
        } catch (IllegalAccessException | InvocationTargetException unused) {
            return false;
        }
    }

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public final Typeface m5201(Context context, C1449 c1449, Resources resources, int i) throws IllegalAccessException, InstantiationException, IllegalArgumentException, InvocationTargetException {
        Object objNewInstance;
        MappedByteBuffer map;
        FileInputStream fileInputStream;
        try {
            objNewInstance = f7455.newInstance(null);
        } catch (IllegalAccessException | InstantiationException | InvocationTargetException unused) {
            objNewInstance = null;
        }
        if (objNewInstance != null) {
            for (C1389 c1389 : c1449.f5861) {
                int i2 = c1389.f5700;
                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 && m5200(objNewInstance, map, c1389.f5699, c1389.f5703, c1389.f5701)) {
                                }
                            } finally {
                            }
                        }
                    } finally {
                        file.delete();
                    }
                }
                map = null;
                if (map != null) {
                }
            }
            return m5199(objNewInstance);
        }
        return null;
    }

    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public final Typeface m5202(Context context, C3491[] c3491Arr, int i) throws IllegalAccessException, InstantiationException, ArrayIndexOutOfBoundsException, IllegalArgumentException, InvocationTargetException, NegativeArraySizeException {
        Object objNewInstance;
        try {
            objNewInstance = f7455.newInstance(null);
        } catch (IllegalAccessException | InstantiationException | InvocationTargetException unused) {
            objNewInstance = null;
        }
        if (objNewInstance != null) {
            int i2 = 0;
            C2771 c2771 = new C2771(0);
            int length = c3491Arr.length;
            while (true) {
                if (i2 < length) {
                    C3491 c3491 = c3491Arr[i2];
                    Uri uri = c3491.f13069;
                    ByteBuffer byteBuffer = (ByteBuffer) c2771.get(uri);
                    if (byteBuffer == null) {
                        byteBuffer = ᵺᵣᵬ.ᵧᵾˀˈ(context, uri);
                        c2771.put(uri, byteBuffer);
                    }
                    if (byteBuffer == null || !m5200(objNewInstance, byteBuffer, c3491.f13070, c3491.f13068, c3491.f13071)) {
                        break;
                    }
                    i2++;
                } else {
                    Typeface typefaceM5199 = m5199(objNewInstance);
                    if (typefaceM5199 != null) {
                        return Typeface.create(typefaceM5199, i);
                    }
                }
            }
        }
        return null;
    }
}
