From 852a203646a2c996ddcff069f4332a44fb040b30 Mon Sep 17 00:00:00 2001 From: Lais Andrade Date: Tue, 20 Apr 2021 18:13:12 +0000 Subject: [PATCH] Create a new config for attentional haptics OGG resource Create a new hidden config with the URI of a OGG file that has only the haptics channels and can be played for attentional haptics when sound is muted (ringtone, notifications, alarms). First usage introduced is to the Telecom project to be played on RINGER_MODE_VIBRATE. Also update Ringtone class to allow playback of haptic-only ringtones (i.e. ringtones with unmutted haptic channels and volume set to zero on devices with audio-coupled haptics support). Bug: 182157749 Test: manual Change-Id: Ic64d8d56c6b029e32b3d55389c416cee7679ddc8 --- core/res/res/values/config.xml | 3 +++ core/res/res/values/public.xml | 2 ++ media/java/android/media/Ringtone.java | 8 +++++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index c2a7e079b1f9f..6c55a342b279b 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -3898,6 +3898,9 @@ /product/media/audio/ui/InCallNotification.ogg + + /product/media/audio/ui/AttentionalHaptics.ogg + 4 diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml index c716000742178..513dfcb11b241 100644 --- a/core/res/res/values/public.xml +++ b/core/res/res/values/public.xml @@ -3230,6 +3230,8 @@ + + diff --git a/media/java/android/media/Ringtone.java b/media/java/android/media/Ringtone.java index 79d505ebbde88..f8297bc93b727 100644 --- a/media/java/android/media/Ringtone.java +++ b/media/java/android/media/Ringtone.java @@ -405,9 +405,11 @@ public class Ringtone { */ public void play() { if (mLocalPlayer != null) { - // do not play ringtones if stream volume is 0 - // (typically because ringer mode is silent). - if (mAudioManager.getStreamVolume( + // Play ringtones if stream volume is over 0 or if it is a haptic-only ringtone + // (typically because ringer mode is vibrate). + boolean isHapticOnly = AudioManager.hasHapticChannels(mUri) + && !mAudioAttributes.areHapticChannelsMuted() && mVolume == 0; + if (isHapticOnly || mAudioManager.getStreamVolume( AudioAttributes.toLegacyStreamType(mAudioAttributes)) != 0) { startLocalPlayer(); }