1 /* 2 * Copyright (c) 2021-2024 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 // is keep user data while uninstall. 50 bool isKeepData = false; 51 bool needSavePreInstallInfo = false; 52 bool isPreInstallApp = false; 53 bool removable = true; 54 // whether need copy hap to install path 55 bool copyHapToInstallPath = true; 56 // is aging Cause uninstall. 57 bool isAgingUninstall = false; 58 bool needSendEvent = true; 59 bool withCopyHaps = false; 60 // for MDM self update 61 bool isSelfUpdate = false; 62 // is shell token 63 bool isCallByShell = false; 64 // for AOT 65 bool isOTA = false; 66 bool concentrateSendEvent = false; 67 bool isRemoveUser = false; 68 bool allUser = false; 69 bool isPatch = false; 70 bool isDataPreloadHap = false; 71 int32_t userId = Constants::UNSPECIFIED_USERID; 72 InstallFlag installFlag = InstallFlag::NORMAL; 73 InstallLocation installLocation = InstallLocation::INTERNAL_ONLY; 74 // status of install bundle permission 75 PermissionStatus installBundlePermissionStatus = PermissionStatus::NOT_VERIFIED_PERMISSION_STATUS; 76 // status of install enterprise bundle permission 77 PermissionStatus installEnterpriseBundlePermissionStatus = PermissionStatus::NOT_VERIFIED_PERMISSION_STATUS; 78 // status of install enterprise normal bundle permission 79 PermissionStatus installEtpNormalBundlePermissionStatus = PermissionStatus::NOT_VERIFIED_PERMISSION_STATUS; 80 // status of install enterprise mdm bundle permission 81 PermissionStatus installEtpMdmBundlePermissionStatus = PermissionStatus::NOT_VERIFIED_PERMISSION_STATUS; 82 // status of install internaltesting bundle permission 83 PermissionStatus installInternaltestingBundlePermissionStatus = PermissionStatus::NOT_VERIFIED_PERMISSION_STATUS; 84 // status of mdm update bundle for self 85 PermissionStatus installUpdateSelfBundlePermissionStatus = PermissionStatus::NOT_VERIFIED_PERMISSION_STATUS; 86 ApplicationInfoFlag preinstallSourceFlag = ApplicationInfoFlag::FLAG_INSTALLED; 87 int64_t crowdtestDeadline = Constants::INVALID_CROWDTEST_DEADLINE; // for crowdtesting type hap 88 // Indicates the distribution type 89 std::string specifiedDistributionType = ""; 90 // Indicates the additional Info 91 std::string additionalInfo = ""; 92 std::string appIdentifier; 93 // shared bundle directory paths 94 std::vector<std::string> sharedBundleDirPaths; 95 std::map<std::string, std::string> parameters; 96 // the profile-guided optimization(PGO) file path 97 std::map<std::string, std::string> pgoParams; 98 std::map<std::string, std::string> hashParams; 99 // utilizing for code-signature 100 std::map<std::string, std::string> verifyCodeParams; 101 // the parcel object function is not const. 102 bool ReadFromParcel(Parcel &parcel); 103 virtual bool Marshalling(Parcel &parcel) const override; 104 static InstallParam *Unmarshalling(Parcel &parcel); 105 106 private: 107 // should force uninstall when delete userinfo. 108 bool forceExecuted = false; 109 // OTA upgrade skips the killing process 110 bool killProcess = true; 111 // system app can be uninstalled when uninstallUpdates 112 bool isUninstallAndRecover = false; 113 114 public: 115 static constexpr const char* RENAME_INSTALL_KEY = "ohos.bms.param.renameInstall"; 116 static constexpr const char* ENTERPRISE_FOR_ALL_USER_KEY = "ohos.bms.param.enterpriseForAllUser"; 117 static constexpr const char* PARAMETERS_VALUE_TRUE = "true"; 118 GetForceExecutedInstallParam119 bool GetForceExecuted() const 120 { 121 return forceExecuted; 122 } 123 SetForceExecutedInstallParam124 void SetForceExecuted(bool value) 125 { 126 if (CheckPermission()) { 127 forceExecuted = value; 128 } 129 } 130 GetKillProcessInstallParam131 bool GetKillProcess() const 132 { 133 return killProcess; 134 } 135 SetKillProcessInstallParam136 void SetKillProcess(bool value) 137 { 138 if (CheckPermission()) { 139 killProcess = value; 140 } 141 } 142 GetIsUninstallAndRecoverInstallParam143 bool GetIsUninstallAndRecover() const 144 { 145 return isUninstallAndRecover; 146 } 147 SetIsUninstallAndRecoverInstallParam148 void SetIsUninstallAndRecover(bool value) 149 { 150 if (CheckPermission()) { 151 isUninstallAndRecover = value; 152 } 153 } 154 IsRenameInstallInstallParam155 bool IsRenameInstall() const 156 { 157 return parameters.find(RENAME_INSTALL_KEY) != parameters.end() && 158 parameters.at(RENAME_INSTALL_KEY) == PARAMETERS_VALUE_TRUE; 159 } 160 IsVerifyUninstallRuleInstallParam161 bool IsVerifyUninstallRule() const 162 { 163 return parameters.find(Constants::VERIFY_UNINSTALL_RULE_KEY) != parameters.end() && 164 parameters.at(Constants::VERIFY_UNINSTALL_RULE_KEY) == Constants::VERIFY_UNINSTALL_RULE_VALUE; 165 } 166 IsEnterpriseForAllUserInstallParam167 bool IsEnterpriseForAllUser() const 168 { 169 return parameters.find(ENTERPRISE_FOR_ALL_USER_KEY) != parameters.end() && 170 parameters.at(ENTERPRISE_FOR_ALL_USER_KEY) == PARAMETERS_VALUE_TRUE; 171 } 172 IsForcedUninstallInstallParam173 bool IsForcedUninstall() const 174 { 175 return parameters.find(Constants::VERIFY_UNINSTALL_FORCED_KEY) != parameters.end() && 176 parameters.at(Constants::VERIFY_UNINSTALL_FORCED_KEY) == Constants::VERIFY_UNINSTALL_FORCED_VALUE; 177 } 178 179 private: 180 bool CheckPermission() const; 181 }; 182 183 struct UninstallParam : public Parcelable { 184 int32_t versionCode = Constants::ALL_VERSIONCODE; 185 int32_t userId = Constants::UNSPECIFIED_USERID; 186 std::string bundleName; 187 std::string moduleName; 188 189 bool ReadFromParcel(Parcel &parcel); 190 virtual bool Marshalling(Parcel &parcel) const override; 191 static UninstallParam *Unmarshalling(Parcel &parcel); 192 }; 193 } // namespace AppExecFwk 194 } // namespace OHOS 195 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_INSTALL_PARAM_H 196