package ῲ.ᨨ.ʬ;

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.CancellationSignal;
import android.os.ParcelFileDescriptor;
import android.util.Log;
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.Collections;
import java.util.HashMap;
import java.util.Map;
import ඓ.K.K.K.C1293;
import ῲ.ᨨ.ῲ.ῲ.C1796;
import ῲ.ᨨ.ῲ.ῲ.C1804;
import ῲ.ᨨ.㴹.C1847;
import K.K.K.ʬ.C2369;

/* renamed from: ῲ.ᨨ.ʬ.ⁱ  reason: contains not printable characters */
/* compiled from: TypefaceCompatApi26Impl */
public class C1717 extends C1709 {

    /* renamed from: ᕣ  reason: contains not printable characters */
    public final Method f6023;

    /* renamed from: ᨨ  reason: contains not printable characters */
    public final Method f6024;

    /* renamed from: ⁱ  reason: contains not printable characters */
    public final Class<?> f6025;

    /* renamed from: 㑃  reason: contains not printable characters */
    public final Method f6026;

    /* renamed from: 㳳  reason: contains not printable characters */
    public final Method f6027;

    /* renamed from: 㿎  reason: contains not printable characters */
    public final Constructor<?> f6028;

    /* renamed from: 䁗  reason: contains not printable characters */
    public final Method f6029;

    public C1717() {
        Method method;
        Method method2;
        Method method3;
        Method method4;
        Method method5;
        Class<?> cls;
        Constructor<?> constructor = null;
        try {
            cls = Class.forName("android.graphics.FontFamily");
            Constructor<?> constructor2 = cls.getConstructor(new Class[0]);
            method3 = m4407(cls);
            method2 = m4402(cls);
            method = cls.getMethod("freeze", new Class[0]);
            method5 = cls.getMethod("abortCreation", new Class[0]);
            method4 = m4399(cls);
            constructor = constructor2;
        } catch (ClassNotFoundException | NoSuchMethodException e) {
            StringBuilder r2 = C1293.m3416("Unable to collect necessary methods for class ");
            r2.append(e.getClass().getName());
            Log.e("TypefaceCompatApi26Impl", r2.toString(), e);
            cls = null;
            method5 = null;
            method4 = null;
            method3 = null;
            method2 = null;
            method = null;
        }
        this.f6025 = cls;
        this.f6028 = constructor;
        this.f6024 = method3;
        this.f6027 = method2;
        this.f6023 = method;
        this.f6026 = method5;
        this.f6029 = method4;
    }

