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 #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& touchInfo) = 0; 55 56 // send component info to enhance service for checking its validity 57 virtual int32_t CheckComponentInfoEnhnace(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 73 // for client 74 class SecCompClientEnhanceInterface { 75 public: 76 // preprocess component info which is send to security component service, e.g. RegisterSecurityComponent 77 virtual bool EnhanceDataPreprocess(const uintptr_t caller, std::string& componentInfo) = 0; 78 virtual bool EnhanceDataPreprocess(const uintptr_t caller, int32_t scId, std::string& componentInfo) = 0; 79 80 // regiter scid to enhance client 81 virtual void RegisterScIdEnhance(const uintptr_t caller, int32_t scId) = 0; 82 // unregiter scid to enhance client 83 virtual void UnregisterScIdEnhance(const uintptr_t caller, int32_t scId) = 0; 84 }; 85 86 class SecCompEnhanceAdapter final { 87 public: 88 static void InitEnhanceHandler(EnhanceInterfaceType type); 89 static int32_t SetEnhanceCfg(uint8_t* cfg, uint32_t cfgLen); 90 static int32_t GetPointerEventEnhanceData(void* data, uint32_t dataLen, 91 uint8_t* enhanceData, uint32_t& enHancedataLen); 92 93 static int32_t CheckExtraInfo(const SecCompClickEvent& touchInfo); 94 static int32_t EnableInputEnhance(); 95 static int32_t DisableInputEnhance(); 96 static int32_t CheckComponentInfoEnhnace(int32_t pid, std::shared_ptr<SecCompBase>& compInfo, 97 const nlohmann::json& jsonComponent); 98 static sptr<IRemoteObject> GetEnhanceRemoteObject(); 99 static void StartEnhanceService(); 100 static void ExistEnhanceService(); 101 static void NotifyProcessDied(int32_t pid); 102 103 static bool EnhanceDataPreprocess(std::string& componentInfo); 104 static bool EnhanceDataPreprocess(int32_t scId, std::string& componentInfo); 105 static void RegisterScIdEnhance(int32_t scId); 106 static void UnregisterScIdEnhance(int32_t scId); 107 108 static SecCompInputEnhanceInterface* inputHandler; 109 static bool isEnhanceInputHandlerInit; 110 111 static SecCompSrvEnhanceInterface* srvHandler; 112 static bool isEnhanceSrvHandlerInit; 113 114 static SecCompClientEnhanceInterface* clientHandler; 115 static bool isEnhanceClientHandlerInit; 116 117 static std::mutex initMtx; 118 }; 119 } // namespace SecurityComponent 120 } // namespace Security 121 } // namespace OHOS 122 #endif // SECURITY_COMPONENT_ENHANCE_ADAPTER_H 123