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

Commit 8ca29d1b authored by Jayden Kim's avatar Jayden Kim
Browse files

ScanManager: Add mock location manager for unit test

- reduces the dependency on the enabled status of location service during unit test

Bug: 262305086
Bug: 262305047
Test: atest BluetoothInstrumentationTests
Tag: #stability
Change-Id: Ia9e4fff94aab587867385f7b37e4ed767629acf0
parent 0bdc30f2
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -166,11 +166,11 @@ public class ScanManager {
        mSuspendedScanClients =
                Collections.newSetFromMap(new ConcurrentHashMap<ScanClient, Boolean>());
        mService = service;
        mAdapterService = adapterService;
        mScanNative = new ScanNative();
        mDm = mService.getSystemService(DisplayManager.class);
        mActivityManager = mService.getSystemService(ActivityManager.class);
        mLocationManager = mService.getSystemService(LocationManager.class);
        mAdapterService = adapterService;
        mLocationManager = mAdapterService.getSystemService(LocationManager.class);
        mBluetoothAdapterProxy = bluetoothAdapterProxy;
        mIsConnecting = false;

+7 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.app.ActivityManager;
import android.bluetooth.le.ScanFilter;
import android.bluetooth.le.ScanSettings;
import android.content.Context;
import android.location.LocationManager;
import android.os.Binder;
import android.os.Handler;
import android.os.Message;
@@ -90,6 +91,7 @@ public class ScanManagerTest {
    @Rule public final ServiceTestRule mServiceRule = new ServiceTestRule();
    @Mock private AdapterService mAdapterService;
    @Mock private BluetoothAdapterProxy mBluetoothAdapterProxy;
    @Mock private LocationManager mLocationManager;
    @Mock private GattObjectsFactory mFactory;
    @Mock private GattNativeInterface mNativeInterface;
    @Mock private ScanNativeInterface mScanNativeInterface;
@@ -109,6 +111,11 @@ public class ScanManagerTest {
                .thenReturn(DEFAULT_NUM_OFFLOAD_SCAN_FILTER);
        when(mAdapterService.getOffloadedScanResultStorage())
                .thenReturn(DEFAULT_BYTES_OFFLOAD_SCAN_RESULT_STORAGE);
        when(mAdapterService.getSystemService(Context.LOCATION_SERVICE))
                .thenReturn(mLocationManager);
        when(mAdapterService.getSystemServiceName(LocationManager.class))
                .thenReturn(Context.LOCATION_SERVICE);
        doReturn(true).when(mLocationManager).isLocationEnabled();

        BluetoothAdapterProxy.setInstanceForTesting(mBluetoothAdapterProxy);
        // Needed to mock Native call/callback when hw offload scan filter is enabled