package j0;

import android.graphics.Typeface;
import android.util.SparseArray;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/* JADX INFO: loaded from: classes.dex */
public abstract class t {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final Field f28537a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final Method f28538b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final Constructor f28539c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final androidx.collection.l f28540d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final Object f28541e;

    static {
        Field declaredField;
        Constructor declaredConstructor;
        Method declaredMethod;
        try {
            declaredField = Typeface.class.getDeclaredField("native_instance");
            Class cls = Long.TYPE;
            declaredMethod = Typeface.class.getDeclaredMethod("nativeCreateFromTypefaceWithExactStyle", cls, Integer.TYPE, Boolean.TYPE);
            declaredMethod.setAccessible(true);
            declaredConstructor = Typeface.class.getDeclaredConstructor(cls);
            declaredConstructor.setAccessible(true);
        } catch (NoSuchFieldException | NoSuchMethodException unused) {
            declaredField = null;
            declaredConstructor = null;
            declaredMethod = null;
        }
        f28537a = declaredField;
        f28538b = declaredMethod;
        f28539c = declaredConstructor;
        f28540d = new androidx.collection.l(3);
        f28541e = new Object();
    }

    public static long a(int i10, boolean z10, long j10) {
        try {
            return ((Long) f28538b.invoke(null, Long.valueOf(j10), Integer.valueOf(i10), Boolean.valueOf(z10))).longValue();
        } catch (IllegalAccessException e10) {
            throw new RuntimeException(e10);
        } catch (InvocationTargetException e11) {
            throw new RuntimeException(e11);
        }
    }

    @Nullable
    private static Typeface create(long j10) {
        try {
            return (Typeface) f28539c.newInstance(Long.valueOf(j10));
        } catch (IllegalAccessException | InstantiationException | InvocationTargetException unused) {
            return null;
        }
    }

    /* JADX WARN: Type inference fix 'apply assigned field type' failed
    java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$PrimitiveArg
    	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
    	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
    	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
     */
    @Nullable
    public static Typeface createWeightStyle(@NonNull Typeface typeface, int i10, boolean z10) {
        Field field = f28537a;
        if (field == null) {
            return null;
        }
        int i11 = (i10 << 1) | (z10 ? 1 : 0);
        synchronized (f28541e) {
            try {
                try {
                    long j10 = field.getLong(typeface);
                    androidx.collection.l lVar = f28540d;
                    SparseArray sparseArray = (SparseArray) lVar.c(j10);
                    if (sparseArray == null) {
                        sparseArray = new SparseArray(4);
                        lVar.e(j10, sparseArray);
                    } else {
                        Typeface typeface2 = (Typeface) sparseArray.get(i11);
                        if (typeface2 != null) {
                            return typeface2;
                        }
                    }
                    Typeface typefaceCreate = create(a(i10, z10, j10));
                    sparseArray.put(i11, typefaceCreate);
                    return typefaceCreate;
                } catch (IllegalAccessException e10) {
                    throw new RuntimeException(e10);
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }
}
