diff options
author | Adam Momtaz <amomtaz@google.com> | 2013-05-09 18:50:45 -0700 |
---|---|---|
committer | Adam Momtaz <amomtaz@google.com> | 2013-05-10 12:18:39 -0700 |
commit | 5dfbc26b70c57c1708c24ed6043bbc550bfc83f1 (patch) | |
tree | c03d467659a32fdae2f584526f41c01059ded5c9 | |
parent | f272fb3892c4ed8cf473e4fe6cd5320cbffa9a34 (diff) | |
download | testing-5dfbc26b70c57c1708c24ed6043bbc550bfc83f1.tar.gz |
Fix for UiDevice press button operations wait for idle
This cl#299334 attempted to address a missing wait for idle
on the UiDevice main pressXXX operation since issues related to
reliability were surfacing. These are pressHome, pressBack
and pressMenu. In error, I added the waitForIdle after and
not before the operation where it should've been in the first place.
Operations should never count on other operations to guarantee
waitForIdle for them. Each operation should ensure its own device
idle before performing any action. The existing implementation
unfortunately didn't improve the reliability and issues remained.
This fix should put these pressXXX commands inline with all the
UiAutomator APIs where everything performs a waitForIdle _before_
performing any action.
Change-Id: I76d7ec50fb822d41a0be4808a0d3e61bdde17935
-rw-r--r-- | uiautomator/library/core-src/com/android/uiautomator/core/UiDevice.java | 37 |
1 files changed, 15 insertions, 22 deletions
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 de7e760..5a2f3a7 100644 --- a/uiautomator/library/core-src/com/android/uiautomator/core/UiDevice.java +++ b/uiautomator/library/core-src/com/android/uiautomator/core/UiDevice.java @@ -186,11 +186,10 @@ public class UiDevice { */ public boolean pressMenu() { Tracer.trace(); - boolean ret = mUiAutomationBridge.getInteractionController().sendKeyAndWaitForEvent( + waitForIdle(); + return mUiAutomationBridge.getInteractionController().sendKeyAndWaitForEvent( KeyEvent.KEYCODE_MENU, 0, AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED, KEY_PRESS_EVENT_TIMEOUT); - waitForIdle(); - return ret; } /** @@ -200,11 +199,10 @@ public class UiDevice { */ public boolean pressBack() { Tracer.trace(); - boolean ret = mUiAutomationBridge.getInteractionController().sendKeyAndWaitForEvent( + waitForIdle(); + return mUiAutomationBridge.getInteractionController().sendKeyAndWaitForEvent( KeyEvent.KEYCODE_BACK, 0, AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED, KEY_PRESS_EVENT_TIMEOUT); - waitForIdle(); - return ret; } /** @@ -214,11 +212,10 @@ public class UiDevice { */ public boolean pressHome() { Tracer.trace(); - boolean ret = mUiAutomationBridge.getInteractionController().sendKeyAndWaitForEvent( + waitForIdle(); + return mUiAutomationBridge.getInteractionController().sendKeyAndWaitForEvent( KeyEvent.KEYCODE_HOME, 0, AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED, KEY_PRESS_EVENT_TIMEOUT); - waitForIdle(); - return ret; } /** @@ -310,9 +307,8 @@ public class UiDevice { */ public boolean pressKeyCode(int keyCode) { Tracer.trace(keyCode); - boolean ret = mUiAutomationBridge.getInteractionController().sendKey(keyCode, 0); waitForIdle(); - return ret; + return mUiAutomationBridge.getInteractionController().sendKey(keyCode, 0); } /** @@ -326,9 +322,8 @@ public class UiDevice { */ public boolean pressKeyCode(int keyCode, int metaState) { Tracer.trace(keyCode, metaState); - boolean ret = mUiAutomationBridge.getInteractionController().sendKey(keyCode, metaState); waitForIdle(); - return ret; + return mUiAutomationBridge.getInteractionController().sendKey(keyCode, metaState); } /** @@ -340,9 +335,8 @@ public class UiDevice { */ public boolean pressRecentApps() throws RemoteException { Tracer.trace(); - boolean ret = getAutomatorBridge().getInteractionController().toggleRecentApps(); waitForIdle(); - return ret; + return getAutomatorBridge().getInteractionController().toggleRecentApps(); } /** @@ -353,9 +347,8 @@ public class UiDevice { */ public boolean openNotification() { Tracer.trace(); - boolean ret = getAutomatorBridge().getInteractionController().openNotification(); waitForIdle(); - return ret; + return getAutomatorBridge().getInteractionController().openNotification(); } /** @@ -366,9 +359,8 @@ public class UiDevice { */ public boolean openQuickSettings() { Tracer.trace(); - boolean ret = getAutomatorBridge().getInteractionController().openQuickSettings(); waitForIdle(); - return ret; + return getAutomatorBridge().getInteractionController().openQuickSettings(); } /** @@ -627,6 +619,7 @@ public class UiDevice { */ public boolean isNaturalOrientation() { Tracer.trace(); + waitForIdle(); int ret = mUiAutomationBridge.getRotation(); return ret == UiAutomation.ROTATION_FREEZE_0 || ret == UiAutomation.ROTATION_FREEZE_180; @@ -676,7 +669,7 @@ public class UiDevice { public void setOrientationLeft() throws RemoteException { Tracer.trace(); getAutomatorBridge().getInteractionController().setRotationLeft(); - waitForIdle(); + waitForIdle(); // we don't need to check for idle on entry for this. We'll sync on exit } /** @@ -691,7 +684,7 @@ public class UiDevice { public void setOrientationRight() throws RemoteException { Tracer.trace(); getAutomatorBridge().getInteractionController().setRotationRight(); - waitForIdle(); + waitForIdle(); // we don't need to check for idle on entry for this. We'll sync on exit } /** @@ -706,7 +699,7 @@ public class UiDevice { public void setOrientationNatural() throws RemoteException { Tracer.trace(); getAutomatorBridge().getInteractionController().setRotationNatural(); - waitForIdle(); + waitForIdle(); // we don't need to check for idle on entry for this. We'll sync on exit } /** |