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

Commit 5942cc59 authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge "Sort notifications by importance."

parents 30693713 0421e6d5
Loading
Loading
Loading
Loading
+4 −14
Original line number Diff line number Diff line
@@ -1002,13 +1002,12 @@ public abstract class NotificationListenerService extends Service {
            return mImportanceExplanation;
        }

        private void populate(String key, int rank, boolean isAmbient,
                boolean matchesInterruptionFilter, int visibilityOverride,
                int suppressedVisualEffects, int importance,
        private void populate(String key, int rank, boolean matchesInterruptionFilter,
                int visibilityOverride, int suppressedVisualEffects, int importance,
                CharSequence explanation) {
            mKey = key;
            mRank = rank;
            mIsAmbient = isAmbient;
            mIsAmbient = importance < IMPORTANCE_DEFAULT;
            mMatchesInterruptionFilter = matchesInterruptionFilter;
            mVisibilityOverride = visibilityOverride;
            mSuppressedVisualEffects = suppressedVisualEffects;
@@ -1079,7 +1078,7 @@ public abstract class NotificationListenerService extends Service {
         */
        public boolean getRanking(String key, Ranking outRanking) {
            int rank = getRank(key);
            outRanking.populate(key, rank, isAmbient(key), !isIntercepted(key),
            outRanking.populate(key, rank, !isIntercepted(key),
                    getVisibilityOverride(key), getSuppressedVisualEffects(key),
                    getImportance(key), getImportanceExplanation(key));
            return rank >= 0;
@@ -1095,15 +1094,6 @@ public abstract class NotificationListenerService extends Service {
            return rank != null ? rank : -1;
        }

        private boolean isAmbient(String key) {
            int firstAmbientIndex = mRankingUpdate.getFirstAmbientIndex();
            if (firstAmbientIndex < 0) {
                return false;
            }
            int rank = getRank(key);
            return rank >= 0 && rank >= firstAmbientIndex;
        }

        private boolean isIntercepted(String key) {
            synchronized (this) {
                if (mIntercepted == null) {
+1 −9
Original line number Diff line number Diff line
@@ -26,17 +26,15 @@ public class NotificationRankingUpdate implements Parcelable {
    // TODO: Support incremental updates.
    private final String[] mKeys;
    private final String[] mInterceptedKeys;
    private final int mFirstAmbientIndex;
    private final Bundle mVisibilityOverrides;
    private final Bundle mSuppressedVisualEffects;
    private final int[] mImportance;
    private final Bundle mImportanceExplanation;

    public NotificationRankingUpdate(String[] keys, String[] interceptedKeys,
            Bundle visibilityOverrides, int firstAmbientIndex, Bundle suppressedVisualEffects,
            Bundle visibilityOverrides, Bundle suppressedVisualEffects,
            int[] importance, Bundle explanation) {
        mKeys = keys;
        mFirstAmbientIndex = firstAmbientIndex;
        mInterceptedKeys = interceptedKeys;
        mVisibilityOverrides = visibilityOverrides;
        mSuppressedVisualEffects = suppressedVisualEffects;
@@ -46,7 +44,6 @@ public class NotificationRankingUpdate implements Parcelable {

    public NotificationRankingUpdate(Parcel in) {
        mKeys = in.readStringArray();
        mFirstAmbientIndex = in.readInt();
        mInterceptedKeys = in.readStringArray();
        mVisibilityOverrides = in.readBundle();
        mSuppressedVisualEffects = in.readBundle();
@@ -63,7 +60,6 @@ public class NotificationRankingUpdate implements Parcelable {
    @Override
    public void writeToParcel(Parcel out, int flags) {
        out.writeStringArray(mKeys);
        out.writeInt(mFirstAmbientIndex);
        out.writeStringArray(mInterceptedKeys);
        out.writeBundle(mVisibilityOverrides);
        out.writeBundle(mSuppressedVisualEffects);
@@ -86,10 +82,6 @@ public class NotificationRankingUpdate implements Parcelable {
        return mKeys;
    }

    public int getFirstAmbientIndex() {
        return mFirstAmbientIndex;
    }

    public String[] getInterceptedKeys() {
        return mInterceptedKeys;
    }
+8 −8
Original line number Diff line number Diff line
@@ -18,20 +18,13 @@ package com.android.server.notification;
import java.util.Comparator;

/**
 * Sorts notifications individually into attention-relelvant order.
 * Sorts notifications individually into attention-relevant order.
 */
public class NotificationComparator
        implements Comparator<NotificationRecord> {

    @Override
    public int compare(NotificationRecord left, NotificationRecord right) {
        final int leftPackagePriority = left.getPackagePriority();
        final int rightPackagePriority = right.getPackagePriority();
        if (leftPackagePriority != rightPackagePriority) {
            // by priority, high to low
            return -1 * Integer.compare(leftPackagePriority, rightPackagePriority);
        }

        final int leftImportance = left.getImportance();
        final int rightImportance = right.getImportance();
        if (leftImportance != rightImportance) {
@@ -39,6 +32,13 @@ public class NotificationComparator
            return -1 * Integer.compare(leftImportance, rightImportance);
        }

        final int leftPackagePriority = left.getPackagePriority();
        final int rightPackagePriority = right.getPackagePriority();
        if (leftPackagePriority != rightPackagePriority) {
            // by priority, high to low
            return -1 * Integer.compare(leftPackagePriority, rightPackagePriority);
        }

        final float leftPeople = left.getContactAffinity();
        final float rightPeople = right.getContactAffinity();
        if (leftPeople != rightPeople) {
+2 −5
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.notification;

import android.app.Notification;
import android.content.Context;
import android.service.notification.NotificationListenerService;
import android.util.Log;
import android.util.Slog;

@@ -44,11 +45,7 @@ public class NotificationIntrusivenessExtractor implements NotificationSignalExt
        }

        final Notification notification = record.getNotification();
        if ((notification.defaults & Notification.DEFAULT_VIBRATE) != 0 ||
                notification.vibrate != null ||
                (notification.defaults & Notification.DEFAULT_SOUND) != 0 ||
                notification.sound != null ||
                notification.fullScreenIntent != null) {
        if (record.getImportance() > NotificationListenerService.Ranking.IMPORTANCE_DEFAULT) {
            record.setRecentlyIntrusive(true);
        }

+1 −14
Original line number Diff line number Diff line
@@ -3294,7 +3294,6 @@ public class NotificationManagerService extends SystemService {
     * <p>Caller must hold a lock on mNotificationList.</p>
     */
    private NotificationRankingUpdate makeRankingUpdateLocked(ManagedServiceInfo info) {
        int speedBumpIndex = -1;
        final int N = mNotificationList.size();
        ArrayList<String> keys = new ArrayList<String>(N);
        ArrayList<String> interceptedKeys = new ArrayList<String>(N);
@@ -3322,18 +3321,6 @@ public class NotificationManagerService extends SystemService {
                    != NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE) {
                visibilityOverrides.putInt(key, record.getPackageVisibilityOverride());
            }
            // Find first min-prio notification for speedbump placement.
            if (speedBumpIndex == -1 &&
                    // Intrusiveness trumps priority, hence ignore intrusives.
                    !record.isRecentlyIntrusive() &&
                    // Currently, package priority is either PRIORITY_DEFAULT or PRIORITY_MAX, so
                    // scanning for PRIORITY_MIN within the package bucket PRIORITY_DEFAULT
                    // (or lower as a safeguard) is sufficient to find the speedbump index.
                    // We'll have to revisit this when more package priority buckets are introduced.
                    record.getPackagePriority() <= Notification.PRIORITY_DEFAULT &&
                    record.sbn.getNotification().priority == Notification.PRIORITY_MIN) {
                speedBumpIndex = keys.size() - 1;
            }
        }
        final int M = keys.size();
        String[] keysAr = keys.toArray(new String[M]);
@@ -3343,7 +3330,7 @@ public class NotificationManagerService extends SystemService {
            importanceAr[i] = importance.get(i);
        }
        return new NotificationRankingUpdate(keysAr, interceptedKeysAr, visibilityOverrides,
                speedBumpIndex, suppressedVisualEffects, importanceAr, explanation);
                suppressedVisualEffects, importanceAr, explanation);
    }

    private boolean isVisibleToListener(StatusBarNotification sbn, ManagedServiceInfo listener) {
Loading