diff options
| author | 2020-02-25 06:10:49 +0000 | |
|---|---|---|
| committer | 2020-02-25 06:10:49 +0000 | |
| commit | b76d7aa6bca464f918babdc55007bf0b9cf507df (patch) | |
| tree | 9f16941e20b3b87292faef3c86a44f980739a5e4 | |
| parent | 20ea7f52584f10febe5fa3e2a11a2cd6012438c2 (diff) | |
| parent | 1223bcaf0c03e30e7935e57d784eb194eda6ca60 (diff) | |
Merge "Remove key from adb_keys if user forgets the key." into rvc-dev
| -rw-r--r-- | services/core/java/com/android/server/adb/AdbDebuggingManager.java | 1 | ||||
| -rw-r--r-- | services/tests/servicestests/src/com/android/server/adb/AdbDebuggingManagerTest.java | 25 |
2 files changed, 26 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/adb/AdbDebuggingManager.java b/services/core/java/com/android/server/adb/AdbDebuggingManager.java index 6c68c312bbde..e49357bee896 100644 --- a/services/core/java/com/android/server/adb/AdbDebuggingManager.java +++ b/services/core/java/com/android/server/adb/AdbDebuggingManager.java @@ -1853,6 +1853,7 @@ public class AdbDebuggingManager { public void removeKey(String key) { if (mKeyMap.containsKey(key)) { mKeyMap.remove(key); + writeKeys(mKeyMap.keySet()); sendPersistKeyStoreMessage(); } } diff --git a/services/tests/servicestests/src/com/android/server/adb/AdbDebuggingManagerTest.java b/services/tests/servicestests/src/com/android/server/adb/AdbDebuggingManagerTest.java index 5a1ad8655ab0..757a2b1280f3 100644 --- a/services/tests/servicestests/src/com/android/server/adb/AdbDebuggingManagerTest.java +++ b/services/tests/servicestests/src/com/android/server/adb/AdbDebuggingManagerTest.java @@ -696,6 +696,31 @@ public final class AdbDebuggingManagerTest { mAdbKeyXmlFile.exists()); } + @Test + public void testAdbKeyStore_removeKey() throws Exception { + // Accept the test key with the 'Always allow' option selected. + runAdbTest(TEST_KEY_1, true, true, false); + runAdbTest(TEST_KEY_2, true, true, false); + + // Set the connection time to 0 to restore the original behavior. + setAllowedConnectionTime(0); + + // Verify that the key is in the adb_keys file to ensure subsequent connections are + // automatically allowed by adbd. + persistKeyStore(); + assertTrue("The key was not in the adb_keys file after persisting the keystore", + isKeyInFile(TEST_KEY_1, mAdbKeyFile)); + assertTrue("The key was not in the adb_keys file after persisting the keystore", + isKeyInFile(TEST_KEY_2, mAdbKeyFile)); + + // Now remove one of the keys and make sure the other key is still there + mKeyStore.removeKey(TEST_KEY_1); + assertFalse("The key was still in the adb_keys file after removing the key", + isKeyInFile(TEST_KEY_1, mAdbKeyFile)); + assertTrue("The key was not in the adb_keys file after removing a different key", + isKeyInFile(TEST_KEY_2, mAdbKeyFile)); + } + /** * Runs an adb test with the provided configuration. * |