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

Commit 8db41f6b authored by Beverly Tai's avatar Beverly Tai Committed by Android (Google) Code Review
Browse files

Merge "Override equals in Person object"

parents dcf5b75b e98937af
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -7461,7 +7461,11 @@ public class Notification implements Parcelable
                return mRemoteInputHistory;
            }

            private Bundle toBundle() {
            /**
             * @hide
             */
            @VisibleForTesting
            public Bundle toBundle() {
                Bundle bundle = new Bundle();
                if (mText != null) {
                    bundle.putCharSequence(KEY_TEXT, mText);
+22 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import android.graphics.drawable.Icon;
import android.os.Parcel;
import android.os.Parcelable;

import java.util.Objects;

/**
 * Provides an immutable reference to an entity that appears repeatedly on different surfaces of the
 * platform. For example, this could represent the sender of a message.
@@ -120,6 +122,26 @@ public final class Person implements Parcelable {
        return "";
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Person) {
            final Person other = (Person) obj;
            return Objects.equals(mName, other.mName)
                    && mIcon == null ? other.mIcon == null :
                    (other.mIcon != null && mIcon.sameAs(other.mIcon))
                    && Objects.equals(mUri, other.mUri)
                    && Objects.equals(mKey, other.mKey)
                    && mIsBot == other.mIsBot
                    && mIsImportant == other.mIsImportant;
        }
        return false;
    }

    @Override
    public int hashCode() {
        return Objects.hash(mName, mIcon, mUri, mKey, mIsBot, mIsImportant);
    }

    @Override
    public int describeContents() {
        return 0;
+28 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.Manifest;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.PendingIntent;
import android.app.Person;
import android.content.Intent;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
@@ -421,6 +422,33 @@ public class NotificationDataTest extends SysuiTestCase {
        assertEquals(snoozeCriterions, entry.snoozeCriteria);
    }

    @Test
    public void notificationDataEntry_testIsLastMessageFromReply() {
        Person.Builder person = new Person.Builder()
                .setName("name")
                .setKey("abc")
                .setUri("uri")
                .setBot(true);

        // EXTRA_MESSAGING_PERSON is the same Person as the sender in last message in EXTRA_MESSAGES
        Bundle bundle = new Bundle();
        bundle.putParcelable(Notification.EXTRA_MESSAGING_PERSON, person.build());
        Bundle[] messagesBundle = new Bundle[]{ new Notification.MessagingStyle.Message(
                "text", 0, person.build()).toBundle() };
        bundle.putParcelableArray(Notification.EXTRA_MESSAGES, messagesBundle);

        Notification notification = new Notification.Builder(mContext, "test")
                .addExtras(bundle)
                .build();
        StatusBarNotification sbn = new StatusBarNotification("pkg", "pkg", 0, "tag", 0, 0,
                notification, mContext.getUser(), "", 0);

        NotificationData.Entry entry = new NotificationData.Entry(sbn);
        entry.setHasSentReply();

        assertTrue(entry.isLastMessageFromReply());
    }

    private void initStatusBarNotification(boolean allowDuringSetup) {
        Bundle bundle = new Bundle();
        bundle.putBoolean(Notification.EXTRA_ALLOW_DURING_SETUP, allowDuringSetup);