1 /* 2 * Copyright (c) 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 OS_ACCOUNT_SERVICE_BUNDLE_MANAGER_ADAPTER_PROXY_H 17 #define OS_ACCOUNT_SERVICE_BUNDLE_MANAGER_ADAPTER_PROXY_H 18 19 #include <string> 20 #include <vector> 21 22 #include "application_info.h" 23 #include "bundle_constants.h" 24 #include "bundle_framework_core_ipc_interface_code.h" 25 #include "bundle_installer_interface.h" 26 #include "bundle_mgr_interface.h" 27 #include "bundle_pack_info.h" 28 #include "bundle_status_callback_interface.h" 29 #include "bundle_user_mgr_interface.h" 30 #include "clean_cache_callback_interface.h" 31 #include "common_event_info.h" 32 #include "distributed_bundle_info.h" 33 #include "extension_ability_info.h" 34 #include "iremote_proxy.h" 35 #include "json_utils.h" 36 #include "permission_define.h" 37 #include "shortcut_info.h" 38 39 namespace OHOS { 40 namespace AccountSA { 41 using namespace AppExecFwk; 42 using namespace AAFwk; 43 class BundleManagerAdapterProxy : public IRemoteProxy<IBundleMgr> { 44 public: 45 explicit BundleManagerAdapterProxy(const sptr<IRemoteObject> &impl); 46 ~BundleManagerAdapterProxy() override; 47 48 /** 49 * @brief Obtains the BundleInfo based on a given bundle name through the proxy object. 50 * @param bundleName Indicates the application bundle name to be queried. 51 * @param flags Indicates the information contained in the BundleInfo object to be returned. 52 * @param bundleInfo Indicates the obtained BundleInfo object. 53 * @param userId Indicates the user ID. 54 * @return Returns true if the BundleInfo is successfully obtained; returns false otherwise. 55 */ 56 bool GetBundleInfo(const std::string &bundleName, BundleFlag flags, 57 BundleInfo &bundleInfo, int32_t userId = Constants::UNSPECIFIED_USERID) override; 58 59 /** 60 * @brief Obtains the application UID based on the given bundle name and user ID through the proxy object. 61 * @param bundleName Indicates the bundle name of the application. 62 * @param userId Indicates the user ID. 63 * @return Returns the uid if successfully obtained; returns -1 otherwise. 64 */ 65 int GetUidByBundleName(const std::string &bundleName, const int userId) override; 66 67 /** @brief Obtains the bundle name of a specified application based on the given UID through the proxy object. 68 * @param uid Indicates the uid. 69 * @param bundleName Indicates the obtained bundle name. 70 * @return Returns true if the bundle name is successfully obtained; returns false otherwise. 71 */ 72 ErrCode GetNameForUid(const int uid, std::string &bundleName) override; 73 74 /** 75 * @brief Obtains the interface used to create or delete user. 76 * @return Returns a pointer to IBundleUserMgr class if exist; returns nullptr otherwise. 77 */ 78 sptr<IBundleUserMgr> GetBundleUserMgr() override; 79 80 /** 81 * @brief Query extension info. 82 * @param Want Indicates the information of extension info. 83 * @param flag Indicates the query flag which will filter any specified stuff in the extension info. 84 * @param userId Indicates the userId in the system. 85 * @param extensionInfos Indicates the obtained extensions. 86 * @return Returns true if this function is successfully called; returns false otherwise. 87 */ 88 bool QueryExtensionAbilityInfos(const Want &want, const int32_t &flag, const int32_t &userId, 89 std::vector<ExtensionAbilityInfo> &extensionInfos) override; 90 91 bool QueryExtensionAbilityInfos(const Want &want, const ExtensionAbilityType &extensionType, 92 const int32_t &flag, const int32_t &userId, std::vector<ExtensionAbilityInfo> &extensionInfos) override; 93 94 template<typename T> 95 ErrCode GetParcelableInfosWithErrCode(BundleMgrInterfaceCode code, MessageParcel &data, 96 std::vector<T> &parcelableInfos); 97 98 bool QueryAbilityInfos( 99 const Want &want, int32_t flags, int32_t userId, std::vector<AbilityInfo> &abilityInfos) override; 100 101 private: 102 bool ParseStr(const char *buf, const int itemLen, int index, std::string &result); 103 bool ParseExtensionInfo(std::string infoStr, ExtensionAbilityInfo &extensionInfo); 104 bool ParseExtensionAbilityInfos( 105 CJsonUnique &jsonObject, std::vector<ExtensionAbilityInfo> &extensionInfos); 106 template<typename T> 107 bool ParseInfo(std::string &infoStr, T &info); 108 109 /** 110 * @brief Send a command message from the proxy object. 111 * @param code Indicates the message code to be sent. 112 * @param data Indicates the objects to be sent. 113 * @param reply Indicates the reply to be sent; 114 * @return Returns true if message send successfully; returns false otherwise. 115 */ 116 bool SendTransactCmd(BundleMgrInterfaceCode code, MessageParcel &data, MessageParcel &reply); 117 /** 118 * @brief Send a command message and then get a parcelable information object from the reply. 119 * @param code Indicates the message code to be sent. 120 * @param data Indicates the objects to be sent. 121 * @param parcelableInfo Indicates the object to be got; 122 * @return Returns true if objects get successfully; returns false otherwise. 123 */ 124 template <typename T> 125 bool GetParcelableInfo(BundleMgrInterfaceCode code, MessageParcel &data, T &parcelableInfo); 126 127 template <typename T> 128 bool GetParcelableFromAshmem(MessageParcel &reply, T &parcelableInfo); 129 130 template<typename T> 131 bool GetBigParcelableInfo( 132 BundleMgrInterfaceCode code, MessageParcel &data, T &parcelableInfo); 133 134 template <typename T> 135 ErrCode GetParcelableInfoWithErrCode(BundleMgrInterfaceCode code, MessageParcel &data, T &parcelableInfo); 136 /** 137 * @brief Send a command message and then get a vector of parcelable information objects from the reply. 138 * @param code Indicates the message code to be sent. 139 * @param data Indicates the objects to be sent. 140 * @param parcelableInfos Indicates the vector objects to be got; 141 * @return Returns true if the vector get successfully; returns false otherwise. 142 */ 143 template <typename T> 144 bool GetParcelableInfos(BundleMgrInterfaceCode code, MessageParcel &data, std::vector<T> &parcelableInfos); 145 template <typename T> 146 bool ParseAshmem(int32_t infoSize, const char* dataStr, int32_t offset, std::vector<T> &parcelableInfos); 147 /** 148 * @brief Send a command message and then get a vector of parcelable information objects from the reply Ashmem. 149 * @param code Indicates the message code to be sent. 150 * @param data Indicates the objects to be sent. 151 * @param parcelableInfos Indicates the vector objects to be got; 152 * @return Returns true if the vector get successfully; returns false otherwise. 153 */ 154 template <typename T> 155 bool GetParcelableInfosFromAshmem( 156 BundleMgrInterfaceCode code, MessageParcel &data, std::vector<T> &parcelableInfos); 157 158 template<typename T> 159 bool GetVectorFromParcelIntelligent( 160 BundleMgrInterfaceCode code, MessageParcel &data, std::vector<T> &parcelableInfos); 161 162 template<typename T> 163 ErrCode InnerGetVectorFromParcelIntelligent( 164 MessageParcel &reply, std::vector<T> &parcelableInfos); 165 166 bool SendData(void *&buffer, size_t size, const void *data); 167 bool GetData(void *&buffer, size_t size, const void *data); 168 169 template <typename T> 170 bool GetParcelInfo(BundleMgrInterfaceCode code, MessageParcel &data, T &parcelInfo); 171 172 template <typename T> 173 bool InnerGetParcelInfo(MessageParcel &reply, T &parcelInfo); 174 175 static inline BrokerDelegator<BundleManagerAdapterProxy> delegator_; 176 }; 177 } // namespace AccountSA 178 } // namespace OHOS 179 #endif // OS_ACCOUNT_SERVICE_BUNDLE_MANAGER_ADAPTER_PROXY_H 180