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_PRE_INSTALL_BUNDLE_INFO_H 17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_PRE_INSTALL_BUNDLE_INFO_H 18 19 #include "inner_bundle_info.h" 20 21 namespace OHOS { 22 namespace AppExecFwk { 23 class PreInstallBundleInfo { 24 public: 25 /** 26 * @brief Transform the PreInstallBundleInfo object to json. 27 * @param jsonObject Indicates the obtained json object. 28 * @return 29 */ 30 void ToJson(nlohmann::json &jsonObject) const; 31 /** 32 * @brief Transform the json object to PreInstallBundleInfo object. 33 * @param jsonObject Indicates the obtained json object. 34 * @return Returns 0 if the json object parsed successfully; returns error code otherwise. 35 */ 36 int32_t FromJson(const nlohmann::json &jsonObject); 37 /** 38 * @brief Transform the PreInstallBundleInfo object to string. 39 * @return Returns the string object 40 */ 41 std::string ToString() const; 42 /** 43 * @brief Get bundle name. 44 * @return Return bundle name 45 */ GetBundleName()46 std::string GetBundleName() const 47 { 48 return bundleName_; 49 } 50 /** 51 * @brief Set bundle name. 52 * @param bundleName bundle name. 53 */ SetBundleName(const std::string & bundleName)54 void SetBundleName(const std::string &bundleName) 55 { 56 bundleName_ = bundleName; 57 } 58 /** 59 * @brief Get versionCode. 60 * @return Return versionCode. 61 */ GetVersionCode()62 uint32_t GetVersionCode() const 63 { 64 return versionCode_; 65 } 66 /** 67 * @brief Set versionCode. 68 * @param versionCode versionCode. 69 */ SetVersionCode(const uint32_t & versionCode)70 void SetVersionCode(const uint32_t &versionCode) 71 { 72 versionCode_ = versionCode; 73 } 74 /** 75 * @brief Get bundle path. 76 * @return Return bundle path 77 */ GetBundlePaths()78 std::vector<std::string> GetBundlePaths() const 79 { 80 return bundlePaths_; 81 } 82 /** 83 * @brief Add bundle path. 84 * @param bundlePath bundle path. 85 */ AddBundlePath(const std::string & bundlePath)86 void AddBundlePath(const std::string &bundlePath) 87 { 88 bool ret = std::find( 89 bundlePaths_.begin(), bundlePaths_.end(), bundlePath) != bundlePaths_.end(); 90 if (!ret) { 91 bundlePaths_.emplace_back(bundlePath); 92 } 93 } 94 /** 95 * @brief Delete bundle path. 96 * @param bundlePath bundle path. 97 */ DeleteBundlePath(const std::string & bundlePath)98 void DeleteBundlePath(const std::string &bundlePath) 99 { 100 auto iter = std::find(bundlePaths_.begin(), bundlePaths_.end(), bundlePath); 101 if (iter != bundlePaths_.end()) { 102 bundlePaths_.erase(iter); 103 } 104 } 105 /** 106 * @brief clear bundle path. 107 * @param bundlePath bundle path. 108 */ ClearBundlePath()109 void ClearBundlePath() 110 { 111 bundlePaths_.clear(); 112 } 113 /** 114 * @brief Has bundle path. 115 * @param bundlePath bundle path. 116 */ HasBundlePath(const std::string & bundlePath)117 bool HasBundlePath(const std::string &bundlePath) 118 { 119 return std::find(bundlePaths_.begin(), bundlePaths_.end(), bundlePath) 120 != bundlePaths_.end(); 121 } 122 /** 123 * @brief Calculate Hap Total Size. 124 */ 125 void CalculateHapTotalSize(); 126 /** 127 * @brief Get HapTotalSize. 128 * @return Returns the HapTotalSize. 129 */ GetHapTotalSize()130 int64_t GetHapTotalSize() const 131 { 132 return hapTotalSize_; 133 } 134 /** 135 * @brief Get AppType. 136 * @return Returns the AppType. 137 */ GetAppType()138 Constants::AppType GetAppType() const 139 { 140 return appType_; 141 } 142 /** 143 * @brief Set AppType. 144 * @param appType Indicates the AppType to be set. 145 */ SetAppType(Constants::AppType appType)146 void SetAppType(Constants::AppType appType) 147 { 148 appType_ = appType; 149 } 150 /** 151 * @brief Is removable or not. 152 * @return Returns the removable. 153 */ IsRemovable()154 bool IsRemovable() const 155 { 156 return removable_; 157 } 158 /** 159 * @brief Set removable. 160 * @param appType Indicates the removable to be set. 161 */ SetRemovable(bool removable)162 void SetRemovable(bool removable) 163 { 164 removable_ = removable; 165 } 166 /** 167 * @brief Is uninstalled or not. 168 * @return Returns the isUninstalled. 169 */ IsUninstalled()170 bool IsUninstalled() const 171 { 172 return isUninstalled_; 173 } 174 /** 175 * @brief Set isUninstalled. 176 * @param appType Indicates the removable to be set. 177 */ SetIsUninstalled(bool isUninstalled)178 void SetIsUninstalled(bool isUninstalled) 179 { 180 isUninstalled_ = isUninstalled; 181 } 182 /** 183 * @brief operator. 184 * @param PreInstallBundleInfo Indicates the PreInstallBundleInfo. 185 */ operator()186 bool operator() (const PreInstallBundleInfo& info) const 187 { 188 return bundleName_ == info.GetBundleName(); 189 } 190 bool operator < (const PreInstallBundleInfo &preInstallBundleInfo) const 191 { 192 if (bundlePaths_.size() == preInstallBundleInfo.GetBundlePaths().size()) { 193 return hapTotalSize_ >= preInstallBundleInfo.GetHapTotalSize(); 194 } 195 196 return bundlePaths_.size() > preInstallBundleInfo.GetBundlePaths().size(); 197 } 198 /** 199 * @brief Get module name. 200 * @return Return module name. 201 */ GetModuleName()202 std::string GetModuleName() const 203 { 204 return moduleName_; 205 } 206 /** 207 * @brief Set module name. 208 * @param moduleName module name. 209 */ SetModuleName(const std::string & moduleName)210 void SetModuleName(const std::string &moduleName) 211 { 212 moduleName_ = moduleName; 213 } 214 /** 215 * @brief Get label id. 216 * @return Return label id. 217 */ GetLabelId()218 uint32_t GetLabelId() const 219 { 220 return labelId_; 221 } 222 /** 223 * @brief Set label id. 224 * @param labelId label id. 225 */ SetLabelId(const uint32_t labelId)226 void SetLabelId(const uint32_t labelId) 227 { 228 labelId_ = labelId; 229 } 230 /** 231 * @brief Get icon id. 232 * @return Return icon id. 233 */ GetIconId()234 uint32_t GetIconId() const 235 { 236 return iconId_; 237 } 238 /** 239 * @brief Set icon id. 240 * @param iconId icon id. 241 */ SetIconId(const uint32_t iconId)242 void SetIconId(const uint32_t iconId) 243 { 244 iconId_ = iconId; 245 } 246 GetSystemApp()247 bool GetSystemApp() const 248 { 249 return systemApp_; 250 } 251 SetSystemApp(bool systemApp)252 void SetSystemApp(bool systemApp) 253 { 254 systemApp_ = systemApp; 255 } 256 GetBundleType()257 BundleType GetBundleType() const 258 { 259 return bundleType_; 260 } 261 SetBundleType(BundleType bundleType)262 void SetBundleType(BundleType bundleType) 263 { 264 bundleType_ = bundleType; 265 } 266 267 private: 268 std::string bundleName_; 269 std::string moduleName_; 270 int64_t hapTotalSize_ = 0; 271 uint32_t versionCode_; 272 uint32_t labelId_ = 0; 273 uint32_t iconId_ = 0; 274 std::vector<std::string> bundlePaths_; 275 bool removable_ = true; 276 bool isUninstalled_ = false; 277 Constants::AppType appType_ = Constants::AppType::SYSTEM_APP; 278 bool systemApp_ = false; 279 BundleType bundleType_ = BundleType::APP; 280 }; 281 } // namespace AppExecFwk 282 } // namespace OHOS 283 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_PRE_INSTALL_BUNDLE_INFO_H 284