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

Commit

Permalink
*[Android] add jsc adapter to control jsc process reboot
Browse files Browse the repository at this point in the history
  • Loading branch information
Darin726 authored and YorkShen committed Nov 28, 2018
1 parent d303509 commit 4eef29d
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 30 deletions.
17 changes: 17 additions & 0 deletions android/sdk/src/main/java/com/taobao/weex/InitConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.taobao.weex.adapter.ClassLoaderAdapter;
import com.taobao.weex.adapter.IDrawableLoader;
import com.taobao.weex.adapter.IWXJscProcessManager;
import com.taobao.weex.adapter.IWXHttpAdapter;
import com.taobao.weex.adapter.IWXImgLoaderAdapter;
import com.taobao.weex.adapter.IWXJSExceptionAdapter;
Expand Down Expand Up @@ -48,6 +49,7 @@ public class InitConfig {
private ClassLoaderAdapter classLoaderAdapter;
private IApmGenerator apmGenerater;
private IWXJsFileLoaderAdapter jsFileLoaderAdapter;
private IWXJscProcessManager jscProcessManager;

public IWXHttpAdapter getHttpAdapter() {
return httpAdapter;
Expand Down Expand Up @@ -105,6 +107,9 @@ public InitConfig setClassLoaderAdapter(ClassLoaderAdapter classLoaderAdapter) {
public IWXJSExceptionAdapter getJSExceptionAdapter() {
return mJSExceptionAdapter;
}
public IWXJscProcessManager getJscProcessManager() {
return jscProcessManager;
}

private InitConfig() {
}
Expand All @@ -124,6 +129,17 @@ public static class Builder{
IApmGenerator apmGenerater;
private IWXJsFileLoaderAdapter jsFileLoaderAdapter;

public IWXJscProcessManager getJscProcessManager() {
return jscProcessManager;
}

public Builder setJscProcessManager(IWXJscProcessManager jscProcessManager) {
this.jscProcessManager = jscProcessManager;
return this;
}

IWXJscProcessManager jscProcessManager;

public Builder(){

}
Expand Down Expand Up @@ -208,6 +224,7 @@ public InitConfig build(){
config.classLoaderAdapter = this.classLoaderAdapter;
config.apmGenerater = this.apmGenerater;
config.jsFileLoaderAdapter = this.jsFileLoaderAdapter;
config.jscProcessManager = this.jscProcessManager;
return config;
}
}
Expand Down
22 changes: 11 additions & 11 deletions android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

import com.alibaba.fastjson.JSONObject;
import com.taobao.weex.adapter.IDrawableLoader;
import com.taobao.weex.adapter.IWXJscProcessManager;
import com.taobao.weex.adapter.IWXHttpAdapter;
import com.taobao.weex.adapter.IWXImgLoaderAdapter;
import com.taobao.weex.adapter.IWXUserTrackAdapter;
Expand Down Expand Up @@ -447,7 +448,13 @@ public final WXSDKInstance createNestedInstance(NestedContainer container){
protected WXSDKInstance newNestedInstance() {
return new WXSDKInstance(mContext);
}
public boolean isHasException() {
return hasException;
}

public void setHasException(boolean hasException) {
this.hasException = hasException;
}
public void addOnInstanceVisibleListener(OnInstanceVisibleListener l){
mVisibleListeners.add(l);
}
Expand Down Expand Up @@ -710,8 +717,9 @@ private void renderInternal(String pageName,
WXSDKManager.getInstance().createInstance(this, template, renderOptions, jsonInitData);
mRendered = true;

final IWXJscProcessManager wxJscProcessManager = WXSDKManager.getInstance().getWXJscProcessManager();

if(WXBridgeManager.getInstance().isIsRebootJscWhenWhiteScreen()) {
if(wxJscProcessManager != null && wxJscProcessManager.shouldReboot()) {
WXSDKManager.getInstance().postOnUiThread(new Runnable() {
@Override
public void run() {
Expand All @@ -722,22 +730,14 @@ public void run() {
View containerView = getContainerView();
if(containerView instanceof ViewGroup) {
if(0 == ((ViewGroup) containerView).getChildCount()) {
boolean isWxActivity = false;
if(mContext != null && mContext.getClass() != null) {
String name = mContext.getClass().getName();
if(!TextUtils.isEmpty(name)) {
isWxActivity = name.contains("WXActivity");
}
}

if(!isWxActivity) {
if(wxJscProcessManager.withException(WXSDKInstance.this)) {
onJSException(String.valueOf(WX_ERR_RELOAD_PAGE),"jsc reboot","jsc reboot");
}
WXBridgeManager.getInstance().callReportCrashReloadPage(mInstanceId, null);
}
}
}
}, WXBridgeManager.getInstance().getRebootJscTimeout());
}, wxJscProcessManager.rebootTimeout());
}
}

Expand Down
7 changes: 6 additions & 1 deletion android/sdk/src/main/java/com/taobao/weex/WXSDKManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.taobao.weex.adapter.DefaultWXHttpAdapter;
import com.taobao.weex.adapter.ICrashInfoReporter;
import com.taobao.weex.adapter.IDrawableLoader;
import com.taobao.weex.adapter.IWXJscProcessManager;
import com.taobao.weex.adapter.ITracingAdapter;
import com.taobao.weex.adapter.IWXAccessibilityRoleAdapter;
import com.taobao.weex.adapter.IWXHttpAdapter;
Expand Down Expand Up @@ -96,6 +97,7 @@ public class WXSDKManager {
private IWebSocketAdapterFactory mIWebSocketAdapterFactory;
private ITracingAdapter mTracingAdapter;
private WXValidateProcessor mWXValidateProcessor;
private IWXJscProcessManager mWXJscProcessManager;
// Tell weexv8 to initialize v8, default is true.
private boolean mNeedInitV8 = true;

Expand Down Expand Up @@ -209,7 +211,9 @@ public WXBridgeManager getWXBridgeManager() {
public WXRenderManager getWXRenderManager() {
return mWXRenderManager;
}

public IWXJscProcessManager getWXJscProcessManager() {
return mWXJscProcessManager;
}
public WXWorkThreadManager getWXWorkThreadManager() {
return mWXWorkThreadManager;
}
Expand Down Expand Up @@ -399,6 +403,7 @@ void setInitConfig(InitConfig config){
this.mClassLoaderAdapter = config.getClassLoaderAdapter();
this.mApmGenerater = config.getApmGenerater();
this.mWXJsFileLoaderAdapter = config.getJsFileLoaderAdapter();
this.mWXJscProcessManager = config.getJscProcessManager();
}

public IWXStorageAdapter getIWXStorageAdapter(){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.taobao.weex.adapter;

import com.taobao.weex.WXSDKInstance;

public interface IWXJscProcessManager {
boolean shouldReboot();
long rebootTimeout();
boolean withException(WXSDKInstance instance);
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,6 @@ public class WXBridgeManager implements Callback, BactchExecutor {
// add for cloud setting, default value is false.
// weexcore use single process or not
private static boolean isUseSingleProcess = false;
private static boolean isRebootJscWhenWhiteScreen = false;
public final static long DEFAULT_REBOOT_JSC_TIMEOUT = 5000;
private static long rebootJscTimeout = DEFAULT_REBOOT_JSC_TIMEOUT;

public enum BundType {
Vue,
Expand Down Expand Up @@ -225,21 +222,7 @@ public static WXBridgeManager getInstance() {
}
return mBridgeManager;
}
public boolean isIsRebootJscWhenWhiteScreen() {
return isRebootJscWhenWhiteScreen;
}

public void setIsRebootJscWhenWhiteScreen(boolean _isRebootJscWhenWhiteScreen) {
isRebootJscWhenWhiteScreen = _isRebootJscWhenWhiteScreen;
}

public long getRebootJscTimeout() {
return rebootJscTimeout;
}

public void setRebootJscTimeout(long timeout) {
rebootJscTimeout = timeout;
}
public void setUseSingleProcess(final boolean flag) {
if (flag != isUseSingleProcess) {
isUseSingleProcess = flag;
Expand Down Expand Up @@ -2230,10 +2213,11 @@ public void reportJSException(String instanceId, String function,
WXSDKInstance instance = null;
WXErrorCode reportErrorCode = WXErrorCode.WX_ERR_JS_EXECUTE;
if (instanceId != null && (instance = WXSDKManager.getInstance().getSDKInstance(instanceId)) != null) {
instance.setHasException(true);
exception += "\n getTemplateInfo==" +instance.getTemplateInfo();//add network header info
if (METHOD_CREATE_INSTANCE.equals(function) || !instance.isContentMd5Match()) {
try {
if (isJSFrameworkInit() && reInitCount > 1 && !instance.isNeedReLoad()) {
if (isJSFrameworkInit() && (reInitCount > 1 && reInitCount < 10) && !instance.isNeedReLoad()) {
new ActionReloadPage(instanceId, true).executeAction();
instance.setNeedLoad(true);
return;
Expand Down

0 comments on commit 4eef29d

Please sign in to comment.