package c.f.e;

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 c.f.d.c.c;
import c.f.i.b;
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 f extends j {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private static final Class<?> f1385b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private static final Constructor<?> f1386c;

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

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

    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 e2) {
            Log.e("TypefaceCompatApi24Impl", e2.getClass().getName(), e2);
            cls = null;
            method = null;
            method2 = null;
        }
        f1386c = constructor;
        f1385b = cls;
        f1387d = method2;
        f1388e = method;
    }

    f() {
    }

    private static boolean j(Object obj, ByteBuffer byteBuffer, int i2, int i3, boolean z) {
        try {
            return ((Boolean) f1387d.invoke(obj, byteBuffer, Integer.valueOf(i2), null, Integer.valueOf(i3), Boolean.valueOf(z))).booleanValue();
        } catch (IllegalAccessException | InvocationTargetException unused) {
            return false;
        }
    }

    private static Typeface k(Object obj) {
        try {
            Object objNewInstance = Array.newInstance(f1385b, 1);
            Array.set(objNewInstance, 0, obj);
            return (Typeface) f1388e.invoke(null, objNewInstance);
        } catch (IllegalAccessException | InvocationTargetException unused) {
            return null;
        }
    }

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

    private static Object m() {
        try {
            return f1386c.newInstance(new Object[0]);
        } catch (IllegalAccessException | InstantiationException | InvocationTargetException unused) {
            return null;
        }
    }

    @Override // c.f.e.j
    public Typeface b(Context context, c.b bVar, Resources resources, int i2) {
        Object objM = m();
        if (objM == null) {
            return null;
        }
        for (c.C0025c c0025c : bVar.a()) {
            ByteBuffer byteBufferB = k.b(context, resources, c0025c.b());
            if (byteBufferB == null || !j(objM, byteBufferB, c0025c.c(), c0025c.e(), c0025c.f())) {
                return null;
            }
        }
        return k(objM);
    }

    @Override // c.f.e.j
    public Typeface c(Context context, CancellationSignal cancellationSignal, b.f[] fVarArr, int i2) {
        Object objM = m();
        if (objM == null) {
            return null;
        }
        c.d.g gVar = new c.d.g();
        for (b.f fVar : fVarArr) {
            Uri uriC = fVar.c();
            ByteBuffer byteBufferF = (ByteBuffer) gVar.get(uriC);
            if (byteBufferF == null) {
                byteBufferF = k.f(context, cancellationSignal, uriC);
                gVar.put(uriC, byteBufferF);
            }
            if (byteBufferF == null || !j(objM, byteBufferF, fVar.b(), fVar.d(), fVar.e())) {
                return null;
            }
        }
        Typeface typefaceK = k(objM);
        if (typefaceK == null) {
            return null;
        }
        return Typeface.create(typefaceK, i2);
    }
}
