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 whyredfire committed Sep 11, 2022
1 parent de425dd commit 67e2c46
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 @@ -5525,6 +5525,14 @@ public static void setShowGTalkServiceStatusForUser(ContentResolver cr, boolean
"lockscreen_scramble_pin_layout";

/**
* Whether 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
* it to PRIVATE_SETTINGS below. Also add a validator that can validate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,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 @@ -1862,6 +1864,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 @@ -1886,6 +1890,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 @@ -1933,6 +1939,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 @@ -7815,7 +7826,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 67e2c46

Please sign in to comment.