• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.annotation.Nullable;
21 import android.content.pm.IPackageInstallObserver2;
22 import android.content.pm.PackageManager;
23 import android.content.pm.SigningDetails;
24 import android.os.UserHandle;
25 
26 import com.android.internal.util.Preconditions;
27 import com.android.server.pm.parsing.pkg.ParsedPackage;
28 
29 import java.util.List;
30 
31 abstract class InstallArgs {
32     /** @see InstallParams#mOriginInfo */
33     final OriginInfo mOriginInfo;
34     /** @see InstallParams#mMoveInfo */
35     final MoveInfo mMoveInfo;
36 
37     final IPackageInstallObserver2 mObserver;
38     // Always refers to PackageManager flags only
39     final int mInstallFlags;
40     @NonNull
41     final InstallSource mInstallSource;
42     final String mVolumeUuid;
43     final UserHandle mUser;
44     final String mAbiOverride;
45     final String[] mInstallGrantPermissions;
46     final List<String> mAllowlistedRestrictedPermissions;
47     final int mAutoRevokePermissionsMode;
48     /** If non-null, drop an async trace when the install completes */
49     final String mTraceMethod;
50     final int mTraceCookie;
51     final SigningDetails mSigningDetails;
52     final int mInstallReason;
53     final int mInstallScenario;
54     final boolean mForceQueryableOverride;
55     final int mDataLoaderType;
56     final int mPackageSource;
57 
58     // The list of instruction sets supported by this app. This is currently
59     // only used during the rmdex() phase to clean up resources. We can get rid of this
60     // if we move dex files under the common app path.
61     @Nullable String[] mInstructionSets;
62 
63     @NonNull final PackageManagerService mPm;
64     @NonNull final RemovePackageHelper mRemovePackageHelper;
65 
InstallArgs(OriginInfo originInfo, MoveInfo moveInfo, IPackageInstallObserver2 observer, int installFlags, InstallSource installSource, String volumeUuid, UserHandle user, String[] instructionSets, String abiOverride, String[] installGrantPermissions, List<String> allowlistedRestrictedPermissions, int autoRevokePermissionsMode, String traceMethod, int traceCookie, SigningDetails signingDetails, int installReason, int installScenario, boolean forceQueryableOverride, int dataLoaderType, int packageSource, PackageManagerService pm)66     InstallArgs(OriginInfo originInfo, MoveInfo moveInfo, IPackageInstallObserver2 observer,
67             int installFlags, InstallSource installSource, String volumeUuid,
68             UserHandle user, String[] instructionSets,
69             String abiOverride, String[] installGrantPermissions,
70             List<String> allowlistedRestrictedPermissions,
71             int autoRevokePermissionsMode,
72             String traceMethod, int traceCookie, SigningDetails signingDetails,
73             int installReason, int installScenario, boolean forceQueryableOverride,
74             int dataLoaderType, int packageSource, PackageManagerService pm) {
75         mOriginInfo = originInfo;
76         mMoveInfo = moveInfo;
77         mInstallFlags = installFlags;
78         mObserver = observer;
79         mInstallSource = Preconditions.checkNotNull(installSource);
80         mVolumeUuid = volumeUuid;
81         mUser = user;
82         mInstructionSets = instructionSets;
83         mAbiOverride = abiOverride;
84         mInstallGrantPermissions = installGrantPermissions;
85         mAllowlistedRestrictedPermissions = allowlistedRestrictedPermissions;
86         mAutoRevokePermissionsMode = autoRevokePermissionsMode;
87         mTraceMethod = traceMethod;
88         mTraceCookie = traceCookie;
89         mSigningDetails = signingDetails;
90         mInstallReason = installReason;
91         mInstallScenario = installScenario;
92         mForceQueryableOverride = forceQueryableOverride;
93         mDataLoaderType = dataLoaderType;
94         mPackageSource = packageSource;
95         mPm = pm;
96         mRemovePackageHelper = new RemovePackageHelper(mPm);
97     }
98 
99     /** New install */
InstallArgs(InstallParams params)100     InstallArgs(InstallParams params) {
101         this(params.mOriginInfo, params.mMoveInfo, params.mObserver, params.mInstallFlags,
102                 params.mInstallSource, params.mVolumeUuid,
103                 params.getUser(), null /*instructionSets*/, params.mPackageAbiOverride,
104                 params.mGrantedRuntimePermissions, params.mAllowlistedRestrictedPermissions,
105                 params.mAutoRevokePermissionsMode,
106                 params.mTraceMethod, params.mTraceCookie, params.mSigningDetails,
107                 params.mInstallReason, params.mInstallScenario, params.mForceQueryableOverride,
108                 params.mDataLoaderType, params.mPackageSource, params.mPm);
109     }
110 
copyApk()111     abstract int copyApk();
doPreInstall(int status)112     abstract int doPreInstall(int status);
113 
114     /**
115      * Rename package into final resting place. All paths on the given
116      * scanned package should be updated to reflect the rename.
117      */
doRename(int status, ParsedPackage parsedPackage)118     abstract boolean doRename(int status, ParsedPackage parsedPackage);
doPostInstall(int status, int uid)119     abstract int doPostInstall(int status, int uid);
120 
121     /** @see PackageSettingBase#getPath() */
getCodePath()122     abstract String getCodePath();
123 
124     // Need installer lock especially for dex file removal.
cleanUpResourcesLI()125     abstract void cleanUpResourcesLI();
doPostDeleteLI(boolean delete)126     abstract boolean doPostDeleteLI(boolean delete);
127 
128     /**
129      * Called before the source arguments are copied. This is used mostly
130      * for MoveParams when it needs to read the source file to put it in the
131      * destination.
132      */
doPreCopy()133     int doPreCopy() {
134         return PackageManager.INSTALL_SUCCEEDED;
135     }
136 
137     /**
138      * Called after the source arguments are copied. This is used mostly for
139      * MoveParams when it needs to read the source file to put it in the
140      * destination.
141      */
doPostCopy(int uid)142     int doPostCopy(int uid) {
143         return PackageManager.INSTALL_SUCCEEDED;
144     }
145 
isEphemeral()146     protected boolean isEphemeral() {
147         return (mInstallFlags & PackageManager.INSTALL_INSTANT_APP) != 0;
148     }
149 
getUser()150     UserHandle getUser() {
151         return mUser;
152     }
153 }
154