summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2020-12-05 01:31:16 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-12-05 01:31:16 +0000
commitabf9241f4aeed0a74c2cadd5f1527a09c2e97642 (patch)
tree0d486e8408b479323db1b33e573797362bd958f9
parent888f8230984ccae70086b64892508fef53bec6d6 (diff)
parent9c202eda348241c5adf1b18a5a1e0ad31b2d30f8 (diff)
downloadBluetooth-abf9241f4aeed0a74c2cadd5f1527a09c2e97642.tar.gz
Merge "Check permission before sending batch scan result" into rvc-dev
-rw-r--r--src/com/android/bluetooth/gatt/GattService.java59
1 files changed, 55 insertions, 4 deletions
diff --git a/src/com/android/bluetooth/gatt/GattService.java b/src/com/android/bluetooth/gatt/GattService.java
index 87e6e52a3..8a792fe6c 100644
--- a/src/com/android/bluetooth/gatt/GattService.java
+++ b/src/com/android/bluetooth/gatt/GattService.java
@@ -1633,6 +1633,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) {
@@ -1647,12 +1656,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) {
}
@@ -1688,13 +1721,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);
}