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