Merge "Consolidate point where ADB is enabled for Test Harness Mode" into tm-dev

This commit is contained in:
William Hester
2022-06-02 18:14:06 +00:00
committed by Android (Google) Code Review
3 changed files with 23 additions and 18 deletions

View File

@@ -56,6 +56,7 @@ import com.android.internal.util.dump.DualDumpOutputStream;
import com.android.server.FgThread;
import com.android.server.LocalServices;
import com.android.server.SystemService;
import com.android.server.testharness.TestHarnessModeService;
import java.io.File;
import java.io.FileDescriptor;
@@ -163,18 +164,8 @@ public class AdbService extends IAdbManager.Stub {
}
}
private void initAdbState() {
private void registerContentObservers() {
try {
/*
* Use the normal bootmode persistent prop to maintain state of adb across
* all boot modes.
*/
mIsAdbUsbEnabled = containsFunction(
SystemProperties.get(USB_PERSISTENT_CONFIG_PROPERTY, ""),
UsbManager.USB_FUNCTION_ADB);
mIsAdbWifiEnabled = "1".equals(
SystemProperties.get(WIFI_PERSISTENT_CONFIG_PROPERTY, "0"));
// register observer to listen for settings changes
mObserver = new AdbSettingsObserver();
mContentResolver.registerContentObserver(
@@ -184,7 +175,7 @@ public class AdbService extends IAdbManager.Stub {
Settings.Global.getUriFor(Settings.Global.ADB_WIFI_ENABLED),
false, mObserver);
} catch (Exception e) {
Slog.e(TAG, "Error in initAdbState", e);
Slog.e(TAG, "Error in registerContentObservers", e);
}
}
@@ -248,7 +239,7 @@ public class AdbService extends IAdbManager.Stub {
mContentResolver = context.getContentResolver();
mDebuggingManager = new AdbDebuggingManager(context);
initAdbState();
registerContentObservers();
LocalServices.addService(AdbManagerInternal.class, new AdbManagerInternalImpl());
}
@@ -259,10 +250,23 @@ public class AdbService extends IAdbManager.Stub {
public void systemReady() {
if (DEBUG) Slog.d(TAG, "systemReady");
/*
* Use the normal bootmode persistent prop to maintain state of adb across
* all boot modes.
*/
mIsAdbUsbEnabled = containsFunction(
SystemProperties.get(USB_PERSISTENT_CONFIG_PROPERTY, ""),
UsbManager.USB_FUNCTION_ADB);
boolean shouldEnableAdbUsb = mIsAdbUsbEnabled
|| SystemProperties.getBoolean(
TestHarnessModeService.TEST_HARNESS_MODE_PROPERTY, false);
mIsAdbWifiEnabled = "1".equals(
SystemProperties.get(WIFI_PERSISTENT_CONFIG_PROPERTY, "0"));
// make sure the ADB_ENABLED setting value matches the current state
try {
Settings.Global.putInt(mContentResolver,
Settings.Global.ADB_ENABLED, mIsAdbUsbEnabled ? 1 : 0);
Settings.Global.ADB_ENABLED, shouldEnableAdbUsb ? 1 : 0);
Settings.Global.putInt(mContentResolver,
Settings.Global.ADB_WIFI_ENABLED, mIsAdbWifiEnabled ? 1 : 0);
} catch (SecurityException e) {
@@ -272,7 +276,7 @@ public class AdbService extends IAdbManager.Stub {
}
/**
* Callend in response to {@code SystemService.PHASE_BOOT_COMPLETED} from {@code SystemServer}.
* Called in response to {@code SystemService.PHASE_BOOT_COMPLETED} from {@code SystemServer}.
*/
public void bootCompleted() {
if (DEBUG) Slog.d(TAG, "boot completed");

View File

@@ -0,0 +1 @@
williamhester@google.com

View File

@@ -69,8 +69,8 @@ import java.util.Set;
* automatic updates, etc.) are all disabled by default but may be re-enabled by the user.
*/
public class TestHarnessModeService extends SystemService {
public static final String TEST_HARNESS_MODE_PROPERTY = "persist.sys.test_harness";
private static final String TAG = TestHarnessModeService.class.getSimpleName();
private static final String TEST_HARNESS_MODE_PROPERTY = "persist.sys.test_harness";
private PersistentDataBlockManagerInternal mPersistentDataBlockManagerInternal;
@@ -168,9 +168,9 @@ public class TestHarnessModeService extends SystemService {
Slog.d(TAG, "Restarted adbd");
}
// Disable the TTL for ADB keys before enabling ADB
// Disable the TTL for ADB keys before ADB is enabled as a part of AdbService's
// initialization.
Settings.Global.putLong(cr, Settings.Global.ADB_ALLOWED_CONNECTION_TIME, 0);
Settings.Global.putInt(cr, Settings.Global.ADB_ENABLED, 1);
Settings.Global.putInt(cr, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
Settings.Global.putInt(cr, Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, 0);
Settings.Global.putInt(