Loading services/core/java/com/android/server/notification/NotificationChannelLogger.java +26 −2 Original line number Original line Diff line number Diff line Loading @@ -98,6 +98,16 @@ public interface NotificationChannelLogger { channelGroup, uid, pkg, false); channelGroup, uid, pkg, false); } } /** * Log blocking or unblocking of the entire app's notifications. * @param uid UID of the app. * @param pkg Package name of the app. * @param enabled If true, notifications are now allowed. */ default void logAppNotificationsAllowed(int uid, String pkg, boolean enabled) { logAppEvent(NotificationChannelEvent.getBlocked(enabled), uid, pkg); } /** /** * Low-level interface for logging events, to be implemented. * Low-level interface for logging events, to be implemented. * @param event Event to log. * @param event Event to log. Loading @@ -123,6 +133,13 @@ public interface NotificationChannelLogger { @NonNull NotificationChannelGroup channelGroup, int uid, String pkg, @NonNull NotificationChannelGroup channelGroup, int uid, String pkg, boolean wasBlocked); boolean wasBlocked); /** * Low-level interface for logging app-as-a-whole events, to be implemented. * @param uid UID of app. * @param pkg Package of app. */ void logAppEvent(@NonNull NotificationChannelEvent event, int uid, String pkg); /** /** * The UiEvent enums that this class can log. * The UiEvent enums that this class can log. */ */ Loading @@ -144,8 +161,11 @@ public interface NotificationChannelLogger { @UiEvent(doc = "System created a new conversation (sub-channel in a notification channel)") @UiEvent(doc = "System created a new conversation (sub-channel in a notification channel)") NOTIFICATION_CHANNEL_CONVERSATION_CREATED(272), NOTIFICATION_CHANNEL_CONVERSATION_CREATED(272), @UiEvent(doc = "System deleted a new conversation (sub-channel in a notification channel)") @UiEvent(doc = "System deleted a new conversation (sub-channel in a notification channel)") NOTIFICATION_CHANNEL_CONVERSATION_DELETED(274); NOTIFICATION_CHANNEL_CONVERSATION_DELETED(274), @UiEvent(doc = "All notifications for the app were blocked.") APP_NOTIFICATIONS_BLOCKED(557), @UiEvent(doc = "Notifications for the app as a whole were unblocked.") APP_NOTIFICATIONS_UNBLOCKED(558); private final int mId; private final int mId; NotificationChannelEvent(int id) { NotificationChannelEvent(int id) { Loading Loading @@ -178,6 +198,10 @@ public interface NotificationChannelLogger { ? NotificationChannelEvent.NOTIFICATION_CHANNEL_GROUP_CREATED ? NotificationChannelEvent.NOTIFICATION_CHANNEL_GROUP_CREATED : NotificationChannelEvent.NOTIFICATION_CHANNEL_GROUP_DELETED; : NotificationChannelEvent.NOTIFICATION_CHANNEL_GROUP_DELETED; } } public static NotificationChannelEvent getBlocked(boolean enabled) { return enabled ? APP_NOTIFICATIONS_UNBLOCKED : APP_NOTIFICATIONS_BLOCKED; } } } /** /** Loading services/core/java/com/android/server/notification/NotificationChannelLoggerImpl.java +9 −0 Original line number Original line Diff line number Diff line Loading @@ -19,6 +19,8 @@ package com.android.server.notification; import android.app.NotificationChannel; import android.app.NotificationChannel; import android.app.NotificationChannelGroup; import android.app.NotificationChannelGroup; import com.android.internal.logging.UiEventLogger; import com.android.internal.logging.UiEventLoggerImpl; import com.android.internal.util.FrameworkStatsLog; import com.android.internal.util.FrameworkStatsLog; /** /** Loading @@ -27,6 +29,8 @@ import com.android.internal.util.FrameworkStatsLog; * should live in the interface so it can be tested. * should live in the interface so it can be tested. */ */ public class NotificationChannelLoggerImpl implements NotificationChannelLogger { public class NotificationChannelLoggerImpl implements NotificationChannelLogger { UiEventLogger mUiEventLogger = new UiEventLoggerImpl(); @Override @Override public void logNotificationChannel(NotificationChannelEvent event, public void logNotificationChannel(NotificationChannelEvent event, NotificationChannel channel, int uid, String pkg, NotificationChannel channel, int uid, String pkg, Loading @@ -51,4 +55,9 @@ public class NotificationChannelLoggerImpl implements NotificationChannelLogger /* int old_importance*/ NotificationChannelLogger.getImportance(wasBlocked), /* int old_importance*/ NotificationChannelLogger.getImportance(wasBlocked), /* int importance*/ NotificationChannelLogger.getImportance(channelGroup)); /* int importance*/ NotificationChannelLogger.getImportance(channelGroup)); } } @Override public void logAppEvent(NotificationChannelEvent event, int uid, String pkg) { mUiEventLogger.log(event, uid, pkg); } } } services/core/java/com/android/server/notification/PreferencesHelper.java +1 −0 Original line number Original line Diff line number Diff line Loading @@ -1654,6 +1654,7 @@ public class PreferencesHelper implements RankingConfig { } } setImportance(packageName, uid, setImportance(packageName, uid, enabled ? DEFAULT_IMPORTANCE : IMPORTANCE_NONE); enabled ? DEFAULT_IMPORTANCE : IMPORTANCE_NONE); mNotificationChannelLogger.logAppNotificationsAllowed(uid, packageName, enabled); } } /** /** Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationChannelLoggerFake.java +5 −0 Original line number Original line Diff line number Diff line Loading @@ -51,4 +51,9 @@ public class NotificationChannelLoggerFake implements NotificationChannelLogger NotificationChannelGroup channelGroup, int uid, String pkg, boolean wasBlocked) { NotificationChannelGroup channelGroup, int uid, String pkg, boolean wasBlocked) { mCalls.add(new CallRecord(event)); mCalls.add(new CallRecord(event)); } } @Override public void logAppEvent(NotificationChannelEvent event, int uid, String pkg) { mCalls.add(new CallRecord(event)); } } } services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +8 −0 Original line number Original line Diff line number Diff line Loading @@ -2265,6 +2265,14 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertEquals(3, mHelper.getBlockedAppCount(0)); assertEquals(3, mHelper.getBlockedAppCount(0)); } } @Test public void testAppBlockedLogging() { mHelper.setEnabled(PKG_N_MR1, 1020, false); assertEquals(1, mLogger.getCalls().size()); assertEquals( NotificationChannelLogger.NotificationChannelEvent.APP_NOTIFICATIONS_BLOCKED, mLogger.get(0).event); } @Test @Test public void testXml_statusBarIcons_default() throws Exception { public void testXml_statusBarIcons_default() throws Exception { String preQXml = "<ranking version=\"1\">\n" String preQXml = "<ranking version=\"1\">\n" Loading Loading
services/core/java/com/android/server/notification/NotificationChannelLogger.java +26 −2 Original line number Original line Diff line number Diff line Loading @@ -98,6 +98,16 @@ public interface NotificationChannelLogger { channelGroup, uid, pkg, false); channelGroup, uid, pkg, false); } } /** * Log blocking or unblocking of the entire app's notifications. * @param uid UID of the app. * @param pkg Package name of the app. * @param enabled If true, notifications are now allowed. */ default void logAppNotificationsAllowed(int uid, String pkg, boolean enabled) { logAppEvent(NotificationChannelEvent.getBlocked(enabled), uid, pkg); } /** /** * Low-level interface for logging events, to be implemented. * Low-level interface for logging events, to be implemented. * @param event Event to log. * @param event Event to log. Loading @@ -123,6 +133,13 @@ public interface NotificationChannelLogger { @NonNull NotificationChannelGroup channelGroup, int uid, String pkg, @NonNull NotificationChannelGroup channelGroup, int uid, String pkg, boolean wasBlocked); boolean wasBlocked); /** * Low-level interface for logging app-as-a-whole events, to be implemented. * @param uid UID of app. * @param pkg Package of app. */ void logAppEvent(@NonNull NotificationChannelEvent event, int uid, String pkg); /** /** * The UiEvent enums that this class can log. * The UiEvent enums that this class can log. */ */ Loading @@ -144,8 +161,11 @@ public interface NotificationChannelLogger { @UiEvent(doc = "System created a new conversation (sub-channel in a notification channel)") @UiEvent(doc = "System created a new conversation (sub-channel in a notification channel)") NOTIFICATION_CHANNEL_CONVERSATION_CREATED(272), NOTIFICATION_CHANNEL_CONVERSATION_CREATED(272), @UiEvent(doc = "System deleted a new conversation (sub-channel in a notification channel)") @UiEvent(doc = "System deleted a new conversation (sub-channel in a notification channel)") NOTIFICATION_CHANNEL_CONVERSATION_DELETED(274); NOTIFICATION_CHANNEL_CONVERSATION_DELETED(274), @UiEvent(doc = "All notifications for the app were blocked.") APP_NOTIFICATIONS_BLOCKED(557), @UiEvent(doc = "Notifications for the app as a whole were unblocked.") APP_NOTIFICATIONS_UNBLOCKED(558); private final int mId; private final int mId; NotificationChannelEvent(int id) { NotificationChannelEvent(int id) { Loading Loading @@ -178,6 +198,10 @@ public interface NotificationChannelLogger { ? NotificationChannelEvent.NOTIFICATION_CHANNEL_GROUP_CREATED ? NotificationChannelEvent.NOTIFICATION_CHANNEL_GROUP_CREATED : NotificationChannelEvent.NOTIFICATION_CHANNEL_GROUP_DELETED; : NotificationChannelEvent.NOTIFICATION_CHANNEL_GROUP_DELETED; } } public static NotificationChannelEvent getBlocked(boolean enabled) { return enabled ? APP_NOTIFICATIONS_UNBLOCKED : APP_NOTIFICATIONS_BLOCKED; } } } /** /** Loading
services/core/java/com/android/server/notification/NotificationChannelLoggerImpl.java +9 −0 Original line number Original line Diff line number Diff line Loading @@ -19,6 +19,8 @@ package com.android.server.notification; import android.app.NotificationChannel; import android.app.NotificationChannel; import android.app.NotificationChannelGroup; import android.app.NotificationChannelGroup; import com.android.internal.logging.UiEventLogger; import com.android.internal.logging.UiEventLoggerImpl; import com.android.internal.util.FrameworkStatsLog; import com.android.internal.util.FrameworkStatsLog; /** /** Loading @@ -27,6 +29,8 @@ import com.android.internal.util.FrameworkStatsLog; * should live in the interface so it can be tested. * should live in the interface so it can be tested. */ */ public class NotificationChannelLoggerImpl implements NotificationChannelLogger { public class NotificationChannelLoggerImpl implements NotificationChannelLogger { UiEventLogger mUiEventLogger = new UiEventLoggerImpl(); @Override @Override public void logNotificationChannel(NotificationChannelEvent event, public void logNotificationChannel(NotificationChannelEvent event, NotificationChannel channel, int uid, String pkg, NotificationChannel channel, int uid, String pkg, Loading @@ -51,4 +55,9 @@ public class NotificationChannelLoggerImpl implements NotificationChannelLogger /* int old_importance*/ NotificationChannelLogger.getImportance(wasBlocked), /* int old_importance*/ NotificationChannelLogger.getImportance(wasBlocked), /* int importance*/ NotificationChannelLogger.getImportance(channelGroup)); /* int importance*/ NotificationChannelLogger.getImportance(channelGroup)); } } @Override public void logAppEvent(NotificationChannelEvent event, int uid, String pkg) { mUiEventLogger.log(event, uid, pkg); } } }
services/core/java/com/android/server/notification/PreferencesHelper.java +1 −0 Original line number Original line Diff line number Diff line Loading @@ -1654,6 +1654,7 @@ public class PreferencesHelper implements RankingConfig { } } setImportance(packageName, uid, setImportance(packageName, uid, enabled ? DEFAULT_IMPORTANCE : IMPORTANCE_NONE); enabled ? DEFAULT_IMPORTANCE : IMPORTANCE_NONE); mNotificationChannelLogger.logAppNotificationsAllowed(uid, packageName, enabled); } } /** /** Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationChannelLoggerFake.java +5 −0 Original line number Original line Diff line number Diff line Loading @@ -51,4 +51,9 @@ public class NotificationChannelLoggerFake implements NotificationChannelLogger NotificationChannelGroup channelGroup, int uid, String pkg, boolean wasBlocked) { NotificationChannelGroup channelGroup, int uid, String pkg, boolean wasBlocked) { mCalls.add(new CallRecord(event)); mCalls.add(new CallRecord(event)); } } @Override public void logAppEvent(NotificationChannelEvent event, int uid, String pkg) { mCalls.add(new CallRecord(event)); } } }
services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +8 −0 Original line number Original line Diff line number Diff line Loading @@ -2265,6 +2265,14 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertEquals(3, mHelper.getBlockedAppCount(0)); assertEquals(3, mHelper.getBlockedAppCount(0)); } } @Test public void testAppBlockedLogging() { mHelper.setEnabled(PKG_N_MR1, 1020, false); assertEquals(1, mLogger.getCalls().size()); assertEquals( NotificationChannelLogger.NotificationChannelEvent.APP_NOTIFICATIONS_BLOCKED, mLogger.get(0).event); } @Test @Test public void testXml_statusBarIcons_default() throws Exception { public void testXml_statusBarIcons_default() throws Exception { String preQXml = "<ranking version=\"1\">\n" String preQXml = "<ranking version=\"1\">\n" Loading