package q3;

import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Typeface;
import androidx.collection.t0;
import androidx.collection.u;
import java.util.ArrayList;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import q3.g;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public abstract class f {

    /* renamed from: a, reason: collision with root package name */
    static final u f33403a = new u(16);

    /* renamed from: b, reason: collision with root package name */
    private static final ExecutorService f33404b = h.a("fonts-androidx", 10, 10000);

    /* renamed from: c, reason: collision with root package name */
    static final Object f33405c = new Object();

    /* renamed from: d, reason: collision with root package name */
    static final t0 f33406d = new t0();

    /* loaded from: classes.dex */
    class a implements Callable {

        /* renamed from: a, reason: collision with root package name */
        final /* synthetic */ String f33407a;

        /* renamed from: b, reason: collision with root package name */
        final /* synthetic */ Context f33408b;

        /* renamed from: c, reason: collision with root package name */
        final /* synthetic */ q3.e f33409c;

        /* renamed from: d, reason: collision with root package name */
        final /* synthetic */ int f33410d;

        a(String str, Context context, q3.e eVar, int i10) {
            this.f33407a = str;
            this.f33408b = context;
            this.f33409c = eVar;
            this.f33410d = i10;
        }

        @Override // java.util.concurrent.Callable
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public e call() {
            return f.c(this.f33407a, this.f33408b, this.f33409c, this.f33410d);
        }
    }

    /* loaded from: classes.dex */
    class b implements s3.a {

        /* renamed from: a, reason: collision with root package name */
        final /* synthetic */ q3.a f33411a;

        b(q3.a aVar) {
            this.f33411a = aVar;
        }

        @Override // s3.a
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public void accept(e eVar) {
            if (eVar == null) {
                eVar = new e(-3);
            }
            this.f33411a.b(eVar);
        }
    }

    /* loaded from: classes.dex */
    class c implements Callable {

        /* renamed from: a, reason: collision with root package name */
        final /* synthetic */ String f33412a;

        /* renamed from: b, reason: collision with root package name */
        final /* synthetic */ Context f33413b;

        /* renamed from: c, reason: collision with root package name */
        final /* synthetic */ q3.e f33414c;

        /* renamed from: d, reason: collision with root package name */
        final /* synthetic */ int f33415d;

        c(String str, Context context, q3.e eVar, int i10) {
            this.f33412a = str;
            this.f33413b = context;
            this.f33414c = eVar;
            this.f33415d = i10;
        }

        @Override // java.util.concurrent.Callable
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public e call() {
            try {
                return f.c(this.f33412a, this.f33413b, this.f33414c, this.f33415d);
            } catch (Throwable unused) {
                return new e(-3);
            }
        }
    }

    /* loaded from: classes.dex */
    class d implements s3.a {

        /* renamed from: a, reason: collision with root package name */
        final /* synthetic */ String f33416a;

        d(String str) {
            this.f33416a = str;
        }

        @Override // s3.a
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public void accept(e eVar) {
            synchronized (f.f33405c) {
                t0 t0Var = f.f33406d;
                ArrayList arrayList = (ArrayList) t0Var.get(this.f33416a);
                if (arrayList == null) {
                    return;
                }
                t0Var.remove(this.f33416a);
                for (int i10 = 0; i10 < arrayList.size(); i10++) {
                    ((s3.a) arrayList.get(i10)).accept(eVar);
                }
            }
        }
    }

    private static String a(q3.e eVar, int i10) {
        return eVar.d() + "-" + i10;
    }

    private static int b(g.a aVar) {
        int i10 = 1;
        if (aVar.c() != 0) {
            return aVar.c() != 1 ? -3 : -2;
        }
        g.b[] b10 = aVar.b();
        if (b10 != null && b10.length != 0) {
            i10 = 0;
            for (g.b bVar : b10) {
                int b11 = bVar.b();
                if (b11 != 0) {
                    if (b11 < 0) {
                        return -3;
                    }
                    return b11;
                }
            }
        }
        return i10;
    }

    static e c(String str, Context context, q3.e eVar, int i10) {
        u uVar = f33403a;
        Typeface typeface = (Typeface) uVar.get(str);
        if (typeface != null) {
            return new e(typeface);
        }
        try {
            g.a e10 = q3.d.e(context, eVar, null);
            int b10 = b(e10);
            if (b10 != 0) {
                return new e(b10);
            }
            Typeface b11 = androidx.core.graphics.e.b(context, null, e10.b(), i10);
            if (b11 == null) {
                return new e(-3);
            }
            uVar.put(str, b11);
            return new e(b11);
        } catch (PackageManager.NameNotFoundException unused) {
            return new e(-1);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static Typeface d(Context context, q3.e eVar, int i10, Executor executor, q3.a aVar) {
        String a10 = a(eVar, i10);
        Typeface typeface = (Typeface) f33403a.get(a10);
        if (typeface != null) {
            aVar.b(new e(typeface));
            return typeface;
        }
        b bVar = new b(aVar);
        synchronized (f33405c) {
            t0 t0Var = f33406d;
            ArrayList arrayList = (ArrayList) t0Var.get(a10);
            if (arrayList != null) {
                arrayList.add(bVar);
                return null;
            }
            ArrayList arrayList2 = new ArrayList();
            arrayList2.add(bVar);
            t0Var.put(a10, arrayList2);
            c cVar = new c(a10, context, eVar, i10);
            if (executor == null) {
                executor = f33404b;
            }
            h.b(executor, cVar, new d(a10));
            return null;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static Typeface e(Context context, q3.e eVar, q3.a aVar, int i10, int i11) {
        String a10 = a(eVar, i10);
        Typeface typeface = (Typeface) f33403a.get(a10);
        if (typeface != null) {
            aVar.b(new e(typeface));
            return typeface;
        }
        if (i11 == -1) {
            e c10 = c(a10, context, eVar, i10);
            aVar.b(c10);
            return c10.f33417a;
        }
        try {
            e eVar2 = (e) h.c(f33404b, new a(a10, context, eVar, i10), i11);
            aVar.b(eVar2);
            return eVar2.f33417a;
        } catch (InterruptedException unused) {
            aVar.b(new e(-3));
            return null;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static final class e {

        /* renamed from: a, reason: collision with root package name */
        final Typeface f33417a;

        /* renamed from: b, reason: collision with root package name */
        final int f33418b;

        e(int i10) {
            this.f33417a = null;
            this.f33418b = i10;
        }

        /* JADX INFO: Access modifiers changed from: package-private */
        public boolean a() {
            return this.f33418b == 0;
        }

        e(Typeface typeface) {
            this.f33417a = typeface;
            this.f33418b = 0;
        }
    }
}
