1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package android.car.extendedapitest; 17 18 import static com.android.compatibility.common.util.ShellUtils.runShellCommand; 19 20 import static org.junit.Assert.fail; 21 22 import android.car.extendedapitest.testbase.CarLessApiTestBase; 23 import android.platform.test.annotations.Presubmit; 24 import android.text.TextUtils; 25 26 import androidx.test.filters.FlakyTest; 27 28 import com.android.compatibility.common.util.NonApiTest; 29 30 import org.junit.Test; 31 32 @Presubmit 33 public final class PreInstalledPackagesTest extends CarLessApiTestBase { 34 35 36 @Test 37 @NonApiTest(exemptionReasons = {}, justification = "Testing package allowlist, which is not " 38 + "an API or CDD requirement") testNoCriticalErrors_currentMode()39 public void testNoCriticalErrors_currentMode() { 40 assertNoCriticalErrors(/* enforceMode= */ false); 41 } 42 43 @FlakyTest(bugId = 330923013) 44 @Test 45 @NonApiTest(exemptionReasons = {}, justification = "Testing package allowlist, which is not " 46 + "an API or CDD requirement") testNoCriticalErrors_enforceMode()47 public void testNoCriticalErrors_enforceMode() { 48 assertNoCriticalErrors(/* enforceMode= */ true); 49 } 50 assertNoCriticalErrors(boolean enforceMode)51 private static void assertNoCriticalErrors(boolean enforceMode) { 52 String cmd = "cmd user report-system-user-package-whitelist-problems --critical-only%s"; 53 String mode = enforceMode ? " --mode 1" : ""; 54 String result = runShellCommand(cmd, mode); 55 if (!TextUtils.isEmpty(result)) { 56 fail("Command '" + String.format(cmd, mode) + "' reported errors:\n" + result 57 + "\nPlease check go/aaos-packages-allowlisting to fix the test!"); 58 } 59 } 60 } 61