summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorRahul Sabnis <rahulsabnis@google.com>2020-02-25 11:33:43 -0800
committerRahul Sabnis <rahulsabnis@google.com>2020-02-25 12:03:48 -0800
commitf9e92a836f140dbc95beebaab823ea4ff68b7ec6 (patch)
tree209b5a9aa60eaa980c1bf5139f47cec59e29f165 /core/java
parenta7fdceeba2139f2b0824af8ca5d10d55b6ced398 (diff)
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. Bug: 149238030 Test: Manual Change-Id: I8add9e26afcaf1a988c15e3cc7f8c446491f0686
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/bluetooth/BluetoothHidHost.java18
-rw-r--r--core/java/android/bluetooth/BluetoothMap.java24
2 files changed, 30 insertions, 12 deletions
diff --git a/core/java/android/bluetooth/BluetoothHidHost.java b/core/java/android/bluetooth/BluetoothHidHost.java
index 26e3e271bffa..e9e1f6866908 100644
--- a/core/java/android/bluetooth/BluetoothHidHost.java
+++ b/core/java/android/bluetooth/BluetoothHidHost.java
@@ -18,7 +18,6 @@ package android.bluetooth;
import android.Manifest;
import android.annotation.NonNull;
-import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
@@ -330,6 +329,7 @@ public final class BluetoothHidHost implements BluetoothProfile {
* {@inheritDoc}
*/
@Override
+ @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
public @NonNull List<BluetoothDevice> getConnectedDevices() {
if (VDBG) log("getConnectedDevices()");
final IBluetoothHidHost service = getService();
@@ -370,8 +370,12 @@ public final class BluetoothHidHost implements BluetoothProfile {
* {@inheritDoc}
*/
@Override
- public int getConnectionState(@Nullable BluetoothDevice device) {
+ @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
+ public int getConnectionState(@NonNull BluetoothDevice device) {
if (VDBG) log("getState(" + device + ")");
+ if (device == null) {
+ throw new IllegalArgumentException("device must not be null");
+ }
final IBluetoothHidHost service = getService();
if (service != null && isEnabled() && isValidDevice(device)) {
try {
@@ -416,9 +420,12 @@ public final class BluetoothHidHost implements BluetoothProfile {
*/
@SystemApi
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
- public boolean setConnectionPolicy(@Nullable BluetoothDevice device,
+ public boolean setConnectionPolicy(@NonNull BluetoothDevice device,
@ConnectionPolicy int connectionPolicy) {
if (DBG) log("setConnectionPolicy(" + device + ", " + connectionPolicy + ")");
+ if (device == null) {
+ throw new IllegalArgumentException("device must not be null");
+ }
final IBluetoothHidHost service = getService();
if (service != null && isEnabled() && isValidDevice(device)) {
if (connectionPolicy != BluetoothProfile.CONNECTION_POLICY_FORBIDDEN
@@ -465,8 +472,11 @@ public final class BluetoothHidHost implements BluetoothProfile {
*/
@SystemApi
@RequiresPermission(Manifest.permission.BLUETOOTH)
- public @ConnectionPolicy int getConnectionPolicy(@Nullable BluetoothDevice device) {
+ public @ConnectionPolicy int getConnectionPolicy(@NonNull BluetoothDevice device) {
if (VDBG) log("getConnectionPolicy(" + device + ")");
+ if (device == null) {
+ throw new IllegalArgumentException("device must not be null");
+ }
final IBluetoothHidHost service = getService();
if (service != null && isEnabled() && isValidDevice(device)) {
try {
diff --git a/core/java/android/bluetooth/BluetoothMap.java b/core/java/android/bluetooth/BluetoothMap.java
index 1c62faa97ee6..cc2b6155a7ea 100644
--- a/core/java/android/bluetooth/BluetoothMap.java
+++ b/core/java/android/bluetooth/BluetoothMap.java
@@ -27,6 +27,7 @@ import android.content.Context;
import android.os.Binder;
import android.os.IBinder;
import android.os.RemoteException;
+import android.util.CloseGuard;
import android.util.Log;
import java.util.ArrayList;
@@ -39,12 +40,14 @@ import java.util.List;
* @hide
*/
@SystemApi
-public final class BluetoothMap implements BluetoothProfile {
+public final class BluetoothMap implements BluetoothProfile, AutoCloseable {
private static final String TAG = "BluetoothMap";
private static final boolean DBG = true;
private static final boolean VDBG = false;
+ private CloseGuard mCloseGuard;
+
/** @hide */
@SuppressLint("ActionValue")
@SystemApi
@@ -86,15 +89,16 @@ public final class BluetoothMap implements BluetoothProfile {
if (DBG) Log.d(TAG, "Create BluetoothMap proxy object");
mAdapter = BluetoothAdapter.getDefaultAdapter();
mProfileConnector.connect(context, listener);
+ mCloseGuard = new CloseGuard();
+ mCloseGuard.open("close");
}
- @SuppressLint("GenericException")
- protected void finalize() throws Throwable {
- try {
- close();
- } finally {
- super.finalize();
+ @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
+ protected void finalize() {
+ if (mCloseGuard != null) {
+ mCloseGuard.warnIfOpen();
}
+ close();
}
/**
@@ -105,7 +109,10 @@ public final class BluetoothMap implements BluetoothProfile {
*
* @hide
*/
- public synchronized void close() {
+ @SystemApi
+ @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
+ public void close() {
+ if (VDBG) log("close()");
mProfileConnector.disconnect();
}
@@ -250,6 +257,7 @@ public final class BluetoothMap implements BluetoothProfile {
* @hide
*/
@SystemApi
+ @RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
public @NonNull List<BluetoothDevice> getConnectedDevices() {
if (DBG) log("getConnectedDevices()");
final IBluetoothMap service = getService();