Merge "Add bluetooth permission annotations" into mnc-dev
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package android.bluetooth;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.RequiresPermission;
|
||||
import android.annotation.SdkConstant;
|
||||
import android.annotation.SdkConstant.SdkConstantType;
|
||||
import android.content.ComponentName;
|
||||
@@ -380,6 +382,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
|
||||
* @return priority of the device
|
||||
* @hide
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||
public int getPriority(BluetoothDevice device) {
|
||||
if (VDBG) log("getPriority(" + device + ")");
|
||||
if (mService != null && isEnabled()
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
|
||||
package android.bluetooth;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.IntDef;
|
||||
import android.annotation.RequiresPermission;
|
||||
import android.annotation.SdkConstant;
|
||||
import android.annotation.SdkConstant.SdkConstantType;
|
||||
import android.annotation.SystemApi;
|
||||
@@ -37,6 +40,8 @@ import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -133,6 +138,12 @@ public final class BluetoothAdapter {
|
||||
public static final String EXTRA_PREVIOUS_STATE =
|
||||
"android.bluetooth.adapter.extra.PREVIOUS_STATE";
|
||||
|
||||
/** @hide */
|
||||
@IntDef({STATE_OFF, STATE_TURNING_ON, STATE_ON, STATE_TURNING_OFF, STATE_BLE_TURNING_ON,
|
||||
STATE_BLE_ON, STATE_BLE_TURNING_OFF})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface AdapterState {}
|
||||
|
||||
/**
|
||||
* Indicates the local Bluetooth adapter is off.
|
||||
*/
|
||||
@@ -273,6 +284,11 @@ public final class BluetoothAdapter {
|
||||
public static final String EXTRA_PREVIOUS_SCAN_MODE =
|
||||
"android.bluetooth.adapter.extra.PREVIOUS_SCAN_MODE";
|
||||
|
||||
/** @hide */
|
||||
@IntDef({SCAN_MODE_NONE, SCAN_MODE_CONNECTABLE, SCAN_MODE_CONNECTABLE_DISCOVERABLE})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface ScanMode {}
|
||||
|
||||
/**
|
||||
* Indicates that both inquiry scan and page scan are disabled on the local
|
||||
* Bluetooth adapter. Therefore this device is neither discoverable
|
||||
@@ -578,6 +594,7 @@ public final class BluetoothAdapter {
|
||||
*
|
||||
* @return true if the local adapter is turned on
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||
public boolean isEnabled() {
|
||||
try {
|
||||
synchronized(mManagerCallback) {
|
||||
@@ -752,6 +769,8 @@ public final class BluetoothAdapter {
|
||||
*
|
||||
* @return current state of Bluetooth adapter
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||
@AdapterState
|
||||
public int getState() {
|
||||
try {
|
||||
synchronized(mManagerCallback) {
|
||||
@@ -792,6 +811,8 @@ public final class BluetoothAdapter {
|
||||
* @return current state of Bluetooth adapter
|
||||
* @hide
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||
@AdapterState
|
||||
public int getLeState() {
|
||||
try {
|
||||
synchronized(mManagerCallback) {
|
||||
@@ -845,6 +866,7 @@ public final class BluetoothAdapter {
|
||||
* @return true to indicate adapter startup has begun, or false on
|
||||
* immediate error
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
|
||||
public boolean enable() {
|
||||
int state = STATE_OFF;
|
||||
if (isEnabled() == true){
|
||||
@@ -893,6 +915,7 @@ public final class BluetoothAdapter {
|
||||
* @return true to indicate adapter shutdown has begun, or false on
|
||||
* immediate error
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
|
||||
public boolean disable() {
|
||||
try {
|
||||
return mManagerService.disable(true);
|
||||
@@ -925,6 +948,7 @@ public final class BluetoothAdapter {
|
||||
*
|
||||
* @return Bluetooth hardware address as string
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||
public String getAddress() {
|
||||
try {
|
||||
return mManagerService.getAddress();
|
||||
@@ -998,6 +1022,7 @@ public final class BluetoothAdapter {
|
||||
* @param name a valid Bluetooth name
|
||||
* @return true if the name was set, false otherwise
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
|
||||
public boolean setName(String name) {
|
||||
if (getState() != STATE_ON) return false;
|
||||
try {
|
||||
@@ -1024,6 +1049,8 @@ public final class BluetoothAdapter {
|
||||
*
|
||||
* @return scan mode
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||
@ScanMode
|
||||
public int getScanMode() {
|
||||
if (getState() != STATE_ON) return SCAN_MODE_NONE;
|
||||
try {
|
||||
@@ -1062,7 +1089,7 @@ public final class BluetoothAdapter {
|
||||
* @return true if the scan mode was set, false otherwise
|
||||
* @hide
|
||||
*/
|
||||
public boolean setScanMode(int mode, int duration) {
|
||||
public boolean setScanMode(@ScanMode int mode, int duration) {
|
||||
if (getState() != STATE_ON) return false;
|
||||
try {
|
||||
synchronized(mManagerCallback) {
|
||||
@@ -1130,6 +1157,7 @@ public final class BluetoothAdapter {
|
||||
*
|
||||
* @return true on success, false on error
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
|
||||
public boolean startDiscovery() {
|
||||
if (getState() != STATE_ON) return false;
|
||||
try {
|
||||
@@ -1157,6 +1185,7 @@ public final class BluetoothAdapter {
|
||||
*
|
||||
* @return true on success, false on error
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
|
||||
public boolean cancelDiscovery() {
|
||||
if (getState() != STATE_ON) return false;
|
||||
try {
|
||||
@@ -1186,6 +1215,7 @@ public final class BluetoothAdapter {
|
||||
*
|
||||
* @return true if discovering
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||
public boolean isDiscovering() {
|
||||
if (getState() != STATE_ON) return false;
|
||||
try {
|
||||
@@ -1345,6 +1375,7 @@ public final class BluetoothAdapter {
|
||||
*
|
||||
* @return unmodifiable set of {@link BluetoothDevice}, or null on error
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||
public Set<BluetoothDevice> getBondedDevices() {
|
||||
if (getState() != STATE_ON) {
|
||||
return toDeviceSet(new BluetoothDevice[0]);
|
||||
@@ -1396,6 +1427,7 @@ public final class BluetoothAdapter {
|
||||
* {@link BluetoothProfile#STATE_CONNECTED},
|
||||
* {@link BluetoothProfile#STATE_DISCONNECTING}
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||
public int getProfileConnectionState(int profile) {
|
||||
if (getState() != STATE_ON) return BluetoothProfile.STATE_DISCONNECTED;
|
||||
try {
|
||||
@@ -1460,6 +1492,7 @@ public final class BluetoothAdapter {
|
||||
* @throws IOException on error, for example Bluetooth not available, or
|
||||
* insufficient permissions, or channel in use.
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||
public BluetoothServerSocket listenUsingRfcommWithServiceRecord(String name, UUID uuid)
|
||||
throws IOException {
|
||||
return createNewRfcommSocketAndRecord(name, uuid, true, true);
|
||||
@@ -1491,6 +1524,7 @@ public final class BluetoothAdapter {
|
||||
* @throws IOException on error, for example Bluetooth not available, or
|
||||
* insufficient permissions, or channel in use.
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||
public BluetoothServerSocket listenUsingInsecureRfcommWithServiceRecord(String name, UUID uuid)
|
||||
throws IOException {
|
||||
return createNewRfcommSocketAndRecord(name, uuid, false, false);
|
||||
@@ -2032,6 +2066,7 @@ public final class BluetoothAdapter {
|
||||
* instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
|
||||
public boolean startLeScan(LeScanCallback callback) {
|
||||
return startLeScan(null, callback);
|
||||
}
|
||||
@@ -2052,6 +2087,7 @@ public final class BluetoothAdapter {
|
||||
* instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
|
||||
public boolean startLeScan(final UUID[] serviceUuids, final LeScanCallback callback) {
|
||||
if (DBG) Log.d(TAG, "startLeScan(): " + serviceUuids);
|
||||
if (callback == null) {
|
||||
@@ -2138,6 +2174,7 @@ public final class BluetoothAdapter {
|
||||
* @deprecated Use {@link BluetoothLeScanner#stopScan(ScanCallback)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
|
||||
public void stopLeScan(LeScanCallback callback) {
|
||||
if (DBG) Log.d(TAG, "stopLeScan()");
|
||||
BluetoothLeScanner scanner = getBluetoothLeScanner();
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package android.bluetooth;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.RequiresPermission;
|
||||
import android.annotation.SdkConstant;
|
||||
import android.annotation.SdkConstant.SdkConstantType;
|
||||
import android.annotation.SystemApi;
|
||||
@@ -709,6 +711,7 @@ public final class BluetoothDevice implements Parcelable {
|
||||
*
|
||||
* @return the Bluetooth name, or null if there was a problem.
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||
public String getName() {
|
||||
if (sService == null) {
|
||||
Log.e(TAG, "BT not enabled. Cannot get Remote Device name");
|
||||
@@ -729,6 +732,7 @@ public final class BluetoothDevice implements Parcelable {
|
||||
* {@link #DEVICE_TYPE_DUAL}.
|
||||
* {@link #DEVICE_TYPE_UNKNOWN} if it's not available
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||
public int getType() {
|
||||
if (sService == null) {
|
||||
Log.e(TAG, "BT not enabled. Cannot get Remote Device type");
|
||||
@@ -807,6 +811,7 @@ public final class BluetoothDevice implements Parcelable {
|
||||
*
|
||||
* @return false on immediate error, true if bonding will begin
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
|
||||
public boolean createBond() {
|
||||
if (sService == null) {
|
||||
Log.e(TAG, "BT not enabled. Cannot create bond to Remote Device");
|
||||
@@ -948,6 +953,7 @@ public final class BluetoothDevice implements Parcelable {
|
||||
*
|
||||
* @return the bond state
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||
public int getBondState() {
|
||||
if (sService == null) {
|
||||
Log.e(TAG, "BT not enabled. Cannot get bond state");
|
||||
@@ -1014,6 +1020,7 @@ public final class BluetoothDevice implements Parcelable {
|
||||
*
|
||||
* @return Bluetooth class object, or null on error
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||
public BluetoothClass getBluetoothClass() {
|
||||
if (sService == null) {
|
||||
Log.e(TAG, "BT not enabled. Cannot get Bluetooth Class");
|
||||
@@ -1039,6 +1046,7 @@ public final class BluetoothDevice implements Parcelable {
|
||||
* @return the supported features (UUIDs) of the remote device,
|
||||
* or null on error
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||
public ParcelUuid[] getUuids() {
|
||||
if (sService == null || isBluetoothEnabled() == false) {
|
||||
Log.e(TAG, "BT not enabled. Cannot get remote device Uuids");
|
||||
@@ -1065,6 +1073,7 @@ public final class BluetoothDevice implements Parcelable {
|
||||
* of initiating an ACL connection to the remote device
|
||||
* was started.
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||
public boolean fetchUuidsWithSdp() {
|
||||
IBluetooth service = sService;
|
||||
if (service == null || isBluetoothEnabled() == false) {
|
||||
@@ -1144,6 +1153,7 @@ public final class BluetoothDevice implements Parcelable {
|
||||
* @return true confirmation has been sent out
|
||||
* false for error
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
|
||||
public boolean setPairingConfirmation(boolean confirm) {
|
||||
if (sService == null) {
|
||||
Log.e(TAG, "BT not enabled. Cannot set pairing confirmation");
|
||||
@@ -1405,6 +1415,7 @@ public final class BluetoothDevice implements Parcelable {
|
||||
* @throws IOException on error, for example Bluetooth not available, or
|
||||
* insufficient permissions
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||
public BluetoothSocket createRfcommSocketToServiceRecord(UUID uuid) throws IOException {
|
||||
if (isBluetoothEnabled() == false) {
|
||||
Log.e(TAG, "Bluetooth is not enabled");
|
||||
@@ -1443,6 +1454,7 @@ public final class BluetoothDevice implements Parcelable {
|
||||
* @throws IOException on error, for example Bluetooth not available, or
|
||||
* insufficient permissions
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||
public BluetoothSocket createInsecureRfcommSocketToServiceRecord(UUID uuid) throws IOException {
|
||||
if (isBluetoothEnabled() == false) {
|
||||
Log.e(TAG, "Bluetooth is not enabled");
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package android.bluetooth;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.RequiresPermission;
|
||||
import android.content.Context;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
@@ -89,6 +91,7 @@ public final class BluetoothManager {
|
||||
* {@link BluetoothProfile#STATE_DISCONNECTED},
|
||||
* {@link BluetoothProfile#STATE_DISCONNECTING}
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||
public int getConnectionState(BluetoothDevice device, int profile) {
|
||||
if (DBG) Log.d(TAG,"getConnectionState()");
|
||||
|
||||
@@ -117,6 +120,7 @@ public final class BluetoothManager {
|
||||
* @param profile GATT or GATT_SERVER
|
||||
* @return List of devices. The list will be empty on error.
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||
public List<BluetoothDevice> getConnectedDevices(int profile) {
|
||||
if (DBG) Log.d(TAG,"getConnectedDevices");
|
||||
if (profile != BluetoothProfile.GATT && profile != BluetoothProfile.GATT_SERVER) {
|
||||
@@ -161,6 +165,7 @@ public final class BluetoothManager {
|
||||
* {@link BluetoothProfile#STATE_DISCONNECTING},
|
||||
* @return List of devices. The list will be empty on error.
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||
public List<BluetoothDevice> getDevicesMatchingConnectionStates(int profile, int[] states) {
|
||||
if (DBG) Log.d(TAG,"getDevicesMatchingConnectionStates");
|
||||
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
|
||||
package android.bluetooth;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.RequiresPermission;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -163,6 +166,7 @@ public interface BluetoothProfile {
|
||||
*
|
||||
* @return List of devices. The list will be empty on error.
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||
public List<BluetoothDevice> getConnectedDevices();
|
||||
|
||||
/**
|
||||
@@ -179,6 +183,7 @@ public interface BluetoothProfile {
|
||||
* {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING},
|
||||
* @return List of devices. The list will be empty on error.
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||
public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states);
|
||||
|
||||
/**
|
||||
@@ -191,6 +196,7 @@ public interface BluetoothProfile {
|
||||
* {@link #STATE_CONNECTED}, {@link #STATE_CONNECTING},
|
||||
* {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING}
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||
public int getConnectionState(BluetoothDevice device);
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package android.bluetooth.le;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.RequiresPermission;
|
||||
import android.annotation.SystemApi;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
@@ -80,6 +82,7 @@ public final class BluetoothLeScanner {
|
||||
* @param callback Callback used to deliver scan results.
|
||||
* @throws IllegalArgumentException If {@code callback} is null.
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
|
||||
public void startScan(final ScanCallback callback) {
|
||||
if (callback == null) {
|
||||
throw new IllegalArgumentException("callback is null");
|
||||
@@ -97,6 +100,7 @@ public final class BluetoothLeScanner {
|
||||
* @param callback Callback used to deliver scan results.
|
||||
* @throws IllegalArgumentException If {@code settings} or {@code callback} is null.
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
|
||||
public void startScan(List<ScanFilter> filters, ScanSettings settings,
|
||||
final ScanCallback callback) {
|
||||
startScan(filters, settings, callback, null);
|
||||
@@ -151,6 +155,7 @@ public final class BluetoothLeScanner {
|
||||
*
|
||||
* @param callback
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
|
||||
public void stopScan(ScanCallback callback) {
|
||||
BluetoothLeUtils.checkAdapterStateOn(mBluetoothAdapter);
|
||||
synchronized (mLeScanClients) {
|
||||
|
||||
Reference in New Issue
Block a user