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:
+5
-3
@@ -34,6 +34,7 @@ import com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_NAVI
|
||||
import com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_NOTIFICATION_DOT_ENABLED
|
||||
import com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_THEMED_ICON_DISABLED
|
||||
import com.android.launcher3.states.RotationHelper.ALLOW_ROTATION_PREFERENCE_KEY
|
||||
import com.android.launcher3.util.DaggerSingletonTracker
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
@@ -62,6 +63,7 @@ class SettingsChangeLoggerTest {
|
||||
@Mock private lateinit var mMockLogger: StatsLogManager.StatsLogger
|
||||
|
||||
@Captor private lateinit var mEventCaptor: ArgumentCaptor<StatsLogManager.EventEnum>
|
||||
@Mock private lateinit var mTracker: DaggerSingletonTracker
|
||||
|
||||
private var mDefaultThemedIcons = false
|
||||
private var mDefaultAllowRotation = false
|
||||
@@ -79,7 +81,7 @@ class SettingsChangeLoggerTest {
|
||||
// To match the default value of ALLOW_ROTATION
|
||||
LauncherPrefs.get(mContext).put(item = ALLOW_ROTATION, value = false)
|
||||
|
||||
mSystemUnderTest = SettingsChangeLogger(mContext, mStatsLogManager)
|
||||
mSystemUnderTest = SettingsChangeLogger(mContext, mStatsLogManager, mTracker)
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -90,7 +92,7 @@ class SettingsChangeLoggerTest {
|
||||
|
||||
@Test
|
||||
fun loggingPrefs_correctDefaultValue() {
|
||||
val systemUnderTest = SettingsChangeLogger(mContext, mStatsLogManager)
|
||||
val systemUnderTest = SettingsChangeLogger(mContext, mStatsLogManager, mTracker)
|
||||
|
||||
assertThat(systemUnderTest.loggingPrefs[ALLOW_ROTATION_PREFERENCE_KEY]!!.defaultValue)
|
||||
.isFalse()
|
||||
@@ -117,7 +119,7 @@ class SettingsChangeLoggerTest {
|
||||
LauncherPrefs.get(mContext).put(item = ALLOW_ROTATION, value = true)
|
||||
|
||||
// This a new object so the values of mLoggablePrefs will be different
|
||||
SettingsChangeLogger(mContext, mStatsLogManager).logSnapshot(mInstanceId)
|
||||
SettingsChangeLogger(mContext, mStatsLogManager, mTracker).logSnapshot(mInstanceId)
|
||||
|
||||
verify(mMockLogger, atLeastOnce()).log(mEventCaptor.capture())
|
||||
val capturedEvents = mEventCaptor.allValues
|
||||
|
||||
Reference in New Issue
Block a user