private DeviceResponse getIsNaturalOrientation() { d(uiaDaemon_logcatTag, "Getting 'isNaturalOrientation'"); this.device.waitForIdle(); DeviceResponse deviceResponse = new DeviceResponse(); deviceResponse.isNaturalOrientation = device.isNaturalOrientation(); return deviceResponse; }
@TargetApi(Build.VERSION_CODES.FROYO) private DeviceResponse performAction(DeviceCommand deviceCommand) throws UiAutomatorDaemonException { Log.v(uiaDaemon_logcatTag, "Performing GUI action"); GuiAction action = deviceCommand.guiAction; // Log.e(uiaDaemon_logcatTag, "==========="); // Log.e(uiaDaemon_logcatTag, action.guiActionCommand); // Log.e(uiaDaemon_logcatTag, "==========="); if (action.guiActionCommand != null) { // Explanation for turning off the 'IfCanBeSwitch' inspection: // the ant script used for building this source uses Java 1.5 in which switch over strings is // not supported. //noinspection IfCanBeSwitch if (action.guiActionCommand.equals(guiActionCommand_pressBack)) { d(uiaDaemon_logcatTag, "Pressing 'back' button."); this.device.pressBack(); waitForGuiToStabilize(); } else if (action.guiActionCommand.equals(guiActionCommand_pressHome)) { d(uiaDaemon_logcatTag, "Pressing 'home' button."); this.device.pressHome(); waitForGuiToStabilize(); } else if (action.guiActionCommand.equals(guiActionCommand_turnWifiOn)) { turnWifiOn(); } else if (action.guiActionCommand.startsWith(guiActionCommand_loadXPrivacyConfig)) { loadXPrivacyConfig(action.guiActionCommand); } else if (action.guiActionCommand.equals(guiActionCommand_launchApp)) { launchApp(action.resourceId); } else { throw new UiAutomatorDaemonException( String.format("Unrecognized GUI action command: %s", action.guiActionCommand)); } } else if (deviceCommand.guiAction.resourceId != null) { d( uiaDaemon_logcatTag, String.format( "Setting text of widget with resource ID %s to %s.", deviceCommand.guiAction.resourceId, deviceCommand.guiAction.textToEnter)); try { boolean enterResult = this.device .findObject(new UiSelector().resourceId(deviceCommand.guiAction.resourceId)) .setText(deviceCommand.guiAction.textToEnter); if (enterResult) waitForGuiToStabilize(); if (!enterResult) Log.w( uiaDaemon_logcatTag, String.format( "Failed to enter text in widget with resource id: %s", deviceCommand.guiAction.resourceId)); } catch (UiObjectNotFoundException e) { throw new AssertionError( "Assertion error: UIObject not found. ResourceId: " + deviceCommand.guiAction.resourceId); } } else { int clickXCoor = deviceCommand.guiAction.clickXCoor; int clickYCoor = deviceCommand.guiAction.clickYCoor; d( uiaDaemon_logcatTag, String.format("Clicking on (x,y) coordinates of (%d,%d)", clickXCoor, clickYCoor)); if (clickXCoor < 0) throw new AssertionError("assert clickXCoor >= 0"); if (clickYCoor < 0) throw new AssertionError("assert clickYCoor >= 0"); if (clickXCoor > this.device.getDisplayWidth()) throw new AssertionError("assert clickXCoor <= device.getDisplayWidth()"); if (clickYCoor > this.device.getDisplayHeight()) throw new AssertionError("assert clickXCoor <= device.getDisplayHeight()"); // WISH return clickResult in deviceResponse, so we can try to click again on 'app has // stopped' and other dialog boxes. Right now there is just last chance attempt in // org.droidmate.exploration.VerifiableDeviceActionsExecutor.executeAndVerify() boolean clickResult; clickResult = click(deviceCommand, clickXCoor, clickYCoor); if (!clickResult) { d( uiaDaemon_logcatTag, (String.format( "The operation device.click(%d, %d) failed (the 'click' method returned 'false'). Retrying after 2 seconds.", clickXCoor, clickYCoor))); try { Thread.sleep(2000); } catch (InterruptedException e) { Log.w( uiaDaemon_logcatTag, "InterruptedException while sleeping before repeating a click."); } clickResult = click(deviceCommand, clickXCoor, clickYCoor); // WISH what does it actually mean that click failed? if (!clickResult) { Log.w( uiaDaemon_logcatTag, (String.format( "The operation ui.getUiDevice().click(%d, %d) failed for the second time. Giving up.", clickXCoor, clickYCoor))); } else d(uiaDaemon_logcatTag, "The click retry attempt succeeded."); } } DeviceResponse deviceResponse = new DeviceResponse(); deviceResponse.isNaturalOrientation = this.device.isNaturalOrientation(); return deviceResponse; }