From 1b33dbe2aeae8882a2cc85c566ffb5e6c844c249 Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Thu, 16 Aug 2012 17:21:30 -0400 Subject: [PATCH] Provide an addJavascriptInterface() exec object. -Disabled for 2.3 emulator to avoid a crash bug. --- .../src/org/apache/cordova/CordovaWebView.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java index 03d916e1..85c3cd82 100755 --- a/framework/src/org/apache/cordova/CordovaWebView.java +++ b/framework/src/org/apache/cordova/CordovaWebView.java @@ -30,6 +30,7 @@ import java.util.regex.Pattern; import org.apache.cordova.api.CordovaInterface; import org.apache.cordova.api.LOG; import org.apache.cordova.api.PluginManager; +import org.json.JSONException; import org.xmlpull.v1.XmlPullParserException; import android.annotation.SuppressLint; @@ -38,6 +39,7 @@ import android.content.Context; import android.content.Intent; import android.content.res.XmlResourceParser; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.util.AttributeSet; import android.util.Log; @@ -232,6 +234,21 @@ public class CordovaWebView extends WebView { // TODO Auto-generated catch block e.printStackTrace(); } + exposeJsInterface(); + } + + private void exposeJsInterface() { + // addJavascriptInterface crashes on the 2.3 emulator. + if (Build.VERSION.RELEASE.startsWith("2.3") && Build.MANUFACTURER.equals("unknown")) { + Log.i(TAG, "Disabled addJavascriptInterface() bridge callback due to a bug on the 2.3 emulator"); + return; + } + this.addJavascriptInterface(new Object() { + @SuppressWarnings("unused") + public String exec(String service, String action, String callbackId, String arguments) throws JSONException { + return pluginManager.exec(service, action, callbackId, arguments, true /* async */); + } + }, "_cordovaExec"); } /**