@Test public void testCallNative() throws Exception { getInstance() .callNative(instance.getInstanceId(), "[{\"module\":\"testModule\",\"method\":\"test\"}]", null); getInstance() .callNative(instance.getInstanceId(), "[{\"module\":\""+WXDomModule.WXDOM+"\",\"method\":\"test\"}]", null); }
public int callNative(String instanceId, String tasks, String callback) { if (TextUtils.isEmpty(tasks)) { if (WXEnvironment.isApkDebugable()) { WXLogUtils.e("[WXBridgeManager] callNative: call Native tasks is null"); } commitJSBridgeAlarmMonitor(instanceId, WXErrorCode.WX_ERR_INVOKE_NATIVE,"[WXBridgeManager] callNative: call Native tasks is null"); return IWXBridge.INSTANCE_RENDERING_ERROR; } if (WXEnvironment.isApkDebugable()) { mLodBuilder.append("[WXBridgeManager] callNative >>>> instanceId:").append(instanceId) .append(", tasks:").append(tasks).append(", callback:").append(callback); WXLogUtils.d(mLodBuilder.substring(0)); mLodBuilder.setLength(0); } if(mDestroyedInstanceId!=null &&mDestroyedInstanceId.contains(instanceId)){ return IWXBridge.DESTROY_INSTANCE; } long start = System.currentTimeMillis(); JSONArray array = JSON.parseArray(tasks); if(WXSDKManager.getInstance().getSDKInstance(instanceId)!=null) { WXSDKManager.getInstance().getSDKInstance(instanceId).jsonParseTime(System.currentTimeMillis() - start); } int size = array.size(); if (size > 0) { try { JSONObject task; for (int i = 0; i < size; ++i) { task = (JSONObject) array.get(i); if (task != null && WXSDKManager.getInstance().getSDKInstance(instanceId) != null) { Object target = task.get(MODULE); Object method = task.get(METHOD); if(target != null){ if(WXDomModule.WXDOM.equals(target) ){ WXDomModule dom = getDomModule(instanceId); dom.callDomMethod(task); }else { callModuleMethod(instanceId, (String) target, (String) task.get(METHOD), (JSONArray) task.get(ARGS)); } }else if(task.get(COMPONENT) != null){ WXDomModule dom = getDomModule(instanceId); dom.invokeMethod((String) task.get(REF),(String) task.get(METHOD),(JSONArray) task.get(ARGS)); }else{ throw new IllegalArgumentException("unknown callNative"); } } } } catch (Exception e) { WXLogUtils.e("[WXBridgeManager] callNative exception: ", e); commitJSBridgeAlarmMonitor(instanceId, WXErrorCode.WX_ERR_INVOKE_NATIVE,"[WXBridgeManager] callNative exception "+e.getCause()); } } if (UNDEFINED.equals(callback) || NON_CALLBACK.equals(callback)) { return IWXBridge.INSTANCE_RENDERING_ERROR; } getNextTick(instanceId, callback); return IWXBridge.INSTANCE_RENDERING; }
WXBridgeManager implements Callback,BactchExecutor { public int callNative(String instanceId, String tasks, String callback) { if (TextUtils.isEmpty(tasks)) { if (WXEnvironment.isApkDebugable()) { WXLogUtils.e("[WXBridgeManager] callNative: call Native tasks is null"); } commitJSBridgeAlarmMonitor(instanceId, WXErrorCode.WX_ERR_INVOKE_NATIVE,"[WXBridgeManager] callNative: call Native tasks is null"); return IWXBridge.INSTANCE_RENDERING_ERROR; } if (WXEnvironment.isApkDebugable()) { mLodBuilder.append("[WXBridgeManager] callNative >>>> instanceId:").append(instanceId) .append(", tasks:").append(tasks).append(", callback:").append(callback); WXLogUtils.d(mLodBuilder.substring(0)); mLodBuilder.setLength(0); } if(mDestroyedInstanceId!=null &&mDestroyedInstanceId.contains(instanceId)){ return IWXBridge.DESTROY_INSTANCE; } long start = System.currentTimeMillis(); JSONArray array = JSON.parseArray(tasks); if(WXSDKManager.getInstance().getSDKInstance(instanceId)!=null) { WXSDKManager.getInstance().getSDKInstance(instanceId).jsonParseTime(System.currentTimeMillis() - start); } int size = array.size(); if (size > 0) { try { JSONObject task; for (int i = 0; i < size; ++i) { task = (JSONObject) array.get(i); if (task != null && WXSDKManager.getInstance().getSDKInstance(instanceId) != null) { Object target = task.get(MODULE); Object method = task.get(METHOD); if(target != null){ if(WXDomModule.WXDOM.equals(target) ){ WXDomModule dom = getDomModule(instanceId); dom.callDomMethod(task); }else { callModuleMethod(instanceId, (String) target, (String) task.get(METHOD), (JSONArray) task.get(ARGS)); } }else if(task.get(COMPONENT) != null){ WXDomModule dom = getDomModule(instanceId); dom.invokeMethod((String) task.get(REF),(String) task.get(METHOD),(JSONArray) task.get(ARGS)); }else{ throw new IllegalArgumentException("unknown callNative"); } } } } catch (Exception e) { WXLogUtils.e("[WXBridgeManager] callNative exception: ", e); commitJSBridgeAlarmMonitor(instanceId, WXErrorCode.WX_ERR_INVOKE_NATIVE,"[WXBridgeManager] callNative exception "+e.getCause()); } } if (UNDEFINED.equals(callback) || NON_CALLBACK.equals(callback)) { return IWXBridge.INSTANCE_RENDERING_ERROR; } getNextTick(instanceId, callback); return IWXBridge.INSTANCE_RENDERING; } }
WXBridgeManager implements Callback,BactchExecutor { public int callNative(String instanceId, String tasks, String callback) { if (TextUtils.isEmpty(tasks)) { if (WXEnvironment.isApkDebugable()) { WXLogUtils.e("[WXBridgeManager] callNative: call Native tasks is null"); } commitJSBridgeAlarmMonitor(instanceId, WXErrorCode.WX_ERR_INVOKE_NATIVE,"[WXBridgeManager] callNative: call Native tasks is null"); return IWXBridge.INSTANCE_RENDERING_ERROR; } if (WXEnvironment.isApkDebugable()) { mLodBuilder.append("[WXBridgeManager] callNative >>>> instanceId:").append(instanceId) .append(", tasks:").append(tasks).append(", callback:").append(callback); WXLogUtils.d(mLodBuilder.substring(0)); mLodBuilder.setLength(0); } if(mDestroyedInstanceId!=null &&mDestroyedInstanceId.contains(instanceId)){ return IWXBridge.DESTROY_INSTANCE; } long start = System.currentTimeMillis(); JSONArray array = JSON.parseArray(tasks); if(WXSDKManager.getInstance().getSDKInstance(instanceId)!=null) { WXSDKManager.getInstance().getSDKInstance(instanceId).jsonParseTime(System.currentTimeMillis() - start); } int size = array.size(); if (size > 0) { try { JSONObject task; for (int i = 0; i < size; ++i) { task = (JSONObject) array.get(i); if (task != null && WXSDKManager.getInstance().getSDKInstance(instanceId) != null) { Object target = task.get(MODULE); Object method = task.get(METHOD); if(target != null){ if(WXDomModule.WXDOM.equals(target) ){ WXDomModule dom = getDomModule(instanceId); dom.callDomMethod(task); }else { callModuleMethod(instanceId, (String) target, (String) task.get(METHOD), (JSONArray) task.get(ARGS)); } }else if(task.get(COMPONENT) != null){ WXDomModule dom = getDomModule(instanceId); dom.invokeMethod((String) task.get(REF),(String) task.get(METHOD),(JSONArray) task.get(ARGS)); }else{ throw new IllegalArgumentException("unknown callNative"); } } } } catch (Exception e) { WXLogUtils.e("[WXBridgeManager] callNative exception: ", e); commitJSBridgeAlarmMonitor(instanceId, WXErrorCode.WX_ERR_INVOKE_NATIVE,"[WXBridgeManager] callNative exception "+e.getCause()); } } if (UNDEFINED.equals(callback) || NON_CALLBACK.equals(callback)) { return IWXBridge.INSTANCE_RENDERING_ERROR; } getNextTick(instanceId, callback); return IWXBridge.INSTANCE_RENDERING; } private  WXBridgeManager(); }
WXBridgeManager implements Callback,BactchExecutor { public int callNative(String instanceId, String tasks, String callback) { if (TextUtils.isEmpty(tasks)) { if (WXEnvironment.isApkDebugable()) { WXLogUtils.e("[WXBridgeManager] callNative: call Native tasks is null"); } commitJSBridgeAlarmMonitor(instanceId, WXErrorCode.WX_ERR_INVOKE_NATIVE,"[WXBridgeManager] callNative: call Native tasks is null"); return IWXBridge.INSTANCE_RENDERING_ERROR; } if (WXEnvironment.isApkDebugable()) { mLodBuilder.append("[WXBridgeManager] callNative >>>> instanceId:").append(instanceId) .append(", tasks:").append(tasks).append(", callback:").append(callback); WXLogUtils.d(mLodBuilder.substring(0)); mLodBuilder.setLength(0); } if(mDestroyedInstanceId!=null &&mDestroyedInstanceId.contains(instanceId)){ return IWXBridge.DESTROY_INSTANCE; } long start = System.currentTimeMillis(); JSONArray array = JSON.parseArray(tasks); if(WXSDKManager.getInstance().getSDKInstance(instanceId)!=null) { WXSDKManager.getInstance().getSDKInstance(instanceId).jsonParseTime(System.currentTimeMillis() - start); } int size = array.size(); if (size > 0) { try { JSONObject task; for (int i = 0; i < size; ++i) { task = (JSONObject) array.get(i); if (task != null && WXSDKManager.getInstance().getSDKInstance(instanceId) != null) { Object target = task.get(MODULE); Object method = task.get(METHOD); if(target != null){ if(WXDomModule.WXDOM.equals(target) ){ WXDomModule dom = getDomModule(instanceId); dom.callDomMethod(task); }else { callModuleMethod(instanceId, (String) target, (String) task.get(METHOD), (JSONArray) task.get(ARGS)); } }else if(task.get(COMPONENT) != null){ WXDomModule dom = getDomModule(instanceId); dom.invokeMethod((String) task.get(REF),(String) task.get(METHOD),(JSONArray) task.get(ARGS)); }else{ throw new IllegalArgumentException("unknown callNative"); } } } } catch (Exception e) { WXLogUtils.e("[WXBridgeManager] callNative exception: ", e); commitJSBridgeAlarmMonitor(instanceId, WXErrorCode.WX_ERR_INVOKE_NATIVE,"[WXBridgeManager] callNative exception "+e.getCause()); } } if (UNDEFINED.equals(callback) || NON_CALLBACK.equals(callback)) { return IWXBridge.INSTANCE_RENDERING_ERROR; } getNextTick(instanceId, callback); return IWXBridge.INSTANCE_RENDERING; } private  WXBridgeManager(); static WXBridgeManager getInstance(); void stopRemoteDebug(); Object callModuleMethod(String instanceId, String moduleStr, String methodStr, JSONArray args); void restart(); synchronized void setStackTopInstance(final String instanceId); @Override void post(Runnable r); @Override void setInterceptor(Interceptor interceptor); void post(Runnable r, Object token); void sendMessageDelayed(Message message, long delayMillis); void removeMessage(int what,Object obj); Object callNativeModule(String instanceId, String module, String method, JSONArray arguments, Object options); Object callNativeComponent(String instanceId, String componentRef, String method, JSONArray arguments, Object options); int callNative(String instanceId, String tasks, String callback); int callCreateBody(String instanceId, String tasks, String callback); int callUpdateFinish(String instanceId, String callback); int callCreateFinish(String instanceId, String callback); int callRefreshFinish(String instanceId, String callback); int callUpdateAttrs(String instanceId, String ref, String task, String callback); int callUpdateStyle(String instanceId, String ref, String task, String callback); int callRemoveElement(String instanceId, String ref, String callback); int callMoveElement(String instanceId, String ref, String parentref, String index, String callback); int callAddEvent(String instanceId, String ref, String event, String callback); int callRemoveEvent(String instanceId, String ref, String event, String callback); int callAddElement(String instanceId, String ref,String dom,String index, String callback); synchronized void initScriptsFramework(String framework); @Deprecated void fireEvent(final String instanceId, final String ref,
                        final String type, final Map<String, Object> data); @Deprecated void fireEvent(final String instanceId, final String ref,
                        final String type, final Map<String, Object> data,final Map<String, Object> domChanges); void fireEventOnNode(final String instanceId, final String ref,
                        final String type, final Map<String, Object> data,final Map<String, Object> domChanges); @Deprecated void callback(String instanceId, String callback,String data); @Deprecated void callback(final String instanceId, final String callback,
                       final Map<String, Object> data); @Deprecated void callback(final String instanceId, final String callback,
                       final Object data,boolean keepAlive); void refreshInstance(final String instanceId, final WXRefreshData jsonData); void commitJSBridgeAlarmMonitor(String instanceId, WXErrorCode errCode, String errMsg); void commitJSFrameworkAlarmMonitor(final String type, final WXErrorCode errorCode, String errMsg); void createInstance(final String instanceId, final String template,
                             final Map<String, Object> options, final String data); void destroyInstance(final String instanceId); @Override boolean handleMessage(Message msg); void invokeExecJS(String instanceId, String namespace, String function,
                            WXJSObject[] args,boolean logTaskDetail); void registerModules(final Map<String, Object> modules); void registerComponents(final List<Map<String, Object>> components); void execJSService(final String service); void destroy(); void reportJSException(String instanceId, String function,
                                String exception); @Deprecated void notifyTrimMemory(); @Nullable Looper getJSLooper(); void notifySerializeCodeCache(); void takeJSHeapSnapshot(String filename); }
