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_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 Has bundle path. 107 * @param bundlePath bundle path. 108 */ HasBundlePath(const std::string & bundlePath)109 bool HasBundlePath(const std::string &bundlePath) 110 { 111 return std::find(bundlePaths_.begin(), bundlePaths_.end(), bundlePath) 112 != bundlePaths_.end(); 113 } 114 /** 115 * @brief Get AppType. 116 * @return Returns the AppType. 117 */ GetAppType()118 Constants::AppType GetAppType() const 119 { 120 return appType_; 121 } 122 /** 123 * @brief Set AppType. 124 * @param appType Indicates the AppType to be set. 125 */ SetAppType(Constants::AppType appType)126 void SetAppType(Constants::AppType appType) 127 { 128 appType_ = appType; 129 } 130 /** 131 * @brief operator. 132 * @param PreInstallBundleInfo Indicates the PreInstallBundleInfo. 133 */ operator()134 bool operator() (const PreInstallBundleInfo& info) const 135 { 136 return bundleName_ == info.GetBundleName(); 137 } 138 private: 139 std::string bundleName_; 140 uint32_t versionCode_; 141 std::vector<std::string> bundlePaths_; 142 Constants::AppType appType_ = Constants::AppType::SYSTEM_APP; 143 }; 144 } // namespace AppExecFwk 145 } // namespace OHOS 146 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_PRE_INSTALL_BUNDLE_INFO_H 147