Loading services/core/java/com/android/server/notification/NotificationRecordLogger.java +6 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.server.notification; import static android.app.Flags.nmSummarization; import static android.app.Flags.nmSummarizationUi; import static android.service.notification.NotificationListenerService.REASON_ASSISTANT_CANCEL; import static android.service.notification.NotificationListenerService.REASON_CANCEL; import static android.service.notification.NotificationListenerService.REASON_CLEAR_DATA; Loading @@ -31,6 +33,7 @@ import android.os.Bundle; import android.service.notification.Adjustment; import android.service.notification.NotificationListenerService; import android.service.notification.NotificationStats; import android.text.TextUtils; import android.util.Log; import com.android.internal.logging.InstanceId; Loading Loading @@ -531,6 +534,7 @@ interface NotificationRecordLogger { final int age_in_minutes; final boolean is_promoted_ongoing; final boolean has_promotable_characteristics; final boolean has_summary; @DurationMillisLong long post_duration_millis; // Not final; calculated at the end. NotificationReported(NotificationRecordPair p, Loading Loading @@ -572,6 +576,8 @@ interface NotificationRecordLogger { p.r.getSbn().getPostTime(), notification.getWhen()); this.is_promoted_ongoing = notification.isPromotedOngoing(); this.has_promotable_characteristics = notification.hasPromotableCharacteristics(); this.has_summary = (nmSummarization() || nmSummarizationUi()) ? !TextUtils.isEmpty(p.r.getSummarization()) : false; } } Loading services/core/java/com/android/server/notification/NotificationRecordLoggerImpl.java +2 −1 Original line number Diff line number Diff line Loading @@ -80,7 +80,8 @@ class NotificationRecordLoggerImpl implements NotificationRecordLogger { notificationReported.is_locked, notificationReported.age_in_minutes, notificationReported.is_promoted_ongoing, notificationReported.has_promotable_characteristics); notificationReported.has_promotable_characteristics, notificationReported.has_summary); } @Override Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +52 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,8 @@ import static android.app.ActivityTaskManager.INVALID_TASK_ID; import static android.app.Flags.FLAG_API_RICH_ONGOING; import static android.app.Flags.FLAG_API_RICH_ONGOING_PERMISSION; import static android.app.Flags.FLAG_NM_SUMMARIZATION; import static android.app.Flags.FLAG_NM_SUMMARIZATION_UI; import static android.app.Flags.FLAG_OPT_IN_RICH_ONGOING; import static android.app.Flags.FLAG_UI_RICH_ONGOING; import static android.app.Notification.EXTRA_ALLOW_DURING_SETUP; import static android.app.Notification.EXTRA_PICTURE; Loading Loading @@ -7831,6 +7833,56 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { instanceId2.getId() /*instance_id*/, r2.getUid())); } @Test @EnableFlags({FLAG_NM_SUMMARIZATION, FLAG_NM_SUMMARIZATION_UI}) public void testSummarizationAdjustmentsLogged() throws RemoteException { NotificationManagerService.WorkerHandler handler = mock( NotificationManagerService.WorkerHandler.class); mService.setHandler(handler); when(mAssistants.isSameUser(any(), anyInt())).thenReturn(true); when(mAssistants.isServiceTokenValidLocked(any())).thenReturn(true); when(mAssistants.isAdjustmentAllowedForPackage(anyInt(), anyString(), anyString())).thenReturn(true); // Set up two notifications, one of which will be adjusted final NotificationRecord r1 = generateNotificationRecord( mTestNotificationChannel, 1, null, true); r1.getSbn().setInstanceId(mNotificationInstanceIdSequence.newInstanceId()); mService.addNotification(r1); final NotificationRecord r2 = generateNotificationRecord( mTestNotificationChannel, 2, null, true); r2.getSbn().setInstanceId(mNotificationInstanceIdSequence.newInstanceId()); mService.addNotification(r2); Bundle signals1 = new Bundle(); signals1.putCharSequence(Adjustment.KEY_SUMMARIZATION, "hello"); Adjustment adjustment1 = new Adjustment(r1.getSbn().getPackageName(), r1.getKey(), signals1, "", r1.getUser().getIdentifier()); mBinderService.applyAdjustmentFromAssistant(null, adjustment1); waitForIdle(); // Actually apply the adjustment & recalculate importance when run doAnswer(invocationOnMock -> { ((NotificationRecord) invocationOnMock.getArguments()[0]) .applyAdjustments(); ((NotificationRecord) invocationOnMock.getArguments()[0]) .calculateImportance(); return null; }).when(mRankingHelper).extractSignals(any(NotificationRecord.class)); // Now make sure that when the sort happens, we actually log the changes. mService.handleRankingSort(); // first verify we got the actual summarization in assertThat(r1.getSummarization()).isEqualTo("hello"); // Expect one log only, for r1's adjustment assertThat(mNotificationRecordLogger.numCalls()).isEqualTo(1); assertThat(mNotificationRecordLogger.event(0)).isEqualTo(NOTIFICATION_ADJUSTED); assertThat(mNotificationRecordLogger.get(0).getInstanceId()).isEqualTo( r1.getSbn().getInstanceId().getId()); } @Test public void testAdjustmentToImportanceNone_cancelsNotification() throws Exception { NotificationManagerService.WorkerHandler handler = mock( Loading Loading
services/core/java/com/android/server/notification/NotificationRecordLogger.java +6 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.server.notification; import static android.app.Flags.nmSummarization; import static android.app.Flags.nmSummarizationUi; import static android.service.notification.NotificationListenerService.REASON_ASSISTANT_CANCEL; import static android.service.notification.NotificationListenerService.REASON_CANCEL; import static android.service.notification.NotificationListenerService.REASON_CLEAR_DATA; Loading @@ -31,6 +33,7 @@ import android.os.Bundle; import android.service.notification.Adjustment; import android.service.notification.NotificationListenerService; import android.service.notification.NotificationStats; import android.text.TextUtils; import android.util.Log; import com.android.internal.logging.InstanceId; Loading Loading @@ -531,6 +534,7 @@ interface NotificationRecordLogger { final int age_in_minutes; final boolean is_promoted_ongoing; final boolean has_promotable_characteristics; final boolean has_summary; @DurationMillisLong long post_duration_millis; // Not final; calculated at the end. NotificationReported(NotificationRecordPair p, Loading Loading @@ -572,6 +576,8 @@ interface NotificationRecordLogger { p.r.getSbn().getPostTime(), notification.getWhen()); this.is_promoted_ongoing = notification.isPromotedOngoing(); this.has_promotable_characteristics = notification.hasPromotableCharacteristics(); this.has_summary = (nmSummarization() || nmSummarizationUi()) ? !TextUtils.isEmpty(p.r.getSummarization()) : false; } } Loading
services/core/java/com/android/server/notification/NotificationRecordLoggerImpl.java +2 −1 Original line number Diff line number Diff line Loading @@ -80,7 +80,8 @@ class NotificationRecordLoggerImpl implements NotificationRecordLogger { notificationReported.is_locked, notificationReported.age_in_minutes, notificationReported.is_promoted_ongoing, notificationReported.has_promotable_characteristics); notificationReported.has_promotable_characteristics, notificationReported.has_summary); } @Override Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +52 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,8 @@ import static android.app.ActivityTaskManager.INVALID_TASK_ID; import static android.app.Flags.FLAG_API_RICH_ONGOING; import static android.app.Flags.FLAG_API_RICH_ONGOING_PERMISSION; import static android.app.Flags.FLAG_NM_SUMMARIZATION; import static android.app.Flags.FLAG_NM_SUMMARIZATION_UI; import static android.app.Flags.FLAG_OPT_IN_RICH_ONGOING; import static android.app.Flags.FLAG_UI_RICH_ONGOING; import static android.app.Notification.EXTRA_ALLOW_DURING_SETUP; import static android.app.Notification.EXTRA_PICTURE; Loading Loading @@ -7831,6 +7833,56 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { instanceId2.getId() /*instance_id*/, r2.getUid())); } @Test @EnableFlags({FLAG_NM_SUMMARIZATION, FLAG_NM_SUMMARIZATION_UI}) public void testSummarizationAdjustmentsLogged() throws RemoteException { NotificationManagerService.WorkerHandler handler = mock( NotificationManagerService.WorkerHandler.class); mService.setHandler(handler); when(mAssistants.isSameUser(any(), anyInt())).thenReturn(true); when(mAssistants.isServiceTokenValidLocked(any())).thenReturn(true); when(mAssistants.isAdjustmentAllowedForPackage(anyInt(), anyString(), anyString())).thenReturn(true); // Set up two notifications, one of which will be adjusted final NotificationRecord r1 = generateNotificationRecord( mTestNotificationChannel, 1, null, true); r1.getSbn().setInstanceId(mNotificationInstanceIdSequence.newInstanceId()); mService.addNotification(r1); final NotificationRecord r2 = generateNotificationRecord( mTestNotificationChannel, 2, null, true); r2.getSbn().setInstanceId(mNotificationInstanceIdSequence.newInstanceId()); mService.addNotification(r2); Bundle signals1 = new Bundle(); signals1.putCharSequence(Adjustment.KEY_SUMMARIZATION, "hello"); Adjustment adjustment1 = new Adjustment(r1.getSbn().getPackageName(), r1.getKey(), signals1, "", r1.getUser().getIdentifier()); mBinderService.applyAdjustmentFromAssistant(null, adjustment1); waitForIdle(); // Actually apply the adjustment & recalculate importance when run doAnswer(invocationOnMock -> { ((NotificationRecord) invocationOnMock.getArguments()[0]) .applyAdjustments(); ((NotificationRecord) invocationOnMock.getArguments()[0]) .calculateImportance(); return null; }).when(mRankingHelper).extractSignals(any(NotificationRecord.class)); // Now make sure that when the sort happens, we actually log the changes. mService.handleRankingSort(); // first verify we got the actual summarization in assertThat(r1.getSummarization()).isEqualTo("hello"); // Expect one log only, for r1's adjustment assertThat(mNotificationRecordLogger.numCalls()).isEqualTo(1); assertThat(mNotificationRecordLogger.event(0)).isEqualTo(NOTIFICATION_ADJUSTED); assertThat(mNotificationRecordLogger.get(0).getInstanceId()).isEqualTo( r1.getSbn().getInstanceId().getId()); } @Test public void testAdjustmentToImportanceNone_cancelsNotification() throws Exception { NotificationManagerService.WorkerHandler handler = mock( Loading