package defpackage;

import android.content.ContentUris;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
import android.content.pm.Signature;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Build;
import android.os.Trace;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/* JADX INFO: renamed from: ˈˇʔᵨ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public abstract class AbstractC1042 {

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public static final C1935 f4498 = new C1935(2);

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public static final C2262 f4497 = new C2262(14);

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public static ProviderInfo m3442(PackageManager packageManager, C3421 c3421, Resources resources) {
        C2262 c2262 = f4497;
        C1935 c1935 = f4498;
        Trace.beginSection(ᵗʓ.ʿٴˇ("FontProvider.getProvider"));
        try {
            List listM2519 = c3421.f13179;
            String str = c3421.f13177;
            String str2 = c3421.f13174;
            if (listM2519 == null) {
                listM2519 = AbstractC0702.m2519(resources, 0);
            }
            C2526 c2526 = new C2526();
            c2526.f9778 = str;
            c2526.f9776 = str2;
            c2526.f9777 = listM2519;
            ProviderInfo providerInfo = (ProviderInfo) c1935.m5189(c2526);
            if (providerInfo != null) {
                return providerInfo;
            }
            ProviderInfo providerInfoResolveContentProvider = packageManager.resolveContentProvider(str, 0);
            if (providerInfoResolveContentProvider == null) {
                throw new PackageManager.NameNotFoundException("No package found for authority: " + str);
            }
            if (!providerInfoResolveContentProvider.packageName.equals(str2)) {
                throw new PackageManager.NameNotFoundException("Found content provider " + str + ", but package was not " + str2);
            }
            Signature[] signatureArr = packageManager.getPackageInfo(providerInfoResolveContentProvider.packageName, 64).signatures;
            ArrayList arrayList = new ArrayList();
            for (Signature signature : signatureArr) {
                arrayList.add(signature.toByteArray());
            }
            Collections.sort(arrayList, c2262);
            for (int i = 0; i < listM2519.size(); i++) {
                ArrayList arrayList2 = new ArrayList((Collection) listM2519.get(i));
                Collections.sort(arrayList2, c2262);
                if (arrayList.size() == arrayList2.size()) {
                    for (int i2 = 0; i2 < arrayList.size(); i2++) {
                        if (!Arrays.equals((byte[]) arrayList.get(i2), (byte[]) arrayList2.get(i2))) {
                            break;
                        }
                    }
                    c1935.m5182(c2526, providerInfoResolveContentProvider);
                    return providerInfoResolveContentProvider;
                }
            }
            Trace.endSection();
            return null;
        } finally {
            Trace.endSection();
        }
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public static C4821[] m3443(Context context, C3421 c3421, String str) {
        ᵟˑʽ c1014;
        String[] strArr;
        int i;
        Uri uriWithAppendedId;
        Trace.beginSection(ᵗʓ.ʿٴˇ("FontProvider.query"));
        try {
            ArrayList arrayList = new ArrayList();
            Uri uriBuild = new Uri.Builder().scheme("content").authority(str).build();
            Uri uriBuild2 = new Uri.Builder().scheme("content").authority(str).appendPath("file").build();
            if (Build.VERSION.SDK_INT < 24) {
                c1014 = new ᵟˑʽ();
                c1014.ˌᴵ = context.getContentResolver().acquireUnstableContentProviderClient(uriBuild);
            } else {
                c1014 = new C1014();
                c1014.f4404 = context.getContentResolver().acquireUnstableContentProviderClient(uriBuild);
            }
            Cursor cursorMo3350 = null;
            try {
                String[] strArr2 = {"_id", "file_id", "font_ttc_index", "font_variation_settings", "font_weight", "font_italic", "result_code"};
                Trace.beginSection(ᵗʓ.ʿٴˇ("ContentQueryWrapper.query"));
                try {
                    String str2 = c3421.f13180;
                    String str3 = c3421.f13175;
                    if (str2 != null) {
                        int length = str2.length();
                        int iCharCount = 0;
                        while (iCharCount < length) {
                            int iCodePointAt = str2.codePointAt(iCharCount);
                            if (!Character.isWhitespace(iCodePointAt)) {
                                strArr = new String[]{str3, "VF"};
                                break;
                            }
                            iCharCount += Character.charCount(iCodePointAt);
                        }
                        strArr = new String[]{str3};
                    } else {
                        strArr = new String[]{str3};
                    }
                    cursorMo3350 = c1014.mo3350(uriBuild, strArr2, strArr);
                    Trace.endSection();
                    if (cursorMo3350 != null && cursorMo3350.getCount() > 0) {
                        int columnIndex = cursorMo3350.getColumnIndex("result_code");
                        ArrayList arrayList2 = new ArrayList();
                        int columnIndex2 = cursorMo3350.getColumnIndex("_id");
                        int columnIndex3 = cursorMo3350.getColumnIndex("file_id");
                        int columnIndex4 = cursorMo3350.getColumnIndex("font_ttc_index");
                        int columnIndex5 = cursorMo3350.getColumnIndex("font_weight");
                        int columnIndex6 = cursorMo3350.getColumnIndex("font_italic");
                        while (cursorMo3350.moveToNext()) {
                            int i2 = columnIndex != -1 ? cursorMo3350.getInt(columnIndex) : 0;
                            int i3 = columnIndex4 != -1 ? cursorMo3350.getInt(columnIndex4) : 0;
                            if (columnIndex3 == -1) {
                                i = columnIndex4;
                                uriWithAppendedId = ContentUris.withAppendedId(uriBuild, cursorMo3350.getLong(columnIndex2));
                            } else {
                                i = columnIndex4;
                                uriWithAppendedId = ContentUris.withAppendedId(uriBuild2, cursorMo3350.getLong(columnIndex3));
                            }
                            arrayList2.add(new C4821(uriWithAppendedId, i3, columnIndex5 != -1 ? cursorMo3350.getInt(columnIndex5) : 400, columnIndex6 != -1 && cursorMo3350.getInt(columnIndex6) == 1, c3421.f13180, i2));
                            columnIndex4 = i;
                        }
                        arrayList = arrayList2;
                    }
                    if (cursorMo3350 != null) {
                        cursorMo3350.close();
                    }
                    c1014.close();
                    return (C4821[]) arrayList.toArray(new C4821[0]);
                } finally {
                }
            } catch (Throwable th) {
                if (cursorMo3350 != null) {
                    cursorMo3350.close();
                }
                c1014.close();
                throw th;
            }
        } finally {
        }
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public static C1542 m3444(Context context, List list) {
        String str;
        Typeface typefaceM7278;
        Trace.beginSection(ᵗʓ.ʿٴˇ("FontProvider.getFontFamilyResult"));
        try {
            ArrayList arrayList = new ArrayList();
            for (int i = 0; i < list.size(); i++) {
                C3421 c3421 = (C3421) list.get(i);
                if (Build.VERSION.SDK_INT < 31 || (typefaceM7278 = AbstractC3170.m7278((str = c3421.f13176))) == null || AbstractC3170.m7280(typefaceM7278) == null) {
                    ProviderInfo providerInfoM3442 = m3442(context.getPackageManager(), c3421, context.getResources());
                    if (providerInfoM3442 == null) {
                        return new C1542();
                    }
                    arrayList.add(m3443(context, c3421, providerInfoM3442.authority));
                } else {
                    arrayList.add(new C4821[]{new C4821(str, c3421.f13180)});
                }
            }
            return new C1542(arrayList);
        } finally {
            Trace.endSection();
        }
    }
}
