FileDocCategorySizeDatePackage
NotificationRecord.javaAPI DocAndroid 5.1 API11409Thu Mar 12 22:22:42 GMT 2015com.android.server.notification

NotificationRecord

public final class NotificationRecord extends Object
Holds data about notifications that should not be shared with the {@link android.service.notification.NotificationListenerService}s.

These objects should not be mutated unless the code is synchronized on {@link NotificationManagerService#mNotificationList}, and any modification should be followed by a sorting of that list.

Is sortable by {@link NotificationComparator}.

{@hide}

Fields Summary
final android.service.notification.StatusBarNotification
sbn
final int
mOriginalFlags
NotificationUsageStats.SingleNotificationStats
stats
boolean
isCanceled
int
score
private float
mContactAffinity
private boolean
mRecentlyIntrusive
private boolean
mIntercept
private long
mRankingTimeMs
public boolean
isUpdate
private int
mPackagePriority
private int
mAuthoritativeRank
private String
mGlobalSortKey
private int
mPackageVisibility
Constructors Summary
public NotificationRecord(android.service.notification.StatusBarNotification sbn, int score)

        this.sbn = sbn;
        this.score = score;
        mOriginalFlags = sbn.getNotification().flags;
        mRankingTimeMs = calculateRankingTimeMs(0L);
    
Methods Summary
private longcalculateRankingTimeMs(long previousRankingTimeMs)

param
previousRankingTimeMs for updated notifications, {@link #getRankingTimeMs()} of the previous notification record, 0 otherwise

        Notification n = getNotification();
        // Take developer provided 'when', unless it's in the future.
        if (n.when != 0 && n.when <= sbn.getPostTime()) {
            return n.when;
        }
        // If we've ranked a previous instance with a timestamp, inherit it. This case is
        // important in order to have ranking stability for updating notifications.
        if (previousRankingTimeMs > 0) {
            return previousRankingTimeMs;
        }
        return sbn.getPostTime();
    
public voidcopyRankingInformation(com.android.server.notification.NotificationRecord previous)

        mContactAffinity = previous.mContactAffinity;
        mRecentlyIntrusive = previous.mRecentlyIntrusive;
        mPackagePriority = previous.mPackagePriority;
        mPackageVisibility = previous.mPackageVisibility;
        mIntercept = previous.mIntercept;
        mRankingTimeMs = calculateRankingTimeMs(previous.getRankingTimeMs());
        // Don't copy mGlobalSortKey, recompute it.
    
voiddump(java.io.PrintWriter pw, java.lang.String prefix, android.content.Context baseContext)

        final Notification notification = sbn.getNotification();
        pw.println(prefix + this);
        pw.println(prefix + "  uid=" + sbn.getUid() + " userId=" + sbn.getUserId());
        pw.println(prefix + "  icon=0x" + Integer.toHexString(notification.icon)
                + " / " + idDebugString(baseContext, sbn.getPackageName(), notification.icon));
        pw.println(prefix + "  pri=" + notification.priority + " score=" + sbn.getScore());
        pw.println(prefix + "  key=" + sbn.getKey());
        pw.println(prefix + "  groupKey=" + getGroupKey());
        pw.println(prefix + "  contentIntent=" + notification.contentIntent);
        pw.println(prefix + "  deleteIntent=" + notification.deleteIntent);
        pw.println(prefix + "  tickerText=" + notification.tickerText);
        pw.println(prefix + "  contentView=" + notification.contentView);
        pw.println(prefix + String.format("  defaults=0x%08x flags=0x%08x",
                notification.defaults, notification.flags));
        pw.println(prefix + "  sound=" + notification.sound);
        pw.println(prefix + "  audioStreamType=" + notification.audioStreamType);
        pw.println(prefix + "  audioAttributes=" + notification.audioAttributes);
        pw.println(prefix + String.format("  color=0x%08x", notification.color));
        pw.println(prefix + "  vibrate=" + Arrays.toString(notification.vibrate));
        pw.println(prefix + String.format("  led=0x%08x onMs=%d offMs=%d",
                notification.ledARGB, notification.ledOnMS, notification.ledOffMS));
        if (notification.actions != null && notification.actions.length > 0) {
            pw.println(prefix + "  actions={");
            final int N = notification.actions.length;
            for (int i=0; i<N; i++) {
                final Notification.Action action = notification.actions[i];
                pw.println(String.format("%s    [%d] \"%s\" -> %s",
                        prefix,
                        i,
                        action.title,
                        action.actionIntent.toString()
                        ));
            }
            pw.println(prefix + "  }");
        }
        if (notification.extras != null && notification.extras.size() > 0) {
            pw.println(prefix + "  extras={");
            for (String key : notification.extras.keySet()) {
                pw.print(prefix + "    " + key + "=");
                Object val = notification.extras.get(key);
                if (val == null) {
                    pw.println("null");
                } else {
                    pw.print(val.getClass().getSimpleName());
                    if (val instanceof CharSequence || val instanceof String) {
                        // redact contents from bugreports
                    } else if (val instanceof Bitmap) {
                        pw.print(String.format(" (%dx%d)",
                                ((Bitmap) val).getWidth(),
                                ((Bitmap) val).getHeight()));
                    } else if (val.getClass().isArray()) {
                        final int N = Array.getLength(val);
                        pw.println(" (" + N + ")");
                    } else {
                        pw.print(" (" + String.valueOf(val) + ")");
                    }
                    pw.println();
                }
            }
            pw.println(prefix + "  }");
        }
        pw.println(prefix + "  stats=" + stats.toString());
        pw.println(prefix + "  mContactAffinity=" + mContactAffinity);
        pw.println(prefix + "  mRecentlyIntrusive=" + mRecentlyIntrusive);
        pw.println(prefix + "  mPackagePriority=" + mPackagePriority);
        pw.println(prefix + "  mPackageVisibility=" + mPackageVisibility);
        pw.println(prefix + "  mIntercept=" + mIntercept);
        pw.println(prefix + "  mGlobalSortKey=" + mGlobalSortKey);
        pw.println(prefix + "  mRankingTimeMs=" + mRankingTimeMs);
    
public intgetAuthoritativeRank()

        return mAuthoritativeRank;
    
public floatgetContactAffinity()

        return mContactAffinity;
    
public intgetFlags()

 return sbn.getNotification().flags; 
public java.lang.StringgetGlobalSortKey()

        return mGlobalSortKey;
    
public java.lang.StringgetGroupKey()

        return sbn.getGroupKey();
    
public java.lang.StringgetKey()

 return sbn.getKey(); 
public android.app.NotificationgetNotification()

 return sbn.getNotification(); 
public intgetPackagePriority()

        return mPackagePriority;
    
public intgetPackageVisibilityOverride()

        return mPackageVisibility;
    
public longgetRankingTimeMs()
Returns the timestamp to use for time-based sorting in the ranker.

        return mRankingTimeMs;
    
public android.os.UserHandlegetUser()

 return sbn.getUser(); 
public intgetUserId()

deprecated
Use {@link #getUser()} instead.

 return sbn.getUserId(); 
static java.lang.StringidDebugString(android.content.Context baseContext, java.lang.String packageName, int id)

        Context c;

        if (packageName != null) {
            try {
                c = baseContext.createPackageContext(packageName, 0);
            } catch (NameNotFoundException e) {
                c = baseContext;
            }
        } else {
            c = baseContext;
        }

        Resources r = c.getResources();
        try {
            return r.getResourceName(id);
        } catch (Resources.NotFoundException e) {
            return "<name unknown>";
        }
    
public booleanisAudioAttributesUsage(int usage)

        final AudioAttributes attributes = getNotification().audioAttributes;
        return attributes != null && attributes.getUsage() == usage;
    
public booleanisAudioStream(int stream)

        return getNotification().audioStreamType == stream;
    
public booleanisCategory(java.lang.String category)

        return Objects.equals(getNotification().category, category);
    
public booleanisIntercepted()

        return mIntercept;
    
public booleanisRecentlyIntrusive()

        return mRecentlyIntrusive;
    
public voidsetAuthoritativeRank(int authoritativeRank)

        mAuthoritativeRank = authoritativeRank;
    
public voidsetContactAffinity(float contactAffinity)

        mContactAffinity = contactAffinity;
    
public voidsetGlobalSortKey(java.lang.String globalSortKey)

        mGlobalSortKey = globalSortKey;
    
public booleansetIntercepted(boolean intercept)

        mIntercept = intercept;
        return mIntercept;
    
public voidsetPackagePriority(int packagePriority)

        mPackagePriority = packagePriority;
    
public voidsetPackageVisibilityOverride(int packageVisibility)

        mPackageVisibility = packageVisibility;
    
public voidsetRecentlyIntusive(boolean recentlyIntrusive)

        mRecentlyIntrusive = recentlyIntrusive;
    
public final java.lang.StringtoString()

        return String.format(
                "NotificationRecord(0x%08x: pkg=%s user=%s id=%d tag=%s score=%d key=%s: %s)",
                System.identityHashCode(this),
                this.sbn.getPackageName(), this.sbn.getUser(), this.sbn.getId(),
                this.sbn.getTag(), this.sbn.getScore(), this.sbn.getKey(),
                this.sbn.getNotification());