aboutsummaryrefslogtreecommitdiff
path: root/framework/java/android/bluetooth/BluetoothAdapter.java
diff options
context:
space:
mode:
authorWilliam Escande <wescande@google.com>2021-10-04 18:04:56 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-10-04 18:04:56 +0000
commitecfd015d388bbff760e7392bcedad12aebb4ec69 (patch)
tree45d67b5c12009109021f092c5bc19f3e2e00b005 /framework/java/android/bluetooth/BluetoothAdapter.java
parent06b6324aa8910e751dd80358e81022c7c9307770 (diff)
parentf1e1df31601a49dc48b6c50184e91b367412b1d0 (diff)
Merge "Add getActiveDevices api" into stage-aosp-master am: 7371482df4 am: 5abf770470 am: 655eaa9bc2 am: f1e1df3160
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15853560 Change-Id: I7a8f49f202cce416dfe5275a19149050bc71d145
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothAdapter.java')
-rw-r--r--framework/java/android/bluetooth/BluetoothAdapter.java51
1 files changed, 51 insertions, 0 deletions
diff --git a/framework/java/android/bluetooth/BluetoothAdapter.java b/framework/java/android/bluetooth/BluetoothAdapter.java
index 9c69903d59..3b744a73e7 100644
--- a/framework/java/android/bluetooth/BluetoothAdapter.java
+++ b/framework/java/android/bluetooth/BluetoothAdapter.java
@@ -511,6 +511,12 @@ public final class BluetoothAdapter {
@SystemApi
public static final int ACTIVE_DEVICE_ALL = 2;
+ /** @hide */
+ @IntDef({BluetoothProfile.HEADSET, BluetoothProfile.A2DP,
+ BluetoothProfile.HEARING_AID})
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface ActiveDeviceProfile {}
+
/**
* Broadcast Action: The local Bluetooth adapter has started the remote
* device discovery process.
@@ -2009,6 +2015,51 @@ public final class BluetoothAdapter {
}
/**
+ * Get the active devices for the BluetoothProfile specified
+ *
+ * @param profile is the profile from which we want the active devices.
+ * Possible values are:
+ * {@link BluetoothProfile#HEADSET},
+ * {@link BluetoothProfile#A2DP},
+ * {@link BluetoothProfile#HEARING_AID}
+ * @return A list of active bluetooth devices
+ * @throws IllegalArgumentException If profile is not one of {@link ActiveDeviceProfile}
+ * @hide
+ */
+ @SystemApi
+ @RequiresPermission(allOf = {
+ android.Manifest.permission.BLUETOOTH_CONNECT,
+ android.Manifest.permission.BLUETOOTH_PRIVILEGED,
+ })
+ public @NonNull List<BluetoothDevice> getActiveDevices(@ActiveDeviceProfile int profile) {
+ if (profile != BluetoothProfile.HEADSET
+ && profile != BluetoothProfile.A2DP
+ && profile != BluetoothProfile.HEARING_AID) {
+ Log.e(TAG, "Invalid profile param value in getActiveDevices");
+ throw new IllegalArgumentException("Profiles must be one of "
+ + "BluetoothProfile.A2DP, "
+ + "BluetoothProfile.HEARING_AID, or"
+ + "BluetoothProfile.HEARING_AID");
+ }
+ try {
+ mServiceLock.readLock().lock();
+ if (mService != null) {
+ if (DBG) {
+ Log.d(TAG, "getActiveDevices(profile= "
+ + BluetoothProfile.getProfileName(profile) + ")");
+ }
+ return mService.getActiveDevices(profile, mAttributionSource);
+ }
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ } finally {
+ mServiceLock.readLock().unlock();
+ }
+
+ return new ArrayList<>();
+ }
+
+ /**
* Return true if the multi advertisement is supported by the chipset
*
* @return true if Multiple Advertisement feature is supported