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

Commit

Permalink
[Android] add new white screen check logic (#2582)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucky-chen authored and YorkShen committed Jun 19, 2019
1 parent 10a0bc5 commit ec44cd4
Show file tree
Hide file tree
Showing 11 changed files with 371 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.alibaba.weex.commons.adapter.PicassoBasedDrawableLoader;
import com.alibaba.weex.extend.adapter.ApmGenerator;
import com.alibaba.weex.extend.adapter.DefaultAccessibilityRoleAdapter;
import com.alibaba.weex.extend.adapter.DefaultConfigAdapter;
import com.alibaba.weex.extend.adapter.InterceptWXHttpAdapter;
import com.alibaba.weex.extend.adapter.WXAnalyzerDemoListener;
import com.alibaba.weex.extend.component.WXComponentSyncTest;
Expand Down Expand Up @@ -83,6 +84,7 @@ public void onCreate() {
.setApmGenerater(new ApmGenerator())
.build()
);
WXSDKManager.getInstance().setWxConfigAdapter(new DefaultConfigAdapter());
WXSDKManager.getInstance().addWXAnalyzer(new WXAnalyzerDemoListener());
WXAnalyzerDataTransfer.isOpenPerformance = false;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* 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.alibaba.weex.extend.adapter;

import com.taobao.weex.adapter.IWXConfigAdapter;

/**
* @author zhongcang
* @date 2019/6/19
*/
public class DefaultConfigAdapter implements IWXConfigAdapter {
@Override
public String getConfig(String nameSpace, String key, String defaultValue) {
return defaultValue;
}
}
25 changes: 25 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 @@ -71,6 +71,8 @@
import com.taobao.weex.instance.InstanceOnFireEventInterceptor;
import com.taobao.weex.layout.ContentBoxMeasurement;
import com.taobao.weex.performance.WXInstanceApm;
import com.taobao.weex.performance.WXStateRecord;
import com.taobao.weex.performance.WhiteScreenUtils;
import com.taobao.weex.tracing.WXTracing;
import com.taobao.weex.ui.action.GraphicActionAddElement;
import com.taobao.weex.ui.component.NestedContainer;
Expand Down Expand Up @@ -862,6 +864,7 @@ private void renderInternal(String pageName,
WXSDKManager.getInstance().postOnUiThread(new Runnable() {
@Override
public void run() {
checkWhiteScreen();
if(isDestroy || hasException || isRenderSuccess) {
return;
}
Expand All @@ -880,6 +883,28 @@ public void run() {
}
}


private void checkWhiteScreen(){
if (isDestroy ||!WhiteScreenUtils.doWhiteScreenCheck()){
return;
}

boolean isWS = WhiteScreenUtils.isWhiteScreen(this);
if (!isWS){
return;
}
WXErrorCode errorCode = WXErrorCode.WX_ERROR_WHITE_SCREEN;
Map<String,String> args = new HashMap<>(1);
String vieTreeMsg = WhiteScreenUtils.getViewMsg(this);
args.put("viewTree",null == vieTreeMsg?"null viewTreeMsg":vieTreeMsg);

for (Map.Entry<String,String> entry: WXStateRecord.getInstance().getStateInfo().entrySet()){
args.put(entry.getKey(),entry.getValue());
}
WXExceptionUtils.commitCriticalExceptionRT(getInstanceId(),errorCode,"checkEmptyScreen",errorCode.getErrorMsg(),args);
}


public boolean skipFrameworkInit(){
return isDataRender() && !mDisableSkipFrameworkInit;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ public IWXConfigAdapter getWxConfigAdapter() {
public void postOnUiThread(Runnable runnable, long delayMillis) {
mWXRenderManager.postOnUiThread(WXThread.secure(runnable), delayMillis);
}

public Map<String, WXSDKInstance> getAllInstanceMap() {
return mAllInstanceMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.taobao.weex.dom.CSSShorthand;
import com.taobao.weex.layout.ContentBoxMeasurement;
import com.taobao.weex.performance.WXInstanceApm;
import com.taobao.weex.performance.WXStateRecord;
import com.taobao.weex.utils.WXExceptionUtils;
import com.taobao.weex.utils.WXJsonUtils;
import com.taobao.weex.utils.WXLogUtils;
Expand Down Expand Up @@ -385,6 +386,7 @@ public void setJSFrmVersion(String version) {
if (version != null) {
WXEnvironment.JS_LIB_SDK_VERSION = version;
}
WXStateRecord.getInstance().onJSFMInit();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import com.taobao.weex.dom.CSSShorthand;
import com.taobao.weex.layout.ContentBoxMeasurement;
import com.taobao.weex.performance.WXInstanceApm;
import com.taobao.weex.performance.WXStateRecord;
import com.taobao.weex.ui.WXComponentRegistry;
import com.taobao.weex.ui.action.ActionReloadPage;
import com.taobao.weex.ui.action.BasicGraphicAction;
Expand Down Expand Up @@ -609,6 +610,8 @@ public Object callNativeModule(String instanceId, String module, String method,
return IWXBridge.INSTANCE_RENDERING_ERROR;
}

WXStateRecord.getInstance().recordAction(instanceId,"callNativeModule:"+module+"."+method);

if (WXEnvironment.isApkDebugable() && BRIDGE_LOG_SWITCH) {
mLodBuilder.append("[WXBridgeManager] callNativeModule >>>> instanceId:").append(instanceId)
.append(", module:").append(module).append(", method:").append(method).append(", arguments:").append(arguments);
Expand Down Expand Up @@ -848,8 +851,10 @@ public int callReportCrashReloadPage(String instanceId, String crashFile) {
} catch (Throwable e) {
e.printStackTrace();
}
WXStateRecord.getInstance().onJSCCrash();
callReportCrash(crashFile, instanceId, url);
} else {
WXStateRecord.getInstance().onJSEngineReload();
commitJscCrashAlarmMonitor(IWXUserTrackAdapter.JS_BRIDGE, WXErrorCode.WX_ERR_RELOAD_PAGE, "reboot jsc Engine", instanceId, url);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ public enum WXErrorCode {
*/
WX_ERR_RELOAD_PAGE("-2111", "reloadPage",ErrorType.NATIVE_ERROR,ErrorGroup.NATIVE),

WX_ERROR_WHITE_SCREEN("-2116", "WHITE_SCREEN",ErrorType.RENDER_ERROR,ErrorGroup.JS),


/**
*
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/**
* 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.performance;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import com.taobao.weex.utils.WXUtils;

/**
* @author zhongcang
* @date 2019/6/19
*/
public class WXStateRecord {

private RecordList<Info> mExceptionHistory;
private RecordList<Info> mActionHistory;
private RecordList<Info> mJsfmInitHistory;
private RecordList<Info> mJscCrashHistory;
private RecordList<Info> mJscReloadHistory;

private static class SingleTonHolder {
private static final WXStateRecord S_INSTANCE = new WXStateRecord();
}

public static WXStateRecord getInstance() {
return SingleTonHolder.S_INSTANCE;
}

private WXStateRecord() {
mExceptionHistory = new RecordList<>(5);
mActionHistory = new RecordList<>(10);
mJsfmInitHistory = new RecordList<>(3);
mJscCrashHistory = new RecordList<>(3);
mJscReloadHistory = new RecordList<>(5);
}

/**
* check history exception (may be cause ws)
*/
public void recordException(String instanceId, String exception) {
String shortException = exception.length() > 200 ?exception.substring(0,200) : exception;
mExceptionHistory.add(new Info(WXUtils.getFixUnixTime(), instanceId, shortException));
}

/**
* check history action (may be occupy cpu by preInstance or some task)
*/
public void recordAction(String instanceId, String action) {
mActionHistory.add(new Info(WXUtils.getFixUnixTime(), instanceId, action));
}

/**
* check onJSFMInit time,and we know when jsfm is init sucess in reloadJsEngine case
*/
public void onJSFMInit() {
mJsfmInitHistory.add(new Info(WXUtils.getFixUnixTime(), "JSFM", "onJsfmInit"));
}

/**
* check onJSEngineReload time,and we know how many times reload and each reload time
*/
public void onJSEngineReload() {
mJscReloadHistory.add(new Info(WXUtils.getFixUnixTime(), "", "onJSEngineReload"));
}

/**
* check jsc crash time,and we know how many times jscCrash and each crash time
*/
public void onJSCCrash() {
mJscCrashHistory.add(new Info(WXUtils.getFixUnixTime(), "", "onJSCCrash"));
}

public Map<String, String> getStateInfo() {
Map<String, String> stateInfo = new HashMap<>(5);
stateInfo.put("exceptionHistory", mExceptionHistory.toString());
stateInfo.put("actionHistory", mActionHistory.toString());
stateInfo.put("jsfmInitHistory", mJsfmInitHistory.toString());
stateInfo.put("jscCrashHistory", mJscCrashHistory.toString());
stateInfo.put("jscReloadHistory", mJscReloadHistory.toString());
return stateInfo;
}

private static class RecordList<E> extends ArrayList<E> {
private int maxSize;

public RecordList(int maxSize) {
super(maxSize);
this.maxSize = maxSize;
}

@Override
public boolean add(E e) {
if (this.size()>0 && this.size() >= maxSize){
remove(this.size() - 1);
}
return super.add(e);
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder();
int size = size();
for (int i = 0; i < size; i++) {
builder.append('[').append(get(i).toString()).append(']').append("->");
}
return builder.toString();
}
}

private static class Info {
private long time;
private String instanceId;
private String msg;

public Info(long time, String instance, String msg) {
this.time = time;
this.instanceId = instance;
this.msg = msg;
}

@Override
public String toString() {
return new StringBuilder()
.append(instanceId).append(',').append(time).append(',').append(msg)
.toString();
}
}
}
Loading

0 comments on commit ec44cd4

Please sign in to comment.