Tracking merge of dalvik-dev to master

React to move of Base64 in libcore for CTS
  git cherry-pick --no-commit bf4c21cfbd8d8eabd2ec9af0f315d5baff626580

Breakup android.core.tests.libcore based on top level package name
  git cherry-pick --no-commit 45490fa3d469f4a581ecac46ac40c7a4a9af4aaf

DexFile constructor now takes an argument.
  git cherry-pick --no-commit 583eab2ec924dadebd45b1189929f1acec08c7c7

Change-Id: I9b8b717f13fdc9d4499fd9e7a7b488c7537d3f79
diff --git a/tests/core/Android.mk b/tests/core/Android.mk
index 7a2a708..e9c9793 100644
--- a/tests/core/Android.mk
+++ b/tests/core/Android.mk
@@ -14,6 +14,4 @@
 
 LOCAL_PATH:= $(call my-dir)
 
-BUILD_CTSCORE_PACKAGE:=$(LOCAL_PATH)/ctscore.mk
-
 include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/tests/core/libcore/Android.mk b/tests/core/libcore/Android.mk
index 5b59965..5a897eb 100644
--- a/tests/core/libcore/Android.mk
+++ b/tests/core/libcore/Android.mk
@@ -14,17 +14,6 @@
 
 LOCAL_PATH:= $(call my-dir)
 
-ifeq ($(BUILD_CTSCORE_PACKAGE),)
-    $(error BUILD_CTSCORE_PACKAGE must be defined)
-endif
+BUILD_CTSCORE_PACKAGE:=$(LOCAL_PATH)/../ctscore.mk
 
-#
-# libcore tests
-##########################################################
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := src/Dummy.java
-LOCAL_PACKAGE_NAME := android.core.tests.libcore
-LOCAL_STATIC_JAVA_LIBRARIES := core-tests
-
-include $(BUILD_CTSCORE_PACKAGE)
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/tests/core/libcore/com/Android.mk b/tests/core/libcore/com/Android.mk
new file mode 100644
index 0000000..91a5da0
--- /dev/null
+++ b/tests/core/libcore/com/Android.mk
@@ -0,0 +1,25 @@
+# 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.
+
+LOCAL_PATH:= $(call my-dir)
+
+ifeq ($(BUILD_CTSCORE_PACKAGE),)
+    $(error BUILD_CTSCORE_PACKAGE must be defined)
+endif
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := ../src/Dummy.java
+LOCAL_PACKAGE_NAME := android.core.tests.libcore.package.com
+LOCAL_STATIC_JAVA_LIBRARIES := core-tests
+include $(BUILD_CTSCORE_PACKAGE)
diff --git a/tests/core/libcore/AndroidManifest.xml b/tests/core/libcore/com/AndroidManifest.xml
similarity index 95%
rename from tests/core/libcore/AndroidManifest.xml
rename to tests/core/libcore/com/AndroidManifest.xml
index d0ce941..4e37ef4 100644
--- a/tests/core/libcore/AndroidManifest.xml
+++ b/tests/core/libcore/com/AndroidManifest.xml
@@ -16,7 +16,7 @@
  -->
 
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="android.core.tests.libcore">
+    package="android.core.tests.libcore.package.com">
     <uses-permission android:name="android.permission.INTERNET" />
     <application>
         <uses-library android:name="android.test.runner" />
diff --git a/tests/core/libcore/dalvik/Android.mk b/tests/core/libcore/dalvik/Android.mk
new file mode 100644
index 0000000..45f6e7e
--- /dev/null
+++ b/tests/core/libcore/dalvik/Android.mk
@@ -0,0 +1,25 @@
+# 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.
+
+LOCAL_PATH:= $(call my-dir)
+
+ifeq ($(BUILD_CTSCORE_PACKAGE),)
+    $(error BUILD_CTSCORE_PACKAGE must be defined)
+endif
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := ../src/Dummy.java
+LOCAL_PACKAGE_NAME := android.core.tests.libcore.package.dalvik
+LOCAL_STATIC_JAVA_LIBRARIES := core-tests
+include $(BUILD_CTSCORE_PACKAGE)
diff --git a/tests/core/libcore/AndroidManifest.xml b/tests/core/libcore/dalvik/AndroidManifest.xml
similarity index 94%
copy from tests/core/libcore/AndroidManifest.xml
copy to tests/core/libcore/dalvik/AndroidManifest.xml
index d0ce941..6def32c 100644
--- a/tests/core/libcore/AndroidManifest.xml
+++ b/tests/core/libcore/dalvik/AndroidManifest.xml
@@ -16,7 +16,7 @@
  -->
 
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="android.core.tests.libcore">
+    package="android.core.tests.libcore.package.dalvik">
     <uses-permission android:name="android.permission.INTERNET" />
     <application>
         <uses-library android:name="android.test.runner" />
