Files
rr3-apk/decompiled/sources/androidx/core/provider/FontProvider.java
Daniel Elliott f9d20bb3fc Add decompiled APK source code (JADX)
- 28,932 files
- Full Java source code
- Smali files
- Resources

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-18 14:52:23 -08:00

328 lines
14 KiB
Java

package androidx.core.provider;
import android.content.ContentProviderClient;
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.net.Uri;
import android.os.CancellationSignal;
import android.os.RemoteException;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.annotation.VisibleForTesting;
import androidx.collection.LruCache;
import androidx.core.content.res.FontResourcesParserCompat;
import androidx.core.provider.FontsContractCompat;
import androidx.tracing.Trace;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
/* loaded from: classes.dex */
class FontProvider {
private static final LruCache<ProviderCacheKey, ProviderInfo> sProviderCache = new LruCache<>(2);
private static final Comparator<byte[]> sByteArrayComparator = new Comparator() { // from class: androidx.core.provider.FontProvider$$ExternalSyntheticLambda0
@Override // java.util.Comparator
public final int compare(Object obj, Object obj2) {
int lambda$static$0;
lambda$static$0 = FontProvider.lambda$static$0((byte[]) obj, (byte[]) obj2);
return lambda$static$0;
}
};
private FontProvider() {
}
@NonNull
public static FontsContractCompat.FontFamilyResult getFontFamilyResult(@NonNull Context context, @NonNull List<FontRequest> list, @Nullable CancellationSignal cancellationSignal) throws PackageManager.NameNotFoundException {
Trace.beginSection("FontProvider.getFontFamilyResult");
try {
ArrayList arrayList = new ArrayList();
for (int i = 0; i < list.size(); i++) {
FontRequest fontRequest = list.get(i);
ProviderInfo provider = getProvider(context.getPackageManager(), fontRequest, context.getResources());
if (provider == null) {
return FontsContractCompat.FontFamilyResult.create(1, (FontsContractCompat.FontInfo[]) null);
}
arrayList.add(query(context, fontRequest, provider.authority, cancellationSignal));
}
return FontsContractCompat.FontFamilyResult.create(0, arrayList);
} finally {
Trace.endSection();
}
}
public static class ProviderCacheKey {
String mAuthority;
List<List<byte[]>> mCertificates;
String mPackageName;
public ProviderCacheKey(String str, String str2, List<List<byte[]>> list) {
this.mAuthority = str;
this.mPackageName = str2;
this.mCertificates = list;
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof ProviderCacheKey)) {
return false;
}
ProviderCacheKey providerCacheKey = (ProviderCacheKey) obj;
return Objects.equals(this.mAuthority, providerCacheKey.mAuthority) && Objects.equals(this.mPackageName, providerCacheKey.mPackageName) && Objects.equals(this.mCertificates, providerCacheKey.mCertificates);
}
public int hashCode() {
return Objects.hash(this.mAuthority, this.mPackageName, this.mCertificates);
}
}
@VisibleForTesting
public static void clearProviderCache() {
sProviderCache.evictAll();
}
@Nullable
@VisibleForTesting
public static ProviderInfo getProvider(@NonNull PackageManager packageManager, @NonNull FontRequest fontRequest, @Nullable Resources resources) throws PackageManager.NameNotFoundException {
Trace.beginSection("FontProvider.getProvider");
try {
List<List<byte[]>> certificates = getCertificates(fontRequest, resources);
ProviderCacheKey providerCacheKey = new ProviderCacheKey(fontRequest.getProviderAuthority(), fontRequest.getProviderPackage(), certificates);
ProviderInfo providerInfo = sProviderCache.get(providerCacheKey);
if (providerInfo != null) {
return providerInfo;
}
String providerAuthority = fontRequest.getProviderAuthority();
ProviderInfo resolveContentProvider = packageManager.resolveContentProvider(providerAuthority, 0);
if (resolveContentProvider == null) {
throw new PackageManager.NameNotFoundException("No package found for authority: " + providerAuthority);
}
if (!resolveContentProvider.packageName.equals(fontRequest.getProviderPackage())) {
throw new PackageManager.NameNotFoundException("Found content provider " + providerAuthority + ", but package was not " + fontRequest.getProviderPackage());
}
List<byte[]> convertToByteArrayList = convertToByteArrayList(packageManager.getPackageInfo(resolveContentProvider.packageName, 64).signatures);
Collections.sort(convertToByteArrayList, sByteArrayComparator);
for (int i = 0; i < certificates.size(); i++) {
ArrayList arrayList = new ArrayList(certificates.get(i));
Collections.sort(arrayList, sByteArrayComparator);
if (equalsByteArrayList(convertToByteArrayList, arrayList)) {
sProviderCache.put(providerCacheKey, resolveContentProvider);
return resolveContentProvider;
}
}
Trace.endSection();
return null;
} finally {
Trace.endSection();
}
}
/* JADX WARN: Multi-variable type inference failed */
@NonNull
@VisibleForTesting
public static FontsContractCompat.FontInfo[] query(Context context, FontRequest fontRequest, String str, CancellationSignal cancellationSignal) {
int i;
Cursor query;
ArrayList arrayList;
int i2;
Uri withAppendedId;
int i3;
boolean z;
Trace.beginSection("FontProvider.query");
try {
ArrayList arrayList2 = new ArrayList();
Uri build = new Uri.Builder().scheme("content").authority(str).build();
Uri build2 = new Uri.Builder().scheme("content").authority(str).appendPath("file").build();
ContentQueryWrapper make = ContentQueryWrapper.make(context, build);
Cursor cursor = null;
try {
String[] strArr = {"_id", FontsContractCompat.Columns.FILE_ID, FontsContractCompat.Columns.TTC_INDEX, FontsContractCompat.Columns.VARIATION_SETTINGS, FontsContractCompat.Columns.WEIGHT, FontsContractCompat.Columns.ITALIC, FontsContractCompat.Columns.RESULT_CODE};
Trace.beginSection("ContentQueryWrapper.query");
try {
i = 1;
query = make.query(build, strArr, "query = ?", new String[]{fontRequest.getQuery()}, null, cancellationSignal);
} finally {
}
} catch (Throwable th) {
th = th;
}
try {
Trace.endSection();
if (query == null || query.getCount() <= 0) {
arrayList = arrayList2;
} else {
int columnIndex = query.getColumnIndex(FontsContractCompat.Columns.RESULT_CODE);
ArrayList arrayList3 = new ArrayList();
int columnIndex2 = query.getColumnIndex("_id");
int columnIndex3 = query.getColumnIndex(FontsContractCompat.Columns.FILE_ID);
int columnIndex4 = query.getColumnIndex(FontsContractCompat.Columns.TTC_INDEX);
int columnIndex5 = query.getColumnIndex(FontsContractCompat.Columns.WEIGHT);
int columnIndex6 = query.getColumnIndex(FontsContractCompat.Columns.ITALIC);
while (query.moveToNext()) {
int i4 = columnIndex != -1 ? query.getInt(columnIndex) : 0;
int i5 = columnIndex4 != -1 ? query.getInt(columnIndex4) : 0;
if (columnIndex3 == -1) {
i2 = i5;
withAppendedId = ContentUris.withAppendedId(build, query.getLong(columnIndex2));
} else {
i2 = i5;
withAppendedId = ContentUris.withAppendedId(build2, query.getLong(columnIndex3));
}
int i6 = columnIndex5 != -1 ? query.getInt(columnIndex5) : 400;
if (columnIndex6 == -1 || query.getInt(columnIndex6) != i) {
i3 = i6;
z = 0;
} else {
z = i;
i3 = i6;
}
arrayList3.add(FontsContractCompat.FontInfo.create(withAppendedId, i2, i3, z, i4));
i = 1;
}
arrayList = arrayList3;
}
if (query != null) {
query.close();
}
make.close();
return (FontsContractCompat.FontInfo[]) arrayList.toArray(new FontsContractCompat.FontInfo[0]);
} catch (Throwable th2) {
th = th2;
cursor = query;
if (cursor != null) {
cursor.close();
}
make.close();
throw th;
}
} catch (Throwable th3) {
throw th3;
}
}
private static List<List<byte[]>> getCertificates(FontRequest fontRequest, Resources resources) {
if (fontRequest.getCertificates() != null) {
return fontRequest.getCertificates();
}
return FontResourcesParserCompat.readCerts(resources, fontRequest.getCertificatesArrayResId());
}
/* JADX INFO: Access modifiers changed from: private */
public static /* synthetic */ int lambda$static$0(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;
}
private static boolean equalsByteArrayList(List<byte[]> list, List<byte[]> list2) {
if (list.size() != list2.size()) {
return false;
}
for (int i = 0; i < list.size(); i++) {
if (!Arrays.equals(list.get(i), list2.get(i))) {
return false;
}
}
return true;
}
private static List<byte[]> convertToByteArrayList(Signature[] signatureArr) {
ArrayList arrayList = new ArrayList();
for (Signature signature : signatureArr) {
arrayList.add(signature.toByteArray());
}
return arrayList;
}
public interface ContentQueryWrapper {
void close();
Cursor query(Uri uri, String[] strArr, String str, String[] strArr2, String str2, CancellationSignal cancellationSignal);
static ContentQueryWrapper make(Context context, Uri uri) {
return new ContentQueryWrapperApi24Impl(context, uri);
}
}
public static class ContentQueryWrapperApi16Impl implements ContentQueryWrapper {
private final ContentProviderClient mClient;
public ContentQueryWrapperApi16Impl(Context context, Uri uri) {
this.mClient = context.getContentResolver().acquireUnstableContentProviderClient(uri);
}
@Override // androidx.core.provider.FontProvider.ContentQueryWrapper
public Cursor query(Uri uri, String[] strArr, String str, String[] strArr2, String str2, CancellationSignal cancellationSignal) {
ContentProviderClient contentProviderClient = this.mClient;
if (contentProviderClient == null) {
return null;
}
try {
return contentProviderClient.query(uri, strArr, str, strArr2, str2, cancellationSignal);
} catch (RemoteException e) {
Log.w("FontsProvider", "Unable to query the content provider", e);
return null;
}
}
@Override // androidx.core.provider.FontProvider.ContentQueryWrapper
public void close() {
ContentProviderClient contentProviderClient = this.mClient;
if (contentProviderClient != null) {
contentProviderClient.release();
}
}
}
@RequiresApi(24)
public static class ContentQueryWrapperApi24Impl implements ContentQueryWrapper {
private final ContentProviderClient mClient;
public ContentQueryWrapperApi24Impl(Context context, Uri uri) {
this.mClient = context.getContentResolver().acquireUnstableContentProviderClient(uri);
}
@Override // androidx.core.provider.FontProvider.ContentQueryWrapper
public Cursor query(Uri uri, String[] strArr, String str, String[] strArr2, String str2, CancellationSignal cancellationSignal) {
ContentProviderClient contentProviderClient = this.mClient;
if (contentProviderClient == null) {
return null;
}
try {
return contentProviderClient.query(uri, strArr, str, strArr2, str2, cancellationSignal);
} catch (RemoteException e) {
Log.w("FontsProvider", "Unable to query the content provider", e);
return null;
}
}
@Override // androidx.core.provider.FontProvider.ContentQueryWrapper
public void close() {
ContentProviderClient contentProviderClient = this.mClient;
if (contentProviderClient != null) {
contentProviderClient.close();
}
}
}
}