package p037.p065.p070;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.CancellationSignal;
import android.util.Log;
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;
import p037.p041.p042.LayoutInflaterFactory2C1494;
import p037.p057.C1729;
import p037.p065.p068.p069.C1854;
import p037.p065.p068.p069.C1855;
import p037.p065.p075.C1884;

/* JADX INFO: renamed from: މ.ރ.ބ.ރ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public class C1867 extends C1871 {

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public static final Class<?> f6265;

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public static final Constructor<?> f6266;

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public static final Method f6267;

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public static final Method f6268;

    static {
        Class<?> cls;
        Method method;
        Method method2;
        Constructor<?> constructor = null;
        try {
            cls = Class.forName("android.graphics.FontFamily");
            Constructor<?> constructor2 = cls.getConstructor(new Class[0]);
            method2 = cls.getMethod("addFontWeightStyle", ByteBuffer.class, Integer.TYPE, List.class, Integer.TYPE, Boolean.TYPE);
            method = Typeface.class.getMethod("createFromFamiliesWithDefault", Array.newInstance(cls, 1).getClass());
            constructor = constructor2;
        } catch (ClassNotFoundException | NoSuchMethodException e) {
            Log.e("TypefaceCompatApi24Impl", e.getClass().getName(), e);
            cls = null;
            method = null;
            method2 = null;
        }
        f6266 = constructor;
        f6265 = cls;
        f6267 = method2;
        f6268 = method;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static Typeface m3679(Object obj) {
        try {
            Object objNewInstance = Array.newInstance(f6265, 1);
            Array.set(objNewInstance, 0, obj);
            return (Typeface) f6268.invoke(null, objNewInstance);
        } catch (IllegalAccessException | InvocationTargetException unused) {
            return null;
        }
    }

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

    @Override // p037.p065.p070.C1871
    /* JADX INFO: renamed from: ֏ */
    public Typeface mo3677(Context context, CancellationSignal cancellationSignal, C1884.C1890[] c1890Arr, int i) {
        Object objNewInstance;
        try {
            objNewInstance = f6266.newInstance(new Object[0]);
        } catch (IllegalAccessException | InstantiationException | InvocationTargetException unused) {
            objNewInstance = null;
        }
        if (objNewInstance == null) {
            return null;
        }
        C1729 c1729 = new C1729();
        for (C1884.C1890 c1890 : c1890Arr) {
            Uri uri = c1890.f6312;
            ByteBuffer byteBufferM2919 = (ByteBuffer) c1729.get(uri);
            if (byteBufferM2919 == null) {
                byteBufferM2919 = LayoutInflaterFactory2C1494.C1505.m2919(context, cancellationSignal, uri);
                c1729.put(uri, byteBufferM2919);
            }
            if (byteBufferM2919 == null || !m3680(objNewInstance, byteBufferM2919, c1890.f6313, c1890.f6314, c1890.f6315)) {
                return null;
            }
        }
        Typeface typefaceM3679 = m3679(objNewInstance);
        if (typefaceM3679 == null) {
            return null;
        }
        return Typeface.create(typefaceM3679, i);
    }

    @Override // p037.p065.p070.C1871
    /* JADX INFO: renamed from: ֏ */
    public Typeface mo3678(Context context, C1854 c1854, Resources resources, int i) {
        Object objNewInstance;
        MappedByteBuffer map;
        FileInputStream fileInputStream;
        try {
            objNewInstance = f6266.newInstance(new Object[0]);
        } catch (IllegalAccessException | InstantiationException | InvocationTargetException unused) {
            objNewInstance = null;
        }
        if (objNewInstance == null) {
            return null;
        }
        for (C1855 c1855 : c1854.f6232) {
            int i2 = c1855.f6238;
            File fileM2909 = LayoutInflaterFactory2C1494.C1505.m2909(context);
            if (fileM2909 == null) {
                map = null;
            } else {
                try {
                    if (LayoutInflaterFactory2C1494.C1505.m2961(fileM2909, resources, i2)) {
                        try {
                            fileInputStream = new FileInputStream(fileM2909);
                        } catch (IOException unused2) {
                            map = null;
                        }
                        try {
                            FileChannel channel = fileInputStream.getChannel();
                            map = channel.map(FileChannel.MapMode.READ_ONLY, 0L, channel.size());
                            fileInputStream.close();
                        } finally {
                        }
                    } else {
                        map = null;
                    }
                } finally {
                    fileM2909.delete();
                }
            }
            if (map == null || !m3680(objNewInstance, map, c1855.f6237, c1855.f6234, c1855.f6235)) {
                return null;
            }
        }
        return m3679(objNewInstance);
    }
}
