[Audiosharing] Fix hysteresis mode
1. Move start broadcast logic from onPlaybackStarted to onBroadcastMetadataChanged 2. Move add source logic from onReceiveStateChanged(BIS>0) to onSourceAdded Test: atest Bug: 355222285 Bug: 377658982 Flag: com.android.settingslib.flags.audio_sharing_hysteresis_mode_fix Change-Id: Ie0a2345e16caa2804fede930d174a67f2ec60259
This commit is contained in:
@@ -177,6 +177,20 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
||||
+ broadcastId
|
||||
+ ", metadata = "
|
||||
+ metadata.getBroadcastName());
|
||||
if (mAssistant == null
|
||||
|| mAssistant.getAllConnectedDevices().stream()
|
||||
.anyMatch(
|
||||
device -> BluetoothUtils
|
||||
.hasActiveLocalBroadcastSourceForBtDevice(
|
||||
device, mBtManager))) {
|
||||
Log.d(
|
||||
TAG,
|
||||
"Skip handleOnBroadcastReady: null assistant or "
|
||||
+ "sink has active local source.");
|
||||
cleanUpStatesForStartSharing();
|
||||
return;
|
||||
}
|
||||
handleOnBroadcastReady();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -221,20 +235,6 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
||||
+ reason
|
||||
+ ", broadcastId = "
|
||||
+ broadcastId);
|
||||
if (mAssistant == null
|
||||
|| mAssistant.getAllConnectedDevices().stream()
|
||||
.anyMatch(
|
||||
device -> BluetoothUtils
|
||||
.hasActiveLocalBroadcastSourceForBtDevice(
|
||||
device, mBtManager))) {
|
||||
Log.d(
|
||||
TAG,
|
||||
"Skip handleOnBroadcastReady: null assistant or "
|
||||
+ "sink has active local source.");
|
||||
cleanUpStatesForStartSharing();
|
||||
return;
|
||||
}
|
||||
handleOnBroadcastReady();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -261,7 +261,30 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
||||
|
||||
@Override
|
||||
public void onSourceAdded(
|
||||
@NonNull BluetoothDevice sink, int sourceId, int reason) {}
|
||||
@NonNull BluetoothDevice sink, int sourceId, int reason) {
|
||||
if (mSinksInAdding.contains(sink)) {
|
||||
mSinksInAdding.remove(sink);
|
||||
}
|
||||
dismissProgressDialogIfNeeded();
|
||||
Log.d(TAG, "onSourceAdded(), sink = " + sink + ", remaining sinks = "
|
||||
+ mSinksInAdding);
|
||||
if (mSinksToWaitFor.contains(sink)) {
|
||||
mSinksToWaitFor.remove(sink);
|
||||
if (mSinksToWaitFor.isEmpty()) {
|
||||
// To avoid users advance to share then pair flow before the
|
||||
// primary/active sinks successfully join the audio sharing,
|
||||
// popup dialog till adding source complete for mSinksToWaitFor.
|
||||
Pair<Integer, Object>[] eventData =
|
||||
AudioSharingUtils.buildAudioSharingDialogEventData(
|
||||
SettingsEnums.AUDIO_SHARING_SETTINGS,
|
||||
SettingsEnums.DIALOG_AUDIO_SHARING_ADD_DEVICE,
|
||||
/* userTriggered= */ false,
|
||||
/* deviceCountInSharing= */ 1,
|
||||
/* candidateDeviceCount= */ 0);
|
||||
showAudioSharingDialog(eventData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSourceAddFailed(
|
||||
@@ -307,34 +330,9 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
||||
@NonNull BluetoothDevice sink,
|
||||
int sourceId,
|
||||
@NonNull BluetoothLeBroadcastReceiveState state) {
|
||||
if (mStoppingSharing.get()) {
|
||||
Log.d(TAG, "Skip onReceiveStateChanged, stopping broadcast");
|
||||
return;
|
||||
}
|
||||
if (BluetoothUtils.isConnected(state)) {
|
||||
if (mSinksInAdding.contains(sink)) {
|
||||
mSinksInAdding.remove(sink);
|
||||
}
|
||||
dismissProgressDialogIfNeeded();
|
||||
Log.d(TAG, "onReceiveStateChanged() connected, sink = " + sink
|
||||
+ ", remaining sinks = " + mSinksInAdding);
|
||||
if (mSinksToWaitFor.contains(sink)) {
|
||||
mSinksToWaitFor.remove(sink);
|
||||
if (mSinksToWaitFor.isEmpty()) {
|
||||
// To avoid users advance to share then pair flow before the
|
||||
// primary/active sinks successfully join the audio sharing,
|
||||
// popup dialog till adding source complete for mSinksToWaitFor.
|
||||
Pair<Integer, Object>[] eventData =
|
||||
AudioSharingUtils.buildAudioSharingDialogEventData(
|
||||
SettingsEnums.AUDIO_SHARING_SETTINGS,
|
||||
SettingsEnums.DIALOG_AUDIO_SHARING_ADD_DEVICE,
|
||||
/* userTriggered= */ false,
|
||||
/* deviceCountInSharing= */ 1,
|
||||
/* candidateDeviceCount= */ 0);
|
||||
showAudioSharingDialog(eventData);
|
||||
}
|
||||
}
|
||||
}
|
||||
Log.d(TAG,
|
||||
"onReceiveStateChanged(), sink = " + sink + ", sourceId = " + sourceId
|
||||
+ ", state = " + state);
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user