Loading src/com/android/customization/module/ThemePickerInjector.kt +9 −24 Original line number Diff line number Diff line Loading @@ -99,11 +99,6 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject private var keyguardQuickAffordanceSnapshotRestorer: KeyguardQuickAffordanceSnapshotRestorer? = null private var notificationsSnapshotRestorer: NotificationsSnapshotRestorer? = null /** * Mapping from LifeCycleOwner's hashcode to ClockRegistry as we need to keep different * ClockRegistries per LifeCycle to ensure proper cleanup */ private var clockRegistries: MutableMap<Int, ClockRegistry> = HashMap() private var clockPickerInteractor: ClockPickerInteractor? = null private var clockSectionViewModel: ClockSectionViewModel? = null private var clockCarouselViewModelFactory: ClockCarouselViewModel.Factory? = null Loading @@ -122,6 +117,7 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject private var gridInteractor: GridInteractor? = null private var gridSnapshotRestorer: GridSnapshotRestorer? = null private var gridScreenViewModelFactory: GridScreenViewModel.Factory? = null private var clockRegistryProvider: ClockRegistryProvider? = null override fun getCustomizationSections(activity: ComponentActivity): CustomizationSections { return customizationSections Loading Loading @@ -344,26 +340,15 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject } override fun getClockRegistry(context: Context, lifecycleOwner: LifecycleOwner): ClockRegistry { return clockRegistries[lifecycleOwner.hashCode()] return (clockRegistryProvider ?: ClockRegistryProvider( context = context, coroutineScope = getApplicationCoroutineScope(), mainDispatcher = Dispatchers.Main, backgroundDispatcher = Dispatchers.IO, ) .get() .also { clockRegistries[lifecycleOwner.hashCode()] = it lifecycleOwner.lifecycle.addObserver( object : DefaultLifecycleObserver { override fun onDestroy(owner: LifecycleOwner) { super.onDestroy(owner) clockRegistries[lifecycleOwner.hashCode()]?.unregisterListeners() clockRegistries.remove(lifecycleOwner.hashCode()) } } ) } .also { clockRegistryProvider = it }) .getForOwner(lifecycleOwner) } override fun getClockPickerInteractor( Loading src/com/android/customization/picker/clock/data/repository/ClockRegistryProvider.kt +26 −1 Original line number Diff line number Diff line Loading @@ -19,6 +19,8 @@ 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 @@ -43,6 +45,7 @@ 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( Loading @@ -60,10 +63,32 @@ class ClockRegistryProvider( .apply { registerListeners() } } fun get(): ClockRegistry { fun getForOwner(lifecycleOwner: LifecycleOwner): ClockRegistry { registerLifecycleOwner(lifecycleOwner) return clockRegistry } 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() } } private fun createPluginManager(context: Context): PluginManager { val privilegedPlugins = listOf<String>() val isDebugDevice = true Loading Loading
src/com/android/customization/module/ThemePickerInjector.kt +9 −24 Original line number Diff line number Diff line Loading @@ -99,11 +99,6 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject private var keyguardQuickAffordanceSnapshotRestorer: KeyguardQuickAffordanceSnapshotRestorer? = null private var notificationsSnapshotRestorer: NotificationsSnapshotRestorer? = null /** * Mapping from LifeCycleOwner's hashcode to ClockRegistry as we need to keep different * ClockRegistries per LifeCycle to ensure proper cleanup */ private var clockRegistries: MutableMap<Int, ClockRegistry> = HashMap() private var clockPickerInteractor: ClockPickerInteractor? = null private var clockSectionViewModel: ClockSectionViewModel? = null private var clockCarouselViewModelFactory: ClockCarouselViewModel.Factory? = null Loading @@ -122,6 +117,7 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject private var gridInteractor: GridInteractor? = null private var gridSnapshotRestorer: GridSnapshotRestorer? = null private var gridScreenViewModelFactory: GridScreenViewModel.Factory? = null private var clockRegistryProvider: ClockRegistryProvider? = null override fun getCustomizationSections(activity: ComponentActivity): CustomizationSections { return customizationSections Loading Loading @@ -344,26 +340,15 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject } override fun getClockRegistry(context: Context, lifecycleOwner: LifecycleOwner): ClockRegistry { return clockRegistries[lifecycleOwner.hashCode()] return (clockRegistryProvider ?: ClockRegistryProvider( context = context, coroutineScope = getApplicationCoroutineScope(), mainDispatcher = Dispatchers.Main, backgroundDispatcher = Dispatchers.IO, ) .get() .also { clockRegistries[lifecycleOwner.hashCode()] = it lifecycleOwner.lifecycle.addObserver( object : DefaultLifecycleObserver { override fun onDestroy(owner: LifecycleOwner) { super.onDestroy(owner) clockRegistries[lifecycleOwner.hashCode()]?.unregisterListeners() clockRegistries.remove(lifecycleOwner.hashCode()) } } ) } .also { clockRegistryProvider = it }) .getForOwner(lifecycleOwner) } override fun getClockPickerInteractor( Loading
src/com/android/customization/picker/clock/data/repository/ClockRegistryProvider.kt +26 −1 Original line number Diff line number Diff line Loading @@ -19,6 +19,8 @@ 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 @@ -43,6 +45,7 @@ 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( Loading @@ -60,10 +63,32 @@ class ClockRegistryProvider( .apply { registerListeners() } } fun get(): ClockRegistry { fun getForOwner(lifecycleOwner: LifecycleOwner): ClockRegistry { registerLifecycleOwner(lifecycleOwner) return clockRegistry } 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() } } private fun createPluginManager(context: Context): PluginManager { val privilegedPlugins = listOf<String>() val isDebugDevice = true Loading