1 /* 2 * Copyright (c) 2024-2025 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_MAIN_ELEMENT_UTILS_H 17 #define OHOS_ABILITY_RUNTIME_MAIN_ELEMENT_UTILS_H 18 19 #include "bundle_info.h" 20 #include "param.h" 21 22 namespace OHOS { 23 namespace AAFwk { 24 /** 25 * @class MainElementUtils 26 * provides main element utilities. 27 */ 28 class MainElementUtils final { 29 public: 30 /** 31 * CheckMainElement, check main element. 32 * 33 * @param hapModuleInfo The hap module info. 34 * @param processName The process name. 35 * @param mainElement The returned main element. 36 * @param isDataAbility The returned flag indicates whether the module contains data ability. 37 * @param uri Returned URI of the data ability. 38 * @param userId User id. 39 * @return Whether or not the hap module has the main element. 40 */ 41 static bool CheckMainElement(const AppExecFwk::HapModuleInfo &hapModuleInfo, 42 const std::string &processName, std::string &mainElement, bool &isDataAbility, 43 std::string &uriStr, int32_t userId = 0); 44 45 /** 46 * UpdateMainElement, update main element. 47 * 48 * @param bundleName The bundle name. 49 * @param moduleName The modle name. 50 * @param mainElement The returned main element. 51 * @param updateEnable Flag indicated whether update is enabled. 52 * @param userId User id. 53 */ 54 static void UpdateMainElement(const std::string &bundleName, const std::string &moduleName, 55 const std::string &mainElement, bool updateEnable, int32_t userId); 56 57 /** 58 * IsMainUIAbility, verify whether or not the ability is main UIAbility. 59 * 60 * @param bundleName The bundle name. 61 * @param abilityName The ability name. 62 * @param userId User id. 63 * @return Whether or not the ability is main UIAbility. 64 */ 65 static bool IsMainUIAbility(const std::string &bundleName, const std::string &abilityName, int32_t userId); 66 67 static void SetMainUIAbilityKeepAliveFlag(bool isMainUIAbility, 68 const std::string &bundleName, AbilityRuntime::LoadParam &loadParam); 69 70 /** 71 * CheckMainUIAbility, check if bundle has main UIAbility. 72 * 73 * @param bundleInfo The bundle info. 74 * @param mainElementName The returned main element name. 75 * @return Whether or not the bundle has the main element. 76 */ 77 static bool CheckMainUIAbility(const AppExecFwk::BundleInfo &bundleInfo, std::string& mainElementName); 78 79 /** 80 * CheckStatusBarAbility, check if bundle has status bar ability. 81 * 82 * @param bundleInfo The bundle info. 83 * @return Whether or not the bundle has a status bar ability. 84 */ 85 static bool CheckStatusBarAbility(const AppExecFwk::BundleInfo &bundleInfo); 86 87 /** 88 * CheckAppServiceExtension, check if bundle has app service extension. 89 * 90 * @param bundleInfo The bundle info. 91 * @return Whether or not the bundle has app service extension. 92 */ 93 static bool CheckAppServiceExtension(const AppExecFwk::BundleInfo &bundleInfo, std::string& mainElementName); 94 }; 95 } // namespace AAFwk 96 } // namespace OHOS 97 #endif // OHOS_ABILITY_RUNTIME_MAIN_ELEMENT_UTILS_H 98