public void exec(final String service,final String action,final String callbackId,final String rawArgs){
  CordovaPlugin plugin=getPlugin(service);
  if (plugin == null) {
    Log.d(TAG,"exec() call to unknown plugin: " + service);
    PluginResult cr=new PluginResult(PluginResult.Status.CLASS_NOT_FOUND_EXCEPTION);
    app.sendPluginResult(cr,callbackId);
    return;
  }
  CallbackContext callbackContext=new CallbackContext(callbackId,app);
  try {
    long pluginStartTime=System.currentTimeMillis();
    boolean wasValidAction=plugin.execute(action,rawArgs,callbackContext);
    long duration=System.currentTimeMillis() - pluginStartTime;
    if (duration > SLOW_EXEC_WARNING_THRESHOLD) {
      Log.w(TAG,"THREAD WARNING: exec() call to " + service + "."+ action+ " blocked the main thread for "+ duration+ "ms. Plugin should use CordovaInterface.getThreadPool().");
    }
    if (!wasValidAction) {
      PluginResult cr=new PluginResult(PluginResult.Status.INVALID_ACTION);
      callbackContext.sendPluginResult(cr);
    }
  }
 catch (  JSONException e) {
    PluginResult cr=new PluginResult(PluginResult.Status.JSON_EXCEPTION);
    callbackContext.sendPluginResult(cr);
  }
catch (  Exception e) {
    Log.e(TAG,"Uncaught exception from plugin",e);
    callbackContext.error(e.getMessage());
  }
}

public void exec ( final String service , final String action , final String callbackId , final String rawArgs ) { CordovaPlugin plugin = getPlugin ( service ) ; if ( plugin == null ) { Log . d ( TAG , "exec() call to unknown plugin: " + service ) ; PluginResult cr = new PluginResult ( PluginResult . Status . CLASS_NOT_FOUND_EXCEPTION ) ; app . sendPluginResult ( cr , callbackId ) ; return ; } CallbackContext callbackContext = new CallbackContext ( callbackId , app ) ; try { long pluginStartTime = System . currentTimeMillis ( ) ; boolean wasValidAction = plugin . execute ( action , rawArgs , callbackContext ) ; long duration = System . currentTimeMillis ( ) - pluginStartTime ; if ( duration > SLOW_EXEC_WARNING_THRESHOLD ) { Log . w ( TAG , "THREAD WARNING: exec() call to " + service + "." + action + " blocked the main thread for " + duration + "ms. Plugin should use CordovaInterface.getThreadPool()." ) ; } if ( ! wasValidAction ) { PluginResult cr = new PluginResult ( PluginResult . Status . INVALID_ACTION ) ; callbackContext . sendPluginResult ( cr ) ; } } catch ( JSONException e ) { PluginResult cr = new PluginResult ( PluginResult . Status . JSON_EXCEPTION ) ; callbackContext . sendPluginResult ( cr ) ; } catch ( Exception e ) { Log . e ( TAG , "Uncaught exception from plugin" , e ) ; callbackContext . error ( e . getMessage ( ) ) ; } }
receives a request for execution and fulfills it by finding the appropriate java class and calling it ' s execute method . pluginmanager . exec can be used either synchronously or async . in either case , a json encoded string is returned that will indicate if any errors have occurred when trying to find or execute the class denoted by the clazz argument .
