mScanNative.startRegularScan(client);
if (!mScanNative.isOpportunisticScanClient(client)) {
mScanNative.configureRegularScanParams();
+
+ if (!mScanNative.isFirstMatchScanClient(client)) {
+ Message msg = mHandler.obtainMessage(MSG_SCAN_TIMEOUT);
+ msg.obj = client;
+ // Only one timeout message should exist at any time
+ mHandler.removeMessages(SCAN_TIMEOUT_MS);
+ mHandler.sendMessageDelayed(msg, SCAN_TIMEOUT_MS);
+ }
}
+
+ // Update BatteryStats with this workload.
+ try {
+ mBatteryStats.noteBleScanStarted(client.workSource);
+ } catch (RemoteException e) {
+ /* ignore */
+ }
}
}
void handleStopScan(ScanClient client) {
Utils.enforceAdminPermission(mService);
if (client == null) return;
+
if (mRegularScanClients.contains(client)) {
+ // The ScanClient passed in just holds the clientIf. We retrieve the real client,
+ // which may have workSource set.
+ client = mScanNative.getRegularScanClient(client.clientIf);
+ if (client == null) return;
+
mScanNative.stopRegularScan(client);
+
+ if (mScanNative.numRegularScanClients() == 0) {
+ mHandler.removeMessages(MSG_SCAN_TIMEOUT);
+ }
+
if (!mScanNative.isOpportunisticScanClient(client)) {
mScanNative.configureRegularScanParams();
}
removeScanFilters(client.clientIf);
}
- // Find the scan client information
- ScanClient getClient(int clientIf) {
+ void regularScanTimeout() {
+ for (ScanClient client : mRegularScanClients) {
+ if (!isOpportunisticScanClient(client) && !isFirstMatchScanClient(client)) {
+ logd("clientIf set to scan opportunisticly: " + client.clientIf);
+ setOpportunisticScanClient(client);
+ client.stats.setScanTimeout();
+ }
+ }
+
+ // The scan should continue for background scans
+ configureRegularScanParams();
+ if (numRegularScanClients() == 0) {
+ logd("stop scan");
+ gattClientScanNative(false);
+ }
+ }
+
+ void setOpportunisticScanClient(ScanClient client) {
+ // TODO: Add constructor to ScanSettings.Builder
+ // that can copy values from an existing ScanSettings object
+ ScanSettings.Builder builder = new ScanSettings.Builder();
+ ScanSettings settings = client.settings;
+ builder.setScanMode(ScanSettings.SCAN_MODE_OPPORTUNISTIC);
+ builder.setCallbackType(settings.getCallbackType());
+ builder.setScanResultType(settings.getScanResultType());
+ builder.setReportDelay(settings.getReportDelayMillis());
+ builder.setNumOfMatches(settings.getNumOfMatches());
+ client.settings = builder.build();
+ }
+
+ // Find the regular scan client information.
+ ScanClient getRegularScanClient(int clientIf) {
for (ScanClient client : mRegularScanClients) {
if (client.clientIf == clientIf) return client;
}