diff options
author | 2024-12-18 17:59:49 +0800 | |
---|---|---|
committer | 2024-12-19 17:21:09 +0800 | |
commit | cae2c99b2d94cddeb5bae1665e864593009f3bc3 (patch) | |
tree | 8b926aac2e59fce7e7a3c06065f79d6ebf885c52 | |
parent | 619d71249d9adabc9185979cda5ab82ab0dadba4 (diff) |
[Audiosharing] Check BluetoothProperties when BT+BLE off
When BT+BLE off, audio sharing support APIs will return
ERROR_BLUETOOTH_NOT_ENABLED instead of real device capability. Read BluetoothProperties directly when BT+BLE off.
Bug: 381026000
Flag: com.android.settingslib.flags.enable_le_audio_sharing
Test: atest
Change-Id: If2f706f6919abca8611db6fd52d686b3dbb09717
-rw-r--r-- | packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java | 51 |
1 files changed, 31 insertions, 20 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java index 429e4c958f05..e91a51c321c1 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java @@ -30,6 +30,7 @@ import android.net.Uri; import android.provider.DeviceConfig; import android.provider.MediaStore; import android.provider.Settings; +import android.sysprop.BluetoothProperties; import android.text.TextUtils; import android.util.Log; import android.util.Pair; @@ -648,8 +649,10 @@ public class BluetoothUtils { /** Returns if the le audio sharing UI is available. */ public static boolean isAudioSharingUIAvailable(@Nullable Context context) { - return isAudioSharingEnabled() || (context != null && isAudioSharingPreviewEnabled( - context.getContentResolver())); + return (Flags.enableLeAudioSharing() + || (context != null && Flags.audioSharingDeveloperOption() + && getAudioSharingPreviewValue(context.getContentResolver()))) + && isAudioSharingSupported(); } /** Returns if the le audio sharing hysteresis mode fix is available. */ @@ -661,31 +664,39 @@ public class BluetoothUtils { /** Returns if the le audio sharing is enabled. */ public static boolean isAudioSharingEnabled() { - BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); - try { - return Flags.enableLeAudioSharing() - && adapter.isLeAudioBroadcastSourceSupported() - == BluetoothStatusCodes.FEATURE_SUPPORTED - && adapter.isLeAudioBroadcastAssistantSupported() - == BluetoothStatusCodes.FEATURE_SUPPORTED; - } catch (IllegalStateException e) { - Log.d(TAG, "Fail to check isAudioSharingEnabled, e = ", e); - return false; - } + return Flags.enableLeAudioSharing() && isAudioSharingSupported(); } /** Returns if the le audio sharing preview is enabled in developer option. */ public static boolean isAudioSharingPreviewEnabled(@Nullable ContentResolver contentResolver) { + return Flags.audioSharingDeveloperOption() + && getAudioSharingPreviewValue(contentResolver) + && isAudioSharingSupported(); + } + + /** Returns if the device has le audio sharing capability */ + private static boolean isAudioSharingSupported() { BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); try { - return Flags.audioSharingDeveloperOption() - && getAudioSharingPreviewValue(contentResolver) - && adapter.isLeAudioBroadcastSourceSupported() - == BluetoothStatusCodes.FEATURE_SUPPORTED - && adapter.isLeAudioBroadcastAssistantSupported() - == BluetoothStatusCodes.FEATURE_SUPPORTED; + // b/381777424 The APIs have to return ERROR_BLUETOOTH_NOT_ENABLED when BT off based on + // CDD definition. + // However, app layer need to gate the feature based on whether the device has audio + // sharing capability regardless of the BT state. + // So here we check the BluetoothProperties when BT off. + // + // TODO: Also check SystemProperties "persist.bluetooth.leaudio_dynamic_switcher.mode" + // and return true if it is in broadcast mode. + // Now SystemUI don't have access to read the value. + int sourceSupportedCode = adapter.isLeAudioBroadcastSourceSupported(); + int assistantSupportedCode = adapter.isLeAudioBroadcastAssistantSupported(); + return (sourceSupportedCode == BluetoothStatusCodes.FEATURE_SUPPORTED + || (sourceSupportedCode == BluetoothStatusCodes.ERROR_BLUETOOTH_NOT_ENABLED + && BluetoothProperties.isProfileBapBroadcastSourceEnabled().orElse(false))) + && (assistantSupportedCode == BluetoothStatusCodes.FEATURE_SUPPORTED + || (assistantSupportedCode == BluetoothStatusCodes.ERROR_BLUETOOTH_NOT_ENABLED + && BluetoothProperties.isProfileBapBroadcastAssistEnabled().orElse(false))); } catch (IllegalStateException e) { - Log.d(TAG, "Fail to check isAudioSharingPreviewEnabled, e = ", e); + Log.d(TAG, "Fail to check isAudioSharingSupported, e = ", e); return false; } } |