1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_INSTALL_PARAM_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_INSTALL_PARAM_H
18 
19 #include <map>
20 #include <string>
21 #include <vector>
22 
23 #include "application_info.h"
24 #include "bundle_constants.h"
25 #include "parcel.h"
26 namespace OHOS {
27 namespace AppExecFwk {
28 enum class InstallFlag : int8_t {
29     NORMAL = 0,
30     // Allow to replace the existing bundle when the new version isn't lower than the old one.
31     // If the bundle does not exist, just like normal flag.
32     REPLACE_EXISTING = 1,
33     FREE_INSTALL = 0x10,
34 };
35 
36 enum class InstallLocation : int8_t {
37     INTERNAL_ONLY = 1,
38     PREFER_EXTERNAL = 2,
39 };
40 
41 enum class PermissionStatus : int8_t {
42     NOT_VERIFIED_PERMISSION_STATUS = 0,
43     HAVE_PERMISSION_STATUS,
44     NON_HAVE_PERMISSION_STATUS
45 };
46 
47 // provides parameters required for installing or uninstalling an application
48 struct InstallParam : public Parcelable {
49     InstallFlag installFlag = InstallFlag::NORMAL;
50     InstallLocation installLocation = InstallLocation::INTERNAL_ONLY;
51     int32_t userId = Constants::UNSPECIFIED_USERID;
52     int64_t crowdtestDeadline = Constants::INVALID_CROWDTEST_DEADLINE; // for crowdtesting type hap
53     // is keep user data while uninstall.
54     bool isKeepData = false;
55     bool needSavePreInstallInfo = false;
56     bool isPreInstallApp = false;
57     bool removable = true;
58     bool needSendEvent = true;
59     bool withCopyHaps = false;
60     std::map<std::string, std::string> hashParams;
61     // whether need copy hap to install path
62     bool copyHapToInstallPath = true;
63     // is aging Cause uninstall.
64     bool isAgingUninstall = false;
65     // shared bundle directory paths
66     std::vector<std::string> sharedBundleDirPaths;
67     // status of install bundle permission
68     PermissionStatus installBundlePermissionStatus = PermissionStatus::NOT_VERIFIED_PERMISSION_STATUS;
69     // status of install enterprise bundle permission
70     PermissionStatus installEnterpriseBundlePermissionStatus = PermissionStatus::NOT_VERIFIED_PERMISSION_STATUS;
71     // status of install enterprise normal bundle permission
72     PermissionStatus installEtpNormalBundlePermissionStatus = PermissionStatus::NOT_VERIFIED_PERMISSION_STATUS;
73     // status of install enterprise mdm bundle permission
74     PermissionStatus installEtpMdmBundlePermissionStatus = PermissionStatus::NOT_VERIFIED_PERMISSION_STATUS;
75     // status of install internaltesting bundle permission
76     PermissionStatus installInternaltestingBundlePermissionStatus = PermissionStatus::NOT_VERIFIED_PERMISSION_STATUS;
77     // status of mdm update bundle for self
78     PermissionStatus installUpdateSelfBundlePermissionStatus = PermissionStatus::NOT_VERIFIED_PERMISSION_STATUS;
79     // is shell token
80     bool isCallByShell = false;
81     // Indicates the distribution type
82     std::string specifiedDistributionType = "";
83     // Indicates the additional Info
84     std::string additionalInfo = "";
85     // for AOT
86     bool isOTA = false;
87     bool concentrateSendEvent = false;
88     bool isRemoveUser = false;
89     bool allUser = false;
90     // utilizing for code-signature
91     std::map<std::string, std::string> verifyCodeParams;
92     ApplicationInfoFlag preinstallSourceFlag = ApplicationInfoFlag::FLAG_INSTALLED;
93     std::map<std::string, std::string> parameters;
94     // for MDM self update
95     bool isSelfUpdate = false;
96     // the profile-guided optimization(PGO) file path
97     std::map<std::string, std::string> pgoParams;
98     // the parcel object function is not const.
99     bool ReadFromParcel(Parcel &parcel);
100     virtual bool Marshalling(Parcel &parcel) const override;
101     static InstallParam *Unmarshalling(Parcel &parcel);
102 
103 private:
104     // should force uninstall when delete userinfo.
105     bool forceExecuted = false;
106     // OTA upgrade skips the killing process
107     bool killProcess = true;
108     // system app can be uninstalled when uninstallUpdates
109     bool isUninstallAndRecover = false;
110 
111 public:
112     static constexpr const char* RENAME_INSTALL_KEY = "ohos.bms.param.renameInstall";
113     static constexpr const char* RENAME_INSTALL_ENABLE_VALUE = "true";
114 
GetForceExecutedInstallParam115     bool GetForceExecuted() const
116     {
117         return forceExecuted;
118     }
119 
SetForceExecutedInstallParam120     void SetForceExecuted(bool value)
121     {
122         if (CheckPermission()) {
123             forceExecuted = value;
124         }
125     }
126 
GetKillProcessInstallParam127     bool GetKillProcess() const
128     {
129         return killProcess;
130     }
131 
SetKillProcessInstallParam132     void SetKillProcess(bool value)
133     {
134         if (CheckPermission()) {
135             killProcess = value;
136         }
137     }
138 
GetIsUninstallAndRecoverInstallParam139     bool GetIsUninstallAndRecover() const
140     {
141         return isUninstallAndRecover;
142     }
143 
SetIsUninstallAndRecoverInstallParam144     void SetIsUninstallAndRecover(bool value)
145     {
146         if (CheckPermission()) {
147             isUninstallAndRecover = value;
148         }
149     }
150 
IsRenameInstallInstallParam151     bool IsRenameInstall() const
152     {
153         return parameters.find(RENAME_INSTALL_KEY) != parameters.end() &&
154             parameters.at(RENAME_INSTALL_KEY) == RENAME_INSTALL_ENABLE_VALUE;
155     }
156 
157 private:
158     bool CheckPermission() const;
159 };
160 
161 struct UninstallParam : public Parcelable {
162     std::string bundleName;
163     std::string moduleName;
164     int32_t versionCode = Constants::ALL_VERSIONCODE;
165     int32_t userId = Constants::UNSPECIFIED_USERID;
166 
167     bool ReadFromParcel(Parcel &parcel);
168     virtual bool Marshalling(Parcel &parcel) const override;
169     static UninstallParam *Unmarshalling(Parcel &parcel);
170 };
171 }  // namespace AppExecFwk
172 }  // namespace OHOS
173 #endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_INSTALL_PARAM_H
174