• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 mdm update bundle for self
76     PermissionStatus installUpdateSelfBundlePermissionStatus = PermissionStatus::NOT_VERIFIED_PERMISSION_STATUS;
77     // is shell token
78     bool isCallByShell = false;
79     // Indicates the distribution type
80     std::string specifiedDistributionType = "";
81     // Indicates the additional Info
82     std::string additionalInfo = "";
83     // for AOT
84     bool isOTA = false;
85     bool concentrateSendEvent = false;
86     bool allUser = false;
87     // utilizing for code-signature
88     std::map<std::string, std::string> verifyCodeParams;
89     ApplicationInfoFlag preinstallSourceFlag = ApplicationInfoFlag::FLAG_INSTALLED;
90     // for MDM self update
91     bool isSelfUpdate = false;
92     // the profile-guided optimization(PGO) file path
93     std::map<std::string, std::string> pgoParams;
94     // the parcel object function is not const.
95     bool ReadFromParcel(Parcel &parcel);
96     virtual bool Marshalling(Parcel &parcel) const override;
97     static InstallParam *Unmarshalling(Parcel &parcel);
98 
99 private:
100     // should force uninstall when delete userinfo.
101     bool forceExecuted = false;
102     // OTA upgrade skips the killing process
103     bool killProcess = true;
104     // system app can be uninstalled when uninstallUpdates
105     bool isUninstallAndRecover = false;
106 
107 public:
GetForceExecutedInstallParam108     bool GetForceExecuted() const
109     {
110         return forceExecuted;
111     }
112 
SetForceExecutedInstallParam113     void SetForceExecuted(bool value)
114     {
115         if (CheckPermission()) {
116             forceExecuted = value;
117         }
118     }
119 
GetKillProcessInstallParam120     bool GetKillProcess() const
121     {
122         return killProcess;
123     }
124 
SetKillProcessInstallParam125     void SetKillProcess(bool value)
126     {
127         if (CheckPermission()) {
128             killProcess = value;
129         }
130     }
131 
GetIsUninstallAndRecoverInstallParam132     bool GetIsUninstallAndRecover() const
133     {
134         return isUninstallAndRecover;
135     }
136 
SetIsUninstallAndRecoverInstallParam137     void SetIsUninstallAndRecover(bool value)
138     {
139         if (CheckPermission()) {
140             isUninstallAndRecover = value;
141         }
142     }
143 
144 private:
145     bool CheckPermission() const;
146 };
147 
148 struct UninstallParam : public Parcelable {
149     std::string bundleName;
150     std::string moduleName;
151     int32_t versionCode = Constants::ALL_VERSIONCODE;
152     int32_t userId = Constants::UNSPECIFIED_USERID;
153 
154     bool ReadFromParcel(Parcel &parcel);
155     virtual bool Marshalling(Parcel &parcel) const override;
156     static UninstallParam *Unmarshalling(Parcel &parcel);
157 };
158 }  // namespace AppExecFwk
159 }  // namespace OHOS
160 #endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_INSTALL_PARAM_H
161