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 static android.app.AppOpsManager.MODE_DEFAULT; 20 21 import android.annotation.NonNull; 22 import android.annotation.Nullable; 23 import android.content.pm.DataLoaderType; 24 import android.content.pm.IPackageInstallObserver2; 25 import android.content.pm.PackageInstaller; 26 import android.content.pm.PackageManager; 27 import android.content.pm.SigningDetails; 28 import android.os.UserHandle; 29 import android.util.ArrayMap; 30 31 import com.android.internal.util.Preconditions; 32 33 import java.io.File; 34 import java.util.List; 35 36 final class InstallArgs { 37 File mCodeFile; 38 /** @see InstallingSession#mOriginInfo */ 39 final OriginInfo mOriginInfo; 40 /** @see InstallingSession#mMoveInfo */ 41 final MoveInfo mMoveInfo; 42 43 final IPackageInstallObserver2 mObserver; 44 // Always refers to PackageManager flags only 45 final int mInstallFlags; 46 @NonNull 47 final InstallSource mInstallSource; 48 final String mVolumeUuid; 49 final UserHandle mUser; 50 final String mAbiOverride; 51 @NonNull 52 final ArrayMap<String, Integer> mPermissionStates; 53 final List<String> mAllowlistedRestrictedPermissions; 54 final int mAutoRevokePermissionsMode; 55 /** If non-null, drop an async trace when the install completes */ 56 final String mTraceMethod; 57 final int mTraceCookie; 58 final SigningDetails mSigningDetails; 59 final int mInstallReason; 60 final int mInstallScenario; 61 final boolean mForceQueryableOverride; 62 final int mDataLoaderType; 63 final int mPackageSource; 64 final boolean mApplicationEnabledSettingPersistent; 65 66 // The list of instruction sets supported by this app. This is currently 67 // only used during the rmdex() phase to clean up resources. We can get rid of this 68 // if we move dex files under the common app path. 69 @Nullable String[] mInstructionSets; 70 InstallArgs(OriginInfo originInfo, MoveInfo moveInfo, IPackageInstallObserver2 observer, int installFlags, InstallSource installSource, String volumeUuid, UserHandle user, String[] instructionSets, String abiOverride, @NonNull ArrayMap<String, Integer> permissionStates, List<String> allowlistedRestrictedPermissions, int autoRevokePermissionsMode, String traceMethod, int traceCookie, SigningDetails signingDetails, int installReason, int installScenario, boolean forceQueryableOverride, int dataLoaderType, int packageSource, boolean applicationEnabledSettingPersistent)71 InstallArgs(OriginInfo originInfo, MoveInfo moveInfo, IPackageInstallObserver2 observer, 72 int installFlags, InstallSource installSource, String volumeUuid, 73 UserHandle user, String[] instructionSets, String abiOverride, 74 @NonNull ArrayMap<String, Integer> permissionStates, 75 List<String> allowlistedRestrictedPermissions, 76 int autoRevokePermissionsMode, String traceMethod, int traceCookie, 77 SigningDetails signingDetails, int installReason, int installScenario, 78 boolean forceQueryableOverride, int dataLoaderType, int packageSource, 79 boolean applicationEnabledSettingPersistent) { 80 mOriginInfo = originInfo; 81 mMoveInfo = moveInfo; 82 mInstallFlags = installFlags; 83 mObserver = observer; 84 mInstallSource = Preconditions.checkNotNull(installSource); 85 mVolumeUuid = volumeUuid; 86 mUser = user; 87 mInstructionSets = instructionSets; 88 mAbiOverride = abiOverride; 89 mPermissionStates = permissionStates; 90 mAllowlistedRestrictedPermissions = allowlistedRestrictedPermissions; 91 mAutoRevokePermissionsMode = autoRevokePermissionsMode; 92 mTraceMethod = traceMethod; 93 mTraceCookie = traceCookie; 94 mSigningDetails = signingDetails; 95 mInstallReason = installReason; 96 mInstallScenario = installScenario; 97 mForceQueryableOverride = forceQueryableOverride; 98 mDataLoaderType = dataLoaderType; 99 mPackageSource = packageSource; 100 mApplicationEnabledSettingPersistent = applicationEnabledSettingPersistent; 101 } 102 103 /** 104 * Create args that describe an existing installed package. Typically used 105 * when cleaning up old installs, or used as a move source. 106 */ InstallArgs(String codePath, String[] instructionSets)107 InstallArgs(String codePath, String[] instructionSets) { 108 this(OriginInfo.fromNothing(), null, null, 0, InstallSource.EMPTY, null, null, 109 instructionSets, null, new ArrayMap<>(), null, MODE_DEFAULT, null, 0, 110 SigningDetails.UNKNOWN, PackageManager.INSTALL_REASON_UNKNOWN, 111 PackageManager.INSTALL_SCENARIO_DEFAULT, false, DataLoaderType.NONE, 112 PackageInstaller.PACKAGE_SOURCE_UNSPECIFIED, false); 113 mCodeFile = (codePath != null) ? new File(codePath) : null; 114 } 115 116 /** @see PackageSettingBase#getPath() */ getCodePath()117 String getCodePath() { 118 return (mCodeFile != null) ? mCodeFile.getAbsolutePath() : null; 119 } 120 } 121