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

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

ERROR_PRONE: enforce ClassCanBeStatic and fix it

Bug: 280890575
Test: atest ServiceBluetoothTests
Test: m RUN_ERROR_PRONE=true service-bluetooth
Change-Id: Iacb9f41d80546fae74bbad310e59ab4aed6323d0
parent 74ee6e0f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ java_defaults {
    errorprone: {
        javacflags: [
            "-Xep:CheckReturnValue:ERROR",
            "-Xep:ClassCanBeStatic:ERROR",
            "-Xep:EqualsIncompatibleType:ERROR",
            "-Xep:ReferenceEquality:ERROR",
        ],
+1 −1
Original line number Diff line number Diff line
@@ -234,7 +234,7 @@ class BluetoothManagerService {
    }

    // Used for tracking apps that enabled / disabled Bluetooth.
    private class ActiveLog {
    private static class ActiveLog {
        private int mReason;
        private String mPackageName;
        private boolean mEnable;
+1 −1
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ class BluetoothShellCommand extends BasicShellCommandHandler {
    };

    @VisibleForTesting
    abstract class BluetoothCommand {
    abstract static class BluetoothCommand {
        final boolean mIsPrivileged;
        final String mName;

+18 −13
Original line number Diff line number Diff line
@@ -165,21 +165,26 @@ public class BluetoothShellCommandTest {
        verify(mBinder).enable(any());
    }

    @Test
    public void onCommand_withPrivilegedCommandName_throwsSecurityException() {
        final String privilegedCommandName = "test_privileged_cmd_name";
        BluetoothCommand privilegedCommand =
                mShellCommand.new BluetoothCommand(true, privilegedCommandName) {
    class TestPrivilegedCmd extends BluetoothCommand {
        TestPrivilegedCmd() {
            super(true, TestPrivilegedCmd.class.getSimpleName());
        }

        @Override
        int exec(String cmd) throws RemoteException {
            return 0;
        }

        @Override
        public void onHelp(PrintWriter pw) {}
        };
        mShellCommand.mBluetoothCommands[0] = privilegedCommand;
    }

    @Test
    public void onCommand_withPrivilegedCommandName_throwsSecurityException() {
        mShellCommand.mBluetoothCommands[0] = new TestPrivilegedCmd();

        assertThrows(SecurityException.class,
                () -> mShellCommand.onCommand(privilegedCommandName));
        assertThrows(
                SecurityException.class,
                () -> mShellCommand.onCommand(TestPrivilegedCmd.class.getSimpleName()));
    }
}