Loading res/xml/configure_notification_settings.xml +1 −1 Original line number Diff line number Diff line Loading @@ -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" Loading src/com/android/settings/notification/NotificationAssistantPreferenceController.java +0 −18 Original line number Diff line number Diff line Loading @@ -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; } ); } } } tests/robotests/src/com/android/settings/notification/NotificationAssistantPreferenceControllerTest.java +0 −38 Original line number Diff line number Diff line Loading @@ -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 { Loading Loading @@ -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()); } } Loading
res/xml/configure_notification_settings.xml +1 −1 Original line number Diff line number Diff line Loading @@ -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" Loading
src/com/android/settings/notification/NotificationAssistantPreferenceController.java +0 −18 Original line number Diff line number Diff line Loading @@ -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; } ); } } }
tests/robotests/src/com/android/settings/notification/NotificationAssistantPreferenceControllerTest.java +0 −38 Original line number Diff line number Diff line Loading @@ -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 { Loading Loading @@ -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()); } }