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

Commit d7fcf05d authored by Mady Mellor's avatar Mady Mellor
Browse files

Specify explicit actions for bubble / unbubble

It's not always safe to flip the channel setting because the notif might
be allowed to bubble, but is not currently displayed as bubble. In that
case the button would say "show as bubble" but the code would flip the
setting to false, doing the opposite of the user action.

This CL specifies actions for bubble / unbubble and only commits the
channel change if the setting actually changed.

Test: atest NotificationConversationInfo
Fixes: 148425750
Bug: 148424396
Change-Id: I6f561cf388d2595df53ac41b9a183f6c50976d21
parent d21c45fc
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import static com.android.systemui.statusbar.notification.row.NotificationConver
import static com.android.systemui.statusbar.notification.row.NotificationConversationInfo.UpdateChannelRunnable.ACTION_HOME;
import static com.android.systemui.statusbar.notification.row.NotificationConversationInfo.UpdateChannelRunnable.ACTION_MUTE;
import static com.android.systemui.statusbar.notification.row.NotificationConversationInfo.UpdateChannelRunnable.ACTION_SNOOZE;
import static com.android.systemui.statusbar.notification.row.NotificationConversationInfo.UpdateChannelRunnable.ACTION_UNBUBBLE;

import static java.lang.annotation.RetentionPolicy.SOURCE;

@@ -121,7 +122,7 @@ public class NotificationConversationInfo extends LinearLayout implements
    boolean mSkipPost = false;

    private OnClickListener mOnBubbleClick = v -> {
        mSelectedAction = ACTION_BUBBLE;
        mSelectedAction = mStartedAsBubble ? ACTION_UNBUBBLE : ACTION_BUBBLE;
        if (mStartedAsBubble) {
            mBubbleController.onUserDemotedBubbleFromNotification(mEntry);
        } else {
@@ -586,6 +587,7 @@ public class NotificationConversationInfo extends LinearLayout implements
        static final int ACTION_SNOOZE = 3;
        static final int ACTION_MUTE = 4;
        static final int ACTION_DEMOTE = 5;
        static final int ACTION_UNBUBBLE = 6;

        private final INotificationManager mINotificationManager;
        private final String mAppPkg;
@@ -606,9 +608,17 @@ public class NotificationConversationInfo extends LinearLayout implements
        @Override
        public void run() {
            try {
                boolean channelSettingChanged = mAction != ACTION_HOME && mAction != ACTION_SNOOZE;
                switch (mAction) {
                    case ACTION_BUBBLE:
                        mChannelToUpdate.setAllowBubbles(!mChannelToUpdate.canBubble());
                    case ACTION_UNBUBBLE:
                        boolean canBubble = mAction == ACTION_BUBBLE;
                        if (mChannelToUpdate.canBubble() != canBubble) {
                            channelSettingChanged = true;
                            mChannelToUpdate.setAllowBubbles(canBubble);
                        } else {
                            channelSettingChanged = false;
                        }
                        break;
                    case ACTION_FAVORITE:
                        // TODO: extend beyond DND
@@ -629,7 +639,7 @@ public class NotificationConversationInfo extends LinearLayout implements

                }

                if (mAction != ACTION_HOME && mAction != ACTION_SNOOZE) {
                if (channelSettingChanged) {
                    mINotificationManager.updateNotificationChannelForPackage(
                            mAppPkg, mAppUid, mChannelToUpdate);
                }
+28 −1
Original line number Diff line number Diff line
@@ -58,7 +58,6 @@ import android.service.notification.StatusBarNotification;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.util.Slog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
@@ -600,6 +599,34 @@ public class NotificationConversationInfoTest extends SysuiTestCase {
        assertFalse(captor.getValue().canBubble());
    }

    @Test
    public void testBubble_noChannelChange() throws Exception {
        mNotificationInfo.bindNotification(
                mShortcutManager,
                mLauncherApps,
                mMockPackageManager,
                mMockINotificationManager,
                mVisualStabilityManager,
                TEST_PACKAGE_NAME,
                mNotificationChannel,
                mBubbleEntry,
                null,
                null,
                null,
                true);

        assertFalse(mBubbleEntry.isBubble());
        assertTrue(mNotificationChannel.canBubble());

        // Promote it
        mNotificationInfo.findViewById(R.id.bubble).performClick();
        mTestableLooper.processAllMessages();

        verify(mBubbleController, times(1)).onUserCreatedBubbleFromNotification(mBubbleEntry);
        verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
                anyString(), anyInt(), any());
    }

    @Test
    public void testFavorite_favorite() throws Exception {
        mNotificationInfo.bindNotification(