summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/people/java/com/android/server/people/data/DataManager.java8
-rw-r--r--services/people/java/com/android/server/people/data/UsageStatsQueryHelper.java17
-rw-r--r--services/tests/servicestests/src/com/android/server/people/data/DataManagerTest.java23
-rw-r--r--services/tests/servicestests/src/com/android/server/people/data/UsageStatsQueryHelperTest.java22
4 files changed, 31 insertions, 39 deletions
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 2d7c937975bd..39a26662da4b 100644
--- a/services/people/java/com/android/server/people/data/DataManager.java
+++ b/services/people/java/com/android/server/people/data/DataManager.java
@@ -640,6 +640,14 @@ public class DataManager {
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) {
if (reason != REASON_CLICK) {
diff --git a/services/people/java/com/android/server/people/data/UsageStatsQueryHelper.java b/services/people/java/com/android/server/people/data/UsageStatsQueryHelper.java
index 6dcfaa00dfd5..72f1abb70e34 100644
--- a/services/people/java/com/android/server/people/data/UsageStatsQueryHelper.java
+++ b/services/people/java/com/android/server/people/data/UsageStatsQueryHelper.java
@@ -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;
@@ -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);
- }
}
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 0bb984ef164b..b6e6f97bcc13 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
@@ -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(
@@ -325,6 +326,28 @@ public final class DataManagerTest {
}
@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);
diff --git a/services/tests/servicestests/src/com/android/server/people/data/UsageStatsQueryHelperTest.java b/services/tests/servicestests/src/com/android/server/people/data/UsageStatsQueryHelperTest.java
index dc4876b665f7..d444466cdef5 100644
--- a/services/tests/servicestests/src/com/android/server/people/data/UsageStatsQueryHelperTest.java
+++ b/services/tests/servicestests/src/com/android/server/people/data/UsageStatsQueryHelperTest.java
@@ -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");
@@ -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();
@@ -114,19 +112,6 @@ public final class UsageStatsQueryHelperTest {
}
@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(
createLocusIdSetEvent(100_000L, LOCUS_ID_1.getId()),
@@ -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;