From a063b00755c324c634933e3b4b0eb34855a7debf Mon Sep 17 00:00:00 2001 From: xxxx Date: Mon, 12 Dec 2022 09:42:08 +0800 Subject: [PATCH] Revert " Match-id-b804691ca6b89759dc40c5f7c5974aff090c5c14 --- common/include/constants_dinput.h | 36 ---- common/include/input_hub.cpp | 163 ++---------------- common/include/input_hub.h | 14 +- inputdevicehandler/BUILD.gn | 2 - .../src/distributed_input_handler.cpp | 24 +-- interfaces/inner_kits/BUILD.gn | 2 - services/sink/inputcollector/BUILD.gn | 2 - .../src/distributed_input_collector.cpp | 1 - services/sink/sinkmanager/BUILD.gn | 2 - .../src/distributed_input_sink_manager.cpp | 12 +- services/sink/transport/BUILD.gn | 2 - .../src/distributed_input_sink_transport.cpp | 1 - services/source/inputinject/BUILD.gn | 6 +- .../include/distributed_input_node_manager.h | 8 +- .../inputinject/include/virtual_device.h | 16 +- .../inputinject/include/virtual_keyboard.h | 39 +++++ .../inputinject/include/virtual_mouse.h | 39 +++++ .../inputinject/include/virtual_touchpad.h | 39 +++++ .../inputinject/include/virtual_touchscreen.h | 39 +++++ .../src/distributed_input_inject.cpp | 24 +-- .../src/distributed_input_node_manager.cpp | 108 +++++------- .../source/inputinject/src/virtual_device.cpp | 46 ++--- .../inputinject/src/virtual_keyboard.cpp | 71 ++++++++ .../source/inputinject/src/virtual_mouse.cpp | 66 +++++++ .../inputinject/src/virtual_touchpad.cpp | 89 ++++++++++ .../inputinject/src/virtual_touchscreen.cpp | 127 ++++++++++++++ .../test/sourceinjectunittest/BUILD.gn | 4 + services/source/sourcemanager/BUILD.gn | 2 - .../src/distributed_input_source_manager.cpp | 8 +- .../test/sourcemanagerunittest/BUILD.gn | 4 + services/source/transport/BUILD.gn | 2 - sourcehandler/BUILD.gn | 2 - utils/include/dinput_context.h | 1 + utils/include/dinput_utils_tool.h | 8 +- utils/src/dinput_utils_tool.cpp | 33 ++-- 35 files changed, 657 insertions(+), 385 deletions(-) create mode 100644 services/source/inputinject/include/virtual_keyboard.h create mode 100644 services/source/inputinject/include/virtual_mouse.h create mode 100644 services/source/inputinject/include/virtual_touchpad.h create mode 100644 services/source/inputinject/include/virtual_touchscreen.h create mode 100644 services/source/inputinject/src/virtual_keyboard.cpp create mode 100644 services/source/inputinject/src/virtual_mouse.cpp create mode 100644 services/source/inputinject/src/virtual_touchpad.cpp create mode 100644 services/source/inputinject/src/virtual_touchscreen.cpp diff --git a/common/include/constants_dinput.h b/common/include/constants_dinput.h index 8c5b762..396d9de 100644 --- a/common/include/constants_dinput.h +++ b/common/include/constants_dinput.h @@ -148,36 +148,6 @@ namespace DistributedInput { const std::string SINK_WINDOW_SHOW_Y = "sinkWinShowY"; - const std::string DEVICE_NAME = "name"; - - const std::string PHYSICAL_PATH = "physicalPath"; - - const std::string UNIQUE_ID = "uniqueId"; - - const std::string BUS = "bus"; - - const std::string VENDOR = "vendor"; - - const std::string PRODUCT = "product"; - - const std::string VERSION = "version"; - - const std::string DESCRIPTOR = "descriptor"; - - const std::string CLASSES = "classes"; - - const std::string EVENT_TYPES = "eventTypes"; - - const std::string EVENT_KEYS = "eventKeys"; - - const std::string ABS_TYPES = "absTypes"; - - const std::string ABS_INFOS = "absInfos"; - - const std::string REL_TYPES = "relTypes"; - - const std::string PROPERTIES = "properties"; - constexpr uint32_t SCREEN_ID_DEFAULT = 0; constexpr uint32_t DEFAULT_VALUE = 0; @@ -229,12 +199,6 @@ namespace DistributedInput { uint16_t version; std::string descriptor; uint32_t classes; - std::vector eventTypes; - std::vector eventKeys; - std::vector absTypes; - std::map> absInfos; - std::vector relTypes; - std::vector properties; }; /* diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index d1ccada..672daef 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -17,16 +17,17 @@ #include #include +#include +#include +#include + #include #include -#include #include #include -#include #include #include #include -#include #include "anonymous_string.h" #include "distributed_hardware_log.h" @@ -101,7 +102,6 @@ int32_t InputHub::Release() ::close(iNotifyFd_); StopCollectInputEvents(); StopCollectInputHandler(); - sharedDHIds_.clear(); return DH_SUCCESS; } @@ -114,6 +114,7 @@ size_t InputHub::StartCollectInputEvents(RawEvent* buffer, size_t bufferSize) needToScanDevices_ = false; ScanInputDevices(DEVICE_PATH); } + { std::unique_lock deviceLock(devicesMutex_); while (!openingDevices_.empty()) { @@ -185,11 +186,9 @@ size_t InputHub::GetEvents(RawEvent* buffer, size_t bufferSize) if (!device) { continue; } - if (!sharedDHIds_[device->identifier.descriptor]) { + if (!device->isShare) { continue; } - DHLOGD("shared device dhId: %s, name: %s", GetAnonyString(device->identifier.descriptor).c_str(), - device->identifier.name.c_str()); if (eventItem.events & EPOLLIN) { event += CollectEvent(event, capacity, device, readBuffer, count); @@ -513,7 +512,7 @@ int32_t InputHub::QueryInputDeviceInfo(int fd, InputDevice& identifier) buffer[sizeof(buffer) - 1] = '\0'; identifier.name = buffer; } - DHLOGD("QueryInputDeviceInfo deviceName: %s", buffer); + // If the device is already a virtual device, don't monitor it. if (identifier.name.find(VIRTUAL_DEVICE_NAME) != std::string::npos) { return ERR_DH_INPUT_HUB_IS_VIRTUAL_DEVICE; @@ -551,127 +550,9 @@ int32_t InputHub::QueryInputDeviceInfo(int fd, InputDevice& identifier) identifier.uniqueId = buffer; } - QueryEventInfo(fd, identifier); return DH_SUCCESS; } -void InputHub::QueryEventInfo(int fd, InputDevice& identifier) -{ - DHLOGI("QueryEventInfo: devName: %s, dhId: %s!", identifier.name.c_str(), - GetAnonyString(identifier.descriptor).c_str()); - struct libevdev *dev = GetLibEvDev(fd); - if (dev == nullptr) { - DHLOGE("dev is nullptr"); - return; - } - GetEventTypes(dev, identifier); - GetEventKeys(dev, identifier); - GetABSInfo(dev, identifier); - GetRELTypes(dev, identifier); - GetProperties(dev, identifier); - libevdev_free(dev); -} - -struct libevdev* InputHub::GetLibEvDev(int fd) -{ - struct libevdev *dev = nullptr; - int rc = 1; - rc = libevdev_new_from_fd(fd, &dev); - if (rc < 0) { - DHLOGE("Failed to init libevdev (%s)", strerror(-rc)); - return nullptr; - } - return dev; -} - -void InputHub::GetEventTypes(struct libevdev* dev, InputDevice& identifier) -{ - for (uint32_t eventType = 0; eventType < EV_CNT; eventType++) { - if (!libevdev_has_event_type(dev, eventType)) { - DHLOGD("The device is not support eventType: %d", eventType); - continue; - } - DHLOGI("QueryInputDeviceInfo eventType: %d", eventType); - identifier.eventTypes.push_back(eventType); - } -} - -int32_t InputHub::GetEventKeys(struct libevdev* dev, InputDevice& identifier) -{ - if (!libevdev_has_event_type(dev, EV_KEY)) { - DHLOGE("The device doesn't has EV_KEY type!"); - return ERR_DH_INPUT_HUB_QUERY_INPUT_DEVICE_INFO_FAIL; - } - for (uint32_t eventKey = 0; eventKey < KEY_CNT; eventKey++) { - if (!libevdev_has_event_code(dev, EV_KEY, eventKey)) { - DHLOGD("The device is not support eventKey: %d", eventKey); - continue; - } - DHLOGI("QueryInputDeviceInfo eventKey: %d", eventKey); - identifier.eventKeys.push_back(eventKey); - } - return DH_SUCCESS; -} - -int32_t InputHub::GetABSInfo(struct libevdev* dev, InputDevice& identifier) -{ - if (!libevdev_has_event_type(dev, EV_ABS)) { - DHLOGE("The device doesn't has EV_ABS type!"); - return ERR_DH_INPUT_HUB_QUERY_INPUT_DEVICE_INFO_FAIL; - } - DHLOGI("The device has abs info, devName: %s, dhId: %s!", identifier.name.c_str(), - GetAnonyString(identifier.descriptor).c_str()); - for (uint32_t absType = 0; absType < ABS_CNT; absType++) { - if (!libevdev_has_event_code(dev, EV_ABS, absType)) { - DHLOGD("The device is not support absType: %d", absType); - continue; - } - DHLOGI("QueryInputDeviceInfo abs type: %d", absType); - identifier.absTypes.push_back(absType); - const struct input_absinfo *abs = libevdev_get_abs_info(dev, absType); - if (abs == nullptr) { - DHLOGE("absInfo is nullptr!"); - continue; - } - DHLOGI("QueryInputDeviceInfo abs info value: %d, min: %d, max: %d, fuzz: %d, flat: %d, res: %d", abs->value, - abs->minimum, abs->maximum, abs->fuzz, abs->flat, abs->resolution); - identifier.absInfos[absType].push_back(abs->value); - identifier.absInfos[absType].push_back(abs->minimum); - identifier.absInfos[absType].push_back(abs->maximum); - identifier.absInfos[absType].push_back(abs->fuzz); - identifier.absInfos[absType].push_back(abs->flat); - identifier.absInfos[absType].push_back(abs->resolution); - } - return DH_SUCCESS; -} - -int32_t InputHub::GetRELTypes(struct libevdev* dev, InputDevice& identifier) -{ - if (!libevdev_has_event_type(dev, EV_REL)) { - DHLOGE("The device doesn't has EV_REL type!"); - return ERR_DH_INPUT_HUB_QUERY_INPUT_DEVICE_INFO_FAIL; - } - for (uint32_t code = 0; code < REL_CNT; code++) { - if (!libevdev_has_event_code(dev, EV_REL, code)) { - DHLOGD("The device is not support eventCode: %d", code); - continue; - } - DHLOGI("QueryInputDeviceInfo rel types: %d", code); - identifier.relTypes.push_back(code); - } - return DH_SUCCESS; -} - -void InputHub::GetProperties(struct libevdev* dev, InputDevice& identifier) -{ - for (uint32_t prop = 0; prop < INPUT_PROP_CNT; prop++) { - if (libevdev_has_property(dev, prop)) { - DHLOGI("QueryInputDeviceInfo rel prop: %d", prop); - identifier.properties.push_back(prop); - } - } -} - int32_t InputHub::MakeDevice(int fd, std::unique_ptr device) { // Figure out the kinds of events the device reports. @@ -686,8 +567,8 @@ int32_t InputHub::MakeDevice(int fd, std::unique_ptr device) QueryLocalTouchScreenInfo(fd); device->classes |= INPUT_DEVICE_CLASS_TOUCH | INPUT_DEVICE_CLASS_TOUCH_MT; } else if (TestBit(BTN_TOUCH, device->keyBitmask) && - TestBit(ABS_X, device->absBitmask) && - TestBit(ABS_Y, device->absBitmask)) { + TestBit(ABS_X, device->absBitmask) && + TestBit(ABS_Y, device->absBitmask)) { QueryLocalTouchScreenInfo(fd); device->classes |= INPUT_DEVICE_CLASS_TOUCH; } @@ -720,10 +601,12 @@ int32_t InputHub::MakeDevice(int fd, std::unique_ptr device) } device->identifier.classes = device->classes; - + if (device->classes & inputTypes_) { + device->isShare = true; + } DHLOGI("inputType=%d", inputTypes_.load()); - DHLOGI("New device: fd=%d, name='%s', classes=0x%x, isShare=%d", fd, device->identifier.name.c_str(), - device->classes); + DHLOGI("New device: fd=%d, name='%s', classes=0x%x, isShare=%d", + fd, device->identifier.name.c_str(), device->classes, device->isShare); AddDeviceLocked(std::move(device)); return DH_SUCCESS; @@ -999,12 +882,9 @@ InputHub::Device* InputHub::GetDeviceByFdLocked(int fd) InputHub::Device* InputHub::GetSupportDeviceByFd(int fd) { - DHLOGI("GetSupportDeviceByFd fd: %d", fd); std::unique_lock deviceLock(devicesMutex_); for (const auto& [id, device] : devices_) { - DHLOGI("GetSupportDeviceByFd device: %d, fd: %d, path: %s, dhId: %s, classes=0x%x", id, device->fd, - device->path.c_str(), GetAnonyString(device->identifier.descriptor).c_str(), device->classes); - if (device != nullptr && device->fd == fd) { + if (device->fd == fd) { return device.get(); } } @@ -1072,14 +952,8 @@ AffectDhIds InputHub::SetSharingDevices(bool enabled, std::vector d { AffectDhIds affDhIds; std::unique_lock deviceLock(devicesMutex_); - DHLOGI("SetSharingDevices start"); for (auto dhId : dhIds) { - DHLOGI("SetSharingDevices dhId: %s, size: %d, enabled: %d", GetAnonyString(dhId).c_str(), devices_.size(), - enabled); - sharedDHIds_[dhId] = enabled; for (const auto &[id, device] : devices_) { - DHLOGI("deviceName %s ,dhId: %s ", device->identifier.name.c_str(), - GetAnonyString(device->identifier.descriptor).c_str()); if (device->identifier.descriptor == dhId) { device->isShare = enabled; DHLOGW("dhid:%s, isshare:%d", GetAnonyString(device->identifier.descriptor).c_str(), enabled); @@ -1088,7 +962,7 @@ AffectDhIds InputHub::SetSharingDevices(bool enabled, std::vector d } } } - DHLOGI("SetSharingDevices end"); + return affDhIds; } @@ -1149,9 +1023,8 @@ void InputHub::GetDevicesInfoByDhId(std::vector dhidsVec, std::map< bool InputHub::IsAllDevicesStoped() { std::unique_lock deviceLock(devicesMutex_); - for (const auto &[dhId, isShared] : sharedDHIds_) { - DHLOGI("the dhId: %s, isShared: %d", GetAnonyString(dhId).c_str(), isShared); - if (isShared) { + for (const auto &[id, device] : devices_) { + if (device->isShare) { return false; } } diff --git a/common/include/input_hub.h b/common/include/input_hub.h index 306253e..f8849b2 100644 --- a/common/include/input_hub.h +++ b/common/include/input_hub.h @@ -21,11 +21,11 @@ #include #include -#include -#include #include #include +#include + #include "constants_dinput.h" namespace OHOS { @@ -95,14 +95,7 @@ private: int32_t RefreshEpollItem(bool isSleep); int32_t OpenInputDeviceLocked(const std::string& devicePath); - int32_t QueryInputDeviceInfo(int32_t fd, InputDevice& identifier); - void QueryEventInfo(int32_t fd, InputDevice& identifier); - struct libevdev* GetLibEvDev(int32_t fd); - void GetEventTypes(struct libevdev* dev, InputDevice& identifier); - int32_t GetEventKeys(struct libevdev* dev, InputDevice& identifier); - int32_t GetABSInfo(struct libevdev* dev, InputDevice& identifier); - int32_t GetRELTypes(struct libevdev* dev, InputDevice& identifier); - void GetProperties(struct libevdev* dev, InputDevice& identifier); + int32_t QueryInputDeviceInfo(int fd, InputDevice& identifier); int32_t MakeDevice(int fd, std::unique_ptr device); void GenerateDescriptor(InputDevice& identifier) const; std::string StringPrintf(const char* format, ...) const; @@ -171,7 +164,6 @@ private: std::atomic inputTypes_; std::atomic isStartCollectEvent_; std::atomic isStartCollectHandler_; - std::unordered_map sharedDHIds_; }; } // namespace DistributedInput } // namespace DistributedHardware diff --git a/inputdevicehandler/BUILD.gn b/inputdevicehandler/BUILD.gn index f560b7e..a828abf 100755 --- a/inputdevicehandler/BUILD.gn +++ b/inputdevicehandler/BUILD.gn @@ -34,7 +34,6 @@ ohos_shared_library("libdinput_handler") { "//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk", "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", "//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include", - "//third_party/libevdev/libevdev/" ] sources = [ @@ -52,7 +51,6 @@ ohos_shared_library("libdinput_handler") { "${fwk_utils_path}:distributedhardwareutils", "${utils_path}:libdinput_utils", "//third_party/openssl:libcrypto_static", - "//third_party/libevdev:libevdev", ] external_deps = [ diff --git a/inputdevicehandler/src/distributed_input_handler.cpp b/inputdevicehandler/src/distributed_input_handler.cpp index d549aa1..b0294bf 100644 --- a/inputdevicehandler/src/distributed_input_handler.cpp +++ b/inputdevicehandler/src/distributed_input_handler.cpp @@ -57,21 +57,15 @@ void DistributedInputHandler::StructTransJson(const InputDevice& pBuf, std::stri DHLOGI("[%s] %d, %d, %d, %d, %s.\n", (pBuf.name).c_str(), pBuf.bus, pBuf.vendor, pBuf.product, pBuf.version, GetAnonyString(pBuf.descriptor).c_str()); nlohmann::json tmpJson; - tmpJson[DEVICE_NAME] = pBuf.name; - tmpJson[PHYSICAL_PATH] = pBuf.physicalPath; - tmpJson[UNIQUE_ID] = pBuf.uniqueId; - tmpJson[BUS] = pBuf.bus; - tmpJson[VENDOR] = pBuf.vendor; - tmpJson[PRODUCT] = pBuf.product; - tmpJson[VERSION] = pBuf.version; - tmpJson[DESCRIPTOR] = pBuf.descriptor; - tmpJson[CLASSES] = pBuf.classes; - tmpJson[EVENT_TYPES] = pBuf.eventTypes; - tmpJson[EVENT_KEYS] = pBuf.eventKeys; - tmpJson[ABS_TYPES] = pBuf.absTypes; - tmpJson[ABS_INFOS] = pBuf.absInfos; - tmpJson[REL_TYPES] = pBuf.relTypes; - tmpJson[PROPERTIES] = pBuf.properties; + tmpJson["name"] = pBuf.name; + tmpJson["physicalPath"] = pBuf.physicalPath; + tmpJson["uniqueId"] = pBuf.uniqueId; + tmpJson["bus"] = pBuf.bus; + tmpJson["vendor"] = pBuf.vendor; + tmpJson["product"] = pBuf.product; + tmpJson["version"] = pBuf.version; + tmpJson["descriptor"] = pBuf.descriptor; + tmpJson["classes"] = pBuf.classes; std::ostringstream stream; stream << tmpJson.dump(); diff --git a/interfaces/inner_kits/BUILD.gn b/interfaces/inner_kits/BUILD.gn index 4358fe0..95d46c3 100644 --- a/interfaces/inner_kits/BUILD.gn +++ b/interfaces/inner_kits/BUILD.gn @@ -36,7 +36,6 @@ config("input_sdk_public_config") { "//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk", "//foundation/communication/dsoftbus/interfaces/kits/bus_center", "//foundation/communication/dsoftbus/interfaces/kits/common", - "//third_party/libevdev/libevdev/" ] } ohos_shared_library("libdinput_sdk") { @@ -86,7 +85,6 @@ ohos_shared_library("libdinput_sdk") { "//base/notification/eventhandler/frameworks/eventhandler:libeventhandler", "${fwk_utils_path}:distributedhardwareutils", "${utils_path}:libdinput_utils", - "//third_party/libevdev:libevdev", ] defines = [ diff --git a/services/sink/inputcollector/BUILD.gn b/services/sink/inputcollector/BUILD.gn index 4573931..0c82693 100755 --- a/services/sink/inputcollector/BUILD.gn +++ b/services/sink/inputcollector/BUILD.gn @@ -33,7 +33,6 @@ ohos_shared_library("libdinput_collector") { "//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk", "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", "//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include", - "//third_party/libevdev/libevdev/" ] sources = [ @@ -52,7 +51,6 @@ ohos_shared_library("libdinput_collector") { "${utils_path}:libdinput_utils", "//base/notification/eventhandler/frameworks/eventhandler:libeventhandler", "//third_party/openssl:libcrypto_static", - "//third_party/libevdev:libevdev", ] external_deps = [ diff --git a/services/sink/inputcollector/src/distributed_input_collector.cpp b/services/sink/inputcollector/src/distributed_input_collector.cpp index b740aa0..3d97076 100644 --- a/services/sink/inputcollector/src/distributed_input_collector.cpp +++ b/services/sink/inputcollector/src/distributed_input_collector.cpp @@ -95,7 +95,6 @@ void *DistributedInputCollector::CollectEventsThread(void *param) void DistributedInputCollector::StartCollectEventsThread() { - DHLOGI("StartCollectEventsThread!"); while (isCollectingEvents_) { memset_s(&mEventBuffer, sizeof(mEventBuffer), 0, sizeof(mEventBuffer)); if (inputHub_ == nullptr) { diff --git a/services/sink/sinkmanager/BUILD.gn b/services/sink/sinkmanager/BUILD.gn index 2670c74..69517c1 100644 --- a/services/sink/sinkmanager/BUILD.gn +++ b/services/sink/sinkmanager/BUILD.gn @@ -48,7 +48,6 @@ ohos_shared_library("libdinput_sink") { "//drivers/peripheral/display/interfaces/include", "//drivers/peripheral/base", "//foundation/graphic/graphic_2d/utils/buffer_handle/export", - "//third_party/libevdev/libevdev/" ] sources = [ @@ -74,7 +73,6 @@ ohos_shared_library("libdinput_sink") { "//foundation/distributedhardware/distributed_input/services/sink/transport:libdinput_sink_trans", "${fwk_interfaces_path}:libdhfwk_sdk", "//foundation/window/window_manager/dm:libdm", - "//third_party/libevdev:libevdev", ] external_deps = [ diff --git a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp index 78f3d46..06cd429 100644 --- a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp +++ b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp @@ -848,32 +848,32 @@ int32_t DistributedInputSinkManager::ProjectWindowListener::ParseMessage(const s return ERR_DH_INPUT_JSON_PARSE_FAIL; } srcDeviceId = jsonObj[SOURCE_DEVICE_ID].get(); - if (!IsUInt64(jsonObj, SOURCE_WINDOW_ID)) { + if (!IsUint64(jsonObj, SOURCE_WINDOW_ID)) { DHLOGE("sourceWinId key is invalid"); return ERR_DH_INPUT_JSON_PARSE_FAIL; } srcWinId = jsonObj[SOURCE_WINDOW_ID].get(); - if (!IsUInt64(jsonObj, SINK_SHOW_WINDOW_ID)) { + if (!IsUint64(jsonObj, SINK_SHOW_WINDOW_ID)) { DHLOGE("sinkWinId key is invalid"); return ERR_DH_INPUT_JSON_PARSE_FAIL; } sinkScreenInfo.sinkShowWinId = jsonObj[SINK_SHOW_WINDOW_ID].get(); - if (!IsUInt32(jsonObj, SINK_PROJECT_SHOW_WIDTH)) { + if (!IsUint32(jsonObj, SINK_PROJECT_SHOW_WIDTH)) { DHLOGE("sourceWinHeight key is invalid"); return ERR_DH_INPUT_JSON_PARSE_FAIL; } sinkScreenInfo.sinkProjShowWidth = jsonObj[SINK_PROJECT_SHOW_WIDTH].get(); - if (!IsUInt32(jsonObj, SINK_PROJECT_SHOW_HEIGHT)) { + if (!IsUint32(jsonObj, SINK_PROJECT_SHOW_HEIGHT)) { DHLOGE("sourceWinHeight key is invalid"); return ERR_DH_INPUT_JSON_PARSE_FAIL; } sinkScreenInfo.sinkProjShowHeight = jsonObj[SINK_PROJECT_SHOW_HEIGHT].get(); - if (!IsUInt32(jsonObj, SINK_WINDOW_SHOW_X)) { + if (!IsUint32(jsonObj, SINK_WINDOW_SHOW_X)) { DHLOGE("sourceWinHeight key is invalid"); return ERR_DH_INPUT_JSON_PARSE_FAIL; } sinkScreenInfo.sinkWinShowX = jsonObj[SINK_WINDOW_SHOW_X].get(); - if (!IsUInt32(jsonObj, SINK_WINDOW_SHOW_Y)) { + if (!IsUint32(jsonObj, SINK_WINDOW_SHOW_Y)) { DHLOGE("sourceWinHeight key is invalid"); return ERR_DH_INPUT_JSON_PARSE_FAIL; } diff --git a/services/sink/transport/BUILD.gn b/services/sink/transport/BUILD.gn index c4ee990..a847b29 100644 --- a/services/sink/transport/BUILD.gn +++ b/services/sink/transport/BUILD.gn @@ -37,7 +37,6 @@ ohos_shared_library("libdinput_sink_trans") { "//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk", "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", "//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include", - "//third_party/libevdev/libevdev/" ] sources = [ @@ -59,7 +58,6 @@ ohos_shared_library("libdinput_sink_trans") { "//base/notification/eventhandler/frameworks/eventhandler:libeventhandler", "//foundation/communication/dsoftbus/sdk:softbus_client", "//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//third_party/libevdev:libevdev", ] external_deps = [ diff --git a/services/sink/transport/src/distributed_input_sink_transport.cpp b/services/sink/transport/src/distributed_input_sink_transport.cpp index bb9992f..26a0aa7 100644 --- a/services/sink/transport/src/distributed_input_sink_transport.cpp +++ b/services/sink/transport/src/distributed_input_sink_transport.cpp @@ -87,7 +87,6 @@ static void StreamReceived(int32_t sessionId, const StreamData *data, const Stre (void)param; DHLOGI("sessionId: %d", sessionId); } - DistributedInputSinkTransport &DistributedInputSinkTransport::GetInstance() { static DistributedInputSinkTransport instance; diff --git a/services/source/inputinject/BUILD.gn b/services/source/inputinject/BUILD.gn index 8872180..62c77a1 100644 --- a/services/source/inputinject/BUILD.gn +++ b/services/source/inputinject/BUILD.gn @@ -36,7 +36,6 @@ ohos_shared_library("libdinput_inject") { "//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk", "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", "//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include", - "//third_party/libevdev/libevdev/" ] sources = [ @@ -44,6 +43,10 @@ ohos_shared_library("libdinput_inject") { "src/distributed_input_inject.cpp", "src/distributed_input_node_manager.cpp", "src/virtual_device.cpp", + "src/virtual_keyboard.cpp", + "src/virtual_mouse.cpp", + "src/virtual_touchpad.cpp", + "src/virtual_touchscreen.cpp", ] defines = [ @@ -57,7 +60,6 @@ ohos_shared_library("libdinput_inject") { "${fwk_utils_path}:distributedhardwareutils", "${utils_path}:libdinput_utils", "//third_party/openssl:libcrypto_static", - "//third_party/libevdev:libevdev", ] external_deps = [ diff --git a/services/source/inputinject/include/distributed_input_node_manager.h b/services/source/inputinject/include/distributed_input_node_manager.h index 83e93b1..5644541 100644 --- a/services/source/inputinject/include/distributed_input_node_manager.h +++ b/services/source/inputinject/include/distributed_input_node_manager.h @@ -24,8 +24,6 @@ #include #include -#include "nlohmann/json.hpp" - #include "constants_dinput.h" #include "input_hub.h" #include "virtual_device.h" @@ -58,9 +56,8 @@ public: private: void AddDeviceLocked(const std::string& dhId, std::unique_ptr device); - int32_t CreateHandle(const InputDevice& inputDevice, const std::string& devId, const std::string& dhId); - void ParseInputDeviceJson(const std::string& str, InputDevice& pBuf); - void VerifyInputDevice(const nlohmann::json& inputDeviceJson, InputDevice& pBuf); + int32_t CreateHandle(InputDevice event, const std::string& devId, const std::string& dhId); + void stringTransJsonTransStruct(const std::string& str, InputDevice& pBuf); void InjectEvent(); /* the key is dhId, and the value is virtualDevice */ @@ -74,7 +71,6 @@ private: std::queue> injectQueue_; std::unique_ptr inputHub_; int32_t virtualTouchScreenFd_; - std::once_flag callOnceFlag_; }; } // namespace DistributedInput } // namespace DistributedHardware diff --git a/services/source/inputinject/include/virtual_device.h b/services/source/inputinject/include/virtual_device.h index 6bbe883..a7bc086 100644 --- a/services/source/inputinject/include/virtual_device.h +++ b/services/source/inputinject/include/virtual_device.h @@ -37,10 +37,9 @@ public: explicit VirtualDevice(const InputDevice& event); virtual ~VirtualDevice(); bool DoIoctl(int32_t fd, int32_t request, const uint32_t value); - bool CreateKey(const InputDevice& inputDevice); - void SetABSInfo(struct uinput_user_dev& inputUserDev, const InputDevice& inputDevice); + bool CreateKey(); bool SetPhys(const std::string deviceName, std::string dhId); - bool SetUp(const InputDevice& inputDevice, const std::string &devId, const std::string &dhId); + bool SetUp(const std::string &devId, const std::string &dhId); bool InjectInputEvent(const input_event &event); void SetNetWorkId(const std::string netWorkId); std::string GetNetWorkId(); @@ -48,7 +47,14 @@ public: int32_t GetDeviceFd(); uint16_t GetDeviceType(); -private: +protected: + VirtualDevice(); + virtual const std::vector& GetEventTypes() const = 0; + virtual const std::vector& GetKeys() const = 0; + virtual const std::vector& GetProperties() const = 0; + virtual const std::vector& GetAbs() const = 0; + virtual const std::vector& GetRelBits() const = 0; + int32_t fd_ = -1; std::string deviceName_; std::string netWorkId_; @@ -58,6 +64,8 @@ private: const uint16_t version_; const uint16_t classes_; struct uinput_user_dev dev_ {}; + struct uinput_abs_setup absTemp_ = {}; + std::vector absInit_; const std::string pid_ = std::to_string(getpid()); private: diff --git a/services/source/inputinject/include/virtual_keyboard.h b/services/source/inputinject/include/virtual_keyboard.h new file mode 100644 index 0000000..a2bcf5a --- /dev/null +++ b/services/source/inputinject/include/virtual_keyboard.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_VIRTUAL_KEYBOARD_H +#define OHOS_VIRTUAL_KEYBOARD_H + +#include "virtual_device.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +class VirtualKeyboard : public VirtualDevice { +public: + explicit VirtualKeyboard(const InputDevice& event); + ~VirtualKeyboard() override; +protected: + const std::vector& GetEventTypes() const override; + const std::vector& GetKeys() const override; + const std::vector& GetProperties() const override; + const std::vector& GetAbs() const override; + const std::vector& GetRelBits() const override; +}; +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS + +#endif // OHOS_VIRTUAL_KEYBOARD_H diff --git a/services/source/inputinject/include/virtual_mouse.h b/services/source/inputinject/include/virtual_mouse.h new file mode 100644 index 0000000..9f974da --- /dev/null +++ b/services/source/inputinject/include/virtual_mouse.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_VIRTUAL_MOUSE_H +#define OHOS_VIRTUAL_MOUSE_H + +#include "virtual_device.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +class VirtualMouse : public VirtualDevice { +public: + explicit VirtualMouse(const InputDevice& event); + ~VirtualMouse() override; +protected: + const std::vector& GetEventTypes() const override; + const std::vector& GetKeys() const override; + const std::vector& GetRelBits() const override; + const std::vector& GetProperties() const override; + const std::vector& GetAbs() const override; +}; +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS + +#endif // VIRTUALKEYBOARD_H diff --git a/services/source/inputinject/include/virtual_touchpad.h b/services/source/inputinject/include/virtual_touchpad.h new file mode 100644 index 0000000..11635e0 --- /dev/null +++ b/services/source/inputinject/include/virtual_touchpad.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_VIRTUAL_TOUCHPAD_H +#define OHOS_VIRTUAL_TOUCHPAD_H + +#include "virtual_device.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +class VirtualTouchpad : public VirtualDevice { +public: + explicit VirtualTouchpad(const InputDevice& event); + ~VirtualTouchpad() override; +protected: + const std::vector& GetEventTypes() const override; + const std::vector& GetKeys() const override; + const std::vector& GetAbs() const override; + const std::vector& GetProperties() const override; + const std::vector& GetRelBits() const override; +}; +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS + +#endif // OHOS_VIRTUAL_TOUCHPAD_H diff --git a/services/source/inputinject/include/virtual_touchscreen.h b/services/source/inputinject/include/virtual_touchscreen.h new file mode 100644 index 0000000..ba7645d --- /dev/null +++ b/services/source/inputinject/include/virtual_touchscreen.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_VIRTUAL_TOUCHSCREEN_H +#define OHOS_VIRTUAL_TOUCHSCREEN_H + +#include "dinput_context.h" +#include "virtual_device.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +class VirtualTouchScreen : public VirtualDevice { +public: + VirtualTouchScreen(const InputDevice& event, LocalAbsInfo& absInfo, uint32_t phyWidth, uint32_t phyHeight); + ~VirtualTouchScreen() override; +protected: + const std::vector& GetEventTypes() const override; + const std::vector& GetKeys() const override; + const std::vector& GetAbs() const override; + const std::vector& GetProperties() const override; + const std::vector& GetRelBits() const override; +}; +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/services/source/inputinject/src/distributed_input_inject.cpp b/services/source/inputinject/src/distributed_input_inject.cpp index 9d9a055..3ba943d 100644 --- a/services/source/inputinject/src/distributed_input_inject.cpp +++ b/services/source/inputinject/src/distributed_input_inject.cpp @@ -131,21 +131,15 @@ int32_t DistributedInputInject::StructTransJson(const InputDevice &pBuf, std::st DHLOGI("[%s] %d, %d, %d, %d, %s.\n", (pBuf.name).c_str(), pBuf.bus, pBuf.vendor, pBuf.product, pBuf.version, GetAnonyString(pBuf.descriptor).c_str()); nlohmann::json tmpJson; - tmpJson[DEVICE_NAME] = pBuf.name; - tmpJson[PHYSICAL_PATH] = pBuf.physicalPath; - tmpJson[UNIQUE_ID] = pBuf.uniqueId; - tmpJson[BUS] = pBuf.bus; - tmpJson[VENDOR] = pBuf.vendor; - tmpJson[PRODUCT] = pBuf.product; - tmpJson[VERSION] = pBuf.version; - tmpJson[DESCRIPTOR] = pBuf.descriptor; - tmpJson[CLASSES] = pBuf.classes; - tmpJson[EVENT_TYPES] = pBuf.eventTypes; - tmpJson[EVENT_KEYS] = pBuf.eventKeys; - tmpJson[ABS_TYPES] = pBuf.absTypes; - tmpJson[ABS_INFOS] = pBuf.absInfos; - tmpJson[REL_TYPES] = pBuf.relTypes; - tmpJson[PROPERTIES] = pBuf.properties; + tmpJson["name"] = pBuf.name; + tmpJson["physicalPath"] = pBuf.physicalPath; + tmpJson["uniqueId"] = pBuf.uniqueId; + tmpJson["bus"] = pBuf.bus; + tmpJson["vendor"] = pBuf.vendor; + tmpJson["product"] = pBuf.product; + tmpJson["version"] = pBuf.version; + tmpJson["descriptor"] = pBuf.descriptor; + tmpJson["classes"] = pBuf.classes; std::ostringstream stream; stream << tmpJson.dump(); diff --git a/services/source/inputinject/src/distributed_input_node_manager.cpp b/services/source/inputinject/src/distributed_input_node_manager.cpp index 26a64fa..48941e1 100644 --- a/services/source/inputinject/src/distributed_input_node_manager.cpp +++ b/services/source/inputinject/src/distributed_input_node_manager.cpp @@ -22,14 +22,18 @@ #include #include "anonymous_string.h" -#include "dinput_utils_tool.h" #include "distributed_hardware_log.h" +#include "nlohmann/json.hpp" #include "softbus_bus_center.h" #include "dinput_context.h" #include "dinput_errcode.h" #include "dinput_softbus_define.h" +#include "virtual_keyboard.h" +#include "virtual_mouse.h" +#include "virtual_touchpad.h" +#include "virtual_touchscreen.h" namespace OHOS { namespace DistributedHardware { @@ -57,7 +61,7 @@ int32_t DistributedInputNodeManager::openDevicesNode(const std::string& devId, c const std::string& parameters) { InputDevice event; - ParseInputDeviceJson(parameters, event); + stringTransJsonTransStruct(parameters, event); if (CreateHandle(event, devId, dhId) < 0) { return ERR_DH_INPUT_SERVER_SOURCE_OPEN_DEVICE_NODE_FAIL; } @@ -65,79 +69,55 @@ int32_t DistributedInputNodeManager::openDevicesNode(const std::string& devId, c return DH_SUCCESS; } -void DistributedInputNodeManager::ParseInputDeviceJson(const std::string& str, InputDevice& pBuf) +void DistributedInputNodeManager::stringTransJsonTransStruct(const std::string& str, InputDevice& pBuf) { - nlohmann::json inputDeviceJson = nlohmann::json::parse(str, nullptr, false); - if (inputDeviceJson.is_discarded()) { + nlohmann::json recMsg = nlohmann::json::parse(str, nullptr, false); + if (recMsg.is_discarded()) { DHLOGE("recMsg parse failed!"); return; } - VerifyInputDevice(inputDeviceJson, pBuf); + recMsg.at("name").get_to(pBuf.name); + recMsg.at("physicalPath").get_to(pBuf.physicalPath); + recMsg.at("uniqueId").get_to(pBuf.uniqueId); + recMsg.at("bus").get_to(pBuf.bus); + recMsg.at("vendor").get_to(pBuf.vendor); + recMsg.at("product").get_to(pBuf.product); + recMsg.at("version").get_to(pBuf.version); + recMsg.at("descriptor").get_to(pBuf.descriptor); + recMsg.at("classes").get_to(pBuf.classes); } -void DistributedInputNodeManager::VerifyInputDevice(const nlohmann::json& inputDeviceJson, InputDevice& pBuf) -{ - if (IsString(inputDeviceJson, DEVICE_NAME)) { - pBuf.name = inputDeviceJson[DEVICE_NAME].get(); - } - if (IsString(inputDeviceJson, PHYSICAL_PATH)) { - pBuf.physicalPath = inputDeviceJson[PHYSICAL_PATH].get(); - } - if (IsString(inputDeviceJson, UNIQUE_ID)) { - pBuf.uniqueId = inputDeviceJson[UNIQUE_ID].get(); - } - if (IsUInt16(inputDeviceJson, BUS)) { - pBuf.bus = inputDeviceJson[BUS].get(); - } - if (IsUInt16(inputDeviceJson, VENDOR)) { - pBuf.vendor = inputDeviceJson[VENDOR].get(); - } - if (IsUInt16(inputDeviceJson, PRODUCT)) { - pBuf.product = inputDeviceJson[PRODUCT].get(); - } - if (IsUInt16(inputDeviceJson, VERSION)) { - pBuf.version = inputDeviceJson[VERSION].get(); - } - if (IsString(inputDeviceJson, DESCRIPTOR)) { - pBuf.descriptor = inputDeviceJson[DESCRIPTOR].get(); - } - if (IsUInt32(inputDeviceJson, CLASSES)) { - pBuf.classes = inputDeviceJson[CLASSES].get(); - } - if (IsArray(inputDeviceJson, EVENT_TYPES)) { - pBuf.eventTypes = inputDeviceJson[EVENT_TYPES].get>(); - } - if (IsArray(inputDeviceJson, EVENT_KEYS)) { - pBuf.eventKeys = inputDeviceJson[EVENT_KEYS].get>(); - } - if (IsArray(inputDeviceJson, ABS_TYPES)) { - pBuf.absTypes = inputDeviceJson[ABS_TYPES].get>(); - } - if (IsArray(inputDeviceJson, ABS_INFOS)) { - pBuf.absInfos = inputDeviceJson[ABS_INFOS].get>>(); - } - if (IsArray(inputDeviceJson, REL_TYPES)) { - pBuf.relTypes = inputDeviceJson[REL_TYPES].get>(); - } - if (IsArray(inputDeviceJson, PROPERTIES)) { - pBuf.properties = inputDeviceJson[PROPERTIES].get>(); - } -} - -int32_t DistributedInputNodeManager::CreateHandle(const InputDevice& inputDevice, const std::string& devId, - const std::string& dhId) +int32_t DistributedInputNodeManager::CreateHandle(InputDevice event, const std::string& devId, const std::string& dhId) { std::unique_lock my_lock(operationMutex_); - std::call_once(callOnceFlag_, [this]() { inputHub_->ScanInputDevices(DEVICE_PATH); }); - std::unique_ptr virtualDevice = std::make_unique(inputDevice); + std::unique_ptr device; + if (event.classes & INPUT_DEVICE_CLASS_KEYBOARD) { + device = std::make_unique(event); + } else if (event.classes & INPUT_DEVICE_CLASS_CURSOR) { + device = std::make_unique(event); + } else if (event.classes & INPUT_DEVICE_CLASS_TOUCH_MT) { + inputHub_->ScanInputDevices(DEVICE_PATH); + LocalAbsInfo info = DInputContext::GetInstance().GetLocalTouchScreenInfo().localAbsInfo; + device = std::make_unique(event, info, info.absMtPositionXMax, info.absMtPositionYMax); + } else if (event.classes & INPUT_DEVICE_CLASS_TOUCH) { + device = std::make_unique(event); + } else { + DHLOGW("could not find the deviceType\n"); + return ERR_DH_INPUT_SERVER_SOURCE_CREATE_HANDLE_FAIL; + } - virtualDevice->SetNetWorkId(devId); + if (device == nullptr) { + DHLOGE("could not create new virtual device == null\n"); + return ERR_DH_INPUT_SERVER_SOURCE_CREATE_HANDLE_FAIL; + } - if (!virtualDevice->SetUp(inputDevice, devId, dhId)) { + device->SetNetWorkId(devId); + + if (!device->SetUp(devId, dhId)) { DHLOGE("could not create new virtual device\n"); return ERR_DH_INPUT_SERVER_SOURCE_CREATE_HANDLE_FAIL; } - AddDeviceLocked(inputDevice.descriptor, std::move(virtualDevice)); + AddDeviceLocked(event.descriptor, std::move(device)); return DH_SUCCESS; } @@ -149,8 +129,8 @@ int32_t DistributedInputNodeManager::CreateVirtualTouchScreenNode(const std::str LocalAbsInfo info = DInputContext::GetInstance().GetLocalTouchScreenInfo().localAbsInfo; DHLOGI("CreateVirtualTouchScreenNode start, dhId: %s, sourcePhyWidth: %d, sourcePhyHeight: %d", GetAnonyString(dhId).c_str(), sourcePhyWidth, sourcePhyHeight); - device = std::make_unique(info.deviceInfo); - if (!device->SetUp(info.deviceInfo, devId, dhId)) { + device = std::make_unique(info.deviceInfo, info, sourcePhyWidth - 1, sourcePhyHeight - 1); + if (!device->SetUp(devId, dhId)) { DHLOGE("Virtual touch Screen setUp fail, devId: %s, dhId: %s", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); return ERR_DH_INPUT_SERVER_SOURCE_CREATE_HANDLE_FAIL; diff --git a/services/source/inputinject/src/virtual_device.cpp b/services/source/inputinject/src/virtual_device.cpp index 444db30..c439415 100644 --- a/services/source/inputinject/src/virtual_device.cpp +++ b/services/source/inputinject/src/virtual_device.cpp @@ -26,16 +26,14 @@ namespace OHOS { namespace DistributedHardware { namespace DistributedInput { -namespace { - constexpr uint32_t ABS_MIN_POS = 1; - constexpr uint32_t ABS_MAX_POS = 2; - constexpr uint32_t ABS_FUZZ_POS = 3; - constexpr uint32_t ABS_FLAT_POS = 4; +VirtualDevice::VirtualDevice() + : deviceName_(""), netWorkId_(""), busType_(0), vendorId_(0), productId_(0), version_(0), classes_(0) +{ } + VirtualDevice::VirtualDevice(const InputDevice& event) : deviceName_(event.name), busType_(event.bus), vendorId_(event.vendor), productId_(event.product), version_(event.version), classes_(event.classes) { - DHLOGI("VirtualDevice ctor!"); } VirtualDevice::~VirtualDevice() @@ -57,7 +55,7 @@ bool VirtualDevice::DoIoctl(int32_t fd, int32_t request, const uint32_t value) return true; } -bool VirtualDevice::CreateKey(const InputDevice& inputDevice) +bool VirtualDevice::CreateKey() { auto fun = [this](int32_t uiSet, const std::vector& list) -> bool { for (uint32_t evt_type : list) { @@ -68,34 +66,20 @@ bool VirtualDevice::CreateKey(const InputDevice& inputDevice) } return true; }; + std::map> evt_type; - evt_type[UI_SET_EVBIT] = inputDevice.eventTypes; - evt_type[UI_SET_KEYBIT] = inputDevice.eventKeys; - evt_type[UI_SET_PROPBIT] = inputDevice.properties; - evt_type[UI_SET_ABSBIT] = inputDevice.absTypes; - evt_type[UI_SET_RELBIT] = inputDevice.relTypes; + evt_type[UI_SET_EVBIT] = GetEventTypes(); + evt_type[UI_SET_KEYBIT] = GetKeys(); + evt_type[UI_SET_PROPBIT] = GetProperties(); + evt_type[UI_SET_ABSBIT] = GetAbs(); + evt_type[UI_SET_RELBIT] = GetRelBits(); for (auto &it : evt_type) { if (!fun(it.first, it.second)) { return false; } } - return true; -} -void VirtualDevice::SetABSInfo(struct uinput_user_dev& inputUserDev, const InputDevice& inputDevice) -{ - DHLOGI("SetABSInfo!"); - for (const auto item : inputDevice.absInfos) { - int absCode = item.first; - std::vector absInfo = item.second; - DHLOGI("SetABSInfo nodeName: %s, absCode: %d, absMin: %d, absMax: %d, absFuzz: %d, absFlat: %d", - inputDevice.name.c_str(), absCode, absInfo[ABS_MIN_POS], absInfo[ABS_MAX_POS], absInfo[ABS_FUZZ_POS], - absInfo[ABS_FLAT_POS]); - inputUserDev.absmin[absCode] = absInfo[ABS_MIN_POS]; - inputUserDev.absmax[absCode] = absInfo[ABS_MAX_POS]; - inputUserDev.absfuzz[absCode] = absInfo[ABS_FUZZ_POS]; - inputUserDev.absflat[absCode] = absInfo[ABS_FLAT_POS]; - } + return true; } bool VirtualDevice::SetPhys(const std::string deviceName, std::string dhId) @@ -110,7 +94,7 @@ bool VirtualDevice::SetPhys(const std::string deviceName, std::string dhId) return true; } -bool VirtualDevice::SetUp(const InputDevice& inputDevice, const std::string& devId, const std::string& dhId) +bool VirtualDevice::SetUp(const std::string& devId, const std::string& dhId) { fd_ = open("/dev/uinput", O_WRONLY | O_NONBLOCK); if (fd_ < 0) { @@ -136,13 +120,11 @@ bool VirtualDevice::SetUp(const InputDevice& inputDevice, const std::string& dev return false; } - if (!CreateKey(inputDevice)) { + if (!CreateKey()) { DHLOGE("Failed to create KeyValue"); return false; } - SetABSInfo(dev_, inputDevice); - if (write(fd_, &dev_, sizeof(dev_)) < 0) { DHLOGE("Unable to set input device info"); return false; diff --git a/services/source/inputinject/src/virtual_keyboard.cpp b/services/source/inputinject/src/virtual_keyboard.cpp new file mode 100644 index 0000000..41136d3 --- /dev/null +++ b/services/source/inputinject/src/virtual_keyboard.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "virtual_keyboard.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +namespace { +const std::vector EVT_TYPES { + EV_KEY, EV_MSC, EV_LED, EV_REP, EV_SYN + }; +const std::vector KEYS { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, + 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 85, + 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, + 113, 114, 115, 116, 117, 119, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, + 137, 138, 140, 142, 150, 152, 158, 159, 161, 163, 164, 165, 166, 173, 176, 177, 178, 179, 180, 183, 184, 185, + 186, 187, 188, 189, 190, 191, 192, 193, 194, 240, 211, 213, 214, 215, 218, 220, 221, 222, 223, 226, 227, 231, + 232, 233, 236, 237, 238, 239, 242, 243, 245, 246, 247, 248, 464, 522, 523, 141, 145, 146, 147, 148, 149, 151, + 153, 154, 157, 160, 162, 170, 175, 182, 200, 201, 202, 203, 204, 205, 101, 112, 118, 120 + }; +const std::vector PROPERTIES {}; +const std::vector ABS {}; +const std::vector RELBITS {}; +} + +VirtualKeyboard::VirtualKeyboard(const InputDevice& event) : VirtualDevice(event) {} + +VirtualKeyboard::~VirtualKeyboard() {} + +const std::vector& VirtualKeyboard::GetEventTypes() const +{ + return EVT_TYPES; +} + +const std::vector& VirtualKeyboard::GetKeys() const +{ + return KEYS; +} + +const std::vector& VirtualKeyboard::GetProperties() const +{ + return PROPERTIES; +} + +const std::vector& VirtualKeyboard::GetAbs() const +{ + return ABS; +} + +const std::vector& VirtualKeyboard::GetRelBits() const +{ + return RELBITS; +} +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/source/inputinject/src/virtual_mouse.cpp b/services/source/inputinject/src/virtual_mouse.cpp new file mode 100644 index 0000000..fe063fd --- /dev/null +++ b/services/source/inputinject/src/virtual_mouse.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "virtual_mouse.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +namespace { +const std::vector EVT_TYPES { + EV_KEY, EV_REL, EV_MSC, EV_SYN + }; +const std::vector KEYS { + BTN_MOUSE, BTN_LEFT, BTN_RIGHT, BTN_MIDDLE, BTN_SIDE, BTN_EXTRA, BTN_FORWARD, BTN_BACK, BTN_TASK + }; +const std::vector PROPERTIES {}; +const std::vector ABS {}; +const std::vector RELBITS { + REL_X, REL_Y, REL_WHEEL, REL_WHEEL_HI_RES +}; +} + +VirtualMouse::VirtualMouse(const InputDevice& event) : VirtualDevice(event) {} + +VirtualMouse::~VirtualMouse() {} + +const std::vector& VirtualMouse::GetEventTypes() const +{ + return EVT_TYPES; +} + +const std::vector& VirtualMouse::GetKeys() const +{ + return KEYS; +} + +const std::vector& VirtualMouse::GetProperties() const +{ + return PROPERTIES; +} + +const std::vector& VirtualMouse::GetAbs() const +{ + return ABS; +} + +const std::vector& VirtualMouse::GetRelBits() const +{ + return RELBITS; +} +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS + diff --git a/services/source/inputinject/src/virtual_touchpad.cpp b/services/source/inputinject/src/virtual_touchpad.cpp new file mode 100644 index 0000000..1f7d206 --- /dev/null +++ b/services/source/inputinject/src/virtual_touchpad.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "virtual_touchpad.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +namespace { +const std::vector EVT_TYPES { + EV_KEY, EV_ABS + }; +const std::vector KEYS { + BTN_0, BTN_1, BTN_2, BTN_3, BTN_4, BTN_5, BTN_6, BTN_STYLUS, BTN_TOOL_PEN + }; +const std::vector PROPERTIES {}; +const std::vector ABS { + ABS_X, ABS_Y, ABS_WHEEL, ABS_MISC +}; +const std::vector RELBITS {}; +} + +VirtualTouchpad::VirtualTouchpad(const InputDevice& event) : VirtualDevice(event) +{ + const int absMaxWheel = 71; + + dev_.absmin[ABS_X] = 0; + dev_.absmax[ABS_X] = 1; + dev_.absfuzz[ABS_X] = 0; + dev_.absflat[ABS_X] = 0; + + dev_.absmin[ABS_Y] = 0; + dev_.absmax[ABS_Y] = 1; + dev_.absfuzz[ABS_Y] = 0; + dev_.absflat[ABS_Y] = 0; + + dev_.absmin[ABS_WHEEL] = 0; + dev_.absmax[ABS_WHEEL] = absMaxWheel; + dev_.absfuzz[ABS_WHEEL] = 0; + dev_.absflat[ABS_WHEEL] = 0; + + dev_.absmin[ABS_MISC] = 0; + dev_.absmax[ABS_MISC] = 0; + dev_.absfuzz[ABS_MISC] = 0; + dev_.absflat[ABS_MISC] = 0; +} + +VirtualTouchpad::~VirtualTouchpad() {} + +const std::vector& VirtualTouchpad::GetEventTypes() const +{ + return EVT_TYPES; +} + +const std::vector& VirtualTouchpad::GetKeys() const +{ + return KEYS; +} + +const std::vector& VirtualTouchpad::GetProperties() const +{ + return PROPERTIES; +} + +const std::vector& VirtualTouchpad::GetAbs() const +{ + return ABS; +} + +const std::vector& VirtualTouchpad::GetRelBits() const +{ + return RELBITS; +} +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS + diff --git a/services/source/inputinject/src/virtual_touchscreen.cpp b/services/source/inputinject/src/virtual_touchscreen.cpp new file mode 100644 index 0000000..7eb797a --- /dev/null +++ b/services/source/inputinject/src/virtual_touchscreen.cpp @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "virtual_touchscreen.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +namespace { +const std::vector EVT_TYPES { + EV_KEY, EV_ABS + }; +const std::vector KEYS { + KEY_F1, KEY_VOLUMEDOWN, KEY_VOLUMEUP, KEY_POWER, BTN_TOOL_FINGER, BTN_TOUCH, BTN_TRIGGER_HAPPY2, + BTN_TRIGGER_HAPPY3 + }; +const std::vector PROPERTIES { + INPUT_PROP_DIRECT + }; +const std::vector ABS { + ABS_X, ABS_Y, ABS_PRESSURE, ABS_MT_TOUCH_MAJOR, ABS_MT_TOUCH_MINOR, ABS_MT_ORIENTATION, ABS_MT_POSITION_X, + ABS_MT_POSITION_Y, ABS_MT_BLOB_ID, ABS_MT_TRACKING_ID, ABS_MT_PRESSURE + }; +const std::vector RELBITS {}; +} + +VirtualTouchScreen::VirtualTouchScreen(const InputDevice& event, LocalAbsInfo& absInfo, uint32_t phyWidth, + uint32_t phyHeight) : VirtualDevice(event) +{ + dev_.absmin[ABS_X] = 0; + dev_.absmax[ABS_X] = static_cast(phyWidth); + dev_.absfuzz[ABS_X] = 0; + dev_.absflat[ABS_X] = 0; + + dev_.absmin[ABS_Y] = 0; + dev_.absmax[ABS_Y] = static_cast(phyHeight); + dev_.absfuzz[ABS_Y] = 0; + dev_.absflat[ABS_Y] = 0; + + dev_.absmin[ABS_PRESSURE] = absInfo.absPressureMin; + dev_.absmax[ABS_PRESSURE] = absInfo.absPressureMax; + dev_.absfuzz[ABS_PRESSURE] = 0; + dev_.absflat[ABS_PRESSURE] = 0; + + dev_.absmin[ABS_MT_TOUCH_MAJOR] = absInfo.absMtTouchMajorMin; + dev_.absmax[ABS_MT_TOUCH_MAJOR] = absInfo.absMtTouchMajorMax; + dev_.absfuzz[ABS_MT_TOUCH_MAJOR] = 0; + dev_.absflat[ABS_MT_TOUCH_MAJOR] = 0; + + dev_.absmin[ABS_MT_TOUCH_MINOR] = absInfo.absMtTouchMinorMin; + dev_.absmax[ABS_MT_TOUCH_MINOR] = absInfo.absMtTouchMinorMax; + dev_.absfuzz[ABS_MT_TOUCH_MINOR] = 0; + dev_.absflat[ABS_MT_TOUCH_MINOR] = 0; + + dev_.absmin[ABS_MT_ORIENTATION] = absInfo.absMtOrientationMin; + dev_.absmax[ABS_MT_ORIENTATION] = absInfo.absMtOrientationMax; + dev_.absfuzz[ABS_MT_ORIENTATION] = 0; + dev_.absflat[ABS_MT_ORIENTATION] = 0; + + dev_.absmin[ABS_MT_POSITION_X] = 0; + dev_.absmax[ABS_MT_POSITION_X] = static_cast(phyWidth); + dev_.absfuzz[ABS_MT_POSITION_X] = 0; + dev_.absflat[ABS_MT_POSITION_X] = 0; + + dev_.absmin[ABS_MT_POSITION_Y] = 0; + dev_.absmax[ABS_MT_POSITION_Y] = static_cast(phyHeight); + dev_.absfuzz[ABS_MT_POSITION_Y] = 0; + dev_.absflat[ABS_MT_POSITION_Y] = 0; + + dev_.absmin[ABS_MT_BLOB_ID] = absInfo.absMtBlobIdMin; + dev_.absmax[ABS_MT_BLOB_ID] = absInfo.absMtBlobIdMax; + dev_.absfuzz[ABS_MT_BLOB_ID] = 0; + dev_.absflat[ABS_MT_BLOB_ID] = 0; + + dev_.absmin[ABS_MT_TRACKING_ID] = absInfo.absMtTrackingIdMin; + dev_.absmax[ABS_MT_TRACKING_ID] = absInfo.absMtTrackingIdMax; + dev_.absfuzz[ABS_MT_TRACKING_ID] = 0; + dev_.absflat[ABS_MT_TRACKING_ID] = 0; + + dev_.absmin[ABS_MT_PRESSURE] = absInfo.absMtPressureMin; + dev_.absmax[ABS_MT_PRESSURE] = absInfo.absMtPressureMax; + dev_.absfuzz[ABS_MT_PRESSURE] = 0; + dev_.absflat[ABS_MT_PRESSURE] = 0; +} + +VirtualTouchScreen::~VirtualTouchScreen() {} + +const std::vector& VirtualTouchScreen::GetEventTypes() const +{ + return EVT_TYPES; +} + +const std::vector& VirtualTouchScreen::GetKeys() const +{ + return KEYS; +} + +const std::vector& VirtualTouchScreen::GetProperties() const +{ + return PROPERTIES; +} + +const std::vector& VirtualTouchScreen::GetAbs() const +{ + return ABS; +} + +const std::vector& VirtualTouchScreen::GetRelBits() const +{ + return RELBITS; +} +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS + diff --git a/services/source/inputinject/test/sourceinjectunittest/BUILD.gn b/services/source/inputinject/test/sourceinjectunittest/BUILD.gn index 5a0170e..dd7ab0b 100755 --- a/services/source/inputinject/test/sourceinjectunittest/BUILD.gn +++ b/services/source/inputinject/test/sourceinjectunittest/BUILD.gn @@ -62,6 +62,10 @@ ohos_unittest("distributed_input_inner_sourceinject_test") { "//foundation/distributedhardware/distributed_input/services/source/inputinject/src/distributed_input_inject.cpp", "//foundation/distributedhardware/distributed_input/services/source/inputinject/src/distributed_input_node_manager.cpp", "//foundation/distributedhardware/distributed_input/services/source/inputinject/src/virtual_device.cpp", + "//foundation/distributedhardware/distributed_input/services/source/inputinject/src/virtual_keyboard.cpp", + "//foundation/distributedhardware/distributed_input/services/source/inputinject/src/virtual_mouse.cpp", + "//foundation/distributedhardware/distributed_input/services/source/inputinject/src/virtual_touchpad.cpp", + "//foundation/distributedhardware/distributed_input/services/source/inputinject/src/virtual_touchscreen.cpp", "distributed_input_sourceinject_test.cpp", "${common_path}/test/mock/softbus_bus_center_mock.cpp", ] diff --git a/services/source/sourcemanager/BUILD.gn b/services/source/sourcemanager/BUILD.gn index aba0d5e..848e1b0 100644 --- a/services/source/sourcemanager/BUILD.gn +++ b/services/source/sourcemanager/BUILD.gn @@ -44,7 +44,6 @@ ohos_shared_library("libdinput_source") { "//base/hiviewdfx/hisysevent/interfaces/native/innerkits/hisysevent/include", "//foundation/communication/dsoftbus/interfaces/kits/bus_center", "//foundation/communication/dsoftbus/interfaces/kits/common", - "//third_party/libevdev/libevdev/" ] sources = [ @@ -102,7 +101,6 @@ ohos_shared_library("libdinput_source") { "//foundation/distributedhardware/distributed_input/services/source/inputinject:libdinput_inject", "//foundation/distributedhardware/distributed_input/services/source/transport:libdinput_source_trans", "${fwk_interfaces_path}:libdhfwk_sdk", - "//third_party/libevdev:libevdev", ] external_deps = [ diff --git a/services/source/sourcemanager/src/distributed_input_source_manager.cpp b/services/source/sourcemanager/src/distributed_input_source_manager.cpp index 61648d3..53d51a3 100644 --- a/services/source/sourcemanager/src/distributed_input_source_manager.cpp +++ b/services/source/sourcemanager/src/distributed_input_source_manager.cpp @@ -2660,17 +2660,17 @@ int32_t DistributedInputSourceManager::StartDScreenListener::ParseMessage(const return ERR_DH_INPUT_JSON_PARSE_FAIL; } sinkDevId = jsonObj[SINK_DEVICE_ID].get(); - if (!IsUInt64(jsonObj, SOURCE_WINDOW_ID)) { + if (!IsUint64(jsonObj, SOURCE_WINDOW_ID)) { DHLOGE("sourceWinId key is invalid"); return ERR_DH_INPUT_JSON_PARSE_FAIL; } srcScreenInfo.sourceWinId = jsonObj[SOURCE_WINDOW_ID].get(); - if (!IsUInt32(jsonObj, SOURCE_WINDOW_WIDTH)) { + if (!IsUint32(jsonObj, SOURCE_WINDOW_WIDTH)) { DHLOGE("sourceWinWidth key is invalid"); return ERR_DH_INPUT_JSON_PARSE_FAIL; } srcScreenInfo.sourceWinWidth = jsonObj[SOURCE_WINDOW_WIDTH].get(); - if (!IsUInt32(jsonObj, SOURCE_WINDOW_HEIGHT)) { + if (!IsUint32(jsonObj, SOURCE_WINDOW_HEIGHT)) { DHLOGE("sourceWinHeight key is invalid"); return ERR_DH_INPUT_JSON_PARSE_FAIL; } @@ -2770,7 +2770,7 @@ int32_t DistributedInputSourceManager::StopDScreenListener::ParseMessage(const s return ERR_DH_INPUT_JSON_PARSE_FAIL; } sinkDevId = jsonObj[SINK_DEVICE_ID].get(); - if (!IsUInt64(jsonObj, SOURCE_WINDOW_ID)) { + if (!IsUint64(jsonObj, SOURCE_WINDOW_ID)) { DHLOGE("sourceWinId key is invalid"); return ERR_DH_INPUT_JSON_PARSE_FAIL; } diff --git a/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn b/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn index 225249c..cf3362d 100755 --- a/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn +++ b/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn @@ -84,6 +84,10 @@ ohos_unittest("distributed_input_sourcemanager_test") { "//foundation/distributedhardware/distributed_input/services/source/inputinject/src/distributed_input_inject.cpp", "//foundation/distributedhardware/distributed_input/services/source/inputinject/src/distributed_input_node_manager.cpp", "//foundation/distributedhardware/distributed_input/services/source/inputinject/src/virtual_device.cpp", + "//foundation/distributedhardware/distributed_input/services/source/inputinject/src/virtual_keyboard.cpp", + "//foundation/distributedhardware/distributed_input/services/source/inputinject/src/virtual_mouse.cpp", + "//foundation/distributedhardware/distributed_input/services/source/inputinject/src/virtual_touchpad.cpp", + "//foundation/distributedhardware/distributed_input/services/source/inputinject/src/virtual_touchscreen.cpp", "//foundation/distributedhardware/distributed_input/services/source/sourcemanager/src/distributed_input_source_event_handler.cpp", "//foundation/distributedhardware/distributed_input/services/source/sourcemanager/src/distributed_input_source_manager.cpp", "//foundation/distributedhardware/distributed_input/services/source/sourcemanager/src/distributed_input_source_sa_cli_mgr.cpp", diff --git a/services/source/transport/BUILD.gn b/services/source/transport/BUILD.gn index 69982d0..fca24a7 100755 --- a/services/source/transport/BUILD.gn +++ b/services/source/transport/BUILD.gn @@ -38,7 +38,6 @@ ohos_shared_library("libdinput_source_trans") { "${distributedinput_path}/inputdevicehandler/include", "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", "//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include", - "//third_party/libevdev/libevdev/" ] sources = [ "src/distributed_input_source_transport.cpp" ] @@ -57,7 +56,6 @@ ohos_shared_library("libdinput_source_trans") { "//base/notification/eventhandler/frameworks/eventhandler:libeventhandler", "//foundation/communication/dsoftbus/sdk:softbus_client", "//foundation/distributedhardware/distributed_input/services/source/inputinject:libdinput_inject", - "//third_party/libevdev:libevdev", ] external_deps = [ diff --git a/sourcehandler/BUILD.gn b/sourcehandler/BUILD.gn index 81189a8..6e61529 100644 --- a/sourcehandler/BUILD.gn +++ b/sourcehandler/BUILD.gn @@ -39,7 +39,6 @@ ohos_shared_library("libdinput_source_handler") { "${services_source_path}/inputinject/include", "//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk", "//base/hiviewdfx/hisysevent/interfaces/native/innerkits/hisysevent/include", - "//third_party/libevdev/libevdev/" ] sources = [ @@ -59,7 +58,6 @@ ohos_shared_library("libdinput_source_handler") { "${innerkits_path}:libdinput_sdk", "//base/notification/eventhandler/frameworks/eventhandler:libeventhandler", "${dfx_utils_path}:libdinput_dfx_utils", - "//third_party/libevdev:libevdev", ] external_deps = [ diff --git a/utils/include/dinput_context.h b/utils/include/dinput_context.h index 0724515..78c44e1 100644 --- a/utils/include/dinput_context.h +++ b/utils/include/dinput_context.h @@ -37,6 +37,7 @@ #include "system_ability_definition.h" #include "i_dinput_context.h" +#include "input_hub.h" namespace OHOS { namespace DistributedHardware { diff --git a/utils/include/dinput_utils_tool.h b/utils/include/dinput_utils_tool.h index 655bfe0..d9a1153 100644 --- a/utils/include/dinput_utils_tool.h +++ b/utils/include/dinput_utils_tool.h @@ -36,13 +36,11 @@ std::string GetLocalNetworkId(); std::string GetUUIDBySoftBus(const std::string &networkId); uint64_t GetCurrentTime(); std::string SetAnonyId(const std::string &message); -/* IsString, IsUInt32 and IsUInt64 are used to valid json key */ +/* IsString, IsUint32 and IsUint64 are used to valid json key */ bool IsString(const nlohmann::json& jsonObj, const std::string& key); bool IsInt32(const nlohmann::json& jsonObj, const std::string& key); -bool IsUInt16(const nlohmann::json& jsonObj, const std::string& key); -bool IsUInt32(const nlohmann::json& jsonObj, const std::string& key); -bool IsUInt64(const nlohmann::json& jsonObj, const std::string& key); -bool IsArray(const nlohmann::json& jsonObj, const std::string& key); +bool IsUint32(const nlohmann::json& jsonObj, const std::string& key); +bool IsUint64(const nlohmann::json& jsonObj, const std::string& key); std::string GetNodeDesc(std::string parameters); } // namespace DistributedInput } // namespace DistributedHardware diff --git a/utils/src/dinput_utils_tool.cpp b/utils/src/dinput_utils_tool.cpp index b380d69..4938a40 100644 --- a/utils/src/dinput_utils_tool.cpp +++ b/utils/src/dinput_utils_tool.cpp @@ -32,6 +32,10 @@ namespace OHOS { namespace DistributedHardware { namespace DistributedInput { +namespace { + const char *const DESCRIPTOR = "descriptor"; +} + DevInfo GetLocalDeviceInfo() { DevInfo devInfo{"", "", 0}; @@ -130,35 +134,20 @@ bool IsInt32(const nlohmann::json& jsonObj, const std::string& key) return res; } - -bool IsUInt16(const nlohmann::json& jsonObj, const std::string& key) -{ - bool res = jsonObj.contains(key) && jsonObj[key].is_number_unsigned() && jsonObj[key] <= UINT16_MAX; - DHLOGI("the key %s in json is %s", key.c_str(), res ? "valid" : "invalid"); - return res; -} - -bool IsUInt32(const nlohmann::json& jsonObj, const std::string& key) +bool IsUint32(const nlohmann::json& jsonObj, const std::string& key) { bool res = jsonObj.contains(key) && jsonObj[key].is_number_unsigned() && jsonObj[key] <= UINT32_MAX; DHLOGI("the key %s in json is %s", key.c_str(), res ? "valid" : "invalid"); return res; } -bool IsUInt64(const nlohmann::json& jsonObj, const std::string& key) +bool IsUint64(const nlohmann::json& jsonObj, const std::string& key) { bool res = jsonObj.contains(key) && jsonObj[key].is_number_unsigned() && jsonObj[key] <= UINT64_MAX; DHLOGI("the key %s in json is %s", key.c_str(), res ? "valid" : "invalid"); return res; } -bool IsArray(const nlohmann::json& jsonObj, const std::string& key) -{ - bool res = jsonObj.contains(key) && jsonObj[key].is_array(); - DHLOGI("the key %s in json is %s", key.c_str(), res ? "valid" : "invalid"); - return res; -} - std::string GetNodeDesc(std::string parameters) { nlohmann::json parObj = nlohmann::json::parse(parameters, nullptr, false); @@ -170,11 +159,11 @@ std::string GetNodeDesc(std::string parameters) std::string physicalPath = "N/A"; int32_t classes = -1; - if (parObj.find(DEVICE_NAME) != parObj.end() && parObj.find(PHYSICAL_PATH) != parObj.end() && - parObj.find(CLASSES) != parObj.end()) { - nodeName = parObj.at(DEVICE_NAME).get(); - physicalPath = parObj.at(PHYSICAL_PATH).get(); - classes = parObj.at(CLASSES).get(); + if (parObj.find("name") != parObj.end() && parObj.find("physicalPath") != parObj.end() && + parObj.find("classes") != parObj.end()) { + nodeName = parObj.at("name").get(); + physicalPath = parObj.at("physicalPath").get(); + classes = parObj.at("classes").get(); } return "{ nodeName: " + nodeName + ", physicalPath: " + physicalPath + ", classes: " + std::to_string(classes) + " }";