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

Commit 2e4082e3 authored by Chloris Kuo's avatar Chloris Kuo Committed by Android (Google) Code Review
Browse files

Merge changes from topic "Feedback-UnlockImportance"

* changes:
  Persist automatic setting in long press menu
  Reset notification channel importance
parents 731f703d 5dad660c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -96,6 +96,8 @@ interface INotificationManager
    NotificationChannelGroup getPopulatedNotificationChannelGroupForPackage(String pkg, int uid, String groupId, boolean includeDeleted);
    void updateNotificationChannelGroupForPackage(String pkg, int uid, in NotificationChannelGroup group);
    void updateNotificationChannelForPackage(String pkg, int uid, in NotificationChannel channel);
    void unlockNotificationChannel(String pkg, int uid, String channelId);
    void unlockAllNotificationChannels();
    NotificationChannel getNotificationChannel(String callingPkg, int userId, String pkg, String channelId);
    NotificationChannel getConversationNotificationChannel(String callingPkg, int userId, String pkg, String channelId, boolean returnParentIfNoConversationChannel, String conversationId);
    void createConversationNotificationChannelForPackage(String pkg, int uid, in NotificationChannel parentChannel, String conversationId);
+5 −3
Original line number Diff line number Diff line
@@ -236,6 +236,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
                            NotificationChannel.DEFAULT_CHANNEL_ID)
                    && numTotalChannels == 1;
        }
        mIsAutomaticChosen = getAlertingBehavior() == BEHAVIOR_AUTOMATIC;

        bindHeader();
        bindChannelDetails();
@@ -658,13 +659,14 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
            try {
                if (mChannelToUpdate != null) {
                    if (mUnlockImportance) {
                        mChannelToUpdate.unlockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
                        mINotificationManager.unlockNotificationChannel(
                                mPackageName, mAppUid, mChannelToUpdate.getId());
                    } else {
                        mChannelToUpdate.setImportance(mNewImportance);
                        mChannelToUpdate.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
                    }
                        mINotificationManager.updateNotificationChannelForPackage(
                                mPackageName, mAppUid, mChannelToUpdate);
                    }
                } else {
                    // For notifications with more than one channel, update notification enabled
                    // state. If the importance was lowered, we disable notifications.
+32 −4
Original line number Diff line number Diff line
@@ -859,6 +859,33 @@ public class NotificationInfoTest extends SysuiTestCase {
                anyString(), eq(TEST_UID), any());
    }

    @Test
    public void testHandleCloseControls_persistAutomatic()
            throws Exception {
        mNotificationChannel.unlockFields(USER_LOCKED_IMPORTANCE);
        mNotificationInfo.bindNotification(
                mMockPackageManager,
                mMockINotificationManager,
                mOnUserInteractionCallback,
                mChannelEditorDialogController,
                TEST_PACKAGE_NAME,
                mNotificationChannel,
                mNotificationChannelSet,
                mEntry,
                null,
                null,
                mUiEventLogger,
                true,
                false,
                true,
                true);

        mNotificationInfo.handleCloseControls(true, false);
        mTestableLooper.processAllMessages();
        verify(mMockINotificationManager, times(1)).unlockNotificationChannel(
                anyString(), eq(TEST_UID), any());
    }

    @Test
    public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnchanged()
            throws Exception {
@@ -1015,16 +1042,17 @@ public class NotificationInfoTest extends SysuiTestCase {
                mUiEventLogger,
                true,
                false,
                false,
                false);
                true,
                true);

        mNotificationInfo.findViewById(R.id.automatic).performClick();
        mNotificationInfo.findViewById(R.id.done).performClick();
        mNotificationInfo.handleCloseControls(true, false);

        mTestableLooper.processAllMessages();
        assertTrue(mNotificationChannel.hasUserSetImportance());
        assertEquals(mNotificationChannel.getImportance(), IMPORTANCE_DEFAULT);
        verify(mMockINotificationManager, times(1)).unlockNotificationChannel(
                anyString(), eq(TEST_UID), any());
        assertEquals(IMPORTANCE_DEFAULT, mNotificationChannel.getImportance());
    }

    @Test
+14 −0
Original line number Diff line number Diff line
@@ -3525,6 +3525,20 @@ public class NotificationManagerService extends SystemService {
            updateNotificationChannelInt(pkg, uid, channel, false);
        }

        @Override
        public void unlockNotificationChannel(String pkg, int uid, String channelId) {
            checkCallerIsSystemOrSystemUiOrShell("Caller not system or sysui or shell");
            mPreferencesHelper.unlockNotificationChannelImportance(pkg, uid, channelId);
            handleSavePolicyFile();
        }

        @Override
        public void unlockAllNotificationChannels() {
            checkCallerIsSystem();
            mPreferencesHelper.unlockAllNotificationChannels();
            handleSavePolicyFile();
        }

        @Override
        public ParceledListSlice<NotificationChannel> getNotificationChannelsForPackage(String pkg,
                int uid, boolean includeDeleted) {
+30 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.notification;

import static android.app.AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
import static android.app.NotificationChannel.PLACEHOLDER_CONVERSATION_ID;
import static android.app.NotificationChannel.USER_LOCKED_IMPORTANCE;
import static android.app.NotificationManager.BUBBLE_PREFERENCE_ALL;
import static android.app.NotificationManager.BUBBLE_PREFERENCE_NONE;
import static android.app.NotificationManager.IMPORTANCE_NONE;
@@ -955,6 +956,23 @@ public class PreferencesHelper implements RankingConfig {
        channel.unlockFields(channel.getUserLockedFields());
    }

    void unlockNotificationChannelImportance(String pkg, int uid, String updatedChannelId) {
        Objects.requireNonNull(updatedChannelId);
        synchronized (mPackagePreferences) {
            PackagePreferences r = getOrCreatePackagePreferencesLocked(pkg, uid);
            if (r == null) {
                throw new IllegalArgumentException("Invalid package");
            }

            NotificationChannel channel = r.channels.get(updatedChannelId);
            if (channel == null || channel.isDeleted()) {
                throw new IllegalArgumentException("Channel does not exist");
            }
            channel.unlockFields(USER_LOCKED_IMPORTANCE);
        }
    }


    @Override
    public void updateNotificationChannel(String pkg, int uid, NotificationChannel updatedChannel,
            boolean fromUser) {
@@ -2389,6 +2407,18 @@ public class PreferencesHelper implements RankingConfig {
        return mBadgingEnabled.get(userId, DEFAULT_SHOW_BADGE);
    }

    public void unlockAllNotificationChannels() {
        synchronized (mPackagePreferences) {
            final int numPackagePreferences = mPackagePreferences.size();
            for (int i = 0; i < numPackagePreferences; i++) {
                final PackagePreferences r = mPackagePreferences.valueAt(i);
                for (NotificationChannel channel : r.channels.values()) {
                    channel.unlockFields(USER_LOCKED_IMPORTANCE);
                }
            }
        }
    }

    private void updateConfig() {
        mRankingHandler.requestSort();
    }
Loading