1 /*
2  * Copyright (c) 2021 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 UPDATE_SERVICE_STUB_H
17 #define UPDATE_SERVICE_STUB_H
18 
19 #include <functional>
20 #include <iostream>
21 #include "iremote_stub.h"
22 #include "iupdate_service.h"
23 #include "message_parcel.h"
24 #include "parcel.h"
25 
26 namespace OHOS {
27 namespace UpdateEngine {
28 class UpdateServiceStub : public IRemoteStub<IUpdateService> {
29 public:
30     UpdateServiceStub();
31     ~UpdateServiceStub() = default;
32     int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
33         MessageOption &option) override;
34 
35     using UpdateServiceStubPtr = UpdateServiceStub *;
36     using RequestFuncType = int32_t (UpdateServiceStub::*)(UpdateServiceStubPtr service,
37         MessageParcel &data, MessageParcel &reply, MessageOption &option);
38 
39     int32_t HandleRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
40                             MessageOption &option);
41 
42 private:
43     int32_t GetNewVersionStub(UpdateServiceStubPtr service,
44         MessageParcel& data, MessageParcel& reply, MessageOption &option);
45     int32_t GetNewVersionDescriptionStub(UpdateServiceStubPtr service,
46         MessageParcel& data, MessageParcel& reply, MessageOption &option);
47     int32_t GetCurrentVersionStub(UpdateServiceStubPtr service,
48         MessageParcel &data, MessageParcel &reply, MessageOption &option);
49     int32_t GetCurrentVersionDescriptionStub(UpdateServiceStubPtr service,
50         MessageParcel& data, MessageParcel& reply, MessageOption &option);
51     int32_t GetTaskInfoStub(UpdateServiceStubPtr service,
52         MessageParcel &data, MessageParcel &reply, MessageOption &option);
53     int32_t CheckNewVersionStub(UpdateServiceStubPtr service,
54         MessageParcel& data, MessageParcel& reply, MessageOption &option);
55     int32_t DownloadVersionStub(UpdateServiceStubPtr service,
56         MessageParcel &data, MessageParcel &reply, MessageOption &option);
57     int32_t PauseDownloadStub(UpdateServiceStubPtr service,
58         MessageParcel& data, MessageParcel& reply, MessageOption &option);
59     int32_t ResumeDownloadStub(UpdateServiceStubPtr service,
60         MessageParcel& data, MessageParcel& reply, MessageOption &option);
61     int32_t DoUpdateStub(UpdateServiceStubPtr service,
62         MessageParcel& data, MessageParcel& reply, MessageOption &option);
63     int32_t ClearErrorStub(UpdateServiceStubPtr service,
64         MessageParcel& data, MessageParcel& reply, MessageOption &option);
65     int32_t TerminateUpgradeStub(UpdateServiceStubPtr service,
66         MessageParcel &data, MessageParcel &reply, MessageOption &option);
67     int32_t SetUpgradePolicyStub(UpdateServiceStubPtr service,
68         MessageParcel &data, MessageParcel &reply, MessageOption &option);
69     int32_t GetUpgradePolicyStub(UpdateServiceStubPtr service,
70         MessageParcel& data, MessageParcel& reply, MessageOption &option);
71     int32_t RegisterUpdateCallbackStub(UpdateServiceStubPtr service,
72         MessageParcel& data, MessageParcel& reply, MessageOption &option);
73     int32_t UnregisterUpdateCallbackStub(UpdateServiceStubPtr service,
74         MessageParcel& data, MessageParcel& reply, MessageOption &option);
75     int32_t CancelStub(UpdateServiceStubPtr service,
76         MessageParcel& data, MessageParcel& reply, MessageOption &option);
77     int32_t FactoryResetStub(UpdateServiceStubPtr service,
78         MessageParcel& data, MessageParcel& reply, MessageOption &option);
79     int32_t ApplyNewVersionStub(UpdateServiceStubPtr service,
80         MessageParcel& data, MessageParcel& reply, MessageOption &option);
81     int32_t VerifyUpgradePackageStub(UpdateServiceStubPtr service,
82         MessageParcel& data, MessageParcel& reply, MessageOption &option);
83     bool IsCallerValid();
84     bool IsPermissionGranted(uint32_t code);
85 
86 private:
87     std::map<uint32_t, RequestFuncType> requestFuncMap_;
88 };
89 } // namespace UpdateEngine
90 } // namespace OHOS
91 #endif // UPDATE_SERVICE_STUB_H