package ῲ.ᨨ.ʬ;

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 ῲ.ᨨ.ῲ.ῲ.C1796;
import ῲ.ᨨ.ῲ.ῲ.C1804;
import ῲ.ᨨ.㴹.C1847;
import ῲ.㴹.C2288;
import K.K.K.ʬ.C2369;

/* renamed from: ῲ.ᨨ.ʬ.㴹  reason: contains not printable characters */
/* compiled from: TypefaceCompatApi24Impl */
public class C1720 extends C1719 {

    /* renamed from: ʬ  reason: contains not printable characters */
    public static final Constructor<?> f6032;

    /* renamed from: ඓ  reason: contains not printable characters */
    public static final Method f6033;

    /* renamed from: ῲ  reason: contains not printable characters */
    public static final Class<?> f6034;

    /* renamed from: 㸾  reason: contains not printable characters */
    public static final Method f6035;

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

    @Override // ῲ.ᨨ.ʬ.C1719
    /* renamed from: K  reason: contains not printable characters */
    public Typeface m4422(Context context, C1796 r18, Resources resources, int i) {
        Object obj;
        MappedByteBuffer mappedByteBuffer;
        try {
            obj = f6032.newInstance(new Object[0]);
        } catch (IllegalAccessException | InstantiationException | InvocationTargetException unused) {
            obj = null;
        }
        if (obj == null) {
            return null;
        }
        C1804[] r3 = r18.f6145;
        for (C1804 r6 : r3) {
            int i2 = r6.f6163;
            File r7 = C2369.m6282(context);
            if (r7 != null) {
                try {
                    if (C2369.m6343(r7, resources, i2)) {
                        try {
                            FileInputStream fileInputStream = new FileInputStream(r7);
                            try {
                                FileChannel channel = fileInputStream.getChannel();
                                mappedByteBuffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
                                fileInputStream.close();
                                r7.delete();
                                if (!(mappedByteBuffer == null && m4420(obj, mappedByteBuffer, r6.f6160, r6.f6161, r6.f6159))) {
                                    return null;
                                }
                            } catch (Throwable th) {
                                th.addSuppressed(th);
                            }
                        } catch (IOException unused2) {
                            mappedByteBuffer = null;
                        }
                    }
                } finally {
                    r7.delete();
                }
            }
            mappedByteBuffer = null;
            if (mappedByteBuffer == null) {
                return null;
            }
        }
        return m4419(obj);
        throw th;
    }

    @Override // ῲ.ᨨ.ʬ.C1719
    /* renamed from: K  reason: contains not printable characters */
    public Typeface m4421(Context context, CancellationSignal cancellationSignal, C1847[] r12, int i) {
        Object obj;
        try {
            obj = f6032.newInstance(new Object[0]);
        } catch (IllegalAccessException | InstantiationException | InvocationTargetException unused) {
            obj = null;
        }
        if (obj == null) {
            return null;
        }
        C2288 r3 = new C2288();
        for (C1847 r5 : r12) {
            Uri uri = r5.f6280;
            ByteBuffer byteBuffer = (ByteBuffer) r3.get(uri);
            if (byteBuffer == null) {
                byteBuffer = C2369.m6318(context, cancellationSignal, uri);
                r3.put(uri, byteBuffer);
            }
            if (byteBuffer == null || !m4420(obj, byteBuffer, r5.f6279, r5.f6277, r5.f6281)) {
                return null;
            }
        }
        Typeface r10 = m4419(obj);
        if (r10 == null) {
            return null;
        }
        return Typeface.create(r10, i);
    }

    /* renamed from: K  reason: contains not printable characters */
    public static boolean m4420(Object obj, ByteBuffer byteBuffer, int i, int i2, boolean z) {
        try {
            return ((Boolean) f6035.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 static Typeface m4419(Object obj) {
        try {
            Object newInstance = Array.newInstance(f6034, 1);
            Array.set(newInstance, 0, obj);
            return (Typeface) f6033.invoke(null, newInstance);
        } catch (IllegalAccessException | InvocationTargetException unused) {
            return null;
        }
    }
}
