frameworks/base
修訂 | 3f8962fc4f47eeea11cf6d39a60c182baba9a98c (tree) |
---|---|
時間 | 2016-10-05 20:38:59 |
作者 | DvTonder <david.vantonder@gmai...> |
Commiter | Steve Kondik |
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
@@ -1162,6 +1162,7 @@ public class NotificationManagerService extends SystemService { | ||
1162 | 1162 | mDisableNotificationEffects = true; |
1163 | 1163 | } |
1164 | 1164 | mZenModeHelper.initZenMode(); |
1165 | + mZenModeHelper.readAllowLightsFromSettings(); | |
1165 | 1166 | mInterruptionFilter = mZenModeHelper.getZenModeListenerInterruptionFilter(); |
1166 | 1167 | |
1167 | 1168 | mUserProfiles.updateCache(getContext()); |
@@ -3091,8 +3092,10 @@ public class NotificationManagerService extends SystemService { | ||
3091 | 3092 | // light |
3092 | 3093 | // release the light |
3093 | 3094 | boolean wasShowLights = mLights.remove(key); |
3094 | - final boolean aboveThresholdWithLight = aboveThreshold || isLedNotificationForcedOn(record); | |
3095 | - if ((notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0 && aboveThresholdWithLight | |
3095 | + final boolean canInterruptWithLight = canInterrupt || | |
3096 | + isLedNotificationForcedOn(record) || | |
3097 | + (!canInterrupt && mZenModeHelper.getAllowLights()); | |
3098 | + if ((notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0 && canInterruptWithLight | |
3096 | 3099 | && ((record.getSuppressedVisualEffects() |
3097 | 3100 | & NotificationListenerService.SUPPRESSED_EFFECT_SCREEN_OFF) == 0)) { |
3098 | 3101 | mLights.add(key); |
@@ -62,6 +62,7 @@ import android.util.SparseArray; | ||
62 | 62 | import com.android.internal.R; |
63 | 63 | import com.android.internal.logging.MetricsLogger; |
64 | 64 | import com.android.server.LocalServices; |
65 | +import cyanogenmod.providers.CMSettings; | |
65 | 66 | |
66 | 67 | import libcore.io.IoUtils; |
67 | 68 |
@@ -104,6 +105,7 @@ public class ZenModeHelper { | ||
104 | 105 | private AudioManagerInternal mAudioManager; |
105 | 106 | private PackageManager mPm; |
106 | 107 | private long mSuppressedEffects; |
108 | + private boolean mAllowLights; | |
107 | 109 | |
108 | 110 | public static final long SUPPRESSED_EFFECT_NOTIFICATIONS = 1; |
109 | 111 | public static final long SUPPRESSED_EFFECT_CALLS = 1 << 1; |
@@ -688,6 +690,7 @@ public class ZenModeHelper { | ||
688 | 690 | ZenLog.traceSetZenMode(zen, reason); |
689 | 691 | mZenMode = zen; |
690 | 692 | updateRingerModeAffectedStreams(); |
693 | + readAllowLightsFromSettings(); | |
691 | 694 | setZenModeSetting(mZenMode); |
692 | 695 | if (setRingerMode) { |
693 | 696 | applyZenToRingerMode(); |
@@ -721,6 +724,24 @@ public class ZenModeHelper { | ||
721 | 724 | } |
722 | 725 | } |
723 | 726 | |
727 | + public boolean getAllowLights() { | |
728 | + return mAllowLights; | |
729 | + } | |
730 | + | |
731 | + public void readAllowLightsFromSettings() { | |
732 | + switch (mZenMode) { | |
733 | + case Global.ZEN_MODE_NO_INTERRUPTIONS: | |
734 | + case Global.ZEN_MODE_ALARMS: | |
735 | + mAllowLights = CMSettings.System.getInt(mContext.getContentResolver(), | |
736 | + CMSettings.System.ZEN_ALLOW_LIGHTS, 1) == 1; | |
737 | + break; | |
738 | + case Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS: | |
739 | + mAllowLights = CMSettings.System.getInt(mContext.getContentResolver(), | |
740 | + CMSettings.System.ZEN_PRIORITY_ALLOW_LIGHTS, 1) == 1; | |
741 | + break; | |
742 | + } | |
743 | + } | |
744 | + | |
724 | 745 | private void applyRestrictions() { |
725 | 746 | final boolean zen = mZenMode != Global.ZEN_MODE_OFF; |
726 | 747 |
@@ -742,6 +763,8 @@ public class ZenModeHelper { | ||
742 | 763 | applyRestrictions(muteEverything, i); |
743 | 764 | } |
744 | 765 | } |
766 | + | |
767 | + readAllowLightsFromSettings(); | |
745 | 768 | } |
746 | 769 | |
747 | 770 | private void applyRestrictions(boolean mute, int usage) { |
@@ -1022,6 +1045,10 @@ public class ZenModeHelper { | ||
1022 | 1045 | |
1023 | 1046 | private final class SettingsObserver extends ContentObserver { |
1024 | 1047 | private final Uri ZEN_MODE = Global.getUriFor(Global.ZEN_MODE); |
1048 | + private final Uri ZEN_ALLOW_LIGHTS = CMSettings.System.getUriFor( | |
1049 | + CMSettings.System.ZEN_ALLOW_LIGHTS); | |
1050 | + private final Uri ZEN_PRIORITY_ALLOW_LIGHTS = CMSettings.System.getUriFor( | |
1051 | + CMSettings.System.ZEN_PRIORITY_ALLOW_LIGHTS); | |
1025 | 1052 | |
1026 | 1053 | public SettingsObserver(Handler handler) { |
1027 | 1054 | super(handler); |
@@ -1030,6 +1057,10 @@ public class ZenModeHelper { | ||
1030 | 1057 | public void observe() { |
1031 | 1058 | final ContentResolver resolver = mContext.getContentResolver(); |
1032 | 1059 | resolver.registerContentObserver(ZEN_MODE, false /*notifyForDescendents*/, this); |
1060 | + resolver.registerContentObserver( | |
1061 | + ZEN_ALLOW_LIGHTS, false /*notifyForDescendents*/, this); | |
1062 | + resolver.registerContentObserver( | |
1063 | + ZEN_PRIORITY_ALLOW_LIGHTS, false /*notifyForDescendents*/, this); | |
1033 | 1064 | update(null); |
1034 | 1065 | } |
1035 | 1066 |
@@ -1044,6 +1075,8 @@ public class ZenModeHelper { | ||
1044 | 1075 | if (DEBUG) Log.d(TAG, "Fixing zen mode setting"); |
1045 | 1076 | setZenModeSetting(mZenMode); |
1046 | 1077 | } |
1078 | + } else if (ZEN_ALLOW_LIGHTS.equals(uri) || ZEN_PRIORITY_ALLOW_LIGHTS.equals(uri)) { | |
1079 | + readAllowLightsFromSettings(); | |
1047 | 1080 | } |
1048 | 1081 | } |
1049 | 1082 | } |