diff options
author | Danny Baumann <dannybaumann@web.de> | 2016-10-17 16:39:46 +0200 |
---|---|---|
committer | Danny Baumann <dannybaumann@web.de> | 2016-10-19 13:38:54 +0200 |
commit | e05eda22dd6d2e4834b5ff2b364d4258ad590f3e (patch) | |
tree | f63d0a2002884d87de5f4e34a6ce2dd5fb5c4be8 /services/core | |
parent | 19139443a777843efe4e0f02a77e939629bd249b (diff) | |
download | frameworks_base-e05eda22dd6d2e4834b5ff2b364d4258ad590f3e.zip frameworks_base-e05eda22dd6d2e4834b5ff2b364d4258ad590f3e.tar.gz frameworks_base-e05eda22dd6d2e4834b5ff2b364d4258ad590f3e.tar.bz2 |
(Optionally) allow vibration during priority zen mode.
Change-Id: I6fb81c5898fbfe9e89a4af3fdc042266c8a9be6c
Diffstat (limited to 'services/core')
-rw-r--r-- | services/core/java/com/android/server/notification/NotificationManagerService.java | 29 | ||||
-rw-r--r-- | services/core/java/com/android/server/notification/ZenModeHelper.java | 37 |
2 files changed, 51 insertions, 15 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 9b2804a..43efddd 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -1264,6 +1264,7 @@ public class NotificationManagerService extends SystemService { } mZenModeHelper.initZenMode(); mZenModeHelper.readAllowLightsFromSettings(); + mZenModeHelper.readVibrationModeFromSettings(); mInterruptionFilter = mZenModeHelper.getZenModeListenerInterruptionFilter(); mUserProfiles.updateCache(getContext()); @@ -2031,7 +2032,7 @@ public class NotificationManagerService extends SystemService { } @Override - public boolean matchesCallFilter(Bundle extras) { + public boolean[] matchesCallFilter(Bundle extras) { enforceSystemOrSystemUI("INotificationManager.matchesCallFilter"); return mZenModeHelper.matchesCallFilter( UserHandle.getCallingUserHandle(), @@ -2698,21 +2699,28 @@ public class NotificationManagerService extends SystemService { ZenLog.traceDisableEffects(record, disableEffects); } - if ((disableEffects == null) + boolean readyForBeepOrBuzz = disableEffects == null && (!(record.isUpdate && (notification.flags & Notification.FLAG_ONLY_ALERT_ONCE) != 0 )) && (record.getUserId() == UserHandle.USER_ALL || record.getUserId() == currentUser || mUserProfiles.isCurrentProfile(record.getUserId())) - && canInterrupt && mSystemReady - && mAudioManager != null) { + && mAudioManager != null; + + boolean canBeep = readyForBeepOrBuzz && canInterrupt; + boolean canBuzz = readyForBeepOrBuzz && + (canInterrupt || mZenModeHelper.allowVibrationForNotifications()); + boolean hasValidSound = false; + + if (canBeep || canBuzz) { if (DBG) Slog.v(TAG, "Interrupting!"); sendAccessibilityEvent(notification, record.sbn.getPackageName()); + } - // sound - + // sound + if (canBeep) { // should we use the default notification sound? (indicated either by // DEFAULT_SOUND or because notification.sound is pointing at // Settings.System.NOTIFICATION_SOUND) @@ -2722,7 +2730,6 @@ public class NotificationManagerService extends SystemService { .equals(notification.sound); Uri soundUri = null; - boolean hasValidSound = false; if (useDefaultSound) { soundUri = Settings.System.DEFAULT_NOTIFICATION_URI; @@ -2763,15 +2770,17 @@ public class NotificationManagerService extends SystemService { } } } + } - // vibrate + + // vibrate + if (canBuzz) { // Does the notification want to specify its own vibration? final boolean hasCustomVibrate = notification.vibrate != null; // new in 4.2: if there was supposed to be a sound and we're in vibrate // mode, and no other vibration is specified, we fall back to vibration - final boolean convertSoundToVibration = - !hasCustomVibrate + final boolean convertSoundToVibration = !hasCustomVibrate && hasValidSound && (mAudioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_VIBRATE); diff --git a/services/core/java/com/android/server/notification/ZenModeHelper.java b/services/core/java/com/android/server/notification/ZenModeHelper.java index 468ef8d..54eac06 100644 --- a/services/core/java/com/android/server/notification/ZenModeHelper.java +++ b/services/core/java/com/android/server/notification/ZenModeHelper.java @@ -91,6 +91,7 @@ public class ZenModeHelper { private AudioManagerInternal mAudioManager; private boolean mEffectsSuppressed; private boolean mAllowLights; + private int mVibrationMode; public ZenModeHelper(Context context, Looper looper, ConditionProviders conditionProviders) { mContext = context; @@ -117,10 +118,12 @@ public class ZenModeHelper { return TAG; } - public boolean matchesCallFilter(UserHandle userHandle, Bundle extras, + public boolean[] matchesCallFilter(UserHandle userHandle, Bundle extras, ValidateNotificationPeople validator, int contactsTimeoutMs, float timeoutAffinity) { - return ZenModeFiltering.matchesCallFilter(mContext, mZenMode, mConfig, userHandle, extras, - validator, contactsTimeoutMs, timeoutAffinity); + boolean matches = ZenModeFiltering.matchesCallFilter(mContext, mZenMode, mConfig, + userHandle, extras, validator, contactsTimeoutMs, timeoutAffinity); + boolean matchesForVibration = matches || allowVibrationForCalls(); + return new boolean[] { matches, matchesForVibration }; } public boolean isCall(NotificationRecord record) { @@ -238,6 +241,8 @@ public class ZenModeHelper { pw.print(prefix); pw.print("mUser="); pw.println(mUser); dump(pw, prefix, "mConfig", mConfig); pw.print(prefix); pw.print("mEffectsSuppressed="); pw.println(mEffectsSuppressed); + pw.print(prefix); pw.print("mAllowLights="); pw.println(mAllowLights); + pw.print(prefix); pw.print("mVibrationMode="); pw.println(mVibrationMode); mFiltering.dump(pw, prefix); mConditions.dump(pw, prefix); } @@ -381,6 +386,7 @@ public class ZenModeHelper { mZenMode = zen; updateRingerModeAffectedStreams(); readAllowLightsFromSettings(); + readVibrationModeFromSettings(); setZenModeSetting(mZenMode); if (setRingerMode) { applyZenToRingerMode(); @@ -428,6 +434,21 @@ public class ZenModeHelper { } } + public boolean allowVibrationForCalls() { + return mVibrationMode > 0; + } + + public boolean allowVibrationForNotifications() { + return mVibrationMode > 1; + } + + public void readVibrationModeFromSettings() { + final ContentResolver cr = mContext.getContentResolver(); + mVibrationMode = mZenMode == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS + ? CMSettings.System.getInt(cr, CMSettings.System.ZEN_PRIORITY_VIBRATION_MODE, 0) + : 0; + } + private void applyRestrictions() { final boolean zen = mZenMode != Global.ZEN_MODE_OFF; @@ -715,9 +736,11 @@ 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); + CMSettings.System.ZEN_ALLOW_LIGHTS); private final Uri ZEN_PRIORITY_ALLOW_LIGHTS = CMSettings.System.getUriFor( - CMSettings.System.ZEN_PRIORITY_ALLOW_LIGHTS); + CMSettings.System.ZEN_PRIORITY_ALLOW_LIGHTS); + private final Uri ZEN_PRIORITY_VIBRATION_MODE = CMSettings.System.getUriFor( + CMSettings.System.ZEN_PRIORITY_VIBRATION_MODE); public SettingsObserver(Handler handler) { super(handler); @@ -730,6 +753,8 @@ public class ZenModeHelper { ZEN_ALLOW_LIGHTS, false /*notifyForDescendents*/, this); resolver.registerContentObserver( ZEN_PRIORITY_ALLOW_LIGHTS, false /*notifyForDescendents*/, this); + resolver.registerContentObserver( + ZEN_PRIORITY_VIBRATION_MODE, false /*notifyForDescendents*/, this); update(null); } @@ -746,6 +771,8 @@ public class ZenModeHelper { } } else if (ZEN_ALLOW_LIGHTS.equals(uri) || ZEN_PRIORITY_ALLOW_LIGHTS.equals(uri)) { readAllowLightsFromSettings(); + } else if (ZEN_PRIORITY_VIBRATION_MODE.equals(uri)) { + readVibrationModeFromSettings(); } } } |