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

Commit 80bd2423 authored by William Escande's avatar William Escande Committed by Automerger Merge Worker
Browse files

Merge "LeAudio: Do not use framework to start/stop scan" into main am: b9ee7a34

parents 06f6570e b9ee7a34
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
@@ -1821,21 +1821,60 @@ public class LeAudioService extends ProfileService {
                return;
            }
            if (Flags.scanManagerRefactor()) {
                mAdapterService
                        .getBluetoothScanController()
                        .getTransitionalScanHelper()
                        .stopScanInternal(mScannerId);

                mAdapterService
                        .getBluetoothScanController()
                        .getTransitionalScanHelper()
                        .unregisterScannerInternal(mScannerId);
            } else {
                mAdapterService
                        .getBluetoothGattService()
                        .getTransitionalScanHelper()
                        .stopScanInternal(mScannerId);

                mAdapterService
                        .getBluetoothGattService()
                        .getTransitionalScanHelper()
                        .unregisterScannerInternal(mScannerId);
            }
            mScannerId = 0;
        }

        @Override
        public synchronized void onScannerRegistered(int status, int scannerId) {
            mScannerId = scannerId;

            /* Filter we are building here will not match to anything.
             * Eventually we should be able to start scan from native when
             * b/276350722 is done
             */
            ScanFilter filter =
                    new ScanFilter.Builder()
                            .setServiceData(BluetoothUuid.LE_AUDIO, new byte[] {0x11})
                            .build();

            ScanSettings settings =
                    new ScanSettings.Builder()
                            .setLegacy(false)
                            .setScanMode(ScanSettings.SCAN_MODE_BALANCED)
                            .setPhy(BluetoothDevice.PHY_LE_1M)
                            .build();

            if (Flags.scanManagerRefactor()) {
                mAdapterService
                        .getBluetoothScanController()
                        .getTransitionalScanHelper()
                        .startScanInternal(scannerId, settings, List.of(filter));
            } else {
                mAdapterService
                        .getBluetoothGattService()
                        .getTransitionalScanHelper()
                        .startScanInternal(scannerId, settings, List.of(filter));
            }
        }

        // Eventually we should be able to start scan from native when b/276350722 is done
+30 −1
Original line number Diff line number Diff line
@@ -1182,12 +1182,36 @@ public class TransitionalScanHelper {
                Utils.checkCallerHasScanWithoutLocationPermission(mContext);
        scanClient.associatedDevices = getAssociatedDevices(callingPackage);

        startScan(scannerId, settings, filters, scanClient);
    }

    /** Intended for internal use within the Bluetooth app. Bypass permission check */
    public void startScanInternal(int scannerId, ScanSettings settings, List<ScanFilter> filters) {
        final ScanClient scanClient = new ScanClient(scannerId, settings, filters);
        scanClient.userHandle = Binder.getCallingUserHandle();
        scanClient.eligibleForSanitizedExposureNotification = false;
        scanClient.hasDisavowedLocation = false;
        scanClient.isQApp = true;
        scanClient.hasNetworkSettingsPermission =
                Utils.checkCallerHasNetworkSettingsPermission(mContext);
        scanClient.hasNetworkSetupWizardPermission =
                Utils.checkCallerHasNetworkSetupWizardPermission(mContext);
        scanClient.hasScanWithoutLocationPermission =
                Utils.checkCallerHasScanWithoutLocationPermission(mContext);
        scanClient.associatedDevices = Collections.emptyList();

        startScan(scannerId, settings, filters, scanClient);
    }

    private void startScan(
            int scannerId, ScanSettings settings, List<ScanFilter> filters, ScanClient scanClient) {
        AppScanStats app = mScannerMap.getAppScanStatsById(scannerId);
        ContextMap.App cbApp = mScannerMap.getById(scannerId);
        if (app != null) {
            scanClient.stats = app;
            boolean isFilteredScan = (filters != null) && !filters.isEmpty();
            boolean isCallbackScan = false;

            ContextMap.App cbApp = mScannerMap.getById(scannerId);
            if (cbApp != null) {
                isCallbackScan = cbApp.callback != null;
            }
@@ -1319,6 +1343,11 @@ public class TransitionalScanHelper {
                mContext, attributionSource, "ScanHelper stopScan")) {
            return;
        }
        stopScanInternal(scannerId);
    }

    /** Intended for internal use within the Bluetooth app. Bypass permission check */
    public void stopScanInternal(int scannerId) {
        int scanQueueSize =
                mScanManager.getBatchScanQueue().size() + mScanManager.getRegularScanQueue().size();
        Log.d(TAG, "stopScan() - queue size =" + scanQueueSize);