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

Commit 1f81a900 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Check permission before sending batch scan result" into rvc-dev am:...

Merge "Check permission before sending batch scan result" into rvc-dev am: 5d39ae18 am: f757ad33 am: 6f5467bd

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Bluetooth/+/13063901

Change-Id: I511d142a0b8e29f15f7f0f4574a9b215bec4cb59
parents 961cb5d1 6f5467bd
Loading
Loading
Loading
Loading
+55 −4
Original line number Diff line number Diff line
@@ -1651,6 +1651,15 @@ public class GattService extends ProfileService {
        mScanManager.callbackDone(clientIf, status);
    }

    ScanClient findBatchScanClientById(int scannerId) {
        for (ScanClient client : mScanManager.getBatchScanQueue()) {
            if (client.scannerId == scannerId) {
                return client;
            }
        }
        return null;
    }

    void onBatchScanReports(int status, int scannerId, int reportType, int numRecords,
            byte[] recordData) throws RemoteException {
        if (DBG) {
@@ -1665,12 +1674,36 @@ public class GattService extends ProfileService {
            if (app == null) {
                return;
            }

            ScanClient client = findBatchScanClientById(scannerId);
            if (client == null) {
                return;
            }

            ArrayList<ScanResult> permittedResults;
            if (hasScanResultPermission(client)) {
                permittedResults = new ArrayList<ScanResult>(results);
            } else {
                permittedResults = new ArrayList<ScanResult>();
                for (ScanResult scanResult : results) {
                    for (String associatedDevice : client.associatedDevices) {
                        if (associatedDevice.equalsIgnoreCase(scanResult.getDevice()
                                    .getAddress())) {
                            permittedResults.add(scanResult);
                        }
                    }
                }
                if (permittedResults.isEmpty()) {
                    return;
                }
            }

            if (app.callback != null) {
                app.callback.onBatchScanResults(new ArrayList<ScanResult>(results));
                app.callback.onBatchScanResults(permittedResults);
            } else {
                // PendingIntent based
                try {
                    sendResultsByPendingIntent(app.info, new ArrayList<ScanResult>(results),
                    sendResultsByPendingIntent(app.info, permittedResults,
                            ScanSettings.CALLBACK_TYPE_ALL_MATCHES);
                } catch (PendingIntent.CanceledException e) {
                }
@@ -1706,13 +1739,31 @@ public class GattService extends ProfileService {
        if (app == null) {
            return;
        }

        ArrayList<ScanResult> permittedResults;
        if (hasScanResultPermission(client)) {
            permittedResults = new ArrayList<ScanResult>(allResults);
        } else {
            permittedResults = new ArrayList<ScanResult>();
            for (ScanResult scanResult : allResults) {
                for (String associatedDevice : client.associatedDevices) {
                    if (associatedDevice.equalsIgnoreCase(scanResult.getDevice().getAddress())) {
                        permittedResults.add(scanResult);
                    }
                }
            }
            if (permittedResults.isEmpty()) {
                return;
            }
        }

        if (client.filters == null || client.filters.isEmpty()) {
            sendBatchScanResults(app, client, new ArrayList<ScanResult>(allResults));
            sendBatchScanResults(app, client, permittedResults);
            // TODO: Question to reviewer: Shouldn't there be a return here?
        }
        // Reconstruct the scan results.
        ArrayList<ScanResult> results = new ArrayList<ScanResult>();
        for (ScanResult scanResult : allResults) {
        for (ScanResult scanResult : permittedResults) {
            if (matchesFilters(client, scanResult)) {
                results.add(scanResult);
            }