OSDN Git Service

Set scan parameters in ScanClient based on BluetoothLeScanSettings
authorPrerepa Viswanadham <dham@google.com>
Fri, 30 May 2014 22:53:30 +0000 (15:53 -0700)
committerPrerepa Viswanadham <dham@google.com>
Fri, 30 May 2014 23:14:00 +0000 (23:14 +0000)
configuration

scan_mode              scan_window_ms    scan_interval_ms
SCAN_MODE_LOW_POWER    500               5000
SCAN_MODE_BALANCED     1000              5000
SCAN_MODE_LOW_LATENCY  2500              5000

Change-Id: I2382c7b584b102555f175a94206c4379141af3fa

src/com/android/bluetooth/gatt/ScanClient.java

index 5b0f5d4..db7034b 100644 (file)
@@ -39,6 +39,16 @@ import java.util.UUID;
      */
     private static final int LE_SCAN_INTERVAL_MS = 100;
 
+    /**
+     * Scan params corresponding to scan setting
+     */
+    private static final int SCAN_MODE_LOW_POWER_WINDOW_MS = 500;
+    private static final int SCAN_MODE_LOW_POWER_INTERVAL_MS = 5000;
+    private static final int SCAN_MODE_BALANCED_WINDOW_MS = 1000;
+    private static final int SCAN_MODE_BALANCED_INTERVAL_MS = 5000;
+    private static final int SCAN_MODE_LOW_LATENCY_WINDOW_MS = 2500;
+    private static final int SCAN_MODE_LOW_LATENCY_INTERVAL_MS = 5000;
+
     int appIf;
     boolean isServer;
     UUID[] uuids;
@@ -73,5 +83,25 @@ import java.util.UUID;
         this.scanInterval = scanInterval;
         this.settings = settings;
         this.filters = filters;
+        if (settings != null) {
+            switch (settings.getScanMode()) {
+                case BluetoothLeScanSettings.SCAN_MODE_LOW_POWER:
+                    this.scanWindow = SCAN_MODE_LOW_POWER_WINDOW_MS;
+                    this.scanInterval = SCAN_MODE_LOW_POWER_INTERVAL_MS;
+                    break;
+                case BluetoothLeScanSettings.SCAN_MODE_BALANCED:
+                    this.scanWindow = SCAN_MODE_BALANCED_WINDOW_MS;
+                    this.scanInterval = SCAN_MODE_BALANCED_INTERVAL_MS;
+                    break;
+                case BluetoothLeScanSettings.SCAN_MODE_LOW_LATENCY:
+                    this.scanWindow = SCAN_MODE_LOW_LATENCY_WINDOW_MS;
+                    this.scanInterval = SCAN_MODE_LOW_LATENCY_INTERVAL_MS;
+                    break;
+                default:
+                    this.scanWindow = SCAN_MODE_BALANCED_WINDOW_MS;
+                    this.scanInterval = SCAN_MODE_BALANCED_INTERVAL_MS;
+                    break;
+            }
+        }
     }
 }