diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index a60cd35c9af1..e73424532c77 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -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 diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index cbe79fa687d6..0b90bf6d8bce 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -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; @@ -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); @@ -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); } @@ -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; + } } } @@ -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();