Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 54960e0b authored by Bo Hu's avatar Bo Hu Committed by Android (Google) Code Review
Browse files

Merge "Revert "Reuse mHandler AdbKeyStore to fetch paired devices"" into main

parents b94dec98 0738b707
Loading
Loading
Loading
Loading
+28 −9
Original line number Diff line number Diff line
@@ -571,14 +571,7 @@ public class AdbDebuggingManager {
        static final String MSG_START_ADB_WIFI = "W1";
        static final String MSG_STOP_ADB_WIFI = "W0";

        @VisibleForTesting @NonNull
        final AdbKeyStore mAdbKeyStore =
                new AdbKeyStore(
                        mContext,
                        mTempKeysFile,
                        mUserKeyFile,
                        mTicker,
                        () -> sendPersistKeyStoreMessage());
        @Nullable @VisibleForTesting AdbKeyStore mAdbKeyStore;

        private final AdbDebuggingThread mThread;

@@ -612,6 +605,20 @@ 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;
@@ -659,6 +666,8 @@ public class AdbDebuggingManager {
        }

        public void handleMessage(Message msg) {
            initKeyStore();

            switch (msg.what) {
                case MESSAGE_ADB_ENABLED -> {
                    if (mAdbUsbEnabled) {
@@ -718,6 +727,9 @@ 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();
@@ -1441,7 +1453,14 @@ public class AdbDebuggingManager {

    /** Returns the list of paired devices. */
    public Map<String, PairDevice> getPairedDevices() {
        return getPairedDevicesForKeys(mHandler.mAdbKeyStore.getKeys());
        AdbKeyStore keystore =
                new AdbKeyStore(
                        mContext,
                        mTempKeysFile,
                        mUserKeyFile,
                        mTicker,
                        () -> sendPersistKeyStoreMessage());
        return getPairedDevicesForKeys(keystore.getKeys());
    }

    private Map<String, PairDevice> getPairedDevicesForKeys(Set<String> keys) {
+1 −0
Original line number Diff line number Diff line
@@ -118,6 +118,7 @@ public final class AdbDebuggingManagerTest {
        mHandler = mManager.mHandler;
        mThread.setHandler(mHandler);

        mHandler.initKeyStore();
        mKeyStore = mHandler.mAdbKeyStore;

        mOriginalAllowedConnectionTime = mKeyStore.getAllowedConnectionTime();