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

Commit 5dad660c authored by Chloris Kuo's avatar Chloris Kuo
Browse files

Persist automatic setting in long press menu

Test: atest NotificationInfoTest
Bug: 165946866
Change-Id: Ia4a4734878f9c1f94bedccfcb40a5f32644b7431
parent c468bba1
Loading
Loading
Loading
Loading
+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