package defpackage;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.graphics.fonts.Font;
import android.graphics.fonts.FontFamily;
import android.graphics.text.PositionedGlyphs;
import android.graphics.text.TextRunShaper;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.Trace;
import android.text.TextUtils;
import j$.util.DesugarCollections;
import j$.util.Objects;
import java.io.IOException;
import java.util.ArrayList;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

/* JADX INFO: renamed from: ᵠᵱˆ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public abstract class AbstractC3170 {

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public static final C1935 f12039;

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public static Paint f12040;

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public static final ᵸˊʾᵜ f12041;

    static {
        Trace.beginSection(ᵗʓ.ʿٴˇ("TypefaceCompat static init"));
        int i = Build.VERSION.SDK_INT;
        if (i >= 31) {
            f12041 = new C4448();
        } else if (i >= 29) {
            f12041 = new C1106();
        } else if (i >= 28) {
            f12041 = new C5520();
        } else if (i >= 26) {
            f12041 = new C4998();
        } else if (i < 24 || C3769.f14340 == null) {
            f12041 = new C0466();
        } else {
            f12041 = new C3769();
        }
        f12039 = new C1935(16);
        f12040 = null;
        Trace.endSection();
    }

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public static String m7277(Resources resources, int i, String str, int i2, int i3) {
        return resources.getResourcePackageName(i) + '-' + str + '-' + i2 + '-' + i + '-' + i3;
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public static Typeface m7278(String str) {
        if (str != null && !str.isEmpty()) {
            Typeface typefaceCreate = Typeface.create(str, 0);
            Typeface typefaceCreate2 = Typeface.create(Typeface.DEFAULT, 0);
            if (typefaceCreate != null && !typefaceCreate.equals(typefaceCreate2)) {
                return typefaceCreate;
            }
        }
        return null;
    }

    /* JADX WARN: Code restructure failed: missing block: B:42:0x00c0, code lost:
    
        r1 = r8.build();
     */
    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static Typeface m7279(Context context, InterfaceC0278 interfaceC0278, Resources resources, int i, String str, int i2, int i3, C0760 c0760, boolean z) {
        Typeface typeface;
        Typeface typefaceBuild;
        FontFamily fontFamilyBuild;
        int i4 = 14;
        if (interfaceC0278 instanceof C1095) {
            C1095 c1095 = (C1095) interfaceC0278;
            String str2 = c1095.f4665;
            typeface = null;
            int i5 = 1;
            int i6 = 0;
            if (TextUtils.isEmpty(str2) || (typefaceBuild = m7278(str2)) == null) {
                ArrayList arrayList = c1095.f4664;
                if (arrayList.size() == 1) {
                    typefaceBuild = m7278(((C3421) arrayList.get(0)).f13176);
                } else if (Build.VERSION.SDK_INT < 31) {
                    typefaceBuild = null;
                } else {
                    int i7 = 0;
                    while (true) {
                        if (i7 >= arrayList.size()) {
                            int i8 = 0;
                            Typeface.CustomFallbackBuilder customFallbackBuilder = null;
                            while (true) {
                                if (i8 >= arrayList.size()) {
                                    break;
                                }
                                C3421 c3421 = (C3421) arrayList.get(i8);
                                if (i8 == arrayList.size() - 1 && TextUtils.isEmpty(c3421.f13180)) {
                                    customFallbackBuilder.setSystemFallback(c3421.f13176);
                                    break;
                                }
                                String str3 = c3421.f13176;
                                String str4 = c3421.f13180;
                                Font fontM7280 = m7280(m7278(str3));
                                if (fontM7280 == null) {
                                    break;
                                }
                                if (TextUtils.isEmpty(str4)) {
                                    fontFamilyBuild = new FontFamily.Builder(fontM7280).build();
                                } else {
                                    try {
                                        fontFamilyBuild = new FontFamily.Builder(AbstractC1975.m5338(fontM7280).setFontVariationSettings(str4).build()).build();
                                    } catch (IOException unused) {
                                    }
                                }
                                if (customFallbackBuilder == null) {
                                    customFallbackBuilder = new Typeface.CustomFallbackBuilder(fontFamilyBuild);
                                } else {
                                    customFallbackBuilder.addCustomFallback(fontFamilyBuild);
                                }
                                i8++;
                            }
                        } else {
                            if (m7278(((C3421) arrayList.get(i7)).f13176) == null) {
                                break;
                            }
                            i7++;
                        }
                    }
                    typefaceBuild = null;
                }
            }
            if (typefaceBuild != null) {
                if (c0760 != null) {
                    new Handler(Looper.getMainLooper()).post(new RunnableC2093(c0760, i4, typefaceBuild));
                }
                f12039.m5182(m7277(resources, i, str, i2, i3), typefaceBuild);
                return typefaceBuild;
            }
            boolean z2 = !z ? c0760 != null : c1095.f4663 != 0;
            int i9 = z ? c1095.f4662 : -1;
            Handler handler = new Handler(Looper.getMainLooper());
            ˈᵷᵵᵞ r9 = new ˈᵷᵵᵞ((char) 0, 25);
            r9.ᵜᵪʾ = c0760;
            ArrayList arrayList2 = c1095.f4664;
            ExecutorC5358 executorC5358 = new ExecutorC5358(handler);
            ˊˊᵞᵽ r10 = new ˊˊᵞᵽ(12, r9, executorC5358, false);
            if (!z2) {
                String strM9589 = AbstractC4544.m9589(i3, arrayList2);
                Typeface typeface2 = (Typeface) AbstractC4544.f17276.m5189(strM9589);
                if (typeface2 != null) {
                    executorC5358.execute(new ᵙᵘ(r9, 5, typeface2));
                    typeface = typeface2;
                } else {
                    C3370 c3370 = new C3370(i6, r10);
                    synchronized (AbstractC4544.f17275) {
                        try {
                            C4053 c4053 = AbstractC4544.f17277;
                            ArrayList arrayList3 = (ArrayList) c4053.get(strM9589);
                            if (arrayList3 != null) {
                                arrayList3.add(c3370);
                            } else {
                                ArrayList arrayList4 = new ArrayList();
                                arrayList4.add(c3370);
                                c4053.put(strM9589, arrayList4);
                                CallableC3177 callableC3177 = new CallableC3177(strM9589, context, arrayList2, i3, 1);
                                ThreadPoolExecutor threadPoolExecutor = AbstractC4544.f17274;
                                C3370 c33702 = new C3370(i5, strM9589);
                                Handler handler2 = Looper.myLooper() == null ? new Handler(Looper.getMainLooper()) : new Handler();
                                ᵶᵮˋᵬ r2 = new ᵶᵮˋᵬ();
                                r2.ᵜᵪʾ = callableC3177;
                                r2.ᵔᵖᵹᵫ = c33702;
                                r2.ᵨᵼⁱ = handler2;
                                threadPoolExecutor.execute(r2);
                            }
                        } finally {
                        }
                    }
                }
            } else {
                if (arrayList2.size() > 1) {
                    ᵕᵩʽᵲ.ᵮᵣᵗˈ("Fallbacks with blocking fetches are not supported for performance reasons");
                    return null;
                }
                C3421 c34212 = (C3421) arrayList2.get(0);
                C1935 c1935 = AbstractC4544.f17276;
                ArrayList arrayList5 = new ArrayList(1);
                Object obj = new Object[]{c34212}[0];
                Objects.requireNonNull(obj);
                arrayList5.add(obj);
                String strM95892 = AbstractC4544.m9589(i3, DesugarCollections.unmodifiableList(arrayList5));
                Typeface typeface3 = (Typeface) AbstractC4544.f17276.m5189(strM95892);
                if (typeface3 != null) {
                    executorC5358.execute(new ᵙᵘ(r9, 5, typeface3));
                    typeface = typeface3;
                } else if (i9 == -1) {
                    Object[] objArr = {c34212};
                    ArrayList arrayList6 = new ArrayList(1);
                    Object obj2 = objArr[0];
                    Objects.requireNonNull(obj2);
                    arrayList6.add(obj2);
                    C4372 c4372M9588 = AbstractC4544.m9588(strM95892, context, DesugarCollections.unmodifiableList(arrayList6), i3);
                    r10.ᵵᵬᵽ(c4372M9588);
                    typeface = c4372M9588.f16609;
                } else {
                    try {
                        try {
                            try {
                                C4372 c4372 = (C4372) AbstractC4544.f17274.submit(new CallableC3177(strM95892, context, c34212, i3, 0)).get(i9, TimeUnit.MILLISECONDS);
                                r10.ᵵᵬᵽ(c4372);
                                typeface = c4372.f16609;
                            } catch (InterruptedException e) {
                                throw e;
                            }
                        } catch (ExecutionException e2) {
                            throw new RuntimeException(e2);
                        } catch (TimeoutException unused2) {
                            throw new InterruptedException("timeout");
                        }
                    } catch (InterruptedException unused3) {
                        ((ExecutorC5358) r10.ᵔᵖᵹᵫ).execute(new RunnableC3996((ˈᵷᵵᵞ) r10.ᵜᵪʾ, -3));
                    }
                }
            }
        } else {
            typeface = f12041.ᵻˈᵦʼ(context, (C2135) interfaceC0278, resources, i3);
            if (c0760 != null) {
                if (typeface != null) {
                    new Handler(Looper.getMainLooper()).post(new RunnableC2093(c0760, i4, typeface));
                } else {
                    c0760.m2732();
                }
            }
        }
        if (typeface != null) {
            f12039.m5182(m7277(resources, i, str, i2, i3), typeface);
        }
        return typeface;
    }

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public static Font m7280(Typeface typeface) {
        if (f12040 == null) {
            f12040 = new Paint();
        }
        f12040.setTextSize(10.0f);
        f12040.setTypeface(typeface);
        PositionedGlyphs positionedGlyphsShapeTextRun = TextRunShaper.shapeTextRun((CharSequence) " ", 0, 1, 0, 1, 0.0f, 0.0f, false, f12040);
        if (positionedGlyphsShapeTextRun.glyphCount() == 0) {
            return null;
        }
        return positionedGlyphsShapeTextRun.getFont(0);
    }
}
