diff options
| author | 2023-10-18 23:50:43 +0000 | |
|---|---|---|
| committer | 2023-10-18 23:50:43 +0000 | |
| commit | 985c8dcf0469345d73b493f50a6799077dc33716 (patch) | |
| tree | f4d9cf4058fa7f7834aaf6dd4fc363848d65172c | |
| parent | 884bd680119f3d5cac96dd6431f0d943a5f5a1c0 (diff) | |
| parent | c4fff832da564ff509677802f4fbd1abb2c4aa37 (diff) | |
Merge "Unlock non-secure users automatically (1/2)" into main
5 files changed, 28 insertions, 26 deletions
diff --git a/core/java/com/android/internal/widget/ILockSettings.aidl b/core/java/com/android/internal/widget/ILockSettings.aidl index 406505517bcc..82367834f93d 100644 --- a/core/java/com/android/internal/widget/ILockSettings.aidl +++ b/core/java/com/android/internal/widget/ILockSettings.aidl @@ -108,4 +108,5 @@ interface ILockSettings { boolean removeWeakEscrowToken(long handle, int userId); boolean isWeakEscrowTokenActive(long handle, int userId); boolean isWeakEscrowTokenValid(long handle, in byte[] token, int userId); + void unlockUserKeyIfUnsecured(int userId); } diff --git a/core/java/com/android/internal/widget/LockPatternUtils.java b/core/java/com/android/internal/widget/LockPatternUtils.java index d5b8f62aaf2b..a3e27062fa7b 100644 --- a/core/java/com/android/internal/widget/LockPatternUtils.java +++ b/core/java/com/android/internal/widget/LockPatternUtils.java @@ -1933,8 +1933,23 @@ public class LockPatternUtils { } } + /** + * Unlocks the credential-encrypted storage for the given user if the user is not secured, i.e. + * doesn't have an LSKF. + * <p> + * Whether the storage has been unlocked can be determined by + * {@link StorageManager#isUserKeyUnlocked()}. + * + * Requires the {@link android.Manifest.permission#ACCESS_KEYGUARD_SECURE_STORAGE} permission. + * + * @param userId the ID of the user whose storage to unlock + */ public void unlockUserKeyIfUnsecured(@UserIdInt int userId) { - getLockSettingsInternal().unlockUserKeyIfUnsecured(userId); + try { + getLockSettings().unlockUserKeyIfUnsecured(userId); + } catch (RemoteException re) { + re.rethrowFromSystemServer(); + } } public void createNewUser(@UserIdInt int userId, int userSerialNumber) { diff --git a/core/java/com/android/internal/widget/LockSettingsInternal.java b/core/java/com/android/internal/widget/LockSettingsInternal.java index 6063c90d6ab9..8114e1fd3bb0 100644 --- a/core/java/com/android/internal/widget/LockSettingsInternal.java +++ b/core/java/com/android/internal/widget/LockSettingsInternal.java @@ -60,17 +60,6 @@ public abstract class LockSettingsInternal { public abstract void onThirdPartyAppsStarted(); /** - * Unlocks the credential-encrypted storage for the given user if the user is not secured, i.e. - * doesn't have an LSKF. - * <p> - * This doesn't throw an exception on failure; whether the storage has been unlocked can be - * determined by {@link StorageManager#isUserKeyUnlocked()}. - * - * @param userId the ID of the user whose storage to unlock - */ - public abstract void unlockUserKeyIfUnsecured(@UserIdInt int userId); - - /** * Creates the locksettings state for a new user. * <p> * This includes creating a synthetic password and protecting it with an empty LSKF. diff --git a/services/core/java/com/android/server/locksettings/LockSettingsService.java b/services/core/java/com/android/server/locksettings/LockSettingsService.java index f92d46ce502d..4ccc554f1fe1 100644 --- a/services/core/java/com/android/server/locksettings/LockSettingsService.java +++ b/services/core/java/com/android/server/locksettings/LockSettingsService.java @@ -2047,7 +2047,9 @@ public class LockSettingsService extends ILockSettings.Stub { } } - private void unlockUserKeyIfUnsecured(@UserIdInt int userId) { + @Override + public void unlockUserKeyIfUnsecured(@UserIdInt int userId) { + checkPasswordReadPermission(); synchronized (mSpManager) { if (isUserKeyUnlocked(userId)) { Slogf.d(TAG, "CE storage for user %d is already unlocked", userId); @@ -3456,11 +3458,6 @@ public class LockSettingsService extends ILockSettings.Stub { } @Override - public void unlockUserKeyIfUnsecured(@UserIdInt int userId) { - LockSettingsService.this.unlockUserKeyIfUnsecured(userId); - } - - @Override public void createNewUser(@UserIdInt int userId, int userSerialNumber) { LockSettingsService.this.createNewUser(userId, userSerialNumber); } diff --git a/services/tests/servicestests/src/com/android/server/locksettings/SyntheticPasswordTests.java b/services/tests/servicestests/src/com/android/server/locksettings/SyntheticPasswordTests.java index 37a6d22f038b..eca19c8e8c4d 100644 --- a/services/tests/servicestests/src/com/android/server/locksettings/SyntheticPasswordTests.java +++ b/services/tests/servicestests/src/com/android/server/locksettings/SyntheticPasswordTests.java @@ -255,7 +255,7 @@ public class SyntheticPasswordTests extends BaseLockSettingsServiceTests { public void testUnlockUserKeyIfUnsecuredPassesPrimaryUserAuthSecret() throws RemoteException { initSpAndSetCredential(PRIMARY_USER_ID, newPassword(null)); reset(mAuthSecretService); - mLocalService.unlockUserKeyIfUnsecured(PRIMARY_USER_ID); + mService.unlockUserKeyIfUnsecured(PRIMARY_USER_ID); verify(mAuthSecretService).setPrimaryUserCredential(any(byte[].class)); } @@ -267,7 +267,7 @@ public class SyntheticPasswordTests extends BaseLockSettingsServiceTests { mService.setLockCredential(nonePassword(), password, PRIMARY_USER_ID); reset(mAuthSecretService); - mLocalService.unlockUserKeyIfUnsecured(PRIMARY_USER_ID); + mService.unlockUserKeyIfUnsecured(PRIMARY_USER_ID); verify(mAuthSecretService).setPrimaryUserCredential(any(byte[].class)); } @@ -285,39 +285,39 @@ public class SyntheticPasswordTests extends BaseLockSettingsServiceTests { @Test public void testHeadlessSystemUserDoesNotPassAuthSecret() throws RemoteException { setupHeadlessTest(); - mLocalService.unlockUserKeyIfUnsecured(PRIMARY_USER_ID); + mService.unlockUserKeyIfUnsecured(PRIMARY_USER_ID); verify(mAuthSecretService, never()).setPrimaryUserCredential(any(byte[].class)); } @Test public void testHeadlessSecondaryUserPassesAuthSecret() throws RemoteException { setupHeadlessTest(); - mLocalService.unlockUserKeyIfUnsecured(SECONDARY_USER_ID); + mService.unlockUserKeyIfUnsecured(SECONDARY_USER_ID); verify(mAuthSecretService).setPrimaryUserCredential(any(byte[].class)); } @Test public void testHeadlessTertiaryUserPassesSameAuthSecret() throws RemoteException { setupHeadlessTest(); - mLocalService.unlockUserKeyIfUnsecured(SECONDARY_USER_ID); + mService.unlockUserKeyIfUnsecured(SECONDARY_USER_ID); var captor = ArgumentCaptor.forClass(byte[].class); verify(mAuthSecretService).setPrimaryUserCredential(captor.capture()); var value = captor.getValue(); reset(mAuthSecretService); - mLocalService.unlockUserKeyIfUnsecured(TERTIARY_USER_ID); + mService.unlockUserKeyIfUnsecured(TERTIARY_USER_ID); verify(mAuthSecretService).setPrimaryUserCredential(eq(value)); } @Test public void testHeadlessTertiaryUserPassesSameAuthSecretAfterReset() throws RemoteException { setupHeadlessTest(); - mLocalService.unlockUserKeyIfUnsecured(SECONDARY_USER_ID); + mService.unlockUserKeyIfUnsecured(SECONDARY_USER_ID); var captor = ArgumentCaptor.forClass(byte[].class); verify(mAuthSecretService).setPrimaryUserCredential(captor.capture()); var value = captor.getValue(); mService.clearAuthSecret(); reset(mAuthSecretService); - mLocalService.unlockUserKeyIfUnsecured(TERTIARY_USER_ID); + mService.unlockUserKeyIfUnsecured(TERTIARY_USER_ID); verify(mAuthSecretService).setPrimaryUserCredential(eq(value)); } |