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