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 SYS_INSTALLER_MODULE_UPDATE_STUB_H
17 #define SYS_INSTALLER_MODULE_UPDATE_STUB_H
18 
19 #include <functional>
20 #include <iostream>
21 #include <map>
22 
23 #include "imodule_update.h"
24 #include "iremote_stub.h"
25 
26 namespace OHOS {
27 namespace SysInstaller {
28 class ModuleUpdateStub : public IRemoteStub<IModuleUpdate> {
29 public:
30     using RequestFuncType = std::function<int (ModuleUpdateStub *service,
31         MessageParcel &data, MessageParcel &reply, MessageOption &option)>;
32 
33     int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
34         MessageOption &option) override;
35     ModuleUpdateStub();
36     virtual ~ModuleUpdateStub();
37 
38 private:
39     int32_t InstallModulePackageStub(ModuleUpdateStub *service,
40         MessageParcel &data, MessageParcel &reply, MessageOption &option) const;
41     int32_t UninstallModulePackageStub(ModuleUpdateStub *service,
42         MessageParcel &data, MessageParcel &reply, MessageOption &option) const;
43     int32_t GetModulePackageInfoStub(ModuleUpdateStub *service,
44         MessageParcel &data, MessageParcel &reply, MessageOption &option) const;
45     int32_t ExitModuleUpdateStub(ModuleUpdateStub *service,
46         MessageParcel &data, MessageParcel &reply, MessageOption &option) const;
47 
48     int32_t GetHmpVersionInfoStub(ModuleUpdateStub *service,
49         MessageParcel &data, MessageParcel &reply, MessageOption &option) const;
50     int32_t StartUpdateHmpPackageStub(ModuleUpdateStub *service,
51         MessageParcel &data, MessageParcel &reply, MessageOption &option) const;
52     int32_t GetHmpUpdateResultStub(ModuleUpdateStub *service,
53         MessageParcel &data, MessageParcel &reply, MessageOption &option) const;
54 
55 private:
56     bool IsPermissionGranted(void);
57     bool CheckCallingPerm(void);
58 
59     std::unordered_map<uint32_t, RequestFuncType> requestFuncMap_ {};
60 };
61 } // namespace SysInstaller
62 } // namespace OHOS
63 #endif // SYS_INSTALLER_MODULE_UPDATE_STUB_H
64