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

Commit 7575e053 authored by Will Brockman's avatar Will Brockman
Browse files

Statsd log for app notification bans.

I accidentally omitted logging for the event of banning/unbanning
notifications for the entire app, when I added notification
channel ban logging in ag/10450892.

Change-Id: Ibf2be1367bf41ad2b431cfcd2fef820ff270fed9
Test: atest PreferencesHelperTest
Bug: 156398451
parent f21036b4
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
@@ -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"