Skip to content
This repository was archived by the owner on Jun 3, 2021. It is now read-only.

Degrade to h5 if can not reload this page #2438

Merged
merged 1 commit into from
May 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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