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;

/* renamed from: ˇᵢᵔ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public abstract class AbstractC0965 {

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public static final C3457 f4318 = new C3457(2);

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public static final C2360 f4319 = new C2360(14);

    /* JADX WARN: Multi-variable type inference failed */
    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public static C3491[] m3297(Context context, C3831 c3831, String str) {
        C3718 c3718;
        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) {
                C2931 c2931 = new C2931();
                c2931.f11366 = context.getContentResolver().acquireUnstableContentProviderClient(uriBuild);
                c3718 = c2931;
            } else {
                C3718 c37182 = new C3718();
                c37182.f13883 = context.getContentResolver().acquireUnstableContentProviderClient(uriBuild);
                c3718 = c37182;
            }
            Cursor cursorMo1169 = 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 = c3831.f14234;
                    String str3 = c3831.f14235;
                    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};
                    }
                    cursorMo1169 = c3718.mo1169(uriBuild, strArr2, strArr);
                    Trace.endSection();
                    if (cursorMo1169 != null && cursorMo1169.getCount() > 0) {
                        int columnIndex = cursorMo1169.getColumnIndex("result_code");
                        ArrayList arrayList2 = new ArrayList();
                        int columnIndex2 = cursorMo1169.getColumnIndex("_id");
                        int columnIndex3 = cursorMo1169.getColumnIndex("file_id");
                        int columnIndex4 = cursorMo1169.getColumnIndex("font_ttc_index");
                        int columnIndex5 = cursorMo1169.getColumnIndex("font_weight");
                        int columnIndex6 = cursorMo1169.getColumnIndex("font_italic");
                        while (cursorMo1169.moveToNext()) {
                            int i2 = columnIndex != -1 ? cursorMo1169.getInt(columnIndex) : 0;
                            int i3 = columnIndex4 != -1 ? cursorMo1169.getInt(columnIndex4) : 0;
                            if (columnIndex3 == -1) {
                                i = columnIndex4;
                                uriWithAppendedId = ContentUris.withAppendedId(uriBuild, cursorMo1169.getLong(columnIndex2));
                            } else {
                                i = columnIndex4;
                                uriWithAppendedId = ContentUris.withAppendedId(uriBuild2, cursorMo1169.getLong(columnIndex3));
                            }
                            arrayList2.add(new C3491(uriWithAppendedId, i3, columnIndex5 != -1 ? cursorMo1169.getInt(columnIndex5) : 400, columnIndex6 != -1 && cursorMo1169.getInt(columnIndex6) == 1, c3831.f14234, i2));
                            columnIndex4 = i;
                        }
                        arrayList = arrayList2;
                    }
                    if (cursorMo1169 != null) {
                        cursorMo1169.close();
                    }
                    c3718.close();
                    return (C3491[]) arrayList.toArray(new C3491[0]);
                } finally {
                }
            } catch (Throwable th) {
                if (cursorMo1169 != null) {
                    cursorMo1169.close();
                }
                c3718.close();
                throw th;
            }
        } finally {
        }
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public static C5045 m3298(Context context, List list) {
        String str;
        Typeface typefaceM11033;
        Trace.beginSection(ˉˇʨ.ˎˑː("FontProvider.getFontFamilyResult"));
        try {
            ArrayList arrayList = new ArrayList();
            for (int i = 0; i < list.size(); i++) {
                C3831 c3831 = (C3831) list.get(i);
                if (Build.VERSION.SDK_INT < 31 || (typefaceM11033 = AbstractC5382.m11033((str = c3831.f14232))) == null || AbstractC5382.m11036(typefaceM11033) == null) {
                    ProviderInfo providerInfoM3299 = m3299(context.getPackageManager(), c3831, context.getResources());
                    if (providerInfoM3299 == null) {
                        return new C5045();
                    }
                    arrayList.add(m3297(context, c3831, providerInfoM3299.authority));
                } else {
                    arrayList.add(new C3491[]{new C3491(str, c3831.f14234)});
                }
            }
            return new C5045(arrayList);
        } finally {
            Trace.endSection();
        }
    }

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public static ProviderInfo m3299(PackageManager packageManager, C3831 c3831, Resources resources) {
        C2360 c2360 = f4319;
        C3457 c3457 = f4318;
        Trace.beginSection(ˉˇʨ.ˎˑː("FontProvider.getProvider"));
        try {
            List listM2162 = c3831.f14238;
            String str = c3831.f14236;
            String str2 = c3831.f14237;
            if (listM2162 == null) {
                listM2162 = AbstractC0494.m2162(resources, 0);
            }
            C0562 c0562 = new C0562();
            c0562.f2929 = str;
            c0562.f2930 = str2;
            c0562.f2928 = listM2162;
            ProviderInfo providerInfo = (ProviderInfo) c3457.m7853(c0562);
            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, c2360);
            for (int i = 0; i < listM2162.size(); i++) {
                ArrayList arrayList2 = new ArrayList((Collection) listM2162.get(i));
                Collections.sort(arrayList2, c2360);
                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;
                        }
                    }
                    c3457.m7858(c0562, providerInfoResolveContentProvider);
                    return providerInfoResolveContentProvider;
                }
            }
            Trace.endSection();
            return null;
        } finally {
            Trace.endSection();
        }
    }
}
