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

Commit 42f32137 authored by William Escande's avatar William Escande
Browse files

SystemServer: shell cmd Add enableBle & DisableBle

This will simulate an app trying to connect and activate BLE_ON mode.
It is very useful when testing on aosp without any sytemservice that try
to bind to Bluetooth in ble only.

Both the command are privileged and required root privileged

Bug: 311772251
Test: m Bluetooth : This is a test command:
      adb shell cmd bluetooth_manager enableBle
Flag: Exempt, test only
Change-Id: I7de3daa8ba60d878fd22c897d918d6aeafb2d6da
parent d7502ad3
Loading
Loading
Loading
Loading
+49 −3
Original line number Diff line number Diff line
@@ -36,9 +36,7 @@ class BluetoothShellCommand extends BasicShellCommandHandler {

    @VisibleForTesting
    final BluetoothCommand[] mBluetoothCommands = {
        new Enable(),
        new Disable(),
        new WaitForAdapterState(),
        new Enable(), new EnableBle(), new Disable(), new DisableBle(), new WaitForAdapterState(),
    };

    @VisibleForTesting
@@ -65,6 +63,54 @@ class BluetoothShellCommand extends BasicShellCommandHandler {
        abstract void onHelp(PrintWriter pw);
    }

    @VisibleForTesting
    class EnableBle extends BluetoothCommand {
        EnableBle() {
            super(true, "enableBle");
        }

        @Override
        public int exec(String cmd) throws RemoteException {
            return mManagerService
                            .getBinder()
                            .enableBle(
                                    AttributionSource.myAttributionSource(),
                                    mManagerService.getBinder())
                    ? 0
                    : -1;
        }

        @Override
        public void onHelp(PrintWriter pw) {
            pw.println("  " + getName());
            pw.println("    Call enableBle to activate ble only mode on this device.");
        }
    }

    @VisibleForTesting
    class DisableBle extends BluetoothCommand {
        DisableBle() {
            super(true, "disableBle");
        }

        @Override
        public int exec(String cmd) throws RemoteException {
            return mManagerService
                            .getBinder()
                            .disableBle(
                                    AttributionSource.myAttributionSource(),
                                    mManagerService.getBinder())
                    ? 0
                    : -1;
        }

        @Override
        public void onHelp(PrintWriter pw) {
            pw.println("  " + getName());
            pw.println("    revoke the call to enableBle. No-op if enableBle wasn't call before");
        }
    }

    @VisibleForTesting
    class Enable extends BluetoothCommand {
        Enable() {