1 /* 2 * Copyright (c) 2021-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_FORM_FWK_FORM_BMS_HELPER_H 17 #define OHOS_FORM_FWK_FORM_BMS_HELPER_H 18 19 #include <singleton.h> 20 #include "ability_manager_interface.h" 21 #include "bundle_mgr_interface.h" 22 #include "want.h" 23 24 namespace OHOS { 25 namespace AppExecFwk { 26 using Want = OHOS::AAFwk::Want; 27 28 /** 29 * @class FormBmsHelper 30 * Bms helpler. 31 */ 32 class FormBmsHelper final : public DelayedRefSingleton<FormBmsHelper> { 33 DECLARE_DELAYED_REF_SINGLETON(FormBmsHelper) 34 35 public: 36 DISALLOW_COPY_AND_MOVE(FormBmsHelper); 37 38 /** 39 * @brief Notify module removable. 40 * @param bundleName Provider ability bundleName. 41 * @param moduleName Provider ability moduleName. 42 */ 43 void NotifyModuleRemovable(const std::string &bundleName, const std::string &moduleName); 44 /** 45 * @brief Notify module not removable. 46 * @param bundleName Provider ability bundleName. 47 * @param moduleName Provider ability moduleName. 48 */ 49 void NotifyModuleNotRemovable(const std::string &bundleName, const std::string &moduleName); 50 51 /** 52 * @brief Acquire a bundle manager, if it not existed, 53 * @return returns the bundle manager ipc object, or nullptr for failed. 54 */ 55 sptr<IBundleMgr> GetBundleMgr(); 56 57 /** 58 * @brief Add the bundle manager instance for debug. 59 * @param bundleManager the bundle manager ipc object. 60 */ 61 void SetBundleManager(const sptr<IBundleMgr> &bundleManager); 62 63 /** 64 * @brief Get bundle package info. 65 * @param bundleName Indicates the bundle name. 66 * @param userId Indicates the user ID. 67 * @param bundlePackInfo Indicates the obtained BundlePackInfo object. 68 * @return Returns true on success, false on failure. 69 */ 70 bool GetBundlePackInfo(const std::string &bundleName, int32_t userId, BundlePackInfo &bundlePackInfo); 71 72 /** 73 * @brief Get ability info 74 * @param want The desired action to look for. 75 * @param userId Indicates the user ID. 76 * @param abilityInfo Indicates the obtained AbilityInfo object. 77 * @param extensionInfo Indicates the obtained extension. 78 * @return Returns true on success, false on failure. 79 */ 80 bool GetAbilityInfo(const Want &want, int32_t userId, AbilityInfo &abilityInfo, 81 ExtensionAbilityInfo &extensionInfo); 82 83 /** 84 * @brief Get ability info by action 85 * @param action The desired action to look for. 86 * @param userId Indicates the user ID. 87 * @param abilityInfo Indicates the obtained AbilityInfo object. 88 * @param extensionAbilityInfo Indicates the obtained extension. 89 * @return Returns true on success, false on failure. 90 */ 91 bool GetAbilityInfoByAction(const std::string &action, int32_t userId, AbilityInfo &abilityInfo, 92 ExtensionAbilityInfo &extensionAbilityInfo); 93 94 /** 95 * @brief Obtains the BundleInfo based on a given bundle name. 96 * @param bundleName Indicates the application bundle name to be queried. 97 * @param userId Indicates the user ID. 98 * @param bundleInfo Indicates the obtained BundleInfo object. 99 * @return Returns true if the BundleInfo is successfully obtained; returns false otherwise. 100 */ 101 bool GetBundleInfo(const std::string &bundleName, int32_t userId, BundleInfo &bundleInfo); 102 103 /** 104 * @brief Obtains the BundleInfo with Permission based on a given bundle name. 105 * @param bundleName Indicates the application bundle name to be queried. 106 * @param userId Indicates the user ID. 107 * @param bundleInfo Indicates the obtained BundleInfo object. 108 * @return Returns true if the BundleInfo is successfully obtained; returns false otherwise. 109 */ 110 bool GetBundleInfoWithPermission(const std::string &bundleName, int32_t userId, BundleInfo &bundleInfo); 111 112 /** 113 * @brief Get caller bundle name. 114 * @param callerBundleName Indicates the caller bundle name. 115 * @return Returns ERR_OK on success, others on failure. 116 */ 117 int32_t GetCallerBundleName(std::string &callerBundleName); 118 119 /** 120 * @brief Obtains the application UID based on the given bundle name and user ID. 121 * @param bundleName Indicates the bundle name of the application. 122 * @param userId Indicates the user ID. 123 * @return Returns the uid if successfully obtained; returns -1 otherwise. 124 */ 125 int32_t GetUidByBundleName(const std::string &bundleName, int32_t userId); 126 127 bool GetCompileMode(const std::string &bundleName, const std::string &moduleName, 128 int32_t userId, int32_t &compileMode); 129 130 bool GetCompatibleVersionCode(const std::string& bundleName, int32_t userId, int32_t& minCompatibleVersionCode); 131 132 int32_t GetBundleNameByUid(const int32_t uid, std::string &bundleName); 133 134 ErrCode GetProxyDataInfos(const std::string &bundleName, const std::string &moduleName, 135 int32_t userId, std::vector<ProxyData> &proxyData); 136 137 ErrCode GetAllProxyDataInfos(int32_t userId, std::vector<ProxyData> &proxyData); 138 139 ErrCode GetApplicationInfo(const std::string &bundleName, int32_t userId, ApplicationInfo &appInfo); 140 static constexpr int64_t INVALID_UID = -1; 141 private: 142 /** 143 * @brief Generate module key. 144 * @param bundleName Provider ability bundleName. 145 * @param moduleName Provider ability moduleName. 146 * @return Module key. 147 */ 148 std::string GenerateModuleKey(const std::string &bundleName, const std::string &moduleName) const; 149 150 private: 151 sptr<IBundleMgr> iBundleMgr_ = nullptr; 152 std::mutex ibundleMutex_; 153 }; 154 } // namespace AppExecFwk 155 } // namespace OHOS 156 157 #endif // OHOS_FORM_FWK_FORM_BMS_HELPER_H 158