diff --git a/android/sdk/src/main/java/com/taobao/weex/bridge/RequestHandler.java b/android/sdk/src/main/java/com/taobao/weex/bridge/RequestHandler.java index a3eba20387..f49ba9cb58 100644 --- a/android/sdk/src/main/java/com/taobao/weex/bridge/RequestHandler.java +++ b/android/sdk/src/main/java/com/taobao/weex/bridge/RequestHandler.java @@ -86,9 +86,9 @@ public void send(String instanceId, String url, long nativeCallback) { @Keep @CalledByNative - public void getBundleType(String instanceId, String content, long nativeCallback){ + public void getBundleType(String instanceId, final String content, final long nativeCallback){ BundType bundleType = WXBridgeManager.getInstance().getBundleType("", content); - String bundleTypeStr = bundleType == null ? "Others" : bundleType.toString(); + final String bundleTypeStr = bundleType == null ? "Others" : bundleType.toString(); WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId); if ("Others".equalsIgnoreCase(bundleTypeStr) && null != instance){ WXExceptionUtils.commitCriticalExceptionRT( @@ -99,7 +99,17 @@ public void getBundleType(String instanceId, String content, long nativeCallback null ); } - nativeInvokeOnSuccess(nativeCallback, content, bundleTypeStr); + WXBridgeManager.getInstance().post(new Runnable() { + @Override + public void run() { + if(WXBridgeManager.getInstance().isJSFrameworkInit()) { + nativeInvokeOnSuccess(nativeCallback, content, bundleTypeStr); + } + else { + nativeInvokeOnFailed(nativeCallback); + } + } + }); } class OnHttpListenerInner extends WXHttpListener { @@ -112,9 +122,9 @@ class OnHttpListenerInner extends WXHttpListener { @Override public void onSuccess(WXResponse response) { - String script = new String(response.originalData); + final String script = new String(response.originalData); BundType bundleType = WXBridgeManager.getInstance().getBundleType("", script); - String bundleTypeStr = bundleType == null ? "Others" : bundleType.toString(); + final String bundleTypeStr = bundleType == null ? "Others" : bundleType.toString(); if ("Others".equalsIgnoreCase(bundleTypeStr) && null != getInstance()){ WXExceptionUtils.commitCriticalExceptionRT( getInstance().getInstanceId(), @@ -124,7 +134,17 @@ public void onSuccess(WXResponse response) { null ); } - nativeInvokeOnSuccess(sNativeCallback, script, bundleTypeStr); + WXBridgeManager.getInstance().post(new Runnable() { + @Override + public void run() { + if(WXBridgeManager.getInstance().isJSFrameworkInit()) { + nativeInvokeOnSuccess(sNativeCallback, script, bundleTypeStr); + } + else{ + nativeInvokeOnFailed(sNativeCallback); + } + } + }); } @Override diff --git a/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridgeManager.java b/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridgeManager.java index 91aba2a267..c1a9616451 100755 --- a/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridgeManager.java +++ b/android/sdk/src/main/java/com/taobao/weex/bridge/WXBridgeManager.java @@ -18,6 +18,8 @@ */ package com.taobao.weex.bridge; +import static com.taobao.weex.bridge.WXModuleManager.createDomModule; + import android.content.Context; import android.net.Uri; import android.os.Build; @@ -27,12 +29,13 @@ import android.os.Message; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.RestrictTo; +import android.support.annotation.RestrictTo.Scope; import android.support.annotation.UiThread; import android.support.v4.util.ArrayMap; import android.text.TextUtils; import android.util.Log; import android.util.Pair; - import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @@ -96,8 +99,6 @@ import com.taobao.weex.utils.batch.BactchExecutor; import com.taobao.weex.utils.batch.Interceptor; import com.taobao.weex.utils.tools.LogDetail; -import com.taobao.weex.utils.tools.TimeCalculator; - import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -109,7 +110,6 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.HashSet; @@ -122,8 +122,6 @@ import java.util.concurrent.TimeUnit; import java.util.regex.Pattern; -import static com.taobao.weex.bridge.WXModuleManager.createDomModule; - /** * Manager class for communication between JavaScript and Android. *
    @@ -152,6 +150,8 @@ public class WXBridgeManager implements Callback, BactchExecutor { public static final String METHOD_CREATE_INSTANCE = "createInstance"; public static final String METHOD_CREATE_PAGE_WITH_CONTENT = "CreatePageWithContent"; public static final String METHOD_UPDATE_COMPONENT_WITH_DATA = "UpdateComponentData"; + private static final String METHOD_POST_TASK_TO_MSG_LOOP = "PostTaskToMsgLoop"; + private static final String METHOD_JSFM_NOT_INIT_IN_EAGLE_MODE = "JsfmNotInitInEagleMode"; public static final String METHOD_DESTROY_INSTANCE = "destroyInstance"; public static final String METHOD_CALL_JS = "callJS"; public static final String METHOD_SET_TIMEOUT = "setTimeoutCallback"; @@ -369,7 +369,8 @@ public void run() { // setJSFrameworkInit and isJSFrameworkInit may use on diff thread // use volatile - private boolean isJSFrameworkInit() { + @RestrictTo(Scope.LIBRARY) + boolean isJSFrameworkInit() { return mInit; } @@ -2552,7 +2553,12 @@ public void reportJSException(String instanceId, String function, reportErrorCode = WXErrorCode.WX_RENDER_ERR_JS_CREATE_INSTANCE; } else if ( METHOD_CREATE_INSTANCE_CONTEXT.equals(function) && !instance.getApmForInstance().hasAddView){ reportErrorCode = WXErrorCode.WX_RENDER_ERR_JS_CREATE_INSTANCE_CONTEXT; - } else if ((METHOD_UPDATE_COMPONENT_WITH_DATA.equals(function) || METHOD_CREATE_PAGE_WITH_CONTENT.equals(function)) && !instance.getApmForInstance().hasAddView){ + } else if ( + (METHOD_UPDATE_COMPONENT_WITH_DATA.equals(function) || + METHOD_CREATE_PAGE_WITH_CONTENT.equals(function) || + METHOD_POST_TASK_TO_MSG_LOOP.equals(function) || + METHOD_JSFM_NOT_INIT_IN_EAGLE_MODE.equals(function) ) + && !instance.getApmForInstance().hasAddView){ reportErrorCode = WXErrorCode.WX_DEGRAD_EAGLE_RENDER_ERROR; } instance.onJSException(reportErrorCode.getErrorCode(), function, exception); diff --git a/weex_core/Source/core/bridge/eagle_bridge.cpp b/weex_core/Source/core/bridge/eagle_bridge.cpp index 61a9356b7b..10ee7a2810 100644 --- a/weex_core/Source/core/bridge/eagle_bridge.cpp +++ b/weex_core/Source/core/bridge/eagle_bridge.cpp @@ -249,10 +249,11 @@ namespace WeexCore { ); } + //FIXME Please don't call this method, which will cause downgrade of Weex. void EagleBridge::WeexCoreHandler::PostTaskToMsgLoop(const weex::base::Closure& closure){ -#ifdef OS_ANDROID - WeexCoreManager::Instance()->script_thread()->message_loop()->PostTask(closure); -#endif + WeexCore::WeexCoreManager::Instance()->getPlatformBridge()->platform_side()->ReportException( + "", "PostTaskToMsgLoop", + "PostTaskToMsgLoop is not supported anymore, please update to the latest version of Weex."); } int EagleBridge::DataRenderHandler::DestroyInstance(const char *instanceId) { diff --git a/weex_core/Source/core/network/android/default_request_handler.cc b/weex_core/Source/core/network/android/default_request_handler.cc index b12d7bfc44..ffacaea1fd 100644 --- a/weex_core/Source/core/network/android/default_request_handler.cc +++ b/weex_core/Source/core/network/android/default_request_handler.cc @@ -23,6 +23,7 @@ #include "android/base/string/scoped_jstring_utf8.h" #include "base/android/jniprebuild/jniheader/RequestHandler_jni.h" #include "base/android/jni/android_jni.h" +#include "core/manager/weex_core_manager.h" using namespace weex::core::network; @@ -44,6 +45,9 @@ static void InvokeOnFailed(JNIEnv* env, jobject jcaller, jlong callback) { CallbackWrapper* callback_wrapper = reinterpret_cast(callback); delete callback_wrapper; + WeexCore::WeexCoreManager::Instance()->getPlatformBridge()->platform_side()->ReportException( + "", "JsfmNotInitInEagleMode", + "JSFramework is not initialized when executing bundle JS in eagle mode"); } namespace weex {