Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7a91f6e7 authored by Yiyi Shen's avatar Yiyi Shen Committed by Android (Google) Code Review
Browse files

Merge "Rename AudioSharingRetryDialogFragment" into main

parents 676ddc7e 51fc7a82
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -29,8 +29,8 @@ import androidx.fragment.app.FragmentManager;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
import com.android.settingslib.bluetooth.BluetoothUtils;

public class AudioSharingRetryDialogFragment extends InstrumentedDialogFragment {
    private static final String TAG = "AudioSharingRetryDialog";
public class AudioSharingErrorDialogFragment extends InstrumentedDialogFragment {
    private static final String TAG = "AudioSharingErrorDialog";

    @Override
    public int getMetricsCategory() {
@@ -39,7 +39,7 @@ public class AudioSharingRetryDialogFragment extends InstrumentedDialogFragment
    }

    /**
     * Display the {@link AudioSharingRetryDialogFragment} dialog.
     * Display the {@link AudioSharingErrorDialogFragment} dialog.
     *
     * @param host The Fragment this dialog will be hosted.
     */
@@ -57,8 +57,8 @@ public class AudioSharingRetryDialogFragment extends InstrumentedDialogFragment
            Log.d(TAG, "Dialog is showing, return.");
            return;
        }
        Log.d(TAG, "Show up the retry dialog.");
        AudioSharingRetryDialogFragment dialogFrag = new AudioSharingRetryDialogFragment();
        Log.d(TAG, "Show up the error dialog.");
        AudioSharingErrorDialogFragment dialogFrag = new AudioSharingErrorDialogFragment();
        dialogFrag.show(manager, TAG);
    }