WXBridgeManager implements Callback,BactchExecutor { public int callNative(String instanceId, String tasks, String callback) { if (TextUtils.isEmpty(tasks)) { if (WXEnvironment.isApkDebugable()) { WXLogUtils.e("[WXBridgeManager] callNative: call Native tasks is null"); } commitJSBridgeAlarmMonitor(instanceId, WXErrorCode.WX_ERR_INVOKE_NATIVE,"[WXBridgeManager] callNative: call Native tasks is null"); return IWXBridge.INSTANCE_RENDERING_ERROR; } if (WXEnvironment.isApkDebugable()) { mLodBuilder.append("[WXBridgeManager] callNative >>>> instanceId:").append(instanceId) .append(", tasks:").append(tasks).append(", callback:").append(callback); WXLogUtils.d(mLodBuilder.substring(0)); mLodBuilder.setLength(0); } if(mDestroyedInstanceId!=null &&mDestroyedInstanceId.contains(instanceId)){ return IWXBridge.DESTROY_INSTANCE; } long start = System.currentTimeMillis(); JSONArray array = JSON.parseArray(tasks); if(WXSDKManager.getInstance().getSDKInstance(instanceId)!=null) { WXSDKManager.getInstance().getSDKInstance(instanceId).jsonParseTime(System.currentTimeMillis() - start); } int size = array.size(); if (size > 0) { try { JSONObject task; for (int i = 0; i < size; ++i) { task = (JSONObject) array.get(i); if (task != null && WXSDKManager.getInstance().getSDKInstance(instanceId) != null) { Object target = task.get(MODULE); Object method = task.get(METHOD); if(target != null){ if(WXDomModule.WXDOM.equals(target) ){ WXDomModule dom = getDomModule(instanceId); dom.callDomMethod(task); }else { callModuleMethod(instanceId, (String) target, (String) task.get(METHOD), (JSONArray) task.get(ARGS)); } }else if(task.get(COMPONENT) != null){ WXDomModule dom = getDomModule(instanceId); dom.invokeMethod((String) task.get(REF),(String) task.get(METHOD),(JSONArray) task.get(ARGS)); }else{ throw new IllegalArgumentException("unknown callNative"); } } } } catch (Exception e) { WXLogUtils.e("[WXBridgeManager] callNative exception: ", e); commitJSBridgeAlarmMonitor(instanceId, WXErrorCode.WX_ERR_INVOKE_NATIVE,"[WXBridgeManager] callNative exception "+e.getCause()); } } if (UNDEFINED.equals(callback) || NON_CALLBACK.equals(callback)) { return IWXBridge.INSTANCE_RENDERING_ERROR; } getNextTick(instanceId, callback); return IWXBridge.INSTANCE_RENDERING; } private  WXBridgeManager(); static WXBridgeManager getInstance(); void stopRemoteDebug(); Object callModuleMethod(String instanceId, String moduleStr, String methodStr, JSONArray args); void restart(); synchronized void setStackTopInstance(final String instanceId); @Override void post(Runnable r); @Override void setInterceptor(Interceptor interceptor); void post(Runnable r, Object token); void sendMessageDelayed(Message message, long delayMillis); void removeMessage(int what,Object obj); Object callNativeModule(String instanceId, String module, String method, JSONArray arguments, Object options); Object callNativeComponent(String instanceId, String componentRef, String method, JSONArray arguments, Object options); int callNative(String instanceId, String tasks, String callback); int callCreateBody(String instanceId, String tasks, String callback); int callUpdateFinish(String instanceId, String callback); int callCreateFinish(String instanceId, String callback); int callRefreshFinish(String instanceId, String callback); int callUpdateAttrs(String instanceId, String ref, String task, String callback); int callUpdateStyle(String instanceId, String ref, String task, String callback); int callRemoveElement(String instanceId, String ref, String callback); int callMoveElement(String instanceId, String ref, String parentref, String index, String callback); int callAddEvent(String instanceId, String ref, String event, String callback); int callRemoveEvent(String instanceId, String ref, String event, String callback); int callAddElement(String instanceId, String ref,String dom,String index, String callback); synchronized void initScriptsFramework(String framework); @Deprecated void fireEvent(final String instanceId, final String ref,
                        final String type, final Map<String, Object> data); @Deprecated void fireEvent(final String instanceId, final String ref,
                        final String type, final Map<String, Object> data,final Map<String, Object> domChanges); void fireEventOnNode(final String instanceId, final String ref,
                        final String type, final Map<String, Object> data,final Map<String, Object> domChanges); @Deprecated void callback(String instanceId, String callback,String data); @Deprecated void callback(final String instanceId, final String callback,
                       final Map<String, Object> data); @Deprecated void callback(final String instanceId, final String callback,
                       final Object data,boolean keepAlive); void refreshInstance(final String instanceId, final WXRefreshData jsonData); void commitJSBridgeAlarmMonitor(String instanceId, WXErrorCode errCode, String errMsg); void commitJSFrameworkAlarmMonitor(final String type, final WXErrorCode errorCode, String errMsg); void createInstance(final String instanceId, final String template,
                             final Map<String, Object> options, final String data); void destroyInstance(final String instanceId); @Override boolean handleMessage(Message msg); void invokeExecJS(String instanceId, String namespace, String function,
                            WXJSObject[] args,boolean logTaskDetail); void registerModules(final Map<String, Object> modules); void registerComponents(final List<Map<String, Object>> components); void execJSService(final String service); void destroy(); void reportJSException(String instanceId, String function,
                                String exception); @Deprecated void notifyTrimMemory(); @Nullable Looper getJSLooper(); void notifySerializeCodeCache(); void takeJSHeapSnapshot(String filename); static final String METHOD_CREATE_INSTANCE; static final String METHOD_DESTROY_INSTANCE; static final String METHOD_CALL_JS; static final String METHOD_SET_TIMEOUT; static final String METHOD_REGISTER_MODULES; static final String METHOD_REGISTER_COMPONENTS; static final String METHOD_FIRE_EVENT; static final String METHOD_CALLBACK; static final String METHOD_REFRESH_INSTANCE; static final String METHOD_NOTIFY_TRIM_MEMORY; static final String METHOD_NOTIFY_SERIALIZE_CODE_CACHE; static final String KEY_METHOD; static final String KEY_ARGS; static final String COMPONENT; static final String REF; static final String MODULE; static final String METHOD; static final String ARGS; }