Remove duel switch from NAS switch

Test: NotificationAssistantPreferenceControllerTest
Fixes: 301340325
Change-Id: Id41fad70bdcda6de75b59befe3654b733dbf66e3
This commit is contained in:
Julia Reynolds
2023-10-25 13:01:57 -04:00
parent 55f14ae70d
commit 7679fec17e
3 changed files with 1 additions and 57 deletions

View File

@@ -174,7 +174,7 @@
android:title="@string/notification_pulse_title"
settings:controller="com.android.settings.notification.PulseNotificationPreferenceController"/>
<com.android.settingslib.PrimarySwitchPreference
<SwitchPreference
android:key="notification_assistant"
android:order="25"
android:title="@string/notification_assistant_title"

View File

@@ -131,30 +131,12 @@ public class NotificationAssistantPreferenceController extends TogglePreferenceC
return (mFragment != null && mFragment instanceof ConfigureNotificationSettings);
}
private boolean isNASSettingActivityAvailable() {
final List<ResolveInfo> resolved = mPackageManager.queryIntentActivities(mNASSettingIntent,
PackageManager.ResolveInfoFlags.of(PackageManager.MATCH_ALL));
return (resolved != null && !resolved.isEmpty());
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
if (mDefaultNASComponent == null) {
preference.setEnabled(false);
((PrimarySwitchPreference) preference).setSwitchEnabled(false);
} else if (isNASSettingActivityAvailable()) {
preference.setIntent(mNASSettingIntent);
} else {
// Cannot find settings activity from the default NAS app
preference.setIntent(null);
preference.setOnPreferenceClickListener(
preference1 -> {
onPreferenceChange(preference1, !isChecked());
((PrimarySwitchPreference) preference1).setChecked(isChecked());
return true;
}
);
}
}
}

View File

@@ -154,34 +154,6 @@ public class NotificationAssistantPreferenceControllerTest {
verify(mBackend, times(1)).setNotificationAssistantGranted(null);
}
@Test
public void testUpdateState_SettingActivityAvailable() throws Exception {
mPreferenceController.updateState(mPreference);
assertNotNull(mPreference.getIntent());
mPreference.performClick();
Intent nextIntent = Shadows.shadowOf(
(Application) ApplicationProvider.getApplicationContext()).getNextStartedActivity();
assertEquals(nextIntent.getAction(), ACTION_NOTIFICATION_ASSISTANT_DETAIL_SETTINGS);
}
@Test
public void testUpdateState_SettingActivityUnavailable() throws Exception {
when(mPackageManager.queryIntentActivities(any(Intent.class), any()))
.thenReturn(null);
mPreferenceController.updateState(mPreference);
assertNull(mPreference.getIntent());
mPreference.performClick();
Intent nextIntent = Shadows.shadowOf(
(Application) ApplicationProvider.getApplicationContext()).getNextStartedActivity();
assertNull(nextIntent);
// Verify a dialog is shown
verify(mFragmentTransaction).add(
any(NotificationAssistantDialogFragment.class), anyString());
verify(mBackend, times(0)).setNotificationAssistantGranted(any());
}
@Test
@Config(shadows = ShadowSecureSettings.class)
public void testMigrationFromSetting_userEnable_multiProfile() throws Exception {
@@ -229,14 +201,4 @@ public class NotificationAssistantPreferenceControllerTest {
verify(mBackend, never())
.setNASMigrationDoneAndResetDefault(eq(10), anyBoolean());
}
@Test
public void testNASUnavailable_settingDisabled() throws Exception {
when(mBackend.getDefaultNotificationAssistant()).thenReturn(null);
mPreferenceController.getDefaultNASIntent();
mPreferenceController.updateState(mPreference);
verify(mPreference, atLeastOnce()).setSwitchEnabled(eq(false));
assertFalse(mPreference.isEnabled());
}
}