package o; import android.content.ContentResolver; import android.content.ContentUris; import android.content.Context; import android.content.pm.PackageItemInfo; 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.net.Uri; import android.os.CancellationSignal; import com.huawei.hms.support.api.entity.common.CommonConstant; import com.prolificinteractive.materialcalendarview.TitleChanger; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; import o.ubj; /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.dex */ public final class TWJ { private static final Comparator d = new Comparator() { // from class: o.ynp @Override // java.util.Comparator public final int compare(Object obj, Object obj2) { return TWJ.b((byte[]) obj, (byte[]) obj2); } }; /* JADX INFO: Access modifiers changed from: package-private */ public static ubj.IeS qx_(Context context, WXG wxg, CancellationSignal cancellationSignal) throws PackageManager.NameNotFoundException { List> nM_; PackageManager packageManager = context.getPackageManager(); Resources resources = context.getResources(); String str = wxg.e; ProviderInfo resolveContentProvider = packageManager.resolveContentProvider(str, 0); if (resolveContentProvider == null) { throw new PackageManager.NameNotFoundException("No package found for authority: ".concat(String.valueOf(str))); } if (!PackageItemInfo.class.getField(CommonConstant.ReqAccessTokenParam.PACKAGE_NAME).get(resolveContentProvider).equals(wxg.b)) { StringBuilder sb = new StringBuilder("Found content provider "); sb.append(str); sb.append(", but package was not "); sb.append(wxg.b); throw new PackageManager.NameNotFoundException(sb.toString()); } Signature[] signatureArr = packageManager.getPackageInfo((String) PackageItemInfo.class.getField(CommonConstant.ReqAccessTokenParam.PACKAGE_NAME).get(resolveContentProvider), 64).signatures; ArrayList arrayList = new ArrayList(); for (Signature signature : signatureArr) { arrayList.add(signature.toByteArray()); } Collections.sort(arrayList, d); if (wxg.c == null) { nM_ = Szw.nM_(resources, wxg.d); } else { nM_ = wxg.c; } int i = 0; loop1: while (true) { if (i >= nM_.size()) { resolveContentProvider = null; break; } ArrayList arrayList2 = new ArrayList(nM_.get(i)); Collections.sort(arrayList2, d); 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; } } break loop1; } i++; } if (resolveContentProvider == null) { return ubj.IeS.c(1, null); } return ubj.IeS.c(0, qy_(context, wxg, resolveContentProvider.authority, cancellationSignal)); } private static ubj.HBt[] qy_(Context context, WXG wxg, String str, CancellationSignal cancellationSignal) { Cursor cursor; Uri withAppendedId; ArrayList arrayList = new ArrayList(); Uri build = new Uri.Builder().scheme("content").authority(str).build(); Uri build2 = new Uri.Builder().scheme("content").authority(str).appendPath("file").build(); try { cursor = Sts.qz_(context.getContentResolver(), build, new String[]{"_id", "file_id", "font_ttc_index", "font_variation_settings", "font_weight", "font_italic", "result_code"}, "query = ?", new String[]{wxg.f}, null, cancellationSignal); if (cursor != null) { try { if (cursor.getCount() > 0) { int columnIndex = cursor.getColumnIndex("result_code"); arrayList = new ArrayList(); int columnIndex2 = cursor.getColumnIndex("_id"); int columnIndex3 = cursor.getColumnIndex("file_id"); int columnIndex4 = cursor.getColumnIndex("font_ttc_index"); int columnIndex5 = cursor.getColumnIndex("font_weight"); int columnIndex6 = cursor.getColumnIndex("font_italic"); while (cursor.moveToNext()) { int i = columnIndex != -1 ? cursor.getInt(columnIndex) : 0; int i2 = columnIndex4 != -1 ? cursor.getInt(columnIndex4) : 0; if (columnIndex3 == -1) { withAppendedId = ContentUris.withAppendedId(build, cursor.getLong(columnIndex2)); } else { withAppendedId = ContentUris.withAppendedId(build2, cursor.getLong(columnIndex3)); } arrayList.add(ubj.HBt.qF_(withAppendedId, i2, columnIndex5 != -1 ? cursor.getInt(columnIndex5) : TitleChanger.DEFAULT_ANIMATION_DELAY, columnIndex6 != -1 && cursor.getInt(columnIndex6) == 1, i)); } } } catch (Throwable th) { th = th; if (cursor != null) { cursor.close(); } throw th; } } if (cursor != null) { cursor.close(); } return (ubj.HBt[]) arrayList.toArray(new ubj.HBt[0]); } catch (Throwable th2) { th = th2; cursor = null; } } /* JADX INFO: Access modifiers changed from: package-private */ public static /* synthetic */ int b(byte[] bArr, byte[] bArr2) { if (bArr.length != bArr2.length) { return bArr.length - bArr2.length; } for (int i = 0; i < bArr.length; i++) { byte b = bArr[i]; byte b2 = bArr2[i]; if (b != b2) { return b - b2; } } return 0; } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.dex */ public static class Sts { static Cursor qz_(ContentResolver contentResolver, Uri uri, String[] strArr, String str, String[] strArr2, String str2, Object obj) { return contentResolver.query(uri, strArr, str, strArr2, str2, (CancellationSignal) obj); } } }