diff options
author | Narayan Kamath <narayan@google.com> | 2011-11-28 10:36:32 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-11-28 10:36:32 -0800 |
commit | a6f8ebc616cfe3185ae2513ef2f846e8d32b551e (patch) | |
tree | 921c68aa0c4f364caae47cfae315ebc1ccb7ba33 | |
parent | 425c595acb798ed9652b5a1f0e5412cbd8e3873d (diff) | |
parent | 68e2af55d65d2e61fbf8096eccaa2e4ca02b6c5a (diff) | |
download | frameworks_base-a6f8ebc616cfe3185ae2513ef2f846e8d32b551e.zip frameworks_base-a6f8ebc616cfe3185ae2513ef2f846e8d32b551e.tar.gz frameworks_base-a6f8ebc616cfe3185ae2513ef2f846e8d32b551e.tar.bz2 |
Merge "Fix TTS instantiation from webview accessibility handlers." into ics-mr1
-rwxr-xr-x | core/java/android/speech/tts/TextToSpeech.java | 20 | ||||
-rw-r--r-- | core/java/android/speech/tts/TextToSpeechService.java | 6 | ||||
-rw-r--r-- | core/java/android/webkit/WebView.java | 11 |
3 files changed, 31 insertions, 6 deletions
diff --git a/core/java/android/speech/tts/TextToSpeech.java b/core/java/android/speech/tts/TextToSpeech.java index 38699ea..a220615 100755 --- a/core/java/android/speech/tts/TextToSpeech.java +++ b/core/java/android/speech/tts/TextToSpeech.java @@ -490,6 +490,7 @@ public class TextToSpeech { private final Map<String, Uri> mUtterances; private final Bundle mParams = new Bundle(); private final TtsEngines mEnginesHelper; + private final String mPackageName; private volatile String mCurrentEngine = null; /** @@ -518,19 +519,36 @@ public class TextToSpeech { * @param engine Package name of the TTS engine to use. */ public TextToSpeech(Context context, OnInitListener listener, String engine) { + this(context, listener, engine, null); + } + + /** + * Used by the framework to instantiate TextToSpeech objects with a supplied + * package name, instead of using {@link android.content.Context#getPackageName()} + * + * @hide + */ + public TextToSpeech(Context context, OnInitListener listener, String engine, + String packageName) { mContext = context; mInitListener = listener; mRequestedEngine = engine; mEarcons = new HashMap<String, Uri>(); mUtterances = new HashMap<String, Uri>(); + mUtteranceProgressListener = null; mEnginesHelper = new TtsEngines(mContext); + if (packageName != null) { + mPackageName = packageName; + } else { + mPackageName = mContext.getPackageName(); + } initTts(); } private String getPackageName() { - return mContext.getPackageName(); + return mPackageName; } private <R> R runActionNoReconnect(Action<R> action, R errorResult, String method) { diff --git a/core/java/android/speech/tts/TextToSpeechService.java b/core/java/android/speech/tts/TextToSpeechService.java index f82a659..aee678a 100644 --- a/core/java/android/speech/tts/TextToSpeechService.java +++ b/core/java/android/speech/tts/TextToSpeechService.java @@ -450,7 +450,7 @@ public abstract class TextToSpeechService extends Service { @Override public void dispatchOnDone() { final String utteranceId = getUtteranceId(); - if (!TextUtils.isEmpty(utteranceId)) { + if (utteranceId != null) { mCallbacks.dispatchOnDone(getCallingApp(), utteranceId); } } @@ -458,7 +458,7 @@ public abstract class TextToSpeechService extends Service { @Override public void dispatchOnStart() { final String utteranceId = getUtteranceId(); - if (!TextUtils.isEmpty(utteranceId)) { + if (utteranceId != null) { mCallbacks.dispatchOnStart(getCallingApp(), utteranceId); } } @@ -466,7 +466,7 @@ public abstract class TextToSpeechService extends Service { @Override public void dispatchOnError() { final String utteranceId = getUtteranceId(); - if (!TextUtils.isEmpty(utteranceId)) { + if (utteranceId != null) { mCallbacks.dispatchOnError(getCallingApp(), utteranceId); } } diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java index 9c2e6b8..2af6e3b 100644 --- a/core/java/android/webkit/WebView.java +++ b/core/java/android/webkit/WebView.java @@ -1306,8 +1306,15 @@ public class WebView extends AbsoluteLayout if (AccessibilityManager.getInstance(mContext).isEnabled() && getSettings().getJavaScriptEnabled()) { // exposing the TTS for now ... - mTextToSpeech = new TextToSpeech(getContext(), null); - addJavascriptInterface(mTextToSpeech, ALIAS_ACCESSIBILITY_JS_INTERFACE); + final Context ctx = getContext(); + if (ctx != null) { + final String packageName = ctx.getPackageName(); + if (packageName != null) { + mTextToSpeech = new TextToSpeech(getContext(), null, null, + packageName + ".**webview**"); + addJavascriptInterface(mTextToSpeech, ALIAS_ACCESSIBILITY_JS_INTERFACE); + } + } } } |