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

Commit db679c91 authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge "Remove duel switch from NAS switch" into main

parents 43306392 7679fec1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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"
+0 −18
Original line number Diff line number Diff line
@@ -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;
                    }
            );
        }
    }
}
+0 −38
Original line number Diff line number Diff line
@@ -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());
    }
}