summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <treehugger-gerrit@google.com> 2019-11-07 18:18:37 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2019-11-07 18:18:37 +0000
commit8ab35ca19d8db831a61c7c0c720ab42aadc7ff52 (patch)
tree4e31fd1e2b763981976e791376bae019b76eb064
parent0bc7ae70693f36f2dc3783cea5a6e137dc9db05c (diff)
parent644d3dd923358fb034fb9bcea1f09a8f384b178e (diff)
Merge "Refactor BluetoothAdapter APIs used by Settings"
-rw-r--r--api/system-current.txt4
-rw-r--r--core/java/android/bluetooth/BluetoothAdapter.java51
2 files changed, 41 insertions, 14 deletions
diff --git a/api/system-current.txt b/api/system-current.txt
index 727c92c16a42..94dc126c177e 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -1242,9 +1242,13 @@ package android.bluetooth {
method public boolean disableBLE();
method public boolean enableBLE();
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADMIN) public boolean enableNoAutoConnect();
+ method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean factoryReset();
+ method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public long getDiscoveryEndMillis();
method public boolean isBleScanAlwaysAvailable();
method public boolean isLeEnabled();
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean removeOnMetadataChangedListener(@NonNull android.bluetooth.BluetoothDevice, @NonNull android.bluetooth.BluetoothAdapter.OnMetadataChangedListener);
+ method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public boolean setScanMode(int, int);
+ method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public boolean setScanMode(int);
field public static final String ACTION_BLE_STATE_CHANGED = "android.bluetooth.adapter.action.BLE_STATE_CHANGED";
field public static final String ACTION_REQUEST_BLE_SCAN_ALWAYS_AVAILABLE = "android.bluetooth.adapter.action.REQUEST_BLE_SCAN_ALWAYS_AVAILABLE";
}
diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java
index e7ba85ad5d9e..566b38738dc1 100644
--- a/core/java/android/bluetooth/BluetoothAdapter.java
+++ b/core/java/android/bluetooth/BluetoothAdapter.java
@@ -1189,13 +1189,11 @@ public final class BluetoothAdapter {
/**
* Factory reset bluetooth settings.
*
- * <p>Requires the {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED}
- * permission
- *
* @return true to indicate that the config file was successfully cleared
* @hide
*/
- @UnsupportedAppUsage
+ @SystemApi
+ @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
public boolean factoryReset() {
try {
mServiceLock.readLock().lock();
@@ -1214,13 +1212,12 @@ public final class BluetoothAdapter {
/**
* Get the UUIDs supported by the local Bluetooth adapter.
*
- * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
- *
* @return the UUIDs supported by the local Bluetooth Adapter.
* @hide
*/
@UnsupportedAppUsage
- public ParcelUuid[] getUuids() {
+ @RequiresPermission(Manifest.permission.BLUETOOTH)
+ public @NonNull ParcelUuid[] getUuids() {
if (getState() != STATE_ON) {
return null;
}
@@ -1476,7 +1473,6 @@ public final class BluetoothAdapter {
* will return false. After turning on Bluetooth,
* wait for {@link #ACTION_STATE_CHANGED} with {@link #STATE_ON}
* to get the updated value.
- * <p>Requires {@link android.Manifest.permission#WRITE_SECURE_SETTINGS}
* <p>Applications cannot set the scan mode. They should use
* <code>startActivityForResult(
* BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE})
@@ -1488,8 +1484,8 @@ public final class BluetoothAdapter {
* @return true if the scan mode was set, false otherwise
* @hide
*/
- @UnsupportedAppUsage(publicAlternatives = "Use {@link #ACTION_REQUEST_DISCOVERABLE}, which "
- + "shows UI that confirms the user wants to go into discoverable mode.")
+ @SystemApi
+ @RequiresPermission(Manifest.permission.BLUETOOTH)
public boolean setScanMode(@ScanMode int mode, int duration) {
if (getState() != STATE_ON) {
return false;
@@ -1507,9 +1503,34 @@ public final class BluetoothAdapter {
return false;
}
- /** @hide */
- @UnsupportedAppUsage
- public boolean setScanMode(int mode) {
+ /**
+ * Set the Bluetooth scan mode of the local Bluetooth adapter.
+ * <p>The Bluetooth scan mode determines if the local adapter is
+ * connectable and/or discoverable from remote Bluetooth devices.
+ * <p>For privacy reasons, discoverable mode is automatically turned off
+ * after <code>duration</code> seconds. For example, 120 seconds should be
+ * enough for a remote device to initiate and complete its discovery
+ * process.
+ * <p>Valid scan mode values are:
+ * {@link #SCAN_MODE_NONE},
+ * {@link #SCAN_MODE_CONNECTABLE},
+ * {@link #SCAN_MODE_CONNECTABLE_DISCOVERABLE}.
+ * <p>If Bluetooth state is not {@link #STATE_ON}, this API
+ * will return false. After turning on Bluetooth,
+ * wait for {@link #ACTION_STATE_CHANGED} with {@link #STATE_ON}
+ * to get the updated value.
+ * <p>Applications cannot set the scan mode. They should use
+ * <code>startActivityForResult(
+ * BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE})
+ * </code>instead.
+ *
+ * @param mode valid scan mode
+ * @return true if the scan mode was set, false otherwise
+ * @hide
+ */
+ @SystemApi
+ @RequiresPermission(Manifest.permission.BLUETOOTH)
+ public boolean setScanMode(@ScanMode int mode) {
if (getState() != STATE_ON) {
return false;
}
@@ -1562,6 +1583,8 @@ public final class BluetoothAdapter {
* been called recently.
* @hide
*/
+ @SystemApi
+ @RequiresPermission(Manifest.permission.BLUETOOTH)
public long getDiscoveryEndMillis() {
try {
mServiceLock.readLock().lock();
@@ -2060,7 +2083,7 @@ public final class BluetoothAdapter {
* BluetoothProfile}.
* @hide
*/
- public List<Integer> getSupportedProfiles() {
+ public @NonNull List<Integer> getSupportedProfiles() {
final ArrayList<Integer> supportedProfiles = new ArrayList<Integer>();
try {