spawn a child asynchronously @param handler name of the handler @param cmd arguments for the child @param env custom environment variables @param receiver receiver for events fired by the child @return the spawned org.csploit.android.core.Child @throws ChildNotStartedExceptio
(String handler, String cmd, String[] env, EventReceiver receiver)
| 79 | * @throws ChildNotStartedException when cannot start a child. |
| 80 | */ |
| 81 | public static Child async(String handler, String cmd, String[] env, EventReceiver receiver) throws ChildNotStartedException { |
| 82 | Child c; |
| 83 | |
| 84 | c = new Child(); |
| 85 | |
| 86 | c.id = Client.StartCommand(handler, cmd, env); |
| 87 | if (c.id == -1) { |
| 88 | Logger.debug(String.format("{ handler='%s', cmd='%s' } => FAILED", handler, cmd)); |
| 89 | throw new ChildNotStartedException(); |
| 90 | } |
| 91 | |
| 92 | Logger.debug(String.format("{ handler='%s', cmd='%s' } => %d", handler, cmd, c.id)); |
| 93 | |
| 94 | c.running = true; |
| 95 | c.receiver = receiver; |
| 96 | |
| 97 | if(c.receiver!=null) |
| 98 | c.receiver.onStart(cmd); |
| 99 | |
| 100 | synchronized (children) { |
| 101 | children.add(c); |
| 102 | children.notifyAll(); |
| 103 | } |
| 104 | |
| 105 | return c; |
| 106 | } |
| 107 | |
| 108 | public static Child async(String handler, String cmd) throws ChildNotStartedException { |
| 109 | return async(handler, cmd, null, null); |
no test coverage detected