diff options
author | Niels Egberts <nielse@google.com> | 2015-06-26 16:00:43 +0100 |
---|---|---|
committer | Niels Egberts <nielse@google.com> | 2015-06-26 16:25:37 +0100 |
commit | 992ea1553c3ae6766505f084061c5ef2321229b7 (patch) | |
tree | f5003e3afc3b8ca1ba64555517d13f627d4b7580 /core/java/android/speech | |
parent | a2e0dc4d20be14ea106b44067cc782774d90df3b (diff) | |
download | frameworks_base-992ea1553c3ae6766505f084061c5ef2321229b7.zip frameworks_base-992ea1553c3ae6766505f084061c5ef2321229b7.tar.gz frameworks_base-992ea1553c3ae6766505f084061c5ef2321229b7.tar.bz2 |
Fix crash with engines that don't override getVoices().
The name of the voices was not normalized in getVoices(), therefore if
you use getDefaultVoiceName, that name possibly doesn't appear in
getVoices(). The framework would then run into a NullPointerException.
This was caught by the cts tests. Also added a few more log statements.
BUG: 22115315
Change-Id: I51404ddcd1bc10dd3e1ddaac410cfa9873bf1438
Diffstat (limited to 'core/java/android/speech')
-rw-r--r-- | core/java/android/speech/tts/TextToSpeech.java | 15 | ||||
-rw-r--r-- | core/java/android/speech/tts/TextToSpeechService.java | 4 |
2 files changed, 16 insertions, 3 deletions
diff --git a/core/java/android/speech/tts/TextToSpeech.java b/core/java/android/speech/tts/TextToSpeech.java index 3eeb04a..eae4329 100644 --- a/core/java/android/speech/tts/TextToSpeech.java +++ b/core/java/android/speech/tts/TextToSpeech.java @@ -1486,19 +1486,28 @@ public class TextToSpeech { // Get the default voice for the locale. String voiceName = service.getDefaultVoiceNameFor(language, country, variant); if (TextUtils.isEmpty(voiceName)) { - Log.w(TAG, "Couldn't find the default voice for " + language + "/" + - country + "/" + variant); + Log.w(TAG, "Couldn't find the default voice for " + language + "-" + + country + "-" + variant); return LANG_NOT_SUPPORTED; } // Load it. if (service.loadVoice(getCallerIdentity(), voiceName) == TextToSpeech.ERROR) { + Log.w(TAG, "The service claimed " + language + "-" + country + "-" + + variant + " was available with voice name " + voiceName + + " but loadVoice returned ERROR"); return LANG_NOT_SUPPORTED; } // Set the language/country/variant of the voice, so #getLanguage will return // the currently set voice locale when called. Voice voice = getVoice(service, voiceName); + if (voice == null) { + Log.w(TAG, "getDefaultVoiceNameFor returned " + voiceName + " for locale " + + language + "-" + country + "-" + variant + + " but getVoice returns null"); + return LANG_NOT_SUPPORTED; + } String voiceLanguage = ""; try { voiceLanguage = voice.getLocale().getISO3Language(); @@ -1682,6 +1691,7 @@ public class TextToSpeech { private Voice getVoice(ITextToSpeechService service, String voiceName) throws RemoteException { List<Voice> voices = service.getVoices(); if (voices == null) { + Log.w(TAG, "getVoices returned null"); return null; } for (Voice voice : voices) { @@ -1689,6 +1699,7 @@ public class TextToSpeech { return voice; } } + Log.w(TAG, "Could not find voice " + voiceName + " in voice list"); return null; } diff --git a/core/java/android/speech/tts/TextToSpeechService.java b/core/java/android/speech/tts/TextToSpeechService.java index ba98f27..fa015b2 100644 --- a/core/java/android/speech/tts/TextToSpeechService.java +++ b/core/java/android/speech/tts/TextToSpeechService.java @@ -293,7 +293,9 @@ public abstract class TextToSpeechService extends Service { } Set<String> features = onGetFeaturesForLanguage(locale.getISO3Language(), locale.getISO3Country(), locale.getVariant()); - voices.add(new Voice(locale.toLanguageTag(), locale, Voice.QUALITY_NORMAL, + String voiceName = onGetDefaultVoiceNameFor(locale.getISO3Language(), + locale.getISO3Country(), locale.getVariant()); + voices.add(new Voice(voiceName, locale, Voice.QUALITY_NORMAL, Voice.LATENCY_NORMAL, false, features)); } return voices; |