Merge "Rename AudioSharingRetryDialogFragment" into main
This commit is contained in:
@@ -29,8 +29,8 @@ import androidx.fragment.app.FragmentManager;
|
|||||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||||
|
|
||||||
public class AudioSharingRetryDialogFragment extends InstrumentedDialogFragment {
|
public class AudioSharingErrorDialogFragment extends InstrumentedDialogFragment {
|
||||||
private static final String TAG = "AudioSharingRetryDialog";
|
private static final String TAG = "AudioSharingErrorDialog";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMetricsCategory() {
|
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.
|
* @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.");
|
Log.d(TAG, "Dialog is showing, return.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Log.d(TAG, "Show up the retry dialog.");
|
Log.d(TAG, "Show up the error dialog.");
|
||||||
AudioSharingRetryDialogFragment dialogFrag = new AudioSharingRetryDialogFragment();
|
AudioSharingErrorDialogFragment dialogFrag = new AudioSharingErrorDialogFragment();
|
||||||
dialogFrag.show(manager, TAG);
|
dialogFrag.show(manager, TAG);
|
||||||
}
|
}
|
||||||
|
|
@@ -161,7 +161,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
|||||||
public void onBroadcastStartFailed(int reason) {
|
public void onBroadcastStartFailed(int reason) {
|
||||||
Log.d(TAG, "onBroadcastStartFailed(), reason = " + reason);
|
Log.d(TAG, "onBroadcastStartFailed(), reason = " + reason);
|
||||||
updateSwitch();
|
updateSwitch();
|
||||||
showRetryDialog();
|
showErrorDialog();
|
||||||
mMetricsFeatureProvider.action(
|
mMetricsFeatureProvider.action(
|
||||||
mContext,
|
mContext,
|
||||||
SettingsEnums.ACTION_AUDIO_SHARING_START_FAILED,
|
SettingsEnums.ACTION_AUDIO_SHARING_START_FAILED,
|
||||||
@@ -190,7 +190,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
|||||||
mStoppingSharing.compareAndSet(true, false);
|
mStoppingSharing.compareAndSet(true, false);
|
||||||
updateSwitch();
|
updateSwitch();
|
||||||
AudioSharingUtils.postOnMainThread(mContext,
|
AudioSharingUtils.postOnMainThread(mContext,
|
||||||
() -> dismissStaleDialogsOtherThanRetryDialog());
|
() -> dismissStaleDialogsOtherThanErrorDialog());
|
||||||
AudioSharingUtils.toastMessage(
|
AudioSharingUtils.toastMessage(
|
||||||
mContext,
|
mContext,
|
||||||
mContext.getString(R.string.audio_sharing_sharing_stopped_label));
|
mContext.getString(R.string.audio_sharing_sharing_stopped_label));
|
||||||
@@ -278,7 +278,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
|||||||
+ reason);
|
+ reason);
|
||||||
if (mSinksInAdding.contains(sink)) {
|
if (mSinksInAdding.contains(sink)) {
|
||||||
stopAudioSharing();
|
stopAudioSharing();
|
||||||
showRetryDialog();
|
showErrorDialog();
|
||||||
mMetricsFeatureProvider.action(
|
mMetricsFeatureProvider.action(
|
||||||
mContext,
|
mContext,
|
||||||
SettingsEnums.ACTION_AUDIO_SHARING_JOIN_FAILED,
|
SettingsEnums.ACTION_AUDIO_SHARING_JOIN_FAILED,
|
||||||
@@ -742,17 +742,17 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showRetryDialog() {
|
private void showErrorDialog() {
|
||||||
AudioSharingUtils.postOnMainThread(mContext,
|
AudioSharingUtils.postOnMainThread(mContext,
|
||||||
() -> {
|
() -> {
|
||||||
// Remove all opening dialogs before show retry dialog
|
// Remove all stale dialogs before showing error dialog
|
||||||
dismissStaleDialogsOtherThanRetryDialog();
|
dismissStaleDialogsOtherThanErrorDialog();
|
||||||
AudioSharingRetryDialogFragment.show(mFragment);
|
AudioSharingErrorDialogFragment.show(mFragment);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
private void dismissStaleDialogsOtherThanRetryDialog() {
|
private void dismissStaleDialogsOtherThanErrorDialog() {
|
||||||
List<Fragment> fragments = new ArrayList<Fragment>();
|
List<Fragment> fragments = new ArrayList<Fragment>();
|
||||||
try {
|
try {
|
||||||
if (mFragment != null) {
|
if (mFragment != null) {
|
||||||
@@ -764,7 +764,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
|
|||||||
}
|
}
|
||||||
for (Fragment fragment : fragments) {
|
for (Fragment fragment : fragments) {
|
||||||
if (fragment != null && fragment instanceof DialogFragment
|
if (fragment != null && fragment instanceof DialogFragment
|
||||||
&& !(fragment instanceof AudioSharingRetryDialogFragment)
|
&& !(fragment instanceof AudioSharingErrorDialogFragment)
|
||||||
&& ((DialogFragment) fragment).getDialog() != null) {
|
&& ((DialogFragment) fragment).getDialog() != null) {
|
||||||
Log.d(TAG, "Remove stale dialog = " + fragment.getTag());
|
Log.d(TAG, "Remove stale dialog = " + fragment.getTag());
|
||||||
((DialogFragment) fragment).dismiss();
|
((DialogFragment) fragment).dismiss();
|
||||||
|
@@ -51,14 +51,14 @@ import org.robolectric.shadows.androidx.fragment.FragmentController;
|
|||||||
ShadowAlertDialogCompat.class,
|
ShadowAlertDialogCompat.class,
|
||||||
ShadowBluetoothAdapter.class,
|
ShadowBluetoothAdapter.class,
|
||||||
})
|
})
|
||||||
public class AudioSharingRetryDialogFragmentTest {
|
public class AudioSharingErrorDialogFragmentTest {
|
||||||
@Rule
|
@Rule
|
||||||
public final MockitoRule mocks = MockitoJUnit.rule();
|
public final MockitoRule mocks = MockitoJUnit.rule();
|
||||||
@Rule
|
@Rule
|
||||||
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||||
|
|
||||||
private Fragment mParent;
|
private Fragment mParent;
|
||||||
private AudioSharingRetryDialogFragment mFragment;
|
private AudioSharingErrorDialogFragment mFragment;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -70,7 +70,7 @@ public class AudioSharingRetryDialogFragmentTest {
|
|||||||
BluetoothStatusCodes.FEATURE_SUPPORTED);
|
BluetoothStatusCodes.FEATURE_SUPPORTED);
|
||||||
shadowBluetoothAdapter.setIsLeAudioBroadcastAssistantSupported(
|
shadowBluetoothAdapter.setIsLeAudioBroadcastAssistantSupported(
|
||||||
BluetoothStatusCodes.FEATURE_SUPPORTED);
|
BluetoothStatusCodes.FEATURE_SUPPORTED);
|
||||||
mFragment = new AudioSharingRetryDialogFragment();
|
mFragment = new AudioSharingErrorDialogFragment();
|
||||||
mParent = new Fragment();
|
mParent = new Fragment();
|
||||||
FragmentController.setupFragment(
|
FragmentController.setupFragment(
|
||||||
mParent, FragmentActivity.class, /* containerViewId= */ 0, /* bundle= */ null);
|
mParent, FragmentActivity.class, /* containerViewId= */ 0, /* bundle= */ null);
|
||||||
@@ -91,7 +91,7 @@ public class AudioSharingRetryDialogFragmentTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onCreateDialog_flagOff_dialogNotExist() {
|
public void onCreateDialog_flagOff_dialogNotExist() {
|
||||||
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||||
AudioSharingRetryDialogFragment.show(mParent);
|
AudioSharingErrorDialogFragment.show(mParent);
|
||||||
shadowMainLooper().idle();
|
shadowMainLooper().idle();
|
||||||
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
assertThat(dialog).isNull();
|
assertThat(dialog).isNull();
|
||||||
@@ -100,7 +100,7 @@ public class AudioSharingRetryDialogFragmentTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onCreateDialog_unattachedFragment_dialogNotExist() {
|
public void onCreateDialog_unattachedFragment_dialogNotExist() {
|
||||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||||
AudioSharingRetryDialogFragment.show(new Fragment());
|
AudioSharingErrorDialogFragment.show(new Fragment());
|
||||||
shadowMainLooper().idle();
|
shadowMainLooper().idle();
|
||||||
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
assertThat(dialog).isNull();
|
assertThat(dialog).isNull();
|
||||||
@@ -109,7 +109,7 @@ public class AudioSharingRetryDialogFragmentTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onCreateDialog_flagOn_showDialog() {
|
public void onCreateDialog_flagOn_showDialog() {
|
||||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||||
AudioSharingRetryDialogFragment.show(mParent);
|
AudioSharingErrorDialogFragment.show(mParent);
|
||||||
shadowMainLooper().idle();
|
shadowMainLooper().idle();
|
||||||
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
assertThat(dialog).isNotNull();
|
assertThat(dialog).isNotNull();
|
||||||
@@ -119,7 +119,7 @@ public class AudioSharingRetryDialogFragmentTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onCreateDialog_clickOk_dialogDismiss() {
|
public void onCreateDialog_clickOk_dialogDismiss() {
|
||||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||||
AudioSharingRetryDialogFragment.show(mParent);
|
AudioSharingErrorDialogFragment.show(mParent);
|
||||||
shadowMainLooper().idle();
|
shadowMainLooper().idle();
|
||||||
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
assertThat(dialog).isNotNull();
|
assertThat(dialog).isNotNull();
|
@@ -821,7 +821,7 @@ public class AudioSharingSwitchBarControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAssistantCallbacks_onSourceAddFailed_twoDevices_showRetryAndLogAction() {
|
public void testAssistantCallbacks_onSourceAddFailed_twoDevices_showErrorAndLogAction() {
|
||||||
FeatureFlagUtils.setEnabled(
|
FeatureFlagUtils.setEnabled(
|
||||||
mContext, FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, true);
|
mContext, FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, true);
|
||||||
when(mBtnView.isEnabled()).thenReturn(true);
|
when(mBtnView.isEnabled()).thenReturn(true);
|
||||||
@@ -857,7 +857,7 @@ public class AudioSharingSwitchBarControllerTest {
|
|||||||
// Progress dialog shows sharing progress for the user chosen sink.
|
// Progress dialog shows sharing progress for the user chosen sink.
|
||||||
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments();
|
||||||
assertThat(childFragments).comparingElementsUsing(CLAZZNAME_EQUALS).containsExactly(
|
assertThat(childFragments).comparingElementsUsing(CLAZZNAME_EQUALS).containsExactly(
|
||||||
AudioSharingRetryDialogFragment.class.getName());
|
AudioSharingErrorDialogFragment.class.getName());
|
||||||
verify(mFeatureFactory.metricsFeatureProvider)
|
verify(mFeatureFactory.metricsFeatureProvider)
|
||||||
.action(
|
.action(
|
||||||
mContext,
|
mContext,
|
||||||
|
Reference in New Issue
Block a user