package p073z;

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;
import p014e0.C0655g;
import p037m.C1457g;
import p071y.C1812f;

/* renamed from: z.s */
/* loaded from: classes.dex */
public class C1908s extends C1899o0 {

    /* renamed from: b */
    public static final Class<?> f4700b;

    /* renamed from: c */
    public static final Constructor<?> f4701c;

    /* renamed from: d */
    public static final Method f4702d;

    /* renamed from: e */
    public static final Method f4703e;

    static {
        Class<?> cls;
        Method method;
        Constructor<?> constructor;
        Method method2;
        try {
            cls = Class.forName("android.graphics.FontFamily");
            constructor = 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());
        } catch (ClassNotFoundException | NoSuchMethodException e) {
            Log.e("TypefaceCompatApi24Impl", e.getClass().getName(), e);
            cls = null;
            method = null;
            constructor = null;
            method2 = null;
        }
        f4701c = constructor;
        f4700b = cls;
        f4702d = method2;
        f4703e = method;
    }

    /* renamed from: l */
    public static boolean m65l(Object obj, ByteBuffer byteBuffer, int i, int i2, boolean z) {
        try {
            return ((Boolean) f4702d.invoke(obj, byteBuffer, Integer.valueOf(i), null, Integer.valueOf(i2), Boolean.valueOf(z))).booleanValue();
        } catch (IllegalAccessException | InvocationTargetException unused) {
            return false;
        }
    }

    /* renamed from: m */
    public static Typeface m64m(Object obj) {
        try {
            Object newInstance = Array.newInstance(f4700b, 1);
            Array.set(newInstance, 0, obj);
            return (Typeface) f4703e.invoke(null, newInstance);
        } catch (IllegalAccessException | InvocationTargetException unused) {
            return null;
        }
    }

    /* renamed from: n */
    public static boolean m63n() {
        Method method = f4702d;
        if (method == null) {
            Log.w("TypefaceCompatApi24Impl", "Unable to collect necessary private methods.Fallback to legacy implementation.");
        }
        return method != null;
    }

    /* renamed from: o */
    public static Object m62o() {
        try {
            return f4701c.newInstance(new Object[0]);
        } catch (IllegalAccessException | InstantiationException | InvocationTargetException unused) {
            return null;
        }
    }

    @Override // p073z.C1899o0
    /* renamed from: b */
    public Typeface mo55b(Context context, C1812f.C1815c c1815c, Resources resources, int i) {
        C1812f.C1816d[] m309a;
        Object m62o = m62o();
        if (m62o == null) {
            return null;
        }
        for (C1812f.C1816d c1816d : c1815c.m309a()) {
            ByteBuffer m79b = C1904p0.m79b(context, resources, c1816d.m307b());
            if (m79b == null || !m65l(m62o, m79b, c1816d.m306c(), c1816d.m304e(), c1816d.m303f())) {
                return null;
            }
        }
        return m64m(m62o);
    }

    @Override // p073z.C1899o0
    /* renamed from: c */
    public Typeface mo54c(Context context, CancellationSignal cancellationSignal, C0655g.C0657b[] c0657bArr, int i) {
        Object m62o = m62o();
        if (m62o == null) {
            return null;
        }
        C1457g c1457g = new C1457g();
        for (C0655g.C0657b c0657b : c0657bArr) {
            Uri m3189d = c0657b.m3189d();
            ByteBuffer byteBuffer = (ByteBuffer) c1457g.get(m3189d);
            if (byteBuffer == null) {
                byteBuffer = C1904p0.m75f(context, cancellationSignal, m3189d);
                c1457g.put(m3189d, byteBuffer);
            }
            if (byteBuffer == null || !m65l(m62o, byteBuffer, c0657b.m3190c(), c0657b.m3188e(), c0657b.m3187f())) {
                return null;
            }
        }
        Typeface m64m = m64m(m62o);
        if (m64m == null) {
            return null;
        }
        return Typeface.create(m64m, i);
    }
}