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

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

Merge "Keys are NAS supported, not user unsupported by default" into main

parents 9fa5cd45 ad7f9f11
Loading
Loading
Loading
Loading
+19 −13
Original line number Diff line number Diff line
@@ -763,7 +763,7 @@ public class NotificationManagerService extends SystemService {
    private int mWarnRemoteViewsSizeBytes;
    private int mStripRemoteViewsSizeBytes;
    private String[] mDefaultUnsupportedAdjustments;
    protected String[] mDefaultUnsupportedAdjustments;
    @VisibleForTesting
    protected boolean mShowReviewPermissionsNotification;
@@ -4378,8 +4378,8 @@ public class NotificationManagerService extends SystemService {
        public @NonNull List<String> getUnsupportedAdjustmentTypes() {
            checkCallerIsSystemOrSystemUiOrShell();
            synchronized (mNotificationLock) {
                return new ArrayList(mAssistants.mNasUnsupported.getOrDefault(
                        UserHandle.getUserId(Binder.getCallingUid()), new HashSet<>()));
                return new ArrayList(mAssistants.getUnsupportedAdjustments(
                        UserHandle.getUserId(Binder.getCallingUid())));
            }
        }
@@ -7222,6 +7222,7 @@ public class NotificationManagerService extends SystemService {
                    toRemove.add(potentialKey);
                }
                if (notificationClassification() && adjustments.containsKey(KEY_TYPE)) {
                    mAssistants.setNasUnsupportedDefaults(r.getSbn().getNormalizedUserId());
                    if (!mAssistants.isAdjustmentKeyTypeAllowed(adjustments.getInt(KEY_TYPE))) {
                        toRemove.add(potentialKey);
                    } else if (notificationClassificationUi()
@@ -11875,9 +11876,9 @@ public class NotificationManagerService extends SystemService {
        static final String TAG_ENABLED_NOTIFICATION_ASSISTANTS = "enabled_assistants";
        private static final String ATT_TYPES = "types";
        private static final String ATT_DENIED = "denied_adjustments";
        private static final String ATT_DENIED = "user_denied_adjustments";
        private static final String ATT_ENABLED_TYPES = "enabled_key_types";
        private static final String ATT_NAS_UNSUPPORTED = "unsupported_adjustments";
        private static final String ATT_NAS_UNSUPPORTED = "nas_unsupported_adjustments";
        private static final String ATT_TYPES_DENIED_APPS = "types_denied_apps";
        private final Object mLock = new Object();
@@ -11973,9 +11974,6 @@ public class NotificationManagerService extends SystemService {
                }
            } else {
                mAllowedAdjustmentKeyTypes.addAll(List.of(DEFAULT_ALLOWED_ADJUSTMENT_KEY_TYPES));
                if (mDefaultUnsupportedAdjustments != null) {
                    mAllowedAdjustments.removeAll(List.of(mDefaultUnsupportedAdjustments));
                }
            }
        }
@@ -12495,7 +12493,7 @@ public class NotificationManagerService extends SystemService {
                }
            } else {
                if (android.service.notification.Flags.notificationClassification()) {
                    mNasUnsupported.put(userId, new HashSet<>());
                    setNasUnsupportedDefaults(userId);
                }
            }
            super.setPackageOrComponentEnabled(pkgOrComponent, userId, isPrimary, enabled, userSet);
@@ -12536,8 +12534,8 @@ public class NotificationManagerService extends SystemService {
            if (!android.service.notification.Flags.notificationClassification()) {
                return;
            }
            HashSet<String> disabledAdjustments =
                    mNasUnsupported.getOrDefault(info.userid, new HashSet<>());
            setNasUnsupportedDefaults(info.userid);
            HashSet<String> disabledAdjustments = mNasUnsupported.get(info.userid);
            if (supported) {
                disabledAdjustments.remove(key);
            } else {
@@ -12553,7 +12551,15 @@ public class NotificationManagerService extends SystemService {
            if (!android.service.notification.Flags.notificationClassification()) {
                return new HashSet<>();
            }
            return mNasUnsupported.getOrDefault(userId, new HashSet<>());
            setNasUnsupportedDefaults(userId);
            return mNasUnsupported.get(userId);
        }
        private void setNasUnsupportedDefaults(@UserIdInt int userId) {
            if (mNasUnsupported != null && !mNasUnsupported.containsKey(userId)) {
                mNasUnsupported.put(userId, new HashSet(List.of(mDefaultUnsupportedAdjustments)));
                handleSavePolicyFile();
            }
        }
        @Override
@@ -12666,7 +12672,7 @@ public class NotificationManagerService extends SystemService {
                List<String> unsupportedAdjustments = new ArrayList(
                        mNasUnsupported.getOrDefault(
                                UserHandle.getUserId(Binder.getCallingUid()),
                                new HashSet<>())
                                new HashSet(List.of(mDefaultUnsupportedAdjustments)))
                );
                bundlesAllowed = !unsupportedAdjustments.contains(Adjustment.KEY_TYPE);
            }
+5 −3
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package com.android.server.notification;

import static android.os.UserHandle.USER_ALL;
import static android.service.notification.Adjustment.KEY_IMPORTANCE;
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;
@@ -165,6 +166,7 @@ public class NotificationAssistantsTest extends UiServiceTestCase {
        mContext.getOrCreateTestableResources().addOverride(
                com.android.internal.R.string.config_defaultAssistantAccessComponent,
                mCn.flattenToString());
        mNm.mDefaultUnsupportedAdjustments = new String[] {};
        mAssistants = spy(mNm.new NotificationAssistants(mContext, mLock, mUserProfiles, miPm));
        when(mNm.getBinderService()).thenReturn(mINm);
        mContext.ensureTestableResources();
@@ -660,7 +662,7 @@ public class NotificationAssistantsTest extends UiServiceTestCase {
        mAssistants.disallowAdjustmentType(Adjustment.KEY_RANKING_SCORE);
        assertThat(mAssistants.getAllowedAssistantAdjustments())
                .doesNotContain(Adjustment.KEY_RANKING_SCORE);
        assertThat(mAssistants.getAllowedAssistantAdjustments()).contains(Adjustment.KEY_TYPE);
        assertThat(mAssistants.getAllowedAssistantAdjustments()).contains(KEY_TYPE);
    }

    @Test
@@ -856,7 +858,7 @@ public class NotificationAssistantsTest extends UiServiceTestCase {
                mAssistants.new ManagedServiceInfo(null, mCn, userId, false, null, 35, 2345256);

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

        // Disable the top-level bundling setting
        mAssistants.setAdjustmentTypeSupportedState(info, Adjustment.KEY_TYPE, false);
        mAssistants.setAdjustmentTypeSupportedState(info, KEY_TYPE, false);
        // Enable these specific bundle types
        mAssistants.setAssistantAdjustmentKeyTypeState(TYPE_PROMOTION, true);
        mAssistants.setAssistantAdjustmentKeyTypeState(TYPE_NEWS, false);
+2 −0
Original line number Diff line number Diff line
@@ -790,6 +790,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        TestableResources tr = mContext.getOrCreateTestableResources();
        tr.addOverride(com.android.internal.R.string.config_defaultSearchSelectorPackageName,
                SEARCH_SELECTOR_PKG);
        tr.addOverride(R.array.config_notificationDefaultUnsupportedAdjustments,
                new String[] {KEY_TYPE});
        doAnswer(invocation -> {
            mOnPermissionChangeListener = invocation.getArgument(2);