Loading android/app/src/com/android/bluetooth/gatt/AdvertiseManager.java +0 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); Loading android/app/src/com/android/bluetooth/gatt/GattService.java +49 −9 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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 { Loading Loading @@ -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) { Loading Loading @@ -950,13 +964,37 @@ public class GattService extends ProfileService { Log.d(TAG, "onBatchScanReports() - clientIf=" + clientIf + ", status=" + status + ", reportType=" + reportType + ", numRecords=" + numRecords); } mScanManager.callbackDone(clientIf, status); Set<ScanResult> results = parseBatchScanResults(numRecords, reportType, recordData); 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; Set<ScanResult> results = parseBatchScanResults(numRecords, reportType, recordData); for (ScanResult result : new ArrayList<ScanResult>(results)) { Log.d(TAG, result.getScanRecord().toString()); } 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(results); } private Set<ScanResult> parseBatchScanResults(int numRecords, int reportType, Loading Loading @@ -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)); } Loading android/app/src/com/android/bluetooth/gatt/ScanManager.java +18 −10 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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); } } Loading Loading @@ -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()); } } Loading Loading @@ -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(); } Loading @@ -432,7 +435,9 @@ public class ScanManager { return; } int resultType = getResultType(client.settings); resetCountDownLatch(); gattClientReadScanReportsNative(client.clientIf, resultType); waitForCallback(); } void cleanup() { Loading Loading @@ -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>(); Loading Loading
android/app/src/com/android/bluetooth/gatt/AdvertiseManager.java +0 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); Loading
android/app/src/com/android/bluetooth/gatt/GattService.java +49 −9 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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 { Loading Loading @@ -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) { Loading Loading @@ -950,13 +964,37 @@ public class GattService extends ProfileService { Log.d(TAG, "onBatchScanReports() - clientIf=" + clientIf + ", status=" + status + ", reportType=" + reportType + ", numRecords=" + numRecords); } mScanManager.callbackDone(clientIf, status); Set<ScanResult> results = parseBatchScanResults(numRecords, reportType, recordData); 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; Set<ScanResult> results = parseBatchScanResults(numRecords, reportType, recordData); for (ScanResult result : new ArrayList<ScanResult>(results)) { Log.d(TAG, result.getScanRecord().toString()); } 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(results); } private Set<ScanResult> parseBatchScanResults(int numRecords, int reportType, Loading Loading @@ -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)); } Loading
android/app/src/com/android/bluetooth/gatt/ScanManager.java +18 −10 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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); } } Loading Loading @@ -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()); } } Loading Loading @@ -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(); } Loading @@ -432,7 +435,9 @@ public class ScanManager { return; } int resultType = getResultType(client.settings); resetCountDownLatch(); gattClientReadScanReportsNative(client.clientIf, resultType); waitForCallback(); } void cleanup() { Loading Loading @@ -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>(); Loading