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

Commit f612869a authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Allow DND mode to suppress visual interruptions.

Bug: 25423508
Change-Id: Idd8242e4bc00a749dbe0b5503c458375fc017072
parent 0283d44c
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -5146,10 +5146,12 @@ package android.app {
  }
  public static class NotificationManager.Policy implements android.os.Parcelable {
    ctor public NotificationManager.Policy(int, int, int);
    ctor public deprecated NotificationManager.Policy(int, int, int);
    ctor public NotificationManager.Policy(int, int, int, int);
    method public int describeContents();
    method public static java.lang.String priorityCategoriesToString(int);
    method public static java.lang.String prioritySendersToString(int);
    method public static java.lang.String suppressedEffectsToString(int);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.app.NotificationManager.Policy> CREATOR;
    field public static final int PRIORITY_CATEGORY_CALLS = 8; // 0x8
@@ -5160,9 +5162,13 @@ package android.app {
    field public static final int PRIORITY_SENDERS_ANY = 0; // 0x0
    field public static final int PRIORITY_SENDERS_CONTACTS = 1; // 0x1
    field public static final int PRIORITY_SENDERS_STARRED = 2; // 0x2
    field public static final int SUPPRESSED_EFFECTS_UNSET = -1; // 0xffffffff
    field public static final int SUPPRESSED_EFFECT_LIGHTS = 1; // 0x1
    field public static final int SUPPRESSED_EFFECT_PEEK = 2; // 0x2
    field public final int priorityCallSenders;
    field public final int priorityCategories;
    field public final int priorityMessageSenders;
    field public final int suppressedVisualEffects;
  }
  public final class PendingIntent implements android.os.Parcelable {
@@ -28974,12 +28980,15 @@ package android.service.notification {
    field public static final int INTERRUPTION_FILTER_PRIORITY = 2; // 0x2
    field public static final int INTERRUPTION_FILTER_UNKNOWN = 0; // 0x0
    field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationListenerService";
    field public static final int SUPPRESSED_EFFECT_LIGHTS = 1; // 0x1
    field public static final int SUPPRESSED_EFFECT_PEEK = 2; // 0x2
  }
  public static class NotificationListenerService.Ranking {
    ctor public NotificationListenerService.Ranking();
    method public java.lang.String getKey();
    method public int getRank();
    method public int getSuppressedVisualEffects();
    method public boolean isAmbient();
    method public boolean matchesInterruptionFilter();
  }
+10 −1
Original line number Diff line number Diff line
@@ -5264,10 +5264,12 @@ package android.app {
  }
  public static class NotificationManager.Policy implements android.os.Parcelable {
    ctor public NotificationManager.Policy(int, int, int);
    ctor public deprecated NotificationManager.Policy(int, int, int);
    ctor public NotificationManager.Policy(int, int, int, int);
    method public int describeContents();
    method public static java.lang.String priorityCategoriesToString(int);
    method public static java.lang.String prioritySendersToString(int);
    method public static java.lang.String suppressedEffectsToString(int);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.app.NotificationManager.Policy> CREATOR;
    field public static final int PRIORITY_CATEGORY_CALLS = 8; // 0x8
@@ -5278,9 +5280,13 @@ package android.app {
    field public static final int PRIORITY_SENDERS_ANY = 0; // 0x0
    field public static final int PRIORITY_SENDERS_CONTACTS = 1; // 0x1
    field public static final int PRIORITY_SENDERS_STARRED = 2; // 0x2
    field public static final int SUPPRESSED_EFFECTS_UNSET = -1; // 0xffffffff
    field public static final int SUPPRESSED_EFFECT_LIGHTS = 1; // 0x1
    field public static final int SUPPRESSED_EFFECT_PEEK = 2; // 0x2
    field public final int priorityCallSenders;
    field public final int priorityCategories;
    field public final int priorityMessageSenders;
    field public final int suppressedVisualEffects;
  }
  public final class PendingIntent implements android.os.Parcelable {
@@ -31090,6 +31096,8 @@ package android.service.notification {
    field public static final int INTERRUPTION_FILTER_PRIORITY = 2; // 0x2
    field public static final int INTERRUPTION_FILTER_UNKNOWN = 0; // 0x0
    field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationListenerService";
    field public static final int SUPPRESSED_EFFECT_LIGHTS = 1; // 0x1
    field public static final int SUPPRESSED_EFFECT_PEEK = 2; // 0x2
    field public static final int TRIM_FULL = 0; // 0x0
    field public static final int TRIM_LIGHT = 1; // 0x1
  }
@@ -31098,6 +31106,7 @@ package android.service.notification {
    ctor public NotificationListenerService.Ranking();
    method public java.lang.String getKey();
    method public int getRank();
    method public int getSuppressedVisualEffects();
    method public boolean isAmbient();
    method public boolean matchesInterruptionFilter();
  }
+59 −3
Original line number Diff line number Diff line
@@ -610,15 +610,39 @@ public class NotificationManager
         * PRIORITY_SENDERS_ANY, PRIORITY_SENDERS_CONTACTS, PRIORITY_SENDERS_STARRED */
        public final int priorityMessageSenders;

        public static final int SUPPRESSED_EFFECTS_UNSET = -1;
        public static final int SUPPRESSED_EFFECT_LIGHTS = 1 << 0;
        public static final int SUPPRESSED_EFFECT_PEEK = 1 << 1;

        private static final int[] ALL_SUPPRESSED_EFFECTS = {
                SUPPRESSED_EFFECT_LIGHTS,
                SUPPRESSED_EFFECT_PEEK,
        };

        /**
         * Visual effects to suppress for a notification that is filtered by Do Not Disturb mode.
         * Bitmask of SUPPRESSED_EFFECT_* constants.
         */
        public final int suppressedVisualEffects;


        @Deprecated
        public Policy(int priorityCategories, int priorityCallSenders, int priorityMessageSenders) {
            this(priorityCategories, priorityCallSenders, priorityMessageSenders,
                    SUPPRESSED_EFFECTS_UNSET);
        }

        public Policy(int priorityCategories, int priorityCallSenders, int priorityMessageSenders,
                int suppressedVisualEffects) {
            this.priorityCategories = priorityCategories;
            this.priorityCallSenders = priorityCallSenders;
            this.priorityMessageSenders = priorityMessageSenders;
            this.suppressedVisualEffects = suppressedVisualEffects;
        }

        /** @hide */
        public Policy(Parcel source) {
            this(source.readInt(), source.readInt(), source.readInt());
            this(source.readInt(), source.readInt(), source.readInt(), source.readInt());
        }

        @Override
@@ -626,6 +650,7 @@ public class NotificationManager
            dest.writeInt(priorityCategories);
            dest.writeInt(priorityCallSenders);
            dest.writeInt(priorityMessageSenders);
            dest.writeInt(suppressedVisualEffects);
        }

        @Override
@@ -635,7 +660,8 @@ public class NotificationManager

        @Override
        public int hashCode() {
            return Objects.hash(priorityCategories, priorityCallSenders, priorityMessageSenders);
            return Objects.hash(priorityCategories, priorityCallSenders, priorityMessageSenders,
                    suppressedVisualEffects);
        }

        @Override
@@ -645,7 +671,8 @@ public class NotificationManager
            final Policy other = (Policy) o;
            return other.priorityCategories == priorityCategories
                    && other.priorityCallSenders == priorityCallSenders
                    && other.priorityMessageSenders == priorityMessageSenders;
                    && other.priorityMessageSenders == priorityMessageSenders
                    && other.suppressedVisualEffects == suppressedVisualEffects;
        }

        @Override
@@ -654,9 +681,29 @@ public class NotificationManager
                    + "priorityCategories=" + priorityCategoriesToString(priorityCategories)
                    + ",priorityCallSenders=" + prioritySendersToString(priorityCallSenders)
                    + ",priorityMessageSenders=" + prioritySendersToString(priorityMessageSenders)
                    + ",suppressedVisualEffects="
                    + suppressedEffectsToString(suppressedVisualEffects)
                    + "]";
        }

        public static String suppressedEffectsToString(int effects) {
            if (effects <= 0) return "";
            final StringBuilder sb = new StringBuilder();
            for (int i = 0; i < ALL_SUPPRESSED_EFFECTS.length; i++) {
                final int effect = ALL_SUPPRESSED_EFFECTS[i];
                if ((effects & effect) != 0) {
                    if (sb.length() > 0) sb.append(',');
                    sb.append(effectToString(effect));
                }
                effects &= ~effect;
            }
            if (effects != 0) {
                if (sb.length() > 0) sb.append(',');
                sb.append("UNKNOWN_").append(effects);
            }
            return sb.toString();
        }

        public static String priorityCategoriesToString(int priorityCategories) {
            if (priorityCategories == 0) return "";
            final StringBuilder sb = new StringBuilder();
@@ -675,6 +722,15 @@ public class NotificationManager
            return sb.toString();
        }

        private static String effectToString(int effect) {
            switch (effect) {
                case SUPPRESSED_EFFECT_LIGHTS: return "SUPPRESSED_EFFECT_LIGHTS";
                case SUPPRESSED_EFFECT_PEEK: return "SUPPRESSED_EFFECT_PEEK";
                case SUPPRESSED_EFFECTS_UNSET: return "SUPPRESSED_EFFECTS_UNSET";
                default: return "UNKNOWN_" + effect;
            }
        }

        private static String priorityCategoryToString(int priorityCategory) {
            switch (priorityCategory) {
                case PRIORITY_CATEGORY_REMINDERS: return "PRIORITY_CATEGORY_REMINDERS";
+44 −5
Original line number Diff line number Diff line
@@ -108,6 +108,11 @@ public abstract class NotificationListenerService extends Service {
     * This does not change the interruption filter, only the effects. **/
    public static final int HINT_HOST_DISABLE_EFFECTS = 1;

    public static final int SUPPRESSED_EFFECT_LIGHTS =
            NotificationManager.Policy.SUPPRESSED_EFFECT_LIGHTS;
    public static final int SUPPRESSED_EFFECT_PEEK =
            NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK;

    /**
     * The full trim of the StatusBarNotification including all its features.
     *
@@ -822,6 +827,7 @@ public abstract class NotificationListenerService extends Service {
        private boolean mIsAmbient;
        private boolean mMatchesInterruptionFilter;
        private int mVisibilityOverride;
        private int mSuppressedVisualEffects;

        public Ranking() {}

@@ -861,6 +867,14 @@ public abstract class NotificationListenerService extends Service {
            return mVisibilityOverride;
        }

        /**
         * Returns the type(s) of visual effects that should be suppressed for this notification.
         * See {@link #SUPPRESSED_EFFECT_LIGHTS}, {@link #SUPPRESSED_EFFECT_PEEK}}.
         */
        public int getSuppressedVisualEffects() {
            return mSuppressedVisualEffects;
        }


        /**
         * Returns whether the notification matches the user's interruption
@@ -874,12 +888,14 @@ public abstract class NotificationListenerService extends Service {
        }

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

@@ -896,6 +912,7 @@ public abstract class NotificationListenerService extends Service {
        private ArrayMap<String,Integer> mRanks;
        private ArraySet<Object> mIntercepted;
        private ArrayMap<String, Integer> mVisibilityOverrides;
        private ArrayMap<String, Integer> mSuppressedVisualEffects;

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

@@ -959,11 +976,24 @@ public abstract class NotificationListenerService extends Service {
                    buildVisibilityOverridesLocked();
                }
            }
            Integer overide = mVisibilityOverrides.get(key);
            if (overide == null) {
            Integer override = mVisibilityOverrides.get(key);
            if (override == null) {
                return Ranking.VISIBILITY_NO_OVERRIDE;
            }
            return overide.intValue();
            return override.intValue();
        }

        private int getSuppressedVisualEffects(String key) {
            synchronized (this) {
                if (mSuppressedVisualEffects == null) {
                    buildSuppressedVisualEffectsLocked();
                }
            }
            Integer suppressed = mSuppressedVisualEffects.get(key);
            if (suppressed == null) {
                return 0;
            }
            return suppressed.intValue();
        }

        // Locked by 'this'
@@ -992,6 +1022,15 @@ public abstract class NotificationListenerService extends Service {
            }
        }

        // Locked by 'this'
        private void buildSuppressedVisualEffectsLocked() {
            Bundle suppressedBundle = mRankingUpdate.getSuppressedVisualEffects();
            mSuppressedVisualEffects = new ArrayMap<>(suppressedBundle.size());
            for (String key: suppressedBundle.keySet()) {
                mSuppressedVisualEffects.put(key, suppressedBundle.getInt(key));
            }
        }

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

        @Override
+9 −1
Original line number Diff line number Diff line
@@ -28,13 +28,15 @@ public class NotificationRankingUpdate implements Parcelable {
    private final String[] mInterceptedKeys;
    private final int mFirstAmbientIndex;
    private final Bundle mVisibilityOverrides;
    private final Bundle mSuppressedVisualEffects;

    public NotificationRankingUpdate(String[] keys, String[] interceptedKeys,
            Bundle visibilityOverrides, int firstAmbientIndex) {
            Bundle visibilityOverrides, int firstAmbientIndex, Bundle suppressedVisualEffects) {
        mKeys = keys;
        mFirstAmbientIndex = firstAmbientIndex;
        mInterceptedKeys = interceptedKeys;
        mVisibilityOverrides = visibilityOverrides;
        mSuppressedVisualEffects = suppressedVisualEffects;
    }

    public NotificationRankingUpdate(Parcel in) {
@@ -42,6 +44,7 @@ public class NotificationRankingUpdate implements Parcelable {
        mFirstAmbientIndex = in.readInt();
        mInterceptedKeys = in.readStringArray();
        mVisibilityOverrides = in.readBundle();
        mSuppressedVisualEffects = in.readBundle();
    }

    @Override
@@ -55,6 +58,7 @@ public class NotificationRankingUpdate implements Parcelable {
        out.writeInt(mFirstAmbientIndex);
        out.writeStringArray(mInterceptedKeys);
        out.writeBundle(mVisibilityOverrides);
        out.writeBundle(mSuppressedVisualEffects);
    }

    public static final Parcelable.Creator<NotificationRankingUpdate> CREATOR
@@ -83,4 +87,8 @@ public class NotificationRankingUpdate implements Parcelable {
    public Bundle getVisibilityOverrides() {
        return mVisibilityOverrides;
    }

    public Bundle getSuppressedVisualEffects() {
        return mSuppressedVisualEffects;
    }
}
Loading