Remove key from adb_keys if user forgets the key. am: f7378376ca

Change-Id: Ic9d70066ffc9012475e6d1e42039e53849b7c850
This commit is contained in:
Automerger Merge Worker
2020-02-26 21:52:07 +00:00
2 changed files with 26 additions and 0 deletions

View File

@@ -1849,6 +1849,7 @@ public class AdbDebuggingManager {
public void removeKey(String key) {
if (mKeyMap.containsKey(key)) {
mKeyMap.remove(key);
writeKeys(mKeyMap.keySet());
sendPersistKeyStoreMessage();
}
}

View File

@@ -672,6 +672,31 @@ public final class AdbDebuggingManagerTest {
connectionTime2, mKeyStore.getLastConnectionTime(TEST_KEY_2));
}
@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.
*