diff options
| author | 2019-05-10 14:54:13 +0200 | |
|---|---|---|
| committer | 2019-05-21 08:57:02 +0200 | |
| commit | 3b33a04fb3b34cac4422b2520ddb0b8be7067b72 (patch) | |
| tree | 038cc593de6025ab370dc37529acb0ee98f322db | |
| parent | 1bebf6a1a0b730cbe9c6c705825f31c21e8ff389 (diff) | |
Adding issuer information to NAS Adjustments
Test: manually tested with AiAi NAS
Fixes: 132679875
Change-Id: I5d4bf41383143e9573ddad5c08205e1dca3ba6b3
4 files changed, 50 insertions, 0 deletions
diff --git a/core/java/android/service/notification/Adjustment.java b/core/java/android/service/notification/Adjustment.java index e81ce7f85ac1..aa11445079cd 100644 --- a/core/java/android/service/notification/Adjustment.java +++ b/core/java/android/service/notification/Adjustment.java @@ -16,6 +16,7 @@ package android.service.notification; import android.annotation.NonNull; +import android.annotation.Nullable; import android.annotation.StringDef; import android.annotation.SystemApi; import android.annotation.TestApi; @@ -48,6 +49,7 @@ public final class Adjustment implements Parcelable { private final CharSequence mExplanation; private final Bundle mSignals; private final int mUser; + @Nullable private String mIssuer; /** @hide */ @StringDef (prefix = { "KEY_" }, value = { @@ -183,6 +185,7 @@ public final class Adjustment implements Parcelable { } mSignals = in.readBundle(); mUser = in.readInt(); + mIssuer = in.readString(); } public static final @android.annotation.NonNull Creator<Adjustment> CREATOR = new Creator<Adjustment>() { @@ -251,6 +254,7 @@ public final class Adjustment implements Parcelable { } dest.writeBundle(mSignals); dest.writeInt(mUser); + dest.writeString(mIssuer); } @Override @@ -259,4 +263,14 @@ public final class Adjustment implements Parcelable { + "mSignals=" + mSignals + '}'; } + + /** @hide */ + public void setIssuer(@Nullable String issuer) { + mIssuer = issuer; + } + + /** @hide */ + public @Nullable String getIssuer() { + return mIssuer; + } } diff --git a/core/java/android/service/notification/NotificationAssistantService.java b/core/java/android/service/notification/NotificationAssistantService.java index cafeb87691bd..3699156d1550 100644 --- a/core/java/android/service/notification/NotificationAssistantService.java +++ b/core/java/android/service/notification/NotificationAssistantService.java @@ -236,6 +236,7 @@ public abstract class NotificationAssistantService extends NotificationListenerS public final void adjustNotification(@NonNull Adjustment adjustment) { if (!isBound()) return; try { + setAdjustmentIssuer(adjustment); getNotificationInterface().applyEnqueuedAdjustmentFromAssistant(mWrapper, adjustment); } catch (android.os.RemoteException ex) { Log.v(TAG, "Unable to contact notification manager", ex); @@ -253,6 +254,9 @@ public abstract class NotificationAssistantService extends NotificationListenerS public final void adjustNotifications(@NonNull List<Adjustment> adjustments) { if (!isBound()) return; try { + for (Adjustment adjustment : adjustments) { + setAdjustmentIssuer(adjustment); + } getNotificationInterface().applyAdjustmentsFromAssistant(mWrapper, adjustments); } catch (android.os.RemoteException ex) { Log.v(TAG, "Unable to contact notification manager", ex); @@ -366,6 +370,10 @@ public abstract class NotificationAssistantService extends NotificationListenerS } } + private void setAdjustmentIssuer(Adjustment adjustment) { + adjustment.setIssuer(getOpPackageName() + "/" + getClass().getName()); + } + private final class MyHandler extends Handler { public static final int MSG_ON_NOTIFICATION_ENQUEUED = 1; public static final int MSG_ON_NOTIFICATION_SNOOZED = 2; @@ -389,6 +397,7 @@ public abstract class NotificationAssistantService extends NotificationListenerS NotificationChannel channel = (NotificationChannel) args.arg2; args.recycle(); Adjustment adjustment = onNotificationEnqueued(sbn, channel); + setAdjustmentIssuer(adjustment); if (adjustment != null) { if (!isBound()) { Log.w(TAG, "MSG_ON_NOTIFICATION_ENQUEUED: service not bound, skip."); diff --git a/proto/src/metrics_constants/metrics_constants.proto b/proto/src/metrics_constants/metrics_constants.proto index c59b16cf3e4c..4131e799c5da 100644 --- a/proto/src/metrics_constants/metrics_constants.proto +++ b/proto/src/metrics_constants/metrics_constants.proto @@ -7365,6 +7365,9 @@ message MetricsEvent { // OS: Q FIELD_EMERGENCY_DIALER_DISCONNECT_CAUSE = 1739; + // Custom tag for NotificationItem. Hash of the NAS that made adjustments. + FIELD_NOTIFICATION_ASSISTANT_SERVICE_HASH = 1740; + // ---- Skipping ahead to avoid conflicts between master and release branches. // ---- End Q Constants, all Q constants go above this line ---- diff --git a/services/core/java/com/android/server/notification/NotificationRecord.java b/services/core/java/com/android/server/notification/NotificationRecord.java index 4ed24ec7971b..4e9b4f75237b 100644 --- a/services/core/java/com/android/server/notification/NotificationRecord.java +++ b/services/core/java/com/android/server/notification/NotificationRecord.java @@ -1268,6 +1268,22 @@ public final class NotificationRecord { } } + // Returns the name of the NAS that made adjustments. By policy, there must only ever be one. + // If this is violated, the NAS that first sent an adjustment is returned. + private @Nullable String getAdjustmentIssuer() { + synchronized (mAdjustments) { + for (Adjustment adjustment : mAdjustments) { + if (adjustment.getSignals().isEmpty()) { + continue; + } + if (adjustment.getIssuer() != null) { + return adjustment.getIssuer(); + } + } + } + return null; + } + public LogMaker getLogMaker(long now) { LogMaker lm = sbn.getLogMaker() .addTaggedData(MetricsEvent.FIELD_NOTIFICATION_CHANNEL_IMPORTANCE, mImportance) @@ -1297,6 +1313,14 @@ public final class NotificationRecord { lm.addTaggedData(MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_ASST, mAssistantImportance); } + // Log the issuer of any adjustments that may have affected this notification. We only log + // the hash here as NotificationItem events are frequent, and the number of NAS + // implementations (and hence the chance of collisions) is low. + String adjustmentIssuer = getAdjustmentIssuer(); + if (adjustmentIssuer != null) { + lm.addTaggedData(MetricsEvent.FIELD_NOTIFICATION_ASSISTANT_SERVICE_HASH, + adjustmentIssuer.hashCode()); + } return lm; } |