Bug 1488434 - Check sTTS is not null before using it. r=jchen
authorEitan Isaacson <eitan@monotonous.org>
Wed, 03 Oct 2018 11:02:00 +0300
changeset 495298 c8b45fb6a89dc3b4189995c0a96990e84868745b
parent 495297 c778ebc41ca773c69bbda50423832a8e03c7d259
child 495299 73a4e7ed19f3447370cbe5fa7b7b30fc1a41710b
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen
bugs1488434
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1488434 - Check sTTS is not null before using it. r=jchen
mobile/android/geckoview/src/main/java/org/mozilla/gecko/SpeechSynthesisService.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/SpeechSynthesisService.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/SpeechSynthesisService.java
@@ -84,32 +84,42 @@ public class SpeechSynthesisService  {
     @WrapForJNI(dispatchTo = "gecko")
     private static native void registerVoice(String uri, String name, String locale, boolean isNetwork, boolean isDefault);
 
     @WrapForJNI(dispatchTo = "gecko")
     private static native void doneRegisteringVoices();
 
     @WrapForJNI(calledFrom = "gecko")
     public static String speak(final String uri, final String text, float rate, float pitch, float volume) {
+        if (sTTS == null) {
+            Log.w(LOGTAG, "TextToSpeech is not initialized");
+            return null;
+        }
+
         HashMap<String, String> params = new HashMap<String, String>();
         final String utteranceId = UUID.randomUUID().toString();
         params.put(TextToSpeech.Engine.KEY_PARAM_VOLUME, Float.toString(volume));
         params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, utteranceId);
         sTTS.setLanguage(new Locale(uri.substring("moz-tts:android:".length())));
         sTTS.setSpeechRate(rate);
         sTTS.setPitch(pitch);
         int result = sTTS.speak(text, TextToSpeech.QUEUE_FLUSH, params);
         if (result != TextToSpeech.SUCCESS) {
             return null;
         }
 
         return utteranceId;
     }
 
     private static void setUtteranceListener() {
+        if (sTTS == null) {
+            Log.w(LOGTAG, "TextToSpeech is not initialized");
+            return;
+        }
+
         sTTS.setOnUtteranceProgressListener(new UtteranceProgressListener() {
             @Override
             public void onDone(String utteranceId) {
                 dispatchEnd(utteranceId);
             }
 
             @Override
             public void onError(String utteranceId) {
@@ -146,16 +156,21 @@ public class SpeechSynthesisService  {
     @WrapForJNI(dispatchTo = "gecko")
     private static native void dispatchError(String utteranceId);
 
     @WrapForJNI(dispatchTo = "gecko")
     private static native void dispatchBoundary(String utteranceId, int start, int end);
 
     @WrapForJNI(calledFrom = "gecko")
     public static void stop() {
+        if (sTTS == null) {
+            Log.w(LOGTAG, "TextToSpeech is not initialized");
+            return;
+        }
+
         sTTS.stop();
         if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
             // Android M has onStop method.  If Android L or above, dispatch
             // event
             dispatchEnd(null);
         }
     }
 }