[Audiosharing] Enable audio sharing UI when preview option on.

Test: atest
Bug: 368401233
Flag: com.android.settingslib.flags.audio_sharing_developer_option
Change-Id: Idbc84e2c43f7361c58c440d1a7d7c78edd3c0521
This commit is contained in:
Yiyi Shen
2024-11-01 18:48:18 +08:00
parent 55cd3c67cb
commit 2fc788c35a
29 changed files with 445 additions and 379 deletions

View File

@@ -84,37 +84,42 @@ public class AudioSharingDialogFragment extends InstrumentedDialogFragment {
* @param eventData The eventData to log with for dialog onClick events.
*/
public static void show(
@NonNull Fragment host,
@Nullable Fragment host,
@NonNull List<AudioSharingDeviceItem> deviceItems,
@NonNull DialogEventListener listener,
@NonNull Pair<Integer, Object>[] eventData) {
if (!BluetoothUtils.isAudioSharingEnabled()) return;
final FragmentManager manager;
try {
manager = host.getChildFragmentManager();
} catch (IllegalStateException e) {
Log.d(TAG, "Fail to show dialog: " + e.getMessage());
if (host == null) {
Log.d(TAG, "Fail to show dialog, host is null");
return;
}
Lifecycle.State currentState = host.getLifecycle().getCurrentState();
if (!currentState.isAtLeast(Lifecycle.State.STARTED)) {
Log.d(TAG, "Fail to show dialog with state: " + currentState);
return;
if (BluetoothUtils.isAudioSharingUIAvailable(host.getContext())) {
final FragmentManager manager;
try {
manager = host.getChildFragmentManager();
} catch (IllegalStateException e) {
Log.d(TAG, "Fail to show dialog: " + e.getMessage());
return;
}
Lifecycle.State currentState = host.getLifecycle().getCurrentState();
if (!currentState.isAtLeast(Lifecycle.State.STARTED)) {
Log.d(TAG, "Fail to show dialog with state: " + currentState);
return;
}
sHost = host;
sListener = listener;
sEventData = eventData;
AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG);
if (dialog != null) {
Log.d(TAG, "Dialog is showing, return.");
return;
}
Log.d(TAG, "Show up the dialog.");
final Bundle bundle = new Bundle();
bundle.putParcelableList(BUNDLE_KEY_DEVICE_ITEMS, deviceItems);
AudioSharingDialogFragment dialogFrag = new AudioSharingDialogFragment();
dialogFrag.setArguments(bundle);
dialogFrag.show(manager, TAG);
}
sHost = host;
sListener = listener;
sEventData = eventData;
AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG);
if (dialog != null) {
Log.d(TAG, "Dialog is showing, return.");
return;
}
Log.d(TAG, "Show up the dialog.");
final Bundle bundle = new Bundle();
bundle.putParcelableList(BUNDLE_KEY_DEVICE_ITEMS, deviceItems);
AudioSharingDialogFragment dialogFrag = new AudioSharingDialogFragment();
dialogFrag.setArguments(bundle);
dialogFrag.show(manager, TAG);
}
/** Return the tag of {@link AudioSharingDialogFragment} dialog. */