For privacy, Android is not by default discoverable. + *
The sender can optionally use extra field {@link + * #EXTRA_DISCOVERABLE_DURATION} to request the duration of + * discoverability. Currently the default duration is 120 seconds, and + * maximum duration is capped at 300 seconds for each request. + *
Notification of the result of this activity is posted using the
+ * {@link android.app.Activity#onActivityResult} callback. The
+ * resultCode
+ * will be the duration (in seconds) of discoverability, or a negative
+ * value if the user rejected discoverability.
+ *
Applications can also listen for {@link #ACTION_SCAN_MODE_CHANGED} + * for global notification whenever the scan mode changes. + *
Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} + */ + @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) + public static final String ACTION_REQUEST_DISCOVERABLE = + "android.bluetooth.adapter.action.REQUEST_DISCOVERABLE"; + + /** + * Used as an optional int extra field in {@link + * #ACTION_REQUEST_DISCOVERABLE} intents to request a specific duration + * for discoverability in seconds. The current default is 120 seconds, and + * requests over 300 seconds will be capped. These values could change. + */ + public static final String EXTRA_DISCOVERABLE_DURATION = + "android.bluetooth.adapter.extra.DISCOVERABLE_DURATION"; + /** * Broadcast Action: Indicates the Bluetooth scan mode of the local Adapter * has changed. @@ -388,10 +420,15 @@ public final class BluetoothAdapter { * {@link #SCAN_MODE_NONE}, * {@link #SCAN_MODE_CONNECTABLE}, * {@link #SCAN_MODE_CONNECTABLE_DISCOVERABLE}. - *
Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} + *
Requires {@link android.Manifest.permission#WRITE_SECURE_SETTINGS} + *
Applications cannot set the scan mode. They should use
+ * startActivityForResult(
+ * BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE})
+ * instead.
*
* @param mode valid scan mode
* @return true if the scan mode was set, false otherwise
+ * @hide
*/
public boolean setScanMode(int mode) {
try {
diff --git a/core/java/android/bluetooth/BluetoothDevice.java b/core/java/android/bluetooth/BluetoothDevice.java
index b52a82260aae2..c714f692a1c36 100644
--- a/core/java/android/bluetooth/BluetoothDevice.java
+++ b/core/java/android/bluetooth/BluetoothDevice.java
@@ -427,6 +427,7 @@ public final class BluetoothDevice implements Parcelable {
*
Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. * * @return false on immediate error, true if bonding will begin + * @hide */ public boolean createBond() { try { @@ -440,6 +441,7 @@ public final class BluetoothDevice implements Parcelable { *
Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. * * @return true on sucess, false on error + * @hide */ public boolean cancelBondProcess() { try { @@ -456,6 +458,7 @@ public final class BluetoothDevice implements Parcelable { *
Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}. * * @return true on sucess, false on error + * @hide */ public boolean removeBond() { try { diff --git a/core/java/android/server/BluetoothService.java b/core/java/android/server/BluetoothService.java index e5b20bdef6cfe..de14b5b4e0bb5 100644 --- a/core/java/android/server/BluetoothService.java +++ b/core/java/android/server/BluetoothService.java @@ -680,8 +680,8 @@ public class BluetoothService extends IBluetooth.Stub { } public synchronized boolean setScanMode(int mode) { - mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, - "Need BLUETOOTH_ADMIN permission"); + mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS, + "Need WRITE_SECURE_SETTINGS permission"); boolean pairable = false; boolean discoverable = false; switch (mode) {