ADD week 5

This commit is contained in:
2025-03-31 16:33:42 +02:00
parent 86f265f22d
commit bf645048e6
4927 changed files with 544053 additions and 0 deletions

View File

@ -0,0 +1,50 @@
package androidx.core.provider;
import android.graphics.Typeface;
import android.os.Handler;
import androidx.core.provider.FontRequestWorker;
import androidx.core.provider.FontsContractCompat;
/* loaded from: classes.dex */
class CallbackWithHandler {
private final FontsContractCompat.FontRequestCallback mCallback;
private final Handler mCallbackHandler;
CallbackWithHandler(FontsContractCompat.FontRequestCallback fontRequestCallback, Handler handler) {
this.mCallback = fontRequestCallback;
this.mCallbackHandler = handler;
}
CallbackWithHandler(FontsContractCompat.FontRequestCallback fontRequestCallback) {
this.mCallback = fontRequestCallback;
this.mCallbackHandler = CalleeHandler.create();
}
private void onTypefaceRetrieved(final Typeface typeface) {
final FontsContractCompat.FontRequestCallback fontRequestCallback = this.mCallback;
this.mCallbackHandler.post(new Runnable() { // from class: androidx.core.provider.CallbackWithHandler.1
@Override // java.lang.Runnable
public void run() {
fontRequestCallback.onTypefaceRetrieved(typeface);
}
});
}
private void onTypefaceRequestFailed(final int i) {
final FontsContractCompat.FontRequestCallback fontRequestCallback = this.mCallback;
this.mCallbackHandler.post(new Runnable() { // from class: androidx.core.provider.CallbackWithHandler.2
@Override // java.lang.Runnable
public void run() {
fontRequestCallback.onTypefaceRequestFailed(i);
}
});
}
void onTypefaceResult(FontRequestWorker.TypefaceResult typefaceResult) {
if (typefaceResult.isSuccess()) {
onTypefaceRetrieved(typefaceResult.mTypeface);
} else {
onTypefaceRequestFailed(typefaceResult.mResult);
}
}
}

View File

@ -0,0 +1,17 @@
package androidx.core.provider;
import android.os.Handler;
import android.os.Looper;
/* loaded from: classes.dex */
class CalleeHandler {
private CalleeHandler() {
}
static Handler create() {
if (Looper.myLooper() == null) {
return new Handler(Looper.getMainLooper());
}
return new Handler();
}
}

View File

