1 /* 2 * Copyright (C) 2018 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.content.pm; 17 18 import static android.content.pm.SharedLibraryNames.ANDROID_TEST_BASE; 19 import static android.content.pm.SharedLibraryNames.ANDROID_TEST_RUNNER; 20 21 import android.content.pm.PackageParser.Package; 22 23 import com.android.internal.annotations.VisibleForTesting; 24 25 /** 26 * Updates a package to ensure that if it targets < P that the android.test.base library is 27 * included by default. 28 * 29 * <p>This is separated out so that it can be conditionally included at build time depending on 30 * whether android.test.base is on the bootclasspath or not. In order to include this at 31 * build time, and remove android.test.base from the bootclasspath pass 32 * REMOVE_ATB_FROM_BCP=true on the build command line, otherwise this class will not be included 33 * and the 34 * 35 * @hide 36 */ 37 @VisibleForTesting 38 public class AndroidTestBaseUpdater extends PackageSharedLibraryUpdater { 39 40 @Override updatePackage(Package pkg)41 public void updatePackage(Package pkg) { 42 // Packages targeted at <= O_MR1 expect the classes in the android.test.base library 43 // to be accessible so this maintains backward compatibility by adding the 44 // android.test.base library to those packages. 45 if (apkTargetsApiLevelLessThanOrEqualToOMR1(pkg)) { 46 prefixRequiredLibrary(pkg, ANDROID_TEST_BASE); 47 } else { 48 // If a package already depends on android.test.runner then add a dependency on 49 // android.test.base because android.test.runner depends on classes from the 50 // android.test.base library. 51 prefixImplicitDependency(pkg, ANDROID_TEST_RUNNER, ANDROID_TEST_BASE); 52 } 53 } 54 } 55