Loading services/core/java/com/android/server/locksettings/recoverablekeystore/RecoverableKeyStoreManager.java +18 −2 Original line number Diff line number Diff line Loading @@ -382,10 +382,26 @@ public class RecoverableKeyStoreManager { Preconditions.checkNotNull(secretTypes, "secretTypes is null"); int userId = UserHandle.getCallingUserId(); int uid = Binder.getCallingUid(); int[] currentSecretTypes = mDatabase.getRecoverySecretTypes(userId, uid); if (Arrays.equals(secretTypes, currentSecretTypes)) { Log.v(TAG, "Not updating secret types - same as old value."); return; } long updatedRows = mDatabase.setRecoverySecretTypes(userId, uid, secretTypes); if (updatedRows > 0) { mDatabase.setShouldCreateSnapshot(userId, uid, true); if (updatedRows < 1) { throw new ServiceSpecificException(ERROR_SERVICE_INTERNAL_ERROR, "Database error trying to set secret types."); } if (currentSecretTypes.length == 0) { Log.i(TAG, "Initialized secret types."); return; } Log.i(TAG, "Updated secret types. Snapshot pending."); mDatabase.setShouldCreateSnapshot(userId, uid, true); } /** Loading services/tests/servicestests/src/com/android/server/locksettings/recoverablekeystore/RecoverableKeyStoreManagerTest.java +36 −1 Original line number Diff line number Diff line Loading @@ -879,7 +879,7 @@ public class RecoverableKeyStoreManagerTest { } @Test public void setRecoverySecretTypes() throws Exception { public void setRecoverySecretTypes_updatesSecretTypes() throws Exception { int[] types1 = new int[]{11, 2000}; int[] types2 = new int[]{1, 2, 3}; int[] types3 = new int[]{}; Loading @@ -897,6 +897,41 @@ public class RecoverableKeyStoreManagerTest { types3); } @Test public void setRecoverySecretTypes_doesNotSetSnapshotPendingIfIniting() throws Exception { int uid = Binder.getCallingUid(); int userId = UserHandle.getCallingUserId(); int[] secretTypes = new int[] { 101 }; mRecoverableKeyStoreManager.setRecoverySecretTypes(secretTypes); assertThat(mRecoverableKeyStoreDb.getShouldCreateSnapshot(userId, uid)).isFalse(); } @Test public void setRecoverySecretTypes_doesNotSetSnapshotPendingIfSettingSameValue() throws Exception { int uid = Binder.getCallingUid(); int userId = UserHandle.getCallingUserId(); int[] secretTypes = new int[] { 101 }; mRecoverableKeyStoreManager.setRecoverySecretTypes(secretTypes); mRecoverableKeyStoreManager.setRecoverySecretTypes(secretTypes); assertThat(mRecoverableKeyStoreDb.getShouldCreateSnapshot(userId, uid)).isFalse(); } @Test public void setRecoverySecretTypes_setsSnapshotPendingIfUpdatingValue() throws Exception { int uid = Binder.getCallingUid(); int userId = UserHandle.getCallingUserId(); mRecoverableKeyStoreManager.setRecoverySecretTypes(new int[] { 101 }); mRecoverableKeyStoreManager.setRecoverySecretTypes(new int[] { 102 }); assertThat(mRecoverableKeyStoreDb.getShouldCreateSnapshot(userId, uid)).isTrue(); } @Test public void setRecoverySecretTypes_throwsIfNullTypes() throws Exception { try { Loading Loading
services/core/java/com/android/server/locksettings/recoverablekeystore/RecoverableKeyStoreManager.java +18 −2 Original line number Diff line number Diff line Loading @@ -382,10 +382,26 @@ public class RecoverableKeyStoreManager { Preconditions.checkNotNull(secretTypes, "secretTypes is null"); int userId = UserHandle.getCallingUserId(); int uid = Binder.getCallingUid(); int[] currentSecretTypes = mDatabase.getRecoverySecretTypes(userId, uid); if (Arrays.equals(secretTypes, currentSecretTypes)) { Log.v(TAG, "Not updating secret types - same as old value."); return; } long updatedRows = mDatabase.setRecoverySecretTypes(userId, uid, secretTypes); if (updatedRows > 0) { mDatabase.setShouldCreateSnapshot(userId, uid, true); if (updatedRows < 1) { throw new ServiceSpecificException(ERROR_SERVICE_INTERNAL_ERROR, "Database error trying to set secret types."); } if (currentSecretTypes.length == 0) { Log.i(TAG, "Initialized secret types."); return; } Log.i(TAG, "Updated secret types. Snapshot pending."); mDatabase.setShouldCreateSnapshot(userId, uid, true); } /** Loading
services/tests/servicestests/src/com/android/server/locksettings/recoverablekeystore/RecoverableKeyStoreManagerTest.java +36 −1 Original line number Diff line number Diff line Loading @@ -879,7 +879,7 @@ public class RecoverableKeyStoreManagerTest { } @Test public void setRecoverySecretTypes() throws Exception { public void setRecoverySecretTypes_updatesSecretTypes() throws Exception { int[] types1 = new int[]{11, 2000}; int[] types2 = new int[]{1, 2, 3}; int[] types3 = new int[]{}; Loading @@ -897,6 +897,41 @@ public class RecoverableKeyStoreManagerTest { types3); } @Test public void setRecoverySecretTypes_doesNotSetSnapshotPendingIfIniting() throws Exception { int uid = Binder.getCallingUid(); int userId = UserHandle.getCallingUserId(); int[] secretTypes = new int[] { 101 }; mRecoverableKeyStoreManager.setRecoverySecretTypes(secretTypes); assertThat(mRecoverableKeyStoreDb.getShouldCreateSnapshot(userId, uid)).isFalse(); } @Test public void setRecoverySecretTypes_doesNotSetSnapshotPendingIfSettingSameValue() throws Exception { int uid = Binder.getCallingUid(); int userId = UserHandle.getCallingUserId(); int[] secretTypes = new int[] { 101 }; mRecoverableKeyStoreManager.setRecoverySecretTypes(secretTypes); mRecoverableKeyStoreManager.setRecoverySecretTypes(secretTypes); assertThat(mRecoverableKeyStoreDb.getShouldCreateSnapshot(userId, uid)).isFalse(); } @Test public void setRecoverySecretTypes_setsSnapshotPendingIfUpdatingValue() throws Exception { int uid = Binder.getCallingUid(); int userId = UserHandle.getCallingUserId(); mRecoverableKeyStoreManager.setRecoverySecretTypes(new int[] { 101 }); mRecoverableKeyStoreManager.setRecoverySecretTypes(new int[] { 102 }); assertThat(mRecoverableKeyStoreDb.getShouldCreateSnapshot(userId, uid)).isTrue(); } @Test public void setRecoverySecretTypes_throwsIfNullTypes() throws Exception { try { Loading