Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 189647c4 authored by Dave Mankoff's avatar Dave Mankoff
Browse files

Revert "Revert "Revert "Revert "Replace field injection with con..."

Revert submission 3342809-revert-3340780-revert-3344343-revert-3343291-k2-upgrade-wpp-KWLCODKLEN-OROSEWLQYI-UXWYBKSHRY

Reason for revert: One more try

Reverted changes: /q/submissionid:3342809-revert-3340780-revert-3344343-revert-3343291-k2-upgrade-wpp-KWLCODKLEN-OROSEWLQYI-UXWYBKSHRY

Change-Id: Icd8c22f4791dd5ff2f15e43cdd0c0dfa879bd983
Merged-In: I718113e103da303ddfb102b73c95f9a9b25da132
Merged-In: I563eb2e6b10c98f9f60c9680e5f50ff0541ad7eb
parent 40a871f4
Loading
Loading
Loading
Loading
+58 −52
Original line number Diff line number Diff line
@@ -70,8 +70,14 @@ import com.android.systemui.shared.notifications.domain.interactor.NotificationS
import com.android.wallpaper.config.BaseFlags
import com.android.wallpaper.module.CustomizationSections
import com.android.wallpaper.module.FragmentFactory
import com.android.wallpaper.module.NetworkStatusNotifier
import com.android.wallpaper.module.PartnerProvider
import com.android.wallpaper.module.WallpaperPicker2Injector
import com.android.wallpaper.module.WallpaperPreferences
import com.android.wallpaper.module.logging.UserEventLogger
import com.android.wallpaper.network.Requester
import com.android.wallpaper.picker.CustomizationPickerActivity
import com.android.wallpaper.picker.customization.data.content.WallpaperClient
import com.android.wallpaper.picker.customization.data.content.WallpaperClientImpl
import com.android.wallpaper.picker.customization.data.repository.WallpaperColorsRepository
import com.android.wallpaper.picker.customization.data.repository.WallpaperRepository
@@ -79,6 +85,8 @@ import com.android.wallpaper.picker.customization.domain.interactor.WallpaperInt
import com.android.wallpaper.picker.di.modules.BackgroundDispatcher
import com.android.wallpaper.picker.di.modules.MainDispatcher
import com.android.wallpaper.picker.undo.domain.interactor.SnapshotRestorer
import com.android.wallpaper.system.UiModeManagerWrapper
import com.android.wallpaper.util.DisplayUtils
import com.android.wallpaper.util.ScreenSizeCalculator
import dagger.Lazy
import javax.inject.Inject
@@ -94,7 +102,32 @@ constructor(
    @MainDispatcher private val mainDispatcher: CoroutineDispatcher,
    @BackgroundDispatcher private val bgScope: CoroutineScope,
    @BackgroundDispatcher private val bgDispatcher: CoroutineDispatcher,
) : WallpaperPicker2Injector(mainScope, bgDispatcher), CustomizationInjector {
    private val colorContrastSectionViewModelFactory: Lazy<ColorContrastSectionViewModel.Factory>,
    private val themesUserEventLogger: Lazy<ThemesUserEventLogger>,
    displayUtils: Lazy<DisplayUtils>,
    requester: Lazy<Requester>,
    networkStatusNotifier: Lazy<NetworkStatusNotifier>,
    partnerProvider: Lazy<PartnerProvider>,
    val uiModeManager: Lazy<UiModeManagerWrapper>,
    userEventLogger: Lazy<UserEventLogger>,
    injectedWallpaperClient: Lazy<WallpaperClient>,
    private val injectedWallpaperInteractor: Lazy<WallpaperInteractor>,
    prefs: Lazy<WallpaperPreferences>,
) :
    WallpaperPicker2Injector(
        mainScope,
        bgDispatcher,
        displayUtils,
        requester,
        networkStatusNotifier,
        partnerProvider,
        uiModeManager,
        userEventLogger,
        injectedWallpaperClient,
        injectedWallpaperInteractor,
        prefs,
    ),
    CustomizationInjector {
    private var customizationSections: CustomizationSections? = null
    private var wallpaperInteractor: WallpaperInteractor? = null
    private var keyguardQuickAffordancePickerInteractor: KeyguardQuickAffordancePickerInteractor? =
@@ -127,9 +160,6 @@ constructor(
    private var clockRegistryProvider: ClockRegistryProvider? = null

    // Injected objects, sorted by type
    @Inject
    lateinit var colorContrastSectionViewModelFactory: Lazy<ColorContrastSectionViewModel.Factory>
    @Inject lateinit var themesUserEventLogger: Lazy<ThemesUserEventLogger>

    override fun getCustomizationSections(activity: ComponentActivity): CustomizationSections {
        val appContext = activity.applicationContext
@@ -180,9 +210,7 @@ constructor(
        return fragmentFactory ?: ThemePickerFragmentFactory().also { fragmentFactory }
    }

    override fun getSnapshotRestorers(
        context: Context,
    ): Map<Int, SnapshotRestorer> {
    override fun getSnapshotRestorers(context: Context): Map<Int, SnapshotRestorer> {
        return super<WallpaperPicker2Injector>.getSnapshotRestorers(context).toMutableMap().apply {
            this[KEY_QUICK_AFFORDANCE_SNAPSHOT_RESTORER] =
                getKeyguardQuickAffordanceSnapshotRestorer(context)
@@ -229,7 +257,7 @@ constructor(
                            getColorCustomizationManager(appContext).currentColorSource,
                            COLOR_SOURCE_PRESET,
                        )
                    }
                    },
                )
                .also { wallpaperInteractor = it }
    }
@@ -264,7 +292,7 @@ constructor(
        val appContext = context.applicationContext
        return KeyguardQuickAffordancePickerInteractor(
            KeyguardQuickAffordancePickerRepository(client, getApplicationCoroutineScope()),
            client
            client,
        ) {
            getKeyguardQuickAffordanceSnapshotRestorer(appContext)
        }
@@ -285,13 +313,13 @@ constructor(
        return keyguardQuickAffordanceSnapshotRestorer
            ?: KeyguardQuickAffordanceSnapshotRestorer(
                    getKeyguardQuickAffordancePickerInteractor(context),
                    getKeyguardQuickAffordancePickerProviderClient(context)
                    getKeyguardQuickAffordancePickerProviderClient(context),
                )
                .also { keyguardQuickAffordanceSnapshotRestorer = it }
    }

    fun getNotificationSectionViewModelFactory(
        context: Context,
        context: Context
    ): NotificationSectionViewModel.Factory {
        return notificationSectionViewModelFactory
            ?: NotificationSectionViewModel.Factory(
@@ -301,9 +329,7 @@ constructor(
                .also { notificationSectionViewModelFactory = it }
    }

    private fun getNotificationsInteractor(
        context: Context,
    ): NotificationSettingsInteractor {
    private fun getNotificationsInteractor(context: Context): NotificationSettingsInteractor {
        return notificationSettingsInteractor
            ?: NotificationSettingsInteractor(
                    repository =
@@ -311,7 +337,7 @@ constructor(
                            scope = getApplicationCoroutineScope(),
                            backgroundDispatcher = bgDispatcher,
                            secureSettingsRepository = getSecureSettingsRepository(context),
                        ),
                        )
                )
                .also { notificationSettingsInteractor = it }
    }
@@ -319,10 +345,7 @@ constructor(
    private fun getNotificationsSnapshotRestorer(context: Context): NotificationsSnapshotRestorer {
        return notificationsSnapshotRestorer
            ?: NotificationsSnapshotRestorer(
                    interactor =
                        getNotificationsInteractor(
                            context = context,
                        ),
                    interactor = getNotificationsInteractor(context = context),
                    backgroundScope = bgScope,
                )
                .also { notificationsSnapshotRestorer = it }
@@ -340,9 +363,7 @@ constructor(
            .get()
    }

    override fun getClockPickerInteractor(
        context: Context,
    ): ClockPickerInteractor {
    override fun getClockPickerInteractor(context: Context): ClockPickerInteractor {
        val appContext = context.applicationContext
        return clockPickerInteractor
            ?: ClockPickerInteractor(
@@ -397,9 +418,7 @@ constructor(
                }
    }

    private fun getClockPickerSnapshotRestorer(
        context: Context,
    ): ClockPickerSnapshotRestorer {
    private fun getClockPickerSnapshotRestorer(context: Context): ClockPickerSnapshotRestorer {
        return clockPickerSnapshotRestorer
            ?: ClockPickerSnapshotRestorer(getClockPickerInteractor(context)).also {
                clockPickerSnapshotRestorer = it
@@ -408,7 +427,7 @@ constructor(

    override fun getWallpaperColorResources(
        wallpaperColors: WallpaperColors,
        context: Context
        context: Context,
    ): WallpaperColorResources {
        return ThemedWallpaperColorResources(wallpaperColors, getSecureSettingsRepository(context))
    }
@@ -423,11 +442,11 @@ constructor(
                    repository =
                        ColorPickerRepositoryImpl(
                            wallpaperColorsRepository,
                            getColorCustomizationManager(appContext)
                            getColorCustomizationManager(appContext),
                        ),
                    snapshotRestorer = {
                        getColorPickerSnapshotRestorer(appContext, wallpaperColorsRepository)
                    }
                    },
                )
                .also { colorPickerInteractor = it }
    }
@@ -463,9 +482,7 @@ constructor(
            }
    }

    fun getDarkModeSnapshotRestorer(
        context: Context,
    ): DarkModeSnapshotRestorer {
    fun getDarkModeSnapshotRestorer(context: Context): DarkModeSnapshotRestorer {
        val appContext = context.applicationContext
        return darkModeSnapshotRestorer
            ?: DarkModeSnapshotRestorer(
@@ -476,9 +493,7 @@ constructor(
                .also { darkModeSnapshotRestorer = it }
    }

    protected fun getThemedIconSnapshotRestorer(
        context: Context,
    ): ThemedIconSnapshotRestorer {
    protected fun getThemedIconSnapshotRestorer(context: Context): ThemedIconSnapshotRestorer {
        val optionProvider = ThemedIconSwitchProvider.getInstance(context)
        return themedIconSnapshotRestorer
            ?: ThemedIconSnapshotRestorer(
@@ -493,10 +508,9 @@ constructor(

    protected fun getThemedIconInteractor(): ThemedIconInteractor {
        return themedIconInteractor
            ?: ThemedIconInteractor(
                    repository = ThemeIconRepository(),
                )
                .also { themedIconInteractor = it }
            ?: ThemedIconInteractor(repository = ThemeIconRepository()).also {
                themedIconInteractor = it
            }
    }

    override fun getClockSettingsViewModelFactory(
@@ -508,10 +522,7 @@ constructor(
            ?: ClockSettingsViewModel.Factory(
                    context.applicationContext,
                    getClockPickerInteractor(context),
                    getColorPickerInteractor(
                        context,
                        wallpaperColorsRepository,
                    ),
                    getColorPickerInteractor(context, wallpaperColorsRepository),
                    getUserEventLogger(),
                ) { clockId ->
                    clockId?.let { clockViewFactory.getController(clockId).config.isReactiveToTone }
@@ -520,9 +531,7 @@ constructor(
                .also { clockSettingsViewModelFactory = it }
    }

    fun getGridScreenViewModelFactory(
        context: Context,
    ): ViewModelProvider.Factory {
    fun getGridScreenViewModelFactory(context: Context): ViewModelProvider.Factory {
        return gridScreenViewModelFactory
            ?: GridScreenViewModel.Factory(
                    context = context,
@@ -549,14 +558,11 @@ constructor(
                .also { gridInteractor = it }
    }

    private fun getGridSnapshotRestorer(
        context: Context,
    ): GridSnapshotRestorer {
    private fun getGridSnapshotRestorer(context: Context): GridSnapshotRestorer {
        return gridSnapshotRestorer
            ?: GridSnapshotRestorer(
                    interactor = getGridInteractor(context),
                )
                .also { gridSnapshotRestorer = it }
            ?: GridSnapshotRestorer(interactor = getGridInteractor(context)).also {
                gridSnapshotRestorer = it
            }
    }

    override fun isCurrentSelectedColorPreset(context: Context): Boolean {
+28 −3
Original line number Diff line number Diff line
@@ -16,9 +16,16 @@ import com.android.customization.picker.color.domain.interactor.ColorPickerInter
import com.android.customization.picker.color.ui.viewmodel.ColorPickerViewModel
import com.android.customization.picker.quickaffordance.domain.interactor.KeyguardQuickAffordancePickerInteractor
import com.android.systemui.shared.clocks.ClockRegistry
import com.android.wallpaper.module.NetworkStatusNotifier
import com.android.wallpaper.module.PartnerProvider
import com.android.wallpaper.module.WallpaperPreferences
import com.android.wallpaper.module.logging.UserEventLogger
import com.android.wallpaper.network.Requester
import com.android.wallpaper.picker.customization.data.repository.WallpaperColorsRepository
import com.android.wallpaper.picker.customization.domain.interactor.WallpaperInteractor
import com.android.wallpaper.testing.FakeWallpaperClient
import com.android.wallpaper.testing.TestInjector
import com.android.wallpaper.util.DisplayUtils
import javax.inject.Inject
import javax.inject.Singleton

@@ -27,8 +34,26 @@ open class TestCustomizationInjector
@Inject
constructor(
    private val customPrefs: TestDefaultCustomizationPreferences,
    private val themesUserEventLogger: ThemesUserEventLogger
) : TestInjector(themesUserEventLogger), CustomizationInjector {
    private val themesUserEventLogger: ThemesUserEventLogger,
    displayUtils: DisplayUtils,
    requester: Requester,
    networkStatusNotifier: NetworkStatusNotifier,
    partnerProvider: PartnerProvider,
    wallpaperClient: FakeWallpaperClient,
    injectedWallpaperInteractor: WallpaperInteractor,
    prefs: WallpaperPreferences,
) :
    TestInjector(
        themesUserEventLogger,
        displayUtils,
        requester,
        networkStatusNotifier,
        partnerProvider,
        wallpaperClient,
        injectedWallpaperInteractor,
        prefs,
    ),
    CustomizationInjector {
    /////////////////
    // CustomizationInjector implementations
    /////////////////
@@ -53,7 +78,7 @@ constructor(

    override fun getWallpaperColorResources(
        wallpaperColors: WallpaperColors,
        context: Context
        context: Context,
    ): WallpaperColorResources {
        throw UnsupportedOperationException("not implemented")
    }
+25 −11
Original line number Diff line number Diff line
@@ -33,6 +33,10 @@ import com.android.systemui.shared.customization.data.content.FakeCustomizationP
import com.android.systemui.shared.keyguard.shared.model.KeyguardQuickAffordanceSlots
import com.android.themepicker.R
import com.android.wallpaper.module.InjectorProvider
import com.android.wallpaper.module.NetworkStatusNotifier
import com.android.wallpaper.module.PartnerProvider
import com.android.wallpaper.module.WallpaperPreferences
import com.android.wallpaper.network.Requester
import com.android.wallpaper.picker.common.icon.ui.viewmodel.Icon
import com.android.wallpaper.picker.common.text.ui.viewmodel.Text
import com.android.wallpaper.picker.customization.data.repository.WallpaperRepository
@@ -44,6 +48,8 @@ import com.android.wallpaper.testing.TestCurrentWallpaperInfoFactory
import com.android.wallpaper.testing.TestInjector
import com.android.wallpaper.testing.TestWallpaperPreferences
import com.android.wallpaper.testing.collectLastValue
import com.android.wallpaper.util.DisplayUtils
import com.android.wallpaper.util.DisplaysProvider
import com.google.common.truth.Truth.assertThat
import com.google.common.truth.Truth.assertWithMessage
import kotlinx.coroutines.Dispatchers
@@ -58,6 +64,7 @@ import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.mock
import org.robolectric.RobolectricTestRunner

@OptIn(ExperimentalCoroutinesApi::class)
@@ -77,7 +84,6 @@ class KeyguardQuickAffordancePickerViewModelTest {

    @Before
    fun setUp() {
        InjectorProvider.setInjector(TestInjector(logger))
        context = ApplicationProvider.getApplicationContext()
        val testDispatcher = StandardTestDispatcher()
        testScope = TestScope(testDispatcher)
@@ -108,7 +114,19 @@ class KeyguardQuickAffordancePickerViewModelTest {
                        client = FakeWallpaperClient(),
                        wallpaperPreferences = TestWallpaperPreferences(),
                        backgroundDispatcher = testDispatcher,
                    ),
                    )
            )
        InjectorProvider.setInjector(
            TestInjector(
                logger,
                DisplayUtils(context, mock(DisplaysProvider::class.java)),
                mock(Requester::class.java),
                mock(NetworkStatusNotifier::class.java),
                mock(PartnerProvider::class.java),
                FakeWallpaperClient(),
                wallpaperInteractor,
                mock(WallpaperPreferences::class.java),
            )
        )
        underTest =
            KeyguardQuickAffordancePickerViewModel.Factory(
@@ -356,12 +374,12 @@ class KeyguardQuickAffordancePickerViewModelTest {
                        icon1 =
                            Icon.Loaded(
                                FakeCustomizationProviderClient.ICON_1,
                                Text.Loaded("Left shortcut")
                                Text.Loaded("Left shortcut"),
                            ),
                        icon2 =
                            Icon.Loaded(
                                FakeCustomizationProviderClient.ICON_3,
                                Text.Loaded("Right shortcut")
                                Text.Loaded("Right shortcut"),
                            ),
                    )
                )
@@ -384,7 +402,7 @@ class KeyguardQuickAffordancePickerViewModelTest {
                        icon1 =
                            Icon.Loaded(
                                FakeCustomizationProviderClient.ICON_1,
                                Text.Loaded("Left shortcut")
                                Text.Loaded("Left shortcut"),
                            ),
                        icon2 = null,
                    )
@@ -412,7 +430,7 @@ class KeyguardQuickAffordancePickerViewModelTest {
                        icon2 =
                            Icon.Loaded(
                                FakeCustomizationProviderClient.ICON_3,
                                Text.Loaded("Right shortcut")
                                Text.Loaded("Right shortcut"),
                            ),
                    )
                )
@@ -473,11 +491,7 @@ class KeyguardQuickAffordancePickerViewModelTest {
        assertThat(affordances).isNotNull()
        affordances?.forEach { affordance ->
            val nameMatchesSelectedName =
                Text.evaluationEquals(
                    context,
                    affordance.text,
                    Text.Loaded(selectedAffordanceText),
                )
                Text.evaluationEquals(context, affordance.text, Text.Loaded(selectedAffordanceText))
            val isSelected: Boolean? = collectLastValue(affordance.isSelected).invoke()
            assertWithMessage(
                    "Expected affordance with name \"${affordance.text}\" to have" +