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

Commit 93304b68 authored by Kweku Adams's avatar Kweku Adams
Browse files

incidentd: Adding Notification Listener and Disabling Effects Data to...

incidentd: Adding Notification Listener and Disabling Effects Data to NotificationManager proto output.

RankingHelper will be done in another CL...that's likely a large CL on
its own.

BUG: 65750824
Test: flash on device and check incident.proto output
Change-Id: I740166aed6ac6769ee3e013cf2bd403256eb77dc
parent e57a4f85
Loading
Loading
Loading
Loading
+30 −24
Original line number Diff line number Diff line
@@ -21,9 +21,9 @@ import android.annotation.Nullable;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.proto.ProtoOutputStream;

import java.io.PrintWriter;
import java.lang.Comparable;

/**
 * Identifier for a specific application component
@@ -283,6 +283,12 @@ public final class ComponentName implements Parcelable, Cloneable, Comparable<Co
        return "ComponentInfo{" + mPackage + "/" + mClass + "}";
    }

    /** Put this here so that individual services don't have to reimplement this. @hide */
    public void toProto(ProtoOutputStream proto) {
        proto.write(ComponentNameProto.PACKAGE_NAME, mPackage);
        proto.write(ComponentNameProto.CLASS_NAME, mClass);
    }

    @Override
    public boolean equals(Object obj) {
        try {
+4 −1
Original line number Diff line number Diff line
@@ -66,9 +66,12 @@ 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 [
        (section).type = SECTION_DUMPSYS,
        (section).args = "notification --proto"
    ];
    android.service.battery.BatteryServiceDumpProto battery = 3006;
    android.service.diskstats.DiskStatsServiceDumpProto diskstats = 3007;
    android.service.notification.NotificationServiceDumpProto notification = 3004;
    android.service.pm.PackageServiceDumpProto package = 3008;
    android.service.power.PowerServiceDumpProto power = 3009;
    android.service.print.PrintServiceDumpProto print = 3010;
+46 −1
Original line number Diff line number Diff line
@@ -21,10 +21,22 @@ package android.service.notification;
option java_multiple_files = true;
option java_outer_classname = "NotificationServiceProto";

import "frameworks/base/core/proto/android/content/component_name.proto";

message NotificationServiceDumpProto {
    repeated NotificationRecordProto records = 1;

    ZenModeProto zen = 2;

    ManagedServicesProto notification_listeners = 3;

    int32 listener_hints = 4;

    repeated ListenersDisablingEffectsProto listeners_disabling_effects = 5;

    ManagedServicesProto notification_assistants = 6;

    ManagedServicesProto condition_providers = 7;
}

message NotificationRecordProto {
@@ -40,6 +52,39 @@ message NotificationRecordProto {
    int32 importance = 10;
}

message ListenersDisablingEffectsProto {
    int32 hint = 1;
    repeated ManagedServiceInfoProto listeners = 2;
}

message ManagedServiceInfoProto {
    android.content.ComponentNameProto component = 1;
    int32 user_id = 2;
    string service = 3;
    bool is_system = 4;
    bool is_guest = 5;
}

message ManagedServicesProto {
    string caption = 1;

    message ServiceProto {
        repeated string name = 1;
        int32 user_id = 2;
        bool is_primary = 3;
    }
    repeated ServiceProto approved = 2;

    // All of this type/caption enabled for current profiles.
    repeated android.content.ComponentNameProto enabled = 3;


    repeated ManagedServiceInfoProto live_services = 4;

    // Snoozed for current profiles.
    repeated android.content.ComponentNameProto snoozed = 5;
}

enum State {
    ENQUEUED = 0;

+61 −0
Original line number Diff line number Diff line
@@ -45,12 +45,16 @@ import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.service.notification.ManagedServiceInfoProto;
import android.service.notification.ManagedServicesProto;
import android.service.notification.ManagedServicesProto.ServiceProto;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Log;
import android.util.Slog;
import android.util.SparseArray;
import android.util.proto.ProtoOutputStream;

import com.android.internal.util.XmlUtils;
import com.android.server.notification.NotificationManagerService.DumpFilter;
@@ -212,6 +216,53 @@ abstract public class ManagedServices {
        }
    }

    public void dump(ProtoOutputStream proto, DumpFilter filter) {
        proto.write(ManagedServicesProto.CAPTION, getCaption());
        final int N = mApproved.size();
        for (int i = 0 ; i < N; i++) {
            final int userId = mApproved.keyAt(i);
            final ArrayMap<Boolean, ArraySet<String>> approvedByType = mApproved.valueAt(i);
            if (approvedByType != null) {
                final int M = approvedByType.size();
                for (int j = 0; j < M; j++) {
                    final boolean isPrimary = approvedByType.keyAt(j);
                    final ArraySet<String> approved = approvedByType.valueAt(j);
                    if (approvedByType != null && approvedByType.size() > 0) {
                        final long sToken = proto.start(ManagedServicesProto.APPROVED);
                        for (String s : approved) {
                            proto.write(ServiceProto.NAME, s);
                        }
                        proto.write(ServiceProto.USER_ID, userId);
                        proto.write(ServiceProto.IS_PRIMARY, isPrimary);
                        proto.end(sToken);
                    }
                }
            }
        }

        for (ComponentName cmpt : mEnabledServicesForCurrentProfiles) {
            if (filter != null && !filter.matches(cmpt)) continue;

            final long cToken = proto.start(ManagedServicesProto.ENABLED);
            cmpt.toProto(proto);
            proto.end(cToken);
        }

        for (ManagedServiceInfo info : mServices) {
            if (filter != null && !filter.matches(info.component)) continue;

            final long lToken = proto.start(ManagedServicesProto.LIVE_SERVICES);
            info.toProto(proto, this);
            proto.end(lToken);
        }

        for (ComponentName name : mSnoozingForCurrentProfiles) {
            final long cToken = proto.start(ManagedServicesProto.SNOOZED);
            name.toProto(proto);
            proto.end(cToken);
        }
    }

    protected void onSettingRestored(String element, String value, int backupSdkInt, int userId) {
        if (!mUseXml) {
            Slog.d(TAG, "Restored managed service setting: " + element);
@@ -1031,6 +1082,16 @@ abstract public class ManagedServices {
                    .append(']').toString();
        }

        public void toProto(ProtoOutputStream proto, ManagedServices host) {
            final long cToken = proto.start(ManagedServiceInfoProto.COMPONENT);
            component.toProto(proto);
            proto.end(cToken);
            proto.write(ManagedServiceInfoProto.USER_ID, userid);
            proto.write(ManagedServiceInfoProto.SERVICE, service.getClass().getName());
            proto.write(ManagedServiceInfoProto.IS_SYSTEM, isSystem);
            proto.write(ManagedServiceInfoProto.IS_GUEST, isGuest(host));
        }

        public boolean enabledAndUserMatches(int nid) {
            if (!isEnabledForCurrentProfiles()) {
                return false;
+40 −6
Original line number Diff line number Diff line
@@ -125,6 +125,7 @@ import android.service.notification.Condition;
import android.service.notification.IConditionProvider;
import android.service.notification.INotificationListener;
import android.service.notification.IStatusBarNotificationHolder;
import android.service.notification.ListenersDisablingEffectsProto;
import android.service.notification.NotificationAssistantService;
import android.service.notification.NotificationListenerService;
import android.service.notification.NotificationRankingUpdate;
@@ -3220,7 +3221,6 @@ public class NotificationManagerService extends SystemService {
                }
            }
            proto.end(records);
        }

            long zenLog = proto.start(NotificationServiceDumpProto.ZEN);
            mZenModeHelper.dump(proto);
@@ -3229,6 +3229,40 @@ public class NotificationManagerService extends SystemService {
            }
            proto.end(zenLog);

            long listenersToken = proto.start(NotificationServiceDumpProto.NOTIFICATION_LISTENERS);
            mListeners.dump(proto, filter);
            proto.end(listenersToken);

            proto.write(NotificationServiceDumpProto.LISTENER_HINTS, mListenerHints);

            for (int i = 0; i < mListenersDisablingEffects.size(); ++i) {
                long effectsToken = proto.start(
                    NotificationServiceDumpProto.LISTENERS_DISABLING_EFFECTS);

                proto.write(
                    ListenersDisablingEffectsProto.HINT, mListenersDisablingEffects.keyAt(i));
                final ArraySet<ManagedServiceInfo> listeners =
                    mListenersDisablingEffects.valueAt(i);
                for (int j = 0; j < listeners.size(); j++) {
                    final ManagedServiceInfo listener = listeners.valueAt(i);
                    listenersToken = proto.start(ListenersDisablingEffectsProto.LISTENERS);
                    listener.toProto(proto, null);
                    proto.end(listenersToken);
                }

                proto.end(effectsToken);
            }

            long assistantsToken = proto.start(
                NotificationServiceDumpProto.NOTIFICATION_ASSISTANTS);
            mAssistants.dump(proto, filter);
            proto.end(assistantsToken);

            long conditionsToken = proto.start(NotificationServiceDumpProto.CONDITION_PROVIDERS);
            mConditionProviders.dump(proto, filter);
            proto.end(conditionsToken);
        }

        proto.flush();
    }