diff options
author | Rob Seymour <rseymour@google.com> | 2022-04-02 03:52:13 +0000 |
---|---|---|
committer | Rob Seymour <rseymour@google.com> | 2022-04-02 04:01:22 +0000 |
commit | 4c7dc59bef24cc991251f9a7924ceada90c6bd63 (patch) | |
tree | a90550aa3ce1bc5e002ab6444c96954deca81af0 /framework/java | |
parent | 6fa2bea006b362a285f744f65f15b5902e55797a (diff) | |
parent | dd4d23c4e1de011f8cd4eb132422172d5e283a73 (diff) |
Merge TP1A.220328.001
Change-Id: I5f07094ba2fb3991da03673f97d2957b1f68018b
Diffstat (limited to 'framework/java')
8 files changed, 141 insertions, 50 deletions
diff --git a/framework/java/android/bluetooth/BluetoothAdapter.java b/framework/java/android/bluetooth/BluetoothAdapter.java index 6b4c8062b6..c21ba6596e 100644 --- a/framework/java/android/bluetooth/BluetoothAdapter.java +++ b/framework/java/android/bluetooth/BluetoothAdapter.java @@ -1526,7 +1526,7 @@ public final class BluetoothAdapter { android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED, }) - public boolean factoryReset() { + public boolean clearBluetooth() { try { mServiceLock.readLock().lock(); if (mService != null) { @@ -1548,6 +1548,22 @@ public final class BluetoothAdapter { return false; } + /** + * See {@link #clearBluetooth()} + * + * @return true to indicate that the config file was successfully cleared + * @hide + */ + @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) + @RequiresBluetoothConnectPermission + @RequiresPermission(allOf = { + android.Manifest.permission.BLUETOOTH_CONNECT, + android.Manifest.permission.BLUETOOTH_PRIVILEGED, + }) + public boolean factoryReset() { + return clearBluetooth(); + } + /** * Get the UUIDs supported by the local Bluetooth adapter. * diff --git a/framework/java/android/bluetooth/BluetoothCodecConfig.java b/framework/java/android/bluetooth/BluetoothCodecConfig.java index 4cbf956c24..d1fb561107 100644 --- a/framework/java/android/bluetooth/BluetoothCodecConfig.java +++ b/framework/java/android/bluetooth/BluetoothCodecConfig.java @@ -566,6 +566,17 @@ public final class BluetoothCodecConfig implements Parcelable { * Returns the codec specific value1. * As the value and usage differ for each codec, please refer to the concerned * codec specification to obtain the codec specific information. + * + * <p>See section 4.3.2 of the Bluetooth A2dp specification for SBC codec specific + * information elements. + * <p>See section 4.4.2 of the Bluetooth A2dp specification for MPEG-1,2 Audio + * codec specific information elements. + * <p>See section 4.5.2 of the Bluetooth A2dp specification for MPEG-2, 4 AAC + * codec specific information elements. + * <p>See section 4.6.2 of the Bluetooth A2dp specification for ATRAC family + * codec specific information elements. + * <p>See section 4.7.2 of the Bluetooth A2dp specification for Vendor Specific A2DP + * codec specific information elements. */ public long getCodecSpecific1() { return mCodecSpecific1; @@ -575,6 +586,17 @@ public final class BluetoothCodecConfig implements Parcelable { * Returns the codec specific value2. * As the value and usage differ for each codec, please refer to the concerned * codec specification to obtain the codec specific information. + * + * <p>See section 4.3.2 of the Bluetooth A2dp specification for SBC codec specific + * information elements. + * <p>See section 4.4.2 of the Bluetooth A2dp specification for MPEG-1,2 Audio + * codec specific information elements. + * <p>See section 4.5.2 of the Bluetooth A2dp specification for MPEG-2, 4 AAC + * codec specific information elements. + * <p>See section 4.6.2 of the Bluetooth A2dp specification for ATRAC family + * codec specific information elements. + * <p>See section 4.7.2 of the Bluetooth A2dp specification for Vendor Specific A2DP + * codec specific information elements. */ public long getCodecSpecific2() { return mCodecSpecific2; @@ -584,6 +606,17 @@ public final class BluetoothCodecConfig implements Parcelable { * Returns the codec specific value3. * As the value and usage differ for each codec, please refer to the concerned * codec specification to obtain the codec specific information. + * + * <p>See section 4.3.2 of the Bluetooth A2dp specification for SBC codec specific + * information elements. + * <p>See section 4.4.2 of the Bluetooth A2dp specification for MPEG-1,2 Audio + * codec specific information elements. + * <p>See section 4.5.2 of the Bluetooth A2dp specification for MPEG-2, 4 AAC + * codec specific information elements. + * <p>See section 4.6.2 of the Bluetooth A2dp specification for ATRAC family + * codec specific information elements. + * <p>See section 4.7.2 of the Bluetooth A2dp specification for Vendor Specific A2DP + * codec specific information elements. */ public long getCodecSpecific3() { return mCodecSpecific3; @@ -593,6 +626,17 @@ public final class BluetoothCodecConfig implements Parcelable { * Returns the codec specific value4. * As the value and usage differ for each codec, please refer to the concerned * codec specification to obtain the codec specific information. + * + * <p>See section 4.3.2 of the Bluetooth A2dp specification for SBC codec specific + * information elements. + * <p>See section 4.4.2 of the Bluetooth A2dp specification for MPEG-1,2 Audio + * codec specific information elements. + * <p>See section 4.5.2 of the Bluetooth A2dp specification for MPEG-2, 4 AAC + * codec specific information elements. + * <p>See section 4.6.2 of the Bluetooth A2dp specification for ATRAC family + * codec specific information elements. + * <p>See section 4.7.2 of the Bluetooth A2dp specification for Vendor Specific A2DP + * codec specific information elements. */ public long getCodecSpecific4() { return mCodecSpecific4; diff --git a/framework/java/android/bluetooth/BluetoothDevice.java b/framework/java/android/bluetooth/BluetoothDevice.java index 5e674890b6..bf3d9697b0 100644 --- a/framework/java/android/bluetooth/BluetoothDevice.java +++ b/framework/java/android/bluetooth/BluetoothDevice.java @@ -652,7 +652,9 @@ public final class BluetoothDevice implements Parcelable, Attributable { METADATA_MAIN_LOW_BATTERY_THRESHOLD, METADATA_UNTETHERED_LEFT_LOW_BATTERY_THRESHOLD, METADATA_UNTETHERED_RIGHT_LOW_BATTERY_THRESHOLD, - METADATA_UNTETHERED_CASE_LOW_BATTERY_THRESHOLD}) + METADATA_UNTETHERED_CASE_LOW_BATTERY_THRESHOLD, + METADATA_SPATIAL_AUDIO, + METADATA_FAST_PAIR_CUSTOMIZED_FIELDS}) @Retention(RetentionPolicy.SOURCE) public @interface MetadataKey{} @@ -862,6 +864,21 @@ public final class BluetoothDevice implements Parcelable, Attributable { @SystemApi public static final int METADATA_UNTETHERED_CASE_LOW_BATTERY_THRESHOLD = 23; + + /** + * The metadata of the audio spatial data. + * Data type should be {@link Byte} array. + * @hide + */ + public static final int METADATA_SPATIAL_AUDIO = 24; + + /** + * The metadata of the Fast Pair for any custmized feature. + * Data type should be {@link Byte} array. + * @hide + */ + public static final int METADATA_FAST_PAIR_CUSTOMIZED_FIELDS = 25; + /** * Device type which is used in METADATA_DEVICE_TYPE * Indicates this Bluetooth device is a standard Bluetooth accessory or @@ -3488,7 +3505,7 @@ public final class BluetoothDevice implements Parcelable, Attributable { * @hide */ public static @MetadataKey int getMaxMetadataKey() { - return METADATA_UNTETHERED_CASE_LOW_BATTERY_THRESHOLD; + return METADATA_FAST_PAIR_CUSTOMIZED_FIELDS; } /** diff --git a/framework/java/android/bluetooth/BluetoothHapClient.java b/framework/java/android/bluetooth/BluetoothHapClient.java index dda803ef38..c05126d9c0 100644 --- a/framework/java/android/bluetooth/BluetoothHapClient.java +++ b/framework/java/android/bluetooth/BluetoothHapClient.java @@ -541,15 +541,19 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable @NonNull Callback callback) { Objects.requireNonNull(executor, "executor cannot be null"); Objects.requireNonNull(callback, "callback cannot be null"); - if (!isEnabled()) { - throw new IllegalStateException("service not enabled"); - } if (DBG) log("registerCallback"); synchronized (mCallbackExecutorMap) { // If the callback map is empty, we register the service-to-app callback if (mCallbackExecutorMap.isEmpty()) { + if (!isEnabled()) { + /* If Bluetooth is off, just store callback and it will be registered + * when Bluetooth is on + */ + mCallbackExecutorMap.put(callback, executor); + return; + } try { final IBluetoothHapClient service = getService(); if (service != null) { @@ -558,7 +562,7 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable service.registerCallback(mCallback, mAttributionSource, recv); recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null); } - } catch (IllegalStateException | TimeoutException e) { + } catch (TimeoutException e) { Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); diff --git a/framework/java/android/bluetooth/BluetoothHeadset.java b/framework/java/android/bluetooth/BluetoothHeadset.java index 9cbfe2971a..693b86608c 100644 --- a/framework/java/android/bluetooth/BluetoothHeadset.java +++ b/framework/java/android/bluetooth/BluetoothHeadset.java @@ -1001,7 +1001,6 @@ public final class BluetoothHeadset implements BluetoothProfile { @Retention(RetentionPolicy.SOURCE) @IntDef(value = { BluetoothStatusCodes.SUCCESS, - BluetoothStatusCodes.ERROR_BLUETOOTH_NOT_ENABLED, BluetoothStatusCodes.ERROR_PROFILE_SERVICE_NOT_BOUND, BluetoothStatusCodes.ERROR_TIMEOUT, BluetoothStatusCodes.ERROR_UNKNOWN, @@ -1013,7 +1012,6 @@ public final class BluetoothHeadset implements BluetoothProfile { @IntDef(value = { BluetoothStatusCodes.ALLOWED, BluetoothStatusCodes.NOT_ALLOWED, - BluetoothStatusCodes.ERROR_BLUETOOTH_NOT_ENABLED, BluetoothStatusCodes.ERROR_PROFILE_SERVICE_NOT_BOUND, BluetoothStatusCodes.ERROR_TIMEOUT, BluetoothStatusCodes.ERROR_UNKNOWN, @@ -1046,21 +1044,22 @@ public final class BluetoothHeadset implements BluetoothProfile { Log.w(TAG, "Proxy not attached to service"); if (DBG) log(Log.getStackTraceString(new Throwable())); return BluetoothStatusCodes.ERROR_PROFILE_SERVICE_NOT_BOUND; - } else if (!isEnabled()) { - return BluetoothStatusCodes.ERROR_BLUETOOTH_NOT_ENABLED; - } - try { - final SynchronousResultReceiver recv = new SynchronousResultReceiver(); - service.setAudioRouteAllowed(allowed, mAttributionSource, recv); - recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null); - return BluetoothStatusCodes.SUCCESS; - } catch (TimeoutException e) { - Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); - return BluetoothStatusCodes.ERROR_TIMEOUT; - } catch (RemoteException e) { - Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); - e.rethrowFromSystemServer(); + } else if (isEnabled()) { + try { + final SynchronousResultReceiver recv = new SynchronousResultReceiver(); + service.setAudioRouteAllowed(allowed, mAttributionSource, recv); + recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null); + return BluetoothStatusCodes.SUCCESS; + } catch (TimeoutException e) { + Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); + return BluetoothStatusCodes.ERROR_TIMEOUT; + } catch (RemoteException e) { + Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); + e.rethrowFromSystemServer(); + } } + + Log.e(TAG, "setAudioRouteAllowed: Bluetooth disabled, but profile service still bound"); return BluetoothStatusCodes.ERROR_UNKNOWN; } @@ -1085,21 +1084,22 @@ public final class BluetoothHeadset implements BluetoothProfile { Log.w(TAG, "Proxy not attached to service"); if (DBG) log(Log.getStackTraceString(new Throwable())); return BluetoothStatusCodes.ERROR_PROFILE_SERVICE_NOT_BOUND; - } else if (!isEnabled()) { - return BluetoothStatusCodes.ERROR_BLUETOOTH_NOT_ENABLED; - } - try { - final SynchronousResultReceiver<Boolean> recv = new SynchronousResultReceiver(); - service.getAudioRouteAllowed(mAttributionSource, recv); - return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(false) - ? BluetoothStatusCodes.ALLOWED : BluetoothStatusCodes.NOT_ALLOWED; - } catch (TimeoutException e) { - Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); - return BluetoothStatusCodes.ERROR_TIMEOUT; - } catch (RemoteException e) { - Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); - e.rethrowFromSystemServer(); + } else if (isEnabled()) { + try { + final SynchronousResultReceiver<Boolean> recv = new SynchronousResultReceiver(); + service.getAudioRouteAllowed(mAttributionSource, recv); + return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(false) + ? BluetoothStatusCodes.ALLOWED : BluetoothStatusCodes.NOT_ALLOWED; + } catch (TimeoutException e) { + Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); + return BluetoothStatusCodes.ERROR_TIMEOUT; + } catch (RemoteException e) { + Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); + e.rethrowFromSystemServer(); + } } + + Log.e(TAG, "getAudioRouteAllowed: Bluetooth disabled, but profile service still bound"); return BluetoothStatusCodes.ERROR_UNKNOWN; } @@ -1136,7 +1136,6 @@ public final class BluetoothHeadset implements BluetoothProfile { BluetoothStatusCodes.ERROR_UNKNOWN, BluetoothStatusCodes.ERROR_PROFILE_SERVICE_NOT_BOUND, BluetoothStatusCodes.ERROR_TIMEOUT, - BluetoothStatusCodes.ERROR_BLUETOOTH_NOT_ENABLED, BluetoothStatusCodes.ERROR_AUDIO_DEVICE_ALREADY_CONNECTED, BluetoothStatusCodes.ERROR_NO_ACTIVE_DEVICES, BluetoothStatusCodes.ERROR_NOT_ACTIVE_DEVICE, @@ -1186,9 +1185,10 @@ public final class BluetoothHeadset implements BluetoothProfile { Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); return BluetoothStatusCodes.ERROR_TIMEOUT; } - } else { - return BluetoothStatusCodes.ERROR_BLUETOOTH_NOT_ENABLED; } + + Log.e(TAG, "connectAudio: Bluetooth disabled, but profile service still bound"); + return defaultValue; } /** @hide */ @@ -1198,7 +1198,6 @@ public final class BluetoothHeadset implements BluetoothProfile { BluetoothStatusCodes.ERROR_UNKNOWN, BluetoothStatusCodes.ERROR_PROFILE_SERVICE_NOT_BOUND, BluetoothStatusCodes.ERROR_TIMEOUT, - BluetoothStatusCodes.ERROR_BLUETOOTH_NOT_ENABLED, BluetoothStatusCodes.ERROR_PROFILE_NOT_CONNECTED, BluetoothStatusCodes.ERROR_AUDIO_DEVICE_ALREADY_DISCONNECTED }) @@ -1241,9 +1240,10 @@ public final class BluetoothHeadset implements BluetoothProfile { Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); return BluetoothStatusCodes.ERROR_TIMEOUT; } - } else { - return BluetoothStatusCodes.ERROR_BLUETOOTH_NOT_ENABLED; } + + Log.e(TAG, "disconnectAudio: Bluetooth disabled, but profile service still bound"); + return defaultValue; } /** diff --git a/framework/java/android/bluetooth/BluetoothLeAudio.java b/framework/java/android/bluetooth/BluetoothLeAudio.java index 6d416434b2..9d77125271 100644 --- a/framework/java/android/bluetooth/BluetoothLeAudio.java +++ b/framework/java/android/bluetooth/BluetoothLeAudio.java @@ -960,9 +960,8 @@ public final class BluetoothLeAudio implements BluetoothProfile, AutoCloseable { service.registerCallback(mCallback, mAttributionSource, recv); recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null); } - } catch (IllegalStateException | TimeoutException e) { + } catch (TimeoutException e) { Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); - throw new IllegalStateException("Unexpected error", e); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } diff --git a/framework/java/android/bluetooth/BluetoothLeBroadcast.java b/framework/java/android/bluetooth/BluetoothLeBroadcast.java index 58f794f2d6..38a8b34a89 100644 --- a/framework/java/android/bluetooth/BluetoothLeBroadcast.java +++ b/framework/java/android/bluetooth/BluetoothLeBroadcast.java @@ -425,15 +425,19 @@ public final class BluetoothLeBroadcast implements AutoCloseable, BluetoothProfi @NonNull Callback callback) { Objects.requireNonNull(executor, "executor cannot be null"); Objects.requireNonNull(callback, "callback cannot be null"); - if (!isEnabled()) { - throw new IllegalStateException("service not enabled"); - } if (DBG) log("registerCallback"); synchronized (mCallbackExecutorMap) { // If the callback map is empty, we register the service-to-app callback if (mCallbackExecutorMap.isEmpty()) { + if (!mAdapter.isEnabled()) { + /* If Bluetooth is off, just store callback and it will be registered + * when Bluetooth is on + */ + mCallbackExecutorMap.put(callback, executor); + return; + } try { final IBluetoothLeAudio service = getService(); if (service != null) { @@ -442,7 +446,7 @@ public final class BluetoothLeBroadcast implements AutoCloseable, BluetoothProfi service.registerLeBroadcastCallback(mCallback, mAttributionSource, recv); recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null); } - } catch (TimeoutException | IllegalStateException e) { + } catch (TimeoutException e) { Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); diff --git a/framework/java/android/bluetooth/BluetoothVolumeControl.java b/framework/java/android/bluetooth/BluetoothVolumeControl.java index a359c91206..080b9a6d64 100644 --- a/framework/java/android/bluetooth/BluetoothVolumeControl.java +++ b/framework/java/android/bluetooth/BluetoothVolumeControl.java @@ -344,6 +344,13 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose synchronized (mCallbackExecutorMap) { // If the callback map is empty, we register the service-to-app callback if (mCallbackExecutorMap.isEmpty()) { + if (!mAdapter.isEnabled()) { + /* If Bluetooth is off, just store callback and it will be registered + * when Bluetooth is on + */ + mCallbackExecutorMap.put(callback, executor); + return; + } try { final IBluetoothVolumeControl service = getService(); if (service != null) { @@ -355,7 +362,7 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose } catch (RemoteException e) { Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); throw e.rethrowFromSystemServer(); - } catch (IllegalStateException | TimeoutException e) { + } catch (TimeoutException e) { Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); } } |