Added support for global action APIs and fixed WaitForIdle
- Added openNotification and openQuickSettings to UiDevice.
- Adjusted for all UiDevice presses and special key injections
to perform waitForIdle after each operation.
- Also screen rotations did not perform waitForIdle and now
they do.
Change-Id: I15784c62278a4f712d08fd081634f48d5dbcabc8
diff --git a/uiautomator/api/current.txt b/uiautomator/api/current.txt
index cafdb3d..1bc6a72 100644
--- a/uiautomator/api/current.txt
+++ b/uiautomator/api/current.txt
@@ -41,6 +41,8 @@
method public boolean hasWatcherTriggered(java.lang.String);
method public boolean isNaturalOrientation();
method public boolean isScreenOn() throws android.os.RemoteException;
+ method public boolean openNotification();
+ method public boolean openQuickSettings();
method public boolean pressBack();
method public boolean pressDPadCenter();
method public boolean pressDPadDown();
diff --git a/uiautomator/library/core-src/com/android/uiautomator/core/InteractionController.java b/uiautomator/library/core-src/com/android/uiautomator/core/InteractionController.java
index e05d5eb..bec318f 100644
--- a/uiautomator/library/core-src/com/android/uiautomator/core/InteractionController.java
+++ b/uiautomator/library/core-src/com/android/uiautomator/core/InteractionController.java
@@ -756,7 +756,36 @@
injectEventSync(event);
}
+ /**
+ * Simulates a short press on the Recent Apps button.
+ *
+ * @return true if successful, else return false
+ * @since API Level 18
+ */
public boolean toggleRecentApps() {
- return mUiAutomatorBridge.performGlobalAction(AccessibilityService.GLOBAL_ACTION_RECENTS);
+ return mUiAutomatorBridge.performGlobalAction(
+ AccessibilityService.GLOBAL_ACTION_RECENTS);
+ }
+
+ /**
+ * Opens the notification shade
+ *
+ * @return true if successful, else return false
+ * @since API Level 18
+ */
+ public boolean openNotification() {
+ return mUiAutomatorBridge.performGlobalAction(
+ AccessibilityService.GLOBAL_ACTION_NOTIFICATIONS);
+ }
+
+ /**
+ * Opens the quick settings shade
+ *
+ * @return true if successful, else return false
+ * @since API Level 18
+ */
+ public boolean openQuickSettings() {
+ return mUiAutomatorBridge.performGlobalAction(
+ AccessibilityService.GLOBAL_ACTION_QUICK_SETTINGS);
}
}
diff --git a/uiautomator/library/core-src/com/android/uiautomator/core/UiDevice.java b/uiautomator/library/core-src/com/android/uiautomator/core/UiDevice.java
index 39c37b4..de7e760 100644
--- a/uiautomator/library/core-src/com/android/uiautomator/core/UiDevice.java
+++ b/uiautomator/library/core-src/com/android/uiautomator/core/UiDevice.java
@@ -186,10 +186,11 @@
*/
public boolean pressMenu() {
Tracer.trace();
- waitForIdle();
- return mUiAutomationBridge.getInteractionController().sendKeyAndWaitForEvent(
+ boolean ret = mUiAutomationBridge.getInteractionController().sendKeyAndWaitForEvent(
KeyEvent.KEYCODE_MENU, 0, AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED,
KEY_PRESS_EVENT_TIMEOUT);
+ waitForIdle();
+ return ret;
}
/**
@@ -199,10 +200,11 @@
*/
public boolean pressBack() {
Tracer.trace();
- waitForIdle();
- return mUiAutomationBridge.getInteractionController().sendKeyAndWaitForEvent(
+ boolean ret = mUiAutomationBridge.getInteractionController().sendKeyAndWaitForEvent(
KeyEvent.KEYCODE_BACK, 0, AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED,
KEY_PRESS_EVENT_TIMEOUT);
+ waitForIdle();
+ return ret;
}
/**
@@ -212,10 +214,11 @@
*/
public boolean pressHome() {
Tracer.trace();
- waitForIdle();
- return mUiAutomationBridge.getInteractionController().sendKeyAndWaitForEvent(
+ boolean ret = mUiAutomationBridge.getInteractionController().sendKeyAndWaitForEvent(
KeyEvent.KEYCODE_HOME, 0, AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED,
KEY_PRESS_EVENT_TIMEOUT);
+ waitForIdle();
+ return ret;
}
/**
@@ -307,8 +310,9 @@
*/
public boolean pressKeyCode(int keyCode) {
Tracer.trace(keyCode);
+ boolean ret = mUiAutomationBridge.getInteractionController().sendKey(keyCode, 0);
waitForIdle();
- return mUiAutomationBridge.getInteractionController().sendKey(keyCode, 0);
+ return ret;
}
/**
@@ -322,8 +326,9 @@
*/
public boolean pressKeyCode(int keyCode, int metaState) {
Tracer.trace(keyCode, metaState);
+ boolean ret = mUiAutomationBridge.getInteractionController().sendKey(keyCode, metaState);
waitForIdle();
- return mUiAutomationBridge.getInteractionController().sendKey(keyCode, metaState);
+ return ret;
}
/**
@@ -335,8 +340,35 @@
*/
public boolean pressRecentApps() throws RemoteException {
Tracer.trace();
+ boolean ret = getAutomatorBridge().getInteractionController().toggleRecentApps();
waitForIdle();
- return getAutomatorBridge().getInteractionController().toggleRecentApps();
+ return ret;
+ }
+
+ /**
+ * Opens the notification shade
+ *
+ * @return true if successful, else return false
+ * @since API Level 18
+ */
+ public boolean openNotification() {
+ Tracer.trace();
+ boolean ret = getAutomatorBridge().getInteractionController().openNotification();
+ waitForIdle();
+ return ret;
+ }
+
+ /**
+ * Opens the quick settings shade
+ *
+ * @return true if successful, else return false
+ * @since API Level 18
+ */
+ public boolean openQuickSettings() {
+ Tracer.trace();
+ boolean ret = getAutomatorBridge().getInteractionController().openQuickSettings();
+ waitForIdle();
+ return ret;
}
/**
@@ -644,6 +676,7 @@
public void setOrientationLeft() throws RemoteException {
Tracer.trace();
getAutomatorBridge().getInteractionController().setRotationLeft();
+ waitForIdle();
}
/**
@@ -658,6 +691,7 @@
public void setOrientationRight() throws RemoteException {
Tracer.trace();
getAutomatorBridge().getInteractionController().setRotationRight();
+ waitForIdle();
}
/**
@@ -672,6 +706,7 @@
public void setOrientationNatural() throws RemoteException {
Tracer.trace();
getAutomatorBridge().getInteractionController().setRotationNatural();
+ waitForIdle();
}
/**