Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c1754c03 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Statsd log for app notification bans." into rvc-dev am: 4c3e3455 am: 94ba1f28

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11881552

Change-Id: Iae56f22a75b18782ea56432c91a9cf3dfb4b1f13
parents 8482342c 94ba1f28
Loading
Loading
Loading
Loading
+26 −2
Original line number Original line Diff line number Diff line
@@ -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.
@@ -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.
     */
     */
@@ -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) {
@@ -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;
        }
    }
    }


    /**
    /**
+9 −0
Original line number Original line Diff line number Diff line
@@ -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;


/**
/**
@@ -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,
@@ -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);
    }
}
}
+1 −0
Original line number Original line Diff line number Diff line
@@ -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);
    }
    }


    /**
    /**
+5 −0
Original line number Original line Diff line number Diff line
@@ -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));
    }
}
}
+8 −0
Original line number Original line Diff line number Diff line
@@ -2302,6 +2302,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"