1 /* 2 * Copyright (c) 2021-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 16 #ifndef INPUT_EVENT_DATA_TRANSFORMATION_H 17 #define INPUT_EVENT_DATA_TRANSFORMATION_H 18 19 #include "key_event.h" 20 #include "long_press_event.h" 21 #include "net_packet.h" 22 #include "pointer_event.h" 23 #include "switch_event.h" 24 25 namespace OHOS { 26 namespace MMI { 27 class InputEventDataTransformation { 28 InputEventDataTransformation() = delete; 29 DISALLOW_COPY_AND_MOVE(InputEventDataTransformation); 30 31 public: 32 static int32_t KeyEventToNetPacket(const std::shared_ptr<KeyEvent> key, NetPacket &pkt); 33 static int32_t NetPacketToKeyEvent(NetPacket &pkt, std::shared_ptr<KeyEvent> key); 34 static int32_t SwitchEventToNetPacket(const std::shared_ptr<SwitchEvent> key, NetPacket &pkt); 35 static int32_t NetPacketToSwitchEvent(NetPacket &pkt, std::shared_ptr<SwitchEvent> key); 36 static int32_t LongPressEventToNetPacket(const LongPressEvent &longPressEvent, NetPacket &pkt); 37 static int32_t NetPacketToLongPressEvent(NetPacket &pkt, LongPressEvent &longPressEvent); 38 static int32_t SerializeInputEvent(std::shared_ptr<InputEvent> event, NetPacket &pkt); 39 static int32_t DeserializeInputEvent(NetPacket &pkt, std::shared_ptr<InputEvent> event); 40 static int32_t Marshalling(std::shared_ptr<PointerEvent> event, NetPacket &pkt); 41 static int32_t Unmarshalling(NetPacket &pkt, std::shared_ptr<PointerEvent> event); 42 #ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT 43 static int32_t MarshallingEnhanceData(std::shared_ptr<PointerEvent> event, NetPacket &pkt); 44 static int32_t UnmarshallingEnhanceData(NetPacket &pkt, std::shared_ptr<PointerEvent> event); 45 static int32_t MarshallingEnhanceData(std::shared_ptr<KeyEvent> event, NetPacket &pkt); 46 static int32_t UnmarshallingEnhanceData(NetPacket &pkt, std::shared_ptr<KeyEvent> event); 47 #endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT 48 private: 49 static void SerializeFingerprint(const std::shared_ptr<PointerEvent> event, NetPacket &pkt); 50 static void SerializePointerEvent(const std::shared_ptr<PointerEvent> event, NetPacket &pkt); 51 static int32_t SerializePointerItem(NetPacket &pkt, PointerEvent::PointerItem &item); 52 static int32_t DeserializePointerItem(NetPacket &pkt, PointerEvent::PointerItem &item); 53 static void SetAxisInfo(NetPacket &pkt, std::shared_ptr<PointerEvent> event); 54 static void ReadFunctionKeys(NetPacket &pkt, std::shared_ptr<KeyEvent> key); 55 static int32_t DeserializePointerIds(std::shared_ptr<PointerEvent> event, NetPacket &pkt); 56 static int32_t DeserializePressedButtons(std::shared_ptr<PointerEvent> event, NetPacket &pkt); 57 static bool SerializeSettings(std::shared_ptr<PointerEvent> event, NetPacket &pkt); 58 static bool DeserializeSettings(NetPacket &pkt, std::shared_ptr<PointerEvent> event); 59 60 #ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT 61 static constexpr uint32_t MAX_HMAC_SIZE = 64; 62 struct SecCompPointEvent { 63 double touchX; 64 double touchY; 65 uint64_t timeStamp; 66 }; 67 #endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT 68 }; 69 } // namespace MMI 70 } // namespace OHOS 71 #endif // INPUT_EVENT_DATA_TRANSFORMATION_H 72