From e7217d4642f42ba938704610af594bb85ed390c6 Mon Sep 17 00:00:00 2001 From: ldy Date: Thu, 10 Apr 2025 07:10:38 +0000 Subject: [PATCH] =?UTF-8?q?updater=20input=20hdi=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ldy --- bundle.json | 2 +- services/BUILD.gn | 4 +- services/ui/BUILD.gn | 2 +- services/ui/driver/input_event.cpp | 60 +++++++++++++--------- services/ui/driver/input_event.h | 14 ++++- services/ui/driver/keys_input_device.h | 1 - services/ui/driver/pointers_input_device.h | 1 - test/unittest/updater_ui_test/BUILD.gn | 2 +- 8 files changed, 52 insertions(+), 34 deletions(-) diff --git a/bundle.json b/bundle.json index c997c816..4f2d73c0 100644 --- a/bundle.json +++ b/bundle.json @@ -49,7 +49,7 @@ "components": [ "init", "hdc", - "drivers_peripheral_input", + "drivers_interface_input", "drivers_peripheral_partitionslot", "c_utils", "hilog", diff --git a/services/BUILD.gn b/services/BUILD.gn index 3e2f3a68..85bf7979 100755 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -100,7 +100,7 @@ ohos_static_library("libupdater_static") { "zlib:libz", ] if (updater_ui_support) { - external_deps += [ "drivers_peripheral_input:hdi_input_udriver" ] + external_deps += [ "drivers_interface_input:libinput_proxy_1.0" ] } if (updater_ui_support) { @@ -184,7 +184,7 @@ ohos_static_library("libupdater") { } if (updater_ui_support) { - external_deps += [ "drivers_peripheral_input:hdi_input_udriver" ] + external_deps += [ "drivers_interface_input:libinput_proxy_1.0" ] } if (updater_ui_support) { diff --git a/services/ui/BUILD.gn b/services/ui/BUILD.gn index 5ce81d8e..0ed22ed5 100644 --- a/services/ui/BUILD.gn +++ b/services/ui/BUILD.gn @@ -108,7 +108,7 @@ ohos_static_library("libui") { sources = [] } else { external_deps += [ - "drivers_peripheral_input:hdi_input", + "drivers_interface_input:libinput_proxy_1.0", "ui_lite:libupdater_layout", ] } diff --git a/services/ui/driver/input_event.cpp b/services/ui/driver/input_event.cpp index afe0408e..cf8a546c 100644 --- a/services/ui/driver/input_event.cpp +++ b/services/ui/driver/input_event.cpp @@ -18,7 +18,6 @@ #include "keys_input_device.h" namespace Updater { -constexpr const int MAX_INPUT_DEVICES = 32; extern "C" __attribute__((constructor)) void RegisterAddInputDeviceHelper(void) { InputEvent::GetInstance().RegisterAddInputDeviceHelper(AddInputDevice); @@ -67,56 +66,67 @@ void InputEvent::GetInputDeviceType(uint32_t devIndex, uint32_t &type) type = it->second; } -void InputEvent::ReportEventPkgCallback(const InputEventPackage **pkgs, const uint32_t count, uint32_t devIndex) +int32_t InputEvent::HdfInputEventCallback::EventPkgCallback( + const std::vector& pkgs, uint32_t devIndex) { - if (pkgs == nullptr || *pkgs == nullptr) { - return; + if (pkgs.empty()) { + LOG(WARNING) << "pkgs is empty"; + return HDF_FAILURE; } - for (uint32_t i = 0; i < count; i++) { + for (uint32_t i = 0; i < pkgs.size(); i++) { struct input_event ev = { - .type = static_cast<__u16>(pkgs[i]->type), - .code = static_cast<__u16>(pkgs[i]->code), - .value = pkgs[i]->value, + .type = static_cast<__u16>(pkgs[i].type), + .code = static_cast<__u16>(pkgs[i].code), + .value = pkgs[i].value, }; uint32_t type = 0; InputEvent::GetInstance().GetInputDeviceType(devIndex, type); InputEvent::GetInstance().HandleInputEvent(&ev, type); } - return; + return HDF_SUCCESS; +} + +int32_t InputEvent::HdfInputEventCallback::HotPlugCallback(const OHOS::HDI::Input::V1_0::HotPlugEvent &event) +{ + return HDF_SUCCESS; } int InputEvent::HdfInit() { - int ret = GetInputInterface(&inputInterface_); - if (ret != INPUT_SUCCESS) { + inputInterface_ = OHOS::HDI::Input::V1_0::IInputInterfaces::Get(true); + if (inputInterface_ == nullptr) { LOG(ERROR) << "get input driver interface failed"; - return ret; + return HDF_FAILURE; } - + sleep(1); // need wait thread running - - InputDevDesc sta[MAX_INPUT_DEVICES] = {{0}}; - ret = inputInterface_->iInputManager->ScanInputDevice(sta, MAX_INPUT_DEVICES); - if (ret != INPUT_SUCCESS) { + + std::vector sta = {}; + int ret = inputInterface_->ScanInputDevice(sta); + if (ret != HDF_SUCCESS) { LOG(ERROR) << "scan device failed"; return ret; } - - for (int i = 0; i < MAX_INPUT_DEVICES; i++) { + + for (int i = 0; i < sta.size(); i++) { uint32_t idx = sta[i].devIndex; uint32_t dev = sta[i].devType; - if ((idx == 0) || (inputInterface_->iInputManager->OpenInputDevice(idx) == INPUT_FAILURE)) { + if ((idx == 0) || (inputInterface_->OpenInputDevice(idx) == HDF_FAILURE)) { continue; } devTypeMap_.insert(std::pair(idx, dev)); - + LOG(INFO) << "hdf devType:" << dev << ", devIndex:" << idx; } - + /* first param not necessary, pass default 1 */ - callback_.EventPkgCallback = ReportEventPkgCallback; - ret = inputInterface_->iInputReporter->RegisterReportCallback(1, &callback_); - if (ret != INPUT_SUCCESS) { + callback_ = new (std::nothrow) HdfInputEventCallback(); + if (callback_ == nullptr) { + LOG(ERROR) << "callback is nullptr"; + return ret; + } + ret = inputInterface_->RegisterReportCallback(1, callback_); + if (ret != HDF_SUCCESS) { LOG(ERROR) << "register callback failed for device 1"; return ret; } diff --git a/services/ui/driver/input_event.h b/services/ui/driver/input_event.h index 63927786..55cdeffb 100644 --- a/services/ui/driver/input_event.h +++ b/services/ui/driver/input_event.h @@ -15,12 +15,12 @@ #ifndef UPDATER_UI_INPUT_EVENT_H #define UPDATER_UI_INPUT_EVENT_H #include +#include #include "common/input_device_manager.h" #include "dock/pointer_input_device.h" -#include "input_manager.h" #include "macros_updater.h" -#include #include "pointers_input_device.h" +#include "v1_0/iinput_interfaces.h" namespace Updater { using AddInputDeviceFunc = std::function; @@ -28,6 +28,14 @@ using HandlePointersEventFunc = std::function &pkgs, + uint32_t devIndex) override; + int32_t HotPlugCallback(const OHOS::HDI::Input::V1_0::HotPlugEvent &event) override; + }; void RegisterAddInputDeviceHelper(AddInputDeviceFunc ptr); void RegisterHandleEventHelper(HandlePointersEventFunc ptr); InputEvent() = default; @@ -42,6 +50,8 @@ public: int HdfInit(); private: + OHOS::sptr callback_ {nullptr}; + OHOS::sptr inputInterface_ = nullptr; IInputInterface *inputInterface_; InputEventCb callback_; std::unordered_map devTypeMap_{}; diff --git a/services/ui/driver/keys_input_device.h b/services/ui/driver/keys_input_device.h index cdaef818..853ea927 100644 --- a/services/ui/driver/keys_input_device.h +++ b/services/ui/driver/keys_input_device.h @@ -18,7 +18,6 @@ #include #include #include -#include "input_manager.h" #include "macros_updater.h" #include "dock/key_input_device.h" #include "events/key_event.h" diff --git a/services/ui/driver/pointers_input_device.h b/services/ui/driver/pointers_input_device.h index a1f4bee5..8fb35cd7 100644 --- a/services/ui/driver/pointers_input_device.h +++ b/services/ui/driver/pointers_input_device.h @@ -15,7 +15,6 @@ #ifndef UPDATER_UI_POINTERS_INPUT_DEVICE_H #define UPDATER_UI_POINTERS_INPUT_DEVICE_H #include -#include "input_manager.h" #include "macros_updater.h" #include "dock/pointer_input_device.h" #include "dock/input_device.h" diff --git a/test/unittest/updater_ui_test/BUILD.gn b/test/unittest/updater_ui_test/BUILD.gn index faff1aa1..81c6f0f1 100644 --- a/test/unittest/updater_ui_test/BUILD.gn +++ b/test/unittest/updater_ui_test/BUILD.gn @@ -98,7 +98,7 @@ ohos_unittest("ui_unittest") { "bounds_checking_function:libsec_static", "cJSON:cjson", "c_utils:utils", - "drivers_peripheral_input:hdi_input", + "drivers_interface_input:libinput_proxy_1.0", "googletest:gmock_main", "googletest:gtest_main", "hilog:libhilog", -- Gitee