diff --git a/tests/core/libcore/libcore/Android.mk b/tests/core/libcore/libcore/Android.mk
new file mode 100644
index 0000000..97e32bc
--- /dev/null
+++ b/tests/core/libcore/libcore/Android.mk
@@ -0,0 +1,25 @@
+# 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.
+
+LOCAL_PATH:= $(call my-dir)
+
+ifeq ($(BUILD_CTSCORE_PACKAGE),)
+    $(error BUILD_CTSCORE_PACKAGE must be defined)
+endif
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := ../src/Dummy.java
+LOCAL_PACKAGE_NAME := android.core.tests.libcore.package.libcore
+LOCAL_STATIC_JAVA_LIBRARIES := core-tests
+include $(BUILD_CTSCORE_PACKAGE)
diff --git a/tests/core/libcore/AndroidManifest.xml b/tests/core/libcore/libcore/AndroidManifest.xml
similarity index 94%
copy from tests/core/libcore/AndroidManifest.xml
copy to tests/core/libcore/libcore/AndroidManifest.xml
index d0ce941..e4a5d1e 100644
--- a/tests/core/libcore/AndroidManifest.xml
+++ b/tests/core/libcore/libcore/AndroidManifest.xml
@@ -16,7 +16,7 @@
  -->
 
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="android.core.tests.libcore">
+    package="android.core.tests.libcore.package.libcore">
     <uses-permission android:name="android.permission.INTERNET" />
     <application>
         <uses-library android:name="android.test.runner" />
diff --git a/tests/core/libcore/org/Android.mk b/tests/core/libcore/org/Android.mk
new file mode 100644
index 0000000..8fad8de
--- /dev/null
+++ b/tests/core/libcore/org/Android.mk
@@ -0,0 +1,25 @@
+# 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.
+
+LOCAL_PATH:= $(call my-dir)
+
+ifeq ($(BUILD_CTSCORE_PACKAGE),)
+    $(error BUILD_CTSCORE_PACKAGE must be defined)
+endif
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := ../src/Dummy.java
+LOCAL_PACKAGE_NAME := android.core.tests.libcore.package.org
+LOCAL_STATIC_JAVA_LIBRARIES := core-tests
+include $(BUILD_CTSCORE_PACKAGE)
diff --git a/tests/core/libcore/AndroidManifest.xml b/tests/core/libcore/org/AndroidManifest.xml
similarity index 95%
copy from tests/core/libcore/AndroidManifest.xml
copy to tests/core/libcore/org/AndroidManifest.xml
index d0ce941..d5b77bd 100644
--- a/tests/core/libcore/AndroidManifest.xml
+++ b/tests/core/libcore/org/AndroidManifest.xml
@@ -16,7 +16,7 @@
  -->
 
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="android.core.tests.libcore">
+    package="android.core.tests.libcore.package.org">
     <uses-permission android:name="android.permission.INTERNET" />
     <application>
         <uses-library android:name="android.test.runner" />
diff --git a/tests/core/libcore/sun/Android.mk b/tests/core/libcore/sun/Android.mk
new file mode 100644
index 0000000..5fc0c48
--- /dev/null
+++ b/tests/core/libcore/sun/Android.mk
@@ -0,0 +1,25 @@
+# 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.
+
+LOCAL_PATH:= $(call my-dir)
+
+ifeq ($(BUILD_CTSCORE_PACKAGE),)
+    $(error BUILD_CTSCORE_PACKAGE must be defined)
+endif
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := ../src/Dummy.java
+LOCAL_PACKAGE_NAME := android.core.tests.libcore.package.sun
+LOCAL_STATIC_JAVA_LIBRARIES := core-tests
+include $(BUILD_CTSCORE_PACKAGE)
diff --git a/tests/core/libcore/AndroidManifest.xml b/tests/core/libcore/sun/AndroidManifest.xml
similarity index 95%
copy from tests/core/libcore/AndroidManifest.xml
copy to tests/core/libcore/sun/AndroidManifest.xml
index d0ce941..cc1a853 100644
--- a/tests/core/libcore/AndroidManifest.xml
+++ b/tests/core/libcore/sun/AndroidManifest.xml
@@ -16,7 +16,7 @@
  -->
 
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="android.core.tests.libcore">
+    package="android.core.tests.libcore.package.sun">
     <uses-permission android:name="android.permission.INTERNET" />
     <application>
         <uses-library android:name="android.test.runner" />
diff --git a/tests/core/libcore/tests/Android.mk b/tests/core/libcore/tests/Android.mk
new file mode 100644
index 0000000..bcb6628
--- /dev/null
+++ b/tests/core/libcore/tests/Android.mk
@@ -0,0 +1,25 @@
+# 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.
+
+LOCAL_PATH:= $(call my-dir)
+
+ifeq ($(BUILD_CTSCORE_PACKAGE),)
+    $(error BUILD_CTSCORE_PACKAGE must be defined)
+endif
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := ../src/Dummy.java
+LOCAL_PACKAGE_NAME := android.core.tests.libcore.package.tests
+LOCAL_STATIC_JAVA_LIBRARIES := core-tests
+include $(BUILD_CTSCORE_PACKAGE)
diff --git a/tests/core/libcore/AndroidManifest.xml b/tests/core/libcore/tests/AndroidManifest.xml
similarity index 94%
copy from tests/core/libcore/AndroidManifest.xml
copy to tests/core/libcore/tests/AndroidManifest.xml
index d0ce941..02f8b4a 100644
--- a/tests/core/libcore/AndroidManifest.xml
+++ b/tests/core/libcore/tests/AndroidManifest.xml
@@ -16,7 +16,7 @@
  -->
 
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="android.core.tests.libcore">
+    package="android.core.tests.libcore.package.tests">
     <uses-permission android:name="android.permission.INTERNET" />
     <application>
         <uses-library android:name="android.test.runner" />
diff --git a/tests/src/android/webkit/cts/CtsTestServer.java b/tests/src/android/webkit/cts/CtsTestServer.java
index c9ef52d..9f66d31 100644
--- a/tests/src/android/webkit/cts/CtsTestServer.java
+++ b/tests/src/android/webkit/cts/CtsTestServer.java
@@ -15,7 +15,7 @@
  */
 package android.webkit.cts;
 
