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

Commit 3f8962fc authored by DvTonder's avatar DvTonder Committed by Steve Kondik
Browse files

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

This allows the user to prevent the notification lights from showing during Zen mode

Change-Id: I831c475204c8647d8ee281094aca837ee9594eb4
parent 33086de9
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -1162,6 +1162,7 @@ public class NotificationManagerService extends SystemService {
            mDisableNotificationEffects = true;
        }
        mZenModeHelper.initZenMode();
        mZenModeHelper.readAllowLightsFromSettings();
        mInterruptionFilter = mZenModeHelper.getZenModeListenerInterruptionFilter();

        mUserProfiles.updateCache(getContext());
@@ -3091,8 +3092,10 @@ public class NotificationManagerService extends SystemService {
        // light
        // release the light
        boolean wasShowLights = mLights.remove(key);
        final boolean aboveThresholdWithLight = aboveThreshold || isLedNotificationForcedOn(record);
        if ((notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0 && aboveThresholdWithLight
        final boolean canInterruptWithLight = canInterrupt ||
                isLedNotificationForcedOn(record) ||
                (!canInterrupt && mZenModeHelper.getAllowLights());
        if ((notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0 && canInterruptWithLight
                && ((record.getSuppressedVisualEffects()
                & NotificationListenerService.SUPPRESSED_EFFECT_SCREEN_OFF) == 0)) {
            mLights.add(key);
+33 −0
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ import android.util.SparseArray;
import com.android.internal.R;
import com.android.internal.logging.MetricsLogger;
import com.android.server.LocalServices;
import cyanogenmod.providers.CMSettings;

import libcore.io.IoUtils;

@@ -104,6 +105,7 @@ public class ZenModeHelper {
    private AudioManagerInternal mAudioManager;
    private PackageManager mPm;
    private long mSuppressedEffects;
    private boolean mAllowLights;

    public static final long SUPPRESSED_EFFECT_NOTIFICATIONS = 1;
    public static final long SUPPRESSED_EFFECT_CALLS = 1 << 1;
@@ -688,6 +690,7 @@ public class ZenModeHelper {
        ZenLog.traceSetZenMode(zen, reason);
        mZenMode = zen;
        updateRingerModeAffectedStreams();
        readAllowLightsFromSettings();
        setZenModeSetting(mZenMode);
        if (setRingerMode) {
            applyZenToRingerMode();
@@ -721,6 +724,24 @@ public class ZenModeHelper {
        }
    }

    public boolean getAllowLights() {
        return mAllowLights;
    }

    public void readAllowLightsFromSettings() {
        switch (mZenMode) {
            case Global.ZEN_MODE_NO_INTERRUPTIONS:
            case Global.ZEN_MODE_ALARMS:
                mAllowLights = CMSettings.System.getInt(mContext.getContentResolver(),
                   CMSettings.System.ZEN_ALLOW_LIGHTS, 1) == 1;
                break;
            case Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS:
                mAllowLights = CMSettings.System.getInt(mContext.getContentResolver(),
                   CMSettings.System.ZEN_PRIORITY_ALLOW_LIGHTS, 1) == 1;
                break;
        }
    }

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

@@ -742,6 +763,8 @@ public class ZenModeHelper {
                applyRestrictions(muteEverything, i);
            }
        }

        readAllowLightsFromSettings();
    }

    private void applyRestrictions(boolean mute, int usage) {
@@ -1022,6 +1045,10 @@ public class ZenModeHelper {

    private final class SettingsObserver extends ContentObserver {
        private final Uri ZEN_MODE = Global.getUriFor(Global.ZEN_MODE);
        private final Uri ZEN_ALLOW_LIGHTS = CMSettings.System.getUriFor(
                                               CMSettings.System.ZEN_ALLOW_LIGHTS);
        private final Uri ZEN_PRIORITY_ALLOW_LIGHTS = CMSettings.System.getUriFor(
                                               CMSettings.System.ZEN_PRIORITY_ALLOW_LIGHTS);

        public SettingsObserver(Handler handler) {
            super(handler);
@@ -1030,6 +1057,10 @@ public class ZenModeHelper {
        public void observe() {
            final ContentResolver resolver = mContext.getContentResolver();
            resolver.registerContentObserver(ZEN_MODE, false /*notifyForDescendents*/, this);
            resolver.registerContentObserver(
                     ZEN_ALLOW_LIGHTS, false /*notifyForDescendents*/, this);
            resolver.registerContentObserver(
                     ZEN_PRIORITY_ALLOW_LIGHTS, false /*notifyForDescendents*/, this);
            update(null);
        }

@@ -1044,6 +1075,8 @@ public class ZenModeHelper {
                    if (DEBUG) Log.d(TAG, "Fixing zen mode setting");
                    setZenModeSetting(mZenMode);
                }
            } else if (ZEN_ALLOW_LIGHTS.equals(uri) || ZEN_PRIORITY_ALLOW_LIGHTS.equals(uri)) {
                readAllowLightsFromSettings();
            }
        }
    }