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 import android.os.Build;
22 
23 import com.android.internal.annotations.VisibleForTesting;
24 
25 /**
26  * Updates a package to ensure that if it targets < P that the org.apache.http.legacy library is
27  * included by default.
28  *
29  * @hide
30  */
31 @VisibleForTesting
32 public class OrgApacheHttpLegacyUpdater extends PackageSharedLibraryUpdater {
33 
apkTargetsApiLevelLessThanOrEqualToOMR1(Package pkg)34     private static boolean apkTargetsApiLevelLessThanOrEqualToOMR1(Package pkg) {
35         int targetSdkVersion = pkg.applicationInfo.targetSdkVersion;
36         return targetSdkVersion < Build.VERSION_CODES.P;
37     }
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