-import org.apache.harmony.luni.util.Base64;
+import libcore.io.Base64;
 import org.apache.http.Header;
 import org.apache.http.HttpException;
 import org.apache.http.HttpRequest;
diff --git a/tools/dasm/src/dasm/DAsm.java b/tools/dasm/src/dasm/DAsm.java
index d14d74a..d298689 100644
--- a/tools/dasm/src/dasm/DAsm.java
+++ b/tools/dasm/src/dasm/DAsm.java
@@ -1600,7 +1600,7 @@
         source_name = name;
         class_header = false;
         classDef = null;
-        dexFile = new DexFile();
+        dexFile = new DexFile(dexOptions);
 
         scanner = new Scanner(input);
         parser parse_obj = new parser(this, scanner);
diff --git a/tools/host/src/com/android/cts/HostConfig.java b/tools/host/src/com/android/cts/HostConfig.java
index ffa5e41..d42dcf4 100644
--- a/tools/host/src/com/android/cts/HostConfig.java
+++ b/tools/host/src/com/android/cts/HostConfig.java
@@ -230,9 +230,9 @@
     }
 
     /**
-     * Get the test package by the JAVA package name of the test package.
+     * Get the test package by the name of the test package.
      *
-     * @param packageName The JAVA package name.
+     * @param packageName The package name.
      * @return The test package.
      */
     public TestPackage getTestPackage(final String packageName) {
@@ -275,7 +275,7 @@
     /**
      * Get the package binary name.
      *
-     * @param appPackageName The JAVA package name.
+     * @param appPackageName The package name.
      * @return The binary name of the package.
      */
     public String getPackageBinaryName(String appPackageName) {
@@ -531,7 +531,7 @@
                 }
             }
         }
-     }
+    }
 
     /**
      * Storing the information of case repository.
@@ -544,7 +544,7 @@
         /**
          * Get package names.
          *
-         * @return The JAVA package names.
+         * @return The package names.
          */
         public ArrayList<String> getPackageNames() {
             ArrayList<String> packageNames = new ArrayList<String>();
diff --git a/tools/host/src/com/android/cts/HostSideOnlyPackage.java b/tools/host/src/com/android/cts/HostSideOnlyPackage.java
index 0dab280..7ed31d5 100644
--- a/tools/host/src/com/android/cts/HostSideOnlyPackage.java
+++ b/tools/host/src/com/android/cts/HostSideOnlyPackage.java
@@ -36,7 +36,7 @@
             final String androidVersion, final String jarPath,
             final String appPackageName) {
         super(null, testPkgBinaryName, null, null, version,
-                androidVersion, jarPath, null, appPackageName);
+                androidVersion, jarPath, null, appPackageName, null);
     }
 
     /** {@inheritDoc} */
diff --git a/tools/host/src/com/android/cts/ReferenceAppTestPackage.java b/tools/host/src/com/android/cts/ReferenceAppTestPackage.java
index 0b6aa50..3a14855 100644
--- a/tools/host/src/com/android/cts/ReferenceAppTestPackage.java
+++ b/tools/host/src/com/android/cts/ReferenceAppTestPackage.java
@@ -64,7 +64,7 @@
             String appNameSpace, String appPackageName,
             String apkToTestName, String packageUnderTest) throws NoSuchAlgorithmException {
         super(instrumentationRunner, testPkgBinaryName, targetNameSpace, targetBinaryName, version,
-                androidVersion, jarPath, appNameSpace, appPackageName);
+                androidVersion, jarPath, appNameSpace, appPackageName, null);
         this.apkToTestName = apkToTestName;
         this.packageUnderTest = packageUnderTest;
     }
