1 /*
2  * Copyright (c) 2023 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_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_BUNDLE_RESOURCE_PROXY_H
17 #define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_BUNDLE_RESOURCE_PROXY_H
18 
19 #include "bundle_resource_interface.h"
20 #include "bundle_framework_core_ipc_interface_code.h"
21 #include "iremote_proxy.h"
22 
23 namespace OHOS {
24 namespace AppExecFwk {
25 class BundleResourceProxy : public IRemoteProxy<IBundleResource> {
26 public:
27     explicit BundleResourceProxy(const sptr<IRemoteObject>& object);
28     virtual ~BundleResourceProxy() = default;
29 
30     virtual ErrCode GetBundleResourceInfo(const std::string &bundleName, const uint32_t flags,
31         BundleResourceInfo &bundleResourceInfo, const int32_t appIndex = 0) override;
32 
33     virtual ErrCode GetLauncherAbilityResourceInfo(const std::string &bundleName, const uint32_t flags,
34         std::vector<LauncherAbilityResourceInfo> &launcherAbilityResourceInfo, const int32_t appIndex = 0) override;
35 
36     virtual ErrCode GetAllBundleResourceInfo(const uint32_t flags,
37         std::vector<BundleResourceInfo> &bundleResourceInfos) override;
38 
39     virtual ErrCode GetAllLauncherAbilityResourceInfo(const uint32_t flags,
40         std::vector<LauncherAbilityResourceInfo> &launcherAbilityResourceInfos) override;
41 
42     virtual ErrCode AddResourceInfoByBundleName(const std::string &bundleName, const int32_t userId) override;
43 
44     virtual ErrCode AddResourceInfoByAbility(const std::string &bundleName, const std::string &moduleName,
45         const std::string &abilityName, const int32_t userId) override;
46 
47     virtual ErrCode DeleteResourceInfo(const std::string &key) override;
48 
49 private:
50     template<typename T>
51     ErrCode GetParcelInfo(BundleResourceInterfaceCode code, MessageParcel &data, T &parcelInfo);
52 
53     template<typename T>
54     ErrCode GetVectorParcelInfo(
55         BundleResourceInterfaceCode code, MessageParcel &data, std::vector<T> &parcelInfos);
56 
57     ErrCode GetParcelInfoFromAshMem(MessageParcel &reply, void *&data);
58 
59     bool SendRequest(BundleResourceInterfaceCode code, MessageParcel &data, MessageParcel &reply);
60 
61     static inline BrokerDelegator<BundleResourceProxy> delegator_;
62 };
63 } // AppExecFwk
64 } // OHOS
65 #endif // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_BUNDLE_RESOURCE_PROXY_H
66