Merge "Add toString helper method"
diff --git a/nearby/framework/java/android/nearby/BroadcastCallback.java b/nearby/framework/java/android/nearby/BroadcastCallback.java
index 84e19b0..54c1916 100644
--- a/nearby/framework/java/android/nearby/BroadcastCallback.java
+++ b/nearby/framework/java/android/nearby/BroadcastCallback.java
@@ -16,14 +16,49 @@
package android.nearby;
+import android.annotation.IntDef;
+import android.annotation.SystemApi;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
/**
* Callback when broadcasting request using nearby specification.
*
* @hide
*/
+@SystemApi
public interface BroadcastCallback {
+ /** Broadcast was successful. */
+ int STATUS_OK = 0;
+
+ /** General status code when broadcast failed. */
+ int STATUS_FAILURE = 1;
+
+ /**
+ * Broadcast failed as the callback was already registered.
+ */
+ int STATUS_FAILURE_ALREADY_REGISTERED = 2;
+
+ /**
+ * Broadcast failed as the request contains excessive data.
+ */
+ int STATUS_FAILURE_SIZE_EXCEED_LIMIT = 3;
+
+ /**
+ * Broadcast failed as the client doesn't hold required permissions.
+ */
+ int STATUS_FAILURE_MISSING_PERMISSIONS = 4;
+
+ /** @hide **/
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef({STATUS_OK, STATUS_FAILURE, STATUS_FAILURE_ALREADY_REGISTERED,
+ STATUS_FAILURE_SIZE_EXCEED_LIMIT, STATUS_FAILURE_MISSING_PERMISSIONS})
+ @interface BroadcastStatus {
+ }
+
/**
* Called when broadcast status changes.
*/
- void onStatus(int status);
+ void onStatus(@BroadcastStatus int status);
}
diff --git a/nearby/framework/java/android/nearby/BroadcastRequest.java b/nearby/framework/java/android/nearby/BroadcastRequest.java
index 1f408d4..27468dd 100644
--- a/nearby/framework/java/android/nearby/BroadcastRequest.java
+++ b/nearby/framework/java/android/nearby/BroadcastRequest.java
@@ -17,8 +17,10 @@
package android.nearby;
import android.annotation.IntDef;
+import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.SuppressLint;
+import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
@@ -32,6 +34,7 @@
*
* @hide
*/
+@SystemApi
@SuppressLint("ParcelNotFinal") // BroadcastRequest constructor is not public
public abstract class BroadcastRequest implements Parcelable {
@@ -39,6 +42,8 @@
public static final int BROADCAST_TYPE_NEARBY_PRESENCE = 3;
/** @hide **/
+ // Currently, only Nearby Presence broadcast is supported, in the future
+ // broadcasting using other nearby specifications will be added.
@Retention(RetentionPolicy.SOURCE)
@IntDef({BROADCAST_TYPE_NEARBY_PRESENCE})
public @interface BroadcastType {
@@ -114,7 +119,7 @@
}
/**
- * Returns the version fo the broadcast.
+ * Returns the version of the broadcast.
*/
public @BroadcastVersion int getVersion() {
return mVersion;
@@ -123,12 +128,13 @@
/**
* Returns the calibrated TX power when this request is broadcast.
*/
+ @IntRange(from = -127, to = 126)
public int getTxPower() {
return mTxPower;
}
/**
- * Returns the list broadcast mediums.
+ * Returns the list of broadcast mediums.
*/
@NonNull
public List<Integer> getMediums() {
diff --git a/nearby/framework/java/android/nearby/CredentialElement.java b/nearby/framework/java/android/nearby/CredentialElement.java
index 5f31c17..d2049d1 100644
--- a/nearby/framework/java/android/nearby/CredentialElement.java
+++ b/nearby/framework/java/android/nearby/CredentialElement.java
@@ -17,6 +17,7 @@
package android.nearby;
import android.annotation.NonNull;
+import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
@@ -27,11 +28,17 @@
*
* @hide
*/
+@SystemApi
public final class CredentialElement implements Parcelable {
private final String mKey;
private final byte[] mValue;
- private CredentialElement(String key, byte[] value) {
+ /**
+ * Constructs a {@link CredentialElement}.
+ */
+ public CredentialElement(@NonNull String key, @NonNull byte[] value) {
+ Preconditions.checkState(key != null && value != null,
+ "neither key or value can be null");
mKey = key;
mValue = value;
}
@@ -44,7 +51,7 @@
String key = in.readString();
byte[] value = new byte[in.readInt()];
in.readByteArray(value);
- return new CredentialElement.Builder().setElement(key, value).build();
+ return new CredentialElement(key, value);
}
@Override
@@ -80,33 +87,4 @@
public byte[] getValue() {
return mValue;
}
-
- /**
- * Builder for {@link CredentialElement}.
- */
- public static final class Builder {
- private String mKey;
- private byte[] mValue;
-
- /**
- * Set the key and value for this credential element.
- */
- @NonNull
- @SuppressWarnings("MissingGetterMatchingBuilder")
- public CredentialElement.Builder setElement(@NonNull String key, @NonNull byte[] value) {
- mKey = key;
- mValue = value;
- return this;
- }
-
- /**
- * Builds a {@link CredentialElement}.
- */
- @NonNull
- public CredentialElement build() {
- Preconditions.checkState(mKey != null && mValue != null,
- "neither key or value can be null");
- return new CredentialElement(mKey, mValue);
- }
- }
}
diff --git a/nearby/framework/java/android/nearby/DataElement.java b/nearby/framework/java/android/nearby/DataElement.java
index f037612..6fa5fb5 100644
--- a/nearby/framework/java/android/nearby/DataElement.java
+++ b/nearby/framework/java/android/nearby/DataElement.java
@@ -17,6 +17,7 @@
package android.nearby;
import android.annotation.NonNull;
+import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
@@ -28,12 +29,17 @@
*
* @hide
*/
+@SystemApi
public final class DataElement implements Parcelable {
private final int mKey;
private final byte[] mValue;
- private DataElement(int key, byte[] value) {
+ /**
+ * Constructs a {@link DataElement}.
+ */
+ public DataElement(int key, @NonNull byte[] value) {
+ Preconditions.checkState(value != null, "value cannot be null");
mKey = key;
mValue = value;
}
@@ -45,7 +51,7 @@
int key = in.readInt();
byte[] value = new byte[in.readInt()];
in.readByteArray(value);
- return new Builder().setElement(key, value).build();
+ return new DataElement(key, value);
}
@Override
@@ -67,7 +73,7 @@
}
/**
- * Returns the key of the data element.
+ * Returns the key of the data element, as defined in the nearby presence specification.
*/
public int getKey() {
return mKey;
@@ -80,33 +86,4 @@
public byte[] getValue() {
return mValue;
}
-
- /**
- * Builder for {@link DataElement}.
- */
- public static final class Builder {
- private int mKey;
- private byte[] mValue;
-
- /**
- * Set the key and value for this data element.
- */
- @NonNull
- @SuppressWarnings("MissingGetterMatchingBuilder")
- public Builder setElement(int key, @NonNull byte[] value) {
- mKey = key;
- mValue = value;
- return this;
- }
-
- /**
- * Builds a {@link DataElement}.
- */
- @NonNull
- public DataElement build() {
- Preconditions.checkState(mValue != null,
- "value can be null");
- return new DataElement(mKey, mValue);
- }
- }
}
diff --git a/nearby/framework/java/android/nearby/FastPairDevice.java b/nearby/framework/java/android/nearby/FastPairDevice.java
index 1e766a5..e12b4f8 100644
--- a/nearby/framework/java/android/nearby/FastPairDevice.java
+++ b/nearby/framework/java/android/nearby/FastPairDevice.java
@@ -22,7 +22,9 @@
import android.os.Parcel;
import android.os.Parcelable;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import java.util.Objects;
/**
@@ -41,7 +43,10 @@
if (in.readInt() == 1) {
builder.setName(in.readString());
}
- builder.setMedium(in.readInt());
+ int size = in.readInt();
+ for (int i = 0; i < size; i++) {
+ builder.addMedium(in.readInt());
+ }
builder.setRssi(in.readInt());
if (in.readInt() == 1) {
builder.setModelId(in.readString());
@@ -75,7 +80,7 @@
* Creates a new FastPairDevice.
*
* @param name Name of the FastPairDevice. Can be {@code null} if there is no name.
- * @param medium The {@link Medium} over which the device is discovered.
+ * @param mediums The {@link Medium}s over which the device is discovered.
* @param rssi The received signal strength in dBm.
* @param modelId The identifier of the Fast Pair device.
* Can be {@code null} if there is no Model ID.
@@ -83,44 +88,18 @@
* @param data Extra data for a Fast Pair device.
*/
public FastPairDevice(@Nullable String name,
- @Medium int medium,
+ List<Integer> mediums,
int rssi,
@Nullable String modelId,
@NonNull String bluetoothAddress,
@Nullable byte[] data) {
- super(name, medium, rssi);
+ super(name, mediums, rssi);
this.mModelId = modelId;
this.mBluetoothAddress = bluetoothAddress;
this.mData = data;
}
/**
- * Gets the name of the device, or {@code null} if not available.
- *
- * @hide
- */
- @Nullable
- @Override
- public String getName() {
- return mName;
- }
-
- /** Gets the medium over which this device was discovered. */
- @Override
- public int getMedium() {
- return mMedium;
- }
-
- /**
- * Gets the received signal strength in dBm.
- */
- @IntRange(from = -127, to = 126)
- @Override
- public int getRssi() {
- return mRssi;
- }
-
- /**
* Gets the identifier of the Fast Pair device. Can be {@code null} if there is no Model ID.
*/
@Nullable
@@ -161,11 +140,15 @@
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("FastPairDevice [");
- if (mName != null && !mName.isEmpty()) {
- stringBuilder.append("name=").append(mName).append(", ");
+ String name = getName();
+ if (getName() != null && !name.isEmpty()) {
+ stringBuilder.append("name=").append(name).append(", ");
}
- stringBuilder.append("medium=").append(mediumToString(mMedium));
- stringBuilder.append(" rssi=").append(mRssi);
+ stringBuilder.append("medium={");
+ for (int medium: getMediums()) {
+ stringBuilder.append(mediumToString(medium));
+ }
+ stringBuilder.append("} rssi=").append(getRssi());
stringBuilder.append(" modelId=").append(mModelId);
stringBuilder.append(" bluetoothAddress=").append(mBluetoothAddress);
stringBuilder.append("]");
@@ -189,17 +172,23 @@
@Override
public int hashCode() {
return Objects.hash(
- mName, mMedium, mRssi, mModelId, mBluetoothAddress, Arrays.hashCode(mData));
+ getName(), getMediums(), getRssi(), mModelId, mBluetoothAddress,
+ Arrays.hashCode(mData));
}
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
- dest.writeInt(mName == null ? 0 : 1);
- if (mName != null) {
- dest.writeString(mName);
+ String name = getName();
+ dest.writeInt(name == null ? 0 : 1);
+ if (name != null) {
+ dest.writeString(name);
}
- dest.writeInt(mMedium);
- dest.writeInt(mRssi);
+ List<Integer> mediums = getMediums();
+ dest.writeInt(mediums.size());
+ for (int medium : mediums) {
+ dest.writeInt(medium);
+ }
+ dest.writeInt(getRssi());
dest.writeInt(mModelId == null ? 0 : 1);
if (mModelId != null) {
dest.writeString(mModelId);
@@ -218,13 +207,18 @@
* @hide
*/
public static final class Builder {
+ private final List<Integer> mMediums;
@Nullable private String mName;
- @Medium private int mMedium;
private int mRssi;
@Nullable private String mModelId;
private String mBluetoothAddress;
@Nullable private byte[] mData;
+
+ public Builder() {
+ mMediums = new ArrayList<>();
+ }
+
/**
* Sets the name of the Fast Pair device.
*
@@ -242,8 +236,8 @@
* @param medium The {@link Medium} over which the device is discovered.
*/
@NonNull
- public Builder setMedium(@Medium int medium) {
- mMedium = medium;
+ public Builder addMedium(@Medium int medium) {
+ mMediums.add(medium);
return this;
}
@@ -253,7 +247,7 @@
* @param rssi The received signal strength in dBm.
*/
@NonNull
- public Builder setRssi(int rssi) {
+ public Builder setRssi(@IntRange(from = -127, to = 126) int rssi) {
mRssi = rssi;
return this;
}
@@ -298,7 +292,7 @@
*/
@NonNull
public FastPairDevice build() {
- return new FastPairDevice(mName, mMedium, mRssi, mModelId,
+ return new FastPairDevice(mName, mMediums, mRssi, mModelId,
mBluetoothAddress, mData);
}
}
diff --git a/nearby/framework/java/android/nearby/NearbyDevice.java b/nearby/framework/java/android/nearby/NearbyDevice.java
index 790b2ed..538940c 100644
--- a/nearby/framework/java/android/nearby/NearbyDevice.java
+++ b/nearby/framework/java/android/nearby/NearbyDevice.java
@@ -18,11 +18,13 @@
import android.annotation.IntDef;
import android.annotation.IntRange;
+import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import com.android.internal.util.Preconditions;
+import java.util.List;
import java.util.Objects;
/**
@@ -34,27 +36,29 @@
public abstract class NearbyDevice {
@Nullable
- final String mName;
+ private final String mName;
@Medium
- final int mMedium;
+ private final List<Integer> mMediums;
- final int mRssi;
+ private final int mRssi;
/**
* Creates a new NearbyDevice.
*
* @param name Local device name. Can be {@code null} if there is no name.
- * @param medium The {@link Medium} over which the device is discovered.
+ * @param mediums The {@link Medium}s over which the device is discovered.
* @param rssi The received signal strength in dBm.
* @hide
*/
- public NearbyDevice(@Nullable String name, @Medium int medium, int rssi) {
- Preconditions.checkState(isValidMedium(medium),
- "Not supported medium: " + medium
- + ", scan medium must be one of NearbyDevice#Medium.");
+ public NearbyDevice(@Nullable String name, List<Integer> mediums, int rssi) {
+ for (int medium : mediums) {
+ Preconditions.checkState(isValidMedium(medium),
+ "Not supported medium: " + medium
+ + ", scan medium must be one of NearbyDevice#Medium.");
+ }
mName = name;
- mMedium = medium;
+ mMediums = mediums;
mRssi = rssi;
}
@@ -81,8 +85,6 @@
/**
* The name of the device, or null if not available.
- *
- * @hide
*/
@Nullable
public String getName() {
@@ -90,9 +92,9 @@
}
/** The medium over which this device was discovered. */
- @Medium
- public int getMedium() {
- return mMedium;
+ @NonNull
+ @Medium public List<Integer> getMediums() {
+ return mMediums;
}
/**
@@ -110,8 +112,11 @@
if (mName != null && !mName.isEmpty()) {
stringBuilder.append("name=").append(mName).append(", ");
}
- stringBuilder.append("medium=").append(mediumToString(mMedium));
- stringBuilder.append(" rssi=").append(mRssi);
+ stringBuilder.append("medium={");
+ for (int medium : mMediums) {
+ stringBuilder.append(mediumToString(medium));
+ }
+ stringBuilder.append("} rssi=").append(mRssi);
stringBuilder.append("]");
return stringBuilder.toString();
}
@@ -121,7 +126,7 @@
if (other instanceof NearbyDevice) {
NearbyDevice otherDevice = (NearbyDevice) other;
return Objects.equals(mName, otherDevice.mName)
- && mMedium == otherDevice.mMedium
+ && mMediums == otherDevice.mMediums
&& mRssi == otherDevice.mRssi;
}
return false;
@@ -129,7 +134,7 @@
@Override
public int hashCode() {
- return Objects.hash(mName, mMedium, mRssi);
+ return Objects.hash(mName, mMediums, mRssi);
}
/**
diff --git a/nearby/framework/java/android/nearby/NearbyManager.java b/nearby/framework/java/android/nearby/NearbyManager.java
index f8eef7f..7fb14ef 100644
--- a/nearby/framework/java/android/nearby/NearbyManager.java
+++ b/nearby/framework/java/android/nearby/NearbyManager.java
@@ -67,7 +67,7 @@
if (scanType == ScanRequest.SCAN_TYPE_FAST_PAIR) {
return new FastPairDevice.Builder()
.setName(nearbyDeviceParcelable.getName())
- .setMedium(nearbyDeviceParcelable.getMedium())
+ .addMedium(nearbyDeviceParcelable.getMedium())
.setRssi(nearbyDeviceParcelable.getRssi())
.setModelId(nearbyDeviceParcelable.getFastPairModelId())
.setBluetoothAddress(nearbyDeviceParcelable.getBluetoothAddress())
@@ -146,8 +146,6 @@
* @param broadcastRequest Request for the nearby broadcast.
* @param executor Executor for running the callback.
* @param callback Callback for notifying the client..
- *
- * @hide
*/
public void startBroadcast(@NonNull BroadcastRequest broadcastRequest,
@CallbackExecutor @NonNull Executor executor, @NonNull BroadcastCallback callback) {
@@ -158,8 +156,6 @@
* Stop the broadcast associated with the given callback.
*
* @param callback The callback that was used for starting the broadcast.
- *
- * @hide
*/
@SuppressLint("ExecutorRegistration")
public void stopBroadcast(@NonNull BroadcastCallback callback) {
diff --git a/nearby/framework/java/android/nearby/PresenceBroadcastRequest.java b/nearby/framework/java/android/nearby/PresenceBroadcastRequest.java
index 7e387b5..b4d4b55 100644
--- a/nearby/framework/java/android/nearby/PresenceBroadcastRequest.java
+++ b/nearby/framework/java/android/nearby/PresenceBroadcastRequest.java
@@ -16,7 +16,9 @@
package android.nearby;
+import android.annotation.IntRange;
import android.annotation.NonNull;
+import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
@@ -24,12 +26,14 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
/**
* Request for Nearby Presence Broadcast.
*
* @hide
*/
+@SystemApi
public final class PresenceBroadcastRequest extends BroadcastRequest implements Parcelable {
private final byte[] mSalt;
private final List<Integer> mActions;
@@ -128,8 +132,6 @@
/**
* Builder for {@link PresenceBroadcastRequest}.
- *
- * @hide
*/
public static final class Builder {
private final List<Integer> mMediums;
@@ -141,12 +143,17 @@
private byte[] mSalt;
private PrivateCredential mCredential;
- public Builder() {
+ public Builder(@NonNull List<Integer> mediums, @NonNull byte[] salt) {
+ Preconditions.checkState(!mediums.isEmpty(), "mediums cannot be empty");
+ Preconditions.checkState(salt != null && salt.length > 0, "salt cannot be empty");
+
mVersion = PRESENCE_VERSION_V0;
mTxPower = UNKNOWN_TX_POWER;
- mMediums = new ArrayList<>();
mActions = new ArrayList<>();
mExtendedProperties = new ArrayList<>();
+
+ mSalt = salt;
+ mMediums = mediums;
}
/**
@@ -159,37 +166,20 @@
}
/**
- * Sets the calibrated tx power level for this request.
+ * Sets the calibrated tx power level in dBm for this request. The tx power level should
+ * be between -127 dBm and 126 dBm.
*/
@NonNull
- public Builder setTxPower(int txPower) {
+ public Builder setTxPower(@IntRange(from = -127, to = 126) int txPower) {
mTxPower = txPower;
return this;
}
/**
- * Add a medium for the presence broadcast request.
- */
- @NonNull
- public Builder addMediums(int medium) {
- mMediums.add(medium);
- return this;
- }
-
- /**
- * Sets the salt for the presence broadcast request.
- */
- @NonNull
- public Builder setSalt(byte[] salt) {
- mSalt = salt;
- return this;
- }
-
- /**
* Adds an action for the presence broadcast request.
*/
@NonNull
- public Builder addAction(int action) {
+ public Builder addAction(@IntRange(from = 1, to = 255) int action) {
mActions.add(action);
return this;
}
@@ -199,6 +189,7 @@
*/
@NonNull
public Builder setCredential(@NonNull PrivateCredential credential) {
+ Objects.requireNonNull(credential);
mCredential = credential;
return this;
}
@@ -207,7 +198,8 @@
* Adds an extended property for the presence broadcast request.
*/
@NonNull
- public Builder addExtendedProperty(DataElement dataElement) {
+ public Builder addExtendedProperty(@NonNull DataElement dataElement) {
+ Objects.requireNonNull(dataElement);
mExtendedProperties.add(dataElement);
return this;
}
@@ -217,8 +209,6 @@
*/
@NonNull
public PresenceBroadcastRequest build() {
- Preconditions.checkState(!mMediums.isEmpty(), "mediums cannot be empty");
- Preconditions.checkState(mSalt != null && mSalt.length > 0, "salt cannot be empty");
return new PresenceBroadcastRequest(mVersion, mTxPower, mMediums, mSalt, mActions,
mCredential, mExtendedProperties);
}
diff --git a/nearby/framework/java/android/nearby/PresenceCredential.java b/nearby/framework/java/android/nearby/PresenceCredential.java
index 14b17ae..fae3603 100644
--- a/nearby/framework/java/android/nearby/PresenceCredential.java
+++ b/nearby/framework/java/android/nearby/PresenceCredential.java
@@ -19,6 +19,7 @@
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.SuppressLint;
+import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
@@ -32,6 +33,7 @@
*
* @hide
*/
+@SystemApi
@SuppressLint("ParcelNotFinal") // PresenceCredential constructor is not public
public abstract class PresenceCredential implements Parcelable {
/**
@@ -86,10 +88,10 @@
private final List<CredentialElement> mCredentialElements;
PresenceCredential(@CredentialType int type, @IdentityType int identityType,
- byte[] secreteId, byte[] authenticityKey, List<CredentialElement> credentialElements) {
+ byte[] secretId, byte[] authenticityKey, List<CredentialElement> credentialElements) {
mType = type;
mIdentityType = identityType;
- mSecretId = secreteId;
+ mSecretId = secretId;
mAuthenticityKey = authenticityKey;
mCredentialElements = credentialElements;
}
diff --git a/nearby/framework/java/android/nearby/PresenceDevice.java b/nearby/framework/java/android/nearby/PresenceDevice.java
index 0b3782c..d5ea0b4 100644
--- a/nearby/framework/java/android/nearby/PresenceDevice.java
+++ b/nearby/framework/java/android/nearby/PresenceDevice.java
@@ -19,18 +19,22 @@
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
-import android.os.Bundle;
+import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
/**
* Represents a Presence device from nearby scans.
*
* @hide
*/
+@SystemApi
public final class PresenceDevice extends NearbyDevice implements Parcelable {
/** The type of presence device. */
@@ -69,18 +73,7 @@
private final int mDeviceType;
private final String mDeviceImageUrl;
private final long mDiscoveryTimestampMillis;
- private final Bundle mExtendedProperties;
-
- /**
- * Gets the name of the device, or {@code null} if not available.
- *
- * @hide
- */
- @Nullable
- @Override
- public String getName() {
- return mName;
- }
+ private final List<DataElement> mExtendedProperties;
/**
* The id of the device.
@@ -137,16 +130,15 @@
* The extended properties of the device.
*/
@NonNull
- public Bundle getExtendedProperties() {
+ public List<DataElement> getExtendedProperties() {
return mExtendedProperties;
}
- private PresenceDevice(String deviceName, int mMedium, int rssi, String deviceId,
+ private PresenceDevice(String deviceName, List<Integer> mMediums, int rssi, String deviceId,
byte[] salt, byte[] secretId, byte[] encryptedIdentity, int deviceType,
String deviceImageUrl, long discoveryTimestampMillis,
- Bundle extendedProperties) {
- // TODO (b/217462253): change medium to a set in NearbyDevice.
- super(deviceName, mMedium, rssi);
+ List<DataElement> extendedProperties) {
+ super(deviceName, mMediums, rssi);
mDeviceId = deviceId;
mSalt = salt;
mSecretId = secretId;
@@ -159,12 +151,17 @@
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
- dest.writeInt(mName == null ? 0 : 1);
- if (mName != null) {
- dest.writeString(mName);
+ String name = getName();
+ dest.writeInt(name == null ? 0 : 1);
+ if (name != null) {
+ dest.writeString(name);
}
- dest.writeInt(mMedium);
- dest.writeInt(mRssi);
+ List<Integer> mediums = getMediums();
+ dest.writeInt(mediums.size());
+ for (int medium : mediums) {
+ dest.writeInt(medium);
+ }
+ dest.writeInt(getRssi());
dest.writeString(mDeviceId);
dest.writeInt(mDeviceType);
dest.writeInt(mDeviceImageUrl == null ? 0 : 1);
@@ -172,7 +169,10 @@
dest.writeString(mDeviceImageUrl);
}
dest.writeLong(mDiscoveryTimestampMillis);
- dest.writeBundle(mExtendedProperties);
+ dest.writeInt(mExtendedProperties.size());
+ for (DataElement dataElement : mExtendedProperties) {
+ dest.writeParcelable(dataElement, 0);
+ }
}
@Override
@@ -188,7 +188,10 @@
if (in.readInt() == 1) {
builder.setName(in.readString());
}
- builder.setMedium(in.readInt());
+ int size = in.readInt();
+ for (int i = 0; i < size; i++) {
+ builder.addMedium(in.readInt());
+ }
builder.setRssi(in.readInt());
builder.setDeviceId(in.readString());
builder.setDeviceType(in.readInt());
@@ -196,9 +199,10 @@
builder.setDeviceImageUrl(in.readString());
}
builder.setDiscoveryTimestampMillis(in.readLong());
- Bundle bundle = in.readBundle();
- for (String key : bundle.keySet()) {
- builder.addExtendedProperty(key, bundle.getCharSequence(key).toString());
+ int dataElementSize = in.readInt();
+ for (int i = 0; i < dataElementSize; i++) {
+ builder.addExtendedProperty(
+ in.readParcelable(DataElement.class.getClassLoader(), DataElement.class));
}
return builder.build();
}
@@ -211,16 +215,14 @@
/**
* Builder class for {@link PresenceDevice}.
- *
- * @hide
*/
public static final class Builder {
- private final Bundle mExtendedProperties;
+ private final List<DataElement> mExtendedProperties;
+ private final List<Integer> mMediums;
private String mName;
private int mRssi;
- private int mMedium;
private String mDeviceId;
private byte[] mSalt;
private byte[] mSecretId;
@@ -230,7 +232,8 @@
private long mDiscoveryTimestampMillis;
public Builder() {
- mExtendedProperties = new Bundle();
+ mMediums = new ArrayList<>();
+ mExtendedProperties = new ArrayList<>();
mRssi = -100;
}
@@ -240,19 +243,19 @@
* @param name Name of the Presence. Can be {@code null} if there is no name.
*/
@NonNull
- public Builder setName(@android.annotation.Nullable String name) {
+ public Builder setName(@Nullable String name) {
mName = name;
return this;
}
/**
- * Sets the medium over which the Presence device is discovered.
+ * Adds the medium over which the Presence device is discovered.
*
* @param medium The {@link Medium} over which the device is discovered.
*/
@NonNull
- public Builder setMedium(@Medium int medium) {
- mMedium = medium;
+ public Builder addMedium(@Medium int medium) {
+ mMediums.add(medium);
return this;
}
@@ -274,6 +277,7 @@
*/
@NonNull
public Builder setDeviceId(@NonNull String deviceId) {
+ Objects.requireNonNull(deviceId);
mDeviceId = deviceId;
return this;
}
@@ -283,15 +287,17 @@
*/
@NonNull
public Builder setSalt(@NonNull byte[] salt) {
+ Objects.requireNonNull(salt);
mSalt = salt;
return this;
}
/**
- * Sets the secret Id of the discovered Presence device.
+ * Sets the secret id of the discovered Presence device.
*/
@NonNull
public Builder setSecretId(@NonNull byte[] secretId) {
+ Objects.requireNonNull(secretId);
mSecretId = secretId;
return this;
}
@@ -301,6 +307,7 @@
*/
@NonNull
public Builder setEncryptedIdentity(@NonNull byte[] encryptedIdentity) {
+ Objects.requireNonNull(encryptedIdentity);
mEncryptedIdentity = encryptedIdentity;
return this;
}
@@ -311,7 +318,7 @@
* @param deviceType Type of the Presence device.
*/
@NonNull
- public Builder setDeviceType(int deviceType) {
+ public Builder setDeviceType(@DeviceType int deviceType) {
mDeviceType = deviceType;
return this;
}
@@ -323,7 +330,7 @@
* @param deviceImageUrl Url of the image for the Presence device.
*/
@NonNull
- public Builder setDeviceImageUrl(@NonNull String deviceImageUrl) {
+ public Builder setDeviceImageUrl(@Nullable String deviceImageUrl) {
mDeviceImageUrl = deviceImageUrl;
return this;
}
@@ -344,12 +351,12 @@
/**
* Adds an extended property of the discovered presence device.
*
- * @param key Key of the extended property.
- * @param value Value of the extended property,
+ * @param dataElement Data element of the extended property.
*/
@NonNull
- public Builder addExtendedProperty(@NonNull String key, @NonNull String value) {
- mExtendedProperties.putCharSequence(key, value);
+ public Builder addExtendedProperty(@NonNull DataElement dataElement) {
+ Objects.requireNonNull(dataElement);
+ mExtendedProperties.add(dataElement);
return this;
}
@@ -358,7 +365,7 @@
*/
@NonNull
public PresenceDevice build() {
- return new PresenceDevice(mName, mMedium, mRssi, mDeviceId,
+ return new PresenceDevice(mName, mMediums, mRssi, mDeviceId,
mSalt, mSecretId, mEncryptedIdentity,
mDeviceType,
mDeviceImageUrl,
diff --git a/nearby/framework/java/android/nearby/PresenceScanFilter.java b/nearby/framework/java/android/nearby/PresenceScanFilter.java
index e9b5faa..f0c3c06 100644
--- a/nearby/framework/java/android/nearby/PresenceScanFilter.java
+++ b/nearby/framework/java/android/nearby/PresenceScanFilter.java
@@ -16,7 +16,9 @@
package android.nearby;
+import android.annotation.IntRange;
import android.annotation.NonNull;
+import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.ArraySet;
@@ -25,6 +27,7 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
import java.util.Set;
/**
@@ -32,6 +35,7 @@
*
* @hide
*/
+@SystemApi
public final class PresenceScanFilter extends ScanFilter implements Parcelable {
private final List<PublicCredential> mCredentials;
@@ -134,18 +138,16 @@
/**
* Builder for {@link PresenceScanFilter}.
- *
- * @hide
*/
public static final class Builder {
- private int mRssiThreshold;
+ private int mMaxPathLoss;
private final Set<PublicCredential> mCredentials;
private final Set<Integer> mPresenceIdentities;
private final Set<Integer> mPresenceActions;
private final List<DataElement> mExtendedProperties;
public Builder() {
- mRssiThreshold = -100;
+ mMaxPathLoss = 127;
mCredentials = new ArraySet<>();
mPresenceIdentities = new ArraySet<>();
mPresenceActions = new ArraySet<>();
@@ -153,29 +155,33 @@
}
/**
- * Sets the rssi threshold for the scan request.
+ * Sets the max path loss (in dBm) for the scan request. The path loss is the attenuation
+ * of radio energy between sender and receiver. Path loss here is defined as (TxPower -
+ * Rssi).
*/
@NonNull
- public Builder setRssiThreshold(int rssiThreshold) {
- mRssiThreshold = rssiThreshold;
+ public Builder setMaxPathLoss(@IntRange(from = 0, to = 127) int maxPathLoss) {
+ mMaxPathLoss = maxPathLoss;
return this;
}
/**
- * Adds a list of credentials the scan filter is expected to match.
+ * Adds a credential the scan filter is expected to match.
*/
@NonNull
public Builder addCredential(@NonNull PublicCredential credential) {
+ Objects.requireNonNull(credential);
mCredentials.add(credential);
return this;
}
/**
- * Adds a presence action for filtering.
+ * Adds a presence action for filtering, which is an action the discoverer could take
+ * when it receives the broadcast of a presence device.
*/
@NonNull
- public Builder addPresenceAction(int action) {
+ public Builder addPresenceAction(@IntRange(from = 1, to = 255) int action) {
mPresenceActions.add(action);
return this;
}
@@ -185,6 +191,7 @@
*/
@NonNull
public Builder addExtendedProperty(@NonNull DataElement dataElement) {
+ Objects.requireNonNull(dataElement);
mExtendedProperties.add(dataElement);
return this;
}
@@ -195,7 +202,7 @@
@NonNull
public PresenceScanFilter build() {
Preconditions.checkState(!mCredentials.isEmpty(), "credentials cannot be empty");
- return new PresenceScanFilter(mRssiThreshold,
+ return new PresenceScanFilter(mMaxPathLoss,
new ArrayList<>(mCredentials),
new ArrayList<>(mPresenceActions),
mExtendedProperties);
diff --git a/nearby/framework/java/android/nearby/PrivateCredential.java b/nearby/framework/java/android/nearby/PrivateCredential.java
index 2860fdb..8db49fa 100644
--- a/nearby/framework/java/android/nearby/PrivateCredential.java
+++ b/nearby/framework/java/android/nearby/PrivateCredential.java
@@ -17,6 +17,7 @@
package android.nearby;
import android.annotation.NonNull;
+import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
@@ -30,6 +31,7 @@
*
* @hide
*/
+@SystemApi
public final class PrivateCredential extends PresenceCredential implements Parcelable {
@NonNull
@@ -46,23 +48,23 @@
}
};
- private byte[] mMetaDataEncryptionKey;
+ private byte[] mMetadataEncryptionKey;
private String mDeviceName;
private PrivateCredential(Parcel in) {
super(CREDENTIAL_TYPE_PRIVATE, in);
- mMetaDataEncryptionKey = new byte[in.readInt()];
- in.readByteArray(mMetaDataEncryptionKey);
+ mMetadataEncryptionKey = new byte[in.readInt()];
+ in.readByteArray(mMetadataEncryptionKey);
mDeviceName = in.readString();
}
- private PrivateCredential(int identityType, byte[] secreteId,
+ private PrivateCredential(int identityType, byte[] secretId,
String deviceName, byte[] authenticityKey, List<CredentialElement> credentialElements,
- byte[] metaDataEncryptionKey) {
- super(CREDENTIAL_TYPE_PRIVATE, identityType, secreteId, authenticityKey,
+ byte[] metadataEncryptionKey) {
+ super(CREDENTIAL_TYPE_PRIVATE, identityType, secretId, authenticityKey,
credentialElements);
mDeviceName = deviceName;
- mMetaDataEncryptionKey = metaDataEncryptionKey;
+ mMetadataEncryptionKey = metadataEncryptionKey;
}
static PrivateCredential createFromParcelBody(Parcel in) {
@@ -77,8 +79,8 @@
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
super.writeToParcel(dest, flags);
- dest.writeInt(mMetaDataEncryptionKey.length);
- dest.writeByteArray(mMetaDataEncryptionKey);
+ dest.writeInt(mMetadataEncryptionKey.length);
+ dest.writeByteArray(mMetadataEncryptionKey);
dest.writeString(mDeviceName);
}
@@ -86,8 +88,8 @@
* Returns the metadata encryption key associated with this credential.
*/
@NonNull
- public byte[] getMetaDataEncryptionKey() {
- return mMetaDataEncryptionKey;
+ public byte[] getMetadataEncryptionKey() {
+ return mMetadataEncryptionKey;
}
/**
@@ -100,19 +102,23 @@
/**
* Builder class for {@link PresenceCredential}.
- *
- * @hide
*/
public static final class Builder {
private final List<CredentialElement> mCredentialElements;
private @IdentityType int mIdentityType;
- private byte[] mSecreteId;
+ private byte[] mSecretId;
private byte[] mAuthenticityKey;
- private byte[] mMetaDataEncryptionKey;
+ private byte[] mMetadataEncryptionKey;
private String mDeviceName;
- public Builder() {
+ public Builder(@NonNull byte[] secretId, @NonNull byte[] authenticityKey) {
+ Preconditions.checkState(secretId != null && secretId.length > 0,
+ "secret id cannot be empty");
+ Preconditions.checkState(authenticityKey != null && authenticityKey.length > 0,
+ "authenticity key cannot be empty");
+ mSecretId = secretId;
+ mAuthenticityKey = authenticityKey;
mCredentialElements = new ArrayList<>();
}
@@ -126,29 +132,11 @@
}
/**
- * Sets the secrete id for the presence credential.
- */
- @NonNull
- public Builder setSecretId(@NonNull byte[] secreteId) {
- mSecreteId = secreteId;
- return this;
- }
-
- /**
- * Sets the authenticity key for the presence credential.
- */
- @NonNull
- public Builder setAuthenticityKey(@NonNull byte[] authenticityKey) {
- mAuthenticityKey = authenticityKey;
- return this;
- }
-
- /**
* Sets the metadata encryption key to the credential.
*/
@NonNull
- public Builder setMetaDataEncryptionKey(@NonNull byte[] metaDataEncryptionKey) {
- mMetaDataEncryptionKey = metaDataEncryptionKey;
+ public Builder setMetadataEncryptionKey(@NonNull byte[] metadataEncryptionKey) {
+ mMetadataEncryptionKey = metadataEncryptionKey;
return this;
}
@@ -175,12 +163,8 @@
*/
@NonNull
public PrivateCredential build() {
- Preconditions.checkState(mSecreteId != null && mSecreteId.length > 0,
- "secrete id cannot be empty");
- Preconditions.checkState(mAuthenticityKey != null && mAuthenticityKey.length > 0,
- "authenticity key cannot be empty");
- return new PrivateCredential(mIdentityType, mSecreteId, mDeviceName,
- mAuthenticityKey, mCredentialElements, mMetaDataEncryptionKey);
+ return new PrivateCredential(mIdentityType, mSecretId, mDeviceName,
+ mAuthenticityKey, mCredentialElements, mMetadataEncryptionKey);
}
}
diff --git a/nearby/framework/java/android/nearby/PublicCredential.java b/nearby/framework/java/android/nearby/PublicCredential.java
index 78f6205..715e7fd 100644
--- a/nearby/framework/java/android/nearby/PublicCredential.java
+++ b/nearby/framework/java/android/nearby/PublicCredential.java
@@ -17,19 +17,20 @@
package android.nearby;
import android.annotation.NonNull;
+import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
-import com.android.internal.util.Preconditions;
-
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
/**
* Represents a public credential.
*
* @hide
*/
+@SystemApi
public final class PublicCredential extends PresenceCredential implements Parcelable {
@NonNull
public static final Creator<PublicCredential> CREATOR = new Creator<PublicCredential>() {
@@ -47,15 +48,15 @@
private final byte[] mPublicKey;
private final byte[] mEncryptedMetadata;
- private final byte[] mMetaDataEncryptionKeyTag;
+ private final byte[] mEncryptedMetadataKeyTag;
- private PublicCredential(int identityType, byte[] secreteId, byte[] authenticityKey,
+ private PublicCredential(int identityType, byte[] secretId, byte[] authenticityKey,
List<CredentialElement> credentialElements, byte[] publicKey, byte[] encryptedMetadata,
- byte[] metaDataEncryptionKeyTag) {
- super(CREDENTIAL_TYPE_PUBLIC, identityType, secreteId, authenticityKey, credentialElements);
+ byte[] metadataEncryptionKeyTag) {
+ super(CREDENTIAL_TYPE_PUBLIC, identityType, secretId, authenticityKey, credentialElements);
mPublicKey = publicKey;
mEncryptedMetadata = encryptedMetadata;
- mMetaDataEncryptionKeyTag = metaDataEncryptionKeyTag;
+ mEncryptedMetadataKeyTag = metadataEncryptionKeyTag;
}
private PublicCredential(Parcel in) {
@@ -64,8 +65,8 @@
in.readByteArray(mPublicKey);
mEncryptedMetadata = new byte[in.readInt()];
in.readByteArray(mEncryptedMetadata);
- mMetaDataEncryptionKeyTag = new byte[in.readInt()];
- in.readByteArray(mMetaDataEncryptionKeyTag);
+ mEncryptedMetadataKeyTag = new byte[in.readInt()];
+ in.readByteArray(mEncryptedMetadataKeyTag);
}
static PublicCredential createFromParcelBody(Parcel in) {
@@ -92,8 +93,8 @@
* Returns the metadata encryption key tag associated with this credential.
*/
@NonNull
- public byte[] getMetaDataEncryptionKeyTag() {
- return mMetaDataEncryptionKeyTag;
+ public byte[] getEncryptedMetadataKeyTag() {
+ return mEncryptedMetadataKeyTag;
}
@Override
@@ -108,26 +109,28 @@
dest.writeByteArray(mPublicKey);
dest.writeInt(mEncryptedMetadata.length);
dest.writeByteArray(mEncryptedMetadata);
- dest.writeInt(mMetaDataEncryptionKeyTag.length);
- dest.writeByteArray(mMetaDataEncryptionKeyTag);
+ dest.writeInt(mEncryptedMetadataKeyTag.length);
+ dest.writeByteArray(mEncryptedMetadataKeyTag);
}
/**
* Builder class for {@link PresenceCredential}.
- *
- * @hide
*/
public static final class Builder {
private final List<CredentialElement> mCredentialElements;
private @IdentityType int mIdentityType;
- private byte[] mSecreteId;
+ private byte[] mSecretId;
private byte[] mAuthenticityKey;
private byte[] mPublicKey;
private byte[] mEncryptedMetadata;
- private byte[] mMetaDataEncryptionKeyTag;
+ private byte[] mEncryptedMetadataKeyTag;
- public Builder() {
+ public Builder(@NonNull byte[] secretId, @NonNull byte[] authenticityKey) {
+ Objects.requireNonNull(secretId);
+ Objects.requireNonNull(authenticityKey);
+ mSecretId = secretId;
+ mAuthenticityKey = authenticityKey;
mCredentialElements = new ArrayList<>();
}
@@ -141,28 +144,11 @@
}
/**
- * Sets the secrete id for the presence credential.
- */
- @NonNull
- public Builder setSecretId(@NonNull byte[] secreteId) {
- mSecreteId = secreteId;
- return this;
- }
-
- /**
- * Sets the authenticity key for the presence credential.
- */
- @NonNull
- public Builder setAuthenticityKey(@NonNull byte[] authenticityKey) {
- mAuthenticityKey = authenticityKey;
- return this;
- }
-
- /**
* Adds an element to the credential.
*/
@NonNull
public Builder addCredentialElement(@NonNull CredentialElement credentialElement) {
+ Objects.requireNonNull(credentialElement);
mCredentialElements.add(credentialElement);
return this;
}
@@ -172,6 +158,7 @@
*/
@NonNull
public Builder setPublicKey(@NonNull byte[] publicKey) {
+ Objects.requireNonNull(publicKey);
mPublicKey = publicKey;
return this;
}
@@ -181,16 +168,18 @@
*/
@NonNull
public Builder setEncryptedMetadata(@NonNull byte[] encryptedMetadata) {
+ Objects.requireNonNull(encryptedMetadata);
mEncryptedMetadata = encryptedMetadata;
return this;
}
/**
- * Sets the metadata encryption key tag.
+ * Sets the encrypted metadata key tag.
*/
@NonNull
- public Builder setMetaDataEncryptionKeyTag(@NonNull byte[] metaDataEncryptionKeyTag) {
- mMetaDataEncryptionKeyTag = metaDataEncryptionKeyTag;
+ public Builder setEncryptedMetadataKeyTag(@NonNull byte[] encryptedMetadataKeyTag) {
+ Objects.requireNonNull(encryptedMetadataKeyTag);
+ mEncryptedMetadataKeyTag = encryptedMetadataKeyTag;
return this;
}
@@ -199,11 +188,8 @@
*/
@NonNull
public PublicCredential build() {
- Preconditions.checkState(mSecreteId.length > 0, "secrete id cannot be empty");
- Preconditions.checkState(mAuthenticityKey.length > 0,
- "authenticity key cannot be empty");
- return new PublicCredential(mIdentityType, mSecreteId, mAuthenticityKey,
- mCredentialElements, mPublicKey, mEncryptedMetadata, mMetaDataEncryptionKeyTag);
+ return new PublicCredential(mIdentityType, mSecretId, mAuthenticityKey,
+ mCredentialElements, mPublicKey, mEncryptedMetadata, mEncryptedMetadataKeyTag);
}
}
diff --git a/nearby/framework/java/android/nearby/ScanFilter.java b/nearby/framework/java/android/nearby/ScanFilter.java
index 0b2a754..e16c6a0 100644
--- a/nearby/framework/java/android/nearby/ScanFilter.java
+++ b/nearby/framework/java/android/nearby/ScanFilter.java
@@ -16,8 +16,10 @@
package android.nearby;
+import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.SuppressLint;
+import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
@@ -26,6 +28,7 @@
*
* @hide
*/
+@SystemApi
@SuppressLint("ParcelNotFinal") // ScanFilter constructor is not public
public abstract class ScanFilter implements Parcelable {
public static final @NonNull Creator<ScanFilter> CREATOR = new Creator<ScanFilter>() {
@@ -33,6 +36,8 @@
public ScanFilter createFromParcel(Parcel in) {
int type = in.readInt();
switch (type) {
+ // Currently, only Nearby Presence filtering is supported, in the future
+ // filtering other nearby specifications will be added.
case ScanRequest.SCAN_TYPE_NEARBY_PRESENCE:
return PresenceScanFilter.createFromParcelBody(in);
default:
@@ -48,16 +53,16 @@
};
private final @ScanRequest.ScanType int mType;
- private final int mRssiThreshold;
+ private final int mMaxPathLoss;
/**
* Constructs a Scan Filter.
*
* @hide
*/
- ScanFilter(@ScanRequest.ScanType int type, int rssiThreshold) {
+ ScanFilter(@ScanRequest.ScanType int type, @IntRange(from = 0, to = 127) int maxPathLoss) {
mType = type;
- mRssiThreshold = rssiThreshold;
+ mMaxPathLoss = maxPathLoss;
}
/**
@@ -67,7 +72,7 @@
*/
ScanFilter(@ScanRequest.ScanType int type, Parcel in) {
mType = type;
- mRssiThreshold = in.readInt();
+ mMaxPathLoss = in.readInt();
}
/**
@@ -78,16 +83,19 @@
}
/**
- * Minimum RSSI of the received scan result.
+ * Returns the maximum path loss (in dBm) of the received scan result. The path loss is the
+ * attenuation of radio energy between sender and receiver. Path loss here is defined as
+ * (TxPower - Rssi).
*/
- public int getRssiThreshold() {
- return mRssiThreshold;
+ @IntRange(from = 0, to = 127)
+ public int getMaxPathLoss() {
+ return mMaxPathLoss;
}
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeInt(mType);
- dest.writeInt(mRssiThreshold);
+ dest.writeInt(mMaxPathLoss);
}
/**
@@ -97,5 +105,4 @@
public int describeContents() {
return 0;
}
-
}
diff --git a/nearby/framework/java/android/nearby/ScanRequest.java b/nearby/framework/java/android/nearby/ScanRequest.java
index 9180d5e..7ff0631 100644
--- a/nearby/framework/java/android/nearby/ScanRequest.java
+++ b/nearby/framework/java/android/nearby/ScanRequest.java
@@ -126,7 +126,7 @@
/**
* Returns true if an integer is a defined scan type.
*/
- public static boolean isValidScanType(int scanType) {
+ public static boolean isValidScanType(@ScanType int scanType) {
return scanType == SCAN_TYPE_FAST_PAIR
|| scanType == SCAN_TYPE_NEARBY_SHARE
|| scanType == SCAN_TYPE_NEARBY_PRESENCE
@@ -136,7 +136,7 @@
/**
* Returns true if an integer is a defined scan mode.
*/
- public static boolean isValidScanMode(int scanMode) {
+ public static boolean isValidScanMode(@ScanMode int scanMode) {
return scanMode == SCAN_MODE_LOW_LATENCY
|| scanMode == SCAN_MODE_BALANCED
|| scanMode == SCAN_MODE_LOW_POWER
@@ -166,8 +166,6 @@
/**
* Returns Scan Filters for this request.
- *
- * @hide
*/
@NonNull
public List<ScanFilter> getScanFilters() {
@@ -334,11 +332,10 @@
* usage of Nearby scans.
*
* @param scanFilter Filter for scanning the request.
- *
- * @hide
*/
@NonNull
public Builder addScanFilter(@NonNull ScanFilter scanFilter) {
+ Objects.requireNonNull(scanFilter);
mScanFilters.add(scanFilter);
return this;
}
diff --git a/nearby/service/java/com/android/server/nearby/provider/Utils.java b/nearby/service/java/com/android/server/nearby/provider/Utils.java
index ddb01fa..3aceb7d 100644
--- a/nearby/service/java/com/android/server/nearby/provider/Utils.java
+++ b/nearby/service/java/com/android/server/nearby/provider/Utils.java
@@ -291,30 +291,42 @@
if (metadata == null) {
return null;
}
+
+ Rpcs.Device.Builder deviceBuilder = Rpcs.Device.newBuilder();
+ if (metadata.antiSpoofPublicKey != null) {
+ deviceBuilder.setAntiSpoofingKeyPair(Rpcs.AntiSpoofingKeyPair.newBuilder()
+ .setPublicKey(ByteString.copyFrom(metadata.antiSpoofPublicKey))
+ .build());
+ }
+ if (metadata.deviceMetadata != null) {
+ Rpcs.TrueWirelessHeadsetImages.Builder imagesBuilder =
+ Rpcs.TrueWirelessHeadsetImages.newBuilder();
+ if (metadata.deviceMetadata.trueWirelessImageUrlLeftBud != null) {
+ imagesBuilder.setLeftBudUrl(metadata.deviceMetadata.trueWirelessImageUrlLeftBud);
+ }
+ if (metadata.deviceMetadata.trueWirelessImageUrlRightBud != null) {
+ imagesBuilder.setRightBudUrl(metadata.deviceMetadata.trueWirelessImageUrlRightBud);
+ }
+ if (metadata.deviceMetadata.trueWirelessImageUrlCase != null) {
+ imagesBuilder.setCaseUrl(metadata.deviceMetadata.trueWirelessImageUrlCase);
+ }
+ deviceBuilder.setTrueWirelessImages(imagesBuilder.build());
+ if (metadata.deviceMetadata.imageUrl != null) {
+ deviceBuilder.setImageUrl(metadata.deviceMetadata.imageUrl);
+ }
+ if (metadata.deviceMetadata.intentUri != null) {
+ deviceBuilder.setIntentUri(metadata.deviceMetadata.intentUri);
+ }
+ if (metadata.deviceMetadata.name != null) {
+ deviceBuilder.setName(metadata.deviceMetadata.name);
+ }
+ deviceBuilder.setBleTxPower(metadata.deviceMetadata.bleTxPower)
+ .setTriggerDistance(metadata.deviceMetadata.triggerDistance)
+ .setDeviceType(Rpcs.DeviceType.forNumber(metadata.deviceMetadata.deviceType));
+ }
+
return Rpcs.GetObservedDeviceResponse.newBuilder()
- .setDevice(Rpcs.Device.newBuilder()
- .setAntiSpoofingKeyPair(Rpcs.AntiSpoofingKeyPair.newBuilder()
- .setPublicKey(ByteString.copyFrom(metadata.antiSpoofPublicKey))
- .build())
- .setTrueWirelessImages(Rpcs.TrueWirelessHeadsetImages.newBuilder()
- .setLeftBudUrl(
- metadata.deviceMetadata.trueWirelessImageUrlLeftBud)
- .setRightBudUrl(
- metadata.deviceMetadata
- .trueWirelessImageUrlRightBud)
- .setCaseUrl(
- metadata.deviceMetadata
- .trueWirelessImageUrlCase
- )
- .build())
- .setImageUrl(metadata.deviceMetadata.imageUrl)
- .setIntentUri(metadata.deviceMetadata.intentUri)
- .setName(metadata.deviceMetadata.name)
- .setBleTxPower(metadata.deviceMetadata.bleTxPower)
- .setTriggerDistance(metadata.deviceMetadata.triggerDistance)
- .setDeviceType(
- Rpcs.DeviceType.forNumber(metadata.deviceMetadata.deviceType))
- .build())
+ .setDevice(deviceBuilder.build())
.setImage(ByteString.copyFrom(metadata.deviceMetadata.image))
.setStrings(Rpcs.ObservedDeviceStrings.newBuilder()
.setAssistantSetupHalfSheet(metadata.deviceMetadata.assistantSetupHalfSheet)
diff --git a/nearby/tests/cts/fastpair/src/android/nearby/cts/CredentialElementTest.java b/nearby/tests/cts/fastpair/src/android/nearby/cts/CredentialElementTest.java
index 0cf81ee..19a4a40 100644
--- a/nearby/tests/cts/fastpair/src/android/nearby/cts/CredentialElementTest.java
+++ b/nearby/tests/cts/fastpair/src/android/nearby/cts/CredentialElementTest.java
@@ -39,8 +39,7 @@
@Test
public void testBuilder() {
- CredentialElement element = new CredentialElement.Builder().setElement(KEY,
- VALUE).build();
+ CredentialElement element = new CredentialElement(KEY, VALUE);
assertThat(element.getKey()).isEqualTo(KEY);
assertThat(Arrays.equals(element.getValue(), VALUE)).isTrue();
@@ -48,8 +47,7 @@
@Test
public void testWriteParcel() {
- CredentialElement element = new CredentialElement.Builder().setElement(KEY,
- VALUE).build();
+ CredentialElement element = new CredentialElement(KEY, VALUE);
Parcel parcel = Parcel.obtain();
element.writeToParcel(parcel, 0);
diff --git a/nearby/tests/cts/fastpair/src/android/nearby/cts/DataElementTest.java b/nearby/tests/cts/fastpair/src/android/nearby/cts/DataElementTest.java
index d096ed1..eb03a0d 100644
--- a/nearby/tests/cts/fastpair/src/android/nearby/cts/DataElementTest.java
+++ b/nearby/tests/cts/fastpair/src/android/nearby/cts/DataElementTest.java
@@ -40,7 +40,7 @@
@Test
public void testBuilder() {
- DataElement dataElement = new DataElement.Builder().setElement(KEY, VALUE).build();
+ DataElement dataElement = new DataElement(KEY, VALUE);
assertThat(dataElement.getKey()).isEqualTo(KEY);
assertThat(Arrays.equals(dataElement.getValue(), VALUE)).isTrue();
@@ -48,7 +48,7 @@
@Test
public void testWriteParcel() {
- DataElement dataElement = new DataElement.Builder().setElement(KEY, VALUE).build();
+ DataElement dataElement = new DataElement(KEY, VALUE);
Parcel parcel = Parcel.obtain();
dataElement.writeToParcel(parcel, 0);
diff --git a/nearby/tests/cts/fastpair/src/android/nearby/cts/NearbyDeviceTest.java b/nearby/tests/cts/fastpair/src/android/nearby/cts/NearbyDeviceTest.java
index aad3fca..f37800a 100644
--- a/nearby/tests/cts/fastpair/src/android/nearby/cts/NearbyDeviceTest.java
+++ b/nearby/tests/cts/fastpair/src/android/nearby/cts/NearbyDeviceTest.java
@@ -49,11 +49,11 @@
@SdkSuppress(minSdkVersion = 32, codeName = "T")
public void test_getMedium_fromChild() {
FastPairDevice fastPairDevice = new FastPairDevice.Builder()
- .setMedium(NearbyDevice.Medium.BLE)
+ .addMedium(NearbyDevice.Medium.BLE)
.setRssi(-60)
.build();
- assertThat(fastPairDevice.getMedium()).isEqualTo(1);
+ assertThat(fastPairDevice.getMediums()).contains(1);
assertThat(fastPairDevice.getRssi()).isEqualTo(-60);
}
}
diff --git a/nearby/tests/cts/fastpair/src/android/nearby/cts/NearbyManagerTest.java b/nearby/tests/cts/fastpair/src/android/nearby/cts/NearbyManagerTest.java
index 23ae47d..f32ef12 100644
--- a/nearby/tests/cts/fastpair/src/android/nearby/cts/NearbyManagerTest.java
+++ b/nearby/tests/cts/fastpair/src/android/nearby/cts/NearbyManagerTest.java
@@ -41,6 +41,7 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import java.util.Collections;
import java.util.concurrent.Executors;
/**
@@ -92,15 +93,12 @@
@Test
public void testStartStopBroadcast() {
- PrivateCredential credential = new PrivateCredential.Builder()
+ PrivateCredential credential = new PrivateCredential.Builder(SECRETE_ID, AUTHENTICITY_KEY)
.setIdentityType(IDENTITY_TYPE_PRIVATE)
- .setSecretId(SECRETE_ID)
- .setAuthenticityKey(AUTHENTICITY_KEY)
.build();
BroadcastRequest broadcastRequest =
- new PresenceBroadcastRequest.Builder()
- .setSalt(SALT)
- .addMediums(BLE_MEDIUM).setCredential(credential)
+ new PresenceBroadcastRequest.Builder(Collections.singletonList(BLE_MEDIUM), SALT)
+ .setCredential(credential)
.build();
BroadcastCallback callback = status -> {
diff --git a/nearby/tests/cts/fastpair/src/android/nearby/cts/PresenceBroadcastRequestTest.java b/nearby/tests/cts/fastpair/src/android/nearby/cts/PresenceBroadcastRequestTest.java
index a27d525..0b3ff07 100644
--- a/nearby/tests/cts/fastpair/src/android/nearby/cts/PresenceBroadcastRequestTest.java
+++ b/nearby/tests/cts/fastpair/src/android/nearby/cts/PresenceBroadcastRequestTest.java
@@ -34,6 +34,8 @@
import org.junit.Test;
import org.junit.runner.RunWith;
+import java.util.Collections;
+
/**
* Tests for {@link PresenceBroadcastRequest}.
*/
@@ -56,19 +58,15 @@
@Before
public void setUp() {
- PrivateCredential credential = new PrivateCredential.Builder()
+ PrivateCredential credential = new PrivateCredential.Builder(SECRETE_ID, AUTHENTICITY_KEY)
.setIdentityType(IDENTITY_TYPE_PRIVATE)
- .setSecretId(SECRETE_ID)
- .setAuthenticityKey(AUTHENTICITY_KEY)
- .setMetaDataEncryptionKey(METADATA_ENCRYPTION_KEY)
+ .setMetadataEncryptionKey(METADATA_ENCRYPTION_KEY)
.build();
- DataElement element = new DataElement.Builder().setElement(KEY, VALUE).build();
- mBuilder = new PresenceBroadcastRequest.Builder()
- .setSalt(SALT)
+ DataElement element = new DataElement(KEY, VALUE);
+ mBuilder = new PresenceBroadcastRequest.Builder(Collections.singletonList(BLE_MEDIUM), SALT)
.setTxPower(TX_POWER)
.setCredential(credential)
.addAction(ACTION_ID)
- .addMediums(BLE_MEDIUM)
.addExtendedProperty(element);
}
diff --git a/nearby/tests/cts/fastpair/src/android/nearby/cts/PresenceDeviceTest.java b/nearby/tests/cts/fastpair/src/android/nearby/cts/PresenceDeviceTest.java
index c704022..e21bc80 100644
--- a/nearby/tests/cts/fastpair/src/android/nearby/cts/PresenceDeviceTest.java
+++ b/nearby/tests/cts/fastpair/src/android/nearby/cts/PresenceDeviceTest.java
@@ -18,6 +18,7 @@
import static com.google.common.truth.Truth.assertThat;
+import android.nearby.DataElement;
import android.nearby.NearbyDevice;
import android.nearby.PresenceDevice;
import android.os.Build;
@@ -29,6 +30,8 @@
import org.junit.Test;
import org.junit.runner.RunWith;
+import java.util.Arrays;
+
/**
* Test for {@link PresenceDevice}.
*/
@@ -38,11 +41,11 @@
private static final int DEVICE_TYPE = PresenceDevice.DeviceType.PHONE;
private static final String DEVICE_ID = "123";
private static final String IMAGE_URL = "http://example.com/imageUrl";
- private static final String SUPPORT_MEDIA = "SupportMedia";
- private static final String SUPPORT_MEDIA_VALUE = "true";
private static final int RSSI = -40;
private static final int MEDIUM = NearbyDevice.Medium.BLE;
private static final String DEVICE_NAME = "testDevice";
+ private static final int KEY = 1234;
+ private static final byte[] VALUE = new byte[]{1, 1, 1, 1};
@Test
public void testBuilder() {
@@ -50,19 +53,20 @@
.setDeviceType(DEVICE_TYPE)
.setDeviceId(DEVICE_ID)
.setDeviceImageUrl(IMAGE_URL)
- .addExtendedProperty(SUPPORT_MEDIA, SUPPORT_MEDIA_VALUE)
+ .addExtendedProperty(new DataElement(KEY, VALUE))
.setRssi(RSSI)
- .setMedium(MEDIUM)
+ .addMedium(MEDIUM)
.setName(DEVICE_NAME)
.build();
assertThat(device.getDeviceType()).isEqualTo(DEVICE_TYPE);
assertThat(device.getDeviceId()).isEqualTo(DEVICE_ID);
assertThat(device.getDeviceImageUrl()).isEqualTo(IMAGE_URL);
- assertThat(device.getExtendedProperties().get(SUPPORT_MEDIA)).isEqualTo(
- SUPPORT_MEDIA_VALUE);
+ DataElement dataElement = device.getExtendedProperties().get(0);
+ assertThat(dataElement.getKey()).isEqualTo(KEY);
+ assertThat(Arrays.equals(dataElement.getValue(), VALUE)).isTrue();
assertThat(device.getRssi()).isEqualTo(RSSI);
- assertThat(device.getMedium()).isEqualTo(MEDIUM);
+ assertThat(device.getMediums()).containsExactly(MEDIUM);
assertThat(device.getName()).isEqualTo(DEVICE_NAME);
}
@@ -70,9 +74,9 @@
public void testWriteParcel() {
PresenceDevice device = new PresenceDevice.Builder()
.setDeviceId(DEVICE_ID)
- .addExtendedProperty(SUPPORT_MEDIA, SUPPORT_MEDIA_VALUE)
+ .addExtendedProperty(new DataElement(KEY, VALUE))
.setRssi(RSSI)
- .setMedium(MEDIUM)
+ .addMedium(MEDIUM)
.setName(DEVICE_NAME)
.build();
@@ -83,10 +87,9 @@
parcel.recycle();
assertThat(parcelDevice.getDeviceId()).isEqualTo(DEVICE_ID);
- assertThat(parcelDevice.getExtendedProperties().get(SUPPORT_MEDIA)).isEqualTo(
- SUPPORT_MEDIA_VALUE);
+ assertThat(parcelDevice.getExtendedProperties().get(0).getKey()).isEqualTo(KEY);
assertThat(parcelDevice.getRssi()).isEqualTo(RSSI);
- assertThat(parcelDevice.getMedium()).isEqualTo(MEDIUM);
+ assertThat(parcelDevice.getMediums()).containsExactly(MEDIUM);
assertThat(parcelDevice.getName()).isEqualTo(DEVICE_NAME);
}
}
diff --git a/nearby/tests/cts/fastpair/src/android/nearby/cts/PresenceScanFilterTest.java b/nearby/tests/cts/fastpair/src/android/nearby/cts/PresenceScanFilterTest.java
index 017677f..8962499 100644
--- a/nearby/tests/cts/fastpair/src/android/nearby/cts/PresenceScanFilterTest.java
+++ b/nearby/tests/cts/fastpair/src/android/nearby/cts/PresenceScanFilterTest.java
@@ -52,22 +52,21 @@
private PublicCredential mPublicCredential =
- new PublicCredential.Builder()
+ new PublicCredential.Builder(SECRETE_ID, AUTHENTICITY_KEY)
.setIdentityType(IDENTITY_TYPE_PRIVATE)
- .setSecretId(SECRETE_ID).setAuthenticityKey(AUTHENTICITY_KEY)
.setPublicKey(PUBLIC_KEY).setEncryptedMetadata(ENCRYPTED_METADATA)
- .setMetaDataEncryptionKeyTag(METADATA_ENCRYPTION_KEY_TAG).build();
+ .setEncryptedMetadataKeyTag(METADATA_ENCRYPTION_KEY_TAG).build();
private PresenceScanFilter.Builder mBuilder = new PresenceScanFilter.Builder()
- .setRssiThreshold(RSSI)
+ .setMaxPathLoss(RSSI)
.addCredential(mPublicCredential)
.addPresenceAction(ACTION)
- .addExtendedProperty(new DataElement.Builder().setElement(KEY, VALUE).build());
+ .addExtendedProperty(new DataElement(KEY, VALUE));
@Test
public void testBuilder() {
PresenceScanFilter filter = mBuilder.build();
- assertThat(filter.getRssiThreshold()).isEqualTo(RSSI);
+ assertThat(filter.getMaxPathLoss()).isEqualTo(RSSI);
assertThat(filter.getCredentials().get(0).getIdentityType()).isEqualTo(
IDENTITY_TYPE_PRIVATE);
assertThat(filter.getPresenceActions()).containsExactly(ACTION);
@@ -84,7 +83,7 @@
parcel.recycle();
assertThat(parcelFilter.getType()).isEqualTo(ScanRequest.SCAN_TYPE_NEARBY_PRESENCE);
- assertThat(parcelFilter.getRssiThreshold()).isEqualTo(RSSI);
+ assertThat(parcelFilter.getMaxPathLoss()).isEqualTo(RSSI);
assertThat(parcelFilter.getPresenceActions()).containsExactly(ACTION);
}
}
diff --git a/nearby/tests/cts/fastpair/src/android/nearby/cts/PrivateCredentialTest.java b/nearby/tests/cts/fastpair/src/android/nearby/cts/PrivateCredentialTest.java
index 054bb1a..3212307 100644
--- a/nearby/tests/cts/fastpair/src/android/nearby/cts/PrivateCredentialTest.java
+++ b/nearby/tests/cts/fastpair/src/android/nearby/cts/PrivateCredentialTest.java
@@ -51,12 +51,10 @@
@Before
public void setUp() {
- mBuilder = new PrivateCredential.Builder()
+ mBuilder = new PrivateCredential.Builder(SECRETE_ID, AUTHENTICITY_KEY)
.setIdentityType(IDENTITY_TYPE_PRIVATE)
- .setSecretId(SECRETE_ID).setAuthenticityKey(AUTHENTICITY_KEY)
- .setMetaDataEncryptionKey(METADATA_ENCRYPTION_KEY)
- .addCredentialElement(
- new CredentialElement.Builder().setElement(KEY, VALUE).build());
+ .setMetadataEncryptionKey(METADATA_ENCRYPTION_KEY)
+ .addCredentialElement(new CredentialElement(KEY, VALUE));
}
@Test
@@ -67,7 +65,7 @@
assertThat(credential.getIdentityType()).isEqualTo(IDENTITY_TYPE_PRIVATE);
assertThat(Arrays.equals(credential.getSecretId(), SECRETE_ID)).isTrue();
assertThat(Arrays.equals(credential.getAuthenticityKey(), AUTHENTICITY_KEY)).isTrue();
- assertThat(Arrays.equals(credential.getMetaDataEncryptionKey(),
+ assertThat(Arrays.equals(credential.getMetadataEncryptionKey(),
METADATA_ENCRYPTION_KEY)).isTrue();
CredentialElement credentialElement = credential.getCredentialElements().get(0);
assertThat(credentialElement.getKey()).isEqualTo(KEY);
@@ -90,7 +88,7 @@
assertThat(Arrays.equals(credentialFromParcel.getSecretId(), SECRETE_ID)).isTrue();
assertThat(Arrays.equals(credentialFromParcel.getAuthenticityKey(),
AUTHENTICITY_KEY)).isTrue();
- assertThat(Arrays.equals(credentialFromParcel.getMetaDataEncryptionKey(),
+ assertThat(Arrays.equals(credentialFromParcel.getMetadataEncryptionKey(),
METADATA_ENCRYPTION_KEY)).isTrue();
CredentialElement credentialElement = credentialFromParcel.getCredentialElements().get(0);
assertThat(credentialElement.getKey()).isEqualTo(KEY);
diff --git a/nearby/tests/cts/fastpair/src/android/nearby/cts/PublicCredentialTest.java b/nearby/tests/cts/fastpair/src/android/nearby/cts/PublicCredentialTest.java
index 4359ba5..4a12416 100644
--- a/nearby/tests/cts/fastpair/src/android/nearby/cts/PublicCredentialTest.java
+++ b/nearby/tests/cts/fastpair/src/android/nearby/cts/PublicCredentialTest.java
@@ -52,11 +52,10 @@
@Before
public void setUp() {
- mBuilder = new PublicCredential.Builder()
+ mBuilder = new PublicCredential.Builder(SECRETE_ID, AUTHENTICITY_KEY)
.setIdentityType(IDENTITY_TYPE_PRIVATE)
- .setSecretId(SECRETE_ID).setAuthenticityKey(AUTHENTICITY_KEY)
.setPublicKey(PUBLIC_KEY).setEncryptedMetadata(ENCRYPTED_METADATA)
- .setMetaDataEncryptionKeyTag(METADATA_ENCRYPTION_KEY_TAG);
+ .setEncryptedMetadataKeyTag(METADATA_ENCRYPTION_KEY_TAG);
}
@Test
@@ -69,7 +68,7 @@
assertThat(Arrays.equals(credential.getAuthenticityKey(), AUTHENTICITY_KEY)).isTrue();
assertThat(Arrays.equals(credential.getPublicKey(), PUBLIC_KEY)).isTrue();
assertThat(Arrays.equals(credential.getEncryptedMetadata(), ENCRYPTED_METADATA)).isTrue();
- assertThat(Arrays.equals(credential.getMetaDataEncryptionKeyTag(),
+ assertThat(Arrays.equals(credential.getEncryptedMetadataKeyTag(),
METADATA_ENCRYPTION_KEY_TAG)).isTrue();
}
@@ -92,7 +91,7 @@
assertThat(Arrays.equals(credentialFromParcel.getPublicKey(), PUBLIC_KEY)).isTrue();
assertThat(Arrays.equals(credentialFromParcel.getEncryptedMetadata(),
ENCRYPTED_METADATA)).isTrue();
- assertThat(Arrays.equals(credentialFromParcel.getMetaDataEncryptionKeyTag(),
+ assertThat(Arrays.equals(credentialFromParcel.getEncryptedMetadataKeyTag(),
METADATA_ENCRYPTION_KEY_TAG)).isTrue();
}
}
diff --git a/nearby/tests/cts/fastpair/src/android/nearby/cts/ScanRequestTest.java b/nearby/tests/cts/fastpair/src/android/nearby/cts/ScanRequestTest.java
index 25aa926..2d01e83 100644
--- a/nearby/tests/cts/fastpair/src/android/nearby/cts/ScanRequestTest.java
+++ b/nearby/tests/cts/fastpair/src/android/nearby/cts/ScanRequestTest.java
@@ -157,25 +157,23 @@
@Test
@SdkSuppress(minSdkVersion = 32, codeName = "T")
public void testScanFilter() {
- final byte[] secreteId = new byte[]{1, 2, 3, 4};
+ final byte[] secretId = new byte[]{1, 2, 3, 4};
final byte[] authenticityKey = new byte[]{0, 1, 1, 1};
final byte[] publicKey = new byte[]{1, 1, 2, 2};
final byte[] encryptedMetadata = new byte[]{1, 2, 3, 4, 5};
final byte[] metadataEncryptionKeyTag = new byte[]{1, 1, 3, 4, 5};
- PublicCredential credential = new PublicCredential.Builder()
+ PublicCredential credential = new PublicCredential.Builder(secretId, authenticityKey)
.setIdentityType(IDENTITY_TYPE_PRIVATE)
- .setSecretId(secreteId)
- .setAuthenticityKey(authenticityKey)
.setEncryptedMetadata(encryptedMetadata)
.setPublicKey(publicKey)
- .setMetaDataEncryptionKeyTag(metadataEncryptionKeyTag).build();
+ .setEncryptedMetadataKeyTag(metadataEncryptionKeyTag).build();
final int rssi = -40;
final int action = 123;
PresenceScanFilter filter = new PresenceScanFilter.Builder()
.addCredential(credential)
- .setRssiThreshold(rssi)
+ .setMaxPathLoss(rssi)
.addPresenceAction(action)
.build();
@@ -183,7 +181,7 @@
SCAN_TYPE_FAST_PAIR).addScanFilter(filter).build();
assertThat(request.getScanFilters()).isNotEmpty();
- assertThat(request.getScanFilters().get(0).getRssiThreshold()).isEqualTo(rssi);
+ assertThat(request.getScanFilters().get(0).getMaxPathLoss()).isEqualTo(rssi);
}
private static WorkSource getWorkSource() {