Loading services/core/java/com/android/server/adb/AdbDebuggingManager.java +4 −26 Original line number Diff line number Diff line Loading @@ -580,7 +580,9 @@ public class AdbDebuggingManager { static final String MSG_START_ADB_WIFI = "W1"; static final String MSG_STOP_ADB_WIFI = "W0"; @Nullable @VisibleForTesting AdbKeyStore mAdbKeyStore; @NonNull @VisibleForTesting final AdbKeyStore mAdbKeyStore = new AdbKeyStore(mContext, mTempKeysFile, mUserKeyFile, mTicker); private final AdbDebuggingThread mThread; Loading Loading @@ -614,20 +616,6 @@ public class AdbDebuggingManager { } } /** Initialize the AdbKeyStore so tests can grab mAdbKeyStore immediately. */ @VisibleForTesting void initKeyStore() { if (mAdbKeyStore == null) { mAdbKeyStore = new AdbKeyStore( mContext, mTempKeysFile, mUserKeyFile, mTicker, () -> sendPersistKeyStoreMessage()); } } // Show when at least one device is connected. public void showAdbConnectedNotification(boolean show) { final int id = SystemMessage.NOTE_ADB_WIFI_ACTIVE; Loading Loading @@ -675,7 +663,6 @@ public class AdbDebuggingManager { } public void handleMessage(Message msg) { initKeyStore(); switch (msg.what) { case MESSAGE_ADB_ENABLED -> { Loading Loading @@ -736,9 +723,6 @@ public class AdbDebuggingManager { case MESSAGE_ADB_CLEAR -> { Slog.d(TAG, "Received a request to clear the adb authorizations"); mConnectedKeys.clear(); // If the key store has not yet been instantiated then do so now; this avoids // the unnecessary creation of the key store when adb is not enabled. initKeyStore(); mWifiConnectedKeys.clear(); mAdbKeyStore.deleteKeyStore(); cancelJobToUpdateAdbKeyStore(); Loading Loading @@ -1462,13 +1446,7 @@ public class AdbDebuggingManager { /** Returns the list of paired devices. */ public Map<String, PairDevice> getPairedDevices() { AdbKeyStore keystore = new AdbKeyStore( mContext, mTempKeysFile, mUserKeyFile, mTicker, () -> sendPersistKeyStoreMessage()); AdbKeyStore keystore = new AdbKeyStore(mContext, mTempKeysFile, mUserKeyFile, mTicker); return getPairedDevicesForKeys(keystore.getKeys()); } Loading services/core/java/com/android/server/adb/AdbKeyStore.java +5 −21 Original line number Diff line number Diff line Loading @@ -69,14 +69,6 @@ class AdbKeyStore { private final Context mContext; private final AdbDebuggingManager.Ticker mTicker; /** * Callback to request that the AdbKeyStore's state be persisted to disk. Schedules a * MESSAGE_ADB_PERSIST_KEYSTORE message in the AdbDebuggingHandler to ensure that AdbKeyStore is * persisted to disk asynchronously. */ // TODO: verify if we can persist keystore synchronously without scheduling messages on handler. private final KeyStorePersistAction mKeyStorePersistAction; private static final String SYSTEM_KEY_FILE = "/adb_keys"; /** Loading @@ -98,11 +90,9 @@ class AdbKeyStore { Context context, File tempKeysFile, File userKeyFile, AdbDebuggingManager.Ticker ticker, KeyStorePersistAction keyStorePersisAction) { AdbDebuggingManager.Ticker ticker) { mContext = context; mTicker = ticker; mKeyStorePersistAction = keyStorePersisAction; mAdbKeyUser = new AdbdKeyStoreStorage(userKeyFile); mAuthStore = new AdbAuthorizationStore(tempKeysFile); Loading @@ -123,7 +113,7 @@ class AdbKeyStore { synchronized void addTrustedNetwork(String bssid) { mAuthEntries.trustedNetworks().add(bssid); mKeyStorePersistAction.requestPersist(); persistKeyStore(); } synchronized Set<String> getKeys() { Loading @@ -143,7 +133,7 @@ class AdbKeyStore { synchronized void removeKey(String key) { if (mAuthEntries.keys().containsKey(key)) { mAuthEntries.keys().remove(key); mKeyStorePersistAction.requestPersist(); persistKeyStore(); } } Loading @@ -158,7 +148,7 @@ class AdbKeyStore { */ synchronized void updateKeyStore() { if (filterOutOldKeys()) { mKeyStorePersistAction.requestPersist(); persistKeyStore(); } } Loading @@ -179,7 +169,7 @@ class AdbKeyStore { } } if (mapUpdated) { mKeyStorePersistAction.requestPersist(); persistKeyStore(); } } Loading Loading @@ -330,10 +320,4 @@ class AdbKeyStore { synchronized boolean isTrustedNetwork(String bssid) { return mAuthEntries.trustedNetworks().contains(bssid); } @FunctionalInterface interface KeyStorePersistAction { /** Requests that the AdbKeyStore's state be persisted. */ void requestPersist(); } } services/tests/servicestests/src/com/android/server/adb/AdbDebuggingManagerTest.java +5 −18 Original line number Diff line number Diff line Loading @@ -36,8 +36,6 @@ import android.util.Log; import androidx.test.InstrumentationRegistry; import com.android.server.adb.AdbDebuggingManager.AdbDebuggingHandler; import org.junit.After; import org.junit.Before; import org.junit.Test; Loading Loading @@ -118,7 +116,6 @@ public final class AdbDebuggingManagerTest { mHandler = mManager.mHandler; mThread.setHandler(mHandler); mHandler.initKeyStore(); mKeyStore = mHandler.mAdbKeyStore; mOriginalAllowedConnectionTime = mKeyStore.getAllowedConnectionTime(); Loading Loading @@ -283,9 +280,7 @@ public final class AdbDebuggingManagerTest { mContext, mAdbKeyXmlFile, mAdbKeyFile, mFakeTicker, () -> mHandler.obtainMessage(AdbDebuggingHandler.MESSAGE_ADB_PERSIST_KEYSTORE) .sendToTarget()); mFakeTicker); assertTrue( "The key with the 'Always allow' option selected was not persisted in the keystore", newKeyStore.isKeyAuthorized(TEST_KEY_1)); Loading @@ -306,9 +301,7 @@ public final class AdbDebuggingManagerTest { mContext, mAdbKeyXmlFile, mAdbKeyFile, mFakeTicker, () -> mHandler.obtainMessage(AdbDebuggingHandler.MESSAGE_ADB_PERSIST_KEYSTORE) .sendToTarget()); mFakeTicker); assertNotEquals( "The last connection time in the key file was not updated after the update " + "connection time message", lastConnectionTime, Loading Loading @@ -661,9 +654,7 @@ public final class AdbDebuggingManagerTest { mContext, mAdbKeyXmlFile, mAdbKeyFile, mFakeTicker, () -> mHandler.obtainMessage(AdbDebuggingHandler.MESSAGE_ADB_PERSIST_KEYSTORE) .sendToTarget()); mFakeTicker); // Verify that the connection time for each test key is within a small value of the current // time. Loading Loading @@ -788,9 +779,7 @@ public final class AdbDebuggingManagerTest { mContext, mAdbKeyXmlFile, mAdbKeyFile, mFakeTicker, () -> mHandler.obtainMessage(AdbDebuggingHandler.MESSAGE_ADB_PERSIST_KEYSTORE) .sendToTarget()); mFakeTicker); assertEquals( "KeyStore not populated from the XML file.", Loading Loading @@ -857,9 +846,7 @@ public final class AdbDebuggingManagerTest { mContext, mAdbKeyXmlFile, mAdbKeyFile, mFakeTicker, () -> mHandler.obtainMessage(AdbDebuggingHandler.MESSAGE_ADB_PERSIST_KEYSTORE) .sendToTarget()); mFakeTicker); assertTrue( "Persisted trusted network not found in new keystore instance.", Loading Loading
services/core/java/com/android/server/adb/AdbDebuggingManager.java +4 −26 Original line number Diff line number Diff line Loading @@ -580,7 +580,9 @@ public class AdbDebuggingManager { static final String MSG_START_ADB_WIFI = "W1"; static final String MSG_STOP_ADB_WIFI = "W0"; @Nullable @VisibleForTesting AdbKeyStore mAdbKeyStore; @NonNull @VisibleForTesting final AdbKeyStore mAdbKeyStore = new AdbKeyStore(mContext, mTempKeysFile, mUserKeyFile, mTicker); private final AdbDebuggingThread mThread; Loading Loading @@ -614,20 +616,6 @@ public class AdbDebuggingManager { } } /** Initialize the AdbKeyStore so tests can grab mAdbKeyStore immediately. */ @VisibleForTesting void initKeyStore() { if (mAdbKeyStore == null) { mAdbKeyStore = new AdbKeyStore( mContext, mTempKeysFile, mUserKeyFile, mTicker, () -> sendPersistKeyStoreMessage()); } } // Show when at least one device is connected. public void showAdbConnectedNotification(boolean show) { final int id = SystemMessage.NOTE_ADB_WIFI_ACTIVE; Loading Loading @@ -675,7 +663,6 @@ public class AdbDebuggingManager { } public void handleMessage(Message msg) { initKeyStore(); switch (msg.what) { case MESSAGE_ADB_ENABLED -> { Loading Loading @@ -736,9 +723,6 @@ public class AdbDebuggingManager { case MESSAGE_ADB_CLEAR -> { Slog.d(TAG, "Received a request to clear the adb authorizations"); mConnectedKeys.clear(); // If the key store has not yet been instantiated then do so now; this avoids // the unnecessary creation of the key store when adb is not enabled. initKeyStore(); mWifiConnectedKeys.clear(); mAdbKeyStore.deleteKeyStore(); cancelJobToUpdateAdbKeyStore(); Loading Loading @@ -1462,13 +1446,7 @@ public class AdbDebuggingManager { /** Returns the list of paired devices. */ public Map<String, PairDevice> getPairedDevices() { AdbKeyStore keystore = new AdbKeyStore( mContext, mTempKeysFile, mUserKeyFile, mTicker, () -> sendPersistKeyStoreMessage()); AdbKeyStore keystore = new AdbKeyStore(mContext, mTempKeysFile, mUserKeyFile, mTicker); return getPairedDevicesForKeys(keystore.getKeys()); } Loading
services/core/java/com/android/server/adb/AdbKeyStore.java +5 −21 Original line number Diff line number Diff line Loading @@ -69,14 +69,6 @@ class AdbKeyStore { private final Context mContext; private final AdbDebuggingManager.Ticker mTicker; /** * Callback to request that the AdbKeyStore's state be persisted to disk. Schedules a * MESSAGE_ADB_PERSIST_KEYSTORE message in the AdbDebuggingHandler to ensure that AdbKeyStore is * persisted to disk asynchronously. */ // TODO: verify if we can persist keystore synchronously without scheduling messages on handler. private final KeyStorePersistAction mKeyStorePersistAction; private static final String SYSTEM_KEY_FILE = "/adb_keys"; /** Loading @@ -98,11 +90,9 @@ class AdbKeyStore { Context context, File tempKeysFile, File userKeyFile, AdbDebuggingManager.Ticker ticker, KeyStorePersistAction keyStorePersisAction) { AdbDebuggingManager.Ticker ticker) { mContext = context; mTicker = ticker; mKeyStorePersistAction = keyStorePersisAction; mAdbKeyUser = new AdbdKeyStoreStorage(userKeyFile); mAuthStore = new AdbAuthorizationStore(tempKeysFile); Loading @@ -123,7 +113,7 @@ class AdbKeyStore { synchronized void addTrustedNetwork(String bssid) { mAuthEntries.trustedNetworks().add(bssid); mKeyStorePersistAction.requestPersist(); persistKeyStore(); } synchronized Set<String> getKeys() { Loading @@ -143,7 +133,7 @@ class AdbKeyStore { synchronized void removeKey(String key) { if (mAuthEntries.keys().containsKey(key)) { mAuthEntries.keys().remove(key); mKeyStorePersistAction.requestPersist(); persistKeyStore(); } } Loading @@ -158,7 +148,7 @@ class AdbKeyStore { */ synchronized void updateKeyStore() { if (filterOutOldKeys()) { mKeyStorePersistAction.requestPersist(); persistKeyStore(); } } Loading @@ -179,7 +169,7 @@ class AdbKeyStore { } } if (mapUpdated) { mKeyStorePersistAction.requestPersist(); persistKeyStore(); } } Loading Loading @@ -330,10 +320,4 @@ class AdbKeyStore { synchronized boolean isTrustedNetwork(String bssid) { return mAuthEntries.trustedNetworks().contains(bssid); } @FunctionalInterface interface KeyStorePersistAction { /** Requests that the AdbKeyStore's state be persisted. */ void requestPersist(); } }
services/tests/servicestests/src/com/android/server/adb/AdbDebuggingManagerTest.java +5 −18 Original line number Diff line number Diff line Loading @@ -36,8 +36,6 @@ import android.util.Log; import androidx.test.InstrumentationRegistry; import com.android.server.adb.AdbDebuggingManager.AdbDebuggingHandler; import org.junit.After; import org.junit.Before; import org.junit.Test; Loading Loading @@ -118,7 +116,6 @@ public final class AdbDebuggingManagerTest { mHandler = mManager.mHandler; mThread.setHandler(mHandler); mHandler.initKeyStore(); mKeyStore = mHandler.mAdbKeyStore; mOriginalAllowedConnectionTime = mKeyStore.getAllowedConnectionTime(); Loading Loading @@ -283,9 +280,7 @@ public final class AdbDebuggingManagerTest { mContext, mAdbKeyXmlFile, mAdbKeyFile, mFakeTicker, () -> mHandler.obtainMessage(AdbDebuggingHandler.MESSAGE_ADB_PERSIST_KEYSTORE) .sendToTarget()); mFakeTicker); assertTrue( "The key with the 'Always allow' option selected was not persisted in the keystore", newKeyStore.isKeyAuthorized(TEST_KEY_1)); Loading @@ -306,9 +301,7 @@ public final class AdbDebuggingManagerTest { mContext, mAdbKeyXmlFile, mAdbKeyFile, mFakeTicker, () -> mHandler.obtainMessage(AdbDebuggingHandler.MESSAGE_ADB_PERSIST_KEYSTORE) .sendToTarget()); mFakeTicker); assertNotEquals( "The last connection time in the key file was not updated after the update " + "connection time message", lastConnectionTime, Loading Loading @@ -661,9 +654,7 @@ public final class AdbDebuggingManagerTest { mContext, mAdbKeyXmlFile, mAdbKeyFile, mFakeTicker, () -> mHandler.obtainMessage(AdbDebuggingHandler.MESSAGE_ADB_PERSIST_KEYSTORE) .sendToTarget()); mFakeTicker); // Verify that the connection time for each test key is within a small value of the current // time. Loading Loading @@ -788,9 +779,7 @@ public final class AdbDebuggingManagerTest { mContext, mAdbKeyXmlFile, mAdbKeyFile, mFakeTicker, () -> mHandler.obtainMessage(AdbDebuggingHandler.MESSAGE_ADB_PERSIST_KEYSTORE) .sendToTarget()); mFakeTicker); assertEquals( "KeyStore not populated from the XML file.", Loading Loading @@ -857,9 +846,7 @@ public final class AdbDebuggingManagerTest { mContext, mAdbKeyXmlFile, mAdbKeyFile, mFakeTicker, () -> mHandler.obtainMessage(AdbDebuggingHandler.MESSAGE_ADB_PERSIST_KEYSTORE) .sendToTarget()); mFakeTicker); assertTrue( "Persisted trusted network not found in new keystore instance.", Loading