diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/DeviceEntryIconViewBinder.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/DeviceEntryIconViewBinder.kt index 873cc847fa6097c71e295f49f65533cceac1bf66..f46a207b273ac5cfc869b098acd6c7912960747b 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/DeviceEntryIconViewBinder.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/DeviceEntryIconViewBinder.kt @@ -22,6 +22,7 @@ import android.content.res.ColorStateList import android.util.StateSet import android.view.HapticFeedbackConstants import android.view.View +import androidx.core.view.isInvisible import androidx.lifecycle.Lifecycle import androidx.lifecycle.repeatOnLifecycle import com.android.systemui.common.ui.view.LongPressHandlingView @@ -81,6 +82,11 @@ object DeviceEntryIconViewBinder { // GONE => AOD transition (even though the view may not be visible until the middle // of the transition. repeatOnLifecycle(Lifecycle.State.CREATED) { + launch { + viewModel.isVisible.collect { isVisible -> + longPressHandlingView.isInvisible = !isVisible + } + } launch { viewModel.isLongPressEnabled.collect { isEnabled -> longPressHandlingView.setLongPressHandlingEnabled(isEnabled) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/DeviceEntryIconViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/DeviceEntryIconViewModel.kt index c9cf0c31a8fd0febd595873926068633a383f341..31e809356e02e89f6cb6184083474a5574d7628b 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/DeviceEntryIconViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/DeviceEntryIconViewModel.kt @@ -37,6 +37,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.delay import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flowOf @@ -206,6 +207,7 @@ constructor( DeviceEntryIconView.IconType.LOCK } } + val isVisible: Flow<Boolean> = deviceEntryViewAlpha.map { it > 0f }.distinctUntilChanged() val isLongPressEnabled: Flow<Boolean> = combine( iconType, @@ -217,6 +219,7 @@ constructor( DeviceEntryIconView.IconType.FINGERPRINT -> false } } + val accessibilityDelegateHint: Flow<DeviceEntryIconView.AccessibilityHintType> = combine(iconType, isLongPressEnabled) { deviceEntryStatus, longPressEnabled -> if (longPressEnabled) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/DeviceEntryIconViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/DeviceEntryIconViewModelTest.kt new file mode 100644 index 0000000000000000000000000000000000000000..02bd810a43d5464947c25ab7b6a33201c91d3d3c --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/viewmodel/DeviceEntryIconViewModelTest.kt @@ -0,0 +1,110 @@ +/* + * 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 androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.SmallTest +import com.android.systemui.SysuiTestCase +import com.android.systemui.biometrics.data.repository.FakeFingerprintPropertyRepository +import com.android.systemui.biometrics.data.repository.fingerprintPropertyRepository +import com.android.systemui.coroutines.collectLastValue +import com.android.systemui.keyguard.data.repository.FakeDeviceEntryFingerprintAuthRepository +import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository +import com.android.systemui.keyguard.data.repository.fakeDeviceEntryFingerprintAuthRepository +import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository +import com.android.systemui.keyguard.data.repository.keyguardRepository +import com.android.systemui.kosmos.testScope +import com.android.systemui.testKosmos +import com.google.common.truth.Truth.assertThat +import kotlin.test.Test +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.test.runTest +import org.junit.Before +import org.junit.runner.RunWith + +@ExperimentalCoroutinesApi +@SmallTest +@RunWith(AndroidJUnit4::class) +class DeviceEntryIconViewModelTest : SysuiTestCase() { + private val kosmos = testKosmos() + private val testScope = kosmos.testScope + private lateinit var keyguardRepository: FakeKeyguardRepository + private lateinit var fingerprintPropertyRepository: FakeFingerprintPropertyRepository + private lateinit var fingerprintAuthRepository: FakeDeviceEntryFingerprintAuthRepository + private lateinit var deviceEntryIconTransition: FakeDeviceEntryIconTransition + private lateinit var underTest: DeviceEntryIconViewModel + + @Before + fun setUp() { + keyguardRepository = kosmos.fakeKeyguardRepository + fingerprintPropertyRepository = kosmos.fingerprintPropertyRepository + fingerprintAuthRepository = kosmos.fakeDeviceEntryFingerprintAuthRepository + deviceEntryIconTransition = kosmos.fakeDeviceEntryIconViewModelTransition + underTest = kosmos.deviceEntryIconViewModel + } + + @Test + fun isLongPressEnabled_udfpsRunning() = + testScope.runTest { + val isLongPressEnabled by collectLastValue(underTest.isLongPressEnabled) + fingerprintPropertyRepository.supportsUdfps() + fingerprintAuthRepository.setIsRunning(true) + keyguardRepository.setKeyguardDismissible(false) + assertThat(isLongPressEnabled).isFalse() + } + + @Test + fun isLongPressEnabled_unlocked() = + testScope.runTest { + val isLongPressEnabled by collectLastValue(underTest.isLongPressEnabled) + keyguardRepository.setKeyguardDismissible(true) + assertThat(isLongPressEnabled).isTrue() + } + + @Test + fun isLongPressEnabled_lock() = + testScope.runTest { + val isLongPressEnabled by collectLastValue(underTest.isLongPressEnabled) + keyguardRepository.setKeyguardDismissible(false) + + // udfps supported + fingerprintPropertyRepository.supportsUdfps() + assertThat(isLongPressEnabled).isTrue() + + // udfps isn't supported + fingerprintPropertyRepository.supportsRearFps() + assertThat(isLongPressEnabled).isFalse() + } + + @Test + fun isVisible() = + testScope.runTest { + val isVisible by collectLastValue(underTest.isVisible) + deviceEntryIconTransitionAlpha(1f) + assertThat(isVisible).isTrue() + + deviceEntryIconTransitionAlpha(0f) + assertThat(isVisible).isFalse() + + deviceEntryIconTransitionAlpha(.5f) + assertThat(isVisible).isTrue() + } + + private fun deviceEntryIconTransitionAlpha(alpha: Float) { + deviceEntryIconTransition.setDeviceEntryParentViewAlpha(alpha) + } +}