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

Commit 75b779e8 authored by Beverly's avatar Beverly
Browse files

Always render the device entry icon white in AOD

Previously this was only an issue when the lock icon showed
on AOD but not for the AOD fingerprint icon because the AOD fingerprint icon uses a lottie view.

Lottie drawables don't use the `imageTintList` property for color,
so the lottie aod fp icon would always render white (the lottie
drawable default color from its json file).

Fixes: 341855923
Flag: com.android.systemui.device_entry_udfps_refactor
Test: atest DeviceEntryForegroundViewModelTest
Test: enroll UDFPS; enable aod; enable light mode;
lock down device; see lock icon is white in AOD

Change-Id: I527d9615e42c8274a0b927abaf76808766a621e2
parent 29f30aa3
Loading
Loading
Loading
Loading
+65 −0
Original line number Original line 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 Original line 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() {
    private fun setupIconStates() {
        // Lockscreen States
        // Lockscreen States
        // LOCK
        // LOCK
+16 −7
Original line number Original line 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
    // While dozing, the display can show the AOD UI; show the AOD udfps when dozing
    private val useAodIconVariant: Flow<Boolean> =
    private val useAodIconVariant: Flow<Boolean> =
        deviceEntryUdfpsInteractor.isUdfpsEnrolledAndEnabled.flatMapLatest { udfspEnrolled ->
        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> =
    private val padding: Flow<Int> =
        deviceEntryUdfpsInteractor.isUdfpsSupported.flatMapLatest { udfpsSupported ->
        deviceEntryUdfpsInteractor.isUdfpsSupported.flatMapLatest { udfpsSupported ->
            if (udfpsSupported) {
            if (udfpsSupported) {