diff --git a/core/java/android/app/people/IPeopleManager.aidl b/core/java/android/app/people/IPeopleManager.aidl index 61dac0d64422d..c547ef1e7e9b5 100644 --- a/core/java/android/app/people/IPeopleManager.aidl +++ b/core/java/android/app/people/IPeopleManager.aidl @@ -39,4 +39,10 @@ interface IPeopleManager { /** Removes all the recent conversations and uncaches their cached shortcuts. */ void removeAllRecentConversations(); + + /** + * Returns the last interaction with the specified conversation. If the + * conversation can't be found or no interactions have been recorded, returns 0L. + */ + long getLastInteraction(in String packageName, int userId, in String shortcutId); } diff --git a/services/people/java/com/android/server/people/PeopleService.java b/services/people/java/com/android/server/people/PeopleService.java index e3f576287c805..6e3bde3a41a4a 100644 --- a/services/people/java/com/android/server/people/PeopleService.java +++ b/services/people/java/com/android/server/people/PeopleService.java @@ -123,6 +123,12 @@ public class PeopleService extends SystemService { mDataManager.removeAllRecentConversations( Binder.getCallingUserHandle().getIdentifier()); } + + @Override + public long getLastInteraction(String packageName, int userId, String shortcutId) { + enforceSystemOrRoot("get last interaction"); + return mDataManager.getLastInteraction(packageName, userId, shortcutId); + } } @VisibleForTesting diff --git a/services/people/java/com/android/server/people/data/DataManager.java b/services/people/java/com/android/server/people/data/DataManager.java index 5e67e6c7cb41b..87f2c581ef8f3 100644 --- a/services/people/java/com/android/server/people/data/DataManager.java +++ b/services/people/java/com/android/server/people/data/DataManager.java @@ -275,6 +275,21 @@ public class DataManager { }); } + /** + * Returns the last notification interaction with the specified conversation. If the + * conversation can't be found or no interactions have been recorded, returns 0L. + */ + public long getLastInteraction(String packageName, int userId, String shortcutId) { + final PackageData packageData = getPackage(packageName, userId); + if (packageData != null) { + final ConversationInfo conversationInfo = packageData.getConversationInfo(shortcutId); + if (conversationInfo != null) { + return conversationInfo.getLastEventTimestamp(); + } + } + return 0L; + } + /** Reports the sharing related {@link AppTargetEvent} from App Prediction Manager. */ public void reportShareTargetEvent(@NonNull AppTargetEvent event, @NonNull IntentFilter intentFilter) { diff --git a/services/tests/servicestests/src/com/android/server/people/data/DataManagerTest.java b/services/tests/servicestests/src/com/android/server/people/data/DataManagerTest.java index efba9da06746a..f37054d269b10 100644 --- a/services/tests/servicestests/src/com/android/server/people/data/DataManagerTest.java +++ b/services/tests/servicestests/src/com/android/server/people/data/DataManagerTest.java @@ -837,6 +837,30 @@ public final class DataManagerTest { assertTrue(result.get(0).hasActiveNotifications()); } + @Test + public void testGetLastInteraction() { + mDataManager.onUserUnlocked(USER_ID_PRIMARY); + + ShortcutInfo shortcut = buildShortcutInfo(TEST_PKG_NAME, USER_ID_PRIMARY, TEST_SHORTCUT_ID, + buildPerson()); + mDataManager.addOrUpdateConversationInfo(shortcut); + + NotificationListenerService listenerService = + mDataManager.getNotificationListenerServiceForTesting(USER_ID_PRIMARY); + listenerService.onNotificationPosted(mStatusBarNotification); + + assertEquals(mStatusBarNotification.getPostTime(), + mDataManager.getLastInteraction(TEST_PKG_NAME, USER_ID_PRIMARY, TEST_SHORTCUT_ID)); + assertEquals(0L, + mDataManager.getLastInteraction("not_test_pkg", USER_ID_PRIMARY, TEST_SHORTCUT_ID)); + assertEquals(0L, + mDataManager.getLastInteraction(TEST_PKG_NAME, USER_ID_PRIMARY_MANAGED, + TEST_SHORTCUT_ID)); + assertEquals(0L, + mDataManager.getLastInteraction(TEST_PKG_NAME, USER_ID_SECONDARY, + TEST_SHORTCUT_ID)); + } + @Test public void testNonCachedShortcutNotInRecentList() { mDataManager.onUserUnlocked(USER_ID_PRIMARY);