@ -0,0 +1,146 @@
package androidx.core.provider;
import android.content.ContentResolver;
import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.provider.DocumentsContract;
import java.io.FileNotFoundException;
import java.util.List;
/* loaded from: classes.dex */
public final class DocumentsContractCompat {
private static final String PATH_TREE = "tree";
public static final class DocumentCompat {
public static final int FLAG_VIRTUAL_DOCUMENT = 512;
private DocumentCompat() {
}
}
public static boolean isDocumentUri(Context context, Uri uri) {
return DocumentsContractApi19Impl.isDocumentUri(context, uri);
}
public static boolean isTreeUri(Uri uri) {
if (Build.VERSION.SDK_INT < 24) {
List<String> pathSegments = uri.getPathSegments();
return pathSegments.size() >= 2 && PATH_TREE.equals(pathSegments.get(0));
}
return DocumentsContractApi24Impl.isTreeUri(uri);
}
public static String getDocumentId(Uri uri) {
return DocumentsContractApi19Impl.getDocumentId(uri);
}
public static String getTreeDocumentId(Uri uri) {
return DocumentsContractApi21Impl.getTreeDocumentId(uri);
}
public static Uri buildDocumentUri(String str, String str2) {
return DocumentsContractApi19Impl.buildDocumentUri(str, str2);
}
public static Uri buildDocumentUriUsingTree(Uri uri, String str) {
return DocumentsContractApi21Impl.buildDocumentUriUsingTree(uri, str);
}
public static Uri buildTreeDocumentUri(String str, String str2) {
return DocumentsContractApi21Impl.buildTreeDocumentUri(str, str2);
}
public static Uri buildChildDocumentsUri(String str, String str2) {
return DocumentsContractApi21Impl.buildChildDocumentsUri(str, str2);
}
public static Uri buildChildDocumentsUriUsingTree(Uri uri, String str) {
return DocumentsContractApi21Impl.buildChildDocumentsUriUsingTree(uri, str);
}
public static Uri createDocument(ContentResolver contentResolver, Uri uri, String str, String str2) throws FileNotFoundException {
return DocumentsContractApi21Impl.createDocument(contentResolver, uri, str, str2);
}
public static Uri renameDocument(ContentResolver contentResolver, Uri uri, String str) throws FileNotFoundException {
return DocumentsContractApi21Impl.renameDocument(contentResolver, uri, str);
}
public static boolean removeDocument(ContentResolver contentResolver, Uri uri, Uri uri2) throws FileNotFoundException {
if (Build.VERSION.SDK_INT >= 24) {
return DocumentsContractApi24Impl.removeDocument(contentResolver, uri, uri2);
}
return DocumentsContractApi19Impl.deleteDocument(contentResolver, uri);
}
private static class DocumentsContractApi19Impl {
public static Uri buildDocumentUri(String str, String str2) {
return DocumentsContract.buildDocumentUri(str, str2);
}
static boolean isDocumentUri(Context context, Uri uri) {
return DocumentsContract.isDocumentUri(context, uri);
}
static String getDocumentId(Uri uri) {
return DocumentsContract.getDocumentId(uri);
}
static boolean deleteDocument(ContentResolver contentResolver, Uri uri) throws FileNotFoundException {
return DocumentsContract.deleteDocument(contentResolver, uri);
}
private DocumentsContractApi19Impl() {
}
}
private static class DocumentsContractApi21Impl {
static String getTreeDocumentId(Uri uri) {
return DocumentsContract.getTreeDocumentId(uri);
}
public static Uri buildTreeDocumentUri(String str, String str2) {
return DocumentsContract.buildTreeDocumentUri(str, str2);
}
static Uri buildDocumentUriUsingTree(Uri uri, String str) {
return DocumentsContract.buildDocumentUriUsingTree(uri, str);
}
static Uri buildChildDocumentsUri(String str, String str2) {
return DocumentsContract.buildChildDocumentsUri(str, str2);
}
static Uri buildChildDocumentsUriUsingTree(Uri uri, String str) {
return DocumentsContract.buildChildDocumentsUriUsingTree(uri, str);
}
static Uri createDocument(ContentResolver contentResolver, Uri uri, String str, String str2) throws FileNotFoundException {
return DocumentsContract.createDocument(contentResolver, uri, str, str2);
}
static Uri renameDocument(ContentResolver contentResolver, Uri uri, String str) throws FileNotFoundException {
return DocumentsContract.renameDocument(contentResolver, uri, str);
}
private DocumentsContractApi21Impl() {
}
}
private static class DocumentsContractApi24Impl {
static boolean isTreeUri(Uri uri) {
return DocumentsContract.isTreeUri(uri);
}
static boolean removeDocument(ContentResolver contentResolver, Uri uri, Uri uri2) throws FileNotFoundException {
return DocumentsContract.removeDocument(contentResolver, uri, uri2);
}
private DocumentsContractApi24Impl() {
}
}
private DocumentsContractCompat() {
}
}

View File

