From 592cb8d3584bd738b3b86d94ecf5cbdc43eb0104 Mon Sep 17 00:00:00 2001 From: Flavio Fiszman Date: Thu, 18 Feb 2021 17:07:09 +0000 Subject: [PATCH] Add Missed call People Tile Change-Id: I76904cff9f512525dbb2bf335409ff038287802f Test: PeopleSpaceUtilsTest Bug: 172576156 --- .../android/app/people/PeopleSpaceTile.java | 16 +++ .../SystemUI/res/drawable/ic_phone_missed.xml | 24 ++++ .../people_space_content_background.xml | 2 +- packages/SystemUI/res/values/strings.xml | 2 + .../systemui/people/PeopleSpaceUtils.java | 65 ++++++++--- .../widget/PeopleSpaceWidgetManager.java | 3 - .../systemui/people/PeopleSpaceUtilsTest.java | 47 ++++++-- .../widget/PeopleSpaceWidgetManagerTest.java | 110 ++++++++++++------ 8 files changed, 204 insertions(+), 65 deletions(-) create mode 100644 packages/SystemUI/res/drawable/ic_phone_missed.xml diff --git a/core/java/android/app/people/PeopleSpaceTile.java b/core/java/android/app/people/PeopleSpaceTile.java index 9a53b99aaefea..132af4b2f67be 100644 --- a/core/java/android/app/people/PeopleSpaceTile.java +++ b/core/java/android/app/people/PeopleSpaceTile.java @@ -53,6 +53,7 @@ public class PeopleSpaceTile implements Parcelable { private boolean mIsImportantConversation; private String mNotificationKey; private CharSequence mNotificationContent; + private String mNotificationCategory; private Uri mNotificationDataUri; private Intent mIntent; private long mNotificationTimestamp; @@ -70,6 +71,7 @@ public class PeopleSpaceTile implements Parcelable { mIsImportantConversation = b.mIsImportantConversation; mNotificationKey = b.mNotificationKey; mNotificationContent = b.mNotificationContent; + mNotificationCategory = b.mNotificationCategory; mNotificationDataUri = b.mNotificationDataUri; mIntent = b.mIntent; mNotificationTimestamp = b.mNotificationTimestamp; @@ -129,6 +131,10 @@ public class PeopleSpaceTile implements Parcelable { return mNotificationContent; } + public String getNotificationCategory() { + return mNotificationCategory; + } + public Uri getNotificationDataUri() { return mNotificationDataUri; } @@ -166,6 +172,7 @@ public class PeopleSpaceTile implements Parcelable { builder.setIsImportantConversation(mIsImportantConversation); builder.setNotificationKey(mNotificationKey); builder.setNotificationContent(mNotificationContent); + builder.setNotificationCategory(mNotificationCategory); builder.setNotificationDataUri(mNotificationDataUri); builder.setIntent(mIntent); builder.setNotificationTimestamp(mNotificationTimestamp); @@ -186,6 +193,7 @@ public class PeopleSpaceTile implements Parcelable { private boolean mIsImportantConversation; private String mNotificationKey; private CharSequence mNotificationContent; + private String mNotificationCategory; private Uri mNotificationDataUri; private Intent mIntent; private long mNotificationTimestamp; @@ -299,6 +307,12 @@ public class PeopleSpaceTile implements Parcelable { return this; } + /** Sets the associated notification's category. */ + public Builder setNotificationCategory(String notificationCategory) { + mNotificationCategory = notificationCategory; + return this; + } + /** Sets the associated notification's data URI. */ public Builder setNotificationDataUri(Uri notificationDataUri) { mNotificationDataUri = notificationDataUri; @@ -342,6 +356,7 @@ public class PeopleSpaceTile implements Parcelable { mIsImportantConversation = in.readBoolean(); mNotificationKey = in.readString(); mNotificationContent = in.readCharSequence(); + mNotificationCategory = in.readString(); mNotificationDataUri = in.readParcelable(Uri.class.getClassLoader()); mIntent = in.readParcelable(Intent.class.getClassLoader()); mNotificationTimestamp = in.readLong(); @@ -367,6 +382,7 @@ public class PeopleSpaceTile implements Parcelable { dest.writeBoolean(mIsImportantConversation); dest.writeString(mNotificationKey); dest.writeCharSequence(mNotificationContent); + dest.writeString(mNotificationCategory); dest.writeParcelable(mNotificationDataUri, flags); dest.writeParcelable(mIntent, flags); dest.writeLong(mNotificationTimestamp); diff --git a/packages/SystemUI/res/drawable/ic_phone_missed.xml b/packages/SystemUI/res/drawable/ic_phone_missed.xml new file mode 100644 index 0000000000000..72e67d4a2ed0b --- /dev/null +++ b/packages/SystemUI/res/drawable/ic_phone_missed.xml @@ -0,0 +1,24 @@ + + + + diff --git a/packages/SystemUI/res/drawable/people_space_content_background.xml b/packages/SystemUI/res/drawable/people_space_content_background.xml index 32314d29277e0..30519aeddb457 100644 --- a/packages/SystemUI/res/drawable/people_space_content_background.xml +++ b/packages/SystemUI/res/drawable/people_space_content_background.xml @@ -15,6 +15,6 @@ ~ limitations under the License. --> - + diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index 70e8b8946ae62..4b95c16a3602f 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -2840,6 +2840,8 @@ Your friend Their status + + Missed call diff --git a/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java b/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java index cd1131ba3e797..5dda23e4a47e0 100644 --- a/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java +++ b/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java @@ -16,6 +16,7 @@ package com.android.systemui.people; +import static android.app.Notification.CATEGORY_MISSED_CALL; import static android.app.Notification.EXTRA_MESSAGES; import static android.app.people.ConversationStatus.ACTIVITY_ANNIVERSARY; import static android.app.people.ConversationStatus.ACTIVITY_BIRTHDAY; @@ -189,7 +190,7 @@ public class PeopleSpaceUtils { tiles.addAll(recentTiles); } - tiles = augmentTilesFromVisibleNotifications(tiles, notificationEntryManager); + tiles = augmentTilesFromVisibleNotifications(context, tiles, notificationEntryManager); return tiles; } @@ -357,8 +358,8 @@ public class PeopleSpaceUtils { && storedUserId == userId; } - static List augmentTilesFromVisibleNotifications(List tiles, - NotificationEntryManager notificationEntryManager) { + static List augmentTilesFromVisibleNotifications(Context context, + List tiles, NotificationEntryManager notificationEntryManager) { if (notificationEntryManager == null) { Log.w(TAG, "NotificationEntryManager is null"); return tiles; @@ -374,12 +375,13 @@ public class PeopleSpaceUtils { } return tiles .stream() - .map(entry -> augmentTileFromVisibleNotifications(entry, visibleNotifications)) + .map(entry -> augmentTileFromVisibleNotifications( + context, entry, visibleNotifications)) .collect(Collectors.toList()); } - static PeopleSpaceTile augmentTileFromVisibleNotifications(PeopleSpaceTile tile, - Map visibleNotifications) { + static PeopleSpaceTile augmentTileFromVisibleNotifications(Context context, + PeopleSpaceTile tile, Map visibleNotifications) { String shortcutId = tile.getId(); String packageName = tile.getPackageName(); int userId = UserHandle.getUserHandleForUid(tile.getUid()).getIdentifier(); @@ -389,7 +391,7 @@ public class PeopleSpaceUtils { return tile; } if (DEBUG) Log.d(TAG, "Augmenting tile from visible notifications, key:" + key); - return augmentTileFromNotification(tile, visibleNotifications.get(key).getSbn()); + return augmentTileFromNotification(context, tile, visibleNotifications.get(key).getSbn()); } /** @@ -408,7 +410,7 @@ public class PeopleSpaceUtils { } if (notificationAction == PeopleSpaceUtils.NotificationAction.POSTED) { if (DEBUG) Log.i(TAG, "Adding notification to storage, appWidgetId: " + appWidgetId); - storedTile = augmentTileFromNotification(storedTile, sbn); + storedTile = augmentTileFromNotification(context, storedTile, sbn); } else { if (DEBUG) { Log.i(TAG, "Removing notification from storage, appWidgetId: " + appWidgetId); @@ -418,23 +420,40 @@ public class PeopleSpaceUtils { .setNotificationKey(null) .setNotificationContent(null) .setNotificationDataUri(null) + .setNotificationCategory(null) .build(); } updateAppWidgetOptionsAndView(appWidgetManager, context, appWidgetId, storedTile); } - static PeopleSpaceTile augmentTileFromNotification(PeopleSpaceTile tile, + static PeopleSpaceTile augmentTileFromNotification(Context context, PeopleSpaceTile tile, StatusBarNotification sbn) { - Notification.MessagingStyle.Message message = getLastMessagingStyleMessage(sbn); - if (message == null) { - if (DEBUG) Log.i(TAG, "Notification doesn't have content, skipping."); + Notification notification = sbn.getNotification(); + if (notification == null) { + if (DEBUG) Log.d(TAG, "Notification is null"); return tile; } + boolean isMissedCall = Objects.equals(notification.category, CATEGORY_MISSED_CALL); + Notification.MessagingStyle.Message message = getLastMessagingStyleMessage(notification); + + if (!isMissedCall && message == null) { + if (DEBUG) Log.d(TAG, "Notification has no content"); + return tile; + } + + // If it's a missed call notification and it doesn't include content, use fallback value, + // otherwise, use notification content. + boolean hasMessageText = message != null && !TextUtils.isEmpty(message.getText()); + CharSequence content = (isMissedCall && !hasMessageText) + ? context.getString(R.string.missed_call) : message.getText(); + Uri dataUri = message != null ? message.getDataUri() : null; + return tile .toBuilder() .setNotificationKey(sbn.getKey()) - .setNotificationContent(message.getText()) - .setNotificationDataUri(message.getDataUri()) + .setNotificationCategory(notification.category) + .setNotificationContent(content) + .setNotificationDataUri(dataUri) .build(); } @@ -462,6 +481,11 @@ public class PeopleSpaceUtils { * content, then birthdays, then the most recent status, and finally last interaction. */ private static RemoteViews getViewForTile(Context context, PeopleSpaceTile tile) { + if (Objects.equals(tile.getNotificationCategory(), CATEGORY_MISSED_CALL)) { + if (DEBUG) Log.d(TAG, "Create missed call view"); + return createMissedCallRemoteViews(context, tile); + } + if (tile.getNotificationKey() != null) { if (DEBUG) Log.d(TAG, "Create notification view"); return createNotificationRemoteViews(context, tile); @@ -630,6 +654,16 @@ public class PeopleSpaceUtils { return views; } + private static RemoteViews createMissedCallRemoteViews(Context context, + PeopleSpaceTile tile) { + RemoteViews views = new RemoteViews( + context.getPackageName(), R.layout.people_space_small_avatar_tile); + views.setTextViewText(R.id.status, tile.getNotificationContent()); + views.setImageViewResource(R.id.status_defined_icon, R.drawable.ic_phone_missed); + views.setBoolean(R.id.content_background, "setClipToOutline", true); + return views; + } + private static RemoteViews createNotificationRemoteViews(Context context, PeopleSpaceTile tile) { RemoteViews views = new RemoteViews( @@ -715,8 +749,7 @@ public class PeopleSpaceUtils { /** Gets the most recent {@link Notification.MessagingStyle.Message} from the notification. */ @VisibleForTesting public static Notification.MessagingStyle.Message getLastMessagingStyleMessage( - StatusBarNotification sbn) { - Notification notification = sbn.getNotification(); + Notification notification) { if (notification == null) { return null; } diff --git a/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java b/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java index bee9889eaa4e9..9e5c786b9a639 100644 --- a/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java +++ b/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java @@ -29,7 +29,6 @@ import android.provider.Settings; import android.service.notification.NotificationListenerService; import android.service.notification.StatusBarNotification; import android.util.Log; -import android.widget.RemoteViews; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.appwidget.IAppWidgetService; @@ -124,8 +123,6 @@ public class PeopleSpaceWidgetManager { */ public void updateWidgetWithNotificationChanged(StatusBarNotification sbn, PeopleSpaceUtils.NotificationAction notificationAction) { - RemoteViews views = new RemoteViews( - mContext.getPackageName(), R.layout.people_space_small_avatar_tile); if (DEBUG) Log.d(TAG, "updateWidgetWithNotificationChanged called"); boolean showSingleConversation = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.PEOPLE_SPACE_CONVERSATION_TYPE, 0) == 0; diff --git a/packages/SystemUI/tests/src/com/android/systemui/people/PeopleSpaceUtilsTest.java b/packages/SystemUI/tests/src/com/android/systemui/people/PeopleSpaceUtilsTest.java index d79155cbb2fc7..c8e939609e873 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/people/PeopleSpaceUtilsTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/people/PeopleSpaceUtilsTest.java @@ -16,6 +16,7 @@ package com.android.systemui.people; +import static android.app.Notification.CATEGORY_MISSED_CALL; import static android.app.people.ConversationStatus.ACTIVITY_BIRTHDAY; import static android.app.people.ConversationStatus.ACTIVITY_GAME; import static android.app.people.ConversationStatus.ACTIVITY_NEW_STORY; @@ -113,6 +114,7 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase { private static final Uri URI = Uri.parse("fake_uri"); private static final Icon ICON = Icon.createWithResource("package", R.drawable.ic_android); private static final String GAME_DESCRIPTION = "Playing a game!"; + private static final CharSequence MISSED_CALL = "Custom missed call message"; private static final String NAME = "username"; private static final Person PERSON = new Person.Builder() .setName("name") @@ -346,7 +348,7 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase { .build(); Notification.MessagingStyle.Message lastMessage = - PeopleSpaceUtils.getLastMessagingStyleMessage(sbn); + PeopleSpaceUtils.getLastMessagingStyleMessage(sbn.getNotification()); assertThat(lastMessage).isNull(); } @@ -447,7 +449,7 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase { .build(); Notification.MessagingStyle.Message lastMessage = - PeopleSpaceUtils.getLastMessagingStyleMessage(sbn); + PeopleSpaceUtils.getLastMessagingStyleMessage(sbn.getNotification()); assertThat(lastMessage.getText().toString()).isEqualTo(NOTIFICATION_TEXT_2); } @@ -465,7 +467,7 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase { .setUid(0) .build(); PeopleSpaceTile actual = PeopleSpaceUtils - .augmentTileFromNotification(tile, sbn); + .augmentTileFromNotification(mContext, tile, sbn); assertThat(actual.getNotificationContent().toString()).isEqualTo(NOTIFICATION_TEXT_2); } @@ -483,9 +485,8 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase { .setUid(0) .build(); PeopleSpaceTile actual = PeopleSpaceUtils - .augmentTileFromNotification(tile, sbn); + .augmentTileFromNotification(mContext, tile, sbn); - assertThat(actual.getNotificationKey()).isEqualTo(null); assertThat(actual.getNotificationContent()).isEqualTo(null); } @@ -498,7 +499,7 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase { .setUid(0) .build(); PeopleSpaceTile actual = PeopleSpaceUtils - .augmentTileFromVisibleNotifications(tile, + .augmentTileFromVisibleNotifications(mContext, tile, Map.of(PeopleSpaceUtils.getKey(mNotificationEntry1), mNotificationEntry1)); assertThat(actual.getNotificationContent().toString()).isEqualTo(NOTIFICATION_TEXT_2); @@ -513,7 +514,7 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase { .setUid(0) .build(); PeopleSpaceTile actual = PeopleSpaceUtils - .augmentTileFromVisibleNotifications(tile, + .augmentTileFromVisibleNotifications(mContext, tile, Map.of(PeopleSpaceUtils.getKey(mNotificationEntry1), mNotificationEntry1)); assertThat(actual.getNotificationContent()).isEqualTo(null); @@ -528,7 +529,8 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase { .setUid(0) .build(); List actualList = PeopleSpaceUtils - .augmentTilesFromVisibleNotifications(List.of(tile), mNotificationEntryManager); + .augmentTilesFromVisibleNotifications( + mContext, List.of(tile), mNotificationEntryManager); assertThat(actualList.size()).isEqualTo(1); assertThat(actualList.get(0).getNotificationContent().toString()) @@ -552,7 +554,7 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase { .setUid(0) .build(); List actualList = PeopleSpaceUtils - .augmentTilesFromVisibleNotifications(List.of(tile1, tile2), + .augmentTilesFromVisibleNotifications(mContext, List.of(tile1, tile2), mNotificationEntryManager); assertThat(actualList.size()).isEqualTo(2); @@ -762,6 +764,33 @@ public class PeopleSpaceUtilsTest extends SysuiTestCase { assertEquals(statusContent.getText(), GAME_DESCRIPTION); } + @Test + public void testCreateRemoteViewsWithMissedCallNotification() { + PeopleSpaceTile tileWithMissedCallNotification = PERSON_TILE.toBuilder() + .setNotificationDataUri(null) + .setNotificationCategory(CATEGORY_MISSED_CALL) + .setNotificationContent(MISSED_CALL) + .build(); + RemoteViews views = PeopleSpaceUtils.createRemoteViews(mContext, + tileWithMissedCallNotification, 0); + View result = views.apply(mContext, null); + + TextView name = (TextView) result.findViewById(R.id.name); + assertEquals(name.getText(), NAME); + // Has availability. + View availability = result.findViewById(R.id.availability); + assertEquals(View.GONE, availability.getVisibility()); + // Has new story. + View personIcon = result.findViewById(R.id.person_icon_only); + View personIconWithStory = result.findViewById(R.id.person_icon_with_story); + assertEquals(View.VISIBLE, personIcon.getVisibility()); + assertEquals(View.GONE, personIconWithStory.getVisibility()); + // Has status. + TextView statusContent = (TextView) result.findViewById(R.id.status); + assertEquals(statusContent.getText(), MISSED_CALL); + } + + @Test public void testCreateRemoteViewsWithNotificationTemplate() { PeopleSpaceTile tileWithStatusAndNotification = PERSON_TILE.toBuilder() diff --git a/packages/SystemUI/tests/src/com/android/systemui/people/widget/PeopleSpaceWidgetManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/people/widget/PeopleSpaceWidgetManagerTest.java index 9470141178dd5..1c8324c524f4d 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/people/widget/PeopleSpaceWidgetManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/people/widget/PeopleSpaceWidgetManagerTest.java @@ -16,6 +16,7 @@ package com.android.systemui.people.widget; +import static android.app.Notification.CATEGORY_MISSED_CALL; import static android.app.NotificationManager.IMPORTANCE_DEFAULT; import static android.app.NotificationManager.IMPORTANCE_HIGH; @@ -167,7 +168,8 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { int[] widgetIdsArray = {}; when(mIAppWidgetService.getAppWidgetIds(any())).thenReturn(widgetIdsArray); - StatusBarNotification sbn = createConversationNotification(OTHER_SHORTCUT_ID); + StatusBarNotification sbn = createNotification( + OTHER_SHORTCUT_ID, /* isMessagingStyle = */ false, /* isMissedCall = */ false); NotifEvent notif1 = mNoMan.postNotif(new NotificationEntryBuilder() .setSbn(sbn) .setId(1)); @@ -207,7 +209,8 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { when(mIAppWidgetService.getAppWidgetIds(any())).thenReturn(widgetIdsArray); StatusBarNotification sbnWithoutPackageName = new SbnBuilder() - .setNotification(createMessagingStyleNotification(SHORTCUT_ID)) + .setNotification(createMessagingStyleNotification( + SHORTCUT_ID, /* isMessagingStyle = */ false, /* isMissedCall = */ false)) .build(); NotifEvent notif1 = mNoMan.postNotif(new NotificationEntryBuilder() .setSbn(sbnWithoutPackageName) @@ -256,7 +259,8 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { int[] widgetIdsArray = {WIDGET_ID_WITH_SHORTCUT, WIDGET_ID_WITHOUT_SHORTCUT}; when(mIAppWidgetService.getAppWidgetIds(any())).thenReturn(widgetIdsArray); - StatusBarNotification sbn = createConversationNotification(OTHER_SHORTCUT_ID); + StatusBarNotification sbn = createNotification( + OTHER_SHORTCUT_ID, /* isMessagingStyle = */ true, /* isMissedCall = */ false); NotifEvent notif1 = mNoMan.postNotif(new NotificationEntryBuilder() .setSbn(sbn) .setId(1)); @@ -276,7 +280,8 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { when(mIAppWidgetService.getAppWidgetIds(any())).thenReturn(widgetIdsArray); StatusBarNotification sbnWithDifferentPackageName = new SbnBuilder() - .setNotification(createMessagingStyleNotification(SHORTCUT_ID)) + .setNotification(createMessagingStyleNotification( + SHORTCUT_ID, /* isMessagingStyle = */ false, /* isMissedCall = */ false)) .setPkg(TEST_PACKAGE_B) .build(); NotifEvent notif1 = mNoMan.postNotif(new NotificationEntryBuilder() @@ -295,7 +300,8 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { int[] widgetIdsArray = {WIDGET_ID_WITH_SHORTCUT, WIDGET_ID_WITHOUT_SHORTCUT}; when(mIAppWidgetService.getAppWidgetIds(any())).thenReturn(widgetIdsArray); - StatusBarNotification sbn = createConversationNotification(OTHER_SHORTCUT_ID); + StatusBarNotification sbn = createNotification( + OTHER_SHORTCUT_ID, /* isMessagingStyle = */ true, /* isMissedCall = */ false); NotifEvent notif1 = mNoMan.postNotif(new NotificationEntryBuilder() .setSbn(sbn) .setId(1)); @@ -315,7 +321,8 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { when(mIAppWidgetService.getAppWidgetIds(any())).thenReturn(widgetIdsArray); StatusBarNotification sbnWithDifferentPackageName = new SbnBuilder() - .setNotification(createMessagingStyleNotification(SHORTCUT_ID)) + .setNotification(createMessagingStyleNotification( + SHORTCUT_ID, /* isMessagingStyle = */ true, /* isMissedCall = */ false)) .setPkg(TEST_PACKAGE_B) .build(); NotifEvent notif1 = mNoMan.postNotif(new NotificationEntryBuilder() @@ -337,7 +344,8 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { when(mIAppWidgetService.getAppWidgetIds(any())).thenReturn(widgetIdsArray); NotifEvent notif1 = mNoMan.postNotif(new NotificationEntryBuilder() - .setSbn(createConversationNotification(SHORTCUT_ID)) + .setSbn(createNotification( + SHORTCUT_ID, /* isMessagingStyle = */ true, /* isMissedCall = */ false)) .setId(1)); mClock.advanceTime(MIN_LINGER_DURATION); @@ -367,7 +375,8 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { when(mIAppWidgetService.getAppWidgetIds(any())).thenReturn(widgetIdsArray); NotifEvent notif1 = mNoMan.postNotif(new NotificationEntryBuilder() - .setSbn(createConversationNotification(SHORTCUT_ID)) + .setSbn(createNotification( + SHORTCUT_ID, /* isMessagingStyle = */ true, /* isMissedCall = */ false)) .setId(1)); mClock.advanceTime(MIN_LINGER_DURATION); @@ -400,7 +409,8 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { PeopleSpaceUtils.removeStorageForTile(mContext, SECOND_WIDGET_ID_WITH_SHORTCUT); NotifEvent notif1 = mNoMan.postNotif(new NotificationEntryBuilder() - .setSbn(createConversationNotification(SHORTCUT_ID)) + .setSbn(createNotification( + SHORTCUT_ID, /* isMessagingStyle = */ true, /* isMissedCall = */ false)) .setId(1)); mClock.advanceTime(MIN_LINGER_DURATION); @@ -417,33 +427,52 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { } @Test - public void testDoNotUpdateNotificationPostedWithoutMessagesIfExistingTile() + public void testUpdateMissedCallNotificationWithoutContentPostedIfExistingTile() throws Exception { int[] widgetIdsArray = {WIDGET_ID_WITH_SHORTCUT, WIDGET_ID_WITHOUT_SHORTCUT}; when(mIAppWidgetService.getAppWidgetIds(any())).thenReturn(widgetIdsArray); setStorageForTile(SHORTCUT_ID, TEST_PACKAGE_A, WIDGET_ID_WITH_SHORTCUT); - Notification notificationWithoutMessagingStyle = new Notification.Builder(mContext) - .setContentTitle("TEST_TITLE") - .setContentText("TEST_TEXT") - .setShortcutId(SHORTCUT_ID) - .build(); - StatusBarNotification sbn = new SbnBuilder() - .setNotification(notificationWithoutMessagingStyle) - .setPkg(TEST_PACKAGE_A) - .setUid(0) - .build(); NotifEvent notif1 = mNoMan.postNotif(new NotificationEntryBuilder() - .setSbn(sbn) + .setSbn(createNotification( + SHORTCUT_ID, /* isMessagingStyle = */ false, /* isMissedCall = */ true)) .setId(1)); mClock.advanceTime(MIN_LINGER_DURATION); verify(mAppWidgetManager, times(1)) .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT), mBundleArgumentCaptor.capture()); - Bundle options = requireNonNull(mBundleArgumentCaptor.getValue()); - assertThat((PeopleSpaceTile) options.getParcelable(OPTIONS_PEOPLE_SPACE_TILE)) - .isEqualTo(PERSON_TILE); + Bundle bundle = requireNonNull(mBundleArgumentCaptor.getValue()); + + PeopleSpaceTile tile = bundle.getParcelable(OPTIONS_PEOPLE_SPACE_TILE); + assertThat(tile.getNotificationKey()).isEqualTo(NOTIFICATION_KEY); + assertThat(tile.getNotificationContent()) + .isEqualTo(mContext.getString(R.string.missed_call)); + verify(mAppWidgetManager, times(1)).updateAppWidget(eq(WIDGET_ID_WITH_SHORTCUT), + any()); + } + + @Test + public void testUpdateMissedCallNotificationWithContentPostedIfExistingTile() + throws Exception { + int[] widgetIdsArray = {WIDGET_ID_WITH_SHORTCUT, WIDGET_ID_WITHOUT_SHORTCUT}; + when(mIAppWidgetService.getAppWidgetIds(any())).thenReturn(widgetIdsArray); + setStorageForTile(SHORTCUT_ID, TEST_PACKAGE_A, WIDGET_ID_WITH_SHORTCUT); + + NotifEvent notif1 = mNoMan.postNotif(new NotificationEntryBuilder() + .setSbn(createNotification( + SHORTCUT_ID, /* isMessagingStyle = */ true, /* isMissedCall = */ true)) + .setId(1)); + mClock.advanceTime(MIN_LINGER_DURATION); + + verify(mAppWidgetManager, times(1)) + .updateAppWidgetOptions(eq(WIDGET_ID_WITH_SHORTCUT), + mBundleArgumentCaptor.capture()); + Bundle bundle = requireNonNull(mBundleArgumentCaptor.getValue()); + + PeopleSpaceTile tile = bundle.getParcelable(OPTIONS_PEOPLE_SPACE_TILE); + assertThat(tile.getNotificationKey()).isEqualTo(NOTIFICATION_KEY); + assertThat(tile.getNotificationContent()).isEqualTo(NOTIFICATION_CONTENT); verify(mAppWidgetManager, times(1)).updateAppWidget(eq(WIDGET_ID_WITH_SHORTCUT), any()); } @@ -453,7 +482,8 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { int[] widgetIdsArray = {WIDGET_ID_WITH_SHORTCUT, WIDGET_ID_WITHOUT_SHORTCUT}; when(mIAppWidgetService.getAppWidgetIds(any())).thenReturn(widgetIdsArray); - StatusBarNotification sbn = createConversationNotification(SHORTCUT_ID); + StatusBarNotification sbn = createNotification( + SHORTCUT_ID, /* isMessagingStyle = */ true, /* isMissedCall = */ false); NotifEvent notif1 = mNoMan.postNotif(new NotificationEntryBuilder() .setSbn(sbn) .setId(1)); @@ -483,21 +513,29 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { return convo; } - private Notification createMessagingStyleNotification(String shortcutId) { - return new Notification.Builder(mContext) + private Notification createMessagingStyleNotification(String shortcutId, + boolean isMessagingStyle, boolean isMissedCall) { + Notification.Builder builder = new Notification.Builder(mContext) .setContentTitle("TEST_TITLE") .setContentText("TEST_TEXT") - .setShortcutId(shortcutId) - .setStyle(new Notification.MessagingStyle(PERSON) - .addMessage( - new Notification.MessagingStyle.Message(NOTIFICATION_CONTENT, 10, - PERSON)) - ) - .build(); + .setShortcutId(shortcutId); + if (isMessagingStyle) { + builder.setStyle(new Notification.MessagingStyle(PERSON) + .addMessage( + new Notification.MessagingStyle.Message(NOTIFICATION_CONTENT, 10, + PERSON)) + ); + } + if (isMissedCall) { + builder.setCategory(CATEGORY_MISSED_CALL); + } + return builder.build(); } - private StatusBarNotification createConversationNotification(String shortcutId) { - Notification notification = createMessagingStyleNotification(shortcutId); + private StatusBarNotification createNotification(String shortcutId, + boolean isMessagingStyle, boolean isMissedCall) { + Notification notification = createMessagingStyleNotification( + shortcutId, isMessagingStyle, isMissedCall); return new SbnBuilder() .setNotification(notification) .setPkg(TEST_PACKAGE_A)