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

Commit 62855c94 authored by Sherif Eid's avatar Sherif Eid
Browse files

Reuse mHandler AdbKeyStore to fetch paired devices

AdbKeyStore is thread-safe, so it's safe to re-use the instance. Reusing
the instace makes sure to get the updated in-memory AdbKeyStore state
without the need to re-read the files which might haven't been persisted
yet.

Test: AdbDebuggingManagerTest
Bug: 420613813
Flag: EXEMPT bugfix
Change-Id: Ia55852559c7d1bc07f9501ba0064f22d846831d9
parent fed2f6bd
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();