diff options
author | 2024-12-17 15:31:06 -0800 | |
---|---|---|
committer | 2024-12-18 10:38:00 -0800 | |
commit | 60bad051c431a19f9be843317c272a44202ce679 (patch) | |
tree | d1572b465c32fea0569abef7726be6e8115fac7c | |
parent | 1bcaab81e3b7690d493455d94e4873635cf79f28 (diff) |
Fixing module inheritence when overriding Launcher component
Bug: 361850561
Flag: EXEMPT dagger migration
Test: Presubmit
Change-Id: I1f726e9895f6872d0294a11ab0c52c6c619c2a3f
10 files changed, 82 insertions, 38 deletions
diff --git a/quickstep/dagger/LauncherAppComponent.java b/quickstep/dagger/com/android/launcher3/dagger/LauncherAppComponent.java index 068f01cc5c..a4cb42037f 100644 --- a/quickstep/dagger/LauncherAppComponent.java +++ b/quickstep/dagger/com/android/launcher3/dagger/LauncherAppComponent.java @@ -17,7 +17,6 @@ package com.android.launcher3.dagger; -import com.android.quickstep.dagger.QuickStepModule; import com.android.quickstep.dagger.QuickstepBaseAppComponent; import dagger.Component; @@ -26,7 +25,7 @@ import dagger.Component; * Root component for Dagger injection for Launcher Quickstep. */ @LauncherAppSingleton -@Component(modules = QuickStepModule.class) +@Component(modules = LauncherAppModule.class) public interface LauncherAppComponent extends QuickstepBaseAppComponent { /** Builder for quickstep LauncherAppComponent. */ @Component.Builder diff --git a/quickstep/dagger/com/android/launcher3/dagger/LauncherAppModule.java b/quickstep/dagger/com/android/launcher3/dagger/LauncherAppModule.java new file mode 100644 index 0000000000..1711fc13e5 --- /dev/null +++ b/quickstep/dagger/com/android/launcher3/dagger/LauncherAppModule.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3.dagger; + +import com.android.quickstep.dagger.QuickStepModule; + +import dagger.Module; + +@Module(includes = QuickStepModule.class) +public class LauncherAppModule {} diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarWindowSandboxContext.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarWindowSandboxContext.kt index 8c512160f6..0b94dfd92e 100644 --- a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarWindowSandboxContext.kt +++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarWindowSandboxContext.kt @@ -25,6 +25,7 @@ import androidx.test.core.app.ApplicationProvider import com.android.launcher3.FakeLauncherPrefs import com.android.launcher3.LauncherPrefs import com.android.launcher3.dagger.LauncherAppComponent +import com.android.launcher3.dagger.LauncherAppModule import com.android.launcher3.dagger.LauncherAppSingleton import com.android.launcher3.util.MainThreadInitializedObject.ObjectSandbox import com.android.launcher3.util.SandboxApplication @@ -116,7 +117,7 @@ private constructor( } @LauncherAppSingleton -@Component +@Component(modules = [LauncherAppModule::class]) interface TaskbarSandboxComponent : LauncherAppComponent { @Component.Builder interface Builder : LauncherAppComponent.Builder { diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/LauncherSwipeHandlerV2Test.kt b/quickstep/tests/multivalentTests/src/com/android/quickstep/LauncherSwipeHandlerV2Test.kt index 37accdbabe..5fce9a8eaf 100644 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/LauncherSwipeHandlerV2Test.kt +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/LauncherSwipeHandlerV2Test.kt @@ -23,10 +23,10 @@ import androidx.test.platform.app.InstrumentationRegistry import com.android.launcher3.Flags.enableLauncherOverviewInWindow import com.android.launcher3.R import com.android.launcher3.dagger.LauncherAppComponent +import com.android.launcher3.dagger.LauncherAppModule import com.android.launcher3.dagger.LauncherAppSingleton import com.android.launcher3.util.LauncherModelHelper import com.android.launcher3.util.MSDLPlayerWrapper -import com.android.quickstep.dagger.QuickStepModule import com.android.quickstep.fallback.window.RecentsWindowFactory import com.android.systemui.contextualeducation.GestureType import com.android.systemui.shared.system.InputConsumerController @@ -123,7 +123,7 @@ class LauncherSwipeHandlerV2Test { } @LauncherAppSingleton -@Component(modules = [QuickStepModule::class]) +@Component(modules = [LauncherAppModule::class]) interface TestComponent : LauncherAppComponent { @Component.Builder interface Builder : LauncherAppComponent.Builder { diff --git a/src_no_quickstep/com/android/launcher3/dagger/LauncherAppComponent.java b/src_no_quickstep/com/android/launcher3/dagger/LauncherAppComponent.java index 63d87e8684..f4f5a0858f 100644 --- a/src_no_quickstep/com/android/launcher3/dagger/LauncherAppComponent.java +++ b/src_no_quickstep/com/android/launcher3/dagger/LauncherAppComponent.java @@ -22,7 +22,7 @@ import dagger.Component; * Root component for Dagger injection for Launcher AOSP. */ @LauncherAppSingleton -@Component +@Component(modules = LauncherAppModule.class) public interface LauncherAppComponent extends LauncherBaseAppComponent { /** Builder for aosp LauncherAppComponent. */ @Component.Builder diff --git a/src_no_quickstep/com/android/launcher3/dagger/LauncherAppModule.java b/src_no_quickstep/com/android/launcher3/dagger/LauncherAppModule.java new file mode 100644 index 0000000000..f7b8489f62 --- /dev/null +++ b/src_no_quickstep/com/android/launcher3/dagger/LauncherAppModule.java @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3.dagger; + +import dagger.Module; + +@Module +public class LauncherAppModule { } diff --git a/tests/multivalentTests/src/com/android/launcher3/AbstractDeviceProfileTest.kt b/tests/multivalentTests/src/com/android/launcher3/AbstractDeviceProfileTest.kt index c80093a09e..8598917a06 100644 --- a/tests/multivalentTests/src/com/android/launcher3/AbstractDeviceProfileTest.kt +++ b/tests/multivalentTests/src/com/android/launcher3/AbstractDeviceProfileTest.kt @@ -29,6 +29,7 @@ import android.view.Surface import androidx.test.core.app.ApplicationProvider.getApplicationContext import androidx.test.platform.app.InstrumentationRegistry import com.android.launcher3.dagger.LauncherAppComponent +import com.android.launcher3.dagger.LauncherAppModule import com.android.launcher3.dagger.LauncherAppSingleton import com.android.launcher3.testing.shared.ResourceUtils import com.android.launcher3.util.DisplayController @@ -68,7 +69,7 @@ abstract class AbstractDeviceProfileTest { protected lateinit var context: SandboxContext protected open val runningContext: Context = getApplicationContext() private val displayController: DisplayController = mock() - private val windowManagerProxy: WindowManagerProxy = mock() + private val windowManagerProxy: MyWmProxy = mock() private val launcherPrefs: LauncherPrefs = mock() @get:Rule val setFlagsRule = SetFlagsRule(SetFlagsRule.DefaultInitValueType.DEVICE_DEFAULT) @@ -362,12 +363,17 @@ abstract class AbstractDeviceProfileTest { } } +class MyWmProxy : WindowManagerProxy() + @LauncherAppSingleton -@Component +@Component(modules = [LauncherAppModule::class]) interface AbsDPTestSandboxComponent : LauncherAppComponent { + + override fun getWmProxy(): MyWmProxy + @Component.Builder interface Builder : LauncherAppComponent.Builder { - @BindsInstance fun bindWMProxy(proxy: WindowManagerProxy): Builder + @BindsInstance fun bindWMProxy(proxy: MyWmProxy): Builder override fun build(): AbsDPTestSandboxComponent } diff --git a/tests/multivalentTests/src/com/android/launcher3/AutoInstallsLayoutTest.kt b/tests/multivalentTests/src/com/android/launcher3/AutoInstallsLayoutTest.kt index f73a9d39f4..fcbb94be9c 100644 --- a/tests/multivalentTests/src/com/android/launcher3/AutoInstallsLayoutTest.kt +++ b/tests/multivalentTests/src/com/android/launcher3/AutoInstallsLayoutTest.kt @@ -42,6 +42,7 @@ import com.android.launcher3.LauncherSettings.Favorites.SPANX import com.android.launcher3.LauncherSettings.Favorites.SPANY import com.android.launcher3.LauncherSettings.Favorites._ID import com.android.launcher3.dagger.LauncherAppComponent +import com.android.launcher3.dagger.LauncherAppModule import com.android.launcher3.dagger.LauncherAppSingleton import com.android.launcher3.model.data.AppInfo import com.android.launcher3.pm.UserCache @@ -66,7 +67,7 @@ import org.junit.runner.RunWith import org.mockito.Mock import org.mockito.MockitoAnnotations import org.mockito.kotlin.doReturn -import org.mockito.kotlin.spy +import org.mockito.kotlin.mock import org.mockito.kotlin.whenever /** Tests for [AutoInstallsLayout] */ @@ -165,7 +166,9 @@ class AutoInstallsLayoutTest { @Test fun work_item_added_to_home() { - val apiWrapperMock = spy(ApiWrapper.INSTANCE[targetContext]) + val original = ApiWrapper.INSTANCE[targetContext] + val apiWrapperMock = + mock<MyApiWrapper>(defaultAnswer = { it.method.invoke(original, *it.arguments) }) targetContext.initDaggerComponent( DaggerAutoInstallsLayoutTestComponent.builder().bindApiWrapper(apiWrapperMock) ) @@ -221,12 +224,17 @@ class AutoInstallsLayoutTest { } } +class MyApiWrapper : ApiWrapper(null) {} + @LauncherAppSingleton -@Component +@Component(modules = [LauncherAppModule::class]) interface AutoInstallsLayoutTestComponent : LauncherAppComponent { + + override fun getApiWrapper(): MyApiWrapper + @Component.Builder interface Builder : LauncherAppComponent.Builder { - @BindsInstance fun bindApiWrapper(wrapper: ApiWrapper): Builder + @BindsInstance fun bindApiWrapper(wrapper: MyApiWrapper): Builder override fun build(): AutoInstallsLayoutTestComponent } diff --git a/tests/multivalentTests/src/com/android/launcher3/util/DisplayControllerTest.kt b/tests/multivalentTests/src/com/android/launcher3/util/DisplayControllerTest.kt index 32df84c457..d0cf6107e5 100644 --- a/tests/multivalentTests/src/com/android/launcher3/util/DisplayControllerTest.kt +++ b/tests/multivalentTests/src/com/android/launcher3/util/DisplayControllerTest.kt @@ -30,6 +30,7 @@ import com.android.launcher3.LauncherPrefs import com.android.launcher3.LauncherPrefs.Companion.TASKBAR_PINNING import com.android.launcher3.LauncherPrefs.Companion.TASKBAR_PINNING_IN_DESKTOP_MODE import com.android.launcher3.dagger.LauncherAppComponent +import com.android.launcher3.dagger.LauncherAppModule import com.android.launcher3.dagger.LauncherAppSingleton import com.android.launcher3.util.DisplayController.CHANGE_DENSITY import com.android.launcher3.util.DisplayController.CHANGE_ROTATION @@ -64,7 +65,7 @@ import org.mockito.stubbing.Answer class DisplayControllerTest { private val context = spy(SandboxModelContext()) - private val windowManagerProxy: WindowManagerProxy = mock() + private val windowManagerProxy: MyWmProxy = mock() private val launcherPrefs: LauncherPrefs = mock() private lateinit var displayManager: DisplayManager private val display: Display = mock() @@ -230,12 +231,17 @@ class DisplayControllerTest { } } +class MyWmProxy : WindowManagerProxy() + @LauncherAppSingleton -@Component +@Component(modules = [LauncherAppModule::class]) interface DisplayControllerTestComponent : LauncherAppComponent { + + override fun getWmProxy(): MyWmProxy + @Component.Builder interface Builder : LauncherAppComponent.Builder { - @BindsInstance fun bindWMProxy(proxy: WindowManagerProxy): Builder + @BindsInstance fun bindWMProxy(proxy: MyWmProxy): Builder override fun build(): DisplayControllerTestComponent } diff --git a/tests/src/com/android/launcher3/popup/SystemShortcutTest.java b/tests/src/com/android/launcher3/popup/SystemShortcutTest.java index ae54e95209..075f6677c7 100644 --- a/tests/src/com/android/launcher3/popup/SystemShortcutTest.java +++ b/tests/src/com/android/launcher3/popup/SystemShortcutTest.java @@ -62,15 +62,12 @@ import androidx.test.platform.app.InstrumentationRegistry; import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.R; import com.android.launcher3.allapps.PrivateProfileManager; -import com.android.launcher3.dagger.LauncherAppComponent; -import com.android.launcher3.dagger.LauncherAppSingleton; import com.android.launcher3.logging.StatsLogManager; import com.android.launcher3.logging.StatsLogManager.StatsLogger; import com.android.launcher3.model.data.AppInfo; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.model.data.WorkspaceItemInfo; import com.android.launcher3.pm.UserCache; -import com.android.launcher3.util.ApiWrapper; import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.LauncherModelHelper.SandboxModelContext; import com.android.launcher3.util.LauncherMultivalentJUnit; @@ -81,9 +78,6 @@ import com.android.launcher3.views.Snackbar; import com.android.launcher3.widget.picker.model.WidgetPickerDataProvider; import com.android.launcher3.widget.picker.model.data.WidgetPickerData; -import dagger.BindsInstance; -import dagger.Component; - import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -109,7 +103,6 @@ public class SystemShortcutTest { private AppInfo mAppInfo; @Mock UserCache mUserCache; - @Mock ApiWrapper mApiWrapper; @Mock UserIconInfo mUserIconInfo; @Mock LauncherActivityInfo mLauncherActivityInfo; @Mock ApplicationInfo mApplicationInfo; @@ -120,9 +113,6 @@ public class SystemShortcutTest { @Before public void setUp() { MockitoAnnotations.initMocks(this); - mSandboxContext.initDaggerComponent( - DaggerSystemShortcutTest_TestComponent.builder().bindApiWrapper( - ApiWrapper.INSTANCE.get(mSandboxContext))); mSandboxContext.putObject(UserCache.INSTANCE, mUserCache); mTestContext = new TestSandboxModelContextWrapper(mSandboxContext) { @Override @@ -412,16 +402,4 @@ public class SystemShortcutTest { systemShortcut.onClick(mView); verify(mSandboxContext).startActivity(any()); } - - @LauncherAppSingleton - @Component - interface TestComponent extends LauncherAppComponent { - @Component.Builder - interface Builder extends LauncherAppComponent.Builder { - @BindsInstance Builder bindApiWrapper(ApiWrapper wrapper); - - @Override - TestComponent build(); - } - } } |