Merge branch 'heads/android-14.0.0_r18' into 14-dev

This commit is contained in:
MrSluffy
2023-12-14 15:26:43 +08:00
parent 32700b0100
commit cc8f9828ab
756 changed files with 23785 additions and 12235 deletions
@@ -50,8 +50,8 @@ public class MainThreadInitializedObject<T> {
}
public T get(Context context) {
if (context instanceof SandboxContext) {
return ((SandboxContext) context).getObject(this, mProvider);
if (context instanceof SandboxContext sc) {
return sc.getObject(this);
}
if (mValue == null) {
@@ -62,7 +62,7 @@ public class MainThreadInitializedObject<T> {
} else {
try {
return MAIN_EXECUTOR.submit(() -> get(context)).get();
} catch (InterruptedException|ExecutionException e) {
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
@@ -70,7 +70,8 @@ public class MainThreadInitializedObject<T> {
return mValue;
}
protected void onPostInit(Context context) { }
protected void onPostInit(Context context) {
}
public T getNoCreate() {
return mValue;
@@ -133,26 +134,26 @@ public class MainThreadInitializedObject<T> {
}
/**
* Find a cached object from mObjectMap if we have already created one. If not, generate
* Find a cached object from mObjectMap if we have already created one. If not,
* generate
* an object using the provider.
*/
private <T> T getObject(MainThreadInitializedObject<T> object, ObjectProvider<T> provider) {
protected <T> T getObject(MainThreadInitializedObject<T> object) {
synchronized (mDestroyLock) {
if (mDestroyed) {
Log.e(TAG, "Static object access with a destroyed context");
}
T t = (T) mObjectMap.get(object);
if (t != null) {
return t;
}
if (Looper.myLooper() == Looper.getMainLooper()) {
t = createObject(provider);
t = createObject(object);
// Check if we've explicitly allowed the object or if it's a SafeCloseable,
// it will get destroyed in onDestroy()
if (!mAllowedObjects.contains(object) && !(t instanceof SafeCloseable)) {
throw new IllegalStateException(
"Leaking unknown objects " + object + " " + provider + " " + t);
throw new IllegalStateException("Leaking unknown objects "
+ object + " " + object.mProvider + " " + t);
}
mObjectMap.put(object, t);
mOrderedObjects.add(t);
@@ -161,15 +162,15 @@ public class MainThreadInitializedObject<T> {
}
try {
return MAIN_EXECUTOR.submit(() -> getObject(object, provider)).get();
return MAIN_EXECUTOR.submit(() -> getObject(object)).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
@UiThread
protected <T> T createObject(ObjectProvider<T> provider) {
return provider.get(this);
protected <T> T createObject(MainThreadInitializedObject<T> object) {
return object.mProvider.get(this);
}
}
}