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

Commit c4d43324 authored by Sherif Eid's avatar Sherif Eid Committed by Android (Google) Code Review
Browse files

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

parents e9b44c27 62855c94
Loading
Loading
Loading
Loading
+9 −28
Original line number Diff line number Diff line
@@ -572,7 +572,14 @@ public class AdbDebuggingManager {
        static final String MSG_START_ADB_WIFI = "W1";
        static final String MSG_STOP_ADB_WIFI = "W0";

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

        private final AdbDebuggingThread mThread;

@@ -600,20 +607,6 @@ public class AdbDebuggingManager {
            mThread = thread;
        }

        /** 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;
@@ -661,8 +654,6 @@ public class AdbDebuggingManager {
        }

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

            switch (msg.what) {
                case MESSAGE_ADB_ENABLED -> {
                    if (mAdbUsbEnabled) {
@@ -722,9 +713,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();
@@ -1449,14 +1437,7 @@ public class AdbDebuggingManager {

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

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

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

        mOriginalAllowedConnectionTime = mKeyStore.getAllowedConnectionTime();