Skip to content

Commit

Permalink
Merge pull request apache#3081 from YorkShen/release/20190925
Browse files Browse the repository at this point in the history
Merge Release/20190925 into master
  • Loading branch information
lucky-chen authored Dec 16, 2019
2 parents 10f7406 + cb8c979 commit f29a6f2
Show file tree
Hide file tree
Showing 65 changed files with 1,860 additions and 174 deletions.
14 changes: 7 additions & 7 deletions android/sdk/src/main/java/org/apache/weex/WXEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ public static String getCacheDir() {
return application.getApplicationContext().getCacheDir().getPath();
}

public static boolean extractSo() {
public static String extractSo() {
File sourceFile = new File(getApplication().getApplicationContext().getApplicationInfo().sourceDir);
final String soDesPath = copySoDesDir();
if (sourceFile.exists() && !TextUtils.isEmpty(soDesPath)) {
Expand All @@ -524,11 +524,11 @@ public static boolean extractSo() {
} catch (IOException e) {
WXLogUtils.e("extractSo error " + e.getMessage());
// e.printStackTrace();
return false;
return null;
}
return true;
return soDesPath;
}
return false;
return null;
}

private static String findIcuPath() {
Expand Down Expand Up @@ -593,9 +593,9 @@ public static String findSoPath(String libName) {
return soPath;
} else {
//unzip from apk file
final boolean success = extractSo();
if (success) {
return new File(getCacheDir(), realName).getAbsolutePath();
final String extractSoPath = extractSo();
if (!TextUtils.isEmpty(extractSoPath)) {
return new File(extractSoPath, realName).getAbsolutePath();
}
}
return soPath;
Expand Down
47 changes: 44 additions & 3 deletions android/sdk/src/main/java/org/apache/weex/WXSDKInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import android.support.annotation.WorkerThread;
import android.support.v4.util.ArrayMap;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -68,6 +69,8 @@
import org.apache.weex.dom.WXEvent;
import org.apache.weex.http.WXHttpUtil;
import org.apache.weex.instance.InstanceOnFireEventInterceptor;
import org.apache.weex.jsEngine.JSContext;
import org.apache.weex.jsEngine.JSEngine;
import org.apache.weex.layout.ContentBoxMeasurement;
import org.apache.weex.performance.WXInstanceApm;
import org.apache.weex.performance.WXStateRecord;
Expand Down Expand Up @@ -209,6 +212,9 @@ public class WXSDKInstance implements IWXActivityStateListener,View.OnLayoutChan

private String mRenderType = RenderTypes.RENDER_TYPE_NATIVE;

private boolean mPageDirty = true;
private boolean mFixMultiThreadBug = false;

public TimeCalculator mTimeCalculator;
/**
* Default Width And Viewport is 750,
Expand Down Expand Up @@ -527,9 +533,18 @@ public WXSDKInstance(){
mApmForInstance = new WXInstanceApm(mInstanceId);
WXSDKManager.getInstance().getAllInstanceMap().put(mInstanceId,this);
mTimeCalculator = new TimeCalculator(this);
initFixMultiThreadFlag();
}


private void initFixMultiThreadFlag() {
IWXConfigAdapter adapter = WXSDKManager.getInstance().getWxConfigAdapter();
if (adapter != null) {
String config = adapter.getConfig("android_weex_ext_config", "fixMultiThreadBug", "true");
mFixMultiThreadBug = Boolean.parseBoolean(config);
}
}

/**
* For unittest only.
*/
Expand Down Expand Up @@ -584,6 +599,7 @@ public void removeOnInstanceVisibleListener(OnInstanceVisibleListener l){
}

public void init(Context context) {
initFixMultiThreadFlag();
RegisterCache.getInstance().idle(true);
mContext = context;
mContainerInfo = new HashMap<>(4);
Expand Down Expand Up @@ -2397,15 +2413,32 @@ public interface NestedInstanceInterceptor {
}

public void OnVSync() {
boolean forceLayout = WXBridgeManager.getInstance().notifyLayout(getInstanceId());
if(forceLayout) {
if(mFixMultiThreadBug) {
if(!mPageDirty) {
return;
}
WXBridgeManager.getInstance().post(new Runnable() {
@Override
public void run() {
WXBridgeManager.getInstance().forceLayout(getInstanceId());
boolean forceLayout = WXBridgeManager.getInstance().notifyLayout(getInstanceId());
if(forceLayout) {
WXBridgeManager.getInstance().forceLayout(getInstanceId());
}
}
});
} else {
boolean forceLayout = WXBridgeManager.getInstance().notifyLayout(getInstanceId());
if(forceLayout) {
WXBridgeManager.getInstance().post(new Runnable() {
@Override
public void run() {
WXBridgeManager.getInstance().forceLayout(getInstanceId());
}
});
}
}


}

public void addContentBoxMeasurement(long renderObjectPtr, ContentBoxMeasurement contentBoxMeasurement) {
Expand Down Expand Up @@ -2459,4 +2492,12 @@ private static boolean isDisableSkipFrameworkInDataRender() {
String result = adapter.getConfig("wxeagle", "disable_skip_framework_init", "false");
return "true".equals(result);
}

public boolean isPageDirty() {
return mPageDirty;
}

public void setPageDirty(boolean mPageDirty) {
this.mPageDirty = mPageDirty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -934,4 +934,13 @@ public void setDeviceDisplayOfPage(String instanceId, float width, float height)
nativeSetDeviceDisplayOfPage(instanceId,width,height);
}

@CalledByNative
@Override
public void setPageDirty(String instanceId, boolean dirty) {
WXSDKInstance sdkInstance = WXSDKManager.getInstance().getSDKInstance(instanceId);
if(sdkInstance != null) {
sdkInstance.setPageDirty(dirty);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.apache.weex.common.WXRuntimeException;
import org.apache.weex.common.WXThread;
import org.apache.weex.dom.CSSShorthand;
import org.apache.weex.jsEngine.JSEngine;
import org.apache.weex.layout.ContentBoxMeasurement;
import org.apache.weex.performance.WXInstanceApm;
import org.apache.weex.performance.WXStateRecord;
Expand Down Expand Up @@ -381,6 +382,7 @@ private void setJSFrameworkInit(boolean init) {
WXStateRecord.getInstance().recoreJsfmInitHistory("setJsfmInitFlag:"+init);
if (init == true) {
onJsFrameWorkInitSuccees();
JSEngine.getInstance().engineInitFinished();
}
}

Expand Down Expand Up @@ -909,7 +911,7 @@ public int callReportCrashReloadPage(String instanceId, String crashFile) {
WXStateRecord.getInstance().onJSEngineReload(TextUtils.isEmpty(instanceId)?"null":instanceId);
commitJscCrashAlarmMonitor(IWXUserTrackAdapter.JS_BRIDGE, WXErrorCode.WX_ERR_RELOAD_PAGE, "reboot jsc Engine", instanceId, url,extInfo);
}

JSEngine.getInstance().engineCrashed();
WXLogUtils.e("reInitCount:"+reInitCount);

if (reInitCount > CRASHREINIT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,5 @@ int callAddChildToRichtext(String instanceId, String nodeType, String ref, Strin

void setDeviceDisplayOfPage(String instanceId, float width, float height);


void setPageDirty(String instanceId, boolean dirty);
}
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 org.apache.weex.jsEngine;

public class CallBackCode {

public static final CallBackCode ERROR_JSENGINE_CRASHED = new CallBackCode(-1, "js engine Crashed");
public static final CallBackCode JSENGINE_INIT_FINISH = new CallBackCode(1, "js Engine init finished");
public int code;
public String msg;

private CallBackCode(int code, String msg) {
this.code = code;
this.msg = msg;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* 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 org.apache.weex.jsEngine;

public interface EnvCallback {
void error(CallBackCode code);
}
29 changes: 29 additions & 0 deletions android/sdk/src/main/java/org/apache/weex/jsEngine/JSBiz.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* 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 org.apache.weex.jsEngine;

public class JSBiz {
private String bizName;
private String bizId;

public JSBiz(String id, String name) {
this.bizId = id;
this.bizName = name;
}
}
122 changes: 122 additions & 0 deletions android/sdk/src/main/java/org/apache/weex/jsEngine/JSContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/**
* 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 org.apache.weex.jsEngine;

import org.apache.weex.base.CalledByNative;
import org.apache.weex.bridge.WXBridgeManager;
import org.apache.weex.utils.WXLogUtils;

import java.io.Serializable;
import java.util.concurrent.ConcurrentHashMap;

import static org.apache.weex.jsEngine.JSEngine.mCreatedJSContext;

public class JSContext implements Serializable {
private ConcurrentHashMap<String, JSFunction> funcMap = new ConcurrentHashMap<>();
//JSEnginePtrContainer
private long mNativeContextPtr = 0;

private JSException mExceptionTransfer = null;

protected JSContext() {
WXBridgeManager.getInstance().post(new Runnable() {
@Override
public void run() {
mNativeContextPtr = nativeCreateContext();
mCreatedJSContext.put(mNativeContextPtr, JSContext.this);
}
});
}

public void registerException(JSException e) {
mExceptionTransfer = e;
}

public void destroy() {
mCreatedJSContext.remove(mNativeContextPtr);
mExceptionTransfer = null;
WXBridgeManager.getInstance().post(new Runnable() {
@Override
public void run() {
if (mNativeContextPtr != 0) {
long tmp = mNativeContextPtr;
mNativeContextPtr = 0;
nativeDestroyContext(tmp);
}
}
});
}

public void bindFunction(final String name, final JSFunction function) {
WXBridgeManager.getInstance().post(new Runnable() {
@Override
public void run() {
funcMap.put(name, function);
nativeBindFunc(mNativeContextPtr, name);
}
});
}

public void unBindFunction(final String name) {
WXBridgeManager.getInstance().post(new Runnable() {
@Override
public void run() {
funcMap.remove(name);
nativeUnBindFunc(mNativeContextPtr, name);
}
});
}

public void Eval(final String script) {
WXBridgeManager.getInstance().post(new Runnable() {
@Override
public void run() {
nativeExecJS(mNativeContextPtr, script);
}
});
}


@CalledByNative
public String Invoke(String name, String args) {
JSFunction jsFunction = funcMap.get(name);
if (jsFunction != null) {
WXLogUtils.d("jsEngine invoke " + name + " arg:" + args);
return jsFunction.invoke(args);
}
return "";
}

@CalledByNative
public void Exception(String exception) {
if (exception != null && mExceptionTransfer != null) {
this.mExceptionTransfer.exception(exception);
}
}

private native long nativeCreateContext();

private native void nativeDestroyContext(long ctxPtr);

private native void nativeBindFunc(long ctxPtr, String name);

private native void nativeUnBindFunc(long ctxPtr, String name);

private native void nativeExecJS(long ctxPtr, String script);
}
Loading

0 comments on commit f29a6f2

Please sign in to comment.