[Audiosharing] Change main toggle enable conditions.

Enable the toggle when:
1. In audio sharing
2. No connected LEA device. We will show dialog to guide users to
   connect a compatible device.
3. Has active device, which means it is a healthy state after broadcast
   -> unicast switch.

Flag: com.android.settingslib.flags.enable_le_audio_sharing
Test: atest
Bug: 305620450
Change-Id: I2c8067f7882df6943beb3704f63a3e1113ce55d2
This commit is contained in:
Yiyi Shen
2024-09-09 12:35:21 +08:00
parent 680df21339
commit 439873d08e
3 changed files with 76 additions and 35 deletions

View File

@@ -25,7 +25,6 @@ import android.bluetooth.BluetoothLeBroadcast;
import android.bluetooth.BluetoothLeBroadcastAssistant;
import android.bluetooth.BluetoothLeBroadcastMetadata;
import android.bluetooth.BluetoothLeBroadcastReceiveState;
import android.bluetooth.BluetoothProfile;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -377,9 +376,9 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
// FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST is always true in
// prod. We can turn off the flag for debug purpose.
if (FeatureFlagUtils.isEnabled(
mContext,
FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST)
&& mAssistant.getAllConnectedDevices().isEmpty()) {
mContext,
FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST)
&& hasEmptyConnectedSink()) {
// Pop up dialog to ask users to connect at least one lea buds before audio sharing.
AudioSharingUtils.postOnMainThread(
mContext,
@@ -435,8 +434,12 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
}
@Override
public void onActiveDeviceChanged(CachedBluetoothDevice activeDevice, int bluetoothProfile) {
if (activeDevice != null && bluetoothProfile == BluetoothProfile.LE_AUDIO) {
public void onActiveDeviceChanged(@Nullable CachedBluetoothDevice activeDevice,
int bluetoothProfile) {
if (activeDevice != null) {
Log.d(TAG, "onActiveDeviceChanged: device = "
+ activeDevice.getDevice().getAnonymizedAddress()
+ ", profile = " + bluetoothProfile);
updateSwitch();
}
}
@@ -536,13 +539,19 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
boolean isBroadcasting = BluetoothUtils.isBroadcasting(mBtManager);
boolean hasActiveDevice =
AudioSharingUtils.hasActiveConnectedLeadDevice(mBtManager);
boolean hasEmptyConnectedDevice = hasEmptyConnectedSink();
boolean isStateReady =
isBluetoothOn()
&& AudioSharingUtils.isAudioSharingProfileReady(
mProfileManager)
mProfileManager)
&& (isBroadcasting
// Always enable toggle when no connected sink. We have
// dialog to guide users to connect compatible devices
// for audio sharing.
|| hasEmptyConnectedDevice
// Disable toggle till device gets active after
// broadcast ends.
&& (isBroadcasting || hasActiveDevice);
|| hasActiveDevice);
AudioSharingUtils.postOnMainThread(
mContext,
() -> {
@@ -566,6 +575,10 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
return mBluetoothAdapter != null && mBluetoothAdapter.isEnabled();
}
private boolean hasEmptyConnectedSink() {
return mAssistant != null && mAssistant.getAllConnectedDevices().isEmpty();
}
private void handleOnBroadcastReady() {
Pair<Integer, Object>[] eventData =
AudioSharingUtils.buildAudioSharingDialogEventData(