619 lines
26 KiB
Java
619 lines
26 KiB
Java
package androidx.core.provider;
|
|
|
|
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.CancellationSignal;
|
|
import android.os.Handler;
|
|
import android.provider.BaseColumns;
|
|
import androidx.annotation.GuardedBy;
|
|
import androidx.annotation.IntRange;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.annotation.RequiresApi;
|
|
import androidx.annotation.RestrictTo;
|
|
import androidx.annotation.VisibleForTesting;
|
|
import androidx.collection.LruCache;
|
|
import androidx.collection.SimpleArrayMap;
|
|
import androidx.core.content.res.FontResourcesParserCompat;
|
|
import androidx.core.content.res.ResourcesCompat;
|
|
import androidx.core.graphics.TypefaceCompat;
|
|
import androidx.core.graphics.TypefaceCompatUtil;
|
|
import androidx.core.provider.SelfDestructiveThread;
|
|
import androidx.core.util.Preconditions;
|
|
import c.d.b.a.a;
|
|
import java.lang.annotation.Retention;
|
|
import java.lang.annotation.RetentionPolicy;
|
|
import java.nio.ByteBuffer;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Collections;
|
|
import java.util.Comparator;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.concurrent.Callable;
|
|
public class FontsContractCompat {
|
|
private static final int BACKGROUND_THREAD_KEEP_ALIVE_DURATION_MS = 10000;
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
public static final String PARCEL_FONT_RESULTS = "font_results";
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
public static final int RESULT_CODE_PROVIDER_NOT_FOUND = -1;
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
public static final int RESULT_CODE_WRONG_CERTIFICATES = -2;
|
|
private static final SelfDestructiveThread sBackgroundThread = new SelfDestructiveThread("fonts", 10, 10000);
|
|
private static final Comparator<byte[]> sByteArrayComparator = new AnonymousClass5();
|
|
public static final Object sLock = new Object();
|
|
@GuardedBy("sLock")
|
|
public static final SimpleArrayMap<String, ArrayList<SelfDestructiveThread.ReplyCallback<TypefaceResult>>> sPendingReplies = new SimpleArrayMap<>();
|
|
public static final LruCache<String, Typeface> sTypefaceCache = new LruCache<>(16);
|
|
|
|
/* renamed from: androidx.core.provider.FontsContractCompat$1 reason: invalid class name */
|
|
public class AnonymousClass1 implements Callable<TypefaceResult> {
|
|
public final /* synthetic */ Context val$context;
|
|
public final /* synthetic */ String val$id;
|
|
public final /* synthetic */ FontRequest val$request;
|
|
public final /* synthetic */ int val$style;
|
|
|
|
public AnonymousClass1(Context context, FontRequest fontRequest, int i, String str) {
|
|
this.val$context = context;
|
|
this.val$request = fontRequest;
|
|
this.val$style = i;
|
|
this.val$id = str;
|
|
}
|
|
|
|
@Override // java.util.concurrent.Callable
|
|
public TypefaceResult call() throws Exception {
|
|
TypefaceResult fontInternal = FontsContractCompat.getFontInternal(this.val$context, this.val$request, this.val$style);
|
|
Typeface typeface = fontInternal.mTypeface;
|
|
if (typeface != null) {
|
|
FontsContractCompat.sTypefaceCache.put(this.val$id, typeface);
|
|
}
|
|
return fontInternal;
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.core.provider.FontsContractCompat$2 reason: invalid class name */
|
|
public class AnonymousClass2 implements SelfDestructiveThread.ReplyCallback<TypefaceResult> {
|
|
public final /* synthetic */ ResourcesCompat.FontCallback val$fontCallback;
|
|
public final /* synthetic */ Handler val$handler;
|
|
|
|
public AnonymousClass2(ResourcesCompat.FontCallback fontCallback, Handler handler) {
|
|
this.val$fontCallback = fontCallback;
|
|
this.val$handler = handler;
|
|
}
|
|
|
|
public void onReply(TypefaceResult typefaceResult) {
|
|
if (typefaceResult == null) {
|
|
this.val$fontCallback.callbackFailAsync(1, this.val$handler);
|
|
return;
|
|
}
|
|
int i = typefaceResult.mResult;
|
|
if (i == 0) {
|
|
this.val$fontCallback.callbackSuccessAsync(typefaceResult.mTypeface, this.val$handler);
|
|
} else {
|
|
this.val$fontCallback.callbackFailAsync(i, this.val$handler);
|
|
}
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.core.provider.FontsContractCompat$3 reason: invalid class name */
|
|
public class AnonymousClass3 implements SelfDestructiveThread.ReplyCallback<TypefaceResult> {
|
|
public final /* synthetic */ String val$id;
|
|
|
|
public AnonymousClass3(String str) {
|
|
this.val$id = str;
|
|
}
|
|
|
|
public void onReply(TypefaceResult typefaceResult) {
|
|
ArrayList<SelfDestructiveThread.ReplyCallback<TypefaceResult>> arrayList;
|
|
synchronized (FontsContractCompat.sLock) {
|
|
SimpleArrayMap<String, ArrayList<SelfDestructiveThread.ReplyCallback<TypefaceResult>>> simpleArrayMap = FontsContractCompat.sPendingReplies;
|
|
arrayList = simpleArrayMap.get(this.val$id);
|
|
if (arrayList != null) {
|
|
simpleArrayMap.remove(this.val$id);
|
|
} else {
|
|
return;
|
|
}
|
|
}
|
|
for (int i = 0; i < arrayList.size(); i++) {
|
|
arrayList.get(i).onReply(typefaceResult);
|
|
}
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.core.provider.FontsContractCompat$4 reason: invalid class name */
|
|
public class AnonymousClass4 implements Runnable {
|
|
public final /* synthetic */ Context val$appContext;
|
|
public final /* synthetic */ FontRequestCallback val$callback;
|
|
public final /* synthetic */ Handler val$callerThreadHandler;
|
|
public final /* synthetic */ FontRequest val$request;
|
|
|
|
/* renamed from: androidx.core.provider.FontsContractCompat$4$1 reason: invalid class name */
|
|
public class AnonymousClass1 implements Runnable {
|
|
public AnonymousClass1() {
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
AnonymousClass4.this.val$callback.onTypefaceRequestFailed(-1);
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.core.provider.FontsContractCompat$4$2 reason: invalid class name */
|
|
public class AnonymousClass2 implements Runnable {
|
|
public AnonymousClass2() {
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
AnonymousClass4.this.val$callback.onTypefaceRequestFailed(-2);
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.core.provider.FontsContractCompat$4$3 reason: invalid class name */
|
|
public class AnonymousClass3 implements Runnable {
|
|
public AnonymousClass3() {
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
AnonymousClass4.this.val$callback.onTypefaceRequestFailed(-3);
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.core.provider.FontsContractCompat$4$4 reason: invalid class name */
|
|
public class AnonymousClass4 implements Runnable {
|
|
public AnonymousClass4() {
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
AnonymousClass4.this.val$callback.onTypefaceRequestFailed(-3);
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.core.provider.FontsContractCompat$4$5 reason: invalid class name */
|
|
public class AnonymousClass5 implements Runnable {
|
|
public AnonymousClass5() {
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
AnonymousClass4.this.val$callback.onTypefaceRequestFailed(1);
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.core.provider.FontsContractCompat$4$6 reason: invalid class name */
|
|
public class AnonymousClass6 implements Runnable {
|
|
public AnonymousClass6() {
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
AnonymousClass4.this.val$callback.onTypefaceRequestFailed(-3);
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.core.provider.FontsContractCompat$4$7 reason: invalid class name */
|
|
public class AnonymousClass7 implements Runnable {
|
|
public final /* synthetic */ int val$resultCode;
|
|
|
|
public AnonymousClass7(int i) {
|
|
this.val$resultCode = i;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
AnonymousClass4.this.val$callback.onTypefaceRequestFailed(this.val$resultCode);
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.core.provider.FontsContractCompat$4$8 reason: invalid class name */
|
|
public class AnonymousClass8 implements Runnable {
|
|
public AnonymousClass8() {
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
AnonymousClass4.this.val$callback.onTypefaceRequestFailed(-3);
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.core.provider.FontsContractCompat$4$9 reason: invalid class name */
|
|
public class AnonymousClass9 implements Runnable {
|
|
public final /* synthetic */ Typeface val$typeface;
|
|
|
|
public AnonymousClass9(Typeface typeface) {
|
|
this.val$typeface = typeface;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
AnonymousClass4.this.val$callback.onTypefaceRetrieved(this.val$typeface);
|
|
}
|
|
}
|
|
|
|
public AnonymousClass4(Context context, FontRequest fontRequest, Handler handler, FontRequestCallback fontRequestCallback) {
|
|
this.val$appContext = context;
|
|
this.val$request = fontRequest;
|
|
this.val$callerThreadHandler = handler;
|
|
this.val$callback = fontRequestCallback;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
try {
|
|
FontFamilyResult fetchFonts = FontsContractCompat.fetchFonts(this.val$appContext, null, this.val$request);
|
|
if (fetchFonts.getStatusCode() != 0) {
|
|
int statusCode = fetchFonts.getStatusCode();
|
|
if (statusCode == 1) {
|
|
this.val$callerThreadHandler.post(new AnonymousClass2());
|
|
} else if (statusCode != 2) {
|
|
this.val$callerThreadHandler.post(new AnonymousClass4());
|
|
} else {
|
|
this.val$callerThreadHandler.post(new AnonymousClass3());
|
|
}
|
|
} else {
|
|
FontInfo[] fonts = fetchFonts.getFonts();
|
|
if (fonts == null || fonts.length == 0) {
|
|
this.val$callerThreadHandler.post(new AnonymousClass5());
|
|
return;
|
|
}
|
|
for (FontInfo fontInfo : fonts) {
|
|
if (fontInfo.getResultCode() != 0) {
|
|
int resultCode = fontInfo.getResultCode();
|
|
if (resultCode < 0) {
|
|
this.val$callerThreadHandler.post(new AnonymousClass6());
|
|
return;
|
|
} else {
|
|
this.val$callerThreadHandler.post(new AnonymousClass7(resultCode));
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
Typeface buildTypeface = FontsContractCompat.buildTypeface(this.val$appContext, null, fonts);
|
|
if (buildTypeface == null) {
|
|
this.val$callerThreadHandler.post(new AnonymousClass8());
|
|
} else {
|
|
this.val$callerThreadHandler.post(new AnonymousClass9(buildTypeface));
|
|
}
|
|
}
|
|
} catch (PackageManager.NameNotFoundException unused) {
|
|
this.val$callerThreadHandler.post(new AnonymousClass1());
|
|
}
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.core.provider.FontsContractCompat$5 reason: invalid class name */
|
|
public class AnonymousClass5 implements Comparator<byte[]> {
|
|
public int compare(byte[] bArr, byte[] bArr2) {
|
|
int i;
|
|
int i2;
|
|
if (bArr.length != bArr2.length) {
|
|
i2 = bArr.length;
|
|
i = bArr2.length;
|
|
} else {
|
|
for (int i3 = 0; i3 < bArr.length; i3++) {
|
|
if (bArr[i3] != bArr2[i3]) {
|
|
i2 = bArr[i3];
|
|
i = bArr2[i3];
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
return (i2 == 1 ? 1 : 0) - (i == 1 ? 1 : 0);
|
|
}
|
|
}
|
|
|
|
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 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;
|
|
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
public FontFamilyResult(int i, @Nullable FontInfo[] fontInfoArr) {
|
|
this.mStatusCode = i;
|
|
this.mFonts = fontInfoArr;
|
|
}
|
|
|
|
public FontInfo[] getFonts() {
|
|
return this.mFonts;
|
|
}
|
|
|
|
public int getStatusCode() {
|
|
return this.mStatusCode;
|
|
}
|
|
}
|
|
|
|
public static class FontInfo {
|
|
private final boolean mItalic;
|
|
private final int mResultCode;
|
|
private final int mTtcIndex;
|
|
private final Uri mUri;
|
|
private final int mWeight;
|
|
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
public FontInfo(@NonNull Uri uri, @IntRange(from = 0) int i, @IntRange(from = 1, to = 1000) int i2, boolean z2, int i3) {
|
|
this.mUri = (Uri) Preconditions.checkNotNull(uri);
|
|
this.mTtcIndex = i;
|
|
this.mWeight = i2;
|
|
this.mItalic = z2;
|
|
this.mResultCode = i3;
|
|
}
|
|
|
|
public int getResultCode() {
|
|
return this.mResultCode;
|
|
}
|
|
|
|
@IntRange(from = 0)
|
|
public int getTtcIndex() {
|
|
return this.mTtcIndex;
|
|
}
|
|
|
|
@NonNull
|
|
public Uri getUri() {
|
|
return this.mUri;
|
|
}
|
|
|
|
@IntRange(from = 1, to = 1000)
|
|
public int getWeight() {
|
|
return this.mWeight;
|
|
}
|
|
|
|
public boolean isItalic() {
|
|
return this.mItalic;
|
|
}
|
|
}
|
|
|
|
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;
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
public static final int RESULT_OK = 0;
|
|
|
|
@Retention(RetentionPolicy.SOURCE)
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
public @interface FontRequestFailReason {
|
|
}
|
|
|
|
public void onTypefaceRequestFailed(int i) {
|
|
}
|
|
|
|
public void onTypefaceRetrieved(Typeface typeface) {
|
|
}
|
|
}
|
|
|
|
public static final class TypefaceResult {
|
|
public final int mResult;
|
|
public final Typeface mTypeface;
|
|
|
|
public TypefaceResult(@Nullable Typeface typeface, int i) {
|
|
this.mTypeface = typeface;
|
|
this.mResult = i;
|
|
}
|
|
}
|
|
|
|
private FontsContractCompat() {
|
|
}
|
|
|
|
@Nullable
|
|
public static Typeface buildTypeface(@NonNull Context context, @Nullable CancellationSignal cancellationSignal, @NonNull FontInfo[] fontInfoArr) {
|
|
return TypefaceCompat.createFromFontInfo(context, cancellationSignal, fontInfoArr, 0);
|
|
}
|
|
|
|
private static List<byte[]> convertToByteArrayList(Signature[] signatureArr) {
|
|
ArrayList arrayList = new ArrayList();
|
|
for (Signature signature : signatureArr) {
|
|
arrayList.add(signature.toByteArray());
|
|
}
|
|
return arrayList;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
@NonNull
|
|
public static FontFamilyResult fetchFonts(@NonNull Context context, @Nullable CancellationSignal cancellationSignal, @NonNull FontRequest fontRequest) throws PackageManager.NameNotFoundException {
|
|
ProviderInfo provider = getProvider(context.getPackageManager(), fontRequest, context.getResources());
|
|
return provider == null ? new FontFamilyResult(1, null) : new FontFamilyResult(0, getFontFromProvider(context, fontRequest, provider.authority, cancellationSignal));
|
|
}
|
|
|
|
private static List<List<byte[]>> getCertificates(FontRequest fontRequest, Resources resources) {
|
|
return fontRequest.getCertificates() != null ? fontRequest.getCertificates() : FontResourcesParserCompat.readCerts(resources, fontRequest.getCertificatesArrayResId());
|
|
}
|
|
|
|
@NonNull
|
|
@VisibleForTesting
|
|
public static FontInfo[] getFontFromProvider(Context context, FontRequest fontRequest, String str, CancellationSignal cancellationSignal) {
|
|
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 = context.getContentResolver().query(build, new String[]{"_id", "file_id", "font_ttc_index", "font_variation_settings", "font_weight", "font_italic", "result_code"}, "query = ?", new String[]{fontRequest.getQuery()}, null, cancellationSignal);
|
|
if (cursor != null && cursor.getCount() > 0) {
|
|
int columnIndex = cursor.getColumnIndex("result_code");
|
|
ArrayList arrayList2 = 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;
|
|
arrayList2.add(new FontInfo(columnIndex3 == -1 ? ContentUris.withAppendedId(build, cursor.getLong(columnIndex2)) : ContentUris.withAppendedId(build2, cursor.getLong(columnIndex3)), columnIndex4 != -1 ? cursor.getInt(columnIndex4) : 0, columnIndex5 != -1 ? cursor.getInt(columnIndex5) : 400, columnIndex6 != -1 && cursor.getInt(columnIndex6) == 1, i));
|
|
}
|
|
arrayList = arrayList2;
|
|
}
|
|
return (FontInfo[]) arrayList.toArray(new FontInfo[0]);
|
|
} finally {
|
|
if (cursor != null) {
|
|
cursor.close();
|
|
}
|
|
}
|
|
}
|
|
|
|
@NonNull
|
|
public static TypefaceResult getFontInternal(Context context, FontRequest fontRequest, int i) {
|
|
try {
|
|
FontFamilyResult fetchFonts = fetchFonts(context, null, fontRequest);
|
|
int i2 = -3;
|
|
if (fetchFonts.getStatusCode() == 0) {
|
|
Typeface createFromFontInfo = TypefaceCompat.createFromFontInfo(context, null, fetchFonts.getFonts(), i);
|
|
if (createFromFontInfo != null) {
|
|
i2 = 0;
|
|
}
|
|
return new TypefaceResult(createFromFontInfo, i2);
|
|
}
|
|
if (fetchFonts.getStatusCode() == 1) {
|
|
i2 = -2;
|
|
}
|
|
return new TypefaceResult(null, i2);
|
|
} catch (PackageManager.NameNotFoundException unused) {
|
|
return new TypefaceResult(null, -1);
|
|
}
|
|
}
|
|
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
public static Typeface getFontSync(Context context, FontRequest fontRequest, @Nullable ResourcesCompat.FontCallback fontCallback, @Nullable Handler handler, boolean z2, int i, int i2) {
|
|
String str = fontRequest.getIdentifier() + "-" + i2;
|
|
Typeface typeface = sTypefaceCache.get(str);
|
|
if (typeface != null) {
|
|
if (fontCallback != null) {
|
|
fontCallback.onFontRetrieved(typeface);
|
|
}
|
|
return typeface;
|
|
} else if (!z2 || i != -1) {
|
|
AnonymousClass1 r1 = new AnonymousClass1(context, fontRequest, i2, str);
|
|
if (z2) {
|
|
try {
|
|
return ((TypefaceResult) sBackgroundThread.postAndWait(r1, i)).mTypeface;
|
|
} catch (InterruptedException unused) {
|
|
return null;
|
|
}
|
|
} else {
|
|
AnonymousClass2 r3 = fontCallback == null ? null : new AnonymousClass2(fontCallback, handler);
|
|
synchronized (sLock) {
|
|
SimpleArrayMap<String, ArrayList<SelfDestructiveThread.ReplyCallback<TypefaceResult>>> simpleArrayMap = sPendingReplies;
|
|
ArrayList<SelfDestructiveThread.ReplyCallback<TypefaceResult>> arrayList = simpleArrayMap.get(str);
|
|
if (arrayList != null) {
|
|
if (r3 != null) {
|
|
arrayList.add(r3);
|
|
}
|
|
return null;
|
|
}
|
|
if (r3 != null) {
|
|
ArrayList<SelfDestructiveThread.ReplyCallback<TypefaceResult>> arrayList2 = new ArrayList<>();
|
|
arrayList2.add(r3);
|
|
simpleArrayMap.put(str, arrayList2);
|
|
}
|
|
sBackgroundThread.postAndReply(r1, new AnonymousClass3(str));
|
|
return null;
|
|
}
|
|
}
|
|
} else {
|
|
TypefaceResult fontInternal = getFontInternal(context, fontRequest, i2);
|
|
if (fontCallback != null) {
|
|
int i3 = fontInternal.mResult;
|
|
if (i3 == 0) {
|
|
fontCallback.callbackSuccessAsync(fontInternal.mTypeface, handler);
|
|
} else {
|
|
fontCallback.callbackFailAsync(i3, handler);
|
|
}
|
|
}
|
|
return fontInternal.mTypeface;
|
|
}
|
|
}
|
|
|
|
@VisibleForTesting
|
|
@Nullable
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
public static ProviderInfo getProvider(@NonNull PackageManager packageManager, @NonNull FontRequest fontRequest, @Nullable Resources resources) throws PackageManager.NameNotFoundException {
|
|
String providerAuthority = fontRequest.getProviderAuthority();
|
|
ProviderInfo resolveContentProvider = packageManager.resolveContentProvider(providerAuthority, 0);
|
|
if (resolveContentProvider == null) {
|
|
throw new PackageManager.NameNotFoundException(a.t("No package found for authority: ", providerAuthority));
|
|
} else if (resolveContentProvider.packageName.equals(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;
|
|
} else {
|
|
StringBuilder Q = a.Q("Found content provider ", providerAuthority, ", but package was not ");
|
|
Q.append(fontRequest.getProviderPackage());
|
|
throw new PackageManager.NameNotFoundException(Q.toString());
|
|
}
|
|
}
|
|
|
|
@RequiresApi(19)
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
public static Map<Uri, ByteBuffer> prepareFontData(Context context, FontInfo[] fontInfoArr, CancellationSignal cancellationSignal) {
|
|
HashMap hashMap = new HashMap();
|
|
for (FontInfo fontInfo : fontInfoArr) {
|
|
if (fontInfo.getResultCode() == 0) {
|
|
Uri uri = fontInfo.getUri();
|
|
if (!hashMap.containsKey(uri)) {
|
|
hashMap.put(uri, TypefaceCompatUtil.mmap(context, cancellationSignal, uri));
|
|
}
|
|
}
|
|
}
|
|
return Collections.unmodifiableMap(hashMap);
|
|
}
|
|
|
|
public static void requestFont(@NonNull Context context, @NonNull FontRequest fontRequest, @NonNull FontRequestCallback fontRequestCallback, @NonNull Handler handler) {
|
|
requestFontInternal(context.getApplicationContext(), fontRequest, fontRequestCallback, handler);
|
|
}
|
|
|
|
private static void requestFontInternal(@NonNull Context context, @NonNull FontRequest fontRequest, @NonNull FontRequestCallback fontRequestCallback, @NonNull Handler handler) {
|
|
handler.post(new AnonymousClass4(context, fontRequest, new Handler(), fontRequestCallback));
|
|
}
|
|
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
public static void resetCache() {
|
|
sTypefaceCache.evictAll();
|
|
}
|
|
}
|