summaryrefslogtreecommitdiff
path: root/framework/java/android/bluetooth/le/AdvertiseSettings.java
diff options
context:
space:
mode:
authorAndriy Naborskyy <andriyn@google.com>2020-07-21 23:19:40 -0700
committerMd Shahriar Hossain Sajib <sajibonly@google.com>2022-01-06 14:23:34 +0800
commit6b15035995968cd7b1f28f7abaeba68b493ebac4 (patch)
tree205f8b783082af6f63bda8e7f39fa6cdf1c51017 /framework/java/android/bluetooth/le/AdvertiseSettings.java
parent0268bbd3847700270ea94f7956d2f5ef5e00bbbb (diff)
le advertisement address type settings
add api to request public or random address type for advertisements. bug: 155993389 Bug: 199827901 Tag: #feature Test: atest BluetoothInstrumentationTests Test: ACTS, SL4A, IOP and BCST, CTS, GTS Change-Id: I4a2b9918e0f0cc31649e3c1952d9ba34f78d337f
Diffstat (limited to 'framework/java/android/bluetooth/le/AdvertiseSettings.java')
-rw-r--r--framework/java/android/bluetooth/le/AdvertiseSettings.java48
1 files changed, 45 insertions, 3 deletions
diff --git a/framework/java/android/bluetooth/le/AdvertiseSettings.java b/framework/java/android/bluetooth/le/AdvertiseSettings.java
index 7129d762cd..c52a6ee339 100644
--- a/framework/java/android/bluetooth/le/AdvertiseSettings.java
+++ b/framework/java/android/bluetooth/le/AdvertiseSettings.java
@@ -16,6 +16,9 @@
package android.bluetooth.le;
+import android.annotation.NonNull;
+import android.annotation.SystemApi;
+import android.bluetooth.le.AdvertisingSetParameters.AddressTypeStatus;
import android.os.Parcel;
import android.os.Parcelable;
@@ -70,17 +73,21 @@ public final class AdvertiseSettings implements Parcelable {
*/
private static final int LIMITED_ADVERTISING_MAX_MILLIS = 180 * 1000;
+
private final int mAdvertiseMode;
private final int mAdvertiseTxPowerLevel;
private final int mAdvertiseTimeoutMillis;
private final boolean mAdvertiseConnectable;
+ private final int mOwnAddressType;
private AdvertiseSettings(int advertiseMode, int advertiseTxPowerLevel,
- boolean advertiseConnectable, int advertiseTimeout) {
+ boolean advertiseConnectable, int advertiseTimeout,
+ @AddressTypeStatus int ownAddressType) {
mAdvertiseMode = advertiseMode;
mAdvertiseTxPowerLevel = advertiseTxPowerLevel;
mAdvertiseConnectable = advertiseConnectable;
mAdvertiseTimeoutMillis = advertiseTimeout;
+ mOwnAddressType = ownAddressType;
}
private AdvertiseSettings(Parcel in) {
@@ -88,6 +95,7 @@ public final class AdvertiseSettings implements Parcelable {
mAdvertiseTxPowerLevel = in.readInt();
mAdvertiseConnectable = in.readInt() != 0;
mAdvertiseTimeoutMillis = in.readInt();
+ mOwnAddressType = in.readInt();
}
/**
@@ -118,12 +126,23 @@ public final class AdvertiseSettings implements Parcelable {
return mAdvertiseTimeoutMillis;
}
+ /**
+ * @return the own address type for advertising
+ *
+ * @hide
+ */
+ @SystemApi
+ public @AddressTypeStatus int getOwnAddressType() {
+ return mOwnAddressType;
+ }
+
@Override
public String toString() {
return "Settings [mAdvertiseMode=" + mAdvertiseMode
+ ", mAdvertiseTxPowerLevel=" + mAdvertiseTxPowerLevel
+ ", mAdvertiseConnectable=" + mAdvertiseConnectable
- + ", mAdvertiseTimeoutMillis=" + mAdvertiseTimeoutMillis + "]";
+ + ", mAdvertiseTimeoutMillis=" + mAdvertiseTimeoutMillis
+ + ", mOwnAddressType=" + mOwnAddressType + "]";
}
@Override
@@ -137,6 +156,7 @@ public final class AdvertiseSettings implements Parcelable {
dest.writeInt(mAdvertiseTxPowerLevel);
dest.writeInt(mAdvertiseConnectable ? 1 : 0);
dest.writeInt(mAdvertiseTimeoutMillis);
+ dest.writeInt(mOwnAddressType);
}
public static final @android.annotation.NonNull Parcelable.Creator<AdvertiseSettings> CREATOR =
@@ -160,6 +180,7 @@ public final class AdvertiseSettings implements Parcelable {
private int mTxPowerLevel = ADVERTISE_TX_POWER_MEDIUM;
private int mTimeoutMillis = 0;
private boolean mConnectable = true;
+ private int mOwnAddressType = AdvertisingSetParameters.ADDRESS_TYPE_DEFAULT;
/**
* Set advertise mode to control the advertising power and latency.
@@ -226,10 +247,31 @@ public final class AdvertiseSettings implements Parcelable {
}
/**
+ * Set own address type for advertising to control public or privacy mode. If used to set
+ * address type anything other than {@link AdvertisingSetParameters#ADDRESS_TYPE_DEFAULT},
+ * then it will require BLUETOOTH_PRIVILEGED permission and will be checked at the
+ * time of starting advertising.
+ *
+ * @throws IllegalArgumentException If the {@code ownAddressType} is invalid
+ *
+ * @hide
+ */
+ @SystemApi
+ public @NonNull Builder setOwnAddressType(@AddressTypeStatus int ownAddressType) {
+ if (ownAddressType < AdvertisingSetParameters.ADDRESS_TYPE_DEFAULT
+ || ownAddressType > AdvertisingSetParameters.ADDRESS_TYPE_RANDOM) {
+ throw new IllegalArgumentException("unknown address type " + ownAddressType);
+ }
+ mOwnAddressType = ownAddressType;
+ return this;
+ }
+
+ /**
* Build the {@link AdvertiseSettings} object.
*/
public AdvertiseSettings build() {
- return new AdvertiseSettings(mMode, mTxPowerLevel, mConnectable, mTimeoutMillis);
+ return new AdvertiseSettings(mMode, mTxPowerLevel, mConnectable, mTimeoutMillis,
+ mOwnAddressType);
}
}
}