OSDN Git Service

Merge commit '98691c26ecdaf8689739966b1aeeaa54f3fd1eb2' into manual_merge_98691c2
authorAjay Panicker <apanicke@google.com>
Fri, 6 May 2016 23:10:04 +0000 (16:10 -0700)
committerAjay Panicker <apanicke@google.com>
Fri, 6 May 2016 23:10:04 +0000 (16:10 -0700)
Change-Id: I57aeffc87caa6da75773d811eb929d9c2aeca13d

1  2 
src/com/android/bluetooth/gatt/GattService.java
src/com/android/bluetooth/gatt/ScanClient.java
src/com/android/bluetooth/gatt/ScanManager.java

@@@ -44,9 -43,8 +44,11 @@@ import java.util.UUID
      // Pre-M apps are allowed to get scan results even if location is disabled
      boolean legacyForegroundApp;
  
 +    // Who is responsible for this scan.
 +    WorkSource workSource;
 +
+     AppScanStats stats = null;
      private static final ScanSettings DEFAULT_SCAN_SETTINGS = new ScanSettings.Builder()
              .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();
  
@@@ -220,28 -223,28 +227,41 @@@ public class ScanManager 
                  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;
              }