diff options
author | Ritwika Mitra <ritwikam@google.com> | 2020-02-03 14:52:30 -0800 |
---|---|---|
committer | Ritwika Mitra <ritwikam@google.com> | 2020-02-05 13:33:23 -0800 |
commit | b2d00e02683db564832222dc6b29bb17d0e22d86 (patch) | |
tree | e70f61025c0e8a36f0229853e954f748a6a50da2 /src/com/android/car | |
parent | e1358b52a2df4d8606c3c3dd172c25169df5a15c (diff) | |
download | Messenger-b2d00e02683db564832222dc6b29bb17d0e22d86.tar.gz |
Exclude dismissed and read messages from the notification
When a user dismisses a message notification, OR when a message
notification is successfully read aloud, the messages in that notification
should not appear when/if that notification gets updated with newer
messages.
This change combines the two states (dismiss and read) since they both
have the same logical consequence.
Change-Id: I1518a86606f4035e6f721844e4705442482a3307
Fix: 146362547
Test: manual
Diffstat (limited to 'src/com/android/car')
4 files changed, 27 insertions, 14 deletions
diff --git a/src/com/android/car/messenger/MapMessage.java b/src/com/android/car/messenger/MapMessage.java index b4b7aee..c7e91e6 100644 --- a/src/com/android/car/messenger/MapMessage.java +++ b/src/com/android/car/messenger/MapMessage.java @@ -34,7 +34,7 @@ class MapMessage { private String mMessageText; private long mReceiveTime; private boolean mIsReadOnPhone; - private boolean mIsReadOnCar; + private boolean mShouldInclude; /** * Constructs a {@link MapMessage} from {@code intent} that was received from MAP service via @@ -151,8 +151,13 @@ class MapMessage { return mMessageText; } - public void markMessageAsRead() { - mIsReadOnCar = true; + /** + * Sets the message to be excluded from the notification. Messages that have been read aloud on + * the car, or that have been dismissed by the user should be excluded from the notification if/ + * when the notification gets updated. Note: this state will not be propagated to the phone. + */ + public void excludeFromNotification() { + mShouldInclude = false; } /** @@ -163,10 +168,12 @@ class MapMessage { } /** - * Returns {@code true} if message was read on the car. + * Returns {@code true} if message should be included in the notification. Messages that + * have been read aloud on the car, or that have been dismissed by the user should be excluded + * from the notification if/when the notification gets updated. */ - public boolean isReadOnCar() { - return mIsReadOnCar; + public boolean shouldIncludeInNotification() { + return mShouldInclude; } @Override @@ -179,7 +186,7 @@ class MapMessage { ", mSenderName='" + mSenderName + '\'' + ", mReceiveTime=" + mReceiveTime + '\'' + ", mIsReadOnPhone= " + mIsReadOnPhone + '\'' + - ", mIsReadOnCar= " + mIsReadOnCar + + ", mShouldInclude= " + mShouldInclude + "}"; } } diff --git a/src/com/android/car/messenger/MessengerDelegate.java b/src/com/android/car/messenger/MessengerDelegate.java index 58193d4..8fb77d7 100644 --- a/src/com/android/car/messenger/MessengerDelegate.java +++ b/src/com/android/car/messenger/MessengerDelegate.java @@ -14,7 +14,6 @@ import android.graphics.Bitmap; import android.graphics.drawable.Drawable; import android.graphics.drawable.Icon; import android.net.Uri; -import android.util.Log; import android.widget.Toast; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; @@ -210,12 +209,17 @@ public class MessengerDelegate implements BluetoothMonitor.OnBluetoothEventListe } } - protected void markAsRead(SenderKey senderKey) { + + /** + * Excludes messages from a notification so that the messages are not shown to the user once + * the notification gets updated with newer messages. + */ + protected void excludeFromNotification(SenderKey senderKey) { NotificationInfo info = mNotificationInfos.get(senderKey); for (MessageKey key : info.mMessageKeys) { MapMessage message = mMessages.get(key); - if (!message.isReadOnCar()) { - message.markMessageAsRead(); + if (message.shouldIncludeInNotification()) { + message.excludeFromNotification(); mSmsDatabaseHandler.addOrUpdate(message); } } @@ -239,6 +243,7 @@ public class MessengerDelegate implements BluetoothMonitor.OnBluetoothEventListe if (predicate.test(senderKey)) { mNotificationManager.cancel(notificationInfo.mNotificationId); } + excludeFromNotification(senderKey); }); } @@ -361,7 +366,7 @@ public class MessengerDelegate implements BluetoothMonitor.OnBluetoothEventListe .setUri(notificationInfo.mSenderContactUri) .build(); notificationInfo.mMessageKeys.stream().map(mMessages::get).forEachOrdered(message -> { - if (!message.isReadOnCar()) { + if (message.shouldIncludeInNotification()) { messagingStyle.addMessage( message.getMessageText(), message.getReceiveTime(), diff --git a/src/com/android/car/messenger/MessengerService.java b/src/com/android/car/messenger/MessengerService.java index 0b0e4e4..a441d99 100644 --- a/src/com/android/car/messenger/MessengerService.java +++ b/src/com/android/car/messenger/MessengerService.java @@ -243,7 +243,7 @@ public class MessengerService extends Service { public void markAsRead(Intent intent) { final SenderKey senderKey = intent.getParcelableExtra(EXTRA_SENDER_KEY); L.d(TAG, "markAsRead"); - mMessengerDelegate.markAsRead(senderKey); + mMessengerDelegate.excludeFromNotification(senderKey); } /** diff --git a/src/com/android/car/messenger/SmsDatabaseHandler.java b/src/com/android/car/messenger/SmsDatabaseHandler.java index 77d8e29..a8fd107 100644 --- a/src/com/android/car/messenger/SmsDatabaseHandler.java +++ b/src/com/android/car/messenger/SmsDatabaseHandler.java @@ -168,7 +168,8 @@ class SmsDatabaseHandler { newMessage.put(Telephony.Sms.PERSON, getContactId(mContentResolver, message.getSenderContactUri())); - newMessage.put(Telephony.Sms.READ, (message.isReadOnPhone() || message.isReadOnCar())); + newMessage.put(Telephony.Sms.READ, (message.isReadOnPhone() + || !message.shouldIncludeInNotification())); return newMessage; } |