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_EVENT_CESFWK_SERVICES_INCLUDE_BUNDLE_MANAGER_HELPER_H 17 #define FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_BUNDLE_MANAGER_HELPER_H 18 19 #include <string> 20 #include <vector> 21 22 #include "bms_death_recipient.h" 23 #include "bundle_mgr_interface.h" 24 #include "extension_ability_info.h" 25 #include "iremote_object.h" 26 #include "refbase.h" 27 #include "singleton.h" 28 #include "want.h" 29 30 namespace OHOS { 31 namespace EventFwk { 32 class BundleManagerHelper : public DelayedSingleton<BundleManagerHelper> { 33 public: 34 using IBundleMgr = OHOS::AppExecFwk::IBundleMgr; 35 36 BundleManagerHelper(); 37 38 virtual ~BundleManagerHelper(); 39 40 /** 41 * Checks whether it is system application. 42 * 43 * @param uid Indicates the uid of the application. 44 * @return Returns true if successful; false otherwise. 45 */ 46 bool CheckIsSystemAppByUid(uid_t uid); 47 48 bool CheckIsSystemAppByBundleName(const std::string &bundleName, const int32_t &userId); 49 50 /** 51 * Gets bundle name. 52 * 53 * @param uid Indicates the uid of the application. 54 * @return Returns the bundle name. 55 */ 56 std::string GetBundleName(uid_t uid); 57 58 /** 59 * Queries extension information. 60 * 61 * @param extensionInfo Indicates the extension information. 62 * @return Returns true if successful; false otherwise. 63 */ 64 bool QueryExtensionInfos(std::vector<AppExecFwk::ExtensionAbilityInfo> &extensionInfo); 65 66 /** 67 * Queries extension information by user. 68 * 69 * @param extensionInfos Indicates the extension information. 70 * @param userId Indicates the ID of user. 71 * @return Returns true if successful; false otherwise. 72 */ 73 bool QueryExtensionInfos(std::vector<AppExecFwk::ExtensionAbilityInfo> &extensionInfos, const int32_t &userId); 74 75 /** 76 * Gets res config file. 77 * 78 * @param extension Indicates the extension information. 79 * @param profileInfos Indicates the profile information. 80 * @return Returns true if successful; false otherwise. 81 */ 82 bool GetResConfigFile(const AppExecFwk::ExtensionAbilityInfo &extension, std::vector<std::string> &profileInfos); 83 84 /** 85 * Clears bundle manager helper. 86 * 87 */ 88 void ClearBundleManagerHelper(); 89 90 private: 91 bool GetBundleMgrProxy(); 92 93 private: 94 sptr<IBundleMgr> sptrBundleMgr_; 95 std::mutex mutex_; 96 sptr<BMSDeathRecipient> bmsDeath_; 97 }; 98 } // namespace EventFwk 99 } // namespace OHOS 100 101 #endif // FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_BUNDLE_MANAGER_HELPER_H