@ -0,0 +1,159 @@
package androidx.core.provider;
import android.content.ContentResolver;
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 androidx.core.content.res.FontResourcesParserCompat;
import androidx.core.provider.FontsContractCompat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/* loaded from: classes.dex */
class FontProvider {
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) {
return FontProvider.lambda$static$0((byte[]) obj, (byte[]) obj2);
}
};
private FontProvider() {
}
static FontsContractCompat.FontFamilyResult getFontFamilyResult(Context context, FontRequest fontRequest, CancellationSignal cancellationSignal) throws PackageManager.NameNotFoundException {
ProviderInfo provider = getProvider(context.getPackageManager(), fontRequest, context.getResources());
if (provider == null) {
return FontsContractCompat.FontFamilyResult.create(1, null);
}
return FontsContractCompat.FontFamilyResult.create(0, query(context, fontRequest, provider.authority, cancellationSignal));
}
static ProviderInfo getProvider(PackageManager packageManager, FontRequest fontRequest, Resources resources) throws PackageManager.NameNotFoundException {
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);
List<List<byte[]>> certificates = getCertificates(fontRequest, resources);
for (int i = 0; i < certificates.size(); i++) {
ArrayList arrayList = new ArrayList(certificates.get(i));
Collections.sort(arrayList, sByteArrayComparator);
if (equalsByteArrayList(convertToByteArrayList, arrayList)) {
return resolveContentProvider;
}
}
return null;
}
static FontsContractCompat.FontInfo[] query(Context context, FontRequest fontRequest, String str, CancellationSignal cancellationSignal) {
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();
Cursor cursor = null;
try {
Cursor query = Api16Impl.query(context.getContentResolver(), build, new String[]{"_id", FontsContractCompat.Columns.FILE_ID, FontsContractCompat.Columns.TTC_INDEX, FontsContractCompat.Columns.VARIATION_SETTINGS, FontsContractCompat.Columns.WEIGHT, FontsContractCompat.Columns.ITALIC, FontsContractCompat.Columns.RESULT_CODE}, "query = ?", new String[]{fontRequest.getQuery()}, null, cancellationSignal);
if (query != null) {
try {
if (query.getCount() > 0) {
int columnIndex = query.getColumnIndex(FontsContractCompat.Columns.RESULT_CODE);
arrayList = 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 i = columnIndex != -1 ? query.getInt(columnIndex) : 0;
int i2 = columnIndex4 != -1 ? query.getInt(columnIndex4) : 0;
if (columnIndex3 == -1) {
withAppendedId = ContentUris.withAppendedId(build, query.getLong(columnIndex2));
} else {
withAppendedId = ContentUris.withAppendedId(build2, query.getLong(columnIndex3));
}
arrayList.add(FontsContractCompat.FontInfo.create(withAppendedId, i2, columnIndex5 != -1 ? query.getInt(columnIndex5) : 400, columnIndex6 != -1 && query.getInt(columnIndex6) == 1, i));
}
}
} catch (Throwable th) {
th = th;
cursor = query;
if (cursor != null) {
cursor.close();
}
throw th;
}
}
if (query != null) {
query.close();
}
return (FontsContractCompat.FontInfo[]) arrayList.toArray(new FontsContractCompat.FontInfo[0]);
} catch (Throwable th2) {
th = th2;
}
}
private static List<List<byte[]>> getCertificates(FontRequest fontRequest, Resources resources) {
if (fontRequest.getCertificates() != null) {
return fontRequest.getCertificates();
}
return FontResourcesParserCompat.readCerts(resources, fontRequest.getCertificatesArrayResId());
}
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;
}
static class Api16Impl {
private Api16Impl() {
}
static Cursor query(ContentResolver contentResolver, Uri uri, String[] strArr, String str, String[] strArr2, String str2, Object obj) {
return contentResolver.query(uri, strArr, str, strArr2, str2, (CancellationSignal) obj);
}
}
}

View File

@ -0,0 +1,85 @@
package androidx.core.provider;
import android.util.Base64;
import androidx.core.util.Preconditions;
import java.util.List;
/* loaded from: classes.dex */
public final class FontRequest {
private final List<List<byte[]>> mCertificates;
private final int mCertificatesArray;
private final String mIdentifier;
private final String mProviderAuthority;
private final String mProviderPackage;
private final String mQuery;
public List<List<byte[]>> getCertificates() {
return this.mCertificates;
}
public int getCertificatesArrayResId() {
return this.mCertificatesArray;
}
String getId() {
return this.mIdentifier;
}
@Deprecated
public String getIdentifier() {
return this.mIdentifier;
}
public String getProviderAuthority() {
return this.mProviderAuthority;
}
public String getProviderPackage() {
return this.mProviderPackage;
}
public String getQuery() {
return this.mQuery;
}
public FontRequest(String str, String str2, String str3, List<List<byte[]>> list) {
this.mProviderAuthority = (String) Preconditions.checkNotNull(str);
this.mProviderPackage = (String) Preconditions.checkNotNull(str2);
this.mQuery = (String) Preconditions.checkNotNull(str3);
this.mCertificates = (List) Preconditions.checkNotNull(list);
this.mCertificatesArray = 0;
this.mIdentifier = createIdentifier(str, str2, str3);
}
public FontRequest(String str, String str2, String str3, int i) {
this.mProviderAuthority = (String) Preconditions.checkNotNull(str);
this.mProviderPackage = (String) Preconditions.checkNotNull(str2);
this.mQuery = (String) Preconditions.checkNotNull(str3);
this.mCertificates = null;
Preconditions.checkArgument(i != 0);
this.mCertificatesArray = i;
this.mIdentifier = createIdentifier(str, str2, str3);
}
private String createIdentifier(String str, String str2, String str3) {
return str + "-" + str2 + "-" + str3;
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("FontRequest {mProviderAuthority: " + this.mProviderAuthority + ", mProviderPackage: " + this.mProviderPackage + ", mQuery: " + this.mQuery + ", mCertificates:");
for (int i = 0; i < this.mCertificates.size(); i++) {
sb.append(" [");
List<byte[]> list = this.mCertificates.get(i);
for (int i2 = 0; i2 < list.size(); i2++) {
sb.append(" \"");
sb.append(Base64.encodeToString(list.get(i2), 0));
sb.append("\"");
}
sb.append(" ]");
}
sb.append("}");
sb.append("mCertificatesArray: " + this.mCertificatesArray);
return sb.toString();
}
}

