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.ORG_APACHE_HTTP_LEGACY;
19 
20 import android.content.pm.PackageParser.Package;
21 
22 import com.android.internal.annotations.VisibleForTesting;
23 
24 /**
25  * Updates a package to ensure that if it targets < P that the org.apache.http.legacy library is
26  * included by default.
27  *
28  * <p>This is separated out so that it can be conditionally included at build time depending on
29  * whether org.apache.http.legacy is on the bootclasspath or not. In order to include this at
30  * build time, and remove org.apache.http.legacy from the bootclasspath pass
31  * REMOVE_OAHL_FROM_BCP=true on the build command line, otherwise this class will not be included
32  * and the
33  *
34  * @hide
35  */
36 @VisibleForTesting
37 public class OrgApacheHttpLegacyUpdater extends PackageSharedLibraryUpdater {
38 
39     @Override
updatePackage(Package pkg)40     public void updatePackage(Package pkg) {
41         // Packages targeted at <= O_MR1 expect the classes in the org.apache.http.legacy library
42         // to be accessible so this maintains backward compatibility by adding the
43         // org.apache.http.legacy library to those packages.
44         if (apkTargetsApiLevelLessThanOrEqualToOMR1(pkg)) {
45             prefixRequiredLibrary(pkg, ORG_APACHE_HTTP_LEGACY);
46         }
47     }
48 }
49