Merge "Add getLastInteraction API to PeopleManager"

This commit is contained in:
Beverly Tai
2020-09-28 18:16:30 +00:00
committed by Android (Google) Code Review
4 changed files with 51 additions and 0 deletions

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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) {

View File

@@ -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);