+9 −9
Original line number Diff line number Diff line
@@ -161,7 +161,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
                public void onBroadcastStartFailed(int reason) {
                    Log.d(TAG, "onBroadcastStartFailed(), reason = " + reason);
                    updateSwitch();
                    showRetryDialog();
                    showErrorDialog();
                    mMetricsFeatureProvider.action(
                            mContext,
                            SettingsEnums.ACTION_AUDIO_SHARING_START_FAILED,
@@ -190,7 +190,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
                    mStoppingSharing.compareAndSet(true, false);
                    updateSwitch();
                    AudioSharingUtils.postOnMainThread(mContext,
                            () -> dismissStaleDialogsOtherThanRetryDialog());
                            () -> dismissStaleDialogsOtherThanErrorDialog());
                    AudioSharingUtils.toastMessage(
                            mContext,
                            mContext.getString(R.string.audio_sharing_sharing_stopped_label));
@@ -278,7 +278,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
                                    + reason);
                    if (mSinksInAdding.contains(sink)) {
                        stopAudioSharing();
                        showRetryDialog();
                        showErrorDialog();
                        mMetricsFeatureProvider.action(
                                mContext,
                                SettingsEnums.ACTION_AUDIO_SHARING_JOIN_FAILED,
@@ -742,17 +742,17 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
                });
    }

    private void showRetryDialog() {
    private void showErrorDialog() {
        AudioSharingUtils.postOnMainThread(mContext,
                () -> {
                    // Remove all opening dialogs before show retry dialog
                    dismissStaleDialogsOtherThanRetryDialog();
                    AudioSharingRetryDialogFragment.show(mFragment);
                    // Remove all stale dialogs before showing error dialog
                    dismissStaleDialogsOtherThanErrorDialog();
                    AudioSharingErrorDialogFragment.show(mFragment);
                });
    }

    @UiThread
    private void dismissStaleDialogsOtherThanRetryDialog() {
    private void dismissStaleDialogsOtherThanErrorDialog() {
        List<Fragment> fragments = new ArrayList<Fragment>();
        try {
            if (mFragment != null) {
@@ -764,7 +764,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
        }
        for (Fragment fragment : fragments) {
            if (fragment != null && fragment instanceof DialogFragment
                    && !(fragment instanceof AudioSharingRetryDialogFragment)
                    && !(fragment instanceof AudioSharingErrorDialogFragment)
                    && ((DialogFragment) fragment).getDialog() != null) {
                Log.d(TAG, "Remove stale dialog = " + fragment.getTag());
                ((DialogFragment) fragment).dismiss();
+7 −7
Original line number Diff line number Diff line
@@ -51,14 +51,14 @@ import org.robolectric.shadows.androidx.fragment.FragmentController;
                ShadowAlertDialogCompat.class,
                ShadowBluetoothAdapter.class,
        })
public class AudioSharingRetryDialogFragmentTest {
public class AudioSharingErrorDialogFragmentTest {
    @Rule
    public final MockitoRule mocks = MockitoJUnit.rule();
    @Rule
    public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();

    private Fragment mParent;
    private AudioSharingRetryDialogFragment mFragment;
    private AudioSharingErrorDialogFragment mFragment;

    @Before
    public void setUp() {
@@ -70,7 +70,7 @@ public class AudioSharingRetryDialogFragmentTest {
                BluetoothStatusCodes.FEATURE_SUPPORTED);
        shadowBluetoothAdapter.setIsLeAudioBroadcastAssistantSupported(
                BluetoothStatusCodes.FEATURE_SUPPORTED);
        mFragment = new AudioSharingRetryDialogFragment();
        mFragment = new AudioSharingErrorDialogFragment();
        mParent = new Fragment();
        FragmentController.setupFragment(
                mParent, FragmentActivity.class, /* containerViewId= */ 0, /* bundle= */ null);
@@ -91,7 +91,7 @@ public class AudioSharingRetryDialogFragmentTest {
    @Test
    public void onCreateDialog_flagOff_dialogNotExist() {
        mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
        AudioSharingRetryDialogFragment.show(mParent);
        AudioSharingErrorDialogFragment.show(mParent);
        shadowMainLooper().idle();
        AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
        assertThat(dialog).isNull();
@@ -100,7 +100,7 @@ public class AudioSharingRetryDialogFragmentTest {
    @Test
    public void onCreateDialog_unattachedFragment_dialogNotExist() {
        mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
        AudioSharingRetryDialogFragment.show(new Fragment());
        AudioSharingErrorDialogFragment.show(new Fragment());
        shadowMainLooper().idle();
        AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
        assertThat(dialog).isNull();
@@ -109,7 +109,7 @@ public class AudioSharingRetryDialogFragmentTest {
    @Test
    public void onCreateDialog_flagOn_showDialog() {
        mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
        AudioSharingRetryDialogFragment.show(mParent);
        AudioSharingErrorDialogFragment.show(mParent);
        shadowMainLooper().idle();
        AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
        assertThat(dialog).isNotNull();
@@ -119,7 +119,7 @@ public class AudioSharingRetryDialogFragmentTest {
    @Test
    public void onCreateDialog_clickOk_dialogDismiss() {
        mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
        AudioSharingRetryDialogFragment.show(mParent);
        AudioSharingErrorDialogFragment.show(mParent);
        shadowMainLooper().idle();
        AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
        assertThat(dialog).isNotNull();
+2 −2
Original line number Diff line number Diff line
@@ -821,7 +821,7 @@ public class AudioSharingSwitchBarControllerTest {
    }

    @Test
    public void testAssistantCallbacks_onSourceAddFailed_twoDevices_showRetryAndLogAction() {
    public void testAssistantCallbacks_onSourceAddFailed_twoDevices_showErrorAndLogAction() {
        FeatureFlagUtils.setEnabled(
                mContext, FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, true);
        when(mBtnView.isEnabled()).thenReturn(true);
@@ -857,7 +857,7 @@ public class AudioSharingSwitchBarControllerTest {
        // Progress dialog shows sharing progress for the user chosen sink.
        List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
        assertThat(childFragments).comparingElementsUsing(CLAZZNAME_EQUALS).containsExactly(
                AudioSharingRetryDialogFragment.class.getName());
                AudioSharingErrorDialogFragment.class.getName());
        verify(mFeatureFactory.metricsFeatureProvider)
                .action(
                        mContext,