Loading packages/SystemUI/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -268,6 +268,7 @@ filegroup { "tests/src/com/android/systemui/keyguard/ui/viewmodel/PrimaryBouncerToGoneTransitionViewModelTest.kt", // Keyguard helper "tests/src/com/android/systemui/keyguard/data/quickaffordance/FakeKeyguardQuickAffordanceConfig.kt", "tests/src/com/android/systemui/dock/DockManagerFake.java", "tests/src/com/android/systemui/dump/LogBufferHelper.kt", "tests/src/com/android/systemui/statusbar/phone/FakeKeyguardStateController.java", "tests/src/com/android/systemui/keyguard/domain/quickaffordance/FakeKeyguardQuickAffordanceRegistry.kt", Loading packages/SystemUI/src/com/android/systemui/dock/DockManagerExtensions.kt 0 → 100644 +34 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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.dock import com.android.systemui.common.coroutine.ConflatedCallbackFlow import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow /** * Retrieves whether or not the device is docked according to DockManager. Emits a starting value * of isDocked. */ fun DockManager.retrieveIsDocked(): Flow<Boolean> = ConflatedCallbackFlow.conflatedCallbackFlow { val callback = DockManager.DockEventListener { trySend(isDocked) } addListener(callback) trySend(isDocked) awaitClose { removeListener(callback) } } No newline at end of file packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardQuickAffordanceInteractor.kt +9 −2 Original line number Diff line number Diff line Loading @@ -27,6 +27,8 @@ import com.android.systemui.animation.Expandable import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Background import com.android.systemui.devicepolicy.areKeyguardShortcutsDisabled import com.android.systemui.dock.DockManager import com.android.systemui.dock.retrieveIsDocked import com.android.systemui.flags.FeatureFlags import com.android.systemui.flags.Flags import com.android.systemui.keyguard.data.quickaffordance.KeyguardQuickAffordanceConfig Loading Loading @@ -71,6 +73,7 @@ constructor( private val launchAnimator: DialogLaunchAnimator, private val logger: KeyguardQuickAffordancesMetricsLogger, private val devicePolicyManager: DevicePolicyManager, private val dockManager: DockManager, @Background private val backgroundDispatcher: CoroutineDispatcher, ) { private val isUsingRepository: Boolean Loading @@ -81,8 +84,12 @@ constructor( * * If `false`, the UI goes back to using single taps. */ val useLongPress: Boolean get() = featureFlags.isEnabled(Flags.CUSTOMIZABLE_LOCK_SCREEN_QUICK_AFFORDANCES) fun useLongPress(): Flow<Boolean> = if (featureFlags.isEnabled(Flags.CUSTOMIZABLE_LOCK_SCREEN_QUICK_AFFORDANCES)) { dockManager.retrieveIsDocked().map { !it } } else { flowOf(false) } /** Returns an observable for the quick affordance at the given position. */ suspend fun quickAffordance( Loading packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBottomAreaViewModel.kt +5 −2 Original line number Diff line number Diff line Loading @@ -184,7 +184,8 @@ constructor( bottomAreaInteractor.animateDozingTransitions.distinctUntilChanged(), areQuickAffordancesFullyOpaque, selectedPreviewSlotId, ) { model, animateReveal, isFullyOpaque, selectedPreviewSlotId -> quickAffordanceInteractor.useLongPress(), ) { model, animateReveal, isFullyOpaque, selectedPreviewSlotId, useLongPress -> val slotId = position.toSlotId() val isSelected = selectedPreviewSlotId == slotId model.toViewModel( Loading @@ -200,6 +201,7 @@ constructor( !isSelected, forceInactive = previewMode.isInPreviewMode, slotId = slotId, useLongPress = useLongPress, ) } .distinctUntilChanged() Loading @@ -213,6 +215,7 @@ constructor( isDimmed: Boolean, forceInactive: Boolean, slotId: String, useLongPress: Boolean, ): KeyguardQuickAffordanceViewModel { return when (this) { is KeyguardQuickAffordanceModel.Visible -> Loading @@ -231,7 +234,7 @@ constructor( isClickable = isClickable, isActivated = !forceInactive && activationState is ActivationState.Active, isSelected = isSelected, useLongPress = quickAffordanceInteractor.useLongPress, useLongPress = useLongPress, isDimmed = isDimmed, slotId = slotId, ) Loading packages/SystemUI/tests/src/com/android/systemui/keyguard/CustomizationProviderTest.kt +6 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import com.android.internal.widget.LockPatternUtils import com.android.systemui.SystemUIAppComponentFactoryBase import com.android.systemui.SysuiTestCase import com.android.systemui.animation.DialogLaunchAnimator import com.android.systemui.dock.DockManagerFake import com.android.systemui.flags.FakeFeatureFlags import com.android.systemui.flags.Flags import com.android.systemui.keyguard.data.quickaffordance.FakeKeyguardQuickAffordanceConfig Loading Loading @@ -94,6 +95,8 @@ class CustomizationProviderTest : SysuiTestCase() { @Mock private lateinit var devicePolicyManager: DevicePolicyManager @Mock private lateinit var logger: KeyguardQuickAffordancesMetricsLogger private lateinit var dockManager: DockManagerFake private lateinit var underTest: CustomizationProvider private lateinit var testScope: TestScope Loading @@ -104,6 +107,8 @@ class CustomizationProviderTest : SysuiTestCase() { whenever(previewRendererFactory.create(any())).thenReturn(previewRenderer) whenever(backgroundHandler.looper).thenReturn(TestableLooper.get(this).looper) dockManager = DockManagerFake() underTest = CustomizationProvider() val testDispatcher = UnconfinedTestDispatcher() testScope = TestScope(testDispatcher) Loading Loading @@ -188,6 +193,7 @@ class CustomizationProviderTest : SysuiTestCase() { launchAnimator = launchAnimator, logger = logger, devicePolicyManager = devicePolicyManager, dockManager = dockManager, backgroundDispatcher = testDispatcher, ) underTest.previewManager = Loading Loading
packages/SystemUI/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -268,6 +268,7 @@ filegroup { "tests/src/com/android/systemui/keyguard/ui/viewmodel/PrimaryBouncerToGoneTransitionViewModelTest.kt", // Keyguard helper "tests/src/com/android/systemui/keyguard/data/quickaffordance/FakeKeyguardQuickAffordanceConfig.kt", "tests/src/com/android/systemui/dock/DockManagerFake.java", "tests/src/com/android/systemui/dump/LogBufferHelper.kt", "tests/src/com/android/systemui/statusbar/phone/FakeKeyguardStateController.java", "tests/src/com/android/systemui/keyguard/domain/quickaffordance/FakeKeyguardQuickAffordanceRegistry.kt", Loading
packages/SystemUI/src/com/android/systemui/dock/DockManagerExtensions.kt 0 → 100644 +34 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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.dock import com.android.systemui.common.coroutine.ConflatedCallbackFlow import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow /** * Retrieves whether or not the device is docked according to DockManager. Emits a starting value * of isDocked. */ fun DockManager.retrieveIsDocked(): Flow<Boolean> = ConflatedCallbackFlow.conflatedCallbackFlow { val callback = DockManager.DockEventListener { trySend(isDocked) } addListener(callback) trySend(isDocked) awaitClose { removeListener(callback) } } No newline at end of file
packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardQuickAffordanceInteractor.kt +9 −2 Original line number Diff line number Diff line Loading @@ -27,6 +27,8 @@ import com.android.systemui.animation.Expandable import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Background import com.android.systemui.devicepolicy.areKeyguardShortcutsDisabled import com.android.systemui.dock.DockManager import com.android.systemui.dock.retrieveIsDocked import com.android.systemui.flags.FeatureFlags import com.android.systemui.flags.Flags import com.android.systemui.keyguard.data.quickaffordance.KeyguardQuickAffordanceConfig Loading Loading @@ -71,6 +73,7 @@ constructor( private val launchAnimator: DialogLaunchAnimator, private val logger: KeyguardQuickAffordancesMetricsLogger, private val devicePolicyManager: DevicePolicyManager, private val dockManager: DockManager, @Background private val backgroundDispatcher: CoroutineDispatcher, ) { private val isUsingRepository: Boolean Loading @@ -81,8 +84,12 @@ constructor( * * If `false`, the UI goes back to using single taps. */ val useLongPress: Boolean get() = featureFlags.isEnabled(Flags.CUSTOMIZABLE_LOCK_SCREEN_QUICK_AFFORDANCES) fun useLongPress(): Flow<Boolean> = if (featureFlags.isEnabled(Flags.CUSTOMIZABLE_LOCK_SCREEN_QUICK_AFFORDANCES)) { dockManager.retrieveIsDocked().map { !it } } else { flowOf(false) } /** Returns an observable for the quick affordance at the given position. */ suspend fun quickAffordance( Loading
packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardBottomAreaViewModel.kt +5 −2 Original line number Diff line number Diff line Loading @@ -184,7 +184,8 @@ constructor( bottomAreaInteractor.animateDozingTransitions.distinctUntilChanged(), areQuickAffordancesFullyOpaque, selectedPreviewSlotId, ) { model, animateReveal, isFullyOpaque, selectedPreviewSlotId -> quickAffordanceInteractor.useLongPress(), ) { model, animateReveal, isFullyOpaque, selectedPreviewSlotId, useLongPress -> val slotId = position.toSlotId() val isSelected = selectedPreviewSlotId == slotId model.toViewModel( Loading @@ -200,6 +201,7 @@ constructor( !isSelected, forceInactive = previewMode.isInPreviewMode, slotId = slotId, useLongPress = useLongPress, ) } .distinctUntilChanged() Loading @@ -213,6 +215,7 @@ constructor( isDimmed: Boolean, forceInactive: Boolean, slotId: String, useLongPress: Boolean, ): KeyguardQuickAffordanceViewModel { return when (this) { is KeyguardQuickAffordanceModel.Visible -> Loading @@ -231,7 +234,7 @@ constructor( isClickable = isClickable, isActivated = !forceInactive && activationState is ActivationState.Active, isSelected = isSelected, useLongPress = quickAffordanceInteractor.useLongPress, useLongPress = useLongPress, isDimmed = isDimmed, slotId = slotId, ) Loading
packages/SystemUI/tests/src/com/android/systemui/keyguard/CustomizationProviderTest.kt +6 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import com.android.internal.widget.LockPatternUtils import com.android.systemui.SystemUIAppComponentFactoryBase import com.android.systemui.SysuiTestCase import com.android.systemui.animation.DialogLaunchAnimator import com.android.systemui.dock.DockManagerFake import com.android.systemui.flags.FakeFeatureFlags import com.android.systemui.flags.Flags import com.android.systemui.keyguard.data.quickaffordance.FakeKeyguardQuickAffordanceConfig Loading Loading @@ -94,6 +95,8 @@ class CustomizationProviderTest : SysuiTestCase() { @Mock private lateinit var devicePolicyManager: DevicePolicyManager @Mock private lateinit var logger: KeyguardQuickAffordancesMetricsLogger private lateinit var dockManager: DockManagerFake private lateinit var underTest: CustomizationProvider private lateinit var testScope: TestScope Loading @@ -104,6 +107,8 @@ class CustomizationProviderTest : SysuiTestCase() { whenever(previewRendererFactory.create(any())).thenReturn(previewRenderer) whenever(backgroundHandler.looper).thenReturn(TestableLooper.get(this).looper) dockManager = DockManagerFake() underTest = CustomizationProvider() val testDispatcher = UnconfinedTestDispatcher() testScope = TestScope(testDispatcher) Loading Loading @@ -188,6 +193,7 @@ class CustomizationProviderTest : SysuiTestCase() { launchAnimator = launchAnimator, logger = logger, devicePolicyManager = devicePolicyManager, dockManager = dockManager, backgroundDispatcher = testDispatcher, ) underTest.previewManager = Loading