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

Commit 8ebb887d authored by William Escande's avatar William Escande
Browse files

Trunk Stable/ScanManager: Use static flagging

Bug: 323981134
Bug: 316266556
Test: m Bluetooth | mechanical refactor
Change-Id: Iedea21658736e427634c0a30b554a4367c207cb6
parent aeaae719
Loading
Loading
Loading
Loading
+2 −5
Original line number Original line Diff line number Diff line
@@ -22,7 +22,6 @@ import android.util.Log;
import com.android.bluetooth.Utils;
import com.android.bluetooth.Utils;
import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.BluetoothAdapterProxy;
import com.android.bluetooth.btservice.BluetoothAdapterProxy;
import com.android.bluetooth.flags.FeatureFlags;
import com.android.bluetooth.le_scan.PeriodicScanManager;
import com.android.bluetooth.le_scan.PeriodicScanManager;
import com.android.bluetooth.le_scan.ScanManager;
import com.android.bluetooth.le_scan.ScanManager;
import com.android.bluetooth.le_scan.ScanNativeInterface;
import com.android.bluetooth.le_scan.ScanNativeInterface;
@@ -86,10 +85,8 @@ public class GattObjectsFactory {
            GattService service,
            GattService service,
            AdapterService adapterService,
            AdapterService adapterService,
            BluetoothAdapterProxy bluetoothAdapterProxy,
            BluetoothAdapterProxy bluetoothAdapterProxy,
            Looper looper,
            Looper looper) {
            FeatureFlags featureFlags) {
        return new ScanManager(service, adapterService, bluetoothAdapterProxy, looper);
        return new ScanManager(
                service, adapterService, bluetoothAdapterProxy, looper, featureFlags);
    }
    }


    public PeriodicScanManager createPeriodicScanManager(AdapterService adapterService) {
    public PeriodicScanManager createPeriodicScanManager(AdapterService adapterService) {
+1 −9
Original line number Original line Diff line number Diff line
@@ -93,8 +93,6 @@ import com.android.bluetooth.btservice.BluetoothAdapterProxy;
import com.android.bluetooth.btservice.CompanionManager;
import com.android.bluetooth.btservice.CompanionManager;
import com.android.bluetooth.btservice.MetricsLogger;
import com.android.bluetooth.btservice.MetricsLogger;
import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.flags.FeatureFlags;
import com.android.bluetooth.flags.FeatureFlagsImpl;
import com.android.bluetooth.flags.Flags;
import com.android.bluetooth.flags.Flags;
import com.android.bluetooth.le_scan.AppScanStats;
import com.android.bluetooth.le_scan.AppScanStats;
import com.android.bluetooth.le_scan.PeriodicScanManager;
import com.android.bluetooth.le_scan.PeriodicScanManager;
@@ -288,7 +286,6 @@ public class GattService extends ProfileService {
     */
     */
    private final HashMap<String, Integer> mPermits = new HashMap<>();
    private final HashMap<String, Integer> mPermits = new HashMap<>();


    private FeatureFlags mFeatureFlags;
    private AdapterService mAdapterService;
    private AdapterService mAdapterService;
    private BluetoothAdapterProxy mBluetoothAdapterProxy;
    private BluetoothAdapterProxy mBluetoothAdapterProxy;
    AdvertiseManager mAdvertiseManager;
    AdvertiseManager mAdvertiseManager;
@@ -353,7 +350,6 @@ public class GattService extends ProfileService {
        mNativeInterface = GattObjectsFactory.getInstance().getNativeInterface();
        mNativeInterface = GattObjectsFactory.getInstance().getNativeInterface();
        mNativeInterface.init(this);
        mNativeInterface.init(this);
        mAdapterService = AdapterService.getAdapterService();
        mAdapterService = AdapterService.getAdapterService();
        mFeatureFlags = new FeatureFlagsImpl();
        mBluetoothAdapterProxy = BluetoothAdapterProxy.getInstance();
        mBluetoothAdapterProxy = BluetoothAdapterProxy.getInstance();
        mCompanionManager = getSystemService(CompanionDeviceManager.class);
        mCompanionManager = getSystemService(CompanionDeviceManager.class);
        mAppOps = getSystemService(AppOpsManager.class);
        mAppOps = getSystemService(AppOpsManager.class);
@@ -369,11 +365,7 @@ public class GattService extends ProfileService {
        mScanManager =
        mScanManager =
                GattObjectsFactory.getInstance()
                GattObjectsFactory.getInstance()
                        .createScanManager(
                        .createScanManager(
                                this,
                                this, mAdapterService, mBluetoothAdapterProxy, thread.getLooper());
                                mAdapterService,
                                mBluetoothAdapterProxy,
                                thread.getLooper(),
                                mFeatureFlags);


        mPeriodicScanManager = GattObjectsFactory.getInstance()
        mPeriodicScanManager = GattObjectsFactory.getInstance()
                .createPeriodicScanManager(mAdapterService);
                .createPeriodicScanManager(mAdapterService);
+3 −6
Original line number Original line Diff line number Diff line
@@ -46,7 +46,7 @@ import android.view.Display;
import com.android.bluetooth.Utils;
import com.android.bluetooth.Utils;
import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.BluetoothAdapterProxy;
import com.android.bluetooth.btservice.BluetoothAdapterProxy;
import com.android.bluetooth.flags.FeatureFlags;
import com.android.bluetooth.flags.Flags;
import com.android.bluetooth.gatt.FilterParams;
import com.android.bluetooth.gatt.FilterParams;
import com.android.bluetooth.gatt.GattObjectsFactory;
import com.android.bluetooth.gatt.GattObjectsFactory;
import com.android.bluetooth.gatt.GattService;
import com.android.bluetooth.gatt.GattService;
@@ -123,7 +123,6 @@ public class ScanManager {
    @GuardedBy("mCurUsedTrackableAdvertisementsLock")
    @GuardedBy("mCurUsedTrackableAdvertisementsLock")
    private int mCurUsedTrackableAdvertisements = 0;
    private int mCurUsedTrackableAdvertisements = 0;


    private final FeatureFlags mFeatureFlags;
    private final GattService mService;
    private final GattService mService;
    private final AdapterService mAdapterService;
    private final AdapterService mAdapterService;
    private BroadcastReceiver mBatchAlarmReceiver;
    private BroadcastReceiver mBatchAlarmReceiver;
@@ -168,8 +167,7 @@ public class ScanManager {
            GattService service,
            GattService service,
            AdapterService adapterService,
            AdapterService adapterService,
            BluetoothAdapterProxy bluetoothAdapterProxy,
            BluetoothAdapterProxy bluetoothAdapterProxy,
            Looper looper,
            Looper looper) {
            FeatureFlags featureFlags) {
        mRegularScanClients =
        mRegularScanClients =
                Collections.newSetFromMap(new ConcurrentHashMap<ScanClient, Boolean>());
                Collections.newSetFromMap(new ConcurrentHashMap<ScanClient, Boolean>());
        mBatchClients = Collections.newSetFromMap(new ConcurrentHashMap<ScanClient, Boolean>());
        mBatchClients = Collections.newSetFromMap(new ConcurrentHashMap<ScanClient, Boolean>());
@@ -178,7 +176,6 @@ public class ScanManager {
        mService = service;
        mService = service;
        mAdapterService = adapterService;
        mAdapterService = adapterService;
        mScanNative = new ScanNative();
        mScanNative = new ScanNative();
        mFeatureFlags = featureFlags;
        mDm = mService.getSystemService(DisplayManager.class);
        mDm = mService.getSystemService(DisplayManager.class);
        mActivityManager = mService.getSystemService(ActivityManager.class);
        mActivityManager = mService.getSystemService(ActivityManager.class);
        mLocationManager = mAdapterService.getSystemService(LocationManager.class);
        mLocationManager = mAdapterService.getSystemService(LocationManager.class);
@@ -455,7 +452,7 @@ public class ScanManager {
                        Message msg = obtainMessage(MSG_SCAN_TIMEOUT);
                        Message msg = obtainMessage(MSG_SCAN_TIMEOUT);
                        msg.obj = client;
                        msg.obj = client;
                        // Only one timeout message should exist at any time
                        // Only one timeout message should exist at any time
                        if (mFeatureFlags.scanTimeoutReset()) {
                        if (Flags.scanTimeoutReset()) {
                            removeMessages(MSG_SCAN_TIMEOUT, client);
                            removeMessages(MSG_SCAN_TIMEOUT, client);
                        }
                        }
                        sendMessageDelayed(msg, mAdapterService.getScanTimeoutMillis());
                        sendMessageDelayed(msg, mAdapterService.getScanTimeoutMillis());
+1 −1
Original line number Original line Diff line number Diff line
@@ -134,7 +134,7 @@ public class GattServiceTest {


        GattObjectsFactory.setInstanceForTesting(mFactory);
        GattObjectsFactory.setInstanceForTesting(mFactory);
        doReturn(mNativeInterface).when(mFactory).getNativeInterface();
        doReturn(mNativeInterface).when(mFactory).getNativeInterface();
        doReturn(mScanManager).when(mFactory).createScanManager(any(), any(), any(), any(), any());
        doReturn(mScanManager).when(mFactory).createScanManager(any(), any(), any(), any());
        doReturn(mPeriodicScanManager).when(mFactory).createPeriodicScanManager(any());
        doReturn(mPeriodicScanManager).when(mFactory).createPeriodicScanManager(any());
        doReturn(mDistanceMeasurementManager).when(mFactory)
        doReturn(mDistanceMeasurementManager).when(mFactory)
                .createDistanceMeasurementManager(any());
                .createDistanceMeasurementManager(any());
+6 −7
Original line number Original line Diff line number Diff line
@@ -53,6 +53,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Handler;
import android.os.Message;
import android.os.Message;
import android.os.test.TestLooper;
import android.os.test.TestLooper;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import android.provider.Settings;
import android.test.mock.MockContentProvider;
import android.test.mock.MockContentProvider;
import android.test.mock.MockContentResolver;
import android.test.mock.MockContentResolver;
@@ -68,12 +69,10 @@ import com.android.bluetooth.TestUtils;
import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.BluetoothAdapterProxy;
import com.android.bluetooth.btservice.BluetoothAdapterProxy;
import com.android.bluetooth.btservice.MetricsLogger;
import com.android.bluetooth.btservice.MetricsLogger;
import com.android.bluetooth.flags.FakeFeatureFlagsImpl;
import com.android.bluetooth.flags.Flags;
import com.android.bluetooth.flags.Flags;
import com.android.bluetooth.gatt.GattNativeInterface;
import com.android.bluetooth.gatt.GattNativeInterface;
import com.android.bluetooth.gatt.GattObjectsFactory;
import com.android.bluetooth.gatt.GattObjectsFactory;
import com.android.bluetooth.gatt.GattService;
import com.android.bluetooth.gatt.GattService;
import com.android.bluetooth.le_scan.ScanClient;
import com.android.internal.app.IBatteryStats;
import com.android.internal.app.IBatteryStats;


import org.junit.After;
import org.junit.After;
@@ -122,8 +121,9 @@ public class ScanManagerTest {
    final BatteryStatsManager mBatteryStatsManager =
    final BatteryStatsManager mBatteryStatsManager =
            new BatteryStatsManager(mock(IBatteryStats.class));
            new BatteryStatsManager(mock(IBatteryStats.class));


    private FakeFeatureFlagsImpl mFakeFlagsImpl;
    @Rule public final ServiceTestRule mServiceRule = new ServiceTestRule();
    @Rule public final ServiceTestRule mServiceRule = new ServiceTestRule();
    @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();

    @Mock private AdapterService mAdapterService;
    @Mock private AdapterService mAdapterService;
    @Mock private GattService mMockGattService;
    @Mock private GattService mMockGattService;
    @Mock private BluetoothAdapterProxy mBluetoothAdapterProxy;
    @Mock private BluetoothAdapterProxy mBluetoothAdapterProxy;
@@ -190,8 +190,6 @@ public class ScanManagerTest {
        doReturn(mTargetContext.getUser()).when(mMockGattService).getUser();
        doReturn(mTargetContext.getUser()).when(mMockGattService).getUser();
        doReturn(mTargetContext.getPackageName()).when(mMockGattService).getPackageName();
        doReturn(mTargetContext.getPackageName()).when(mMockGattService).getPackageName();


        mFakeFlagsImpl = new FakeFeatureFlagsImpl();
        mFakeFlagsImpl.setFlag(Flags.FLAG_SCAN_TIMEOUT_RESET, true);
        mTestLooper = new TestLooper();
        mTestLooper = new TestLooper();
        mTestLooper.startAutoDispatch();
        mTestLooper.startAutoDispatch();
        mScanManager =
        mScanManager =
@@ -199,8 +197,7 @@ public class ScanManagerTest {
                        mMockGattService,
                        mMockGattService,
                        mAdapterService,
                        mAdapterService,
                        mBluetoothAdapterProxy,
                        mBluetoothAdapterProxy,
                        mTestLooper.getLooper(),
                        mTestLooper.getLooper());
                        mFakeFlagsImpl);


        mHandler = mScanManager.getClientHandler();
        mHandler = mScanManager.getClientHandler();
        assertThat(mHandler).isNotNull();
        assertThat(mHandler).isNotNull();
@@ -648,6 +645,8 @@ public class ScanManagerTest {


    @Test
    @Test
    public void testScanTimeoutResetForNewScan() {
    public void testScanTimeoutResetForNewScan() {
        mSetFlagsRule.enableFlags(Flags.FLAG_SCAN_TIMEOUT_RESET);

        mTestLooper.stopAutoDispatchAndIgnoreExceptions();
        mTestLooper.stopAutoDispatchAndIgnoreExceptions();
        // Set filtered scan flag
        // Set filtered scan flag
        final boolean isFiltered = false;
        final boolean isFiltered = false;