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

Commit 918f23b3 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Updates to default values

- all classification types are allowed by default
- Only reload nas unsupported defaults on nas change/upgrade

Test: NotificationAssistantServiceTest
Test: NotificationAsssistantsTest
Bug: 367996732
Bug: 388485761
Flag: android.app.nm_summarization
Change-Id: Ie649222d6dd059eb8712f2c623b9403113004ac0
parent de851127
Loading
Loading
Loading
Loading
+41 −27
Original line number Diff line number Diff line
@@ -111,7 +111,9 @@ import static android.os.UserHandle.USER_SYSTEM;
import static android.service.notification.Adjustment.KEY_SUMMARIZATION;
import static android.service.notification.Adjustment.KEY_TYPE;
import static android.service.notification.Adjustment.TYPE_CONTENT_RECOMMENDATION;
import static android.service.notification.Adjustment.TYPE_NEWS;
import static android.service.notification.Adjustment.TYPE_PROMOTION;
import static android.service.notification.Adjustment.TYPE_SOCIAL_MEDIA;
import static android.service.notification.Flags.FLAG_NOTIFICATION_CONVERSATION_CHANNEL_MANAGEMENT;
import static android.service.notification.Flags.callstyleCallbackApi;
import static android.service.notification.Flags.notificationClassification;
@@ -491,7 +493,10 @@ public class NotificationManagerService extends SystemService {
    };
    static final Integer[] DEFAULT_ALLOWED_ADJUSTMENT_KEY_TYPES = new Integer[] {
            TYPE_PROMOTION
            TYPE_PROMOTION,
            TYPE_NEWS,
            TYPE_CONTENT_RECOMMENDATION,
            TYPE_SOCIAL_MEDIA
    };
    static final String[] NON_BLOCKABLE_DEFAULT_ROLES = new String[] {
@@ -4521,7 +4526,7 @@ public class NotificationManagerService extends SystemService {
                    if (key == null) {
                        return;
                    }
                    mAssistants.setAdjustmentTypeSupportedState(info,  key, supported);
                    mAssistants.setAdjustmentTypeSupportedState(info.userid,  key, supported);
                }
            } finally {
                Binder.restoreCallingIdentity(identity);
@@ -7014,7 +7019,7 @@ public class NotificationManagerService extends SystemService {
            final long identity = Binder.clearCallingIdentity();
            try {
                synchronized (mNotificationLock) {
                    mAssistants.checkServiceTokenLocked(token);
                    ManagedServiceInfo info = mAssistants.checkServiceTokenLocked(token);
                    int N = mEnqueuedNotifications.size();
                    for (int i = 0; i < N; i++) {
                        final NotificationRecord r = mEnqueuedNotifications.get(i);
@@ -7360,6 +7365,10 @@ public class NotificationManagerService extends SystemService {
                    mAssistants.setPackageOrComponentEnabled(assistant.flattenToString(),
                            userId, true, granted, userSet);
                    if (android.service.notification.Flags.notificationClassification()) {
                        mAssistants.setNasUnsupportedDefaults(userId);
                    }
                    getContext().sendBroadcastAsUser(
                            new Intent(ACTION_NOTIFICATION_POLICY_ACCESS_GRANTED_CHANGED)
                                    .setPackage(assistant.getPackageName())
@@ -7391,7 +7400,8 @@ public class NotificationManagerService extends SystemService {
                    toRemove.add(potentialKey);
                }
                if (notificationClassification() && potentialKey.equals(KEY_TYPE)) {
                    mAssistants.setNasUnsupportedDefaults(r.getSbn().getNormalizedUserId());
                    mAssistants.setAdjustmentTypeSupportedState(
                            r.getSbn().getNormalizedUserId(), potentialKey, true);
                    if (!mAssistants.isAdjustmentKeyTypeAllowed(adjustments.getInt(KEY_TYPE))) {
                        toRemove.add(potentialKey);
                    } else if (notificationClassificationUi()
@@ -7402,6 +7412,8 @@ public class NotificationManagerService extends SystemService {
                }
                if ((nmSummarization() || nmSummarizationUi())
                        && potentialKey.equals(KEY_SUMMARIZATION)) {
                    mAssistants.setAdjustmentTypeSupportedState(
                            r.getSbn().getNormalizedUserId(), potentialKey, true);
                    if (!mAssistants.isAdjustmentAllowedForPackage(KEY_SUMMARIZATION,
                            r.getSbn().getPackageName())) {
                        toRemove.add(potentialKey);
@@ -12059,8 +12071,8 @@ public class NotificationManagerService extends SystemService {
        private static final String TAG_DENIED_KEY = "adjustment";
        private static final String ATT_DENIED_KEY = "key";
        private static final String ATT_DENIED_KEY_APPS = "denied_apps";
        private static final String TAG_ENABLED_TYPES = "enabled_key_types";
        private static final String ATT_NAS_UNSUPPORTED = "nas_unsupported_adjustments";
        private static final String TAG_ENABLED_TYPES = "enabled_classification_types";
        private static final String ATT_NAS_UNSUPPORTED = "unsupported_adjustments";
        private final Object mLock = new Object();
@@ -12662,10 +12674,6 @@ public class NotificationManagerService extends SystemService {
                    setNotificationAssistantAccessGrantedForUserInternal(
                            currentComponent, userId, false, userSet);
                }
            } else {
                if (android.service.notification.Flags.notificationClassification()) {
                    setNasUnsupportedDefaults(userId);
                }
            }
            super.setPackageOrComponentEnabled(pkgOrComponent, userId, isPrimary, enabled, userSet);
        }
@@ -12698,36 +12706,37 @@ public class NotificationManagerService extends SystemService {
            }
        }
        @FlaggedApi(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION)
        @GuardedBy("mNotificationLock")
        public void setAdjustmentTypeSupportedState(ManagedServiceInfo info,
        public void setAdjustmentTypeSupportedState(@UserIdInt int userId,
                @Adjustment.Keys String key, boolean supported) {
            if (!android.service.notification.Flags.notificationClassification()) {
            if (!(android.service.notification.Flags.notificationClassification()
                    || android.app.Flags.nmSummarizationUi()
                    || android.app.Flags.nmSummarization())) {
                return;
            }
            setNasUnsupportedDefaults(info.userid);
            HashSet<String> disabledAdjustments = mNasUnsupported.get(info.userid);
            HashSet<String> disabledAdjustments =
                    mNasUnsupported.getOrDefault(userId, new HashSet<>());
            if (supported) {
                disabledAdjustments.remove(key);
            } else {
                disabledAdjustments.add(key);
            }
            mNasUnsupported.put(info.userid, disabledAdjustments);
            mNasUnsupported.put(userId, disabledAdjustments);
            handleSavePolicyFile();
        }
        @FlaggedApi(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION)
        @GuardedBy("mNotificationLock")
        public @NonNull Set<String> getUnsupportedAdjustments(@UserIdInt int userId) {
            if (!android.service.notification.Flags.notificationClassification()) {
            if (!(android.service.notification.Flags.notificationClassification()
                    || android.app.Flags.nmSummarizationUi()
                    || android.app.Flags.nmSummarization())) {
                return new HashSet<>();
            }
            setNasUnsupportedDefaults(userId);
            return mNasUnsupported.get(userId);
            return mNasUnsupported.getOrDefault(userId, new HashSet<>());
        }
        private void setNasUnsupportedDefaults(@UserIdInt int userId) {
            if (mNasUnsupported != null && !mNasUnsupported.containsKey(userId)) {
            if (mNasUnsupported != null) {
                mNasUnsupported.put(userId, new HashSet(List.of(mDefaultUnsupportedAdjustments)));
                handleSavePolicyFile();
            }
@@ -12740,10 +12749,8 @@ public class NotificationManagerService extends SystemService {
                return;
            }
            synchronized (mLock) {
                if (mNasUnsupported.containsKey(approvedUserId)) {
                    out.attribute(null, ATT_NAS_UNSUPPORTED,
                            TextUtils.join(",", mNasUnsupported.get(approvedUserId)));
                }
                out.attribute(null, ATT_NAS_UNSUPPORTED, TextUtils.join(",",
                        mNasUnsupported.getOrDefault(approvedUserId, new HashSet<>())));
            }
        }
@@ -12756,8 +12763,15 @@ public class NotificationManagerService extends SystemService {
            if (ManagedServices.TAG_MANAGED_SERVICES.equals(tag)) {
                final String types = XmlUtils.readStringAttribute(parser, ATT_NAS_UNSUPPORTED);
                synchronized (mLock) {
                    if (types == null) {
                        setNasUnsupportedDefaults(approvedUserId);
                    } else {
                        if (!TextUtils.isEmpty(types)) {
                        mNasUnsupported.put(approvedUserId, new HashSet(List.of(types.split(","))));
                            mNasUnsupported.put(approvedUserId,
                                    new HashSet(List.of(types.split(","))));
                        } else {
                            mNasUnsupported.put(approvedUserId, new HashSet());
                        }
                    }
                }
            }
+17 −10
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static android.service.notification.Adjustment.KEY_TYPE;
import static android.service.notification.Adjustment.TYPE_CONTENT_RECOMMENDATION;
import static android.service.notification.Adjustment.TYPE_NEWS;
import static android.service.notification.Adjustment.TYPE_PROMOTION;
import static android.service.notification.Adjustment.TYPE_SOCIAL_MEDIA;

import static com.android.server.notification.NotificationManagerService.DEFAULT_ALLOWED_ADJUSTMENTS;

@@ -611,7 +612,8 @@ public class NotificationAssistantsTest extends UiServiceTestCase {

        ManagedServices.ManagedServiceInfo info =
                mAssistants.new ManagedServiceInfo(null, mCn, userId, false, null, 35, 2345256);
        mAssistants.setAdjustmentTypeSupportedState(info, Adjustment.KEY_NOT_CONVERSATION, false);
        mAssistants.setAdjustmentTypeSupportedState(
                info.userid, Adjustment.KEY_NOT_CONVERSATION, false);

        assertThat(mAssistants.getUnsupportedAdjustments(userId)).contains(
                Adjustment.KEY_NOT_CONVERSATION);
@@ -632,7 +634,8 @@ public class NotificationAssistantsTest extends UiServiceTestCase {

        ManagedServices.ManagedServiceInfo info =
                mAssistants.new ManagedServiceInfo(null, mCn, userId, false, null, 35, 2345256);
        mAssistants.setAdjustmentTypeSupportedState(info, Adjustment.KEY_NOT_CONVERSATION, false);
        mAssistants.setAdjustmentTypeSupportedState(
                info.userid, Adjustment.KEY_NOT_CONVERSATION, false);

        writeXmlAndReload(USER_ALL);

@@ -654,7 +657,6 @@ public class NotificationAssistantsTest extends UiServiceTestCase {
        assertNotNull(current);

        writeXmlAndReload(USER_ALL);

        assertThat(mAssistants.getUnsupportedAdjustments(userId).size()).isEqualTo(0);
    }

@@ -707,26 +709,29 @@ public class NotificationAssistantsTest extends UiServiceTestCase {
    @Test
    @EnableFlags(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION)
    public void testSetAssistantAdjustmentKeyTypeState_allow() {
        assertThat(mAssistants.getAllowedClassificationTypes()).asList()
                .containsExactly(TYPE_PROMOTION);
        mAssistants.setAssistantAdjustmentKeyTypeState(TYPE_CONTENT_RECOMMENDATION, false);
        assertThat(mAssistants.getAllowedClassificationTypes())
                .asList().doesNotContain(TYPE_CONTENT_RECOMMENDATION);

        mAssistants.setAssistantAdjustmentKeyTypeState(TYPE_CONTENT_RECOMMENDATION, true);

        assertThat(mAssistants.getAllowedClassificationTypes()).asList()
                .containsExactlyElementsIn(List.of(TYPE_PROMOTION, TYPE_CONTENT_RECOMMENDATION));
                .contains(TYPE_CONTENT_RECOMMENDATION);
    }

    @Test
    @EnableFlags(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION)
    public void testSetAssistantAdjustmentKeyTypeState_disallow() {
        mAssistants.setAssistantAdjustmentKeyTypeState(TYPE_PROMOTION, false);
        assertThat(mAssistants.getAllowedClassificationTypes()).isEmpty();
        assertThat(mAssistants.getAllowedClassificationTypes())
                .asList().doesNotContain(TYPE_PROMOTION);
    }

    @Test
    @EnableFlags(Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI)
    public void testDisallowAdjustmentKeyType_readWriteXml() throws Exception {
        mAssistants.loadDefaultsFromConfig(true);
        mAssistants.setAssistantAdjustmentKeyTypeState(TYPE_SOCIAL_MEDIA, false);
        mAssistants.setAssistantAdjustmentKeyTypeState(TYPE_PROMOTION, false);
        mAssistants.setAssistantAdjustmentKeyTypeState(TYPE_NEWS, true);
        mAssistants.setAssistantAdjustmentKeyTypeState(TYPE_CONTENT_RECOMMENDATION, true);
@@ -745,7 +750,8 @@ public class NotificationAssistantsTest extends UiServiceTestCase {
        writeXmlAndReload(USER_ALL);

        assertThat(mAssistants.getAllowedClassificationTypes()).asList()
                .containsExactly(TYPE_PROMOTION);
                .containsExactlyElementsIn(List.of(TYPE_PROMOTION, TYPE_NEWS, TYPE_SOCIAL_MEDIA,
                        TYPE_CONTENT_RECOMMENDATION));
    }

    @Test
@@ -860,8 +866,9 @@ public class NotificationAssistantsTest extends UiServiceTestCase {
                mAssistants.new ManagedServiceInfo(null, mCn, userId, false, null, 35, 2345256);

        // Ensure bundling is enabled
        mAssistants.setAdjustmentTypeSupportedState(info, KEY_TYPE, true);
        mAssistants.setAdjustmentTypeSupportedState(info.userid, KEY_TYPE, true);
        // Enable these specific bundle types
        mAssistants.setAssistantAdjustmentKeyTypeState(TYPE_SOCIAL_MEDIA, false);
        mAssistants.setAssistantAdjustmentKeyTypeState(TYPE_PROMOTION, false);
        mAssistants.setAssistantAdjustmentKeyTypeState(TYPE_NEWS, true);
        mAssistants.setAssistantAdjustmentKeyTypeState(TYPE_CONTENT_RECOMMENDATION, true);
@@ -894,7 +901,7 @@ public class NotificationAssistantsTest extends UiServiceTestCase {
                .isEqualTo(NotificationProtoEnums.TYPE_CONTENT_RECOMMENDATION);

        // Disable the top-level bundling setting
        mAssistants.setAdjustmentTypeSupportedState(info, KEY_TYPE, false);
        mAssistants.setAdjustmentTypeSupportedState(info.userid, KEY_TYPE, false);
        // Enable these specific bundle types
        mAssistants.setAssistantAdjustmentKeyTypeState(TYPE_PROMOTION, true);
        mAssistants.setAssistantAdjustmentKeyTypeState(TYPE_NEWS, false);