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

Commit bdf33766 authored by Chris Wren's avatar Chris Wren
Browse files

use importance instead of score

Change-Id: Id3b0a074671943b4fcabb63fe990cbfd1e46bdfd
parent 5f986095
Loading
Loading
Loading
Loading
+53 −4
Original line number Diff line number Diff line
@@ -863,6 +863,8 @@ public abstract class NotificationListenerService extends Service {
        private boolean mMatchesInterruptionFilter;
        private int mVisibilityOverride;
        private int mSuppressedVisualEffects;
        private int mImportance;
        private CharSequence mImportanceExplanation;

        public Ranking() {}

@@ -928,7 +930,7 @@ public abstract class NotificationListenerService extends Service {
         * @return the rank of the notification
         */
        public int getImportance() {
            return IMPORTANCE_DEFAULT;  // TODO implement;
            return mImportance;
        }

        /**
@@ -939,18 +941,21 @@ public abstract class NotificationListenerService extends Service {
         * @return the explanation for the importance, or null if it is the natural importance
         */
        public CharSequence getImportanceExplanation() {
            return null;  // TODO implement
            return mImportanceExplanation;
        }

        private void populate(String key, int rank, boolean isAmbient,
                boolean matchesInterruptionFilter, int visibilityOverride,
                int suppressedVisualEffects) {
                int suppressedVisualEffects, int importance,
                CharSequence explanation) {
            mKey = key;
            mRank = rank;
            mIsAmbient = isAmbient;
            mMatchesInterruptionFilter = matchesInterruptionFilter;
            mVisibilityOverride = visibilityOverride;
            mSuppressedVisualEffects = suppressedVisualEffects;
            mImportance = importance;
            mImportanceExplanation = explanation;
        }

        /**
@@ -990,6 +995,8 @@ public abstract class NotificationListenerService extends Service {
        private ArraySet<Object> mIntercepted;
        private ArrayMap<String, Integer> mVisibilityOverrides;
        private ArrayMap<String, Integer> mSuppressedVisualEffects;
        private ArrayMap<String, Integer> mImportance;
        private ArrayMap<String, String> mImportanceExplanation;

        private RankingMap(NotificationRankingUpdate rankingUpdate) {
            mRankingUpdate = rankingUpdate;
@@ -1015,7 +1022,8 @@ 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),
                    getVisibilityOverride(key), getSuppressedVisualEffects(key));
                    getVisibilityOverride(key), getSuppressedVisualEffects(key),
                    getImportance(key), getImportanceExplanation(key));
            return rank >= 0;
        }

@@ -1073,6 +1081,28 @@ public abstract class NotificationListenerService extends Service {
            return suppressed.intValue();
        }

        private int getImportance(String key) {
            synchronized (this) {
                if (mImportance == null) {
                    buildImportanceLocked();
                }
            }
            Integer importance = mImportance.get(key);
            if (importance == null) {
                return Ranking.IMPORTANCE_DEFAULT;
            }
            return importance.intValue();
        }

        private String getImportanceExplanation(String key) {
            synchronized (this) {
                if (mImportanceExplanation == null) {
                    buildImportanceExplanationLocked();
                }
            }
            return mImportanceExplanation.get(key);
        }

        // Locked by 'this'
        private void buildRanksLocked() {
            String[] orderedKeys = mRankingUpdate.getOrderedKeys();
@@ -1107,6 +1137,25 @@ public abstract class NotificationListenerService extends Service {
                mSuppressedVisualEffects.put(key, suppressedBundle.getInt(key));
            }
        }
        // Locked by 'this'
        private void buildImportanceLocked() {
            String[] orderedKeys = mRankingUpdate.getOrderedKeys();
            int[] importance = mRankingUpdate.getImportance();
            mImportance = new ArrayMap<>(orderedKeys.length);
            for (int i = 0; i < orderedKeys.length; i++) {
                String key = orderedKeys[i];
                mImportance.put(key, importance[i]);
            }
        }

        // Locked by 'this'
        private void buildImportanceExplanationLocked() {
            Bundle explanationBundle = mRankingUpdate.getImportanceExplanation();
            mImportanceExplanation = new ArrayMap<>(explanationBundle.size());
            for (String key: explanationBundle.keySet()) {
                mImportanceExplanation.put(key, explanationBundle.getString(key));
            }
        }

        // ----------- Parcelable

+19 −1
Original line number Diff line number Diff line
@@ -29,14 +29,19 @@ public class NotificationRankingUpdate implements Parcelable {
    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, int firstAmbientIndex, Bundle suppressedVisualEffects,
            int[] importance, Bundle explanation) {
        mKeys = keys;
        mFirstAmbientIndex = firstAmbientIndex;
        mInterceptedKeys = interceptedKeys;
        mVisibilityOverrides = visibilityOverrides;
        mSuppressedVisualEffects = suppressedVisualEffects;
        mImportance = importance;
        mImportanceExplanation = explanation;
    }

    public NotificationRankingUpdate(Parcel in) {
@@ -45,6 +50,9 @@ public class NotificationRankingUpdate implements Parcelable {
        mInterceptedKeys = in.readStringArray();
        mVisibilityOverrides = in.readBundle();
        mSuppressedVisualEffects = in.readBundle();
        mImportance = new int[mKeys.length];
        in.readIntArray(mImportance);
        mImportanceExplanation = in.readBundle();
    }

    @Override
@@ -59,6 +67,8 @@ public class NotificationRankingUpdate implements Parcelable {
        out.writeStringArray(mInterceptedKeys);
        out.writeBundle(mVisibilityOverrides);
        out.writeBundle(mSuppressedVisualEffects);
        out.writeIntArray(mImportance);
        out.writeBundle(mImportanceExplanation);
    }

    public static final Parcelable.Creator<NotificationRankingUpdate> CREATOR
@@ -91,4 +101,12 @@ public class NotificationRankingUpdate implements Parcelable {
    public Bundle getSuppressedVisualEffects() {
        return mSuppressedVisualEffects;
    }

    public int[] getImportance() {
        return mImportance;
    }

    public Bundle getImportanceExplanation() {
        return mImportanceExplanation;
    }
}
+3 −12
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@ public class StatusBarNotification implements Parcelable {
    private final UserHandle user;
    private final long postTime;

    private final int score;
    private Context mContext; // used for inflation & icon expansion

    /** @hide */
@@ -64,7 +63,6 @@ public class StatusBarNotification implements Parcelable {
        this.tag = tag;
        this.uid = uid;
        this.initialPid = initialPid;
        this.score = score;
        this.notification = notification;
        this.user = user;
        this.postTime = postTime;
@@ -83,7 +81,6 @@ public class StatusBarNotification implements Parcelable {
        }
        this.uid = in.readInt();
        this.initialPid = in.readInt();
        this.score = in.readInt();
        this.notification = new Notification(in);
        this.user = UserHandle.readFromParcel(in);
        this.postTime = in.readLong();
@@ -120,7 +117,6 @@ public class StatusBarNotification implements Parcelable {
        }
        out.writeInt(this.uid);
        out.writeInt(this.initialPid);
        out.writeInt(this.score);
        this.notification.writeToParcel(out, flags);
        user.writeToParcel(out, flags);

@@ -153,14 +149,14 @@ public class StatusBarNotification implements Parcelable {
        this.notification.cloneInto(no, false); // light copy
        return new StatusBarNotification(this.pkg, this.opPkg,
                this.id, this.tag, this.uid, this.initialPid,
                this.score, no, this.user, this.postTime);
                0, no, this.user, this.postTime);
    }

    @Override
    public StatusBarNotification clone() {
        return new StatusBarNotification(this.pkg, this.opPkg,
                this.id, this.tag, this.uid, this.initialPid,
                this.score, this.notification.clone(), this.user, this.postTime);
                0, this.notification.clone(), this.user, this.postTime);
    }

    @Override
@@ -168,7 +164,7 @@ public class StatusBarNotification implements Parcelable {
        return String.format(
                "StatusBarNotification(pkg=%s user=%s id=%d tag=%s score=%d key=%s: %s)",
                this.pkg, this.user, this.id, this.tag,
                this.score, this.key, this.notification);
                0, this.key, this.notification);
    }

    /** Convenience method to check the notification's flags for
@@ -247,11 +243,6 @@ public class StatusBarNotification implements Parcelable {
        return postTime;
    }

    /** @hide */
    public int getScore() {
        return score;
    }

    /**
     * A unique instance key for this notification record.
     */
+3 −0
Original line number Diff line number Diff line
@@ -4102,4 +4102,7 @@
    </plurals>

    <string name="default_notification_topic_label">Miscellaneous</string>

    <string name="importance_from_topic">You set the importance of these notifications.</string>
    <string name="importance_from_person">This is important because of the people involved.</string>
</resources>
+2 −0
Original line number Diff line number Diff line
@@ -2378,4 +2378,6 @@
  <java-symbol type="dimen" name="notification_content_margin_end" />
  <java-symbol type="dimen" name="notification_content_picture_margin" />
  <java-symbol type="dimen" name="notification_content_margin_top" />
  <java-symbol type="string" name="importance_from_topic" />
  <java-symbol type="string" name="importance_from_person" />
</resources>
Loading