summaryrefslogtreecommitdiffstats
path: root/src/com/android/bluetooth/gatt
diff options
context:
space:
mode:
authorWei Wang <weiwa@google.com>2014-08-04 23:17:29 -0700
committerWei Wang <weiwa@google.com>2014-08-06 14:11:25 -0700
commit00975169ba4eb5251397a66532ee9a3288c0f137 (patch)
treed80647c3f0829c7bbfc9cfdd3fa21ea26c2ce0a1 /src/com/android/bluetooth/gatt
parent475a4f7727a082ccf289ce406e75c463750a515c (diff)
downloadandroid_packages_apps_Bluetooth-00975169ba4eb5251397a66532ee9a3288c0f137.tar.gz
android_packages_apps_Bluetooth-00975169ba4eb5251397a66532ee9a3288c0f137.tar.bz2
android_packages_apps_Bluetooth-00975169ba4eb5251397a66532ee9a3288c0f137.zip
Clear pending data and allow all filter when batch stopped.
Also send batch data to multiple clients for full batch. b/16802098 Change-Id: Ife1723b818531fcf2cff897686f33f6b0a1d0aaa
Diffstat (limited to 'src/com/android/bluetooth/gatt')
-rw-r--r--src/com/android/bluetooth/gatt/AdvertiseManager.java2
-rw-r--r--src/com/android/bluetooth/gatt/GattService.java58
-rw-r--r--src/com/android/bluetooth/gatt/ScanManager.java28
3 files changed, 67 insertions, 21 deletions
diff --git a/src/com/android/bluetooth/gatt/AdvertiseManager.java b/src/com/android/bluetooth/gatt/AdvertiseManager.java
index 87f235c57..e1c271213 100644
--- a/src/com/android/bluetooth/gatt/AdvertiseManager.java
+++ b/src/com/android/bluetooth/gatt/AdvertiseManager.java
@@ -34,7 +34,6 @@ import com.android.bluetooth.btservice.AdapterService;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.HashSet;
-import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
@@ -207,7 +206,6 @@ class AdvertiseManager {
if (client == null) {
return;
}
- int clientIf = client.clientIf;
logd("advertise clients size " + mAdvertiseClients.size());
if (mAdvertiseClients.contains(client)) {
mAdvertiseNative.stopAdvertising(client);
diff --git a/src/com/android/bluetooth/gatt/GattService.java b/src/com/android/bluetooth/gatt/GattService.java
index 92a69c016..fa3a5af94 100644
--- a/src/com/android/bluetooth/gatt/GattService.java
+++ b/src/com/android/bluetooth/gatt/GattService.java
@@ -220,7 +220,7 @@ public class GattService extends ProfileService {
public void binderDied() {
if (DBG) Log.d(TAG, "Binder is dead - unregistering client (" + mAppIf + ")!");
- if (mScanManager.scanQueue().contains(new ScanClient(mAppIf, false))) {
+ if (isScanClient(mAppIf)) {
stopScan(mAppIf, false);
} else {
stopMultiAdvertising(mAppIf);
@@ -229,6 +229,20 @@ public class GattService extends ProfileService {
// condition.
unregisterClient(mAppIf);
}
+
+ private boolean isScanClient(int clientIf) {
+ for (ScanClient client : mScanManager.getRegularScanQueue()) {
+ if (client.clientIf == clientIf) {
+ return true;
+ }
+ }
+ for (ScanClient client : mScanManager.getBatchScanQueue()) {
+ if (client.clientIf == clientIf) {
+ return true;
+ }
+ }
+ return false;
+ }
}
class ServerDeathRecipient implements IBinder.DeathRecipient {
@@ -539,7 +553,7 @@ public class GattService extends ProfileService {
+ ", rssi=" + rssi);
ScanRecord record = ScanRecord.parseFromBytes(adv_data);
List<UUID> remoteUuids = parseUuids(adv_data);
- for (ScanClient client : mScanManager.scanQueue()) {
+ for (ScanClient client : mScanManager.getRegularScanQueue()) {
if (client.uuids.length > 0) {
int matches = 0;
for (UUID search : client.uuids) {
@@ -950,13 +964,37 @@ public class GattService extends ProfileService {
Log.d(TAG, "onBatchScanReports() - clientIf=" + clientIf + ", status=" + status
+ ", reportType=" + reportType + ", numRecords=" + numRecords);
}
- ClientMap.App app = mClientMap.getById(clientIf);
- if (app == null) return;
+ mScanManager.callbackDone(clientIf, status);
Set<ScanResult> results = parseBatchScanResults(numRecords, reportType, recordData);
- for (ScanResult result : new ArrayList<ScanResult>(results)) {
- Log.d(TAG, result.getScanRecord().toString());
+ if (reportType == ScanManager.SCAN_RESULT_TYPE_TRUNCATED) {
+ // We only support single client for truncated mode.
+ ClientMap.App app = mClientMap.getById(clientIf);
+ if (app == null) return;
+ app.callback.onBatchScanResults(new ArrayList<ScanResult>(results));
+ } else {
+ for (ScanClient client : mScanManager.getBatchScanQueue()) {
+ // Deliver results for each client.
+ deliverBatchScan(client, results);
+ }
+ }
+ }
+
+ // Check and deliver scan results for different scan clients.
+ private void deliverBatchScan(ScanClient client, Set<ScanResult> allResults) throws
+ RemoteException {
+ ClientMap.App app = mClientMap.getById(client.clientIf);
+ if (app == null) return;
+ if (client.filters == null || client.filters.isEmpty()) {
+ app.callback.onBatchScanResults(new ArrayList<ScanResult>(allResults));
+ }
+ // Reconstruct the scan results.
+ List<ScanResult> results = new ArrayList<ScanResult>();
+ for (ScanResult scanResult : allResults) {
+ if (matchesFilters(client, scanResult)) {
+ results.add(scanResult);
+ }
}
- app.callback.onBatchScanResults(new ArrayList<ScanResult>(results));
+ app.callback.onBatchScanResults(results);
}
private Set<ScanResult> parseBatchScanResults(int numRecords, int reportType,
@@ -1215,7 +1253,7 @@ public class GattService extends ProfileService {
void startScan(int appIf, boolean isServer, ScanSettings settings,
List<ScanFilter> filters) {
- if (DBG) Log.d(TAG, "start scan with filters ");
+ if (DBG) Log.d(TAG, "start scan with filters");
enforceAdminPermission();
mScanManager.startScan(new ScanClient(appIf, isServer, settings, filters));
}
@@ -1228,7 +1266,9 @@ public class GattService extends ProfileService {
void stopScan(int appIf, boolean isServer) {
enforceAdminPermission();
- if (DBG) Log.d(TAG, "stopScan() - queue=" + mScanManager.scanQueue().size());
+ int scanQueueSize = mScanManager.getBatchScanQueue().size() +
+ mScanManager.getRegularScanQueue().size();
+ if (DBG) Log.d(TAG, "stopScan() - queue size =" + scanQueueSize);
mScanManager.stopScan(new ScanClient(appIf, isServer));
}
diff --git a/src/com/android/bluetooth/gatt/ScanManager.java b/src/com/android/bluetooth/gatt/ScanManager.java
index e6e8a42df..b5df5f777 100644
--- a/src/com/android/bluetooth/gatt/ScanManager.java
+++ b/src/com/android/bluetooth/gatt/ScanManager.java
@@ -101,13 +101,17 @@ public class ScanManager {
}
/**
- * Returns the combined scan queue of regular scans and batch scans.
+ * Returns the regular scan queue.
*/
- List<ScanClient> scanQueue() {
- List<ScanClient> clients = new ArrayList<>();
- clients.addAll(mRegularScanClients);
- clients.addAll(mBatchClients);
- return clients;
+ Set<ScanClient> getRegularScanQueue() {
+ return mRegularScanClients;
+ }
+
+ /**
+ * Returns batch scan queue.
+ */
+ Set<ScanClient> getBatchScanQueue() {
+ return mBatchClients;
}
void startScan(ScanClient client) {
@@ -195,11 +199,9 @@ public class ScanManager {
void handleStopScan(ScanClient client) {
Utils.enforceAdminPermission(mService);
if (mRegularScanClients.contains(client)) {
- mRegularScanClients.remove(client);
mScanNative.configureRegularScanParams();
mScanNative.stopRegularScan(client);
} else {
- mBatchClients.remove(client);
mScanNative.stopBatchScan(client);
}
}
@@ -286,7 +288,7 @@ public class ScanManager {
if (mBatchClients.isEmpty()) {
return;
}
- // TODO: find out if we need to flush all clients at once.
+ // Note this actually flushes all pending batch data.
flushBatchScanResults(mBatchClients.iterator().next());
}
}
@@ -418,9 +420,10 @@ public class ScanManager {
}
void stopBatchScan(ScanClient client) {
+ flushBatchResults(client.clientIf);
removeScanFilters(client.clientIf);
- mBatchClients.remove(client);
gattClientStopBatchScanNative(client.clientIf);
+ mBatchClients.remove(client);
setBatchAlarm();
}
@@ -432,7 +435,9 @@ public class ScanManager {
return;
}
int resultType = getResultType(client.settings);
+ resetCountDownLatch();
gattClientReadScanReportsNative(client.clientIf, resultType);
+ waitForCallback();
}
void cleanup() {
@@ -463,6 +468,9 @@ public class ScanManager {
resetCountDownLatch();
configureFilterParamter(clientIf, client, ALLOW_ALL_FILTER_SELECTION,
ALLOW_ALL_FILTER_INDEX);
+ Deque<Integer> clientFilterIndices = new ArrayDeque<Integer>();
+ clientFilterIndices.add(ALLOW_ALL_FILTER_INDEX);
+ mClientFilterIndexMap.put(clientIf, clientFilterIndices);
waitForCallback();
} else {
Deque<Integer> clientFilterIndices = new ArrayDeque<Integer>();