package X6FRs_4.IMuAHx_6.IFxWkV_5;

import X6FRs_4.IMuAHx_6.X6FRs_4.PGPF6hQ_2.PGPF6hQ_2;
import X6FRs_4.IMuAHx_6.XnFJ5_9.QxJ9d_1;
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.Map;
/* compiled from: TypefaceCompatApi26Impl.java */
/* loaded from: classes.dex */
public class IFxWkV_5 extends Mqv2r_3 {

    /* renamed from: IFxWkV_5  reason: collision with root package name */
    public final Method f3109IFxWkV_5;

    /* renamed from: IMuAHx_6  reason: collision with root package name */
    public final Method f3110IMuAHx_6;

    /* renamed from: Mqv2r_3  reason: collision with root package name */
    public final Method f3111Mqv2r_3;
    public final Method PGPF6hQ_2;
    public final Class QxJ9d_1;

    /* renamed from: QxJ9d_1  reason: collision with other field name */
    public final Constructor f396QxJ9d_1;

    /* renamed from: X6FRs_4  reason: collision with root package name */
    public final Method f3112X6FRs_4;

    public IFxWkV_5() {
        Method method;
        Constructor constructor;
        Method method2;
        Method method3;
        Method method4;
        Method method5;
        Class cls = null;
        try {
            Class m279KQgRr5e_0 = m279KQgRr5e_0();
            constructor = KQgRr5e_0(m279KQgRr5e_0);
            method2 = QxJ9d_1(m279KQgRr5e_0);
            method3 = PGPF6hQ_2(m279KQgRr5e_0);
            method4 = X6FRs_4(m279KQgRr5e_0);
            method5 = m280KQgRr5e_0(m279KQgRr5e_0);
            method = Mqv2r_3(m279KQgRr5e_0);
            cls = m279KQgRr5e_0;
        } catch (ClassNotFoundException | NoSuchMethodException e) {
            Log.e("TypefaceCompatApi26Impl", "Unable to collect necessary methods for class " + e.getClass().getName(), e);
            method = null;
            constructor = null;
            method2 = null;
            method3 = null;
            method4 = null;
            method5 = null;
        }
        this.QxJ9d_1 = cls;
        this.f396QxJ9d_1 = constructor;
        this.PGPF6hQ_2 = method2;
        this.f3111Mqv2r_3 = method3;
        this.f3112X6FRs_4 = method4;
        this.f3109IFxWkV_5 = method5;
        this.f3110IMuAHx_6 = method;
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public final boolean m282KQgRr5e_0() {
        if (this.PGPF6hQ_2 == null) {
            Log.w("TypefaceCompatApi26Impl", "Unable to collect necessary private methods. Fallback to legacy implementation.");
        }
        return this.PGPF6hQ_2 != null;
    }

    public Method Mqv2r_3(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;
    }

    public Method PGPF6hQ_2(Class cls) throws NoSuchMethodException {
        Class<?> cls2 = Integer.TYPE;
        return cls.getMethod("addFontFromBuffer", ByteBuffer.class, cls2, FontVariationAxis[].class, cls2, cls2);
    }

    public Method QxJ9d_1(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);
    }

    public Method X6FRs_4(Class cls) throws NoSuchMethodException {
        return cls.getMethod("freeze", new Class[0]);
    }

    private Object KQgRr5e_0() {
        try {
            return this.f396QxJ9d_1.newInstance(new Object[0]);
        } catch (IllegalAccessException | InstantiationException | InvocationTargetException unused) {
            return null;
        }
    }

    public final boolean KQgRr5e_0(Context context, Object obj, String str, int i, int i2, int i3, FontVariationAxis[] fontVariationAxisArr) {
        try {
            return ((Boolean) this.PGPF6hQ_2.invoke(obj, context.getAssets(), str, 0, false, Integer.valueOf(i), Integer.valueOf(i2), Integer.valueOf(i3), fontVariationAxisArr)).booleanValue();
        } catch (IllegalAccessException | InvocationTargetException unused) {
            return false;
        }
    }

    public final boolean KQgRr5e_0(Object obj, ByteBuffer byteBuffer, int i, int i2, int i3) {
        try {
            return ((Boolean) this.f3111Mqv2r_3.invoke(obj, byteBuffer, Integer.valueOf(i), null, Integer.valueOf(i2), Integer.valueOf(i3))).booleanValue();
        } catch (IllegalAccessException | InvocationTargetException unused) {
            return false;
        }
    }

