am a0ec0db: AI 147957: CTS: Add configuration variable to set max size f

Merge commit 'a0ec0db9ab29f1bee1abb2e4ed7e058cc65fb051' into donut

* commit 'a0ec0db9ab29f1bee1abb2e4ed7e058cc65fb051':
  AI 147957: CTS: Add configuration variable to set max size for a package to be run in batch mode
diff --git a/tools/host/src/com/android/cts/HostConfig.java b/tools/host/src/com/android/cts/HostConfig.java
index 8826f31..4db1fe9 100644
--- a/tools/host/src/com/android/cts/HostConfig.java
+++ b/tools/host/src/com/android/cts/HostConfig.java
@@ -71,6 +71,8 @@
     enum Ints {
         // Number of tests executed between reboots. A value <= 0 disables reboots.
         maxTestCount (200),
+        // Max size [tests] for a package to be run in batch mode
+        maxTestsInBatchMode (Integer.MAX_VALUE),
         // Max time [ms] between test status updates for both individual and batch mode.
         testStatusTimeoutMs (5 * 60 * 1000),
         // Max time [ms] from start of package in batch mode and the first test status update.
diff --git a/tools/host/src/com/android/cts/TestPackage.java b/tools/host/src/com/android/cts/TestPackage.java
index 33a4f45..db02681 100644
--- a/tools/host/src/com/android/cts/TestPackage.java
+++ b/tools/host/src/com/android/cts/TestPackage.java
@@ -67,7 +67,6 @@
 
     protected boolean mTestStop;
     private TestSessionThread mTestThread;
-    private boolean mEnableBatchMode = true;
 
     private HostTimer mTimeOutTimer;
     private ProgressObserver mProgressObserver;
@@ -763,8 +762,15 @@
      * @return If each test under this package doesn't depend on any host controller, return true;
      *         else, return false;
      */
-    private boolean isInBatchMode() {
-        for (Test test : getTests()) {
+    private boolean supportsBatchMode() {
+        Collection<Test> tests = getTests();
+        
+        // check whether the package is small enough for batch mode
+        if (tests.size() > HostConfig.Ints.maxTestsInBatchMode.value()) {
+            return false;
+        }
+        
+        for (Test test : tests) {
             if (!test.getResult().isNotExecuted()) {
                 // if any test has been run, use individual mode
                 return false;
@@ -971,7 +977,7 @@
                 setMessageDigest(genMessageDigest(HostConfig.getInstance()
                         .getCaseRepository().getApkPath(getAppBinaryName())));
 
-                if ((mEnableBatchMode) && isInBatchMode()) {
+                if (supportsBatchMode()) {
                     mIsInBatchMode = true;
                     Log.d("run in batch mode...");
                     runInBatchMode(javaPkgName);
diff --git a/tools/utils/host_config.xml b/tools/utils/host_config.xml
index 784c93f..ce618f7 100644
--- a/tools/utils/host_config.xml
+++ b/tools/utils/host_config.xml
@@ -26,6 +26,8 @@
 
     <!-- Number of tests executed between reboots. A value <= 0 disables reboots. -->
     <IntValue name="maxTestCount" value="200" />
+    <!-- Max size [tests] for a package to be run in batch mode. -->
+    <IntValue name="maxTestsInBatchMode" value="2147483647" />
 
     <!-- Max time [ms] between test status updates. -->
     <IntValue name="testStatusTimeoutMs" value="300000" />
@@ -33,8 +35,8 @@
     <IntValue name="batchStartTimeoutMs" value="1800000" />
     <!-- Max time [ms] from start of test in individual mode to the first test status update. -->
     <IntValue name="individualStartTimeoutMs" value="300000" />
-    <!-- Timeout [ms] for the signature check -->
+    <!-- Timeout [ms] for the signature check. -->
     <IntValue name="signatureTestTimeoutMs" value="600000" />
-    <!-- Timeout [ms] for package installations -->
+    <!-- Timeout [ms] for package installations. -->
     <IntValue name="packageInstallTimeoutMs" value="120000" />
 </HostConfiguration>