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

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

Follow error prone recommendation

In btservice/RemoteDevices.java:
```
468: warning: Private method 'isCoordinatedSetMember' is never used.
        private boolean isCoordinatedSetMember() {
                        ^
651: warning: The local variable 'numUuids' is never read.
                            int numUuids = val.length / AbstractionLayer.BT_UUID_SIZE;
                                ^
140: warning: This assignment is to a static field.
Mutating static state from a constructor is highly error-prone.
        sAdapter = BluetoothAdapter.getDefaultAdapter();
                 ^
141: warning: This assignment is to a static field.
Mutating static state from a constructor is highly error-prone.
        sAdapterService = service;
                        ^
142: warning: This assignment is to a static field.
Mutating static state from a constructor is highly error-prone.
        sSdpTracker = new ArrayList<BluetoothDevice>();
                    ^
145: warning: It is very rare for LinkedList to out-perform ArrayList or ArrayDeque.
Avoid it unless you're willing to invest a lot of time into benchmarking.
        mDeviceQueue = new LinkedList<String>();
                       ^
192: warning: Method reset() annotated [none] but too narrow;
invokes method requiring {allOf=[android.permission.BLUETOOTH_CONNECT]}
                    if (bluetoothDevice.isConnected()) {
                                                   ^
197: warning: Broadcast annotated {allOf=[android.permission.BLUETOOTH_CONNECT]}
but protected with {allOf=[android.permission.BLUETOOTH]}
                        sAdapterService.sendBroadcast(intent, AdapterService.BLUETOOTH_PERM);
                                                     ^
397: warning: Parameter name `mBondState` is unknown. Did you mean newBondState?
         * @param mBondState the mBondState to set
           ^
853: warning: Method aclStateChangeCallback() annotated [none] but too narrow;
invokes method requiring {allOf=[android.permission.BLUETOOTH_CONNECT]}
                    + device.getBondState());
                                         ^
```

Bug: 236759221
Test: m RUN_ERROR_PRONE=true Bluetooth
Test: atest 'BluetoothInstrumentationTests:com.android.bluetooth.btservice.RemoteDevicesTest'
Ignore-AOSP-First: Merge conflict resolution
Merged-In: Ie3f35df29a81a5f55a28b63ce2c228eedd1f72f0
Change-Id: Ie3f35df29a81a5f55a28b63ce2c228eedd1f72f0
parent 6821b8fa
Loading
Loading
Loading
Loading
+181 −81

File changed.

Preview size limit exceeded, changes collapsed.

+10 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.app.AlarmManager;
import android.app.admin.DevicePolicyManager;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothManager;
import android.bluetooth.IBluetoothCallback;
import android.content.AttributionSource;
import android.content.Context;
@@ -144,6 +145,7 @@ public class AdapterServiceTest {
    private final AttributionSource mAttributionSource = new AttributionSource.Builder(
            Process.myUid()).build();

    private BluetoothManager mBluetoothManager;
    private PowerManager mPowerManager;
    private PermissionCheckerManager mPermissionCheckerManager;
    private PermissionManager mPermissionManager;
@@ -238,6 +240,9 @@ public class AdapterServiceTest {
        mPermissionManager = InstrumentationRegistry.getTargetContext()
                .getSystemService(PermissionManager.class);

        mBluetoothManager = InstrumentationRegistry.getTargetContext()
                .getSystemService(BluetoothManager.class);

        when(mMockContext.getApplicationInfo()).thenReturn(mMockApplicationInfo);
        when(mMockContext.getContentResolver()).thenReturn(mMockContentResolver);
        when(mMockContext.getApplicationContext()).thenReturn(mMockContext);
@@ -273,6 +278,11 @@ public class AdapterServiceTest {
                .thenReturn(mBatteryStatsManager);
        when(mMockContext.getSystemServiceName(BatteryStatsManager.class))
                .thenReturn(Context.BATTERY_STATS_SERVICE);
        when(mMockContext.getSystemService(Context.BLUETOOTH_SERVICE))
                .thenReturn(mBluetoothManager);
        when(mMockContext.getSystemServiceName(BluetoothManager.class))
                .thenReturn(Context.BLUETOOTH_SERVICE);

        when(mMockContext.getAttributionSource()).thenReturn(mAttributionSource);
        doAnswer(invocation -> {
            Object[] args = invocation.getArguments();
+8 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.Manifest.permission.BLUETOOTH_CONNECT;
import static org.mockito.Mockito.*;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
@@ -56,6 +57,7 @@ public class BondStateMachineTest {
    private static final int BOND_BONDING = BluetoothDevice.BOND_BONDING;
    private static final int BOND_BONDED = BluetoothDevice.BOND_BONDED;

    private BluetoothManager mBluetoothManager;
    private AdapterProperties mAdapterProperties;
    private BluetoothDevice mDevice;
    private Context mTargetContext;
@@ -75,6 +77,12 @@ public class BondStateMachineTest {
        mHandlerThread = new HandlerThread("BondStateMachineTestHandlerThread");
        mHandlerThread.start();

        mBluetoothManager = mTargetContext.getSystemService(BluetoothManager.class);
        when(mAdapterService.getSystemService(Context.BLUETOOTH_SERVICE))
                .thenReturn(mBluetoothManager);
        when(mAdapterService.getSystemServiceName(BluetoothManager.class))
                .thenReturn(Context.BLUETOOTH_SERVICE);

        mRemoteDevices = new RemoteDevices(mAdapterService, mHandlerThread.getLooper());
        mRemoteDevices.reset();
        when(mAdapterService.getResources()).thenReturn(
+16 −0
Original line number Diff line number Diff line
@@ -9,7 +9,9 @@ import android.bluetooth.BluetoothAssignedNumbers;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothHeadsetClient;
import android.bluetooth.BluetoothManager;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.HandlerThread;
@@ -46,17 +48,31 @@ public class RemoteDevicesTest {
    private HandlerThread mHandlerThread;
    private TestLooperManager mTestLooperManager;

    private Context mTargetContext;
    private BluetoothManager mBluetoothManager;

    @Mock private AdapterService mAdapterService;

    @Before
    public void setUp() {
        mTargetContext = InstrumentationRegistry.getTargetContext();

        MockitoAnnotations.initMocks(this);
        mDevice1 = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(TEST_BT_ADDR_1);
        mHandlerThread = new HandlerThread("RemoteDevicesTestHandlerThread");
        mHandlerThread.start();
        mTestLooperManager = InstrumentationRegistry.getInstrumentation()
                .acquireLooperManager(mHandlerThread.getLooper());

        mBluetoothManager = mTargetContext.getSystemService(BluetoothManager.class);
        when(mAdapterService.getSystemService(Context.BLUETOOTH_SERVICE))
                .thenReturn(mBluetoothManager);
        when(mAdapterService.getSystemServiceName(BluetoothManager.class))
                .thenReturn(Context.BLUETOOTH_SERVICE);

        mRemoteDevices = new RemoteDevices(mAdapterService, mHandlerThread.getLooper());
        verify(mAdapterService, times(1)).getSystemService(Context.BLUETOOTH_SERVICE);
        verify(mAdapterService, times(1)).getSystemService(BluetoothManager.class);
    }

    @After