summaryrefslogtreecommitdiff
path: root/framework/java/android/bluetooth/le/AdvertisingSetParameters.java
diff options
context:
space:
mode:
authorJakub Pawlowski <jpawlowski@google.com>2017-03-30 11:19:24 -0700
committerJakub Pawlowski <jpawlowski@google.com>2017-04-01 04:33:24 +0000
commit76741757b6061c005b7dcb20d9ebecb43f37a147 (patch)
tree8dea9b3eed2761e7fc02866931263cedca885c22 /framework/java/android/bluetooth/le/AdvertisingSetParameters.java
parenta7f399ae6d6b73bd4ccd60cc3c0286daae540ee4 (diff)
Bluetooth LE Advertising minor improvements
This patch adds some additional error checking for the advertising set parameters, and some more comments. Test: manual Bug: 30622771 Change-Id: I87bd44f4179ef63694ad3ed656dc2acc52e40f1e
Diffstat (limited to 'framework/java/android/bluetooth/le/AdvertisingSetParameters.java')
-rw-r--r--framework/java/android/bluetooth/le/AdvertisingSetParameters.java35
1 files changed, 34 insertions, 1 deletions
diff --git a/framework/java/android/bluetooth/le/AdvertisingSetParameters.java b/framework/java/android/bluetooth/le/AdvertisingSetParameters.java
index 3e13ad34f0..7e37157424 100644
--- a/framework/java/android/bluetooth/le/AdvertisingSetParameters.java
+++ b/framework/java/android/bluetooth/le/AdvertisingSetParameters.java
@@ -16,6 +16,7 @@
package android.bluetooth.le;
+import android.bluetooth.BluetoothAdapter;
import android.os.Parcel;
import android.os.Parcelable;
@@ -305,7 +306,7 @@ public final class AdvertisingSetParameters implements Parcelable {
* This is used only if legacy mode is not used.
*
* @param includeTxPower whether TX power should be included in extended
- * header
+ * header
*/
public Builder setIncludeTxPower(boolean includeTxPower) {
this.includeTxPower = includeTxPower;
@@ -317,6 +318,8 @@ public final class AdvertisingSetParameters implements Parcelable {
*
* This is used only if legacy mode is not used.
*
+ * Use {@link BluetoothAdapter#isLeCodedPhySupported} to determine if LE Coded PHY is
+ * supported on this device.
* @param primaryPhy Primary advertising physical channel, can only be
* {@link AdvertisingSetParameters#PHY_LE_1M} or
* {@link AdvertisingSetParameters#PHY_LE_CODED}.
@@ -335,6 +338,10 @@ public final class AdvertisingSetParameters implements Parcelable {
*
* This is used only if legacy mode is not used.
*
+ * Use {@link BluetoothAdapter#isLeCodedPhySupported} and
+ * {@link BluetoothAdapter#isLe2MPhySupported} to determine if LE Coded PHY or 2M PHY is
+ * supported on this device.
+ *
* @param secondaryPhy Secondary advertising physical channel, can only be
* one of {@link AdvertisingSetParameters#PHY_LE_1M},
* {@link AdvertisingSetParameters#PHY_LE_2M} or
@@ -393,6 +400,32 @@ public final class AdvertisingSetParameters implements Parcelable {
* Build the {@link AdvertisingSetParameters} object.
*/
public AdvertisingSetParameters build() {
+ if (isLegacy) {
+ if (isAnonymous) {
+ throw new IllegalArgumentException("Legacy advertising can't be anonymous");
+ }
+
+ if (connectable == true && scannable == false) {
+ throw new IllegalArgumentException(
+ "Legacy advertisement can't be connectable and non-scannable");
+ }
+
+ if (includeTxPower) {
+ throw new IllegalArgumentException(
+ "Legacy advertising can't include TX power level in header");
+ }
+ } else {
+ if (connectable && scannable) {
+ throw new IllegalArgumentException(
+ "Advertising can't be both connectable and scannable");
+ }
+
+ if (isAnonymous && connectable) {
+ throw new IllegalArgumentException(
+ "Advertising can't be both connectable and anonymous");
+ }
+ }
+
return new AdvertisingSetParameters(connectable, scannable, isLegacy, isAnonymous,
includeTxPower, primaryPhy,
secondaryPhy, interval, txPowerLevel);