Update KUM usage of primaryUser to systemUser

KeyguardUpdateMonitor only wants to run fingerprint
and face listening state from the systemUser. PrimaryUser
usage is deprecated.

The DeviceEntryFaceAuthRepository doesn't need to check for
the primary user. Instead, the FaceAuth triggers should only
be running in the system user (as all SystemUI CoreStartables
are done that aren't "@PerUser").

Test: atest KeyguardUpdateMonitorTest DeviceEntryFaceAuthRepositoryTest
Bug: 264869291
Change-Id: Idb49fc652182bcba9393af3c7b1f1eb968e417e3
This commit is contained in:
Beverly
2023-04-12 16:50:24 +00:00
parent 844c5aec48
commit 002b09c340
6 changed files with 42 additions and 57 deletions

View File

@@ -41,10 +41,10 @@ data class KeyguardFaceListenModel(
var listeningForFaceAssistant: Boolean = false,
var occludingAppRequestingFaceAuth: Boolean = false,
var postureAllowsListening: Boolean = false,
var primaryUser: Boolean = false,
var secureCameraLaunched: Boolean = false,
var supportsDetect: Boolean = false,
var switchingUser: Boolean = false,
var systemUser: Boolean = false,
var udfpsFingerDown: Boolean = false,
var userNotTrustedOrDetectionIsNeeded: Boolean = false,
) : KeyguardListenModel() {
@@ -69,11 +69,11 @@ data class KeyguardFaceListenModel(
keyguardGoingAway.toString(),
listeningForFaceAssistant.toString(),
occludingAppRequestingFaceAuth.toString(),
primaryUser.toString(),
postureAllowsListening.toString(),
secureCameraLaunched.toString(),
supportsDetect.toString(),
switchingUser.toString(),
systemUser.toString(),
alternateBouncerShowing.toString(),
udfpsFingerDown.toString(),
userNotTrustedOrDetectionIsNeeded.toString(),
@@ -109,12 +109,11 @@ data class KeyguardFaceListenModel(
keyguardGoingAway = model.keyguardGoingAway
listeningForFaceAssistant = model.listeningForFaceAssistant
occludingAppRequestingFaceAuth = model.occludingAppRequestingFaceAuth
primaryUser = model.primaryUser
postureAllowsListening = model.postureAllowsListening
secureCameraLaunched = model.secureCameraLaunched
supportsDetect = model.supportsDetect
switchingUser = model.switchingUser
switchingUser = model.switchingUser
systemUser = model.systemUser
udfpsFingerDown = model.udfpsFingerDown
userNotTrustedOrDetectionIsNeeded = model.userNotTrustedOrDetectionIsNeeded
}
@@ -153,11 +152,11 @@ data class KeyguardFaceListenModel(
"keyguardGoingAway",
"listeningForFaceAssistant",
"occludingAppRequestingFaceAuth",
"primaryUser",
"postureAllowsListening",
"secureCameraLaunched",
"supportsDetect",
"switchingUser",
"systemUser",
"udfpsBouncerShowing",
"udfpsFingerDown",
"userNotTrustedOrDetectionIsNeeded",

View File

@@ -41,11 +41,11 @@ data class KeyguardFingerprintListenModel(
var keyguardIsVisible: Boolean = false,
var keyguardOccluded: Boolean = false,
var occludingAppRequestingFp: Boolean = false,
var primaryUser: Boolean = false,
var shouldListenSfpsState: Boolean = false,
var shouldListenForFingerprintAssistant: Boolean = false,
var strongerAuthRequired: Boolean = false,
var switchingUser: Boolean = false,
var systemUser: Boolean = false,
var udfps: Boolean = false,
var userDoesNotHaveTrust: Boolean = false,
) : KeyguardListenModel() {
@@ -72,11 +72,11 @@ data class KeyguardFingerprintListenModel(
keyguardIsVisible.toString(),
keyguardOccluded.toString(),
occludingAppRequestingFp.toString(),
primaryUser.toString(),
shouldListenSfpsState.toString(),
shouldListenForFingerprintAssistant.toString(),
strongerAuthRequired.toString(),
switchingUser.toString(),
systemUser.toString(),
udfps.toString(),
userDoesNotHaveTrust.toString(),
)
@@ -112,11 +112,11 @@ data class KeyguardFingerprintListenModel(
keyguardIsVisible = model.keyguardIsVisible
keyguardOccluded = model.keyguardOccluded
occludingAppRequestingFp = model.occludingAppRequestingFp
primaryUser = model.primaryUser
shouldListenSfpsState = model.shouldListenSfpsState
shouldListenForFingerprintAssistant = model.shouldListenForFingerprintAssistant
strongerAuthRequired = model.strongerAuthRequired
switchingUser = model.switchingUser
systemUser = model.systemUser
udfps = model.udfps
userDoesNotHaveTrust = model.userDoesNotHaveTrust
}
@@ -158,11 +158,11 @@ data class KeyguardFingerprintListenModel(
"keyguardIsVisible",
"keyguardOccluded",
"occludingAppRequestingFp",
"primaryUser",
"shouldListenSidFingerprintState",
"shouldListenForFingerprintAssistant",
"strongAuthRequired",
"switchingUser",
"systemUser",
"underDisplayFingerprint",
"userDoesNotHaveTrust",
)

View File

@@ -296,7 +296,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
private final Context mContext;
private final UserTracker mUserTracker;
private final KeyguardUpdateMonitorLogger mLogger;
private final boolean mIsPrimaryUser;
private final boolean mIsSystemUser;
private final AuthController mAuthController;
private final UiEventLogger mUiEventLogger;
private final Set<Integer> mFaceAcquiredInfoIgnoreList;
@@ -2514,7 +2514,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
updateBiometricListeningState(BIOMETRIC_ACTION_UPDATE, FACE_AUTH_UPDATED_ON_KEYGUARD_INIT);
TaskStackChangeListeners.getInstance().registerTaskStackListener(mTaskStackListener);
mIsPrimaryUser = mUserManager.isPrimaryUser();
mIsSystemUser = mUserManager.isSystemUser();
int user = mUserTracker.getUserId();
mUserIsUnlocked.put(user, mUserManager.isUserUnlocked(user));
mLogoutEnabled = mDevicePolicyManager.isLogoutEnabled();
@@ -2960,7 +2960,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
|| (mKeyguardOccluded && userDoesNotHaveTrust && mKeyguardShowing
&& (mOccludingAppRequestingFp || isUdfps || mAlternateBouncerShowing));
// Only listen if this KeyguardUpdateMonitor belongs to the primary user. There is an
// Only listen if this KeyguardUpdateMonitor belongs to the system user. There is an
// instance of KeyguardUpdateMonitor for each user but KeyguardUpdateMonitor is user-aware.
final boolean biometricEnabledForUser = mBiometricEnabledForUser.get(user);
final boolean userCanSkipBouncer = getUserCanSkipBouncer(user);
@@ -2969,7 +2969,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
!mSwitchingUser
&& !fingerprintDisabledForUser
&& (!mKeyguardGoingAway || !mDeviceInteractive)
&& mIsPrimaryUser
&& mIsSystemUser
&& biometricEnabledForUser
&& !isUserInLockdown(user);
final boolean strongerAuthRequired = !isUnlockingWithFingerprintAllowed();
@@ -3013,11 +3013,11 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
isKeyguardVisible(),
mKeyguardOccluded,
mOccludingAppRequestingFp,
mIsPrimaryUser,
shouldListenSideFpsState,
shouldListenForFingerprintAssistant,
strongerAuthRequired,
mSwitchingUser,
mIsSystemUser,
isUdfps,
userDoesNotHaveTrust));
@@ -3062,7 +3062,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
final boolean shouldListenForFaceAssistant = shouldListenForFaceAssistant();
final boolean isUdfpsFingerDown = mAuthController.isUdfpsFingerDown();
final boolean isPostureAllowedForFaceAuth = doesPostureAllowFaceAuth(mPostureState);
// Only listen if this KeyguardUpdateMonitor belongs to the primary user. There is an
// Only listen if this KeyguardUpdateMonitor belongs to the system user. There is an
// instance of KeyguardUpdateMonitor for each user but KeyguardUpdateMonitor is user-aware.
final boolean shouldListen =
(mPrimaryBouncerFullyShown
@@ -3074,7 +3074,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
|| mAlternateBouncerShowing)
&& !mSwitchingUser && !faceDisabledForUser && userNotTrustedOrDetectionIsNeeded
&& !mKeyguardGoingAway && biometricEnabledForUser
&& faceAuthAllowedOrDetectionIsNeeded && mIsPrimaryUser
&& faceAuthAllowedOrDetectionIsNeeded && mIsSystemUser
&& (!mSecureCameraLaunched || mAlternateBouncerShowing)
&& faceAndFpNotAuthenticated
&& !mGoingToSleep
@@ -3100,10 +3100,10 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
shouldListenForFaceAssistant,
mOccludingAppRequestingFace,
isPostureAllowedForFaceAuth,
mIsPrimaryUser,
mSecureCameraLaunched,
supportsDetect,
mSwitchingUser,
mIsSystemUser,
isUdfpsFingerDown,
userNotTrustedOrDetectionIsNeeded));

View File

@@ -334,11 +334,6 @@ constructor(
"nonStrongBiometricIsAllowed",
faceAuthLog
),
logAndObserve(
userRepository.selectedUserInfo.map { it.isPrimary },
"userIsPrimaryUser",
faceAuthLog
),
)
.reduce(::and)
.distinctUntilChanged()

