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_HIDL_BASE; 19 import static android.content.pm.SharedLibraryNames.ANDROID_HIDL_MANAGER; 20 21 import android.content.pm.PackageParser.Package; 22 import android.os.Build; 23 24 import com.android.internal.annotations.VisibleForTesting; 25 26 /** 27 * Updates a package to ensure that if it targets <= P that the android.hidl.base-V1.0-java 28 * and android.hidl.manager-V1.0-java libraries are included by default. 29 * 30 * @hide 31 */ 32 @VisibleForTesting 33 public class AndroidHidlUpdater extends PackageSharedLibraryUpdater { 34 35 @Override updatePackage(Package pkg)36 public void updatePackage(Package pkg) { 37 ApplicationInfo info = pkg.applicationInfo; 38 39 // This was the default <= P and is maintained for backwards compatibility. 40 boolean isLegacy = info.targetSdkVersion <= Build.VERSION_CODES.P; 41 // Only system apps use these libraries 42 boolean isSystem = info.isSystemApp() || info.isUpdatedSystemApp(); 43 44 if (isLegacy && isSystem) { 45 prefixRequiredLibrary(pkg, ANDROID_HIDL_BASE); 46 prefixRequiredLibrary(pkg, ANDROID_HIDL_MANAGER); 47 } else { 48 removeLibrary(pkg, ANDROID_HIDL_BASE); 49 removeLibrary(pkg, ANDROID_HIDL_MANAGER); 50 } 51 } 52 } 53