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 BMS_SERVICES_INCLUDE_ECOLOGICAL_RULE_MANAGER_SERVICE_CLIENT_H
17 #define BMS_SERVICES_INCLUDE_ECOLOGICAL_RULE_MANAGER_SERVICE_CLIENT_H
18 #include <mutex>
19 #include "iremote_proxy.h"
20 #include "bms_ecological_rule_mgr_service_interface.h"
21 
22 namespace OHOS {
23 namespace AppExecFwk {
24 
25 using namespace std;
26 using Want = OHOS::AAFwk::Want;
27 
28 class BmsEcologicalRuleMgrServiceDeathRecipient : public IRemoteObject::DeathRecipient {
29 public:
BmsEcologicalRuleMgrServiceDeathRecipient()30     BmsEcologicalRuleMgrServiceDeathRecipient() {};
31     ~BmsEcologicalRuleMgrServiceDeathRecipient() = default;
32     void OnRemoteDied(const wptr<IRemoteObject> &object) override;
33 
34 private:
35     DISALLOW_COPY_AND_MOVE(BmsEcologicalRuleMgrServiceDeathRecipient);
36 };
37 
38 class BmsEcologicalRuleMgrServiceProxy : public OHOS::IRemoteProxy<IBmsEcologicalRuleMgrService> {
39 public:
40     explicit BmsEcologicalRuleMgrServiceProxy(const sptr<IRemoteObject> &object);
41     ~BmsEcologicalRuleMgrServiceProxy() = default;
42     DISALLOW_COPY_AND_MOVE(BmsEcologicalRuleMgrServiceProxy);
43 
44     int32_t QueryFreeInstallExperience(const Want &want, const BmsCallerInfo &callerInfo,
45         BmsExperienceRule &rule) override;
46 
47 private:
48     template <typename T> bool ReadParcelableVector(vector<T> &parcelableVector, MessageParcel &reply);
49     static inline BrokerDelegator<BmsEcologicalRuleMgrServiceProxy> delegator_;
50 };
51 
52 class BmsEcologicalRuleMgrServiceClient : public RefBase {
53 public:
54     DISALLOW_COPY_AND_MOVE(BmsEcologicalRuleMgrServiceClient);
55     static sptr<BmsEcologicalRuleMgrServiceClient> GetInstance();
56     void OnRemoteSaDied(const wptr<IRemoteObject> &object);
57     int32_t QueryFreeInstallExperience(const Want &want, const BmsCallerInfo &callerInfo, BmsExperienceRule &rule);
58 
59 private:
BmsEcologicalRuleMgrServiceClient()60     BmsEcologicalRuleMgrServiceClient() {};
61     ~BmsEcologicalRuleMgrServiceClient();
62     static sptr<IBmsEcologicalRuleMgrService> ConnectService();
63     static bool CheckConnectService();
64 
65     static mutex instanceLock_;
66     static sptr<BmsEcologicalRuleMgrServiceClient> instance_;
67     static sptr<IBmsEcologicalRuleMgrService> bmsEcologicalRuleMgrServiceProxy_;
68     static sptr<BmsEcologicalRuleMgrServiceDeathRecipient> deathRecipient_;
69 
70     static string ERMS_ORIGINAL_TARGET;
71 };
72 } // namespace AppExecFwk
73 } // namespace OHOS
74 
75 #endif // BMS_SERVICES_INCLUDE_ECOLOGICAL_RULE_MANAGER_SERVICE_CLIENT_H
76