diff options
author | Chienyuan <chienyuanhuang@google.com> | 2021-03-12 20:46:17 +0800 |
---|---|---|
committer | Chienyuan <chienyuanhuang@google.com> | 2021-03-16 17:53:19 +0800 |
commit | f757d2fa69546fc25e36ebef1b8e49c6afc2ece5 (patch) | |
tree | 229521b77b470eab0c8b93e18141aa388be741d5 | |
parent | 9deb79f959b8459a1739f5bedfefac0e76a6b1d8 (diff) |
Le Scan: Add ambient discovery mode (1/2)
Bug: 177466875
Test: manual
Change-Id: I4a5c8a0768903ef0838dcf55cf5cfba9a0a18eef
-rw-r--r-- | core/api/system-current.txt | 1 | ||||
-rw-r--r-- | core/java/android/bluetooth/le/ScanSettings.java | 23 |
2 files changed, 21 insertions, 3 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt index da56f45e9d6e..526442f40f81 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -1677,6 +1677,7 @@ package android.bluetooth.le { } public final class ScanSettings implements android.os.Parcelable { + field public static final int SCAN_MODE_AMBIENT_DISCOVERY = 3; // 0x3 field public static final int SCAN_RESULT_TYPE_ABBREVIATED = 1; // 0x1 field public static final int SCAN_RESULT_TYPE_FULL = 0; // 0x0 } diff --git a/core/java/android/bluetooth/le/ScanSettings.java b/core/java/android/bluetooth/le/ScanSettings.java index 504118ec5da8..368d1eecade4 100644 --- a/core/java/android/bluetooth/le/ScanSettings.java +++ b/core/java/android/bluetooth/le/ScanSettings.java @@ -52,6 +52,16 @@ public final class ScanSettings implements Parcelable { public static final int SCAN_MODE_LOW_LATENCY = 2; /** + * Perform Bluetooth LE scan in ambient discovery mode. This mode has lower duty cycle and more + * aggressive scan interval than balanced mode that provides a good trade-off between scan + * latency and power consumption. + * + * @hide + */ + @SystemApi + public static final int SCAN_MODE_AMBIENT_DISCOVERY = 3; + + /** * Trigger a callback for every Bluetooth advertisement found that matches the filter criteria. * If no filter is active, all advertisement packets are reported. */ @@ -276,10 +286,17 @@ public final class ScanSettings implements Parcelable { * @throws IllegalArgumentException If the {@code scanMode} is invalid. */ public Builder setScanMode(int scanMode) { - if (scanMode < SCAN_MODE_OPPORTUNISTIC || scanMode > SCAN_MODE_LOW_LATENCY) { - throw new IllegalArgumentException("invalid scan mode " + scanMode); + switch (scanMode) { + case SCAN_MODE_OPPORTUNISTIC: + case SCAN_MODE_LOW_POWER: + case SCAN_MODE_BALANCED: + case SCAN_MODE_LOW_LATENCY: + case SCAN_MODE_AMBIENT_DISCOVERY: + mScanMode = scanMode; + break; + default: + throw new IllegalArgumentException("invalid scan mode " + scanMode); } - mScanMode = scanMode; return this; } |