Merge "Fix TTS instantiation from webview accessibility handlers." into ics-mr1
This commit is contained in:
committed by
Android (Google) Code Review
commit
a6f8ebc616
@@ -490,6 +490,7 @@ public class TextToSpeech {
|
|||||||
private final Map<String, Uri> mUtterances;
|
private final Map<String, Uri> mUtterances;
|
||||||
private final Bundle mParams = new Bundle();
|
private final Bundle mParams = new Bundle();
|
||||||
private final TtsEngines mEnginesHelper;
|
private final TtsEngines mEnginesHelper;
|
||||||
|
private final String mPackageName;
|
||||||
private volatile String mCurrentEngine = null;
|
private volatile String mCurrentEngine = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -518,19 +519,36 @@ public class TextToSpeech {
|
|||||||
* @param engine Package name of the TTS engine to use.
|
* @param engine Package name of the TTS engine to use.
|
||||||
*/
|
*/
|
||||||
public TextToSpeech(Context context, OnInitListener listener, String engine) {
|
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;
|
mContext = context;
|
||||||
mInitListener = listener;
|
mInitListener = listener;
|
||||||
mRequestedEngine = engine;
|
mRequestedEngine = engine;
|
||||||
|
|
||||||
mEarcons = new HashMap<String, Uri>();
|
mEarcons = new HashMap<String, Uri>();
|
||||||
mUtterances = new HashMap<String, Uri>();
|
mUtterances = new HashMap<String, Uri>();
|
||||||
|
mUtteranceProgressListener = null;
|
||||||
|
|
||||||
mEnginesHelper = new TtsEngines(mContext);
|
mEnginesHelper = new TtsEngines(mContext);
|
||||||
|
if (packageName != null) {
|
||||||
|
mPackageName = packageName;
|
||||||
|
} else {
|
||||||
|
mPackageName = mContext.getPackageName();
|
||||||
|
}
|
||||||
initTts();
|
initTts();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPackageName() {
|
private String getPackageName() {
|
||||||
return mContext.getPackageName();
|
return mPackageName;
|
||||||
}
|
}
|
||||||
|
|
||||||
private <R> R runActionNoReconnect(Action<R> action, R errorResult, String method) {
|
private <R> R runActionNoReconnect(Action<R> action, R errorResult, String method) {
|
||||||
|
|||||||
@@ -450,7 +450,7 @@ public abstract class TextToSpeechService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
public void dispatchOnDone() {
|
public void dispatchOnDone() {
|
||||||
final String utteranceId = getUtteranceId();
|
final String utteranceId = getUtteranceId();
|
||||||
if (!TextUtils.isEmpty(utteranceId)) {
|
if (utteranceId != null) {
|
||||||
mCallbacks.dispatchOnDone(getCallingApp(), utteranceId);
|
mCallbacks.dispatchOnDone(getCallingApp(), utteranceId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -458,7 +458,7 @@ public abstract class TextToSpeechService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
public void dispatchOnStart() {
|
public void dispatchOnStart() {
|
||||||
final String utteranceId = getUtteranceId();
|
final String utteranceId = getUtteranceId();
|
||||||
if (!TextUtils.isEmpty(utteranceId)) {
|
if (utteranceId != null) {
|
||||||
mCallbacks.dispatchOnStart(getCallingApp(), utteranceId);
|
mCallbacks.dispatchOnStart(getCallingApp(), utteranceId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -466,7 +466,7 @@ public abstract class TextToSpeechService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
public void dispatchOnError() {
|
public void dispatchOnError() {
|
||||||
final String utteranceId = getUtteranceId();
|
final String utteranceId = getUtteranceId();
|
||||||
if (!TextUtils.isEmpty(utteranceId)) {
|
if (utteranceId != null) {
|
||||||
mCallbacks.dispatchOnError(getCallingApp(), utteranceId);
|
mCallbacks.dispatchOnError(getCallingApp(), utteranceId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1306,8 +1306,15 @@ public class WebView extends AbsoluteLayout
|
|||||||
if (AccessibilityManager.getInstance(mContext).isEnabled()
|
if (AccessibilityManager.getInstance(mContext).isEnabled()
|
||||||
&& getSettings().getJavaScriptEnabled()) {
|
&& getSettings().getJavaScriptEnabled()) {
|
||||||
// exposing the TTS for now ...
|
// exposing the TTS for now ...
|
||||||
mTextToSpeech = new TextToSpeech(getContext(), null);
|
final Context ctx = getContext();
|
||||||
addJavascriptInterface(mTextToSpeech, ALIAS_ACCESSIBILITY_JS_INTERFACE);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user