Loading services/people/java/com/android/server/people/data/DataManager.java +8 −0 Original line number Diff line number Diff line Loading @@ -639,6 +639,14 @@ public class DataManager { /** Listener for the notifications and their settings changes. */ private class NotificationListener extends NotificationListenerService { @Override public void onNotificationPosted(StatusBarNotification sbn) { EventHistoryImpl eventHistory = getEventHistoryIfEligible(sbn); if (eventHistory != null) { eventHistory.addEvent(new Event(sbn.getPostTime(), Event.TYPE_NOTIFICATION_POSTED)); } } @Override public void onNotificationRemoved(StatusBarNotification sbn, RankingMap rankingMap, int reason) { Loading services/people/java/com/android/server/people/data/UsageStatsQueryHelper.java +0 −17 Original line number Diff line number Diff line Loading @@ -80,10 +80,6 @@ class UsageStatsQueryHelper { addEventByShortcutId(packageData, e.getShortcutId(), new Event(e.getTimeStamp(), Event.TYPE_SHORTCUT_INVOCATION)); break; case UsageEvents.Event.NOTIFICATION_INTERRUPTION: addEventByNotificationChannelId(packageData, e.getNotificationChannelId(), new Event(e.getTimeStamp(), Event.TYPE_NOTIFICATION_POSTED)); break; case UsageEvents.Event.LOCUS_ID_SET: onInAppConversationEnded(packageData, e); LocusId locusId = e.getLocusId() != null ? new LocusId(e.getLocusId()) : null; Loading Loading @@ -142,17 +138,4 @@ class UsageStatsQueryHelper { EventStore.CATEGORY_LOCUS_ID_BASED, locusId.getId()); eventHistory.addEvent(event); } private void addEventByNotificationChannelId(PackageData packageData, String notificationChannelId, Event event) { ConversationInfo conversationInfo = packageData.getConversationStore().getConversationByNotificationChannelId( notificationChannelId); if (conversationInfo == null) { return; } EventHistoryImpl eventHistory = packageData.getEventStore().getOrCreateEventHistory( EventStore.CATEGORY_SHORTCUT_BASED, conversationInfo.getShortcutId()); eventHistory.addEvent(event); } } services/tests/servicestests/src/com/android/server/people/data/DataManagerTest.java +23 −0 Original line number Diff line number Diff line Loading @@ -184,6 +184,7 @@ public final class DataManagerTest { when(mStatusBarNotification.getNotification()).thenReturn(mNotification); when(mStatusBarNotification.getPackageName()).thenReturn(TEST_PKG_NAME); when(mStatusBarNotification.getUser()).thenReturn(UserHandle.of(USER_ID_PRIMARY)); when(mStatusBarNotification.getPostTime()).thenReturn(System.currentTimeMillis()); when(mNotification.getShortcutId()).thenReturn(TEST_SHORTCUT_ID); mNotificationChannel = new NotificationChannel( Loading Loading @@ -324,6 +325,28 @@ public final class DataManagerTest { assertEquals(newPhoneNumber, conversations.get(0).getContactPhoneNumber()); } @Test public void testNotificationPosted() { mDataManager.onUserUnlocked(USER_ID_PRIMARY); ShortcutInfo shortcut = buildShortcutInfo(TEST_PKG_NAME, USER_ID_PRIMARY, TEST_SHORTCUT_ID, buildPerson()); mDataManager.onShortcutAddedOrUpdated(shortcut); NotificationListenerService listenerService = mDataManager.getNotificationListenerServiceForTesting(USER_ID_PRIMARY); listenerService.onNotificationPosted(mStatusBarNotification); List<Range<Long>> activeNotificationOpenTimeSlots = new ArrayList<>(); mDataManager.forAllPackages(packageData -> activeNotificationOpenTimeSlots.addAll( packageData.getEventHistory(TEST_SHORTCUT_ID) .getEventIndex(Event.TYPE_NOTIFICATION_POSTED) .getActiveTimeSlots())); assertEquals(1, activeNotificationOpenTimeSlots.size()); } @Test public void testNotificationOpened() { mDataManager.onUserUnlocked(USER_ID_PRIMARY); Loading services/tests/servicestests/src/com/android/server/people/data/UsageStatsQueryHelperTest.java +0 −22 Original line number Diff line number Diff line Loading @@ -59,7 +59,6 @@ public final class UsageStatsQueryHelperTest { private static final String PKG_NAME = "pkg"; private static final String ACTIVITY_NAME = "TestActivity"; private static final String SHORTCUT_ID = "abc"; private static final String NOTIFICATION_CHANNEL_ID = "test : abc"; private static final LocusId LOCUS_ID_1 = new LocusId("locus_1"); private static final LocusId LOCUS_ID_2 = new LocusId("locus_2"); Loading @@ -83,7 +82,6 @@ public final class UsageStatsQueryHelperTest { scheduledExecutorService, testDir, helper); mPackageData.mConversationStore.mConversationInfo = new ConversationInfo.Builder() .setShortcutId(SHORTCUT_ID) .setNotificationChannelId(NOTIFICATION_CHANNEL_ID) .setLocusId(LOCUS_ID_1) .build(); Loading Loading @@ -113,19 +111,6 @@ public final class UsageStatsQueryHelperTest { assertEquals(expectedEvent, events.get(0)); } @Test public void testQueryNotificationInterruptionEvent() { addUsageEvents(createNotificationInterruptionEvent(100L)); assertTrue(mHelper.querySince(50L)); assertEquals(100L, mHelper.getLastEventTimestamp()); Event expectedEvent = new Event(100L, Event.TYPE_NOTIFICATION_POSTED); List<Event> events = mPackageData.mEventStore.mShortcutEventHistory.queryEvents( Event.ALL_EVENT_TYPES, 0L, Long.MAX_VALUE); assertEquals(1, events.size()); assertEquals(expectedEvent, events.get(0)); } @Test public void testInAppConversationSwitch() { addUsageEvents( Loading Loading @@ -203,13 +188,6 @@ public final class UsageStatsQueryHelperTest { return e; } private static UsageEvents.Event createNotificationInterruptionEvent(long timestamp) { UsageEvents.Event e = createUsageEvent(UsageEvents.Event.NOTIFICATION_INTERRUPTION, timestamp); e.mNotificationChannelId = NOTIFICATION_CHANNEL_ID; return e; } private static UsageEvents.Event createLocusIdSetEvent(long timestamp, String locusId) { UsageEvents.Event e = createUsageEvent(UsageEvents.Event.LOCUS_ID_SET, timestamp); e.mClass = ACTIVITY_NAME; Loading Loading
services/people/java/com/android/server/people/data/DataManager.java +8 −0 Original line number Diff line number Diff line Loading @@ -639,6 +639,14 @@ public class DataManager { /** Listener for the notifications and their settings changes. */ private class NotificationListener extends NotificationListenerService { @Override public void onNotificationPosted(StatusBarNotification sbn) { EventHistoryImpl eventHistory = getEventHistoryIfEligible(sbn); if (eventHistory != null) { eventHistory.addEvent(new Event(sbn.getPostTime(), Event.TYPE_NOTIFICATION_POSTED)); } } @Override public void onNotificationRemoved(StatusBarNotification sbn, RankingMap rankingMap, int reason) { Loading
services/people/java/com/android/server/people/data/UsageStatsQueryHelper.java +0 −17 Original line number Diff line number Diff line Loading @@ -80,10 +80,6 @@ class UsageStatsQueryHelper { addEventByShortcutId(packageData, e.getShortcutId(), new Event(e.getTimeStamp(), Event.TYPE_SHORTCUT_INVOCATION)); break; case UsageEvents.Event.NOTIFICATION_INTERRUPTION: addEventByNotificationChannelId(packageData, e.getNotificationChannelId(), new Event(e.getTimeStamp(), Event.TYPE_NOTIFICATION_POSTED)); break; case UsageEvents.Event.LOCUS_ID_SET: onInAppConversationEnded(packageData, e); LocusId locusId = e.getLocusId() != null ? new LocusId(e.getLocusId()) : null; Loading Loading @@ -142,17 +138,4 @@ class UsageStatsQueryHelper { EventStore.CATEGORY_LOCUS_ID_BASED, locusId.getId()); eventHistory.addEvent(event); } private void addEventByNotificationChannelId(PackageData packageData, String notificationChannelId, Event event) { ConversationInfo conversationInfo = packageData.getConversationStore().getConversationByNotificationChannelId( notificationChannelId); if (conversationInfo == null) { return; } EventHistoryImpl eventHistory = packageData.getEventStore().getOrCreateEventHistory( EventStore.CATEGORY_SHORTCUT_BASED, conversationInfo.getShortcutId()); eventHistory.addEvent(event); } }
services/tests/servicestests/src/com/android/server/people/data/DataManagerTest.java +23 −0 Original line number Diff line number Diff line Loading @@ -184,6 +184,7 @@ public final class DataManagerTest { when(mStatusBarNotification.getNotification()).thenReturn(mNotification); when(mStatusBarNotification.getPackageName()).thenReturn(TEST_PKG_NAME); when(mStatusBarNotification.getUser()).thenReturn(UserHandle.of(USER_ID_PRIMARY)); when(mStatusBarNotification.getPostTime()).thenReturn(System.currentTimeMillis()); when(mNotification.getShortcutId()).thenReturn(TEST_SHORTCUT_ID); mNotificationChannel = new NotificationChannel( Loading Loading @@ -324,6 +325,28 @@ public final class DataManagerTest { assertEquals(newPhoneNumber, conversations.get(0).getContactPhoneNumber()); } @Test public void testNotificationPosted() { mDataManager.onUserUnlocked(USER_ID_PRIMARY); ShortcutInfo shortcut = buildShortcutInfo(TEST_PKG_NAME, USER_ID_PRIMARY, TEST_SHORTCUT_ID, buildPerson()); mDataManager.onShortcutAddedOrUpdated(shortcut); NotificationListenerService listenerService = mDataManager.getNotificationListenerServiceForTesting(USER_ID_PRIMARY); listenerService.onNotificationPosted(mStatusBarNotification); List<Range<Long>> activeNotificationOpenTimeSlots = new ArrayList<>(); mDataManager.forAllPackages(packageData -> activeNotificationOpenTimeSlots.addAll( packageData.getEventHistory(TEST_SHORTCUT_ID) .getEventIndex(Event.TYPE_NOTIFICATION_POSTED) .getActiveTimeSlots())); assertEquals(1, activeNotificationOpenTimeSlots.size()); } @Test public void testNotificationOpened() { mDataManager.onUserUnlocked(USER_ID_PRIMARY); Loading
services/tests/servicestests/src/com/android/server/people/data/UsageStatsQueryHelperTest.java +0 −22 Original line number Diff line number Diff line Loading @@ -59,7 +59,6 @@ public final class UsageStatsQueryHelperTest { private static final String PKG_NAME = "pkg"; private static final String ACTIVITY_NAME = "TestActivity"; private static final String SHORTCUT_ID = "abc"; private static final String NOTIFICATION_CHANNEL_ID = "test : abc"; private static final LocusId LOCUS_ID_1 = new LocusId("locus_1"); private static final LocusId LOCUS_ID_2 = new LocusId("locus_2"); Loading @@ -83,7 +82,6 @@ public final class UsageStatsQueryHelperTest { scheduledExecutorService, testDir, helper); mPackageData.mConversationStore.mConversationInfo = new ConversationInfo.Builder() .setShortcutId(SHORTCUT_ID) .setNotificationChannelId(NOTIFICATION_CHANNEL_ID) .setLocusId(LOCUS_ID_1) .build(); Loading Loading @@ -113,19 +111,6 @@ public final class UsageStatsQueryHelperTest { assertEquals(expectedEvent, events.get(0)); } @Test public void testQueryNotificationInterruptionEvent() { addUsageEvents(createNotificationInterruptionEvent(100L)); assertTrue(mHelper.querySince(50L)); assertEquals(100L, mHelper.getLastEventTimestamp()); Event expectedEvent = new Event(100L, Event.TYPE_NOTIFICATION_POSTED); List<Event> events = mPackageData.mEventStore.mShortcutEventHistory.queryEvents( Event.ALL_EVENT_TYPES, 0L, Long.MAX_VALUE); assertEquals(1, events.size()); assertEquals(expectedEvent, events.get(0)); } @Test public void testInAppConversationSwitch() { addUsageEvents( Loading Loading @@ -203,13 +188,6 @@ public final class UsageStatsQueryHelperTest { return e; } private static UsageEvents.Event createNotificationInterruptionEvent(long timestamp) { UsageEvents.Event e = createUsageEvent(UsageEvents.Event.NOTIFICATION_INTERRUPTION, timestamp); e.mNotificationChannelId = NOTIFICATION_CHANNEL_ID; return e; } private static UsageEvents.Event createLocusIdSetEvent(long timestamp, String locusId) { UsageEvents.Event e = createUsageEvent(UsageEvents.Event.LOCUS_ID_SET, timestamp); e.mClass = ACTIVITY_NAME; Loading