Loading core/java/android/service/notification/Adjustment.java +14 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 = { Loading Loading @@ -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>() { Loading Loading @@ -251,6 +254,7 @@ public final class Adjustment implements Parcelable { } dest.writeBundle(mSignals); dest.writeInt(mUser); dest.writeString(mIssuer); } @Override Loading @@ -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; } } core/java/android/service/notification/NotificationAssistantService.java +11 −0 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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); Loading Loading @@ -366,6 +370,12 @@ public abstract class NotificationAssistantService extends NotificationListenerS } } private void setAdjustmentIssuer(@Nullable Adjustment adjustment) { if (adjustment != null) { 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; Loading @@ -389,6 +399,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."); Loading proto/src/metrics_constants/metrics_constants.proto +3 −0 Original line number Diff line number Diff line Loading @@ -7376,6 +7376,9 @@ message MetricsEvent { // OS: Q FIELD_BIOMETRIC_AUTH_ERROR = 1741; // Custom tag for NotificationItem. Hash of the NAS that made adjustments. FIELD_NOTIFICATION_ASSISTANT_SERVICE_HASH = 1742; // ---- End Q Constants, all Q constants go above this line ---- // Add new aosp constants above this line. // END OF AOSP CONSTANTS Loading services/core/java/com/android/server/notification/NotificationRecord.java +11 −0 Original line number Diff line number Diff line Loading @@ -174,6 +174,7 @@ public final class NotificationRecord { private ArrayList<CharSequence> mSmartReplies; private final List<Adjustment> mAdjustments; private String mAdjustmentIssuer; private final NotificationStats mStats; private int mUserSentiment; private boolean mIsInterruptive; Loading Loading @@ -684,6 +685,9 @@ public final class NotificationRecord { importance = Math.min(IMPORTANCE_HIGH, importance); setAssistantImportance(importance); } if (!signals.isEmpty() && adjustment.getIssuer() != null) { mAdjustmentIssuer = adjustment.getIssuer(); } } // We have now gotten all the information out of the adjustments and can forget them. mAdjustments.clear(); Loading Loading @@ -1297,6 +1301,13 @@ 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. if (mAdjustmentIssuer != null) { lm.addTaggedData(MetricsEvent.FIELD_NOTIFICATION_ASSISTANT_SERVICE_HASH, mAdjustmentIssuer.hashCode()); } return lm; } Loading Loading
core/java/android/service/notification/Adjustment.java +14 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 = { Loading Loading @@ -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>() { Loading Loading @@ -251,6 +254,7 @@ public final class Adjustment implements Parcelable { } dest.writeBundle(mSignals); dest.writeInt(mUser); dest.writeString(mIssuer); } @Override Loading @@ -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; } }
core/java/android/service/notification/NotificationAssistantService.java +11 −0 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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); Loading Loading @@ -366,6 +370,12 @@ public abstract class NotificationAssistantService extends NotificationListenerS } } private void setAdjustmentIssuer(@Nullable Adjustment adjustment) { if (adjustment != null) { 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; Loading @@ -389,6 +399,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."); Loading
proto/src/metrics_constants/metrics_constants.proto +3 −0 Original line number Diff line number Diff line Loading @@ -7376,6 +7376,9 @@ message MetricsEvent { // OS: Q FIELD_BIOMETRIC_AUTH_ERROR = 1741; // Custom tag for NotificationItem. Hash of the NAS that made adjustments. FIELD_NOTIFICATION_ASSISTANT_SERVICE_HASH = 1742; // ---- End Q Constants, all Q constants go above this line ---- // Add new aosp constants above this line. // END OF AOSP CONSTANTS Loading
services/core/java/com/android/server/notification/NotificationRecord.java +11 −0 Original line number Diff line number Diff line Loading @@ -174,6 +174,7 @@ public final class NotificationRecord { private ArrayList<CharSequence> mSmartReplies; private final List<Adjustment> mAdjustments; private String mAdjustmentIssuer; private final NotificationStats mStats; private int mUserSentiment; private boolean mIsInterruptive; Loading Loading @@ -684,6 +685,9 @@ public final class NotificationRecord { importance = Math.min(IMPORTANCE_HIGH, importance); setAssistantImportance(importance); } if (!signals.isEmpty() && adjustment.getIssuer() != null) { mAdjustmentIssuer = adjustment.getIssuer(); } } // We have now gotten all the information out of the adjustments and can forget them. mAdjustments.clear(); Loading Loading @@ -1297,6 +1301,13 @@ 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. if (mAdjustmentIssuer != null) { lm.addTaggedData(MetricsEvent.FIELD_NOTIFICATION_ASSISTANT_SERVICE_HASH, mAdjustmentIssuer.hashCode()); } return lm; } Loading