diff --git a/tools/host/src/com/android/cts/SignatureCheckPackage.java b/tools/host/src/com/android/cts/SignatureCheckPackage.java
index ddc06a0..485530e 100644
--- a/tools/host/src/com/android/cts/SignatureCheckPackage.java
+++ b/tools/host/src/com/android/cts/SignatureCheckPackage.java
@@ -61,7 +61,7 @@
             final String androidVersion, final String jarPath, final String appNameSpace,
             final String appPackageName) throws NoSuchAlgorithmException {
         super(instrumentationRunner, testPkgBinaryName, targetNameSpace, targetBinaryName, version,
-                androidVersion, jarPath, appNameSpace, appPackageName);
+                androidVersion, jarPath, appNameSpace, appPackageName, null);
     }
 
     /**
diff --git a/tools/host/src/com/android/cts/TestDevice.java b/tools/host/src/com/android/cts/TestDevice.java
index 6ac56a1..a90f6f1 100644
--- a/tools/host/src/com/android/cts/TestDevice.java
+++ b/tools/host/src/com/android/cts/TestDevice.java
@@ -890,7 +890,7 @@
         }
 
         String name = testPackage.getAppPackageName();
-        if ((javaPkgName != null) && (javaPkgName.length() != 0)) {
+        if ((javaPkgName != null) && !javaPkgName.isEmpty()) {
             name = javaPkgName;
         }
 
diff --git a/tools/host/src/com/android/cts/TestPackage.java b/tools/host/src/com/android/cts/TestPackage.java
index 8647ade..a332297 100644
--- a/tools/host/src/com/android/cts/TestPackage.java
+++ b/tools/host/src/com/android/cts/TestPackage.java
@@ -49,13 +49,18 @@
     public static final String FINISH = "finish";
     public static final String START = "start";
 
-    private String mName, mVersion, mAndroidVersion;
-    private String mTargetNameSpace, mTargetBinaryName, mInstrumentationRunner;
-    private Collection<TestSuite> mSuites;
+    private final String mName;
+    private final String mVersion;
+    private final String mAndroidVersion;
+    private final String mTargetNameSpace;
+    private final String mTargetBinaryName;
+    private final String mInstrumentationRunner;
+    private final Collection<TestSuite> mSuites;
     private String mDigest;
-    private String mJarPath;
-    private String mAppNameSpace;
-    private String mAppPackageName;
+    private final String mJarPath;
+    private final String mAppNameSpace;
+    private final String mAppPackageName;
+    private final String mJavaPackageFilter;
 
     protected TestSuite mCurrentTestSuite;
 
@@ -79,13 +84,14 @@
      * @param androidVersion The version of the Anroid platform allowed.
      * @param jarPath The host controller's jar path and file.
      * @param appNameSpace The package name space.
-     * @param appPackageName The Java package name of the test package.
+     * @param appPackageName The package name of the test package.
+     * @param javaPackageFilter The prefix used to select which Java packages to run
      */
     public TestPackage(final String instrumentationRunner,
             final String testPkgBinaryName, final String targetNameSpace,
             final String targetBinaryName, final String version,
             final String androidVersion, final String jarPath, final String appNameSpace,
-            final String appPackageName) {
+            final String appPackageName, final String javaPackageFilter) {
         mInstrumentationRunner = instrumentationRunner;
         mName = testPkgBinaryName;
         mTargetNameSpace = targetNameSpace;
@@ -96,6 +102,7 @@
         mJarPath = jarPath;
         mAppNameSpace = appNameSpace;
         mAppPackageName = appPackageName;
+        mJavaPackageFilter = javaPackageFilter;
 
         mDevice = null;
         mTestStop = false;
@@ -114,9 +121,9 @@
     }
 
     /**
-     * Get the app JAVA package name.
+     * Get the app package name.
      *
-     * @return The app JAVA package name.
+     * @return The app package name.
      */
     public String getAppPackageName() {
         return mAppPackageName;
@@ -858,7 +865,7 @@
         mTimeOutTimer.start();
         mProgressObserver = new ProgressObserver();
 
-        if ((javaPkgName != null) && (javaPkgName.length() > 0)) {
+        if ((javaPkgName != null) && !javaPkgName.isEmpty()) {
             runInBatchModeImpl(javaPkgName);
         } else {
             for (String pkgName : getPackageNames()) {
@@ -995,14 +1002,15 @@
             return;
         }
 
-        setup(device, javaPkgName);
-        runImpl(javaPkgName);
+        String javaPackage = (javaPkgName != null) ? javaPkgName : mJavaPackageFilter;
+        setup(device, javaPackage);
+        runImpl(javaPackage);
     }
 
     /**
      * Implementation of running the test package.
      *
-     * @param javaPkgName The JAVA package name.
+     * @param javaPkgName The Java package name.
      * @param profile The profile of the device being tested.
      */
     protected void runImpl(final String javaPkgName) throws IOException,
@@ -1050,7 +1058,7 @@
      * Set up before running.
      *
      * @param device The device to run this package.getName
-     * @param javaPkgName The JAVA package name.
+     * @param javaPkgName The Java package name.
      */
     protected void setup(final TestDevice device, final String javaPkgName) {
         if (!TestSession.isADBServerRestartedMode() || noTestsExecuted()) {
diff --git a/tools/host/src/com/android/cts/TestSessionBuilder.java b/tools/host/src/com/android/cts/TestSessionBuilder.java
index de937a6..fd520a7 100644
--- a/tools/host/src/com/android/cts/TestSessionBuilder.java
+++ b/tools/host/src/com/android/cts/TestSessionBuilder.java
@@ -65,6 +65,7 @@
     private static final String ATTRIBUTE_FRAMEWORK_VERSION = "AndroidFramework";
     private static final String ATTRIBUTE_APK_TO_TEST_NAME = "apkToTestName";
     private static final String ATTRIBUTE_PACKAGE_TO_TEST = "packageToTest";
+    private static final String ATTRIBUTE_JAVA_PACKAGE_FILTER = "javaPackageFilter";
     private static TestSessionBuilder sInstance;
 
     private DocumentBuilder mDocBuilder;
@@ -208,22 +209,21 @@
     public TestPackage loadPackage(final Node pkgNode, ArrayList<String> excludedList)
                                 throws NoSuchAlgorithmException {
 
-        String appBinaryName, targetNameSpace, targetBinaryName, version, frameworkVersion,
-               runner, jarPath, appNameSpace, appPackageName, hostSideOnly;
         NodeList suiteList = pkgNode.getChildNodes();
 
-        appBinaryName = getStringAttributeValue(pkgNode, ATTRIBUTE_NAME);
-        targetNameSpace = getStringAttributeValue(pkgNode, ATTRIBUTE_TARGET_NAME_SPACE);
-        targetBinaryName = getStringAttributeValue(pkgNode, ATTRIBUTE_TARGET_BINARY_NAME);
-        version = getStringAttributeValue(pkgNode, ATTRIBUTE_VERSION);
-        frameworkVersion = getStringAttributeValue(pkgNode, ATTRIBUTE_FRAMEWORK_VERSION);
-        runner = getStringAttributeValue(pkgNode, ATTRIBUTE_RUNNER);
-        jarPath = getStringAttributeValue(pkgNode, ATTRIBUTE_JAR_PATH);
-        appNameSpace = getStringAttributeValue(pkgNode, ATTRIBUTE_APP_NAME_SPACE);
-        appPackageName = getStringAttributeValue(pkgNode, ATTRIBUTE_APP_PACKAGE_NAME);
-        hostSideOnly = getStringAttributeValue(pkgNode, ATTRIBUTE_HOST_SIDE_ONLY);
+        String appBinaryName = getStringAttributeValue(pkgNode, ATTRIBUTE_NAME);
+        String targetNameSpace = getStringAttributeValue(pkgNode, ATTRIBUTE_TARGET_NAME_SPACE);
+        String targetBinaryName = getStringAttributeValue(pkgNode, ATTRIBUTE_TARGET_BINARY_NAME);
+        String version = getStringAttributeValue(pkgNode, ATTRIBUTE_VERSION);
+        String frameworkVersion = getStringAttributeValue(pkgNode, ATTRIBUTE_FRAMEWORK_VERSION);
+        String runner = getStringAttributeValue(pkgNode, ATTRIBUTE_RUNNER);
+        String jarPath = getStringAttributeValue(pkgNode, ATTRIBUTE_JAR_PATH);
+        String appNameSpace = getStringAttributeValue(pkgNode, ATTRIBUTE_APP_NAME_SPACE);
+        String appPackageName = getStringAttributeValue(pkgNode, ATTRIBUTE_APP_PACKAGE_NAME);
+        String hostSideOnly = getStringAttributeValue(pkgNode, ATTRIBUTE_HOST_SIDE_ONLY);
         String signature = getStringAttributeValue(pkgNode, ATTRIBUTE_SIGNATURE_CHECK);
         String referenceAppTest = getStringAttributeValue(pkgNode, ATTRIBUTE_REFERENCE_APP_TEST);
+        String javaPackageFilter = getStringAttributeValue(pkgNode, ATTRIBUTE_JAVA_PACKAGE_FILTER);
         TestPackage pkg = null;
 
         if ("true".equals(referenceAppTest)) {
@@ -241,8 +241,8 @@
             pkg = new HostSideOnlyPackage(appBinaryName, version, frameworkVersion,
                     jarPath, appPackageName);
         } else {
-            pkg = new TestPackage(runner, appBinaryName, targetNameSpace, targetBinaryName,
-                    version, frameworkVersion, jarPath, appNameSpace, appPackageName);
+            pkg = new TestPackage(runner, appBinaryName, targetNameSpace, targetBinaryName, version,
+                    frameworkVersion, jarPath, appNameSpace, appPackageName, javaPackageFilter);
         }
 
         for (int i = 0; i < suiteList.getLength(); i++) {
diff --git a/tools/host/src/com/android/cts/TestSessionLog.java b/tools/host/src/com/android/cts/TestSessionLog.java
index bf5b3e8..7eb9ffd 100644
--- a/tools/host/src/com/android/cts/TestSessionLog.java
+++ b/tools/host/src/com/android/cts/TestSessionLog.java
@@ -489,7 +489,7 @@
         String[] processNames = rootProcesses.split(";");
         for (String processName : processNames) {
             processName = processName.trim();
-            if (processName.length() > 0) {
+            if (!processName.isEmpty()) {
                 Node process = document.createElement(TAG_PROCESS);
                 processInfo.appendChild(process);
 
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageDef.java b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageDef.java
index e89ed2f..20396f7 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageDef.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageDef.java
@@ -47,6 +47,7 @@
     private boolean mIsReferenceAppTest = false;
     private String mPackageToTest = null;
     private String mApkToTestName = null;
+    private String mTestPackageName = null;
 
     // use a LinkedHashSet for predictable iteration insertion-order, and fast lookups
     private Collection<TestIdentifier> mTests = new LinkedHashSet<TestIdentifier>();
@@ -133,6 +134,10 @@
         mPackageToTest = packageName;
     }
 
+    void setTestPackageName(String testPackageName) {
+        mTestPackageName = testPackageName;
+    }
+
     void setApkToTest(String apkName) {
         mApkToTestName = apkName;
     }
@@ -195,6 +200,7 @@
             String methodName, InstrumentationApkTest instrTest) {
         instrTest.setPackageName(mAppNameSpace);
         instrTest.setRunnerName(mRunner);
+        instrTest.setTestPackageName(mTestPackageName);
         instrTest.setClassName(className);
         instrTest.setMethodName(methodName);
         // mName means 'apk file name' for instrumentation tests
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageXmlParser.java b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageXmlParser.java
index 3d3242e..fa2423f 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageXmlParser.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageXmlParser.java
@@ -73,6 +73,7 @@
                 final String referenceApp = attributes.getValue("referenceAppTest");
                 final String apkToTest = attributes.getValue("apkToTestName");
                 final String packageToTest = attributes.getValue("packageToTest");
+                final String javaPackageFilter = attributes.getValue("javaPackageFilter");
 
                 mPackageDef = new TestPackageDef();
                 mPackageDef.setUri(entryUriValue);
@@ -86,6 +87,7 @@
                 mPackageDef.setIsReferenceApp(parseBoolean(referenceApp));
                 mPackageDef.setApkToTest(apkToTest);
                 mPackageDef.setPackageToTest(packageToTest);
+                mPackageDef.setTestPackageName(javaPackageFilter);
 
                 // reset the class name
                 mClassNameStack = new Stack<String>();
diff --git a/tools/utils/CollectAllTests.java b/tools/utils/CollectAllTests.java
index 44f257d..c6c536d 100644
--- a/tools/utils/CollectAllTests.java
+++ b/tools/utils/CollectAllTests.java
@@ -55,138 +55,128 @@
 
 public class CollectAllTests extends DescriptionGenerator {
 
-    static final String ATTRIBUTE_RUNNER = "runner";
-    static final String ATTRIBUTE_PACKAGE = "appPackageName";
-    static final String ATTRIBUTE_NS = "appNameSpace";
-    static final String ATTRIBUTE_TARGET = "targetNameSpace";
-    static final String ATTRIBUTE_TARGET_BINARY = "targetBinaryName";
-    static final String ATTRIBUTE_HOST_SIDE_ONLY = "hostSideOnly";
-    static final String ATTRIBUTE_VM_HOST_TEST = "vmHostTest";
-    static final String ATTRIBUTE_JAR_PATH = "jarPath";
+    private static final String ATTRIBUTE_RUNNER = "runner";
+    private static final String ATTRIBUTE_PACKAGE = "appPackageName";
+    private static final String ATTRIBUTE_NS = "appNameSpace";
+    private static final String ATTRIBUTE_TARGET = "targetNameSpace";
+    private static final String ATTRIBUTE_TARGET_BINARY = "targetBinaryName";
+    private static final String ATTRIBUTE_HOST_SIDE_ONLY = "hostSideOnly";
+    private static final String ATTRIBUTE_VM_HOST_TEST = "vmHostTest";
+    private static final String ATTRIBUTE_JAR_PATH = "jarPath";
+    private static final String ATTRIBUTE_JAVA_PACKAGE_FILTER = "javaPackageFilter";
 
-    static final String JAR_PATH = "LOCAL_JAR_PATH :=";
-    static final String TEST_TYPE = "LOCAL_TEST_TYPE :";
-
-    static final int HOST_SIDE_ONLY = 1;
-    static final int DEVICE_SIDE_ONLY = 2;
-    static final int VM_HOST_TEST = 3;
-
-    private static String runner;
-    private static String packageName;
-    private static String target;
-    private static String xmlName;
-    private static int testType;
-    private static String jarPath;
-
-    private static Map<String,TestClass> testCases;
-
-    private static class MyXMLGenerator extends XMLGenerator {
-
-        MyXMLGenerator(String outputPath) throws ParserConfigurationException {
-            super(outputPath);
-
-            Node testPackageElem = mDoc.getDocumentElement();
-
-            setAttribute(testPackageElem, ATTRIBUTE_NAME, xmlName);
-            setAttribute(testPackageElem, ATTRIBUTE_RUNNER, runner);
-            setAttribute(testPackageElem, ATTRIBUTE_PACKAGE, packageName);
-            setAttribute(testPackageElem, ATTRIBUTE_NS, packageName);
-
-            if (testType == HOST_SIDE_ONLY) {
-                setAttribute(testPackageElem, ATTRIBUTE_HOST_SIDE_ONLY, "true");
-                setAttribute(testPackageElem, ATTRIBUTE_JAR_PATH, jarPath);
-            }
-
-            if (testType == VM_HOST_TEST) {
-                setAttribute(testPackageElem, ATTRIBUTE_VM_HOST_TEST, "true");
-                setAttribute(testPackageElem, ATTRIBUTE_JAR_PATH, jarPath);
-            }
-
-            if (!packageName.equals(target)) {
-                setAttribute(testPackageElem, ATTRIBUTE_TARGET, target);
-                setAttribute(testPackageElem, ATTRIBUTE_TARGET_BINARY, target);
-            }
-        }
-    }
-
-    private static String OUTPUTFILE;
-    private static String MANIFESTFILE;
-    private static String JARFILE;
-    private static String LIBCORE_EXPECTATION_DIR;
-    private static String ANDROID_MAKE_FILE = "";
-
-    static XMLGenerator xmlGenerator;
-    private static ExpectationStore libcoreVogarExpectationStore;
-    private static ExpectationStore ctsVogarExpectationStore;
+    private static final String JAR_PATH = "LOCAL_JAR_PATH :=";
+    private static final String TEST_TYPE = "LOCAL_TEST_TYPE :";
 
     public static void main(String[] args) {
-        if (args.length >= 3 && args.length <= 5) {
-            OUTPUTFILE = args[0];
-            MANIFESTFILE = args[1];
-            JARFILE = args[2];
-            if (args.length >= 4) {
-                LIBCORE_EXPECTATION_DIR = args[3];
-                if (args.length >= 5) {
-                    ANDROID_MAKE_FILE = args[4];
+        if (args.length < 4 || args.length > 6) {
+            System.err.println("usage: CollectAllTests <output-file> <manifest-file> <jar-file> "
+                               + "<java-package> [expectation-dir [makefile-file]]");
+            if (args.length != 0) {
+                System.err.println("received:");
+                for (String arg : args) {
+                    System.err.println("  " + arg);
                 }
             }
-        } else {
-            System.err.println("usage: CollectAllTests <output-file> <manifest-file> <jar-file>"
-                               + "[expectation-dir [makefile-file]]");
             System.exit(1);
         }
 
-        if (ANDROID_MAKE_FILE.length() > 0) {
-            testType = getTestType(ANDROID_MAKE_FILE);
-        }
+        final String outputPathPrefix = args[0];
+        File manifestFile = new File(args[1]);
+        String jarFileName = args[2];
+        final String javaPackageFilter = args[3];
+        String libcoreExpectationDir = (args.length > 4) ? args[4] : null;
+        String androidMakeFile = (args.length > 5) ? args[5] : null;
 
-        Document manifest = null;
+        final TestType testType = TestType.getTestType(androidMakeFile);
+
+        Document manifest;
         try {
             manifest = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
-                    new FileInputStream(MANIFESTFILE));
+                  new FileInputStream(manifestFile));
         } catch (Exception e) {
-            System.err.println("cannot open manifest " + MANIFESTFILE);
+            System.err.println("cannot open manifest " + manifestFile);
             e.printStackTrace();
             System.exit(1);
+            return;
         }
 
         Element documentElement = manifest.getDocumentElement();
-
         documentElement.getAttribute("package");
+        final String runner = getElementAttribute(documentElement,
+                                                  "instrumentation",
+                                                  "android:name");
+        final String packageName = documentElement.getAttribute("package");
+        final String target = getElementAttribute(documentElement,
+                                                  "instrumentation",
+                                                  "android:targetPackage");
 
-        xmlName = new File(OUTPUTFILE).getName();
-        runner = getElementAttribute(documentElement, "instrumentation", "android:name");
-        packageName = documentElement.getAttribute("package");
-        target = getElementAttribute(documentElement, "instrumentation", "android:targetPackage");
-
+        String outputXmlFile = outputPathPrefix + ".xml";
+        final String xmlName = new File(outputPathPrefix).getName();
+        XMLGenerator xmlGenerator;
         try {
-            xmlGenerator = new MyXMLGenerator(OUTPUTFILE + ".xml");
+            xmlGenerator = new XMLGenerator(outputXmlFile) {
+                {
+                    Node testPackageElem = mDoc.getDocumentElement();
+
+                    setAttribute(testPackageElem, ATTRIBUTE_NAME, xmlName);
+                    setAttribute(testPackageElem, ATTRIBUTE_RUNNER, runner);
+                    setAttribute(testPackageElem, ATTRIBUTE_PACKAGE, packageName);
+                    setAttribute(testPackageElem, ATTRIBUTE_NS, packageName);
+                    setAttribute(testPackageElem, ATTRIBUTE_JAVA_PACKAGE_FILTER, javaPackageFilter);
+
+                    if (testType.type == TestType.HOST_SIDE_ONLY) {
+                        setAttribute(testPackageElem, ATTRIBUTE_HOST_SIDE_ONLY, "true");
+                        setAttribute(testPackageElem, ATTRIBUTE_JAR_PATH, testType.jarPath);
+                    }
+
+                    if (testType.type == TestType.VM_HOST_TEST) {
+                        setAttribute(testPackageElem, ATTRIBUTE_VM_HOST_TEST, "true");
+                        setAttribute(testPackageElem, ATTRIBUTE_JAR_PATH, testType.jarPath);
+                    }
+
+                    if (!packageName.equals(target)) {
+                        setAttribute(testPackageElem, ATTRIBUTE_TARGET, target);
+                        setAttribute(testPackageElem, ATTRIBUTE_TARGET_BINARY, target);
+                    }
+                }
+            };
         } catch (ParserConfigurationException e) {
-            System.err.println("Can't initialize XML Generator " + OUTPUTFILE + ".xml");
+            System.err.println("Can't initialize XML Generator " + outputXmlFile);
             System.exit(1);
+            return;
         }
 
+        ExpectationStore libcoreVogarExpectationStore;
+        ExpectationStore ctsVogarExpectationStore;
+
         try {
             libcoreVogarExpectationStore
-                    = VogarUtils.provideExpectationStore(LIBCORE_EXPECTATION_DIR);
+                    = VogarUtils.provideExpectationStore(libcoreExpectationDir);
             ctsVogarExpectationStore = VogarUtils.provideExpectationStore(CTS_EXPECTATION_DIR);
         } catch (IOException e) {
             System.err.println("Can't initialize vogar expectation store from "
-                               + LIBCORE_EXPECTATION_DIR);
+                               + libcoreExpectationDir);
             e.printStackTrace(System.err);
             System.exit(1);
+            return;
         }
+        ExpectationStore[] expectations = new ExpectationStore[] {
+            libcoreVogarExpectationStore, ctsVogarExpectationStore
+        };
 
         JarFile jarFile = null;
         try {
-            jarFile = new JarFile(JARFILE);
+            jarFile = new JarFile(jarFileName);
         } catch (Exception e) {
-            System.err.println("cannot open jarfile " + JARFILE);
+            System.err.println("cannot open jarfile " + jarFileName);
             e.printStackTrace();
             System.exit(1);
         }
 
-        testCases = new LinkedHashMap<String, TestClass>();
+        Map<String,TestClass> testCases = new LinkedHashMap<String, TestClass>();
+
+        String javaPackagePrefix = javaPackageFilter.isEmpty() ? "" : (javaPackageFilter + ".");
 
         Enumeration<JarEntry> jarEntries = jarFile.entries();
         while (jarEntries.hasMoreElements()) {
@@ -197,6 +187,9 @@
             }
             String className
                     = name.substring(0, name.length() - ".class".length()).replace('/', '.');
+            if (!className.startsWith(javaPackagePrefix)) {
+                continue;
+            }
             try {
                 Class<?> klass = Class.forName(className,
                                                false,
@@ -212,13 +205,13 @@
                 }
                 try {
                     klass.getConstructor(new Class<?>[] { String.class } );
-                    addToTests(klass.asSubclass(TestCase.class));
+                    addToTests(expectations, testCases, klass.asSubclass(TestCase.class));
                     continue;
                 } catch (NoSuchMethodException e) {
                 }
                 try {
                     klass.getConstructor(new Class<?>[0]);
-                    addToTests(klass.asSubclass(TestCase.class));
+                    addToTests(expectations, testCases, klass.asSubclass(TestCase.class));
                     continue;
                 } catch (NoSuchMethodException e) {
                 }
@@ -237,35 +230,51 @@
         try {
             xmlGenerator.dump();
         } catch (Exception e) {
-            System.err.println("cannot dump xml to " + OUTPUTFILE + ".xml");
+            System.err.println("cannot dump xml to " + outputXmlFile);
             e.printStackTrace();
             System.exit(1);
         }
     }
 
-    private static int getTestType(String makeFileName) {
+    private static class TestType {
+        private static final int HOST_SIDE_ONLY = 1;
+        private static final int DEVICE_SIDE_ONLY = 2;
+        private static final int VM_HOST_TEST = 3;
 
-        int type = DEVICE_SIDE_ONLY;
-        try {
-            BufferedReader reader = new BufferedReader(new FileReader(makeFileName));
-            String line;
+        private final int type;
+        private final String jarPath;
 
-            while ((line =reader.readLine())!=null) {
-                if (line.startsWith(TEST_TYPE)) {
-                    if (line.indexOf(ATTRIBUTE_VM_HOST_TEST) >= 0) {
-                        type = VM_HOST_TEST;
-                    } else {
-                        type = HOST_SIDE_ONLY;
-                    }
-                } else if (line.startsWith(JAR_PATH)) {
-                    jarPath = line.substring(JAR_PATH.length(), line.length()).trim();
-                }
-            }
-            reader.close();
-        } catch (IOException e) {
+        private TestType (int type, String jarPath) {
+            this.type = type;
+            this.jarPath = jarPath;
         }
 
-        return type;
+        private static TestType getTestType(String makeFileName) {
+            if (makeFileName == null || makeFileName.isEmpty()) {
+                return new TestType(DEVICE_SIDE_ONLY, null);
+            }
+            int type = TestType.DEVICE_SIDE_ONLY;
+            String jarPath = null;
+            try {
+                BufferedReader reader = new BufferedReader(new FileReader(makeFileName));
+                String line;
+
+                while ((line =reader.readLine())!=null) {
+                    if (line.startsWith(TEST_TYPE)) {
+                        if (line.indexOf(ATTRIBUTE_VM_HOST_TEST) >= 0) {
+                            type = VM_HOST_TEST;
+                        } else {
+                            type = HOST_SIDE_ONLY;
+                        }
+                    } else if (line.startsWith(JAR_PATH)) {
+                        jarPath = line.substring(JAR_PATH.length(), line.length()).trim();
+                    }
+                }
+                reader.close();
+            } catch (IOException e) {
+            }
+            return new TestType(type, jarPath);
+        }
     }
 
     private static Element getElement(Element element, String tagName) {
@@ -339,13 +348,15 @@
 
             }
 
-        } catch (java.lang.NoSuchMethodException e) {
+        } catch (NoSuchMethodException e) {
         }
 
         return null;
     }
 
-    private static void addToTests(Class<? extends TestCase> test) {
+    private static void addToTests(ExpectationStore[] expectations,
+                                   Map<String,TestClass> testCases,
+                                   Class<? extends TestCase> test) {
         Class testClass = test;
         Set<String> testNames = new HashSet<String>();
         while (TestCase.class.isAssignableFrom(testClass)) {
@@ -368,13 +379,16 @@
                     continue;
                 }
                 testNames.add(testName);
-                addToTests(test, testName);
+                addToTests(expectations, testCases, test, testName);
             }
             testClass = testClass.getSuperclass();
         }
     }
 
-    private static void addToTests(Class<? extends TestCase> test, String testName) {
+    private static void addToTests(ExpectationStore[] expectations,
+                                   Map<String,TestClass> testCases,
+                                   Class<? extends TestCase> test,
+                                   String testName) {
 
         String testClassName = test.getName();
         String knownFailure = getKnownFailure(test, testName);
@@ -391,16 +405,10 @@
         } else if (hasSideEffects(test, testName)) {
             System.out.println("ignoring test with side effects: " + test + "#" + testName);
             return;
-        } else if (VogarUtils.isVogarKnownFailure(libcoreVogarExpectationStore,
+        } else if (VogarUtils.isVogarKnownFailure(expectations,
                                                   testClassName,
                                                   testName)) {
-            System.out.println("ignoring libcore expectation known failure: " + test
-                               + "#" + testName);
-            return;
-        } else if (VogarUtils.isVogarKnownFailure(ctsVogarExpectationStore,
-                                                  testClassName,
-                                                  testName)) {
-            System.out.println("ignoring cts expectation known failure: " + test
+            System.out.println("ignoring expectation known failure: " + test
                                + "#" + testName);
             return;
         }
diff --git a/tools/utils/VogarUtils.java b/tools/utils/VogarUtils.java
index 06b48c6..c7070a5 100644
--- a/tools/utils/VogarUtils.java
+++ b/tools/utils/VogarUtils.java
@@ -27,6 +27,17 @@
 
 public class VogarUtils {
 
+    public static boolean isVogarKnownFailure(ExpectationStore[] expectationStores,
+            final String testClassName,
+            final String testMethodName) {
+        for (ExpectationStore expectationStore : expectationStores) {
+            if (isVogarKnownFailure(expectationStore, testClassName, testMethodName)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     public static boolean isVogarKnownFailure(ExpectationStore expectationStore,
             final String testClassName,
             final String testMethodName) {