diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-03-19 03:09:17 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-03-19 03:09:17 +0000 |
commit | d9423c9ef8395df5effd3d4656546b70461b41d8 (patch) | |
tree | 33cd612f98167351102d54ca77d5a70f626d21ab /framework/java/android/bluetooth/BluetoothAdapter.java | |
parent | 9b52556d5cd7842ebfb13f13f3dc9ca68ae018c3 (diff) | |
parent | 1792ff8d0259a5ab5e22aba63bae2ad95db0e69f (diff) |
Snap for 8323531 from 1792ff8d0259a5ab5e22aba63bae2ad95db0e69f to tm-release
Change-Id: I09ba33f25d6f13b86f04f3a2b7019513c164cec4
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothAdapter.java')
-rw-r--r-- | framework/java/android/bluetooth/BluetoothAdapter.java | 61 |
1 files changed, 32 insertions, 29 deletions
diff --git a/framework/java/android/bluetooth/BluetoothAdapter.java b/framework/java/android/bluetooth/BluetoothAdapter.java index 58ab06dffb..53f96a60f6 100644 --- a/framework/java/android/bluetooth/BluetoothAdapter.java +++ b/framework/java/android/bluetooth/BluetoothAdapter.java @@ -748,6 +748,16 @@ public final class BluetoothAdapter { 3; //BluetoothProtoEnums.CONNECTION_STATE_DISCONNECTING; /** @hide */ + @Retention(RetentionPolicy.SOURCE) + @IntDef(prefix = { "STATE_" }, value = { + STATE_DISCONNECTED, + STATE_CONNECTING, + STATE_CONNECTED, + STATE_DISCONNECTING, + }) + public @interface ConnectionState {} + + /** @hide */ public static final String BLUETOOTH_MANAGER_SERVICE = "bluetooth_manager"; private final IBinder mToken; @@ -1541,25 +1551,8 @@ public final class BluetoothAdapter { @RequiresBluetoothConnectPermission @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public @NonNull ParcelUuid[] getUuids() { - if (getState() != STATE_ON) { - return new ParcelUuid[0]; - } - try { - mServiceLock.readLock().lock(); - if (mService != null) { - final SynchronousResultReceiver<List<ParcelUuid>> recv = - new SynchronousResultReceiver(); - mService.getUuids(mAttributionSource, recv); - List<ParcelUuid> parcels = recv.awaitResultNoInterrupt(getSyncTimeout()) - .getValue(new ArrayList<>()); - return parcels.toArray(new ParcelUuid[parcels.size()]); - } - } catch (RemoteException | TimeoutException e) { - Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); - } finally { - mServiceLock.readLock().unlock(); - } - return new ParcelUuid[0]; + List<ParcelUuid> parcels = getUuidsList(); + return parcels.toArray(new ParcelUuid[parcels.size()]); } /** @@ -1571,7 +1564,22 @@ public final class BluetoothAdapter { @SystemApi @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public @NonNull List<ParcelUuid> getUuidsList() { - return Arrays.asList(getUuids()); + List<ParcelUuid> defaultValue = new ArrayList<>(); + if (getState() != STATE_ON || mService == null) { + return defaultValue; + } + mServiceLock.readLock().lock(); + try { + final SynchronousResultReceiver<List<ParcelUuid>> recv = + new SynchronousResultReceiver(); + mService.getUuids(mAttributionSource, recv); + return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue); + } catch (RemoteException | TimeoutException e) { + Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); + } finally { + mServiceLock.readLock().unlock(); + } + return defaultValue; } /** @@ -2921,13 +2929,12 @@ public final class BluetoothAdapter { * <p> Use this function along with {@link #ACTION_CONNECTION_STATE_CHANGED} * intent to get the connection state of the adapter. * - * @return One of {@link #STATE_CONNECTED}, {@link #STATE_DISCONNECTED}, {@link - * #STATE_CONNECTING} or {@link #STATE_DISCONNECTED} + * @return the connection state * @hide */ @SystemApi @RequiresNoPermission - public int getConnectionState() { + public @ConnectionState int getConnectionState() { if (getState() != STATE_ON) { return BluetoothAdapter.STATE_DISCONNECTED; } @@ -2983,17 +2990,13 @@ public final class BluetoothAdapter { * is connected to any remote device for a specific profile. * Profile can be one of {@link BluetoothProfile#HEADSET}, {@link BluetoothProfile#A2DP}. * - * <p> Return value can be one of - * {@link BluetoothProfile#STATE_DISCONNECTED}, - * {@link BluetoothProfile#STATE_CONNECTING}, - * {@link BluetoothProfile#STATE_CONNECTED}, - * {@link BluetoothProfile#STATE_DISCONNECTING} + * <p> Return the profile connection state */ @RequiresLegacyBluetoothPermission @RequiresBluetoothConnectPermission @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) @SuppressLint("AndroidFrameworkRequiresPermission") - public int getProfileConnectionState(int profile) { + public @ConnectionState int getProfileConnectionState(int profile) { if (getState() != STATE_ON) { return BluetoothProfile.STATE_DISCONNECTED; } |