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

Commit 8e2eab4f authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix Activity leaks" into udc-dev

parents 3d0a6e1b 829006f7
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -50,10 +50,7 @@ interface CustomizationInjector : Injector {

    fun getClockRegistry(context: Context, lifecycleOwner: LifecycleOwner): ClockRegistry

    fun getClockPickerInteractor(
        context: Context,
        lifecycleOwner: LifecycleOwner
    ): ClockPickerInteractor
    fun getClockPickerInteractor(context: Context): ClockPickerInteractor

    fun getClockSectionViewModel(
        context: Context,
+31 −26
Original line number Diff line number Diff line
@@ -134,7 +134,7 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject
                    ),
                    getFlags(),
                    getClockCarouselViewModelFactory(
                        getClockPickerInteractor(activity.applicationContext, activity),
                        getClockPickerInteractor(activity.applicationContext),
                    ),
                    getClockViewFactory(activity),
                    getDarkModeSnapshotRestorer(activity),
@@ -181,7 +181,7 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject
    @Synchronized
    override fun getUserEventLogger(context: Context): ThemesUserEventLogger {
        return if (userEventLogger != null) userEventLogger as ThemesUserEventLogger
        else StatsLogUserEventLogger(context).also { userEventLogger = it }
        else StatsLogUserEventLogger(context.applicationContext).also { userEventLogger = it }
    }

    @Synchronized
@@ -211,8 +211,7 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject
                this[KEY_APP_GRID_SNAPSHOT_RESTORER] = getGridSnapshotRestorer(context)
                this[KEY_COLOR_PICKER_SNAPSHOT_RESTORER] =
                    getColorPickerSnapshotRestorer(context, getWallpaperColorsViewModel())
                this[KEY_CLOCKS_SNAPSHOT_RESTORER] =
                    getClockPickerSnapshotRestorer(context, lifecycleOwner)
                this[KEY_CLOCKS_SNAPSHOT_RESTORER] = getClockPickerSnapshotRestorer(context)
            }
    }

@@ -230,6 +229,7 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject
    }

    override fun getWallpaperInteractor(context: Context): WallpaperInteractor {
        val appContext = context.applicationContext
        return wallpaperInteractor
            ?: WallpaperInteractor(
                    repository =
@@ -237,16 +237,16 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject
                            scope = getApplicationCoroutineScope(),
                            client =
                                WallpaperClientImpl(
                                    context = context,
                                    context = appContext,
                                    infoFactory = getCurrentWallpaperInfoFactory(context),
                                    wallpaperManager = WallpaperManager.getInstance(context)
                                ),
                            wallpaperPreferences = getPreferences(context = context),
                            wallpaperPreferences = getPreferences(context = appContext),
                            backgroundDispatcher = Dispatchers.IO,
                        ),
                    shouldHandleReload = {
                        TextUtils.equals(
                            getColorCustomizationManager(context).currentColorSource,
                            getColorCustomizationManager(appContext).currentColorSource,
                            ColorOptionsProvider.COLOR_SOURCE_PRESET
                        )
                    }
@@ -268,7 +268,7 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject
    ): KeyguardQuickAffordancePickerViewModel.Factory {
        return keyguardQuickAffordancePickerViewModelFactory
            ?: KeyguardQuickAffordancePickerViewModel.Factory(
                    context,
                    context.applicationContext,
                    getKeyguardQuickAffordancePickerInteractor(context),
                    getWallpaperInteractor(context),
                    getCurrentWallpaperInfoFactory(context),
@@ -280,11 +280,12 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject
        context: Context
    ): KeyguardQuickAffordancePickerInteractor {
        val client = getKeyguardQuickAffordancePickerProviderClient(context)
        val appContext = context.applicationContext
        return KeyguardQuickAffordancePickerInteractor(
            KeyguardQuickAffordancePickerRepository(client, Dispatchers.IO),
            client
        ) {
            getKeyguardQuickAffordanceSnapshotRestorer(context)
            getKeyguardQuickAffordanceSnapshotRestorer(appContext)
        }
    }

@@ -292,7 +293,7 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject
        context: Context
    ): CustomizationProviderClient {
        return customizationProviderClient
            ?: CustomizationProviderClientImpl(context, Dispatchers.IO).also {
            ?: CustomizationProviderClientImpl(context.applicationContext, Dispatchers.IO).also {
                customizationProviderClient = it
            }
    }
@@ -321,6 +322,7 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject
    private fun getNotificationsInteractor(
        context: Context,
    ): NotificationsInteractor {
        val appContext = context.applicationContext
        return notificationsInteractor
            ?: NotificationsInteractor(
                    repository =
@@ -329,7 +331,7 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject
                            backgroundDispatcher = Dispatchers.IO,
                            secureSettingsRepository = getSecureSettingsRepository(context),
                        ),
                    snapshotRestorer = { getNotificationsSnapshotRestorer(context) },
                    snapshotRestorer = { getNotificationsSnapshotRestorer(appContext) },
                )
                .also { notificationsInteractor = it }
    }
