Loading src/com/android/customization/module/CustomizationInjector.kt +1 −4 Original line number Diff line number Diff line Loading @@ -18,7 +18,6 @@ package com.android.customization.module import android.content.Context import androidx.activity.ComponentActivity import androidx.fragment.app.FragmentActivity import androidx.lifecycle.LifecycleOwner import com.android.customization.model.theme.OverlayManagerCompat import com.android.customization.model.theme.ThemeBundleProvider import com.android.customization.model.theme.ThemeManager Loading Loading @@ -48,13 +47,12 @@ interface CustomizationInjector : Injector { context: Context, ): KeyguardQuickAffordancePickerInteractor fun getClockRegistry(context: Context, lifecycleOwner: LifecycleOwner): ClockRegistry fun getClockRegistry(context: Context): ClockRegistry? fun getClockPickerInteractor(context: Context): ClockPickerInteractor fun getClockSectionViewModel( context: Context, lifecycleOwner: LifecycleOwner ): ClockSectionViewModel fun getColorPickerInteractor( Loading @@ -77,6 +75,5 @@ interface CustomizationInjector : Injector { context: Context, wallpaperColorsViewModel: WallpaperColorsViewModel, clockViewFactory: ClockViewFactory, lifecycleOwner: LifecycleOwner, ): ClockSettingsViewModel.Factory } src/com/android/customization/module/ThemePickerInjector.kt +21 −28 Original line number Diff line number Diff line Loading @@ -196,16 +196,12 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject override fun getSnapshotRestorers( context: Context, lifecycleOwner: LifecycleOwner ): Map<Int, SnapshotRestorer> { return super<WallpaperPicker2Injector>.getSnapshotRestorers(context, lifecycleOwner) .toMutableMap() .apply { return super<WallpaperPicker2Injector>.getSnapshotRestorers(context).toMutableMap().apply { this[KEY_QUICK_AFFORDANCE_SNAPSHOT_RESTORER] = getKeyguardQuickAffordanceSnapshotRestorer(context) this[KEY_WALLPAPER_SNAPSHOT_RESTORER] = getWallpaperSnapshotRestorer(context) this[KEY_NOTIFICATIONS_SNAPSHOT_RESTORER] = getNotificationsSnapshotRestorer(context) this[KEY_NOTIFICATIONS_SNAPSHOT_RESTORER] = getNotificationsSnapshotRestorer(context) this[KEY_DARK_MODE_SNAPSHOT_RESTORER] = getDarkModeSnapshotRestorer(context) this[KEY_THEMED_ICON_SNAPSHOT_RESTORER] = getThemedIconSnapshotRestorer(context) this[KEY_APP_GRID_SNAPSHOT_RESTORER] = getGridSnapshotRestorer(context) Loading Loading @@ -347,7 +343,7 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject .also { notificationsSnapshotRestorer = it } } override fun getClockRegistry(context: Context, lifecycleOwner: LifecycleOwner): ClockRegistry { override fun getClockRegistry(context: Context): ClockRegistry { return (clockRegistryProvider ?: ClockRegistryProvider( context = context.applicationContext, Loading @@ -356,7 +352,7 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject backgroundDispatcher = Dispatchers.IO, ) .also { clockRegistryProvider = it }) .getForOwner(lifecycleOwner) .get() } override fun getClockPickerInteractor( Loading @@ -367,9 +363,8 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject ?: ClockPickerInteractor( repository = ClockPickerRepositoryImpl( secureSettingsRepository = getSecureSettingsRepository(context), // TODO (b/285978251): remove second argument once b/285348630 is fixed registry = getClockRegistry(context, context as LifecycleOwner), secureSettingsRepository = getSecureSettingsRepository(appContext), registry = getClockRegistry(appContext), scope = getApplicationCoroutineScope(), mainDispatcher = Dispatchers.Main, ), Loading @@ -380,10 +375,12 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject override fun getClockSectionViewModel( context: Context, lifecycleOwner: LifecycleOwner ): ClockSectionViewModel { return clockSectionViewModel ?: ClockSectionViewModel(context.applicationContext, getClockPickerInteractor(context)) ?: ClockSectionViewModel( context.applicationContext, getClockPickerInteractor(context.applicationContext) ) .also { clockSectionViewModel = it } } Loading @@ -404,10 +401,7 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject ScreenSizeCalculator.getInstance() .getScreenSize(activity.windowManager.defaultDisplay), WallpaperManager.getInstance(activity.applicationContext), getClockRegistry( context = activity.applicationContext, lifecycleOwner = activity, ), getClockRegistry(activity.applicationContext), ) .also { clockViewFactories[activityHashCode] = it Loading Loading @@ -521,7 +515,6 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject context: Context, wallpaperColorsViewModel: WallpaperColorsViewModel, clockViewFactory: ClockViewFactory, lifecycleOwner: LifecycleOwner, ): ClockSettingsViewModel.Factory { return clockSettingsViewModelFactory ?: ClockSettingsViewModel.Factory( Loading src/com/android/customization/picker/clock/data/repository/ClockRegistryProvider.kt +15 −39 Original line number Diff line number Diff line Loading @@ -19,8 +19,6 @@ import android.app.NotificationManager import android.content.ComponentName import android.content.Context import android.view.LayoutInflater import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.LifecycleOwner import com.android.systemui.plugins.Plugin import com.android.systemui.plugins.PluginManager import com.android.systemui.shared.clocks.ClockRegistry Loading @@ -45,12 +43,10 @@ class ClockRegistryProvider( private val mainDispatcher: CoroutineDispatcher, private val backgroundDispatcher: CoroutineDispatcher, ) { private val lifecycleOwners = mutableSetOf<Int>() private val pluginManager: PluginManager by lazy { createPluginManager(context) } private val clockRegistry: ClockRegistry by lazy { ClockRegistry( context, pluginManager, createPluginManager(context), coroutineScope, mainDispatcher, backgroundDispatcher, Loading @@ -60,34 +56,14 @@ class ClockRegistryProvider( keepAllLoaded = true, subTag = "Picker", ) .apply { registerListeners() } } fun getForOwner(lifecycleOwner: LifecycleOwner): ClockRegistry { registerLifecycleOwner(lifecycleOwner) return clockRegistry init { // Listeners in ClockRegistry get cleaned up when app ended clockRegistry.registerListeners() } private fun registerLifecycleOwner(lifecycleOwner: LifecycleOwner) { lifecycleOwners.add(lifecycleOwner.hashCode()) lifecycleOwner.lifecycle.addObserver( object : DefaultLifecycleObserver { override fun onDestroy(owner: LifecycleOwner) { super.onDestroy(owner) unregisterLifecycleOwner(owner) } } ) } private fun unregisterLifecycleOwner(lifecycleOwner: LifecycleOwner) { lifecycleOwners.remove(lifecycleOwner.hashCode()) if (lifecycleOwners.isEmpty()) { clockRegistry.unregisterListeners() } } fun get() = clockRegistry private fun createPluginManager(context: Context): PluginManager { val privilegedPlugins = listOf<String>() Loading src/com/android/customization/picker/clock/ui/fragment/ClockCustomDemoFragment.kt +0 −1 Original line number Diff line number Diff line Loading @@ -37,7 +37,6 @@ class ClockCustomDemoFragment : AppbarFragment() { clockRegistry = (InjectorProvider.getInjector() as ThemePickerInjector).getClockRegistry( requireContext(), this ) val listInUse = clockRegistry.getClocks().filter { "NOT_IN_USE" !in it.clockId } Loading src/com/android/customization/picker/clock/ui/fragment/ClockSettingsFragment.kt +0 −1 Original line number Diff line number Diff line Loading @@ -123,7 +123,6 @@ class ClockSettingsFragment : AppbarFragment() { context, injector.getWallpaperColorsViewModel(), injector.getClockViewFactory(activity), activity, ), ) .get(), Loading Loading
src/com/android/customization/module/CustomizationInjector.kt +1 −4 Original line number Diff line number Diff line Loading @@ -18,7 +18,6 @@ package com.android.customization.module import android.content.Context import androidx.activity.ComponentActivity import androidx.fragment.app.FragmentActivity import androidx.lifecycle.LifecycleOwner import com.android.customization.model.theme.OverlayManagerCompat import com.android.customization.model.theme.ThemeBundleProvider import com.android.customization.model.theme.ThemeManager Loading Loading @@ -48,13 +47,12 @@ interface CustomizationInjector : Injector { context: Context, ): KeyguardQuickAffordancePickerInteractor fun getClockRegistry(context: Context, lifecycleOwner: LifecycleOwner): ClockRegistry fun getClockRegistry(context: Context): ClockRegistry? fun getClockPickerInteractor(context: Context): ClockPickerInteractor fun getClockSectionViewModel( context: Context, lifecycleOwner: LifecycleOwner ): ClockSectionViewModel fun getColorPickerInteractor( Loading @@ -77,6 +75,5 @@ interface CustomizationInjector : Injector { context: Context, wallpaperColorsViewModel: WallpaperColorsViewModel, clockViewFactory: ClockViewFactory, lifecycleOwner: LifecycleOwner, ): ClockSettingsViewModel.Factory }
src/com/android/customization/module/ThemePickerInjector.kt +21 −28 Original line number Diff line number Diff line Loading @@ -196,16 +196,12 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject override fun getSnapshotRestorers( context: Context, lifecycleOwner: LifecycleOwner ): Map<Int, SnapshotRestorer> { return super<WallpaperPicker2Injector>.getSnapshotRestorers(context, lifecycleOwner) .toMutableMap() .apply { return super<WallpaperPicker2Injector>.getSnapshotRestorers(context).toMutableMap().apply { this[KEY_QUICK_AFFORDANCE_SNAPSHOT_RESTORER] = getKeyguardQuickAffordanceSnapshotRestorer(context) this[KEY_WALLPAPER_SNAPSHOT_RESTORER] = getWallpaperSnapshotRestorer(context) this[KEY_NOTIFICATIONS_SNAPSHOT_RESTORER] = getNotificationsSnapshotRestorer(context) this[KEY_NOTIFICATIONS_SNAPSHOT_RESTORER] = getNotificationsSnapshotRestorer(context) this[KEY_DARK_MODE_SNAPSHOT_RESTORER] = getDarkModeSnapshotRestorer(context) this[KEY_THEMED_ICON_SNAPSHOT_RESTORER] = getThemedIconSnapshotRestorer(context) this[KEY_APP_GRID_SNAPSHOT_RESTORER] = getGridSnapshotRestorer(context) Loading Loading @@ -347,7 +343,7 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject .also { notificationsSnapshotRestorer = it } } override fun getClockRegistry(context: Context, lifecycleOwner: LifecycleOwner): ClockRegistry { override fun getClockRegistry(context: Context): ClockRegistry { return (clockRegistryProvider ?: ClockRegistryProvider( context = context.applicationContext, Loading @@ -356,7 +352,7 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject backgroundDispatcher = Dispatchers.IO, ) .also { clockRegistryProvider = it }) .getForOwner(lifecycleOwner) .get() } override fun getClockPickerInteractor( Loading @@ -367,9 +363,8 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject ?: ClockPickerInteractor( repository = ClockPickerRepositoryImpl( secureSettingsRepository = getSecureSettingsRepository(context), // TODO (b/285978251): remove second argument once b/285348630 is fixed registry = getClockRegistry(context, context as LifecycleOwner), secureSettingsRepository = getSecureSettingsRepository(appContext), registry = getClockRegistry(appContext), scope = getApplicationCoroutineScope(), mainDispatcher = Dispatchers.Main, ), Loading @@ -380,10 +375,12 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject override fun getClockSectionViewModel( context: Context, lifecycleOwner: LifecycleOwner ): ClockSectionViewModel { return clockSectionViewModel ?: ClockSectionViewModel(context.applicationContext, getClockPickerInteractor(context)) ?: ClockSectionViewModel( context.applicationContext, getClockPickerInteractor(context.applicationContext) ) .also { clockSectionViewModel = it } } Loading @@ -404,10 +401,7 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject ScreenSizeCalculator.getInstance() .getScreenSize(activity.windowManager.defaultDisplay), WallpaperManager.getInstance(activity.applicationContext), getClockRegistry( context = activity.applicationContext, lifecycleOwner = activity, ), getClockRegistry(activity.applicationContext), ) .also { clockViewFactories[activityHashCode] = it Loading Loading @@ -521,7 +515,6 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject context: Context, wallpaperColorsViewModel: WallpaperColorsViewModel, clockViewFactory: ClockViewFactory, lifecycleOwner: LifecycleOwner, ): ClockSettingsViewModel.Factory { return clockSettingsViewModelFactory ?: ClockSettingsViewModel.Factory( Loading
src/com/android/customization/picker/clock/data/repository/ClockRegistryProvider.kt +15 −39 Original line number Diff line number Diff line Loading @@ -19,8 +19,6 @@ import android.app.NotificationManager import android.content.ComponentName import android.content.Context import android.view.LayoutInflater import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.LifecycleOwner import com.android.systemui.plugins.Plugin import com.android.systemui.plugins.PluginManager import com.android.systemui.shared.clocks.ClockRegistry Loading @@ -45,12 +43,10 @@ class ClockRegistryProvider( private val mainDispatcher: CoroutineDispatcher, private val backgroundDispatcher: CoroutineDispatcher, ) { private val lifecycleOwners = mutableSetOf<Int>() private val pluginManager: PluginManager by lazy { createPluginManager(context) } private val clockRegistry: ClockRegistry by lazy { ClockRegistry( context, pluginManager, createPluginManager(context), coroutineScope, mainDispatcher, backgroundDispatcher, Loading @@ -60,34 +56,14 @@ class ClockRegistryProvider( keepAllLoaded = true, subTag = "Picker", ) .apply { registerListeners() } } fun getForOwner(lifecycleOwner: LifecycleOwner): ClockRegistry { registerLifecycleOwner(lifecycleOwner) return clockRegistry init { // Listeners in ClockRegistry get cleaned up when app ended clockRegistry.registerListeners() } private fun registerLifecycleOwner(lifecycleOwner: LifecycleOwner) { lifecycleOwners.add(lifecycleOwner.hashCode()) lifecycleOwner.lifecycle.addObserver( object : DefaultLifecycleObserver { override fun onDestroy(owner: LifecycleOwner) { super.onDestroy(owner) unregisterLifecycleOwner(owner) } } ) } private fun unregisterLifecycleOwner(lifecycleOwner: LifecycleOwner) { lifecycleOwners.remove(lifecycleOwner.hashCode()) if (lifecycleOwners.isEmpty()) { clockRegistry.unregisterListeners() } } fun get() = clockRegistry private fun createPluginManager(context: Context): PluginManager { val privilegedPlugins = listOf<String>() Loading
src/com/android/customization/picker/clock/ui/fragment/ClockCustomDemoFragment.kt +0 −1 Original line number Diff line number Diff line Loading @@ -37,7 +37,6 @@ class ClockCustomDemoFragment : AppbarFragment() { clockRegistry = (InjectorProvider.getInjector() as ThemePickerInjector).getClockRegistry( requireContext(), this ) val listInUse = clockRegistry.getClocks().filter { "NOT_IN_USE" !in it.clockId } Loading
src/com/android/customization/picker/clock/ui/fragment/ClockSettingsFragment.kt +0 −1 Original line number Diff line number Diff line Loading @@ -123,7 +123,6 @@ class ClockSettingsFragment : AppbarFragment() { context, injector.getWallpaperColorsViewModel(), injector.getClockViewFactory(activity), activity, ), ) .get(), Loading