    /* renamed from: ʬ  reason: contains not printable characters */
    private Object m4398() {
        try {
            return this.f6028.newInstance(new Object[0]);
        } catch (IllegalAccessException | InstantiationException | InvocationTargetException unused) {
            return null;
        }
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public final boolean m4403() {
        if (this.f6024 == null) {
            Log.w("TypefaceCompatApi26Impl", "Unable to collect necessary private methods. Fallback to legacy implementation.");
        }
        return this.f6024 != null;
    }

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

    /* renamed from: ʬ  reason: contains not printable characters */
    public final boolean m4400(Object obj) {
        try {
            return ((Boolean) this.f6023.invoke(obj, new Object[0])).booleanValue();
        } catch (IllegalAccessException | InvocationTargetException unused) {
            return false;
        }
    }

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

    /* renamed from: ῲ  reason: contains not printable characters */
    public Typeface m4401(Object obj) {
        try {
            Object newInstance = Array.newInstance(this.f6025, 1);
            Array.set(newInstance, 0, obj);
            return (Typeface) this.f6029.invoke(null, newInstance, -1, -1);
        } catch (IllegalAccessException | InvocationTargetException unused) {
            return null;
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public final void m4408(Object obj) {
        try {
            this.f6026.invoke(obj, new Object[0]);
        } catch (IllegalAccessException | InvocationTargetException unused) {
        }
    }

    @Override // ῲ.ᨨ.ʬ.C1709, ῲ.ᨨ.ʬ.C1719
    /* renamed from: K  reason: contains not printable characters */
    public Typeface m4406(Context context, C1796 r12, Resources resources, int i) {
        if (!m4403()) {
            return super.m4384(context, r12, resources, i);
        }
        Object r13 = m4398();
        if (r13 == null) {
            return null;
        }
        C1804[] r122 = r12.f6145;
        for (C1804 r0 : r122) {
            if (!m4409(context, r13, r0.f6162, r0.f6160, r0.f6161, r0.f6159 ? 1 : 0, FontVariationAxis.fromFontVariationSettings(r0.f6164))) {
                m4408(r13);
                return null;
            }
        }
        if (!m4400(r13)) {
            return null;
        }
        return m4401(r13);
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public Method m4402(Class<?> cls) throws NoSuchMethodException {
        Class<?> cls2 = Integer.TYPE;
        return cls.getMethod("addFontFromBuffer", ByteBuffer.class, cls2, FontVariationAxis[].class, cls2, cls2);
    }

    @Override // ῲ.ᨨ.ʬ.C1709, ῲ.ᨨ.ʬ.C1719
    /* renamed from: K  reason: contains not printable characters */
    public Typeface m4405(Context context, CancellationSignal cancellationSignal, C1847[] r14, int i) {
        Typeface r12;
        boolean z;
        if (r14.length < 1) {
            return null;
        }
        if (!m4403()) {
            C1847 r142 = m4418(r14, i);
            try {
                ParcelFileDescriptor openFileDescriptor = context.getContentResolver().openFileDescriptor(r142.f6280, "r", cancellationSignal);
                if (openFileDescriptor == null) {
                    if (openFileDescriptor != null) {
                        openFileDescriptor.close();
                    }
                    return null;
                }
                try {
                    Typeface build = new Typeface.Builder(openFileDescriptor.getFileDescriptor()).setWeight(r142.f6277).setItalic(r142.f6281).build();
                    openFileDescriptor.close();
                    return build;
                } catch (Throwable th) {
                    th.addSuppressed(th);
                }
            } catch (IOException unused) {
                return null;
            }
        } else {
            HashMap hashMap = new HashMap();
            for (C1847 r6 : r14) {
                if (r6.m4816() == 0) {
                    Uri uri = r6.f6280;
                    if (!hashMap.containsKey(uri)) {
                        hashMap.put(uri, C2369.m6318(context, cancellationSignal, uri));
                    }
                }
            }
            Map unmodifiableMap = Collections.unmodifiableMap(hashMap);
            Object r13 = m4398();
            if (r13 == null) {
                return null;
            }
            boolean z2 = false;
            for (C1847 r62 : r14) {
                ByteBuffer byteBuffer = (ByteBuffer) unmodifiableMap.get(r62.f6280);
                if (byteBuffer != null) {
                    try {
                        z = ((Boolean) this.f6027.invoke(r13, byteBuffer, Integer.valueOf(r62.f6279), null, Integer.valueOf(r62.f6277), Integer.valueOf(r62.f6281 ? 1 : 0))).booleanValue();
                    } catch (IllegalAccessException | InvocationTargetException unused2) {
                        z = false;
                    }
                    if (!z) {
                        m4408(r13);
                        return null;
                    }
                    z2 = true;
                }
            }
            if (!z2) {
                m4408(r13);
                return null;
            } else if (m4400(r13) && (r12 = m4401(r13)) != null) {
                return Typeface.create(r12, i);
            } else {
                return null;
            }
        }
        throw th;
    }

    @Override // ῲ.ᨨ.ʬ.C1719
    /* renamed from: K  reason: contains not printable characters */
    public Typeface m4404(Context context, Resources resources, int i, String str, int i2) {
        if (!m4403()) {
            return super.m4414(context, resources, i, str, i2);
        }
        Object r10 = m4398();
        if (r10 == null) {
            return null;
        }
        if (!m4409(context, r10, str, 0, -1, -1, null)) {
            m4408(r10);
            return null;
        } else if (!m4400(r10)) {
            return null;
        } else {
            return m4401(r10);
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public Method m4407(Class<?> cls) throws NoSuchMethodException {
        Class<?> cls2 = Integer.TYPE;
        return cls.getMethod("addFontFromAssetManager", AssetManager.class, String.class, Integer.TYPE, Boolean.TYPE, cls2, cls2, cls2, FontVariationAxis[].class);
    }
}