    public Typeface KQgRr5e_0(Object obj) {
        try {
            Object newInstance = Array.newInstance(this.QxJ9d_1, 1);
            Array.set(newInstance, 0, obj);
            return (Typeface) this.f3110IMuAHx_6.invoke(null, newInstance, -1, -1);
        } catch (IllegalAccessException | InvocationTargetException unused) {
            return null;
        }
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public final boolean m283KQgRr5e_0(Object obj) {
        try {
            return ((Boolean) this.f3112X6FRs_4.invoke(obj, new Object[0])).booleanValue();
        } catch (IllegalAccessException | InvocationTargetException unused) {
            return false;
        }
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public final void m281KQgRr5e_0(Object obj) {
        try {
            this.f3109IFxWkV_5.invoke(obj, new Object[0]);
        } catch (IllegalAccessException | InvocationTargetException unused) {
        }
    }

    @Override // X6FRs_4.IMuAHx_6.IFxWkV_5.Mqv2r_3, X6FRs_4.IMuAHx_6.IFxWkV_5.FSaI4_7
    public Typeface KQgRr5e_0(Context context, PGPF6hQ_2.QxJ9d_1 qxJ9d_1, Resources resources, int i) {
        PGPF6hQ_2.C0046PGPF6hQ_2[] KQgRr5e_0;
        if (!m282KQgRr5e_0()) {
            return super.KQgRr5e_0(context, qxJ9d_1, resources, i);
        }
        Object KQgRr5e_02 = KQgRr5e_0();
        if (KQgRr5e_02 == null) {
            return null;
        }
        for (PGPF6hQ_2.C0046PGPF6hQ_2 c0046PGPF6hQ_2 : qxJ9d_1.KQgRr5e_0()) {
            if (!KQgRr5e_0(context, KQgRr5e_02, c0046PGPF6hQ_2.m338KQgRr5e_0(), c0046PGPF6hQ_2.QxJ9d_1(), c0046PGPF6hQ_2.PGPF6hQ_2(), c0046PGPF6hQ_2.m339KQgRr5e_0() ? 1 : 0, FontVariationAxis.fromFontVariationSettings(c0046PGPF6hQ_2.m340QxJ9d_1()))) {
                m281KQgRr5e_0(KQgRr5e_02);
                return null;
            }
        }
        if (m283KQgRr5e_0(KQgRr5e_02)) {
            return KQgRr5e_0(KQgRr5e_02);
        }
        return null;
    }

    @Override // X6FRs_4.IMuAHx_6.IFxWkV_5.Mqv2r_3, X6FRs_4.IMuAHx_6.IFxWkV_5.FSaI4_7
    public Typeface KQgRr5e_0(Context context, CancellationSignal cancellationSignal, QxJ9d_1.IFxWkV_5[] iFxWkV_5Arr, int i) {
        Typeface KQgRr5e_0;
        if (iFxWkV_5Arr.length < 1) {
            return null;
        }
        if (!m282KQgRr5e_0()) {
            QxJ9d_1.IFxWkV_5 KQgRr5e_02 = KQgRr5e_0(iFxWkV_5Arr, i);
            try {
                ParcelFileDescriptor openFileDescriptor = context.getContentResolver().openFileDescriptor(KQgRr5e_02.m346KQgRr5e_0(), "r", cancellationSignal);
                if (openFileDescriptor == null) {
                    if (openFileDescriptor != null) {
                        openFileDescriptor.close();
                    }
                    return null;
                }
                Typeface build = new Typeface.Builder(openFileDescriptor.getFileDescriptor()).setWeight(KQgRr5e_02.PGPF6hQ_2()).setItalic(KQgRr5e_02.m347KQgRr5e_0()).build();
                if (openFileDescriptor != null) {
                    openFileDescriptor.close();
                }
                return build;
            } catch (IOException unused) {
                return null;
            }
        }
        Map<Uri, ByteBuffer> KQgRr5e_03 = X6FRs_4.IMuAHx_6.XnFJ5_9.QxJ9d_1.KQgRr5e_0(context, iFxWkV_5Arr, cancellationSignal);
        Object KQgRr5e_04 = KQgRr5e_0();
        if (KQgRr5e_04 == null) {
            return null;
        }
        boolean z = false;
        for (QxJ9d_1.IFxWkV_5 iFxWkV_5 : iFxWkV_5Arr) {
            ByteBuffer byteBuffer = KQgRr5e_03.get(iFxWkV_5.m346KQgRr5e_0());
            if (byteBuffer != null) {
                if (!KQgRr5e_0(KQgRr5e_04, byteBuffer, iFxWkV_5.QxJ9d_1(), iFxWkV_5.PGPF6hQ_2(), iFxWkV_5.m347KQgRr5e_0() ? 1 : 0)) {
                    m281KQgRr5e_0(KQgRr5e_04);
                    return null;
                }
                z = true;
            }
        }
        if (!z) {
            m281KQgRr5e_0(KQgRr5e_04);
            return null;
        } else if (m283KQgRr5e_0(KQgRr5e_04) && (KQgRr5e_0 = KQgRr5e_0(KQgRr5e_04)) != null) {
            return Typeface.create(KQgRr5e_0, i);
        } else {
            return null;
        }
    }

    @Override // X6FRs_4.IMuAHx_6.IFxWkV_5.FSaI4_7
    public Typeface KQgRr5e_0(Context context, Resources resources, int i, String str, int i2) {
        if (!m282KQgRr5e_0()) {
            return super.KQgRr5e_0(context, resources, i, str, i2);
        }
        Object KQgRr5e_0 = KQgRr5e_0();
        if (KQgRr5e_0 == null) {
            return null;
        }
        if (!KQgRr5e_0(context, KQgRr5e_0, str, 0, -1, -1, null)) {
            m281KQgRr5e_0(KQgRr5e_0);
            return null;
        } else if (m283KQgRr5e_0(KQgRr5e_0)) {
            return KQgRr5e_0(KQgRr5e_0);
        } else {
            return null;
        }
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public Class m279KQgRr5e_0() throws ClassNotFoundException {
        return Class.forName("android.graphics.FontFamily");
    }

    public Constructor KQgRr5e_0(Class cls) throws NoSuchMethodException {
        return cls.getConstructor(new Class[0]);
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public Method m280KQgRr5e_0(Class cls) throws NoSuchMethodException {
        return cls.getMethod("abortCreation", new Class[0]);
    }
}
