From 93304b6850cd0ee7224ed7672eba1c8bad25f609 Mon Sep 17 00:00:00 2001 From: Kweku Adams Date: Wed, 20 Sep 2017 17:03:00 -0700 Subject: [PATCH] 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 --- core/java/android/content/ComponentName.java | 54 ++++++++-------- core/proto/android/os/incident.proto | 5 +- core/proto/android/service/notification.proto | 47 +++++++++++++- .../server/notification/ManagedServices.java | 61 +++++++++++++++++++ .../NotificationManagerService.java | 46 ++++++++++++-- 5 files changed, 181 insertions(+), 32 deletions(-) diff --git a/core/java/android/content/ComponentName.java b/core/java/android/content/ComponentName.java index ea6b7690b4319..0d36bddc8665a 100644 --- a/core/java/android/content/ComponentName.java +++ b/core/java/android/content/ComponentName.java @@ -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 @@ -33,7 +33,7 @@ import java.lang.Comparable; * pieces of information, encapsulated here, are required to identify * a component: the package (a String) it exists in, and the class (a String) * name inside of that package. - * + * */ public final class ComponentName implements Parcelable, Cloneable, Comparable { private final String mPackage; @@ -91,7 +91,7 @@ public final class ComponentName implements Parcelable, Cloneable, Comparablepkg that @@ -106,7 +106,7 @@ public final class ComponentName implements Parcelable, Cloneable, Comparablepkg that @@ -120,7 +120,7 @@ public final class ComponentName implements Parcelable, Cloneable, Comparablestr - * + * * @see #flattenToString() */ public static @Nullable ComponentName unflattenFromString(@NonNull String str) { @@ -269,7 +269,7 @@ public final class ComponentName implements Parcelable, Cloneable, Comparable CREATOR = new Parcelable.Creator() { public ComponentName createFromParcel(Parcel in) { @@ -371,7 +377,7 @@ public final class ComponentName implements Parcelable, Cloneable, Comparable> 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 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; diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index fd413469a984c..8fafe3279d89d 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -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,14 +3221,47 @@ public class NotificationManagerService extends SystemService { } } proto.end(records); - } - long zenLog = proto.start(NotificationServiceDumpProto.ZEN); - mZenModeHelper.dump(proto); - for (ComponentName suppressor : mEffectsSuppressors) { - proto.write(ZenModeProto.SUPPRESSORS, suppressor.toString()); + long zenLog = proto.start(NotificationServiceDumpProto.ZEN); + mZenModeHelper.dump(proto); + for (ComponentName suppressor : mEffectsSuppressors) { + proto.write(ZenModeProto.SUPPRESSORS, suppressor.toString()); + } + 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 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.end(zenLog); proto.flush(); }