Test setting multiple standby buckets at once

Test: atest CtsAppUsageHostTestCases
Bug: 63527785
Change-Id: Ica951c44f2b68d19c3e290d6e4e4aec9def954bc
diff --git a/hostsidetests/usage/AndroidTest.xml b/hostsidetests/usage/AndroidTest.xml
index 6dd8e6f..9649168 100644
--- a/hostsidetests/usage/AndroidTest.xml
+++ b/hostsidetests/usage/AndroidTest.xml
@@ -18,9 +18,10 @@
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
         <option name="test-file-name" value="CtsAppUsageTestApp.apk" />
+        <option name="test-file-name" value="CtsAppUsageTestAppToo.apk" />
     </target_preparer>
     <test class="com.android.compatibility.common.tradefed.testtype.JarHostTest" >
         <option name="jar" value="CtsAppUsageHostTestCases.jar" />
-        <option name="runtime-hint" value="8m" />
+        <option name="runtime-hint" value="2m" />
     </test>
 </configuration>
diff --git a/hostsidetests/usage/app/Android.mk b/hostsidetests/usage/app/Android.mk
index 59626d6..3d51230 100644
--- a/hostsidetests/usage/app/Android.mk
+++ b/hostsidetests/usage/app/Android.mk
@@ -29,3 +29,23 @@
 LOCAL_COMPATIBILITY_SUITE := cts vts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
+
+# Build a second one similar to the first
+
+include $(CLEAR_VARS)
+
+# Don't include this package in any target.
+LOCAL_MODULE_TAGS := tests
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_SDK_VERSION := current
+
+LOCAL_PACKAGE_NAME := CtsAppUsageTestAppToo
+
+# tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts vts general-tests
+
+LOCAL_AAPT_FLAGS += --rename-manifest-package android.app.usage.apptoo
+
+include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/usage/app/AndroidManifest.xml b/hostsidetests/usage/app/AndroidManifest.xml
index 7d5ce48..303c26f 100755
--- a/hostsidetests/usage/app/AndroidManifest.xml
+++ b/hostsidetests/usage/app/AndroidManifest.xml
@@ -19,7 +19,7 @@
     package="android.app.usage.app">
 
     <application>
-        <activity android:name=".TestActivity">
+        <activity android:name="android.app.usage.app.TestActivity">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.DEFAULT" />
diff --git a/hostsidetests/usage/src/android/app/usage/cts/AppIdleHostTest.java b/hostsidetests/usage/src/android/app/usage/cts/AppIdleHostTest.java
index 7f4f550..1243cdd 100644
--- a/hostsidetests/usage/src/android/app/usage/cts/AppIdleHostTest.java
+++ b/hostsidetests/usage/src/android/app/usage/cts/AppIdleHostTest.java
@@ -31,6 +31,7 @@
 
     private static final String TEST_APP_PACKAGE = "android.app.usage.app";
     private static final String TEST_APP_CLASS = "TestActivity";
+    private static final String TEST_APP_PACKAGE2 = "android.app.usage.apptoo";
 
     private static final long ACTIVITY_LAUNCH_WAIT_MILLIS = 500;
 
@@ -124,7 +125,6 @@
     private int getAppStandbyBucket(String packageName) throws Exception {
         String bucketString = mDevice.executeShellCommand(
                 String.format("am get-standby-bucket %s", packageName));
-        System.err.println(bucketString);
         try {
             return Integer.parseInt(bucketString.trim());
         } catch (NumberFormatException nfe) {
@@ -141,6 +141,15 @@
         assertEquals(20, getAppStandbyBucket(TEST_APP_PACKAGE));
     }
 
+    public void testSetAppStandbyBuckets() throws Exception {
+        // Set multiple packages states
+        String command = String.format("am set-standby-bucket %s %d %s %d",
+                TEST_APP_PACKAGE, SB_FREQUENT, TEST_APP_PACKAGE2, SB_WORKING_SET);
+        mDevice.executeShellCommand(command);
+        assertEquals(SB_FREQUENT, getAppStandbyBucket(TEST_APP_PACKAGE));
+        assertEquals(SB_WORKING_SET, getAppStandbyBucket(TEST_APP_PACKAGE2));
+    }
+
     public void testCantSetOwnStandbyBucket() throws Exception {
         setAppStandbyBucket("com.android.shell", 40);
         assertNotEquals(40, getAppStandbyBucket("com.android.shell"));