package androidx.core.provider;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Typeface;
import androidx.core.provider.g;
import java.util.ArrayList;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;

/* JADX INFO: compiled from: FontRequestWorker.java */
/* JADX INFO: loaded from: classes.dex */
class f {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    static final j.e<String, Typeface> f1759a = new j.e<>(16);

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

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    static final j.g<String, ArrayList<androidx.core.util.a<e>>> f1762d = new j.g<>();

    /* JADX INFO: compiled from: FontRequestWorker.java */
    class a implements Callable<e> {

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

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

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        final /* synthetic */ androidx.core.provider.e f1765c;

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

        a(String str, Context context, androidx.core.provider.e eVar, int i3) {
            this.f1763a = str;
            this.f1764b = context;
            this.f1765c = eVar;
            this.f1766d = i3;
        }

        @Override // java.util.concurrent.Callable
        /* JADX INFO: renamed from: a, reason: merged with bridge method [inline-methods] */
        public e call() {
            return f.c(this.f1763a, this.f1764b, this.f1765c, this.f1766d);
        }
    }

    /* JADX INFO: compiled from: FontRequestWorker.java */
    class b implements androidx.core.util.a<e> {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        final /* synthetic */ androidx.core.provider.a f1767a;

        b(androidx.core.provider.a aVar) {
            this.f1767a = aVar;
        }

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

    /* JADX INFO: compiled from: FontRequestWorker.java */
    class c implements Callable<e> {

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

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

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        final /* synthetic */ androidx.core.provider.e f1770c;

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

        c(String str, Context context, androidx.core.provider.e eVar, int i3) {
            this.f1768a = str;
            this.f1769b = context;
            this.f1770c = eVar;
            this.f1771d = i3;
        }

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

    /* JADX INFO: compiled from: FontRequestWorker.java */
    class d implements androidx.core.util.a<e> {

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

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

        @Override // androidx.core.util.a
        /* JADX INFO: renamed from: b, reason: merged with bridge method [inline-methods] */
        public void a(e eVar) {
            synchronized (f.f1761c) {
                j.g<String, ArrayList<androidx.core.util.a<e>>> gVar = f.f1762d;
                ArrayList<androidx.core.util.a<e>> arrayList = gVar.get(this.f1772a);
                if (arrayList == null) {
                    return;
                }
                gVar.remove(this.f1772a);
                for (int i3 = 0; i3 < arrayList.size(); i3++) {
                    arrayList.get(i3).a(eVar);
                }
            }
        }
    }

    private static String a(androidx.core.provider.e eVar, int i3) {
        return eVar.d() + "-" + i3;
    }

    @SuppressLint({"WrongConstant"})
    private static int b(g.a aVar) {
        int i3 = 1;
        if (aVar.c() != 0) {
            return aVar.c() != 1 ? -3 : -2;
        }
        g.b[] bVarArrB = aVar.b();
        if (bVarArrB != null && bVarArrB.length != 0) {
            i3 = 0;
            for (g.b bVar : bVarArrB) {
                int iB = bVar.b();
                if (iB != 0) {
                    if (iB < 0) {
                        return -3;
                    }
                    return iB;
                }
            }
        }
        return i3;
    }

    static e c(String str, Context context, androidx.core.provider.e eVar, int i3) {
        j.e<String, Typeface> eVar2 = f1759a;
        Typeface typefaceC = eVar2.c(str);
        if (typefaceC != null) {
            return new e(typefaceC);
        }
        try {
            g.a aVarE = androidx.core.provider.d.e(context, eVar, null);
            int iB = b(aVarE);
            if (iB != 0) {
                return new e(iB);
            }
            Typeface typefaceB = androidx.core.graphics.e.b(context, null, aVarE.b(), i3);
            if (typefaceB == null) {
                return new e(-3);
            }
            eVar2.d(str, typefaceB);
            return new e(typefaceB);
        } catch (PackageManager.NameNotFoundException unused) {
            return new e(-1);
        }
    }

    static Typeface d(Context context, androidx.core.provider.e eVar, int i3, Executor executor, androidx.core.provider.a aVar) {
        String strA = a(eVar, i3);
        Typeface typefaceC = f1759a.c(strA);
        if (typefaceC != null) {
            aVar.b(new e(typefaceC));
            return typefaceC;
        }
        b bVar = new b(aVar);
        synchronized (f1761c) {
            j.g<String, ArrayList<androidx.core.util.a<e>>> gVar = f1762d;
            ArrayList<androidx.core.util.a<e>> arrayList = gVar.get(strA);
            if (arrayList != null) {
                arrayList.add(bVar);
                return null;
            }
            ArrayList<androidx.core.util.a<e>> arrayList2 = new ArrayList<>();
            arrayList2.add(bVar);
            gVar.put(strA, arrayList2);
            c cVar = new c(strA, context, eVar, i3);
            if (executor == null) {
                executor = f1760b;
            }
            h.b(executor, cVar, new d(strA));
            return null;
        }
    }

    static Typeface e(Context context, androidx.core.provider.e eVar, androidx.core.provider.a aVar, int i3, int i4) {
        String strA = a(eVar, i3);
        Typeface typefaceC = f1759a.c(strA);
        if (typefaceC != null) {
            aVar.b(new e(typefaceC));
            return typefaceC;
        }
        if (i4 == -1) {
            e eVarC = c(strA, context, eVar, i3);
            aVar.b(eVarC);
            return eVarC.f1773a;
        }
        try {
            e eVar2 = (e) h.c(f1760b, new a(strA, context, eVar, i3), i4);
            aVar.b(eVar2);
            return eVar2.f1773a;
        } catch (InterruptedException unused) {
            aVar.b(new e(-3));
            return null;
        }
    }

    /* JADX INFO: compiled from: FontRequestWorker.java */
    static final class e {

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

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

        e(int i3) {
            this.f1773a = null;
            this.f1774b = i3;
        }

        @SuppressLint({"WrongConstant"})
        boolean a() {
            return this.f1774b == 0;
        }

        @SuppressLint({"WrongConstant"})
        e(Typeface typeface) {
            this.f1773a = typeface;
            this.f1774b = 0;
        }
    }
}
