[Audiosharing] Dismiss all dialogs before show a new one.
Flagged with enable_le_audio_sharing Bug: 305620450 Test: manual Change-Id: I9c3ed31185814b184c9591103636f495046ecd3c
This commit is contained in:
@@ -27,6 +27,8 @@ import android.content.Context;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.fragment.app.DialogFragment;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.lifecycle.DefaultLifecycleObserver;
|
import androidx.lifecycle.DefaultLifecycleObserver;
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
@@ -39,6 +41,7 @@ import com.android.settings.connecteddevice.DevicePreferenceCallback;
|
|||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settingslib.bluetooth.BluetoothCallback;
|
import com.android.settingslib.bluetooth.BluetoothCallback;
|
||||||
|
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||||
import com.android.settingslib.bluetooth.LeAudioProfile;
|
import com.android.settingslib.bluetooth.LeAudioProfile;
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast;
|
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast;
|
||||||
@@ -54,6 +57,7 @@ import java.util.concurrent.Executors;
|
|||||||
|
|
||||||
public class AudioSharingDevicePreferenceController extends BasePreferenceController
|
public class AudioSharingDevicePreferenceController extends BasePreferenceController
|
||||||
implements DefaultLifecycleObserver, DevicePreferenceCallback, BluetoothCallback {
|
implements DefaultLifecycleObserver, DevicePreferenceCallback, BluetoothCallback {
|
||||||
|
private static final boolean DEBUG = BluetoothUtils.D;
|
||||||
|
|
||||||
private static final String TAG = "AudioSharingDevicePrefController";
|
private static final String TAG = "AudioSharingDevicePrefController";
|
||||||
private static final String KEY = "audio_sharing_device_list";
|
private static final String KEY = "audio_sharing_device_list";
|
||||||
@@ -372,19 +376,31 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
|
|||||||
+ " non le audio device");
|
+ " non le audio device");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(
|
||||||
|
TAG,
|
||||||
|
"Start handling onProfileConnectionStateChanged for "
|
||||||
|
+ cachedDevice.getDevice().getAnonymizedAddress());
|
||||||
|
}
|
||||||
if (!isLeAudioSupported) {
|
if (!isLeAudioSupported) {
|
||||||
// Handle connected ineligible (non LE audio) remote device
|
// Handle connected ineligible (non LE audio) remote device
|
||||||
if (isBroadcasting()) {
|
if (isBroadcasting()) {
|
||||||
// Show stop audio sharing dialog when an ineligible (non LE audio) remote device
|
// Show stop audio sharing dialog when an ineligible (non LE audio) remote device
|
||||||
// connected during a sharing session.
|
// connected during a sharing session.
|
||||||
|
closeOpeningDialogs();
|
||||||
AudioSharingStopDialogFragment.show(
|
AudioSharingStopDialogFragment.show(
|
||||||
mFragment,
|
mFragment,
|
||||||
cachedDevice.getName(),
|
cachedDevice.getName(),
|
||||||
() -> {
|
() -> mBroadcast.stopBroadcast(mBroadcast.getLatestBroadcastId()));
|
||||||
mBroadcast.stopBroadcast(mBroadcast.getLatestBroadcastId());
|
} else {
|
||||||
});
|
|
||||||
}
|
|
||||||
// Do nothing for ineligible (non LE audio) remote device when no sharing session.
|
// Do nothing for ineligible (non LE audio) remote device when no sharing session.
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(
|
||||||
|
TAG,
|
||||||
|
"Ignore onProfileConnectionStateChanged for non LE audio without"
|
||||||
|
+ " sharing session");
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Map<Integer, List<CachedBluetoothDevice>> groupedDevices =
|
Map<Integer, List<CachedBluetoothDevice>> groupedDevices =
|
||||||
AudioSharingUtils.fetchConnectedDevicesByGroupId(mLocalBtManager);
|
AudioSharingUtils.fetchConnectedDevicesByGroupId(mLocalBtManager);
|
||||||
@@ -398,6 +414,7 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
|
|||||||
// Show audio sharing switch dialog when the third eligible (LE audio) remote device
|
// Show audio sharing switch dialog when the third eligible (LE audio) remote device
|
||||||
// connected during a sharing session.
|
// connected during a sharing session.
|
||||||
if (deviceItemsInSharingSession.size() >= 2) {
|
if (deviceItemsInSharingSession.size() >= 2) {
|
||||||
|
closeOpeningDialogs();
|
||||||
AudioSharingDisconnectDialogFragment.show(
|
AudioSharingDisconnectDialogFragment.show(
|
||||||
mFragment,
|
mFragment,
|
||||||
deviceItemsInSharingSession,
|
deviceItemsInSharingSession,
|
||||||
@@ -421,6 +438,7 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
|
|||||||
} else {
|
} else {
|
||||||
// Show audio sharing join dialog when the first or second eligible (LE audio)
|
// Show audio sharing join dialog when the first or second eligible (LE audio)
|
||||||
// remote device connected during a sharing session.
|
// remote device connected during a sharing session.
|
||||||
|
closeOpeningDialogs();
|
||||||
AudioSharingJoinDialogFragment.show(
|
AudioSharingJoinDialogFragment.show(
|
||||||
mFragment,
|
mFragment,
|
||||||
deviceItemsInSharingSession,
|
deviceItemsInSharingSession,
|
||||||
@@ -447,6 +465,7 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
|
|||||||
// Show audio sharing join dialog when the second eligible (LE audio) remote device
|
// Show audio sharing join dialog when the second eligible (LE audio) remote device
|
||||||
// connect and no sharing session.
|
// connect and no sharing session.
|
||||||
if (deviceItems.size() == 1) {
|
if (deviceItems.size() == 1) {
|
||||||
|
closeOpeningDialogs();
|
||||||
AudioSharingJoinDialogFragment.show(
|
AudioSharingJoinDialogFragment.show(
|
||||||
mFragment,
|
mFragment,
|
||||||
deviceItems,
|
deviceItems,
|
||||||
@@ -524,4 +543,15 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
|
|||||||
mAssistant.addSource(sink, broadcastMetadata, /* isGroupOp= */ false);
|
mAssistant.addSource(sink, broadcastMetadata, /* isGroupOp= */ false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void closeOpeningDialogs() {
|
||||||
|
if (mFragment == null) return;
|
||||||
|
List<Fragment> fragments = mFragment.getChildFragmentManager().getFragments();
|
||||||
|
for (Fragment fragment : fragments) {
|
||||||
|
if (fragment instanceof DialogFragment) {
|
||||||
|
Log.d(TAG, "Remove staled opening dialog " + fragment.getTag());
|
||||||
|
((DialogFragment) fragment).dismiss();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -77,16 +77,13 @@ public class AudioSharingDisconnectDialogFragment extends InstrumentedDialogFrag
|
|||||||
if (!AudioSharingUtils.isFeatureEnabled()) return;
|
if (!AudioSharingUtils.isFeatureEnabled()) return;
|
||||||
final FragmentManager manager = host.getChildFragmentManager();
|
final FragmentManager manager = host.getChildFragmentManager();
|
||||||
sListener = listener;
|
sListener = listener;
|
||||||
if (manager.findFragmentByTag(TAG) == null) {
|
|
||||||
final Bundle bundle = new Bundle();
|
final Bundle bundle = new Bundle();
|
||||||
bundle.putParcelableArrayList(BUNDLE_KEY_DEVICE_TO_DISCONNECT_ITEMS, deviceItems);
|
bundle.putParcelableArrayList(BUNDLE_KEY_DEVICE_TO_DISCONNECT_ITEMS, deviceItems);
|
||||||
bundle.putString(BUNDLE_KEY_NEW_DEVICE_NAME, newDeviceName);
|
bundle.putString(BUNDLE_KEY_NEW_DEVICE_NAME, newDeviceName);
|
||||||
AudioSharingDisconnectDialogFragment dialog =
|
AudioSharingDisconnectDialogFragment dialog = new AudioSharingDisconnectDialogFragment();
|
||||||
new AudioSharingDisconnectDialogFragment();
|
|
||||||
dialog.setArguments(bundle);
|
dialog.setArguments(bundle);
|
||||||
dialog.show(manager, TAG);
|
dialog.show(manager, TAG);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
@@ -71,7 +71,6 @@ public class AudioSharingJoinDialogFragment extends InstrumentedDialogFragment {
|
|||||||
if (!AudioSharingUtils.isFeatureEnabled()) return;
|
if (!AudioSharingUtils.isFeatureEnabled()) return;
|
||||||
final FragmentManager manager = host.getChildFragmentManager();
|
final FragmentManager manager = host.getChildFragmentManager();
|
||||||
sListener = listener;
|
sListener = listener;
|
||||||
if (manager.findFragmentByTag(TAG) == null) {
|
|
||||||
final Bundle bundle = new Bundle();
|
final Bundle bundle = new Bundle();
|
||||||
bundle.putParcelableArrayList(BUNDLE_KEY_DEVICE_ITEMS, deviceItems);
|
bundle.putParcelableArrayList(BUNDLE_KEY_DEVICE_ITEMS, deviceItems);
|
||||||
bundle.putString(BUNDLE_KEY_NEW_DEVICE_NAME, newDeviceName);
|
bundle.putString(BUNDLE_KEY_NEW_DEVICE_NAME, newDeviceName);
|
||||||
@@ -79,7 +78,6 @@ public class AudioSharingJoinDialogFragment extends InstrumentedDialogFragment {
|
|||||||
dialog.setArguments(bundle);
|
dialog.setArguments(bundle);
|
||||||
dialog.show(manager, TAG);
|
dialog.show(manager, TAG);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
@@ -56,14 +56,12 @@ public class AudioSharingStopDialogFragment extends InstrumentedDialogFragment {
|
|||||||
if (!AudioSharingUtils.isFeatureEnabled()) return;
|
if (!AudioSharingUtils.isFeatureEnabled()) return;
|
||||||
final FragmentManager manager = host.getChildFragmentManager();
|
final FragmentManager manager = host.getChildFragmentManager();
|
||||||
sListener = listener;
|
sListener = listener;
|
||||||
if (manager.findFragmentByTag(TAG) == null) {
|
|
||||||
final Bundle bundle = new Bundle();
|
final Bundle bundle = new Bundle();
|
||||||
bundle.putString(BUNDLE_KEY_NEW_DEVICE_NAME, newDeviceName);
|
bundle.putString(BUNDLE_KEY_NEW_DEVICE_NAME, newDeviceName);
|
||||||
AudioSharingStopDialogFragment dialog = new AudioSharingStopDialogFragment();
|
AudioSharingStopDialogFragment dialog = new AudioSharingStopDialogFragment();
|
||||||
dialog.setArguments(bundle);
|
dialog.setArguments(bundle);
|
||||||
dialog.show(manager, TAG);
|
dialog.show(manager, TAG);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
Reference in New Issue
Block a user