Skip to content

Commit e05eda2

Browse files
committed
(Optionally) allow vibration during priority zen mode.
Change-Id: I6fb81c5898fbfe9e89a4af3fdc042266c8a9be6c
1 parent 1913944 commit e05eda2

4 files changed

Lines changed: 54 additions & 18 deletions

File tree

core/java/android/app/INotificationManager.aidl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ interface INotificationManager
8080
void setInterruptionFilter(String pkg, int interruptionFilter);
8181

8282
ComponentName getEffectsSuppressor();
83-
boolean matchesCallFilter(in Bundle extras);
83+
boolean[] matchesCallFilter(in Bundle extras);
8484
boolean isSystemConditionProviderEnabled(String path);
8585

8686
int getZenMode();

core/java/android/app/NotificationManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,12 @@ public ComponentName getEffectsSuppressor() {
341341
/**
342342
* @hide
343343
*/
344-
public boolean matchesCallFilter(Bundle extras) {
344+
public boolean[] matchesCallFilter(Bundle extras) {
345345
INotificationManager service = getService();
346346
try {
347347
return service.matchesCallFilter(extras);
348348
} catch (RemoteException e) {
349-
return false;
349+
return null;
350350
}
351351
}
352352

services/core/java/com/android/server/notification/NotificationManagerService.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,7 @@ void onPolicyChanged() {
12641264
}
12651265
mZenModeHelper.initZenMode();
12661266
mZenModeHelper.readAllowLightsFromSettings();
1267+
mZenModeHelper.readVibrationModeFromSettings();
12671268
mInterruptionFilter = mZenModeHelper.getZenModeListenerInterruptionFilter();
12681269

12691270
mUserProfiles.updateCache(getContext());
@@ -2031,7 +2032,7 @@ public ComponentName getEffectsSuppressor() {
20312032
}
20322033

20332034
@Override
2034-
public boolean matchesCallFilter(Bundle extras) {
2035+
public boolean[] matchesCallFilter(Bundle extras) {
20352036
enforceSystemOrSystemUI("INotificationManager.matchesCallFilter");
20362037
return mZenModeHelper.matchesCallFilter(
20372038
UserHandle.getCallingUserHandle(),
@@ -2698,21 +2699,28 @@ private void buzzBeepBlinkLocked(NotificationRecord record) {
26982699
ZenLog.traceDisableEffects(record, disableEffects);
26992700
}
27002701

2701-
if ((disableEffects == null)
2702+
boolean readyForBeepOrBuzz = disableEffects == null
27022703
&& (!(record.isUpdate
27032704
&& (notification.flags & Notification.FLAG_ONLY_ALERT_ONCE) != 0 ))
27042705
&& (record.getUserId() == UserHandle.USER_ALL ||
27052706
record.getUserId() == currentUser ||
27062707
mUserProfiles.isCurrentProfile(record.getUserId()))
2707-
&& canInterrupt
27082708
&& mSystemReady
2709-
&& mAudioManager != null) {
2709+
&& mAudioManager != null;
2710+
2711+
boolean canBeep = readyForBeepOrBuzz && canInterrupt;
2712+
boolean canBuzz = readyForBeepOrBuzz &&
2713+
(canInterrupt || mZenModeHelper.allowVibrationForNotifications());
2714+
boolean hasValidSound = false;
2715+
2716+
if (canBeep || canBuzz) {
27102717
if (DBG) Slog.v(TAG, "Interrupting!");
27112718

27122719
sendAccessibilityEvent(notification, record.sbn.getPackageName());
2720+
}
27132721

2714-
// sound
2715-
2722+
// sound
2723+
if (canBeep) {
27162724
// should we use the default notification sound? (indicated either by
27172725
// DEFAULT_SOUND or because notification.sound is pointing at
27182726
// Settings.System.NOTIFICATION_SOUND)
@@ -2722,7 +2730,6 @@ private void buzzBeepBlinkLocked(NotificationRecord record) {
27222730
.equals(notification.sound);
27232731

27242732
Uri soundUri = null;
2725-
boolean hasValidSound = false;
27262733

27272734
if (useDefaultSound) {
27282735
soundUri = Settings.System.DEFAULT_NOTIFICATION_URI;
@@ -2763,15 +2770,17 @@ private void buzzBeepBlinkLocked(NotificationRecord record) {
27632770
}
27642771
}
27652772
}
2773+
}
27662774

2767-
// vibrate
2775+
2776+
// vibrate
2777+
if (canBuzz) {
27682778
// Does the notification want to specify its own vibration?
27692779
final boolean hasCustomVibrate = notification.vibrate != null;
27702780

27712781
// new in 4.2: if there was supposed to be a sound and we're in vibrate
27722782
// mode, and no other vibration is specified, we fall back to vibration
2773-
final boolean convertSoundToVibration =
2774-
!hasCustomVibrate
2783+
final boolean convertSoundToVibration = !hasCustomVibrate
27752784
&& hasValidSound
27762785
&& (mAudioManager.getRingerModeInternal()
27772786
== AudioManager.RINGER_MODE_VIBRATE);

services/core/java/com/android/server/notification/ZenModeHelper.java

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public class ZenModeHelper {
9191
private AudioManagerInternal mAudioManager;
9292
private boolean mEffectsSuppressed;
9393
private boolean mAllowLights;
94+
private int mVibrationMode;
9495

9596
public ZenModeHelper(Context context, Looper looper, ConditionProviders conditionProviders) {
9697
mContext = context;
@@ -117,10 +118,12 @@ public String toString() {
117118
return TAG;
118119
}
119120

120-
public boolean matchesCallFilter(UserHandle userHandle, Bundle extras,
121+
public boolean[] matchesCallFilter(UserHandle userHandle, Bundle extras,
121122
ValidateNotificationPeople validator, int contactsTimeoutMs, float timeoutAffinity) {
122-
return ZenModeFiltering.matchesCallFilter(mContext, mZenMode, mConfig, userHandle, extras,
123-
validator, contactsTimeoutMs, timeoutAffinity);
123+
boolean matches = ZenModeFiltering.matchesCallFilter(mContext, mZenMode, mConfig,
124+
userHandle, extras, validator, contactsTimeoutMs, timeoutAffinity);
125+
boolean matchesForVibration = matches || allowVibrationForCalls();
126+
return new boolean[] { matches, matchesForVibration };
124127
}
125128

126129
public boolean isCall(NotificationRecord record) {
@@ -238,6 +241,8 @@ public void dump(PrintWriter pw, String prefix) {
238241
pw.print(prefix); pw.print("mUser="); pw.println(mUser);
239242
dump(pw, prefix, "mConfig", mConfig);
240243
pw.print(prefix); pw.print("mEffectsSuppressed="); pw.println(mEffectsSuppressed);
244+
pw.print(prefix); pw.print("mAllowLights="); pw.println(mAllowLights);
245+
pw.print(prefix); pw.print("mVibrationMode="); pw.println(mVibrationMode);
241246
mFiltering.dump(pw, prefix);
242247
mConditions.dump(pw, prefix);
243248
}
@@ -381,6 +386,7 @@ private boolean evaluateZenMode(String reason, boolean setRingerMode) {
381386
mZenMode = zen;
382387
updateRingerModeAffectedStreams();
383388
readAllowLightsFromSettings();
389+
readVibrationModeFromSettings();
384390
setZenModeSetting(mZenMode);
385391
if (setRingerMode) {
386392
applyZenToRingerMode();
@@ -428,6 +434,21 @@ public void readAllowLightsFromSettings() {
428434
}
429435
}
430436

437+
public boolean allowVibrationForCalls() {
438+
return mVibrationMode > 0;
439+
}
440+
441+
public boolean allowVibrationForNotifications() {
442+
return mVibrationMode > 1;
443+
}
444+
445+
public void readVibrationModeFromSettings() {
446+
final ContentResolver cr = mContext.getContentResolver();
447+
mVibrationMode = mZenMode == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS
448+
? CMSettings.System.getInt(cr, CMSettings.System.ZEN_PRIORITY_VIBRATION_MODE, 0)
449+
: 0;
450+
}
451+
431452
private void applyRestrictions() {
432453
final boolean zen = mZenMode != Global.ZEN_MODE_OFF;
433454

@@ -715,9 +736,11 @@ public int getRingerModeAffectedStreams(int streams) {
715736
private final class SettingsObserver extends ContentObserver {
716737
private final Uri ZEN_MODE = Global.getUriFor(Global.ZEN_MODE);
717738
private final Uri ZEN_ALLOW_LIGHTS = CMSettings.System.getUriFor(
718-
CMSettings.System.ZEN_ALLOW_LIGHTS);
739+
CMSettings.System.ZEN_ALLOW_LIGHTS);
719740
private final Uri ZEN_PRIORITY_ALLOW_LIGHTS = CMSettings.System.getUriFor(
720-
CMSettings.System.ZEN_PRIORITY_ALLOW_LIGHTS);
741+
CMSettings.System.ZEN_PRIORITY_ALLOW_LIGHTS);
742+
private final Uri ZEN_PRIORITY_VIBRATION_MODE = CMSettings.System.getUriFor(
743+
CMSettings.System.ZEN_PRIORITY_VIBRATION_MODE);
721744

722745
public SettingsObserver(Handler handler) {
723746
super(handler);
@@ -730,6 +753,8 @@ public void observe() {
730753
ZEN_ALLOW_LIGHTS, false /*notifyForDescendents*/, this);
731754
resolver.registerContentObserver(
732755
ZEN_PRIORITY_ALLOW_LIGHTS, false /*notifyForDescendents*/, this);
756+
resolver.registerContentObserver(
757+
ZEN_PRIORITY_VIBRATION_MODE, false /*notifyForDescendents*/, this);
733758
update(null);
734759
}
735760

@@ -746,6 +771,8 @@ public void update(Uri uri) {
746771
}
747772
} else if (ZEN_ALLOW_LIGHTS.equals(uri) || ZEN_PRIORITY_ALLOW_LIGHTS.equals(uri)) {
748773
readAllowLightsFromSettings();
774+
} else if (ZEN_PRIORITY_VIBRATION_MODE.equals(uri)) {
775+
readVibrationModeFromSettings();
749776
}
750777
}
751778
}

0 commit comments

Comments
 (0)