Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7aa222d7 authored by Beverly Tai's avatar Beverly Tai Committed by Android (Google) Code Review
Browse files

Merge "Always render the device entry icon white in AOD" into main

parents e992e5c2 75b779e8
Loading
Loading
Loading
Loading
+65 −0
Original line number Diff line number Diff line
/*
 * 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 android.graphics.Color
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.coroutines.collectLastValue
import com.android.systemui.keyguard.data.repository.fakeBiometricSettingsRepository
import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.kosmos.testScope
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.junit.Test
import org.junit.runner.RunWith

@ExperimentalCoroutinesApi
@SmallTest
@RunWith(AndroidJUnit4::class)
class DeviceEntryForegroundViewModelTest : SysuiTestCase() {
    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope
    private val underTest: DeviceEntryForegroundViewModel =
        kosmos.deviceEntryForegroundIconViewModel

    @Test
    fun aodIconColorWhite() =
        testScope.runTest {
            val viewModel by collectLastValue(underTest.viewModel)

            givenUdfpsEnrolledAndEnabled()
            kosmos.fakeKeyguardTransitionRepository.sendTransitionSteps(
                from = KeyguardState.LOCKSCREEN,
                to = KeyguardState.AOD,
                testScope = testScope,
            )

            assertThat(viewModel?.useAodVariant).isEqualTo(true)
            assertThat(viewModel?.tint).isEqualTo(Color.WHITE)
        }

    private fun givenUdfpsEnrolledAndEnabled() {
        kosmos.fakeFingerprintPropertyRepository.supportsUdfps()
        kosmos.fakeBiometricSettingsRepository.setIsFingerprintAuthEnrolledAndEnabled(true)
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -88,6 +88,12 @@ constructor(
            }
    }

    /**
     * Setups different icon states.
     * - All lottie views will require a LottieOnCompositionLoadedListener to update
     *   LottieProperties (like color) of the view.
     * - Drawable properties can be updated using ImageView properties like imageTintList.
     */
    private fun setupIconStates() {
        // Lockscreen States
        // LOCK
+16 −7
Original line number Diff line number Diff line
@@ -64,13 +64,6 @@ constructor(
        }
    }

    private val color: Flow<Int> =
        deviceEntryIconViewModel.useBackgroundProtection.flatMapLatest { useBgProtection ->
            configurationInteractor.onAnyConfigurationChange
                .map { getColor(useBgProtection) }
                .onStart { emit(getColor(useBgProtection)) }
        }

    // While dozing, the display can show the AOD UI; show the AOD udfps when dozing
    private val useAodIconVariant: Flow<Boolean> =
        deviceEntryUdfpsInteractor.isUdfpsEnrolledAndEnabled.flatMapLatest { udfspEnrolled ->
@@ -81,6 +74,22 @@ constructor(
            }
        }

    private val color: Flow<Int> =
        useAodIconVariant
            .flatMapLatest { useAodVariant ->
                if (useAodVariant) {
                    flowOf(android.graphics.Color.WHITE)
                } else {
                    deviceEntryIconViewModel.useBackgroundProtection.flatMapLatest { useBgProtection
                        ->
                        configurationInteractor.onAnyConfigurationChange
                            .map { getColor(useBgProtection) }
                            .onStart { emit(getColor(useBgProtection)) }
                    }
                }
            }
            .distinctUntilChanged()

    private val padding: Flow<Int> =
        deviceEntryUdfpsInteractor.isUdfpsSupported.flatMapLatest { udfpsSupported ->
            if (udfpsSupported) {