FIX 1839556 -- Silent mode not really silent
Fix the dialer to not play touch tone sounds if the phone is in "silent mode".
Note we have to re-check for silent mode *every time* the user presses a
key, rather than just in onResume(), since the user can toggle silent mode
via ENDCALL-longpress (without actually leaving the current activity.)
TESTED:
- "Audible touch tones" preference off: no tones
- "Audible touch tones" preference on, silent mode off: tones play
- "Audible touch tones" preference on, silent mode ON: no tones
- Switch in and out of silent mode via ENDCALL-longpress, confirm change
takes effect immediately.
diff --git a/src/com/android/contacts/TwelveKeyDialer.java b/src/com/android/contacts/TwelveKeyDialer.java
index ea157fc..152ff30 100644
--- a/src/com/android/contacts/TwelveKeyDialer.java
+++ b/src/com/android/contacts/TwelveKeyDialer.java
@@ -688,8 +688,12 @@
};
/**
- * Play a tone for TONE_LENGTH_MS milliseconds.
- *
+ * Plays the specified tone for TONE_LENGTH_MS milliseconds.
+ *
+ * The tone is played locally, using the audio stream for phone calls.
+ * Tones are played only if the "Audible touch tones" user preference
+ * is checked, and are NOT played if the device is in silent mode.
+ *
* @param tone a tone code from {@link ToneGenerator}
*/
void playTone(int tone) {
@@ -697,7 +701,17 @@
if (!mDTMFToneEnabled) {
return;
}
-
+
+ // Also do nothing if the phone is in silent mode.
+ // We need to re-check the ringer mode for *every* playTone()
+ // call, rather than keeping a local flag that's updated in
+ // onResume(), since it's possible to toggle silent mode without
+ // leaving the current activity (via the ENDCALL-longpress menu.)
+ AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
+ if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
+ return;
+ }
+
synchronized(mToneGeneratorLock) {
if (mToneGenerator == null) {
Log.w(TAG, "playTone: mToneGenerator == null, tone: "+tone);