package a.c.d;

import a.c.c.b.c;
import a.c.f.b;
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.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.List;

/* JADX INFO: compiled from: TypefaceCompatApi24Impl.java */
/* JADX INFO: loaded from: classes.dex */
class e extends h {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private static final Class f184a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private static final Constructor f185b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private static final Method f186c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private static final Method f187d;

    static {
        Class<?> cls;
        Method method;
        Method method2;
        Constructor<?> constructor = null;
        try {
            cls = Class.forName("android.graphics.FontFamily");
            Constructor<?> constructor2 = cls.getConstructor(new Class[0]);
            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 e2) {
            Log.e("TypefaceCompatApi24Impl", e2.getClass().getName(), e2);
            cls = null;
            method = null;
            method2 = null;
        }
        f185b = constructor;
        f184a = cls;
        f186c = method2;
        f187d = method;
    }

    e() {
    }

    private static boolean h(Object obj, ByteBuffer byteBuffer, int i, int i2, boolean z) {
        try {
            return ((Boolean) f186c.invoke(obj, byteBuffer, Integer.valueOf(i), null, Integer.valueOf(i2), Boolean.valueOf(z))).booleanValue();
        } catch (IllegalAccessException | InvocationTargetException e2) {
            throw new RuntimeException(e2);
        }
    }

    private static Typeface i(Object obj) {
        try {
            Object objNewInstance = Array.newInstance((Class<?>) f184a, 1);
            Array.set(objNewInstance, 0, obj);
            return (Typeface) f187d.invoke(null, objNewInstance);
        } catch (IllegalAccessException | InvocationTargetException e2) {
            throw new RuntimeException(e2);
        }
    }

    public static boolean j() {
        Method method = f186c;
        if (method == null) {
            Log.w("TypefaceCompatApi24Impl", "Unable to collect necessary private methods.Fallback to legacy implementation.");
        }
        return method != null;
    }

    private static Object k() {
        try {
            return f185b.newInstance(new Object[0]);
        } catch (IllegalAccessException | InstantiationException | InvocationTargetException e2) {
            throw new RuntimeException(e2);
        }
    }

    @Override // a.c.d.h
    public Typeface a(Context context, c.b bVar, Resources resources, int i) {
        Object objK = k();
        for (c.C0005c c0005c : bVar.a()) {
            ByteBuffer byteBufferB = i.b(context, resources, c0005c.b());
            if (byteBufferB == null || !h(objK, byteBufferB, c0005c.c(), c0005c.e(), c0005c.f())) {
                return null;
            }
        }
        return i(objK);
    }

    @Override // a.c.d.h
    public Typeface b(Context context, CancellationSignal cancellationSignal, b.f[] fVarArr, int i) {
        Object objK = k();
        a.b.f fVar = new a.b.f();
        for (b.f fVar2 : fVarArr) {
            Uri uriC = fVar2.c();
            ByteBuffer byteBufferF = (ByteBuffer) fVar.get(uriC);
            if (byteBufferF == null) {
                byteBufferF = i.f(context, cancellationSignal, uriC);
                fVar.put(uriC, byteBufferF);
            }
            if (!h(objK, byteBufferF, fVar2.b(), fVar2.d(), fVar2.e())) {
                return null;
            }
        }
        return Typeface.create(i(objK), i);
    }
}
