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

Commit

Permalink
do not let same crash page reload again on short time
Browse files Browse the repository at this point in the history
  • Loading branch information
御魂 authored and yuhun-alibaba committed Sep 14, 2017
1 parent 595ded4 commit de67bd8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 20 deletions.
26 changes: 14 additions & 12 deletions android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java
Expand Up @@ -606,21 +606,23 @@ private String assembleFilePath(Uri uri) {
return "";
}

public void reloadPage() {
public void reloadPage(boolean reloadThis) {

WXSDKEngine.reload();

// 可以发送广播吗?
if (mContext != null) {
Intent intent = new Intent();
intent.setAction(IWXDebugProxy.ACTION_INSTANCE_RELOAD);
intent.putExtra("url", mBundleUrl);
mContext.sendBroadcast(intent);
if (reloadThis) {
// 可以发送广播吗?
if (mContext != null) {
Intent intent = new Intent();
intent.setAction(IWXDebugProxy.ACTION_INSTANCE_RELOAD);
intent.putExtra("url", mBundleUrl);
mContext.sendBroadcast(intent);
}
// mRendered = false;
// destroy();
// renderInternal(mPackage, mTemplate, mOptions, mJsonInitData, mFlag);
// refreshInstance("{}");
}
// mRendered = false;
// destroy();
// renderInternal(mPackage, mTemplate, mOptions, mJsonInitData, mFlag);
// refreshInstance("{}");

}
/**
* Refresh instance asynchronously.
Expand Down
Expand Up @@ -135,6 +135,9 @@ public class WXBridgeManager implements Callback,BactchExecutor {
private static final int CRASHREINIT = 50;
private static int reInitCount = 1;

private static String crashUrl = null;
private static long lastCrashTime = 0;


/**
* next tick tasks, can set priority
Expand Down Expand Up @@ -962,19 +965,35 @@ public int callReportCrashReloadPage(String instanceId, String crashFile) {
WXLogUtils.e("[WXBridgeManager] callReportCrashReloadPage exception: ", e);
}
try {

if (WXSDKManager.getInstance().getSDKInstance(instanceId) != null) {
// JSONObject domObject = JSON.parseObject(tasks);
boolean reloadThisInstance = shouReloadCurrentInstance(
WXSDKManager.getInstance().getSDKInstance(instanceId).getBundleUrl());
WXDomModule domModule = getDomModule(instanceId);
Action action = Actions.getReloadPage(instanceId);
domModule.postAction((DOMAction)action, true);
Action action = Actions.getReloadPage(instanceId, reloadThisInstance);
domModule.postAction((DOMAction) action, true);
}

} catch (Exception e) {
WXLogUtils.e("[WXBridgeManager] callReloadPage exception: ", e);
commitJSBridgeAlarmMonitor(instanceId, WXErrorCode.WX_ERR_RELOAD_PAGE,"[WXBridgeManager] callReloadPage exception "+e.getCause());
}
return IWXBridge.INSTANCE_RENDERING_ERROR;
}

public boolean shouReloadCurrentInstance(String aUrl) {
long time = System.currentTimeMillis();
if (crashUrl == null ||
(crashUrl != null && !crashUrl.equals(aUrl)) ||
((time - lastCrashTime) > 10000)) {
crashUrl = aUrl;
lastCrashTime = time;
return true;
}
lastCrashTime = time;
return false;
}

public void callReportCrash(String crashFile, final String instanceId, final String url) {
// statistic weexjsc process crash
Date date = new Date();
Expand Down Expand Up @@ -1809,7 +1828,7 @@ public void reportJSException(String instanceId, String function,
if (reInitCount > 1 && !instance.isNeedReLoad()) {
// JSONObject domObject = JSON.parseObject(tasks);
WXDomModule domModule = getDomModule(instanceId);
Action action = Actions.getReloadPage(instanceId);
Action action = Actions.getReloadPage(instanceId, true);
domModule.postAction((DOMAction)action, true);
instance.setNeedLoad(true);
return;
Expand Down
Expand Up @@ -225,7 +225,7 @@ public static DOMAction getExecutableRenderAction(@NonNull Runnable runnable) {
return new ExecutableRenderAction(runnable);
}

public static DOMAction getReloadPage(String instanceId) {
return new ReloadPageAction(instanceId);
public static DOMAction getReloadPage(String instanceId, boolean relaod) {
return new ReloadPageAction(instanceId, relaod);
}
}
Expand Up @@ -36,9 +36,11 @@
final class ReloadPageAction implements DOMAction, RenderAction {
private final String TAG = "ReloadPageAction";
private String mInstanceId;
private boolean mReloadThis;

ReloadPageAction(String instanceId) {
ReloadPageAction(String instanceId, boolean reloadThis) {
mInstanceId = instanceId;
mReloadThis = reloadThis;
}

@Override
Expand All @@ -51,7 +53,7 @@ public void executeDom(DOMActionContext context) {
WXSDKInstance instance = context.getInstance();
if (instance != null) {
// instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS);
instance.reloadPage();
instance.reloadPage(mReloadThis);
} else {
Log.e(TAG, "ReloadPageAction executeDom reloadPage instance is null");
}
Expand Down

0 comments on commit de67bd8

Please sign in to comment.