View File

@ -0,0 +1,183 @@
package androidx.core.provider;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Typeface;
import androidx.collection.LruCache;
import androidx.collection.SimpleArrayMap;
import androidx.core.graphics.TypefaceCompat;
import androidx.core.provider.FontsContractCompat;
import androidx.core.util.Consumer;
import java.util.ArrayList;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
/* loaded from: classes.dex */
class FontRequestWorker {
static final LruCache<String, Typeface> sTypefaceCache = new LruCache<>(16);
private static final ExecutorService DEFAULT_EXECUTOR_SERVICE = RequestExecutor.createDefaultExecutor("fonts-androidx", 10, 10000);
static final Object LOCK = new Object();
static final SimpleArrayMap<String, ArrayList<Consumer<TypefaceResult>>> PENDING_REPLIES = new SimpleArrayMap<>();
private FontRequestWorker() {
}
static void resetTypefaceCache() {
sTypefaceCache.evictAll();
}
static Typeface requestFontSync(final Context context, final FontRequest fontRequest, CallbackWithHandler callbackWithHandler, final int i, int i2) {
final String createCacheId = createCacheId(fontRequest, i);
Typeface typeface = sTypefaceCache.get(createCacheId);
if (typeface != null) {
callbackWithHandler.onTypefaceResult(new TypefaceResult(typeface));
return typeface;
}
if (i2 == -1) {
TypefaceResult fontSync = getFontSync(createCacheId, context, fontRequest, i);
callbackWithHandler.onTypefaceResult(fontSync);
return fontSync.mTypeface;
}
try {
TypefaceResult typefaceResult = (TypefaceResult) RequestExecutor.submit(DEFAULT_EXECUTOR_SERVICE, new Callable<TypefaceResult>() { // from class: androidx.core.provider.FontRequestWorker.1
/* JADX WARN: Can't rename method to resolve collision */
@Override // java.util.concurrent.Callable
public TypefaceResult call() {
return FontRequestWorker.getFontSync(createCacheId, context, fontRequest, i);
}
}, i2);
callbackWithHandler.onTypefaceResult(typefaceResult);
return typefaceResult.mTypeface;
} catch (InterruptedException unused) {
callbackWithHandler.onTypefaceResult(new TypefaceResult(-3));
return null;
}
}
static Typeface requestFontAsync(final Context context, final FontRequest fontRequest, final int i, Executor executor, final CallbackWithHandler callbackWithHandler) {
final String createCacheId = createCacheId(fontRequest, i);
Typeface typeface = sTypefaceCache.get(createCacheId);
if (typeface != null) {
callbackWithHandler.onTypefaceResult(new TypefaceResult(typeface));
return typeface;
}
Consumer<TypefaceResult> consumer = new Consumer<TypefaceResult>() { // from class: androidx.core.provider.FontRequestWorker.2
@Override // androidx.core.util.Consumer
public void accept(TypefaceResult typefaceResult) {
if (typefaceResult == null) {
typefaceResult = new TypefaceResult(-3);
}
CallbackWithHandler.this.onTypefaceResult(typefaceResult);
}
};
synchronized (LOCK) {
SimpleArrayMap<String, ArrayList<Consumer<TypefaceResult>>> simpleArrayMap = PENDING_REPLIES;
ArrayList<Consumer<TypefaceResult>> arrayList = simpleArrayMap.get(createCacheId);
if (arrayList != null) {
arrayList.add(consumer);
return null;
}
ArrayList<Consumer<TypefaceResult>> arrayList2 = new ArrayList<>();
arrayList2.add(consumer);
simpleArrayMap.put(createCacheId, arrayList2);
Callable<TypefaceResult> callable = new Callable<TypefaceResult>() { // from class: androidx.core.provider.FontRequestWorker.3
/* JADX WARN: Can't rename method to resolve collision */
@Override // java.util.concurrent.Callable
public TypefaceResult call() {
try {
return FontRequestWorker.getFontSync(createCacheId, context, fontRequest, i);
} catch (Throwable unused) {
return new TypefaceResult(-3);
}
}
};
if (executor == null) {
executor = DEFAULT_EXECUTOR_SERVICE;
}
RequestExecutor.execute(executor, callable, new Consumer<TypefaceResult>() { // from class: androidx.core.provider.FontRequestWorker.4
@Override // androidx.core.util.Consumer
public void accept(TypefaceResult typefaceResult) {
synchronized (FontRequestWorker.LOCK) {
ArrayList<Consumer<TypefaceResult>> arrayList3 = FontRequestWorker.PENDING_REPLIES.get(createCacheId);
if (arrayList3 == null) {
return;
}
FontRequestWorker.PENDING_REPLIES.remove(createCacheId);
for (int i2 = 0; i2 < arrayList3.size(); i2++) {
arrayList3.get(i2).accept(typefaceResult);
}
}
}
});
return null;
}
}
private static String createCacheId(FontRequest fontRequest, int i) {
return fontRequest.getId() + "-" + i;
}
static TypefaceResult getFontSync(String str, Context context, FontRequest fontRequest, int i) {
LruCache<String, Typeface> lruCache = sTypefaceCache;
Typeface typeface = lruCache.get(str);
if (typeface != null) {
return new TypefaceResult(typeface);
}
try {
FontsContractCompat.FontFamilyResult fontFamilyResult = FontProvider.getFontFamilyResult(context, fontRequest, null);
int fontFamilyResultStatus = getFontFamilyResultStatus(fontFamilyResult);
if (fontFamilyResultStatus != 0) {
return new TypefaceResult(fontFamilyResultStatus);
}
Typeface createFromFontInfo = TypefaceCompat.createFromFontInfo(context, null, fontFamilyResult.getFonts(), i);
if (createFromFontInfo != null) {
lruCache.put(str, createFromFontInfo);
return new TypefaceResult(createFromFontInfo);
}
return new TypefaceResult(-3);
} catch (PackageManager.NameNotFoundException unused) {
return new TypefaceResult(-1);
}
}
private static int getFontFamilyResultStatus(FontsContractCompat.FontFamilyResult fontFamilyResult) {
int i = 1;
if (fontFamilyResult.getStatusCode() != 0) {
return fontFamilyResult.getStatusCode() != 1 ? -3 : -2;
}
FontsContractCompat.FontInfo[] fonts = fontFamilyResult.getFonts();
if (fonts != null && fonts.length != 0) {
i = 0;
for (FontsContractCompat.FontInfo fontInfo : fonts) {
int resultCode = fontInfo.getResultCode();
if (resultCode != 0) {
if (resultCode < 0) {
return -3;
}
return resultCode;
}
}
}
return i;
}
static final class TypefaceResult {
final int mResult;
final Typeface mTypeface;
boolean isSuccess() {
return this.mResult == 0;
}
TypefaceResult(int i) {
this.mTypeface = null;
this.mResult = i;
}
TypefaceResult(Typeface typeface) {
this.mTypeface = typeface;
this.mResult = 0;
}
}
}

