Bluetooth API: Do not allow apps to programmatically make BT discoverable.
Instead add ACTION_REQUEST_DISCOVERABLE for the system to show a dialog to adjust discoverable mode. Also remove createBond(), removeBond() and cancelBondProcess(). The Settings App already handles these automatically when connections require bonding. Change-Id: I216154cd1b6de410de64ba91b07d7263ac03e8df
This commit is contained in:
@ -25927,19 +25927,6 @@
|
|||||||
<parameter name="name" type="java.lang.String">
|
<parameter name="name" type="java.lang.String">
|
||||||
</parameter>
|
</parameter>
|
||||||
</method>
|
</method>
|
||||||
<method name="setScanMode"
|
|
||||||
return="boolean"
|
|
||||||
abstract="false"
|
|
||||||
native="false"
|
|
||||||
synchronized="false"
|
|
||||||
static="false"
|
|
||||||
final="false"
|
|
||||||
deprecated="not deprecated"
|
|
||||||
visibility="public"
|
|
||||||
>
|
|
||||||
<parameter name="mode" type="int">
|
|
||||||
</parameter>
|
|
||||||
</method>
|
|
||||||
<method name="startDiscovery"
|
<method name="startDiscovery"
|
||||||
return="boolean"
|
return="boolean"
|
||||||
abstract="false"
|
abstract="false"
|
||||||
@ -25984,6 +25971,17 @@
|
|||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
</field>
|
</field>
|
||||||
|
<field name="ACTION_REQUEST_DISCOVERABLE"
|
||||||
|
type="java.lang.String"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value=""android.bluetooth.adapter.action.REQUEST_DISCOVERABLE""
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
<field name="ACTION_SCAN_MODE_CHANGED"
|
<field name="ACTION_SCAN_MODE_CHANGED"
|
||||||
type="java.lang.String"
|
type="java.lang.String"
|
||||||
transient="false"
|
transient="false"
|
||||||
@ -26017,6 +26015,17 @@
|
|||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
</field>
|
</field>
|
||||||
|
<field name="EXTRA_DISCOVERABLE_DURATION"
|
||||||
|
type="java.lang.String"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value=""android.bluetooth.adapter.extra.DISCOVERABLE_DURATION""
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
<field name="EXTRA_LOCAL_NAME"
|
<field name="EXTRA_LOCAL_NAME"
|
||||||
type="java.lang.String"
|
type="java.lang.String"
|
||||||
transient="false"
|
transient="false"
|
||||||
@ -27063,28 +27072,6 @@
|
|||||||
>
|
>
|
||||||
<implements name="android.os.Parcelable">
|
<implements name="android.os.Parcelable">
|
||||||
</implements>
|
</implements>
|
||||||
<method name="cancelBondProcess"
|
|
||||||
return="boolean"
|
|
||||||
abstract="false"
|
|
||||||
native="false"
|
|
||||||
synchronized="false"
|
|
||||||
static="false"
|
|
||||||
final="false"
|
|
||||||
deprecated="not deprecated"
|
|
||||||
visibility="public"
|
|
||||||
>
|
|
||||||
</method>
|
|
||||||
<method name="createBond"
|
|
||||||
return="boolean"
|
|
||||||
abstract="false"
|
|
||||||
native="false"
|
|
||||||
synchronized="false"
|
|
||||||
static="false"
|
|
||||||
final="false"
|
|
||||||
deprecated="not deprecated"
|
|
||||||
visibility="public"
|
|
||||||
>
|
|
||||||
</method>
|
|
||||||
<method name="createRfcommSocket"
|
<method name="createRfcommSocket"
|
||||||
return="android.bluetooth.BluetoothSocket"
|
return="android.bluetooth.BluetoothSocket"
|
||||||
abstract="false"
|
abstract="false"
|
||||||
@ -27155,17 +27142,6 @@
|
|||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
</method>
|
</method>
|
||||||
<method name="removeBond"
|
|
||||||
return="boolean"
|
|
||||||
abstract="false"
|
|
||||||
native="false"
|
|
||||||
synchronized="false"
|
|
||||||
static="false"
|
|
||||||
final="false"
|
|
||||||
deprecated="not deprecated"
|
|
||||||
visibility="public"
|
|
||||||
>
|
|
||||||
</method>
|
|
||||||
<method name="writeToParcel"
|
<method name="writeToParcel"
|
||||||
return="void"
|
return="void"
|
||||||
abstract="false"
|
abstract="false"
|
||||||
|
@ -103,6 +103,38 @@ public final class BluetoothAdapter {
|
|||||||
*/
|
*/
|
||||||
public static final int STATE_TURNING_OFF = 13;
|
public static final int STATE_TURNING_OFF = 13;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activity Action: Show a system activity that requests discoverable mode.
|
||||||
|
* <p>Discoverable mode is equivalent to {@link
|
||||||
|
* #SCAN_MODE_CONNECTABLE_DISCOVERABLE}. It allows remote devices to see
|
||||||
|
* this Bluetooth adapter when they perform a discovery.
|
||||||
|
* <p>For privacy, Android is not by default discoverable.
|
||||||
|
* <p>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.
|
||||||
|
* <p>Notification of the result of this activity is posted using the
|
||||||
|
* {@link android.app.Activity#onActivityResult} callback. The
|
||||||
|
* <code>resultCode</code>
|
||||||
|
* will be the duration (in seconds) of discoverability, or a negative
|
||||||
|
* value if the user rejected discoverability.
|
||||||
|
* <p>Applications can also listen for {@link #ACTION_SCAN_MODE_CHANGED}
|
||||||
|
* for global notification whenever the scan mode changes.
|
||||||
|
* <p>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
|
* Broadcast Action: Indicates the Bluetooth scan mode of the local Adapter
|
||||||
* has changed.
|
* has changed.
|
||||||
@ -388,10 +420,15 @@ public final class BluetoothAdapter {
|
|||||||
* {@link #SCAN_MODE_NONE},
|
* {@link #SCAN_MODE_NONE},
|
||||||
* {@link #SCAN_MODE_CONNECTABLE},
|
* {@link #SCAN_MODE_CONNECTABLE},
|
||||||
* {@link #SCAN_MODE_CONNECTABLE_DISCOVERABLE}.
|
* {@link #SCAN_MODE_CONNECTABLE_DISCOVERABLE}.
|
||||||
* <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
|
* <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})
|
||||||
|
* </code>instead.
|
||||||
*
|
*
|
||||||
* @param mode valid scan mode
|
* @param mode valid scan mode
|
||||||
* @return true if the scan mode was set, false otherwise
|
* @return true if the scan mode was set, false otherwise
|
||||||
|
* @hide
|
||||||
*/
|
*/
|
||||||
public boolean setScanMode(int mode) {
|
public boolean setScanMode(int mode) {
|
||||||
try {
|
try {
|
||||||
|
@ -427,6 +427,7 @@ public final class BluetoothDevice implements Parcelable {
|
|||||||
* <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
|
* <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
|
||||||
*
|
*
|
||||||
* @return false on immediate error, true if bonding will begin
|
* @return false on immediate error, true if bonding will begin
|
||||||
|
* @hide
|
||||||
*/
|
*/
|
||||||
public boolean createBond() {
|
public boolean createBond() {
|
||||||
try {
|
try {
|
||||||
@ -440,6 +441,7 @@ public final class BluetoothDevice implements Parcelable {
|
|||||||
* <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
|
* <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
|
||||||
*
|
*
|
||||||
* @return true on sucess, false on error
|
* @return true on sucess, false on error
|
||||||
|
* @hide
|
||||||
*/
|
*/
|
||||||
public boolean cancelBondProcess() {
|
public boolean cancelBondProcess() {
|
||||||
try {
|
try {
|
||||||
@ -456,6 +458,7 @@ public final class BluetoothDevice implements Parcelable {
|
|||||||
* <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
|
* <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
|
||||||
*
|
*
|
||||||
* @return true on sucess, false on error
|
* @return true on sucess, false on error
|
||||||
|
* @hide
|
||||||
*/
|
*/
|
||||||
public boolean removeBond() {
|
public boolean removeBond() {
|
||||||
try {
|
try {
|
||||||
|
@ -680,8 +680,8 @@ public class BluetoothService extends IBluetooth.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean setScanMode(int mode) {
|
public synchronized boolean setScanMode(int mode) {
|
||||||
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
|
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS,
|
||||||
"Need BLUETOOTH_ADMIN permission");
|
"Need WRITE_SECURE_SETTINGS permission");
|
||||||
boolean pairable = false;
|
boolean pairable = false;
|
||||||
boolean discoverable = false;
|
boolean discoverable = false;
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
|
Reference in New Issue
Block a user