Check permission before sending batch scan result

Use same checks as for regular scan results

Bug: 172670415
Test: compilation
Merged-In: I4274026943ce64a51a30c3fbf6cc85eec853ad4f
Change-Id: I4274026943ce64a51a30c3fbf6cc85eec853ad4f
diff --git a/src/com/android/bluetooth/gatt/GattService.java b/src/com/android/bluetooth/gatt/GattService.java
index 8a3a1aa..80046d0 100644
--- a/src/com/android/bluetooth/gatt/GattService.java
+++ b/src/com/android/bluetooth/gatt/GattService.java
@@ -1551,6 +1551,15 @@
         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) {
@@ -1565,6 +1574,17 @@
             if (app == null) {
                 return;
             }
+
+            ScanClient client = findBatchScanClientById(scannerId);
+            if (client == null) {
+                return;
+            }
+
+            // Do not report if location mode is OFF or the client has no location permission
+            if (!hasScanResultPermission(client)) {
+                return;
+            }
+
             if (app.callback != null) {
                 app.callback.onBatchScanResults(new ArrayList<ScanResult>(results));
             } else {
@@ -1606,6 +1626,12 @@
         if (app == null) {
             return;
         }
+
+        // Do not report if location mode is OFF or the client has no location permission
+        if (!hasScanResultPermission(client)) {
+            return;
+        }
+
         if (client.filters == null || client.filters.isEmpty()) {
             sendBatchScanResults(app, client, new ArrayList<ScanResult>(allResults));
             // TODO: Question to reviewer: Shouldn't there be a return here?