diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index a808795cbc0a9..5ec8e3f70955d 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -943,7 +943,8 @@ public class NotificationManagerService extends SystemService { .addTaggedData(MetricsEvent.NOTIFICATION_LOCATION, nv.location.toMetricsEventEnum())); mNotificationRecordLogger.log( - NotificationRecordLogger.NotificationEvent.NOTIFICATION_ACTION_CLICKED, r); + NotificationRecordLogger.NotificationEvent.fromAction(actionIndex, + generatedByAssistant, action.isContextual()), r); EventLogTags.writeNotificationActionClicked(key, actionIndex, r.getLifespanMs(now), r.getFreshnessMs(now), r.getExposureMs(now), nv.rank, nv.count); diff --git a/services/core/java/com/android/server/notification/NotificationRecordLogger.java b/services/core/java/com/android/server/notification/NotificationRecordLogger.java index 34e6ec18be881..e06e01e53852d 100644 --- a/services/core/java/com/android/server/notification/NotificationRecordLogger.java +++ b/services/core/java/com/android/server/notification/NotificationRecordLogger.java @@ -229,7 +229,7 @@ public interface NotificationRecordLogger { NOTIFICATION_NOT_POSTED_SNOOZED(319), @UiEvent(doc = "Notification was clicked.") NOTIFICATION_CLICKED(320), - @UiEvent(doc = "Notification action was clicked.") + @UiEvent(doc = "Notification action was clicked; unexpected position.") NOTIFICATION_ACTION_CLICKED(321), @UiEvent(doc = "Notification detail was expanded due to non-user action.") NOTIFICATION_DETAIL_OPEN_SYSTEM(327), @@ -245,7 +245,24 @@ public interface NotificationRecordLogger { NOTIFICATION_SMART_REPLIED(332), @UiEvent(doc = "Notification smart reply action was visible.") NOTIFICATION_SMART_REPLY_VISIBLE(333), - ; + @UiEvent(doc = "App-generated notification action at position 0 was clicked.") + NOTIFICATION_ACTION_CLICKED_0(450), + @UiEvent(doc = "App-generated notification action at position 1 was clicked.") + NOTIFICATION_ACTION_CLICKED_1(451), + @UiEvent(doc = "App-generated notification action at position 2 was clicked.") + NOTIFICATION_ACTION_CLICKED_2(452), + @UiEvent(doc = "Contextual notification action at position 0 was clicked.") + NOTIFICATION_CONTEXTUAL_ACTION_CLICKED_0(453), + @UiEvent(doc = "Contextual notification action at position 1 was clicked.") + NOTIFICATION_CONTEXTUAL_ACTION_CLICKED_1(454), + @UiEvent(doc = "Contextual notification action at position 2 was clicked.") + NOTIFICATION_CONTEXTUAL_ACTION_CLICKED_2(455), + @UiEvent(doc = "Notification assistant generated notification action at 0 was clicked.") + NOTIFICATION_ASSIST_ACTION_CLICKED_0(456), + @UiEvent(doc = "Notification assistant generated notification action at 1 was clicked.") + NOTIFICATION_ASSIST_ACTION_CLICKED_1(457), + @UiEvent(doc = "Notification assistant generated notification action at 2 was clicked.") + NOTIFICATION_ASSIST_ACTION_CLICKED_2(458); private final int mId; NotificationEvent(int id) { @@ -264,6 +281,21 @@ public interface NotificationRecordLogger { } return expanded ? NOTIFICATION_DETAIL_OPEN_SYSTEM : NOTIFICATION_DETAIL_CLOSE_SYSTEM; } + public static NotificationEvent fromAction(int index, boolean isAssistant, + boolean isContextual) { + if (index < 0 || index > 2) { + return NOTIFICATION_ACTION_CLICKED; + } + if (isAssistant) { // Assistant actions are contextual by definition + return NotificationEvent.values()[ + NOTIFICATION_ASSIST_ACTION_CLICKED_0.ordinal() + index]; + } + if (isContextual) { + return NotificationEvent.values()[ + NOTIFICATION_CONTEXTUAL_ACTION_CLICKED_0.ordinal() + index]; + } + return NotificationEvent.values()[NOTIFICATION_ACTION_CLICKED_0.ordinal() + index]; + } } enum NotificationPanelEvent implements UiEventLogger.UiEventEnum { diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java index bda0c610fa12b..babe80e4b6122 100755 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -4932,7 +4932,32 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { eq(r.getSbn()), eq(actionIndex), eq(action), eq(generatedByAssistant)); assertEquals(1, mNotificationRecordLogger.numCalls()); - assertEquals(NotificationRecordLogger.NotificationEvent.NOTIFICATION_ACTION_CLICKED, + assertEquals( + NotificationRecordLogger.NotificationEvent.NOTIFICATION_ACTION_CLICKED_2, + mNotificationRecordLogger.event(0)); + } + + @Test + public void testOnAssistantNotificationActionClick() { + final int actionIndex = 1; + final Notification.Action action = + new Notification.Action.Builder(null, "text", null).build(); + final boolean generatedByAssistant = true; + + NotificationRecord r = generateNotificationRecord(mTestNotificationChannel); + mService.addNotification(r); + + NotificationVisibility notificationVisibility = + NotificationVisibility.obtain(r.getKey(), 1, 2, true); + mService.mNotificationDelegate.onNotificationActionClick( + 10, 10, r.getKey(), actionIndex, action, notificationVisibility, + generatedByAssistant); + verify(mAssistants).notifyAssistantActionClicked( + eq(r.getSbn()), eq(actionIndex), eq(action), eq(generatedByAssistant)); + + assertEquals(1, mNotificationRecordLogger.numCalls()); + assertEquals( + NotificationRecordLogger.NotificationEvent.NOTIFICATION_ASSIST_ACTION_CLICKED_1, mNotificationRecordLogger.event(0)); }