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 "ffrt.h" 26 #include "iremote_object.h" 27 #include "refbase.h" 28 #include "singleton.h" 29 #include "want.h" 30 31 namespace OHOS { 32 namespace EventFwk { 33 34 class BundleManagerHelper : public DelayedSingleton<BundleManagerHelper> { 35 public: 36 using IBundleMgr = OHOS::AppExecFwk::IBundleMgr; 37 38 BundleManagerHelper(); 39 40 virtual ~BundleManagerHelper(); 41 42 /** 43 * Checks whether it is system application. 44 * 45 * @param uid Indicates the uid of the application. 46 * @return Returns true if successful; false otherwise. 47 */ 48 bool CheckIsSystemAppByUid(const uid_t uid); 49 50 bool CheckIsSystemAppByBundleName(const std::string &bundleName, const int32_t &userId); 51 52 /** 53 * Gets bundle name. 54 * 55 * @param uid Indicates the uid of the application. 56 * @return Returns the bundle name. 57 */ 58 std::string GetBundleName(const uid_t uid); 59 60 /** 61 * Queries extension information. 62 * 63 * @param extensionInfo Indicates the extension information. 64 * @return Returns true if successful; false otherwise. 65 */ 66 bool QueryExtensionInfos(std::vector<AppExecFwk::ExtensionAbilityInfo> &extensionInfo); 67 68 /** 69 * Queries extension information by user. 70 * 71 * @param extensionInfos Indicates the extension information. 72 * @param userId Indicates the ID of user. 73 * @return Returns true if successful; false otherwise. 74 */ 75 bool QueryExtensionInfos(std::vector<AppExecFwk::ExtensionAbilityInfo> &extensionInfos, 76 const int32_t &userId); 77 78 /** 79 * Gets res config file. 80 * 81 * @param extension Indicates the extension information. 82 * @param profileInfos Indicates the profile information. 83 * @return Returns true if successful; false otherwise. 84 */ 85 bool GetResConfigFile(const AppExecFwk::ExtensionAbilityInfo &extension, 86 std::vector<std::string> &profileInfos); 87 88 /** 89 * Clears bundle manager helper. 90 * 91 */ 92 void ClearBundleManagerHelper(); 93 94 /** 95 * @brief Obtains information about all installed applications of current user. 96 * @param flag Indicates the flag used to specify information contained 97 * in the ApplicationInfo objects that will be returned. 98 * @param appInfos Indicates all of the obtained ApplicationInfo objects. 99 * @return Returns true if the application is successfully obtained; returns false otherwise. 100 */ 101 bool GetApplicationInfos(const AppExecFwk::ApplicationFlag &flag, 102 std::vector<AppExecFwk::ApplicationInfo> &appInfos); 103 104 int32_t GetDefaultUidByBundleName(const std::string &bundle, const int32_t userId); 105 106 private: 107 bool GetBundleMgrProxy(); 108 bool GetBundleMgrProxyAsync(); 109 bool GetBundleMgrProxyInner(bool isAsync); 110 111 private: 112 sptr<IBundleMgr> sptrBundleMgr_; 113 ffrt::mutex mutex_; 114 sptr<BMSDeathRecipient> bmsDeath_; 115 }; 116 } // namespace EventFwk 117 } // namespace OHOS 118 119 #endif // FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_BUNDLE_MANAGER_HELPER_H