Make sandboxContext extend LauncherApplication (4/n)
See https://docs.google.com/drawings/d/1JHFi_nhmQt2xPT1N3FB_1mnaRK5TVqKZ9-fSl3EA7sU/edit?usp=sharing and https://docs.google.com/drawings/d/1bx4WURP4uHZGzZ1bWQgpw701jkTkVqlNfA02Yt-ZtSI/edit?usp=sharing&resourcekey=0-oySjsnaCsOSrNIPqqEa0gw for design details. We need to make SandboxContext extend LauncherApplication because we want create MainThreadInitializedObjects in SandboxContext's AppComponent scope. Since MainThreadInitiliazedObjects are closed in SandboxContext's OnDestroy() , we need to replicate same thing using dagger as well. - DaggerSingletonObject is same as MainThreadInitializedObject but is used for fetching the dagger created singletons so that we can avoid major refactors for accessing singletons. This will be deleted soon. - DaggerSingletonTracker to track dagger created singletons and call close() on those singleton objects created in SandboxContext scope. - Annotate the singleton object SettingsChangeLogger constructor with @Inject and execute the statements in Main thread. - Added createSandboxContextForTest(only for Test) to avoid creation of dagger component in test. As follow up, I will delete this method and introduce fakeDaggerComponents in test. Bug: 361850561 Test: Manual Flag: NONE Dagger Integration Change-Id: I2d3762ea64e53baa4de190790568aec750b54201
This commit is contained in:
@@ -18,13 +18,13 @@ package com.android.launcher3.util;
|
||||
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.UiThread;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.launcher3.LauncherApplication;
|
||||
import com.android.launcher3.util.ResourceBasedOverride.Overrides;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -118,7 +118,7 @@ public class MainThreadInitializedObject<T extends SafeCloseable> {
|
||||
* Abstract Context which allows custom implementations for
|
||||
* {@link MainThreadInitializedObject} providers
|
||||
*/
|
||||
public static class SandboxContext extends ContextWrapper implements SandboxApplication {
|
||||
public static class SandboxContext extends LauncherApplication implements SandboxApplication {
|
||||
|
||||
private static final String TAG = "SandboxContext";
|
||||
|
||||
@@ -129,7 +129,8 @@ public class MainThreadInitializedObject<T extends SafeCloseable> {
|
||||
private boolean mDestroyed = false;
|
||||
|
||||
public SandboxContext(Context base) {
|
||||
super(base);
|
||||
attachBaseContext(base);
|
||||
initDagger();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -138,6 +139,7 @@ public class MainThreadInitializedObject<T extends SafeCloseable> {
|
||||
}
|
||||
|
||||
public void onDestroy() {
|
||||
getAppComponent().getDaggerSingletonTracker().close();
|
||||
synchronized (mDestroyLock) {
|
||||
// Destroy in reverse order
|
||||
for (int i = mOrderedObjects.size() - 1; i >= 0; i--) {
|
||||
|
||||
Reference in New Issue
Block a user