Merge "Added post-submit test to check pre-installed packages configuration." into rvc-dev
diff --git a/TEST_MAPPING b/TEST_MAPPING
new file mode 100644
index 0000000..6239f78
--- /dev/null
+++ b/TEST_MAPPING
@@ -0,0 +1,12 @@
+{
+  "auto-postsubmit": [
+    {
+      "name": "AndroidCarApiTest",
+      "options": [
+        {
+          "include-filter": "android.car.apitest.PreInstalledPackagesTest"
+        }
+      ]
+    }
+  ]
+}
\ No newline at end of file
diff --git a/tests/android_car_api_test/src/android/car/apitest/PreInstalledPackagesTest.java b/tests/android_car_api_test/src/android/car/apitest/PreInstalledPackagesTest.java
new file mode 100644
index 0000000..f072fff
--- /dev/null
+++ b/tests/android_car_api_test/src/android/car/apitest/PreInstalledPackagesTest.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2020 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.car.apitest;
+
+import static com.android.compatibility.common.util.ShellUtils.runShellCommand;
+
+import static org.junit.Assert.fail;
+
+import android.text.TextUtils;
+
+import androidx.test.filters.FlakyTest;
+
+import org.junit.Test;
+
+public final class PreInstalledPackagesTest {
+
+    @FlakyTest // TODO(b/154112291): remove once it's passing on acloud
+    @Test
+    public void testNoCriticalErrors_currentMode() {
+        assertNoCriticalErrors(/* enforceMode= */ false);
+    }
+
+    @FlakyTest // TODO(b/154112291): remove once it's passing on acloud
+    @Test
+    public void testNoCriticalErrors_enforceMode() {
+        assertNoCriticalErrors(/* enforceMode= */ true);
+    }
+
+    private static void assertNoCriticalErrors(boolean enforceMode) {
+        String cmd = "cmd user report-system-user-package-whitelist-problems --critical-only%s";
+        String mode =  enforceMode ? " --mode 1" : "";
+        String result = runShellCommand(cmd, mode);
+        if (!TextUtils.isEmpty(result)) {
+            fail("Command '" + cmd + " reported errors:\n" + result);
+        }
+    }
+}