You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by do...@apache.org on 2019/08/15 12:42:03 UTC
[incubator-weex] branch master updated: [Android] Fix Android Crash
in PostTaskToMsgLoop (#2830)
This is an automated email from the ASF dual-hosted git repository.
dongyayun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-weex.git
The following commit(s) were added to refs/heads/master by this push:
new 16e476e [Android] Fix Android Crash in PostTaskToMsgLoop (#2830)
16e476e is described below
commit 16e476e247c34909d1b27e8a96a7359463430c24
Author: YorkShen <sh...@gmail.com>
AuthorDate: Thu Aug 15 20:41:55 2019 +0800
[Android] Fix Android Crash in PostTaskToMsgLoop (#2830)
* [Android] Fix Android Crash in `EagleBridge::WeexCoreHandler::PostTaskToMsgLoop`
As `WeexCoreManager::Instance()->script_thread()` is initialized in `WeexCore::InitFramework`, `EagleBridge::WeexCoreHandler::PostTaskToMsgLoop` will crash if `WeexCore::InitFramework` is not invoked.
Fix this problem by not supporting `EagleBridge::WeexCoreHandler::PostTaskToMsgLoop` anymore.
```
libweexcore.so (_ZN8WeexCore11EagleBridge15WeexCoreHandler17PostTaskToMsgLoopERKNSt6__ndk18functionIFvvEEE+13)
```
* [Android] Downgrade if JSC is not initialized in eagle mode
* [Android] Add `isJSFrameworkInit` before calling `nativeInvokeOnSuccess`
---
.../com/taobao/weex/bridge/RequestHandler.java | 32 ++++++++++++++++++----
.../com/taobao/weex/bridge/WXBridgeManager.java | 22 +++++++++------
weex_core/Source/core/bridge/eagle_bridge.cpp | 7 +++--
.../network/android/default_request_handler.cc | 4 +++
4 files changed, 48 insertions(+), 17 deletions(-)
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 a3eba20..f49ba9c 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 class RequestHandler {
@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 class RequestHandler {
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 @@ public class RequestHandler {
@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 class RequestHandler {
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 91aba2a..c1a9616 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.Looper;
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.WXWsonJSONSwitch;
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.lang.reflect.Method;
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.CountDownLatch;
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.
* <ol>
@@ -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 class WXBridgeManager implements Callback, BactchExecutor {
// 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 class WXBridgeManager implements Callback, BactchExecutor {
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 61a9356..10ee7a2 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 b12d7bf..ffacaea 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<CallbackWrapper*>(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 {