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

Commit 3fc294bb authored by William Hester's avatar William Hester Committed by Automerger Merge Worker
Browse files

Merge "Consolidate point where ADB is enabled for Test Harness Mode" am: d9c4a359 am: 96d1e8b9

parents 59bf8d32 96d1e8b9
Loading
Loading
Loading
Loading
+19 −15
Original line number Original line Diff line number Diff line
@@ -56,6 +56,7 @@ import com.android.internal.util.dump.DualDumpOutputStream;
import com.android.server.FgThread;
import com.android.server.FgThread;
import com.android.server.LocalServices;
import com.android.server.LocalServices;
import com.android.server.SystemService;
import com.android.server.SystemService;
import com.android.server.testharness.TestHarnessModeService;


import java.io.File;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileDescriptor;
@@ -163,18 +164,8 @@ public class AdbService extends IAdbManager.Stub {
        }
        }
    }
    }


    private void initAdbState() {
    private void registerContentObservers() {
        try {
        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
            // register observer to listen for settings changes
            mObserver = new AdbSettingsObserver();
            mObserver = new AdbSettingsObserver();
            mContentResolver.registerContentObserver(
            mContentResolver.registerContentObserver(
@@ -184,7 +175,7 @@ public class AdbService extends IAdbManager.Stub {
                    Settings.Global.getUriFor(Settings.Global.ADB_WIFI_ENABLED),
                    Settings.Global.getUriFor(Settings.Global.ADB_WIFI_ENABLED),
                    false, mObserver);
                    false, mObserver);
        } catch (Exception e) {
        } 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();
        mContentResolver = context.getContentResolver();
        mDebuggingManager = new AdbDebuggingManager(context);
        mDebuggingManager = new AdbDebuggingManager(context);


        initAdbState();
        registerContentObservers();
        LocalServices.addService(AdbManagerInternal.class, new AdbManagerInternalImpl());
        LocalServices.addService(AdbManagerInternal.class, new AdbManagerInternalImpl());
    }
    }


@@ -259,10 +250,23 @@ public class AdbService extends IAdbManager.Stub {
    public void systemReady() {
    public void systemReady() {
        if (DEBUG) Slog.d(TAG, "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
        // make sure the ADB_ENABLED setting value matches the current state
        try {
        try {
            Settings.Global.putInt(mContentResolver,
            Settings.Global.putInt(mContentResolver,
                    Settings.Global.ADB_ENABLED, mIsAdbUsbEnabled ? 1 : 0);
                    Settings.Global.ADB_ENABLED, shouldEnableAdbUsb ? 1 : 0);
            Settings.Global.putInt(mContentResolver,
            Settings.Global.putInt(mContentResolver,
                    Settings.Global.ADB_WIFI_ENABLED, mIsAdbWifiEnabled ? 1 : 0);
                    Settings.Global.ADB_WIFI_ENABLED, mIsAdbWifiEnabled ? 1 : 0);
        } catch (SecurityException e) {
        } 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() {
    public void bootCompleted() {
        if (DEBUG) Slog.d(TAG, "boot completed");
        if (DEBUG) Slog.d(TAG, "boot completed");
+1 −0
Original line number Original line Diff line number Diff line
williamhester@google.com
+3 −3
Original line number Original line Diff line number Diff line
@@ -69,8 +69,8 @@ import java.util.Set;
 * automatic updates, etc.) are all disabled by default but may be re-enabled by the user.
 * automatic updates, etc.) are all disabled by default but may be re-enabled by the user.
 */
 */
public class TestHarnessModeService extends SystemService {
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 TAG = TestHarnessModeService.class.getSimpleName();
    private static final String TEST_HARNESS_MODE_PROPERTY = "persist.sys.test_harness";


    private PersistentDataBlockManagerInternal mPersistentDataBlockManagerInternal;
    private PersistentDataBlockManagerInternal mPersistentDataBlockManagerInternal;


@@ -168,9 +168,9 @@ public class TestHarnessModeService extends SystemService {
            Slog.d(TAG, "Restarted adbd");
            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.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.DEVELOPMENT_SETTINGS_ENABLED, 1);
        Settings.Global.putInt(cr, Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, 0);
        Settings.Global.putInt(cr, Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, 0);
        Settings.Global.putInt(
        Settings.Global.putInt(