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

Commit 01daf3eb authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Hide adjustment field on app page if feature disabled

Test: BundleListPreferenceControllerTest
Test: AdjustmentKeyPreferenceControllerTest
Fixes: 412712590
Flag: android.app.notification_classification_ui
Change-Id: I8450f7a7868f525fbebc24320c53846ecfc9528c
parent c2413775
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -452,9 +452,10 @@ public class NotificationBackend {
        }
    }

    public List<String> getAllowedAssistantAdjustments(String pkg) {
    public List<String> getAllowedAssistantAdjustments() {
        try {
            return sINM.getAllowedAssistantAdjustments(pkg);
            // this app is system uid so the pkg arg is not checked
            return sINM.getAllowedAssistantAdjustments("");
        } catch (Exception e) {
            Log.w(TAG, "Error calling NoMan", e);
        }
+5 −0
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
 */
package com.android.settings.notification.app;

import static android.service.notification.Adjustment.KEY_TYPE;

import android.app.Flags;
import android.content.Context;
import android.service.notification.Adjustment;
@@ -66,6 +68,9 @@ public class AdjustmentKeyPreferenceController extends
                || mBackend.isInInvalidMsgState(mAppRow.pkg, mAppRow.uid))) {
            return false;
        }
        if (!mBackend.getAllowedAssistantAdjustments().contains(mKey)) {
            return false;
        }
        return super.isAvailable();
    }

+1 −1
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ public class BundleListPreferenceController extends NotificationPreferenceContro
        if (mAppRow == null) {
            return false;
        }
        if (!mBackend.getAllowedAssistantAdjustments(mAppRow.pkg).contains(KEY_TYPE)) {
        if (!mBackend.getAllowedAssistantAdjustments().contains(KEY_TYPE)) {
            return false;
        }
        if (mAppRow.banned || mAppRow.lockedImportance || mAppRow.systemApp) {
+10 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;

import java.util.ArrayList;
import java.util.List;

@RunWith(RobolectricTestRunner.class)
@@ -73,6 +74,7 @@ public class AdjustmentKeyPreferenceControllerTest {
        mSwitch = new RestrictedSwitchPreference(mContext);
        new PreferenceManager(mContext).createPreferenceScreen(mContext).addPreference(mSwitch);
        when(mBackend.hasSentValidMsg(anyString(), anyInt())).thenReturn(true);
        when(mBackend.getAllowedAssistantAdjustments()).thenReturn(List.of(KEY_TYPE));

        mPrefController = new AdjustmentKeyPreferenceController(mContext, mBackend, KEY_TYPE);

@@ -89,6 +91,14 @@ public class AdjustmentKeyPreferenceControllerTest {
        assertThat(mPrefController.isAvailable()).isFalse();
    }

    @Test
    @EnableFlags({Flags.FLAG_NM_SUMMARIZATION, Flags.FLAG_NM_SUMMARIZATION_UI,
            Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI})
    public void testIsAvailable_globalFeatureOff() {
        when(mBackend.getAllowedAssistantAdjustments()).thenReturn(new ArrayList<>());
        assertThat(mPrefController.isAvailable()).isFalse();
    }

    @Test
    @EnableFlags({Flags.FLAG_NM_SUMMARIZATION, Flags.FLAG_NM_SUMMARIZATION_UI,
            Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI})
+2 −2
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ public class BundleListPreferenceControllerTest {
        MockitoAnnotations.initMocks(this);
        mContext = ApplicationProvider.getApplicationContext();

        when(mBackend.getAllowedAssistantAdjustments(anyString())).thenReturn(List.of(KEY_TYPE));
        when(mBackend.getAllowedAssistantAdjustments()).thenReturn(List.of(KEY_TYPE));
        when(mBackend.isNotificationBundlingSupported()).thenReturn(true);

        mAppRow = new NotificationBackend.AppRow();
@@ -112,7 +112,7 @@ public class BundleListPreferenceControllerTest {

    @Test
    public void isAvailable_featureOffForPackage() {
        when(mBackend.getAllowedAssistantAdjustments(anyString())).thenReturn(List.of());
        when(mBackend.getAllowedAssistantAdjustments()).thenReturn(List.of());
        assertThat(mController.isAvailable()).isFalse();
    }