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 SERVICES_INCLUDE_ECOLOGICAL_RULE_MANAGER_SERVICE_PROXY_H
17 #define SERVICES_INCLUDE_ECOLOGICAL_RULE_MANAGER_SERVICE_PROXY_H
18 
19 #include <mutex>
20 #include "iremote_broker.h"
21 #include "iremote_object.h"
22 #include "iremote_proxy.h"
23 #include "ability_ecological_rule_mgr_service_interface.h"
24 
25 namespace OHOS {
26 namespace EcologicalRuleMgrService {
27 
28 using namespace std;
29 using Want = OHOS::AAFwk::Want;
30 using AbilityInfo = OHOS::AppExecFwk::AbilityInfo;
31 
32 class AbilityEcologicalRuleMgrServiceClient : public RefBase {
33 public:
34     DISALLOW_COPY_AND_MOVE(AbilityEcologicalRuleMgrServiceClient);
35     static sptr<AbilityEcologicalRuleMgrServiceClient> GetInstance();
36     void OnRemoteSaDied(const wptr<IRemoteObject> &object);
37 
38     int32_t EvaluateResolveInfos(const Want &want, const AbilityCallerInfo &callerInfo, int32_t type,
39         vector<AbilityInfo> &abInfo, const vector<AppExecFwk::ExtensionAbilityInfo> &extInfo =
40         vector<AppExecFwk::ExtensionAbilityInfo>());
41     int32_t QueryStartExperience(const Want &want, const AbilityCallerInfo &callerInfo, AbilityExperienceRule &rule);
42 
43 private:
AbilityEcologicalRuleMgrServiceClient()44     AbilityEcologicalRuleMgrServiceClient() {};
45     ~AbilityEcologicalRuleMgrServiceClient();
46     static sptr<IAbilityEcologicalRuleMgrService> ConnectService();
47     static bool CheckConnectService();
48 
49     static mutex instanceLock_;
50     static mutex proxyLock_;
51     static sptr<AbilityEcologicalRuleMgrServiceClient> instance_;
52     static sptr<IAbilityEcologicalRuleMgrService> ecologicalRuleMgrServiceProxy_;
53     static sptr<IRemoteObject::DeathRecipient> deathRecipient_;
54 
55     static string ERMS_ORIGINAL_TARGET;
56 };
57 
58 class AbilityEcologicalRuleMgrServiceDeathRecipient : public IRemoteObject::DeathRecipient {
59 public:
AbilityEcologicalRuleMgrServiceDeathRecipient()60     AbilityEcologicalRuleMgrServiceDeathRecipient() {};
61     ~AbilityEcologicalRuleMgrServiceDeathRecipient() = default;
62     void OnRemoteDied(const wptr<IRemoteObject> &object) override;
63 
64 private:
65     DISALLOW_COPY_AND_MOVE(AbilityEcologicalRuleMgrServiceDeathRecipient);
66 };
67 
68 class AbilityEcologicalRuleMgrServiceProxy : public IRemoteProxy<IAbilityEcologicalRuleMgrService> {
69 public:
70     explicit AbilityEcologicalRuleMgrServiceProxy(const sptr<IRemoteObject>& impl);
71     virtual ~AbilityEcologicalRuleMgrServiceProxy() = default;
72 
73     int32_t EvaluateResolveInfos(const Want &want, const AbilityCallerInfo &callerInfo, int32_t type,
74         vector<AbilityInfo> &abilityInfo) override;
75     int32_t QueryStartExperience(const Want &want, const AbilityCallerInfo &callerInfo,
76         AbilityExperienceRule &rule) override;
77 
78 private:
79     template <typename T> bool ReadParcelableVector(vector<T> &parcelableVector, MessageParcel &reply);
80     static inline BrokerDelegator<AbilityEcologicalRuleMgrServiceProxy> delegator_;
81 };
82 } // namespace EcologicalRuleMgrService
83 } // namespace OHOS
84 
85 #endif // SERVICES_INCLUDE_ECOLOGICAL_RULE_MANAGER_SERVICE_PROXY_H
86