Initial commit
This commit is contained in:
70
sources/androidx/core/provider/FontRequest.java
Normal file
70
sources/androidx/core/provider/FontRequest.java
Normal file
@@ -0,0 +1,70 @@
|
||||
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 String a;
|
||||
private final String b;
|
||||
private final String c;
|
||||
private final List<List<byte[]>> d;
|
||||
private final int e;
|
||||
private final String f;
|
||||
|
||||
public FontRequest(String str, String str2, String str3, List<List<byte[]>> list) {
|
||||
Preconditions.a(str);
|
||||
this.a = str;
|
||||
Preconditions.a(str2);
|
||||
this.b = str2;
|
||||
Preconditions.a(str3);
|
||||
this.c = str3;
|
||||
Preconditions.a(list);
|
||||
this.d = list;
|
||||
this.e = 0;
|
||||
this.f = this.a + "-" + this.b + "-" + this.c;
|
||||
}
|
||||
|
||||
public List<List<byte[]>> a() {
|
||||
return this.d;
|
||||
}
|
||||
|
||||
public int b() {
|
||||
return this.e;
|
||||
}
|
||||
|
||||
public String c() {
|
||||
return this.f;
|
||||
}
|
||||
|
||||
public String d() {
|
||||
return this.a;
|
||||
}
|
||||
|
||||
public String e() {
|
||||
return this.b;
|
||||
}
|
||||
|
||||
public String f() {
|
||||
return this.c;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("FontRequest {mProviderAuthority: " + this.a + ", mProviderPackage: " + this.b + ", mQuery: " + this.c + ", mCertificates:");
|
||||
for (int i = 0; i < this.d.size(); i++) {
|
||||
sb.append(" [");
|
||||
List<byte[]> list = this.d.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.e);
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
335
sources/androidx/core/provider/FontsContractCompat.java
Normal file
335
sources/androidx/core/provider/FontsContractCompat.java
Normal file
@@ -0,0 +1,335 @@
|
||||
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.Build;
|
||||
import android.os.CancellationSignal;
|
||||
import android.os.Handler;
|
||||
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 com.liulishuo.filedownloader.model.FileDownloadModel;
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
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;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class FontsContractCompat {
|
||||
static final LruCache<String, Typeface> a = new LruCache<>(16);
|
||||
private static final SelfDestructiveThread b = new SelfDestructiveThread("fonts", 10, XStream.PRIORITY_VERY_HIGH);
|
||||
static final Object c = new Object();
|
||||
static final SimpleArrayMap<String, ArrayList<SelfDestructiveThread.ReplyCallback<TypefaceResult>>> d = new SimpleArrayMap<>();
|
||||
private static final Comparator<byte[]> e = new Comparator<byte[]>() { // from class: androidx.core.provider.FontsContractCompat.5
|
||||
@Override // java.util.Comparator
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public int compare(byte[] bArr, byte[] bArr2) {
|
||||
int i;
|
||||
int i2;
|
||||
if (bArr.length == bArr2.length) {
|
||||
for (int i3 = 0; i3 < bArr.length; i3++) {
|
||||
if (bArr[i3] != bArr2[i3]) {
|
||||
i = bArr[i3];
|
||||
i2 = bArr2[i3];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
i = bArr.length;
|
||||
i2 = bArr2.length;
|
||||
return i - i2;
|
||||
}
|
||||
};
|
||||
|
||||
public static class FontFamilyResult {
|
||||
private final int a;
|
||||
private final FontInfo[] b;
|
||||
|
||||
public FontFamilyResult(int i, FontInfo[] fontInfoArr) {
|
||||
this.a = i;
|
||||
this.b = fontInfoArr;
|
||||
}
|
||||
|
||||
public FontInfo[] a() {
|
||||
return this.b;
|
||||
}
|
||||
|
||||
public int b() {
|
||||
return this.a;
|
||||
}
|
||||
}
|
||||
|
||||
public static class FontInfo {
|
||||
private final Uri a;
|
||||
private final int b;
|
||||
private final int c;
|
||||
private final boolean d;
|
||||
private final int e;
|
||||
|
||||
public FontInfo(Uri uri, int i, int i2, boolean z, int i3) {
|
||||
Preconditions.a(uri);
|
||||
this.a = uri;
|
||||
this.b = i;
|
||||
this.c = i2;
|
||||
this.d = z;
|
||||
this.e = i3;
|
||||
}
|
||||
|
||||
public int a() {
|
||||
return this.e;
|
||||
}
|
||||
|
||||
public int b() {
|
||||
return this.b;
|
||||
}
|
||||
|
||||
public Uri c() {
|
||||
return this.a;
|
||||
}
|
||||
|
||||
public int d() {
|
||||
return this.c;
|
||||
}
|
||||
|
||||
public boolean e() {
|
||||
return this.d;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class TypefaceResult {
|
||||
final Typeface a;
|
||||
final int b;
|
||||
|
||||
TypefaceResult(Typeface typeface, int i) {
|
||||
this.a = typeface;
|
||||
this.b = i;
|
||||
}
|
||||
}
|
||||
|
||||
static TypefaceResult a(Context context, FontRequest fontRequest, int i) {
|
||||
try {
|
||||
FontFamilyResult a2 = a(context, (CancellationSignal) null, fontRequest);
|
||||
if (a2.b() != 0) {
|
||||
return new TypefaceResult(null, a2.b() == 1 ? -2 : -3);
|
||||
}
|
||||
Typeface a3 = TypefaceCompat.a(context, null, a2.a(), i);
|
||||
return new TypefaceResult(a3, a3 != null ? 0 : -3);
|
||||
} catch (PackageManager.NameNotFoundException unused) {
|
||||
return new TypefaceResult(null, -1);
|
||||
}
|
||||
}
|
||||
|
||||
public static Typeface a(final Context context, final FontRequest fontRequest, final ResourcesCompat.FontCallback fontCallback, final Handler handler, boolean z, int i, final int i2) {
|
||||
final String str = fontRequest.c() + "-" + i2;
|
||||
Typeface b2 = a.b(str);
|
||||
if (b2 != null) {
|
||||
if (fontCallback != null) {
|
||||
fontCallback.a(b2);
|
||||
}
|
||||
return b2;
|
||||
}
|
||||
if (z && i == -1) {
|
||||
TypefaceResult a2 = a(context, fontRequest, i2);
|
||||
if (fontCallback != null) {
|
||||
int i3 = a2.b;
|
||||
if (i3 == 0) {
|
||||
fontCallback.a(a2.a, handler);
|
||||
} else {
|
||||
fontCallback.a(i3, handler);
|
||||
}
|
||||
}
|
||||
return a2.a;
|
||||
}
|
||||
Callable<TypefaceResult> callable = new Callable<TypefaceResult>() { // from class: androidx.core.provider.FontsContractCompat.1
|
||||
/* JADX WARN: Can't rename method to resolve collision */
|
||||
@Override // java.util.concurrent.Callable
|
||||
public TypefaceResult call() throws Exception {
|
||||
TypefaceResult a3 = FontsContractCompat.a(context, fontRequest, i2);
|
||||
Typeface typeface = a3.a;
|
||||
if (typeface != null) {
|
||||
FontsContractCompat.a.a(str, typeface);
|
||||
}
|
||||
return a3;
|
||||
}
|
||||
};
|
||||
if (z) {
|
||||
try {
|
||||
return ((TypefaceResult) b.a(callable, i)).a;
|
||||
} catch (InterruptedException unused) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
SelfDestructiveThread.ReplyCallback<TypefaceResult> replyCallback = fontCallback == null ? null : new SelfDestructiveThread.ReplyCallback<TypefaceResult>() { // from class: androidx.core.provider.FontsContractCompat.2
|
||||
@Override // androidx.core.provider.SelfDestructiveThread.ReplyCallback
|
||||
public void a(TypefaceResult typefaceResult) {
|
||||
if (typefaceResult == null) {
|
||||
ResourcesCompat.FontCallback.this.a(1, handler);
|
||||
return;
|
||||
}
|
||||
int i4 = typefaceResult.b;
|
||||
if (i4 == 0) {
|
||||
ResourcesCompat.FontCallback.this.a(typefaceResult.a, handler);
|
||||
} else {
|
||||
ResourcesCompat.FontCallback.this.a(i4, handler);
|
||||
}
|
||||
}
|
||||
};
|
||||
synchronized (c) {
|
||||
if (d.containsKey(str)) {
|
||||
if (replyCallback != null) {
|
||||
d.get(str).add(replyCallback);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (replyCallback != null) {
|
||||
ArrayList<SelfDestructiveThread.ReplyCallback<TypefaceResult>> arrayList = new ArrayList<>();
|
||||
arrayList.add(replyCallback);
|
||||
d.put(str, arrayList);
|
||||
}
|
||||
b.a(callable, new SelfDestructiveThread.ReplyCallback<TypefaceResult>() { // from class: androidx.core.provider.FontsContractCompat.3
|
||||
@Override // androidx.core.provider.SelfDestructiveThread.ReplyCallback
|
||||
public void a(TypefaceResult typefaceResult) {
|
||||
synchronized (FontsContractCompat.c) {
|
||||
ArrayList<SelfDestructiveThread.ReplyCallback<TypefaceResult>> arrayList2 = FontsContractCompat.d.get(str);
|
||||
if (arrayList2 == null) {
|
||||
return;
|
||||
}
|
||||
FontsContractCompat.d.remove(str);
|
||||
for (int i4 = 0; i4 < arrayList2.size(); i4++) {
|
||||
arrayList2.get(i4).a(typefaceResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<Uri, ByteBuffer> a(Context context, FontInfo[] fontInfoArr, CancellationSignal cancellationSignal) {
|
||||
HashMap hashMap = new HashMap();
|
||||
for (FontInfo fontInfo : fontInfoArr) {
|
||||
if (fontInfo.a() == 0) {
|
||||
Uri c2 = fontInfo.c();
|
||||
if (!hashMap.containsKey(c2)) {
|
||||
hashMap.put(c2, TypefaceCompatUtil.a(context, cancellationSignal, c2));
|
||||
}
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableMap(hashMap);
|
||||
}
|
||||
|
||||
public static FontFamilyResult a(Context context, CancellationSignal cancellationSignal, FontRequest fontRequest) throws PackageManager.NameNotFoundException {
|
||||
ProviderInfo a2 = a(context.getPackageManager(), fontRequest, context.getResources());
|
||||
if (a2 == null) {
|
||||
return new FontFamilyResult(1, null);
|
||||
}
|
||||
return new FontFamilyResult(0, a(context, fontRequest, a2.authority, cancellationSignal));
|
||||
}
|
||||
|
||||
public static ProviderInfo a(PackageManager packageManager, FontRequest fontRequest, Resources resources) throws PackageManager.NameNotFoundException {
|
||||
String d2 = fontRequest.d();
|
||||
ProviderInfo resolveContentProvider = packageManager.resolveContentProvider(d2, 0);
|
||||
if (resolveContentProvider != null) {
|
||||
if (resolveContentProvider.packageName.equals(fontRequest.e())) {
|
||||
List<byte[]> a2 = a(packageManager.getPackageInfo(resolveContentProvider.packageName, 64).signatures);
|
||||
Collections.sort(a2, e);
|
||||
List<List<byte[]>> a3 = a(fontRequest, resources);
|
||||
for (int i = 0; i < a3.size(); i++) {
|
||||
ArrayList arrayList = new ArrayList(a3.get(i));
|
||||
Collections.sort(arrayList, e);
|
||||
if (a(a2, arrayList)) {
|
||||
return resolveContentProvider;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
throw new PackageManager.NameNotFoundException("Found content provider " + d2 + ", but package was not " + fontRequest.e());
|
||||
}
|
||||
throw new PackageManager.NameNotFoundException("No package found for authority: " + d2);
|
||||
}
|
||||
|
||||
private static List<List<byte[]>> a(FontRequest fontRequest, Resources resources) {
|
||||
if (fontRequest.a() != null) {
|
||||
return fontRequest.a();
|
||||
}
|
||||
return FontResourcesParserCompat.a(resources, fontRequest.b());
|
||||
}
|
||||
|
||||
private static boolean a(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[]> a(Signature[] signatureArr) {
|
||||
ArrayList arrayList = new ArrayList();
|
||||
for (Signature signature : signatureArr) {
|
||||
arrayList.add(signature.toByteArray());
|
||||
}
|
||||
return arrayList;
|
||||
}
|
||||
|
||||
static FontInfo[] a(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 {
|
||||
if (Build.VERSION.SDK_INT > 16) {
|
||||
cursor = context.getContentResolver().query(build, new String[]{FileDownloadModel.ID, "file_id", "font_ttc_index", "font_variation_settings", "font_weight", "font_italic", "result_code"}, "query = ?", new String[]{fontRequest.f()}, null, cancellationSignal);
|
||||
} else {
|
||||
cursor = context.getContentResolver().query(build, new String[]{FileDownloadModel.ID, "file_id", "font_ttc_index", "font_variation_settings", "font_weight", "font_italic", "result_code"}, "query = ?", new String[]{fontRequest.f()}, null);
|
||||
}
|
||||
if (cursor != null && cursor.getCount() > 0) {
|
||||
int columnIndex = cursor.getColumnIndex("result_code");
|
||||
ArrayList arrayList2 = new ArrayList();
|
||||
int columnIndex2 = cursor.getColumnIndex(FileDownloadModel.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));
|
||||
}
|
||||
arrayList2.add(new FontInfo(withAppendedId, i2, 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
142
sources/androidx/core/provider/SelfDestructiveThread.java
Normal file
142
sources/androidx/core/provider/SelfDestructiveThread.java
Normal file
@@ -0,0 +1,142 @@
|
||||
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;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class SelfDestructiveThread {
|
||||
private HandlerThread b;
|
||||
private Handler c;
|
||||
private final int f;
|
||||
private final int g;
|
||||
private final String h;
|
||||
private final Object a = new Object();
|
||||
private Handler.Callback e = 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.a();
|
||||
return true;
|
||||
}
|
||||
if (i != 1) {
|
||||
return true;
|
||||
}
|
||||
SelfDestructiveThread.this.a((Runnable) message.obj);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
private int d = 0;
|
||||
|
||||
public interface ReplyCallback<T> {
|
||||
void a(T t);
|
||||
}
|
||||
|
||||
public SelfDestructiveThread(String str, int i, int i2) {
|
||||
this.h = str;
|
||||
this.g = i;
|
||||
this.f = i2;
|
||||
}
|
||||
|
||||
private void b(Runnable runnable) {
|
||||
synchronized (this.a) {
|
||||
if (this.b == null) {
|
||||
this.b = new HandlerThread(this.h, this.g);
|
||||
this.b.start();
|
||||
this.c = new Handler(this.b.getLooper(), this.e);
|
||||
this.d++;
|
||||
}
|
||||
this.c.removeMessages(0);
|
||||
this.c.sendMessage(this.c.obtainMessage(1, runnable));
|
||||
}
|
||||
}
|
||||
|
||||
public <T> void a(final Callable<T> callable, final ReplyCallback<T> replyCallback) {
|
||||
final Handler handler = new Handler();
|
||||
b(new Runnable(this) { // 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;
|
||||
}
|
||||
handler.post(new Runnable() { // from class: androidx.core.provider.SelfDestructiveThread.2.1
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
replyCallback.a(obj);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public <T> T a(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);
|
||||
b(new Runnable(this) { // 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 a(Runnable runnable) {
|
||||
runnable.run();
|
||||
synchronized (this.a) {
|
||||
this.c.removeMessages(0);
|
||||
this.c.sendMessageDelayed(this.c.obtainMessage(0), this.f);
|
||||
}
|
||||
}
|
||||
|
||||
void a() {
|
||||
synchronized (this.a) {
|
||||
if (this.c.hasMessages(1)) {
|
||||
return;
|
||||
}
|
||||
this.b.quit();
|
||||
this.b = null;
|
||||
this.c = null;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user