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

Commit 042ebb1d authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge changes from topics "jr-all-convo", "jr-default-vic"

* changes:
  Optionally make VICs bubble
  Add method to retrieve all conversations
parents 724502fd 908201e1
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -88,6 +88,7 @@ interface INotificationManager
    void createNotificationChannelGroups(String pkg, in ParceledListSlice channelGroupList);
    void createNotificationChannels(String pkg, in ParceledListSlice channelsList);
    void createNotificationChannelsForPackage(String pkg, int uid, in ParceledListSlice channelsList);
    ParceledListSlice getConversations(boolean onlyImportant);
    ParceledListSlice getConversationsForPackage(String pkg, int uid);
    ParceledListSlice getNotificationChannelGroupsForPackage(String pkg, int uid, boolean includeDeleted);
    NotificationChannelGroup getNotificationChannelGroupForPackage(String groupId, String pkg, int uid);
+9 −0
Original line number Diff line number Diff line
@@ -8594,6 +8594,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).
+26 −2
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ public final class ConversationChannelWrapper implements Parcelable {
    private CharSequence mGroupLabel;
    private CharSequence mParentChannelLabel;
    private ShortcutInfo mShortcutInfo;
    private String mPkg;
    private int mUid;

    public ConversationChannelWrapper() {}

@@ -41,6 +43,8 @@ public final class ConversationChannelWrapper implements Parcelable {
        mGroupLabel = in.readCharSequence();
        mParentChannelLabel = in.readCharSequence();
        mShortcutInfo = in.readParcelable(ShortcutInfo.class.getClassLoader());
        mPkg = in.readStringNoHelper();
        mUid = in.readInt();
    }

    @Override
@@ -49,6 +53,8 @@ public final class ConversationChannelWrapper implements Parcelable {
        dest.writeCharSequence(mGroupLabel);
        dest.writeCharSequence(mParentChannelLabel);
        dest.writeParcelable(mShortcutInfo, flags);
        dest.writeStringNoHelper(mPkg);
        dest.writeInt(mUid);
    }

    @Override
@@ -103,6 +109,22 @@ public final class ConversationChannelWrapper implements Parcelable {
        mShortcutInfo = shortcutInfo;
    }

    public String getPkg() {
        return mPkg;
    }

    public void setPkg(String pkg) {
        mPkg = pkg;
    }

    public int getUid() {
        return mUid;
    }

    public void setUid(int uid) {
        mUid = uid;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
@@ -111,12 +133,14 @@ public final class ConversationChannelWrapper implements Parcelable {
        return Objects.equals(getNotificationChannel(), that.getNotificationChannel()) &&
                Objects.equals(getGroupLabel(), that.getGroupLabel()) &&
                Objects.equals(getParentChannelLabel(), that.getParentChannelLabel()) &&
                Objects.equals(getShortcutInfo(), that.getShortcutInfo());
                Objects.equals(getShortcutInfo(), that.getShortcutInfo()) &&
                Objects.equals(getPkg(), that.getPkg()) &&
                getUid() == that.getUid();
    }

    @Override
    public int hashCode() {
        return Objects.hash(getNotificationChannel(), getGroupLabel(), getParentChannelLabel(),
                getShortcutInfo());
                getShortcutInfo(), getPkg(), getUid());
    }
}
+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);

@@ -579,6 +586,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
Loading