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

Commit c9842c16 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Dump notification records to proto

Bug: 34227881
Test: cts
Change-Id: I1b55d37ee73a17330f4039a50bdf05e9ce1be24d
parent 2187d34e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import "frameworks/base/libs/incident/proto/android/privacy.proto";
import "frameworks/base/core/proto/android/service/appwidget.proto";
import "frameworks/base/core/proto/android/service/fingerprint.proto";
import "frameworks/base/core/proto/android/service/netstats.proto";
import "frameworks/base/core/proto/android/service/notification.proto";
import "frameworks/base/core/proto/android/providers/settings.proto";

package android.os;
@@ -55,4 +56,5 @@ message IncidentProto {
    android.service.NetworkStatsServiceDumpProto netstats = 3001;
    android.providers.settings.SettingsServiceDumpProto settings = 3002;
    android.service.appwidget.AppWidgetServiceDumpProto appwidget = 3003;
    android.service.notification.NotificationServiceDumpProto notification = 3004;
}
+45 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

syntax = "proto3";

package android.service.notification;

option java_multiple_files = true;
option java_outer_classname = "NotificationServiceProto";

message NotificationServiceDumpProto {
    repeated NotificationRecordProto records = 1;
}

message NotificationRecordProto {
    string key = 1;
    State state = 2;
    int32 flags = 3;
    string channelId = 4;
    string sound = 5;
    int32 sound_usage = 6;
    bool can_vibrate = 7;
    bool can_show_light = 8;
    string group_key = 9;
    int32 importance = 10;
}

enum State {
    ENQUEUED = 0;

    POSTED = 1;
}
 No newline at end of file
+37 −0
Original line number Diff line number Diff line
@@ -115,6 +115,9 @@ import android.service.notification.IStatusBarNotificationHolder;
import android.service.notification.NotificationAssistantService;
import android.service.notification.NotificationListenerService;
import android.service.notification.NotificationRankingUpdate;
import android.service.notification.NotificationRecordProto;
import android.service.notification.NotificationServiceDumpProto;
import android.service.notification.NotificationServiceProto;
import android.service.notification.SnoozeCriterion;
import android.service.notification.StatusBarNotification;
import android.service.notification.ZenModeConfig;
@@ -128,6 +131,7 @@ import android.util.Log;
import android.util.Slog;
import android.util.SparseArray;
import android.util.Xml;
import android.util.proto.ProtoOutputStream;
import android.view.WindowManagerInternal;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
@@ -2400,6 +2404,8 @@ public class NotificationManagerService extends SystemService {
            final DumpFilter filter = DumpFilter.parseFromArguments(args);
            if (filter != null && filter.stats) {
                dumpJson(pw, filter);
            } else if (filter != null && filter.proto) {
                dumpProto(fd, filter);
            } else {
                dumpImpl(pw, filter);
            }
@@ -2764,6 +2770,33 @@ public class NotificationManagerService extends SystemService {
        pw.println(dump);
    }

    private void dumpProto(FileDescriptor fd, DumpFilter filter) {
        final ProtoOutputStream proto = new ProtoOutputStream(fd);
        synchronized (mNotificationLock) {
            long records = proto.start(NotificationServiceDumpProto.RECORDS);
            int N = mNotificationList.size();
            if (N > 0) {
                for (int i = 0; i < N; i++) {
                    final NotificationRecord nr = mNotificationList.get(i);
                    if (filter.filtered && !filter.matches(nr.sbn)) continue;
                    nr.dump(proto, filter.redact);
                    proto.write(NotificationRecordProto.STATE, NotificationServiceProto.POSTED);
                }
            }
            N = mEnqueuedNotifications.size();
            if (N > 0) {
                for (int i = 0; i < N; i++) {
                    final NotificationRecord nr = mEnqueuedNotifications.get(i);
                    if (filter.filtered && !filter.matches(nr.sbn)) continue;
                    nr.dump(proto, filter.redact);
                    proto.write(NotificationRecordProto.STATE, NotificationServiceProto.ENQUEUED);
                }
            }
            proto.end(records);
        }
        proto.flush();
    }

    void dumpImpl(PrintWriter pw, DumpFilter filter) {
        pw.print("Current Notification Manager state");
        if (filter.filtered) {
@@ -4822,11 +4855,15 @@ public class NotificationManagerService extends SystemService {
        public long since;
        public boolean stats;
        public boolean redact = true;
        public boolean proto = false;

        public static DumpFilter parseFromArguments(String[] args) {
            final DumpFilter filter = new DumpFilter();
            for (int ai = 0; ai < args.length; ai++) {
                final String a = args[ai];
                if ("--proto".equals(args[0])) {
                    filter.proto = true;
                }
                if ("--noredact".equals(a) || "--reveal".equals(a)) {
                    filter.redact = false;
                } else if ("p".equals(a) || "pkg".equals(a) || "--package".equals(a)) {
+20 −0
Original line number Diff line number Diff line
@@ -37,12 +37,14 @@ import android.os.Build;
import android.os.UserHandle;
import android.provider.Settings;
import android.service.notification.NotificationListenerService;
import android.service.notification.NotificationRecordProto;
import android.service.notification.SnoozeCriterion;
import android.service.notification.StatusBarNotification;
import android.text.TextUtils;
import android.util.Log;
import android.util.Slog;
import android.util.TimeUtils;
import android.util.proto.ProtoOutputStream;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.MetricsLogger;
@@ -337,6 +339,24 @@ public final class NotificationRecord {
    /** @deprecated Use {@link #getUser()} instead. */
    public int getUserId() { return sbn.getUserId(); }

    void dump(ProtoOutputStream proto, boolean redact) {
        proto.write(NotificationRecordProto.KEY, sbn.getKey());
        if (getChannel() != null) {
            proto.write(NotificationRecordProto.CHANNEL_ID, getChannel().getId());
        }
        proto.write(NotificationRecordProto.CAN_SHOW_LIGHT, getLight() != null);
        proto.write(NotificationRecordProto.CAN_VIBRATE, getVibration() != null);
        proto.write(NotificationRecordProto.FLAGS, sbn.getNotification().flags);
        proto.write(NotificationRecordProto.GROUP_KEY, getGroupKey());
        proto.write(NotificationRecordProto.IMPORTANCE, getImportance());
        if (getSound() != null) {
            proto.write(NotificationRecordProto.SOUND, getSound().toString());
        }
        if (getAudioAttributes() != null) {
            proto.write(NotificationRecordProto.SOUND_USAGE, getAudioAttributes().getUsage());
        }
    }

    void dump(PrintWriter pw, String prefix, Context baseContext, boolean redact) {
        final Notification notification = sbn.getNotification();
        final Icon icon = notification.getSmallIcon();