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

Commit 702b4919 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add MessagingStyle#isGroupConversation()."

parents 1396ffee 9ac617c5
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -5200,6 +5200,7 @@ package android.app {
    field public static final java.lang.String EXTRA_CONVERSATION_TITLE = "android.conversationTitle";
    field public static final java.lang.String EXTRA_HISTORIC_MESSAGES = "android.messages.historic";
    field public static final java.lang.String EXTRA_INFO_TEXT = "android.infoText";
    field public static final java.lang.String EXTRA_IS_GROUP_CONVERSATION = "android.isGroupConversation";
    field public static final deprecated java.lang.String EXTRA_LARGE_ICON = "android.largeIcon";
    field public static final java.lang.String EXTRA_LARGE_ICON_BIG = "android.largeIcon.big";
    field public static final java.lang.String EXTRA_MEDIA_SESSION = "android.mediaSession";
@@ -5483,7 +5484,9 @@ package android.app {
    method public java.util.List<android.app.Notification.MessagingStyle.Message> getHistoricMessages();
    method public java.util.List<android.app.Notification.MessagingStyle.Message> getMessages();
    method public java.lang.CharSequence getUserDisplayName();
    method public boolean isGroupConversation();
    method public android.app.Notification.MessagingStyle setConversationTitle(java.lang.CharSequence);
    method public android.app.Notification.MessagingStyle setGroupConversation(boolean);
    field public static final int MAXIMUM_RETAINED_MESSAGES = 25; // 0x19
  }
+34 −7
Original line number Diff line number Diff line
@@ -1089,6 +1089,12 @@ public class Notification implements Parcelable
     */
    public static final String EXTRA_HISTORIC_MESSAGES = "android.messages.historic";

    /**
     * {@link #extras} key: whether the {@link android.app.Notification.MessagingStyle} notification
     * represents a group conversation.
     */
    public static final String EXTRA_IS_GROUP_CONVERSATION = "android.isGroupConversation";

    /**
     * {@link #extras} key: whether the notification should be colorized as
     * supplied to {@link Builder#setColorized(boolean)}}.
@@ -5960,9 +5966,10 @@ public class Notification implements Parcelable
        public static final int MAXIMUM_RETAINED_MESSAGES = 25;

        CharSequence mUserDisplayName;
        CharSequence mConversationTitle;
        @Nullable CharSequence mConversationTitle;
        List<Message> mMessages = new ArrayList<>();
        List<Message> mHistoricMessages = new ArrayList<>();
        boolean mIsGroupConversation;

        MessagingStyle() {
        }
@@ -5985,20 +5992,20 @@ public class Notification implements Parcelable
        }

        /**
         * Sets the title to be displayed on this conversation. This should only be used for
         * group messaging and left unset for one-on-one conversations.
         * @param conversationTitle
         * Sets the title to be displayed on this conversation. May be set to {@code null}.
         *
         * @param conversationTitle A name for the conversation, or {@code null}
         * @return this object for method chaining.
         */
        public MessagingStyle setConversationTitle(CharSequence conversationTitle) {
        public MessagingStyle setConversationTitle(@Nullable CharSequence conversationTitle) {
            mConversationTitle = conversationTitle;
            return this;
        }

        /**
         * Return the title to be displayed on this conversation. Can be <code>null</code> and
         * should be for one-on-one conversations
         * Return the title to be displayed on this conversation. May return {@code null}.
         */
        @Nullable
        public CharSequence getConversationTitle() {
            return mConversationTitle;
        }
@@ -6074,6 +6081,24 @@ public class Notification implements Parcelable
            return mHistoricMessages;
        }

        /**
         * Sets whether this conversation notification represents a group.
         * @param isGroupConversation {@code true} if the conversation represents a group,
         * {@code false} otherwise.
         * @return this object for method chaining
         */
        public MessagingStyle setGroupConversation(boolean isGroupConversation) {
            mIsGroupConversation = isGroupConversation;
            return this;
        }

        /**
         * Returns {@code true} if this notification represents a group conversation.
         */
        public boolean isGroupConversation() {
            return mIsGroupConversation;
        }

        /**
         * @hide
         */
@@ -6094,6 +6119,7 @@ public class Notification implements Parcelable
            }

            fixTitleAndTextExtras(extras);
            extras.putBoolean(EXTRA_IS_GROUP_CONVERSATION, mIsGroupConversation);
        }

        private void fixTitleAndTextExtras(Bundle extras) {
@@ -6136,6 +6162,7 @@ public class Notification implements Parcelable
            mMessages = Message.getMessagesFromBundleArray(messages);
            Parcelable[] histMessages = extras.getParcelableArray(EXTRA_HISTORIC_MESSAGES);
            mHistoricMessages = Message.getMessagesFromBundleArray(histMessages);
            mIsGroupConversation = extras.getBoolean(EXTRA_IS_GROUP_CONVERSATION);
        }

        /**
+14 −0
Original line number Diff line number Diff line
@@ -214,6 +214,20 @@ public class NotificationTest {
        assertTrue(n.allPendingIntents.contains(intent));
    }

    @Test
    public void testMessagingStyle_isGroupConversation() {
        Notification.MessagingStyle messagingStyle = new Notification.MessagingStyle("self name")
                .setGroupConversation(true);
        Notification notification = new Notification.Builder(mContext, "test id")
                .setSmallIcon(1)
                .setContentTitle("test title")
                .setStyle(messagingStyle)
                .build();

        assertTrue(messagingStyle.isGroupConversation());
        assertTrue(notification.extras.getBoolean(Notification.EXTRA_IS_GROUP_CONVERSATION));
    }

    private Notification.Builder getMediaNotification() {
        MediaSession session = new MediaSession(mContext, "test");
        return new Notification.Builder(mContext, "color")