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

Commit adc7c43d authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Fix app level adjust key settings

these api names are too similar :D

Test: AdjustmentExcludedAppsPreferenceControllerTest
Test: AdjustmentKeyPreferenceControllerTest
Flag: android.app.nm_summarization
Fixes: 412631759
Change-Id: If08423de4cf4371bdcce9aaee773897904750289
parent 9840820e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -139,7 +139,7 @@ public class AdjustmentExcludedAppsPreferenceController extends BasePreferenceCo
            return;
        }

        List<String> excludedApps = List.of(mBackend.getAdjustmentDeniedPackages(mAdjustmentKey));
        List<String> excludedApps = mBackend.getAdjustmentDeniedPackages(mAdjustmentKey);

        for (ApplicationsState.AppEntry app : apps) {
            String pkg = app.info.packageName;
+3 −3
Original line number Diff line number Diff line
@@ -798,12 +798,12 @@ public class NotificationBackend {
        }
    }

    public @NonNull String[] getAdjustmentDeniedPackages(String key) {
    public @NonNull List<String> getAdjustmentDeniedPackages(String key) {
        try {
            return sINM.getAdjustmentDeniedPackages(key);
            return List.of(sINM.getAdjustmentDeniedPackages(key));
        } catch (Exception e) {
            Log.w(TAG, "Error calling NoMan", e);
            return new String[]{};
            return new ArrayList<>();
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -84,7 +84,7 @@ public class AdjustmentKeyPreferenceController extends
        if (pref != null && mAppRow != null) {
            pref.setDisabledByAdmin(mAdmin);
            pref.setEnabled(!pref.isDisabledByAdmin());
            pref.setChecked(mBackend.getAllowedAssistantAdjustments(mAppRow.pkg).contains(mKey));
            pref.setChecked(!mBackend.getAdjustmentDeniedPackages(mKey).contains(mAppRow.pkg));
            pref.setOnPreferenceChangeListener(this);
        }
    }
+1 −1
Original line number Diff line number Diff line
@@ -98,7 +98,7 @@ public class AdjustmentExcludedAppsPreferenceControllerTest {
    @Test
    public void testUpdateAppList() throws Exception {
        when(mBackend.getAdjustmentDeniedPackages(KEY_SUMMARIZATION)).thenReturn(
                new String[] {"cannot", "cannot2"});
                List.of("cannot", "cannot2"));

        // GIVEN there are four apps, and two have KEY_SUMMARIZATION off
        ApplicationsState.AppEntry canSummarize =
+12 −6
Original line number Diff line number Diff line
@@ -113,16 +113,22 @@ public class AdjustmentKeyPreferenceControllerTest {
    @EnableFlags({Flags.FLAG_NM_SUMMARIZATION, Flags.FLAG_NM_SUMMARIZATION_UI,
            Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI})
    public void testChecked_adjustmentAllowed() {
        when(mBackend.getAllowedAssistantAdjustments(mAppRow.pkg)).thenReturn(
                List.of(KEY_TYPE, KEY_IMPORTANCE));
        when(mBackend.getAdjustmentDeniedPackages(KEY_TYPE)).thenReturn(
                List.of("not this"));
        mPrefController.onResume(mAppRow, null, null, null, null, null, null);

        mPrefController.updateState(mSwitch);
        assertThat(mSwitch.isChecked()).isTrue();
    }

        when(mBackend.getAllowedAssistantAdjustments(mAppRow.pkg)).thenReturn(
                List.of(KEY_SUMMARIZATION, KEY_IMPORTANCE));
    @Test
    @EnableFlags({Flags.FLAG_NM_SUMMARIZATION, Flags.FLAG_NM_SUMMARIZATION_UI,
            Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI})
    public void testChecked_adjustmentNotAllowed() {
        when(mBackend.getAdjustmentDeniedPackages(KEY_TYPE)).thenReturn(
                List.of(mAppRow.pkg));
        mPrefController.onResume(mAppRow, null, null, null, null, null, null);

        mPrefController.updateState(mSwitch);
        assertThat(mSwitch.isChecked()).isFalse();
    }
@@ -131,8 +137,8 @@ public class AdjustmentKeyPreferenceControllerTest {
    @EnableFlags({Flags.FLAG_NM_SUMMARIZATION, Flags.FLAG_NM_SUMMARIZATION_UI,
            Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI})
    public void testOnPreferenceChange_changeOnAndOff() {
        when(mBackend.getAllowedAssistantAdjustments(mAppRow.pkg)).thenReturn(
                List.of(KEY_TYPE, KEY_IMPORTANCE));
        when(mBackend.getAdjustmentDeniedPackages(KEY_TYPE)).thenReturn(
                List.of("not this"));
        mPrefController.onResume(mAppRow, null, null, null, null, null, null);

        // when the switch value changes to false