Loading services/core/java/com/android/server/notification/NotificationManagerService.java +16 −8 Original line number Diff line number Diff line Loading @@ -361,6 +361,7 @@ import com.android.server.lights.LightsManager; import com.android.server.notification.GroupHelper.NotificationAttributes; import com.android.server.notification.ManagedServices.ManagedServiceInfo; import com.android.server.notification.ManagedServices.UserProfiles; import com.android.server.notification.NotificationRecordLogger.NotificationReportedEvent; import com.android.server.notification.toast.CustomToastRecord; import com.android.server.notification.toast.TextToastRecord; import com.android.server.notification.toast.ToastRecord; Loading Loading @@ -1934,10 +1935,20 @@ public class NotificationManagerService extends SystemService { hasSensitiveContent, lifespanMs); } protected void logClassificationChannelAdjustmentReceived(boolean hasPosted, boolean isAlerting, int classification, int lifespanMs) { protected void logClassificationChannelAdjustmentReceived(NotificationRecord r, boolean hasPosted, int classification) { // Note that this value of isAlerting does not fully indicate whether a notif // would make a sound or HUN on device; it is an approximation for metrics. boolean isAlerting = r.getChannel().getImportance() >= IMPORTANCE_DEFAULT; int instanceId = r.getSbn().getInstanceId() == null ? 0 : r.getSbn().getInstanceId().getId(); FrameworkStatsLog.write(FrameworkStatsLog.NOTIFICATION_CHANNEL_CLASSIFICATION, hasPosted, isAlerting, classification, lifespanMs); hasPosted, isAlerting, classification, r.getLifespanMs(System.currentTimeMillis()), NotificationReportedEvent.NOTIFICATION_ADJUSTED.getId(), instanceId, r.getUid()); } protected final BroadcastReceiver mLocaleChangeReceiver = new BroadcastReceiver() { Loading Loading @@ -7052,11 +7063,8 @@ public class NotificationManagerService extends SystemService { int classification = adjustments.getInt(KEY_TYPE); // swap app provided type with the real thing adjustments.putParcelable(KEY_TYPE, newChannel); // Note that this value of isAlerting does not fully indicate whether a notif // would make a sound or HUN on device; it is an approximation for metrics. boolean isAlerting = r.getChannel().getImportance() >= IMPORTANCE_DEFAULT; logClassificationChannelAdjustmentReceived(isPosted, isAlerting, classification, r.getLifespanMs(System.currentTimeMillis())); logClassificationChannelAdjustmentReceived(r, isPosted, classification); } } r.addAdjustment(adjustment); Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +16 −7 Original line number Diff line number Diff line Loading @@ -311,6 +311,7 @@ import androidx.test.filters.SmallTest; import com.android.internal.R; import com.android.internal.config.sysui.TestableFlagResolver; import com.android.internal.logging.InstanceId; import com.android.internal.logging.InstanceIdSequence; import com.android.internal.logging.InstanceIdSequenceFake; import com.android.internal.messages.nano.SystemMessageProto; Loading Loading @@ -7637,7 +7638,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mTestNotificationChannel, 1, null, true)); when(r1.getLifespanMs(anyLong())).thenReturn(234); r1.getSbn().setInstanceId(mNotificationInstanceIdSequence.newInstanceId()); InstanceId instanceId1 = mNotificationInstanceIdSequence.newInstanceId(); r1.getSbn().setInstanceId(instanceId1); // Enqueues the notification to be posted, so hasPosted will be false. mService.addEnqueuedNotification(r1); Loading @@ -7648,8 +7650,10 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { r1.getSbn().getPackageName(), r1.getKey(), signals, "", r1.getUser().getIdentifier()); mBinderService.applyEnqueuedAdjustmentFromAssistant(null, adjustment1); assertTrue(mService.checkLastClassificationChannelLog(false /*hasPosted*/, true /*isAlerting*/, 3 /*TYPE_NEWS*/, 234)); assertTrue(mService.checkLastClassificationChannelLog(false /*=hasPosted*/, true /*=isAlerting*/, Adjustment.TYPE_NEWS, 234, NOTIFICATION_ADJUSTED.getId(), instanceId1.getId(), r1.getUid())); // Set up notifications that will be adjusted // This notification starts on a low importance channel, so isAlerting is false. Loading @@ -7659,7 +7663,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mLowImportanceNotificationChannel, 1, null, true)); when(r2.getLifespanMs(anyLong())).thenReturn(345); r2.getSbn().setInstanceId(mNotificationInstanceIdSequence.newInstanceId()); InstanceId instanceId2 = mNotificationInstanceIdSequence.newInstanceId(); r2.getSbn().setInstanceId(instanceId2); // Adds the notification as already posted, so hasPosted will be true. mService.addNotification(r2); // The signal is removed when used so it has to be readded. Loading @@ -7669,15 +7674,19 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { r2.getUser().getIdentifier()); mBinderService.applyEnqueuedAdjustmentFromAssistant(null, adjustment2); assertTrue(mService.checkLastClassificationChannelLog(true /*hasPosted*/, false /*isAlerting*/, 3 /*TYPE_NEWS*/, 345)); // currently failing false /*isAlerting*/, Adjustment.TYPE_NEWS, 345, NOTIFICATION_ADJUSTED.getId(), instanceId2.getId() /*instance_id*/, r2.getUid())); signals.putInt(Adjustment.KEY_TYPE, Adjustment.TYPE_PROMOTION); Adjustment adjustment3 = new Adjustment( r2.getSbn().getPackageName(), r2.getKey(), signals, "", r2.getUser().getIdentifier()); mBinderService.applyEnqueuedAdjustmentFromAssistant(null, adjustment3); assertTrue(mService.checkLastClassificationChannelLog(true /*hasPosted*/, false /*isAlerting*/, 1 /*TYPE_PROMOTION*/, 345)); assertTrue(mService.checkLastClassificationChannelLog(true /*=hasPosted*/, false /*=isAlerting*/, Adjustment.TYPE_PROMOTION, 345, NOTIFICATION_ADJUSTED.getId(), instanceId2.getId() /*instance_id*/, r2.getUid())); } @Test Loading services/tests/uiservicestests/src/com/android/server/notification/TestableNotificationManagerService.java +27 −4 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.server.notification; import static android.app.NotificationManager.IMPORTANCE_DEFAULT; import android.companion.ICompanionDeviceManager; import android.content.ComponentName; import android.content.Context; Loading @@ -25,6 +27,7 @@ import androidx.annotation.Nullable; import com.android.internal.logging.InstanceIdSequence; import com.android.server.notification.ManagedServices.ManagedServiceInfo; import com.android.server.notification.NotificationRecordLogger.NotificationReportedEvent; import java.util.HashSet; import java.util.Set; Loading Loading @@ -57,6 +60,9 @@ public class TestableNotificationManagerService extends NotificationManagerServi public boolean isAlerting; public long classification; public long lifetime; public long eventId; public long instanceId; public long uid; } public ClassificationChannelLog lastClassificationChannelLog = null; Loading Loading @@ -221,20 +227,34 @@ public class TestableNotificationManagerService extends NotificationManagerServi } @Override protected void logClassificationChannelAdjustmentReceived(boolean hasPosted, boolean isAlerting, int classification, int lifetimeMs) { protected void logClassificationChannelAdjustmentReceived(NotificationRecord r, boolean hasPosted, int classification) { boolean isAlerting = r.getChannel().getImportance() >= IMPORTANCE_DEFAULT; int instanceId = r.getSbn().getInstanceId() == null ? 0 : r.getSbn().getInstanceId().getId(); int lifetimeMs = r.getLifespanMs(System.currentTimeMillis()); int uid = r.getUid(); lastClassificationChannelLog = new ClassificationChannelLog(); lastClassificationChannelLog.hasPosted = hasPosted; lastClassificationChannelLog.isAlerting = isAlerting; lastClassificationChannelLog.classification = classification; lastClassificationChannelLog.lifetime = lifetimeMs; lastClassificationChannelLog.eventId = NotificationReportedEvent.NOTIFICATION_ADJUSTED.getId(); lastClassificationChannelLog.instanceId = instanceId; lastClassificationChannelLog.uid = uid; } /** * Returns true if the last recorded classification channel log has all the values specified. */ public boolean checkLastClassificationChannelLog(boolean hasPosted, boolean isAlerting, int classification, int lifetime) { int classification, int lifetime, int eventId, int instanceId, int uid) { if (lastClassificationChannelLog == null) { return false; } Loading @@ -242,6 +262,9 @@ public class TestableNotificationManagerService extends NotificationManagerServi return hasPosted == lastClassificationChannelLog.hasPosted && isAlerting == lastClassificationChannelLog.isAlerting && classification == lastClassificationChannelLog.classification && lifetime == lastClassificationChannelLog.lifetime; && lifetime == lastClassificationChannelLog.lifetime && eventId == lastClassificationChannelLog.eventId && instanceId == lastClassificationChannelLog.instanceId && uid == lastClassificationChannelLog.uid; } } Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +16 −8 Original line number Diff line number Diff line Loading @@ -361,6 +361,7 @@ import com.android.server.lights.LightsManager; import com.android.server.notification.GroupHelper.NotificationAttributes; import com.android.server.notification.ManagedServices.ManagedServiceInfo; import com.android.server.notification.ManagedServices.UserProfiles; import com.android.server.notification.NotificationRecordLogger.NotificationReportedEvent; import com.android.server.notification.toast.CustomToastRecord; import com.android.server.notification.toast.TextToastRecord; import com.android.server.notification.toast.ToastRecord; Loading Loading @@ -1934,10 +1935,20 @@ public class NotificationManagerService extends SystemService { hasSensitiveContent, lifespanMs); } protected void logClassificationChannelAdjustmentReceived(boolean hasPosted, boolean isAlerting, int classification, int lifespanMs) { protected void logClassificationChannelAdjustmentReceived(NotificationRecord r, boolean hasPosted, int classification) { // Note that this value of isAlerting does not fully indicate whether a notif // would make a sound or HUN on device; it is an approximation for metrics. boolean isAlerting = r.getChannel().getImportance() >= IMPORTANCE_DEFAULT; int instanceId = r.getSbn().getInstanceId() == null ? 0 : r.getSbn().getInstanceId().getId(); FrameworkStatsLog.write(FrameworkStatsLog.NOTIFICATION_CHANNEL_CLASSIFICATION, hasPosted, isAlerting, classification, lifespanMs); hasPosted, isAlerting, classification, r.getLifespanMs(System.currentTimeMillis()), NotificationReportedEvent.NOTIFICATION_ADJUSTED.getId(), instanceId, r.getUid()); } protected final BroadcastReceiver mLocaleChangeReceiver = new BroadcastReceiver() { Loading Loading @@ -7052,11 +7063,8 @@ public class NotificationManagerService extends SystemService { int classification = adjustments.getInt(KEY_TYPE); // swap app provided type with the real thing adjustments.putParcelable(KEY_TYPE, newChannel); // Note that this value of isAlerting does not fully indicate whether a notif // would make a sound or HUN on device; it is an approximation for metrics. boolean isAlerting = r.getChannel().getImportance() >= IMPORTANCE_DEFAULT; logClassificationChannelAdjustmentReceived(isPosted, isAlerting, classification, r.getLifespanMs(System.currentTimeMillis())); logClassificationChannelAdjustmentReceived(r, isPosted, classification); } } r.addAdjustment(adjustment); Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +16 −7 Original line number Diff line number Diff line Loading @@ -311,6 +311,7 @@ import androidx.test.filters.SmallTest; import com.android.internal.R; import com.android.internal.config.sysui.TestableFlagResolver; import com.android.internal.logging.InstanceId; import com.android.internal.logging.InstanceIdSequence; import com.android.internal.logging.InstanceIdSequenceFake; import com.android.internal.messages.nano.SystemMessageProto; Loading Loading @@ -7637,7 +7638,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mTestNotificationChannel, 1, null, true)); when(r1.getLifespanMs(anyLong())).thenReturn(234); r1.getSbn().setInstanceId(mNotificationInstanceIdSequence.newInstanceId()); InstanceId instanceId1 = mNotificationInstanceIdSequence.newInstanceId(); r1.getSbn().setInstanceId(instanceId1); // Enqueues the notification to be posted, so hasPosted will be false. mService.addEnqueuedNotification(r1); Loading @@ -7648,8 +7650,10 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { r1.getSbn().getPackageName(), r1.getKey(), signals, "", r1.getUser().getIdentifier()); mBinderService.applyEnqueuedAdjustmentFromAssistant(null, adjustment1); assertTrue(mService.checkLastClassificationChannelLog(false /*hasPosted*/, true /*isAlerting*/, 3 /*TYPE_NEWS*/, 234)); assertTrue(mService.checkLastClassificationChannelLog(false /*=hasPosted*/, true /*=isAlerting*/, Adjustment.TYPE_NEWS, 234, NOTIFICATION_ADJUSTED.getId(), instanceId1.getId(), r1.getUid())); // Set up notifications that will be adjusted // This notification starts on a low importance channel, so isAlerting is false. Loading @@ -7659,7 +7663,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mLowImportanceNotificationChannel, 1, null, true)); when(r2.getLifespanMs(anyLong())).thenReturn(345); r2.getSbn().setInstanceId(mNotificationInstanceIdSequence.newInstanceId()); InstanceId instanceId2 = mNotificationInstanceIdSequence.newInstanceId(); r2.getSbn().setInstanceId(instanceId2); // Adds the notification as already posted, so hasPosted will be true. mService.addNotification(r2); // The signal is removed when used so it has to be readded. Loading @@ -7669,15 +7674,19 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { r2.getUser().getIdentifier()); mBinderService.applyEnqueuedAdjustmentFromAssistant(null, adjustment2); assertTrue(mService.checkLastClassificationChannelLog(true /*hasPosted*/, false /*isAlerting*/, 3 /*TYPE_NEWS*/, 345)); // currently failing false /*isAlerting*/, Adjustment.TYPE_NEWS, 345, NOTIFICATION_ADJUSTED.getId(), instanceId2.getId() /*instance_id*/, r2.getUid())); signals.putInt(Adjustment.KEY_TYPE, Adjustment.TYPE_PROMOTION); Adjustment adjustment3 = new Adjustment( r2.getSbn().getPackageName(), r2.getKey(), signals, "", r2.getUser().getIdentifier()); mBinderService.applyEnqueuedAdjustmentFromAssistant(null, adjustment3); assertTrue(mService.checkLastClassificationChannelLog(true /*hasPosted*/, false /*isAlerting*/, 1 /*TYPE_PROMOTION*/, 345)); assertTrue(mService.checkLastClassificationChannelLog(true /*=hasPosted*/, false /*=isAlerting*/, Adjustment.TYPE_PROMOTION, 345, NOTIFICATION_ADJUSTED.getId(), instanceId2.getId() /*instance_id*/, r2.getUid())); } @Test Loading
services/tests/uiservicestests/src/com/android/server/notification/TestableNotificationManagerService.java +27 −4 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.server.notification; import static android.app.NotificationManager.IMPORTANCE_DEFAULT; import android.companion.ICompanionDeviceManager; import android.content.ComponentName; import android.content.Context; Loading @@ -25,6 +27,7 @@ import androidx.annotation.Nullable; import com.android.internal.logging.InstanceIdSequence; import com.android.server.notification.ManagedServices.ManagedServiceInfo; import com.android.server.notification.NotificationRecordLogger.NotificationReportedEvent; import java.util.HashSet; import java.util.Set; Loading Loading @@ -57,6 +60,9 @@ public class TestableNotificationManagerService extends NotificationManagerServi public boolean isAlerting; public long classification; public long lifetime; public long eventId; public long instanceId; public long uid; } public ClassificationChannelLog lastClassificationChannelLog = null; Loading Loading @@ -221,20 +227,34 @@ public class TestableNotificationManagerService extends NotificationManagerServi } @Override protected void logClassificationChannelAdjustmentReceived(boolean hasPosted, boolean isAlerting, int classification, int lifetimeMs) { protected void logClassificationChannelAdjustmentReceived(NotificationRecord r, boolean hasPosted, int classification) { boolean isAlerting = r.getChannel().getImportance() >= IMPORTANCE_DEFAULT; int instanceId = r.getSbn().getInstanceId() == null ? 0 : r.getSbn().getInstanceId().getId(); int lifetimeMs = r.getLifespanMs(System.currentTimeMillis()); int uid = r.getUid(); lastClassificationChannelLog = new ClassificationChannelLog(); lastClassificationChannelLog.hasPosted = hasPosted; lastClassificationChannelLog.isAlerting = isAlerting; lastClassificationChannelLog.classification = classification; lastClassificationChannelLog.lifetime = lifetimeMs; lastClassificationChannelLog.eventId = NotificationReportedEvent.NOTIFICATION_ADJUSTED.getId(); lastClassificationChannelLog.instanceId = instanceId; lastClassificationChannelLog.uid = uid; } /** * Returns true if the last recorded classification channel log has all the values specified. */ public boolean checkLastClassificationChannelLog(boolean hasPosted, boolean isAlerting, int classification, int lifetime) { int classification, int lifetime, int eventId, int instanceId, int uid) { if (lastClassificationChannelLog == null) { return false; } Loading @@ -242,6 +262,9 @@ public class TestableNotificationManagerService extends NotificationManagerServi return hasPosted == lastClassificationChannelLog.hasPosted && isAlerting == lastClassificationChannelLog.isAlerting && classification == lastClassificationChannelLog.classification && lifetime == lastClassificationChannelLog.lifetime; && lifetime == lastClassificationChannelLog.lifetime && eventId == lastClassificationChannelLog.eventId && instanceId == lastClassificationChannelLog.instanceId && uid == lastClassificationChannelLog.uid; } }