@@ -348,7 +350,7 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject
    override fun getClockRegistry(context: Context, lifecycleOwner: LifecycleOwner): ClockRegistry {
        return (clockRegistryProvider
                ?: ClockRegistryProvider(
                        context = context,
                        context = context.applicationContext,
                        coroutineScope = getApplicationCoroutineScope(),
                        mainDispatcher = Dispatchers.Main,
                        backgroundDispatcher = Dispatchers.IO,
@@ -359,18 +361,19 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject

    override fun getClockPickerInteractor(
        context: Context,
        lifecycleOwner: LifecycleOwner,
    ): ClockPickerInteractor {
        val appContext = context.applicationContext
        return clockPickerInteractor
            ?: ClockPickerInteractor(
                    repository =
                        ClockPickerRepositoryImpl(
                            secureSettingsRepository = getSecureSettingsRepository(context),
                            registry = getClockRegistry(context, lifecycleOwner),
                            // TODO (b/285978251): remove second argument once b/285348630 is fixed
                            registry = getClockRegistry(context, context as LifecycleOwner),
                            scope = getApplicationCoroutineScope(),
                            mainDispatcher = Dispatchers.Main,
                        ),
                    snapshotRestorer = { getClockPickerSnapshotRestorer(context, lifecycleOwner) },
                    snapshotRestorer = { getClockPickerSnapshotRestorer(appContext) },
                )
                .also { clockPickerInteractor = it }
    }
@@ -380,7 +383,7 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject
        lifecycleOwner: LifecycleOwner
    ): ClockSectionViewModel {
        return clockSectionViewModel
            ?: ClockSectionViewModel(context, getClockPickerInteractor(context, lifecycleOwner))
            ?: ClockSectionViewModel(context.applicationContext, getClockPickerInteractor(context))
                .also { clockSectionViewModel = it }
    }

@@ -422,10 +425,9 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject

    private fun getClockPickerSnapshotRestorer(
        context: Context,
        lifecycleOwner: LifecycleOwner
    ): ClockPickerSnapshotRestorer {
        return clockPickerSnapshotRestorer
            ?: ClockPickerSnapshotRestorer(getClockPickerInteractor(context, lifecycleOwner)).also {
            ?: ClockPickerSnapshotRestorer(getClockPickerInteractor(context)).also {
                clockPickerSnapshotRestorer = it
            }
    }
@@ -434,15 +436,16 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject
        context: Context,
        wallpaperColorsViewModel: WallpaperColorsViewModel,
    ): ColorPickerInteractor {
        val appContext = context.applicationContext
        return colorPickerInteractor
            ?: ColorPickerInteractor(
                    repository =
                        ColorPickerRepositoryImpl(
                            wallpaperColorsViewModel,
                            getColorCustomizationManager(context)
                            getColorCustomizationManager(appContext)
                        ),
                    snapshotRestorer = {
                        getColorPickerSnapshotRestorer(context, wallpaperColorsViewModel)
                        getColorPickerSnapshotRestorer(appContext, wallpaperColorsViewModel)
                    }
                )
                .also { colorPickerInteractor = it }
@@ -454,7 +457,7 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject
    ): ColorPickerViewModel.Factory {
        return colorPickerViewModelFactory
            ?: ColorPickerViewModel.Factory(
                    context,
                    context.applicationContext,
                    getColorPickerInteractor(context, wallpaperColorsViewModel),
                )
                .also { colorPickerViewModelFactory = it }
@@ -481,10 +484,11 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject
    fun getDarkModeSnapshotRestorer(
        context: Context,
    ): DarkModeSnapshotRestorer {
        val appContext = context.applicationContext
        return darkModeSnapshotRestorer
            ?: DarkModeSnapshotRestorer(
                    context = context,
                    manager = context.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager,
                    context = appContext,
                    manager = appContext.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager,
                    backgroundDispatcher = Dispatchers.IO,
                )
                .also { darkModeSnapshotRestorer = it }
@@ -521,8 +525,8 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject
    ): ClockSettingsViewModel.Factory {
        return clockSettingsViewModelFactory
            ?: ClockSettingsViewModel.Factory(
                    context,
                    getClockPickerInteractor(context, lifecycleOwner),
                    context.applicationContext,
                    getClockPickerInteractor(context),
                    getColorPickerInteractor(
                        context,
                        wallpaperColorsViewModel,
@@ -548,6 +552,7 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject
    private fun getGridInteractor(
        context: Context,
    ): GridInteractor {
        val appContext = context.applicationContext
        return gridInteractor
            ?: GridInteractor(
                    applicationScope = getApplicationCoroutineScope(),
@@ -557,7 +562,7 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject
                            manager = GridOptionsManager.getInstance(context),
                            backgroundDispatcher = Dispatchers.IO,
                        ),
                    snapshotRestorer = { getGridSnapshotRestorer(context) },
                    snapshotRestorer = { getGridSnapshotRestorer(appContext) },
                )
                .also { gridInteractor = it }
    }
+1 −1
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ class ClockSectionViewModel(context: Context, interactor: ClockPickerInteractor)
            (selectedColorId, selectedClockSize) ->
            val colorText =
                clockColorMap[selectedColorId]?.colorName
                    ?: context.getString(R.string.default_theme_title)
                    ?: appContext.getString(R.string.default_theme_title)
            val sizeText =
                when (selectedClockSize) {
                    ClockSize.SMALL -> appContext.getString(R.string.clock_size_small)