View File

@ -0,0 +1,184 @@
package androidx.core.provider;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.CancellationSignal;
import android.os.Handler;
import android.provider.BaseColumns;
import androidx.core.content.res.ResourcesCompat;
import androidx.core.graphics.TypefaceCompat;
import androidx.core.graphics.TypefaceCompatUtil;
import androidx.core.util.Preconditions;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.nio.ByteBuffer;
import java.util.Map;
/* loaded from: classes.dex */
public class FontsContractCompat {
@Deprecated
public static final String PARCEL_FONT_RESULTS = "font_results";
@Deprecated
static final int RESULT_CODE_PROVIDER_NOT_FOUND = -1;
@Deprecated
static final int RESULT_CODE_WRONG_CERTIFICATES = -2;
public static final class Columns implements BaseColumns {
public static final String FILE_ID = "file_id";
public static final String ITALIC = "font_italic";
public static final String RESULT_CODE = "result_code";
public static final int RESULT_CODE_FONT_NOT_FOUND = 1;
public static final int RESULT_CODE_FONT_UNAVAILABLE = 2;
public static final int RESULT_CODE_MALFORMED_QUERY = 3;
public static final int RESULT_CODE_OK = 0;
public static final String TTC_INDEX = "font_ttc_index";
public static final String VARIATION_SETTINGS = "font_variation_settings";
public static final String WEIGHT = "font_weight";
}
public static class FontRequestCallback {
public static final int FAIL_REASON_FONT_LOAD_ERROR = -3;
public static final int FAIL_REASON_FONT_NOT_FOUND = 1;
public static final int FAIL_REASON_FONT_UNAVAILABLE = 2;
public static final int FAIL_REASON_MALFORMED_QUERY = 3;
public static final int FAIL_REASON_PROVIDER_NOT_FOUND = -1;
public static final int FAIL_REASON_SECURITY_VIOLATION = -4;
public static final int FAIL_REASON_WRONG_CERTIFICATES = -2;
@Deprecated
public static final int RESULT_OK = 0;
static final int RESULT_SUCCESS = 0;
@Retention(RetentionPolicy.SOURCE)
public @interface FontRequestFailReason {
}
public void onTypefaceRequestFailed(int i) {
}
public void onTypefaceRetrieved(Typeface typeface) {
}
}
private FontsContractCompat() {
}
public static Typeface buildTypeface(Context context, CancellationSignal cancellationSignal, FontInfo[] fontInfoArr) {
return TypefaceCompat.createFromFontInfo(context, cancellationSignal, fontInfoArr, 0);
}
public static FontFamilyResult fetchFonts(Context context, CancellationSignal cancellationSignal, FontRequest fontRequest) throws PackageManager.NameNotFoundException {
return FontProvider.getFontFamilyResult(context, fontRequest, cancellationSignal);
}
public static void requestFont(Context context, FontRequest fontRequest, FontRequestCallback fontRequestCallback, Handler handler) {
CallbackWithHandler callbackWithHandler = new CallbackWithHandler(fontRequestCallback);
FontRequestWorker.requestFontAsync(context.getApplicationContext(), fontRequest, 0, RequestExecutor.createHandlerExecutor(handler), callbackWithHandler);
}
public static Typeface requestFont(Context context, FontRequest fontRequest, int i, boolean z, int i2, Handler handler, FontRequestCallback fontRequestCallback) {
CallbackWithHandler callbackWithHandler = new CallbackWithHandler(fontRequestCallback, handler);
if (z) {
return FontRequestWorker.requestFontSync(context, fontRequest, callbackWithHandler, i, i2);
}
return FontRequestWorker.requestFontAsync(context, fontRequest, i, null, callbackWithHandler);
}
public static void resetTypefaceCache() {
FontRequestWorker.resetTypefaceCache();
}
public static class FontInfo {
private final boolean mItalic;
private final int mResultCode;
private final int mTtcIndex;
private final Uri mUri;
private final int mWeight;
public int getResultCode() {
return this.mResultCode;
}
public int getTtcIndex() {
return this.mTtcIndex;
}
public Uri getUri() {
return this.mUri;
}
public int getWeight() {
return this.mWeight;
}
public boolean isItalic() {
return this.mItalic;
}
@Deprecated
public FontInfo(Uri uri, int i, int i2, boolean z, int i3) {
this.mUri = (Uri) Preconditions.checkNotNull(uri);
this.mTtcIndex = i;
this.mWeight = i2;
this.mItalic = z;
this.mResultCode = i3;
}
static FontInfo create(Uri uri, int i, int i2, boolean z, int i3) {
return new FontInfo(uri, i, i2, z, i3);
}
}
public static class FontFamilyResult {
public static final int STATUS_OK = 0;
public static final int STATUS_UNEXPECTED_DATA_PROVIDED = 2;
public static final int STATUS_WRONG_CERTIFICATES = 1;
private final FontInfo[] mFonts;
private final int mStatusCode;
public FontInfo[] getFonts() {
return this.mFonts;
}
public int getStatusCode() {
return this.mStatusCode;
}
@Deprecated
public FontFamilyResult(int i, FontInfo[] fontInfoArr) {
this.mStatusCode = i;
this.mFonts = fontInfoArr;
}
static FontFamilyResult create(int i, FontInfo[] fontInfoArr) {
return new FontFamilyResult(i, fontInfoArr);
}
}
@Deprecated
public static Typeface getFontSync(Context context, FontRequest fontRequest, ResourcesCompat.FontCallback fontCallback, Handler handler, boolean z, int i, int i2) {
return requestFont(context, fontRequest, i2, z, i, ResourcesCompat.FontCallback.getHandler(handler), new TypefaceCompat.ResourcesCallbackAdapter(fontCallback));
}
@Deprecated
public static void resetCache() {
FontRequestWorker.resetTypefaceCache();
}
@Deprecated
public static Map<Uri, ByteBuffer> prepareFontData(Context context, FontInfo[] fontInfoArr, CancellationSignal cancellationSignal) {
return TypefaceCompatUtil.readFontInfoIntoByteBuffer(context, fontInfoArr, cancellationSignal);
}
@Deprecated
public static ProviderInfo getProvider(PackageManager packageManager, FontRequest fontRequest, Resources resources) throws PackageManager.NameNotFoundException {
return FontProvider.getProvider(packageManager, fontRequest, resources);
}
}

