• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 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 #ifndef SECURITY_COMPONENT_ENHANCE_ADAPTER_H
16 #define SECURITY_COMPONENT_ENHANCE_ADAPTER_H
17 
18 #include <mutex>
19 #include "iremote_object.h"
20 #include "nlohmann/json.hpp"
21 #include "sec_comp_base.h"
22 #include "sec_comp_info.h"
23 
24 namespace OHOS {
25 namespace Security {
26 namespace SecurityComponent {
27 enum EnhanceInterfaceType {
28     SEC_COMP_ENHANCE_INPUT_INTERFACE = 0,
29     SEC_COMP_ENHANCE_SRV_INTERFACE = 1,
30     SEC_COMP_ENHANCE_CLIENT_INTERFACE = 2,
31 };
32 
33 // for multimodalinput to add enhance data to PointerEvent
34 class SecCompInputEnhanceInterface {
35 public:
36     // for multimodalinput to set enhance cfg which is from security component enhance service
37     virtual int32_t SetEnhanceCfg(uint8_t* cfg, uint32_t cfgLen) = 0;
38 
39     // for multimodalinput to get enhance data
40     virtual int32_t GetPointerEventEnhanceData(void* data, uint32_t dataLen,
41         uint8_t* enhanceData, uint32_t& enHancedataLen) = 0;
42 };
43 
44 // for security component service to send command to enhance service
45 class SecCompSrvEnhanceInterface {
46 public:
47     // enable input enhance, then enhance service send config to multimodalinput
48     virtual int32_t EnableInputEnhance() = 0;
49 
50     // disable input enhance
51     virtual int32_t DisableInputEnhance() = 0;
52 
53     // send click event to enhance service for checking extra data validity
54     virtual int32_t CheckExtraInfo(const SecCompClickEvent& clickInfo) = 0;
55 
56     // send component info to enhance service for checking its validity
57     virtual int32_t CheckComponentInfoEnhance(int32_t pid, std::shared_ptr<SecCompBase>& compInfo,
58         const nlohmann::json& jsonComponent) = 0;
59 
60     // get RemoteObject of enhance service to connect it
61     virtual sptr<IRemoteObject> GetEnhanceRemoteObject() = 0;
62 
63     // start enhance service
64     virtual void StartEnhanceService() = 0;
65 
66     // exit enhance service
67     virtual void ExitEnhanceService() = 0;
68 
69     // notify process died
70     virtual void NotifyProcessDied(int32_t pid) = 0;
71 
72     // notify process registered
73     virtual void AddSecurityComponentProcess(int32_t pid) = 0;
74 
75     virtual bool EnhanceSrvSerialize(MessageParcel& input, MessageParcel& output) = 0;
76     virtual bool EnhanceSrvDeserialize(MessageParcel& input, MessageParcel& output,
77         MessageParcel& reply) = 0;
78 };
79 
80 // for client
81 class SecCompClientEnhanceInterface {
82 public:
83     // preprocess component info which is send to security component service, e.g. RegisterSecurityComponent
84     virtual bool EnhanceDataPreprocess(const uintptr_t caller, std::string& componentInfo) = 0;
85     virtual bool EnhanceDataPreprocess(const uintptr_t caller, int32_t scId, std::string& componentInfo) = 0;
86 
87     virtual bool EnhanceClientSerialize(const uintptr_t caller,
88         MessageParcel& input, MessageParcel& output) = 0;
89     virtual bool EnhanceClientDeserialize(const uintptr_t caller, MessageParcel& input,
90         MessageParcel& output) = 0;
91 
92     // regiter scid to enhance client
93     virtual void RegisterScIdEnhance(const uintptr_t caller, int32_t scId) = 0;
94     // unregiter scid to enhance client
95     virtual void UnregisterScIdEnhance(const uintptr_t caller, int32_t scId) = 0;
96 };
97 
98 #ifndef SEC_COMP_SERVICE_COMPILE_ENABLE
99 class SecCompEnhanceAdapter final {
100 #else
101 class __attribute__((visibility("default"))) SecCompEnhanceAdapter final {
102 #endif
103 public:
104     static void InitEnhanceHandler(EnhanceInterfaceType type);
105     static int32_t SetEnhanceCfg(uint8_t* cfg, uint32_t cfgLen);
106     static int32_t GetPointerEventEnhanceData(void* data, uint32_t dataLen,
107         uint8_t* enhanceData, uint32_t& enHancedataLen);
108 
109     static int32_t CheckExtraInfo(const SecCompClickEvent& clickInfo);
110     static int32_t EnableInputEnhance();
111     static int32_t DisableInputEnhance();
112     static int32_t CheckComponentInfoEnhance(int32_t pid, std::shared_ptr<SecCompBase>& compInfo,
113         const nlohmann::json& jsonComponent);
114     static sptr<IRemoteObject> GetEnhanceRemoteObject();
115     static void StartEnhanceService();
116     static void ExitEnhanceService();
117     static void NotifyProcessDied(int32_t pid);
118 
119     static bool EnhanceDataPreprocess(std::string& componentInfo);
120     static bool EnhanceDataPreprocess(int32_t scId, std::string& componentInfo);
121     static bool EnhanceClientSerialize(MessageParcel& input, MessageParcel& output);
122     static bool EnhanceClientDeserialize(MessageParcel& input, MessageParcel& output);
123     static void RegisterScIdEnhance(int32_t scId);
124     static void UnregisterScIdEnhance(int32_t scId);
125 
126     static void AddSecurityComponentProcess(int32_t pid);
127 
128     static bool EnhanceSrvSerialize(MessageParcel& input, MessageParcel& output);
129     static bool EnhanceSrvDeserialize(MessageParcel& input, MessageParcel& output,
130         MessageParcel& reply);
131     static __attribute__((visibility("default"))) SecCompInputEnhanceInterface* inputHandler;
132     static bool isEnhanceInputHandlerInit;
133 
134     static __attribute__((visibility("default"))) SecCompSrvEnhanceInterface* srvHandler;
135     static bool isEnhanceSrvHandlerInit;
136 
137     static __attribute__((visibility("default"))) SecCompClientEnhanceInterface* clientHandler;
138     static bool isEnhanceClientHandlerInit;
139 
140     static std::mutex initMtx;
141 };
142 typedef SecCompClientEnhanceInterface* (*EnhanceInterface) (void);
143 }  // namespace SecurityComponent
144 }  // namespace Security
145 }  // namespace OHOS
146 #endif  // SECURITY_COMPONENT_ENHANCE_ADAPTER_H
147