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"); } WXErrorCode.WX_ERR_INVOKE_NATIVE.appendErrMsg("[WXBridgeManager] callNative: call Native tasks is null"); commitJSBridgeAlarmMonitor(instanceId, WXErrorCode.WX_ERR_INVOKE_NATIVE); 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) { if (TextUtils.equals(WXDomModule.WXDOM, (String) task.get(MODULE))) { sDomModule = getDomModule(instanceId); sDomModule.callDomMethod(task); sDomModule.mWXSDKInstance = null; } else { WXModuleManager.callModuleMethod(instanceId, (String) task.get(MODULE), (String) task.get(METHOD), (JSONArray) task.get(ARGS)); } } } } catch (Exception e) { WXLogUtils.e("[WXBridgeManager] callNative exception: ", e); WXErrorCode.WX_ERR_INVOKE_NATIVE.appendErrMsg("[WXBridgeManager] callNative exception "+e.getCause()); commitJSBridgeAlarmMonitor(instanceId, WXErrorCode.WX_ERR_INVOKE_NATIVE); } } if (UNDEFINED.equals(callback)) { return IWXBridge.INSTANCE_RENDERING_ERROR; } getNextTick(instanceId, callback); return IWXBridge.INSTANCE_RENDERING; } private  WXBridgeManager(); static WXBridgeManager getInstance(); boolean 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); int callNative(String instanceId, String tasks, 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); void commitAlert(final String type, final WXErrorCode errorCode); 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 registerModules(final Map<String, Object> modules); void registerComponents(final List<Map<String, String>> components); void destroy(); void reportJSException(String instanceId, String function,
                                String exception); 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 KEY_METHOD; static final String KEY_ARGS; static final String MODULE; static final String METHOD; static final String ARGS; }
@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); }