Move Common files from CtsTestStubs to ctsdeviceutil
bug: 17211776
Change-Id: I8dfe89d4d4f7dfcd173c264ccd32edc525674190
diff --git a/libs/deviceutil/Android.mk b/libs/deviceutil/Android.mk
index d5a2c57..8c81ee4 100644
--- a/libs/deviceutil/Android.mk
+++ b/libs/deviceutil/Android.mk
@@ -29,3 +29,5 @@
LOCAL_SDK_VERSION := current
include $(BUILD_STATIC_JAVA_LIBRARY)
+
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/libs/deviceutil/jni/Android.mk b/libs/deviceutil/jni/Android.mk
new file mode 100644
index 0000000..b801a4d
--- /dev/null
+++ b/libs/deviceutil/jni/Android.mk
@@ -0,0 +1,32 @@
+# Copyright (C) 2010 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 := libcts_jni
+
+# Don't include this package in any configuration by default.
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := \
+ CtsJniOnLoad.cpp \
+ android_cts_FileUtils.cpp
+
+LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
+
+LOCAL_SHARED_LIBRARIES := libnativehelper liblog libdl
+
+include $(BUILD_SHARED_LIBRARY)
\ No newline at end of file
diff --git a/libs/deviceutil/jni/CtsJniOnLoad.cpp b/libs/deviceutil/jni/CtsJniOnLoad.cpp
new file mode 100644
index 0000000..abf8e01
--- /dev/null
+++ b/libs/deviceutil/jni/CtsJniOnLoad.cpp
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+#include <jni.h>
+#include <stdio.h>
+
+extern int register_android_cts_FileUtils(JNIEnv*);
+
+jint JNI_OnLoad(JavaVM *vm, void *reserved) {
+ JNIEnv *env = NULL;
+
+ if (vm->GetEnv((void **) &env, JNI_VERSION_1_4) != JNI_OK) {
+ return JNI_ERR;
+ }
+
+ if (register_android_cts_FileUtils(env)) {
+ return JNI_ERR;
+ }
+
+ return JNI_VERSION_1_4;
+}
diff --git a/tests/tests/security/jni/android_security_cts_FileUtils.cpp b/libs/deviceutil/jni/android_cts_FileUtils.cpp
similarity index 80%
rename from tests/tests/security/jni/android_security_cts_FileUtils.cpp
rename to libs/deviceutil/jni/android_cts_FileUtils.cpp
index 8009c04..91b74bf 100644
--- a/tests/tests/security/jni/android_security_cts_FileUtils.cpp
+++ b/libs/deviceutil/jni/android_cts_FileUtils.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2014 The Android Open Source Project
+ * Copyright (C) 2011 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.
@@ -40,12 +40,12 @@
/*
* Native methods used by
- * cts/tests/src/android/security/cts/FileUtils.java
+ * cts/libs/deviceutil/src/android/cts/util/FileUtils.java
*
- * Copied from hidden API: frameworks/base/core/jni/android_security_FileUtils.cpp
+ * Copied from hidden API: frameworks/base/core/jni/android_FileUtils.cpp
*/
-jboolean android_security_cts_FileUtils_getFileStatus(JNIEnv* env, jobject thiz,
+jboolean android_cts_FileUtils_getFileStatus(JNIEnv* env, jobject thiz,
jstring path, jobject fileStatus, jboolean statLinks)
{
const char* pathStr = env->GetStringUTFChars(path, NULL);
@@ -77,21 +77,21 @@
return ret;
}
-jstring android_security_cts_FileUtils_getUserName(JNIEnv* env, jobject thiz,
+jstring android_cts_FileUtils_getUserName(JNIEnv* env, jobject thiz,
jint uid)
{
struct passwd *pwd = getpwuid(uid);
return env->NewStringUTF(pwd->pw_name);
}
-jstring android_security_cts_FileUtils_getGroupName(JNIEnv* env, jobject thiz,
+jstring android_cts_FileUtils_getGroupName(JNIEnv* env, jobject thiz,
jint gid)
{
struct group *grp = getgrgid(gid);
return env->NewStringUTF(grp->gr_name);
}
-jint android_security_cts_FileUtils_setPermissions(JNIEnv* env, jobject clazz,
+jint android_cts_FileUtils_setPermissions(JNIEnv* env, jobject clazz,
jstring file, jint mode)
{
const char *fileStr = env->GetStringUTFChars(file, NULL);
@@ -110,22 +110,22 @@
}
static JNINativeMethod gMethods[] = {
- { "getFileStatus", "(Ljava/lang/String;Landroid/security/cts/FileUtils$FileStatus;Z)Z",
- (void *) android_security_cts_FileUtils_getFileStatus },
+ { "getFileStatus", "(Ljava/lang/String;Landroid/cts/util/FileUtils$FileStatus;Z)Z",
+ (void *) android_cts_FileUtils_getFileStatus },
{ "getUserName", "(I)Ljava/lang/String;",
- (void *) android_security_cts_FileUtils_getUserName },
+ (void *) android_cts_FileUtils_getUserName },
{ "getGroupName", "(I)Ljava/lang/String;",
- (void *) android_security_cts_FileUtils_getGroupName },
+ (void *) android_cts_FileUtils_getGroupName },
{ "setPermissions", "(Ljava/lang/String;I)I",
- (void *) android_security_cts_FileUtils_setPermissions },
+ (void *) android_cts_FileUtils_setPermissions },
};
-int register_android_security_cts_FileUtils(JNIEnv* env)
+int register_android_cts_FileUtils(JNIEnv* env)
{
- jclass clazz = env->FindClass("android/security/cts/FileUtils");
+ jclass clazz = env->FindClass("android/cts/util/FileUtils");
assert(clazz != null);
- gFileStatusClass = env->FindClass("android/security/cts/FileUtils$FileStatus");
+ gFileStatusClass = env->FindClass("android/cts/util/FileUtils$FileStatus");
assert(gFileStatusClass != null);
gFileStatusDevFieldID = env->GetFieldID(gFileStatusClass, "dev", "I");
gFileStatusInoFieldID = env->GetFieldID(gFileStatusClass, "ino", "I");
diff --git a/libs/deviceutil/src/android/app/cts/CTSResult.java b/libs/deviceutil/src/android/cts/util/CTSResult.java
similarity index 96%
rename from libs/deviceutil/src/android/app/cts/CTSResult.java
rename to libs/deviceutil/src/android/cts/util/CTSResult.java
index ae4dbfd..c780f57 100644
--- a/libs/deviceutil/src/android/app/cts/CTSResult.java
+++ b/libs/deviceutil/src/android/cts/util/CTSResult.java
@@ -14,7 +14,7 @@
* the License.
*/
-package android.app.cts;
+package android.cts.util;
public interface CTSResult {
public static final int RESULT_OK = 1;
diff --git a/libs/deviceutil/src/android/provider/cts/FileCopyHelper.java b/libs/deviceutil/src/android/cts/util/FileCopyHelper.java
similarity index 98%
rename from libs/deviceutil/src/android/provider/cts/FileCopyHelper.java
rename to libs/deviceutil/src/android/cts/util/FileCopyHelper.java
index 507eb06..e84e920 100644
--- a/libs/deviceutil/src/android/provider/cts/FileCopyHelper.java
+++ b/libs/deviceutil/src/android/cts/util/FileCopyHelper.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package android.provider.cts;
+package android.cts.util;
import android.content.Context;
diff --git a/tests/tests/os/src/android/os/cts/FileUtils.java b/libs/deviceutil/src/android/cts/util/FileUtils.java
similarity index 98%
rename from tests/tests/os/src/android/os/cts/FileUtils.java
rename to libs/deviceutil/src/android/cts/util/FileUtils.java
index 8600d8b..055f2d6 100644
--- a/tests/tests/os/src/android/os/cts/FileUtils.java
+++ b/libs/deviceutil/src/android/cts/util/FileUtils.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package android.os.cts;
+package android.cts.util;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -54,7 +54,7 @@
public static final int S_IXOTH = 00001;
static {
- System.loadLibrary("ctsos_jni");
+ System.loadLibrary("cts_jni");
}
public static class FileStatus {
diff --git a/tests/tests/os/src/android/os/cts/IBinderParcelable.java b/libs/deviceutil/src/android/cts/util/IBinderParcelable.java
similarity index 97%
rename from tests/tests/os/src/android/os/cts/IBinderParcelable.java
rename to libs/deviceutil/src/android/cts/util/IBinderParcelable.java
index e48f58a..c80716e 100644
--- a/tests/tests/os/src/android/os/cts/IBinderParcelable.java
+++ b/libs/deviceutil/src/android/cts/util/IBinderParcelable.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package android.os.cts;
+package android.cts.util;
import android.os.IBinder;
import android.os.Parcel;
diff --git a/tests/tests/widget/src/android/widget/cts/NullWebViewUtils.java b/libs/deviceutil/src/android/cts/util/NullWebViewUtils.java
similarity index 98%
rename from tests/tests/widget/src/android/widget/cts/NullWebViewUtils.java
rename to libs/deviceutil/src/android/cts/util/NullWebViewUtils.java
index d7a73fa..e1b23f7 100644
--- a/tests/tests/widget/src/android/widget/cts/NullWebViewUtils.java
+++ b/libs/deviceutil/src/android/cts/util/NullWebViewUtils.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package android.widget.cts;
+package android.cts.util;
import android.content.Context;
import android.content.pm.PackageManager;
diff --git a/tests/tests/os/src/android/os/cts/ReadElf.java b/libs/deviceutil/src/android/cts/util/ReadElf.java
similarity index 99%
rename from tests/tests/os/src/android/os/cts/ReadElf.java
rename to libs/deviceutil/src/android/cts/util/ReadElf.java
index 4a20031..559cbd0 100644
--- a/tests/tests/os/src/android/os/cts/ReadElf.java
+++ b/libs/deviceutil/src/android/cts/util/ReadElf.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package android.os.cts;
+package android.cts.util;
import java.io.File;
import java.io.IOException;
diff --git a/tests/tests/telephony/src/android/telephony/cts/TestThread.java b/libs/deviceutil/src/android/cts/util/TestThread.java
similarity index 98%
rename from tests/tests/telephony/src/android/telephony/cts/TestThread.java
rename to libs/deviceutil/src/android/cts/util/TestThread.java
index 9bf40de..14df61c 100644
--- a/tests/tests/telephony/src/android/telephony/cts/TestThread.java
+++ b/libs/deviceutil/src/android/cts/util/TestThread.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package android.telephony.cts;
+package android.cts.util;
/**
* Thread class for executing a Runnable containing assertions in a separate thread.
diff --git a/tests/tests/view/src/android/view/cts/WidgetTestUtils.java b/libs/deviceutil/src/android/cts/util/WidgetTestUtils.java
similarity index 98%
rename from tests/tests/view/src/android/view/cts/WidgetTestUtils.java
rename to libs/deviceutil/src/android/cts/util/WidgetTestUtils.java
index e82e9df4..813672e 100644
--- a/tests/tests/view/src/android/view/cts/WidgetTestUtils.java
+++ b/libs/deviceutil/src/android/cts/util/WidgetTestUtils.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package android.view.cts;
+package android.cts.util;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
diff --git a/libs/deviceutillegacy/Android.mk b/libs/deviceutillegacy/Android.mk
new file mode 100644
index 0000000..852ce38
--- /dev/null
+++ b/libs/deviceutillegacy/Android.mk
@@ -0,0 +1,30 @@
+# Copyright (C) 2014 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_STATIC_JAVA_LIBRARIES := ctsdeviceutil
+
+LOCAL_SRC_FILES := \
+ $(call all-java-files-under, src)
+
+LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_MODULE := ctsdeviceutillegacy
+
+include $(BUILD_STATIC_JAVA_LIBRARY)
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebViewOnUiThread.java b/libs/deviceutillegacy/src/android/webkit/cts/WebViewOnUiThread.java
similarity index 99%
rename from tests/tests/webkit/src/android/webkit/cts/WebViewOnUiThread.java
rename to libs/deviceutillegacy/src/android/webkit/cts/WebViewOnUiThread.java
index 9b2d803..b9d3af1 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebViewOnUiThread.java
+++ b/libs/deviceutillegacy/src/android/webkit/cts/WebViewOnUiThread.java
@@ -17,6 +17,7 @@
package android.webkit.cts;
import android.cts.util.PollingCheck;
+import android.cts.util.TestThread;
import android.graphics.Bitmap;
import android.graphics.Picture;
import android.graphics.Rect;
diff --git a/tests/app/src/android/app/cts/CTSActivityTestCaseBase.java b/tests/app/src/android/app/cts/CTSActivityTestCaseBase.java
index 9ab1965..efe693a 100644
--- a/tests/app/src/android/app/cts/CTSActivityTestCaseBase.java
+++ b/tests/app/src/android/app/cts/CTSActivityTestCaseBase.java
@@ -16,6 +16,7 @@
package android.app.cts;
+import android.cts.util.CTSResult;
import android.test.InstrumentationTestCase;
public class CTSActivityTestCaseBase extends InstrumentationTestCase implements CTSResult {
diff --git a/tests/app/src/android/app/cts/IBinderParcelable.java b/tests/app/src/android/app/cts/IBinderParcelable.java
deleted file mode 100644
index 228097f..0000000
--- a/tests/app/src/android/app/cts/IBinderParcelable.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2009 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 android.app.cts;
-
-import android.os.IBinder;
-import android.os.Parcel;
-import android.os.Parcelable;
-
-public class IBinderParcelable implements Parcelable {
- public IBinder binder;
-
- public IBinderParcelable(IBinder source) {
- binder = source;
- }
-
- public int describeContents() {
- return 0;
- }
-
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeStrongBinder(binder);
- }
-
- public static final Parcelable.Creator<IBinderParcelable>
- CREATOR = new Parcelable.Creator<IBinderParcelable>() {
-
- public IBinderParcelable createFromParcel(Parcel source) {
- return new IBinderParcelable(source);
- }
-
- public IBinderParcelable[] newArray(int size) {
- return new IBinderParcelable[size];
- }
- };
-
- private IBinderParcelable(Parcel source) {
- binder = source.readStrongBinder();
- }
-}
diff --git a/tests/app/src/android/app/cts/LocalActivityManagerTestHelper.java b/tests/app/src/android/app/cts/LocalActivityManagerTestHelper.java
index 76af648..70764e4 100644
--- a/tests/app/src/android/app/cts/LocalActivityManagerTestHelper.java
+++ b/tests/app/src/android/app/cts/LocalActivityManagerTestHelper.java
@@ -21,9 +21,9 @@
import android.app.ActivityGroup;
import android.app.LocalActivityManager;
import android.content.Intent;
+import android.cts.util.CTSResult;
import android.os.Bundle;
import android.view.Window;
-import android.app.cts.CTSResult;
public class LocalActivityManagerTestHelper extends ActivityGroup {
diff --git a/tests/app/src/android/app/cts/LocalService.java b/tests/app/src/android/app/cts/LocalService.java
index 22273b0..6c4ae99 100644
--- a/tests/app/src/android/app/cts/LocalService.java
+++ b/tests/app/src/android/app/cts/LocalService.java
@@ -18,6 +18,7 @@
import android.app.Service;
import android.content.Intent;
+import android.cts.util.IBinderParcelable;
import android.os.Binder;
import android.os.IBinder;
import android.os.Parcel;
diff --git a/tests/app/src/android/app/cts/SearchManagerStubActivity.java b/tests/app/src/android/app/cts/SearchManagerStubActivity.java
index 6385fef..0dbd832 100644
--- a/tests/app/src/android/app/cts/SearchManagerStubActivity.java
+++ b/tests/app/src/android/app/cts/SearchManagerStubActivity.java
@@ -20,6 +20,7 @@
import android.app.SearchManager;
import android.content.ComponentName;
import android.content.Context;
+import android.cts.util.CTSResult;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
diff --git a/tests/tests/app/src/android/app/cts/LocalActivityManagerTest.java b/tests/tests/app/src/android/app/cts/LocalActivityManagerTest.java
index 1b40476..db3baba 100644
--- a/tests/tests/app/src/android/app/cts/LocalActivityManagerTest.java
+++ b/tests/tests/app/src/android/app/cts/LocalActivityManagerTest.java
@@ -20,6 +20,7 @@
import android.app.Instrumentation;
import android.app.LocalActivityManager;
import android.content.Intent;
+import android.cts.util.CTSResult;
import android.test.InstrumentationTestCase;
import android.test.UiThreadTest;
diff --git a/tests/tests/app/src/android/app/cts/SearchManagerTest.java b/tests/tests/app/src/android/app/cts/SearchManagerTest.java
index 8e465e8..1cece76 100644
--- a/tests/tests/app/src/android/app/cts/SearchManagerTest.java
+++ b/tests/tests/app/src/android/app/cts/SearchManagerTest.java
@@ -17,6 +17,7 @@
package android.app.cts;
import android.content.Intent;
+import android.cts.util.CTSResult;
public class SearchManagerTest extends CTSActivityTestCaseBase {
diff --git a/tests/tests/app/src/android/app/cts/ServiceTest.java b/tests/tests/app/src/android/app/cts/ServiceTest.java
index 675b7ae..b66f4c8 100644
--- a/tests/tests/app/src/android/app/cts/ServiceTest.java
+++ b/tests/tests/app/src/android/app/cts/ServiceTest.java
@@ -20,6 +20,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
+import android.cts.util.IBinderParcelable;
import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
diff --git a/tests/tests/content/src/android/content/pm/cts/ComponentInfoTest.java b/tests/tests/content/src/android/content/pm/cts/ComponentInfoTest.java
index 361bfe4..14a42c0 100644
--- a/tests/tests/content/src/android/content/pm/cts/ComponentInfoTest.java
+++ b/tests/tests/content/src/android/content/pm/cts/ComponentInfoTest.java
@@ -20,6 +20,7 @@
import android.content.pm.ComponentInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
+import android.cts.util.WidgetTestUtils;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
diff --git a/tests/tests/content/src/android/content/pm/cts/WidgetTestUtils.java b/tests/tests/content/src/android/content/pm/cts/WidgetTestUtils.java
deleted file mode 100644
index 6efd8b1..0000000
--- a/tests/tests/content/src/android/content/pm/cts/WidgetTestUtils.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright (C) 2008 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 android.content.pm.cts;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-
-import java.io.IOException;
-
-import junit.framework.Assert;
-
-/**
- * The useful methods for widget test.
- */
-public class WidgetTestUtils {
- /**
- * Assert that two bitmaps are equal.
- *
- * @param Bitmap b1 the first bitmap which needs to compare.
- * @param Bitmap b2 the second bitmap which needs to compare.
- */
- public static void assertEquals(Bitmap b1, Bitmap b2) {
- if (b1 == b2) {
- return;
- }
-
- if (b1 == null || b2 == null) {
- Assert.fail("the bitmaps are not equal");
- }
-
- // b1 and b2 are all not null.
- if (b1.getWidth() != b2.getWidth() || b1.getHeight() != b2.getHeight()
- || b1.getConfig() != b2.getConfig()) {
- Assert.fail("the bitmaps are not equal");
- }
-
- int w = b1.getWidth();
- int h = b1.getHeight();
- int s = w * h;
- int[] pixels1 = new int[s];
- int[] pixels2 = new int[s];
-
- b1.getPixels(pixels1, 0, w, 0, 0, w, h);
- b2.getPixels(pixels2, 0, w, 0, 0, w, h);
-
- for (int i = 0; i < s; i++) {
- if (pixels1[i] != pixels2[i]) {
- Assert.fail("the bitmaps are not equal");
- }
- }
- }
-
- /**
- * Find beginning of the special element.
- * @param parser XmlPullParser will be parsed.
- * @param firstElementName the target element name.
- *
- * @throws XmlPullParserException if XML Pull Parser related faults occur.
- * @throws IOException if I/O-related error occur when parsing.
- */
- public static final void beginDocument(XmlPullParser parser, String firstElementName)
- throws XmlPullParserException, IOException {
- Assert.assertNotNull(parser);
- Assert.assertNotNull(firstElementName);
-
- int type;
- while ((type = parser.next()) != XmlPullParser.START_TAG
- && type != XmlPullParser.END_DOCUMENT) {
- ;
- }
-
- if (!parser.getName().equals(firstElementName)) {
- throw new XmlPullParserException("Unexpected start tag: found " + parser.getName()
- + ", expected " + firstElementName);
- }
- }
-
- /**
- * Compare the expected pixels with actual, scaling for the target context density
- *
- * @throws AssertionFailedError
- */
- public static void assertScaledPixels(int expected, int actual, Context context) {
- Assert.assertEquals(expected * context.getResources().getDisplayMetrics().density,
- actual, 3);
- }
-
- /** Converts dips into pixels using the {@link Context}'s density. */
- public static int convertDipToPixels(Context context, int dip) {
- float density = context.getResources().getDisplayMetrics().density;
- return Math.round(density * dip);
- }
-
- /**
- * Retrieve a bitmap that can be used for comparison on any density
- * @param resources
- * @return the {@link Bitmap} or <code>null</code>
- */
- public static Bitmap getUnscaledBitmap(Resources resources, int resId) {
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inScaled = false;
- return BitmapFactory.decodeResource(resources, resId, options);
- }
-
- /**
- * Retrieve a dithered bitmap that can be used for comparison on any density
- * @param resources
- * @param config the preferred config for the returning bitmap
- * @return the {@link Bitmap} or <code>null</code>
- */
- public static Bitmap getUnscaledAndDitheredBitmap(Resources resources,
- int resId, Bitmap.Config config) {
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inDither = true;
- options.inScaled = false;
- options.inPreferredConfig = config;
- return BitmapFactory.decodeResource(resources, resId, options);
- }
-}
diff --git a/tests/tests/graphics/src/android/graphics/cts/BitmapTest.java b/tests/tests/graphics/src/android/graphics/cts/BitmapTest.java
index 4ea89c7..f58b871 100644
--- a/tests/tests/graphics/src/android/graphics/cts/BitmapTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/BitmapTest.java
@@ -19,6 +19,7 @@
import android.content.res.Resources;
+import android.cts.util.WidgetTestUtils;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
diff --git a/tests/tests/graphics/src/android/graphics/cts/MovieTest.java b/tests/tests/graphics/src/android/graphics/cts/MovieTest.java
index 2facdc9..b18b800 100644
--- a/tests/tests/graphics/src/android/graphics/cts/MovieTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/MovieTest.java
@@ -24,12 +24,12 @@
import java.io.OutputStream;
import android.content.Context;
+import android.cts.util.WidgetTestUtils;
import android.graphics.Canvas;
import android.graphics.Movie;
import android.graphics.Paint;
import android.test.ActivityInstrumentationTestCase2;
-
public class MovieTest extends ActivityInstrumentationTestCase2<MockActivity> {
private Movie mMovie;
private final int MOVIE = com.android.cts.graphics.R.drawable.animated;
diff --git a/tests/tests/graphics/src/android/graphics/cts/WidgetTestUtils.java b/tests/tests/graphics/src/android/graphics/cts/WidgetTestUtils.java
deleted file mode 100644
index 63bafac..0000000
--- a/tests/tests/graphics/src/android/graphics/cts/WidgetTestUtils.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright (C) 2008 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 android.graphics.cts;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-
-import java.io.IOException;
-
-import junit.framework.Assert;
-
-/**
- * The useful methods for widget test.
- */
-public class WidgetTestUtils {
- /**
- * Assert that two bitmaps are equal.
- *
- * @param Bitmap b1 the first bitmap which needs to compare.
- * @param Bitmap b2 the second bitmap which needs to compare.
- */
- public static void assertEquals(Bitmap b1, Bitmap b2) {
- if (b1 == b2) {
- return;
- }
-
- if (b1 == null || b2 == null) {
- Assert.fail("the bitmaps are not equal");
- }
-
- // b1 and b2 are all not null.
- if (b1.getWidth() != b2.getWidth() || b1.getHeight() != b2.getHeight()
- || b1.getConfig() != b2.getConfig()) {
- Assert.fail("the bitmaps are not equal");
- }
-
- int w = b1.getWidth();
- int h = b1.getHeight();
- int s = w * h;
- int[] pixels1 = new int[s];
- int[] pixels2 = new int[s];
-
- b1.getPixels(pixels1, 0, w, 0, 0, w, h);
- b2.getPixels(pixels2, 0, w, 0, 0, w, h);
-
- for (int i = 0; i < s; i++) {
- if (pixels1[i] != pixels2[i]) {
- Assert.fail("the bitmaps are not equal");
- }
- }
- }
-
- /**
- * Find beginning of the special element.
- * @param parser XmlPullParser will be parsed.
- * @param firstElementName the target element name.
- *
- * @throws XmlPullParserException if XML Pull Parser related faults occur.
- * @throws IOException if I/O-related error occur when parsing.
- */
- public static final void beginDocument(XmlPullParser parser, String firstElementName)
- throws XmlPullParserException, IOException {
- Assert.assertNotNull(parser);
- Assert.assertNotNull(firstElementName);
-
- int type;
- while ((type = parser.next()) != XmlPullParser.START_TAG
- && type != XmlPullParser.END_DOCUMENT) {
- ;
- }
-
- if (!parser.getName().equals(firstElementName)) {
- throw new XmlPullParserException("Unexpected start tag: found " + parser.getName()
- + ", expected " + firstElementName);
- }
- }
-
- /**
- * Compare the expected pixels with actual, scaling for the target context density
- *
- * @throws AssertionFailedError
- */
- public static void assertScaledPixels(int expected, int actual, Context context) {
- Assert.assertEquals(expected * context.getResources().getDisplayMetrics().density,
- actual, 3);
- }
-
- /** Converts dips into pixels using the {@link Context}'s density. */
- public static int convertDipToPixels(Context context, int dip) {
- float density = context.getResources().getDisplayMetrics().density;
- return Math.round(density * dip);
- }
-
- /**
- * Retrieve a bitmap that can be used for comparison on any density
- * @param resources
- * @return the {@link Bitmap} or <code>null</code>
- */
- public static Bitmap getUnscaledBitmap(Resources resources, int resId) {
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inScaled = false;
- return BitmapFactory.decodeResource(resources, resId, options);
- }
-
- /**
- * Retrieve a dithered bitmap that can be used for comparison on any density
- * @param resources
- * @param config the preferred config for the returning bitmap
- * @return the {@link Bitmap} or <code>null</code>
- */
- public static Bitmap getUnscaledAndDitheredBitmap(Resources resources,
- int resId, Bitmap.Config config) {
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inDither = true;
- options.inScaled = false;
- options.inPreferredConfig = config;
- return BitmapFactory.decodeResource(resources, resId, options);
- }
-}
diff --git a/tests/tests/media/src/android/media/cts/AudioManagerStub.java b/tests/tests/media/src/android/media/cts/AudioManagerStub.java
index baae5fc..290b866 100644
--- a/tests/tests/media/src/android/media/cts/AudioManagerStub.java
+++ b/tests/tests/media/src/android/media/cts/AudioManagerStub.java
@@ -19,7 +19,7 @@
import com.android.cts.media.R;
import android.app.Activity;
-import android.app.cts.CTSResult;
+import android.cts.util.CTSResult;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
diff --git a/tests/tests/media/src/android/media/cts/MediaScannerConnectionTest.java b/tests/tests/media/src/android/media/cts/MediaScannerConnectionTest.java
index 4234a5b..ddf87b8 100644
--- a/tests/tests/media/src/android/media/cts/MediaScannerConnectionTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaScannerConnectionTest.java
@@ -21,12 +21,12 @@
import android.content.ComponentName;
import android.content.Context;
+import android.cts.util.FileCopyHelper;
import android.cts.util.PollingCheck;
import android.media.MediaScannerConnection;
import android.media.MediaScannerConnection.MediaScannerConnectionClient;
import android.net.Uri;
import android.os.IBinder;
-import android.provider.cts.FileCopyHelper;
import android.test.AndroidTestCase;
import java.io.File;
diff --git a/tests/tests/media/src/android/media/cts/MediaScannerTest.java b/tests/tests/media/src/android/media/cts/MediaScannerTest.java
index b537467..4b42690 100644
--- a/tests/tests/media/src/android/media/cts/MediaScannerTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaScannerTest.java
@@ -26,6 +26,7 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.AssetFileDescriptor;
+import android.cts.util.FileCopyHelper;
import android.cts.util.PollingCheck;
import android.database.Cursor;
import android.media.MediaMetadataRetriever;
@@ -38,7 +39,6 @@
import android.os.IBinder;
import android.os.SystemClock;
import android.provider.MediaStore;
-import android.provider.cts.FileCopyHelper;
import android.test.AndroidTestCase;
import android.util.Log;
diff --git a/tests/tests/os/Android.mk b/tests/tests/os/Android.mk
index f0fb88a..1d78af4 100644
--- a/tests/tests/os/Android.mk
+++ b/tests/tests/os/Android.mk
@@ -25,7 +25,7 @@
LOCAL_STATIC_JAVA_LIBRARIES := ctsdeviceutil ctstestrunner guava
-LOCAL_JNI_SHARED_LIBRARIES := libctsos_jni
+LOCAL_JNI_SHARED_LIBRARIES := libcts_jni libctsos_jni
LOCAL_SRC_FILES := $(call all-java-files-under, src) \
src/android/os/cts/IParcelFileDescriptorPeer.aidl \
diff --git a/tests/tests/os/jni/Android.mk b/tests/tests/os/jni/Android.mk
index a39b5d1..3d3bc33 100644
--- a/tests/tests/os/jni/Android.mk
+++ b/tests/tests/os/jni/Android.mk
@@ -25,8 +25,7 @@
CtsOsJniOnLoad.cpp \
android_os_cts_CpuInstructions.cpp.arm \
android_os_cts_TaggedPointer.cpp \
- android_os_cts_OSFeatures.cpp \
- android_os_cts_FileUtils.cpp \
+ android_os_cts_OSFeatures.cpp
LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
diff --git a/tests/tests/os/jni/CtsOsJniOnLoad.cpp b/tests/tests/os/jni/CtsOsJniOnLoad.cpp
index ef69732..c6b88f5 100644
--- a/tests/tests/os/jni/CtsOsJniOnLoad.cpp
+++ b/tests/tests/os/jni/CtsOsJniOnLoad.cpp
@@ -25,8 +25,6 @@
extern int register_android_os_cts_OSFeatures(JNIEnv*);
-extern int register_android_os_cts_FileUtils(JNIEnv*);
-
jint JNI_OnLoad(JavaVM *vm, void *reserved) {
JNIEnv *env = NULL;
@@ -50,9 +48,5 @@
return JNI_ERR;
}
- if (register_android_os_cts_FileUtils(env)) {
- return JNI_ERR;
- }
-
return JNI_VERSION_1_4;
}
diff --git a/tests/tests/os/jni/android_os_cts_FileUtils.cpp b/tests/tests/os/jni/android_os_cts_FileUtils.cpp
deleted file mode 100644
index 2b7e282..0000000
--- a/tests/tests/os/jni/android_os_cts_FileUtils.cpp
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Copyright (C) 2011 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.
- */
-
-#include <grp.h>
-#include <jni.h>
-#include <pwd.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <assert.h>
-
-static jclass gFileStatusClass;
-static jfieldID gFileStatusDevFieldID;
-static jfieldID gFileStatusInoFieldID;
-static jfieldID gFileStatusModeFieldID;
-static jfieldID gFileStatusNlinkFieldID;
-static jfieldID gFileStatusUidFieldID;
-static jfieldID gFileStatusGidFieldID;
-static jfieldID gFileStatusSizeFieldID;
-static jfieldID gFileStatusBlksizeFieldID;
-static jfieldID gFileStatusBlocksFieldID;
-static jfieldID gFileStatusAtimeFieldID;
-static jfieldID gFileStatusMtimeFieldID;
-static jfieldID gFileStatusCtimeFieldID;
-
-/*
- * Native methods used by
- * cts/tests/src/android/os/cts/FileUtils.java
- *
- * Copied from hidden API: frameworks/base/core/jni/android_os_FileUtils.cpp
- */
-
-jboolean android_os_cts_FileUtils_getFileStatus(JNIEnv* env, jobject thiz,
- jstring path, jobject fileStatus, jboolean statLinks)
-{
- const char* pathStr = env->GetStringUTFChars(path, NULL);
- jboolean ret = false;
- struct stat s;
-
- int res = statLinks == true ? lstat(pathStr, &s) : stat(pathStr, &s);
-
- if (res == 0) {
- ret = true;
- if (fileStatus != NULL) {
- env->SetIntField(fileStatus, gFileStatusDevFieldID, s.st_dev);
- env->SetIntField(fileStatus, gFileStatusInoFieldID, s.st_ino);
- env->SetIntField(fileStatus, gFileStatusModeFieldID, s.st_mode);
- env->SetIntField(fileStatus, gFileStatusNlinkFieldID, s.st_nlink);
- env->SetIntField(fileStatus, gFileStatusUidFieldID, s.st_uid);
- env->SetIntField(fileStatus, gFileStatusGidFieldID, s.st_gid);
- env->SetLongField(fileStatus, gFileStatusSizeFieldID, s.st_size);
- env->SetIntField(fileStatus, gFileStatusBlksizeFieldID, s.st_blksize);
- env->SetLongField(fileStatus, gFileStatusBlocksFieldID, s.st_blocks);
- env->SetLongField(fileStatus, gFileStatusAtimeFieldID, s.st_atime);
- env->SetLongField(fileStatus, gFileStatusMtimeFieldID, s.st_mtime);
- env->SetLongField(fileStatus, gFileStatusCtimeFieldID, s.st_ctime);
- }
- }
-
- env->ReleaseStringUTFChars(path, pathStr);
-
- return ret;
-}
-
-jstring android_os_cts_FileUtils_getUserName(JNIEnv* env, jobject thiz,
- jint uid)
-{
- struct passwd *pwd = getpwuid(uid);
- return env->NewStringUTF(pwd->pw_name);
-}
-
-jstring android_os_cts_FileUtils_getGroupName(JNIEnv* env, jobject thiz,
- jint gid)
-{
- struct group *grp = getgrgid(gid);
- return env->NewStringUTF(grp->gr_name);
-}
-
-jint android_os_cts_FileUtils_setPermissions(JNIEnv* env, jobject clazz,
- jstring file, jint mode)
-{
- const char *fileStr = env->GetStringUTFChars(file, NULL);
- if (fileStr == NULL) {
- return -1;
- }
-
- if (strlen(fileStr) <= 0) {
- env->ReleaseStringUTFChars(file, fileStr);
- return ENOENT;
- }
-
- jint returnValue = chmod(fileStr, mode) == 0 ? 0 : errno;
- env->ReleaseStringUTFChars(file, fileStr);
- return returnValue;
-}
-
-static JNINativeMethod gMethods[] = {
- { "getFileStatus", "(Ljava/lang/String;Landroid/os/cts/FileUtils$FileStatus;Z)Z",
- (void *) android_os_cts_FileUtils_getFileStatus },
- { "getUserName", "(I)Ljava/lang/String;",
- (void *) android_os_cts_FileUtils_getUserName },
- { "getGroupName", "(I)Ljava/lang/String;",
- (void *) android_os_cts_FileUtils_getGroupName },
- { "setPermissions", "(Ljava/lang/String;I)I",
- (void *) android_os_cts_FileUtils_setPermissions },
-};
-
-int register_android_os_cts_FileUtils(JNIEnv* env)
-{
- jclass clazz = env->FindClass("android/os/cts/FileUtils");
- assert(clazz != null);
-
- gFileStatusClass = env->FindClass("android/os/cts/FileUtils$FileStatus");
- assert(gFileStatusClass != null);
- gFileStatusDevFieldID = env->GetFieldID(gFileStatusClass, "dev", "I");
- gFileStatusInoFieldID = env->GetFieldID(gFileStatusClass, "ino", "I");
- gFileStatusModeFieldID = env->GetFieldID(gFileStatusClass, "mode", "I");
- gFileStatusNlinkFieldID = env->GetFieldID(gFileStatusClass, "nlink", "I");
- gFileStatusUidFieldID = env->GetFieldID(gFileStatusClass, "uid", "I");
- gFileStatusGidFieldID = env->GetFieldID(gFileStatusClass, "gid", "I");
- gFileStatusSizeFieldID = env->GetFieldID(gFileStatusClass, "size", "J");
- gFileStatusBlksizeFieldID = env->GetFieldID(gFileStatusClass, "blksize", "I");
- gFileStatusBlocksFieldID = env->GetFieldID(gFileStatusClass, "blocks", "J");
- gFileStatusAtimeFieldID = env->GetFieldID(gFileStatusClass, "atime", "J");
- gFileStatusMtimeFieldID = env->GetFieldID(gFileStatusClass, "mtime", "J");
- gFileStatusCtimeFieldID = env->GetFieldID(gFileStatusClass, "ctime", "J");
-
- return env->RegisterNatives(clazz, gMethods,
- sizeof(gMethods) / sizeof(JNINativeMethod));
-}
diff --git a/tests/tests/os/src/android/os/cts/AbiTest.java b/tests/tests/os/src/android/os/cts/AbiTest.java
index a342669..ee2c168 100644
--- a/tests/tests/os/src/android/os/cts/AbiTest.java
+++ b/tests/tests/os/src/android/os/cts/AbiTest.java
@@ -16,7 +16,7 @@
package android.os.cts;
-import android.os.cts.ReadElf;
+import android.cts.util.ReadElf;
import java.io.File;
diff --git a/tests/tests/os/src/android/os/cts/ConditionVariableTest.java b/tests/tests/os/src/android/os/cts/ConditionVariableTest.java
index 559f890..cad9dec 100644
--- a/tests/tests/os/src/android/os/cts/ConditionVariableTest.java
+++ b/tests/tests/os/src/android/os/cts/ConditionVariableTest.java
@@ -16,6 +16,7 @@
package android.os.cts;
import junit.framework.TestCase;
+import android.cts.util.TestThread;
import android.os.ConditionVariable;
public class ConditionVariableTest extends TestCase {
diff --git a/tests/tests/os/src/android/os/cts/DebugTest.java b/tests/tests/os/src/android/os/cts/DebugTest.java
index c05c78a..c097240 100644
--- a/tests/tests/os/src/android/os/cts/DebugTest.java
+++ b/tests/tests/os/src/android/os/cts/DebugTest.java
@@ -22,6 +22,7 @@
import java.util.logging.Logger;
import android.content.Context;
+import android.cts.util.TestThread;
import android.os.Debug;
import android.test.AndroidTestCase;
import dalvik.system.VMDebug;
diff --git a/tests/tests/os/src/android/os/cts/HandlerTest.java b/tests/tests/os/src/android/os/cts/HandlerTest.java
index fc775e4..7183d7e 100644
--- a/tests/tests/os/src/android/os/cts/HandlerTest.java
+++ b/tests/tests/os/src/android/os/cts/HandlerTest.java
@@ -17,6 +17,7 @@
package android.os.cts;
import junit.framework.TestCase;
+import android.cts.util.TestThread;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
diff --git a/tests/tests/os/src/android/os/cts/LocalService.java b/tests/tests/os/src/android/os/cts/LocalService.java
index 0353c23..cc427f8 100644
--- a/tests/tests/os/src/android/os/cts/LocalService.java
+++ b/tests/tests/os/src/android/os/cts/LocalService.java
@@ -18,6 +18,7 @@
import android.app.Service;
import android.content.Intent;
+import android.cts.util.IBinderParcelable;
import android.os.Binder;
import android.os.IBinder;
import android.os.Parcel;
diff --git a/tests/tests/os/src/android/os/cts/LooperTest.java b/tests/tests/os/src/android/os/cts/LooperTest.java
index e71b752..79a55c6 100644
--- a/tests/tests/os/src/android/os/cts/LooperTest.java
+++ b/tests/tests/os/src/android/os/cts/LooperTest.java
@@ -16,6 +16,7 @@
package android.os.cts;
+import android.cts.util.TestThread;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
diff --git a/tests/tests/os/src/android/os/cts/TestThread.java b/tests/tests/os/src/android/os/cts/TestThread.java
deleted file mode 100644
index 1a28a20..0000000
--- a/tests/tests/os/src/android/os/cts/TestThread.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (C) 2009 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 android.os.cts;
-
-/**
- * Thread class for executing a Runnable containing assertions in a separate thread.
- * Uncaught exceptions in the Runnable are rethrown in the context of the the thread
- * calling the <code>runTest()</code> method.
- */
-public final class TestThread extends Thread {
- private Throwable mThrowable;
- private Runnable mTarget;
-
- public TestThread(Runnable target) {
- mTarget = target;
- }
-
- @Override
- public final void run() {
- try {
- mTarget.run();
- } catch (Throwable t) {
- mThrowable = t;
- }
- }
-
- /**
- * Run the target Runnable object and wait until the test finish or throw
- * out Exception if test fail.
- *
- * @param runTime
- * @throws Throwable
- */
- public void runTest(long runTime) throws Throwable {
- start();
- joinAndCheck(runTime);
- }
-
- /**
- * Get the Throwable object which is thrown when test running
- * @return The Throwable object
- */
- public Throwable getThrowable() {
- return mThrowable;
- }
-
- /**
- * Set the Throwable object which is thrown when test running
- * @param t The Throwable object
- */
- public void setThrowable(Throwable t) {
- mThrowable = t;
- }
-
- /**
- * Wait for the test thread to complete and throw the stored exception if there is one.
- *
- * @param runTime The time to wait for the test thread to complete.
- * @throws Throwable
- */
- public void joinAndCheck(long runTime) throws Throwable {
- this.join(runTime);
- if (this.isAlive()) {
- this.interrupt();
- this.join(runTime);
- throw new Exception("Thread did not finish within allotted time.");
- }
- checkException();
- }
-
- /**
- * Check whether there is an exception when running Runnable object.
- * @throws Throwable
- */
- public void checkException() throws Throwable {
- if (mThrowable != null) {
- throw mThrowable;
- }
- }
-}
diff --git a/tests/tests/os/src/android/os/storage/cts/StorageManagerTest.java b/tests/tests/os/src/android/os/storage/cts/StorageManagerTest.java
index 7d2d4ff..a8e8e64 100644
--- a/tests/tests/os/src/android/os/storage/cts/StorageManagerTest.java
+++ b/tests/tests/os/src/android/os/storage/cts/StorageManagerTest.java
@@ -22,7 +22,7 @@
import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
import android.os.Environment;
-import android.os.cts.FileUtils;
+import android.cts.util.FileUtils;
import android.os.storage.OnObbStateChangeListener;
import android.os.storage.StorageManager;
import android.test.AndroidTestCase;
diff --git a/tests/tests/provider/Android.mk b/tests/tests/provider/Android.mk
index 81ff9ee..fdc02e9 100644
--- a/tests/tests/provider/Android.mk
+++ b/tests/tests/provider/Android.mk
@@ -25,6 +25,8 @@
LOCAL_STATIC_JAVA_LIBRARIES := ctsdeviceutil ctstestrunner
+LOCAL_JNI_SHARED_LIBRARIES := libcts_jni
+
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := CtsProviderTestCases
diff --git a/tests/tests/provider/src/android/provider/cts/ContactsContract_PhotoTest.java b/tests/tests/provider/src/android/provider/cts/ContactsContract_PhotoTest.java
index 45ba8b8..8c97c22 100644
--- a/tests/tests/provider/src/android/provider/cts/ContactsContract_PhotoTest.java
+++ b/tests/tests/provider/src/android/provider/cts/ContactsContract_PhotoTest.java
@@ -19,6 +19,7 @@
import android.content.ContentProviderClient;
import android.content.ContentResolver;
import android.content.Context;
+import android.cts.util.FileUtils;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Photo;
import android.provider.ContactsContract.Contacts;
diff --git a/tests/tests/provider/src/android/provider/cts/FileUtils.java b/tests/tests/provider/src/android/provider/cts/FileUtils.java
deleted file mode 100644
index 0766e6d..0000000
--- a/tests/tests/provider/src/android/provider/cts/FileUtils.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright (C) 2011 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 android.provider.cts;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-/** Bits and pieces copied from hidden API of android.os.FileUtils. */
-public class FileUtils {
-
- /**
- * Copy data from a source stream to destFile.
- * Return true if succeed, return false if failed.
- */
- public static boolean copyToFile(InputStream inputStream, File destFile) {
- try {
- if (destFile.exists()) {
- destFile.delete();
- }
- FileOutputStream out = new FileOutputStream(destFile);
- try {
- byte[] buffer = new byte[4096];
- int bytesRead;
- while ((bytesRead = inputStream.read(buffer)) >= 0) {
- out.write(buffer, 0, bytesRead);
- }
- } finally {
- out.flush();
- try {
- out.getFD().sync();
- } catch (IOException e) {
- }
- out.close();
- }
- return true;
- } catch (IOException e) {
- return false;
- }
- }
-
- public static void createFile(File file, int numBytes) throws IOException {
- File parentFile = file.getParentFile();
- if (parentFile != null) {
- parentFile.mkdirs();
- }
- byte[] buffer = new byte[numBytes];
- FileOutputStream output = new FileOutputStream(file);
- try {
- output.write(buffer);
- } finally {
- output.close();
- }
- }
-
- public static byte[] readInputStreamFully(InputStream is) {
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- byte[] buffer = new byte[32768];
- int count;
- try {
- while ((count = is.read(buffer)) != -1) {
- os.write(buffer, 0, count);
- }
- is.close();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- return os.toByteArray();
- }
-}
diff --git a/tests/tests/provider/src/android/provider/cts/MediaStore_Audio_AlbumsTest.java b/tests/tests/provider/src/android/provider/cts/MediaStore_Audio_AlbumsTest.java
index bad1108..84da62a 100644
--- a/tests/tests/provider/src/android/provider/cts/MediaStore_Audio_AlbumsTest.java
+++ b/tests/tests/provider/src/android/provider/cts/MediaStore_Audio_AlbumsTest.java
@@ -21,6 +21,7 @@
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.res.AssetFileDescriptor;
+import android.cts.util.FileCopyHelper;
import android.database.Cursor;
import android.net.Uri;
import android.os.Environment;
diff --git a/tests/tests/provider/src/android/provider/cts/MediaStore_FilesTest.java b/tests/tests/provider/src/android/provider/cts/MediaStore_FilesTest.java
index 67396d4..0eae82b 100644
--- a/tests/tests/provider/src/android/provider/cts/MediaStore_FilesTest.java
+++ b/tests/tests/provider/src/android/provider/cts/MediaStore_FilesTest.java
@@ -22,6 +22,7 @@
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
+import android.cts.util.FileCopyHelper;
import android.database.Cursor;
import android.net.Uri;
import android.os.Environment;
diff --git a/tests/tests/provider/src/android/provider/cts/MediaStore_Images_MediaTest.java b/tests/tests/provider/src/android/provider/cts/MediaStore_Images_MediaTest.java
index bc86b0a..7469f8e 100644
--- a/tests/tests/provider/src/android/provider/cts/MediaStore_Images_MediaTest.java
+++ b/tests/tests/provider/src/android/provider/cts/MediaStore_Images_MediaTest.java
@@ -21,6 +21,8 @@
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
+import android.cts.util.FileCopyHelper;
+import android.cts.util.FileUtils;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
diff --git a/tests/tests/provider/src/android/provider/cts/MediaStore_Images_ThumbnailsTest.java b/tests/tests/provider/src/android/provider/cts/MediaStore_Images_ThumbnailsTest.java
index 025be2c..9413d7a 100644
--- a/tests/tests/provider/src/android/provider/cts/MediaStore_Images_ThumbnailsTest.java
+++ b/tests/tests/provider/src/android/provider/cts/MediaStore_Images_ThumbnailsTest.java
@@ -22,6 +22,7 @@
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
+import android.cts.util.FileCopyHelper;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
diff --git a/tests/tests/provider/src/android/provider/cts/MediaStore_VideoTest.java b/tests/tests/provider/src/android/provider/cts/MediaStore_VideoTest.java
index 2c9ebd1..89de9c6 100644
--- a/tests/tests/provider/src/android/provider/cts/MediaStore_VideoTest.java
+++ b/tests/tests/provider/src/android/provider/cts/MediaStore_VideoTest.java
@@ -21,6 +21,7 @@
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
+import android.cts.util.FileCopyHelper;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore.Video;
diff --git a/tests/tests/provider/src/android/provider/cts/MediaStore_Video_MediaTest.java b/tests/tests/provider/src/android/provider/cts/MediaStore_Video_MediaTest.java
index c3f5070..f84b75c 100644
--- a/tests/tests/provider/src/android/provider/cts/MediaStore_Video_MediaTest.java
+++ b/tests/tests/provider/src/android/provider/cts/MediaStore_Video_MediaTest.java
@@ -22,6 +22,8 @@
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
+import android.cts.util.FileCopyHelper;
+import android.cts.util.FileUtils;
import android.database.Cursor;
import android.net.Uri;
import android.os.Environment;
diff --git a/tests/tests/provider/src/android/provider/cts/MediaStore_Video_ThumbnailsTest.java b/tests/tests/provider/src/android/provider/cts/MediaStore_Video_ThumbnailsTest.java
index e74cce4..b6175be 100644
--- a/tests/tests/provider/src/android/provider/cts/MediaStore_Video_ThumbnailsTest.java
+++ b/tests/tests/provider/src/android/provider/cts/MediaStore_Video_ThumbnailsTest.java
@@ -21,6 +21,7 @@
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
+import android.cts.util.FileCopyHelper;
import android.database.Cursor;
import android.media.MediaCodecInfo;
import android.media.MediaCodecList;
diff --git a/tests/tests/provider/src/android/provider/cts/PhotoUtil.java b/tests/tests/provider/src/android/provider/cts/PhotoUtil.java
index 3f5f873..ec4fdef 100644
--- a/tests/tests/provider/src/android/provider/cts/PhotoUtil.java
+++ b/tests/tests/provider/src/android/provider/cts/PhotoUtil.java
@@ -19,6 +19,7 @@
import com.android.cts.provider.R;
import android.content.Context;
+import android.cts.util.FileUtils;
import java.io.InputStream;
diff --git a/tests/tests/security/Android.mk b/tests/tests/security/Android.mk
index 10ad5f8..dfb7884 100644
--- a/tests/tests/security/Android.mk
+++ b/tests/tests/security/Android.mk
@@ -22,7 +22,7 @@
LOCAL_JAVA_LIBRARIES := android.test.runner
-LOCAL_JNI_SHARED_LIBRARIES := libctssecurity_jni
+LOCAL_JNI_SHARED_LIBRARIES := libctssecurity_jni libcts_jni
LOCAL_SRC_FILES := $(call all-java-files-under, src)\
src/android/security/cts/activity/ISecureRandomService.aidl
diff --git a/tests/tests/security/jni/Android.mk b/tests/tests/security/jni/Android.mk
index 84f62c0..fa862c1 100644
--- a/tests/tests/security/jni/Android.mk
+++ b/tests/tests/security/jni/Android.mk
@@ -31,7 +31,6 @@
android_security_cts_SeccompDeathTestService.cpp \
android_security_cts_SELinuxTest.cpp \
android_security_cts_MMapExecutableTest.cpp \
- android_security_cts_FileUtils.cpp \
android_security_cts_NetlinkSocket.cpp
LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
diff --git a/tests/tests/security/jni/CtsSecurityJniOnLoad.cpp b/tests/tests/security/jni/CtsSecurityJniOnLoad.cpp
index d9a5f28..0e91b4e 100644
--- a/tests/tests/security/jni/CtsSecurityJniOnLoad.cpp
+++ b/tests/tests/security/jni/CtsSecurityJniOnLoad.cpp
@@ -26,7 +26,6 @@
extern int register_android_security_cts_SeccompDeathTestService(JNIEnv*);
extern int register_android_security_cts_SELinuxTest(JNIEnv*);
extern int register_android_security_cts_MMapExecutableTest(JNIEnv* env);
-extern int register_android_security_cts_FileUtils(JNIEnv*);
jint JNI_OnLoad(JavaVM *vm, void *reserved) {
JNIEnv *env = NULL;
@@ -67,10 +66,6 @@
return JNI_ERR;
}
- if (register_android_security_cts_FileUtils(env)) {
- return JNI_ERR;
- }
-
if (register_android_security_cts_NetlinkSocket(env)) {
return JNI_ERR;
}
diff --git a/tests/tests/security/src/android/security/cts/AslrTest.java b/tests/tests/security/src/android/security/cts/AslrTest.java
index f1552f6..913b49b 100644
--- a/tests/tests/security/src/android/security/cts/AslrTest.java
+++ b/tests/tests/security/src/android/security/cts/AslrTest.java
@@ -24,7 +24,7 @@
import java.io.FileReader;
import java.io.IOException;
-import android.security.cts.ReadElf;
+import android.cts.util.ReadElf;
/**
* Verify that ASLR is properly enabled on Android Compatible devices.
diff --git a/tests/tests/security/src/android/security/cts/BannedFilesTest.java b/tests/tests/security/src/android/security/cts/BannedFilesTest.java
index a71dcce..8076f8e 100644
--- a/tests/tests/security/src/android/security/cts/BannedFilesTest.java
+++ b/tests/tests/security/src/android/security/cts/BannedFilesTest.java
@@ -16,7 +16,7 @@
package android.security.cts;
-import android.security.cts.FileUtils;
+import android.cts.util.FileUtils;
import junit.framework.TestCase;
diff --git a/tests/tests/security/src/android/security/cts/FileUtils.java b/tests/tests/security/src/android/security/cts/FileUtils.java
deleted file mode 100644
index 3708f68..0000000
--- a/tests/tests/security/src/android/security/cts/FileUtils.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Copyright (C) 2014 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 android.security.cts;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-/** Bits and pieces copied from hidden API of android.os.FileUtils. */
-public class FileUtils {
-
- public static final int S_IFMT = 0170000;
- public static final int S_IFSOCK = 0140000;
- public static final int S_IFLNK = 0120000;
- public static final int S_IFREG = 0100000;
- public static final int S_IFBLK = 0060000;
- public static final int S_IFDIR = 0040000;
- public static final int S_IFCHR = 0020000;
- public static final int S_IFIFO = 0010000;
-
- public static final int S_ISUID = 0004000;
- public static final int S_ISGID = 0002000;
- public static final int S_ISVTX = 0001000;
-
- public static final int S_IRWXU = 00700;
- public static final int S_IRUSR = 00400;
- public static final int S_IWUSR = 00200;
- public static final int S_IXUSR = 00100;
-
- public static final int S_IRWXG = 00070;
- public static final int S_IRGRP = 00040;
- public static final int S_IWGRP = 00020;
- public static final int S_IXGRP = 00010;
-
- public static final int S_IRWXO = 00007;
- public static final int S_IROTH = 00004;
- public static final int S_IWOTH = 00002;
- public static final int S_IXOTH = 00001;
-
- static {
- System.loadLibrary("ctssecurity_jni");
- }
-
- public static class FileStatus {
-
- public int dev;
- public int ino;
- public int mode;
- public int nlink;
- public int uid;
- public int gid;
- public int rdev;
- public long size;
- public int blksize;
- public long blocks;
- public long atime;
- public long mtime;
- public long ctime;
-
- public boolean hasModeFlag(int flag) {
- if (((S_IRWXU | S_IRWXG | S_IRWXO) & flag) != flag) {
- throw new IllegalArgumentException("Inappropriate flag " + flag);
- }
- return (mode & flag) == flag;
- }
-
- public boolean isOfType(int type) {
- if ((type & S_IFMT) != type) {
- throw new IllegalArgumentException("Unknown type " + type);
- }
- return (mode & S_IFMT) == type;
- }
- }
-
- /**
- * @param path of the file to stat
- * @param status object to set the fields on
- * @param statLinks or don't stat links (lstat vs stat)
- * @return whether or not we were able to stat the file
- */
- public native static boolean getFileStatus(String path, FileStatus status, boolean statLinks);
-
- public native static String getUserName(int uid);
-
- public native static String getGroupName(int gid);
-
- public native static int setPermissions(String file, int mode);
-
- /**
- * Copy data from a source stream to destFile.
- * Return true if succeed, return false if failed.
- */
- public static boolean copyToFile(InputStream inputStream, File destFile) {
- try {
- if (destFile.exists()) {
- destFile.delete();
- }
- FileOutputStream out = new FileOutputStream(destFile);
- try {
- byte[] buffer = new byte[4096];
- int bytesRead;
- while ((bytesRead = inputStream.read(buffer)) >= 0) {
- out.write(buffer, 0, bytesRead);
- }
- } finally {
- out.flush();
- try {
- out.getFD().sync();
- } catch (IOException e) {
- }
- out.close();
- }
- return true;
- } catch (IOException e) {
- return false;
- }
- }
-
- public static void createFile(File file, int numBytes) throws IOException {
- File parentFile = file.getParentFile();
- if (parentFile != null) {
- parentFile.mkdirs();
- }
- byte[] buffer = new byte[numBytes];
- FileOutputStream output = new FileOutputStream(file);
- try {
- output.write(buffer);
- } finally {
- output.close();
- }
- }
-
- public static byte[] readInputStreamFully(InputStream is) {
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- byte[] buffer = new byte[32768];
- int count;
- try {
- while ((count = is.read(buffer)) != -1) {
- os.write(buffer, 0, count);
- }
- is.close();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- return os.toByteArray();
- }
-}
diff --git a/tests/tests/security/src/android/security/cts/ReadElf.java b/tests/tests/security/src/android/security/cts/ReadElf.java
deleted file mode 100644
index a9a4e3c..0000000
--- a/tests/tests/security/src/android/security/cts/ReadElf.java
+++ /dev/null
@@ -1,523 +0,0 @@
-/*
- * Copyright (C) 2014 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 android.security.cts;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * A poor man's implementation of the readelf command. This program is
- * designed to parse ELF (Executable and Linkable Format) files.
- */
-public class ReadElf implements AutoCloseable {
- /** The magic values for the ELF identification. */
- private static final byte[] ELF_IDENT = {
- (byte) 0x7F, (byte) 'E', (byte) 'L', (byte) 'F',
- };
-
- private static final int EI_CLASS = 4;
- private static final int EI_DATA = 5;
-
- private static final int EM_386 = 3;
- private static final int EM_MIPS = 8;
- private static final int EM_ARM = 40;
- // http://en.wikipedia.org/wiki/Qualcomm_Hexagon
- private static final int EM_QDSP6 = 164;
-
- /** Size of the e_ident[] structure in the ELF header. */
- private static final int EI_NIDENT = 16;
-
- /** Offset from end of ident structure in half-word sizes. */
- private static final int OFFSET_TYPE = 0;
-
- /** Machine type. */
- private static final int OFFSET_MACHINE = 1;
-
- /** ELF version. */
- private static final int OFFSET_VERSION = 2;
-
- /**
- * The offset to which the system transfers control. e.g., the first thing
- * executed.
- */
- private static final int OFFSET_ENTRY = 4;
-
- /** Program header offset in bytes. */
- private static final int OFFSET_PHOFF = 6;
-
- /** Segment header offset in bytes. */
- private static final int OFFSET_SHOFF = 8;
-
- /** Processor-specific flags for binary. */
- private static final int OFFSET_FLAGS = 10;
-
- /** ELF header size in bytes. */
- private static final int OFFSET_EHSIZE = 12;
-
- /** All program headers entry size in bytes. */
- private static final int OFFSET_PHENTSIZE = 13;
-
- /** Number of program headers in ELF. */
- private static final int OFFSET_PHNUM = 14;
-
- /** All segment headers entry size in bytes. */
- private static final int OFFSET_SHENTSIZE = 15;
-
- /** Number of segment headers in ELF. */
- private static final int OFFSET_SHNUM = 16;
-
- /** The section header index that refers to string table. */
- private static final int OFFSET_SHSTRNDX = 17;
-
- /** Program header offset for type of this program header. */
- private static final int PHOFF_TYPE = 0;
-
- /** Program header offset for absolute offset in file. */
- private static final int PHOFF_OFFSET = 2;
-
- /** Program header offset for virtual address. */
- private static final int PHOFF_VADDR = 4;
-
- /** Program header offset for physical address. */
- private static final int PHOFF_PADDR = 6;
-
- /** Program header offset for file size in bytes. */
- private static final int PHOFF_FILESZ = 8;
-
- /** Program header offset for memory size in bytes. */
- private static final int PHOFF_MEMSZ = 10;
-
- /** Program header offset for flags. */
- private static final int PHOFF_FLAGS = 12;
-
- /**
- * Program header offset for required alignment. 0 or 1 means no alignment
- * necessary.
- */
- private static final int PHOFF_ALIGN = 14;
-
- /** Index into string pool for segment name. */
- private static final long SHOFF_NAME = 0;
-
- /** Segment header offset for type (half-words) */
- private static final long SHOFF_TYPE = 2;
-
- /** Segment header offset for offset (meta!) (half-words) */
- private static final long SHOFF_OFFSET = 8;
-
- /** Segment header offset for size (half-words) */
- private static final long SHOFF_SIZE = 10;
-
- /** Data is presented in LSB format. */
- private static final int ELFDATA2LSB = 1;
-
- /** Date is presented in MSB format. */
- private static final int ELFDATA2MSB = 2;
-
- private static final int ELFCLASS32 = 1;
-
- private static final int ELFCLASS64 = 2;
-
- private static final long PT_LOAD = 1;
-
- /** Section Type: Symbol Table */
- private static final int SHT_SYMTAB = 2;
-
- /** Section Type: String Table */
- private static final int SHT_STRTAB = 3;
-
- /** Section Type: Dynamic **/
- private static final int SHT_DYNAMIC = 6;
-
- /** Section Type: Dynamic Symbol Table */
- private static final int SHT_DYNSYM = 11;
-
- /** Symbol Table Entry: Name offset */
- private static final int SYMTAB_NAME = 0;
-
- /** Symbol Table Entry: SymTab Info */
- private static final int SYMTAB_ST_INFO = 6;
-
- /** Symbol Table Entry size (half-words) */
- private static final int SYMTAB_ENTRY_HALFWORD_SIZE = 7;
-
- /**
- * Symbol Table Entry size (extra in bytes) to cover "st_info" and
- * "st_other"
- */
- private static final int SYMTAB_ENTRY_BYTE_EXTRA_SIZE = 2;
-
- public static class Symbol {
- public static final int STB_LOCAL = 0;
-
- public static final int STB_GLOBAL = 1;
-
- public static final int STB_WEAK = 2;
-
- public static final int STB_LOPROC = 13;
-
- public static final int STB_HIPROC = 15;
-
- public final String name;
-
- public final int bind;
-
- public final int type;
-
- Symbol(String name, int st_info) {
- this.name = name;
- this.bind = (st_info >> 4) & 0x0F;
- this.type = st_info & 0x0F;
- }
- };
-
- private final String mPath;
- private final RandomAccessFile mFile;
- private final byte[] mBuffer = new byte[512];
- private int mEndian;
- private boolean mIsDynamic;
- private boolean mIsPIE;
- private int mType;
- private int mWordSize;
- private int mHalfWordSize;
-
- /** Symbol Table offset */
- private long mSymTabOffset;
-
- /** Symbol Table size */
- private long mSymTabSize;
-
- /** Dynamic Symbol Table offset */
- private long mDynSymOffset;
-
- /** Dynamic Symbol Table size */
- private long mDynSymSize;
-
- /** Section Header String Table offset */
- private long mShStrTabOffset;
-
- /** Section Header String Table size */
- private long mShStrTabSize;
-
- /** String Table offset */
- private long mStrTabOffset;
-
- /** String Table size */
- private long mStrTabSize;
-
- /** Dynamic String Table offset */
- private long mDynStrOffset;
-
- /** Dynamic String Table size */
- private long mDynStrSize;
-
- /** Symbol Table symbol names */
- private Map<String, Symbol> mSymbols;
-
- /** Dynamic Symbol Table symbol names */
- private Map<String, Symbol> mDynamicSymbols;
-
- public static ReadElf read(File file) throws IOException {
- return new ReadElf(file);
- }
-
- public boolean isDynamic() {
- return mIsDynamic;
- }
-
- public int getType() {
- return mType;
- }
-
- public boolean isPIE() {
- return mIsPIE;
- }
-
- private ReadElf(File file) throws IOException {
- mPath = file.getPath();
- mFile = new RandomAccessFile(file, "r");
-
- if (mFile.length() < EI_NIDENT) {
- throw new IllegalArgumentException("Too small to be an ELF file: " + file);
- }
-
- readIdent();
- readHeader();
- }
-
- public void close() {
- try {
- mFile.close();
- } catch (IOException ignored) {
- }
- }
-
- protected void finalize() throws Throwable {
- try {
- close();
- } finally {
- super.finalize();
- }
- }
-
- private void readHeader() throws IOException {
- mType = readHalf(getHeaderOffset(OFFSET_TYPE));
- int e_machine = readHalf(getHeaderOffset(OFFSET_MACHINE));
- if (e_machine != EM_386 && e_machine != EM_MIPS && e_machine != EM_ARM &&
- e_machine != EM_QDSP6) {
- throw new IOException("Invalid ELF e_machine: " + e_machine + ": " + mPath);
- }
-
- final long shOffset = readWord(getHeaderOffset(OFFSET_SHOFF));
- final int shNumber = readHalf(getHeaderOffset(OFFSET_SHNUM));
- final int shSize = readHalf(getHeaderOffset(OFFSET_SHENTSIZE));
- final int shStrIndex = readHalf(getHeaderOffset(OFFSET_SHSTRNDX));
-
- readSectionHeaders(shOffset, shNumber, shSize, shStrIndex);
-
- final long phOffset = readWord(getHeaderOffset(OFFSET_PHOFF));
- final int phNumber = readHalf(getHeaderOffset(OFFSET_PHNUM));
- final int phSize = readHalf(getHeaderOffset(OFFSET_PHENTSIZE));
-
- readProgramHeaders(phOffset, phNumber, phSize);
- }
-
- private void readSectionHeaders(long tableOffset, int shNumber, int shSize, int shStrIndex)
- throws IOException {
- // Read the Section Header String Table offset first.
- {
- final long shStrTabShOffset = tableOffset + shStrIndex * shSize;
- final long type = readWord(shStrTabShOffset + mHalfWordSize * SHOFF_TYPE);
-
- if (type == SHT_STRTAB) {
- mShStrTabOffset = readWord(shStrTabShOffset + mHalfWordSize * SHOFF_OFFSET);
- mShStrTabSize = readWord(shStrTabShOffset + mHalfWordSize * SHOFF_SIZE);
- }
- }
-
- for (int i = 0; i < shNumber; i++) {
- // Don't bother to re-read the Section Header StrTab.
- if (i == shStrIndex) {
- continue;
- }
-
- final long shOffset = tableOffset + i * shSize;
-
- final long type = readWord(shOffset + mHalfWordSize * SHOFF_TYPE);
- if ((type == SHT_SYMTAB) || (type == SHT_DYNSYM)) {
- final long nameOffset = readWord(shOffset + mHalfWordSize * SHOFF_NAME);
- final long offset = readWord(shOffset + mHalfWordSize * SHOFF_OFFSET);
- final long size = readWord(shOffset + mHalfWordSize * SHOFF_SIZE);
-
- final String symTabName = readShStrTabEntry(nameOffset);
- if (".symtab".equals(symTabName)) {
- mSymTabOffset = offset;
- mSymTabSize = size;
- } else if (".dynsym".equals(symTabName)) {
- mDynSymOffset = offset;
- mDynSymSize = size;
- }
- } else if (type == SHT_STRTAB) {
- final long nameOffset = readWord(shOffset + mHalfWordSize * SHOFF_NAME);
- final long offset = readWord(shOffset + mHalfWordSize * SHOFF_OFFSET);
- final long size = readWord(shOffset + mHalfWordSize * SHOFF_SIZE);
-
- final String strTabName = readShStrTabEntry(nameOffset);
- if (".strtab".equals(strTabName)) {
- mStrTabOffset = offset;
- mStrTabSize = size;
- } else if (".dynstr".equals(strTabName)) {
- mDynStrOffset = offset;
- mDynStrSize = size;
- }
- } else if (type == SHT_DYNAMIC) {
- mIsDynamic = true;
- }
- }
- }
-
- private void readProgramHeaders(long phOffset, int phNumber, int phSize) throws IOException {
- for (int i = 0; i < phNumber; i++) {
- final long baseOffset = phOffset + i * phSize;
- final long type = readWord(baseOffset);
- if (type == PT_LOAD) {
- final long virtAddress = readWord(baseOffset + mHalfWordSize * PHOFF_VADDR);
- if (virtAddress == 0) {
- mIsPIE = true;
- }
- }
- }
- }
-
- private void readSymbolTable(Map<String, Symbol> symbolMap, long symStrOffset, long symStrSize,
- long symOffset, long symSize) throws IOException {
- final long symEnd = symOffset + symSize;
- for (long off = symOffset; off < symEnd; off += SYMTAB_ENTRY_HALFWORD_SIZE * mHalfWordSize
- + SYMTAB_ENTRY_BYTE_EXTRA_SIZE) {
- long strOffset = readWord(off + SYMTAB_NAME);
- if (strOffset == 0) {
- continue;
- }
-
- final String symName = readStrTabEntry(symStrOffset, symStrSize, strOffset);
- if (symName != null) {
- final int st_info = readByte(off + SYMTAB_ST_INFO);
- symbolMap.put(symName, new Symbol(symName, st_info));
- }
- }
- }
-
- private String readShStrTabEntry(long strOffset) throws IOException {
- if ((mShStrTabOffset == 0) || (strOffset < 0) || (strOffset >= mShStrTabSize)) {
- return null;
- }
-
- return readString(mShStrTabOffset + strOffset);
- }
-
- private String readStrTabEntry(long tableOffset, long tableSize, long strOffset)
- throws IOException {
- if ((tableOffset == 0) || (strOffset < 0) || (strOffset >= tableSize)) {
- return null;
- }
-
- return readString(tableOffset + strOffset);
- }
-
- private int getHeaderOffset(int halfWorldOffset) {
- return EI_NIDENT + halfWorldOffset * mHalfWordSize;
- }
-
- private int readByte(long offset) throws IOException {
- mFile.seek(offset);
- mFile.readFully(mBuffer, 0, 1);
-
- return mBuffer[0] & 0xff;
- }
-
- private int readHalf(long offset) throws IOException {
- mFile.seek(offset);
- mFile.readFully(mBuffer, 0, mWordSize);
-
- final int answer;
- if (mEndian == ELFDATA2LSB) {
- answer = mBuffer[1] << 8 | (mBuffer[0] & 0xff);
- } else {
- answer = mBuffer[0] << 8 | (mBuffer[1] & 0xff);
- }
-
- return answer;
- }
-
- private long readWord(long offset) throws IOException {
- mFile.seek(offset);
- mFile.readFully(mBuffer, 0, mWordSize);
-
- int answer = 0;
- if (mEndian == ELFDATA2LSB) {
- for (int i = mWordSize - 1; i >= 0; i--) {
- answer = (answer << 8) | (mBuffer[i] & 0xff);
- }
- } else {
- final int N = mWordSize - 1;
- for (int i = 0; i <= N; i++) {
- answer = (answer << 8) | (mBuffer[i] & 0xff);
- }
- }
-
- return answer;
- }
-
- private String readString(long offset) throws IOException {
- mFile.seek(offset);
- mFile.readFully(mBuffer, 0, (int) Math.min(mBuffer.length, mFile.length() - offset));
-
- for (int i = 0; i < mBuffer.length; i++) {
- if (mBuffer[i] == 0) {
- return new String(mBuffer, 0, i);
- }
- }
-
- return null;
- }
-
- private void readIdent() throws IOException {
- mFile.seek(0);
- mFile.readFully(mBuffer, 0, EI_NIDENT);
-
- if ((mBuffer[0] != ELF_IDENT[0]) || (mBuffer[1] != ELF_IDENT[1])
- || (mBuffer[2] != ELF_IDENT[2]) || (mBuffer[3] != ELF_IDENT[3])) {
- throw new IllegalArgumentException("Invalid ELF file: " + mPath);
- }
-
- int elfClass = mBuffer[EI_CLASS];
- if (elfClass == ELFCLASS32) {
- mWordSize = 4;
- mHalfWordSize = 2;
- } else if (elfClass == ELFCLASS64) {
- throw new IOException("Unsupported ELFCLASS64 file: " + mPath);
- } else {
- throw new IOException("Invalid ELF EI_CLASS: " + elfClass + ": " + mPath);
- }
-
- mEndian = mBuffer[EI_DATA];
- if (mEndian == ELFDATA2LSB) {
- } else if (mEndian == ELFDATA2MSB) {
- throw new IOException("Unsupported ELFDATA2MSB file: " + mPath);
- } else {
- throw new IOException("Invalid ELF EI_DATA: " + mEndian + ": " + mPath);
- }
- }
-
- public Symbol getSymbol(String name) {
- if ((mSymTabOffset == 0) && (mSymTabSize == 0)) {
- return null;
- }
-
- if (mSymbols == null) {
- mSymbols = new HashMap<String, Symbol>();
- try {
- readSymbolTable(mSymbols, mStrTabOffset, mStrTabSize, mSymTabOffset, mSymTabSize);
- } catch (IOException e) {
- return null;
- }
- }
-
- return mSymbols.get(name);
- }
-
- public Symbol getDynamicSymbol(String name) {
- if ((mDynSymOffset == 0) && (mDynSymSize == 0)) {
- return null;
- }
-
- if (mDynamicSymbols == null) {
- mDynamicSymbols = new HashMap<String, Symbol>();
- try {
- readSymbolTable(mDynamicSymbols, mDynStrOffset, mDynStrSize, mDynSymOffset,
- mDynSymSize);
- } catch (IOException e) {
- return null;
- }
- }
-
- return mDynamicSymbols.get(name);
- }
-}
diff --git a/tests/tests/telephony/Android.mk b/tests/tests/telephony/Android.mk
index e15d0d5..85864f9 100644
--- a/tests/tests/telephony/Android.mk
+++ b/tests/tests/telephony/Android.mk
@@ -24,7 +24,7 @@
LOCAL_JAVA_LIBRARIES := telephony-common
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner
+LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner ctsdeviceutil
LOCAL_SRC_FILES := $(call all-java-files-under, src)
diff --git a/tests/tests/telephony/src/android/telephony/cts/CellLocationTest.java b/tests/tests/telephony/src/android/telephony/cts/CellLocationTest.java
index 00c9844..c1f5757 100644
--- a/tests/tests/telephony/src/android/telephony/cts/CellLocationTest.java
+++ b/tests/tests/telephony/src/android/telephony/cts/CellLocationTest.java
@@ -17,6 +17,8 @@
import android.content.Context;
+import android.cts.util.ReadElf;
+import android.cts.util.TestThread;
import android.os.Looper;
import android.net.ConnectivityManager;
import android.telephony.CellLocation;
diff --git a/tests/tests/telephony/src/android/telephony/cts/PhoneStateListenerTest.java b/tests/tests/telephony/src/android/telephony/cts/PhoneStateListenerTest.java
index 9d8f842..f0f977a 100644
--- a/tests/tests/telephony/src/android/telephony/cts/PhoneStateListenerTest.java
+++ b/tests/tests/telephony/src/android/telephony/cts/PhoneStateListenerTest.java
@@ -16,6 +16,8 @@
package android.telephony.cts;
import android.content.Context;
+import android.cts.util.ReadElf;
+import android.cts.util.TestThread;
import android.os.Looper;
import android.telephony.CellLocation;
import android.telephony.PhoneStateListener;
diff --git a/tests/tests/telephony/src/android/telephony/cts/TelephonyManagerTest.java b/tests/tests/telephony/src/android/telephony/cts/TelephonyManagerTest.java
index b9c720c..7ade7c7 100644
--- a/tests/tests/telephony/src/android/telephony/cts/TelephonyManagerTest.java
+++ b/tests/tests/telephony/src/android/telephony/cts/TelephonyManagerTest.java
@@ -19,6 +19,8 @@
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.pm.PackageManager;
+import android.cts.util.ReadElf;
+import android.cts.util.TestThread;
import android.net.ConnectivityManager;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
diff --git a/tests/tests/text/Android.mk b/tests/tests/text/Android.mk
index df2d324..7b2def1 100644
--- a/tests/tests/text/Android.mk
+++ b/tests/tests/text/Android.mk
@@ -23,7 +23,7 @@
LOCAL_JAVA_LIBRARIES := android.test.runner
-LOCAL_STATIC_JAVA_LIBRARIES := ctsdeviceutil ctstestrunner
+LOCAL_STATIC_JAVA_LIBRARIES := ctsdeviceutil ctsdeviceutillegacy ctstestrunner
LOCAL_SRC_FILES := $(call all-java-files-under, src)
diff --git a/tests/tests/text/src/android/text/cts/EmojiCtsActivity.java b/tests/tests/text/src/android/text/cts/EmojiCtsActivity.java
index eb88426..195bdf1 100644
--- a/tests/tests/text/src/android/text/cts/EmojiCtsActivity.java
+++ b/tests/tests/text/src/android/text/cts/EmojiCtsActivity.java
@@ -20,6 +20,7 @@
import android.app.Activity;
import android.os.Bundle;
+import android.cts.util.NullWebViewUtils;
import android.webkit.WebView;
public class EmojiCtsActivity extends Activity {
diff --git a/tests/tests/text/src/android/text/cts/EmojiTest.java b/tests/tests/text/src/android/text/cts/EmojiTest.java
index b753739..e1249f3 100644
--- a/tests/tests/text/src/android/text/cts/EmojiTest.java
+++ b/tests/tests/text/src/android/text/cts/EmojiTest.java
@@ -17,6 +17,7 @@
package android.text.cts;
import android.content.Context;
+import android.cts.util.NullWebViewUtils;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
@@ -27,6 +28,7 @@
import android.view.View;
import android.widget.TextView;
import android.widget.EditText;
+import android.webkit.cts.WebViewOnUiThread;
public class EmojiTest extends ActivityInstrumentationTestCase2<EmojiCtsActivity> {
diff --git a/tests/tests/text/src/android/text/cts/NullWebViewUtils.java b/tests/tests/text/src/android/text/cts/NullWebViewUtils.java
deleted file mode 100644
index 86d0843..0000000
--- a/tests/tests/text/src/android/text/cts/NullWebViewUtils.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (C) 2010 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 android.text.cts;
-
-import android.content.Context;
-import android.content.pm.PackageManager;
-
-/**
- * Utilities to enable the android.webkit.* CTS tests (and others that rely on a functioning
- * android.webkit.WebView implementation) to determine whether a functioning WebView is present
- * on the device or not.
- *
- * Test cases that require android.webkit.* classes should wrap their first usage of WebView in a
- * try catch block, and pass any exception that is thrown to
- * NullWebViewUtils.determineIfWebViewAvailable. The return value of
- * NullWebViewUtils.isWebViewAvailable will then determine if the test should expect to be able to
- * use a WebView.
- */
-public class NullWebViewUtils {
-
- private static boolean sWebViewUnavailable;
-
- /**
- * @param context Current Activity context, used to query the PackageManager.
- * @param t An exception thrown by trying to invoke android.webkit.* APIs.
- */
- public static void determineIfWebViewAvailable(Context context, Throwable t) {
- sWebViewUnavailable = !hasWebViewFeature(context) && checkCauseWasUnsupportedOperation(t);
- }
-
- /**
- * After calling determineIfWebViewAvailable, this returns whether a WebView is available on the
- * device and wheter the test can rely on it.
- * @return True iff. PackageManager determined that there is no WebView on the device and the
- * exception thrown from android.webkit.* was UnsupportedOperationException.
- */
- public static boolean isWebViewAvailable() {
- return !sWebViewUnavailable;
- }
-
- private static boolean hasWebViewFeature(Context context) {
- // Query the system property that determins if there is a functional WebView on the device.
- PackageManager pm = context.getPackageManager();
- return pm.hasSystemFeature(PackageManager.FEATURE_WEBVIEW);
- }
-
- private static boolean checkCauseWasUnsupportedOperation(Throwable t) {
- if (t == null) return false;
- while (t.getCause() != null) {
- t = t.getCause();
- }
- return t instanceof UnsupportedOperationException;
- }
-
- /**
- * Some CTS tests (by design) first use android.webkit.* from a background thread. This helper
- * allows the test to catch the UnsupportedOperationException from that background thread, and
- * then query the result from the test main thread.
- */
- public static class NullWebViewFromThreadExceptionHandler
- implements Thread.UncaughtExceptionHandler {
- private Throwable mPendingException;
-
- @Override
- public void uncaughtException(Thread t, Throwable e) {
- mPendingException = e;
- }
-
- public boolean isWebViewAvailable(Context context) {
- return hasWebViewFeature(context) ||
- !checkCauseWasUnsupportedOperation(mPendingException);
- }
- }
-}
\ No newline at end of file
diff --git a/tests/tests/text/src/android/text/cts/WebViewOnUiThread.java b/tests/tests/text/src/android/text/cts/WebViewOnUiThread.java
deleted file mode 100644
index 3d62ce4..0000000
--- a/tests/tests/text/src/android/text/cts/WebViewOnUiThread.java
+++ /dev/null
@@ -1,980 +0,0 @@
-/*
- * Copyright (C) 2011 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 android.text.cts;
-
-import android.cts.util.PollingCheck;
-import android.graphics.Bitmap;
-import android.graphics.Picture;
-import android.graphics.Rect;
-import android.os.Bundle;
-import android.os.Looper;
-import android.os.Message;
-import android.os.SystemClock;
-import android.print.PrintDocumentAdapter;
-import android.test.InstrumentationTestCase;
-import android.util.DisplayMetrics;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.ViewParent;
-import android.webkit.DownloadListener;
-import android.webkit.CookieManager;
-import android.webkit.ValueCallback;
-import android.webkit.WebBackForwardList;
-import android.webkit.WebChromeClient;
-import android.webkit.WebSettings;
-import android.webkit.WebView.HitTestResult;
-import android.webkit.WebView.PictureListener;
-import android.webkit.WebView;
-import android.webkit.WebViewClient;
-
-import junit.framework.Assert;
-
-import java.io.File;
-import java.util.concurrent.Callable;
-import java.util.Map;
-
-/**
- * Many tests need to run WebView code in the UI thread. This class
- * wraps a WebView so that calls are ensured to arrive on the UI thread.
- *
- * All methods may be run on either the UI thread or test thread.
- */
-public class WebViewOnUiThread {
- /**
- * The maximum time, in milliseconds (10 seconds) to wait for a load
- * to be triggered.
- */
- private static final long LOAD_TIMEOUT = 10000;
-
- /**
- * Set to true after onPageFinished is called.
- */
- private boolean mLoaded;
-
- /**
- * Set to true after onNewPicture is called. Reset when onPageStarted
- * is called.
- */
- private boolean mNewPicture;
-
- /**
- * The progress, in percentage, of the page load. Valid values are between
- * 0 and 100.
- */
- private int mProgress;
-
- /**
- * The test that this class is being used in. Used for runTestOnUiThread.
- */
- private InstrumentationTestCase mTest;
-
- /**
- * The WebView that calls will be made on.
- */
- private WebView mWebView;
-
- /**
- * Initializes the webView with a WebViewClient, WebChromeClient,
- * and PictureListener to prepare for loadUrlAndWaitForCompletion.
- *
- * A new WebViewOnUiThread should be called during setUp so as to
- * reinitialize between calls.
- *
- * @param test The test in which this is being run.
- * @param webView The webView that the methods should call.
- * @see loadUrlAndWaitForCompletion
- */
- public WebViewOnUiThread(InstrumentationTestCase test, WebView webView) {
- mTest = test;
- mWebView = webView;
- final WebViewClient webViewClient = new WaitForLoadedClient(this);
- final WebChromeClient webChromeClient = new WaitForProgressClient(this);
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mWebView.setWebViewClient(webViewClient);
- mWebView.setWebChromeClient(webChromeClient);
- mWebView.setPictureListener(new WaitForNewPicture());
- }
- });
- }
-
- /**
- * Called after a test is complete and the WebView should be disengaged from
- * the tests.
- */
- public void cleanUp() {
- clearHistory();
- clearCache(true);
- setPictureListener(null);
- setWebChromeClient(null);
- setWebViewClient(null);
- }
-
- /**
- * Called from WaitForNewPicture, this is used to indicate that
- * the page has been drawn.
- */
- synchronized public void onNewPicture() {
- mNewPicture = true;
- this.notifyAll();
- }
-
- /**
- * Called from WaitForLoadedClient, this is used to clear the picture
- * draw state so that draws before the URL begins loading don't count.
- */
- synchronized public void onPageStarted() {
- mNewPicture = false; // Earlier paints won't count.
- }
-
- /**
- * Called from WaitForLoadedClient, this is used to indicate that
- * the page is loaded, but not drawn yet.
- */
- synchronized public void onPageFinished() {
- mLoaded = true;
- this.notifyAll();
- }
-
- /**
- * Called from the WebChrome client, this sets the current progress
- * for a page.
- * @param progress The progress made so far between 0 and 100.
- */
- synchronized public void onProgressChanged(int progress) {
- mProgress = progress;
- this.notifyAll();
- }
-
- public void setWebViewClient(final WebViewClient webViewClient) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mWebView.setWebViewClient(webViewClient);
- }
- });
- }
-
- public void setWebChromeClient(final WebChromeClient webChromeClient) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mWebView.setWebChromeClient(webChromeClient);
- }
- });
- }
-
- public void setPictureListener(final PictureListener pictureListener) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mWebView.setPictureListener(pictureListener);
- }
- });
- }
-
- public void setNetworkAvailable(final boolean available) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mWebView.setNetworkAvailable(available);
- }
- });
- }
-
- public void setDownloadListener(final DownloadListener listener) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mWebView.setDownloadListener(listener);
- }
- });
- }
-
- public void setBackgroundColor(final int color) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mWebView.setBackgroundColor(color);
- }
- });
- }
-
- public void clearCache(final boolean includeDiskFiles) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mWebView.clearCache(includeDiskFiles);
- }
- });
- }
-
- public void clearHistory() {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mWebView.clearHistory();
- }
- });
- }
-
- public void requestFocus() {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mWebView.requestFocus();
- }
- });
- }
-
- public boolean canZoomIn() {
- return getValue(new ValueGetter<Boolean>() {
- @Override
- public Boolean capture() {
- return mWebView.canZoomIn();
- }
- });
- }
-
- public boolean zoomIn() {
- return getValue(new ValueGetter<Boolean>() {
- @Override
- public Boolean capture() {
- return mWebView.zoomIn();
- }
- });
- }
-
- public boolean zoomOut() {
- return getValue(new ValueGetter<Boolean>() {
- @Override
- public Boolean capture() {
- return mWebView.zoomOut();
- }
- });
- }
-
- public void setFindListener(final WebView.FindListener listener) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mWebView.setFindListener(listener);
- }
- });
- }
-
- public void removeJavascriptInterface(final String interfaceName) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mWebView.removeJavascriptInterface(interfaceName);
- }
- });
- }
-
- public void addJavascriptInterface(final Object object, final String name) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mWebView.addJavascriptInterface(object, name);
- }
- });
- }
-
- public void flingScroll(final int vx, final int vy) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mWebView.flingScroll(vx, vy);
- }
- });
- }
-
- public void requestFocusNodeHref(final Message hrefMsg) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mWebView.requestFocusNodeHref(hrefMsg);
- }
- });
- }
-
- public void requestImageRef(final Message msg) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mWebView.requestImageRef(msg);
- }
- });
- }
-
- public void setInitialScale(final int scaleInPercent) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mWebView.setInitialScale(scaleInPercent);
- }
- });
- }
-
- public void clearSslPreferences() {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mWebView.clearSslPreferences();
- }
- });
- }
-
- public void clearClientCertPreferences(final Runnable onCleared) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- WebView.clearClientCertPreferences(onCleared);
- }
- });
- }
-
- public void resumeTimers() {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mWebView.resumeTimers();
- }
- });
- }
-
- public void findNext(final boolean forward) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mWebView.findNext(forward);
- }
- });
- }
-
- public void clearMatches() {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mWebView.clearMatches();
- }
- });
- }
-
- /**
- * Calls loadUrl on the WebView and then waits onPageFinished,
- * onNewPicture and onProgressChange to reach 100.
- * Test fails if the load timeout elapses.
- * @param url The URL to load.
- */
- public void loadUrlAndWaitForCompletion(final String url) {
- callAndWait(new Runnable() {
- @Override
- public void run() {
- mWebView.loadUrl(url);
- }
- });
- }
-
- /**
- * Calls loadUrl on the WebView and then waits onPageFinished,
- * onNewPicture and onProgressChange to reach 100.
- * Test fails if the load timeout elapses.
- * @param url The URL to load.
- * @param extraHeaders The additional headers to be used in the HTTP request.
- */
- public void loadUrlAndWaitForCompletion(final String url,
- final Map<String, String> extraHeaders) {
- callAndWait(new Runnable() {
- @Override
- public void run() {
- mWebView.loadUrl(url, extraHeaders);
- }
- });
- }
-
- public void loadUrl(final String url) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mWebView.loadUrl(url);
- }
- });
- }
-
- public void stopLoading() {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mWebView.stopLoading();
- }
- });
- }
-
- public void postUrlAndWaitForCompletion(final String url, final byte[] postData) {
- callAndWait(new Runnable() {
- @Override
- public void run() {
- mWebView.postUrl(url, postData);
- }
- });
- }
-
- public void loadDataAndWaitForCompletion(final String data,
- final String mimeType, final String encoding) {
- callAndWait(new Runnable() {
- @Override
- public void run() {
- mWebView.loadData(data, mimeType, encoding);
- }
- });
- }
-
- public void loadDataWithBaseURLAndWaitForCompletion(final String baseUrl,
- final String data, final String mimeType, final String encoding,
- final String historyUrl) {
- callAndWait(new Runnable() {
- @Override
- public void run() {
- mWebView.loadDataWithBaseURL(baseUrl, data, mimeType, encoding,
- historyUrl);
- }
- });
- }
-
- /**
- * Reloads a page and waits for it to complete reloading. Use reload
- * if it is a form resubmission and the onFormResubmission responds
- * by telling WebView not to resubmit it.
- */
- public void reloadAndWaitForCompletion() {
- callAndWait(new Runnable() {
- @Override
- public void run() {
- mWebView.reload();
- }
- });
- }
-
- /**
- * Reload the previous URL. Use reloadAndWaitForCompletion unless
- * it is a form resubmission and the onFormResubmission responds
- * by telling WebView not to resubmit it.
- */
- public void reload() {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mWebView.reload();
- }
- });
- }
-
- /**
- * Use this only when JavaScript causes a page load to wait for the
- * page load to complete. Otherwise use loadUrlAndWaitForCompletion or
- * similar functions.
- */
- public void waitForLoadCompletion() {
- waitForCriteria(LOAD_TIMEOUT,
- new Callable<Boolean>() {
- @Override
- public Boolean call() {
- return isLoaded();
- }
- });
- clearLoad();
- }
-
- private void waitForCriteria(long timeout, Callable<Boolean> doneCriteria) {
- if (isUiThread()) {
- waitOnUiThread(timeout, doneCriteria);
- } else {
- waitOnTestThread(timeout, doneCriteria);
- }
- }
-
- public String getTitle() {
- return getValue(new ValueGetter<String>() {
- @Override
- public String capture() {
- return mWebView.getTitle();
- }
- });
- }
-
- public WebSettings getSettings() {
- return getValue(new ValueGetter<WebSettings>() {
- @Override
- public WebSettings capture() {
- return mWebView.getSettings();
- }
- });
- }
-
- public WebBackForwardList copyBackForwardList() {
- return getValue(new ValueGetter<WebBackForwardList>() {
- @Override
- public WebBackForwardList capture() {
- return mWebView.copyBackForwardList();
- }
- });
- }
-
- public Bitmap getFavicon() {
- return getValue(new ValueGetter<Bitmap>() {
- @Override
- public Bitmap capture() {
- return mWebView.getFavicon();
- }
- });
- }
-
- public String getUrl() {
- return getValue(new ValueGetter<String>() {
- @Override
- public String capture() {
- return mWebView.getUrl();
- }
- });
- }
-
- public int getProgress() {
- return getValue(new ValueGetter<Integer>() {
- @Override
- public Integer capture() {
- return mWebView.getProgress();
- }
- });
- }
-
- public int getHeight() {
- return getValue(new ValueGetter<Integer>() {
- @Override
- public Integer capture() {
- return mWebView.getHeight();
- }
- });
- }
-
- public int getContentHeight() {
- return getValue(new ValueGetter<Integer>() {
- @Override
- public Integer capture() {
- return mWebView.getContentHeight();
- }
- });
- }
-
- public boolean savePicture(final Bundle b, final File dest) {
- return getValue(new ValueGetter<Boolean>() {
- @Override
- public Boolean capture() {
- return mWebView.savePicture(b, dest);
- }
- });
- }
-
- public boolean pageUp(final boolean top) {
- return getValue(new ValueGetter<Boolean>() {
- @Override
- public Boolean capture() {
- return mWebView.pageUp(top);
- }
- });
- }
-
- public boolean pageDown(final boolean bottom) {
- return getValue(new ValueGetter<Boolean>() {
- @Override
- public Boolean capture() {
- return mWebView.pageDown(bottom);
- }
- });
- }
-
- public int[] getLocationOnScreen() {
- final int[] location = new int[2];
- return getValue(new ValueGetter<int[]>() {
- @Override
- public int[] capture() {
- mWebView.getLocationOnScreen(location);
- return location;
- }
- });
- }
-
- public float getScale() {
- return getValue(new ValueGetter<Float>() {
- @Override
- public Float capture() {
- return mWebView.getScale();
- }
- });
- }
-
- public boolean requestFocus(final int direction,
- final Rect previouslyFocusedRect) {
- return getValue(new ValueGetter<Boolean>() {
- @Override
- public Boolean capture() {
- return mWebView.requestFocus(direction, previouslyFocusedRect);
- }
- });
- }
-
- public HitTestResult getHitTestResult() {
- return getValue(new ValueGetter<HitTestResult>() {
- @Override
- public HitTestResult capture() {
- return mWebView.getHitTestResult();
- }
- });
- }
-
- public int getScrollX() {
- return getValue(new ValueGetter<Integer>() {
- @Override
- public Integer capture() {
- return mWebView.getScrollX();
- }
- });
- }
-
- public int getScrollY() {
- return getValue(new ValueGetter<Integer>() {
- @Override
- public Integer capture() {
- return mWebView.getScrollY();
- }
- });
- }
-
- public final DisplayMetrics getDisplayMetrics() {
- return getValue(new ValueGetter<DisplayMetrics>() {
- @Override
- public DisplayMetrics capture() {
- return mWebView.getContext().getResources().getDisplayMetrics();
- }
- });
- }
-
- public boolean requestChildRectangleOnScreen(final View child,
- final Rect rect,
- final boolean immediate) {
- return getValue(new ValueGetter<Boolean>() {
- @Override
- public Boolean capture() {
- return mWebView.requestChildRectangleOnScreen(child, rect,
- immediate);
- }
- });
- }
-
- public int findAll(final String find) {
- return getValue(new ValueGetter<Integer>() {
- @Override
- public Integer capture() {
- return mWebView.findAll(find);
- }
- });
- }
-
- public Picture capturePicture() {
- return getValue(new ValueGetter<Picture>() {
- @Override
- public Picture capture() {
- return mWebView.capturePicture();
- }
- });
- }
-
- public void evaluateJavascript(final String script, final ValueCallback<String> result) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mWebView.evaluateJavascript(script, result);
- }
- });
- }
-
- public WebView createWebView() {
- return getValue(new ValueGetter<WebView>() {
- @Override
- public WebView capture() {
- return new WebView(mWebView.getContext());
- }
- });
- }
-
- public PrintDocumentAdapter createPrintDocumentAdapter() {
- return getValue(new ValueGetter<PrintDocumentAdapter>() {
- @Override
- public PrintDocumentAdapter capture() {
- return mWebView.createPrintDocumentAdapter();
- }
- });
- }
-
- public void setLayoutHeightToMatchParent() {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- ViewParent parent = mWebView.getParent();
- if (parent instanceof ViewGroup) {
- ((ViewGroup) parent).getLayoutParams().height =
- ViewGroup.LayoutParams.MATCH_PARENT;
- }
- mWebView.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
- mWebView.requestLayout();
- }
- });
- }
-
- public void setAcceptThirdPartyCookies(final boolean accept) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView, accept);
- }
- });
- }
-
- public boolean acceptThirdPartyCookies() {
- return getValue(new ValueGetter<Boolean>() {
- @Override
- public Boolean capture() {
- return CookieManager.getInstance().acceptThirdPartyCookies(mWebView);
- }
- });
- }
-
- /**
- * Helper for running code on the UI thread where an exception is
- * a test failure. If this is already the UI thread then it runs
- * the code immediately.
- *
- * @see runTestOnUiThread
- * @param r The code to run in the UI thread
- */
- public void runOnUiThread(Runnable r) {
- try {
- if (isUiThread()) {
- r.run();
- } else {
- mTest.runTestOnUiThread(r);
- }
- } catch (Throwable t) {
- Assert.fail("Unexpected error while running on UI thread: "
- + t.getMessage());
- }
- }
-
- /**
- * Accessor for underlying WebView.
- * @return The WebView being wrapped by this class.
- */
- public WebView getWebView() {
- return mWebView;
- }
-
- private<T> T getValue(ValueGetter<T> getter) {
- runOnUiThread(getter);
- return getter.getValue();
- }
-
- private abstract class ValueGetter<T> implements Runnable {
- private T mValue;
-
- @Override
- public void run() {
- mValue = capture();
- }
-
- protected abstract T capture();
-
- public T getValue() {
- return mValue;
- }
- }
-
- /**
- * Returns true if the current thread is the UI thread based on the
- * Looper.
- */
- private static boolean isUiThread() {
- return (Looper.myLooper() == Looper.getMainLooper());
- }
-
- /**
- * @return Whether or not the load has finished.
- */
- private synchronized boolean isLoaded() {
- return mLoaded && mNewPicture && mProgress == 100;
- }
-
- /**
- * Makes a WebView call, waits for completion and then resets the
- * load state in preparation for the next load call.
- * @param call The call to make on the UI thread prior to waiting.
- */
- private void callAndWait(Runnable call) {
- Assert.assertTrue("WebViewOnUiThread.load*AndWaitForCompletion calls "
- + "may not be mixed with load* calls directly on WebView "
- + "without calling waitForLoadCompletion after the load",
- !isLoaded());
- clearLoad(); // clear any extraneous signals from a previous load.
- runOnUiThread(call);
- waitForLoadCompletion();
- }
-
- /**
- * Called whenever a load has been completed so that a subsequent call to
- * waitForLoadCompletion doesn't return immediately.
- */
- synchronized private void clearLoad() {
- mLoaded = false;
- mNewPicture = false;
- mProgress = 0;
- }
-
- /**
- * Uses a polling mechanism, while pumping messages to check when the
- * criteria is met.
- */
- private void waitOnUiThread(long timeout, final Callable<Boolean> doneCriteria) {
- new PollingCheck(timeout) {
- @Override
- protected boolean check() {
- pumpMessages();
- try {
- return doneCriteria.call();
- } catch (Exception e) {
- Assert.fail("Unexpected error while checking the criteria: "
- + e.getMessage());
- return true;
- }
- }
- }.run();
- }
-
- /**
- * Uses a wait/notify to check when the criteria is met.
- */
- private synchronized void waitOnTestThread(long timeout, Callable<Boolean> doneCriteria) {
- try {
- long waitEnd = SystemClock.uptimeMillis() + timeout;
- long timeRemaining = timeout;
- while (!doneCriteria.call() && timeRemaining > 0) {
- this.wait(timeRemaining);
- timeRemaining = waitEnd - SystemClock.uptimeMillis();
- }
- Assert.assertTrue("Action failed to complete before timeout", doneCriteria.call());
- } catch (InterruptedException e) {
- // We'll just drop out of the loop and fail
- } catch (Exception e) {
- Assert.fail("Unexpected error while checking the criteria: "
- + e.getMessage());
- }
- }
-
- /**
- * Pumps all currently-queued messages in the UI thread and then exits.
- * This is useful to force processing while running tests in the UI thread.
- */
- private void pumpMessages() {
- class ExitLoopException extends RuntimeException {
- }
-
- // Force loop to exit when processing this. Loop.quit() doesn't
- // work because this is the main Loop.
- mWebView.getHandler().post(new Runnable() {
- @Override
- public void run() {
- throw new ExitLoopException(); // exit loop!
- }
- });
- try {
- // Pump messages until our message gets through.
- Looper.loop();
- } catch (ExitLoopException e) {
- }
- }
-
- /**
- * A WebChromeClient used to capture the onProgressChanged for use
- * in waitFor functions. If a test must override the WebChromeClient,
- * it can derive from this class or call onProgressChanged
- * directly.
- */
- public static class WaitForProgressClient extends WebChromeClient {
- private WebViewOnUiThread mOnUiThread;
-
- public WaitForProgressClient(WebViewOnUiThread onUiThread) {
- mOnUiThread = onUiThread;
- }
-
- @Override
- public void onProgressChanged(WebView view, int newProgress) {
- super.onProgressChanged(view, newProgress);
- mOnUiThread.onProgressChanged(newProgress);
- }
- }
-
- /**
- * A WebViewClient that captures the onPageFinished for use in
- * waitFor functions. Using initializeWebView sets the WaitForLoadedClient
- * into the WebView. If a test needs to set a specific WebViewClient and
- * needs the waitForCompletion capability then it should derive from
- * WaitForLoadedClient or call WebViewOnUiThread.onPageFinished.
- */
- public static class WaitForLoadedClient extends WebViewClient {
- private WebViewOnUiThread mOnUiThread;
-
- public WaitForLoadedClient(WebViewOnUiThread onUiThread) {
- mOnUiThread = onUiThread;
- }
-
- @Override
- public void onPageFinished(WebView view, String url) {
- super.onPageFinished(view, url);
- mOnUiThread.onPageFinished();
- }
-
- @Override
- public void onPageStarted(WebView view, String url, Bitmap favicon) {
- super.onPageStarted(view, url, favicon);
- mOnUiThread.onPageStarted();
- }
- }
-
- /**
- * A PictureListener that captures the onNewPicture for use in
- * waitForLoadCompletion. Using initializeWebView sets the PictureListener
- * into the WebView. If a test needs to set a specific PictureListener and
- * needs the waitForCompletion capability then it should call
- * WebViewOnUiThread.onNewPicture.
- */
- private class WaitForNewPicture implements PictureListener {
- @Override
- public void onNewPicture(WebView view, Picture picture) {
- WebViewOnUiThread.this.onNewPicture();
- }
- }
-}
diff --git a/tests/tests/text/src/android/text/cts/WidgetTestUtils.java b/tests/tests/text/src/android/text/cts/WidgetTestUtils.java
deleted file mode 100644
index d41b242..0000000
--- a/tests/tests/text/src/android/text/cts/WidgetTestUtils.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright (C) 2008 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 android.text.cts;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-
-import java.io.IOException;
-
-import junit.framework.Assert;
-
-/**
- * The useful methods for widget test.
- */
-public class WidgetTestUtils {
- /**
- * Assert that two bitmaps are equal.
- *
- * @param Bitmap b1 the first bitmap which needs to compare.
- * @param Bitmap b2 the second bitmap which needs to compare.
- */
- public static void assertEquals(Bitmap b1, Bitmap b2) {
- if (b1 == b2) {
- return;
- }
-
- if (b1 == null || b2 == null) {
- Assert.fail("the bitmaps are not equal");
- }
-
- // b1 and b2 are all not null.
- if (b1.getWidth() != b2.getWidth() || b1.getHeight() != b2.getHeight()
- || b1.getConfig() != b2.getConfig()) {
- Assert.fail("the bitmaps are not equal");
- }
-
- int w = b1.getWidth();
- int h = b1.getHeight();
- int s = w * h;
- int[] pixels1 = new int[s];
- int[] pixels2 = new int[s];
-
- b1.getPixels(pixels1, 0, w, 0, 0, w, h);
- b2.getPixels(pixels2, 0, w, 0, 0, w, h);
-
- for (int i = 0; i < s; i++) {
- if (pixels1[i] != pixels2[i]) {
- Assert.fail("the bitmaps are not equal");
- }
- }
- }
-
- /**
- * Find beginning of the special element.
- * @param parser XmlPullParser will be parsed.
- * @param firstElementName the target element name.
- *
- * @throws XmlPullParserException if XML Pull Parser related faults occur.
- * @throws IOException if I/O-related error occur when parsing.
- */
- public static final void beginDocument(XmlPullParser parser, String firstElementName)
- throws XmlPullParserException, IOException {
- Assert.assertNotNull(parser);
- Assert.assertNotNull(firstElementName);
-
- int type;
- while ((type = parser.next()) != XmlPullParser.START_TAG
- && type != XmlPullParser.END_DOCUMENT) {
- ;
- }
-
- if (!parser.getName().equals(firstElementName)) {
- throw new XmlPullParserException("Unexpected start tag: found " + parser.getName()
- + ", expected " + firstElementName);
- }
- }
-
- /**
- * Compare the expected pixels with actual, scaling for the target context density
- *
- * @throws AssertionFailedError
- */
- public static void assertScaledPixels(int expected, int actual, Context context) {
- Assert.assertEquals(expected * context.getResources().getDisplayMetrics().density,
- actual, 3);
- }
-
- /** Converts dips into pixels using the {@link Context}'s density. */
- public static int convertDipToPixels(Context context, int dip) {
- float density = context.getResources().getDisplayMetrics().density;
- return Math.round(density * dip);
- }
-
- /**
- * Retrieve a bitmap that can be used for comparison on any density
- * @param resources
- * @return the {@link Bitmap} or <code>null</code>
- */
- public static Bitmap getUnscaledBitmap(Resources resources, int resId) {
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inScaled = false;
- return BitmapFactory.decodeResource(resources, resId, options);
- }
-
- /**
- * Retrieve a dithered bitmap that can be used for comparison on any density
- * @param resources
- * @param config the preferred config for the returning bitmap
- * @return the {@link Bitmap} or <code>null</code>
- */
- public static Bitmap getUnscaledAndDitheredBitmap(Resources resources,
- int resId, Bitmap.Config config) {
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inDither = true;
- options.inScaled = false;
- options.inPreferredConfig = config;
- return BitmapFactory.decodeResource(resources, resId, options);
- }
-}
diff --git a/tests/tests/text/src/android/text/method/cts/ScrollingMovementMethodTest.java b/tests/tests/text/src/android/text/method/cts/ScrollingMovementMethodTest.java
index c186cde..73fd763 100644
--- a/tests/tests/text/src/android/text/method/cts/ScrollingMovementMethodTest.java
+++ b/tests/tests/text/src/android/text/method/cts/ScrollingMovementMethodTest.java
@@ -18,6 +18,7 @@
import dalvik.annotation.KnownFailure;
+import android.cts.util.WidgetTestUtils;
import android.os.SystemClock;
import android.test.ActivityInstrumentationTestCase2;
import android.text.Layout;
@@ -33,7 +34,6 @@
import android.view.ViewGroup.LayoutParams;
import android.widget.TextView;
import android.widget.TextView.BufferType;
-import android.text.cts.WidgetTestUtils;
/**
* Test {@link ScrollingMovementMethod}. The class is an implementation of interface
diff --git a/tests/tests/text/src/android/text/style/cts/ImageSpanTest.java b/tests/tests/text/src/android/text/style/cts/ImageSpanTest.java
index a98c748..6f056d0 100644
--- a/tests/tests/text/src/android/text/style/cts/ImageSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/ImageSpanTest.java
@@ -20,6 +20,7 @@
import android.content.Context;
+import android.cts.util.WidgetTestUtils;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
@@ -27,7 +28,6 @@
import android.test.AndroidTestCase;
import android.text.style.DynamicDrawableSpan;
import android.text.style.ImageSpan;
-import android.text.cts.WidgetTestUtils;
public class ImageSpanTest extends AndroidTestCase {
public void testConstructor() {
diff --git a/tests/tests/view/src/android/view/cts/MenuInflaterTest.java b/tests/tests/view/src/android/view/cts/MenuInflaterTest.java
index bd483f9..40d1d3d 100644
--- a/tests/tests/view/src/android/view/cts/MenuInflaterTest.java
+++ b/tests/tests/view/src/android/view/cts/MenuInflaterTest.java
@@ -23,6 +23,7 @@
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
+import android.cts.util.WidgetTestUtils;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
diff --git a/tests/tests/view/src/android/view/cts/ViewGroupCtsActivity.java b/tests/tests/view/src/android/view/cts/ViewGroupCtsActivity.java
index 71bb28c..880a450 100644
--- a/tests/tests/view/src/android/view/cts/ViewGroupCtsActivity.java
+++ b/tests/tests/view/src/android/view/cts/ViewGroupCtsActivity.java
@@ -17,7 +17,7 @@
package android.view.cts;
import android.app.Activity;
-import android.app.cts.CTSResult;
+import android.cts.util.CTSResult;
import android.os.Bundle;
import android.os.Handler;
import android.widget.TextView;
diff --git a/tests/tests/view/src/android/view/cts/ViewGroupTest.java b/tests/tests/view/src/android/view/cts/ViewGroupTest.java
index 55428de..f1064a7 100644
--- a/tests/tests/view/src/android/view/cts/ViewGroupTest.java
+++ b/tests/tests/view/src/android/view/cts/ViewGroupTest.java
@@ -19,9 +19,9 @@
import com.android.internal.util.XmlUtils;
-import android.app.cts.CTSResult;
import android.content.Context;
import android.content.Intent;
+import android.cts.util.CTSResult;
import android.content.res.XmlResourceParser;
import android.graphics.Bitmap;
import android.graphics.Canvas;
diff --git a/tests/tests/webkit/Android.mk b/tests/tests/webkit/Android.mk
index 1d593df..c2d8c3c 100644
--- a/tests/tests/webkit/Android.mk
+++ b/tests/tests/webkit/Android.mk
@@ -23,7 +23,7 @@
LOCAL_JAVA_LIBRARIES := android.test.runner
-LOCAL_STATIC_JAVA_LIBRARIES := ctsdeviceutil ctstestserver ctstestrunner
+LOCAL_STATIC_JAVA_LIBRARIES := ctsdeviceutil ctsdeviceutillegacy ctstestserver ctstestrunner
LOCAL_SRC_FILES := $(call all-java-files-under, src)
diff --git a/tests/tests/webkit/src/android/webkit/cts/CookieManagerTest.java b/tests/tests/webkit/src/android/webkit/cts/CookieManagerTest.java
index 9db7c21..c612886 100644
--- a/tests/tests/webkit/src/android/webkit/cts/CookieManagerTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/CookieManagerTest.java
@@ -16,6 +16,7 @@
package android.webkit.cts;
+import android.cts.util.NullWebViewUtils;
import android.cts.util.PollingCheck;
import android.test.ActivityInstrumentationTestCase2;
import android.webkit.CookieManager;
diff --git a/tests/tests/webkit/src/android/webkit/cts/CookieSyncManagerCtsActivity.java b/tests/tests/webkit/src/android/webkit/cts/CookieSyncManagerCtsActivity.java
index 51eeed3..e623405 100644
--- a/tests/tests/webkit/src/android/webkit/cts/CookieSyncManagerCtsActivity.java
+++ b/tests/tests/webkit/src/android/webkit/cts/CookieSyncManagerCtsActivity.java
@@ -17,6 +17,7 @@
package android.webkit.cts;
import android.app.Activity;
+import android.cts.util.NullWebViewUtils;
import android.os.Bundle;
import android.webkit.CookieSyncManager;
import android.webkit.WebView;
diff --git a/tests/tests/webkit/src/android/webkit/cts/CookieTest.java b/tests/tests/webkit/src/android/webkit/cts/CookieTest.java
index bc5e3b0..555266b 100644
--- a/tests/tests/webkit/src/android/webkit/cts/CookieTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/CookieTest.java
@@ -16,6 +16,7 @@
package android.webkit.cts;
+import android.cts.util.NullWebViewUtils;
import android.test.ActivityInstrumentationTestCase2;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
diff --git a/tests/tests/webkit/src/android/webkit/cts/GeolocationTest.java b/tests/tests/webkit/src/android/webkit/cts/GeolocationTest.java
index 63990bf..ba0e0e9 100644
--- a/tests/tests/webkit/src/android/webkit/cts/GeolocationTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/GeolocationTest.java
@@ -17,6 +17,7 @@
package android.webkit.cts;
import android.content.Context;
+import android.cts.util.NullWebViewUtils;
import android.cts.util.PollingCheck;
import android.graphics.Bitmap;
import android.location.Criteria;
diff --git a/tests/tests/webkit/src/android/webkit/cts/HttpAuthHandlerTest.java b/tests/tests/webkit/src/android/webkit/cts/HttpAuthHandlerTest.java
index fbda04b..5c86987 100644
--- a/tests/tests/webkit/src/android/webkit/cts/HttpAuthHandlerTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/HttpAuthHandlerTest.java
@@ -16,6 +16,7 @@
package android.webkit.cts;
+import android.cts.util.NullWebViewUtils;
import android.test.ActivityInstrumentationTestCase2;
import android.webkit.HttpAuthHandler;
import android.webkit.WebView;
diff --git a/tests/tests/webkit/src/android/webkit/cts/NullWebViewUtils.java b/tests/tests/webkit/src/android/webkit/cts/NullWebViewUtils.java
deleted file mode 100644
index c52219f..0000000
--- a/tests/tests/webkit/src/android/webkit/cts/NullWebViewUtils.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (C) 2010 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 android.webkit.cts;
-
-import android.content.Context;
-import android.content.pm.PackageManager;
-
-/**
- * Utilities to enable the android.webkit.* CTS tests (and others that rely on a functioning
- * android.webkit.WebView implementation) to determine whether a functioning WebView is present
- * on the device or not.
- *
- * Test cases that require android.webkit.* classes should wrap their first usage of WebView in a
- * try catch block, and pass any exception that is thrown to
- * NullWebViewUtils.determineIfWebViewAvailable. The return value of
- * NullWebViewUtils.isWebViewAvailable will then determine if the test should expect to be able to
- * use a WebView.
- */
-public class NullWebViewUtils {
-
- private static boolean sWebViewUnavailable;
-
- /**
- * @param context Current Activity context, used to query the PackageManager.
- * @param t An exception thrown by trying to invoke android.webkit.* APIs.
- */
- public static void determineIfWebViewAvailable(Context context, Throwable t) {
- sWebViewUnavailable = !hasWebViewFeature(context) && checkCauseWasUnsupportedOperation(t);
- }
-
- /**
- * After calling determineIfWebViewAvailable, this returns whether a WebView is available on the
- * device and wheter the test can rely on it.
- * @return True iff. PackageManager determined that there is no WebView on the device and the
- * exception thrown from android.webkit.* was UnsupportedOperationException.
- */
- public static boolean isWebViewAvailable() {
- return !sWebViewUnavailable;
- }
-
- private static boolean hasWebViewFeature(Context context) {
- // Query the system property that determins if there is a functional WebView on the device.
- PackageManager pm = context.getPackageManager();
- return pm.hasSystemFeature(PackageManager.FEATURE_WEBVIEW);
- }
-
- private static boolean checkCauseWasUnsupportedOperation(Throwable t) {
- if (t == null) return false;
- while (t.getCause() != null) {
- t = t.getCause();
- }
- return t instanceof UnsupportedOperationException;
- }
-
- /**
- * Some CTS tests (by design) first use android.webkit.* from a background thread. This helper
- * allows the test to catch the UnsupportedOperationException from that background thread, and
- * then query the result from the test main thread.
- */
- public static class NullWebViewFromThreadExceptionHandler
- implements Thread.UncaughtExceptionHandler {
- private Throwable mPendingException;
-
- @Override
- public void uncaughtException(Thread t, Throwable e) {
- mPendingException = e;
- }
-
- public boolean isWebViewAvailable(Context context) {
- return hasWebViewFeature(context) ||
- !checkCauseWasUnsupportedOperation(mPendingException);
- }
- }
-}
\ No newline at end of file
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebBackForwardListTest.java b/tests/tests/webkit/src/android/webkit/cts/WebBackForwardListTest.java
index 21a5b98..7d25b84 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebBackForwardListTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebBackForwardListTest.java
@@ -16,6 +16,7 @@
package android.webkit.cts;
+import android.cts.util.NullWebViewUtils;
import android.cts.util.PollingCheck;
import android.test.ActivityInstrumentationTestCase2;
import android.webkit.WebBackForwardList;
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java b/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java
index 6a94a99..150fd86 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java
@@ -16,6 +16,7 @@
package android.webkit.cts;
+import android.cts.util.NullWebViewUtils;
import android.cts.util.PollingCheck;
import android.graphics.Bitmap;
import android.os.Message;
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebHistoryItemTest.java b/tests/tests/webkit/src/android/webkit/cts/WebHistoryItemTest.java
index d4f326b..a6b647d 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebHistoryItemTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebHistoryItemTest.java
@@ -16,6 +16,7 @@
package android.webkit.cts;
+import android.cts.util.NullWebViewUtils;
import android.cts.util.PollingCheck;
import android.graphics.Bitmap;
import android.test.ActivityInstrumentationTestCase2;
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java b/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java
index 3e7a592..33a9cee 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java
@@ -16,6 +16,7 @@
package android.webkit.cts;
import android.content.Context;
+import android.cts.util.NullWebViewUtils;
import android.cts.util.PollingCheck;
import android.graphics.Bitmap;
import android.net.http.SslError;
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebViewClientTest.java b/tests/tests/webkit/src/android/webkit/cts/WebViewClientTest.java
index 2430c8c..5b906ba 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebViewClientTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebViewClientTest.java
@@ -17,6 +17,7 @@
package android.webkit.cts;
import android.cts.util.EvaluateJsResultPollingCheck;
+import android.cts.util.NullWebViewUtils;
import android.cts.util.PollingCheck;
import android.graphics.Bitmap;
import android.os.Message;
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebViewCtsActivity.java b/tests/tests/webkit/src/android/webkit/cts/WebViewCtsActivity.java
index d809a42..9af7266 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebViewCtsActivity.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebViewCtsActivity.java
@@ -19,6 +19,7 @@
import com.android.cts.webkit.R;
import android.app.Activity;
+import android.cts.util.NullWebViewUtils;
import android.os.Bundle;
import android.view.ViewGroup;
import android.view.ViewParent;
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebViewSslTest.java b/tests/tests/webkit/src/android/webkit/cts/WebViewSslTest.java
index 8aa0145..378bf6e 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebViewSslTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebViewSslTest.java
@@ -16,6 +16,7 @@
package android.webkit.cts;
+import android.cts.util.NullWebViewUtils;
import android.cts.util.PollingCheck;
import android.net.Uri;
import android.net.http.SslCertificate;
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebViewStartupTest.java b/tests/tests/webkit/src/android/webkit/cts/WebViewStartupTest.java
index 8f4dcc2..776cfab 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebViewStartupTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebViewStartupTest.java
@@ -18,6 +18,7 @@
import android.content.Context;
+import android.cts.util.NullWebViewUtils;
import android.cts.util.PollingCheck;
import android.test.ActivityInstrumentationTestCase2;
import android.test.UiThreadTest;
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
index 1d8a02a..ef64f4d 100755
--- a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
@@ -20,6 +20,7 @@
import android.content.Context;
import android.content.res.AssetManager;
import android.cts.util.EvaluateJsResultPollingCheck;
+import android.cts.util.NullWebViewUtils;
import android.cts.util.PollingCheck;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebView_WebViewTransportTest.java b/tests/tests/webkit/src/android/webkit/cts/WebView_WebViewTransportTest.java
index 0c04706..1db7fca 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebView_WebViewTransportTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebView_WebViewTransportTest.java
@@ -16,6 +16,7 @@
package android.webkit.cts;
+import android.cts.util.NullWebViewUtils;
import android.test.ActivityInstrumentationTestCase2;
import android.test.UiThreadTest;
import android.webkit.WebView;
diff --git a/tests/tests/widget/src/android/widget/cts/AbsListViewTest.java b/tests/tests/widget/src/android/widget/cts/AbsListViewTest.java
index b6a96fb..9d8c7d2 100644
--- a/tests/tests/widget/src/android/widget/cts/AbsListViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/AbsListViewTest.java
@@ -25,6 +25,7 @@
import android.app.Instrumentation;
import android.content.Context;
import android.cts.util.PollingCheck;
+import android.cts.util.WidgetTestUtils;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Rect;
diff --git a/tests/tests/widget/src/android/widget/cts/AbsListView_LayoutParamsTest.java b/tests/tests/widget/src/android/widget/cts/AbsListView_LayoutParamsTest.java
index 413bc2a..305a9e2 100644
--- a/tests/tests/widget/src/android/widget/cts/AbsListView_LayoutParamsTest.java
+++ b/tests/tests/widget/src/android/widget/cts/AbsListView_LayoutParamsTest.java
@@ -21,6 +21,7 @@
import org.xmlpull.v1.XmlPullParser;
+import android.cts.util.WidgetTestUtils;
import android.test.AndroidTestCase;
import android.util.AttributeSet;
import android.util.Xml;
diff --git a/tests/tests/widget/src/android/widget/cts/AbsoluteLayoutTest.java b/tests/tests/widget/src/android/widget/cts/AbsoluteLayoutTest.java
index 053f42b..bac2479 100644
--- a/tests/tests/widget/src/android/widget/cts/AbsoluteLayoutTest.java
+++ b/tests/tests/widget/src/android/widget/cts/AbsoluteLayoutTest.java
@@ -24,6 +24,7 @@
import android.app.Activity;
import android.content.Context;
+import android.cts.util.WidgetTestUtils;
import android.test.ActivityInstrumentationTestCase2;
import android.util.AttributeSet;
import android.util.Xml;
diff --git a/tests/tests/widget/src/android/widget/cts/AbsoluteLayout_LayoutParamsTest.java b/tests/tests/widget/src/android/widget/cts/AbsoluteLayout_LayoutParamsTest.java
index 685f2d3..ebc4e74 100644
--- a/tests/tests/widget/src/android/widget/cts/AbsoluteLayout_LayoutParamsTest.java
+++ b/tests/tests/widget/src/android/widget/cts/AbsoluteLayout_LayoutParamsTest.java
@@ -22,6 +22,7 @@
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
+import android.cts.util.WidgetTestUtils;
import android.test.AndroidTestCase;
import android.util.AttributeSet;
import android.util.Xml;
diff --git a/tests/tests/widget/src/android/widget/cts/CursorAdapterTest.java b/tests/tests/widget/src/android/widget/cts/CursorAdapterTest.java
index 8cc0754..0916e59 100644
--- a/tests/tests/widget/src/android/widget/cts/CursorAdapterTest.java
+++ b/tests/tests/widget/src/android/widget/cts/CursorAdapterTest.java
@@ -20,6 +20,8 @@
import android.content.Context;
import android.cts.util.PollingCheck;
+import android.cts.util.ReadElf;
+import android.cts.util.TestThread;
import android.database.ContentObserver;
import android.database.Cursor;
import android.database.DataSetObserver;
diff --git a/tests/tests/widget/src/android/widget/cts/FilterTest.java b/tests/tests/widget/src/android/widget/cts/FilterTest.java
index 76de481..2c598dd 100644
--- a/tests/tests/widget/src/android/widget/cts/FilterTest.java
+++ b/tests/tests/widget/src/android/widget/cts/FilterTest.java
@@ -18,6 +18,8 @@
import android.cts.util.PollingCheck;
+import android.cts.util.ReadElf;
+import android.cts.util.TestThread;
import android.os.Looper;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.Filter;
diff --git a/tests/tests/widget/src/android/widget/cts/FrameLayoutTest.java b/tests/tests/widget/src/android/widget/cts/FrameLayoutTest.java
index dcab088..31d9fff 100644
--- a/tests/tests/widget/src/android/widget/cts/FrameLayoutTest.java
+++ b/tests/tests/widget/src/android/widget/cts/FrameLayoutTest.java
@@ -17,6 +17,7 @@
package android.widget.cts;
import android.content.res.ColorStateList;
+import android.cts.util.WidgetTestUtils;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
diff --git a/tests/tests/widget/src/android/widget/cts/FrameLayout_LayoutParamsTest.java b/tests/tests/widget/src/android/widget/cts/FrameLayout_LayoutParamsTest.java
index d8f1296..1e7082f 100644
--- a/tests/tests/widget/src/android/widget/cts/FrameLayout_LayoutParamsTest.java
+++ b/tests/tests/widget/src/android/widget/cts/FrameLayout_LayoutParamsTest.java
@@ -22,6 +22,7 @@
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
+import android.cts.util.WidgetTestUtils;
import android.test.AndroidTestCase;
import android.util.AttributeSet;
import android.util.Xml;
diff --git a/tests/tests/widget/src/android/widget/cts/GalleryTest.java b/tests/tests/widget/src/android/widget/cts/GalleryTest.java
index a2deab9..2813965 100644
--- a/tests/tests/widget/src/android/widget/cts/GalleryTest.java
+++ b/tests/tests/widget/src/android/widget/cts/GalleryTest.java
@@ -26,6 +26,7 @@
import android.app.Activity;
import android.app.Instrumentation;
import android.content.Context;
+import android.cts.util.WidgetTestUtils;
import android.os.SystemClock;
import android.test.ActivityInstrumentationTestCase2;
import android.test.UiThreadTest;
diff --git a/tests/tests/widget/src/android/widget/cts/Gallery_LayoutParamsTest.java b/tests/tests/widget/src/android/widget/cts/Gallery_LayoutParamsTest.java
index de90ed3..0502e38 100644
--- a/tests/tests/widget/src/android/widget/cts/Gallery_LayoutParamsTest.java
+++ b/tests/tests/widget/src/android/widget/cts/Gallery_LayoutParamsTest.java
@@ -22,6 +22,7 @@
import org.xmlpull.v1.XmlPullParserException;
import android.content.res.XmlResourceParser;
+import android.cts.util.WidgetTestUtils;
import android.test.AndroidTestCase;
import android.widget.Gallery.LayoutParams;
diff --git a/tests/tests/widget/src/android/widget/cts/HorizontalScrollViewTest.java b/tests/tests/widget/src/android/widget/cts/HorizontalScrollViewTest.java
index 2862865..36398c3 100644
--- a/tests/tests/widget/src/android/widget/cts/HorizontalScrollViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/HorizontalScrollViewTest.java
@@ -24,6 +24,7 @@
import android.app.Activity;
import android.content.Context;
import android.cts.util.PollingCheck;
+import android.cts.util.WidgetTestUtils;
import android.graphics.Rect;
import android.test.ActivityInstrumentationTestCase2;
import android.test.UiThreadTest;
diff --git a/tests/tests/widget/src/android/widget/cts/ImageSwitcherTest.java b/tests/tests/widget/src/android/widget/cts/ImageSwitcherTest.java
index c0e606c..eb75557 100644
--- a/tests/tests/widget/src/android/widget/cts/ImageSwitcherTest.java
+++ b/tests/tests/widget/src/android/widget/cts/ImageSwitcherTest.java
@@ -23,6 +23,7 @@
import android.content.Context;
import android.content.res.Resources;
+import android.cts.util.WidgetTestUtils;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
diff --git a/tests/tests/widget/src/android/widget/cts/ImageViewTest.java b/tests/tests/widget/src/android/widget/cts/ImageViewTest.java
index 7b0b65a..c93d4a1 100644
--- a/tests/tests/widget/src/android/widget/cts/ImageViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/ImageViewTest.java
@@ -29,6 +29,7 @@
import android.app.Activity;
import android.content.Context;
+import android.cts.util.WidgetTestUtils;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
diff --git a/tests/tests/widget/src/android/widget/cts/RemoteViewsActivityTest.java b/tests/tests/widget/src/android/widget/cts/RemoteViewsActivityTest.java
index a03edce..ab109b1 100644
--- a/tests/tests/widget/src/android/widget/cts/RemoteViewsActivityTest.java
+++ b/tests/tests/widget/src/android/widget/cts/RemoteViewsActivityTest.java
@@ -17,6 +17,7 @@
package android.widget.cts;
import android.app.Activity;
+import android.cts.util.NullWebViewUtils;
import android.os.Parcel;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.MediumTest;
diff --git a/tests/tests/widget/src/android/widget/cts/RemoteViewsCtsActivity.java b/tests/tests/widget/src/android/widget/cts/RemoteViewsCtsActivity.java
index 6826eb3..4da5aa2 100644
--- a/tests/tests/widget/src/android/widget/cts/RemoteViewsCtsActivity.java
+++ b/tests/tests/widget/src/android/widget/cts/RemoteViewsCtsActivity.java
@@ -19,6 +19,7 @@
import com.android.cts.widget.R;
import android.app.Activity;
+import android.cts.util.NullWebViewUtils;
import android.os.Bundle;
import android.widget.RemoteViews;
diff --git a/tests/tests/widget/src/android/widget/cts/RemoteViewsTest.java b/tests/tests/widget/src/android/widget/cts/RemoteViewsTest.java
index 8d1cddf..328f9f3 100644
--- a/tests/tests/widget/src/android/widget/cts/RemoteViewsTest.java
+++ b/tests/tests/widget/src/android/widget/cts/RemoteViewsTest.java
@@ -26,6 +26,7 @@
import android.app.Instrumentation.ActivityMonitor;
import android.content.Intent;
import android.content.res.ColorStateList;
+import android.cts.util.WidgetTestUtils;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
diff --git a/tests/tests/widget/src/android/widget/cts/SimpleAdapterTest.java b/tests/tests/widget/src/android/widget/cts/SimpleAdapterTest.java
index 90ff617..c530293 100644
--- a/tests/tests/widget/src/android/widget/cts/SimpleAdapterTest.java
+++ b/tests/tests/widget/src/android/widget/cts/SimpleAdapterTest.java
@@ -20,6 +20,7 @@
import android.content.Context;
+import android.cts.util.WidgetTestUtils;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.test.InstrumentationTestCase;
diff --git a/tests/tests/widget/src/android/widget/cts/SimpleCursorAdapterTest.java b/tests/tests/widget/src/android/widget/cts/SimpleCursorAdapterTest.java
index f19dce7..13184de 100644
--- a/tests/tests/widget/src/android/widget/cts/SimpleCursorAdapterTest.java
+++ b/tests/tests/widget/src/android/widget/cts/SimpleCursorAdapterTest.java
@@ -20,6 +20,7 @@
import android.content.Context;
+import android.cts.util.WidgetTestUtils;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.graphics.Bitmap;
diff --git a/tests/tests/widget/src/android/widget/cts/SimpleCursorTreeAdapterTest.java b/tests/tests/widget/src/android/widget/cts/SimpleCursorTreeAdapterTest.java
index 0db5322..c9fdbc3 100644
--- a/tests/tests/widget/src/android/widget/cts/SimpleCursorTreeAdapterTest.java
+++ b/tests/tests/widget/src/android/widget/cts/SimpleCursorTreeAdapterTest.java
@@ -20,6 +20,7 @@
import android.content.Context;
+import android.cts.util.WidgetTestUtils;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.graphics.Bitmap;
diff --git a/tests/tests/widget/src/android/widget/cts/TabHostTest.java b/tests/tests/widget/src/android/widget/cts/TabHostTest.java
index 3af8d9c..00ecd40 100644
--- a/tests/tests/widget/src/android/widget/cts/TabHostTest.java
+++ b/tests/tests/widget/src/android/widget/cts/TabHostTest.java
@@ -22,6 +22,7 @@
import android.app.Activity;
import android.app.ActivityGroup;
import android.content.Intent;
+import android.cts.util.WidgetTestUtils;
import android.test.ActivityInstrumentationTestCase2;
import android.test.UiThreadTest;
import android.view.View;
diff --git a/tests/tests/widget/src/android/widget/cts/TestThread.java b/tests/tests/widget/src/android/widget/cts/TestThread.java
deleted file mode 100644
index 78295b9..0000000
--- a/tests/tests/widget/src/android/widget/cts/TestThread.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (C) 2009 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 android.widget.cts;
-
-/**
- * Thread class for executing a Runnable containing assertions in a separate thread.
- * Uncaught exceptions in the Runnable are rethrown in the context of the the thread
- * calling the <code>runTest()</code> method.
- */
-public final class TestThread extends Thread {
- private Throwable mThrowable;
- private Runnable mTarget;
-
- public TestThread(Runnable target) {
- mTarget = target;
- }
-
- @Override
- public final void run() {
- try {
- mTarget.run();
- } catch (Throwable t) {
- mThrowable = t;
- }
- }
-
- /**
- * Run the target Runnable object and wait until the test finish or throw
- * out Exception if test fail.
- *
- * @param runTime
- * @throws Throwable
- */
- public void runTest(long runTime) throws Throwable {
- start();
- joinAndCheck(runTime);
- }
-
- /**
- * Get the Throwable object which is thrown when test running
- * @return The Throwable object
- */
- public Throwable getThrowable() {
- return mThrowable;
- }
-
- /**
- * Set the Throwable object which is thrown when test running
- * @param t The Throwable object
- */
- public void setThrowable(Throwable t) {
- mThrowable = t;
- }
-
- /**
- * Wait for the test thread to complete and throw the stored exception if there is one.
- *
- * @param runTime The time to wait for the test thread to complete.
- * @throws Throwable
- */
- public void joinAndCheck(long runTime) throws Throwable {
- this.join(runTime);
- if (this.isAlive()) {
- this.interrupt();
- this.join(runTime);
- throw new Exception("Thread did not finish within allotted time.");
- }
- checkException();
- }
-
- /**
- * Check whether there is an exception when running Runnable object.
- * @throws Throwable
- */
- public void checkException() throws Throwable {
- if (mThrowable != null) {
- throw mThrowable;
- }
- }
-}
diff --git a/tests/tests/widget/src/android/widget/cts/TextViewTest.java b/tests/tests/widget/src/android/widget/cts/TextViewTest.java
index c5d9985..72193e7 100644
--- a/tests/tests/widget/src/android/widget/cts/TextViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/TextViewTest.java
@@ -28,6 +28,7 @@
import android.content.res.ColorStateList;
import android.content.res.Resources.NotFoundException;
import android.cts.util.PollingCheck;
+import android.cts.util.WidgetTestUtils;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Paint;
diff --git a/tests/tests/widget/src/android/widget/cts/ViewGroupCtsActivity.java b/tests/tests/widget/src/android/widget/cts/ViewGroupCtsActivity.java
index 378395e..4e14fc2 100644
--- a/tests/tests/widget/src/android/widget/cts/ViewGroupCtsActivity.java
+++ b/tests/tests/widget/src/android/widget/cts/ViewGroupCtsActivity.java
@@ -17,7 +17,7 @@
package android.widget.cts;
import android.app.Activity;
-import android.app.cts.CTSResult;
+import android.cts.util.CTSResult;
import android.os.Bundle;
import android.os.Handler;
import android.widget.TextView;
diff --git a/tests/tests/widget/src/android/widget/cts/WidgetTestUtils.java b/tests/tests/widget/src/android/widget/cts/WidgetTestUtils.java
deleted file mode 100644
index 2df6629..0000000
--- a/tests/tests/widget/src/android/widget/cts/WidgetTestUtils.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright (C) 2008 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 android.widget.cts;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-
-import java.io.IOException;
-
-import junit.framework.Assert;
-
-/**
- * The useful methods for widget test.
- */
-public class WidgetTestUtils {
- /**
- * Assert that two bitmaps are equal.
- *
- * @param Bitmap b1 the first bitmap which needs to compare.
- * @param Bitmap b2 the second bitmap which needs to compare.
- */
- public static void assertEquals(Bitmap b1, Bitmap b2) {
- if (b1 == b2) {
- return;
- }
-
- if (b1 == null || b2 == null) {
- Assert.fail("the bitmaps are not equal");
- }
-
- // b1 and b2 are all not null.
- if (b1.getWidth() != b2.getWidth() || b1.getHeight() != b2.getHeight()
- || b1.getConfig() != b2.getConfig()) {
- Assert.fail("the bitmaps are not equal");
- }
-
- int w = b1.getWidth();
- int h = b1.getHeight();
- int s = w * h;
- int[] pixels1 = new int[s];
- int[] pixels2 = new int[s];
-
- b1.getPixels(pixels1, 0, w, 0, 0, w, h);
- b2.getPixels(pixels2, 0, w, 0, 0, w, h);
-
- for (int i = 0; i < s; i++) {
- if (pixels1[i] != pixels2[i]) {
- Assert.fail("the bitmaps are not equal");
- }
- }
- }
-
- /**
- * Find beginning of the special element.
- * @param parser XmlPullParser will be parsed.
- * @param firstElementName the target element name.
- *
- * @throws XmlPullParserException if XML Pull Parser related faults occur.
- * @throws IOException if I/O-related error occur when parsing.
- */
- public static final void beginDocument(XmlPullParser parser, String firstElementName)
- throws XmlPullParserException, IOException {
- Assert.assertNotNull(parser);
- Assert.assertNotNull(firstElementName);
-
- int type;
- while ((type = parser.next()) != XmlPullParser.START_TAG
- && type != XmlPullParser.END_DOCUMENT) {
- ;
- }
-
- if (!parser.getName().equals(firstElementName)) {
- throw new XmlPullParserException("Unexpected start tag: found " + parser.getName()
- + ", expected " + firstElementName);
- }
- }
-
- /**
- * Compare the expected pixels with actual, scaling for the target context density
- *
- * @throws AssertionFailedError
- */
- public static void assertScaledPixels(int expected, int actual, Context context) {
- Assert.assertEquals(expected * context.getResources().getDisplayMetrics().density,
- actual, 3);
- }
-
- /** Converts dips into pixels using the {@link Context}'s density. */
- public static int convertDipToPixels(Context context, int dip) {
- float density = context.getResources().getDisplayMetrics().density;
- return Math.round(density * dip);
- }
-
- /**
- * Retrieve a bitmap that can be used for comparison on any density
- * @param resources
- * @return the {@link Bitmap} or <code>null</code>
- */
- public static Bitmap getUnscaledBitmap(Resources resources, int resId) {
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inScaled = false;
- return BitmapFactory.decodeResource(resources, resId, options);
- }
-
- /**
- * Retrieve a dithered bitmap that can be used for comparison on any density
- * @param resources
- * @param config the preferred config for the returning bitmap
- * @return the {@link Bitmap} or <code>null</code>
- */
- public static Bitmap getUnscaledAndDitheredBitmap(Resources resources,
- int resId, Bitmap.Config config) {
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inDither = true;
- options.inScaled = false;
- options.inPreferredConfig = config;
- return BitmapFactory.decodeResource(resources, resId, options);
- }
-}
diff --git a/tests/webgl/src/android/webgl/WebGLActivity.java b/tests/webgl/src/android/webgl/WebGLActivity.java
index e88de16..3f911c4 100644
--- a/tests/webgl/src/android/webgl/WebGLActivity.java
+++ b/tests/webgl/src/android/webgl/WebGLActivity.java
@@ -19,9 +19,9 @@
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
+import android.cts.util.NullWebViewUtils;
import android.os.Bundle;
import android.util.Log;
-import android.webgl.cts.NullWebViewUtils;
import android.webgl.cts.R;
import android.webkit.WebView;
import android.webkit.JavascriptInterface;
diff --git a/tests/webgl/src/android/webgl/cts/NullWebViewUtils.java b/tests/webgl/src/android/webgl/cts/NullWebViewUtils.java
deleted file mode 100644
index 861cc22..0000000
--- a/tests/webgl/src/android/webgl/cts/NullWebViewUtils.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (C) 2010 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 android.webgl.cts;
-
-import android.content.Context;
-import android.content.pm.PackageManager;
-
-/**
- * Utilities to enable the android.webkit.* CTS tests (and others that rely on a functioning
- * android.webkit.WebView implementation) to determine whether a functioning WebView is present
- * on the device or not.
- *
- * Test cases that require android.webkit.* classes should wrap their first usage of WebView in a
- * try catch block, and pass any exception that is thrown to
- * NullWebViewUtils.determineIfWebViewAvailable. The return value of
- * NullWebViewUtils.isWebViewAvailable will then determine if the test should expect to be able to
- * use a WebView.
- */
-public class NullWebViewUtils {
-
- private static boolean sWebViewUnavailable;
-
- /**
- * @param context Current Activity context, used to query the PackageManager.
- * @param t An exception thrown by trying to invoke android.webkit.* APIs.
- */
- public static void determineIfWebViewAvailable(Context context, Throwable t) {
- sWebViewUnavailable = !hasWebViewFeature(context) && checkCauseWasUnsupportedOperation(t);
- }
-
- /**
- * After calling determineIfWebViewAvailable, this returns whether a WebView is available on the
- * device and wheter the test can rely on it.
- * @return True iff. PackageManager determined that there is no WebView on the device and the
- * exception thrown from android.webkit.* was UnsupportedOperationException.
- */
- public static boolean isWebViewAvailable() {
- return !sWebViewUnavailable;
- }
-
- private static boolean hasWebViewFeature(Context context) {
- // Query the system property that determins if there is a functional WebView on the device.
- PackageManager pm = context.getPackageManager();
- return pm.hasSystemFeature(PackageManager.FEATURE_WEBVIEW);
- }
-
- private static boolean checkCauseWasUnsupportedOperation(Throwable t) {
- if (t == null) return false;
- while (t.getCause() != null) {
- t = t.getCause();
- }
- return t instanceof UnsupportedOperationException;
- }
-
- /**
- * Some CTS tests (by design) first use android.webkit.* from a background thread. This helper
- * allows the test to catch the UnsupportedOperationException from that background thread, and
- * then query the result from the test main thread.
- */
- public static class NullWebViewFromThreadExceptionHandler
- implements Thread.UncaughtExceptionHandler {
- private Throwable mPendingException;
-
- @Override
- public void uncaughtException(Thread t, Throwable e) {
- mPendingException = e;
- }
-
- public boolean isWebViewAvailable(Context context) {
- return hasWebViewFeature(context) ||
- !checkCauseWasUnsupportedOperation(mPendingException);
- }
- }
-}