Merge "Add missing RequiresPermission annotations in BluetoothHidHost and BluetoothMap APIs, disallow null device input for setConnectionPolicy, getConnectionPolicy, and getConnectionState in BluetoothHidHost, and BluetoothMap implements AutoCloseable, its close() method is public, and utilizes a CloseGuard." am: a9e6a280f8 am: 7e3f076b2c
Change-Id: I2932905cba9dfff800e705289bca07c48898791c
This commit is contained in:
@@ -1633,15 +1633,17 @@ package android.bluetooth {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final class BluetoothHidHost implements android.bluetooth.BluetoothProfile {
|
public final class BluetoothHidHost implements android.bluetooth.BluetoothProfile {
|
||||||
method @NonNull public java.util.List<android.bluetooth.BluetoothDevice> getConnectedDevices();
|
method @NonNull @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public java.util.List<android.bluetooth.BluetoothDevice> getConnectedDevices();
|
||||||
method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public int getConnectionPolicy(@Nullable android.bluetooth.BluetoothDevice);
|
method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public int getConnectionPolicy(@NonNull android.bluetooth.BluetoothDevice);
|
||||||
method public int getConnectionState(@Nullable android.bluetooth.BluetoothDevice);
|
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public int getConnectionState(@NonNull android.bluetooth.BluetoothDevice);
|
||||||
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADMIN) public boolean setConnectionPolicy(@Nullable android.bluetooth.BluetoothDevice, int);
|
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADMIN) public boolean setConnectionPolicy(@NonNull android.bluetooth.BluetoothDevice, int);
|
||||||
field public static final String ACTION_CONNECTION_STATE_CHANGED = "android.bluetooth.input.profile.action.CONNECTION_STATE_CHANGED";
|
field public static final String ACTION_CONNECTION_STATE_CHANGED = "android.bluetooth.input.profile.action.CONNECTION_STATE_CHANGED";
|
||||||
}
|
}
|
||||||
|
|
||||||
public final class BluetoothMap implements android.bluetooth.BluetoothProfile {
|
public final class BluetoothMap implements java.lang.AutoCloseable android.bluetooth.BluetoothProfile {
|
||||||
method @NonNull public java.util.List<android.bluetooth.BluetoothDevice> getConnectedDevices();
|
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public void close();
|
||||||
|
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) protected void finalize();
|
||||||
|
method @NonNull @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public java.util.List<android.bluetooth.BluetoothDevice> getConnectedDevices();
|
||||||
method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public int getConnectionPolicy(@Nullable android.bluetooth.BluetoothDevice);
|
method @RequiresPermission(android.Manifest.permission.BLUETOOTH) public int getConnectionPolicy(@Nullable android.bluetooth.BluetoothDevice);
|
||||||
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADMIN) public boolean setConnectionPolicy(@Nullable android.bluetooth.BluetoothDevice, int);
|
method @RequiresPermission(android.Manifest.permission.BLUETOOTH_ADMIN) public boolean setConnectionPolicy(@Nullable android.bluetooth.BluetoothDevice, int);
|
||||||
field public static final String ACTION_CONNECTION_STATE_CHANGED = "android.bluetooth.map.profile.action.CONNECTION_STATE_CHANGED";
|
field public static final String ACTION_CONNECTION_STATE_CHANGED = "android.bluetooth.map.profile.action.CONNECTION_STATE_CHANGED";
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ package android.bluetooth;
|
|||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
|
||||||
import android.annotation.RequiresPermission;
|
import android.annotation.RequiresPermission;
|
||||||
import android.annotation.SdkConstant;
|
import android.annotation.SdkConstant;
|
||||||
import android.annotation.SdkConstant.SdkConstantType;
|
import android.annotation.SdkConstant.SdkConstantType;
|
||||||
@@ -330,6 +329,7 @@ public final class BluetoothHidHost implements BluetoothProfile {
|
|||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
|
||||||
public @NonNull List<BluetoothDevice> getConnectedDevices() {
|
public @NonNull List<BluetoothDevice> getConnectedDevices() {
|
||||||
if (VDBG) log("getConnectedDevices()");
|
if (VDBG) log("getConnectedDevices()");
|
||||||
final IBluetoothHidHost service = getService();
|
final IBluetoothHidHost service = getService();
|
||||||
@@ -370,8 +370,12 @@ public final class BluetoothHidHost implements BluetoothProfile {
|
|||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getConnectionState(@Nullable BluetoothDevice device) {
|
@RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
|
||||||
|
public int getConnectionState(@NonNull BluetoothDevice device) {
|
||||||
if (VDBG) log("getState(" + device + ")");
|
if (VDBG) log("getState(" + device + ")");
|
||||||
|
if (device == null) {
|
||||||
|
throw new IllegalArgumentException("device must not be null");
|
||||||
|
}
|
||||||
final IBluetoothHidHost service = getService();
|
final IBluetoothHidHost service = getService();
|
||||||
if (service != null && isEnabled() && isValidDevice(device)) {
|
if (service != null && isEnabled() && isValidDevice(device)) {
|
||||||
try {
|
try {
|
||||||
@@ -416,9 +420,12 @@ public final class BluetoothHidHost implements BluetoothProfile {
|
|||||||
*/
|
*/
|
||||||
@SystemApi
|
@SystemApi
|
||||||
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
|
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
|
||||||
public boolean setConnectionPolicy(@Nullable BluetoothDevice device,
|
public boolean setConnectionPolicy(@NonNull BluetoothDevice device,
|
||||||
@ConnectionPolicy int connectionPolicy) {
|
@ConnectionPolicy int connectionPolicy) {
|
||||||
if (DBG) log("setConnectionPolicy(" + device + ", " + connectionPolicy + ")");
|
if (DBG) log("setConnectionPolicy(" + device + ", " + connectionPolicy + ")");
|
||||||
|
if (device == null) {
|
||||||
|
throw new IllegalArgumentException("device must not be null");
|
||||||
|
}
|
||||||
final IBluetoothHidHost service = getService();
|
final IBluetoothHidHost service = getService();
|
||||||
if (service != null && isEnabled() && isValidDevice(device)) {
|
if (service != null && isEnabled() && isValidDevice(device)) {
|
||||||
if (connectionPolicy != BluetoothProfile.CONNECTION_POLICY_FORBIDDEN
|
if (connectionPolicy != BluetoothProfile.CONNECTION_POLICY_FORBIDDEN
|
||||||
@@ -465,8 +472,11 @@ public final class BluetoothHidHost implements BluetoothProfile {
|
|||||||
*/
|
*/
|
||||||
@SystemApi
|
@SystemApi
|
||||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||||
public @ConnectionPolicy int getConnectionPolicy(@Nullable BluetoothDevice device) {
|
public @ConnectionPolicy int getConnectionPolicy(@NonNull BluetoothDevice device) {
|
||||||
if (VDBG) log("getConnectionPolicy(" + device + ")");
|
if (VDBG) log("getConnectionPolicy(" + device + ")");
|
||||||
|
if (device == null) {
|
||||||
|
throw new IllegalArgumentException("device must not be null");
|
||||||
|
}
|
||||||
final IBluetoothHidHost service = getService();
|
final IBluetoothHidHost service = getService();
|
||||||
if (service != null && isEnabled() && isValidDevice(device)) {
|
if (service != null && isEnabled() && isValidDevice(device)) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import android.content.Context;
|
|||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
import android.util.CloseGuard;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -39,12 +40,14 @@ import java.util.List;
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@SystemApi
|
@SystemApi
|
||||||
public final class BluetoothMap implements BluetoothProfile {
|
public final class BluetoothMap implements BluetoothProfile, AutoCloseable {
|
||||||
|
|
||||||
private static final String TAG = "BluetoothMap";
|
private static final String TAG = "BluetoothMap";
|
||||||
private static final boolean DBG = true;
|
private static final boolean DBG = true;
|
||||||
private static final boolean VDBG = false;
|
private static final boolean VDBG = false;
|
||||||
|
|
||||||
|
private CloseGuard mCloseGuard;
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@SuppressLint("ActionValue")
|
@SuppressLint("ActionValue")
|
||||||
@SystemApi
|
@SystemApi
|
||||||
@@ -86,15 +89,16 @@ public final class BluetoothMap implements BluetoothProfile {
|
|||||||
if (DBG) Log.d(TAG, "Create BluetoothMap proxy object");
|
if (DBG) Log.d(TAG, "Create BluetoothMap proxy object");
|
||||||
mAdapter = BluetoothAdapter.getDefaultAdapter();
|
mAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
mProfileConnector.connect(context, listener);
|
mProfileConnector.connect(context, listener);
|
||||||
|
mCloseGuard = new CloseGuard();
|
||||||
|
mCloseGuard.open("close");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("GenericException")
|
@RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
|
||||||
protected void finalize() throws Throwable {
|
protected void finalize() {
|
||||||
try {
|
if (mCloseGuard != null) {
|
||||||
close();
|
mCloseGuard.warnIfOpen();
|
||||||
} finally {
|
|
||||||
super.finalize();
|
|
||||||
}
|
}
|
||||||
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,7 +109,10 @@ public final class BluetoothMap implements BluetoothProfile {
|
|||||||
*
|
*
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public synchronized void close() {
|
@SystemApi
|
||||||
|
@RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
|
||||||
|
public void close() {
|
||||||
|
if (VDBG) log("close()");
|
||||||
mProfileConnector.disconnect();
|
mProfileConnector.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,6 +257,7 @@ public final class BluetoothMap implements BluetoothProfile {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@SystemApi
|
@SystemApi
|
||||||
|
@RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
|
||||||
public @NonNull List<BluetoothDevice> getConnectedDevices() {
|
public @NonNull List<BluetoothDevice> getConnectedDevices() {
|
||||||
if (DBG) log("getConnectedDevices()");
|
if (DBG) log("getConnectedDevices()");
|
||||||
final IBluetoothMap service = getService();
|
final IBluetoothMap service = getService();
|
||||||
|
|||||||
Reference in New Issue
Block a user