Source:
<code>public Response safeHandle(HttpRequest request) throws JSONException { SelendroidLogger.info("Got actions request"); JSONArray payload = getPayload(request).getJSONArray("payload"); int actionChainCount = payload.length(); boolean stillRunning = true; boolean allPaused; List<ActionChain> actionChains = new ArrayList<ActionChain>(); for (int i = 0; i < actionChainCount; i++) { actionChains.add(new ActionChain(payload.getJSONObject(i))); } while (stillRunning) { stillRunning = false; allPaused = true; for (ActionChain chain : actionChains) { if (chain.isPaused()) { stillRunning = true; } else if (chain.hasNext()) { stillRunning = true; JSONObject action = chain.next(); String actionName = action.getString("name"); SelendroidLogger.info("Performing action " + chain.getInputDevice() + "/" + actionName); if (!actionName.equals(TouchActionName.PAUSE)) { allPaused = false; ActionHandler handler = ActionHandler.getHandlerForInputDevice(chain.getInputDevice()); handler.handle(actionName, getSelendroidDriver(request), action, chain.getContext()); } } } if(allPaused) { <START> int pauseTime = shortestPause(actionChains); <END> try { Thread.sleep(pauseTime); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } updatePauseTimes(actionChains, pauseTime); } } return new SelendroidResponse(getSessionId(request), ""); }</code><technical_language>so, this shortest pause, original 'longest' pause. intention of multi-action chains is gate 'tick' other actions tick. [ [down, pause 10, release], [pause 0, pause 1, tap] ] This result in tap performed 9 seconds release. This example payload perform "down" command, a 10 pause (the longest) in 'tick', release tap "same" time (the release get called first, tap) Also... original proposed flawed finding sleep interval be. determined in current 'tick' of action chain, searching entire payload (or actionChains) time</technical_language>

Target:
public Response safeHandle(HttpRequest request) throws JSONException { SelendroidLogger.info("Got actions request"); JSONArray payload = getPayload(request).getJSONArray("payload"); int actionChainCount = payload.length(); boolean stillRunning = true; int longestPause; List<ActionChain> actionChains = new ArrayList<ActionChain>(); for (int i = 0; i < actionChainCount; i++) { actionChains.add(new ActionChain(payload.getJSONObject(i))); } while (stillRunning) { longestPause = 0; stillRunning = false; for (ActionChain chain : actionChains) { if (chain.hasNext()) { stillRunning = true; JSONObject action = chain.next(); String actionName = action.getString("name"); SelendroidLogger.info("Performing action " + chain.getInputDevice() + "/" + actionName); if (actionName.equals(TouchActionName.PAUSE)) { if (chain.getPauseTime() > longestPause) { longestPause = chain.getPauseTime(); } } else { ActionHandler handler = ActionHandler.getHandlerForInputDevice(chain.getInputDevice()); handler.handle(actionName, getSelendroidDriver(request), action, chain.getContext()); } } } if (longestPause > 0) { try { Thread.sleep(longestPause); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } } return new SelendroidResponse(getSessionId(request), ""); }