1 /* 2 * Copyright (c) 2023 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 OHOS_ABILITY_RUNTIME_SIMULATOR_INNER_BUNDLE_INFO_H 17 #define OHOS_ABILITY_RUNTIME_SIMULATOR_INNER_BUNDLE_INFO_H 18 19 #include "nocopyable.h" 20 #include "ability_info.h" 21 #include "bundle_constants.h" 22 #include "common_profile.h" 23 #include "extension_ability_info.h" 24 #include "hap_module_info.h" 25 #include "json_util.h" 26 27 namespace OHOS { 28 namespace AppExecFwk { 29 struct Distro { 30 bool deliveryWithInstall = false; 31 std::string moduleName; 32 std::string moduleType; 33 bool installationFree = false; 34 }; 35 36 struct InnerModuleInfo { 37 std::string name; 38 std::string modulePackage; 39 std::string moduleName; 40 std::string modulePath; 41 std::string moduleDataDir; 42 std::string moduleResPath; 43 std::string label; 44 std::string hapPath; 45 int32_t labelId = 0; 46 std::string description; 47 int32_t descriptionId = 0; 48 std::string icon; 49 int32_t iconId = 0; 50 std::string mainAbility; // config.json : mainAbility; module.json : mainElement 51 std::string entryAbilityKey; // skills contains "action.system.home" and "entity.system.home" 52 std::string srcPath; 53 std::string hashValue; 54 bool isEntry = false; 55 bool installationFree = false; 56 // all user's value of isRemovable 57 // key:userId 58 // value:isRemovable true or flase 59 std::map<std::string, bool> isRemovable; 60 MetaData metaData; 61 ModuleColorMode colorMode = ModuleColorMode::AUTO; 62 Distro distro; 63 std::vector<std::string> reqCapabilities; 64 std::vector<std::string> abilityKeys; 65 std::vector<std::string> skillKeys; 66 // new version fields 67 std::string pages; 68 std::string process; 69 std::string srcEntrance; 70 std::string uiSyntax; 71 std::string virtualMachine; 72 bool isModuleJson = false; 73 bool isStageBasedModel = false; 74 std::vector<std::string> deviceTypes; 75 std::vector<std::string> extensionKeys; 76 std::vector<std::string> extensionSkillKeys; 77 std::vector<Metadata> metadata; 78 int32_t upgradeFlag = 0; 79 std::vector<Dependency> dependencies; 80 std::string compileMode; 81 bool isLibIsolated = false; 82 std::string nativeLibraryPath; 83 std::string cpuAbi; 84 std::string targetModuleName; 85 int32_t targetPriority; 86 AtomicServiceModuleType atomicServiceModuleType; 87 std::vector<std::string> preloads; 88 BundleType bundleType = BundleType::SHARED; 89 uint32_t versionCode = 0; 90 std::string versionName; 91 std::vector<ProxyData> proxyDatas; 92 std::string buildHash; 93 std::string isolationMode; 94 bool compressNativeLibs = true; 95 std::vector<std::string> nativeLibraryFileNames; 96 AOTCompileStatus aotCompileStatus = AOTCompileStatus::NOT_COMPILED; 97 }; 98 99 class InnerBundleInfo { 100 public: 101 enum class BundleStatus { 102 ENABLED = 1, 103 DISABLED, 104 }; 105 106 InnerBundleInfo(); 107 InnerBundleInfo &operator=(const InnerBundleInfo &info); 108 ~InnerBundleInfo(); 109 /** 110 * @brief Transform the InnerBundleInfo object to json. 111 * @param jsonObject Indicates the obtained json object. 112 * @return 113 */ 114 void ToJson(nlohmann::json &jsonObject) const; 115 /** 116 * @brief Transform the json object to InnerBundleInfo object. 117 * @param jsonObject Indicates the obtained json object. 118 * @return Returns 0 if the json object parsed successfully; returns error code otherwise. 119 */ 120 int32_t FromJson(const nlohmann::json &jsonObject); 121 /** 122 * @brief Find hap module info by module package. 123 * @param modulePackage Indicates the module package. 124 * @param userId Indicates the user ID. 125 * @return Returns the HapModuleInfo object if find it; returns null otherwise. 126 */ 127 std::optional<HapModuleInfo> FindHapModuleInfo( 128 const std::string &modulePackage, int32_t userId = Constants::UNSPECIFIED_USERID) const; 129 /** 130 * @brief Find abilityInfo by bundle name and ability name. 131 * @param moduleName Indicates the module name 132 * @param abilityName Indicates the ability name. 133 * @param userId Indicates the user ID. 134 * @return Returns the AbilityInfo object if find it; returns null otherwise. 135 */ 136 std::optional<AbilityInfo> FindAbilityInfo( 137 const std::string &moduleName, 138 const std::string &abilityName, 139 int32_t userId = Constants::UNSPECIFIED_USERID) const; 140 /** 141 * @brief Find abilityInfo by bundle name module name and ability name. 142 * @param moduleName Indicates the module name 143 * @param abilityName Indicates the ability name. 144 * @return Returns ERR_OK if abilityInfo find successfully obtained; returns other ErrCode otherwise. 145 */ 146 ErrCode FindAbilityInfo( 147 const std::string &moduleName, const std::string &abilityName, AbilityInfo &info) const; 148 /** 149 * @brief Transform the InnerBundleInfo object to string. 150 * @return Returns the string object 151 */ 152 std::string ToString() const; 153 /** 154 * @brief Get bundle name. 155 * @return Return bundle name 156 */ GetBundleName()157 const std::string GetBundleName() const 158 { 159 return baseApplicationInfo_->bundleName; 160 } 161 /** 162 * @brief Set baseApplicationInfo. 163 * @param applicationInfo Indicates the ApplicationInfo object. 164 */ SetBaseApplicationInfo(const ApplicationInfo & applicationInfo)165 void SetBaseApplicationInfo(const ApplicationInfo &applicationInfo) 166 { 167 *baseApplicationInfo_ = applicationInfo; 168 } 169 /** 170 * @brief Insert innerModuleInfos. 171 * @param modulePackage Indicates the modulePackage object as key. 172 * @param innerModuleInfo Indicates the InnerModuleInfo object as value. 173 */ InsertInnerModuleInfo(const std::string & modulePackage,const InnerModuleInfo & innerModuleInfo)174 void InsertInnerModuleInfo(const std::string &modulePackage, const InnerModuleInfo &innerModuleInfo) 175 { 176 innerModuleInfos_.try_emplace(modulePackage, innerModuleInfo); 177 } 178 /** 179 * @brief Insert AbilityInfo. 180 * @param key bundleName.moduleName.abilityName 181 * @param abilityInfo value. 182 */ InsertAbilitiesInfo(const std::string & key,const AbilityInfo & abilityInfo)183 void InsertAbilitiesInfo(const std::string &key, const AbilityInfo &abilityInfo) 184 { 185 baseAbilityInfos_.emplace(key, abilityInfo); 186 } 187 /** 188 * @brief Insert ExtensionAbilityInfo. 189 * @param key bundleName.moduleName.extensionName 190 * @param extensionInfo value. 191 */ InsertExtensionInfo(const std::string & key,const ExtensionAbilityInfo & extensionInfo)192 void InsertExtensionInfo(const std::string &key, const ExtensionAbilityInfo &extensionInfo) 193 { 194 baseExtensionInfos_.emplace(key, extensionInfo); 195 } 196 /** 197 * @brief Get application AppType. 198 * @return Returns the AppType. 199 */ GetAppType()200 Constants::AppType GetAppType() const 201 { 202 return appType_; 203 } 204 SetCurrentModulePackage(const std::string & modulePackage)205 void SetCurrentModulePackage(const std::string &modulePackage) 206 { 207 currentPackage_ = modulePackage; 208 } 209 210 /** 211 * @brief Obtains configuration information about an application. 212 * @param flags Indicates the flag used to specify information contained 213 * in the ApplicationInfo object that will be returned. 214 * @param userId Indicates the user ID. 215 * @param appInfo Indicates the obtained ApplicationInfo object. 216 */ 217 void GetApplicationInfo(int32_t flags, int32_t userId, ApplicationInfo &appInfo) const; 218 SetKeepAlive(bool keepAlive)219 void SetKeepAlive(bool keepAlive) 220 { 221 baseApplicationInfo_->keepAlive = keepAlive; 222 } 223 SetTargetPriority(int32_t priority)224 void SetTargetPriority(int32_t priority) 225 { 226 baseApplicationInfo_->targetPriority = priority; 227 } 228 SetIsNewVersion(bool isNewVersion)229 void SetIsNewVersion(bool isNewVersion) 230 { 231 isNewVersion_ = isNewVersion; 232 } 233 234 private: 235 void RemoveDuplicateName(std::vector<std::string> &name) const; 236 IsolationMode GetIsolationMode(const std::string &isolationMode) const; 237 238 // using for get 239 Constants::AppType appType_ = Constants::AppType::THIRD_PARTY_APP; 240 int userId_ = Constants::DEFAULT_USERID; 241 BundleStatus bundleStatus_ = BundleStatus::ENABLED; 242 std::shared_ptr<ApplicationInfo> baseApplicationInfo_; 243 std::string appFeature_; 244 std::vector<std::string> allowedAcls_; 245 int32_t appIndex_ = Constants::INITIAL_APP_INDEX; 246 bool isSandboxApp_ = false; 247 std::string currentPackage_; 248 bool onlyCreateBundleUser_ = false; 249 std::map<std::string, InnerModuleInfo> innerModuleInfos_; 250 std::map<std::string, AbilityInfo> baseAbilityInfos_; 251 bool isNewVersion_ = false; 252 std::map<std::string, ExtensionAbilityInfo> baseExtensionInfos_; 253 std::vector<Metadata> provisionMetadatas_; 254 }; 255 256 void from_json(const nlohmann::json &jsonObject, InnerModuleInfo &info); 257 void from_json(const nlohmann::json &jsonObject, Distro &distro); 258 } // namespace AppExecFwk 259 } // namespace OHOS 260 #endif // OHOS_ABILITY_RUNTIME_SIMULATOR_INNER_BUNDLE_INFO_H 261