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 INTERFACES_INNERKITS_INCLUDE_ECOLOGICALRULEMGRSERVICE_CLIENT_H
17 #define INTERFACES_INNERKITS_INCLUDE_ECOLOGICALRULEMGRSERVICE_CLIENT_H
18 
19 #include <mutex>
20 #include "refbase.h"
21 #include "iremote_object.h"
22 #include "ecological_rule_mgr_service_interface.h"
23 
24 namespace OHOS {
25 namespace EcologicalRuleMgrService {
26 using namespace std;
27 using namespace AppExecFwk;
28 
29 class EcologicalRuleMgrServiceDeathRecipient : public IRemoteObject::DeathRecipient {
30 public:
31     EcologicalRuleMgrServiceDeathRecipient();
32     ~EcologicalRuleMgrServiceDeathRecipient() = default;
33     void OnRemoteDied(const wptr<IRemoteObject> &object) override;
34 
35 private:
36     DISALLOW_COPY_AND_MOVE(EcologicalRuleMgrServiceDeathRecipient);
37 };
38 
39 class EcologicalRuleMgrServiceClient : public RefBase {
40 public:
41     DISALLOW_COPY_AND_MOVE(EcologicalRuleMgrServiceClient);
42     static sptr<EcologicalRuleMgrServiceClient> GetInstance();
43     void OnRemoteSaDied(const wptr<IRemoteObject> &object);
44 
45     int32_t QueryFreeInstallExperience(const AAFwk::Want &want, const CallerInfo &callerInfo, ExperienceRule &rule);
46     int32_t EvaluateResolveInfos(const AAFwk::Want &want, const CallerInfo &callerInfo, int32_t type,
47         vector<AbilityInfo> &abInfos, const vector<ExtensionAbilityInfo> &extInfos = vector<ExtensionAbilityInfo>());
48     int32_t QueryStartExperience(const AAFwk::Want &want, const CallerInfo &callerInfo, ExperienceRule &rule);
49     int32_t IsSupportPublishForm(const vector<AAFwk::Want> &wants, const CallerInfo &callerInfo, bool &bSupport);
50 
51 private:
52     EcologicalRuleMgrServiceClient();
53     ~EcologicalRuleMgrServiceClient();
54     static sptr<EcologicalRuleMgrServiceInterface> ConnectService();
55     static bool CheckConnectService();
56 
57     static mutex instanceLock_;
58     static sptr<EcologicalRuleMgrServiceClient> instance_;
59     static sptr<EcologicalRuleMgrServiceInterface> ecologicalRuleMgrServiceProxy_;
60     static sptr<EcologicalRuleMgrServiceDeathRecipient> deathRecipient_;
61 
62     static string ERMS_ORIGINAL_TARGET;
63 };
64 } // namespace EcologicalRuleMgrService
65 } // namespace OHOS
66 
67 #endif // INTERFACES_INNERKITS_INCLUDE_EcologicalRuleMgrService_CLIENT_H