Skip to content

Commit

Permalink
Degrade to h5 if can not reload this page (apache#2438)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darin726 authored and 东煜 committed May 15, 2019
1 parent 21e7ba4 commit f728a51
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
13 changes: 13 additions & 0 deletions android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package com.taobao.weex;

import static com.taobao.weex.common.WXErrorCode.WX_ERR_JSC_CRASH;
import static com.taobao.weex.common.WXErrorCode.WX_ERR_RELOAD_PAGE;
import static com.taobao.weex.http.WXHttpUtil.KEY_USER_AGENT;

Expand Down Expand Up @@ -912,6 +913,18 @@ public void reloadPage(boolean reloadThis) {
// destroy();
// renderInternal(mPackage, mTemplate, mOptions, mJsonInitData, mFlag);
// refreshInstance("{}");
} else {
IWXConfigAdapter adapter = WXSDKManager.getInstance().getWxConfigAdapter();
if (adapter != null) {
boolean degrade = Boolean.parseBoolean(adapter
.getConfig("android_weex_ext_config",
"degrade_to_h5_if_not_reload",
"true"));
WXLogUtils.e("degrade : " + degrade);
if(degrade) {
onJSException(String.valueOf(WX_ERR_JSC_CRASH.getErrorCode()),"jsc Crashed", "jsc Crashed degradeToH5");
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.taobao.weex.WXSDKEngine;
import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.WXSDKManager;
import com.taobao.weex.adapter.IWXConfigAdapter;
import com.taobao.weex.adapter.IWXJSExceptionAdapter;
import com.taobao.weex.adapter.IWXJsFileLoaderAdapter;
import com.taobao.weex.adapter.IWXJscProcessManager;
Expand Down Expand Up @@ -872,7 +873,7 @@ public int callReportCrashReloadPage(String instanceId, String crashFile) {
try {

if (WXSDKManager.getInstance().getSDKInstance(instanceId) != null) {
boolean reloadThisInstance = shouReloadCurrentInstance(
boolean reloadThisInstance = shouldReloadCurrentInstance(
WXSDKManager.getInstance().getSDKInstance(instanceId).getBundleUrl());
new ActionReloadPage(instanceId, reloadThisInstance).executeAction();
}
Expand All @@ -886,12 +887,28 @@ public int callReportCrashReloadPage(String instanceId, String crashFile) {
return IWXBridge.INSTANCE_RENDERING_ERROR;
}

public boolean shouReloadCurrentInstance(String aUrl) {
public boolean shouldReloadCurrentInstance(String aUrl) {
long time = System.currentTimeMillis();
String bizUrl = aUrl;
IWXConfigAdapter adapter = WXSDKManager.getInstance().getWxConfigAdapter();
if (adapter != null) {
boolean check_biz_url = Boolean.parseBoolean(adapter
.getConfig("android_weex_ext_config",
"check_biz_url",
"true"));
WXLogUtils.e("check_biz_url : " + check_biz_url);
if(check_biz_url && !TextUtils.isEmpty(aUrl)) {
Uri uri = Uri.parse(aUrl);
if(uri != null) {
bizUrl = uri.buildUpon().clearQuery().build().toString();
}
}
}

if (crashUrl == null ||
(crashUrl != null && !crashUrl.equals(aUrl)) ||
(crashUrl != null && !crashUrl.equals(bizUrl)) ||
((time - lastCrashTime) > 15000)) {
crashUrl = aUrl;
crashUrl = bizUrl;
lastCrashTime = time;
return true;
}
Expand Down

0 comments on commit f728a51

Please sign in to comment.