diff options
author | Rahul Sabnis <rahulsabnis@google.com> | 2020-02-25 11:33:43 -0800 |
---|---|---|
committer | Rahul Sabnis <rahulsabnis@google.com> | 2020-03-02 19:13:19 +0000 |
commit | d87b6b0457b2b31f682623c28f289404ed349281 (patch) | |
tree | 6e080c67f34c57c3df70c92a0e1934c7033c387a /framework/java/android/bluetooth/BluetoothMap.java | |
parent | c3389265edab7bf009a17e30fcd4069d06bd1230 (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
Merged-In: I8add9e26afcaf1a988c15e3cc7f8c446491f0686
Change-Id: I8add9e26afcaf1a988c15e3cc7f8c446491f0686
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothMap.java')
-rw-r--r-- | framework/java/android/bluetooth/BluetoothMap.java | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/framework/java/android/bluetooth/BluetoothMap.java b/framework/java/android/bluetooth/BluetoothMap.java index 1c62faa97e..cc2b6155a7 100644 --- a/framework/java/android/bluetooth/BluetoothMap.java +++ b/framework/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(); |