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

Commit 64782618 authored by William Escande's avatar William Escande
Browse files

Reformat java file in service

Bug: 311772251
Flag: Exempt refactor
Test: None
Change-Id: I283afc0ce8e3afac74db2936a5f36451c00e3bab
parent 32f1b534
Loading
Loading
Loading
Loading
+4 −7
Original line number Diff line number Diff line
@@ -19,18 +19,15 @@ package com.android.server.bluetooth;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledSince;

/**
 * All the {@link ChangeId} used in the Bluetooth service .
 */
/** All the {@link ChangeId} used in the Bluetooth service . */
class ChangeIds {
    private ChangeIds() {}

    /**
     * Starting with {@link android.os.Build.VERSION_CODES#TIRAMISU}, applications are
     * not allowed to enable/disable Bluetooth.
     * Starting with {@link android.os.Build.VERSION_CODES#TIRAMISU}, applications are not allowed
     * to enable/disable Bluetooth.
     */
    @ChangeId
    @EnabledSince(targetSdkVersion = android.os.Build.VERSION_CODES.TIRAMISU)
    static final long RESTRICT_ENABLE_DISABLE = 218493289L;
}
+1 −2
Original line number Diff line number Diff line
@@ -30,8 +30,7 @@ class BluetoothServerProxy {
    private static final Object INSTANCE_LOCK = new Object();
    private static BluetoothServerProxy sInstance;

    private BluetoothServerProxy() {
    }
    private BluetoothServerProxy() {}

    /**
     * Get the singleton instance of proxy
+21 −4
Original line number Diff line number Diff line
@@ -52,14 +52,17 @@ class BluetoothShellCommand extends BasicShellCommandHandler {
        String getName() {
            return mName;
        }

        boolean isMatch(String cmd) {
            return mName.equals(cmd);
        }

        boolean isPrivileged() {
            return mIsPrivileged;
        }

        abstract int exec(String cmd) throws RemoteException;

        abstract void onHelp(PrintWriter pw);
    }

@@ -116,12 +119,14 @@ class BluetoothShellCommand extends BasicShellCommandHandler {
        Enable() {
            super(false, "enable");
        }

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

        @Override
        public void onHelp(PrintWriter pw) {
            pw.println("  " + getName());
@@ -134,6 +139,7 @@ class BluetoothShellCommand extends BasicShellCommandHandler {
        Disable() {
            super(false, "disable");
        }

        @Override
        public int exec(String cmd) throws RemoteException {
            return mManagerService
@@ -142,6 +148,7 @@ class BluetoothShellCommand extends BasicShellCommandHandler {
                    ? 0
                    : -1;
        }

        @Override
        public void onHelp(PrintWriter pw) {
            pw.println("  " + getName());
@@ -154,6 +161,7 @@ class BluetoothShellCommand extends BasicShellCommandHandler {
        WaitForAdapterState() {
            super(false, "wait-for-state");
        }

        private int getWaitingState(String in) {
            if (!in.startsWith(getName() + ":")) return -1;
            String[] split = in.split(":", 2);
@@ -179,20 +187,24 @@ class BluetoothShellCommand extends BasicShellCommandHandler {
                    throw new IllegalArgumentException();
            }
        }

        @Override
        boolean isMatch(String cmd) {
            return getWaitingState(cmd) != -1;
        }

        @Override
        public int exec(String cmd) throws RemoteException {
            int ret = mManagerService.waitForManagerState(getWaitingState(cmd)) ? 0 : -1;
            Log.d(TAG, cmd + ": Return value is " + ret); // logging as this method can take time
            return ret;
        }

        @Override
        public void onHelp(PrintWriter pw) {
            pw.println("  " + getName() + ":<STATE>");
            pw.println("    Wait until the adapter state is <STATE>."
            pw.println(
                    "    Wait until the adapter state is <STATE>."
                            + " <STATE> can be one of STATE_OFF | STATE_ON");
            pw.println("    Note: This command can timeout and failed");
        }
@@ -211,8 +223,12 @@ class BluetoothShellCommand extends BasicShellCommandHandler {
            if (bt_cmd.isPrivileged()) {
                final int uid = Binder.getCallingUid();
                if (uid != Process.ROOT_UID) {
                    throw new SecurityException("Uid " + uid + " does not have access to "
                            + cmd + " bluetooth command");
                    throw new SecurityException(
                            "Uid "
                                    + uid
                                    + " does not have access to "
                                    + cmd
                                    + " bluetooth command");
                }
            }
            try {
@@ -246,6 +262,7 @@ class BluetoothShellCommand extends BasicShellCommandHandler {
            bt_cmd.onHelp(pw);
        }
    }

    @Override
    public void onHelp() {
        printHelp(getOutPrintWriter());
+9 −8
Original line number Diff line number Diff line
@@ -56,8 +56,7 @@ import java.io.PrintWriter;
public class BluetoothShellCommandTest {
    @Rule public final Expect expect = Expect.create();

    @Mock
    BluetoothManagerService mManagerService;
    @Mock BluetoothManagerService mManagerService;

    @Mock BluetoothServiceBinder mBinder;

@@ -70,8 +69,12 @@ public class BluetoothShellCommandTest {

        mShellCommand = new BluetoothShellCommand(mManagerService);
        mShellCommand.init(
                mock(Binder.class), mock(FileDescriptor.class), mock(FileDescriptor.class),
                mock(FileDescriptor.class), new String[0], -1);
                mock(Binder.class),
                mock(FileDescriptor.class),
                mock(FileDescriptor.class),
                mock(FileDescriptor.class),
                new String[0],
                -1);
    }

    @After
@@ -112,15 +115,13 @@ public class BluetoothShellCommandTest {

        expect.that(waitCmd.getName()).isEqualTo("wait-for-state");
        String[] validCmd = {
            "wait-for-state:STATE_OFF",
            "wait-for-state:STATE_ON",
            "wait-for-state:STATE_OFF", "wait-for-state:STATE_ON",
        };
        for (String m : validCmd) {
            expect.that(waitCmd.isMatch(m)).isTrue();
        }
        String[] falseCmd = {
            "wait-for-stateSTATE_ON",
            "wait-for-foo:STATE_ON",
            "wait-for-stateSTATE_ON", "wait-for-foo:STATE_ON",
        };
        for (String m : falseCmd) {
            expect.that(waitCmd.isMatch(m)).isFalse();