diff options
4 files changed, 54 insertions, 18 deletions
diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl index e749d0a..7c51a83 100644 --- a/core/java/android/app/INotificationManager.aidl +++ b/core/java/android/app/INotificationManager.aidl @@ -80,7 +80,7 @@ interface INotificationManager void setInterruptionFilter(String pkg, int interruptionFilter); ComponentName getEffectsSuppressor(); - boolean matchesCallFilter(in Bundle extras); + boolean[] matchesCallFilter(in Bundle extras); boolean isSystemConditionProviderEnabled(String path); int getZenMode(); diff --git a/core/java/android/app/NotificationManager.java b/core/java/android/app/NotificationManager.java index 2219e64..d84eee2 100644 --- a/core/java/android/app/NotificationManager.java +++ b/core/java/android/app/NotificationManager.java @@ -341,12 +341,12 @@ public class NotificationManager /** * @hide */ - public boolean matchesCallFilter(Bundle extras) { + public boolean[] matchesCallFilter(Bundle extras) { INotificationManager service = getService(); try { return service.matchesCallFilter(extras); } catch (RemoteException e) { - return false; + return null; } } 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(); } } } |