Merge "adding IAutomationSupport for API compatibility" into jb-mr2-dev
diff --git a/uiautomator/instrumentation/testrunner-src/com/android/uiautomator/testrunner/IAutomationSupport.java b/uiautomator/instrumentation/testrunner-src/com/android/uiautomator/testrunner/IAutomationSupport.java
new file mode 100644
index 0000000..f0c60d2
--- /dev/null
+++ b/uiautomator/instrumentation/testrunner-src/com/android/uiautomator/testrunner/IAutomationSupport.java
@@ -0,0 +1,37 @@
+/*
+ * 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/uiautomator/instrumentation/testrunner-src/com/android/uiautomator/testrunner/InstrumentationAutomationSupport.java b/uiautomator/instrumentation/testrunner-src/com/android/uiautomator/testrunner/InstrumentationAutomationSupport.java
new file mode 100644
index 0000000..a70586e
--- /dev/null
+++ b/uiautomator/instrumentation/testrunner-src/com/android/uiautomator/testrunner/InstrumentationAutomationSupport.java
@@ -0,0 +1,40 @@
+/*
+ * 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.testrunner;
+
+import android.app.Instrumentation;
+import android.os.Bundle;
+
+/**
+ * A wrapper around {@link Instrumentation} to provide sendStatus function
+ *
+ * Provided for backwards compatibility purpose. New code should use
+ * {@link Instrumentation#sendStatus(int, Bundle)} instead.
+ *
+ */
+class InstrumentationAutomationSupport implements IAutomationSupport {
+
+ private Instrumentation mInstrumentation;
+
+ InstrumentationAutomationSupport(Instrumentation instrumentation) {
+ mInstrumentation = instrumentation;
+ }
+
+ @Override
+ public void sendStatus(int resultCode, Bundle status) {
+ mInstrumentation.sendStatus(resultCode, status);
+ }
+}
diff --git a/uiautomator/instrumentation/testrunner-src/com/android/uiautomator/testrunner/UiAutomatorTestCase.java b/uiautomator/instrumentation/testrunner-src/com/android/uiautomator/testrunner/UiAutomatorTestCase.java
index 5c48672..b5f21c9 100644
--- a/uiautomator/instrumentation/testrunner-src/com/android/uiautomator/testrunner/UiAutomatorTestCase.java
+++ b/uiautomator/instrumentation/testrunner-src/com/android/uiautomator/testrunner/UiAutomatorTestCase.java
@@ -16,6 +16,7 @@
package com.android.uiautomator.testrunner;
+import android.app.Instrumentation;
import android.os.Bundle;
import android.os.SystemClock;
import android.test.InstrumentationTestCase;
@@ -29,6 +30,7 @@
public class UiAutomatorTestCase extends InstrumentationTestCase {
private Bundle mParams;
+ private IAutomationSupport mAutomationSupport;
/**
* Get current instance of {@link UiDevice}. Works similar to calling the static
@@ -49,6 +51,24 @@
return mParams;
}
+ void setAutomationSupport(IAutomationSupport automationSupport) {
+ mAutomationSupport = automationSupport;
+ }
+
+ /**
+ * Provides support for running tests to report interim status
+ *
+ * @return IAutomationSupport
+ * @since API Level 16
+ * @deprecated Use {@link Instrumentation#sendStatus(int, Bundle)} instead
+ */
+ public IAutomationSupport getAutomationSupport() {
+ if (mAutomationSupport == null) {
+ mAutomationSupport = new InstrumentationAutomationSupport(getInstrumentation());
+ }
+ return mAutomationSupport;
+ }
+
/**
* Initializes this test case.
*