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

Commit 596bc39f authored by DvTonder's avatar DvTonder Committed by Gerrit Code Review
Browse files

Frameworks: Allow/Prevent notification light in Zen mode (1 of 2)

This allows the user to prevent the notification lights from showing during Zen mode as per Android 5.0.x

Change-Id: I831c475204c8647d8ee281094aca837ee9594eb4
parent 555b1752
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -3508,6 +3508,12 @@ public final class Settings {
         */
        public static final String NONE_IS_SILENT = "none_is_silent";

        /**
         * Whether the notification light will be allowed when in zen mode during downtime
         * @hide
         */
        public static final String ALLOW_LIGHTS = "allow_lights";

        /**
         * Settings to backup. This is here so that it's in the same place as the settings
         * keys and easy to update.
@@ -3591,7 +3597,9 @@ public final class Settings {
            DISPLAY_TEMPERATURE_DAY,
            DISPLAY_TEMPERATURE_MODE,
            DISPLAY_AUTO_OUTDOOR_MODE,
            LIVE_DISPLAY_HINTED
            LIVE_DISPLAY_HINTED,
            NONE_IS_SILENT,
            ALLOW_LIGHTS
        };

        /**
+4 −2
Original line number Diff line number Diff line
@@ -1055,6 +1055,7 @@ public class NotificationManagerService extends SystemService {
        }
        mZenModeHelper.readZenModeFromSetting();
        mZenModeHelper.readSilentModeFromSetting();
        mZenModeHelper.readLightsAllowedModeFromSetting();
        mInterruptionFilter = mZenModeHelper.getZenModeListenerInterruptionFilter();

        mUserProfiles.updateCache(getContext());
@@ -2328,8 +2329,9 @@ public class NotificationManagerService extends SystemService {
        // light
        // release the light
        boolean wasShowLights = mLights.remove(record.getKey());
        final boolean aboveThresholdWithLight = aboveThreshold || isLedNotificationForcedOn(record);
        if ((notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0 && aboveThresholdWithLight) {
        final boolean canInterruptWithLight = canInterrupt || isLedNotificationForcedOn(record)
                || (!canInterrupt && mZenModeHelper.getAreLightsAllowed());
        if ((notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0 && canInterruptWithLight) {
            mLights.add(record.getKey());
            updateLightsLocked();
            if (mUseAttentionLight) {
+14 −0
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ public class ZenModeHelper implements AudioManagerInternal.RingerModeDelegate {
    private int mPreviousRingerMode = -1;
    private boolean mEffectsSuppressed;
    private boolean mNoneIsSilent;
    private boolean mAllowLights;

    public ZenModeHelper(Context context, Looper looper) {
        mContext = context;
@@ -264,6 +265,15 @@ public class ZenModeHelper implements AudioManagerInternal.RingerModeDelegate {
        applyRestrictions();
    }

    public boolean getAreLightsAllowed() {
        return mAllowLights;
    }

    public void readLightsAllowedModeFromSetting() {
        mAllowLights = System.getIntForUser(mContext.getContentResolver(),
                System.ALLOW_LIGHTS, 1, UserHandle.USER_CURRENT) == 1;
    }

    private void applyRestrictions() {
        final boolean zen = mZenMode != Global.ZEN_MODE_OFF;

@@ -527,6 +537,7 @@ public class ZenModeHelper implements AudioManagerInternal.RingerModeDelegate {
    private class SettingsObserver extends ContentObserver {
        private final Uri ZEN_MODE = Global.getUriFor(Global.ZEN_MODE);
        private final Uri NONE_IS_SILENT = System.getUriFor(System.NONE_IS_SILENT);
        private final Uri ALLOW_LIGHTS = System.getUriFor(System.ALLOW_LIGHTS);

        public SettingsObserver(Handler handler) {
            super(handler);
@@ -536,6 +547,7 @@ public class ZenModeHelper implements AudioManagerInternal.RingerModeDelegate {
            final ContentResolver resolver = mContext.getContentResolver();
            resolver.registerContentObserver(ZEN_MODE, false /*notifyForDescendents*/, this);
            resolver.registerContentObserver(NONE_IS_SILENT, false /*notifyForDescendents*/, this);
            resolver.registerContentObserver(ALLOW_LIGHTS, false /*notifyForDescendents*/, this);
            update(null);
        }

@@ -549,6 +561,8 @@ public class ZenModeHelper implements AudioManagerInternal.RingerModeDelegate {
                readZenModeFromSetting();
            } else if (NONE_IS_SILENT.equals(uri)) {
                readSilentModeFromSetting();
            } else if (ALLOW_LIGHTS.equals(uri)) {
                readLightsAllowedModeFromSetting();
            }
        }
    }