View File

@ -0,0 +1,124 @@
package androidx.core.provider;
import android.os.Handler;
import android.os.Process;
import androidx.core.util.Consumer;
import androidx.core.util.Preconditions;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/* loaded from: classes.dex */
class RequestExecutor {
private RequestExecutor() {
}
static <T> void execute(Executor executor, Callable<T> callable, Consumer<T> consumer) {
executor.execute(new ReplyRunnable(CalleeHandler.create(), callable, consumer));
}
static <T> T submit(ExecutorService executorService, Callable<T> callable, int i) throws InterruptedException {
try {
return executorService.submit(callable).get(i, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
throw e;
} catch (ExecutionException e2) {
throw new RuntimeException(e2);
} catch (TimeoutException unused) {
throw new InterruptedException("timeout");
}
}
static ThreadPoolExecutor createDefaultExecutor(String str, int i, int i2) {
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(0, 1, i2, TimeUnit.MILLISECONDS, new LinkedBlockingDeque(), new DefaultThreadFactory(str, i));
threadPoolExecutor.allowCoreThreadTimeOut(true);
return threadPoolExecutor;
}
static Executor createHandlerExecutor(Handler handler) {
return new HandlerExecutor(handler);
}
private static class HandlerExecutor implements Executor {
private final Handler mHandler;
HandlerExecutor(Handler handler) {
this.mHandler = (Handler) Preconditions.checkNotNull(handler);
}
@Override // java.util.concurrent.Executor
public void execute(Runnable runnable) {
if (this.mHandler.post((Runnable) Preconditions.checkNotNull(runnable))) {
return;
}
throw new RejectedExecutionException(this.mHandler + " is shutting down");
}
}
private static class ReplyRunnable<T> implements Runnable {
private Callable<T> mCallable;
private Consumer<T> mConsumer;
private Handler mHandler;
ReplyRunnable(Handler handler, Callable<T> callable, Consumer<T> consumer) {
this.mCallable = callable;
this.mConsumer = consumer;
this.mHandler = handler;
}
@Override // java.lang.Runnable
public void run() {
final T t;
try {
t = this.mCallable.call();
} catch (Exception unused) {
t = null;
}
final Consumer<T> consumer = this.mConsumer;
this.mHandler.post(new Runnable() { // from class: androidx.core.provider.RequestExecutor.ReplyRunnable.1
/* JADX WARN: Multi-variable type inference failed */
@Override // java.lang.Runnable
public void run() {
consumer.accept(t);
}
});
}
}
private static class DefaultThreadFactory implements ThreadFactory {
private int mPriority;
private String mThreadName;
DefaultThreadFactory(String str, int i) {
this.mThreadName = str;
this.mPriority = i;
}
@Override // java.util.concurrent.ThreadFactory
public Thread newThread(Runnable runnable) {
return new ProcessPriorityThread(runnable, this.mThreadName, this.mPriority);
}
private static class ProcessPriorityThread extends Thread {
private final int mPriority;
ProcessPriorityThread(Runnable runnable, String str, int i) {
super(runnable, str);
this.mPriority = i;
}
@Override // java.lang.Thread, java.lang.Runnable
public void run() {
Process.setThreadPriority(this.mPriority);
super.run();
}
}
}
}

View File

@ -0,0 +1,164 @@
package androidx.core.provider;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
@Deprecated
/* loaded from: classes.dex */
public class SelfDestructiveThread {
private static final int MSG_DESTRUCTION = 0;
private static final int MSG_INVOKE_RUNNABLE = 1;
private final int mDestructAfterMillisec;
private Handler mHandler;
private final int mPriority;
private HandlerThread mThread;
private final String mThreadName;
private final Object mLock = new Object();
private Handler.Callback mCallback = new Handler.Callback() { // from class: androidx.core.provider.SelfDestructiveThread.1
@Override // android.os.Handler.Callback
public boolean handleMessage(Message message) {
int i = message.what;
if (i == 0) {
SelfDestructiveThread.this.onDestruction();
return true;
}
if (i != 1) {
return true;
}
SelfDestructiveThread.this.onInvokeRunnable((Runnable) message.obj);
return true;
}
};
private int mGeneration = 0;
public interface ReplyCallback<T> {
void onReply(T t);
}
public SelfDestructiveThread(String str, int i, int i2) {
this.mThreadName = str;
this.mPriority = i;
this.mDestructAfterMillisec = i2;
}
public boolean isRunning() {
boolean z;
synchronized (this.mLock) {
z = this.mThread != null;
}
return z;
}
public int getGeneration() {
int i;
synchronized (this.mLock) {
i = this.mGeneration;
}
return i;
}
private void post(Runnable runnable) {
synchronized (this.mLock) {
if (this.mThread == null) {
HandlerThread handlerThread = new HandlerThread(this.mThreadName, this.mPriority);
this.mThread = handlerThread;
handlerThread.start();
this.mHandler = new Handler(this.mThread.getLooper(), this.mCallback);
this.mGeneration++;
}
this.mHandler.removeMessages(0);
Handler handler = this.mHandler;
handler.sendMessage(handler.obtainMessage(1, runnable));
}
}
public <T> void postAndReply(final Callable<T> callable, final ReplyCallback<T> replyCallback) {
final Handler create = CalleeHandler.create();
post(new Runnable() { // from class: androidx.core.provider.SelfDestructiveThread.2
@Override // java.lang.Runnable
public void run() {
final Object obj;
try {
obj = callable.call();
} catch (Exception unused) {
obj = null;
}
create.post(new Runnable() { // from class: androidx.core.provider.SelfDestructiveThread.2.1
@Override // java.lang.Runnable
public void run() {
replyCallback.onReply(obj);
}
});
}
});
}
public <T> T postAndWait(final Callable<T> callable, int i) throws InterruptedException {
final ReentrantLock reentrantLock = new ReentrantLock();
final Condition newCondition = reentrantLock.newCondition();
final AtomicReference atomicReference = new AtomicReference();
final AtomicBoolean atomicBoolean = new AtomicBoolean(true);
post(new Runnable() { // from class: androidx.core.provider.SelfDestructiveThread.3
@Override // java.lang.Runnable
public void run() {
try {
atomicReference.set(callable.call());
} catch (Exception unused) {
}
reentrantLock.lock();
try {
atomicBoolean.set(false);
newCondition.signal();
} finally {
reentrantLock.unlock();
}
}
});
reentrantLock.lock();
try {
if (!atomicBoolean.get()) {
return (T) atomicReference.get();
}
long nanos = TimeUnit.MILLISECONDS.toNanos(i);
do {
try {
nanos = newCondition.awaitNanos(nanos);
} catch (InterruptedException unused) {
}
if (!atomicBoolean.get()) {
return (T) atomicReference.get();
}
} while (nanos > 0);
throw new InterruptedException("timeout");
} finally {
reentrantLock.unlock();
}
}
void onInvokeRunnable(Runnable runnable) {
runnable.run();
synchronized (this.mLock) {
this.mHandler.removeMessages(0);
Handler handler = this.mHandler;
handler.sendMessageDelayed(handler.obtainMessage(0), this.mDestructAfterMillisec);
}
}
void onDestruction() {
synchronized (this.mLock) {
if (this.mHandler.hasMessages(1)) {
return;
}
this.mThread.quit();
this.mThread = null;
this.mHandler = null;
}
}
}