diff options
| author | 2025-03-03 14:29:58 +0000 | |
|---|---|---|
| committer | 2025-03-05 10:56:17 +0000 | |
| commit | 7f125e22f427d8040f4370cb098dc75585c3d0f9 (patch) | |
| tree | 164fe6b856015a6dbc7c3450da8cda1ca034a3f0 | |
| parent | d88f8f54e31c6e4e01d2f73f7167d4f1d3481864 (diff) | |
Extract chip creation outside of the main chip flow.
This is in preparation of a new version of the chip flow that fully
leverages the new `isHidden` field and enables return animations.
Bug: 202516970
Flag: EXEMPT moving code only
Test: atest CallChipViewModelTest
Change-Id: Ia09a2b34ffce0b0c82ae8faefb84f14c7ce7c66d
2 files changed, 58 insertions, 59 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/chips/call/ui/viewmodel/CallChipViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/chips/call/ui/viewmodel/CallChipViewModelTest.kt index fda4ab005446..f45b44a4cc1b 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/chips/call/ui/viewmodel/CallChipViewModelTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/chips/call/ui/viewmodel/CallChipViewModelTest.kt @@ -27,6 +27,7 @@ import com.android.systemui.animation.Expandable import com.android.systemui.common.shared.model.ContentDescription.Companion.loadContentDescription import com.android.systemui.common.shared.model.Icon import com.android.systemui.coroutines.collectLastValue +import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runTest import com.android.systemui.kosmos.useUnconfinedTestDispatcher @@ -71,7 +72,7 @@ class CallChipViewModelTest : SysuiTestCase() { private val mockExpandable: Expandable = mock<Expandable>().apply { whenever(dialogTransitionController(any())).thenReturn(mock()) } - private val underTest by lazy { kosmos.callChipViewModel } + private val Kosmos.underTest by Kosmos.Fixture { callChipViewModel } @Test fun chip_noCall_isHidden() = diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/chips/call/ui/viewmodel/CallChipViewModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/chips/call/ui/viewmodel/CallChipViewModel.kt index be3afad4e1d1..baf26c19595d 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/chips/call/ui/viewmodel/CallChipViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/chips/call/ui/viewmodel/CallChipViewModel.kt @@ -16,6 +16,7 @@ package com.android.systemui.statusbar.chips.call.ui.viewmodel +import android.app.PendingIntent import android.content.Context import android.view.View import com.android.internal.jank.Cuj @@ -65,61 +66,63 @@ constructor( when (state) { is OngoingCallModel.NoCall, is OngoingCallModel.InCallWithVisibleApp -> OngoingActivityChipModel.Inactive() - is OngoingCallModel.InCall -> { - val key = state.notificationKey - val contentDescription = getContentDescription(state.appName) - val icon = - if (state.notificationIconView != null) { - StatusBarConnectedDisplays.assertInLegacyMode() - OngoingActivityChipModel.ChipIcon.StatusBarView( - state.notificationIconView, - contentDescription, - ) - } else if (StatusBarConnectedDisplays.isEnabled) { - OngoingActivityChipModel.ChipIcon.StatusBarNotificationIcon( - state.notificationKey, - contentDescription, - ) - } else { - OngoingActivityChipModel.ChipIcon.SingleColorIcon(phoneIcon) - } - - val colors = ColorsModel.AccentThemed - - // This block mimics OngoingCallController#updateChip. - if (state.startTimeMs <= 0L) { - // If the start time is invalid, don't show a timer and show just an - // icon. See b/192379214. - OngoingActivityChipModel.Active.IconOnly( - key = key, - icon = icon, - colors = colors, - onClickListenerLegacy = getOnClickListener(state), - clickBehavior = getClickBehavior(state), - ) - } else { - val startTimeInElapsedRealtime = - state.startTimeMs - systemClock.currentTimeMillis() + - systemClock.elapsedRealtime() - OngoingActivityChipModel.Active.Timer( - key = key, - icon = icon, - colors = colors, - startTimeMs = startTimeInElapsedRealtime, - onClickListenerLegacy = getOnClickListener(state), - clickBehavior = getClickBehavior(state), - ) - } - } + is OngoingCallModel.InCall -> prepareChip(state, systemClock) } } .stateIn(scope, SharingStarted.WhileSubscribed(), OngoingActivityChipModel.Inactive()) - private fun getOnClickListener(state: OngoingCallModel.InCall): View.OnClickListener? { - if (state.intent == null) { - return null + /** Builds an [OngoingActivityChipModel.Active] from all the relevant information. */ + private fun prepareChip( + state: OngoingCallModel.InCall, + systemClock: SystemClock, + ): OngoingActivityChipModel.Active { + val key = state.notificationKey + val contentDescription = getContentDescription(state.appName) + val icon = + if (state.notificationIconView != null) { + StatusBarConnectedDisplays.assertInLegacyMode() + OngoingActivityChipModel.ChipIcon.StatusBarView( + state.notificationIconView, + contentDescription, + ) + } else if (StatusBarConnectedDisplays.isEnabled) { + OngoingActivityChipModel.ChipIcon.StatusBarNotificationIcon( + state.notificationKey, + contentDescription, + ) + } else { + OngoingActivityChipModel.ChipIcon.SingleColorIcon(phoneIcon) + } + + val colors = ColorsModel.AccentThemed + + // This block mimics OngoingCallController#updateChip. + if (state.startTimeMs <= 0L) { + // If the start time is invalid, don't show a timer and show just an icon. + // See b/192379214. + return OngoingActivityChipModel.Active.IconOnly( + key = key, + icon = icon, + colors = colors, + onClickListenerLegacy = getOnClickListener(state.intent), + clickBehavior = getClickBehavior(state.intent), + ) + } else { + val startTimeInElapsedRealtime = + state.startTimeMs - systemClock.currentTimeMillis() + systemClock.elapsedRealtime() + return OngoingActivityChipModel.Active.Timer( + key = key, + icon = icon, + colors = colors, + startTimeMs = startTimeInElapsedRealtime, + onClickListenerLegacy = getOnClickListener(state.intent), + clickBehavior = getClickBehavior(state.intent), + ) } + } + private fun getOnClickListener(intent: PendingIntent?): View.OnClickListener? { + if (intent == null) return null return View.OnClickListener { view -> StatusBarChipsModernization.assertInLegacyMode() logger.log(TAG, LogLevel.INFO, {}, { "Chip clicked" }) @@ -127,7 +130,7 @@ constructor( view.requireViewById<ChipBackgroundContainer>(R.id.ongoing_activity_chip_background) // This mimics OngoingCallController#updateChipClickListener. activityStarter.postStartActivityDismissingKeyguard( - state.intent, + intent, ActivityTransitionAnimator.Controller.fromView( backgroundView, Cuj.CUJ_STATUS_BAR_APP_LAUNCH_FROM_CALL_CHIP, @@ -136,10 +139,8 @@ constructor( } } - private fun getClickBehavior( - state: OngoingCallModel.InCall - ): OngoingActivityChipModel.ClickBehavior = - if (state.intent == null) { + private fun getClickBehavior(intent: PendingIntent?): OngoingActivityChipModel.ClickBehavior = + if (intent == null) { OngoingActivityChipModel.ClickBehavior.None } else { OngoingActivityChipModel.ClickBehavior.ExpandAction( @@ -149,10 +150,7 @@ constructor( expandable.activityTransitionController( Cuj.CUJ_STATUS_BAR_APP_LAUNCH_FROM_CALL_CHIP ) - activityStarter.postStartActivityDismissingKeyguard( - state.intent, - animationController, - ) + activityStarter.postStartActivityDismissingKeyguard(intent, animationController) } ) } |