summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Yu <jackyu@google.com>2015-10-16 21:19:52 -0700
committerJack Yu <jackyu@google.com>2015-10-16 21:19:52 -0700
commit3d91c54e6649ec46ddd728079702aba2f0ae96b8 (patch)
tree29c62de1a663696ed2b302ddaa6641dd78ce7546
parent170b39b30ef6340a99fde0e1e6a46cf935e4cde6 (diff)
downloadandroid_packages_apps_CellBroadcastReceiver-3d91c54e6649ec46ddd728079702aba2f0ae96b8.tar.gz
android_packages_apps_CellBroadcastReceiver-3d91c54e6649ec46ddd728079702aba2f0ae96b8.tar.bz2
android_packages_apps_CellBroadcastReceiver-3d91c54e6649ec46ddd728079702aba2f0ae96b8.zip
DO NOT MERGE. Fixed emergency alert TTS not playing on bluetooth speaker.
Added an extra param so TTS engine knows where to route the audio. Also release the audio focus at the time after tone + TTS are played, not just tone so TTS won't mix with other audio stream (e.g. music) bug: 24366038 Change-Id: I8f045f9264ea49d00125a53f3180c9924b02b08c
-rw-r--r--src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java
index 6a70079c..2381689f 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertAudio.java
@@ -122,6 +122,9 @@ public class CellBroadcastAlertAudio extends Service implements TextToSpeech.OnI
PAUSE_DURATION_BEFORE_SPEAKING_MSEC);
mState = STATE_PAUSING;
} else {
+ if (DBG) log("MessageEmpty = " + (mMessageBody == null) +
+ ", mTtsEngineReady = " + mTtsEngineReady +
+ ", mTtsLanguageSupported = " + mTtsLanguageSupported);
stopSelf();
mState = STATE_IDLE;
}
@@ -135,6 +138,10 @@ public class CellBroadcastAlertAudio extends Service implements TextToSpeech.OnI
HashMap<String, String> ttsHashMap = new HashMap<String, String>();
ttsHashMap.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,
TTS_UTTERANCE_ID);
+ // Play TTS on notification stream.
+ ttsHashMap.put(TextToSpeech.Engine.KEY_PARAM_STREAM,
+ Integer.toString(AudioManager.STREAM_NOTIFICATION));
+
res = mTts.speak(mMessageBody, TextToSpeech.QUEUE_FLUSH, ttsHashMap);
mState = STATE_SPEAKING;
}
@@ -206,7 +213,11 @@ public class CellBroadcastAlertAudio extends Service implements TextToSpeech.OnI
@Override
public void onUtteranceCompleted(String utteranceId) {
if (utteranceId.equals(TTS_UTTERANCE_ID)) {
- stopSelf();
+ // When we reach here, it could be TTS completed or TTS was cut due to another
+ // new alert started playing. We don't want to stop the service in the later case.
+ if (mState == STATE_SPEAKING) {
+ stopSelf();
+ }
}
}
@@ -236,6 +247,14 @@ public class CellBroadcastAlertAudio extends Service implements TextToSpeech.OnI
loge("exception trying to shutdown text-to-speech");
}
}
+
+ if (mEnableAudio) {
+ // Release the audio focus so other audio (e.g. music) can resume.
+ // Do not do this in stop() because stop() is also called when we stop the tone (before
+ // TTS is playing). We only want to release the focus when tone and TTS are played.
+ mAudioManager.abandonAudioFocus(null);
+ }
+
// release CPU wake lock acquired by CellBroadcastAlertService
CellBroadcastAlertWakeLock.releaseCpuLock();
}
@@ -435,7 +454,7 @@ public class CellBroadcastAlertAudio extends Service implements TextToSpeech.OnI
loge("exception trying to stop text-to-speech");
}
}
- mAudioManager.abandonAudioFocus(null);
+
mState = STATE_IDLE;
}