Skip to content

Commit

Permalink
[WEEX-378][android] wson support for weex-core new architecture and r…
Browse files Browse the repository at this point in the history
…emove rapidjson
  • Loading branch information
jianbai.gbj committed May 24, 2018
1 parent 162d705 commit 50ae70c
Show file tree
Hide file tree
Showing 86 changed files with 2,973 additions and 16,674 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public void onCreate() {
**/
// initDebugEnvironment(true, false, "DEBUG_SERVER_HOST");
WXBridgeManager.updateGlobalConfig("wson_on");
WXEnvironment.setOpenDebugLog(true);
WXEnvironment.setApkDebugable(true);
WXEnvironment.setOpenDebugLog(false);
WXEnvironment.setApkDebugable(false);
WXSDKEngine.addCustomOptions("appName", "WXSample");
WXSDKEngine.addCustomOptions("appGroup", "WXApp");
WXSDKEngine.initialize(this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.taobao.weex.WXEnvironment;
import com.taobao.weex.annotation.JSMethod;
import com.taobao.weex.bridge.JSCallback;
import com.taobao.weex.bridge.WXBridgeManager;
import com.taobao.weex.common.WXModule;
import com.taobao.weex.utils.WXWsonJSONSwitch;
import com.taobao.weex.wson.Wson;

/**
* Created by furture on 2018/1/18.
Expand Down Expand Up @@ -54,4 +59,25 @@ public void backAsync(JSONObject params, JSCallback callback) {
back.put("javaJSON", back.toJSONString());
callback.invoke(back);
}

@JSMethod(uiThread = false)
public Object benchmark(JSONObject params) {
if(params == null){
throw new RuntimeException("params is null");
}//do nothing
return params;
}

@JSMethod(uiThread = false)
public void switchTrans(JSCallback callback) {
if(WXWsonJSONSwitch.USE_WSON){
WXBridgeManager.updateGlobalConfig("wson_off");
callback.invoke("wson off, use json");
}else{
WXBridgeManager.updateGlobalConfig("wson_on");
callback.invoke("wson on, use wson");
}
}


}
Binary file modified android/sdk/libs/armeabi-v7a/libweexjsb.so
Binary file not shown.
Binary file added android/sdk/libs/armeabi-v7a/libweexjsc.so
Binary file not shown.
Binary file modified android/sdk/libs/armeabi-v7a/libweexjss.so
Binary file not shown.
Binary file modified android/sdk/libs/armeabi/libweexjsb.so
Binary file not shown.
Binary file added android/sdk/libs/armeabi/libweexjsc.so
Binary file not shown.
Binary file modified android/sdk/libs/armeabi/libweexjss.so
Binary file not shown.
Binary file modified android/sdk/libs/x86/libweexjsb.so
Binary file not shown.
Binary file added android/sdk/libs/x86/libweexjsc.so
Binary file not shown.
Binary file modified android/sdk/libs/x86/libweexjss.so
Binary file not shown.
49 changes: 36 additions & 13 deletions android/sdk/src/main/java/com/taobao/weex/bridge/WXBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.taobao.weex.WXEnvironment;
import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.WXSDKManager;
import com.taobao.weex.adapter.IWXUserTrackAdapter;
import com.taobao.weex.common.IWXBridge;
Expand All @@ -32,6 +33,7 @@
import com.taobao.weex.layout.ContentBoxMeasurement;
import com.taobao.weex.utils.WXExceptionUtils;
import com.taobao.weex.utils.WXLogUtils;
import com.taobao.weex.utils.WXWsonJSONSwitch;

import java.io.Serializable;
import java.util.HashMap;
Expand Down Expand Up @@ -165,11 +167,25 @@ public String execJSOnInstance(String instanceId, String script, int type) {
* @param callback
*/
public int callNative(String instanceId, byte[] tasks, String callback) {
return callNative(instanceId, new String(tasks), callback);
return callNative(instanceId, (JSONArray) JSON.parseArray(new String(tasks)), callback);
}

@Override
public int callNative(String instanceId, String tasks, String callback) {
try{
return callNative(instanceId, JSONArray.parseArray(tasks), callback);
}catch (Exception e){
WXLogUtils.e(TAG, "callNative throw exception: " + e.getMessage());
return IWXBridge.INSTANCE_RENDERING;
}
}

private int callNative(String instanceId, JSONArray tasks, String callback){
long start = System.currentTimeMillis();
WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
if (instance != null) {
instance.firstScreenCreateInstanceTime(start);
}
int errorCode = IWXBridge.INSTANCE_RENDERING;
try {
errorCode = WXBridgeManager.getInstance().callNative(instanceId, tasks, callback);
Expand Down Expand Up @@ -203,16 +219,18 @@ public void reportJSException(String instanceId, String func, String exception)
*/
@Override
public Object callNativeModule(String instanceId, String module, String method, byte[] arguments, byte[] options) {
JSONArray argArray = null;
if (arguments != null) {
argArray = JSON.parseArray(new String(arguments));
}
JSONObject optionsObj = null;
if (options != null) {
optionsObj = JSON.parseObject(new String(options));
try{
JSONArray argArray = (JSONArray) WXWsonJSONSwitch.parseWsonOrJSON(arguments);
JSONObject optionsObj = null;
if (options != null) {
optionsObj = (JSONObject) WXWsonJSONSwitch.parseWsonOrJSON(options);
}
Object object = WXBridgeManager.getInstance().callNativeModule(instanceId, module, method, argArray, optionsObj);
return WXWsonJSONSwitch.toWsonOrJsonWXJSObject(object);
}catch (Exception e){
WXLogUtils.e(TAG, e);
return new WXJSObject(null);
}
Object object = WXBridgeManager.getInstance().callNativeModule(instanceId, module, method, argArray, optionsObj);
return new WXJSObject(object);
}

/**
Expand All @@ -225,9 +243,14 @@ public Object callNativeModule(String instanceId, String module, String method,
* @param options option arguments for extending
*/
@Override
public void callNativeComponent(String instanceId, String ref, String method, byte[] arguments, byte[] options) {
JSONArray argArray = JSON.parseArray(new String(arguments));
WXBridgeManager.getInstance().callNativeComponent(instanceId, ref, method, argArray, options);
public void callNativeComponent(String instanceId, String ref, String method, byte[] arguments, byte[] optionsData) {
try{
JSONArray argArray = (JSONArray) WXWsonJSONSwitch.parseWsonOrJSON(arguments);
Object options = WXWsonJSONSwitch.parseWsonOrJSON(optionsData);
WXBridgeManager.getInstance().callNativeComponent(instanceId, ref, method, argArray, options);
}catch (Exception e){
WXLogUtils.e(TAG, e);
}
}

public void setTimeoutNative(String callbackId, String time) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.taobao.weex.WXEnvironment;
import com.taobao.weex.WXSDKEngine;
import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.WXSDKManager;
import com.taobao.weex.adapter.IWXJSExceptionAdapter;
Expand Down Expand Up @@ -73,12 +72,12 @@
import com.taobao.weex.ui.action.GraphicActionUpdateStyle;
import com.taobao.weex.ui.action.GraphicPosition;
import com.taobao.weex.ui.action.GraphicSize;
import com.taobao.weex.ui.component.WXComponent;
import com.taobao.weex.ui.module.WXDomModule;
import com.taobao.weex.utils.WXExceptionUtils;
import com.taobao.weex.utils.WXFileUtils;
import com.taobao.weex.utils.WXJsonUtils;
import com.taobao.weex.utils.WXLogUtils;
import com.taobao.weex.utils.WXWsonJSONSwitch;
import com.taobao.weex.utils.WXUtils;
import com.taobao.weex.utils.WXViewUtils;
import com.taobao.weex.utils.batch.BactchExecutor;
Expand Down Expand Up @@ -554,8 +553,8 @@ public Object callNativeComponent(String instanceId, String componentRef, String
* @param tasks tasks to be executed
* @param callback next tick id
*/
public int callNative(String instanceId, String tasks, String callback) {
if (TextUtils.isEmpty(tasks)) {
public int callNative(String instanceId, JSONArray tasks, String callback) {
if (tasks == null) {
String err = "[WXBridgeManager] callNative: call Native tasks is null";
WXLogUtils.e(err);
WXExceptionUtils.commitCriticalExceptionRT(instanceId,
Expand All @@ -578,7 +577,7 @@ public int callNative(String instanceId, String tasks, String callback) {


long parseNanos = System.nanoTime();
JSONArray array = JSON.parseArray(tasks);
JSONArray array = tasks;
parseNanos = System.nanoTime() - parseNanos;

if (null != array && array.size() > 0) {
Expand Down Expand Up @@ -880,7 +879,7 @@ public void run() {
Object[] tasks = {task};
WXJSObject[] jsArgs = {
new WXJSObject(WXJSObject.String, instanceId),
new WXJSObject(WXJSObject.JSON, WXJsonUtils.fromObjectToJSONString(tasks))};
WXWsonJSONSwitch.toWsonOrJsonWXJSObject(tasks)};
invokeExecJS(String.valueOf(instanceId), null, METHOD_CALL_JS, jsArgs, true);
jsArgs[0] = null;
jsArgs = null;
Expand Down Expand Up @@ -920,13 +919,13 @@ public void run() {
Object[] tasks = {task};
WXJSObject[] jsArgs = {
new WXJSObject(WXJSObject.String, instanceId),
new WXJSObject(WXJSObject.JSON, WXJsonUtils.fromObjectToJSONString(tasks))};
WXWsonJSONSwitch.toWsonOrJsonWXJSObject(tasks)};
byte[] taskResult = invokeExecJSWithResult(String.valueOf(instanceId), null, METHOD_CALL_JS, jsArgs, true);
if(eventCallback == null){
return;
}
if(taskResult != null){
JSONArray arrayResult = (JSONArray) JSON.parse(new String(taskResult, "UTF-8"));
JSONArray arrayResult = (JSONArray) WXWsonJSONSwitch.parseWsonOrJSON(taskResult);
if(arrayResult != null && arrayResult.size() > 0){
result = arrayResult.get(0);
}
Expand Down Expand Up @@ -1602,7 +1601,7 @@ private String invokeExecJSOnInstance(String instanceId, String js, int type) {

private byte[] invokeExecJSWithResult(String instanceId, String namespace, String function,
WXJSObject[] args,boolean logTaskDetail){
if (WXEnvironment.isOpenDebugLog()) {
if (WXEnvironment.isOpenDebugLog() && BRIDGE_LOG_SWITCH) {
mLodBuilder.append("callJS >>>> instanceId:").append(instanceId)
.append("function:").append(function);
if(logTaskDetail) {
Expand Down Expand Up @@ -1767,8 +1766,7 @@ private void invokeCallJSBatch(Message message) {

WXJSObject[] args = {
new WXJSObject(WXJSObject.String, instanceId),
new WXJSObject(WXJSObject.JSON,
WXJsonUtils.fromObjectToJSONString(task))};
WXWsonJSONSwitch.toWsonOrJsonWXJSObject(task)};

invokeExecJS(String.valueOf(instanceId), null, METHOD_CALL_JS, args);

Expand Down Expand Up @@ -1937,8 +1935,7 @@ private void invokeRegisterModules(Map<String, Object> modules, List<Map<String,
return;
}

WXJSObject[] args = {new WXJSObject(WXJSObject.JSON,
WXJsonUtils.fromObjectToJSONString(modules))};
WXJSObject[] args = {WXWsonJSONSwitch.toWsonOrJsonWXJSObject(modules)};
try {
mWXBridge.execJS("", null, METHOD_REGISTER_MODULES, args);
try {
Expand Down Expand Up @@ -1980,8 +1977,7 @@ private void invokeRegisterComponents(List<Map<String, Object>> components, List
return;
}

WXJSObject[] args = {new WXJSObject(WXJSObject.JSON,
WXJsonUtils.fromObjectToJSONString(components))};
WXJSObject[] args = {WXWsonJSONSwitch.toWsonOrJsonWXJSObject(components)};
try {
mWXBridge.execJS("", null, METHOD_REGISTER_COMPONENTS, args);
} catch (Throwable e) {
Expand Down Expand Up @@ -2167,6 +2163,11 @@ public void run() {
}
}
}
if(globalConfig.contains(WXWsonJSONSwitch.WSON_OFF)){
WXWsonJSONSwitch.USE_WSON = false;
}else{
WXWsonJSONSwitch.USE_WSON = true;
}
}
};
if(mBridgeManager != null && mBridgeManager.isJSFrameworkInit()){
Expand Down Expand Up @@ -2530,7 +2531,10 @@ public int callLayout(String pageId, String ref, int top, int bottom, int left,
addAction.setIndex(index);
}
WXSDKManager.getInstance().getWXRenderManager().postGraphicAction(pageId, addAction);
WXSDKManager.getInstance().getSDKInstance(pageId).removeInActiveAddElmentAction(ref);
WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(pageId);
if(instance != null){
instance.removeInActiveAddElmentAction(ref);
}
}
else {
final BasicGraphicAction action = new GraphicActionLayout(pageId, ref, position, size);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
*/
package com.taobao.weex.bridge;

import com.alibaba.fastjson.JSON;
import com.taobao.weex.common.IWXJsFunctions;
import com.taobao.weex.utils.WXWsonJSONSwitch;
import com.taobao.weex.wson.WsonUtils;

/**
* Created by darin on 27/03/2018.
Expand All @@ -37,16 +40,31 @@ public class WXJsFunctions implements IWXJsFunctions {
@Override
public native void jsHandleCallNative(String instanceId, byte[] tasks, String callback);


@Override
public native void jsHandleCallNativeModule(String instanceId, String module, String method, byte[] arguments, byte[] options);
public void jsHandleCallNativeModule(String instanceId, String module, String method, byte[] arguments, byte[] options){
jsHandleCallNativeModule(instanceId, module, method,
WXWsonJSONSwitch.convertJSONToWsonIfUseWson(arguments), WXWsonJSONSwitch.convertJSONToWsonIfUseWson(options), true);
}

public native void jsHandleCallNativeModule(String instanceId, String module, String method, byte[] arguments, byte[] options, boolean h5);


@Override
public native void jsHandleCallNativeComponent(String instanceId, String componentRef, String method, byte[] arguments, byte[] options);
public void jsHandleCallNativeComponent(String instanceId, String componentRef, String method, byte[] arguments, byte[] options){
jsHandleCallNativeComponent(instanceId, componentRef, method, arguments, options, true);
}


public native void jsHandleCallNativeComponent(String instanceId, String componentRef, String method, byte[] arguments, byte[] options, boolean from);


@Override
public native void jsHandleCallAddElement(String instanceId, String ref, String dom, String index);
public void jsHandleCallAddElement(String instanceId, String ref, String dom, String index){
jsHandleCallAddElement(instanceId, ref, WsonUtils.toWson(JSON.parse(dom)), index, true);
}

public native void jsHandleCallAddElement(String instanceId, String ref, byte[] dom, String index, boolean h5);


@Override
Expand All @@ -58,7 +76,11 @@ public class WXJsFunctions implements IWXJsFunctions {


@Override
public native void jsFunctionCallCreateBody(String pageId, String domStr);
public void jsFunctionCallCreateBody(String pageId, String domStr){
jsFunctionCallCreateBody(pageId, WsonUtils.toWson(JSON.parse(domStr)), true);
}

public native void jsFunctionCallCreateBody(String pageId, byte[] domStr, boolean h5);


@Override
Expand All @@ -74,11 +96,19 @@ public class WXJsFunctions implements IWXJsFunctions {


@Override
public native void jsFunctionCallUpdateAttrs(String pageId, String ref, String data);
public void jsFunctionCallUpdateAttrs(String pageId, String ref, String data){
jsFunctionCallUpdateAttrs(pageId, ref, WsonUtils.toWson(JSON.parseObject(data)), true);
}

public native void jsFunctionCallUpdateAttrs(String pageId, String ref, byte[] data, boolean h5);


@Override
public native void jsFunctionCallUpdateStyle(String pageId, String ref, String data);
public void jsFunctionCallUpdateStyle(String pageId, String ref, String data){
jsFunctionCallUpdateStyle(pageId, ref, WsonUtils.toWson(JSON.parseObject(data)), true);
}

public native void jsFunctionCallUpdateStyle(String pageId, String ref, byte[] data, boolean h5);


@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public String getLogLevel() {
}

public String getUseSingleProcess() {
WXLogUtils.e("getUseSingleProcess is running");
WXLogUtils.e("getUseSingleProcess is running " + useSingleProcess);
return useSingleProcess;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public interface IWXBridge extends IWXObject {
*/
int callNative(String instanceId, byte[] tasks, String callback);


int callNative(String instanceId, String tasks, String callback);

void reportJSException(String instanceId, String func, String exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,9 @@ public void updateProperties(Map<String, Object> props) {
* @return true means that the property is consumed
*/
protected boolean setProperty(String key, Object param) {
if(key == null){
return true;
}
switch (key) {
case Constants.Name.PREVENT_MOVE_EVENT:
if (mGesture != null) {
Expand Down
Loading

0 comments on commit 50ae70c

Please sign in to comment.