I have downloaded the AOSP Source code for Lollipop 5.0. In api level 21, under bluetooth low energy scan settings there are three options for scanning the ble devices- SCAN_MODE_BALANCED, SCAN_MODE_LOW_LATENCY, SCAN_MODE_LOW_POWER
. Are the based on different scan interval and scan window values? If so, where can I find the values defined for these macros in the source code directory.
Asked
Active
Viewed 6,130 times
5

Vikasdeep Singh
- 20,983
- 15
- 78
- 104

HRG
- 182
- 5
- 16
2 Answers
7
I found below values in http://androidxref.com/5.0.0_r2/xref/packages/apps/Bluetooth/src/com/android/bluetooth/gatt/ScanManager.java while greping the keyword "SCAN_MODE_BALANCED" :
/**
* Scan params corresponding to regular 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 = 2000;
private static final int SCAN_MODE_BALANCED_INTERVAL_MS = 5000;
private static final int SCAN_MODE_LOW_LATENCY_WINDOW_MS = 5000;
private static final int SCAN_MODE_LOW_LATENCY_INTERVAL_MS = 5000;
/**
* Scan params corresponding to batch scan setting
*/
private static final int SCAN_MODE_BATCH_LOW_POWER_WINDOW_MS = 1500;
private static final int SCAN_MODE_BATCH_LOW_POWER_INTERVAL_MS = 150000;
private static final int SCAN_MODE_BATCH_BALANCED_WINDOW_MS = 1500;
private static final int SCAN_MODE_BATCH_BALANCED_INTERVAL_MS = 15000;
private static final int SCAN_MODE_BATCH_LOW_LATENCY_WINDOW_MS = 1500;
private static final int SCAN_MODE_BATCH_LOW_LATENCY_INTERVAL_MS = 5000;
Also checkout out ScanManager.ScanNative.configureRegularScanParams(). Two params scanWindow
and scanInterval
are set according to the scan setting (ScanSettings.SCAN_MODE_LOW_POWER
, ScanSettings.SCAN_MODE_BALANCED
, ScanSettings.SCAN_MODE_LOW_LATENCY
), converted into BLE units, and then passed to gattSetScanParametersNative().
Hope this helps.

yanoken
- 98
- 1
- 6
-
3What does it exactly mean if I say I set my ScanSettings to SCAN_MODE_LOW_LATENCY ? Does it say it scans every 5 seconds for 5 seconds and then starts scanning again - I don't think this is the case as I have an application where the updates are faster than every 5 second. Could you please elaborate on interpreting these values? – BigPenguin Jun 11 '15 at 17:24
3
I'm not sure if this is accurate or if you can even use it to find the values you need, but I found some code from Google regarding scanning settings:
// Constants for Scan Cycle
// Low Power: 2.5 minute period with 1.5 seconds active (1% duty cycle)
/* @VisibleForTesting */ static final int LOW_POWER_IDLE_MILLIS = 148500;
/* @VisibleForTesting */ static final int LOW_POWER_ACTIVE_MILLIS = 1500;
// Balanced: 15 second period with 1.5 second active (10% duty cycle)
/* @VisibleForTesting */ static final int BALANCED_IDLE_MILLIS = 13500;
/* @VisibleForTesting */ static final int BALANCED_ACTIVE_MILLIS = 1500;
// Low Latency: 1.67 second period with 1.5 seconds active (90% duty cycle)
/* @VisibleForTesting */ static final int LOW_LATENCY_IDLE_MILLIS = 167;
/* @VisibleForTesting */ static final int LOW_LATENCY_ACTIVE_MILLIS = 1500;

Tim Tisdall
- 9,914
- 3
- 52
- 82
-
Thankyou Tim. But i couldnt find such kind of definitions in google android source code .After searching in driver level i found something here like this http://androidxref.com/5.0.0_r2/xref/external/bluetooth/bluedroid/stack/btm/btm_ble_int.h #define BTM_BLE_GAP_DISC_SCAN_INT 18 /* Interval(scan_int) = 11.25 ms= 0x0010 * 0.625 ms */ #define BTM_BLE_GAP_DISC_SCAN_WIN 18 /* scan_window = 11.25 ms= 0x0010 * 0.625 ms */ – HRG Jan 07 '15 at 04:35
-
is the above corresponds to the scan window and scan interval .But i wonder how they define the values for SCAN_MODE_BALANCED, SCAN_MODE_LOW_LATENCY, SCAN_MODE_LOW_POWER ! – HRG Jan 07 '15 at 04:37