Merge Android 12L

Bug: 222710654
Merged-In: Iea747b72b05f0826d809fa5347e05168dd30aadc
Change-Id: I491a0eb7883823c8ecd4e1ec5e63517ed7fa009d
diff --git a/tools/catbox-common/Android.bp b/tools/catbox-common/Android.bp
new file mode 100644
index 0000000..8ab766e
--- /dev/null
+++ b/tools/catbox-common/Android.bp
@@ -0,0 +1,22 @@
+// Copyright (C) 2021 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 {
+    default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+java_library_host {
+    name: "catbox-common",
+    java_resource_dirs: ["res"],
+}
diff --git a/tools/catbox-tradefed/res/config/basic-reporters.xml b/tools/catbox-common/res/config/basic-reporters.xml
similarity index 100%
rename from tools/catbox-tradefed/res/config/basic-reporters.xml
rename to tools/catbox-common/res/config/basic-reporters.xml
diff --git a/tools/catbox-tradefed/res/config/catbox-common.xml b/tools/catbox-common/res/config/catbox-common.xml
similarity index 100%
rename from tools/catbox-tradefed/res/config/catbox-common.xml
rename to tools/catbox-common/res/config/catbox-common.xml
diff --git a/tools/catbox-tradefed/res/config/catbox-performance-app-start-up-base.xml b/tools/catbox-common/res/config/catbox-performance-app-start-up-base.xml
similarity index 100%
rename from tools/catbox-tradefed/res/config/catbox-performance-app-start-up-base.xml
rename to tools/catbox-common/res/config/catbox-performance-app-start-up-base.xml
diff --git a/tools/catbox-tradefed/res/config/catbox-performance-base.xml b/tools/catbox-common/res/config/catbox-performance-base.xml
similarity index 100%
rename from tools/catbox-tradefed/res/config/catbox-performance-base.xml
rename to tools/catbox-common/res/config/catbox-performance-base.xml
diff --git a/tools/catbox-tradefed/res/config/catbox-performance-jank-base.xml b/tools/catbox-common/res/config/catbox-performance-jank-base.xml
similarity index 100%
rename from tools/catbox-tradefed/res/config/catbox-performance-jank-base.xml
rename to tools/catbox-common/res/config/catbox-performance-jank-base.xml
diff --git a/tools/catbox-tradefed/res/config/catbox-performance-multiuser-base.xml b/tools/catbox-common/res/config/catbox-performance-multiuser-base.xml
similarity index 100%
rename from tools/catbox-tradefed/res/config/catbox-performance-multiuser-base.xml
rename to tools/catbox-common/res/config/catbox-performance-multiuser-base.xml
diff --git a/tools/catbox-tradefed/res/config/catbox-performance-postprocessors.xml b/tools/catbox-common/res/config/catbox-performance-postprocessors.xml
similarity index 68%
rename from tools/catbox-tradefed/res/config/catbox-performance-postprocessors.xml
rename to tools/catbox-common/res/config/catbox-performance-postprocessors.xml
index 7b1773e..edbaddf 100644
--- a/tools/catbox-tradefed/res/config/catbox-performance-postprocessors.xml
+++ b/tools/catbox-common/res/config/catbox-performance-postprocessors.xml
@@ -14,5 +14,10 @@
      limitations under the License.
 -->
 <configuration description="Post Processors to Aggregate Performance Metrics.">
-  <!-- No Post Processor -->
+  <metric_post_processor class="com.android.tradefed.postprocessor.MetricFilePostProcessor">
+    <option name="disable" value="false" />
+    <option name="aggregate-similar-tests" value="true" />
+    <option name="test-iteration-separator" value="$" />
+    <option name="enable-per-test-log" value="false" />
+  </metric_post_processor>
 </configuration>
diff --git a/tools/catbox-tradefed/res/config/catbox-preparer.xml b/tools/catbox-common/res/config/catbox-preparer.xml
similarity index 90%
rename from tools/catbox-tradefed/res/config/catbox-preparer.xml
rename to tools/catbox-common/res/config/catbox-preparer.xml
index 58ad6bf..62c7c23 100644
--- a/tools/catbox-tradefed/res/config/catbox-preparer.xml
+++ b/tools/catbox-common/res/config/catbox-preparer.xml
@@ -14,6 +14,11 @@
      limitations under the License.
 -->
 <configuration description="CATBOX Target Preparer Configuration">