View File

@@ -290,7 +290,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
when(mSessionTracker.getSessionId(SESSION_KEYGUARD)).thenReturn(mKeyguardInstanceId);
when(mUserManager.isUserUnlocked(anyInt())).thenReturn(true);
when(mUserManager.isPrimaryUser()).thenReturn(true);
currentUserIsSystem();
when(mStrongAuthTracker.getStub()).thenReturn(mock(IStrongAuthTracker.Stub.class));
when(mStrongAuthTracker
.isUnlockingWithBiometricAllowed(anyBoolean() /* isClass3Biometric */))
@@ -958,7 +958,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
public void requestFaceAuth_whenFaceAuthWasStarted_returnsTrue() throws RemoteException {
// This satisfies all the preconditions to run face auth.
keyguardNotGoingAway();
currentUserIsPrimary();
currentUserIsSystem();
currentUserDoesNotHaveTrust();
biometricsNotDisabledThroughDevicePolicyManager();
biometricsEnabledForCurrentUser();
@@ -1465,7 +1465,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
// Preconditions for sfps auth to run
keyguardNotGoingAway();
currentUserIsPrimary();
currentUserIsSystem();
currentUserDoesNotHaveTrust();
biometricsNotDisabledThroughDevicePolicyManager();
biometricsEnabledForCurrentUser();
@@ -1501,7 +1501,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
// GIVEN Preconditions for sfps auth to run
keyguardNotGoingAway();
currentUserIsPrimary();
currentUserIsSystem();
currentUserDoesNotHaveTrust();
biometricsNotDisabledThroughDevicePolicyManager();
biometricsEnabledForCurrentUser();
@@ -1530,7 +1530,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
// GIVEN Preconditions for sfps auth to run
keyguardNotGoingAway();
currentUserIsPrimary();
currentUserIsSystem();
currentUserDoesNotHaveTrust();
biometricsNotDisabledThroughDevicePolicyManager();
biometricsEnabledForCurrentUser();
@@ -1682,7 +1682,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
// Face auth should run when the following is true.
keyguardNotGoingAway();
occludingAppRequestsFaceAuth();
currentUserIsPrimary();
currentUserIsSystem();
primaryAuthNotRequiredByStrongAuthTracker();
biometricsEnabledForCurrentUser();
currentUserDoesNotHaveTrust();
@@ -1703,7 +1703,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
// Face auth should run when the following is true.
bouncerFullyVisibleAndNotGoingToSleep();
keyguardNotGoingAway();
currentUserIsPrimary();
currentUserIsSystem();
primaryAuthNotRequiredByStrongAuthTracker();
biometricsEnabledForCurrentUser();
currentUserDoesNotHaveTrust();
@@ -1726,7 +1726,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
// Face auth should run when the following is true.
bouncerFullyVisibleAndNotGoingToSleep();
keyguardNotGoingAway();
currentUserIsPrimary();
currentUserIsSystem();
primaryAuthNotRequiredByStrongAuthTracker();
biometricsEnabledForCurrentUser();
currentUserDoesNotHaveTrust();
@@ -1747,7 +1747,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
public void testShouldListenForFace_whenUserIsNotPrimary_returnsFalse() throws RemoteException {
cleanupKeyguardUpdateMonitor();
// This disables face auth
when(mUserManager.isPrimaryUser()).thenReturn(false);
when(mUserManager.isSystemUser()).thenReturn(false);
mKeyguardUpdateMonitor =
new TestableKeyguardUpdateMonitor(mContext);
@@ -1771,7 +1771,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
// Face auth should run when the following is true.
keyguardNotGoingAway();
bouncerFullyVisibleAndNotGoingToSleep();
currentUserIsPrimary();
currentUserIsSystem();
biometricsEnabledForCurrentUser();
currentUserDoesNotHaveTrust();
biometricsNotDisabledThroughDevicePolicyManager();
@@ -1789,7 +1789,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
throws RemoteException {
keyguardNotGoingAway();
bouncerFullyVisibleAndNotGoingToSleep();
currentUserIsPrimary();
currentUserIsSystem();
currentUserDoesNotHaveTrust();
biometricsNotDisabledThroughDevicePolicyManager();
biometricsEnabledForCurrentUser();
@@ -1811,7 +1811,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
// Face auth should run when the following is true.
keyguardNotGoingAway();
bouncerFullyVisibleAndNotGoingToSleep();
currentUserIsPrimary();
currentUserIsSystem();
currentUserDoesNotHaveTrust();
biometricsNotDisabledThroughDevicePolicyManager();
biometricsEnabledForCurrentUser();
@@ -1831,7 +1831,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
throws RemoteException {
keyguardNotGoingAway();
bouncerFullyVisibleAndNotGoingToSleep();
currentUserIsPrimary();
currentUserIsSystem();
currentUserDoesNotHaveTrust();
biometricsNotDisabledThroughDevicePolicyManager();
biometricsEnabledForCurrentUser();
@@ -1852,7 +1852,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
// Face auth should run when the following is true.
keyguardNotGoingAway();
bouncerFullyVisibleAndNotGoingToSleep();
currentUserIsPrimary();
currentUserIsSystem();
currentUserDoesNotHaveTrust();
biometricsNotDisabledThroughDevicePolicyManager();
biometricsEnabledForCurrentUser();
@@ -1874,7 +1874,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
throws RemoteException {
// Face auth should run when the following is true.
keyguardNotGoingAway();
currentUserIsPrimary();
currentUserIsSystem();
currentUserDoesNotHaveTrust();
biometricsNotDisabledThroughDevicePolicyManager();
biometricsEnabledForCurrentUser();
@@ -1894,7 +1894,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
throws RemoteException {
// Face auth should run when the following is true.
keyguardNotGoingAway();
currentUserIsPrimary();
currentUserIsSystem();
currentUserDoesNotHaveTrust();
biometricsNotDisabledThroughDevicePolicyManager();
biometricsEnabledForCurrentUser();
@@ -1913,7 +1913,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
public void testShouldListenForFace_whenKeyguardIsAwake_returnsTrue() throws RemoteException {
// Preconditions for face auth to run
keyguardNotGoingAway();
currentUserIsPrimary();
currentUserIsSystem();
currentUserDoesNotHaveTrust();
biometricsNotDisabledThroughDevicePolicyManager();
biometricsEnabledForCurrentUser();
@@ -1938,7 +1938,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
public void testShouldListenForFace_whenUdfpsFingerDown_returnsTrue() throws RemoteException {
// Preconditions for face auth to run
keyguardNotGoingAway();
currentUserIsPrimary();
currentUserIsSystem();
currentUserDoesNotHaveTrust();
biometricsNotDisabledThroughDevicePolicyManager();
biometricsEnabledForCurrentUser();
@@ -1957,7 +1957,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
throws RemoteException {
// Preconditions for face auth to run
keyguardNotGoingAway();
currentUserIsPrimary();
currentUserIsSystem();
currentUserDoesNotHaveTrust();
biometricsNotDisabledThroughDevicePolicyManager();
biometricsEnabledForCurrentUser();
@@ -1975,7 +1975,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
throws RemoteException {
// Preconditions for face auth to run
keyguardNotGoingAway();
currentUserIsPrimary();
currentUserIsSystem();
currentUserDoesNotHaveTrust();
biometricsNotDisabledThroughDevicePolicyManager();
biometricsEnabledForCurrentUser();
@@ -2000,7 +2000,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
throws RemoteException {
// Preconditions for face auth to run
keyguardNotGoingAway();
currentUserIsPrimary();
currentUserIsSystem();
currentUserDoesNotHaveTrust();
biometricsNotDisabledThroughDevicePolicyManager();
biometricsEnabledForCurrentUser();
@@ -2322,7 +2322,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
throws RemoteException {
keyguardNotGoingAway();
bouncerFullyVisibleAndNotGoingToSleep();
currentUserIsPrimary();
currentUserIsSystem();
currentUserDoesNotHaveTrust();
biometricsNotDisabledThroughDevicePolicyManager();
biometricsEnabledForCurrentUser();
@@ -2453,7 +2453,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
mKeyguardUpdateMonitor.mConfigFaceAuthSupportedPosture = DEVICE_POSTURE_CLOSED;
keyguardNotGoingAway();
bouncerFullyVisibleAndNotGoingToSleep();
currentUserIsPrimary();
currentUserIsSystem();
currentUserDoesNotHaveTrust();
biometricsNotDisabledThroughDevicePolicyManager();
biometricsEnabledForCurrentUser();
@@ -2477,7 +2477,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
mKeyguardUpdateMonitor.mConfigFaceAuthSupportedPosture = DEVICE_POSTURE_UNKNOWN;
keyguardNotGoingAway();
bouncerFullyVisibleAndNotGoingToSleep();
currentUserIsPrimary();
currentUserIsSystem();
currentUserDoesNotHaveTrust();
biometricsNotDisabledThroughDevicePolicyManager();
biometricsEnabledForCurrentUser();
@@ -2888,8 +2888,8 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
new FaceManager.AuthenticationResult(null, null, mCurrentUserId, false));
}
private void currentUserIsPrimary() {
when(mUserManager.isPrimaryUser()).thenReturn(true);
private void currentUserIsSystem() {
when(mUserManager.isSystemUser()).thenReturn(true);
}
private void biometricsNotDisabledThroughDevicePolicyManager() {

View File

@@ -68,7 +68,6 @@ import com.google.common.truth.Truth.assertThat
import java.io.PrintWriter
import java.io.StringWriter
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.TestDispatcher
import kotlinx.coroutines.test.TestScope
@@ -532,14 +531,6 @@ class DeviceEntryFaceAuthRepositoryTest : SysuiTestCase() {
}
}
@Test
fun authenticateDoesNotRunWhenCurrentUserIsNotPrimary() =
testScope.runTest {
testGatingCheckForFaceAuth {
launch { fakeUserRepository.setSelectedUserInfo(secondaryUser) }
}
}
@Test
fun authenticateDoesNotRunWhenSecureCameraIsActive() =
testScope.runTest {