diff options
| author | 2024-08-30 22:40:54 +0000 | |
|---|---|---|
| committer | 2024-09-04 18:05:51 +0000 | |
| commit | 47b10dd396cf9ca96de102fa61447ce737ece5af (patch) | |
| tree | ebdfb17f46cddff4ca3f1d2c1174417361d8dd92 | |
| parent | eff91c9fabd673ef9debd0f4f6cb9305cc6b459c (diff) | |
Selectively share KeyguardQuickAffordancesCombinedViewModel
Since the indication area and shortcuts section refer to the
same quick affordances, they should share the same model, which
will greatly reduce the number of continuations running.
Also add a bit more logging for when quick affordances update.
Fixes: 360066410
Test: atest PlatformScenarioTests:LockscreenShortcutTest
Flag: EXEMPT bugfix
Change-Id: I6fb579e37f79d8210e86996dda8623654078e645
9 files changed, 80 insertions, 6 deletions
diff --git a/packages/SystemUI/src/com/android/keyguard/logging/KeyguardQuickAffordancesLogger.kt b/packages/SystemUI/src/com/android/keyguard/logging/KeyguardQuickAffordancesLogger.kt index c11cf55c92a4..7dbf013b084c 100644 --- a/packages/SystemUI/src/com/android/keyguard/logging/KeyguardQuickAffordancesLogger.kt +++ b/packages/SystemUI/src/com/android/keyguard/logging/KeyguardQuickAffordancesLogger.kt @@ -16,6 +16,7 @@ package com.android.keyguard.logging +import com.android.systemui.keyguard.ui.viewmodel.KeyguardQuickAffordanceViewModel import com.android.systemui.log.LogBuffer import com.android.systemui.log.core.LogLevel import com.android.systemui.log.dagger.KeyguardQuickAffordancesLog @@ -63,6 +64,15 @@ constructor( ) } + fun logUpdate(viewModel: KeyguardQuickAffordanceViewModel) { + buffer.log( + TAG, + LogLevel.DEBUG, + { str1 = viewModel.toString() }, + { "QuickAffordance updated: $str1" } + ) + } + private fun String.decode(): Pair<String, String> { val splitUp = this.split(DELIMITER) return Pair(splitUp[0], splitUp[1]) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java b/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java index a43bfd3a8fff..8a3d01707540 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java @@ -63,6 +63,7 @@ import com.android.systemui.keyguard.domain.interactor.StartKeyguardTransitionMo import com.android.systemui.keyguard.shared.quickaffordance.KeyguardQuickAffordancesMetricsLogger; import com.android.systemui.keyguard.shared.quickaffordance.KeyguardQuickAffordancesMetricsLoggerImpl; import com.android.systemui.keyguard.ui.transitions.DeviceEntryIconTransitionModule; +import com.android.systemui.keyguard.ui.viewmodel.KeyguardQuickAffordancesCombinedViewModelModule; import com.android.systemui.log.SessionTracker; import com.android.systemui.navigationbar.NavigationModeController; import com.android.systemui.process.ProcessWrapper; @@ -111,6 +112,7 @@ import java.util.concurrent.Executor; DeviceEntryIconTransitionModule.class, FalsingModule.class, KeyguardDataQuickAffordanceModule.class, + KeyguardQuickAffordancesCombinedViewModelModule.class, KeyguardRepositoryModule.class, DeviceEntryFaceAuthModule.class, KeyguardDisplayModule.class, diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardQuickAffordanceViewBinder.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardQuickAffordanceViewBinder.kt index 28a17ef4922a..27dd18d2b24e 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardQuickAffordanceViewBinder.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardQuickAffordanceViewBinder.kt @@ -93,7 +93,7 @@ constructor( val configurationBasedDimensions = MutableStateFlow(loadFromResources(view)) val disposableHandle = view.repeatWhenAttached { - repeatOnLifecycle(Lifecycle.State.CREATED) { + repeatOnLifecycle(Lifecycle.State.STARTED) { launch { viewModel.collect { buttonModel -> updateButton( @@ -141,6 +141,7 @@ constructor( viewModel: KeyguardQuickAffordanceViewModel, messageDisplayer: (Int) -> Unit, ) { + logger.logUpdate(viewModel) if (!viewModel.isVisible) { view.isInvisible = true return diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/BaseShortcutSection.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/BaseShortcutSection.kt index a4137ac934a1..8861c1e11ae1 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/BaseShortcutSection.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/BaseShortcutSection.kt @@ -4,10 +4,10 @@ import android.view.View import android.widget.ImageView import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.content.res.ResourcesCompat -import com.android.systemui.res.R import com.android.systemui.animation.view.LaunchableImageView import com.android.systemui.keyguard.shared.model.KeyguardSection import com.android.systemui.keyguard.ui.binder.KeyguardQuickAffordanceViewBinder +import com.android.systemui.res.R abstract class BaseShortcutSection : KeyguardSection() { protected var leftShortcutHandle: KeyguardQuickAffordanceViewBinder.Binding? = null @@ -15,7 +15,9 @@ abstract class BaseShortcutSection : KeyguardSection() { override fun removeViews(constraintLayout: ConstraintLayout) { leftShortcutHandle?.destroy() + leftShortcutHandle = null rightShortcutHandle?.destroy() + rightShortcutHandle = null constraintLayout.removeView(R.id.start_button) constraintLayout.removeView(R.id.end_button) } @@ -75,6 +77,7 @@ abstract class BaseShortcutSection : KeyguardSection() { } constraintLayout.addView(view) } + /** * Defines equality as same class. * diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultShortcutsSection.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultShortcutsSection.kt index e558033728ba..6c6e14cac84d 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultShortcutsSection.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultShortcutsSection.kt @@ -33,16 +33,19 @@ import com.android.systemui.keyguard.domain.interactor.KeyguardBlueprintInteract import com.android.systemui.keyguard.ui.binder.KeyguardQuickAffordanceViewBinder import com.android.systemui.keyguard.ui.view.layout.blueprints.transitions.IntraBlueprintTransition import com.android.systemui.keyguard.ui.viewmodel.KeyguardQuickAffordancesCombinedViewModel +import com.android.systemui.keyguard.ui.viewmodel.KeyguardQuickAffordancesCombinedViewModelModule.Companion.LOCKSCREEN_INSTANCE import com.android.systemui.keyguard.ui.viewmodel.KeyguardRootViewModel import com.android.systemui.res.R import com.android.systemui.statusbar.KeyguardIndicationController import dagger.Lazy import javax.inject.Inject +import javax.inject.Named class DefaultShortcutsSection @Inject constructor( @Main private val resources: Resources, + @Named(LOCKSCREEN_INSTANCE) private val keyguardQuickAffordancesCombinedViewModel: KeyguardQuickAffordancesCombinedViewModel, private val keyguardRootViewModel: KeyguardRootViewModel, @@ -76,6 +79,7 @@ constructor( override fun bindData(constraintLayout: ConstraintLayout) { if (KeyguardBottomAreaRefactor.isEnabled) { + leftShortcutHandle?.destroy() leftShortcutHandle = keyguardQuickAffordanceViewBinder.bind( constraintLayout.requireViewById(R.id.start_button), @@ -84,6 +88,7 @@ constructor( ) { indicationController.showTransientIndication(it) } + rightShortcutHandle?.destroy() rightShortcutHandle = keyguardQuickAffordanceViewBinder.bind( constraintLayout.requireViewById(R.id.end_button), diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardIndicationAreaViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardIndicationAreaViewModel.kt index 609b571d94fd..ceae1b5e9038 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardIndicationAreaViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardIndicationAreaViewModel.kt @@ -33,6 +33,7 @@ import com.android.systemui.keyguard.shared.model.StatusBarState import com.android.systemui.res.R import com.android.systemui.util.kotlin.BooleanFlowOperators.anyOf import javax.inject.Inject +import javax.inject.Named import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow @@ -50,6 +51,7 @@ constructor( keyguardBottomAreaViewModel: KeyguardBottomAreaViewModel, private val burnInHelperWrapper: BurnInHelperWrapper, burnInInteractor: BurnInInteractor, + @Named(KeyguardQuickAffordancesCombinedViewModelModule.Companion.LOCKSCREEN_INSTANCE) shortcutsCombinedViewModel: KeyguardQuickAffordancesCombinedViewModel, configurationInteractor: ConfigurationInteractor, keyguardTransitionInteractor: KeyguardTransitionInteractor, diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordancesCombinedViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordancesCombinedViewModel.kt index 72740d5f5cef..7e13d2282e05 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordancesCombinedViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordancesCombinedViewModel.kt @@ -177,10 +177,16 @@ constructor( ) } } else { - button( - KeyguardQuickAffordancePosition.BOTTOM_START, - ) + button(KeyguardQuickAffordancePosition.BOTTOM_START) } + .stateIn( + scope = applicationScope, + started = SharingStarted.WhileSubscribed(), + initialValue = + KeyguardQuickAffordanceViewModel( + slotId = KeyguardQuickAffordancePosition.BOTTOM_START.toSlotId() + ), + ) /** An observable for the view-model of the "end button" quick affordance. */ val endButton: Flow<KeyguardQuickAffordanceViewModel> = @@ -194,6 +200,14 @@ constructor( } else { button(KeyguardQuickAffordancePosition.BOTTOM_END) } + .stateIn( + scope = applicationScope, + started = SharingStarted.WhileSubscribed(), + initialValue = + KeyguardQuickAffordanceViewModel( + slotId = KeyguardQuickAffordancePosition.BOTTOM_END.toSlotId() + ), + ) /** * Notifies that a slot with the given ID has been selected in the preview experience that is diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordancesCombinedViewModelModule.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordancesCombinedViewModelModule.kt new file mode 100644 index 000000000000..fceacc982606 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardQuickAffordancesCombinedViewModelModule.kt @@ -0,0 +1,37 @@ +/* + * 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.systemui.keyguard.ui.viewmodel + +import com.android.systemui.dagger.SysUISingleton +import dagger.Binds +import dagger.Module +import javax.inject.Named + +@Module +interface KeyguardQuickAffordancesCombinedViewModelModule { + companion object { + const val LOCKSCREEN_INSTANCE = "lockscreen_instance" + } + + @SysUISingleton + @Binds + @Named(LOCKSCREEN_INSTANCE) + fun provideKeyguardQuickAffordancesCombinedViewModel( + model: KeyguardQuickAffordancesCombinedViewModel + ): KeyguardQuickAffordancesCombinedViewModel +} diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java b/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java index ed766469094e..4be9c5d1bdb6 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java @@ -584,7 +584,7 @@ public class LogModule { @SysUISingleton @KeyguardQuickAffordancesLog public static LogBuffer provideKeyguardQuickAffordancesLogBuffer(LogBufferFactory factory) { - return factory.create("KeyguardQuickAffordancesLog", 25); + return factory.create("KeyguardQuickAffordancesLog", 100); } /** |