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

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

Keys are NAS supported, not user unsupported by default

Rename xml attrs to make that more clear and to fix the
bad data stored by the previous cl

Test: NotificationAssistantServiceTest
Bug: 388485761
Flag: android.service.notification.notification_classification
Change-Id: I8fdddfc923aa26b98abfbf58ee8dfd681cb49ecb
parent ef515d32
Loading
Loading
Loading
Loading
+19 −13
Original line number Diff line number Diff line
@@ -762,7 +762,7 @@ public class NotificationManagerService extends SystemService {
    private int mWarnRemoteViewsSizeBytes;
    private int mStripRemoteViewsSizeBytes;
    private String[] mDefaultUnsupportedAdjustments;
    protected String[] mDefaultUnsupportedAdjustments;
    @VisibleForTesting
    protected boolean mShowReviewPermissionsNotification;
@@ -4377,8 +4377,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())));
            }
        }
@@ -7214,6 +7214,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()
@@ -11867,9 +11868,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();
@@ -11965,9 +11966,6 @@ public class NotificationManagerService extends SystemService {
                }
            } else {
                mAllowedAdjustmentKeyTypes.addAll(List.of(DEFAULT_ALLOWED_ADJUSTMENT_KEY_TYPES));
                if (mDefaultUnsupportedAdjustments != null) {
                    mAllowedAdjustments.removeAll(List.of(mDefaultUnsupportedAdjustments));
                }
            }
        }
@@ -12487,7 +12485,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);
@@ -12528,8 +12526,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 {
@@ -12545,7 +12543,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
@@ -12658,7 +12664,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);