Merge "Statsd log for app notification bans." into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
4c3e345502
@@ -98,6 +98,16 @@ public interface NotificationChannelLogger {
|
||||
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.
|
||||
* @param event Event to log.
|
||||
@@ -123,6 +133,13 @@ public interface NotificationChannelLogger {
|
||||
@NonNull NotificationChannelGroup channelGroup, int uid, String pkg,
|
||||
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.
|
||||
*/
|
||||
@@ -144,8 +161,11 @@ public interface NotificationChannelLogger {
|
||||
@UiEvent(doc = "System created a new conversation (sub-channel in a notification channel)")
|
||||
NOTIFICATION_CHANNEL_CONVERSATION_CREATED(272),
|
||||
@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;
|
||||
NotificationChannelEvent(int id) {
|
||||
@@ -178,6 +198,10 @@ public interface NotificationChannelLogger {
|
||||
? NotificationChannelEvent.NOTIFICATION_CHANNEL_GROUP_CREATED
|
||||
: NotificationChannelEvent.NOTIFICATION_CHANNEL_GROUP_DELETED;
|
||||
}
|
||||
|
||||
public static NotificationChannelEvent getBlocked(boolean enabled) {
|
||||
return enabled ? APP_NOTIFICATIONS_UNBLOCKED : APP_NOTIFICATIONS_BLOCKED;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,6 +19,8 @@ package com.android.server.notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationChannelGroup;
|
||||
|
||||
import com.android.internal.logging.UiEventLogger;
|
||||
import com.android.internal.logging.UiEventLoggerImpl;
|
||||
import com.android.internal.util.FrameworkStatsLog;
|
||||
|
||||
/**
|
||||
@@ -27,6 +29,8 @@ import com.android.internal.util.FrameworkStatsLog;
|
||||
* should live in the interface so it can be tested.
|
||||
*/
|
||||
public class NotificationChannelLoggerImpl implements NotificationChannelLogger {
|
||||
UiEventLogger mUiEventLogger = new UiEventLoggerImpl();
|
||||
|
||||
@Override
|
||||
public void logNotificationChannel(NotificationChannelEvent event,
|
||||
NotificationChannel channel, int uid, String pkg,
|
||||
@@ -51,4 +55,9 @@ public class NotificationChannelLoggerImpl implements NotificationChannelLogger
|
||||
/* int old_importance*/ NotificationChannelLogger.getImportance(wasBlocked),
|
||||
/* int importance*/ NotificationChannelLogger.getImportance(channelGroup));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logAppEvent(NotificationChannelEvent event, int uid, String pkg) {
|
||||
mUiEventLogger.log(event, uid, pkg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1654,6 +1654,7 @@ public class PreferencesHelper implements RankingConfig {
|
||||
}
|
||||
setImportance(packageName, uid,
|
||||
enabled ? DEFAULT_IMPORTANCE : IMPORTANCE_NONE);
|
||||
mNotificationChannelLogger.logAppNotificationsAllowed(uid, packageName, enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -51,4 +51,9 @@ public class NotificationChannelLoggerFake implements NotificationChannelLogger
|
||||
NotificationChannelGroup channelGroup, int uid, String pkg, boolean wasBlocked) {
|
||||
mCalls.add(new CallRecord(event));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logAppEvent(NotificationChannelEvent event, int uid, String pkg) {
|
||||
mCalls.add(new CallRecord(event));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2265,6 +2265,14 @@ public class PreferencesHelperTest extends UiServiceTestCase {
|
||||
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
|
||||
public void testXml_statusBarIcons_default() throws Exception {
|
||||
String preQXml = "<ranking version=\"1\">\n"
|
||||
|
||||
Reference in New Issue
Block a user