blob: 707443b19679237b2775af223b173d475491712c [file] [log] [blame]
Paul Duffinbeee5dc2018-01-23 13:39:00 +00001/*
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 */
16package android.content.pm;
17
Paul Duffin0692a562018-01-09 12:35:32 +000018import static android.content.pm.SharedLibraryNames.ORG_APACHE_HTTP_LEGACY;
19
Paul Duffinbeee5dc2018-01-23 13:39:00 +000020import android.content.pm.PackageParser.Package;
Paul Duffin5d70cdf2018-05-16 13:06:33 +010021import android.os.Build;
Paul Duffinbeee5dc2018-01-23 13:39:00 +000022
23import com.android.internal.annotations.VisibleForTesting;
24
Paul Duffinbeee5dc2018-01-23 13:39:00 +000025/**
26 * Updates a package to ensure that if it targets < P that the org.apache.http.legacy library is
27 * included by default.
28 *
Paul Duffinbeee5dc2018-01-23 13:39:00 +000029 * @hide
30 */
31@VisibleForTesting
32public class OrgApacheHttpLegacyUpdater extends PackageSharedLibraryUpdater {
33
Paul Duffin5d70cdf2018-05-16 13:06:33 +010034 private static boolean apkTargetsApiLevelLessThanOrEqualToOMR1(Package pkg) {
35 int targetSdkVersion = pkg.applicationInfo.targetSdkVersion;
36 return targetSdkVersion < Build.VERSION_CODES.P;
37 }
38
Paul Duffinbeee5dc2018-01-23 13:39:00 +000039 @Override
40 public void updatePackage(Package pkg) {
Paul Duffinbeee5dc2018-01-23 13:39:00 +000041 // 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)) {
Paul Duffin0692a562018-01-09 12:35:32 +000045 prefixRequiredLibrary(pkg, ORG_APACHE_HTTP_LEGACY);
Paul Duffinbeee5dc2018-01-23 13:39:00 +000046 }
Paul Duffinbeee5dc2018-01-23 13:39:00 +000047 }
48}