1 /* 2 * Copyright (C) 2021 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 17 package com.android.server.pm; 18 19 import android.annotation.NonNull; 20 import android.content.pm.SharedLibraryInfo; 21 import android.content.pm.SigningDetails; 22 import android.util.ArrayMap; 23 24 import com.android.server.pm.pkg.AndroidPackage; 25 26 import java.util.ArrayList; 27 import java.util.List; 28 import java.util.Map; 29 30 /** 31 * A container of all data needed to commit a package to in-memory data structures and to disk. 32 * TODO: move most of the data contained here into a PackageSetting for commit. 33 */ 34 final class ReconciledPackage { 35 private final List<InstallRequest> mInstallRequests; 36 private final Map<String, AndroidPackage> mAllPackages; 37 @NonNull public final InstallRequest mInstallRequest; 38 public final DeletePackageAction mDeletePackageAction; 39 public final List<SharedLibraryInfo> mAllowedSharedLibraryInfos; 40 public final SigningDetails mSigningDetails; 41 public final boolean mSharedUserSignaturesChanged; 42 public ArrayList<SharedLibraryInfo> mCollectedSharedLibraryInfos; 43 public final boolean mRemoveAppKeySetData; 44 ReconciledPackage(List<InstallRequest> installRequests, Map<String, AndroidPackage> allPackages, InstallRequest installRequest, DeletePackageAction deletePackageAction, List<SharedLibraryInfo> allowedSharedLibraryInfos, SigningDetails signingDetails, boolean sharedUserSignaturesChanged, boolean removeAppKeySetData)45 ReconciledPackage(List<InstallRequest> installRequests, 46 Map<String, AndroidPackage> allPackages, 47 InstallRequest installRequest, 48 DeletePackageAction deletePackageAction, 49 List<SharedLibraryInfo> allowedSharedLibraryInfos, 50 SigningDetails signingDetails, 51 boolean sharedUserSignaturesChanged, 52 boolean removeAppKeySetData) { 53 mInstallRequests = installRequests; 54 mAllPackages = allPackages; 55 mInstallRequest = installRequest; 56 mDeletePackageAction = deletePackageAction; 57 mAllowedSharedLibraryInfos = allowedSharedLibraryInfos; 58 mSigningDetails = signingDetails; 59 mSharedUserSignaturesChanged = sharedUserSignaturesChanged; 60 mRemoveAppKeySetData = removeAppKeySetData; 61 } 62 63 /** 64 * Returns a combined set of packages containing the packages already installed combined 65 * with the package(s) currently being installed. The to-be installed packages take 66 * precedence and may shadow already installed packages. 67 */ getCombinedAvailablePackages()68 @NonNull Map<String, AndroidPackage> getCombinedAvailablePackages() { 69 final ArrayMap<String, AndroidPackage> combined = 70 new ArrayMap<>(mAllPackages.size() + mInstallRequests.size()); 71 72 combined.putAll(mAllPackages); 73 74 for (InstallRequest installRequest : mInstallRequests) { 75 combined.put(installRequest.getScannedPackageSetting().getPackageName(), 76 installRequest.getParsedPackage()); 77 } 78 79 return combined; 80 } 81 } 82