diff --git a/bundle.json b/bundle.json index c997c816dd39918f0c3e2756e3a5d6bfa0b07e50..4f2d73c0fa941cb3208eb096f53cbc4d4c7d5338 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 3e2f3a6856d89e4f3ae8110edc87fc061386ae0b..85bf7979b1c8307fc6293c1722890bf612949876 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 5ce81d8e14da32156c90b810946431d1f08ec936..0ed22ed58846a91363fe3bb89a5360905eb59511 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 afe0408ee0e55952b9b740184af1bf40dd859a78..cf8a546c28ed48de7d98a676ea451ab095d5916d 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 6392778634cec00bee8b085d03bf7e69a6f5be9f..55cdeffb95ae4c98b60092022b14ffa757fa3678 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 cdaef818da25a07438ad3a56cbc64156e7122fe9..853ea92764290a1645e114ad648d238732f7aa4c 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 a1f4bee5a35755ef525d1d74b34907eab9670ea2..8fb35cd766d422c292525126e9e323ad261dc0ed 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 faff1aa1636e956c6a2c7aa07b267c264ae02dda..81c6f0f1e7618ce66c4debb018c358d8547aad7d 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",