summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuang Zhu <guangzhu@google.com>2013-09-19 19:09:53 -0700
committerGuang Zhu <guangzhu@google.com>2013-09-19 19:16:31 -0700
commitb6bcdebde2bb031ad2e9b20cdf68ce5a3718048a (patch)
treeb54c46ed999c0be3682d85f6f39148b1c1978ede
parentdc86da8036955064aa3f3767b3dd8e02aa273d72 (diff)
downloaduiautomator-b6bcdebde2bb031ad2e9b20cdf68ce5a3718048a.tar.gz
shuffling unbundled UI automator source code
* remove shell based UI automator code * port API checks from shell based to instrumentation based UI automator makefile * reorganize code structure Bug: 10793010 Change-Id: I936ded6c73f037fa15466b184826b14a1a204074
-rw-r--r--Android.mk117
-rw-r--r--api/0.txt (renamed from api/17.txt)42
-rw-r--r--api/16.txt174
-rw-r--r--api/current.txt8
-rw-r--r--apicheck_msg_current.txt (renamed from library/apicheck_msg_current.txt)0
-rw-r--r--apicheck_msg_last.txt (renamed from library/apicheck_msg_last.txt)0
-rw-r--r--core/com/android/uiautomator/core/AccessibilityNodeInfoDumper.java (renamed from library/core-src/com/android/uiautomator/core/AccessibilityNodeInfoDumper.java)0
-rw-r--r--core/com/android/uiautomator/core/AccessibilityNodeInfoHelper.java (renamed from library/core-src/com/android/uiautomator/core/AccessibilityNodeInfoHelper.java)0
-rw-r--r--core/com/android/uiautomator/core/Configurator.java (renamed from library/core-src/com/android/uiautomator/core/Configurator.java)0
-rw-r--r--core/com/android/uiautomator/core/InteractionController.java (renamed from library/core-src/com/android/uiautomator/core/InteractionController.java)0
-rw-r--r--core/com/android/uiautomator/core/QueryController.java (renamed from library/core-src/com/android/uiautomator/core/QueryController.java)0
-rw-r--r--core/com/android/uiautomator/core/Tracer.java (renamed from library/core-src/com/android/uiautomator/core/Tracer.java)0
-rw-r--r--core/com/android/uiautomator/core/UiAutomatorBridge.java (renamed from library/core-src/com/android/uiautomator/core/UiAutomatorBridge.java)0
-rw-r--r--core/com/android/uiautomator/core/UiCollection.java (renamed from library/core-src/com/android/uiautomator/core/UiCollection.java)0
-rw-r--r--core/com/android/uiautomator/core/UiDevice.java (renamed from library/core-src/com/android/uiautomator/core/UiDevice.java)0
-rw-r--r--core/com/android/uiautomator/core/UiObject.java (renamed from library/core-src/com/android/uiautomator/core/UiObject.java)0
-rw-r--r--core/com/android/uiautomator/core/UiObjectNotFoundException.java (renamed from library/core-src/com/android/uiautomator/core/UiObjectNotFoundException.java)0
-rw-r--r--core/com/android/uiautomator/core/UiScrollable.java (renamed from library/core-src/com/android/uiautomator/core/UiScrollable.java)0
-rw-r--r--core/com/android/uiautomator/core/UiSelector.java (renamed from library/core-src/com/android/uiautomator/core/UiSelector.java)0
-rw-r--r--core/com/android/uiautomator/core/UiWatcher.java (renamed from library/core-src/com/android/uiautomator/core/UiWatcher.java)0
-rw-r--r--instrumentation/Android.mk27
-rw-r--r--library/Android.mk123
-rw-r--r--library/testrunner-src/com/android/uiautomator/core/ShellUiAutomatorBridge.java122
-rw-r--r--library/testrunner-src/com/android/uiautomator/core/UiAutomationShellWrapper.java127
-rw-r--r--library/testrunner-src/com/android/uiautomator/testrunner/IAutomationSupport.java37
-rw-r--r--library/testrunner-src/com/android/uiautomator/testrunner/TestCaseCollector.java152
-rw-r--r--library/testrunner-src/com/android/uiautomator/testrunner/UiAutomatorTestCase.java147
-rw-r--r--library/testrunner-src/com/android/uiautomator/testrunner/UiAutomatorTestCaseFilter.java42
-rw-r--r--library/testrunner-src/com/android/uiautomator/testrunner/UiAutomatorTestRunner.java431
-rw-r--r--testrunner/com/android/uiautomator/core/InstrumentationUiAutomatorBridge.java (renamed from instrumentation/testrunner-src/com/android/uiautomator/core/InstrumentationUiAutomatorBridge.java)0
-rw-r--r--testrunner/com/android/uiautomator/testrunner/IAutomationSupport.java (renamed from instrumentation/testrunner-src/com/android/uiautomator/testrunner/IAutomationSupport.java)0
-rw-r--r--testrunner/com/android/uiautomator/testrunner/InstrumentationAutomationSupport.java (renamed from instrumentation/testrunner-src/com/android/uiautomator/testrunner/InstrumentationAutomationSupport.java)0
-rw-r--r--testrunner/com/android/uiautomator/testrunner/UiAutomatorInstrumentationTestRunner.java (renamed from instrumentation/testrunner-src/com/android/uiautomator/testrunner/UiAutomatorInstrumentationTestRunner.java)0
-rw-r--r--testrunner/com/android/uiautomator/testrunner/UiAutomatorTestCase.java (renamed from instrumentation/testrunner-src/com/android/uiautomator/testrunner/UiAutomatorTestCase.java)0
-rw-r--r--uiautomator_test_libraries/Android.mk33
-rw-r--r--uiautomator_test_libraries/src/com/android/uiautomator/common/UiWatchers.java163
-rw-r--r--uiautomator_test_libraries/src/com/android/uiautomator/common/helpers/AppHelperBase.java96
-rw-r--r--uiautomator_test_libraries/src/com/android/uiautomator/common/helpers/DatePickerHelper.java195
-rw-r--r--uiautomator_test_libraries/src/com/android/uiautomator/common/helpers/TimePickerHelper.java162
-rw-r--r--uiautomator_test_libraries/src/com/android/uiautomator/platform/JankTestBase.java481
-rw-r--r--uiautomator_test_libraries/src/com/android/uiautomator/platform/SurfaceFlingerHelper.java421
-rw-r--r--uiautomator_test_libraries/src/com/android/uiautomator/platform/TestWatchers.java40
42 files changed, 160 insertions, 2980 deletions
diff --git a/Android.mk b/Android.mk
index c141484..d176d69 100644
--- a/Android.mk
+++ b/Android.mk
@@ -14,4 +14,119 @@
# limitations under the License.
#
-include $(call all-subdir-makefiles)
+LOCAL_PATH:= $(call my-dir)
+
+uiautomator.core_src_files := $(call all-java-files-under, testrunner) \
+ $(call all-java-files-under, core)
+#uiautomator.core_java_libraries := android.test.runner core-junit
+
+uiautomator_internal_api_file := $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/uiautomator_api.txt
+
+###############################################
+# Build core library
+include $(CLEAR_VARS)
+
+#LOCAL_MODULE_TAGS := tests
+LOCAL_SRC_FILES := $(uiautomator.core_src_files)
+LOCAL_MODULE := uiautomator
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_STATIC_JAVA_LIBRARY)
+###############################################
+
+
+###############################################
+# Generate the stub source files
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := $(uiautomator.core_src_files)
+LOCAL_SDK_VERSION := current
+#LOCAL_JAVA_LIBRARIES := $(uiautomator.core_java_libraries)
+LOCAL_MODULE_CLASS := JAVA_LIBRARIES
+LOCAL_DROIDDOC_SOURCE_PATH := $(LOCAL_PATH)/core \
+ $(LOCAL_PATH)/testrunner
+LOCAL_DROIDDOC_HTML_DIR :=
+
+LOCAL_DROIDDOC_OPTIONS:= \
+ -stubs $(TARGET_OUT_COMMON_INTERMEDIATES)/JAVA_LIBRARIES/android_uiautomator_intermediates/src \
+ -stubpackages com.android.uiautomator.core:com.android.uiautomator.testrunner \
+ -api $(uiautomator_internal_api_file)
+
+LOCAL_DROIDDOC_CUSTOM_TEMPLATE_DIR := build/tools/droiddoc/templates-sdk
+LOCAL_UNINSTALLABLE_MODULE := true
+
+LOCAL_MODULE := uiautomator-stubs
+
+include $(BUILD_DROIDDOC)
+
+uiautomator_stubs_stamp := $(full_target)
+$(uiautomator_internal_api_file) : $(full_target)
+
+###############################################
+# Build the stub source files into a jar.
+include $(CLEAR_VARS)
+LOCAL_MODULE := android_uiautomator
+LOCAL_SDK_VERSION := current
+#LOCAL_JAVA_LIBRARIES := $(uiautomator.core_java_libraries)
+LOCAL_SOURCE_FILES_ALL_GENERATED := true
+include $(BUILD_STATIC_JAVA_LIBRARY)
+# Make sure to run droiddoc first to generate the stub source files.
+$(full_classes_compiled_jar) : $(uiautomator_stubs_stamp)
+uiautomator_stubs_jar := $(full_classes_compiled_jar)
+
+###############################################
+# API check
+# Please refer to build/core/tasks/apicheck.mk.
+uiautomator_api_dir := frameworks/uiautomator/api
+last_released_sdk_version := $(lastword $(call numerically_sort, \
+ $(filter-out current, \
+ $(patsubst $(uiautomator_api_dir)/%.txt,%, $(wildcard $(uiautomator_api_dir)/*.txt)) \
+ )))
+
+checkapi_last_error_level_flags := \
+ -hide 2 -hide 3 -hide 4 -hide 5 -hide 6 -hide 24 -hide 25 \
+ -error 7 -error 8 -error 9 -error 10 -error 11 -error 12 -error 13 -error 14 -error 15 \
+ -error 16 -error 17 -error 18
+
+# Check that the API we're building hasn't broken the last-released SDK version.
+$(eval $(call check-api, \
+ uiautomator-checkapi-last, \
+ $(uiautomator_api_dir)/$(last_released_sdk_version).txt, \
+ $(uiautomator_internal_api_file), \
+ $(checkapi_last_error_level_flags), \
+ cat $(LOCAL_PATH)/apicheck_msg_last.txt, \
+ $(uiautomator_stubs_jar), \
+ $(uiautomator_stubs_stamp)))
+
+checkapi_current_error_level_flags := \
+ -error 2 -error 3 -error 4 -error 5 -error 6 \
+ -error 7 -error 8 -error 9 -error 10 -error 11 -error 12 -error 13 -error 14 -error 15 \
+ -error 16 -error 17 -error 18 -error 19 -error 20 -error 21 -error 23 -error 24 \
+ -error 25
+
+# Check that the API we're building hasn't changed from the not-yet-released
+# SDK version.
+$(eval $(call check-api, \
+ uiautomator-checkapi-current, \
+ $(uiautomator_api_dir)/current.txt, \
+ $(uiautomator_internal_api_file), \
+ $(checkapi_current_error_level_flags), \
+ cat $(LOCAL_PATH)/apicheck_msg_current.txt, \
+ $(uiautomator_stubs_jar), \
+ $(uiautomator_stubs_stamp)))
+
+.PHONY: update-uiautomator-api
+update-uiautomator-api: PRIVATE_API_DIR := $(uiautomator_api_dir)
+update-uiautomator-api: $(uiautomator_internal_api_file) | $(ACP)
+ @echo Copying uiautomator current.txt
+ $(hide) $(ACP) $< $(PRIVATE_API_DIR)/current.txt
+
+###############################################
+# clean up temp vars
+uiautomator.core_src_files :=
+uiautomator.core_java_libraries :=
+uiautomator_stubs_stamp :=
+uiautomator_internal_api_file :=
+uiautomator_stubs_jar :=
+uiautomator_api_dir :=
+checkapi_last_error_level_flags :=
+checkapi_current_error_level_flags :=
diff --git a/api/17.txt b/api/0.txt
index a1d80c4..aabf23f 100644
--- a/api/17.txt
+++ b/api/0.txt
@@ -1,5 +1,19 @@
package com.android.uiautomator.core {
+ public final class Configurator {
+ method public long getActionAcknowledgmentTimeout();
+ method public static com.android.uiautomator.core.Configurator getInstance();
+ method public long getKeyInjectionDelay();
+ method public long getScrollAcknowledgmentTimeout();
+ method public long getWaitForIdleTimeout();
+ method public long getWaitForSelectorTimeout();
+ method public com.android.uiautomator.core.Configurator setActionAcknowledgmentTimeout(long);
+ method public com.android.uiautomator.core.Configurator setKeyInjectionDelay(long);
+ method public com.android.uiautomator.core.Configurator setScrollAcknowledgmentTimeout(long);
+ method public com.android.uiautomator.core.Configurator setWaitForIdleTimeout(long);
+ method public com.android.uiautomator.core.Configurator setWaitForSelectorTimeout(long);
+ }
+
public class UiCollection extends com.android.uiautomator.core.UiObject {
ctor public UiCollection(com.android.uiautomator.core.UiSelector);
method public com.android.uiautomator.core.UiObject getChildByDescription(com.android.uiautomator.core.UiSelector, java.lang.String) throws com.android.uiautomator.core.UiObjectNotFoundException;
@@ -11,12 +25,14 @@ package com.android.uiautomator.core {
public class UiDevice {
method public void clearLastTraversedText();
method public boolean click(int, int);
+ method public boolean drag(int, int, int, int, int);
method public void dumpWindowHierarchy(java.lang.String);
method public void freezeRotation() throws android.os.RemoteException;
method public deprecated java.lang.String getCurrentActivityName();
method public java.lang.String getCurrentPackageName();
method public int getDisplayHeight();
method public int getDisplayRotation();
+ method public android.graphics.Point getDisplaySizeDp();
method public int getDisplayWidth();
method public static com.android.uiautomator.core.UiDevice getInstance();
method public java.lang.String getLastTraversedText();
@@ -25,6 +41,8 @@ package com.android.uiautomator.core {
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();
@@ -43,6 +61,7 @@ package com.android.uiautomator.core {
method public void removeWatcher(java.lang.String);
method public void resetWatcherTriggers();
method public void runWatchers();
+ method public void setCompressedLayoutHeirarchy(boolean);
method public void setOrientationLeft() throws android.os.RemoteException;
method public void setOrientationNatural() throws android.os.RemoteException;
method public void setOrientationRight() throws android.os.RemoteException;
@@ -66,11 +85,14 @@ package com.android.uiautomator.core {
method public boolean clickAndWaitForNewWindow(long) throws com.android.uiautomator.core.UiObjectNotFoundException;
method public boolean clickBottomRight() throws com.android.uiautomator.core.UiObjectNotFoundException;
method public boolean clickTopLeft() throws com.android.uiautomator.core.UiObjectNotFoundException;
+ method public boolean dragTo(com.android.uiautomator.core.UiObject, int) throws com.android.uiautomator.core.UiObjectNotFoundException;
+ method public boolean dragTo(int, int, int) throws com.android.uiautomator.core.UiObjectNotFoundException;
method public boolean exists();
method protected android.view.accessibility.AccessibilityNodeInfo findAccessibilityNodeInfo(long);
method public android.graphics.Rect getBounds() throws com.android.uiautomator.core.UiObjectNotFoundException;
method public com.android.uiautomator.core.UiObject getChild(com.android.uiautomator.core.UiSelector) throws com.android.uiautomator.core.UiObjectNotFoundException;
method public int getChildCount() throws com.android.uiautomator.core.UiObjectNotFoundException;
+ method public java.lang.String getClassName() throws com.android.uiautomator.core.UiObjectNotFoundException;
method public java.lang.String getContentDescription() throws com.android.uiautomator.core.UiObjectNotFoundException;
method public com.android.uiautomator.core.UiObject getFromParent(com.android.uiautomator.core.UiSelector) throws com.android.uiautomator.core.UiObjectNotFoundException;
method public java.lang.String getPackageName() throws com.android.uiautomator.core.UiObjectNotFoundException;
@@ -89,6 +111,10 @@ package com.android.uiautomator.core {
method public boolean longClick() throws com.android.uiautomator.core.UiObjectNotFoundException;
method public boolean longClickBottomRight() throws com.android.uiautomator.core.UiObjectNotFoundException;
method public boolean longClickTopLeft() throws com.android.uiautomator.core.UiObjectNotFoundException;
+ method public boolean performMultiPointerGesture(android.view.MotionEvent.PointerCoords...);
+ method public boolean performTwoPointerGesture(android.graphics.Point, android.graphics.Point, android.graphics.Point, android.graphics.Point, int);
+ method public boolean pinchIn(int, int) throws com.android.uiautomator.core.UiObjectNotFoundException;
+ method public boolean pinchOut(int, int) throws com.android.uiautomator.core.UiObjectNotFoundException;
method public boolean setText(java.lang.String) throws com.android.uiautomator.core.UiObjectNotFoundException;
method public boolean swipeDown(int) throws com.android.uiautomator.core.UiObjectNotFoundException;
method public boolean swipeLeft(int) throws com.android.uiautomator.core.UiObjectNotFoundException;
@@ -96,10 +122,11 @@ package com.android.uiautomator.core {
method public boolean swipeUp(int) throws com.android.uiautomator.core.UiObjectNotFoundException;
method public boolean waitForExists(long);
method public boolean waitUntilGone(long);
+ field protected static final int FINGER_TOUCH_HALF_WIDTH = 20; // 0x14
field protected static final int SWIPE_MARGIN_LIMIT = 5; // 0x5
- field protected static final long WAIT_FOR_EVENT_TMEOUT = 3000L; // 0xbb8L
+ field protected static final deprecated long WAIT_FOR_EVENT_TMEOUT = 3000L; // 0xbb8L
field protected static final long WAIT_FOR_SELECTOR_POLL = 1000L; // 0x3e8L
- field protected static final long WAIT_FOR_SELECTOR_TIMEOUT = 10000L; // 0x2710L
+ field protected static final deprecated long WAIT_FOR_SELECTOR_TIMEOUT = 10000L; // 0x2710L
field protected static final long WAIT_FOR_WINDOW_TMEOUT = 5500L; // 0x157cL
}
@@ -140,6 +167,7 @@ package com.android.uiautomator.core {
public class UiSelector {
ctor public UiSelector();
+ method public com.android.uiautomator.core.UiSelector checkable(boolean);
method public com.android.uiautomator.core.UiSelector checked(boolean);
method public com.android.uiautomator.core.UiSelector childSelector(com.android.uiautomator.core.UiSelector);
method public com.android.uiautomator.core.UiSelector className(java.lang.String);
@@ -160,6 +188,8 @@ package com.android.uiautomator.core {
method public com.android.uiautomator.core.UiSelector longClickable(boolean);
method public com.android.uiautomator.core.UiSelector packageName(java.lang.String);
method public com.android.uiautomator.core.UiSelector packageNameMatches(java.lang.String);
+ method public com.android.uiautomator.core.UiSelector resourceId(java.lang.String);
+ method public com.android.uiautomator.core.UiSelector resourceIdMatches(java.lang.String);
method public com.android.uiautomator.core.UiSelector scrollable(boolean);
method public com.android.uiautomator.core.UiSelector selected(boolean);
method public com.android.uiautomator.core.UiSelector text(java.lang.String);
@@ -180,9 +210,13 @@ package com.android.uiautomator.testrunner {
method public abstract void sendStatus(int, android.os.Bundle);
}
- public class UiAutomatorTestCase extends junit.framework.TestCase {
+ public class UiAutomatorInstrumentationTestRunner extends android.test.InstrumentationTestRunner {
+ ctor public UiAutomatorInstrumentationTestRunner();
+ }
+
+ public class UiAutomatorTestCase extends android.test.InstrumentationTestCase {
ctor public UiAutomatorTestCase();
- method public com.android.uiautomator.testrunner.IAutomationSupport getAutomationSupport();
+ method public deprecated com.android.uiautomator.testrunner.IAutomationSupport getAutomationSupport();
method public android.os.Bundle getParams();
method public com.android.uiautomator.core.UiDevice getUiDevice();
method public void sleep(long);
diff --git a/api/16.txt b/api/16.txt
deleted file mode 100644
index f3b0eb7..0000000
--- a/api/16.txt
+++ /dev/null
@@ -1,174 +0,0 @@
-package com.android.uiautomator.core {
-
- public class UiCollection extends com.android.uiautomator.core.UiObject {
- ctor public UiCollection(com.android.uiautomator.core.UiSelector);
- method public com.android.uiautomator.core.UiObject getChildByDescription(com.android.uiautomator.core.UiSelector, java.lang.String) throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public com.android.uiautomator.core.UiObject getChildByInstance(com.android.uiautomator.core.UiSelector, int) throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public com.android.uiautomator.core.UiObject getChildByText(com.android.uiautomator.core.UiSelector, java.lang.String) throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public int getChildCount(com.android.uiautomator.core.UiSelector);
- }
-
- public class UiDevice {
- method public void clearLastTraversedText();
- method public boolean click(int, int);
- method public void dumpWindowHierarchy(java.lang.String);
- method public void freezeRotation() throws android.os.RemoteException;
- method public java.lang.String getCurrentActivityName();
- method public java.lang.String getCurrentPackageName();
- method public int getDisplayHeight();
- method public int getDisplayWidth();
- method public static com.android.uiautomator.core.UiDevice getInstance();
- method public java.lang.String getLastTraversedText();
- method public boolean hasAnyWatcherTriggered();
- method public boolean hasWatcherTriggered(java.lang.String);
- method public boolean isScreenOn() throws android.os.RemoteException;
- method public boolean pressBack();
- method public boolean pressDPadCenter();
- method public boolean pressDPadDown();
- method public boolean pressDPadLeft();
- method public boolean pressDPadRight();
- method public boolean pressDPadUp();
- method public boolean pressDelete();
- method public boolean pressEnter();
- method public boolean pressHome();
- method public boolean pressKeyCode(int);
- method public boolean pressKeyCode(int, int);
- method public boolean pressMenu();
- method public boolean pressRecentApps() throws android.os.RemoteException;
- method public boolean pressSearch();
- method public void registerWatcher(java.lang.String, com.android.uiautomator.core.UiWatcher);
- method public void removeWatcher(java.lang.String);
- method public void resetWatcherTriggers();
- method public void runWatchers();
- method public void sleep() throws android.os.RemoteException;
- method public boolean swipe(int, int, int, int, int);
- method public boolean swipe(android.graphics.Point[], int);
- method public void unfreezeRotation() throws android.os.RemoteException;
- method public void waitForIdle();
- method public void waitForIdle(long);
- method public boolean waitForWindowUpdate(java.lang.String, long);
- method public void wakeUp() throws android.os.RemoteException;
- }
-
- public class UiObject {
- ctor public UiObject(com.android.uiautomator.core.UiSelector);
- method public void clearTextField() throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public boolean click() throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public boolean clickAndWaitForNewWindow() throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public boolean clickAndWaitForNewWindow(long) throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public boolean clickBottomRight() throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public boolean clickTopLeft() throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public boolean exists();
- method protected android.view.accessibility.AccessibilityNodeInfo findAccessibilityNodeInfo(long);
- method public android.graphics.Rect getBounds() throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public com.android.uiautomator.core.UiObject getChild(com.android.uiautomator.core.UiSelector) throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public int getChildCount() throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public java.lang.String getContentDescription() throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public com.android.uiautomator.core.UiObject getFromParent(com.android.uiautomator.core.UiSelector) throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public java.lang.String getPackageName() throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public final com.android.uiautomator.core.UiSelector getSelector();
- method public java.lang.String getText() throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public boolean isCheckable() throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public boolean isChecked() throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public boolean isClickable() throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public boolean isEnabled() throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public boolean isFocusable() throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public boolean isFocused() throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public boolean isLongClickable() throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public boolean isScrollable() throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public boolean isSelected() throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public boolean longClick() throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public boolean longClickBottomRight() throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public boolean longClickTopLeft() throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public boolean setText(java.lang.String) throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public boolean swipeDown(int) throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public boolean swipeLeft(int) throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public boolean swipeRight(int) throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public boolean swipeUp(int) throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public boolean waitForExists(long);
- method public boolean waitUntilGone(long);
- field protected static final int SWIPE_MARGIN_LIMIT = 5; // 0x5
- field protected static final long WAIT_FOR_SELECTOR_POLL = 1000L; // 0x3e8L
- field protected static final long WAIT_FOR_SELECTOR_TIMEOUT = 10000L; // 0x2710L
- field protected static final long WAIT_FOR_WINDOW_TMEOUT = 5500L; // 0x157cL
- }
-
- public class UiObjectNotFoundException extends java.lang.Exception {
- ctor public UiObjectNotFoundException(java.lang.String);
- ctor public UiObjectNotFoundException(java.lang.String, java.lang.Throwable);
- ctor public UiObjectNotFoundException(java.lang.Throwable);
- }
-
- public class UiScrollable extends com.android.uiautomator.core.UiCollection {
- ctor public UiScrollable(com.android.uiautomator.core.UiSelector);
- method protected boolean exists(com.android.uiautomator.core.UiSelector);
- method public boolean flingBackward();
- method public boolean flingForward();
- method public boolean flingToBeginning(int);
- method public boolean flingToEnd(int);
- method public com.android.uiautomator.core.UiObject getChildByDescription(com.android.uiautomator.core.UiSelector, java.lang.String, boolean) throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public com.android.uiautomator.core.UiObject getChildByText(com.android.uiautomator.core.UiSelector, java.lang.String, boolean) throws com.android.uiautomator.core.UiObjectNotFoundException;
- method public int getMaxSearchSwipes();
- method public double getSwipeDeadZonePercentage();
- method public boolean scrollBackward();
- method public boolean scrollBackward(int);
- method public boolean scrollDescriptionIntoView(java.lang.String);
- method public boolean scrollForward();
- method public boolean scrollForward(int);
- method public boolean scrollIntoView(com.android.uiautomator.core.UiSelector);
- method public boolean scrollTextIntoView(java.lang.String);
- method public boolean scrollToBeginning(int, int);
- method public boolean scrollToBeginning(int);
- method public boolean scrollToEnd(int, int);
- method public boolean scrollToEnd(int);
- method public void setAsHorizontalList();
- method public void setAsVerticalList();
- method public void setMaxSearchSwipes(int);
- method public void setSwipeDeadZonePercentage(double);
- }
-
- public class UiSelector {
- ctor public UiSelector();
- method public com.android.uiautomator.core.UiSelector checked(boolean);
- method public com.android.uiautomator.core.UiSelector childSelector(com.android.uiautomator.core.UiSelector);
- method public com.android.uiautomator.core.UiSelector className(java.lang.String);
- method public com.android.uiautomator.core.UiSelector clickable(boolean);
- method public com.android.uiautomator.core.UiSelector description(java.lang.String);
- method public com.android.uiautomator.core.UiSelector descriptionContains(java.lang.String);
- method public com.android.uiautomator.core.UiSelector descriptionStartsWith(java.lang.String);
- method public com.android.uiautomator.core.UiSelector enabled(boolean);
- method public com.android.uiautomator.core.UiSelector focusable(boolean);
- method public com.android.uiautomator.core.UiSelector focused(boolean);
- method public com.android.uiautomator.core.UiSelector fromParent(com.android.uiautomator.core.UiSelector);
- method public com.android.uiautomator.core.UiSelector index(int);
- method public com.android.uiautomator.core.UiSelector instance(int);
- method public com.android.uiautomator.core.UiSelector packageName(java.lang.String);
- method public com.android.uiautomator.core.UiSelector scrollable(boolean);
- method public com.android.uiautomator.core.UiSelector selected(boolean);
- method public com.android.uiautomator.core.UiSelector text(java.lang.String);
- method public com.android.uiautomator.core.UiSelector textContains(java.lang.String);
- method public com.android.uiautomator.core.UiSelector textStartsWith(java.lang.String);
- }
-
- public abstract interface UiWatcher {
- method public abstract boolean checkForCondition();
- }
-
-}
-
-package com.android.uiautomator.testrunner {
-
- public abstract interface IAutomationSupport {
- method public abstract void sendStatus(int, android.os.Bundle);
- }
-
- public class UiAutomatorTestCase extends junit.framework.TestCase {
- ctor public UiAutomatorTestCase();
- method public com.android.uiautomator.testrunner.IAutomationSupport getAutomationSupport();
- method public android.os.Bundle getParams();
- method public com.android.uiautomator.core.UiDevice getUiDevice();
- method public void sleep(long);
- }
-
-}
-
diff --git a/api/current.txt b/api/current.txt
index 7eeecf5..aabf23f 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -210,9 +210,13 @@ package com.android.uiautomator.testrunner {
method public abstract void sendStatus(int, android.os.Bundle);
}
- public class UiAutomatorTestCase extends junit.framework.TestCase {
+ public class UiAutomatorInstrumentationTestRunner extends android.test.InstrumentationTestRunner {
+ ctor public UiAutomatorInstrumentationTestRunner();
+ }
+
+ public class UiAutomatorTestCase extends android.test.InstrumentationTestCase {
ctor public UiAutomatorTestCase();
- method public com.android.uiautomator.testrunner.IAutomationSupport getAutomationSupport();
+ method public deprecated com.android.uiautomator.testrunner.IAutomationSupport getAutomationSupport();
method public android.os.Bundle getParams();
method public com.android.uiautomator.core.UiDevice getUiDevice();
method public void sleep(long);
diff --git a/library/apicheck_msg_current.txt b/apicheck_msg_current.txt
index 989248d..989248d 100644
--- a/library/apicheck_msg_current.txt
+++ b/apicheck_msg_current.txt
diff --git a/library/apicheck_msg_last.txt b/apicheck_msg_last.txt
index 2993157..2993157 100644
--- a/library/apicheck_msg_last.txt
+++ b/apicheck_msg_last.txt
diff --git a/library/core-src/com/android/uiautomator/core/AccessibilityNodeInfoDumper.java b/core/com/android/uiautomator/core/AccessibilityNodeInfoDumper.java
index 63c51e8..63c51e8 100644
--- a/library/core-src/com/android/uiautomator/core/AccessibilityNodeInfoDumper.java
+++ b/core/com/android/uiautomator/core/AccessibilityNodeInfoDumper.java
diff --git a/library/core-src/com/android/uiautomator/core/AccessibilityNodeInfoHelper.java b/core/com/android/uiautomator/core/AccessibilityNodeInfoHelper.java
index 54835e3..54835e3 100644
--- a/library/core-src/com/android/uiautomator/core/AccessibilityNodeInfoHelper.java
+++ b/core/com/android/uiautomator/core/AccessibilityNodeInfoHelper.java
diff --git a/library/core-src/com/android/uiautomator/core/Configurator.java b/core/com/android/uiautomator/core/Configurator.java
index 249f404..249f404 100644
--- a/library/core-src/com/android/uiautomator/core/Configurator.java
+++ b/core/com/android/uiautomator/core/Configurator.java
diff --git a/library/core-src/com/android/uiautomator/core/InteractionController.java b/core/com/android/uiautomator/core/InteractionController.java
index 73e46f1..73e46f1 100644
--- a/library/core-src/com/android/uiautomator/core/InteractionController.java
+++ b/core/com/android/uiautomator/core/InteractionController.java
diff --git a/library/core-src/com/android/uiautomator/core/QueryController.java b/core/com/android/uiautomator/core/QueryController.java
index 6931528..6931528 100644
--- a/library/core-src/com/android/uiautomator/core/QueryController.java
+++ b/core/com/android/uiautomator/core/QueryController.java
diff --git a/library/core-src/com/android/uiautomator/core/Tracer.java b/core/com/android/uiautomator/core/Tracer.java
index d574fc0..d574fc0 100644
--- a/library/core-src/com/android/uiautomator/core/Tracer.java
+++ b/core/com/android/uiautomator/core/Tracer.java
diff --git a/library/core-src/com/android/uiautomator/core/UiAutomatorBridge.java b/core/com/android/uiautomator/core/UiAutomatorBridge.java
index bc5bc8e..bc5bc8e 100644
--- a/library/core-src/com/android/uiautomator/core/UiAutomatorBridge.java
+++ b/core/com/android/uiautomator/core/UiAutomatorBridge.java
diff --git a/library/core-src/com/android/uiautomator/core/UiCollection.java b/core/com/android/uiautomator/core/UiCollection.java
index e15beb2..e15beb2 100644
--- a/library/core-src/com/android/uiautomator/core/UiCollection.java
+++ b/core/com/android/uiautomator/core/UiCollection.java
diff --git a/library/core-src/com/android/uiautomator/core/UiDevice.java b/core/com/android/uiautomator/core/UiDevice.java
index a930eb4..a930eb4 100644
--- a/library/core-src/com/android/uiautomator/core/UiDevice.java
+++ b/core/com/android/uiautomator/core/UiDevice.java
diff --git a/library/core-src/com/android/uiautomator/core/UiObject.java b/core/com/android/uiautomator/core/UiObject.java
index 4bb99cd..4bb99cd 100644
--- a/library/core-src/com/android/uiautomator/core/UiObject.java
+++ b/core/com/android/uiautomator/core/UiObject.java
diff --git a/library/core-src/com/android/uiautomator/core/UiObjectNotFoundException.java b/core/com/android/uiautomator/core/UiObjectNotFoundException.java
index fc0891b..fc0891b 100644
--- a/library/core-src/com/android/uiautomator/core/UiObjectNotFoundException.java
+++ b/core/com/android/uiautomator/core/UiObjectNotFoundException.java
diff --git a/library/core-src/com/android/uiautomator/core/UiScrollable.java b/core/com/android/uiautomator/core/UiScrollable.java
index a8d20c3..a8d20c3 100644
--- a/library/core-src/com/android/uiautomator/core/UiScrollable.java
+++ b/core/com/android/uiautomator/core/UiScrollable.java
diff --git a/library/core-src/com/android/uiautomator/core/UiSelector.java b/core/com/android/uiautomator/core/UiSelector.java
index bd61bfd..bd61bfd 100644
--- a/library/core-src/com/android/uiautomator/core/UiSelector.java
+++ b/core/com/android/uiautomator/core/UiSelector.java
diff --git a/library/core-src/com/android/uiautomator/core/UiWatcher.java b/core/com/android/uiautomator/core/UiWatcher.java
index 5403e30..5403e30 100644
--- a/library/core-src/com/android/uiautomator/core/UiWatcher.java
+++ b/core/com/android/uiautomator/core/UiWatcher.java
diff --git a/instrumentation/Android.mk b/instrumentation/Android.mk
deleted file mode 100644
index e538519..0000000
--- a/instrumentation/Android.mk
+++ /dev/null
@@ -1,27 +0,0 @@
-#
-# Copyright (C) 2012 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-LOCAL_PATH:= $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := tests
-LOCAL_SRC_FILES := $(call all-java-files-under, testrunner-src) \
- $(call all-java-files-under, ../library/core-src)
-LOCAL_MODULE := uiautomator-instrumentation
-LOCAL_SDK_VERSION := current
-
-include $(BUILD_STATIC_JAVA_LIBRARY)
diff --git a/library/Android.mk b/library/Android.mk
deleted file mode 100644
index 470e8ab..0000000
--- a/library/Android.mk
+++ /dev/null
@@ -1,123 +0,0 @@
-#
-# Copyright (C) 2012 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-LOCAL_PATH:= $(call my-dir)
-
-uiautomator.core_src_files := $(call all-java-files-under, core-src) \
- $(call all-java-files-under, testrunner-src)
-uiautomator.core_java_libraries := android.test.runner core-junit
-
-uiautomator_internal_api_file := $(TARGET_OUT_COMMON_INTERMEDIATES)/PACKAGING/uiautomator_api.txt
-
-###############################################
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := $(uiautomator.core_src_files)
-LOCAL_MODULE := uiautomator.core
-LOCAL_JAVA_LIBRARIES := android.test.runner
-include $(BUILD_STATIC_JAVA_LIBRARY)
-
-###############################################
-# Generate the stub source files
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES := $(uiautomator.core_src_files)
-LOCAL_JAVA_LIBRARIES := $(uiautomator.core_java_libraries)
-LOCAL_MODULE_CLASS := JAVA_LIBRARIES
-LOCAL_DROIDDOC_SOURCE_PATH := $(LOCAL_PATH)/core-src \
- $(LOCAL_PATH)/testrunner-src
-LOCAL_DROIDDOC_HTML_DIR :=
-
-LOCAL_DROIDDOC_OPTIONS:= \
- -stubs $(TARGET_OUT_COMMON_INTERMEDIATES)/JAVA_LIBRARIES/android_uiautomator_intermediates/src \
- -stubpackages com.android.uiautomator.core:com.android.uiautomator.testrunner \
- -api $(uiautomator_internal_api_file)
-
-LOCAL_DROIDDOC_CUSTOM_TEMPLATE_DIR := build/tools/droiddoc/templates-sdk
-LOCAL_UNINSTALLABLE_MODULE := true
-
-LOCAL_MODULE := uiautomator-stubs
-
-include $(BUILD_DROIDDOC)
-uiautomator_stubs_stamp := $(full_target)
-$(uiautomator_internal_api_file) : $(full_target)
-
-###############################################
-# Build the stub source files into a jar.
-include $(CLEAR_VARS)
-LOCAL_MODULE := android_uiautomator
-LOCAL_JAVA_LIBRARIES := $(uiautomator.core_java_libraries)
-LOCAL_SOURCE_FILES_ALL_GENERATED := true
-include $(BUILD_STATIC_JAVA_LIBRARY)
-# Make sure to run droiddoc first to generate the stub source files.
-$(full_classes_compiled_jar) : $(uiautomator_stubs_stamp)
-uiautomator_stubs_jar := $(full_classes_compiled_jar)
-
-###############################################
-# API check
-# Please refer to build/core/tasks/apicheck.mk.
-uiautomator_api_dir := frameworks/testing/uiautomator/api
-last_released_sdk_version := $(lastword $(call numerically_sort, \
- $(filter-out current, \
- $(patsubst $(uiautomator_api_dir)/%.txt,%, $(wildcard $(uiautomator_api_dir)/*.txt)) \
- )))
-
-checkapi_last_error_level_flags := \
- -hide 2 -hide 3 -hide 4 -hide 5 -hide 6 -hide 24 -hide 25 \
- -error 7 -error 8 -error 9 -error 10 -error 11 -error 12 -error 13 -error 14 -error 15 \
- -error 16 -error 17 -error 18
-
-# Check that the API we're building hasn't broken the last-released SDK version.
-$(eval $(call check-api, \
- uiautomator-checkapi-last, \
- $(uiautomator_api_dir)/$(last_released_sdk_version).txt, \
- $(uiautomator_internal_api_file), \
- $(checkapi_last_error_level_flags), \
- cat $(LOCAL_PATH)/apicheck_msg_last.txt, \
- $(uiautomator_stubs_jar), \
- $(uiautomator_stubs_stamp)))
-
-checkapi_current_error_level_flags := \
- -error 2 -error 3 -error 4 -error 5 -error 6 \
- -error 7 -error 8 -error 9 -error 10 -error 11 -error 12 -error 13 -error 14 -error 15 \
- -error 16 -error 17 -error 18 -error 19 -error 20 -error 21 -error 23 -error 24 \
- -error 25
-
-# Check that the API we're building hasn't changed from the not-yet-released
-# SDK version.
-$(eval $(call check-api, \
- uiautomator-checkapi-current, \
- $(uiautomator_api_dir)/current.txt, \
- $(uiautomator_internal_api_file), \
- $(checkapi_current_error_level_flags), \
- cat $(LOCAL_PATH)/apicheck_msg_current.txt, \
- $(uiautomator_stubs_jar), \
- $(uiautomator_stubs_stamp)))
-
-.PHONY: update-uiautomator-api
-update-uiautomator-api: PRIVATE_API_DIR := $(uiautomator_api_dir)
-update-uiautomator-api: $(uiautomator_internal_api_file) | $(ACP)
- @echo Copying uiautomator current.txt
- $(hide) $(ACP) $< $(PRIVATE_API_DIR)/current.txt
-
-###############################################
-# clean up temp vars
-uiautomator.core_src_files :=
-uiautomator.core_java_libraries :=
-uiautomator_stubs_stamp :=
-uiautomator_internal_api_file :=
-uiautomator_stubs_jar :=
-uiautomator_api_dir :=
-checkapi_last_error_level_flags :=
-checkapi_current_error_level_flags :=
diff --git a/library/testrunner-src/com/android/uiautomator/core/ShellUiAutomatorBridge.java b/library/testrunner-src/com/android/uiautomator/core/ShellUiAutomatorBridge.java
deleted file mode 100644
index 1afa513..0000000
--- a/library/testrunner-src/com/android/uiautomator/core/ShellUiAutomatorBridge.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.uiautomator.core;
-
-import android.app.ActivityManagerNative;
-import android.app.IActivityManager;
-import android.app.IActivityManager.ContentProviderHolder;
-import android.app.UiAutomation;
-import android.content.Context;
-import android.content.IContentProvider;
-import android.database.Cursor;
-import android.hardware.display.DisplayManagerGlobal;
-import android.os.Binder;
-import android.os.IBinder;
-import android.os.IPowerManager;
-import android.os.RemoteException;
-import android.os.ServiceManager;
-import android.os.UserHandle;
-import android.provider.Settings;
-import android.util.Log;
-import android.view.Display;
-import android.view.IWindowManager;
-
-/**
- * @hide
- */
-public class ShellUiAutomatorBridge extends UiAutomatorBridge {
-
- private static final String LOG_TAG = ShellUiAutomatorBridge.class.getSimpleName();
-
- public ShellUiAutomatorBridge(UiAutomation uiAutomation) {
- super(uiAutomation);
- }
-
- public Display getDefaultDisplay() {
- return DisplayManagerGlobal.getInstance().getRealDisplay(Display.DEFAULT_DISPLAY);
- }
-
- public long getSystemLongPressTime() {
- // Read the long press timeout setting.
- long longPressTimeout = 0;
- try {
- IContentProvider provider = null;
- Cursor cursor = null;
- IActivityManager activityManager = ActivityManagerNative.getDefault();
- String providerName = Settings.Secure.CONTENT_URI.getAuthority();
- IBinder token = new Binder();
- try {
- ContentProviderHolder holder = activityManager.getContentProviderExternal(
- providerName, UserHandle.USER_OWNER, token);
- if (holder == null) {
- throw new IllegalStateException("Could not find provider: " + providerName);
- }
- provider = holder.provider;
- cursor = provider.query(null, Settings.Secure.CONTENT_URI,
- new String[] {
- Settings.Secure.VALUE
- }, "name=?",
- new String[] {
- Settings.Secure.LONG_PRESS_TIMEOUT
- }, null, null);
- if (cursor.moveToFirst()) {
- longPressTimeout = cursor.getInt(0);
- }
- } finally {
- if (cursor != null) {
- cursor.close();
- }
- if (provider != null) {
- activityManager.removeContentProviderExternal(providerName, token);
- }
- }
- } catch (RemoteException e) {
- String message = "Error reading long press timeout setting.";
- Log.e(LOG_TAG, message, e);
- throw new RuntimeException(message, e);
- }
- return longPressTimeout;
- }
-
- @Override
- public int getRotation() {
- IWindowManager wm =
- IWindowManager.Stub.asInterface(ServiceManager.getService(Context.WINDOW_SERVICE));
- int ret = -1;
- try {
- ret = wm.getRotation();
- } catch (RemoteException e) {
- Log.e(LOG_TAG, "Error getting screen rotation", e);
- throw new RuntimeException(e);
- }
- return ret;
- }
-
- @Override
- public boolean isScreenOn() {
- IPowerManager pm =
- IPowerManager.Stub.asInterface(ServiceManager.getService(Context.POWER_SERVICE));
- boolean ret = false;
- try {
- ret = pm.isScreenOn();
- } catch (RemoteException e) {
- Log.e(LOG_TAG, "Error getting screen status", e);
- throw new RuntimeException(e);
- }
- return ret;
- }
-}
diff --git a/library/testrunner-src/com/android/uiautomator/core/UiAutomationShellWrapper.java b/library/testrunner-src/com/android/uiautomator/core/UiAutomationShellWrapper.java
deleted file mode 100644
index 1fa9bac..0000000
--- a/library/testrunner-src/com/android/uiautomator/core/UiAutomationShellWrapper.java
+++ /dev/null
@@ -1,127 +0,0 @@
-package com.android.uiautomator.core;
-
-import android.accessibilityservice.AccessibilityServiceInfo;
-import android.app.ActivityManager;
-import android.app.ActivityManagerNative;
-import android.app.IActivityController;
-import android.app.IActivityManager;
-import android.app.UiAutomation;
-import android.app.UiAutomationConnection;
-import android.content.Intent;
-import android.os.HandlerThread;
-import android.os.RemoteException;
-
-/**
- * @hide
- */
-public class UiAutomationShellWrapper {
-
- private static final String HANDLER_THREAD_NAME = "UiAutomatorHandlerThread";
-
- private final HandlerThread mHandlerThread = new HandlerThread(HANDLER_THREAD_NAME);
-
- private UiAutomation mUiAutomation;
-
- public void connect() {
- if (mHandlerThread.isAlive()) {
- throw new IllegalStateException("Already connected!");
- }
- mHandlerThread.start();
- mUiAutomation = new UiAutomation(mHandlerThread.getLooper(),
- new UiAutomationConnection());
- mUiAutomation.connect();
- }
-
- /**
- * Enable or disable monkey test mode.
- *
- * Setting test as "monkey" indicates to some applications that a test framework is
- * running as a "monkey" type. Such applications may choose not to perform actions that
- * do submits so to avoid allowing monkey tests from doing harm or performing annoying
- * actions such as dialing 911 or posting messages to public forums, etc.
- *
- * @param isSet True to set as monkey test. False to set as regular functional test (default).
- * @see {@link ActivityManager#isUserAMonkey()}
- */
- public void setRunAsMonkey(boolean isSet) {
- IActivityManager am = ActivityManagerNative.getDefault();
- if (am == null) {
- throw new RuntimeException("Can't manage monkey status; is the system running?");
- }
- try {
- if (isSet) {
- am.setActivityController(new DummyActivityController());
- } else {
- am.setActivityController(null);
- }
- } catch (RemoteException e) {
- throw new RuntimeException(e);
- }
- }
-
- public void disconnect() {
- if (!mHandlerThread.isAlive()) {
- throw new IllegalStateException("Already disconnected!");
- }
- mUiAutomation.disconnect();
- mHandlerThread.quit();
- }
-
- public UiAutomation getUiAutomation() {
- return mUiAutomation;
- }
-
- public void setCompressedLayoutHierarchy(boolean compressed) {
- AccessibilityServiceInfo info = mUiAutomation.getServiceInfo();
- if (compressed)
- info.flags &= ~AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS;
- else
- info.flags |= AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS;
- mUiAutomation.setServiceInfo(info);
- }
-
- /**
- * Dummy, no interference, activity controller.
- */
- private class DummyActivityController extends IActivityController.Stub {
- @Override
- public boolean activityStarting(Intent intent, String pkg) throws RemoteException {
- /* do nothing and let activity proceed normally */
- return true;
- }
-
- @Override
- public boolean activityResuming(String pkg) throws RemoteException {
- /* do nothing and let activity proceed normally */
- return true;
- }
-
- @Override
- public boolean appCrashed(String processName, int pid, String shortMsg, String longMsg,
- long timeMillis, String stackTrace) throws RemoteException {
- /* do nothing and let activity proceed normally */
- return true;
- }
-
- @Override
- public int appEarlyNotResponding(String processName, int pid, String annotation)
- throws RemoteException {
- /* do nothing and let activity proceed normally */
- return 0;
- }
-
- @Override
- public int appNotResponding(String processName, int pid, String processStats)
- throws RemoteException {
- /* do nothing and let activity proceed normally */
- return 0;
- }
-
- @Override
- public int systemNotResponding(String message)
- throws RemoteException {
- /* do nothing and let system proceed normally */
- return 0;
- }
- }
-}
diff --git a/library/testrunner-src/com/android/uiautomator/testrunner/IAutomationSupport.java b/library/testrunner-src/com/android/uiautomator/testrunner/IAutomationSupport.java
deleted file mode 100644
index f0c60d2..0000000
--- a/library/testrunner-src/com/android/uiautomator/testrunner/IAutomationSupport.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.uiautomator.testrunner;
-
-import android.os.Bundle;
-
-/**
- * Provides auxiliary support for running test cases
- *
- * @since API Level 16
- */
-public interface IAutomationSupport {
-
- /**
- * Allows the running test cases to send out interim status
- *
- * @param resultCode
- * @param status status report, consisting of key value pairs
- * @since API Level 16
- */
- public void sendStatus(int resultCode, Bundle status);
-
-}
diff --git a/library/testrunner-src/com/android/uiautomator/testrunner/TestCaseCollector.java b/library/testrunner-src/com/android/uiautomator/testrunner/TestCaseCollector.java
deleted file mode 100644
index cda49f6..0000000
--- a/library/testrunner-src/com/android/uiautomator/testrunner/TestCaseCollector.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.uiautomator.testrunner;
-
-import junit.framework.TestCase;
-
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * A convenient class that encapsulates functions for adding test classes
- *
- * @hide
- */
-public class TestCaseCollector {
-
- private ClassLoader mClassLoader;
- private List<TestCase> mTestCases;
- private TestCaseFilter mFilter;
-
- public TestCaseCollector(ClassLoader classLoader, TestCaseFilter filter) {
- mClassLoader = classLoader;
- mTestCases = new ArrayList<TestCase>();
- mFilter = filter;
- }
-
- /**
- * Adds classes to test by providing a list of class names in string
- *
- * The class name may be in "<class name>#<method name>" format
- *
- * @param classNames class must be subclass of {@link UiAutomatorTestCase}
- * @throws ClassNotFoundException
- */
- public void addTestClasses(List<String> classNames) throws ClassNotFoundException {
- for (String className : classNames) {
- addTestClass(className);
- }
- }
-
- /**
- * Adds class to test by providing class name in string.
- *
- * The class name may be in "<class name>#<method name>" format
- *
- * @param className classes must be subclass of {@link UiAutomatorTestCase}
- * @throws ClassNotFoundException
- */
- public void addTestClass(String className) throws ClassNotFoundException {
- int hashPos = className.indexOf('#');
- String methodName = null;
- if (hashPos != -1) {
- methodName = className.substring(hashPos + 1);
- className = className.substring(0, hashPos);
- }
- addTestClass(className, methodName);
- }
-
- /**
- * Adds class to test by providing class name and method name in separate strings
- *
- * @param className class must be subclass of {@link UiAutomatorTestCase}
- * @param methodName may be null, in which case all "public void testNNN(void)" functions
- * will be added
- * @throws ClassNotFoundException
- */
- public void addTestClass(String className, String methodName) throws ClassNotFoundException {
- Class<?> clazz = mClassLoader.loadClass(className);
- if (methodName != null) {
- addSingleTestMethod(clazz, methodName);
- } else {
- Method[] methods = clazz.getMethods();
- for (Method method : methods) {
- if (mFilter.accept(method)) {
- addSingleTestMethod(clazz, method.getName());
- }
- }
- }
- }
-
- /**
- * Gets the list of added test cases so far
- * @return a list of {@link TestCase}
- */
- public List<TestCase> getTestCases() {
- return Collections.unmodifiableList(mTestCases);
- }
-
- protected void addSingleTestMethod(Class<?> clazz, String method) {
- if (!(mFilter.accept(clazz))) {
- throw new RuntimeException("Test class must be derived from UiAutomatorTestCase");
- }
- try {
- TestCase testCase = (TestCase) clazz.newInstance();
- testCase.setName(method);
- mTestCases.add(testCase);
- } catch (InstantiationException e) {
- mTestCases.add(error(clazz, "InstantiationException: could not instantiate " +
- "test class. Class: " + clazz.getName()));
- } catch (IllegalAccessException e) {
- mTestCases.add(error(clazz, "IllegalAccessException: could not instantiate " +
- "test class. Class: " + clazz.getName()));
- }
- }
-
- private UiAutomatorTestCase error(Class<?> clazz, final String message) {
- UiAutomatorTestCase warning = new UiAutomatorTestCase() {
- protected void runTest() {
- fail(message);
- }
- };
-
- warning.setName(clazz.getName());
- return warning;
- }
-
- /**
- * Determine if a class and its method should be accepted into test suite
- *
- */
- public interface TestCaseFilter {
-
- /**
- * Determine that based on the method signature, if it can be accepted
- * @param method
- */
- public boolean accept(Method method);
-
- /**
- * Determine that based on the class type, if it can be accepted
- * @param clazz
- * @return
- */
- public boolean accept(Class<?> clazz);
- }
-}
diff --git a/library/testrunner-src/com/android/uiautomator/testrunner/UiAutomatorTestCase.java b/library/testrunner-src/com/android/uiautomator/testrunner/UiAutomatorTestCase.java
deleted file mode 100644
index e7d961b..0000000
--- a/library/testrunner-src/com/android/uiautomator/testrunner/UiAutomatorTestCase.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.uiautomator.testrunner;
-
-import android.content.Context;
-import android.os.Bundle;
-import android.os.RemoteException;
-import android.os.ServiceManager;
-import android.os.SystemClock;
-import android.view.inputmethod.InputMethodInfo;
-
-import com.android.internal.view.IInputMethodManager;
-import com.android.uiautomator.core.UiDevice;
-
-import junit.framework.TestCase;
-
-import java.util.List;
-
-/**
- * UI automation test should extend this class. This class provides access
- * to the following:
- * {@link UiDevice} instance
- * {@link Bundle} for command line parameters.
- * @since API Level 16
- */
-public class UiAutomatorTestCase extends TestCase {
-
- private static final String DISABLE_IME = "disable_ime";
- private static final String DUMMY_IME_PACKAGE = "com.android.testing.dummyime";
- private UiDevice mUiDevice;
- private Bundle mParams;
- private IAutomationSupport mAutomationSupport;
- private boolean mShouldDisableIme = false;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- mShouldDisableIme = "true".equals(mParams.getString(DISABLE_IME));
- if (mShouldDisableIme) {
- setDummyIme();
- }
- }
-
- @Override
- protected void tearDown() throws Exception {
- if (mShouldDisableIme) {
- restoreActiveIme();
- }
- super.tearDown();
- }
-
- /**
- * Get current instance of {@link UiDevice}. Works similar to calling the static
- * {@link UiDevice#getInstance()} from anywhere in the test classes.
- * @since API Level 16
- */
- public UiDevice getUiDevice() {
- return mUiDevice;
- }
-
- /**
- * Get command line parameters. On the command line when passing <code>-e key value</code>
- * pairs, the {@link Bundle} will have the key value pairs conveniently available to the
- * tests.
- * @since API Level 16
- */
- public Bundle getParams() {
- return mParams;
- }
-
- /**
- * Provides support for running tests to report interim status
- *
- * @return IAutomationSupport
- * @since API Level 16
- */
- public IAutomationSupport getAutomationSupport() {
- return mAutomationSupport;
- }
-
- /**
- * package private
- * @param uiDevice
- */
- void setUiDevice(UiDevice uiDevice) {
- mUiDevice = uiDevice;
- }
-
- /**
- * package private
- * @param params
- */
- void setParams(Bundle params) {
- mParams = params;
- }
-
- void setAutomationSupport(IAutomationSupport automationSupport) {
- mAutomationSupport = automationSupport;
- }
-
- /**
- * Calls {@link SystemClock#sleep(long)} to sleep
- * @param ms is in milliseconds.
- * @since API Level 16
- */
- public void sleep(long ms) {
- SystemClock.sleep(ms);
- }
-
- private void setDummyIme() throws RemoteException {
- IInputMethodManager im = IInputMethodManager.Stub.asInterface(ServiceManager
- .getService(Context.INPUT_METHOD_SERVICE));
- List<InputMethodInfo> infos = im.getInputMethodList();
- String id = null;
- for (InputMethodInfo info : infos) {
- if (DUMMY_IME_PACKAGE.equals(info.getComponent().getPackageName())) {
- id = info.getId();
- }
- }
- if (id == null) {
- throw new RuntimeException(String.format(
- "Required testing fixture missing: IME package (%s)", DUMMY_IME_PACKAGE));
- }
- im.setInputMethod(null, id);
- }
-
- private void restoreActiveIme() throws RemoteException {
- // TODO: figure out a way to restore active IME
- // Currently retrieving active IME requires querying secure settings provider, which is hard
- // to do without a Context; so the caveat here is that to make the post test device usable,
- // the active IME needs to be manually switched.
- }
-}
diff --git a/library/testrunner-src/com/android/uiautomator/testrunner/UiAutomatorTestCaseFilter.java b/library/testrunner-src/com/android/uiautomator/testrunner/UiAutomatorTestCaseFilter.java
deleted file mode 100644
index 1de5a4d..0000000
--- a/library/testrunner-src/com/android/uiautomator/testrunner/UiAutomatorTestCaseFilter.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.uiautomator.testrunner;
-
-import com.android.uiautomator.testrunner.TestCaseCollector.TestCaseFilter;
-
-import java.lang.reflect.Method;
-
-/**
- * A {@link TestCaseFilter} that accepts testFoo methods and {@link UiAutomatorTestCase} classes
- *
- * @hide
- */
-public class UiAutomatorTestCaseFilter implements TestCaseFilter {
-
- @Override
- public boolean accept(Method method) {
- return ((method.getParameterTypes().length == 0) &&
- (method.getName().startsWith("test")) &&
- (method.getReturnType().getSimpleName().equals("void")));
- }
-
- @Override
- public boolean accept(Class<?> clazz) {
- return UiAutomatorTestCase.class.isAssignableFrom(clazz);
- }
-
-}
diff --git a/library/testrunner-src/com/android/uiautomator/testrunner/UiAutomatorTestRunner.java b/library/testrunner-src/com/android/uiautomator/testrunner/UiAutomatorTestRunner.java
deleted file mode 100644
index ef167f9..0000000
--- a/library/testrunner-src/com/android/uiautomator/testrunner/UiAutomatorTestRunner.java
+++ /dev/null
@@ -1,431 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.uiautomator.testrunner;
-
-import android.app.Activity;
-import android.app.IInstrumentationWatcher;
-import android.app.Instrumentation;
-import android.content.ComponentName;
-import android.os.Bundle;
-import android.os.Debug;
-import android.os.HandlerThread;
-import android.os.IBinder;
-import android.os.SystemClock;
-import android.test.RepetitiveTest;
-import android.util.Log;
-
-import com.android.uiautomator.core.ShellUiAutomatorBridge;
-import com.android.uiautomator.core.Tracer;
-import com.android.uiautomator.core.UiAutomationShellWrapper;
-import com.android.uiautomator.core.UiDevice;
-
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-import java.lang.Thread.UncaughtExceptionHandler;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestListener;
-import junit.framework.TestResult;
-import junit.runner.BaseTestRunner;
-import junit.textui.ResultPrinter;
-
-/**
- * @hide
- */
-public class UiAutomatorTestRunner {
-
- private static final String LOGTAG = UiAutomatorTestRunner.class.getSimpleName();
- private static final int EXIT_OK = 0;
- private static final int EXIT_EXCEPTION = -1;
-
- private static final String HANDLER_THREAD_NAME = "UiAutomatorHandlerThread";
-
- private boolean mDebug;
- private boolean mMonkey;
- private Bundle mParams = null;
- private UiDevice mUiDevice;
- private List<String> mTestClasses = null;
- private final FakeInstrumentationWatcher mWatcher = new FakeInstrumentationWatcher();
- private final IAutomationSupport mAutomationSupport = new IAutomationSupport() {
- @Override
- public void sendStatus(int resultCode, Bundle status) {
- mWatcher.instrumentationStatus(null, resultCode, status);
- }
- };
- private final List<TestListener> mTestListeners = new ArrayList<TestListener>();
-
- private HandlerThread mHandlerThread;
-
- public void run(List<String> testClasses, Bundle params, boolean debug, boolean monkey) {
- Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
- @Override
- public void uncaughtException(Thread thread, Throwable ex) {
- Log.e(LOGTAG, "uncaught exception", ex);
- Bundle results = new Bundle();
- results.putString("shortMsg", ex.getClass().getName());
- results.putString("longMsg", ex.getMessage());
- mWatcher.instrumentationFinished(null, 0, results);
- // bailing on uncaught exception
- System.exit(EXIT_EXCEPTION);
- }
- });
-
- mTestClasses = testClasses;
- mParams = params;
- mDebug = debug;
- mMonkey = monkey;
- start();
- System.exit(EXIT_OK);
- }
-
- /**
- * Called after all test classes are in place, ready to test
- */
- protected void start() {
- TestCaseCollector collector = getTestCaseCollector(this.getClass().getClassLoader());
- try {
- collector.addTestClasses(mTestClasses);
- } catch (ClassNotFoundException e) {
- // will be caught by uncaught handler
- throw new RuntimeException(e.getMessage(), e);
- }
- if (mDebug) {
- Debug.waitForDebugger();
- }
- mHandlerThread = new HandlerThread(HANDLER_THREAD_NAME);
- mHandlerThread.setDaemon(true);
- mHandlerThread.start();
- UiAutomationShellWrapper automationWrapper = new UiAutomationShellWrapper();
- automationWrapper.connect();
-
- long startTime = SystemClock.uptimeMillis();
- TestResult testRunResult = new TestResult();
- ResultReporter resultPrinter;
- String outputFormat = mParams.getString("outputFormat");
- List<TestCase> testCases = collector.getTestCases();
- Bundle testRunOutput = new Bundle();
- if ("simple".equals(outputFormat)) {
- resultPrinter = new SimpleResultPrinter(System.out, true);
- } else {
- resultPrinter = new WatcherResultPrinter(testCases.size());
- }
- try {
- automationWrapper.setRunAsMonkey(mMonkey);
- mUiDevice = UiDevice.getInstance();
- mUiDevice.initialize(new ShellUiAutomatorBridge(automationWrapper.getUiAutomation()));
-
- String traceType = mParams.getString("traceOutputMode");
- if(traceType != null) {
- Tracer.Mode mode = Tracer.Mode.valueOf(Tracer.Mode.class, traceType);
- if (mode == Tracer.Mode.FILE || mode == Tracer.Mode.ALL) {
- String filename = mParams.getString("traceLogFilename");
- if (filename == null) {
- throw new RuntimeException("Name of log file not specified. " +
- "Please specify it using traceLogFilename parameter");
- }
- Tracer.getInstance().setOutputFilename(filename);
- }
- Tracer.getInstance().setOutputMode(mode);
- }
-
- // add test listeners
- testRunResult.addListener(resultPrinter);
- // add all custom listeners
- for (TestListener listener : mTestListeners) {
- testRunResult.addListener(listener);
- }
-
- // run tests for realz!
- for (TestCase testCase : testCases) {
- prepareTestCase(testCase);
- testCase.run(testRunResult);
- }
- } catch (Throwable t) {
- // catch all exceptions so a more verbose error message can be outputted
- resultPrinter.printUnexpectedError(t);
- testRunOutput.putString("shortMsg", t.getMessage());
- } finally {
- long runTime = SystemClock.uptimeMillis() - startTime;
- resultPrinter.print(testRunResult, runTime, testRunOutput);
- automationWrapper.disconnect();
- automationWrapper.setRunAsMonkey(false);
- mHandlerThread.quit();
- }
- }
-
- // copy & pasted from com.android.commands.am.Am
- private class FakeInstrumentationWatcher implements IInstrumentationWatcher {
-
- private final boolean mRawMode = true;
-
- @Override
- public IBinder asBinder() {
- throw new UnsupportedOperationException("I'm just a fake!");
- }
-
- @Override
- public void instrumentationStatus(ComponentName name, int resultCode, Bundle results) {
- synchronized (this) {
- // pretty printer mode?
- String pretty = null;
- if (!mRawMode && results != null) {
- pretty = results.getString(Instrumentation.REPORT_KEY_STREAMRESULT);
- }
- if (pretty != null) {
- System.out.print(pretty);
- } else {
- if (results != null) {
- for (String key : results.keySet()) {
- System.out.println("INSTRUMENTATION_STATUS: " + key + "="
- + results.get(key));
- }
- }
- System.out.println("INSTRUMENTATION_STATUS_CODE: " + resultCode);
- }
- notifyAll();
- }
- }
-
- @Override
- public void instrumentationFinished(ComponentName name, int resultCode, Bundle results) {
- synchronized (this) {
- // pretty printer mode?
- String pretty = null;
- if (!mRawMode && results != null) {
- pretty = results.getString(Instrumentation.REPORT_KEY_STREAMRESULT);
- }
- if (pretty != null) {
- System.out.println(pretty);
- } else {
- if (results != null) {
- for (String key : results.keySet()) {
- System.out.println("INSTRUMENTATION_RESULT: " + key + "="
- + results.get(key));
- }
- }
- System.out.println("INSTRUMENTATION_CODE: " + resultCode);
- }
- notifyAll();
- }
- }
- }
-
- private interface ResultReporter extends TestListener {
- public void print(TestResult result, long runTime, Bundle testOutput);
- public void printUnexpectedError(Throwable t);
- }
-
- // Copy & pasted from InstrumentationTestRunner.WatcherResultPrinter
- private class WatcherResultPrinter implements ResultReporter {
-
- private static final String REPORT_KEY_NUM_TOTAL = "numtests";
- private static final String REPORT_KEY_NAME_CLASS = "class";
- private static final String REPORT_KEY_NUM_CURRENT = "current";
- private static final String REPORT_KEY_NAME_TEST = "test";
- private static final String REPORT_KEY_NUM_ITERATIONS = "numiterations";
- private static final String REPORT_VALUE_ID = "UiAutomatorTestRunner";
- private static final String REPORT_KEY_STACK = "stack";
-
- private static final int REPORT_VALUE_RESULT_START = 1;
- private static final int REPORT_VALUE_RESULT_ERROR = -1;
- private static final int REPORT_VALUE_RESULT_FAILURE = -2;
-
- private final Bundle mResultTemplate;
- Bundle mTestResult;
- int mTestNum = 0;
- int mTestResultCode = 0;
- String mTestClass = null;
-
- private final SimpleResultPrinter mPrinter;
- private final ByteArrayOutputStream mStream;
- private final PrintStream mWriter;
-
- public WatcherResultPrinter(int numTests) {
- mResultTemplate = new Bundle();
- mResultTemplate.putString(Instrumentation.REPORT_KEY_IDENTIFIER, REPORT_VALUE_ID);
- mResultTemplate.putInt(REPORT_KEY_NUM_TOTAL, numTests);
-
- mStream = new ByteArrayOutputStream();
- mWriter = new PrintStream(mStream);
- mPrinter = new SimpleResultPrinter(mWriter, false);
- }
-
- /**
- * send a status for the start of a each test, so long tests can be seen
- * as "running"
- */
- @Override
- public void startTest(Test test) {
- String testClass = test.getClass().getName();
- String testName = ((TestCase) test).getName();
- mTestResult = new Bundle(mResultTemplate);
- mTestResult.putString(REPORT_KEY_NAME_CLASS, testClass);
- mTestResult.putString(REPORT_KEY_NAME_TEST, testName);
- mTestResult.putInt(REPORT_KEY_NUM_CURRENT, ++mTestNum);
- // pretty printing
- if (testClass != null && !testClass.equals(mTestClass)) {
- mTestResult.putString(Instrumentation.REPORT_KEY_STREAMRESULT,
- String.format("\n%s:", testClass));
- mTestClass = testClass;
- } else {
- mTestResult.putString(Instrumentation.REPORT_KEY_STREAMRESULT, "");
- }
-
- Method testMethod = null;
- try {
- testMethod = test.getClass().getMethod(testName);
- // Report total number of iterations, if test is repetitive
- if (testMethod.isAnnotationPresent(RepetitiveTest.class)) {
- int numIterations = testMethod.getAnnotation(RepetitiveTest.class)
- .numIterations();
- mTestResult.putInt(REPORT_KEY_NUM_ITERATIONS, numIterations);
- }
- } catch (NoSuchMethodException e) {
- // ignore- the test with given name does not exist. Will be
- // handled during test
- // execution
- }
-
- mAutomationSupport.sendStatus(REPORT_VALUE_RESULT_START, mTestResult);
- mTestResultCode = 0;
-
- mPrinter.startTest(test);
- }
-
- @Override
- public void addError(Test test, Throwable t) {
- mTestResult.putString(REPORT_KEY_STACK, BaseTestRunner.getFilteredTrace(t));
- mTestResultCode = REPORT_VALUE_RESULT_ERROR;
- // pretty printing
- mTestResult.putString(Instrumentation.REPORT_KEY_STREAMRESULT,
- String.format("\nError in %s:\n%s",
- ((TestCase)test).getName(), BaseTestRunner.getFilteredTrace(t)));
-
- mPrinter.addError(test, t);
- }
-
- @Override
- public void addFailure(Test test, AssertionFailedError t) {
- mTestResult.putString(REPORT_KEY_STACK, BaseTestRunner.getFilteredTrace(t));
- mTestResultCode = REPORT_VALUE_RESULT_FAILURE;
- // pretty printing
- mTestResult.putString(Instrumentation.REPORT_KEY_STREAMRESULT,
- String.format("\nFailure in %s:\n%s",
- ((TestCase)test).getName(), BaseTestRunner.getFilteredTrace(t)));
-
- mPrinter.addFailure(test, t);
- }
-
- @Override
- public void endTest(Test test) {
- if (mTestResultCode == 0) {
- mTestResult.putString(Instrumentation.REPORT_KEY_STREAMRESULT, ".");
- }
- mAutomationSupport.sendStatus(mTestResultCode, mTestResult);
-
- mPrinter.endTest(test);
- }
-
- @Override
- public void print(TestResult result, long runTime, Bundle testOutput) {
- mPrinter.print(result, runTime, testOutput);
- testOutput.putString(Instrumentation.REPORT_KEY_STREAMRESULT,
- String.format("\nTest results for %s=%s",
- getClass().getSimpleName(),
- mStream.toString()));
- mWriter.close();
- mAutomationSupport.sendStatus(Activity.RESULT_OK, testOutput);
- }
-
- @Override
- public void printUnexpectedError(Throwable t) {
- mWriter.println(String.format("Test run aborted due to unexpected exception: %s",
- t.getMessage()));
- t.printStackTrace(mWriter);
- }
- }
-
- /**
- * Class that produces the same output as JUnit when running from command line. Can be
- * used when default UiAutomator output is too verbose.
- */
- private class SimpleResultPrinter extends ResultPrinter implements ResultReporter {
- private final boolean mFullOutput;
- public SimpleResultPrinter(PrintStream writer, boolean fullOutput) {
- super(writer);
- mFullOutput = fullOutput;
- }
-
- @Override
- public void print(TestResult result, long runTime, Bundle testOutput) {
- printHeader(runTime);
- if (mFullOutput) {
- printErrors(result);
- printFailures(result);
- }
- printFooter(result);
- }
-
- @Override
- public void printUnexpectedError(Throwable t) {
- if (mFullOutput) {
- getWriter().printf("Test run aborted due to unexpected exeption: %s",
- t.getMessage());
- t.printStackTrace(getWriter());
- }
- }
- }
-
- protected TestCaseCollector getTestCaseCollector(ClassLoader classLoader) {
- return new TestCaseCollector(classLoader, getTestCaseFilter());
- }
-
- /**
- * Returns an object which determines if the class and its methods should be
- * accepted into the test suite.
- * @return
- */
- public UiAutomatorTestCaseFilter getTestCaseFilter() {
- return new UiAutomatorTestCaseFilter();
- }
-
- protected void addTestListener(TestListener listener) {
- if (!mTestListeners.contains(listener)) {
- mTestListeners.add(listener);
- }
- }
-
- protected void removeTestListener(TestListener listener) {
- mTestListeners.remove(listener);
- }
-
- /**
- * subclass may override this method to perform further preparation
- *
- * @param testCase
- */
- protected void prepareTestCase(TestCase testCase) {
- ((UiAutomatorTestCase)testCase).setAutomationSupport(mAutomationSupport);
- ((UiAutomatorTestCase)testCase).setUiDevice(mUiDevice);
- ((UiAutomatorTestCase)testCase).setParams(mParams);
- }
-}
diff --git a/instrumentation/testrunner-src/com/android/uiautomator/core/InstrumentationUiAutomatorBridge.java b/testrunner/com/android/uiautomator/core/InstrumentationUiAutomatorBridge.java
index 1d4fb93..1d4fb93 100644
--- a/instrumentation/testrunner-src/com/android/uiautomator/core/InstrumentationUiAutomatorBridge.java
+++ b/testrunner/com/android/uiautomator/core/InstrumentationUiAutomatorBridge.java
diff --git a/instrumentation/testrunner-src/com/android/uiautomator/testrunner/IAutomationSupport.java b/testrunner/com/android/uiautomator/testrunner/IAutomationSupport.java
index f0c60d2..f0c60d2 100644
--- a/instrumentation/testrunner-src/com/android/uiautomator/testrunner/IAutomationSupport.java
+++ b/testrunner/com/android/uiautomator/testrunner/IAutomationSupport.java
diff --git a/instrumentation/testrunner-src/com/android/uiautomator/testrunner/InstrumentationAutomationSupport.java b/testrunner/com/android/uiautomator/testrunner/InstrumentationAutomationSupport.java
index a70586e..a70586e 100644
--- a/instrumentation/testrunner-src/com/android/uiautomator/testrunner/InstrumentationAutomationSupport.java
+++ b/testrunner/com/android/uiautomator/testrunner/InstrumentationAutomationSupport.java
diff --git a/instrumentation/testrunner-src/com/android/uiautomator/testrunner/UiAutomatorInstrumentationTestRunner.java b/testrunner/com/android/uiautomator/testrunner/UiAutomatorInstrumentationTestRunner.java
index ae763f2..ae763f2 100644
--- a/instrumentation/testrunner-src/com/android/uiautomator/testrunner/UiAutomatorInstrumentationTestRunner.java
+++ b/testrunner/com/android/uiautomator/testrunner/UiAutomatorInstrumentationTestRunner.java
diff --git a/instrumentation/testrunner-src/com/android/uiautomator/testrunner/UiAutomatorTestCase.java b/testrunner/com/android/uiautomator/testrunner/UiAutomatorTestCase.java
index b5f21c9..b5f21c9 100644
--- a/instrumentation/testrunner-src/com/android/uiautomator/testrunner/UiAutomatorTestCase.java
+++ b/testrunner/com/android/uiautomator/testrunner/UiAutomatorTestCase.java
diff --git a/uiautomator_test_libraries/Android.mk b/uiautomator_test_libraries/Android.mk
deleted file mode 100644
index f975016..0000000
--- a/uiautomator_test_libraries/Android.mk
+++ /dev/null
@@ -1,33 +0,0 @@
-#
-# Copyright (C) 2012 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-local_target_dir := $(TARGET_OUT_DATA)/local/tmp
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-
-LOCAL_MODULE := com.android.uiautomator.platform.common
-
-LOCAL_SDK_VERSION := 16
-
-LOCAL_JAVA_LIBRARIES := uiautomator_sdk_v$(LOCAL_SDK_VERSION)
-
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_MODULE_PATH := $(local_target_dir)
-
-include $(BUILD_STATIC_JAVA_LIBRARY)
diff --git a/uiautomator_test_libraries/src/com/android/uiautomator/common/UiWatchers.java b/uiautomator_test_libraries/src/com/android/uiautomator/common/UiWatchers.java
deleted file mode 100644
index dd1bb5b..0000000
--- a/uiautomator_test_libraries/src/com/android/uiautomator/common/UiWatchers.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.uiautomator.common;
-
-import android.util.Log;
-
-import com.android.uiautomator.core.UiDevice;
-import com.android.uiautomator.core.UiObject;
-import com.android.uiautomator.core.UiObjectNotFoundException;
-import com.android.uiautomator.core.UiSelector;
-import com.android.uiautomator.core.UiWatcher;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-public class UiWatchers {
- private static final String LOG_TAG = UiWatchers.class.getSimpleName();
- private final List<String> mErrors = new ArrayList<String>();
-
- /**
- * We can use the UiDevice registerWatcher to register a small script to be executed when the
- * framework is waiting for a control to appear. Waiting may be the cause of an unexpected
- * dialog on the screen and it is the time when the framework runs the registered watchers.
- * This is a sample watcher looking for ANR and crashes. it closes it and moves on. You should
- * create your own watchers and handle error logging properly for your type of tests.
- */
- public void registerAnrAndCrashWatchers() {
-
- UiDevice.getInstance().registerWatcher("ANR", new UiWatcher() {
- @Override
- public boolean checkForCondition() {
- UiObject window = new UiObject(new UiSelector().className(
- "com.android.server.am.AppNotRespondingDialog"));
- String errorText = null;
- if (window.exists()) {
- try {
- errorText = window.getText();
- } catch (UiObjectNotFoundException e) {
- Log.e(LOG_TAG, "dialog gone?", e);
- }
- onAnrDetected(errorText);
- postHandler();
- return true; // triggered
- }
- return false; // no trigger
- }
- });
-
- // class names may have changed
- UiDevice.getInstance().registerWatcher("ANR2", new UiWatcher() {
- @Override
- public boolean checkForCondition() {
- UiObject window = new UiObject(new UiSelector().packageName("android")
- .textContains("isn't responding."));
- if (window.exists()) {
- String errorText = null;
- try {
- errorText = window.getText();
- } catch (UiObjectNotFoundException e) {
- Log.e(LOG_TAG, "dialog gone?", e);
- }
- onAnrDetected(errorText);
- postHandler();
- return true; // triggered
- }
- return false; // no trigger
- }
- });
-
- UiDevice.getInstance().registerWatcher("CRASH", new UiWatcher() {
- @Override
- public boolean checkForCondition() {
- UiObject window = new UiObject(new UiSelector().className(
- "com.android.server.am.AppErrorDialog"));
- if (window.exists()) {
- String errorText = null;
- try {
- errorText = window.getText();
- } catch (UiObjectNotFoundException e) {
- Log.e(LOG_TAG, "dialog gone?", e);
- }
- onCrashDetected(errorText);
- postHandler();
- return true; // triggered
- }
- return false; // no trigger
- }
- });
-
- UiDevice.getInstance().registerWatcher("CRASH2", new UiWatcher() {
- @Override
- public boolean checkForCondition() {
- UiObject window = new UiObject(new UiSelector().packageName("android")
- .textContains("has stopped"));
- if (window.exists()) {
- String errorText = null;
- try {
- errorText = window.getText();
- } catch (UiObjectNotFoundException e) {
- Log.e(LOG_TAG, "dialog gone?", e);
- }
- onCrashDetected(errorText);
- postHandler();
- return true; // triggered
- }
- return false; // no trigger
- }
- });
-
- Log.i(LOG_TAG, "Registed GUI Exception watchers");
- }
-
- public void onAnrDetected(String errorText) {
- mErrors.add(errorText);
- }
-
- public void onCrashDetected(String errorText) {
- mErrors.add(errorText);
- }
-
- public void reset() {
- mErrors.clear();
- }
-
- public List<String> getErrors() {
- return Collections.unmodifiableList(mErrors);
- }
-
- /**
- * Current implementation ignores the exception and continues.
- */
- public void postHandler() {
- // TODO: Add custom error logging here
-
- String formatedOutput = String.format("UI Exception Message: %-20s\n", UiDevice
- .getInstance().getCurrentPackageName());
- Log.e(LOG_TAG, formatedOutput);
-
- UiObject buttonOK = new UiObject(new UiSelector().text("OK").enabled(true));
- // sometimes it takes a while for the OK button to become enabled
- buttonOK.waitForExists(5000);
- try {
- buttonOK.click();
- } catch (UiObjectNotFoundException e) {
- Log.e(LOG_TAG, "Exception", e);
- }
- }
-}
diff --git a/uiautomator_test_libraries/src/com/android/uiautomator/common/helpers/AppHelperBase.java b/uiautomator_test_libraries/src/com/android/uiautomator/common/helpers/AppHelperBase.java
deleted file mode 100644
index e3d9b61..0000000
--- a/uiautomator_test_libraries/src/com/android/uiautomator/common/helpers/AppHelperBase.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.uiautomator.common.helpers;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-
-/**
- * Base app helper class intended for all app helper to extend.
- * This class provides common APIs that are expected to be present across
- * all app helpers.
- */
-public abstract class AppHelperBase {
-
- /*
- * App helpers should provide methods for accessing various UI widgets.
- * Assume the app has an Action Bar, the helper should provide something similar to
- * SomeAppHelper.ActionBar.getRefreshButton(). Methods like this help the tests check the
- * state of the targeted widget as well as clicking it if need be. These types of methods are
- * referred to as object getters. If there are different components, consider creating internal
- * name spaces as in the .ActionBar example for better context.
- *
- * Adding basic units of functionality APIs is also very helpful to test.
- * Consider the Alarm clock application as an example. It would be helpful if its helper
- * provided basic functionality such as, setAlarm(Date) and deleteAlarm(Date). Such basic
- * and key functionality helper methods, will abstract the tests from the UI implementation and
- * make tests more reliable.
- */
-
- /**
- * Launches the application.
- *
- * This is typically performed by executing a shell command to launch the application
- * via Intent. It is possible to launch the application by automating the Launcher
- * views and finding the target app icon to launch, however, this is prone to failure if
- * the Launcher UI implementation differ from one platform to another.
- */
- abstract public void open();
-
- /**
- * Checks if the application is in foreground.
- *
- * This is typically performed by verifying the current package name of the foreground
- * application. See UiDevice.getCurrentPackageName()
- * @return true if open, else false.
- */
- abstract public boolean isOpen();
-
-
- /**
- * Helper to execute a shell command.
- * @param command
- */
- protected void runShellCommand(String command) {
- Process p = null;
- BufferedReader resultReader = null;
- try {
- p = Runtime.getRuntime().exec(command);
- int status = p.waitFor();
- if (status != 0) {
- System.err.println(String.format("Run shell command: %s, status: %s", command,
- status));
- }
- } catch (IOException e) {
- System.err.println("// Exception from command " + command + ":");
- System.err.println(e.toString());
- } catch (InterruptedException e) {
- System.err.println("// Interrupted while waiting for the command to finish. ");
- System.err.println(e.toString());
- } finally {
- try {
- if (resultReader != null) {
- resultReader.close();
- }
- if (p != null) {
- p.destroy();
- }
- } catch (IOException e) {
- System.err.println(e.toString());
- }
- }
- }
-}
diff --git a/uiautomator_test_libraries/src/com/android/uiautomator/common/helpers/DatePickerHelper.java b/uiautomator_test_libraries/src/com/android/uiautomator/common/helpers/DatePickerHelper.java
deleted file mode 100644
index 6c7db3a..0000000
--- a/uiautomator_test_libraries/src/com/android/uiautomator/common/helpers/DatePickerHelper.java
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.uiautomator.common.helpers;
-
-import com.android.uiautomator.core.UiObject;
-import com.android.uiautomator.core.UiObjectNotFoundException;
-import com.android.uiautomator.core.UiSelector;
-
-import java.util.Calendar;
-
-/**
- * Use this helper anywhere there is a date picker to manage. This helper
- * will set date specified in a Calendar object.
- */
-public class DatePickerHelper {
-
- public static final int MONTH = 0;
- public static final int DAY = 1;
- public static final int YEAR = 2;
-
- public static String getCurrentMonth() throws UiObjectNotFoundException {
- return getNumberPickerField(MONTH).getText();
- }
-
- public static String getCurrentDay() throws UiObjectNotFoundException {
- return getNumberPickerField(DAY).getText();
- }
-
- public static String getCurrentYear() throws UiObjectNotFoundException {
- return getNumberPickerField(YEAR).getText();
- }
-
- public static void incrementMonth() throws UiObjectNotFoundException {
- incrementMonth(1);
- }
-
- public static void incrementMonth(int count) throws UiObjectNotFoundException {
- for (int x = 0; x < count; x++)
- getNumberPickerIncrementButton(MONTH).click();
- }
-
- public static void decrementMonth() throws UiObjectNotFoundException {
- decrementMonth(1);
- }
-
- public static void decrementMonth(int count) throws UiObjectNotFoundException {
- for (int x = 0; x < count; x++)
- getNumberPickerDecrementButton(MONTH).click();
- }
-
- public static void incrementDay() throws UiObjectNotFoundException {
- incrementDay(1);
- }
-
- public static void incrementDay(int count) throws UiObjectNotFoundException {
- for (int x = 0; x < count; x++)
- getNumberPickerIncrementButton(DAY).click();
- }
-
- public static void decrementDay() throws UiObjectNotFoundException {
- decrementDay(1);
- }
-
- public static void decrementDay(int count) throws UiObjectNotFoundException {
- for (int x = 0; x < count; x++)
- getNumberPickerDecrementButton(DAY).click();
- }
-
- public static void incrementYear() throws UiObjectNotFoundException {
- incrementYear(1);
- }
-
- public static void incrementYear(int count) throws UiObjectNotFoundException {
- for (int x = 0; x < count; x++)
- getNumberPickerIncrementButton(YEAR).click();
- }
-
- public static void decrementYear() throws UiObjectNotFoundException {
- decrementYear(1);
- }
-
- public static void decrementYear(int count) throws UiObjectNotFoundException {
- for (int x = 0; x < count; x++)
- getNumberPickerDecrementButton(YEAR).click();
- }
-
- public static UiObject getNumberPicker(int instance) {
- return new UiObject(new UiSelector().className(
- android.widget.NumberPicker.class.getName()).instance(instance));
- }
-
- public static UiObject getNumberPickerField(int instance)
- throws UiObjectNotFoundException {
- return getNumberPicker(instance).getChild(
- new UiSelector().className(android.widget.EditText.class.getName()));
- }
-
- public static UiObject getNumberPickerDecrementButton(int instance)
- throws UiObjectNotFoundException {
- return getNumberPicker(instance).getChild(
- new UiSelector().className(android.widget.Button.class.getName()).instance(0));
- }
-
- public static UiObject getNumberPickerIncrementButton(int instance)
- throws UiObjectNotFoundException {
- return getNumberPicker(instance).getChild(
- new UiSelector().className(android.widget.Button.class.getName()).instance(1));
- }
-
- public static void clickDone() throws UiObjectNotFoundException {
- new UiObject(new UiSelector().text("Done")).click();
- }
-
- public static void setDate(Calendar cal) throws UiObjectNotFoundException {
- int calYear = cal.get(Calendar.YEAR);
- int calMonth = cal.get(Calendar.MONTH);
- int calDay = cal.get(Calendar.DAY_OF_MONTH);
-
- // Adjust day - increment or decrement using the shortest path
- // while accounting for number of days in month and considering
- // special case for Feb and leap years.
- int dpDay = Integer.parseInt(getCurrentDay());
- if (calDay > dpDay) {
- if (calDay - dpDay < getDaysInMonth(calYear, calMonth) / 2)
- incrementDay(calDay - dpDay);
- else
- decrementDay(dpDay - calDay + getDaysInMonth(calYear, calMonth));
- } else if (dpDay > calDay) {
- if (dpDay - calDay < getDaysInMonth(calYear, calMonth) / 2)
- decrementDay(dpDay - calDay);
- else
- incrementDay(calDay - dpDay + getDaysInMonth(calYear, calMonth));
- }
-
- // Adjust month - increment or decrement using the shortest path
- int dpMonth = toMonthNumber(getCurrentMonth());
- if (calMonth > dpMonth) {
- if (calMonth - dpMonth < 6)
- incrementMonth(calMonth - dpMonth);
- else
- decrementMonth(dpMonth - calMonth + 12);
- } else if (dpMonth > calMonth) {
- if (dpMonth - calMonth < 6)
- decrementMonth(dpMonth - calMonth);
- else
- incrementMonth(calMonth - dpMonth + 12);
- }
-
- // Adjust year
- int dpYear = Integer.parseInt(getCurrentYear());
- if (calYear > dpYear) {
- incrementYear(calYear - dpYear);
- } else if (dpYear > calYear) {
- decrementYear(dpYear - calYear);
- }
- }
-
- private static int toMonthNumber(String monthName) {
- String months[] = new String[] {"January", "February", "March", "April", "May", "June",
- "July", "August", "September", "October", "November", "December"};
-
- for (int x = 0; x < months.length; x++) {
- if (months[x].contains(monthName))
- return x;
- }
-
- return 0;
- }
-
- /**
- * Get the number of days in the month
- * @param year
- * @param month
- * @return
- */
- private static int getDaysInMonth(int year, int month) {
- Calendar cal = Calendar.getInstance();
- cal.set(Calendar.YEAR, year);
- cal.set(Calendar.MONTH, month);
- return cal.getActualMaximum(Calendar.DAY_OF_MONTH);
- }
-}
diff --git a/uiautomator_test_libraries/src/com/android/uiautomator/common/helpers/TimePickerHelper.java b/uiautomator_test_libraries/src/com/android/uiautomator/common/helpers/TimePickerHelper.java
deleted file mode 100644
index c5e3add..0000000
--- a/uiautomator_test_libraries/src/com/android/uiautomator/common/helpers/TimePickerHelper.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.uiautomator.common.helpers;
-
-import com.android.uiautomator.core.UiObject;
-import com.android.uiautomator.core.UiObjectNotFoundException;
-import com.android.uiautomator.core.UiSelector;
-
-import java.util.Calendar;
-import java.util.Locale;
-
-/**
- * Use this helper anywhere there is a time picker to manage. This helper
- * will set time specified in a Calendar object.
- */
-public class TimePickerHelper {
-
- public static final int HOUR = 0;
- public static final int MINUTE = 1;
- public static final int MERIDIEM = 2;
-
- public static String getCurrentHour() throws UiObjectNotFoundException {
- return getNumberPickerField(HOUR).getText();
- }
-
- public static String getCurrentMinute() throws UiObjectNotFoundException {
- return getNumberPickerField(MINUTE).getText();
- }
-
- public static String getCurrentMeridiem() throws UiObjectNotFoundException {
- return getNumberPickerField(MERIDIEM).getText();
- }
-
-
- public static void incrementHour() throws UiObjectNotFoundException {
- incrementHour(1);
- }
-
- public static void incrementHour(int count) throws UiObjectNotFoundException {
- for (int x = 0; x < count; x++)
- getNumberPickerIncrementButton(HOUR).click();
- }
-
- public static void decrementHour() throws UiObjectNotFoundException {
- decrementHour(1);
- }
-
- public static void decrementHour(int count) throws UiObjectNotFoundException {
- for (int x = 0; x < count; x++)
- getNumberPickerDecrementButton(HOUR).click();
- }
-
- public static void incrementMinute() throws UiObjectNotFoundException {
- incrementMinute(1);
- }
-
- public static void incrementMinute(int count) throws UiObjectNotFoundException {
- for (int x = 0; x < count; x++)
- getNumberPickerIncrementButton(MINUTE).click();
- }
-
- public static void decrementMinute() throws UiObjectNotFoundException {
- decrementMinute(1);
- }
-
- public static void decrementMinute(int count) throws UiObjectNotFoundException {
- for (int x = 0; x < count; x++)
- getNumberPickerDecrementButton(MINUTE).click();
- }
-
- public static void selectPM() throws UiObjectNotFoundException {
- getNumberPicker(MERIDIEM).getChild(new UiSelector().text("PM")).click();
- }
-
- public static void selectAM() throws UiObjectNotFoundException {
- getNumberPicker(MERIDIEM).getChild(new UiSelector().text("AM")).click();
- }
-
- public static UiObject getNumberPicker(int instance) {
- return new UiObject(new UiSelector().className(
- android.widget.NumberPicker.class.getName()).instance(instance));
- }
-
- public static UiObject getNumberPickerField(int instance)
- throws UiObjectNotFoundException {
- return getNumberPicker(instance).getChild(
- new UiSelector().className(android.widget.EditText.class.getName()));
- }
-
- public static UiObject getNumberPickerDecrementButton(int instance)
- throws UiObjectNotFoundException {
- return getNumberPicker(instance).getChild(
- new UiSelector().className(android.widget.Button.class.getName()).instance(0));
- }
-
- public static UiObject getNumberPickerIncrementButton(int instance)
- throws UiObjectNotFoundException {
- return getNumberPicker(instance).getChild(
- new UiSelector().className(android.widget.Button.class.getName()).instance(1));
- }
-
- public static void clickDone() throws UiObjectNotFoundException {
- new UiObject(new UiSelector().text("Done")).click();
- }
-
- public static void setTime(Calendar cal) throws UiObjectNotFoundException {
- // Adjust minutes - increment or decrement using the shortest path
- int tpMinute = Integer.parseInt(getCurrentMinute());
- int calMinute = cal.get(Calendar.MINUTE);
- if (calMinute > tpMinute) {
- if (calMinute - tpMinute < 30)
- incrementMinute(calMinute - tpMinute);
- else
- decrementMinute(tpMinute - calMinute + 60);
- } else if (tpMinute > calMinute) {
- if (tpMinute - calMinute < 30)
- decrementMinute(tpMinute - calMinute);
- else
- incrementMinute(calMinute - tpMinute + 60);
- }
-
- // Adjust hour - increment or decrement using the shortest path
- int tpHour = Integer.parseInt(getCurrentHour());
- int calHour = cal.get(Calendar.HOUR);
- if (calHour > tpHour) {
- if (calHour - tpHour < 6)
- incrementHour(calHour - tpHour);
- else
- decrementHour(tpHour - calHour + 12);
- } else if (tpHour > calHour) {
- if (tpHour - calHour < 6)
- decrementHour(tpHour - calHour);
- else
- incrementHour(calHour - tpHour + 12);
- }
-
- // Adjust meridiem
- String calMer = cal.getDisplayName(Calendar.AM_PM, Calendar.SHORT, Locale.US);
- String tpMer = getCurrentMeridiem();
- if (tpMer.equalsIgnoreCase(calMer))
- return;
-
- if (!calMer.equalsIgnoreCase("AM")) {
- selectPM();
- } else {
- selectAM();
- }
- }
-}
diff --git a/uiautomator_test_libraries/src/com/android/uiautomator/platform/JankTestBase.java b/uiautomator_test_libraries/src/com/android/uiautomator/platform/JankTestBase.java
deleted file mode 100644
index 6662f80..0000000
--- a/uiautomator_test_libraries/src/com/android/uiautomator/platform/JankTestBase.java
+++ /dev/null
@@ -1,481 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.uiautomator.platform;
-
-import android.os.Bundle;
-import android.os.Environment;
-import android.util.Log;
-
-import com.android.uiautomator.core.UiDevice;
-import com.android.uiautomator.testrunner.UiAutomatorTestCase;
-
-import java.io.BufferedOutputStream;
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-
-/**
- * Base class for jank test.
- * All jank test needs to extend JankTestBase
- */
-public class JankTestBase extends UiAutomatorTestCase {
- private static final String TAG = JankTestBase.class.getSimpleName();
-
- protected UiDevice mDevice;
- protected TestWatchers mTestWatchers = null;
- protected BufferedWriter mWriter = null;
- protected BufferedWriter mStatusWriter = null;
- protected int mIteration = 20; // default iteration is set 20
- /* can be used to enable/disable systrace in the test */
- protected int mTraceTime = 0;
- protected Bundle mParams;
- protected String mTestCaseName;
- protected int mSuccessTestRuns = 0;
- protected Thread mThread = null;
-
- // holds all params for the derived tests
- private static final String PROPERTY_FILE_NAME = "UiJankinessTests.conf";
- private static final String PARAM_CONFIG = "conf";
- private static final String LOCAL_TMP_DIR = "/data/local/tmp/";
- // File that hold the test results
- private static String OUTPUT_FILE_NAME = LOCAL_TMP_DIR + "UiJankinessTestsOutput.txt";
- // File that hold test status, e.g successful test iterations
- private static String STATUS_FILE_NAME = LOCAL_TMP_DIR + "UiJankinessTestsStatus.txt";
- private static final String RAW_DATA_DIR = LOCAL_TMP_DIR + "UiJankinessRawData";
-
- private static int SUCCESS_THRESHOLD = 80;
- private static boolean DEBUG = false;
-
- /* default animation time is set to 2 seconds */
- protected static final long DEFAULT_ANIMATION_TIME = 2 * 1000;
- /* default swipe steps for fling animation */
- protected static final int DEFAULT_FLING_STEPS = 8;
-
- /* Array to record jankiness data in each test iteration */
- private int[] jankinessArray;
- /* Array to record frame rate in each test iteration */
- private double[] frameRateArray;
- /* Array to save max accumulated frame number in each test iteration */
- private int[] maxDeltaVsyncArray;
- /* Default file to store the systrace */
- private static final File SYSTRACE_DIR = new File(LOCAL_TMP_DIR, "systrace");
- /* Default trace file name */
- private static final String TRACE_FILE_NAME = "trace.txt";
- /* Default tracing time is 5 seconds */
- private static final int DEFAULT_TRACE_TIME = 5; // 5 seconds
- // Command to dump compressed trace data
- private static final String ATRACE_COMMAND = "atrace -z -t %d gfx input view sched freq";
-
- /**
- * Thread to capture systrace log from the test
- */
- public class SystraceTracker implements Runnable {
- File mFile = new File(SYSTRACE_DIR, TRACE_FILE_NAME);
- int mTime = DEFAULT_TRACE_TIME;
-
- public SystraceTracker(int traceTime, String fileName) {
- try {
- if (!SYSTRACE_DIR.exists()) {
- if (!SYSTRACE_DIR.mkdir()) {
- log(String.format("create directory %s failed, you can manually create "
- + "it and start the test again", SYSTRACE_DIR.getAbsolutePath()));
- return;
- }
- }
- } catch (SecurityException e) {
- Log.e(TAG, "creating directory failed?", e);
- }
-
- if (traceTime > 0) {
- mTime = traceTime;
- }
- if (fileName != null) {
- mFile = new File(SYSTRACE_DIR, fileName);
- }
- }
-
- @Override
- public void run() {
- String command = String.format(ATRACE_COMMAND, mTime);
- Log.v(TAG, "command: " + command);
- Process p = null;
- InputStream in = null;
- BufferedOutputStream out = null;
- try {
- p = Runtime.getRuntime().exec(command);
- Log.v(TAG, "write systrace into file: " + mFile.getAbsolutePath());
- // read bytes from the process output stream as the output is compressed
- byte[] buffer = new byte[1024];
- in = p.getInputStream();
- out = new BufferedOutputStream(new FileOutputStream(mFile));
- int n;
- while ((n = in.read(buffer)) != -1) {
- out.write(buffer, 0, n);
- out.flush();
- }
- in.close();
- out.close();
- // read error message
- BufferedReader br = new BufferedReader(new InputStreamReader(p.getErrorStream()));
- String line;
- while ((line = br.readLine()) != null) {
- Log.e(TAG, "Command return errors: " + line);
- }
- br.close();
-
- // Due to limited buffer size for standard input and output stream,
- // promptly reading from the input stream or output stream to avoid block
- int status = p.waitFor();
- if (status != 0) {
- Log.e(TAG, String.format("Run shell command: %s, status: %s",
- command, status));
- }
- } catch (InterruptedException e) {
- Log.e(TAG, "Exception from command " + command + ":");
- Log.e(TAG, "Thread interrupted? ", e);
- } catch (IOException e) {
- Log.e(TAG, "Open file error: ", e);
- } catch (IllegalThreadStateException e) {
- Log.e(TAG, "the process has not exit yet ", e);
- }
- }
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- mDevice = UiDevice.getInstance();
- mTestWatchers = new TestWatchers(); // extends the common class UiWatchers
- mTestWatchers.registerAnrAndCrashWatchers();
-
- mWriter = new BufferedWriter(new FileWriter(new File(OUTPUT_FILE_NAME), true));
- mStatusWriter = new BufferedWriter(new FileWriter(new File(STATUS_FILE_NAME), true));
-
- mParams = getParams();
- if (mParams != null && !mParams.isEmpty()) {
- log("mParams is not empty, get properties.");
- String mIterationStr = getPropertyString(mParams, "iteration");
- if (mIterationStr != null) {
- mIteration = Integer.valueOf(mIterationStr);
- }
- String mTraceTimeStr = getPropertyString(mParams, "tracetime");
- if (mTraceTimeStr != null) {
- mTraceTime = Integer.valueOf(mTraceTimeStr);
- }
- }
- jankinessArray = new int[mIteration];
- frameRateArray = new double[mIteration];
- maxDeltaVsyncArray = new int[mIteration];
- mTestCaseName = this.getName();
-
- mSuccessTestRuns = 0;
- mDevice.pressHome();
- }
-
- /**
- * Create a new thread for systrace and start the thread
- *
- * @param testCaseName
- * @param iteration
- */
- protected void startTrace(String testCaseName, int iteration) {
- if (mTraceTime > 0) {
- String outputFile = String.format("%s_%d_trace", mTestCaseName, iteration);
- mThread = new Thread(new SystraceTracker(mTraceTime, outputFile));
- mThread.start();
- }
- }
-
- /**
- * Wait for the tracing thread to exit
- */
- protected void endTrace() {
- if (mThread != null) {
- try {
- mThread.join();
- } catch (InterruptedException e) {
- Log.e(TAG, "wait for the trace thread to exit exception:", e);
- }
- }
- }
-
- /**
- * Expects a file from the command line via conf param or default following format each on its
- * own line. <code>
- * key=Value
- * Browser_URL1=cnn.com
- * Browser_URL2=google.com
- * Camera_ShutterDelay=1000
- * etc...
- * </code>
- * @param Bundle params
- * @param key
- * @return the value of the property else defaultValue
- * @throws FileNotFoundException
- * @throws IOException
- */
- protected String getPropertyString(Bundle params, String key)
- throws FileNotFoundException, IOException {
- Properties prop = new Properties();
- prop.load(new FileInputStream(new File(LOCAL_TMP_DIR,
- params.getString(PARAM_CONFIG, PROPERTY_FILE_NAME))));
- String value = prop.getProperty(key);
- if (value != null && !value.isEmpty())
- return value;
- return null;
- }
-
- /**
- * Expects a file from the command line via conf param or default following format each on its
- * own line. <code>
- * key=Value
- * Browser_URL1=cnn.com
- * Browser_URL2=google.com
- * Camera_ShutterDelay=1000
- * etc...
- * </code>
- * @param Bundle params
- * @param key
- * @return the value of the property else defaultValue
- * @throws FileNotFoundException
- * @throws IOException
- */
- protected long getPropertyLong(Bundle params, String key)
- throws FileNotFoundException, IOException {
- Properties prop = new Properties();
- prop.load(new FileInputStream(new File(LOCAL_TMP_DIR,
- params.getString(PARAM_CONFIG, PROPERTY_FILE_NAME))));
- String value = prop.getProperty(key);
- if (value != null && !value.trim().isEmpty())
- return Long.valueOf(value.trim());
- return 0;
- }
-
- /**
- * Verify the test result by comparing data sample size with expected value
- * @param expectedDataSize the expected data size
- */
- protected boolean validateResults(int expectedDataSize) {
- int receivedDataSize = SurfaceFlingerHelper.getDataSampleSize();
- return ((expectedDataSize > 0) && (receivedDataSize >= expectedDataSize));
- }
-
- /**
- * Process the raw data, calculate jankiness, frame rate and max accumulated frames number
- * @param testCaseName
- * @param iteration
- */
- protected void recordResults(String testCaseName, int iteration) {
- long refreshPeriod = SurfaceFlingerHelper.getRefreshPeriod();
- // if the raw directory doesn't exit, create the directory
- File rawDataDir = new File(RAW_DATA_DIR);
- try {
- if (!rawDataDir.exists()) {
- if (!rawDataDir.mkdir()) {
- log(String.format("create directory %s failed, you can manually create " +
- "it and start the test again", rawDataDir));
- }
- }
- } catch (SecurityException e) {
- Log.e(TAG, "create directory failed: ", e);
- }
- String rawFileName = String.format("%s/%s_%d.txt", RAW_DATA_DIR, testCaseName, iteration);
- // write results into a file
- BufferedWriter fw = null;
- try {
- fw = new BufferedWriter(new FileWriter(new File(rawFileName), false));
- fw.write(SurfaceFlingerHelper.getFrameBufferData());
- } catch (IOException e) {
- Log.e(TAG, "failed to write to file", e);
- return;
- } finally {
- try {
- if (fw != null) {
- fw.close();
- }
- }
- catch (IOException e) {
- Log.e(TAG, "close file failed.", e);
- }
- }
-
- // get jankiness count
- int jankinessCount = SurfaceFlingerHelper.getVsyncJankiness();
- // get frame rate
- double frameRate = SurfaceFlingerHelper.getFrameRate();
- // get max accumulated frames
- int maxDeltaVsync = SurfaceFlingerHelper.getMaxDeltaVsync();
-
- // only record data when they are valid
- if (jankinessCount >=0 && frameRate > 0) {
- jankinessArray[iteration] = jankinessCount;
- frameRateArray[iteration] = frameRate;
- maxDeltaVsyncArray[iteration] = maxDeltaVsync;
- mSuccessTestRuns++;
- }
- String msg = String.format("%s, iteration %d\n" +
- "refresh period: %d\n" +
- "jankiness count: %d\n" +
- "frame rate: %f\n" +
- "max accumulated frames: %d\n",
- testCaseName, iteration, refreshPeriod,
- jankinessCount, frameRate, maxDeltaVsync);
- log(msg);
- if (DEBUG) {
- SurfaceFlingerHelper.printData(testCaseName, iteration);
- }
- }
-
- /**
- * Process data from all test iterations, and save to disk
- * @param testCaseName
- */
- protected void saveResults(String testCaseName) {
- // write test status into status file
- try {
- mStatusWriter.write(String.format("%s: %d success runs out of %d iterations\n",
- testCaseName, mSuccessTestRuns, mIteration));
- } catch (IOException e) {
- log("failed to write output for test case " + testCaseName);
- }
-
- // if successful test runs is less than the threshold, no results will be saved.
- if (mSuccessTestRuns * 100 / mIteration < SUCCESS_THRESHOLD) {
- log(String.format("In %s, # of successful test runs out of %s iterations: %d ",
- testCaseName, mIteration, mSuccessTestRuns));
- log(String.format("threshold is %d%%", SUCCESS_THRESHOLD));
- return;
- }
-
- if (DEBUG) {
- print(jankinessArray, "jankiness array");
- print(frameRateArray, "frame rate array");
- print(maxDeltaVsyncArray, "max delta vsync array");
- }
- double avgJankinessCount = getAverage(jankinessArray);
- int maxJankinessCount = getMaxValue(jankinessArray);
- double avgFrameRate = getAverage(frameRateArray);
- double avgMaxDeltaVsync = getAverage(maxDeltaVsyncArray);
-
- String avgMsg = String.format("%s\n" +
- "average number of jankiness: %f\n" +
- "max number of jankiness: %d\n" +
- "average frame rate: %f\n" +
- "average of max accumulated frames: %f\n",
- testCaseName, avgJankinessCount, maxJankinessCount, avgFrameRate, avgMaxDeltaVsync);
- log(avgMsg);
-
- try {
- mWriter.write(avgMsg);
- } catch (IOException e) {
- log("failed to write output for test case " + testCaseName);
- }
- }
-
- // return the max value in an integer array
- private int getMaxValue(int[] intArray) {
- int index = 0;
- int max = intArray[index];
- for (int i = 1; i < intArray.length; i++) {
- if (max < intArray[i]) {
- max = intArray[i];
- }
- }
- return max;
- }
-
- private double getAverage(int[] intArray) {
- int mean = 0;
- int numberTests = 0;
- for (int i = 0; i < intArray.length; i++) {
- // in case in some iteration, test fails, no data points is collected
- if (intArray[i] >= 0) {
- mean += intArray[i];
- ++numberTests;
- }
- }
- return (double)mean/numberTests;
- }
-
- private double getAverage(double[] doubleArray) {
- double mean = 0;
- int numberTests = 0;
- for (int i = 0; i < doubleArray.length; i++) {
- // in case in some iteration, test fails, no data points is collected
- if (doubleArray[i] >= 0) {
- mean += doubleArray[i];
- ++numberTests;
- }
- }
- return mean/numberTests;
- }
-
- private void print(int[] intArray, String arrayName) {
- log("start to print array for " + arrayName);
- for (int i = 0; i < intArray.length; i++) {
- log(String.format("%d: %d", i, intArray[i]));
- }
- }
-
- private void print(double[] doubleArray, String arrayName) {
- log("start to print array for " + arrayName);
- for (int i = 0; i < doubleArray.length; i++) {
- log(String.format("%d: %f", i, doubleArray[i]));
- }
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- if (mWriter != null) {
- mWriter.close();
- }
- if (mStatusWriter != null) {
- mStatusWriter.close();
- }
- }
-
- private void log(String message) {
- Log.v(TAG, message);
- }
-
- /**
- * Set the total number of test iteration
- * @param iteration
- */
- protected void setIteration(int iteration){
- mIteration = iteration;
- }
-
- /**
- * Get the total number of test iteration
- * @return iteration
- */
- protected int getIteration(){
- return mIteration;
- }
-}
diff --git a/uiautomator_test_libraries/src/com/android/uiautomator/platform/SurfaceFlingerHelper.java b/uiautomator_test_libraries/src/com/android/uiautomator/platform/SurfaceFlingerHelper.java
deleted file mode 100644
index 748b433..0000000
--- a/uiautomator_test_libraries/src/com/android/uiautomator/platform/SurfaceFlingerHelper.java
+++ /dev/null
@@ -1,421 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.uiautomator.platform;
-
-import android.os.Environment;
-import android.util.Log;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.ArrayList;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.BufferedWriter;
-import java.io.InputStreamReader;
-import java.io.IOException;
-import java.lang.Math;
-
-/*
- * Tools to measure jankiness through SurfaceFlinger
- */
-public class SurfaceFlingerHelper {
- private static String TAG = "SurfaceFlingerHelper";
- private static int BUFFER_SIZE = 128;
- private static int BUFFER_NUMBER = 3;
- private static String CLEAR_BUFFER_CMD = "dumpsys SurfaceFlinger --latency-clear";
- private static String FRAME_LATENCY_CMD = "dumpsys SurfaceFlinger --latency";
- private static final String RAW_DATA_DIR = "UiJankinessRawData";
- private static final String LOCAL_TMP_DIR = "/data/local/tmp/";
- /* If the latency between two frames is greater than this number, it it treated as a pause
- * not a jankiness */
- private static final int PAUSE_LATENCY = 20;
-
- /* An array list which includes the raw buffer information from frame latency tool */
- private static List<List<String>> mFrameBufferData = new ArrayList<List<String>>(BUFFER_SIZE);
-
- /* Record the refresh period returned from driver */
- private static long mRefreshPeriod = -1;
-
- /* Record the size of frame latency */
- private static int mFrameLatencySampleSize = 0;
-
- /* An integer array which includes delta vsync */
- private static long[] mDeltaVsync = new long[BUFFER_SIZE];
-
- /* Integer array for delta of delta vsync */
- private static long[] mDelta2Vsync = new long[BUFFER_SIZE];
-
- /* the maximum delta vsync number */
- private static long mMaxDeltaVsync;
-
- /* Normalized data */
- private static double[] mNormalizedDelta2Vsync = new double[BUFFER_SIZE];
- private static int[] mRoundNormalizedDelta2Vsync = new int[BUFFER_SIZE];
- // Symbol of unfinished frame time */
- public static final String PENDING_FENCE_TIME = new Long(Long.MAX_VALUE).toString();
-
- /**
- * Run clear buffer command and clear the saved frame buffer results
- *
- * @param windowName the window name that the buffer will be cleared
- */
- public static void clearBuffer(String windowName) {
- // clear results
- if (mFrameBufferData != null) {
- mFrameBufferData.clear();
- }
- Arrays.fill(mDeltaVsync, -1);
- Arrays.fill(mDelta2Vsync, -1);
- Arrays.fill(mNormalizedDelta2Vsync, -1.0);
- Arrays.fill(mRoundNormalizedDelta2Vsync, -1);
- mRefreshPeriod = -1;
- mFrameLatencySampleSize = 0;
- mMaxDeltaVsync = 0;
-
- Process p = null;
- BufferedReader resultReader = null;
- String command = CLEAR_BUFFER_CMD;
- if (windowName != null) {
- command = String.format("%s %s", CLEAR_BUFFER_CMD, windowName);
- }
- try {
- p = Runtime.getRuntime().exec(command);
- int status = p.waitFor();
- if (status != 0) {
- Log.e(TAG, String.format("Run shell command: %s, status: %s",
- command, status));
- }
- } catch (IOException e) {
- Log.e(TAG, "// Exception from command " + command + ":", e);
- } catch (InterruptedException e) {
- Log.e(TAG, "// Interrupted while waiting for the command to finish. ", e);
- } finally {
- try {
- if (resultReader != null) {
- resultReader.close();
- }
- if (p != null) {
- p.destroy();
- }
- } catch (IOException e) {
- Log.e(TAG, "exception " + e);
- }
- }
- }
-
- /**
- * Run frame latency command without ignoring pending fence time
- *
- * @param windowName the window name which SurfaceFlinger will acquire frame time for
- */
- public static boolean dumpFrameLatency(String windowName) {
- return dumpFrameLatency(windowName, false);
- }
-
- /**
- * Run frame latency command to get frame time
- *
- * @param windowName the window name which SurfaceFlinger will get frame time for
- * @param ignorePendingFenceTime flag to process frames with pending fence time
- * set true to ignore pending fence time
- * set false to fail the test if pending fence time is not allowed
- */
- public static boolean dumpFrameLatency(String windowName, boolean ignorePendingFenceTime) {
- Process p = null;
- BufferedReader resultReader = null;
- String command = FRAME_LATENCY_CMD;
- if (windowName != null) {
- command = String.format("%s %s", FRAME_LATENCY_CMD, windowName);
- }
- log("dump frame latency command: " + command);
- try {
- p = Runtime.getRuntime().exec(command);
- int status = p.waitFor();
- if (status != 0) {
- Log.e(TAG, String.format("Run shell command: %s, status: %s",command, status));
- }
- resultReader = new BufferedReader(new InputStreamReader(p.getInputStream()));
- String line = resultReader.readLine();
- mRefreshPeriod = Long.parseLong(line.trim());
- log("reading refresh period: " + mRefreshPeriod);
- if (mRefreshPeriod < 0) {
- return false;
- }
- boolean dataInvalidFlag = false;
- while((line = resultReader.readLine()) != null) {
- // remove lines which are empty
- if (line.trim().isEmpty()) {
- break;
- }
- String[] bufferValues = line.split("\\s+");
- if (bufferValues[0].trim().compareTo("0") == 0) {
- continue;
- } else if (bufferValues[1].trim().compareTo(PENDING_FENCE_TIME) == 0 ) {
- if (ignorePendingFenceTime) {
- log("ignore pending fence time");
- dataInvalidFlag = true;
- } else {
- log("the data contains unfinished frame time, please allow the animation"
- + " to finish in the test before calling dumpFrameLatency.");
- return false;
- }
- }
- // store raw data which could have both valid and invalid data
- List<String> delayArray = Arrays.asList(bufferValues);
- mFrameBufferData.add(delayArray);
- if (!dataInvalidFlag) {
- // only count frames which have valid time
- ++mFrameLatencySampleSize;
- }
- }
- log("frame latency sample size: " + mFrameLatencySampleSize);
- } catch (InterruptedException e) {
- Log.e(TAG, "// Exception from command " + command + ":", e);
- } catch (IOException e) {
- Log.e(TAG, "Open file error: ", e);
- return false;
- }
- finally {
- try {
- if (resultReader != null) {
- resultReader.close();
- }
- if (p != null) {
- p.destroy();
- }
- } catch (IOException e) {
- Log.e(TAG, "io exception: ", e);
- }
- }
- return true;
- }
-
- public static int getDataSampleSize() {
- return mFrameLatencySampleSize;
- }
-
- public static long getRefreshPeriod() {
- if (mRefreshPeriod < 0) {
- // Haven't dump the frame latency yet
- log("Run command \"" + FRAME_LATENCY_CMD + " \" before retrieving the refresh period");
- }
- return mRefreshPeriod;
- }
-
- public static String getFrameBufferData() {
- if (mFrameBufferData.get(0) == null) {
- log("Run command \"" + FRAME_LATENCY_CMD + " \" before retrieving frame buffer data");
- return null;
- }
- String rawData = String.format("%d\n", mRefreshPeriod);
- List<String> tempList = new ArrayList<String>(BUFFER_NUMBER);
- for (int i = 0; i < mFrameBufferData.size(); i++) {
- tempList = mFrameBufferData.get(i);
- for (int j = 0; j < BUFFER_NUMBER; j++) {
- rawData += String.format("%s", tempList.get(j));
- if (j < BUFFER_NUMBER - 1) {
- rawData += "\t";
- } else {
- rawData += "\n";
- }
- }
- }
- return rawData;
- }
-
- /**
- * Calculate delta(vsync)
- * @return
- */
- public static long[] getDeltaVsync() {
- if (mRefreshPeriod < 0) {
- log("Run command \"" + FRAME_LATENCY_CMD + " \" before retrieving frame latency");
- return null;
- }
- if (mDeltaVsync[0] < 0 ) {
- // keep a record of the max DeltaVsync
- mMaxDeltaVsync = 0;
- // get the first frame vsync time
- long preVsyncTime = Long.parseLong(mFrameBufferData.get(0).get(1));
- for (int i = 0; i < mFrameLatencySampleSize - 1; i++) {
- long curVsyncTime = Long.parseLong(mFrameBufferData.get(i + 1).get(1));
- mDeltaVsync[i] = curVsyncTime - preVsyncTime;
- preVsyncTime = curVsyncTime;
- if (mMaxDeltaVsync < mDeltaVsync[i]) {
- mMaxDeltaVsync = mDeltaVsync[i];
- }
- }
- }
- return mDeltaVsync;
- }
-
- /**
- * Calculate difference between delta vsync
- * @return
- */
- public static long[] getDelta2Vsync() {
- if (mRefreshPeriod < 0) {
- log("Run command \"" + FRAME_LATENCY_CMD + " \" before retrieving frame latency");
- return null;
- }
- if (mDeltaVsync[0] < 0) {
- getDeltaVsync();
- }
- if (mDelta2Vsync[0] < 0) {
- int numDeltaVsync = mFrameLatencySampleSize - 1;
- for (int i = 0; i < numDeltaVsync - 1; i++) {
- mDelta2Vsync[i] = mDeltaVsync[i + 1] - mDeltaVsync[i];
- }
- }
- return mDelta2Vsync;
- }
-
- /**
- * normalized delta(delta(vsync)) by refresh period
- * @return
- */
- public static double[] getNormalizedDelta2Vsync() {
- if (mRefreshPeriod < 0) {
- log("Run command \"" + FRAME_LATENCY_CMD + " \" before retrieving frame latency");
- return null;
- }
- if (mDelta2Vsync[0] < 0) {
- getDelta2Vsync();
- }
- if (mNormalizedDelta2Vsync[0] < 0) {
- for (int i = 0; i < mFrameLatencySampleSize - 2; i++) {
- mNormalizedDelta2Vsync[i] = (double)mDelta2Vsync[i] /mRefreshPeriod;
- }
- }
- return mNormalizedDelta2Vsync;
- }
-
- public static int[] getRoundNormalizedDelta2Vsync() {
- if (mRefreshPeriod < 0) {
- log("Run command \"" + FRAME_LATENCY_CMD + " \" for number of jankiness.");
- return null;
- }
- if (mNormalizedDelta2Vsync[0] < 0) {
- getNormalizedDelta2Vsync();
- }
-
- for (int i = 0; i < mFrameLatencySampleSize - 2; i++) {
- int value = (int)Math.round(Math.max(mNormalizedDelta2Vsync[i], 0.0));
- mRoundNormalizedDelta2Vsync[i] = value;
- }
- return mRoundNormalizedDelta2Vsync;
- }
-
- /*
- * Get number of jankiness using Vsync time difference
- */
- public static int getVsyncJankiness() {
- if (mRefreshPeriod < 0) {
- log("Run command \"" + FRAME_LATENCY_CMD + " \" for number of jankiness.");
- return -1;
- }
- if (mRoundNormalizedDelta2Vsync[0] < 0) {
- getRoundNormalizedDelta2Vsync();
- }
- int numberJankiness = 0;
- for (int i = 0; i < mFrameLatencySampleSize - 2; i++) {
- int value = mRoundNormalizedDelta2Vsync[i];
- // ignore the latency which is too long
- if (value > 0 && value < PAUSE_LATENCY) {
- numberJankiness++;
- }
- }
- return numberJankiness;
- }
-
- /* Track the maximum delta which shows the accumulating time
- * before animation starts */
- public static int getMaxDeltaVsync() {
- return Math.round((float)mMaxDeltaVsync /mRefreshPeriod);
- }
-
- /**
- * Calculate frame rate
- * @return
- */
- public static double getFrameRate() {
- if (mRefreshPeriod < 0) {
- log("Run command \"" + FRAME_LATENCY_CMD + " \" before calcuating average frame rate");
- return -1.0;
- }
- if (mFrameBufferData.get(0) == null) {
- log("Run command \"" + FRAME_LATENCY_CMD + " \" before retrieving frame buffer data");
- return -1.0;
- }
- long startTime = Long.parseLong(mFrameBufferData.get(0).get(1));
- long endTime = Long.parseLong(mFrameBufferData.get(mFrameLatencySampleSize - 1).get(1));
- long totalDuration = endTime - startTime;
- return (double)((mFrameLatencySampleSize - 1) * Math.pow(10, 9))/totalDuration;
- }
-
- /**
- * Print raw data and processed results into file <testcasename_[iteration]_processed.txt>
- * @param fileName
- * @param index
- */
- public static void printData(String fileName, int index) {
- String rawAndProcDataFileName = String.format("%s/%s_%d_processed.txt", RAW_DATA_DIR,
- fileName, index);
- log("write raw data and process data into file: " + rawAndProcDataFileName);
- BufferedWriter fw = null;
- try {
- fw = new BufferedWriter(new FileWriter(new File(rawAndProcDataFileName), false));
- // Show the number of jankiness first:
- fw.write(String.format("Jankiness count: %d\n", getVsyncJankiness()));
- fw.write(String.format("Max accumulated frames: %d\n", getMaxDeltaVsync()));
- fw.write(String.format("Frame rate is: %f\n", getFrameRate()));
-
- // refresh period
- fw.write(String.valueOf(mRefreshPeriod));
- fw.write("\n");
- fw.write("app\tvsync\tset\tdelta(vsync)\tdelta^2(vsync)\t" +
- "delta^2(vsync)/refreshPeriod\t normalized delta^2(vsync)\n");
-
- for (int i = 0; i < mFrameLatencySampleSize; i++) {
- // write raw data
- List<String> rawData = mFrameBufferData.get(i);
- String line = String.format("%s\t%s\t%s\t%d\t%d\t%f\t%d\n",
- rawData.get(0), rawData.get(1), rawData.get(2),
- mDeltaVsync[i], mDelta2Vsync[i],
- mNormalizedDelta2Vsync[i], mRoundNormalizedDelta2Vsync[i]);
- fw.write(line);
- }
- } catch (IOException e) {
- log("Open file error: " + e.toString());
- } finally {
- try {
- if (fw != null) {
- fw.flush();
- fw.close();
- }
- }
- catch (IOException e) {
- Log.e(TAG, "close file exception: ", e);
- }
- }
- }
-
- private static void log(String msg) {
- Log.v(TAG, msg);
- }
-}
diff --git a/uiautomator_test_libraries/src/com/android/uiautomator/platform/TestWatchers.java b/uiautomator_test_libraries/src/com/android/uiautomator/platform/TestWatchers.java
deleted file mode 100644
index 5cab83a..0000000
--- a/uiautomator_test_libraries/src/com/android/uiautomator/platform/TestWatchers.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.uiautomator.platform;
-
-import com.android.uiautomator.common.UiWatchers;
-
-public class TestWatchers extends UiWatchers {
- private String TAG = "TestWatchers";
-
- @Override
- public void onAnrDetected(String errorText) {
- // The ANR dialog is still open now and upon returning from here
- // it will automatically get closed. See UiWatchers or implement
- // your handlers directly.
- super.onAnrDetected("ANR:" + errorText);
- }
-
- @Override
- public void onCrashDetected(String errorText) {
- // what do we need to do here?
- // The Crash dialog is still open now and upon returning from here
- // it will automatically get closed. See UiWatchers or implement
- // your handlers directly.
- super.onCrashDetected("CRASH:" + errorText);
- }
-}