Skip to content

Commit

Permalink
Allow to suppress notifications sound/vibration if screen is ON [1/2]
Browse files Browse the repository at this point in the history
Change-Id: I279b202682939d797d3116089f50d65e3dd3eb01
  • Loading branch information
ezio84 authored and heisinbug committed Dec 17, 2021
1 parent ce30e9f commit e430f6e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 8 additions & 0 deletions core/java/android/provider/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -5203,6 +5203,14 @@ public static void setShowGTalkServiceStatusForUser(ContentResolver cr, boolean
*/
public static final String GLOBAL_ACTIONS_LIST = "global_actions_list";

/**
* Wheter to play notification sound and vibration if screen is ON
* 0 - never
* 1 - always
* @hide
*/
public static final String NOTIFICATION_SOUND_VIB_SCREEN_ON = "notification_sound_vib_screen_on";

/**
* IMPORTANT: If you add a new public settings you also have to add it to
* PUBLIC_SETTINGS below. If the new setting is hidden you have to add
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@ public class NotificationManagerService extends SystemService {
protected boolean mInCallStateOffHook = false;
boolean mNotificationPulseEnabled;

private boolean mSoundVibScreenOn;

private Uri mInCallNotificationUri;
private AudioAttributes mInCallNotificationAudioAttributes;
private float mInCallNotificationVolume;
Expand Down Expand Up @@ -1912,6 +1914,8 @@ private final class SettingsObserver extends ContentObserver {
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS);
private final Uri LOCK_SCREEN_SHOW_NOTIFICATIONS
= Settings.Secure.getUriFor(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS);
private final Uri NOTIFICATION_SOUND_VIB_SCREEN_ON
= Settings.System.getUriFor(Settings.System.NOTIFICATION_SOUND_VIB_SCREEN_ON);

SettingsObserver(Handler handler) {
super(handler);
Expand All @@ -1936,6 +1940,8 @@ void observe() {
false, this, UserHandle.USER_ALL);
resolver.registerContentObserver(LOCK_SCREEN_SHOW_NOTIFICATIONS,
false, this, UserHandle.USER_ALL);
resolver.registerContentObserver(NOTIFICATION_SOUND_VIB_SCREEN_ON,
false, this, UserHandle.USER_ALL);
update(null);
}

Expand Down Expand Up @@ -1983,6 +1989,11 @@ public void update(Uri uri) {
if (uri == null || LOCK_SCREEN_SHOW_NOTIFICATIONS.equals(uri)) {
mPreferencesHelper.updateLockScreenShowNotifications();
}
if (uri == null || NOTIFICATION_SOUND_VIB_SCREEN_ON.equals(uri)) {
mSoundVibScreenOn = Settings.System.getIntForUser(resolver,
Settings.System.NOTIFICATION_SOUND_VIB_SCREEN_ON, 1,
UserHandle.USER_CURRENT) == 1;
}
}
}

Expand Down Expand Up @@ -7428,7 +7439,8 @@ int buzzBeepBlinkLocked(NotificationRecord record) {
}

if (aboveThreshold && isNotificationForCurrentUser(record)) {
if (mSystemReady && mAudioManager != null) {
boolean skipSound = mScreenOn && !mSoundVibScreenOn;
if (mSystemReady && mAudioManager != null && !skipSound) {
Uri soundUri = record.getSound();
hasValidSound = soundUri != null && !Uri.EMPTY.equals(soundUri);
VibrationEffect vibration = record.getVibration();
Expand Down

0 comments on commit e430f6e

Please sign in to comment.