From 482900c14a087f973496724b0e708faf9a597877 Mon Sep 17 00:00:00 2001 From: William Hester Date: Wed, 22 Apr 2020 18:15:32 -0700 Subject: [PATCH] Ensure that adbd is stopped explicitly before re-enabling it Simply putting the Global setting and waiting for the ContentObserver created a race condition, where reading the updated setting may skip reading the value that triggered the change. In this case, it meant that we never toggled off ADB. This explicitly disables and kills ADB before re-enabling it. Bug: 150721793 Test: Manually, running adb shell cmd testharness enable on user and userdebug builds Change-Id: Ic2b3aadbadc2bfe52440066aa98f9a2238ae3bb9 --- .../android/server/testharness/TestHarnessModeService.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/services/core/java/com/android/server/testharness/TestHarnessModeService.java b/services/core/java/com/android/server/testharness/TestHarnessModeService.java index 735a9e41a03bb..531136976c817 100644 --- a/services/core/java/com/android/server/testharness/TestHarnessModeService.java +++ b/services/core/java/com/android/server/testharness/TestHarnessModeService.java @@ -25,6 +25,7 @@ import android.content.Context; import android.content.Intent; import android.content.pm.UserInfo; import android.debug.AdbManagerInternal; +import android.debug.AdbTransportType; import android.location.LocationManager; import android.os.BatteryManager; import android.os.Binder; @@ -164,6 +165,10 @@ public class TestHarnessModeService extends SystemService { // Stop ADB before we enable it, otherwise on userdebug/eng builds, the keys won't have // registered with adbd, and it will prompt the user to confirm the keys. Settings.Global.putInt(cr, Settings.Global.ADB_ENABLED, 0); + AdbManagerInternal adbManager = LocalServices.getService(AdbManagerInternal.class); + if (adbManager.isAdbEnabled(AdbTransportType.USB)) { + adbManager.stopAdbdForTransport(AdbTransportType.USB); + } // Disable the TTL for ADB keys before enabling ADB Settings.Global.putLong(cr, Settings.Global.ADB_ALLOWED_CONNECTION_TIME, 0);