Cache TrustManager#isTrustUsuallyManaged
Test: atest KeyguardUpdateMonitorTest Fixes: 140053364 Change-Id: Ic06125490ddbe35aef5558b5bc78d1495426821d
This commit is contained in:
@@ -58,6 +58,7 @@ import android.content.IntentFilter;
|
||||
import android.content.pm.IPackageManager;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.database.ContentObserver;
|
||||
import android.hardware.biometrics.BiometricManager;
|
||||
import android.hardware.biometrics.BiometricSourceType;
|
||||
@@ -329,6 +330,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
|
||||
private SparseBooleanArray mUserIsUnlocked = new SparseBooleanArray();
|
||||
private SparseBooleanArray mUserHasTrust = new SparseBooleanArray();
|
||||
private SparseBooleanArray mUserTrustIsManaged = new SparseBooleanArray();
|
||||
private SparseBooleanArray mUserTrustIsUsuallyManaged = new SparseBooleanArray();
|
||||
private SparseBooleanArray mUserFingerprintAuthenticated = new SparseBooleanArray();
|
||||
private SparseBooleanArray mUserFaceAuthenticated = new SparseBooleanArray();
|
||||
private SparseBooleanArray mUserFaceUnlockRunning = new SparseBooleanArray();
|
||||
@@ -472,6 +474,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
|
||||
public void onTrustManagedChanged(boolean managed, int userId) {
|
||||
checkIsHandlerThread();
|
||||
mUserTrustIsManaged.put(userId, managed);
|
||||
mUserTrustIsUsuallyManaged.put(userId, mTrustManager.isTrustUsuallyManaged(userId));
|
||||
for (int i = 0; i < mCallbacks.size(); i++) {
|
||||
KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
|
||||
if (cb != null) {
|
||||
@@ -925,6 +928,14 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
|
||||
return mUserTrustIsManaged.get(userId) && !isTrustDisabled(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cached version of {@link TrustManager#isTrustUsuallyManaged(int)}.
|
||||
*/
|
||||
public boolean isTrustUsuallyManaged(int userId) {
|
||||
checkIsHandlerThread();
|
||||
return mUserTrustIsUsuallyManaged.get(userId);
|
||||
}
|
||||
|
||||
public boolean isUnlockingWithBiometricAllowed() {
|
||||
return mStrongAuthTracker.isUnlockingWithBiometricAllowed();
|
||||
}
|
||||
@@ -1474,9 +1485,11 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
|
||||
mUserIsUnlocked.put(userId, mUserManager.isUserUnlocked(userId));
|
||||
}
|
||||
|
||||
private void handleUserRemoved(int userId) {
|
||||
@VisibleForTesting
|
||||
void handleUserRemoved(int userId) {
|
||||
checkIsHandlerThread();
|
||||
mUserIsUnlocked.delete(userId);
|
||||
mUserTrustIsUsuallyManaged.delete(userId);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -1662,7 +1675,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
|
||||
e.rethrowAsRuntimeException();
|
||||
}
|
||||
|
||||
mTrustManager = (TrustManager) context.getSystemService(Context.TRUST_SERVICE);
|
||||
mTrustManager = context.getSystemService(TrustManager.class);
|
||||
mTrustManager.registerTrustListener(this);
|
||||
mLockPatternUtils = new LockPatternUtils(context);
|
||||
mLockPatternUtils.registerStrongAuthTracker(mStrongAuthTracker);
|
||||
@@ -1697,6 +1710,11 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
|
||||
mUserIsUnlocked.put(user, mUserManager.isUserUnlocked(user));
|
||||
mDevicePolicyManager = context.getSystemService(DevicePolicyManager.class);
|
||||
mLogoutEnabled = mDevicePolicyManager.isLogoutEnabled();
|
||||
List<UserInfo> allUsers = mUserManager.getUsers();
|
||||
for (UserInfo userInfo : allUsers) {
|
||||
mUserTrustIsUsuallyManaged.put(userInfo.id,
|
||||
mTrustManager.isTrustUsuallyManaged(userInfo.id));
|
||||
}
|
||||
updateAirplaneModeState();
|
||||
|
||||
TelephonyManager telephony =
|
||||
@@ -2048,6 +2066,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
|
||||
*/
|
||||
private void handleUserSwitching(int userId, IRemoteCallback reply) {
|
||||
checkIsHandlerThread();
|
||||
mUserTrustIsUsuallyManaged.put(userId, mTrustManager.isTrustUsuallyManaged(userId));
|
||||
for (int i = 0; i < mCallbacks.size(); i++) {
|
||||
KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
|
||||
if (cb != null) {
|
||||
|
||||
@@ -648,29 +648,26 @@ public class KeyguardViewMediator extends SystemUI {
|
||||
|
||||
@Override
|
||||
public int getBouncerPromptReason() {
|
||||
// TODO(b/140053364)
|
||||
return whitelistIpcs(() -> {
|
||||
int currentUser = ActivityManager.getCurrentUser();
|
||||
boolean trust = mTrustManager.isTrustUsuallyManaged(currentUser);
|
||||
boolean biometrics = mUpdateMonitor.isUnlockingWithBiometricsPossible(currentUser);
|
||||
boolean any = trust || biometrics;
|
||||
KeyguardUpdateMonitor.StrongAuthTracker strongAuthTracker =
|
||||
mUpdateMonitor.getStrongAuthTracker();
|
||||
int strongAuth = strongAuthTracker.getStrongAuthForUser(currentUser);
|
||||
int currentUser = KeyguardUpdateMonitor.getCurrentUser();
|
||||
boolean trust = mUpdateMonitor.isTrustUsuallyManaged(currentUser);
|
||||
boolean biometrics = mUpdateMonitor.isUnlockingWithBiometricsPossible(currentUser);
|
||||
boolean any = trust || biometrics;
|
||||
KeyguardUpdateMonitor.StrongAuthTracker strongAuthTracker =
|
||||
mUpdateMonitor.getStrongAuthTracker();
|
||||
int strongAuth = strongAuthTracker.getStrongAuthForUser(currentUser);
|
||||
|
||||
if (any && !strongAuthTracker.hasUserAuthenticatedSinceBoot()) {
|
||||
return KeyguardSecurityView.PROMPT_REASON_RESTART;
|
||||
} else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_TIMEOUT) != 0) {
|
||||
return KeyguardSecurityView.PROMPT_REASON_TIMEOUT;
|
||||
} else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW) != 0) {
|
||||
return KeyguardSecurityView.PROMPT_REASON_DEVICE_ADMIN;
|
||||
} else if (trust && (strongAuth & SOME_AUTH_REQUIRED_AFTER_USER_REQUEST) != 0) {
|
||||
return KeyguardSecurityView.PROMPT_REASON_USER_REQUEST;
|
||||
} else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_LOCKOUT) != 0) {
|
||||
return KeyguardSecurityView.PROMPT_REASON_AFTER_LOCKOUT;
|
||||
}
|
||||
return KeyguardSecurityView.PROMPT_REASON_NONE;
|
||||
});
|
||||
if (any && !strongAuthTracker.hasUserAuthenticatedSinceBoot()) {
|
||||
return KeyguardSecurityView.PROMPT_REASON_RESTART;
|
||||
} else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_TIMEOUT) != 0) {
|
||||
return KeyguardSecurityView.PROMPT_REASON_TIMEOUT;
|
||||
} else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW) != 0) {
|
||||
return KeyguardSecurityView.PROMPT_REASON_DEVICE_ADMIN;
|
||||
} else if (trust && (strongAuth & SOME_AUTH_REQUIRED_AFTER_USER_REQUEST) != 0) {
|
||||
return KeyguardSecurityView.PROMPT_REASON_USER_REQUEST;
|
||||
} else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_LOCKOUT) != 0) {
|
||||
return KeyguardSecurityView.PROMPT_REASON_AFTER_LOCKOUT;
|
||||
}
|
||||
return KeyguardSecurityView.PROMPT_REASON_NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -699,7 +696,7 @@ public class KeyguardViewMediator extends SystemUI {
|
||||
|
||||
private void setupLocked() {
|
||||
mPM = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
|
||||
mTrustManager = (TrustManager) mContext.getSystemService(Context.TRUST_SERVICE);
|
||||
mTrustManager = mContext.getSystemService(TrustManager.class);
|
||||
|
||||
mShowKeyguardWakeLock = mPM.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "show keyguard");
|
||||
mShowKeyguardWakeLock.setReferenceCounted(false);
|
||||
|
||||
@@ -25,6 +25,7 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.clearInvocations;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -481,6 +482,25 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
|
||||
assertThat(mKeyguardUpdateMonitor.isUserUnlocked(randomUser)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTrustUsuallyManaged_whenTrustChanges() {
|
||||
int user = KeyguardUpdateMonitor.getCurrentUser();
|
||||
when(mTrustManager.isTrustUsuallyManaged(eq(user))).thenReturn(true);
|
||||
mKeyguardUpdateMonitor.onTrustManagedChanged(false /* managed */, user);
|
||||
assertThat(mKeyguardUpdateMonitor.isTrustUsuallyManaged(user)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTrustUsuallyManaged_resetWhenUserIsRemoved() {
|
||||
int user = KeyguardUpdateMonitor.getCurrentUser();
|
||||
when(mTrustManager.isTrustUsuallyManaged(eq(user))).thenReturn(true);
|
||||
mKeyguardUpdateMonitor.onTrustManagedChanged(false /* managed */, user);
|
||||
assertThat(mKeyguardUpdateMonitor.isTrustUsuallyManaged(user)).isTrue();
|
||||
|
||||
mKeyguardUpdateMonitor.handleUserRemoved(user);
|
||||
assertThat(mKeyguardUpdateMonitor.isTrustUsuallyManaged(user)).isFalse();
|
||||
}
|
||||
|
||||
private Intent putPhoneInfo(Intent intent, Bundle data, Boolean simInited) {
|
||||
int subscription = simInited
|
||||
? 1/* mock subid=1 */ : SubscriptionManager.DUMMY_SUBSCRIPTION_ID_BASE;
|
||||
|
||||
Reference in New Issue
Block a user