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

Commit 908201e1 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Optionally make VICs bubble

Test: atest
Bug: 149696991
Change-Id: Iec86ac860a51bcecde70d7abd7feeb5f9319ebfa
parent 02971455
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -8591,6 +8591,15 @@ public final class Settings {
         */
        public static final String NOTIFICATION_HISTORY_ENABLED = "notification_history_enabled";
        /**
         * When enabled conversations marked as favorites will be set to bubble.
         *
         * The value 1 - enable, 0 - disable
         * @hide
         */
        public static final String BUBBLE_IMPORTANT_CONVERSATIONS
                = "bubble_important_conversations";
        /**
         * Whether notifications are dismissed by a right-to-left swipe (instead of a left-to-right
         * swipe).
+15 −4
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static android.app.NotificationManager.IMPORTANCE_LOW;
import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
import static android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_DYNAMIC;
import static android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED;
import static android.provider.Settings.Secure.BUBBLE_IMPORTANT_CONVERSATIONS;

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

@@ -112,7 +113,8 @@ public class NotificationConversationInfo extends LinearLayout implements
    boolean mSkipPost = false;

    @Retention(SOURCE)
    @IntDef({ACTION_BUBBLE, ACTION_HOME, ACTION_FAVORITE, ACTION_SNOOZE, ACTION_MUTE})
    @IntDef({ACTION_BUBBLE, ACTION_HOME, ACTION_FAVORITE, ACTION_SNOOZE, ACTION_MUTE,
            ACTION_UNBUBBLE, ACTION_SETTINGS})
    private @interface Action {}
    static final int ACTION_BUBBLE = 0;
    static final int ACTION_HOME = 1;
@@ -128,8 +130,6 @@ public class NotificationConversationInfo extends LinearLayout implements
            mBubbleController.onUserDemotedBubbleFromNotification(mEntry);
        } else {
            mBubbleController.onUserCreatedBubbleFromNotification(mEntry);
            Settings.Global.putInt(
                    mContext.getContentResolver(), Settings.Global.NOTIFICATION_BUBBLES, 1);
        }
        closeControls(v, true);
    };
@@ -225,7 +225,9 @@ public class NotificationConversationInfo extends LinearLayout implements
            mShortcutInfo = shortcuts.get(0);
        }

        mIsBubbleable = mEntry.getBubbleMetadata() != null;
        mIsBubbleable = mEntry.getBubbleMetadata() != null
            && Settings.Global.getInt(mContext.getContentResolver(),
                Settings.Global.NOTIFICATION_BUBBLES, 0) == 1;
        mStartedAsBubble = mEntry.isBubble();

        createConversationChannelIfNeeded();
@@ -382,6 +384,11 @@ public class NotificationConversationInfo extends LinearLayout implements
        ((TextView) findViewById(R.id.pkg_name)).setText(mAppName);
    }

    private boolean bubbleImportantConversations() {
        return Settings.Secure.getInt(mContext.getContentResolver(),
                BUBBLE_IMPORTANT_CONVERSATIONS, 1) == 1;
    }

    private void bindDelegate() {
        TextView delegateView = findViewById(R.id.delegate_name);

@@ -575,6 +582,10 @@ public class NotificationConversationInfo extends LinearLayout implements
                    case ACTION_FAVORITE:
                        mChannelToUpdate.setImportantConversation(
                                !mChannelToUpdate.isImportantConversation());
                        if (mChannelToUpdate.isImportantConversation()
                                && bubbleImportantConversations()) {
                            mChannelToUpdate.setAllowBubbles(true);
                        }
                        break;
                    case ACTION_MUTE:
                        if (mChannelToUpdate.getImportance() == IMPORTANCE_UNSPECIFIED
+74 −2
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.app.NotificationManager.IMPORTANCE_LOW;
import static android.print.PrintManager.PRINT_SPOOLER_PACKAGE_NAME;
import static android.provider.Settings.Global.NOTIFICATION_BUBBLES;
import static android.provider.Settings.Secure.BUBBLE_IMPORTANT_CONVERSATIONS;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;

@@ -55,6 +57,7 @@ import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Icon;
import android.os.UserHandle;
import android.provider.Settings;
import android.service.notification.StatusBarNotification;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
@@ -449,6 +452,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase {

    @Test
    public void testBindNotification_bubbleActionVisibleWhenCanBubble()  {
        Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, 1);
        mNotificationInfo.bindNotification(
                mShortcutManager,
                mLauncherApps,
@@ -469,7 +473,8 @@ public class NotificationConversationInfoTest extends SysuiTestCase {
    }

    @Test
    public void testBindNotification_bubbleActionVisibleWhenCannotBubble()  {
    public void testBindNotification_bubbleAction_noBubbleMetadata()  {
        Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, 1);
        mNotificationInfo.bindNotification(
                mShortcutManager,
                mLauncherApps,
@@ -489,6 +494,28 @@ public class NotificationConversationInfoTest extends SysuiTestCase {
        assertEquals(View.GONE, bubbleView.getVisibility());
    }

    @Test
    public void testBindNotification_bubbleActionGloballyOff()  {
        Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, 0);
        mNotificationInfo.bindNotification(
                mShortcutManager,
                mLauncherApps,
                mMockPackageManager,
                mMockINotificationManager,
                mVisualStabilityManager,
                TEST_PACKAGE_NAME,
                mNotificationChannel,
                mBubbleEntry,
                null,
                null,
                null,
                mIconFactory,
                true);

        View bubbleView = mNotificationInfo.findViewById(R.id.bubble);
        assertEquals(View.GONE, bubbleView.getVisibility());
    }

    @Test
    public void testAddToHome() throws Exception {
        when(mShortcutManager.isRequestPinShortcutSupported()).thenReturn(true);
@@ -550,6 +577,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase {

    @Test
    public void testBubble_promotesBubble() throws Exception {
        Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, 1);
        mNotificationChannel.setAllowBubbles(false);
        mConversationChannel.setAllowBubbles(false);

@@ -584,6 +612,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase {

    @Test
    public void testBubble_demotesBubble() throws Exception {
        Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, 1);
        mBubbleEntry.getSbn().getNotification().flags |= FLAG_BUBBLE;

        mNotificationInfo.bindNotification(
@@ -617,6 +646,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase {

    @Test
    public void testBubble_noChannelChange() throws Exception {
        Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, 1);
        mNotificationInfo.bindNotification(
                mShortcutManager,
                mLauncherApps,
@@ -645,7 +675,48 @@ public class NotificationConversationInfoTest extends SysuiTestCase {
    }

    @Test
    public void testFavorite_favorite() throws Exception {
    public void testFavorite_favorite_noBubble() throws Exception {
        Settings.Secure.putInt(mContext.getContentResolver(),
                BUBBLE_IMPORTANT_CONVERSATIONS, 0);
        mNotificationChannel.setAllowBubbles(false);
        mConversationChannel.setAllowBubbles(false);
        mNotificationInfo.bindNotification(
                mShortcutManager,
                mLauncherApps,
                mMockPackageManager,
                mMockINotificationManager,
                mVisualStabilityManager,
                TEST_PACKAGE_NAME,
                mNotificationChannel,
                mEntry,
                null,
                null,
                null,
                mIconFactory,
                true);

        ImageButton fave = mNotificationInfo.findViewById(R.id.fave);
        assertEquals(mContext.getString(R.string.notification_conversation_unfavorite),
                fave.getContentDescription().toString());

        fave.performClick();
        mTestableLooper.processAllMessages();

        ArgumentCaptor<NotificationChannel> captor =
                ArgumentCaptor.forClass(NotificationChannel.class);
        verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
                anyString(), anyInt(), captor.capture());
        assertTrue(captor.getValue().isImportantConversation());
        assertFalse(captor.getValue().canBubble());
        verify(mBubbleController, never()).onUserCreatedBubbleFromNotification(mEntry);
    }

    @Test
    public void testFavorite_favorite_bubble() throws Exception {
        Settings.Secure.putInt(mContext.getContentResolver(),
                BUBBLE_IMPORTANT_CONVERSATIONS, 1);
        mNotificationChannel.setAllowBubbles(false);
        mConversationChannel.setAllowBubbles(false);
        mNotificationInfo.bindNotification(
                mShortcutManager,
                mLauncherApps,
@@ -673,6 +744,7 @@ public class NotificationConversationInfoTest extends SysuiTestCase {
        verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
                anyString(), anyInt(), captor.capture());
        assertTrue(captor.getValue().isImportantConversation());
        assertTrue(captor.getValue().canBubble());
    }

    @Test