+  <!-- Target Preparers - Add System User and Disable By Default -->
+  <target_preparer class="com.android.tradefed.targetprep.RunOnSystemUserTargetPreparer">
+    <option name="disable" value="true" />
+  </target_preparer>
+
   <!-- Target Preparers - Disable SELinux before Test Execution -->
   <target_preparer class="com.android.tradefed.targetprep.DisableSELinuxTargetPreparer" />
 
@@ -47,4 +52,4 @@
 
   <!-- Template for Account Log In -->
   <template-include name="account-preparer" default="empty" />
-</configuration>
\ No newline at end of file
+</configuration>
diff --git a/tools/catbox-tradefed/res/config/catbox.xml b/tools/catbox-common/res/config/catbox.xml
similarity index 100%
rename from tools/catbox-tradefed/res/config/catbox.xml
rename to tools/catbox-common/res/config/catbox.xml
diff --git a/tools/catbox-tradefed/Android.bp b/tools/catbox-tradefed/Android.bp
index 5d44324..3fc7e80 100644
--- a/tools/catbox-tradefed/Android.bp
+++ b/tools/catbox-tradefed/Android.bp
@@ -23,6 +23,6 @@
     short_name: "CATBOX",
     full_name: "Complete Automotive Test in a Box",
     version: "1.0",
-    static_libs: ["cts-tradefed-harness"],
+    static_libs: ["cts-tradefed-harness", "catbox-common"],
     required: ["compatibility-host-util", "catbox-report-lib"],
 }
