Add NearbyFrameworkInitializer and expose NearbyManager as SystemApi
Test: Built successfully
Bug: 189954300
Change-Id: I1323dc7b2fb9c91a7acf03e88f27c4029425c21d
CTS-Coverage-Bug: 213364287
diff --git a/nearby/framework/api/system-current.txt b/nearby/framework/api/system-current.txt
index fe3cd98..9d0d135 100644
--- a/nearby/framework/api/system-current.txt
+++ b/nearby/framework/api/system-current.txt
@@ -33,5 +33,79 @@
method @Nullable public byte[] getModelId();
}
+ public abstract class NearbyDevice {
+ method public int getMedium();
+ method @IntRange(from=0xffffff81, to=126) public int getRssi();
+ method public static boolean isValidMedium(int);
+ }
+
+ public final class NearbyDeviceParcelable implements android.os.Parcelable {
+ method public int describeContents();
+ method @Nullable public String getBluetoothAddress();
+ method @Nullable public byte[] getData();
+ method @Nullable public String getFastPairModelId();
+ method public int getMedium();
+ method @Nullable public String getName();
+ method @IntRange(from=0xffffff81, to=126) public int getRssi();
+ method public void writeToParcel(@NonNull android.os.Parcel, int);
+ field @NonNull public static final android.os.Parcelable.Creator<android.nearby.NearbyDeviceParcelable> CREATOR;
+ }
+
+ public static final class NearbyDeviceParcelable.Builder {
+ ctor public NearbyDeviceParcelable.Builder();
+ method @NonNull public android.nearby.NearbyDeviceParcelable build();
+ method @NonNull public android.nearby.NearbyDeviceParcelable.Builder setBluetoothAddress(@Nullable String);
+ method @NonNull public android.nearby.NearbyDeviceParcelable.Builder setData(@Nullable byte[]);
+ method @NonNull public android.nearby.NearbyDeviceParcelable.Builder setFastPairModelId(@Nullable String);
+ method @NonNull public android.nearby.NearbyDeviceParcelable.Builder setMedium(int);
+ method @NonNull public android.nearby.NearbyDeviceParcelable.Builder setName(@Nullable String);
+ method @NonNull public android.nearby.NearbyDeviceParcelable.Builder setRssi(int);
+ }
+
+ public final class NearbyFrameworkInitializer {
+ method public static void registerServiceWrappers();
+ }
+
+ public class NearbyManager {
+ method public void startScan(@NonNull android.nearby.ScanRequest, @NonNull java.util.concurrent.Executor, @NonNull android.nearby.ScanCallback);
+ method public void stopScan(@NonNull android.nearby.ScanCallback);
+ }
+
+ public interface ScanCallback {
+ method public void onDiscovered(@NonNull android.nearby.NearbyDevice);
+ method public void onLost(@NonNull android.nearby.NearbyDevice);
+ method public void onUpdated(@NonNull android.nearby.NearbyDevice);
+ }
+
+ public final class ScanRequest implements android.os.Parcelable {
+ method public int describeContents();
+ method public int getScanMode();
+ method public int getScanType();
+ method @NonNull public android.os.WorkSource getWorkSource();
+ method public boolean isEnableBle();
+ method public static boolean isValidScanMode(int);
+ method public static boolean isValidScanType(int);
+ method @NonNull public static String scanModeToString(int);
+ method public void writeToParcel(@NonNull android.os.Parcel, int);
+ field @NonNull public static final android.os.Parcelable.Creator<android.nearby.ScanRequest> CREATOR;
+ field public static final int SCAN_MODE_BALANCED = 1; // 0x1
+ field public static final int SCAN_MODE_LOW_LATENCY = 2; // 0x2
+ field public static final int SCAN_MODE_LOW_POWER = 0; // 0x0
+ field public static final int SCAN_MODE_NO_POWER = -1; // 0xffffffff
+ field public static final int SCAN_TYPE_EXPOSURE_NOTIFICATION = 4; // 0x4
+ field public static final int SCAN_TYPE_FAST_PAIR = 1; // 0x1
+ field public static final int SCAN_TYPE_NEARBY_PRESENCE = 3; // 0x3
+ field public static final int SCAN_TYPE_NEARBY_SHARE = 2; // 0x2
+ }
+
+ public static final class ScanRequest.Builder {
+ ctor public ScanRequest.Builder();
+ method @NonNull public android.nearby.ScanRequest build();
+ method @NonNull public android.nearby.ScanRequest.Builder setEnableBle(boolean);
+ method @NonNull public android.nearby.ScanRequest.Builder setScanMode(int);
+ method @NonNull public android.nearby.ScanRequest.Builder setScanType(int);
+ method @NonNull @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public android.nearby.ScanRequest.Builder setWorkSource(@Nullable android.os.WorkSource);
+ }
+
}
diff --git a/nearby/framework/java/android/nearby/FastPairDevice.java b/nearby/framework/java/android/nearby/FastPairDevice.java
index bda1d48..1e766a5 100644
--- a/nearby/framework/java/android/nearby/FastPairDevice.java
+++ b/nearby/framework/java/android/nearby/FastPairDevice.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007 The Android Open Source Project
+ * Copyright (C) 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
package android.nearby;
-import android.annotation.Hide;
+import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Parcel;
@@ -31,6 +31,9 @@
* @hide
*/
public class FastPairDevice extends NearbyDevice implements Parcelable {
+ /**
+ * Used to read a FastPairDevice from a Parcel.
+ */
public static final Creator<FastPairDevice> CREATOR = new Creator<FastPairDevice>() {
@Override
public FastPairDevice createFromParcel(Parcel in) {
@@ -68,6 +71,17 @@
@Nullable
private final byte[] mData;
+ /**
+ * 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 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.
+ * @param bluetoothAddress The hardware address of this BluetoothDevice.
+ * @param data Extra data for a Fast Pair device.
+ */
public FastPairDevice(@Nullable String name,
@Medium int medium,
int rssi,
@@ -80,44 +94,69 @@
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
public String getModelId() {
return this.mModelId;
}
+ /**
+ * Gets the hardware address of this BluetoothDevice.
+ */
@NonNull
public String getBluetoothAddress() {
return mBluetoothAddress;
}
- // Only visible to system clients.
+ /**
+ * Gets the extra data for a Fast Pair device. Can be {@code null} if there is extra data.
+ *
+ * @hide
+ */
@Nullable
- @Hide
public byte[] getData() {
return mData;
}
+ /**
+ * No special parcel contents.
+ */
@Override
public int describeContents() {
return 0;
}
+ /**
+ * Returns a string representation of this FastPairDevice.
+ */
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
@@ -178,7 +217,7 @@
*
* @hide
*/
- public static final class Builder extends NearbyDevice.Builder {
+ public static final class Builder {
@Nullable private String mName;
@Medium private int mMedium;
@@ -188,6 +227,8 @@
@Nullable private byte[] mData;
/**
* Sets the name of the Fast Pair device.
+ *
+ * @param name Name of the FastPairDevice. Can be {@code null} if there is no name.
*/
@NonNull
public Builder setName(@Nullable String name) {
@@ -197,6 +238,8 @@
/**
* Sets the medium over which the Fast Pair device is discovered.
+ *
+ * @param medium The {@link Medium} over which the device is discovered.
*/
@NonNull
public Builder setMedium(@Medium int medium) {
@@ -206,6 +249,8 @@
/**
* Sets the RSSI between the scan device and the discovered Fast Pair device.
+ *
+ * @param rssi The received signal strength in dBm.
*/
@NonNull
public Builder setRssi(int rssi) {
@@ -215,29 +260,35 @@
/**
* Sets the model Id of this Fast Pair device.
+ *
+ * @param modelId The identifier of the Fast Pair device. Can be {@code null}
+ * if there is no Model ID.
*/
@NonNull
- public Builder setModelId(String modelId) {
+ public Builder setModelId(@Nullable String modelId) {
mModelId = modelId;
return this;
}
/**
* Sets the hardware address of this BluetoothDevice.
+ *
+ * @param bluetoothAddress The hardware address of this BluetoothDevice.
*/
@NonNull
- public Builder setBluetoothAddress(@NonNull String maskedBluetoothAddress) {
- mBluetoothAddress = maskedBluetoothAddress;
+ public Builder setBluetoothAddress(@NonNull String bluetoothAddress) {
+ Objects.requireNonNull(bluetoothAddress);
+ mBluetoothAddress = bluetoothAddress;
return this;
}
/**
- * Sets the raw data. Only visible to system API.
+ * Sets the raw data for a FastPairDevice. Can be {@code null} if there is no extra data.
+ *
* @hide
*/
- @Hide
@NonNull
- public Builder setData(byte[] data) {
+ public Builder setData(@Nullable byte[] data) {
mData = data;
return this;
}
diff --git a/nearby/framework/java/android/nearby/NearbyDevice.java b/nearby/framework/java/android/nearby/NearbyDevice.java
index 12c4ff1..790b2ed 100644
--- a/nearby/framework/java/android/nearby/NearbyDevice.java
+++ b/nearby/framework/java/android/nearby/NearbyDevice.java
@@ -17,7 +17,9 @@
package android.nearby;
import android.annotation.IntDef;
+import android.annotation.IntRange;
import android.annotation.Nullable;
+import android.annotation.SystemApi;
import com.android.internal.util.Preconditions;
@@ -28,6 +30,7 @@
*
* @hide
*/
+@SystemApi
public abstract class NearbyDevice {
@Nullable
@@ -39,6 +42,11 @@
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 rssi The received signal strength in dBm.
* @hide
*/
public NearbyDevice(@Nullable String name, @Medium int medium, int rssi) {
@@ -63,6 +71,8 @@
/**
* True if the medium is defined in {@link Medium}.
+ *
+ * @param medium Integer that may represent a medium type.
*/
public static boolean isValidMedium(@Medium int medium) {
return medium == Medium.BLE
@@ -86,8 +96,9 @@
}
/**
- * Returns the received signal strength in dBm. The valid range is [-127, 126].
+ * Returns the received signal strength in dBm.
*/
+ @IntRange(from = -127, to = 126)
public int getRssi() {
return mRssi;
}
@@ -131,31 +142,5 @@
int BLE = 1;
int BLUETOOTH = 2;
}
-
- /**
- * Builder for a NearbyDevice.
- */
- public abstract static class Builder {
-
- /**
- * Sets the name of Nearby Device.
- */
- public abstract Builder setName(String name);
-
- /**
- * Sets the medium over which the Nearby Device is discovered.
- */
- public abstract Builder setMedium(int medium);
-
- /**
- * Sets the RSSI between scanned device and the discovered device.
- */
- public abstract Builder setRssi(int rssi);
-
- /**
- * Builds the Nearby Device.
- */
- public abstract NearbyDevice build();
- }
}
diff --git a/nearby/framework/java/android/nearby/NearbyDeviceParcelable.aidl b/nearby/framework/java/android/nearby/NearbyDeviceParcelable.aidl
index e211187..1a88181 100644
--- a/nearby/framework/java/android/nearby/NearbyDeviceParcelable.aidl
+++ b/nearby/framework/java/android/nearby/NearbyDeviceParcelable.aidl
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package android.nearby;
parcelable NearbyDeviceParcelable;
diff --git a/nearby/framework/java/android/nearby/NearbyDeviceParcelable.java b/nearby/framework/java/android/nearby/NearbyDeviceParcelable.java
index 6910d13..ed3cb7b 100644
--- a/nearby/framework/java/android/nearby/NearbyDeviceParcelable.java
+++ b/nearby/framework/java/android/nearby/NearbyDeviceParcelable.java
@@ -17,8 +17,11 @@
package android.nearby;
+import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.annotation.SystemApi;
+import android.bluetooth.le.ScanRecord;
import android.os.Parcel;
import android.os.Parcelable;
@@ -34,7 +37,13 @@
*
* @hide
*/
+@SystemApi
public final class NearbyDeviceParcelable implements Parcelable {
+
+ /**
+ * Used to read a NearbyDeviceParcelable from a Parcel.
+ */
+ @NonNull
public static final Creator<NearbyDeviceParcelable> CREATOR =
new Creator<NearbyDeviceParcelable>() {
@Override
@@ -76,7 +85,8 @@
private final byte[] mData;
private NearbyDeviceParcelable(@Nullable String name, int medium, int rssi,
- @Nullable String fastPairModelId, @Nullable String bluetoothAddress, byte[] data) {
+ @Nullable String fastPairModelId, @Nullable String bluetoothAddress,
+ @Nullable byte[] data) {
mName = name;
mMedium = medium;
mRssi = rssi;
@@ -85,11 +95,21 @@
mData = data;
}
+ /**
+ * No special parcel contents.
+ */
@Override
public int describeContents() {
return 0;
}
+ /**
+ * Flatten this NearbyDeviceParcelable in to a Parcel.
+ *
+ * @param dest The Parcel in which the object should be written.
+ * @param flags Additional flags about how the object should be written.
+ */
+
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeInt(mName == null ? 0 : 1);
@@ -113,28 +133,53 @@
}
}
+ /**
+ * Gets the name of the NearbyDeviceParcelable. Returns {@code null} If there is no name.
+ */
+ @Nullable
public String getName() {
return mName;
}
+ /**
+ * Gets the {@link android.nearby.NearbyDevice.Medium} of the NearbyDeviceParcelable over which
+ * it is discovered.
+ */
+ @NearbyDevice.Medium
public int getMedium() {
return mMedium;
}
+ /**
+ * Gets the received signal strength in dBm.
+ */
+ @IntRange(from = -127, to = 126)
public int getRssi() {
return mRssi;
}
+ /**
+ * Gets the Fast Pair identifier. Returns {@code null} if there is no Model ID or this is not a
+ * Fast Pair device.
+ */
@Nullable
public String getFastPairModelId() {
return mFastPairModelId;
}
+ /**
+ * Gets the Bluetooth device hardware address. Returns {@code null} if the device is not
+ * discovered by Bluetooth.
+ */
@Nullable
public String getBluetoothAddress() {
return mBluetoothAddress;
}
+ /**
+ * Gets the raw data from the scanning. Returns {@code null} if there is no extra data.
+ */
+ @Nullable
public byte[] getData() {
return mData;
}
@@ -157,48 +202,67 @@
/**
* Sets the name of the scanned device.
+ *
+ * @param name The local name of the scanned device.
*/
- public Builder setName(String name) {
+ @NonNull
+ public Builder setName(@Nullable String name) {
mName = name;
return this;
}
/**
* Sets the medium over which the device is discovered.
+ *
+ * @param medium The {@link NearbyDevice.Medium} over which the device is discovered.
*/
- public Builder setMedium(int medium) {
+ @NonNull
+ public Builder setMedium(@NearbyDevice.Medium int medium) {
mMedium = medium;
return this;
}
/**
* Sets the RSSI between scanned device and the discovered device.
+ *
+ * @param rssi The received signal strength in dBm.
*/
+ @NonNull
public Builder setRssi(int rssi) {
mRssi = rssi;
return this;
}
/**
- * Sets the identifier of the device.
+ * Sets the Fast Pair model Id.
+ *
+ * @param fastPairModelId Fast Pair device identifier.
*/
- public Builder setFastPairModelId(String fastPairModelId) {
+ @NonNull
+ public Builder setFastPairModelId(@Nullable String fastPairModelId) {
mFastPairModelId = fastPairModelId;
return this;
}
/**
- * Sets the scanned Fast Pair data.
+ * Sets the bluetooth address.
+ *
+ * @param bluetoothAddress The hardware address of the bluetooth device.
*/
- public Builder setBluetoothAddress(String bluetoothAddress) {
+ @NonNull
+ public Builder setBluetoothAddress(@Nullable String bluetoothAddress) {
mBluetoothAddress = bluetoothAddress;
return this;
}
/**
- * Sets the raw data.
+ * Sets the scanned raw data.
+ *
+ * @param data Data the scan.
+ * For example, {@link ScanRecord#getServiceData()} if scanned by Bluetooth.
*/
- public Builder setData(byte[] data) {
+ @NonNull
+ public Builder setData(@Nullable byte[] data) {
mData = data;
return this;
}
@@ -206,6 +270,7 @@
/**
* Builds a ScanResult.
*/
+ @NonNull
public NearbyDeviceParcelable build() {
return new NearbyDeviceParcelable(mName, mMedium, mRssi, mFastPairModelId,
mBluetoothAddress, mData);
diff --git a/nearby/framework/java/android/nearby/NearbyFrameworkInitializer.java b/nearby/framework/java/android/nearby/NearbyFrameworkInitializer.java
new file mode 100644
index 0000000..80d1005
--- /dev/null
+++ b/nearby/framework/java/android/nearby/NearbyFrameworkInitializer.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.nearby;
+
+import android.annotation.SystemApi;
+import android.app.SystemServiceRegistry;
+import android.content.Context;
+
+/**
+ * Class for performing registration for all Nearby services.
+ *
+ * @hide
+ */
+@SystemApi
+public final class NearbyFrameworkInitializer {
+
+ private NearbyFrameworkInitializer() {}
+
+ /**
+ * Called by {@link SystemServiceRegistry}'s static initializer and registers all
+ * Nearby services to {@link Context}, so that {@link Context#getSystemService} can return them.
+ *
+ * @throws IllegalStateException if this is called from anywhere besides
+ * {@link SystemServiceRegistry}
+ */
+ public static void registerServiceWrappers() {
+ SystemServiceRegistry.registerContextAwareService(
+ Context.NEARBY_SERVICE,
+ NearbyManager.class,
+ (context, serviceBinder) -> {
+ INearbyManager service = INearbyManager.Stub.asInterface(serviceBinder);
+ return new NearbyManager(service);
+ }
+ );
+ }
+}
diff --git a/nearby/framework/java/android/nearby/NearbyManager.java b/nearby/framework/java/android/nearby/NearbyManager.java
index d8f6917..4b69e4f 100644
--- a/nearby/framework/java/android/nearby/NearbyManager.java
+++ b/nearby/framework/java/android/nearby/NearbyManager.java
@@ -19,6 +19,10 @@
import android.annotation.CallbackExecutor;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.annotation.SuppressLint;
+import android.annotation.SystemApi;
+import android.annotation.SystemService;
+import android.content.Context;
import android.os.RemoteException;
import com.android.internal.annotations.GuardedBy;
@@ -38,6 +42,8 @@
*
* @hide
*/
+@SystemApi
+@SystemService(Context.NEARBY_SERVICE)
public class NearbyManager {
private static final String TAG = "NearbyManager";
@@ -46,7 +52,12 @@
sScanListeners = new WeakHashMap<>();
private final INearbyManager mService;
- public NearbyManager(@NonNull INearbyManager service) {
+ /**
+ * Creates a new NearbyManager.
+ *
+ * @param service The service object.
+ */
+ NearbyManager(@NonNull INearbyManager service) {
mService = service;
}
@@ -69,10 +80,13 @@
* Start scan for nearby devices with given parameters. Devices matching {@link ScanRequest}
* will be delivered through the given callback.
*
+ * @param scanRequest Various parameters clients send when requesting scanning.
* @param executor Executor where the listener method is called.
+ * @param scanCallback The callback to notify clients when there is a scan result.
*/
- public void startScan(ScanRequest scanRequest, ScanCallback scanCallback, @CallbackExecutor
- Executor executor) {
+ public void startScan(@NonNull ScanRequest scanRequest,
+ @CallbackExecutor @NonNull Executor executor,
+ @NonNull ScanCallback scanCallback) {
Objects.requireNonNull(scanRequest, "scanRequest must not be null");
Objects.requireNonNull(scanCallback, "scanCallback must not be null");
Objects.requireNonNull(executor, "executor must not be null");
@@ -100,7 +114,13 @@
* Stops the nearby device scan for the specified callback. The given callback
* is guaranteed not to receive any invocations that happen after this method
* is invoked.
+ *
+ * Suppressed lint: Registration methods should have overload that accepts delivery Executor.
+ * Already have executor in startScan() method.
+ *
+ * @param scanCallback The callback that was used to start the scan.
*/
+ @SuppressLint("ExecutorRegistration")
public void stopScan(@NonNull ScanCallback scanCallback) {
Preconditions.checkArgument(scanCallback != null,
"invalid null scanCallback");
diff --git a/nearby/framework/java/android/nearby/ScanCallback.java b/nearby/framework/java/android/nearby/ScanCallback.java
index 498e672..1b1b4bc 100644
--- a/nearby/framework/java/android/nearby/ScanCallback.java
+++ b/nearby/framework/java/android/nearby/ScanCallback.java
@@ -17,6 +17,7 @@
package android.nearby;
import android.annotation.NonNull;
+import android.annotation.SystemApi;
/**
* Reports newly discovered devices.
@@ -28,13 +29,26 @@
*
* @hide
*/
+@SystemApi
public interface ScanCallback {
- /** Reports a {@link NearbyDevice} being discovered. */
+ /**
+ * Reports a {@link NearbyDevice} being discovered.
+ *
+ * @param device {@link NearbyDevice} that is found.
+ */
void onDiscovered(@NonNull NearbyDevice device);
- /** Reports a {@link NearbyDevice} information(distance, packet, and etc) changed. */
+ /**
+ * Reports a {@link NearbyDevice} information(distance, packet, and etc) changed.
+ *
+ * @param device {@link NearbyDevice} that has updates.
+ */
void onUpdated(@NonNull NearbyDevice device);
- /** Reports a {@link NearbyDevice} is no longer within range. */
+ /**
+ * Reports a {@link NearbyDevice} is no longer within range.
+ *
+ * @param device {@link NearbyDevice} that is lost.
+ */
void onLost(@NonNull NearbyDevice device);
}
diff --git a/nearby/framework/java/android/nearby/ScanRequest.java b/nearby/framework/java/android/nearby/ScanRequest.java
index c9a4072..737f574 100644
--- a/nearby/framework/java/android/nearby/ScanRequest.java
+++ b/nearby/framework/java/android/nearby/ScanRequest.java
@@ -21,6 +21,7 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
+import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.WorkSource;
@@ -36,6 +37,7 @@
*
* @hide
*/
+@SystemApi
public final class ScanRequest implements Parcelable {
/** Scan type for scanning devices using fast pair protocol. */
@@ -60,6 +62,10 @@
* results without starting BLE scans themselves.
*/
public static final int SCAN_MODE_NO_POWER = -1;
+ /**
+ * Used to read a ScanRequest from a Parcel.
+ */
+ @NonNull
public static final Creator<ScanRequest> CREATOR = new Creator<ScanRequest>() {
@Override
public ScanRequest createFromParcel(Parcel in) {
@@ -78,10 +84,10 @@
private final @ScanType int mScanType;
private final @ScanMode int mScanMode;
private final boolean mEnableBle;
- private final WorkSource mWorkSource;
+ private final @NonNull WorkSource mWorkSource;
private ScanRequest(@ScanType int scanType, @ScanMode int scanMode, boolean enableBle,
- WorkSource workSource) {
+ @NonNull WorkSource workSource) {
mScanType = scanType;
mScanMode = scanMode;
mEnableBle = enableBle;
@@ -90,7 +96,10 @@
/**
* Convert scan mode to readable string.
+ *
+ * @param scanMode Integer that may represent a{@link ScanMode}.
*/
+ @NonNull
public static String scanModeToString(@ScanMode int scanMode) {
switch (scanMode) {
case SCAN_MODE_LOW_LATENCY:
@@ -152,15 +161,23 @@
*
* @hide
*/
+ @SystemApi
+ @NonNull
public WorkSource getWorkSource() {
return mWorkSource;
}
+ /**
+ * No special parcel contents.
+ */
@Override
public int describeContents() {
return 0;
}
+ /**
+ * Returns a string representation of this ScanRequest.
+ */
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
@@ -231,7 +248,10 @@
/**
* Sets the scan type for the request. The scan type must be one of the SCAN_TYPE_ constants
* in {@link ScanRequest}.
+ *
+ * @param scanType The scan type for the request
*/
+ @NonNull
public Builder setScanType(@ScanType int scanType) {
mScanType = scanType;
return this;
@@ -240,7 +260,10 @@
/**
* Sets the scan mode for the request. The scan type must be one of the SCAN_MODE_ constants
* in {@link ScanRequest}.
+ *
+ * @param scanMode The scan mode for the request
*/
+ @NonNull
public Builder setScanMode(@ScanMode int scanMode) {
mScanMode = scanMode;
return this;
@@ -248,8 +271,10 @@
/**
* Sets if the ble is enabled for scanning.
- * in {@link ScanRequest}.
+ *
+ * @param enableBle If the BluetoothLe is enabled in the device.
*/
+ @NonNull
public Builder setEnableBle(boolean enableBle) {
mEnableBle = enableBle;
return this;
@@ -263,10 +288,12 @@
* <p>Permission enforcement occurs when the resulting scan request is used, not when
* this method is invoked.
*
+ * @param workSource identifying the application(s) for which to blame for the scan.
* @hide
*/
@RequiresPermission(Manifest.permission.UPDATE_DEVICE_STATS)
@NonNull
+ @SystemApi
public Builder setWorkSource(@Nullable WorkSource workSource) {
if (workSource == null) {
mWorkSource = new WorkSource();