Paul Duffin | beee5dc | 2018-01-23 13:39:00 +0000 | [diff] [blame] | 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 | |
Paul Duffin | 0692a56 | 2018-01-09 12:35:32 +0000 | [diff] [blame] | 18 | import static android.content.pm.SharedLibraryNames.ORG_APACHE_HTTP_LEGACY; |
| 19 | |
Paul Duffin | beee5dc | 2018-01-23 13:39:00 +0000 | [diff] [blame] | 20 | import android.content.pm.PackageParser.Package; |
Paul Duffin | 5d70cdf | 2018-05-16 13:06:33 +0100 | [diff] [blame] | 21 | import android.os.Build; |
Paul Duffin | beee5dc | 2018-01-23 13:39:00 +0000 | [diff] [blame] | 22 | |
| 23 | import com.android.internal.annotations.VisibleForTesting; |
| 24 | |
Paul Duffin | beee5dc | 2018-01-23 13:39:00 +0000 | [diff] [blame] | 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 | * |
Paul Duffin | beee5dc | 2018-01-23 13:39:00 +0000 | [diff] [blame] | 29 | * @hide |
| 30 | */ |
| 31 | @VisibleForTesting |
| 32 | public class OrgApacheHttpLegacyUpdater extends PackageSharedLibraryUpdater { |
| 33 | |
Paul Duffin | 5d70cdf | 2018-05-16 13:06:33 +0100 | [diff] [blame] | 34 | private static boolean apkTargetsApiLevelLessThanOrEqualToOMR1(Package pkg) { |
| 35 | int targetSdkVersion = pkg.applicationInfo.targetSdkVersion; |
| 36 | return targetSdkVersion < Build.VERSION_CODES.P; |
| 37 | } |
| 38 | |
Paul Duffin | beee5dc | 2018-01-23 13:39:00 +0000 | [diff] [blame] | 39 | @Override |
| 40 | public void updatePackage(Package pkg) { |
Paul Duffin | beee5dc | 2018-01-23 13:39:00 +0000 | [diff] [blame] | 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)) { |
Paul Duffin | 0692a56 | 2018-01-09 12:35:32 +0000 | [diff] [blame] | 45 | prefixRequiredLibrary(pkg, ORG_APACHE_HTTP_LEGACY); |
Paul Duffin | beee5dc | 2018-01-23 13:39:00 +0000 | [diff] [blame] | 46 | } |
Paul Duffin | beee5dc | 2018-01-23 13:39:00 +0000 | [diff] [blame] | 47 | } |
| 48 | } |