diff --git a/tools/catbox-tradefed/res/config/catbox-functional-mediacenter.xml b/tools/catbox-tradefed/res/config/catbox-functional-mediacenter.xml
new file mode 100644
index 0000000..67ad31b
--- /dev/null
+++ b/tools/catbox-tradefed/res/config/catbox-functional-mediacenter.xml
@@ -0,0 +1,38 @@
+<!--
+ Copyright (C) 2021 Google Inc.
+
+     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.
+-->
+<configuration description="Complete Automotive Tests - MediaCenter Functional Tests.">
+  <!-- Common Base -->
+  <include name="catbox-common"/>
+
+  <!-- Device Preparers -->
+  <include name="catbox-preparer"/>
+
+  <!-- Plan -->
+  <option name="plan" value="catbox-functional-mediacenter"/>
+
+  <!-- Test Args -->
+  <option name="compatibility:test-arg" value="com.android.tradefed.testtype.AndroidJUnitTest:runner:androidx.test.runner.AndroidJUnitRunner" />
+  <option name="compatibility:test-arg" value="com.android.tradefed.testtype.AndroidJUnitTest:package:android.platform.tests" />
+  <option name="compatibility:test-arg" value="com.android.tradefed.testtype.AndroidJUnitTest:no-rerun:true" />
+  <option name="compatibility:test-arg" value="com.android.tradefed.testtype.AndroidJUnitTest:shell-timeout:500000" />
+  <option name="compatibility:test-arg" value="com.android.tradefed.testtype.AndroidJUnitTest:test-timeout:500000" />
+
+  <!-- Tests -->
+  <option name="compatibility:include-filter" value="AndroidAutomotiveMediaCenterTests android.platform.tests.OpenAppFromMediaCenterTest" />
+  <option name="compatibility:include-filter" value="AndroidAutomotiveMediaCenterTests android.platform.tests.MediaTestAppTest" />
+  <option name="compatibility:include-filter" value="AndroidAutomotiveMediaCenterTests android.platform.tests.NoUserLoggedInTest" />
+
+</configuration>
diff --git a/tools/catbox-tradefed/res/config/catbox-functional-multiuser-system-user.xml b/tools/catbox-tradefed/res/config/catbox-functional-multiuser-system-user.xml
new file mode 100644
index 0000000..3eb46e3
--- /dev/null
+++ b/tools/catbox-tradefed/res/config/catbox-functional-multiuser-system-user.xml
@@ -0,0 +1,38 @@
+<!--
+     Copyright (C) 2021 Google Inc.
+
+     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.
+-->
+<configuration description="Complete Automotive Tests - Multiuser Functional Tests.">
+  <!-- Common Base -->
+  <include name="catbox-common"/>
+
+  <!-- Device Preparers -->
+  <include name="catbox-preparer"/>
+
+  <!-- Enable system user target preparer to run as user 0 -->
+  <option name="run-on-system-user:disable" value="false" />
+
+  <!-- Plan -->
+  <option name="plan" value="catbox-functional-multiuser-system-user"/>
+
+  <!-- Test Args -->
+  <option name="compatibility:test-arg" value="com.android.tradefed.testtype.AndroidJUnitTest:runner:androidx.test.runner.AndroidJUnitRunner" />
+  <option name="compatibility:test-arg" value="com.android.tradefed.testtype.AndroidJUnitTest:package:android.platform.tests" />
+  <option name="compatibility:test-arg" value="com.android.tradefed.testtype.AndroidJUnitTest:no-rerun:true" />
+
+  <!-- Tests -->
+  <option name="compatibility:include-filter" value="AndroidAutomotiveMultiuserTests android.platform.tests.DeleteCurrentNonAdminUser" />
+  <option name="compatibility:include-filter" value="AndroidAutomotiveMultiuserTests android.platform.tests.SwitchToGuestFromNonAdmin" />
+  <option name="compatibility:include-filter" value="AndroidAutomotiveMultiuserTests android.platform.tests.DeleteLastAdminUser" />
+</configuration>
diff --git a/tools/catbox-tradefed/res/config/catbox-functional-multiuser.xml b/tools/catbox-tradefed/res/config/catbox-functional-multiuser.xml
new file mode 100644
index 0000000..921e626
--- /dev/null
+++ b/tools/catbox-tradefed/res/config/catbox-functional-multiuser.xml
@@ -0,0 +1,44 @@
+<!--
+     Copyright (C) 2021 Google Inc.
+
+     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.
+-->
+<configuration description="Complete Automotive Tests - Multiuser Functional Tests.">
+  <!-- Common Base -->
+  <include name="catbox-common"/>
+
+  <!-- Device Preparers -->
+  <include name="catbox-preparer"/>
+
+  <!-- Plan -->
+  <option name="plan" value="catbox-functional-multiuser"/>
+
+  <!-- adb shell command specific to multiuser tests -->
+  <option name="run-command:run-command" value="setprop fw.stop_bg_users_on_switch 0" />
+
+  <!-- Test Args -->
+  <option name="compatibility:test-arg" value="com.android.tradefed.testtype.AndroidJUnitTest:runner:androidx.test.runner.AndroidJUnitRunner" />
+  <option name="compatibility:test-arg" value="com.android.tradefed.testtype.AndroidJUnitTest:package:android.platform.tests" />
+  <option name="compatibility:test-arg" value="com.android.tradefed.testtype.AndroidJUnitTest:no-rerun:true" />
+  <option name="compatibility:test-arg" value="com.android.tradefed.testtype.AndroidJUnitTest:shell-timeout:500000" />
+  <option name="compatibility:test-arg" value="com.android.tradefed.testtype.AndroidJUnitTest:test-timeout:500000" />
+
+  <!-- Tests -->
+  <option name="compatibility:include-filter" value="AndroidAutomotiveMultiuserTests android.platform.tests.AddUserQuickSettings" />
+  <option name="compatibility:include-filter" value="AndroidAutomotiveMultiuserTests android.platform.tests.AddUserSettings" />
+  <option name="compatibility:include-filter" value="AndroidAutomotiveMultiuserTests android.platform.tests.DeleteAdminUser" />
+  <option name="compatibility:include-filter" value="AndroidAutomotiveMultiuserTests android.platform.tests.DeleteGuestNotAllowed" />
+  <option name="compatibility:include-filter" value="AndroidAutomotiveMultiuserTests android.platform.tests.DeleteNonAdminUser" />
+  <option name="compatibility:include-filter" value="AndroidAutomotiveMultiuserTests android.platform.tests.SwitchUserQuickSettings" />
+  <option name="compatibility:include-filter" value="AndroidAutomotiveMultiuserTests android.platform.tests.DeleteGuestSelfNotAllowed" />
+</configuration>