Fix stray ProfileSelectDialog when only one profile exists

Fixes: 377829434
Test: atest ZenModePrioritySendersPreferenceControllerTest
Flag: android.app.modes_ui
Change-Id: Ia5f667fd937107af98dfb3a073cadeb935ff8a8a
This commit is contained in:
Matías Hernández
2024-11-07 18:52:59 +01:00
parent 2c4aec3a23
commit b152c2d34f
2 changed files with 16 additions and 0 deletions

View File

@@ -299,6 +299,7 @@ class ZenModePrioritySendersPreferenceController
List<UserHandle> userProfiles = mUserManager.getEnabledProfiles();
if (userProfiles.size() <= 1) {
mContext.startActivity(intent);
return;
}
mProfileSelectDialog = ProfileSelectDialog.createDialog(mContext, userProfiles,

View File

@@ -1545,6 +1545,21 @@ public final class ZenModePrioritySendersPreferenceControllerTest {
assertThat(nextActivity.getAction()).isEqualTo(Intent.ACTION_MAIN);
}
@Test
public void contactsSettingsClick_singleProfile_opensActivityWithoutDialog() {
String contactsPackage = mContext.getString(R.string.config_contacts_package_name);
setUpContactsApp(contactsPackage, /* withPreciseIntents= */ true);
mCallsController.displayPreference(mPreferenceScreen);
mCallsController.updateZenMode(mCallsPrefCategory, TestModeBuilder.EXAMPLE);
SelectorWithWidgetPreference contactsPref = getBoundSelectorPreference(KEY_CONTACTS);
contactsPref.getExtraWidget().performClick();
assertThat(ShadowDialog.getLatestDialog()).isNull();
assertThat(shadowOf(mActivity).getNextStartedActivity()).isNotNull();
}
@Test
public void contactsSettingsClick_multipleProfiles_showsProfileChooserDialog() {
String contactsPackage = mContext.getString(R.string.config_contacts_package_name);