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

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

Merge "Updates to default values" into main

parents e9136277 918f23b3
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;
@@ -492,7 +494,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[] {
@@ -4522,7 +4527,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);
@@ -7023,7 +7028,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);
@@ -7369,6 +7374,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())
@@ -7400,7 +7409,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()
@@ -7411,6 +7421,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);
@@ -12068,8 +12080,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();
@@ -12681,10 +12693,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);
        }
@@ -12717,36 +12725,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();
            }
@@ -12759,10 +12768,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<>())));
            }
        }
@@ -12775,8 +12782,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
@@ -868,8 +874,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);
@@ -902,7 +909,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);