Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7014861f authored by Beverly Tai's avatar Beverly Tai Committed by Android (Google) Code Review
Browse files

Merge "Add getLastInteraction API to PeopleManager"

parents 0df7f453 feb12590
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -39,4 +39,10 @@ interface IPeopleManager {


    /** Removes all the recent conversations and uncaches their cached shortcuts. */
    /** Removes all the recent conversations and uncaches their cached shortcuts. */
    void removeAllRecentConversations();
    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);
}
}
+6 −0
Original line number Original line Diff line number Diff line
@@ -123,6 +123,12 @@ public class PeopleService extends SystemService {
            mDataManager.removeAllRecentConversations(
            mDataManager.removeAllRecentConversations(
                    Binder.getCallingUserHandle().getIdentifier());
                    Binder.getCallingUserHandle().getIdentifier());
        }
        }

        @Override
        public long getLastInteraction(String packageName, int userId, String shortcutId) {
            enforceSystemOrRoot("get last interaction");
            return mDataManager.getLastInteraction(packageName, userId, shortcutId);
        }
    }
    }


    @VisibleForTesting
    @VisibleForTesting
+15 −0
Original line number Original line Diff line number Diff line
@@ -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. */
    /** Reports the sharing related {@link AppTargetEvent} from App Prediction Manager. */
    public void reportShareTargetEvent(@NonNull AppTargetEvent event,
    public void reportShareTargetEvent(@NonNull AppTargetEvent event,
            @NonNull IntentFilter intentFilter) {
            @NonNull IntentFilter intentFilter) {
+24 −0
Original line number Original line Diff line number Diff line
@@ -837,6 +837,30 @@ public final class DataManagerTest {
        assertTrue(result.get(0).hasActiveNotifications());
        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
    @Test
    public void testNonCachedShortcutNotInRecentList() {
    public void testNonCachedShortcutNotInRecentList() {
        mDataManager.onUserUnlocked(USER_ID_PRIMARY);
        mDataManager.onUserUnlocked(USER_ID_PRIMARY);