Loading packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java +16 −8 Original line number Diff line number Diff line Loading @@ -203,7 +203,7 @@ public class PeopleSpaceUtils { if (DEBUG) { Log.i(TAG, "Removing any notification stored for tile Id: " + tile.getId()); } return tile PeopleSpaceTile.Builder updatedTile = tile .toBuilder() // Reset notification content. .setNotificationKey(null) Loading @@ -212,8 +212,15 @@ public class PeopleSpaceUtils { .setNotificationDataUri(null) .setMessagesCount(0) // Reset missed calls category. .setNotificationCategory(null) .build(); .setNotificationCategory(null); // Only set last interaction to now if we are clearing a notification. if (!TextUtils.isEmpty(tile.getNotificationKey())) { long currentTimeMillis = System.currentTimeMillis(); if (DEBUG) Log.d(TAG, "Set last interaction on clear: " + currentTimeMillis); updatedTile.setLastInteractionTimestamp(currentTimeMillis); } return updatedTile.build(); } /** Loading @@ -227,10 +234,11 @@ public class PeopleSpaceUtils { if (DEBUG) Log.d(TAG, "Tile key: " + key.toString() + ". Notification is null"); return removeNotificationFields(tile); } Notification notification = notificationEntry.getSbn().getNotification(); StatusBarNotification sbn = notificationEntry.getSbn(); Notification notification = sbn.getNotification(); PeopleSpaceTile.Builder updatedTile = tile.toBuilder(); String uriFromNotification = getContactUri(notificationEntry.getSbn()); String uriFromNotification = getContactUri(sbn); if (appWidgetId.isPresent() && tile.getContactUri() == null && !TextUtils.isEmpty( uriFromNotification)) { if (DEBUG) Log.d(TAG, "Add uri from notification to tile: " + uriFromNotification); Loading @@ -241,7 +249,6 @@ public class PeopleSpaceUtils { // Update cached tile in-memory. updatedTile.setContactUri(contactUri); } boolean isMissedCall = isMissedCall(notification); List<Notification.MessagingStyle.Message> messages = getMessagingStyleMessages(notification); Loading @@ -261,12 +268,13 @@ public class PeopleSpaceUtils { Uri dataUri = message != null ? message.getDataUri() : null; if (DEBUG) { Log.d(TAG, "Tile key: " + key.toString() + ". Notification message has text: " + hasMessageText); + hasMessageText + " Has last interaction: " + sbn.getPostTime()); } CharSequence sender = getSenderIfGroupConversation(notification, message); return updatedTile .setNotificationKey(notificationEntry.getSbn().getKey()) .setLastInteractionTimestamp(sbn.getPostTime()) .setNotificationKey(sbn.getKey()) .setNotificationCategory(notification.category) .setNotificationContent(content) .setNotificationSender(sender) Loading packages/SystemUI/src/com/android/systemui/people/PeopleTileViewHelper.java +1 −1 Original line number Diff line number Diff line Loading @@ -835,7 +835,7 @@ public class PeopleTileViewHelper { return null; } else if (durationSinceLastInteraction.toDays() < DAYS_IN_A_WEEK) { return context.getString(R.string.timestamp, formatter.formatMeasures( new Measure(durationSinceLastInteraction.toHours(), new Measure(durationSinceLastInteraction.toDays(), MeasureUnit.DAY))); } else if (durationSinceLastInteraction.toDays() <= DAYS_IN_A_WEEK * 2) { return context.getString(durationSinceLastInteraction.toDays() == DAYS_IN_A_WEEK Loading packages/SystemUI/tests/src/com/android/systemui/people/widget/PeopleSpaceWidgetManagerTest.java +6 −1 Original line number Diff line number Diff line Loading @@ -191,6 +191,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { | SUPPRESSED_EFFECT_LIGHTS | SUPPRESSED_EFFECT_PEEK | SUPPRESSED_EFFECT_NOTIFICATION_LIST; private static final long SBN_POST_TIME = 567L; private ShortcutInfo mShortcutInfo; private NotificationEntry mNotificationEntry; Loading Loading @@ -607,6 +608,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT); assertThat(tile.getNotificationKey()).isEqualTo(NOTIFICATION_KEY); assertThat(tile.getLastInteractionTimestamp()).isEqualTo(SBN_POST_TIME); assertThat(tile.getNotificationContent()).isEqualTo(NOTIFICATION_CONTENT_1); verify(mAppWidgetManager, times(1)).updateAppWidget(eq(WIDGET_ID_WITH_SHORTCUT), any()); Loading Loading @@ -917,18 +919,20 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { .setSbn(sbn) .setId(1)); mClock.advanceTime(MIN_LINGER_DURATION); long timestampBeforeNotificationClear = System.currentTimeMillis(); NotifEvent notif1b = mNoMan.retractNotif(notif1.sbn, 0); mClock.advanceTime(MIN_LINGER_DURATION); PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT); assertThat(tile.getNotificationKey()).isEqualTo(null); assertThat(tile.getLastInteractionTimestamp()).isLessThan( timestampBeforeNotificationClear); assertThat(tile.getNotificationContent()).isEqualTo(null); assertThat(tile.getNotificationDataUri()).isEqualTo(null); verify(mAppWidgetManager, times(2)).updateAppWidget(eq(WIDGET_ID_WITH_SHORTCUT), any()); } @Test public void testAddThenReconfigureWidgetsUpdatesStorageCacheAndListeners() throws Exception { Loading Loading @@ -1446,6 +1450,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { .setNotification(notification) .setPkg(TEST_PACKAGE_A) .setUid(0) .setPostTime(SBN_POST_TIME) .setUser(new UserHandle(0)) .build(); } Loading services/people/java/com/android/server/people/data/DataManager.java +13 −2 Original line number Diff line number Diff line Loading @@ -1149,11 +1149,11 @@ public class DataManager { if (conversationInfo == null) { return; } if (DEBUG) Log.d(TAG, "Last event from notification: " + sbn.getPostTime()); ConversationInfo updated = new ConversationInfo.Builder(conversationInfo) .setLastEventTimestamp(sbn.getPostTime()) .setParentNotificationChannelId(sbn.getNotification().getChannelId()) .build(); // Don't update listeners on notifications posted. packageData.getConversationStore().addOrUpdate(updated); EventHistoryImpl eventHistory = packageData.getEventStore().getOrCreateEventHistory( Loading Loading @@ -1186,9 +1186,19 @@ public class DataManager { if (reason != REASON_CLICK || packageData == null) { return; } long currentTime = System.currentTimeMillis(); ConversationInfo conversationInfo = packageData.getConversationInfo(shortcutId); if (conversationInfo == null) { return; } if (DEBUG) Log.d(TAG, "Last event from notification removed: " + currentTime); ConversationInfo updated = new ConversationInfo.Builder(conversationInfo) .setLastEventTimestamp(currentTime) .build(); packageData.getConversationStore().addOrUpdate(updated); EventHistoryImpl eventHistory = packageData.getEventStore().getOrCreateEventHistory( EventStore.CATEGORY_SHORTCUT_BASED, shortcutId); long currentTime = System.currentTimeMillis(); eventHistory.addEvent(new Event(currentTime, Event.TYPE_NOTIFICATION_OPENED)); } Loading Loading @@ -1265,6 +1275,7 @@ public class DataManager { public void onEvent(PackageData packageData, ConversationInfo conversationInfo, Event event) { if (event.getType() == Event.TYPE_IN_APP_CONVERSATION) { if (DEBUG) Log.d(TAG, "Last event from in-app: " + event.getTimestamp()); ConversationInfo updated = new ConversationInfo.Builder(conversationInfo) .setLastEventTimestamp(event.getTimestamp()) .build(); Loading services/tests/servicestests/src/com/android/server/people/data/DataManagerTest.java +21 −1 Original line number Diff line number Diff line Loading @@ -693,7 +693,6 @@ public final class DataManagerTest { NotificationListenerService listenerService = mDataManager.getNotificationListenerServiceForTesting(USER_ID_PRIMARY); listenerService.onNotificationPosted(mStatusBarNotification); ConversationChannel result = mDataManager.getConversation(TEST_PKG_NAME, USER_ID_PRIMARY, TEST_SHORTCUT_ID); Loading Loading @@ -1360,6 +1359,27 @@ public final class DataManagerTest { assertTrue(result.isEmpty()); } @Test public void testNotificationRemoved() { mDataManager.onUserUnlocked(USER_ID_PRIMARY); ShortcutInfo shortcut = buildShortcutInfo(TEST_PKG_NAME, USER_ID_PRIMARY, TEST_SHORTCUT_ID, buildPerson()); shortcut.setCached(ShortcutInfo.FLAG_CACHED_NOTIFICATIONS); mDataManager.addOrUpdateConversationInfo(shortcut); NotificationListenerService listenerService = mDataManager.getNotificationListenerServiceForTesting(USER_ID_PRIMARY); listenerService.onNotificationPosted(mStatusBarNotification); listenerService.onNotificationRemoved(mStatusBarNotification, null, NotificationListenerService.REASON_CANCEL); ConversationInfo conversationInfo = mDataManager.getPackage(TEST_PKG_NAME, USER_ID_PRIMARY) .getConversationStore() .getConversation(TEST_SHORTCUT_ID); assertEquals(conversationInfo.getLastEventTimestamp(), System.currentTimeMillis()); } @Test public void testRemoveRecentConversation() { mDataManager.onUserUnlocked(USER_ID_PRIMARY); Loading Loading
packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java +16 −8 Original line number Diff line number Diff line Loading @@ -203,7 +203,7 @@ public class PeopleSpaceUtils { if (DEBUG) { Log.i(TAG, "Removing any notification stored for tile Id: " + tile.getId()); } return tile PeopleSpaceTile.Builder updatedTile = tile .toBuilder() // Reset notification content. .setNotificationKey(null) Loading @@ -212,8 +212,15 @@ public class PeopleSpaceUtils { .setNotificationDataUri(null) .setMessagesCount(0) // Reset missed calls category. .setNotificationCategory(null) .build(); .setNotificationCategory(null); // Only set last interaction to now if we are clearing a notification. if (!TextUtils.isEmpty(tile.getNotificationKey())) { long currentTimeMillis = System.currentTimeMillis(); if (DEBUG) Log.d(TAG, "Set last interaction on clear: " + currentTimeMillis); updatedTile.setLastInteractionTimestamp(currentTimeMillis); } return updatedTile.build(); } /** Loading @@ -227,10 +234,11 @@ public class PeopleSpaceUtils { if (DEBUG) Log.d(TAG, "Tile key: " + key.toString() + ". Notification is null"); return removeNotificationFields(tile); } Notification notification = notificationEntry.getSbn().getNotification(); StatusBarNotification sbn = notificationEntry.getSbn(); Notification notification = sbn.getNotification(); PeopleSpaceTile.Builder updatedTile = tile.toBuilder(); String uriFromNotification = getContactUri(notificationEntry.getSbn()); String uriFromNotification = getContactUri(sbn); if (appWidgetId.isPresent() && tile.getContactUri() == null && !TextUtils.isEmpty( uriFromNotification)) { if (DEBUG) Log.d(TAG, "Add uri from notification to tile: " + uriFromNotification); Loading @@ -241,7 +249,6 @@ public class PeopleSpaceUtils { // Update cached tile in-memory. updatedTile.setContactUri(contactUri); } boolean isMissedCall = isMissedCall(notification); List<Notification.MessagingStyle.Message> messages = getMessagingStyleMessages(notification); Loading @@ -261,12 +268,13 @@ public class PeopleSpaceUtils { Uri dataUri = message != null ? message.getDataUri() : null; if (DEBUG) { Log.d(TAG, "Tile key: " + key.toString() + ". Notification message has text: " + hasMessageText); + hasMessageText + " Has last interaction: " + sbn.getPostTime()); } CharSequence sender = getSenderIfGroupConversation(notification, message); return updatedTile .setNotificationKey(notificationEntry.getSbn().getKey()) .setLastInteractionTimestamp(sbn.getPostTime()) .setNotificationKey(sbn.getKey()) .setNotificationCategory(notification.category) .setNotificationContent(content) .setNotificationSender(sender) Loading
packages/SystemUI/src/com/android/systemui/people/PeopleTileViewHelper.java +1 −1 Original line number Diff line number Diff line Loading @@ -835,7 +835,7 @@ public class PeopleTileViewHelper { return null; } else if (durationSinceLastInteraction.toDays() < DAYS_IN_A_WEEK) { return context.getString(R.string.timestamp, formatter.formatMeasures( new Measure(durationSinceLastInteraction.toHours(), new Measure(durationSinceLastInteraction.toDays(), MeasureUnit.DAY))); } else if (durationSinceLastInteraction.toDays() <= DAYS_IN_A_WEEK * 2) { return context.getString(durationSinceLastInteraction.toDays() == DAYS_IN_A_WEEK Loading
packages/SystemUI/tests/src/com/android/systemui/people/widget/PeopleSpaceWidgetManagerTest.java +6 −1 Original line number Diff line number Diff line Loading @@ -191,6 +191,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { | SUPPRESSED_EFFECT_LIGHTS | SUPPRESSED_EFFECT_PEEK | SUPPRESSED_EFFECT_NOTIFICATION_LIST; private static final long SBN_POST_TIME = 567L; private ShortcutInfo mShortcutInfo; private NotificationEntry mNotificationEntry; Loading Loading @@ -607,6 +608,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT); assertThat(tile.getNotificationKey()).isEqualTo(NOTIFICATION_KEY); assertThat(tile.getLastInteractionTimestamp()).isEqualTo(SBN_POST_TIME); assertThat(tile.getNotificationContent()).isEqualTo(NOTIFICATION_CONTENT_1); verify(mAppWidgetManager, times(1)).updateAppWidget(eq(WIDGET_ID_WITH_SHORTCUT), any()); Loading Loading @@ -917,18 +919,20 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { .setSbn(sbn) .setId(1)); mClock.advanceTime(MIN_LINGER_DURATION); long timestampBeforeNotificationClear = System.currentTimeMillis(); NotifEvent notif1b = mNoMan.retractNotif(notif1.sbn, 0); mClock.advanceTime(MIN_LINGER_DURATION); PeopleSpaceTile tile = mManager.mTiles.get(WIDGET_ID_WITH_SHORTCUT); assertThat(tile.getNotificationKey()).isEqualTo(null); assertThat(tile.getLastInteractionTimestamp()).isLessThan( timestampBeforeNotificationClear); assertThat(tile.getNotificationContent()).isEqualTo(null); assertThat(tile.getNotificationDataUri()).isEqualTo(null); verify(mAppWidgetManager, times(2)).updateAppWidget(eq(WIDGET_ID_WITH_SHORTCUT), any()); } @Test public void testAddThenReconfigureWidgetsUpdatesStorageCacheAndListeners() throws Exception { Loading Loading @@ -1446,6 +1450,7 @@ public class PeopleSpaceWidgetManagerTest extends SysuiTestCase { .setNotification(notification) .setPkg(TEST_PACKAGE_A) .setUid(0) .setPostTime(SBN_POST_TIME) .setUser(new UserHandle(0)) .build(); } Loading
services/people/java/com/android/server/people/data/DataManager.java +13 −2 Original line number Diff line number Diff line Loading @@ -1149,11 +1149,11 @@ public class DataManager { if (conversationInfo == null) { return; } if (DEBUG) Log.d(TAG, "Last event from notification: " + sbn.getPostTime()); ConversationInfo updated = new ConversationInfo.Builder(conversationInfo) .setLastEventTimestamp(sbn.getPostTime()) .setParentNotificationChannelId(sbn.getNotification().getChannelId()) .build(); // Don't update listeners on notifications posted. packageData.getConversationStore().addOrUpdate(updated); EventHistoryImpl eventHistory = packageData.getEventStore().getOrCreateEventHistory( Loading Loading @@ -1186,9 +1186,19 @@ public class DataManager { if (reason != REASON_CLICK || packageData == null) { return; } long currentTime = System.currentTimeMillis(); ConversationInfo conversationInfo = packageData.getConversationInfo(shortcutId); if (conversationInfo == null) { return; } if (DEBUG) Log.d(TAG, "Last event from notification removed: " + currentTime); ConversationInfo updated = new ConversationInfo.Builder(conversationInfo) .setLastEventTimestamp(currentTime) .build(); packageData.getConversationStore().addOrUpdate(updated); EventHistoryImpl eventHistory = packageData.getEventStore().getOrCreateEventHistory( EventStore.CATEGORY_SHORTCUT_BASED, shortcutId); long currentTime = System.currentTimeMillis(); eventHistory.addEvent(new Event(currentTime, Event.TYPE_NOTIFICATION_OPENED)); } Loading Loading @@ -1265,6 +1275,7 @@ public class DataManager { public void onEvent(PackageData packageData, ConversationInfo conversationInfo, Event event) { if (event.getType() == Event.TYPE_IN_APP_CONVERSATION) { if (DEBUG) Log.d(TAG, "Last event from in-app: " + event.getTimestamp()); ConversationInfo updated = new ConversationInfo.Builder(conversationInfo) .setLastEventTimestamp(event.getTimestamp()) .build(); Loading
services/tests/servicestests/src/com/android/server/people/data/DataManagerTest.java +21 −1 Original line number Diff line number Diff line Loading @@ -693,7 +693,6 @@ public final class DataManagerTest { NotificationListenerService listenerService = mDataManager.getNotificationListenerServiceForTesting(USER_ID_PRIMARY); listenerService.onNotificationPosted(mStatusBarNotification); ConversationChannel result = mDataManager.getConversation(TEST_PKG_NAME, USER_ID_PRIMARY, TEST_SHORTCUT_ID); Loading Loading @@ -1360,6 +1359,27 @@ public final class DataManagerTest { assertTrue(result.isEmpty()); } @Test public void testNotificationRemoved() { mDataManager.onUserUnlocked(USER_ID_PRIMARY); ShortcutInfo shortcut = buildShortcutInfo(TEST_PKG_NAME, USER_ID_PRIMARY, TEST_SHORTCUT_ID, buildPerson()); shortcut.setCached(ShortcutInfo.FLAG_CACHED_NOTIFICATIONS); mDataManager.addOrUpdateConversationInfo(shortcut); NotificationListenerService listenerService = mDataManager.getNotificationListenerServiceForTesting(USER_ID_PRIMARY); listenerService.onNotificationPosted(mStatusBarNotification); listenerService.onNotificationRemoved(mStatusBarNotification, null, NotificationListenerService.REASON_CANCEL); ConversationInfo conversationInfo = mDataManager.getPackage(TEST_PKG_NAME, USER_ID_PRIMARY) .getConversationStore() .getConversation(TEST_SHORTCUT_ID); assertEquals(conversationInfo.getLastEventTimestamp(), System.currentTimeMillis()); } @Test public void testRemoveRecentConversation() { mDataManager.onUserUnlocked(USER_ID_PRIMARY); Loading