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

Commit 1a4a3413 authored by William Escande's avatar William Escande Committed by Android (Google) Code Review
Browse files

Merge "Follow error prone recommendation" into tm-dev-plus-aosp

parents 04ee59dc 7ffbcd2e
Loading
Loading
Loading
Loading
+181 −81

File changed.

Preview size limit exceeded, changes collapsed.

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


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


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

        when(mMockContext.getApplicationInfo()).thenReturn(mMockApplicationInfo);
        when(mMockContext.getApplicationInfo()).thenReturn(mMockApplicationInfo);
        when(mMockContext.getContentResolver()).thenReturn(mMockContentResolver);
        when(mMockContext.getContentResolver()).thenReturn(mMockContentResolver);
        when(mMockContext.getApplicationContext()).thenReturn(mMockContext);
        when(mMockContext.getApplicationContext()).thenReturn(mMockContext);
@@ -273,6 +278,11 @@ public class AdapterServiceTest {
                .thenReturn(mBatteryStatsManager);
                .thenReturn(mBatteryStatsManager);
        when(mMockContext.getSystemServiceName(BatteryStatsManager.class))
        when(mMockContext.getSystemServiceName(BatteryStatsManager.class))
                .thenReturn(Context.BATTERY_STATS_SERVICE);
                .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);
        when(mMockContext.getAttributionSource()).thenReturn(mAttributionSource);
        doAnswer(invocation -> {
        doAnswer(invocation -> {
            Object[] args = invocation.getArguments();
            Object[] args = invocation.getArguments();
+8 −0
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.Manifest.permission.BLUETOOTH_CONNECT;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.*;


import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothManager;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.os.Bundle;
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_BONDING = BluetoothDevice.BOND_BONDING;
    private static final int BOND_BONDED = BluetoothDevice.BOND_BONDED;
    private static final int BOND_BONDED = BluetoothDevice.BOND_BONDED;


    private BluetoothManager mBluetoothManager;
    private AdapterProperties mAdapterProperties;
    private AdapterProperties mAdapterProperties;
    private BluetoothDevice mDevice;
    private BluetoothDevice mDevice;
    private Context mTargetContext;
    private Context mTargetContext;
@@ -75,6 +77,12 @@ public class BondStateMachineTest {
        mHandlerThread = new HandlerThread("BondStateMachineTestHandlerThread");
        mHandlerThread = new HandlerThread("BondStateMachineTestHandlerThread");
        mHandlerThread.start();
        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 = new RemoteDevices(mAdapterService, mHandlerThread.getLooper());
        mRemoteDevices.reset();
        mRemoteDevices.reset();
        when(mAdapterService.getResources()).thenReturn(
        when(mAdapterService.getResources()).thenReturn(
+16 −0
Original line number Original line Diff line number Diff line
@@ -9,7 +9,9 @@ import android.bluetooth.BluetoothAssignedNumbers;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothHeadsetClient;
import android.bluetooth.BluetoothHeadsetClient;
import android.bluetooth.BluetoothManager;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.os.Bundle;
import android.os.Bundle;
import android.os.HandlerThread;
import android.os.HandlerThread;
@@ -46,17 +48,31 @@ public class RemoteDevicesTest {
    private HandlerThread mHandlerThread;
    private HandlerThread mHandlerThread;
    private TestLooperManager mTestLooperManager;
    private TestLooperManager mTestLooperManager;


    private Context mTargetContext;
    private BluetoothManager mBluetoothManager;

    @Mock private AdapterService mAdapterService;
    @Mock private AdapterService mAdapterService;


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

        MockitoAnnotations.initMocks(this);
        MockitoAnnotations.initMocks(this);
        mDevice1 = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(TEST_BT_ADDR_1);
        mDevice1 = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(TEST_BT_ADDR_1);
        mHandlerThread = new HandlerThread("RemoteDevicesTestHandlerThread");
        mHandlerThread = new HandlerThread("RemoteDevicesTestHandlerThread");
        mHandlerThread.start();
        mHandlerThread.start();
        mTestLooperManager = InstrumentationRegistry.getInstrumentation()
        mTestLooperManager = InstrumentationRegistry.getInstrumentation()
                .acquireLooperManager(mHandlerThread.getLooper());
                .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());
        mRemoteDevices = new RemoteDevices(mAdapterService, mHandlerThread.getLooper());
        verify(mAdapterService, times(1)).getSystemService(Context.BLUETOOTH_SERVICE);
        verify(mAdapterService, times(1)).getSystemService(BluetoothManager.class);
    }
    }


    @After
    @After