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_ECOLOGICALRULEMANAGERSERVICE_STUB_H
17 #define SERVICES_INCLUDE_ECOLOGICALRULEMANAGERSERVICE_STUB_H
18 
19 #include <map>
20 #include <string>
21 #include <condition_variable>
22 #include <future>
23 #include "iremote_stub.h"
24 #include "ipc_skeleton.h"
25 #include "message_parcel.h"
26 #include "system_ability.h"
27 #include "ecological_rule_mgr_service_interface.h"
28 #include "access_token.h"
29 #include "accesstoken_kit.h"
30 #include "tokenid_kit.h"
31 
32 namespace OHOS {
33 namespace EcologicalRuleMgrService {
34 using namespace OHOS::AppExecFwk;
35 
36 class EcologicalRuleMgrServiceStub : public IRemoteStub<EcologicalRuleMgrServiceInterface> {
37 public:
38     using Want = OHOS::AAFwk::Want;
39     using AbilityInfo = OHOS::AppExecFwk::AbilityInfo;
40 
41     EcologicalRuleMgrServiceStub();
42     ~EcologicalRuleMgrServiceStub();
43     int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
44 
45 protected:
46     static void SendQueryFreeInstallExperienceResult(int32_t &code, bool &hasNewVersion, std::string &appUpdateInfo);
47     static void SendEvaluateResolveInfosResult(int32_t &code, bool &hasNewVersion, std::string &appUpdateInfo);
48     static void SendQueryStartExperienceResult(int32_t &code, bool &hasNewVersion, std::string &appUpdateInfo);
49     static void SendIsSupportPublishFormResult(int32_t &code, bool &hasNewVersion, std::string &appUpdateInfo);
50 
51     bool updateServiceInit_ = false;
52     std::condition_variable waitInitCondition_;
53     std::mutex waitInitMutex_;
54 
55 private:
56     using EcologicalRuleManagerServiceFuncs = int32_t (EcologicalRuleMgrServiceStub::*)(MessageParcel &data,
57         MessageParcel &reply);
58     int32_t OnQueryInitialStatus(MessageParcel &data, MessageParcel &reply);
59 
60     int32_t OnQueryFreeInstallExperienceResult(MessageParcel &data, MessageParcel &reply);
61     int32_t OnEvaluateResolveInfosResult(MessageParcel &data, MessageParcel &reply);
62     int32_t OnQueryStartExperienceResult(MessageParcel &data, MessageParcel &reply);
63     int32_t OnIsSupportPublishFormResult(MessageParcel &data, MessageParcel &reply);
64 
65     bool EnforceInterceToken(MessageParcel &data);
66     template <typename T> bool WriteParcelableVector(const std::vector<T> &parcelableVector, MessageParcel &reply);
67 
68     static std::mutex bmInstanceLock_;
69     std::map<uint32_t, EcologicalRuleManagerServiceFuncs> memberFuncMap_;
70 
71     const int32_t MAX_WANT_SIZE = 15;
72     const int32_t MAX_ABILITY_INFO_SIZE = 1000;
73 
74     bool VerifySystemApp();
75 };
76 } // EcologicalRuleMgrService
77 } // OHOS
78 
79 #endif // SERVICES_INCLUDE_ECOLOGICALRULEMGRSERVICE_STUB_H