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.apitest; 17 18 import static com.android.compatibility.common.util.ShellUtils.runShellCommand; 19 20 import static org.junit.Assert.fail; 21 22 import android.platform.test.annotations.Presubmit; 23 import android.text.TextUtils; 24 25 import org.junit.Test; 26 27 @Presubmit 28 public final class PreInstalledPackagesTest { 29 30 @Test testNoCriticalErrors_currentMode()31 public void testNoCriticalErrors_currentMode() { 32 assertNoCriticalErrors(/* enforceMode= */ false); 33 } 34 35 @Test testNoCriticalErrors_enforceMode()36 public void testNoCriticalErrors_enforceMode() { 37 assertNoCriticalErrors(/* enforceMode= */ true); 38 } 39 assertNoCriticalErrors(boolean enforceMode)40 private static void assertNoCriticalErrors(boolean enforceMode) { 41 String cmd = "cmd user report-system-user-package-whitelist-problems --critical-only%s"; 42 String mode = enforceMode ? " --mode 1" : ""; 43 String result = runShellCommand(cmd, mode); 44 if (!TextUtils.isEmpty(result)) { 45 fail("Command '" + String.format(cmd, mode) + "' reported errors:\n" + result); 46 } 47 } 48 } 49