diff --git a/BUILD.gn b/BUILD.gn index 81dbdc438607feab34cc9faf87537c333d231ae3..3213fc677979d3e44c09462aba02e48d838db7af 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -31,15 +31,7 @@ ohos_prebuilt_etc("multimodalinput.rc") { ohos_executable("uinput_inject") { install_enable = true - sources = [ - "uinput/hdf_device_event_dispatch.cpp", - "uinput/hdf_device_event_manager.cpp", - "uinput/inject_thread.cpp", - "uinput/keyboard_inject.cpp", - "uinput/virtual_device.cpp", - "uinput/virtual_keyboard.cpp", - "uinput/virtual_touch_screen.cpp", - ] + sources = uinput_inject_sources include_dirs = [ "//foundation/multimodalinput/input/util/common/include", @@ -48,7 +40,7 @@ ohos_executable("uinput_inject") { external_deps = [ "c_utils:utils", - "drivers_interface_input:hdi_input", + "drivers_interface_input:libinput_proxy_1.0", "hiviewdfx_hilog_native:libhilog", ] @@ -56,10 +48,6 @@ ohos_executable("uinput_inject") { subsystem_name = "multimodalinput" } -config("multimodalinput_mmi_public_config") { - include_dirs = [ "util/common/include/" ] -} - group("multimodalinput_mmi_base") { deps = [] } @@ -84,9 +72,6 @@ group("input_jsapi_group") { "frameworks/napi/mouse_event:mouseevent", "frameworks/napi/touch_event:touchevent", ] - if (input_feature_distributed) { - deps += [ "frameworks/napi/distributed_input:distributedinput" ] - } if (input_feature_monitor) { deps += [ "frameworks/napi/input_monitor:inputmonitor" ] } @@ -134,7 +119,7 @@ group("ut_mmi_debug_tools") { group("mmi_tests_manual") { testonly = true deps = [ - "frameworks/proxy:InputManagerManualTest", + "frameworks/proxy:InputManagerFilterManualTest", "service:TransformPointTest", ] } @@ -142,6 +127,7 @@ group("mmi_tests_manual") { group("mmi_tests") { testonly = true deps = [ + "frameworks/proxy:InputManagerManualTest", "frameworks/proxy:InputManagerTest", "frameworks/proxy:KeyEventTest", "frameworks/proxy:PointerEventTest", @@ -149,7 +135,10 @@ group("mmi_tests") { "service:ut-mmi-service-out", "test/fuzztest:test", "tools/inject_event:InjectEventTest", - "util:RunShellUtilTest", "util:ut-mmi-util-out", ] } + +group("examples_group") { + deps = [ "examples/input_device_display_bind:input_device_display_bind" ] +} diff --git a/bundle.json b/bundle.json index 103405cafba683c3d84ef1e539baaf07968c22d9..3fcd4350405565e67fdf1c690176df4627829c7d 100644 --- a/bundle.json +++ b/bundle.json @@ -62,7 +62,6 @@ "common" ], "third_party": [ - "quickjs", "node", "libuv", "json" @@ -92,7 +91,8 @@ "//third_party/mtdev:libmtdev", "//third_party/libevdev:libevdev", "//foundation/multimodalinput/input:uinput_inject", - "//foundation/multimodalinput/input:mmi_uinput.rc" + "//foundation/multimodalinput/input:mmi_uinput.rc", + "//foundation/multimodalinput/input:examples_group" ] }, "inner_kits": [ @@ -100,7 +100,7 @@ "name": "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", "header": { "header_files": [ - "proxy/include/display_info.h", + "proxy/include/window_info.h", "proxy/include/input_manager.h", "event/include/key_event.h", "event/include/pointer_event.h", diff --git a/etc/ability_launch_config.json b/etc/ability_launch_config.json new file mode 100644 index 0000000000000000000000000000000000000000..30f51eb13c5d3e63b40bc4b35c19f3a5365c47c4 --- /dev/null +++ b/etc/ability_launch_config.json @@ -0,0 +1,6 @@ +{ + "Shortkeys": [ + ], + "Sequences" : [ + ] + } \ No newline at end of file diff --git a/etc/mouse_icon/BUILD.gn b/etc/mouse_icon/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6f99ab478643c01b6e4f72ae2b2f8067a661cf19 --- /dev/null +++ b/etc/mouse_icon/BUILD.gn @@ -0,0 +1,348 @@ +# 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. + +import("//build/ohos.gni") +import("//foundation/multimodalinput/input/multimodalinput_mini.gni") + +ohos_prebuilt_etc("drawing_pointer_image_Colorsucker") { + source = "src/Colorsucker.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_Copy") { + source = "src/Copy.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_Cross") { + source = "src/Cross.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_Default") { + source = "src/Default.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_East") { + source = "src/East.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_Forbid") { + source = "src/Forbid.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_Hand_Grabbing") { + source = "src/Hand_Grabbing.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_Hand_Open") { + source = "src/Hand_Open.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_Hand_Pointing") { + source = "src/Hand_Pointing.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_Help") { + source = "src/Help.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_MID_Btn_East") { + source = "src/MID_Btn_East.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_MID_Btn_North") { + source = "src/MID_Btn_North.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_MID_Btn_North_East") { + source = "src/MID_Btn_North_East.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_MID_Btn_North_South") { + source = "src/MID_Btn_North_South.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_MID_Btn_North_South_West_East") { + source = "src/MID_Btn_North_South_West_East.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_MID_Btn_North_West") { + source = "src/MID_Btn_North_West.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_MID_Btn_South") { + source = "src/MID_Btn_South.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_MID_Btn_South_East") { + source = "src/MID_Btn_South_East.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_MID_Btn_South_West") { + source = "src/MID_Btn_South_West.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_MID_Btn_West") { + source = "src/MID_Btn_West.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_Move") { + source = "src/Move.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_North") { + source = "src/North.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_North_East") { + source = "src/North_East.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_North_East_South_West") { + source = "src/North_East_South_West.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_North_South") { + source = "src/North_South.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_North_West") { + source = "src/North_West.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_North_West_South_East") { + source = "src/North_West_South_East.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_Resize_Left_Right") { + source = "src/Resize_Left_Right.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_Resize_Up_Down") { + source = "src/Resize_Up_Down.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_Screenshot_Cross") { + source = "src/Screenshot_Cross.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_Screenshot_Cursor") { + source = "src/Screenshot_Cursor.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_South") { + source = "src/South.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_South_East") { + source = "src/South_East.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_South_West") { + source = "src/South_West.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_Text_Cursor") { + source = "src/Text_Cursor.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_West") { + source = "src/West.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_West_East") { + source = "src/West_East.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_Zoom_In") { + source = "src/Zoom_In.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("drawing_pointer_image_Zoom_Out") { + source = "src/Zoom_Out.png" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput/mouse_icon" +} + +ohos_prebuilt_etc("multimodalinput_config_ability.json") { + source = "${mmi_path}/etc/ability_launch_config.json" + part_name = "input" + subsystem_name = "multimodalinput" + relative_install_dir = "multimodalinput" +} + +ohos_prebuilt_etc("multimodalinput.para.dac") { + source = "${mmi_path}/etc/multimodalinput.para.dac" + part_name = "input" + subsystem_name = "multimodalinput" + module_install_dir = "etc/param" +} + +group("input_mouse_icon") { + deps = [ + ":drawing_pointer_image_Colorsucker", + ":drawing_pointer_image_Copy", + ":drawing_pointer_image_Cross", + ":drawing_pointer_image_Default", + ":drawing_pointer_image_East", + ":drawing_pointer_image_Forbid", + ":drawing_pointer_image_Hand_Grabbing", + ":drawing_pointer_image_Hand_Open", + ":drawing_pointer_image_Hand_Pointing", + ":drawing_pointer_image_Help", + ":drawing_pointer_image_MID_Btn_East", + ":drawing_pointer_image_MID_Btn_North", + ":drawing_pointer_image_MID_Btn_North_East", + ":drawing_pointer_image_MID_Btn_North_South", + ":drawing_pointer_image_MID_Btn_North_South_West_East", + ":drawing_pointer_image_MID_Btn_North_West", + ":drawing_pointer_image_MID_Btn_South", + ":drawing_pointer_image_MID_Btn_South_East", + ":drawing_pointer_image_MID_Btn_South_West", + ":drawing_pointer_image_MID_Btn_West", + ":drawing_pointer_image_Move", + ":drawing_pointer_image_North", + ":drawing_pointer_image_North_East", + ":drawing_pointer_image_North_East_South_West", + ":drawing_pointer_image_North_South", + ":drawing_pointer_image_North_West", + ":drawing_pointer_image_North_West_South_East", + ":drawing_pointer_image_Resize_Left_Right", + ":drawing_pointer_image_Resize_Up_Down", + ":drawing_pointer_image_Screenshot_Cross", + ":drawing_pointer_image_Screenshot_Cursor", + ":drawing_pointer_image_South", + ":drawing_pointer_image_South_East", + ":drawing_pointer_image_South_West", + ":drawing_pointer_image_Text_Cursor", + ":drawing_pointer_image_West", + ":drawing_pointer_image_West_East", + ":drawing_pointer_image_Zoom_In", + ":drawing_pointer_image_Zoom_Out", + ":multimodalinput.para.dac", + ":multimodalinput_config_ability.json", + ] +} diff --git a/util/source_icon/Colorsucker.png b/etc/mouse_icon/src/Colorsucker.png similarity index 100% rename from util/source_icon/Colorsucker.png rename to etc/mouse_icon/src/Colorsucker.png diff --git a/util/source_icon/Copy.png b/etc/mouse_icon/src/Copy.png similarity index 100% rename from util/source_icon/Copy.png rename to etc/mouse_icon/src/Copy.png diff --git a/util/source_icon/Cross.png b/etc/mouse_icon/src/Cross.png similarity index 100% rename from util/source_icon/Cross.png rename to etc/mouse_icon/src/Cross.png diff --git a/util/source_icon/Default.png b/etc/mouse_icon/src/Default.png similarity index 100% rename from util/source_icon/Default.png rename to etc/mouse_icon/src/Default.png diff --git a/util/source_icon/East.png b/etc/mouse_icon/src/East.png similarity index 100% rename from util/source_icon/East.png rename to etc/mouse_icon/src/East.png diff --git a/util/source_icon/Forbid.png b/etc/mouse_icon/src/Forbid.png similarity index 100% rename from util/source_icon/Forbid.png rename to etc/mouse_icon/src/Forbid.png diff --git a/util/source_icon/Hand_Grabbing.png b/etc/mouse_icon/src/Hand_Grabbing.png similarity index 100% rename from util/source_icon/Hand_Grabbing.png rename to etc/mouse_icon/src/Hand_Grabbing.png diff --git a/util/source_icon/Hand_Open.png b/etc/mouse_icon/src/Hand_Open.png similarity index 100% rename from util/source_icon/Hand_Open.png rename to etc/mouse_icon/src/Hand_Open.png diff --git a/util/source_icon/Hand_Pointing.png b/etc/mouse_icon/src/Hand_Pointing.png similarity index 100% rename from util/source_icon/Hand_Pointing.png rename to etc/mouse_icon/src/Hand_Pointing.png diff --git a/util/source_icon/Help.png b/etc/mouse_icon/src/Help.png similarity index 100% rename from util/source_icon/Help.png rename to etc/mouse_icon/src/Help.png diff --git a/util/source_icon/MID_Btn_East.png b/etc/mouse_icon/src/MID_Btn_East.png similarity index 100% rename from util/source_icon/MID_Btn_East.png rename to etc/mouse_icon/src/MID_Btn_East.png diff --git a/util/source_icon/MID_Btn_North.png b/etc/mouse_icon/src/MID_Btn_North.png similarity index 100% rename from util/source_icon/MID_Btn_North.png rename to etc/mouse_icon/src/MID_Btn_North.png diff --git a/util/source_icon/MID_Btn_North_East.png b/etc/mouse_icon/src/MID_Btn_North_East.png similarity index 100% rename from util/source_icon/MID_Btn_North_East.png rename to etc/mouse_icon/src/MID_Btn_North_East.png diff --git a/util/source_icon/MID_Btn_North_South.png b/etc/mouse_icon/src/MID_Btn_North_South.png similarity index 100% rename from util/source_icon/MID_Btn_North_South.png rename to etc/mouse_icon/src/MID_Btn_North_South.png diff --git a/util/source_icon/MID_Btn_North_South_West_East.png b/etc/mouse_icon/src/MID_Btn_North_South_West_East.png similarity index 100% rename from util/source_icon/MID_Btn_North_South_West_East.png rename to etc/mouse_icon/src/MID_Btn_North_South_West_East.png diff --git a/util/source_icon/MID_Btn_North_West.png b/etc/mouse_icon/src/MID_Btn_North_West.png similarity index 100% rename from util/source_icon/MID_Btn_North_West.png rename to etc/mouse_icon/src/MID_Btn_North_West.png diff --git a/util/source_icon/MID_Btn_South.png b/etc/mouse_icon/src/MID_Btn_South.png similarity index 100% rename from util/source_icon/MID_Btn_South.png rename to etc/mouse_icon/src/MID_Btn_South.png diff --git a/util/source_icon/MID_Btn_South_East.png b/etc/mouse_icon/src/MID_Btn_South_East.png similarity index 100% rename from util/source_icon/MID_Btn_South_East.png rename to etc/mouse_icon/src/MID_Btn_South_East.png diff --git a/util/source_icon/MID_Btn_South_West.png b/etc/mouse_icon/src/MID_Btn_South_West.png similarity index 100% rename from util/source_icon/MID_Btn_South_West.png rename to etc/mouse_icon/src/MID_Btn_South_West.png diff --git a/util/source_icon/MID_Btn_West.png b/etc/mouse_icon/src/MID_Btn_West.png similarity index 100% rename from util/source_icon/MID_Btn_West.png rename to etc/mouse_icon/src/MID_Btn_West.png diff --git a/util/source_icon/Move.png b/etc/mouse_icon/src/Move.png similarity index 100% rename from util/source_icon/Move.png rename to etc/mouse_icon/src/Move.png diff --git a/util/source_icon/North.png b/etc/mouse_icon/src/North.png similarity index 100% rename from util/source_icon/North.png rename to etc/mouse_icon/src/North.png diff --git a/util/source_icon/North_East.png b/etc/mouse_icon/src/North_East.png similarity index 100% rename from util/source_icon/North_East.png rename to etc/mouse_icon/src/North_East.png diff --git a/util/source_icon/North_East_South_West.png b/etc/mouse_icon/src/North_East_South_West.png similarity index 100% rename from util/source_icon/North_East_South_West.png rename to etc/mouse_icon/src/North_East_South_West.png diff --git a/util/source_icon/North_South.png b/etc/mouse_icon/src/North_South.png similarity index 100% rename from util/source_icon/North_South.png rename to etc/mouse_icon/src/North_South.png diff --git a/util/source_icon/North_West.png b/etc/mouse_icon/src/North_West.png similarity index 100% rename from util/source_icon/North_West.png rename to etc/mouse_icon/src/North_West.png diff --git a/util/source_icon/North_West_South_East.png b/etc/mouse_icon/src/North_West_South_East.png similarity index 100% rename from util/source_icon/North_West_South_East.png rename to etc/mouse_icon/src/North_West_South_East.png diff --git a/util/source_icon/Resize_Left_Right.png b/etc/mouse_icon/src/Resize_Left_Right.png similarity index 100% rename from util/source_icon/Resize_Left_Right.png rename to etc/mouse_icon/src/Resize_Left_Right.png diff --git a/util/source_icon/Resize_Up_Down.png b/etc/mouse_icon/src/Resize_Up_Down.png similarity index 100% rename from util/source_icon/Resize_Up_Down.png rename to etc/mouse_icon/src/Resize_Up_Down.png diff --git a/util/source_icon/Screenshot_Cross.png b/etc/mouse_icon/src/Screenshot_Cross.png similarity index 100% rename from util/source_icon/Screenshot_Cross.png rename to etc/mouse_icon/src/Screenshot_Cross.png diff --git a/util/source_icon/Screenshot_Cursor.png b/etc/mouse_icon/src/Screenshot_Cursor.png similarity index 100% rename from util/source_icon/Screenshot_Cursor.png rename to etc/mouse_icon/src/Screenshot_Cursor.png diff --git a/util/source_icon/South.png b/etc/mouse_icon/src/South.png similarity index 100% rename from util/source_icon/South.png rename to etc/mouse_icon/src/South.png diff --git a/util/source_icon/South_East.png b/etc/mouse_icon/src/South_East.png similarity index 100% rename from util/source_icon/South_East.png rename to etc/mouse_icon/src/South_East.png diff --git a/util/source_icon/South_West.png b/etc/mouse_icon/src/South_West.png similarity index 100% rename from util/source_icon/South_West.png rename to etc/mouse_icon/src/South_West.png diff --git a/util/source_icon/Text_Cursor.png b/etc/mouse_icon/src/Text_Cursor.png similarity index 100% rename from util/source_icon/Text_Cursor.png rename to etc/mouse_icon/src/Text_Cursor.png diff --git a/util/source_icon/West.png b/etc/mouse_icon/src/West.png similarity index 100% rename from util/source_icon/West.png rename to etc/mouse_icon/src/West.png diff --git a/util/source_icon/West_East.png b/etc/mouse_icon/src/West_East.png similarity index 100% rename from util/source_icon/West_East.png rename to etc/mouse_icon/src/West_East.png diff --git a/util/source_icon/Zoom_In.png b/etc/mouse_icon/src/Zoom_In.png similarity index 100% rename from util/source_icon/Zoom_In.png rename to etc/mouse_icon/src/Zoom_In.png diff --git a/util/source_icon/Zoom_Out.png b/etc/mouse_icon/src/Zoom_Out.png similarity index 100% rename from util/source_icon/Zoom_Out.png rename to etc/mouse_icon/src/Zoom_Out.png diff --git a/patch/diff_mtdev_hdf/BUILD.gn b/examples/input_device_display_bind/BUILD.gn similarity index 30% rename from patch/diff_mtdev_hdf/BUILD.gn rename to examples/input_device_display_bind/BUILD.gn index 5f51caf69c8ac29cf09b9f18c0aa24866b47d710..b3d665d89442fd958b10ef9c1d88e47ad9dbcc72 100644 --- a/patch/diff_mtdev_hdf/BUILD.gn +++ b/examples/input_device_display_bind/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# 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 @@ -13,73 +13,16 @@ import("//build/ohos.gni") -gen_src_dir = "//third_party/mtdev" -gen_dst_dir = root_out_dir + "/diff_mtdev_hdf" -patches_root_dir = "//foundation/multimodalinput/input/patch" -build_gn_dir = "$patches_root_dir/diff_mtdev_hdf" +ohos_executable("input_device_display_bind") { + sources = [ "src/input_device_display_bind.cpp" ] -action("apply_patch") { - visibility = [ ":*" ] - script = "$patches_root_dir/apply_patch.sh" - inputs = [ "$gen_src_dir" ] - outputs = [ - "$gen_dst_dir/include", - "$gen_dst_dir/src", - "$gen_dst_dir/src/caps.c", - "$gen_dst_dir/src/core.c", - "$gen_dst_dir/src/iobuf.c", - "$gen_dst_dir/src/match.c", - "$gen_dst_dir/src/match_four.c", - ] - args = [ - rebase_path(gen_src_dir, root_build_dir), - rebase_path(gen_dst_dir, root_build_dir), - rebase_path(build_gn_dir, root_build_dir), - ] -} - -config("libmtdev_config") { - visibility = [ ":*" ] - - include_dirs = [ "$gen_dst_dir/src" ] - - cflags = [ - "-Wno-unused-parameter", - "-Wno-sign-compare", - ] -} - -config("libmtdev_public_config") { - include_dirs = [ "$gen_dst_dir/include" ] - - cflags = [] -} + include_dirs = [] -ohos_source_set("patch_gen_mtdev-third") { - sources = [ - "$gen_dst_dir/src/caps.c", - "$gen_dst_dir/src/core.c", - "$gen_dst_dir/src/iobuf.c", - "$gen_dst_dir/src/match.c", - "$gen_dst_dir/src/match_four.c", + deps = [ + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", + "//foundation/multimodalinput/input/util:libmmi-util", ] - configs = [ ":libmtdev_config" ] - - deps = [ ":apply_patch" ] - - public_deps = [] -} - -ohos_shared_library("libmtdev-hdf") { - sources = [] - - configs = [ ":libmtdev_config" ] - - deps = [] - - public_deps = [ ":patch_gen_mtdev-third" ] - - part_name = "input" subsystem_name = "multimodalinput" + part_name = "input" } diff --git a/examples/input_device_display_bind/src/input_device_display_bind.cpp b/examples/input_device_display_bind/src/input_device_display_bind.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a17e2aacdf98bf1e3b206b548bec1cf5f6be0958 --- /dev/null +++ b/examples/input_device_display_bind/src/input_device_display_bind.cpp @@ -0,0 +1,121 @@ +/* + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "input_manager.h" + +void Help(const std::string title = {}) +{ + std::cout << title << std::endl; + printf( +"Usage\n" +"-q --query Query input device and display infomation\n" +"-s --set 'inputDeivceId displayId' Query input device and display infomation\n" + ); +} + +int main(int argc, char *argv[]) +{ + struct option headOptions[] = { + {"query", no_argument, NULL, 'q'}, + {"set", required_argument, NULL, 's'}, + {"help", no_argument, NULL, 'h'}, + {NULL, 0, NULL, 0} + }; + + if (argc < 2) { + Help(); + return 0; + } + + int32_t optionIndex = 0; + optind = 0; + int32_t c = 0; + if ((c = getopt_long(argc, argv, "qs:h?", headOptions, &optionIndex)) != -1) { + switch (c) { + case 'q': { + printf("query\n"); + OHOS::MMI::DisplayBindInfos infos; + auto ret = OHOS::MMI::InputManager::GetInstance()->GetDisplayBindInfo(infos); + if (ret != 0) { + printf("Get display bind info failed.\n"); + return -1; + } + std::vector> arrStrings; + std::array arr0 = {"No.", "Input device Id", "Input device Name", "Display id", "Display name"}; + arrStrings.push_back(arr0); + for (size_t i = 0; i < infos.size(); ++i) { + const auto &info = infos[i]; + std::array arr; + arr[0] = std::to_string(i + 1); + arr[1] = (info.inputDeviceId == -1) ? "" : std::to_string(info.inputDeviceId); + arr[2] = info.inputDeviceName; + arr[3] = (info.displayId == -1) ? "" : std::to_string(info.displayId); + arr[4] = info.displayName; + arrStrings.push_back(arr); + } + std::array arrWidth {}; + for (const auto &[a, b, c, d, e] : arrStrings) { + arrWidth[0] = std::max(arrWidth[0], a.length()); + arrWidth[1] = std::max(arrWidth[1], b.length()); + arrWidth[2] = std::max(arrWidth[2], c.length()); + arrWidth[3] = std::max(arrWidth[3], d.length()); + arrWidth[4] = std::max(arrWidth[4], e.length()); + } + for (const auto &[a, b, c, d, e] : arrStrings) { + std::cout << "|" << " " << std::setw(arrWidth[0]) << std::setfill(' ') << std::left << a << " " + << "|" << " " << std::setw(arrWidth[1]) << std::setfill(' ') << std::left << b << " " + << "|" << " " << std::setw(arrWidth[2]) << std::setfill(' ') << std::left << c << " " + << "|" << " " << std::setw(arrWidth[3]) << std::setfill(' ') << std::left << d << " " + << "|" << " " << std::setw(arrWidth[4]) << std::setfill(' ') << std::left << e << " " + << "|" << std::endl; + } + return 0; + } + case 's': { + std::istringstream iss(optarg); + int32_t deviceId = -1; + int32_t displayId = -1; + iss >> deviceId >> displayId; + if (iss.fail()) { + Help("Arg is not right"); + return -1; + } + printf("args: deviceId:%d, displayId:%d\n", deviceId, displayId); + std::string msg; + auto ret = OHOS::MMI::InputManager::GetInstance()->SetDisplayBind(deviceId, displayId, msg); + if (ret != 0) { + printf("Set display bind failed, %s\n", msg.c_str()); + return -1; + } + return 0; + } + case 'h': + default: { + Help(); + break; + } + } + }; + return 0; +} \ No newline at end of file diff --git a/examples/mmi/BUILD.gn b/examples/mmi/BUILD.gn index 9696c5f5cafa07ef229fa034cac84a6e31d3162a..99a9153ae59982ce6003a2b64781f75ccb187e0f 100644 --- a/examples/mmi/BUILD.gn +++ b/examples/mmi/BUILD.gn @@ -17,36 +17,18 @@ import("//foundation/multimodalinput/input/multimodalinput_mini.gni") ohos_executable("mmi-server") { sources = [ "src/mmi_service_main.cpp" ] deps = [ - "//foundation/multimodalinput/input/frameworks/proxy:libmmi-common", + "//foundation/multimodalinput/input/patch/diff_libinput_mmi:libinput-third-mmi", "//foundation/multimodalinput/input/service:libmmi-server", "//foundation/multimodalinput/input/util:libmmi-util", ] - if (input_feature_libinput) { - deps += [ "//foundation/multimodalinput/input/patch/diff_libinput_mmi:libinput-third-mmi" ] - } - external_deps = [ "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", + "ipc:ipc_single", "safwk:system_ability_fwk", "samgr:samgr_proxy", ] - defines = [] - - if (input_feature_debug) { - defines += [ "OHOS_BUILD_MMI_DEBUG" ] - } - - if (input_feature_libinput) { - defines += [ "OHOS_BUILD_LIBINPUT" ] - } - - if (input_feature_hdf) { - defines += [ "OHOS_BUILD_HDF" ] - } - install_enable = true part_name = "input" subsystem_name = "multimodalinput" diff --git a/examples/mmi/src/mmi_service_main.cpp b/examples/mmi/src/mmi_service_main.cpp index 48e2387488004f43021ec511e83af216369679ad..319144323eb7e75adf342dd57d72b2f904b5034e 100644 --- a/examples/mmi/src/mmi_service_main.cpp +++ b/examples/mmi/src/mmi_service_main.cpp @@ -25,7 +25,6 @@ constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "MmiSe int32_t main(int32_t argc, const char *argv[]) { - using namespace OHOS::MMI; auto service = OHOS::DelayedSingleton::GetInstance(); service->OnStart(); constexpr int32_t sleepTime = 10 * 60; diff --git a/frameworks/napi/distributed_input/include/js_input_dinput_context.h b/frameworks/napi/distributed_input/include/js_input_dinput_context.h deleted file mode 100644 index 4431691e053d204c025cdb15341dd2c05b9f1fbc..0000000000000000000000000000000000000000 --- a/frameworks/napi/distributed_input/include/js_input_dinput_context.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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 JS_INPUT_DINPUT_CONTEXT_H -#define JS_INPUT_DINPUT_CONTEXT_H - -#include "js_input_dinput_manager.h" - -namespace OHOS { -namespace MMI { -class JsInputDinputContext { -public: - JsInputDinputContext() = default; - ~JsInputDinputContext() = default; - static JsInputDinputContext* GetInstance(napi_env env); - static napi_value Export(napi_env env, napi_value exports); - static napi_value PrepareRemoteInput(napi_env env, napi_callback_info info); - static napi_value UnprepareRemoteInput(napi_env env, napi_callback_info info); - static napi_value StartRemoteInput(napi_env env, napi_callback_info info); - static napi_value StopRemoteInput(napi_env env, napi_callback_info info); - static napi_value GetRemoteInputAbility(napi_env env, napi_callback_info info); - -private: - static napi_value CreateInstance(napi_env env); - static napi_value JsConstructor(napi_env env, napi_callback_info info); - static napi_value Init(napi_env env, napi_value exports); - static napi_value InitInputAbilityTypeEnum(napi_env env, napi_value exports); - static napi_value EnumTypeConstructor(napi_env env, napi_callback_info info); - - static napi_value GetParameter(napi_env env, napi_callback_info info, napi_ref &first); - static napi_value GetParameter(napi_env env, napi_callback_info info, - std::string &first, napi_ref &second); - static napi_value GetParameter(napi_env env, napi_callback_info info, - int32_t &first, int32_t &second, napi_ref &third); - static napi_value GetParameter(napi_env env, napi_callback_info info, - std::string &first, int32_t second, napi_ref &third); - static napi_value GetParameter(napi_env env, napi_callback_info info, - std::string &first, std::vector &second, napi_ref &third); - static bool TypeOf(napi_env env, napi_value value, napi_valuetype type); - std::shared_ptr GetJsInputDinputMgr() const; - std::shared_ptr mgr_ { std::make_shared() }; - napi_ref contextRef_ { nullptr }; - std::mutex mtx_; -}; -} // namespace MMI -} // namespace OHOS - -#endif // JS_INPUT_DEVICE_CONTEXT_H \ No newline at end of file diff --git a/frameworks/napi/distributed_input/include/js_input_dinput_manager.h b/frameworks/napi/distributed_input/include/js_input_dinput_manager.h deleted file mode 100644 index d74f30778a8d644a78b497d369f33caa56137864..0000000000000000000000000000000000000000 --- a/frameworks/napi/distributed_input/include/js_input_dinput_manager.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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 JS_INPUT_DINPUT_MANAGER_H -#define JS_INPUT_DINPUT_MANAGER_H - -#include -#include -#include - -#include "napi/native_api.h" -#include "napi/native_node_api.h" -#include "utils/log.h" - -#include "define_multimodal.h" -#include "error_multimodal.h" -#include "util_napi.h" - -#define PARAMERTER_NUM 1 -namespace OHOS { -namespace MMI { -enum InputAbilityType { - MOUSE = 1, - KEYBOARD = 2, - TOUCHPAD = 4, -}; -template -class CallbackInfo { -public: - napi_env env { nullptr }; - napi_ref ref { nullptr }; - napi_async_work asyncWork { nullptr }; - napi_deferred deferred { nullptr }; - napi_value promise { nullptr }; - int32_t mouseX { 0 }; - int32_t mouseY { 0 }; - T returnResult; -}; - -class JsInputDinputManager { -public: - napi_value PrepareRemoteInput(napi_env env, const std::string& deviceId, napi_ref handle); - napi_value UnprepareRemoteInput(napi_env env, const std::string& deviceId, napi_ref handle); - napi_value StartRemoteInput(napi_env env, const std::string& deviceId, - const std::vector& inputAbility, napi_ref handle); - napi_value StopRemoteInput(napi_env env, const std::string& deviceId, - const std::vector& inputAbility, napi_ref handle); - napi_value GetRemoteInputAbility(napi_env env, const std::string& deviceId, napi_ref handle); -public: - template - CallbackInfo* CreateCallbackInfo(napi_env env, napi_ref handle) - { - auto cb = new (std::nothrow) CallbackInfo; - if (cb == nullptr) { - return nullptr; - } - cb->env = env; - if (handle == nullptr) { - if (napi_create_promise(env, &cb->deferred, &cb->promise) != napi_ok) { - delete cb; - cb = nullptr; - napi_throw_error(env, nullptr, "Failed to create promise"); - } - } else { - cb->ref = handle; - } - return cb; - } - -private: - static void HandleCallBack(CallbackInfo* cb); - static void HandleCallBack(CallbackInfo>* cb); - static napi_value MakeInputAbilityObj(napi_env env, std::set types); - static uint32_t GetAbilityType(std::vector abilities); - - static void CallFunctionPromise(napi_env env, napi_deferred deferred, napi_value object); - static void CallFunctionAsync(napi_env env, napi_ref handleRef, size_t count, napi_value* object); - std::mutex cbMutex_; -}; -} // namespace MMI -} // namespace OHOS -#endif // JS_INPUT_DINPUT_MANAGER_H \ No newline at end of file diff --git a/frameworks/napi/distributed_input/src/js_input_dinput_context.cpp b/frameworks/napi/distributed_input/src/js_input_dinput_context.cpp deleted file mode 100644 index 0169621caba037a9fff3fa4b3d97300bb3995b64..0000000000000000000000000000000000000000 --- a/frameworks/napi/distributed_input/src/js_input_dinput_context.cpp +++ /dev/null @@ -1,404 +0,0 @@ -/* - * 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. - */ - -#include "js_input_dinput_context.h" - -#include "napi_constants.h" -#include "util_napi.h" - -namespace OHOS { -namespace MMI { -namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "JsInputDinputContext" }; -constexpr uint32_t ARGV_FIRST = 0; -constexpr uint32_t ARGV_SECOND = 1; -constexpr uint32_t ARGV_THIRD = 2; -constexpr uint32_t ARGC_NUM_1 = 1; -constexpr uint32_t ARGC_NUM_2 = 2; -constexpr uint32_t ARGC_NUM_3 = 3; -constexpr uint32_t INIT_REF_COUNT = 1; -const std::string GET_GLOBLE = "napi_get_global"; - -napi_ref inputAbilityTypeEnumConstructor_ = nullptr; -} // namespace - -napi_value JsInputDinputContext::CreateInstance(napi_env env) -{ - CALL_LOG_ENTER; - napi_value global = nullptr; - CHKRP(env, napi_get_global(env, &global), GET_GLOBLE); - constexpr char className[] = "JsInputDinputContext"; - napi_value jsClass = nullptr; - napi_property_descriptor desc[] = {}; - napi_status status = napi_define_class(env, className, sizeof(className), - JsInputDinputContext::JsConstructor, nullptr, sizeof(desc) / sizeof(desc[0]), nullptr, &jsClass); - CHKRP(env, status, DEFINE_CLASS); - status = napi_set_named_property(env, global, "multimodalinput_input_dinput_class", jsClass); - CHKRP(env, status, SET_NAMED_PROPERTY); - napi_value jsInstance = nullptr; - CHKRP(env, napi_new_instance(env, jsClass, 0, nullptr, &jsInstance), NEW_INSTANCE); - CHKRP(env, napi_set_named_property(env, global, "multimodal_input_dinput", jsInstance), SET_NAMED_PROPERTY); - - JsInputDinputContext *jsContext = nullptr; - status = napi_unwrap(env, jsInstance, (void**)&jsContext); - CHKPP(jsContext); - CHKRP(env, napi_create_reference(env, jsInstance, 1, &(jsContext->contextRef_)), CREATE_REFERENCE); - uint32_t refCount = 0; - CHKRP(env, napi_reference_ref(env, jsContext->contextRef_, &refCount), REFERENCE_REF); - return jsInstance; -} - -napi_value JsInputDinputContext::JsConstructor(napi_env env, napi_callback_info info) -{ - CALL_LOG_ENTER; - napi_value thisVar = nullptr; - void *data = nullptr; - CHKRP(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, &data), GET_CB_INFO); - JsInputDinputContext *jsContext = new (std::nothrow) JsInputDinputContext(); - CHKPP(jsContext); - CHKPP(data); - napi_status status = napi_wrap(env, thisVar, jsContext, [](napi_env env, void* data, void* hin) { - MMI_HILOGI("jsvm ends"); - CHKPL(data); - auto context = static_cast(data); - delete context; - }, nullptr, nullptr); - if (status != napi_ok) { - delete jsContext; - THROWERR(env, "Failed to wrap native instance"); - return nullptr; - } - return thisVar; -} - -JsInputDinputContext* JsInputDinputContext::GetInstance(napi_env env) -{ - CALL_LOG_ENTER; - napi_value global = nullptr; - CHKRP(env, napi_get_global(env, &global), GET_GLOBLE); - bool result = false; - CHKRP(env, napi_has_named_property(env, global, "multimodal_input_dinput", &result), HAS_NAMED_PROPERTY); - napi_value object = nullptr; - CHKRP(env, napi_get_named_property(env, global, "multimodal_input_dinput", &object), SET_NAMED_PROPERTY); - if (object == nullptr) { - THROWERR(env, "object is nullptr"); - return nullptr; - } - JsInputDinputContext *instance = nullptr; - CHKRP(env, napi_unwrap(env, object, (void**)&instance), UNWRAP); - if (instance == nullptr) { - THROWERR(env, "instance is nullptr"); - return nullptr; - } - return instance; -} - -std::shared_ptr JsInputDinputContext::GetJsInputDinputMgr() const -{ - return mgr_; -} - -napi_value JsInputDinputContext::PrepareRemoteInput(napi_env env, napi_callback_info info) -{ - CALL_LOG_ENTER; - std::string deviceId; - napi_ref callBackRef = nullptr; - if (GetParameter(env, info, deviceId, callBackRef) != nullptr) { - JsInputDinputContext *jsContext = JsInputDinputContext::GetInstance(env); - CHKPP(jsContext); - auto jsInputDinputMgr = jsContext->GetJsInputDinputMgr(); - CHKPP(jsInputDinputMgr); - return jsInputDinputMgr->PrepareRemoteInput(env, deviceId, callBackRef); - } - return nullptr; -} - -napi_value JsInputDinputContext::UnprepareRemoteInput(napi_env env, napi_callback_info info) -{ - CALL_LOG_ENTER; - std::string deviceId; - napi_ref callBackRef = nullptr; - if (GetParameter(env, info, deviceId, callBackRef) != nullptr) { - JsInputDinputContext *jsContext = JsInputDinputContext::GetInstance(env); - CHKPP(jsContext); - auto jsInputDinputMgr = jsContext->GetJsInputDinputMgr(); - CHKPP(jsInputDinputMgr); - return jsInputDinputMgr->UnprepareRemoteInput(env, deviceId, callBackRef); - } - return nullptr; -} - -napi_value JsInputDinputContext::StartRemoteInput(napi_env env, napi_callback_info info) -{ - CALL_LOG_ENTER; - std::string deviceId; - std::vector inputAbility; - napi_ref callBackRef = nullptr; - if (GetParameter(env, info, deviceId, inputAbility, callBackRef) != nullptr) { - JsInputDinputContext *jsContext = JsInputDinputContext::GetInstance(env); - CHKPP(jsContext); - auto jsInputDinputMgr = jsContext->GetJsInputDinputMgr(); - CHKPP(jsInputDinputMgr); - return jsInputDinputMgr->StartRemoteInput(env, deviceId, inputAbility, callBackRef); - } - return nullptr; -} - -napi_value JsInputDinputContext::StopRemoteInput(napi_env env, napi_callback_info info) -{ - CALL_LOG_ENTER; - std::string deviceId; - std::vector inputAbility; - napi_ref callBackRef = nullptr; - if (GetParameter(env, info, deviceId, inputAbility, callBackRef) != nullptr) { - JsInputDinputContext *jsContext = JsInputDinputContext::GetInstance(env); - CHKPP(jsContext); - auto jsInputDinputMgr = jsContext->GetJsInputDinputMgr(); - CHKPP(jsInputDinputMgr); - return jsInputDinputMgr->StopRemoteInput(env, deviceId, inputAbility, callBackRef); - } - return nullptr; -} - -napi_value JsInputDinputContext::GetRemoteInputAbility(napi_env env, napi_callback_info info) -{ - CALL_LOG_ENTER; - std::string deviceId; - napi_ref callBackRef = nullptr; - if (GetParameter(env, info, deviceId, callBackRef) != nullptr) { - JsInputDinputContext *jsContext = JsInputDinputContext::GetInstance(env); - CHKPP(jsContext); - auto jsInputDinputMgr = jsContext->GetJsInputDinputMgr(); - CHKPP(jsInputDinputMgr); - return jsInputDinputMgr->GetRemoteInputAbility(env, deviceId, callBackRef); - } - return nullptr; -} - -napi_value JsInputDinputContext::GetParameter(napi_env env, napi_callback_info info, napi_ref &first) -{ - CALL_LOG_ENTER; - size_t argc = ARGC_NUM_1; - napi_value argv[ARGC_NUM_1]; - napi_value ret = nullptr; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); - CHKRP(env, napi_create_int32(env, argc, &ret), CREATE_INT32); - if (argc > ARGC_NUM_1) { - THROWERR(env, "parameters count error"); - return nullptr; - } - if (argc == 0) { - first = nullptr; - return ret; - } - if (!TypeOf(env, argv[ARGV_FIRST], napi_function)) { - THROWERR(env, "The first parameter type is incorrect"); - return nullptr; - } - CHKRP(env, napi_create_reference(env, argv[ARGV_FIRST], INIT_REF_COUNT, &first), CREATE_REFERENCE); - return ret; -} - -napi_value JsInputDinputContext::GetParameter(napi_env env, napi_callback_info info, - std::string &first, napi_ref &second) -{ - CALL_LOG_ENTER; - size_t argc = ARGC_NUM_2; - napi_value argv[ARGC_NUM_2]; - napi_value ret = nullptr; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); - CHKRP(env, napi_create_int32(env, argc, &ret), CREATE_INT32); - if (argc > ARGC_NUM_2 || argc < ARGC_NUM_1) { - THROWERR(env, "parameters count error"); - return nullptr; - } - if (!TypeOf(env, argv[ARGV_FIRST], napi_string)) { - THROWERR(env, "The first parameter type is incorrect"); - return nullptr; - } - char deviceId[MAX_STRING_LEN] = { 0 }; - size_t typeLen = 0; - CHKRP(env, napi_get_value_string_utf8(env, argv[ARGV_FIRST], deviceId, - MAX_STRING_LEN - 1, &typeLen), GET_STRING_UTF8); - first = deviceId; - if (argc == ARGC_NUM_1) { - second = nullptr; - return ret; - } - if (!TypeOf(env, argv[ARGV_SECOND], napi_function)) { - THROWERR(env, "The second parameter type is incorrect"); - return nullptr; - } - CHKRP(env, napi_create_reference(env, argv[ARGV_SECOND], INIT_REF_COUNT, &second), CREATE_REFERENCE); - return ret; -} - -napi_value JsInputDinputContext::GetParameter(napi_env env, napi_callback_info info, - int32_t &first, int32_t &second, napi_ref &third) -{ - CALL_LOG_ENTER; - size_t argc = ARGC_NUM_3; - napi_value argv[ARGC_NUM_3]; - napi_value ret = nullptr; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); - CHKRP(env, napi_create_int32(env, argc, &ret), CREATE_INT32); - if (argc > ARGC_NUM_3 || argc < ARGC_NUM_2) { - THROWERR(env, "parameters count error"); - return nullptr; - } - if (!TypeOf(env, argv[ARGV_FIRST], napi_number)) { - THROWERR(env, "The first parameter type is incorrect"); - return nullptr; - } - if (!TypeOf(env, argv[ARGV_SECOND], napi_number)) { - THROWERR(env, "The second parameter type is incorrect"); - return nullptr; - } - napi_get_value_int32(env, argv[ARGV_FIRST], &first); - napi_get_value_int32(env, argv[ARGV_SECOND], &second); - if (argc == ARGC_NUM_2) { - third = nullptr; - return ret; - } - if (!TypeOf(env, argv[ARGV_THIRD], napi_function)) { - THROWERR(env, "The third parameter type is incorrect"); - return nullptr; - } - CHKRP(env, napi_create_reference(env, argv[ARGV_THIRD], INIT_REF_COUNT, &third), CREATE_REFERENCE); - return ret; -} - -napi_value JsInputDinputContext::GetParameter(napi_env env, napi_callback_info info, - std::string &first, std::vector &second, napi_ref &third) -{ - CALL_LOG_ENTER; - size_t argc = ARGC_NUM_3; - napi_value argv[ARGC_NUM_3]; - napi_value ret = nullptr; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); - CHKRP(env, napi_create_int32(env, argc, &ret), CREATE_INT32); - if (argc > ARGC_NUM_3 || argc < ARGC_NUM_2) { - THROWERR(env, "parameters count error"); - return nullptr; - } - if (!TypeOf(env, argv[ARGV_FIRST], napi_string)) { - THROWERR(env, "The first parameter type is incorrect"); - return nullptr; - } - char deviceId[MAX_STRING_LEN] = { 0 }; - size_t typeLen = 0; - CHKRP(env, napi_get_value_string_utf8(env, argv[ARGV_FIRST], deviceId, - MAX_STRING_LEN - 1, &typeLen), GET_STRING_UTF8); - first = deviceId; - - uint32_t arrayLength = 0; - CHKRP(env, napi_get_array_length(env, argv[ARGV_SECOND], &arrayLength), GET_ARRAY_LENGTH); - if (arrayLength <= 0) { - THROWERR(env, "length is incorrect"); - return nullptr; - } - for (size_t i = 0; i < arrayLength; i++) { - napi_value inputAbility = nullptr; - CHKRP(env, napi_get_element(env, argv[ARGV_SECOND], i, &inputAbility), GET_ELEMENT); - if (!TypeOf(env, inputAbility, napi_number)) { - THROWERR(env, "The numeric parameter type is incorrect"); - return nullptr; - } - int32_t value0 = 0; - CHKRP(env, napi_get_value_int32(env, inputAbility, &value0), GET_INT32); - second.push_back(value0); - } - if (argc == ARGC_NUM_2) { - third = nullptr; - return ret; - } - if (!TypeOf(env, argv[ARGV_THIRD], napi_function)) { - THROWERR(env, "The function parameter type is incorrect"); - return nullptr; - } - CHKRP(env, napi_create_reference(env, argv[ARGV_THIRD], INIT_REF_COUNT, &third), CREATE_REFERENCE); - return ret; -} - -bool JsInputDinputContext::TypeOf(napi_env env, napi_value value, napi_valuetype type) -{ - napi_valuetype valueType = napi_undefined; - CHKRF(env, napi_typeof(env, value, &valueType), TYPEOF); - return valueType == type; -} - -napi_value JsInputDinputContext::EnumTypeConstructor(napi_env env, napi_callback_info info) -{ - size_t argc = 0; - napi_value args[ARGC_NUM_1] = { 0 }; - napi_value res = nullptr; - void *data = nullptr; - CHKRP(env, napi_get_cb_info(env, info, &argc, args, &res, &data), GET_CB_INFO); - MMI_HILOGD("Constructed successfully"); - return res; -} - -napi_value JsInputDinputContext::Init(napi_env env, napi_value exports) -{ - CALL_LOG_ENTER; - auto instance = CreateInstance(env); - if (instance == nullptr) { - napi_throw_error(env, nullptr, "JsInputDeviceContext: failed to create instance"); - MMI_HILOGW("Failed to create instance"); - return nullptr; - } - napi_property_descriptor desc[] = { - DECLARE_NAPI_FUNCTION("prepareRemoteInput", PrepareRemoteInput), - DECLARE_NAPI_FUNCTION("unprepareRemoteInput", UnprepareRemoteInput), - DECLARE_NAPI_FUNCTION("startRemoteInput", StartRemoteInput), - DECLARE_NAPI_FUNCTION("stopRemoteInput", StopRemoteInput), - DECLARE_NAPI_FUNCTION("getRemoteInputAbility", GetRemoteInputAbility), - }; - NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc)); - return exports; -} - -napi_value JsInputDinputContext::InitInputAbilityTypeEnum(napi_env env, napi_value exports) -{ - napi_value mouse; - napi_value keyboard; - napi_value touchpad; - - int32_t refCount = 1; - napi_create_uint32(env, static_cast(InputAbilityType::MOUSE), &mouse); - napi_create_uint32(env, static_cast(InputAbilityType::KEYBOARD), &keyboard); - napi_create_uint32(env, static_cast(InputAbilityType::TOUCHPAD), &touchpad); - napi_property_descriptor desc[] = { - DECLARE_NAPI_STATIC_PROPERTY("MOUSE", mouse), - DECLARE_NAPI_STATIC_PROPERTY("KEYBOARD", keyboard), - DECLARE_NAPI_STATIC_PROPERTY("TOUCHPAD", touchpad), - }; - - napi_value result = nullptr; - napi_define_class(env, "InputAbilityType", NAPI_AUTO_LENGTH, EnumTypeConstructor, - nullptr, sizeof(desc) / sizeof(*desc), desc, &result); - napi_create_reference(env, result, refCount, &inputAbilityTypeEnumConstructor_); - napi_set_named_property(env, exports, "InputAbilityType", result); - return exports; -} - -napi_value JsInputDinputContext::Export(napi_env env, napi_value exports) -{ - JsInputDinputContext::Init(env, exports); - JsInputDinputContext::InitInputAbilityTypeEnum(env, exports); - return exports; -} -} // namespace MMI -} // namespace OHOS \ No newline at end of file diff --git a/frameworks/napi/distributed_input/src/js_input_dinput_manager.cpp b/frameworks/napi/distributed_input/src/js_input_dinput_manager.cpp deleted file mode 100644 index 360366a9f6a841f6a3f92ac28329e6516b54f103..0000000000000000000000000000000000000000 --- a/frameworks/napi/distributed_input/src/js_input_dinput_manager.cpp +++ /dev/null @@ -1,247 +0,0 @@ -/* - * 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. - */ - - -#include "js_input_dinput_manager.h" - -#include - -#include "input_manager.h" -#include "napi_constants.h" -#include "util_napi.h" - -namespace OHOS { -namespace MMI { -namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "JsInputDinputManager" }; -const std::string DELETE_ASYNC_WORK = "napi_delete_async_work"; -const std::string CREATE_STRING_LATIN = "napi_create_string_latin1"; - -std::mutex mutex_; - -std::map deviceTypeMap = { - {InputAbilityType::KEYBOARD, EVDEV_UDEV_TAG_KEYBOARD}, - {InputAbilityType::MOUSE, EVDEV_UDEV_TAG_MOUSE}, - {InputAbilityType::TOUCHPAD, EVDEV_UDEV_TAG_TOUCHPAD}, -}; -} - -napi_value JsInputDinputManager::PrepareRemoteInput(napi_env env, const std::string& deviceId, napi_ref handle) -{ - CALL_LOG_ENTER; - CHKPP(handle); - auto cb = CreateCallbackInfo(env, handle); - CHKPP(cb); - InputManager::GetInstance()->PrepareRemoteInput(deviceId, [cb](int32_t returnResult) { - CHKPL(cb); - cb->returnResult = returnResult; - JsInputDinputManager::HandleCallBack(cb); - }); - return cb->promise; -} - -napi_value JsInputDinputManager::UnprepareRemoteInput(napi_env env, const std::string& deviceId, napi_ref handle) -{ - CALL_LOG_ENTER; - CHKPP(handle); - auto cb = CreateCallbackInfo(env, handle); - CHKPP(cb); - InputManager::GetInstance()->UnprepareRemoteInput(deviceId, [cb](int32_t returnResult) { - CHKPL(cb); - cb->returnResult = returnResult; - JsInputDinputManager::HandleCallBack(cb); - }); - CHKPP(handle); - return cb->promise; -} - -napi_value JsInputDinputManager::StartRemoteInput(napi_env env, const std::string& deviceId, - const std::vector& inputAbility, napi_ref handle) -{ - CALL_LOG_ENTER; - CHKPP(handle); - auto cb = CreateCallbackInfo(env, handle); - uint32_t ability = GetAbilityType(inputAbility); - CHKPP(cb); - InputManager::GetInstance()->StartRemoteInput(deviceId, ability, [cb](int32_t returnResult) { - CHKPL(cb); - cb->returnResult = returnResult; - JsInputDinputManager::HandleCallBack(cb); - }); - CHKPP(handle); - return cb->promise; -} - -napi_value JsInputDinputManager::StopRemoteInput(napi_env env, const std::string& deviceId, - const std::vector& inputAbility, napi_ref handle) -{ - CALL_LOG_ENTER; - CHKPP(handle); - auto cb = CreateCallbackInfo(env, handle); - uint32_t ability = GetAbilityType(inputAbility); - CHKPP(cb); - InputManager::GetInstance()->StopRemoteInput(deviceId, ability, [cb](int32_t returnResult) { - CHKPL(cb); - cb->returnResult = returnResult; - JsInputDinputManager::HandleCallBack(cb); - }); - CHKPP(handle); - return cb->promise; -} - -napi_value JsInputDinputManager::GetRemoteInputAbility(napi_env env, const std::string& deviceId, napi_ref handle) -{ - CALL_LOG_ENTER; - CHKPP(handle); - auto cb = CreateCallbackInfo>(env, handle); - CHKPP(cb); - InputManager::GetInstance()->GetRemoteInputAbility(deviceId, [cb](std::set returnResult) { - CHKPL(cb); - cb->returnResult = returnResult; - JsInputDinputManager::HandleCallBack(cb); - }); - CHKPP(handle); - return cb->promise; -} - -uint32_t JsInputDinputManager::GetAbilityType(std::vector abilities) -{ - CALL_LOG_ENTER; - uint32_t inputAbility = 0; - for (const auto &item : abilities) { - inputAbility |= item; - } - return inputAbility & (InputAbilityType::MOUSE | InputAbilityType::KEYBOARD); -} - -void JsInputDinputManager::HandleCallBack(CallbackInfo* cb) -{ - CALL_LOG_ENTER; - std::lock_guard guard(mutex_); - napi_value resourceName = nullptr; - CHKPV(cb); - CHKRV(cb->env, napi_create_string_latin1(cb->env, "HandleCallBack", NAPI_AUTO_LENGTH, &resourceName), - CREATE_STRING_LATIN); - napi_status retStatus = napi_create_async_work( - cb->env, nullptr, resourceName, - [](napi_env env, void *data) {}, - [](napi_env env, napi_status status, void *data) { - (void)status; - auto cbInfo = static_cast*>(data); - napi_value resultObj[1] = { 0 }; - if (cbInfo->returnResult == RET_OK) { - napi_get_undefined(cbInfo->env, &resultObj[0]); - } else { - napi_value result = nullptr; - CHKRV(env, napi_create_int32(cbInfo->env, cbInfo->returnResult, &result), CREATE_INT32); - CHKRV(env, napi_create_object(cbInfo->env, &resultObj[0]), CREATE_OBJECT); - CHKRV(env, napi_set_named_property(cbInfo->env, resultObj[0], "code", - result), SET_NAMED_PROPERTY); - } - if (cbInfo->promise != nullptr) { - CallFunctionPromise(cbInfo->env, cbInfo->deferred, resultObj[0]); - } else if (cbInfo->ref != nullptr) { - CallFunctionAsync(cbInfo->env, cbInfo->ref, PARAMERTER_NUM, &resultObj[0]); - } - MMI_HILOGD("async_work end"); - CHKRV(env, napi_delete_reference(env, cbInfo->ref), DELETE_REFERENCE); - CHKRV(env, napi_delete_async_work(env, cbInfo->asyncWork), DELETE_ASYNC_WORK); - delete cbInfo; - }, (void *)cb, &cb->asyncWork); - if (retStatus != napi_ok) { - MMI_HILOGE("Create async work failed"); - } - napi_queue_async_work(cb->env, cb->asyncWork); -} - -void JsInputDinputManager::HandleCallBack(CallbackInfo>* cb) -{ - CALL_LOG_ENTER; - std::lock_guard guard(mutex_); - napi_value resourceName = nullptr; - CHKPV(cb); - CHKRV(cb->env, napi_create_string_latin1(cb->env, "HandleCallBack", NAPI_AUTO_LENGTH, &resourceName), - CREATE_STRING_LATIN); - napi_status retStatus = napi_create_async_work( - cb->env, nullptr, resourceName, - [](napi_env env, void *data) {}, - [](napi_env env, napi_status status, void *data) { - (void)status; - auto cbInfo = static_cast>*>(data); - napi_value resultObj[2] = {}; - napi_get_undefined(cbInfo->env, &resultObj[0]); - resultObj[1] = MakeInputAbilityObj(cbInfo->env, cbInfo->returnResult); - CHKPV(resultObj); - if (cbInfo->promise != nullptr) { - CallFunctionPromise(cbInfo->env, cbInfo->deferred, resultObj[1]); - } else if (cbInfo->ref != nullptr) { - CallFunctionAsync(cbInfo->env, cbInfo->ref, (PARAMERTER_NUM + 1), &resultObj[0]); - } - MMI_HILOGD("async_work end"); - CHKRV(env, napi_delete_reference(env, cbInfo->ref), DELETE_REFERENCE); - CHKRV(env, napi_delete_async_work(env, cbInfo->asyncWork), DELETE_ASYNC_WORK); - delete cbInfo; - }, (void *)cb, &cb->asyncWork); - if (retStatus != napi_ok) { - MMI_HILOGE("Create async work failed"); - } - napi_queue_async_work(cb->env, cb->asyncWork); -} - -napi_value JsInputDinputManager::MakeInputAbilityObj(napi_env env, std::set types) -{ - napi_value returnResult = nullptr; - napi_value resultArry = nullptr; - int32_t i = 0; - CHKRP(env, napi_create_array(env, &resultArry), CREATE_ARRAY); - for (const auto &deviceType : types) { - MMI_HILOGD("deviceType:%{public}d", deviceType); - for (const auto &item : deviceTypeMap) { - MMI_HILOGD("deviceType:%{public}d, item.second:%{public}d", deviceType, item.second); - if (deviceType & item.second) { - CHKRP(env, napi_create_int32(env, item.first, &returnResult), CREATE_INT32); - CHKRP(env, napi_set_element(env, resultArry, i++, returnResult), SET_ELEMENT); - break; - } - } - } - napi_value resultObj; - CHKRP(env, napi_create_object(env, &resultObj), CREATE_OBJECT); - CHKRP(env, napi_set_named_property(env, resultObj, "inputAbility", resultArry), SET_NAMED_PROPERTY); - return resultObj; -} - -void JsInputDinputManager::CallFunctionPromise(napi_env env, napi_deferred deferred, napi_value object) -{ - CALL_LOG_ENTER; - CHKRV(env, napi_resolve_deferred(env, deferred, object), RESOLVE_DEFERRED); -} - -void JsInputDinputManager::CallFunctionAsync(napi_env env, napi_ref handleRef, size_t count, napi_value* object) -{ - CALL_LOG_ENTER; - napi_value handler = nullptr; - CHKRV(env, napi_get_reference_value(env, handleRef, &handler), GET_REFERENCE); - napi_value result = nullptr; - if (handler != nullptr) { - CHKRV(env, napi_call_function(env, nullptr, handler, count, object, &result), CALL_FUNCTION); - } else { - MMI_HILOGE("The handler is nullptr"); - } - uint32_t refCount = 0; - CHKRV(env, napi_reference_unref(env, handleRef, &refCount), REFERENCE_UNREF); -} -} // namespace MMI -} // namespace OHOS \ No newline at end of file diff --git a/frameworks/napi/input_consumer/BUILD.gn b/frameworks/napi/input_consumer/BUILD.gn index 76d494b0f281a857e4b3079f24e96e8136fd0099..1be6c44a151282d554c76866a31497dd9634b63c 100644 --- a/frameworks/napi/input_consumer/BUILD.gn +++ b/frameworks/napi/input_consumer/BUILD.gn @@ -22,15 +22,6 @@ config("inputconsumer_config") { "//foundation/multimodalinput/input/tools/event_inject/include", "//foundation/multimodalinput/input/interfaces/native/innerkits/proxy/include", ] - - defines = [] - if (input_feature_libinput) { - defines += [ "OHOS_BUILD_LIBINPUT" ] - } - - if (input_feature_hdf) { - defines += [ "OHOS_BUILD_HDF" ] - } } ohos_shared_library("inputconsumer") { @@ -43,7 +34,6 @@ ohos_shared_library("inputconsumer") { deps = [ "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", - "//foundation/multimodalinput/input/frameworks/proxy:libmmi-common", "//foundation/multimodalinput/input/util:libmmi-util", ] diff --git a/frameworks/napi/input_consumer/include/js_register_module.h b/frameworks/napi/input_consumer/include/js_register_module.h index c6da2a7c2066d1a50038b98fcacd21e6474e7f1a..bcc233cf2ed1fd28b737a5248472ad10d952fea8 100644 --- a/frameworks/napi/input_consumer/include/js_register_module.h +++ b/frameworks/napi/input_consumer/include/js_register_module.h @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef JS_REGISTER_MODULE_H #define JS_REGISTER_MODULE_H @@ -20,14 +21,15 @@ #include #include #include +#include #include "napi/native_api.h" #include "napi/native_node_api.h" #include "utils/log.h" +#include "define_multimodal.h" #include "key_event.h" #include "key_option.h" -#include "define_multimodal.h" #define SUCCESS_CODE 0 #define ERROR_CODE (-1) @@ -50,11 +52,23 @@ struct KeyEventMonitorInfo { std::string name; napi_value handle { nullptr }; std::shared_ptr keyEvent { nullptr }; - napi_ref callback[1] {}; + napi_ref callback[1] { nullptr }; int32_t subscribeId { 0 }; std::shared_ptr keyOption { nullptr }; + bool valid { true }; + std::mutex refLock; + void SetValid(bool flag) + { + std::lock_guard lock(refLock); + valid = flag; + } + bool IsValid() + { + std::lock_guard lock(refLock); + return valid; + } }; - +static std::mutex sCallBacksMutex_; typedef std::map> Callbacks; } // namespace MMI } // namespace OHOS diff --git a/frameworks/napi/input_consumer/include/js_register_util.h b/frameworks/napi/input_consumer/include/js_register_util.h index 129221f0147344d91c3d88632c2018c4f7201d48..f808b49ef2bf257801d048d93f554b0f215d79e8 100644 --- a/frameworks/napi/input_consumer/include/js_register_util.h +++ b/frameworks/napi/input_consumer/include/js_register_util.h @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef JS_REGISTER_UTIL_H #define JS_REGISTER_UTIL_H diff --git a/frameworks/napi/input_consumer/src/js_register_module.cpp b/frameworks/napi/input_consumer/src/js_register_module.cpp index 16b689b7cd24829714adacec6aa0095f250db592..c657919b86b867a756caba1afe69bb5a7d152dc4 100644 --- a/frameworks/napi/input_consumer/src/js_register_module.cpp +++ b/frameworks/napi/input_consumer/src/js_register_module.cpp @@ -21,8 +21,8 @@ #include "input_manager.h" #include "js_register_util.h" #include "napi_constants.h" -#include "util_napi_error.h" #include "util_napi.h" +#include "util_napi_error.h" namespace OHOS { namespace MMI { @@ -42,7 +42,7 @@ napi_value GetEventInfoAPI9(napi_env env, napi_callback_info info, KeyEventMonit CHKPP(keyOption); size_t argc = 3; napi_value argv[3] = { 0 }; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); napi_valuetype valueType = napi_undefined; if (!UtilNapi::TypeOf(env, argv[0], napi_string)) { THROWERR_API9(env, COMMON_PARAMETER_ERROR, "type", "string"); @@ -56,7 +56,7 @@ napi_value GetEventInfoAPI9(napi_env env, napi_callback_info info, KeyEventMonit } char eventType[EVENT_NAME_LEN] = { 0 }; size_t typeLen = 0; - CHKRP(env, napi_get_value_string_utf8(env, argv[0], eventType, EVENT_NAME_LEN - 1, &typeLen), GET_STRING_UTF8); + CHKRP(napi_get_value_string_utf8(env, argv[0], eventType, EVENT_NAME_LEN - 1, &typeLen), GET_VALUE_STRING_UTF8); std::string type = eventType; if (type != SUBSCRIBE_TYPE) { MMI_HILOGE("Type is not key"); @@ -64,7 +64,7 @@ napi_value GetEventInfoAPI9(napi_env env, napi_callback_info info, KeyEventMonit return nullptr; } napi_value receiveValue = nullptr; - CHKRP(env, napi_get_named_property(env, argv[1], "preKeys", &receiveValue), GET_NAMED_PROPERTY); + CHKRP(napi_get_named_property(env, argv[1], "preKeys", &receiveValue), GET_NAMED_PROPERTY); if (receiveValue == nullptr) { THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "preKeys not found"); return nullptr; @@ -111,7 +111,7 @@ napi_value GetEventInfoAPI9(napi_env env, napi_callback_info info, KeyEventMonit subKeyNames += ","; keyOption->SetFinalKeyDown(isFinalKeyDown); MMI_HILOGD("IsFinalKeyDown:%{public}d,map_key:%{public}s", - (isFinalKeyDown == true?1:0), subKeyNames.c_str()); + (isFinalKeyDown == true ? 1 : 0), subKeyNames.c_str()); std::optional tempKeyDownDuration = GetNamedPropertyInt32(env, argv[1], "finalKeyDownDuration"); if (!tempKeyDownDuration) { MMI_HILOGE("GetNamedPropertyInt32 failed"); @@ -128,21 +128,36 @@ napi_value GetEventInfoAPI9(napi_env env, napi_callback_info info, KeyEventMonit event->eventType = subKeyNames; MMI_HILOGD("FinalKeyDownDuration:%{public}d", finalKeyDownDuration); if (argc == 3) { - CHKRP(env, napi_typeof(env, argv[2], &valueType), TYPEOF); + CHKRP(napi_typeof(env, argv[2], &valueType), TYPEOF); if (valueType != napi_function) { MMI_HILOGE("the third parameter is not napi_function"); THROWERR_API9(env, COMMON_PARAMETER_ERROR, "callback", "function"); return nullptr; } - CHKRP(env, napi_create_reference(env, argv[2], 1, &event->callback[0]), REFERENCE_REF); + CHKRP(napi_create_reference(env, argv[2], 1, &event->callback[0]), REFERENCE_REF); } else { event->callback[0] = nullptr; } napi_value ret; - CHKRP(env, napi_create_int32(env, RET_OK, &ret), CREATE_INT32); + CHKRP(napi_create_int32(env, RET_OK, &ret), CREATE_INT32); return ret; } +static bool IsMatchKeyAction(bool isFinalKeydown, int32_t keyAction) +{ + CALL_DEBUG_ENTER; + MMI_HILOGD("isFinalKeydown:%{public}d,keyAction:%{public}d", isFinalKeydown, keyAction); + if (isFinalKeydown && keyAction == KeyEvent::KEY_ACTION_DOWN) { + return true; + } + + if (!isFinalKeydown && keyAction == KeyEvent::KEY_ACTION_UP) { + return true; + } + MMI_HILOGE("isFinalKeydown not matched with keyAction"); + return false; +} + static bool MatchCombinationKeys(KeyEventMonitorInfo* monitorInfo, std::shared_ptr keyEvent) { CALL_DEBUG_ENTER; @@ -153,8 +168,10 @@ static bool MatchCombinationKeys(KeyEventMonitorInfo* monitorInfo, std::shared_p std::vector items = keyEvent->GetKeyItems(); int32_t infoFinalKey = keyOption->GetFinalKey(); int32_t keyEventFinalKey = keyEvent->GetKeyCode(); + bool isFinalKeydown = keyOption->IsFinalKeyDown(); MMI_HILOGD("infoFinalKey:%{public}d,keyEventFinalKey:%{public}d", infoFinalKey, keyEventFinalKey); - if (infoFinalKey != keyEventFinalKey || items.size() > PRE_KEYS_SIZE) { + if (infoFinalKey != keyEventFinalKey || items.size() > PRE_KEYS_SIZE || + !IsMatchKeyAction(isFinalKeydown, keyEvent->GetKeyAction())) { MMI_HILOGE("Param invalid"); return false; } @@ -180,10 +197,13 @@ static bool MatchCombinationKeys(KeyEventMonitorInfo* monitorInfo, std::shared_p count++; } MMI_HILOGD("kevEventSize:%{public}d,infoSize:%{public}d", count, infoSize); - auto keyItem = keyEvent->GetKeyItem(); - CHKPF(keyItem); - auto upTime = keyEvent->GetActionTime(); + std::optional keyItem = keyEvent->GetKeyItem(); + if (!keyItem) { + MMI_HILOGE("The keyItem is nullopt"); + return false; + } auto downTime = keyItem->GetDownTime(); + auto upTime = keyEvent->GetActionTime(); auto curDurationTime = keyOption->GetFinalKeyDownDuration(); if (curDurationTime > 0 && (upTime - downTime >= (static_cast(curDurationTime) * 1000))) { MMI_HILOGE("Skip, upTime - downTime >= duration"); @@ -196,6 +216,7 @@ static void SubKeyEventCallback(std::shared_ptr keyEvent) { CALL_DEBUG_ENTER; CHKPV(keyEvent); + std::lock_guard guard(sCallBacksMutex_); auto iter = callbacks.begin(); while (iter != callbacks.end()) { auto &list = iter->second; @@ -218,9 +239,20 @@ static napi_value JsOn(napi_env env, napi_callback_info info) CALL_DEBUG_ENTER; size_t argc = 3; napi_value argv[3] = { 0 }; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + napi_value thisArg = nullptr; + CHKRP(napi_get_cb_info(env, info, &argc, argv, &thisArg, nullptr), GET_CB_INFO); if (argc < 3) { - THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "paramter number error"); + THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "parameter number error"); + return nullptr; + } + if (thisArg == nullptr) { + MMI_HILOGE("%{public}s, This argument is nullptr.", __func__); + return nullptr; + } + napi_valuetype valueOfThis = napi_undefined; + CHKRP(napi_typeof(env, thisArg, &valueOfThis), TYPEOF); + if (valueOfThis == napi_undefined) { + MMI_HILOGE("%{public}s, Wrong value of this.", __func__); return nullptr; } KeyEventMonitorInfo *event = new (std::nothrow) KeyEventMonitorInfo { @@ -229,11 +261,6 @@ static napi_value JsOn(napi_env env, napi_callback_info info) }; CHKPP(event); auto keyOption = std::make_shared(); - if ((keyOption) == nullptr) { - delete event; - MMI_HILOGE("Check keyOption is null"); - return nullptr; - } napi_valuetype valueType = napi_undefined; if (napi_typeof(env, argv[0], &valueType) != napi_ok) { delete event; @@ -267,6 +294,14 @@ static napi_value JsOn(napi_env env, napi_callback_info info) MMI_HILOGE("AddEventCallback failed"); return nullptr; } + std::shared_ptr* cbInfo = new std::shared_ptr(event); + napi_wrap(env, thisArg, (void*)cbInfo, [](napi_env env, void* data, void* hint) { + std::shared_ptr* cbInfo = static_cast*>(data); + if (cbInfo != nullptr && *cbInfo != nullptr) { + (*cbInfo)->SetValid(false); + delete cbInfo; + } + }, nullptr, nullptr); return nullptr; } @@ -275,7 +310,7 @@ static napi_value JsOff(napi_env env, napi_callback_info info) CALL_DEBUG_ENTER; size_t argc = 3; napi_value argv[3] = { 0 }; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc < 2) { THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "parameter number error"); return nullptr; @@ -286,11 +321,6 @@ static napi_value JsOff(napi_env env, napi_callback_info info) }; CHKPP(event); auto keyOption = std::make_shared(); - if (keyOption == nullptr) { - delete event; - MMI_HILOGE("Check keyOption is null"); - return nullptr; - } napi_valuetype valueType = napi_undefined; if (napi_typeof(env, argv[0], &valueType) != napi_ok) { delete event; @@ -347,4 +377,4 @@ extern "C" __attribute__((constructor)) void RegisterModule(void) napi_module_register(&mmiModule); } } // namespace MMI -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/frameworks/napi/input_consumer/src/js_register_util.cpp b/frameworks/napi/input_consumer/src/js_register_util.cpp index 3fed12574e874560792d71c5e99a8a0705c62669..84220e656cd722fb8258c5942e263edc14e5ceaf 100644 --- a/frameworks/napi/input_consumer/src/js_register_util.cpp +++ b/frameworks/napi/input_consumer/src/js_register_util.cpp @@ -21,8 +21,8 @@ #include "error_multimodal.h" #include "napi_constants.h" -#include "util_napi_error.h" #include "util_napi.h" +#include "util_napi_error.h" namespace OHOS { namespace MMI { @@ -34,7 +34,7 @@ void SetNamedProperty(const napi_env &env, napi_value &object, const std::string { MMI_HILOGD("%{public}s=%{public}d", name.c_str(), value); napi_value napiValue; - CHKRV(env, napi_create_int32(env, value, &napiValue), CREATE_INT32); + CHKRV(napi_create_int32(env, value, &napiValue), CREATE_INT32); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, object, name.c_str(), napiValue)); } @@ -42,7 +42,7 @@ void SetNamedProperty(const napi_env &env, napi_value &object, const std::string { MMI_HILOGD("%{public}s=%{public}s", name.c_str(), value.c_str()); napi_value napiValue; - CHKRV(env, napi_create_string_utf8(env, value.c_str(), NAPI_AUTO_LENGTH, &napiValue), CREATE_STRING_UTF8); + CHKRV(napi_create_string_utf8(env, value.c_str(), NAPI_AUTO_LENGTH, &napiValue), CREATE_STRING_UTF8); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, object, name.c_str(), napiValue)); } @@ -52,13 +52,13 @@ bool GetNamedPropertyBool(const napi_env &env, const napi_value &object, const s napi_get_named_property(env, object, name.c_str(), &napiValue); napi_valuetype tmpType = napi_undefined; - CHKRF(env, napi_typeof(env, napiValue, &tmpType), TYPEOF); + CHKRF(napi_typeof(env, napiValue, &tmpType), TYPEOF); if (tmpType != napi_boolean) { MMI_HILOGE("The value is not bool"); THROWERR_API9(env, COMMON_PARAMETER_ERROR, name.c_str(), "bool"); return false; } - CHKRF(env, napi_get_value_bool(env, napiValue, &ret), GET_BOOL); + CHKRF(napi_get_value_bool(env, napiValue, &ret), GET_VALUE_BOOL); MMI_HILOGD("%{public}s=%{public}d", name.c_str(), ret); return true; } @@ -90,19 +90,19 @@ napi_value GetPreKeys(const napi_env &env, const napi_value &value, std::seteventType) == callbacks.end()) { MMI_HILOGD("No callback in %{public}s", event->eventType.c_str()); callbacks[event->eventType] = {}; @@ -173,6 +174,7 @@ int32_t DelEventCallback(const napi_env &env, Callbacks &callbacks, { CALL_DEBUG_ENTER; CHKPR(event, ERROR_NULL_POINTER); + std::lock_guard guard(sCallBacksMutex_); if (callbacks.count(event->eventType) <= 0) { MMI_HILOGE("Callback doesn't exists"); return JS_CALLBACK_EVENT_FAILED; @@ -250,15 +252,15 @@ static void AsyncWorkFn(const napi_env &env, KeyEventMonitorInfo *event, napi_va CHKPV(event); CHKPV(event->keyOption); MMI_HILOGD("Status > 0 enter"); - CHKRV(env, napi_create_object(env, &result), CREATE_OBJECT); + CHKRV(napi_create_object(env, &result), CREATE_OBJECT); napi_value arr; - CHKRV(env, napi_create_array(env, &arr), CREATE_ARRAY); + CHKRV(napi_create_array(env, &arr), CREATE_ARRAY); std::set preKeys = event->keyOption->GetPreKeys(); int32_t i = 0; napi_value value; for (const auto &preKey : preKeys) { - CHKRV(env, napi_create_int32(env, preKey, &value), CREATE_INT32); - CHKRV(env, napi_set_element(env, arr, i, value), SET_ELEMENT); + CHKRV(napi_create_int32(env, preKey, &value), CREATE_INT32); + CHKRV(napi_set_element(env, arr, i, value), SET_ELEMENT); ++i; } std::string preKeysStr = "preKeys"; @@ -278,7 +280,7 @@ void UvQueueWorkAsyncCallback(uv_work_t *work, int32_t status) CALL_DEBUG_ENTER; CHKPV(work); if (work->data == nullptr) { - MMI_HILOGE("Check data is null"); + MMI_HILOGE("Check data is nullptr"); delete work; work = nullptr; return; @@ -311,12 +313,20 @@ void EmitAsyncCallbackWork(KeyEventMonitorInfo *reportEvent) { CALL_DEBUG_ENTER; CHKPV(reportEvent); + if (!reportEvent->IsValid()) { + MMI_HILOGE("%{public}s, module exported object is invalid.", __func__); + return; + } uv_loop_s *loop = nullptr; - CHKRV(reportEvent->env, napi_get_uv_event_loop(reportEvent->env, &loop), GET_UV_LOOP); + CHKRV(napi_get_uv_event_loop(reportEvent->env, &loop), GET_UV_EVENT_LOOP); uv_work_t *work = new (std::nothrow) uv_work_t; CHKPV(work); KeyEventMonitorInfoWorker *dataWorker = new (std::nothrow) KeyEventMonitorInfoWorker(); - CHKPV(dataWorker); + if (dataWorker == nullptr) { + MMI_HILOGE("dataWorker is nullptr"); + delete work; + return; + } dataWorker->env = reportEvent->env; dataWorker->reportEvent = reportEvent; diff --git a/frameworks/napi/input_device/BUILD.gn b/frameworks/napi/input_device/BUILD.gn index 9ce7ade106fdee28a98fde6203409b1766b0661f..5376eabe4840937c84638ed49dad01ccb5ae386a 100644 --- a/frameworks/napi/input_device/BUILD.gn +++ b/frameworks/napi/input_device/BUILD.gn @@ -24,25 +24,10 @@ config("inputdevice_config") { "//foundation/multimodalinput/input/frameworks/proxy/event_handler/include", "//foundation/multimodalinput/input/frameworks/proxy/module_loader/include", ] - - defines = [] - if (input_feature_libinput) { - defines += [ "OHOS_BUILD_LIBINPUT" ] - } - - if (input_feature_hdf) { - defines += [ "OHOS_BUILD_HDF" ] - } } ohos_shared_library("inputdevice") { - sources = [ - "src/js_event_target.cpp", - "src/js_input_device_context.cpp", - "src/js_input_device_manager.cpp", - "src/js_util.cpp", - "src/native_register_module.cpp", - ] + sources = inputdevice_sources configs = [ ":inputdevice_config" ] diff --git a/frameworks/napi/input_device/include/js_event_target.h b/frameworks/napi/input_device/include/js_event_target.h index add03f0de2cf14f78ea36035d828fe559336b9d8..ade0fe8b44beb5f60f57262b27bf6baccb001318 100644 --- a/frameworks/napi/input_device/include/js_event_target.h +++ b/frameworks/napi/input_device/include/js_event_target.h @@ -32,19 +32,18 @@ namespace MMI { class JsEventTarget : public IInputDeviceListener, public std::enable_shared_from_this { public: JsEventTarget(); - ~JsEventTarget(); + virtual ~JsEventTarget() = default; DISALLOW_COPY_AND_MOVE(JsEventTarget); - static void EmitJsIds(int32_t userData, std::vector &ids); - static void EmitJsDev(int32_t userData, std::shared_ptr device); - static void EmitSupportKeys(int32_t userData, std::vector &keystrokeAbility); - static void EmitJsKeyboardType(int32_t userData, int32_t keyboardType); + static void EmitJsIds(sptr cb, std::vector &ids); + static void EmitJsDev(sptr cb, std::shared_ptr device); + static void EmitSupportKeys(sptr cb, std::vector &keystrokeAbility); + static void EmitJsKeyboardType(sptr cb, int32_t keyboardType); void AddListener(napi_env env, const std::string &type, napi_value handle); void RemoveListener(napi_env env, const std::string &type, napi_value handle); - void RemoveCallbackInfo(napi_env env, napi_value handle, int32_t userData); - napi_value CreateCallbackInfo(napi_env env, napi_value handle, const int32_t userData, bool isApi9 = false); + napi_value CreateCallbackInfo(napi_env, napi_value handle, sptr cb); void ResetEnv(); - virtual void OnDeviceAdded(int32_t deviceId, const std::string &type) override; - virtual void OnDeviceRemoved(int32_t deviceId, const std::string &type) override; + void OnDeviceAdded(int32_t deviceId, const std::string &type) override; + void OnDeviceRemoved(int32_t deviceId, const std::string &type) override; private: static void CallIdsPromiseWork(uv_work_t *work, int32_t status); @@ -61,10 +60,8 @@ private: static void CallDevInfoPromiseWork(uv_work_t *work, int32_t status); static void EmitAddedDeviceEvent(uv_work_t *work, int32_t status); static void EmitRemoveDeviceEvent(uv_work_t *work, int32_t status); - static std::unique_ptr GetCallbackInfo(uv_work_t *work); static napi_value GreateBusinessError(napi_env env, int32_t errCode, std::string errMessage); private: - inline static std::map> callback_ {}; inline static std::map>> devListener_ {}; bool isListeningProcess_ { false }; }; diff --git a/frameworks/napi/input_device/include/js_input_device_context.h b/frameworks/napi/input_device/include/js_input_device_context.h index 08ac10b7af867bd6b506ba95835b15bc9288b3c5..9e78e180c2faced89ec0e879043dfd8abb7cb7e3 100644 --- a/frameworks/napi/input_device/include/js_input_device_context.h +++ b/frameworks/napi/input_device/include/js_input_device_context.h @@ -20,7 +20,7 @@ namespace OHOS { namespace MMI { -class JsInputDeviceContext { +class JsInputDeviceContext final { public: JsInputDeviceContext(); DISALLOW_COPY_AND_MOVE(JsInputDeviceContext); diff --git a/frameworks/napi/input_device/include/js_util.h b/frameworks/napi/input_device/include/js_util.h index 6cabb8afbb8f95e3ed6c1535b64d841ec3a3e7d0..ad2e2cb46361d444249cbc505bd9de7e993bd359 100644 --- a/frameworks/napi/input_device/include/js_util.h +++ b/frameworks/napi/input_device/include/js_util.h @@ -21,6 +21,7 @@ #include "input_device.h" #include "napi/native_api.h" #include "napi/native_node_api.h" +#include "refbase.h" namespace OHOS { namespace MMI { @@ -39,7 +40,7 @@ public: int32_t deviceId { 0 }; int32_t keyboardType { 0 }; }; - struct CallbackInfo { + struct CallbackInfo : RefBase { napi_env env { nullptr }; napi_ref ref { nullptr }; napi_deferred deferred { nullptr }; @@ -54,9 +55,9 @@ public: }; static bool IsSameHandle(napi_env env, napi_value handle, napi_ref ref); - static napi_value GetDeviceInfo(const std::unique_ptr &cb); - static bool GetDeviceAxisInfo(const std::unique_ptr &cb, napi_value &object); - static bool GetDeviceSourceType(const std::unique_ptr &cb, napi_value &object); + static napi_value GetDeviceInfo(sptr cb); + static bool GetDeviceAxisInfo(sptr cb, napi_value &object); + static bool GetDeviceSourceType(sptr cb, napi_value &object); static bool TypeOf(napi_env env, napi_value value, napi_valuetype type); static void DeleteCallbackInfo(std::unique_ptr callback); template diff --git a/frameworks/napi/input_device/src/js_event_target.cpp b/frameworks/napi/input_device/src/js_event_target.cpp old mode 100755 new mode 100644 index c24c33d2583d1f2660df00e83a50dff2e2a7b148..77c54982cd332c8268b2374c0d9d34c336df5818 --- a/frameworks/napi/input_device/src/js_event_target.cpp +++ b/frameworks/napi/input_device/src/js_event_target.cpp @@ -14,7 +14,7 @@ */ #include "js_event_target.h" - +#include "js_util.h" #include "napi_constants.h" #include "util_napi_error.h" @@ -35,8 +35,6 @@ JsEventTarget::JsEventTarget() CK(ret.second, VAL_NOT_EXP); } -JsEventTarget::~JsEventTarget() {} - void JsEventTarget::EmitAddedDeviceEvent(uv_work_t *work, int32_t status) { CALL_DEBUG_ENTER; @@ -44,7 +42,7 @@ void JsEventTarget::EmitAddedDeviceEvent(uv_work_t *work, int32_t status) CHKPV(work); if (work->data == nullptr) { JsUtil::DeletePtr(work); - MMI_HILOGE("Check data is null"); + MMI_HILOGE("Check data is nullptr"); return; } auto temp = static_cast*>(work->data); @@ -78,7 +76,7 @@ void JsEventTarget::EmitAddedDeviceEvent(uv_work_t *work, int32_t status) CHKRV_SCOPE(item->env, napi_set_named_property(item->env, object, "deviceId", deviceId), SET_NAMED_PROPERTY, scope); napi_value handler = nullptr; - CHKRV_SCOPE(item->env, napi_get_reference_value(item->env, item->ref, &handler), GET_REFERENCE, scope); + CHKRV_SCOPE(item->env, napi_get_reference_value(item->env, item->ref, &handler), GET_REFERENCE_VALUE, scope); napi_value ret = nullptr; CHKRV_SCOPE(item->env, napi_call_function(item->env, nullptr, handler, 1, &object, &ret), CALL_FUNCTION, scope); @@ -93,7 +91,7 @@ void JsEventTarget::EmitRemoveDeviceEvent(uv_work_t *work, int32_t status) CHKPV(work); if (work->data == nullptr) { JsUtil::DeletePtr(work); - MMI_HILOGE("Check data is null"); + MMI_HILOGE("Check data is nullptr"); return; } auto temp = static_cast*>(work->data); @@ -123,7 +121,7 @@ void JsEventTarget::EmitRemoveDeviceEvent(uv_work_t *work, int32_t status) napi_value deviceId = nullptr; CHKRV_SCOPE(item->env, napi_create_int32(item->env, item->data.deviceId, &deviceId), CREATE_INT32, scope); - + napi_value object = nullptr; CHKRV_SCOPE(item->env, napi_create_object(item->env, &object), CREATE_OBJECT, scope); CHKRV_SCOPE(item->env, napi_set_named_property(item->env, object, "type", eventType), @@ -132,7 +130,7 @@ void JsEventTarget::EmitRemoveDeviceEvent(uv_work_t *work, int32_t status) SET_NAMED_PROPERTY, scope); napi_value handler = nullptr; - CHKRV_SCOPE(item->env, napi_get_reference_value(item->env, item->ref, &handler), GET_REFERENCE, scope); + CHKRV_SCOPE(item->env, napi_get_reference_value(item->env, item->ref, &handler), GET_REFERENCE_VALUE, scope); napi_value ret = nullptr; CHKRV_SCOPE(item->env, napi_call_function(item->env, nullptr, handler, 1, &object, &ret), @@ -155,7 +153,7 @@ void JsEventTarget::OnDeviceAdded(int32_t deviceId, const std::string &type) CHKPC(item); CHKPC(item->env); uv_loop_s *loop = nullptr; - CHKRV(item->env, napi_get_uv_event_loop(item->env, &loop), GET_UV_LOOP); + CHKRV(napi_get_uv_event_loop(item->env, &loop), GET_UV_EVENT_LOOP); uv_work_t *work = new (std::nothrow) uv_work_t; CHKPV(work); item->data.deviceId = deviceId; @@ -182,7 +180,7 @@ void JsEventTarget::OnDeviceRemoved(int32_t deviceId, const std::string &type) CHKPC(item); CHKPC(item->env); uv_loop_s *loop = nullptr; - CHKRV(item->env, napi_get_uv_event_loop(item->env, &loop), GET_UV_LOOP); + CHKRV(napi_get_uv_event_loop(item->env, &loop), GET_UV_EVENT_LOOP); uv_work_t *work = new (std::nothrow) uv_work_t; CHKPV(work); item->data.deviceId = deviceId; @@ -202,36 +200,35 @@ void JsEventTarget::CallIdsAsyncWork(uv_work_t *work, int32_t status) CHKPV(work); if (work->data == nullptr) { JsUtil::DeletePtr(work); - MMI_HILOGE("Check data is null"); + MMI_HILOGE("Check data is nullptr"); return; } - std::unique_ptr cb = GetCallbackInfo(work); - CHKPV(cb); + sptr cb(static_cast(work->data)); + JsUtil::DeletePtr(work); + cb->DecStrongRef(nullptr); CHKPV(cb->env); - napi_handle_scope scope = nullptr; napi_open_handle_scope(cb->env, &scope); if (scope == nullptr) { MMI_HILOGE("scope is nullptr"); return; } - napi_value arr = nullptr; - CHKRV_SCOPE(cb->env, napi_create_array(cb->env, &arr), CREATE_ARRAY, scope); + napi_value arr[2]; + CHKRV_SCOPE(cb->env, napi_get_undefined(cb->env, &arr[0]), GET_UNDEFINED, scope); + CHKRV_SCOPE(cb->env, napi_create_array(cb->env, &arr[1]), CREATE_ARRAY, scope); uint32_t index = 0; napi_value value = nullptr; for (const auto &item : cb->data.ids) { CHKRV_SCOPE(cb->env, napi_create_int32(cb->env, item, &value), CREATE_INT32, scope); - CHKRV_SCOPE(cb->env, napi_set_element(cb->env, arr, index, value), SET_ELEMENT, scope); + CHKRV_SCOPE(cb->env, napi_set_element(cb->env, arr[1], index, value), SET_ELEMENT, scope); ++index; } napi_value handler = nullptr; - CHKRV_SCOPE(cb->env, napi_get_reference_value(cb->env, cb->ref, &handler), GET_REFERENCE, scope); + CHKRV_SCOPE(cb->env, napi_get_reference_value(cb->env, cb->ref, &handler), GET_REFERENCE_VALUE, scope); napi_value result = nullptr; - CHKRV_SCOPE(cb->env, napi_call_function(cb->env, nullptr, handler, 1, &arr, &result), - CALL_FUNCTION, scope); + CHKRV_SCOPE(cb->env, napi_call_function(cb->env, nullptr, handler, 2, arr, &result), CALL_FUNCTION, scope); napi_close_handle_scope(cb->env, scope); - JsUtil::DeleteCallbackInfo(std::move(cb)); } void JsEventTarget::CallIdsPromiseWork(uv_work_t *work, int32_t status) @@ -240,13 +237,13 @@ void JsEventTarget::CallIdsPromiseWork(uv_work_t *work, int32_t status) CHKPV(work); if (work->data == nullptr) { JsUtil::DeletePtr(work); - MMI_HILOGE("Check data is null"); + MMI_HILOGE("Check data is nullptr"); return; } - std::unique_ptr cb = GetCallbackInfo(work); - CHKPV(cb); + sptr cb(static_cast(work->data)); + JsUtil::DeletePtr(work); + cb->DecStrongRef(nullptr); CHKPV(cb->env); - napi_handle_scope scope = nullptr; napi_open_handle_scope(cb->env, &scope); if (scope == nullptr) { @@ -264,47 +261,30 @@ void JsEventTarget::CallIdsPromiseWork(uv_work_t *work, int32_t status) } CHKRV_SCOPE(cb->env, napi_resolve_deferred(cb->env, cb->deferred, arr), RESOLVE_DEFERRED, scope); napi_close_handle_scope(cb->env, scope); - JsUtil::DeleteCallbackInfo(std::move(cb)); } -void JsEventTarget::EmitJsIds(int32_t userData, std::vector &ids) +void JsEventTarget::EmitJsIds(sptr cb, std::vector &ids) { CALL_DEBUG_ENTER; - std::lock_guard guard(mutex_); - auto iter = callback_.find(userData); - if (iter == callback_.end()) { - MMI_HILOGE("Failed to search for userData"); - return; - } - CHKPV(iter->second); - if (iter->second->env == nullptr) { - callback_.erase(iter); - MMI_HILOGE("The env is nullptr"); - return; - } - - iter->second->data.ids = ids; - iter->second->errCode = RET_OK; + CHKPV(cb); + CHKPV(cb->env); + cb->data.ids = ids; + cb->errCode = RET_OK; uv_loop_s *loop = nullptr; - CHKRV(iter->second->env, napi_get_uv_event_loop(iter->second->env, &loop), GET_UV_LOOP); + CHKRV(napi_get_uv_event_loop(cb->env, &loop), GET_UV_EVENT_LOOP); uv_work_t *work = new (std::nothrow) uv_work_t; CHKPV(work); - int32_t *uData = new (std::nothrow) int32_t(userData); - if ((uData) == nullptr) { - JsUtil::DeletePtr(work); - MMI_HILOGE("Check uData is null"); - return; - } - work->data = static_cast(uData); + cb->IncStrongRef(nullptr); + work->data = cb.GetRefPtr(); int32_t ret; - if (iter->second->isApi9) { - if (iter->second->ref == nullptr) { + if (cb->isApi9) { + if (cb->ref == nullptr) { ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, CallDevListPromiseWork); } else { ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, CallDevListAsyncWork); } } else { - if (iter->second->ref == nullptr) { + if (cb->ref == nullptr) { ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, CallIdsPromiseWork); } else { ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, CallIdsAsyncWork); @@ -313,7 +293,6 @@ void JsEventTarget::EmitJsIds(int32_t userData, std::vector &ids) if (ret != 0) { MMI_HILOGE("uv_queue_work failed"); JsUtil::DeletePtr(work); - JsUtil::DeletePtr(uData); } } @@ -323,11 +302,12 @@ void JsEventTarget::CallDevAsyncWork(uv_work_t *work, int32_t status) CHKPV(work); if (work->data == nullptr) { JsUtil::DeletePtr(work); - MMI_HILOGE("Check data is null"); + MMI_HILOGE("Check data is nullptr"); return; } - std::unique_ptr cb = GetCallbackInfo(work); - CHKPV(cb); + sptr cb(static_cast(work->data)); + JsUtil::DeletePtr(work); + cb->DecStrongRef(nullptr); CHKPV(cb->env); napi_handle_scope scope = nullptr; napi_open_handle_scope(cb->env, &scope); @@ -335,19 +315,15 @@ void JsEventTarget::CallDevAsyncWork(uv_work_t *work, int32_t status) MMI_HILOGE("scope is nullptr"); return; } - napi_value object = JsUtil::GetDeviceInfo(cb); - if (object == nullptr) { - MMI_HILOGE("Check object is null"); - napi_close_handle_scope(cb->env, scope); - return; - } + napi_value object[2]; + CHKRV_SCOPE(cb->env, napi_get_undefined(cb->env, &object[0]), GET_UNDEFINED, scope); + object[1] = JsUtil::GetDeviceInfo(cb); napi_value handler = nullptr; - CHKRV_SCOPE(cb->env, napi_get_reference_value(cb->env, cb->ref, &handler), GET_REFERENCE, scope); + CHKRV_SCOPE(cb->env, napi_get_reference_value(cb->env, cb->ref, &handler), GET_REFERENCE_VALUE, scope); napi_value result = nullptr; - CHKRV_SCOPE(cb->env, napi_call_function(cb->env, nullptr, handler, 1, &object, &result), CALL_FUNCTION, + CHKRV_SCOPE(cb->env, napi_call_function(cb->env, nullptr, handler, 2, object, &result), CALL_FUNCTION, scope); napi_close_handle_scope(cb->env, scope); - JsUtil::DeleteCallbackInfo(std::move(cb)); } void JsEventTarget::CallDevPromiseWork(uv_work_t *work, int32_t status) @@ -356,11 +332,12 @@ void JsEventTarget::CallDevPromiseWork(uv_work_t *work, int32_t status) CHKPV(work); if (work->data == nullptr) { JsUtil::DeletePtr(work); - MMI_HILOGE("Check data is null"); + MMI_HILOGE("Check data is nullptr"); return; } - std::unique_ptr cb = GetCallbackInfo(work); - CHKPV(cb); + sptr cb(static_cast(work->data)); + JsUtil::DeletePtr(work); + cb->DecStrongRef(nullptr); CHKPV(cb->env); napi_handle_scope scope = nullptr; napi_open_handle_scope(cb->env, &scope); @@ -370,50 +347,37 @@ void JsEventTarget::CallDevPromiseWork(uv_work_t *work, int32_t status) } napi_value object = JsUtil::GetDeviceInfo(cb); if (object == nullptr) { - MMI_HILOGE("Check object is null"); + MMI_HILOGE("Check object is nullptr"); napi_close_handle_scope(cb->env, scope); return; } CHKRV_SCOPE(cb->env, napi_resolve_deferred(cb->env, cb->deferred, object), RESOLVE_DEFERRED, scope); napi_close_handle_scope(cb->env, scope); - JsUtil::DeleteCallbackInfo(std::move(cb)); } -void JsEventTarget::EmitJsDev(int32_t userData, std::shared_ptr device) +void JsEventTarget::EmitJsDev(sptr cb, std::shared_ptr device) { CALL_DEBUG_ENTER; - std::lock_guard guard(mutex_); CHKPV(device); - auto iter = callback_.find(userData); - if (iter == callback_.end()) { - MMI_HILOGE("Failed to search for userData"); - return; - } - CHKPV(iter->second); - if (iter->second->env == nullptr) { - callback_.erase(iter); - MMI_HILOGE("The env is nullptr"); - return; - } - - iter->second->data.device = device; - iter->second->errCode = RET_OK; + CHKPV(cb); + CHKPV(cb->env); + cb->data.device = device; + cb->errCode = RET_OK; uv_loop_s *loop = nullptr; - CHKRV(iter->second->env, napi_get_uv_event_loop(iter->second->env, &loop), GET_UV_LOOP); + CHKRV(napi_get_uv_event_loop(cb->env, &loop), GET_UV_EVENT_LOOP); uv_work_t *work = new (std::nothrow) uv_work_t; CHKPV(work); - int32_t *uData = new (std::nothrow) int32_t(userData); - CHKPV(uData); - work->data = static_cast(uData); + cb->IncStrongRef(nullptr); + work->data = cb.GetRefPtr(); int32_t ret; - if (iter->second->isApi9) { - if (iter->second->ref == nullptr) { + if (cb->isApi9) { + if (cb->ref == nullptr) { ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, CallDevInfoPromiseWork); } else { ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, CallDevInfoAsyncWork); } } else { - if (iter->second->ref == nullptr) { + if (cb->ref == nullptr) { ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, CallDevPromiseWork); } else { ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, CallDevAsyncWork); @@ -422,8 +386,6 @@ void JsEventTarget::EmitJsDev(int32_t userData, std::shared_ptr dev if (ret != 0) { MMI_HILOGE("uv_queue_work failed"); JsUtil::DeletePtr(work); - JsUtil::DeletePtr(uData); - return; } } @@ -433,13 +395,13 @@ void JsEventTarget::CallKeystrokeAbilityPromise(uv_work_t *work, int32_t status) CHKPV(work); if (work->data == nullptr) { JsUtil::DeletePtr(work); - MMI_HILOGE("Check data is null"); + MMI_HILOGE("Check data is nullptr"); return; } - std::unique_ptr cb = GetCallbackInfo(work); - CHKPV(cb); + sptr cb(static_cast(work->data)); + JsUtil::DeletePtr(work); + cb->DecStrongRef(nullptr); CHKPV(cb->env); - napi_handle_scope scope = nullptr; napi_open_handle_scope(cb->env, &scope); CHKPV(scope); @@ -457,6 +419,11 @@ void JsEventTarget::CallKeystrokeAbilityPromise(uv_work_t *work, int32_t status) return; } callResult = GreateBusinessError(cb->env, cb->errCode, codeMsg.msg); + if (callResult == nullptr) { + MMI_HILOGE("callResult is nullptr"); + napi_close_handle_scope(cb->env, scope); + return; + } CHKRV_SCOPE(cb->env, napi_reject_deferred(cb->env, cb->deferred, callResult), REJECT_DEFERRED, scope); } else { CHKRV_SCOPE(cb->env, napi_create_array(cb->env, &callResult), CREATE_ARRAY, scope); @@ -472,7 +439,6 @@ void JsEventTarget::CallKeystrokeAbilityPromise(uv_work_t *work, int32_t status) CHKRV_SCOPE(cb->env, napi_resolve_deferred(cb->env, cb->deferred, callResult), RESOLVE_DEFERRED, scope); } napi_close_handle_scope(cb->env, scope); - JsUtil::DeleteCallbackInfo(std::move(cb)); } void JsEventTarget::CallKeystrokeAbilityAsync(uv_work_t *work, int32_t status) @@ -481,13 +447,13 @@ void JsEventTarget::CallKeystrokeAbilityAsync(uv_work_t *work, int32_t status) CHKPV(work); if (work->data == nullptr) { JsUtil::DeletePtr(work); - MMI_HILOGE("Check data is null"); + MMI_HILOGE("Check data is nullptr"); return; } - std::unique_ptr cb = GetCallbackInfo(work); - CHKPV(cb); + sptr cb(static_cast(work->data)); + JsUtil::DeletePtr(work); + cb->DecStrongRef(nullptr); CHKPV(cb->env); - napi_handle_scope scope = nullptr; napi_open_handle_scope(cb->env, &scope); CHKPV(scope); @@ -505,6 +471,11 @@ void JsEventTarget::CallKeystrokeAbilityAsync(uv_work_t *work, int32_t status) return; } callResult[0] = GreateBusinessError(cb->env, cb->errCode, codeMsg.msg); + if (callResult[0] == nullptr) { + MMI_HILOGE("callResult[0] is nullptr"); + napi_close_handle_scope(cb->env, scope); + return; + } CHKRV_SCOPE(cb->env, napi_get_undefined(cb->env, &callResult[1]), GET_UNDEFINED, scope); } else { CHKRV_SCOPE(cb->env, napi_create_array(cb->env, &callResult[1]), CREATE_ARRAY, scope); @@ -521,41 +492,27 @@ void JsEventTarget::CallKeystrokeAbilityAsync(uv_work_t *work, int32_t status) } napi_value handler = nullptr; CHKRV_SCOPE(cb->env, napi_get_reference_value(cb->env, cb->ref, &handler), - GET_REFERENCE, scope); + GET_REFERENCE_VALUE, scope); napi_value result = nullptr; - CHKRV_SCOPE(cb->env, napi_call_function(cb->env, nullptr, handler, 2, callResult, &result), - CALL_FUNCTION, scope); + CHKRV_SCOPE(cb->env, napi_call_function(cb->env, nullptr, handler, 2, callResult, &result), CALL_FUNCTION, scope); napi_close_handle_scope(cb->env, scope); - JsUtil::DeleteCallbackInfo(std::move(cb)); } -void JsEventTarget::EmitSupportKeys(int32_t userData, std::vector &keystrokeAbility) +void JsEventTarget::EmitSupportKeys(sptr cb, std::vector &keystrokeAbility) { CALL_DEBUG_ENTER; - std::lock_guard guard(mutex_); - auto iter = callback_.find(userData); - if (iter == callback_.end()) { - MMI_HILOGE("Failed to search for userData"); - return; - } - CHKPV(iter->second); - if (iter->second->env == nullptr) { - callback_.erase(iter); - MMI_HILOGE("The env is nullptr"); - return; - } - - iter->second->data.keystrokeAbility = keystrokeAbility; - iter->second->errCode = RET_OK; + CHKPV(cb); + CHKPV(cb->env); + cb->data.keystrokeAbility = keystrokeAbility; + cb->errCode = RET_OK; uv_loop_s *loop = nullptr; - CHKRV(iter->second->env, napi_get_uv_event_loop(iter->second->env, &loop), GET_UV_LOOP); + CHKRV(napi_get_uv_event_loop(cb->env, &loop), GET_UV_EVENT_LOOP); uv_work_t *work = new (std::nothrow) uv_work_t; CHKPV(work); - int32_t *uData = new (std::nothrow) int32_t(userData); - CHKPV(uData); - work->data = static_cast(uData); + cb->IncStrongRef(nullptr); + work->data = cb.GetRefPtr(); int32_t ret; - if (iter->second->ref == nullptr) { + if (cb->ref == nullptr) { ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, CallKeystrokeAbilityPromise); } else { ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, CallKeystrokeAbilityAsync); @@ -563,38 +520,25 @@ void JsEventTarget::EmitSupportKeys(int32_t userData, std::vector &keystro if (ret != 0) { MMI_HILOGE("uv_queue_work failed"); JsUtil::DeletePtr(work); - JsUtil::DeletePtr(uData); - return; } } -void JsEventTarget::EmitJsKeyboardType(int32_t userData, int32_t keyboardType) +void JsEventTarget::EmitJsKeyboardType(sptr cb, int32_t keyboardType) { CALL_DEBUG_ENTER; - std::lock_guard guard(mutex_); - auto iter = callback_.find(userData); - if (iter == callback_.end()) { - MMI_HILOGE("Failed to search for userData"); - return; - } - CHKPV(iter->second); - if (iter->second->env == nullptr) { - callback_.erase(iter); - MMI_HILOGE("The env is nullptr"); - return; - } - iter->second->data.keyboardType = keyboardType; - iter->second->errCode = RET_OK; + CHKPV(cb); + CHKPV(cb->env); + cb->data.keyboardType = keyboardType; + cb->errCode = RET_OK; uv_loop_s *loop = nullptr; - CHKRV(iter->second->env, napi_get_uv_event_loop(iter->second->env, &loop), GET_UV_LOOP); + CHKRV(napi_get_uv_event_loop(cb->env, &loop), GET_UV_EVENT_LOOP); uv_work_t *work = new (std::nothrow) uv_work_t; CHKPV(work); - int32_t *uData = new (std::nothrow) int32_t(userData); - CHKPV(uData); - work->data = static_cast(uData); - int32_t ret = 0; - if (iter->second->ref == nullptr) { + cb->IncStrongRef(nullptr); + work->data = cb.GetRefPtr(); + int32_t ret; + if (cb->ref == nullptr) { ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, CallKeyboardTypePromise); } else { ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, CallKeyboardTypeAsync); @@ -602,8 +546,6 @@ void JsEventTarget::EmitJsKeyboardType(int32_t userData, int32_t keyboardType) if (ret != 0) { MMI_HILOGE("uv_queue_work failed"); JsUtil::DeletePtr(work); - JsUtil::DeletePtr(uData); - return; } } @@ -613,11 +555,12 @@ void JsEventTarget::CallKeyboardTypeAsync(uv_work_t *work, int32_t status) CHKPV(work); if (work->data == nullptr) { JsUtil::DeletePtr(work); - MMI_HILOGE("Check data is null"); + MMI_HILOGE("Check data is nullptr"); return; } - std::unique_ptr cb = GetCallbackInfo(work); - CHKPV(cb); + sptr cb(static_cast(work->data)); + JsUtil::DeletePtr(work); + cb->DecStrongRef(nullptr); CHKPV(cb->env); napi_handle_scope scope = nullptr; @@ -638,18 +581,22 @@ void JsEventTarget::CallKeyboardTypeAsync(uv_work_t *work, int32_t status) return; } callResult[0] = GreateBusinessError(cb->env, cb->errCode, codeMsg.msg); + if (callResult[0] == nullptr) { + MMI_HILOGE("callResult[0] is nullptr"); + napi_close_handle_scope(cb->env, scope); + return; + } CHKRV_SCOPE(cb->env, napi_get_undefined(cb->env, &callResult[1]), GET_UNDEFINED, scope); } else { CHKRV_SCOPE(cb->env, napi_create_int32(cb->env, cb->data.keyboardType, &callResult[1]), CREATE_INT32, scope); CHKRV_SCOPE(cb->env, napi_get_undefined(cb->env, &callResult[0]), GET_UNDEFINED, scope); } napi_value handler = nullptr; - CHKRV_SCOPE(cb->env, napi_get_reference_value(cb->env, cb->ref, &handler), GET_REFERENCE, scope); + CHKRV_SCOPE(cb->env, napi_get_reference_value(cb->env, cb->ref, &handler), GET_REFERENCE_VALUE, scope); napi_value result = nullptr; CHKRV_SCOPE(cb->env, napi_call_function(cb->env, nullptr, handler, 2, callResult, &result), CALL_FUNCTION, scope); napi_close_handle_scope(cb->env, scope); - JsUtil::DeleteCallbackInfo(std::move(cb)); } void JsEventTarget::CallKeyboardTypePromise(uv_work_t *work, int32_t status) @@ -658,11 +605,12 @@ void JsEventTarget::CallKeyboardTypePromise(uv_work_t *work, int32_t status) CHKPV(work); if (work->data == nullptr) { JsUtil::DeletePtr(work); - MMI_HILOGE("Check data is null"); + MMI_HILOGE("Check data is nullptr"); return; } - std::unique_ptr cb = GetCallbackInfo(work); - CHKPV(cb); + sptr cb(static_cast(work->data)); + JsUtil::DeletePtr(work); + cb->DecStrongRef(nullptr); CHKPV(cb->env); napi_handle_scope scope = nullptr; @@ -683,13 +631,17 @@ void JsEventTarget::CallKeyboardTypePromise(uv_work_t *work, int32_t status) return; } callResult = GreateBusinessError(cb->env, cb->errCode, codeMsg.msg); + if (callResult == nullptr) { + MMI_HILOGE("callResult is nullptr"); + napi_close_handle_scope(cb->env, scope); + return; + } CHKRV_SCOPE(cb->env, napi_reject_deferred(cb->env, cb->deferred, callResult), REJECT_DEFERRED, scope); } else { CHKRV_SCOPE(cb->env, napi_create_int32(cb->env, cb->data.keyboardType, &callResult), CREATE_INT32, scope); CHKRV_SCOPE(cb->env, napi_resolve_deferred(cb->env, cb->deferred, callResult), RESOLVE_DEFERRED, scope); } napi_close_handle_scope(cb->env, scope); - JsUtil::DeleteCallbackInfo(std::move(cb)); } void JsEventTarget::CallDevListAsyncWork(uv_work_t *work, int32_t status) @@ -698,11 +650,12 @@ void JsEventTarget::CallDevListAsyncWork(uv_work_t *work, int32_t status) CHKPV(work); if (work->data == nullptr) { JsUtil::DeletePtr(work); - MMI_HILOGE("Check data is null"); + MMI_HILOGE("Check data is nullptr"); return; } - std::unique_ptr cb = GetCallbackInfo(work); - CHKPV(cb); + sptr cb(static_cast(work->data)); + JsUtil::DeletePtr(work); + cb->DecStrongRef(nullptr); CHKPV(cb->env); napi_handle_scope scope = nullptr; napi_open_handle_scope(cb->env, &scope); @@ -722,6 +675,11 @@ void JsEventTarget::CallDevListAsyncWork(uv_work_t *work, int32_t status) return; } callResult[0] = GreateBusinessError(cb->env, cb->errCode, codeMsg.msg); + if (callResult[0] == nullptr) { + MMI_HILOGE("callResult[0] is nullptr"); + napi_close_handle_scope(cb->env, scope); + return; + } CHKRV_SCOPE(cb->env, napi_get_undefined(cb->env, &callResult[1]), GET_UNDEFINED, scope); } else { CHKRV_SCOPE(cb->env, napi_create_array(cb->env, &callResult[1]), CREATE_ARRAY, scope); @@ -735,12 +693,10 @@ void JsEventTarget::CallDevListAsyncWork(uv_work_t *work, int32_t status) CHKRV_SCOPE(cb->env, napi_get_undefined(cb->env, &callResult[0]), GET_UNDEFINED, scope); } napi_value handler = nullptr; - CHKRV_SCOPE(cb->env, napi_get_reference_value(cb->env, cb->ref, &handler), GET_REFERENCE, scope); + CHKRV_SCOPE(cb->env, napi_get_reference_value(cb->env, cb->ref, &handler), GET_REFERENCE_VALUE, scope); napi_value result = nullptr; - CHKRV_SCOPE(cb->env, napi_call_function(cb->env, nullptr, handler, 2, callResult, &result), - CALL_FUNCTION, scope); + CHKRV_SCOPE(cb->env, napi_call_function(cb->env, nullptr, handler, 2, callResult, &result), CALL_FUNCTION, scope); napi_close_handle_scope(cb->env, scope); - JsUtil::DeleteCallbackInfo(std::move(cb)); } void JsEventTarget::CallDevListPromiseWork(uv_work_t *work, int32_t status) @@ -749,11 +705,12 @@ void JsEventTarget::CallDevListPromiseWork(uv_work_t *work, int32_t status) CHKPV(work); if (work->data == nullptr) { JsUtil::DeletePtr(work); - MMI_HILOGE("Check data is null"); + MMI_HILOGE("Check data is nullptr"); return; } - std::unique_ptr cb = GetCallbackInfo(work); - CHKPV(cb); + sptr cb(static_cast(work->data)); + JsUtil::DeletePtr(work); + cb->DecStrongRef(nullptr); CHKPV(cb->env); napi_handle_scope scope = nullptr; napi_open_handle_scope(cb->env, &scope); @@ -772,6 +729,11 @@ void JsEventTarget::CallDevListPromiseWork(uv_work_t *work, int32_t status) return; } callResult = GreateBusinessError(cb->env, cb->errCode, codeMsg.msg); + if (callResult == nullptr) { + MMI_HILOGE("callResult is nullptr"); + napi_close_handle_scope(cb->env, scope); + return; + } CHKRV_SCOPE(cb->env, napi_reject_deferred(cb->env, cb->deferred, callResult), REJECT_DEFERRED, scope); } else { CHKRV_SCOPE(cb->env, napi_create_array(cb->env, &callResult), CREATE_ARRAY, scope); @@ -785,7 +747,6 @@ void JsEventTarget::CallDevListPromiseWork(uv_work_t *work, int32_t status) CHKRV_SCOPE(cb->env, napi_resolve_deferred(cb->env, cb->deferred, callResult), RESOLVE_DEFERRED, scope); } napi_close_handle_scope(cb->env, scope); - JsUtil::DeleteCallbackInfo(std::move(cb)); } void JsEventTarget::CallDevInfoPromiseWork(uv_work_t *work, int32_t status) @@ -794,15 +755,19 @@ void JsEventTarget::CallDevInfoPromiseWork(uv_work_t *work, int32_t status) CHKPV(work); if (work->data == nullptr) { JsUtil::DeletePtr(work); - MMI_HILOGE("Check data is null"); + MMI_HILOGE("Check data is nullptr"); return; } - std::unique_ptr cb = GetCallbackInfo(work); - CHKPV(cb); + sptr cb(static_cast(work->data)); + JsUtil::DeletePtr(work); + cb->DecStrongRef(nullptr); CHKPV(cb->env); napi_handle_scope scope = nullptr; napi_open_handle_scope(cb->env, &scope); - CHKPV(scope); + if (scope == nullptr) { + MMI_HILOGE("scope is nullptr"); + return; + } napi_value callResult = nullptr; if (cb->errCode != RET_OK) { if (cb->errCode == RET_ERR) { @@ -817,18 +782,22 @@ void JsEventTarget::CallDevInfoPromiseWork(uv_work_t *work, int32_t status) return; } callResult = GreateBusinessError(cb->env, cb->errCode, codeMsg.msg); + if (callResult == nullptr) { + MMI_HILOGE("callResult is nullptr"); + napi_close_handle_scope(cb->env, scope); + return; + } CHKRV_SCOPE(cb->env, napi_reject_deferred(cb->env, cb->deferred, callResult), REJECT_DEFERRED, scope); } else { callResult = JsUtil::GetDeviceInfo(cb); if (callResult == nullptr) { - MMI_HILOGE("Check callResult is null"); + MMI_HILOGE("Check callResult is nullptr"); napi_close_handle_scope(cb->env, scope); return; } CHKRV_SCOPE(cb->env, napi_resolve_deferred(cb->env, cb->deferred, callResult), RESOLVE_DEFERRED, scope); } napi_close_handle_scope(cb->env, scope); - JsUtil::DeleteCallbackInfo(std::move(cb)); } void JsEventTarget::CallDevInfoAsyncWork(uv_work_t *work, int32_t status) @@ -837,11 +806,12 @@ void JsEventTarget::CallDevInfoAsyncWork(uv_work_t *work, int32_t status) CHKPV(work); if (work->data == nullptr) { JsUtil::DeletePtr(work); - MMI_HILOGE("Check data is null"); + MMI_HILOGE("Check data is nullptr"); return; } - std::unique_ptr cb = GetCallbackInfo(work); - CHKPV(cb); + sptr cb(static_cast(work->data)); + JsUtil::DeletePtr(work); + cb->DecStrongRef(nullptr); CHKPV(cb->env); napi_handle_scope scope = nullptr; napi_open_handle_scope(cb->env, &scope); @@ -860,18 +830,22 @@ void JsEventTarget::CallDevInfoAsyncWork(uv_work_t *work, int32_t status) return; } callResult[0] = GreateBusinessError(cb->env, cb->errCode, codeMsg.msg); + if (callResult[0] == nullptr) { + MMI_HILOGE("callResult[0] is nullptr"); + napi_close_handle_scope(cb->env, scope); + return; + } CHKRV_SCOPE(cb->env, napi_get_undefined(cb->env, &callResult[1]), GET_UNDEFINED, scope); } else { callResult[1] = JsUtil::GetDeviceInfo(cb); CHKRV_SCOPE(cb->env, napi_get_undefined(cb->env, &callResult[0]), GET_UNDEFINED, scope); } napi_value handler = nullptr; - CHKRV_SCOPE(cb->env, napi_get_reference_value(cb->env, cb->ref, &handler), GET_REFERENCE, scope); + CHKRV_SCOPE(cb->env, napi_get_reference_value(cb->env, cb->ref, &handler), GET_REFERENCE_VALUE, scope); napi_value result = nullptr; CHKRV_SCOPE(cb->env, napi_call_function(cb->env, nullptr, handler, 2, callResult, &result), CALL_FUNCTION, scope); napi_close_handle_scope(cb->env, scope); - JsUtil::DeleteCallbackInfo(std::move(cb)); } void JsEventTarget::AddListener(napi_env env, const std::string &type, napi_value handle) @@ -895,15 +869,14 @@ void JsEventTarget::AddListener(napi_env env, const std::string &type, napi_valu } } napi_ref ref = nullptr; - CHKRV(env, napi_create_reference(env, handle, 1, &ref), CREATE_REFERENCE); + CHKRV(napi_create_reference(env, handle, 1, &ref), CREATE_REFERENCE); auto monitor = std::make_unique(); - CHKPV(monitor); monitor->env = env; monitor->ref = ref; iter->second.push_back(std::move(monitor)); if (!isListeningProcess_) { isListeningProcess_ = true; - InputMgr->RegisterDevListener("change", shared_from_this()); + InputManager::GetInstance()->RegisterDevListener("change", shared_from_this()); } } @@ -935,26 +908,8 @@ void JsEventTarget::RemoveListener(napi_env env, const std::string &type, napi_v monitorLabel: if (isListeningProcess_ && iter->second.empty()) { isListeningProcess_ = false; - InputMgr->UnregisterDevListener("change", shared_from_this()); - } -} - -napi_value JsEventTarget::CreateCallbackInfo(napi_env env, napi_value handle, const int32_t userData, bool isApi9) -{ - CALL_DEBUG_ENTER; - std::lock_guard guard(mutex_); - auto cb = std::make_unique(); - CHKPP(cb); - cb->env = env; - cb->isApi9 = isApi9; - napi_value promise = nullptr; - if (handle == nullptr) { - CHKRP(env, napi_create_promise(env, &cb->deferred, &promise), CREATE_PROMISE); - } else { - CHKRP(env, napi_create_reference(env, handle, 1, &cb->ref), CREATE_REFERENCE); + InputManager::GetInstance()->UnregisterDevListener("change", shared_from_this()); } - callback_.emplace(userData, std::move(cb)); - return promise; } napi_value JsEventTarget::GreateBusinessError(napi_env env, int32_t errCode, std::string errMessage) @@ -963,50 +918,33 @@ napi_value JsEventTarget::GreateBusinessError(napi_env env, int32_t errCode, std napi_value result = nullptr; napi_value resultCode = nullptr; napi_value resultMessage = nullptr; - CHKRP(env, napi_create_int32(env, errCode, &resultCode), CREATE_INT32); - CHKRP(env, napi_create_string_utf8(env, errMessage.data(), NAPI_AUTO_LENGTH, &resultMessage), CREATE_STRING_UTF8); - CHKRP(env, napi_create_error(env, nullptr, resultMessage, &result), CREATE_ERROR); - CHKRP(env, napi_set_named_property(env, result, ERR_CODE.c_str(), resultCode), SET_NAMED_PROPERTY); + CHKRP(napi_create_int32(env, errCode, &resultCode), CREATE_INT32); + CHKRP(napi_create_string_utf8(env, errMessage.data(), NAPI_AUTO_LENGTH, &resultMessage), CREATE_STRING_UTF8); + CHKRP(napi_create_error(env, nullptr, resultMessage, &result), CREATE_ERROR); + CHKRP(napi_set_named_property(env, result, ERR_CODE.c_str(), resultCode), SET_NAMED_PROPERTY); return result; } -std::unique_ptr JsEventTarget::GetCallbackInfo(uv_work_t *work) -{ - std::lock_guard guard(mutex_); - int32_t *uData = static_cast(work->data); - int32_t userData = *uData; - JsUtil::DeletePtr(work); - JsUtil::DeletePtr(uData); - - auto iter = callback_.find(userData); - if (iter == callback_.end()) { - MMI_HILOGE("Find userData failed"); - return nullptr; - } - auto cb = std::move(iter->second); - callback_.erase(iter); - return cb; -} - -void JsEventTarget::RemoveCallbackInfo(napi_env env, napi_value handle, int32_t userData) +napi_value JsEventTarget::CreateCallbackInfo(napi_env env, napi_value handle, sptr cb) { - CALL_DEBUG_ENTER; - std::lock_guard guard(mutex_); - auto iter = callback_.find(userData); - if (iter != callback_.end()) { - auto cb = std::move(iter->second); - JsUtil::DeleteCallbackInfo(std::move(cb)); - callback_.erase(iter); + CALL_INFO_TRACE; + CHKPP(cb); + cb->env = env; + napi_value promise = nullptr; + if (handle == nullptr) { + CHKRP(napi_create_promise(env, &cb->deferred, &promise), CREATE_PROMISE); + } else { + CHKRP(napi_create_reference(env, handle, 1, &cb->ref), CREATE_REFERENCE); } + return promise; } void JsEventTarget::ResetEnv() { CALL_DEBUG_ENTER; std::lock_guard guard(mutex_); - callback_.clear(); devListener_.clear(); - InputMgr->UnregisterDevListener("change", shared_from_this()); + InputManager::GetInstance()->UnregisterDevListener("change", shared_from_this()); } } // namespace MMI } // namespace OHOS \ No newline at end of file diff --git a/frameworks/napi/input_device/src/js_input_device_context.cpp b/frameworks/napi/input_device/src/js_input_device_context.cpp index b14f573a3d3b896c83837e741e30e8980ae502a4..9501daa057eb52eab3d1a9449978602dfabd20cd 100644 --- a/frameworks/napi/input_device/src/js_input_device_context.cpp +++ b/frameworks/napi/input_device/src/js_input_device_context.cpp @@ -14,6 +14,7 @@ */ #include "js_input_device_context.h" + #include "mmi_log.h" #include "napi_constants.h" #include "util_napi_error.h" @@ -22,21 +23,13 @@ namespace OHOS { namespace MMI { namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "JsInputDeviceContext" }; - -enum KeyboardType { - NONE = 0, - UNKNOWN = 1, - ALPHABETIC_KEYBOARD = 2, - DIGITAL_KEYBOARD = 3, - HANDWRITING_PEN = 4, - REMOTE_CONTROL = 5, -}; +constexpr uint32_t MIN_N_SIZE = 1; +constexpr uint32_t MAX_N_SIZE = 5; } // namespace JsInputDeviceContext::JsInputDeviceContext() { mgr_ = std::make_shared(); - CHKPL(mgr_); } JsInputDeviceContext::~JsInputDeviceContext() @@ -53,29 +46,29 @@ napi_value JsInputDeviceContext::CreateInstance(napi_env env) { CALL_DEBUG_ENTER; napi_value global = nullptr; - CHKRP(env, napi_get_global(env, &global), GET_GLOBAL); + CHKRP(napi_get_global(env, &global), GET_GLOBAL); constexpr char className[] = "JsInputDeviceContext"; napi_value jsClass = nullptr; napi_property_descriptor desc[] = {}; napi_status status = napi_define_class(env, className, sizeof(className), JsInputDeviceContext::JsConstructor, nullptr, sizeof(desc) / sizeof(desc[0]), nullptr, &jsClass); - CHKRP(env, status, DEFINE_CLASS); + CHKRP(status, DEFINE_CLASS); status = napi_set_named_property(env, global, "multimodalinput_input_device_class", jsClass); - CHKRP(env, status, SET_NAMED_PROPERTY); + CHKRP(status, SET_NAMED_PROPERTY); napi_value jsInstance = nullptr; - CHKRP(env, napi_new_instance(env, jsClass, 0, nullptr, &jsInstance), NEW_INSTANCE); - CHKRP(env, napi_set_named_property(env, global, "multimodal_input_device", jsInstance), SET_NAMED_PROPERTY); + CHKRP(napi_new_instance(env, jsClass, 0, nullptr, &jsInstance), NEW_INSTANCE); + CHKRP(napi_set_named_property(env, global, "multimodal_input_device", jsInstance), SET_NAMED_PROPERTY); JsInputDeviceContext *jsContext = nullptr; - CHKRP(env, napi_unwrap(env, jsInstance, (void**)&jsContext), UNWRAP); + CHKRP(napi_unwrap(env, jsInstance, (void**)&jsContext), UNWRAP); CHKPP(jsContext); - CHKRP(env, napi_create_reference(env, jsInstance, 1, &(jsContext->contextRef_)), CREATE_REFERENCE); + CHKRP(napi_create_reference(env, jsInstance, 1, &(jsContext->contextRef_)), CREATE_REFERENCE); uint32_t refCount = 0; - CHKRP(env, napi_reference_ref(env, jsContext->contextRef_, &refCount), REFERENCE_REF); + CHKRP(napi_reference_ref(env, jsContext->contextRef_, &refCount), REFERENCE_REF); return jsInstance; } @@ -84,7 +77,7 @@ napi_value JsInputDeviceContext::JsConstructor(napi_env env, napi_callback_info CALL_DEBUG_ENTER; napi_value thisVar = nullptr; void *data = nullptr; - CHKRP(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, &data), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, &data), GET_CB_INFO); JsInputDeviceContext *jsContext = new (std::nothrow) JsInputDeviceContext(); CHKPP(jsContext); @@ -92,6 +85,7 @@ napi_value JsInputDeviceContext::JsConstructor(napi_env env, napi_callback_info MMI_HILOGI("jsvm ends"); JsInputDeviceContext *context = static_cast(data); delete context; + context = nullptr; }, nullptr, nullptr); if (status != napi_ok) { delete jsContext; @@ -105,24 +99,24 @@ JsInputDeviceContext* JsInputDeviceContext::GetInstance(napi_env env) { CALL_DEBUG_ENTER; napi_value global = nullptr; - CHKRP(env, napi_get_global(env, &global), GET_GLOBAL); + CHKRP(napi_get_global(env, &global), GET_GLOBAL); bool result = false; - CHKRP(env, napi_has_named_property(env, global, "multimodal_input_device", &result), HAS_NAMED_PROPERTY); + CHKRP(napi_has_named_property(env, global, "multimodal_input_device", &result), HAS_NAMED_PROPERTY); if (!result) { MMI_HILOGE("multimodal_input_device was not found"); return nullptr; } napi_value object = nullptr; - CHKRP(env, napi_get_named_property(env, global, "multimodal_input_device", &object), GET_NAMED_PROPERTY); + CHKRP(napi_get_named_property(env, global, "multimodal_input_device", &object), GET_NAMED_PROPERTY); if (object == nullptr) { MMI_HILOGE("object is nullptr"); return nullptr; } JsInputDeviceContext *instance = nullptr; - CHKRP(env, napi_unwrap(env, object, (void**)&instance), UNWRAP); + CHKRP(napi_unwrap(env, object, (void**)&instance), UNWRAP); if (instance == nullptr) { MMI_HILOGE("instance is nullptr"); return nullptr; @@ -140,7 +134,7 @@ napi_value JsInputDeviceContext::On(napi_env env, napi_callback_info info) CALL_DEBUG_ENTER; size_t argc = 2; napi_value argv[2]; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc == 0) { MMI_HILOGE("Require two parameters"); THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "Parameter count error"); @@ -152,9 +146,9 @@ napi_value JsInputDeviceContext::On(napi_env env, napi_callback_info info) return nullptr; } - char eventType[MAX_STRING_LEN] = {0}; + char eventType[MAX_STRING_LEN] = { 0 }; size_t ret = 0; - CHKRP(env, napi_get_value_string_utf8(env, argv[0], eventType, MAX_STRING_LEN - 1, &ret), GET_STRING_UTF8); + CHKRP(napi_get_value_string_utf8(env, argv[0], eventType, MAX_STRING_LEN - 1, &ret), GET_VALUE_STRING_UTF8); std::string type = eventType; if (type != CHANGED_TYPE) { MMI_HILOGE("Type is not change"); @@ -179,7 +173,7 @@ napi_value JsInputDeviceContext::Off(napi_env env, napi_callback_info info) CALL_DEBUG_ENTER; size_t argc = 2; napi_value argv[2]; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc == 0) { MMI_HILOGE("Require two parameters"); THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "Parameter count error"); @@ -191,9 +185,9 @@ napi_value JsInputDeviceContext::Off(napi_env env, napi_callback_info info) return nullptr; } - char eventType[MAX_STRING_LEN] = {0}; + char eventType[MAX_STRING_LEN] = { 0 }; size_t ret = 0; - CHKRP(env, napi_get_value_string_utf8(env, argv[0], eventType, MAX_STRING_LEN - 1, &ret), GET_STRING_UTF8); + CHKRP(napi_get_value_string_utf8(env, argv[0], eventType, MAX_STRING_LEN - 1, &ret), GET_VALUE_STRING_UTF8); std::string type = eventType; if (type != CHANGED_TYPE) { MMI_HILOGE("Type is not change"); @@ -222,7 +216,7 @@ napi_value JsInputDeviceContext::GetDeviceIds(napi_env env, napi_callback_info i CALL_DEBUG_ENTER; size_t argc = 1; napi_value argv[1]; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc > 1) { THROWERR(env, "too many parameters"); return nullptr; @@ -246,7 +240,7 @@ napi_value JsInputDeviceContext::GetDevice(napi_env env, napi_callback_info info CALL_DEBUG_ENTER; size_t argc = 2; napi_value argv[2]; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc < 1 || argc > 2) { THROWERR(env, "the number of parameters is not as expected"); return nullptr; @@ -256,7 +250,7 @@ napi_value JsInputDeviceContext::GetDevice(napi_env env, napi_callback_info info return nullptr; } int32_t id = 0; - CHKRP(env, napi_get_value_int32(env, argv[0], &id), GET_INT32); + CHKRP(napi_get_value_int32(env, argv[0], &id), GET_VALUE_INT32); JsInputDeviceContext *jsDev = JsInputDeviceContext::GetInstance(env); CHKPP(jsDev); auto jsInputDeviceMgr = jsDev->GetJsInputDeviceMgr(); @@ -275,7 +269,7 @@ napi_value JsInputDeviceContext::SupportKeys(napi_env env, napi_callback_info in CALL_DEBUG_ENTER; size_t argc = 3; napi_value argv[3]; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc < 2) { MMI_HILOGE("Require three parameters"); THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "Parameter count error"); @@ -288,7 +282,7 @@ napi_value JsInputDeviceContext::SupportKeys(napi_env env, napi_callback_info in return nullptr; } int32_t deviceId = 0; - CHKRP(env, napi_get_value_int32(env, argv[0], &deviceId), GET_INT32); + CHKRP(napi_get_value_int32(env, argv[0], &deviceId), GET_VALUE_INT32); if (!JsUtil::TypeOf(env, argv[1], napi_object)) { MMI_HILOGE("Second parameter type error"); @@ -296,8 +290,8 @@ napi_value JsInputDeviceContext::SupportKeys(napi_env env, napi_callback_info in return nullptr; } uint32_t size = 0; - CHKRP(env, napi_get_array_length(env, argv[1], &size), GET_ARRAY_LENGTH); - if (size < 1 || size > 5) { + CHKRP(napi_get_array_length(env, argv[1], &size), GET_ARRAY_LENGTH); + if (size < MIN_N_SIZE || size > MAX_N_SIZE) { MMI_HILOGE("Size range error"); THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "size range error"); return nullptr; @@ -307,13 +301,13 @@ napi_value JsInputDeviceContext::SupportKeys(napi_env env, napi_callback_info in std::vector keyCodes; for (uint32_t i = 0; i < size; ++i) { napi_value keyValue = nullptr; - CHKRP(env, napi_get_element(env, argv[1], i, &keyValue), GET_ELEMENT); + CHKRP(napi_get_element(env, argv[1], i, &keyValue), GET_ELEMENT); if (!JsUtil::TypeOf(env, keyValue, napi_number)) { MMI_HILOGE("Second parameter type error"); THROWERR_API9(env, COMMON_PARAMETER_ERROR, "KeyCode", "number"); return nullptr; } - CHKRP(env, napi_get_value_int32(env, keyValue, &data), GET_INT32); + CHKRP(napi_get_value_int32(env, keyValue, &data), GET_VALUE_INT32); keyCodes.push_back(data); } @@ -335,7 +329,7 @@ napi_value JsInputDeviceContext::GetKeyboardType(napi_env env, napi_callback_inf CALL_DEBUG_ENTER; size_t argc = 2; napi_value argv[2]; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc == 0) { MMI_HILOGE("Require two parameters"); THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "Parameter count error"); @@ -348,11 +342,12 @@ napi_value JsInputDeviceContext::GetKeyboardType(napi_env env, napi_callback_inf return nullptr; } int32_t id = 0; - CHKRP(env, napi_get_value_int32(env, argv[0], &id), GET_INT32); + CHKRP(napi_get_value_int32(env, argv[0], &id), GET_VALUE_INT32); JsInputDeviceContext *jsDev = JsInputDeviceContext::GetInstance(env); CHKPP(jsDev); auto jsInputDeviceMgr = jsDev->GetJsInputDeviceMgr(); + CHKPP(jsInputDeviceMgr); if (argc == 1) { return jsInputDeviceMgr->GetKeyboardType(env, id); } @@ -369,7 +364,7 @@ napi_value JsInputDeviceContext::GetDeviceList(napi_env env, napi_callback_info CALL_DEBUG_ENTER; size_t argc = 1; napi_value argv[1]; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); JsInputDeviceContext *jsIds = JsInputDeviceContext::GetInstance(env); CHKPP(jsIds); @@ -390,7 +385,7 @@ napi_value JsInputDeviceContext::GetDeviceInfo(napi_env env, napi_callback_info CALL_DEBUG_ENTER; size_t argc = 2; napi_value argv[2]; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc == 0) { MMI_HILOGE("Require two parameters"); THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "Parameter count error"); @@ -402,7 +397,7 @@ napi_value JsInputDeviceContext::GetDeviceInfo(napi_env env, napi_callback_info return nullptr; } int32_t id = 0; - CHKRP(env, napi_get_value_int32(env, argv[0], &id), GET_INT32); + CHKRP(napi_get_value_int32(env, argv[0], &id), GET_VALUE_INT32); JsInputDeviceContext *jsDev = JsInputDeviceContext::GetInstance(env); CHKPP(jsDev); @@ -422,10 +417,10 @@ napi_value JsInputDeviceContext::EnumClassConstructor(napi_env env, napi_callbac { CALL_DEBUG_ENTER; size_t argc = 0; - napi_value args[1] = {0}; + napi_value args[1] = { 0 }; napi_value ret = nullptr; void *data = nullptr; - CHKRP(env, napi_get_cb_info(env, info, &argc, args, &ret, &data), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, args, &ret, &data), GET_CB_INFO); return ret; } @@ -433,17 +428,17 @@ napi_value JsInputDeviceContext::CreateEnumKeyboardType(napi_env env, napi_value { CALL_DEBUG_ENTER; napi_value none = nullptr; - CHKRP(env, napi_create_int32(env, KeyboardType::NONE, &none), CREATE_INT32); + CHKRP(napi_create_int32(env, KeyboardType::KEYBOARD_TYPE_NONE, &none), CREATE_INT32); napi_value unknown = nullptr; - CHKRP(env, napi_create_int32(env, KeyboardType::UNKNOWN, &unknown), CREATE_INT32); + CHKRP(napi_create_int32(env, KeyboardType::KEYBOARD_TYPE_UNKNOWN, &unknown), CREATE_INT32); napi_value alphabeticKeyboard = nullptr; - CHKRP(env, napi_create_int32(env, KeyboardType::ALPHABETIC_KEYBOARD, &alphabeticKeyboard), CREATE_INT32); + CHKRP(napi_create_int32(env, KeyboardType::KEYBOARD_TYPE_ALPHABETICKEYBOARD, &alphabeticKeyboard), CREATE_INT32); napi_value digitalKeyboard = nullptr; - CHKRP(env, napi_create_int32(env, KeyboardType::DIGITAL_KEYBOARD, &digitalKeyboard), CREATE_INT32); + CHKRP(napi_create_int32(env, KeyboardType::KEYBOARD_TYPE_DIGITALKEYBOARD, &digitalKeyboard), CREATE_INT32); napi_value handwritingPen = nullptr; - CHKRP(env, napi_create_int32(env, KeyboardType::HANDWRITING_PEN, &handwritingPen), CREATE_INT32); + CHKRP(napi_create_int32(env, KeyboardType::KEYBOARD_TYPE_HANDWRITINGPEN, &handwritingPen), CREATE_INT32); napi_value remoteControl = nullptr; - CHKRP(env, napi_create_int32(env, KeyboardType::REMOTE_CONTROL, &remoteControl), CREATE_INT32); + CHKRP(napi_create_int32(env, KeyboardType::KEYBOARD_TYPE_REMOTECONTROL, &remoteControl), CREATE_INT32); napi_property_descriptor desc[] = { DECLARE_NAPI_STATIC_PROPERTY("NONE", none), DECLARE_NAPI_STATIC_PROPERTY("UNKNOWN", unknown), @@ -453,9 +448,9 @@ napi_value JsInputDeviceContext::CreateEnumKeyboardType(napi_env env, napi_value DECLARE_NAPI_STATIC_PROPERTY("REMOTE_CONTROL", remoteControl), }; napi_value result = nullptr; - CHKRP(env, napi_define_class(env, "KeyboardType", NAPI_AUTO_LENGTH, EnumClassConstructor, nullptr, + CHKRP(napi_define_class(env, "KeyboardType", NAPI_AUTO_LENGTH, EnumClassConstructor, nullptr, sizeof(desc) / sizeof(*desc), desc, &result), DEFINE_CLASS); - CHKRP(env, napi_set_named_property(env, exports, "KeyboardType", result), SET_NAMED_PROPERTY); + CHKRP(napi_set_named_property(env, exports, "KeyboardType", result), SET_NAMED_PROPERTY); return exports; } @@ -477,7 +472,7 @@ napi_value JsInputDeviceContext::Export(napi_env env, napi_value exports) DECLARE_NAPI_STATIC_FUNCTION("getDeviceList", GetDeviceList), DECLARE_NAPI_STATIC_FUNCTION("getDeviceInfo", GetDeviceInfo), }; - CHKRP(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc), DEFINE_PROPERTIES); + CHKRP(napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc), DEFINE_PROPERTIES); if (CreateEnumKeyboardType(env, exports) == nullptr) { MMI_HILOGE("Failed to create keyboard type enum"); return nullptr; diff --git a/frameworks/napi/input_device/src/js_input_device_manager.cpp b/frameworks/napi/input_device/src/js_input_device_manager.cpp index 6de4913eb8d31bd15a3b26945f1d7ac8e6829258..a453eeb1ba5187f658d279cf0904d6da004443ba 100644 --- a/frameworks/napi/input_device/src/js_input_device_manager.cpp +++ b/frameworks/napi/input_device/src/js_input_device_manager.cpp @@ -39,22 +39,22 @@ void JsInputDeviceManager::UnregisterDevListener(napi_env env, const std::string napi_value JsInputDeviceManager::GetDeviceIds(napi_env env, napi_value handle) { CALL_DEBUG_ENTER; - std::lock_guard guard(mutex_); - int32_t userData = InputDevImpl.GetUserData(); - napi_value ret = CreateCallbackInfo(env, handle, userData); - auto callback = std::bind(EmitJsIds, userData, std::placeholders::_1); - InputMgr->GetDeviceIds(callback); + sptr cb = new (std::nothrow) JsUtil::CallbackInfo(); + CHKPP(cb); + napi_value ret = CreateCallbackInfo(env, handle, cb); + auto callback = std::bind(EmitJsIds, cb, std::placeholders::_1); + InputManager::GetInstance()->GetDeviceIds(callback); return ret; } napi_value JsInputDeviceManager::GetDevice(napi_env env, int32_t id, napi_value handle) { CALL_DEBUG_ENTER; - std::lock_guard guard(mutex_); - int32_t userData = InputDevImpl.GetUserData(); - napi_value ret = CreateCallbackInfo(env, handle, userData); - auto callback = std::bind(EmitJsDev, userData, std::placeholders::_1); - InputMgr->GetDevice(id, callback); + sptr cb = new (std::nothrow) JsUtil::CallbackInfo(); + CHKPP(cb); + napi_value ret = CreateCallbackInfo(env, handle, cb); + auto callback = std::bind(EmitJsDev, cb, std::placeholders::_1); + InputManager::GetInstance()->GetDevice(id, callback); return ret; } @@ -62,65 +62,53 @@ napi_value JsInputDeviceManager::SupportKeys(napi_env env, int32_t id, std::vect napi_value handle) { CALL_DEBUG_ENTER; - std::lock_guard guard(mutex_); - int32_t userData = InputDevImpl.GetUserData(); - napi_value ret = CreateCallbackInfo(env, handle, userData); - auto callback = std::bind(EmitSupportKeys, userData, std::placeholders::_1); - int32_t napiCode = InputMgr->SupportKeys(id, keyCodes, callback); + sptr cb = new (std::nothrow) JsUtil::CallbackInfo(); + CHKPP(cb); + napi_value ret = CreateCallbackInfo(env, handle, cb); + auto callback = std::bind(EmitSupportKeys, cb, std::placeholders::_1); + int32_t napiCode = InputManager::GetInstance()->SupportKeys(id, keyCodes, callback); if (napiCode != OTHER_ERROR && napiCode != RET_OK) { THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "Invalid input device id"); } - if (napiCode != RET_OK) { - JsEventTarget::RemoveCallbackInfo(env, handle, userData); - } return ret; } napi_value JsInputDeviceManager::GetKeyboardType(napi_env env, int32_t id, napi_value handle) { CALL_DEBUG_ENTER; - std::lock_guard guard(mutex_); - int32_t userData = InputDevImpl.GetUserData(); - napi_value ret = CreateCallbackInfo(env, handle, userData); - auto callback = std::bind(EmitJsKeyboardType, userData, std::placeholders::_1); - int32_t napiCode = InputMgr->GetKeyboardType(id, callback); + sptr cb = new (std::nothrow) JsUtil::CallbackInfo(); + CHKPP(cb); + napi_value ret = CreateCallbackInfo(env, handle, cb); + auto callback = std::bind(EmitJsKeyboardType, cb, std::placeholders::_1); + int32_t napiCode = InputManager::GetInstance()->GetKeyboardType(id, callback); if (napiCode != OTHER_ERROR && napiCode != RET_OK) { THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "Invalid input device id"); } - if (napiCode != RET_OK) { - JsEventTarget::RemoveCallbackInfo(env, handle, userData); - } return ret; } napi_value JsInputDeviceManager::GetDeviceList(napi_env env, napi_value handle) { CALL_DEBUG_ENTER; - std::lock_guard guard(mutex_); - int32_t userData = InputDevImpl.GetUserData(); - napi_value ret = CreateCallbackInfo(env, handle, userData, true); - auto callback = std::bind(EmitJsIds, userData, std::placeholders::_1); - int32_t napiCode = InputMgr->GetDeviceIds(callback); - if (napiCode != RET_OK) { - JsEventTarget::RemoveCallbackInfo(env, handle, userData); - } + sptr cb = new (std::nothrow) JsUtil::CallbackInfo(); + CHKPP(cb); + napi_value ret = CreateCallbackInfo(env, handle, cb); + auto callback = std::bind(EmitJsIds, cb, std::placeholders::_1); + InputManager::GetInstance()->GetDeviceIds(callback); return ret; } napi_value JsInputDeviceManager::GetDeviceInfo(napi_env env, int32_t id, napi_value handle) { CALL_DEBUG_ENTER; - std::lock_guard guard(mutex_); - int32_t userData = InputDevImpl.GetUserData(); - napi_value ret = CreateCallbackInfo(env, handle, userData, true); - auto callback = std::bind(EmitJsDev, userData, std::placeholders::_1); - int32_t napiCode = InputMgr->GetDevice(id, callback); + sptr cb = new (std::nothrow) JsUtil::CallbackInfo(); + CHKPP(cb); + napi_value ret = CreateCallbackInfo(env, handle, cb); + auto callback = std::bind(EmitJsDev, cb, std::placeholders::_1); + int32_t napiCode = InputManager::GetInstance()->GetDevice(id, callback); if (napiCode != OTHER_ERROR && napiCode != RET_OK) { THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "Invalid input device id"); } - if (napiCode != RET_OK) { - JsEventTarget::RemoveCallbackInfo(env, handle, userData); - } return ret; } diff --git a/frameworks/napi/input_device/src/js_util.cpp b/frameworks/napi/input_device/src/js_util.cpp index ff98f31108db7bfe91f2af10ec722b42750b6265..590eca1b4cb5d70b8c02047a3cd7dcf54620a9a5 100644 --- a/frameworks/napi/input_device/src/js_util.cpp +++ b/frameworks/napi/input_device/src/js_util.cpp @@ -27,14 +27,14 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "JsUtil" }; std::map axisType = { - {ABS_MT_TOUCH_MAJOR, "touchMajor"}, - {ABS_MT_TOUCH_MINOR, "touchMinor"}, - {ABS_MT_ORIENTATION, "orientation"}, - {ABS_MT_POSITION_X, "x"}, - {ABS_MT_POSITION_Y, "y"}, - {ABS_MT_PRESSURE, "pressure"}, - {ABS_MT_WIDTH_MAJOR, "toolMajor"}, - {ABS_MT_WIDTH_MINOR, "toolMinor"}, + { ABS_MT_TOUCH_MAJOR, "touchmajor" }, + { ABS_MT_TOUCH_MINOR, "touchminor" }, + { ABS_MT_ORIENTATION, "orientation" }, + { ABS_MT_POSITION_X, "x" }, + { ABS_MT_POSITION_Y, "y" }, + { ABS_MT_PRESSURE, "pressure" }, + { ABS_MT_WIDTH_MAJOR, "toolmajor" }, + { ABS_MT_WIDTH_MINOR, "toolminor" }, }; constexpr uint32_t EVDEV_UDEV_TAG_TOUCHSCREEN = (1 << 4); @@ -42,57 +42,57 @@ constexpr uint32_t EVDEV_UDEV_TAG_JOYSTICK = (1 << 6); constexpr uint32_t EVDEV_UDEV_TAG_TRACKBALL = (1 << 10); JsUtil::DeviceType g_deviceType[] = { - {"keyboard", EVDEV_UDEV_TAG_KEYBOARD}, - {"mouse", EVDEV_UDEV_TAG_MOUSE}, - {"touchpad", EVDEV_UDEV_TAG_TOUCHPAD}, - {"touchscreen", EVDEV_UDEV_TAG_TOUCHSCREEN}, - {"joystick", EVDEV_UDEV_TAG_JOYSTICK}, - {"trackball", EVDEV_UDEV_TAG_TRACKBALL}, + { "keyboard", EVDEV_UDEV_TAG_KEYBOARD }, + { "mouse", EVDEV_UDEV_TAG_MOUSE }, + { "touchpad", EVDEV_UDEV_TAG_TOUCHPAD }, + { "touchscreen", EVDEV_UDEV_TAG_TOUCHSCREEN }, + { "joystick", EVDEV_UDEV_TAG_JOYSTICK }, + { "trackball", EVDEV_UDEV_TAG_TRACKBALL }, }; } // namespace bool JsUtil::IsSameHandle(napi_env env, napi_value handle, napi_ref ref) { napi_value handlerTemp = nullptr; - CHKRF(env, napi_get_reference_value(env, ref, &handlerTemp), GET_REFERENCE); + CHKRF(napi_get_reference_value(env, ref, &handlerTemp), GET_REFERENCE_VALUE); bool isEqual = false; - CHKRF(env, napi_strict_equals(env, handle, handlerTemp, &isEqual), STRICT_EQUALS); + CHKRF(napi_strict_equals(env, handle, handlerTemp, &isEqual), STRICT_EQUALS); return isEqual; } -napi_value JsUtil::GetDeviceInfo(const std::unique_ptr &cb) +napi_value JsUtil::GetDeviceInfo(sptr cb) { CHKPP(cb); CHKPP(cb->env); CHKPP(cb->data.device); napi_value object = nullptr; - CHKRP(cb->env, napi_create_object(cb->env, &object), CREATE_OBJECT); + CHKRP(napi_create_object(cb->env, &object), CREATE_OBJECT); napi_value id = nullptr; - CHKRP(cb->env, napi_create_int32(cb->env, cb->data.device->GetId(), &id), CREATE_INT32); + CHKRP(napi_create_int32(cb->env, cb->data.device->GetId(), &id), CREATE_INT32); napi_value name = nullptr; - CHKRP(cb->env, napi_create_string_utf8(cb->env, (cb->data.device->GetName()).c_str(), + CHKRP(napi_create_string_utf8(cb->env, (cb->data.device->GetName()).c_str(), NAPI_AUTO_LENGTH, &name), CREATE_STRING_UTF8); - CHKRP(cb->env, napi_set_named_property(cb->env, object, "id", id), SET_NAMED_PROPERTY); - CHKRP(cb->env, napi_set_named_property(cb->env, object, "name", name), SET_NAMED_PROPERTY); + CHKRP(napi_set_named_property(cb->env, object, "id", id), SET_NAMED_PROPERTY); + CHKRP(napi_set_named_property(cb->env, object, "name", name), SET_NAMED_PROPERTY); napi_value busType = nullptr; - CHKRP(cb->env, napi_create_int32(cb->env, cb->data.device->GetBus(), &busType), CREATE_INT32); - CHKRP(cb->env, napi_set_named_property(cb->env, object, "bus", busType), SET_NAMED_PROPERTY); + CHKRP(napi_create_int32(cb->env, cb->data.device->GetBus(), &busType), CREATE_INT32); + CHKRP(napi_set_named_property(cb->env, object, "bus", busType), SET_NAMED_PROPERTY); napi_value product = nullptr; - CHKRP(cb->env, napi_create_int32(cb->env, cb->data.device->GetProduct(), &product), CREATE_INT32); - CHKRP(cb->env, napi_set_named_property(cb->env, object, "product", product), SET_NAMED_PROPERTY); + CHKRP(napi_create_int32(cb->env, cb->data.device->GetProduct(), &product), CREATE_INT32); + CHKRP(napi_set_named_property(cb->env, object, "product", product), SET_NAMED_PROPERTY); napi_value vendor = nullptr; - CHKRP(cb->env, napi_create_int32(cb->env, cb->data.device->GetVendor(), &vendor), CREATE_INT32); - CHKRP(cb->env, napi_set_named_property(cb->env, object, "vendor", vendor), SET_NAMED_PROPERTY); + CHKRP(napi_create_int32(cb->env, cb->data.device->GetVendor(), &vendor), CREATE_INT32); + CHKRP(napi_set_named_property(cb->env, object, "vendor", vendor), SET_NAMED_PROPERTY); napi_value version = nullptr; - CHKRP(cb->env, napi_create_int32(cb->env, cb->data.device->GetVersion(), &version), CREATE_INT32); - CHKRP(cb->env, napi_set_named_property(cb->env, object, "version", version), SET_NAMED_PROPERTY); + CHKRP(napi_create_int32(cb->env, cb->data.device->GetVersion(), &version), CREATE_INT32); + CHKRP(napi_set_named_property(cb->env, object, "version", version), SET_NAMED_PROPERTY); napi_value uniq = nullptr; - CHKRP(cb->env, napi_create_string_utf8(cb->env, (cb->data.device->GetUniq()).c_str(), + CHKRP(napi_create_string_utf8(cb->env, (cb->data.device->GetUniq()).c_str(), NAPI_AUTO_LENGTH, &uniq), CREATE_STRING_UTF8); - CHKRP(cb->env, napi_set_named_property(cb->env, object, "uniq", uniq), SET_NAMED_PROPERTY); + CHKRP(napi_set_named_property(cb->env, object, "uniq", uniq), SET_NAMED_PROPERTY); napi_value phys = nullptr; - CHKRP(cb->env, napi_create_string_utf8(cb->env, (cb->data.device->GetPhys()).c_str(), + CHKRP(napi_create_string_utf8(cb->env, (cb->data.device->GetPhys()).c_str(), NAPI_AUTO_LENGTH, &phys), CREATE_STRING_UTF8); - CHKRP(cb->env, napi_set_named_property(cb->env, object, "phys", phys), SET_NAMED_PROPERTY); + CHKRP(napi_set_named_property(cb->env, object, "phys", phys), SET_NAMED_PROPERTY); if (!GetDeviceSourceType(cb, object)) { MMI_HILOGE("Get device source type failed"); @@ -105,7 +105,7 @@ napi_value JsUtil::GetDeviceInfo(const std::unique_ptr &cb) return object; } -bool JsUtil::GetDeviceAxisInfo(const std::unique_ptr &cb, napi_value &object) +bool JsUtil::GetDeviceAxisInfo(sptr cb, napi_value &object) { CHKPF(cb); CHKPF(cb->env); @@ -114,13 +114,18 @@ bool JsUtil::GetDeviceAxisInfo(const std::unique_ptr &cb, napi_val uint32_t types = cb->data.device->GetType(); for (const auto &item : g_deviceType) { if (types &item.typeBit) { - CHKRF(cb->env, napi_create_string_utf8(cb->env, item.sourceTypeName.c_str(), + CHKRF(napi_create_string_utf8(cb->env, item.sourceTypeName.c_str(), NAPI_AUTO_LENGTH, &sourceType), CREATE_STRING_UTF8); break; } } napi_value axisRanges = nullptr; - CHKRF(cb->env, napi_create_array(cb->env, &axisRanges), CREATE_ARRAY); + CHKRF(napi_create_array(cb->env, &axisRanges), CREATE_ARRAY); + if (sourceType == nullptr) { + CHKRF(napi_set_named_property(cb->env, object, "axisRanges", axisRanges), SET_NAMED_PROPERTY); + MMI_HILOGD("SourceType not found"); + return true; + } napi_value axisRange = nullptr; uint32_t i = 0; for (const auto &item : cb->data.device->GetAxisInfo()) { @@ -129,35 +134,35 @@ bool JsUtil::GetDeviceAxisInfo(const std::unique_ptr &cb, napi_val MMI_HILOGD("Find axisType failed"); continue; } - CHKRF(cb->env, napi_create_object(cb->env, &axisRange), CREATE_OBJECT); - CHKRF(cb->env, napi_set_named_property(cb->env, axisRange, "source", sourceType), SET_NAMED_PROPERTY); + CHKRF(napi_create_object(cb->env, &axisRange), CREATE_OBJECT); + CHKRF(napi_set_named_property(cb->env, axisRange, "source", sourceType), SET_NAMED_PROPERTY); napi_value axisType = nullptr; - CHKRF(cb->env, napi_create_string_utf8(cb->env, iter->second.c_str(), + CHKRF(napi_create_string_utf8(cb->env, iter->second.c_str(), NAPI_AUTO_LENGTH, &axisType), CREATE_STRING_UTF8); - CHKRF(cb->env, napi_set_named_property(cb->env, axisRange, "axis", axisType), SET_NAMED_PROPERTY); + CHKRF(napi_set_named_property(cb->env, axisRange, "axis", axisType), SET_NAMED_PROPERTY); napi_value min = nullptr; - CHKRF(cb->env, napi_create_int32(cb->env, item.GetMinimum(), &min), CREATE_INT32); - CHKRF(cb->env, napi_set_named_property(cb->env, axisRange, "min", min), SET_NAMED_PROPERTY); + CHKRF(napi_create_int32(cb->env, item.GetMinimum(), &min), CREATE_INT32); + CHKRF(napi_set_named_property(cb->env, axisRange, "min", min), SET_NAMED_PROPERTY); napi_value max = nullptr; - CHKRF(cb->env, napi_create_int32(cb->env, item.GetMaximum(), &max), CREATE_INT32); - CHKRF(cb->env, napi_set_named_property(cb->env, axisRange, "max", max), SET_NAMED_PROPERTY); + CHKRF(napi_create_int32(cb->env, item.GetMaximum(), &max), CREATE_INT32); + CHKRF(napi_set_named_property(cb->env, axisRange, "max", max), SET_NAMED_PROPERTY); napi_value fuzz = nullptr; - CHKRF(cb->env, napi_create_int32(cb->env, item.GetFuzz(), &fuzz), CREATE_INT32); - CHKRF(cb->env, napi_set_named_property(cb->env, axisRange, "fuzz", fuzz), SET_NAMED_PROPERTY); + CHKRF(napi_create_int32(cb->env, item.GetFuzz(), &fuzz), CREATE_INT32); + CHKRF(napi_set_named_property(cb->env, axisRange, "fuzz", fuzz), SET_NAMED_PROPERTY); napi_value flat = nullptr; - CHKRF(cb->env, napi_create_int32(cb->env, item.GetFlat(), &flat), CREATE_INT32); - CHKRF(cb->env, napi_set_named_property(cb->env, axisRange, "flat", flat), SET_NAMED_PROPERTY); + CHKRF(napi_create_int32(cb->env, item.GetFlat(), &flat), CREATE_INT32); + CHKRF(napi_set_named_property(cb->env, axisRange, "flat", flat), SET_NAMED_PROPERTY); napi_value resolution = nullptr; - CHKRF(cb->env, napi_create_int32(cb->env, item.GetResolution(), &resolution), CREATE_INT32); - CHKRF(cb->env, napi_set_named_property(cb->env, axisRange, "resolution", resolution), SET_NAMED_PROPERTY); - CHKRF(cb->env, napi_set_element(cb->env, axisRanges, i, axisRange), SET_ELEMENT); + CHKRF(napi_create_int32(cb->env, item.GetResolution(), &resolution), CREATE_INT32); + CHKRF(napi_set_named_property(cb->env, axisRange, "resolution", resolution), SET_NAMED_PROPERTY); + CHKRF(napi_set_element(cb->env, axisRanges, i, axisRange), SET_ELEMENT); ++i; } - CHKRF(cb->env, napi_set_named_property(cb->env, object, "axisRanges", axisRanges), SET_NAMED_PROPERTY); + CHKRF(napi_set_named_property(cb->env, object, "axisRanges", axisRanges), SET_NAMED_PROPERTY); return true; } -bool JsUtil::GetDeviceSourceType(const std::unique_ptr &cb, napi_value &object) +bool JsUtil::GetDeviceSourceType(sptr cb, napi_value &object) { CHKPF(cb); CHKPF(cb->env); @@ -170,21 +175,21 @@ bool JsUtil::GetDeviceSourceType(const std::unique_ptr &cb, napi_v } } napi_value devSources = nullptr; - CHKRF(cb->env, napi_create_array(cb->env, &devSources), CREATE_ARRAY); + CHKRF(napi_create_array(cb->env, &devSources), CREATE_ARRAY); napi_value value = nullptr; for (size_t i = 0; i < sources.size(); ++i) { - CHKRF(cb->env, napi_create_string_utf8(cb->env, sources[i].c_str(), NAPI_AUTO_LENGTH, &value), + CHKRF(napi_create_string_utf8(cb->env, sources[i].c_str(), NAPI_AUTO_LENGTH, &value), CREATE_STRING_UTF8); - CHKRF(cb->env, napi_set_element(cb->env, devSources, i, value), SET_ELEMENT); + CHKRF(napi_set_element(cb->env, devSources, i, value), SET_ELEMENT); } - CHKRF(cb->env, napi_set_named_property(cb->env, object, "sources", devSources), SET_NAMED_PROPERTY); + CHKRF(napi_set_named_property(cb->env, object, "sources", devSources), SET_NAMED_PROPERTY); return true; } bool JsUtil::TypeOf(napi_env env, napi_value value, napi_valuetype type) { napi_valuetype valueType = napi_undefined; - CHKRF(env, napi_typeof(env, value, &valueType), TYPEOF); + CHKRF(napi_typeof(env, value, &valueType), TYPEOF); if (valueType != type) { return false; } @@ -195,7 +200,7 @@ void JsUtil::DeleteCallbackInfo(std::unique_ptr callback) { CALL_DEBUG_ENTER; if (callback->ref != nullptr && callback->env != nullptr) { - CHKRV(callback->env, napi_delete_reference(callback->env, callback->ref), DELETE_REFERENCE); + CHKRV(napi_delete_reference(callback->env, callback->ref), DELETE_REFERENCE); callback->env = nullptr; } } diff --git a/frameworks/napi/input_device_cooperate/BUILD.gn b/frameworks/napi/input_device_cooperate/BUILD.gn old mode 100755 new mode 100644 index 2adaaed82b707306402cd0492959642ad28a239a..c2ef290d3c3eb614b2bc5d74b5bed4d89fa5ca17 --- a/frameworks/napi/input_device_cooperate/BUILD.gn +++ b/frameworks/napi/input_device_cooperate/BUILD.gn @@ -20,15 +20,13 @@ config("inputdevicecooperate_config") { } ohos_shared_library("inputdevicecooperate") { - sources = [ - "src/js_event_target.cpp", - "src/js_input_device_cooperate_context.cpp", - "src/js_input_device_cooperate_manager.cpp", - "src/js_util.cpp", - "src/native_register_module.cpp", - ] + sources = inputdevicecooperate_sources - configs = [ ":inputdevicecooperate_config" ] + configs = [ + ":inputdevicecooperate_config", + "//foundation/multimodalinput/input/util:libmmi_util_public_config", + "//foundation/multimodalinput/input/service/filter:mmi_event_filter_config", + ] deps = [ "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", diff --git a/frameworks/napi/input_device_cooperate/include/js_event_target.h b/frameworks/napi/input_device_cooperate/include/js_event_target.h index b34b8bc8ebd52d0e2faddbeed70ae085421d78bf..dcc55efe56ba2d2186ac8ab6d9a33e198e273b4a 100755 --- a/frameworks/napi/input_device_cooperate/include/js_event_target.h +++ b/frameworks/napi/input_device_cooperate/include/js_event_target.h @@ -36,18 +36,17 @@ namespace MMI { class JsEventTarget : public IInputDeviceCooperateListener, public std::enable_shared_from_this { public: JsEventTarget(); - ~JsEventTarget() = default; + virtual ~JsEventTarget() = default; DISALLOW_COPY_AND_MOVE(JsEventTarget); - static void EmitJsEnable(int32_t userData, std::string deviceId, CooperationMessage msg); - static void EmitJsStart(int32_t userData, std::string, CooperationMessage msg); - static void EmitJsStop(int32_t userData, std::string, CooperationMessage msg); - static void EmitJsGetState(int32_t userData, bool state); + static void EmitJsEnable(sptr cb, const std::string &deviceId, const CooperationMessage &msg); + static void EmitJsStart(sptr cb, const std::string &deviceId, const CooperationMessage &msg); + static void EmitJsStop(sptr cb, const std::string &deviceId, const CooperationMessage &msg); + static void EmitJsGetState(sptr cb, bool state); void AddListener(napi_env env, const std::string &type, napi_value handle); void RemoveListener(napi_env env, const std::string &type, napi_value handle); - napi_value CreateCallbackInfo(napi_env, napi_value handle, int32_t userData); - void RemoveCallbackInfo(int32_t userData); + napi_value CreateCallbackInfo(napi_env, napi_value handle, sptr cb); void HandleExecuteResult(napi_env env, int32_t errCode); void ResetEnv(); @@ -55,11 +54,10 @@ public: private: inline static std::map>> - cooperateListener_ = {}; - inline static std::map> callback_ = {}; + cooperateListener_ {}; bool isListeningProcess_ { false }; - static void CallEnablePromsieWork(uv_work_t *work, int32_t status); + static void CallEnablePromiseWork(uv_work_t *work, int32_t status); static void CallEnableAsyncWork(uv_work_t *work, int32_t status); static void CallStartPromiseWork(uv_work_t *work, int32_t status); static void CallStartAsyncWork(uv_work_t *work, int32_t status); @@ -68,8 +66,6 @@ private: static void CallGetStatePromiseWork(uv_work_t *work, int32_t status); static void CallGetStateAsyncWork(uv_work_t *work, int32_t status); static void EmitCooperateMessageEvent(uv_work_t *work, int32_t status); - - static std::unique_ptr GetCallbackInfo(uv_work_t *work); }; } // namespace MMI } // namespace OHOS diff --git a/frameworks/napi/input_device_cooperate/include/js_input_device_cooperate_context.h b/frameworks/napi/input_device_cooperate/include/js_input_device_cooperate_context.h index ff607762e21052845fa69c258ea6ed9c436fc624..875e0b42e1c7749dbb54c92c00561d63960206f2 100755 --- a/frameworks/napi/input_device_cooperate/include/js_input_device_cooperate_context.h +++ b/frameworks/napi/input_device_cooperate/include/js_input_device_cooperate_context.h @@ -25,7 +25,7 @@ namespace OHOS { namespace MMI { -class JsInputDeviceCooperateContext { +class JsInputDeviceCooperateContext final { public: JsInputDeviceCooperateContext(); ~JsInputDeviceCooperateContext(); diff --git a/frameworks/napi/input_device_cooperate/include/js_util.h b/frameworks/napi/input_device_cooperate/include/js_util.h old mode 100755 new mode 100644 index f71520469fa99213253cdb82bf3bce440da8425d..5c66f48e9f021d1b093d514dad0757f07ee653b1 --- a/frameworks/napi/input_device_cooperate/include/js_util.h +++ b/frameworks/napi/input_device_cooperate/include/js_util.h @@ -20,10 +20,14 @@ #include #include #include +#include #include #include "cooperation_message.h" +#include "napi_constants.h" + +#include "refbase.h" namespace OHOS { namespace MMI { @@ -46,7 +50,7 @@ public: CooperationMessage msg = CooperationMessage::OPEN_SUCCESS; }; - struct CallbackInfo { + struct CallbackInfo : RefBase { CallbackInfo() = default; ~CallbackInfo(); napi_env env { nullptr }; @@ -57,12 +61,25 @@ public: UserData uData; }; - static napi_value GetEnableInfo(const std::unique_ptr &cb); - static napi_value GetStartInfo(const std::unique_ptr &cb); - static napi_value GetStopInfo(const std::unique_ptr &cb); - static napi_value GetStateInfo(const std::unique_ptr &cb); + struct CallbackReceiveInfoWorker { + napi_env env { nullptr }; + napi_ref ref { nullptr }; + napi_deferred deferred { nullptr }; + int32_t errCode { 0 }; + CallbackData data; + UserData uData; + std::unique_ptr callback = nullptr; + }; + + static napi_value GetEnableInfo(sptr cb); + static napi_value GetStartInfo(sptr cb); + static napi_value GetStopInfo(sptr cb); + static napi_value GetStateInfo(sptr cb); + static napi_value GetStateResult(napi_env env, bool result); static napi_value GetResult(napi_env env, bool result, int32_t errCode); static bool IsSameHandle(napi_env env, napi_value handle, napi_ref ref); + static void DeleteNapiRef(napi_env env, napi_ref ref); + static void UvQueueWorkDeleteRef(uv_work_t *work, int32_t status); template static void DeletePtr(T &ptr) diff --git a/frameworks/napi/input_device_cooperate/src/js_event_target.cpp b/frameworks/napi/input_device_cooperate/src/js_event_target.cpp old mode 100755 new mode 100644 index c0cf85af345cc97f9d9301c1606a5f174ce555a0..136cc37920e0f12d8cc37d6ae2762c9bd40f9063 --- a/frameworks/napi/input_device_cooperate/src/js_event_target.cpp +++ b/frameworks/napi/input_device_cooperate/src/js_event_target.cpp @@ -21,7 +21,7 @@ #include "define_multimodal.h" #include "error_multimodal.h" -#include "input_manager.h" +#include "input_manager_impl.h" #include "mmi_log.h" #include "napi_constants.h" #include "util_napi.h" @@ -42,39 +42,22 @@ JsEventTarget::JsEventTarget() CK(ret.second, VAL_NOT_EXP); } -void JsEventTarget::EmitJsEnable(int32_t userData, std::string deviceId, CooperationMessage msg) +void JsEventTarget::EmitJsEnable(sptr cb, const std::string &deviceId, const CooperationMessage &msg) { CALL_INFO_TRACE; - std::lock_guard guard(mutex_); - auto iter = callback_.find(userData); - if (iter == callback_.end()) { - MMI_HILOGE("Failed to search for userData"); - return; - } - CHKPV(iter->second); - if (iter->second->env == nullptr) { - callback_.erase(iter); - MMI_HILOGE("The env is nullptr"); - return; - } - iter->second->data.enableResult = - (msg == CooperationMessage::OPEN_SUCCESS || msg == CooperationMessage::CLOSE_SUCCESS) ? true : false; - iter->second->data.errCode = static_cast(msg); + CHKPV(cb); + CHKPV(cb->env); + cb->data.enableResult = (msg == CooperationMessage::OPEN_SUCCESS || msg == CooperationMessage::CLOSE_SUCCESS); + cb->data.errCode = static_cast(msg); uv_loop_s *loop = nullptr; - CHKRV(iter->second->env, napi_get_uv_event_loop(iter->second->env, &loop), GET_UV_LOOP); + CHKRV(napi_get_uv_event_loop(cb->env, &loop), GET_UV_EVENT_LOOP); uv_work_s *work = new (std::nothrow) uv_work_t; CHKPV(work); - int32_t *uData = new (std::nothrow) int32_t(userData); - if (uData == nullptr) { - MMI_HILOGE("uData is nullptr"); - delete work; - work = nullptr; - return; - } - work->data = static_cast(uData); + cb->IncStrongRef(nullptr); + work->data = cb.GetRefPtr(); int32_t result; - if (iter->second->ref == nullptr) { - result = uv_queue_work(loop, work, [](uv_work_t *work) {}, CallEnablePromsieWork); + if (cb->ref == nullptr) { + result = uv_queue_work(loop, work, [](uv_work_t *work) {}, CallEnablePromiseWork); } else { result = uv_queue_work(loop, work, [](uv_work_t *work) {}, CallEnableAsyncWork); } @@ -82,41 +65,24 @@ void JsEventTarget::EmitJsEnable(int32_t userData, std::string deviceId, Coopera if (result != 0) { MMI_HILOGE("uv_queue_work failed"); JsUtil::DeletePtr(work); - JsUtil::DeletePtr(uData); } } -void JsEventTarget::EmitJsStart(int32_t userData, std::string deviceId, CooperationMessage msg) +void JsEventTarget::EmitJsStart(sptr cb, const std::string &deviceId, const CooperationMessage &msg) { CALL_INFO_TRACE; - std::lock_guard guard(mutex_); - auto iter = callback_.find(userData); - if (iter == callback_.end()) { - MMI_HILOGE("Failed to search for userData"); - return; - } - CHKPV(iter->second); - if (iter->second->env == nullptr) { - callback_.erase(iter); - MMI_HILOGE("The env is nullptr"); - return; - } - iter->second->data.startResult = (msg == CooperationMessage::INFO_SUCCESS ? true : false); - iter->second->data.errCode = static_cast(msg); + CHKPV(cb); + CHKPV(cb->env); + cb->data.startResult = (msg == CooperationMessage::INFO_SUCCESS); + cb->data.errCode = static_cast(msg); uv_loop_s *loop = nullptr; - CHKRV(iter->second->env, napi_get_uv_event_loop(iter->second->env, &loop), GET_UV_LOOP); + CHKRV(napi_get_uv_event_loop(cb->env, &loop), GET_UV_EVENT_LOOP); uv_work_s *work = new (std::nothrow) uv_work_t; CHKPV(work); - int32_t *uData = new (std::nothrow) int32_t(userData); - if (uData == nullptr) { - MMI_HILOGE("uData is nullptr"); - delete work; - work = nullptr; - return; - } - work->data = static_cast(uData); + cb->IncStrongRef(nullptr); + work->data = cb.GetRefPtr(); int32_t result; - if (iter->second->ref == nullptr) { + if (cb->ref == nullptr) { result = uv_queue_work(loop, work, [](uv_work_t *work) {}, CallStartPromiseWork); } else { result = uv_queue_work(loop, work, [](uv_work_t *work) {}, CallStartAsyncWork); @@ -125,41 +91,24 @@ void JsEventTarget::EmitJsStart(int32_t userData, std::string deviceId, Cooperat if (result != 0) { MMI_HILOGE("uv_queue_work failed"); JsUtil::DeletePtr(work); - JsUtil::DeletePtr(uData); } } -void JsEventTarget::EmitJsStop(int32_t userData, std::string deviceId, CooperationMessage msg) +void JsEventTarget::EmitJsStop(sptr cb, const std::string &deviceId, const CooperationMessage &msg) { CALL_INFO_TRACE; - std::lock_guard guard(mutex_); - auto iter = callback_.find(userData); - if (iter == callback_.end()) { - MMI_HILOGE("Failed to search for userData"); - return; - } - CHKPV(iter->second); - if (iter->second->env == nullptr) { - callback_.erase(iter); - MMI_HILOGE("The env is nullptr"); - return; - } - iter->second->data.stopResult = (msg == CooperationMessage::STOP_SUCCESS ? true : false); - iter->second->data.errCode = static_cast(msg); + CHKPV(cb); + CHKPV(cb->env); + cb->data.stopResult = (msg == CooperationMessage::STOP_SUCCESS); + cb->data.errCode = static_cast(msg); uv_loop_s *loop = nullptr; - CHKRV(iter->second->env, napi_get_uv_event_loop(iter->second->env, &loop), GET_UV_LOOP); + CHKRV(napi_get_uv_event_loop(cb->env, &loop), GET_UV_EVENT_LOOP); uv_work_s *work = new (std::nothrow) uv_work_t; CHKPV(work); - int32_t *uData = new (std::nothrow) int32_t(userData); - if (uData == nullptr) { - MMI_HILOGE("uData is nullptr"); - delete work; - work = nullptr; - return; - } - work->data = static_cast(uData); + cb->IncStrongRef(nullptr); + work->data = cb.GetRefPtr(); int32_t result; - if (iter->second->ref == nullptr) { + if (cb->ref == nullptr) { result = uv_queue_work(loop, work, [](uv_work_t *work) {}, CallStopPromiseWork); } else { result = uv_queue_work(loop, work, [](uv_work_t *work) {}, CallStopAsyncWork); @@ -168,40 +117,23 @@ void JsEventTarget::EmitJsStop(int32_t userData, std::string deviceId, Cooperati if (result != 0) { MMI_HILOGE("uv_queue_work failed"); JsUtil::DeletePtr(work); - JsUtil::DeletePtr(uData); } } -void JsEventTarget::EmitJsGetState(int32_t userData, bool state) +void JsEventTarget::EmitJsGetState(sptr cb, bool state) { CALL_INFO_TRACE; - std::lock_guard guard(mutex_); - auto iter = callback_.find(userData); - if (iter == callback_.end()) { - MMI_HILOGE("Failed to search for userData"); - return; - } - CHKPV(iter->second); - if (iter->second->env == nullptr) { - callback_.erase(iter); - MMI_HILOGE("The env is nullptr"); - return; - } - iter->second->data.cooperateOpened = state; + CHKPV(cb); + CHKPV(cb->env); + cb->data.cooperateOpened = state; uv_loop_s *loop = nullptr; - CHKRV(iter->second->env, napi_get_uv_event_loop(iter->second->env, &loop), GET_UV_LOOP); + CHKRV(napi_get_uv_event_loop(cb->env, &loop), GET_UV_EVENT_LOOP); uv_work_s *work = new (std::nothrow) uv_work_t; CHKPV(work); - int32_t *uData = new (std::nothrow) int32_t(userData); - if (uData == nullptr) { - MMI_HILOGE("uData is null"); - delete work; - work = nullptr; - return; - } - work->data = static_cast(uData); + cb->IncStrongRef(nullptr); + work->data = cb.GetRefPtr(); int32_t result; - if (iter->second->ref == nullptr) { + if (cb->ref == nullptr) { result = uv_queue_work(loop, work, [](uv_work_t *work) {}, CallGetStatePromiseWork); } else { result = uv_queue_work(loop, work, [](uv_work_t *work) {}, CallGetStateAsyncWork); @@ -210,7 +142,6 @@ void JsEventTarget::EmitJsGetState(int32_t userData, bool state) if (result != 0) { MMI_HILOGE("uv_queue_work failed"); JsUtil::DeletePtr(work); - JsUtil::DeletePtr(uData); } } @@ -232,19 +163,14 @@ void JsEventTarget::AddListener(napi_env env, const std::string &type, napi_valu } } napi_ref ref = nullptr; - CHKRV(env, napi_create_reference(env, handle, 1, &ref), CREATE_REFERENCE); + CHKRV(napi_create_reference(env, handle, 1, &ref), CREATE_REFERENCE); auto monitor = std::make_unique(); - if (monitor == nullptr) { - napi_delete_reference(env, ref); - MMI_HILOGE("monitor is nullptr"); - return; - } monitor->env = env; monitor->ref = ref; iter->second.push_back(std::move(monitor)); if (!isListeningProcess_) { isListeningProcess_ = true; - InputMgr->RegisterCooperateListener(shared_from_this()); + InputMgrImpl.RegisterCooperateListener(shared_from_this()); } } @@ -272,44 +198,30 @@ void JsEventTarget::RemoveListener(napi_env env, const std::string &type, napi_v monitorLabel: if (isListeningProcess_ && iter->second.empty()) { isListeningProcess_ = false; - InputMgr->UnregisterCooperateListener(shared_from_this()); + InputMgrImpl.UnregisterCooperateListener(shared_from_this()); } } -napi_value JsEventTarget::CreateCallbackInfo(napi_env env, napi_value handle, int32_t userData) +napi_value JsEventTarget::CreateCallbackInfo(napi_env env, napi_value handle, sptr cb) { CALL_INFO_TRACE; - std::lock_guard guard(mutex_); - auto cb = std::make_unique(); CHKPP(cb); cb->env = env; napi_value promise = nullptr; if (handle == nullptr) { - CHKRP(env, napi_create_promise(env, &cb->deferred, &promise), CREATE_PROMISE); + CHKRP(napi_create_promise(env, &cb->deferred, &promise), CREATE_PROMISE); } else { - CHKRP(env, napi_create_reference(env, handle, 1, &cb->ref), CREATE_REFERENCE); + CHKRP(napi_create_reference(env, handle, 1, &cb->ref), CREATE_REFERENCE); } - callback_.emplace(userData, std::move(cb)); return promise; } -void JsEventTarget::RemoveCallbackInfo(int32_t userData) -{ - CALL_INFO_TRACE; - std::lock_guard guard(mutex_); - auto iter = callback_.find(userData); - if (iter != callback_.end()) { - callback_.erase(iter); - } -} - void JsEventTarget::ResetEnv() { CALL_INFO_TRACE; std::lock_guard guard(mutex_); - callback_.clear(); cooperateListener_.clear(); - InputMgr->UnregisterCooperateListener(shared_from_this()); + InputMgrImpl.UnregisterCooperateListener(shared_from_this()); } void JsEventTarget::OnCooperateMessage(const std::string &deviceId, CooperationMessage msg) @@ -326,7 +238,7 @@ void JsEventTarget::OnCooperateMessage(const std::string &deviceId, CooperationM CHKPC(item); CHKPC(item->env); uv_loop_s *loop = nullptr; - CHKRV(item->env, napi_get_uv_event_loop(item->env, &loop), GET_UV_LOOP); + CHKRV(napi_get_uv_event_loop(item->env, &loop), GET_UV_EVENT_LOOP); uv_work_t *work = new (std::nothrow) uv_work_t; CHKPV(work); item->data.msg = msg; @@ -334,27 +246,31 @@ void JsEventTarget::OnCooperateMessage(const std::string &deviceId, CooperationM work->data = static_cast(&item); int32_t result = uv_queue_work(loop, work, [](uv_work_t *work) {}, EmitCooperateMessageEvent); if (result != 0) { - MMI_HILOGE("uv_queue_work faild"); + MMI_HILOGE("uv_queue_work failed"); JsUtil::DeletePtr(work); } } } -void JsEventTarget::CallEnablePromsieWork(uv_work_t *work, int32_t status) +void JsEventTarget::CallEnablePromiseWork(uv_work_t *work, int32_t status) { CALL_INFO_TRACE; CHKPV(work); if (work->data == nullptr) { JsUtil::DeletePtr(work); - MMI_HILOGE("Check data is null"); + MMI_HILOGE("Check data is nullptr"); return; } - std::unique_ptr cb = GetCallbackInfo(work); - CHKPV(cb); + sptr cb(static_cast(work->data)); + JsUtil::DeletePtr(work); + cb->DecStrongRef(nullptr); CHKPV(cb->env); napi_handle_scope scope = nullptr; napi_open_handle_scope(cb->env, &scope); - + if (scope == nullptr) { + MMI_HILOGE("scope is nullptr"); + return; + } napi_value object = JsUtil::GetEnableInfo(cb); if (object == nullptr) { MMI_HILOGE("object is nullptr"); @@ -381,14 +297,19 @@ void JsEventTarget::CallEnableAsyncWork(uv_work_t *work, int32_t status) CHKPV(work); if (work->data == nullptr) { JsUtil::DeletePtr(work); - MMI_HILOGE("Check data is null"); + MMI_HILOGE("Check data is nullptr"); return; } - std::unique_ptr cb = GetCallbackInfo(work); - CHKPV(cb); + sptr cb(static_cast(work->data)); + JsUtil::DeletePtr(work); + cb->DecStrongRef(nullptr); + CHKPV(cb->env); napi_handle_scope scope = nullptr; napi_open_handle_scope(cb->env, &scope); - + if (scope == nullptr) { + MMI_HILOGE("scope is nullptr"); + return; + } napi_value object = JsUtil::GetEnableInfo(cb); if (object == nullptr) { MMI_HILOGE("object is nullptr"); @@ -408,15 +329,19 @@ void JsEventTarget::CallStartPromiseWork(uv_work_t *work, int32_t status) CHKPV(work); if (work->data == nullptr) { JsUtil::DeletePtr(work); - MMI_HILOGE("Check data is null"); + MMI_HILOGE("Check data is nullptr"); return; } - std::unique_ptr cb = GetCallbackInfo(work); - CHKPV(cb); + sptr cb(static_cast(work->data)); + JsUtil::DeletePtr(work); + cb->DecStrongRef(nullptr); CHKPV(cb->env); napi_handle_scope scope = nullptr; napi_open_handle_scope(cb->env, &scope); - + if (scope == nullptr) { + MMI_HILOGE("scope is nullptr"); + return; + } napi_value object = JsUtil::GetStartInfo(cb); if (object == nullptr) { MMI_HILOGE("object is nullptr"); @@ -443,14 +368,19 @@ void JsEventTarget::CallStartAsyncWork(uv_work_t *work, int32_t status) CHKPV(work); if (work->data == nullptr) { JsUtil::DeletePtr(work); - MMI_HILOGE("Check data is null"); + MMI_HILOGE("Check data is nullptr"); return; } - std::unique_ptr cb = GetCallbackInfo(work); - CHKPV(cb); + sptr cb(static_cast(work->data)); + JsUtil::DeletePtr(work); + cb->DecStrongRef(nullptr); + CHKPV(cb->env); napi_handle_scope scope = nullptr; napi_open_handle_scope(cb->env, &scope); - + if (scope == nullptr) { + MMI_HILOGE("scope is nullptr"); + return; + } napi_value object = JsUtil::GetStartInfo(cb); if (object == nullptr) { MMI_HILOGE("object is nullptr"); @@ -470,15 +400,19 @@ void JsEventTarget::CallStopPromiseWork(uv_work_t *work, int32_t status) CHKPV(work); if (work->data == nullptr) { JsUtil::DeletePtr(work); - MMI_HILOGE("Check data is null"); + MMI_HILOGE("Check data is nullptr"); return; } - std::unique_ptr cb = GetCallbackInfo(work); - CHKPV(cb); + sptr cb(static_cast(work->data)); + JsUtil::DeletePtr(work); + cb->DecStrongRef(nullptr); CHKPV(cb->env); napi_handle_scope scope = nullptr; napi_open_handle_scope(cb->env, &scope); - + if (scope == nullptr) { + MMI_HILOGE("scope is nullptr"); + return; + } napi_value object = JsUtil::GetStopInfo(cb); if (object == nullptr) { MMI_HILOGE("object is nullptr"); @@ -506,14 +440,19 @@ void JsEventTarget::CallStopAsyncWork(uv_work_t *work, int32_t status) CHKPV(work); if (work->data == nullptr) { JsUtil::DeletePtr(work); - MMI_HILOGE("Check data is null"); + MMI_HILOGE("Check data is nullptr"); return; } - std::unique_ptr cb = GetCallbackInfo(work); - CHKPV(cb); + sptr cb(static_cast(work->data)); + JsUtil::DeletePtr(work); + cb->DecStrongRef(nullptr); + CHKPV(cb->env); napi_handle_scope scope = nullptr; napi_open_handle_scope(cb->env, &scope); - + if (scope == nullptr) { + MMI_HILOGE("scope is nullptr"); + return; + } napi_value object = JsUtil::GetStopInfo(cb); if (object == nullptr) { MMI_HILOGE("object is nullptr"); @@ -533,14 +472,19 @@ void JsEventTarget::CallGetStatePromiseWork(uv_work_t *work, int32_t status) CHKPV(work); if (work->data == nullptr) { JsUtil::DeletePtr(work); - MMI_HILOGE("Check data is null"); + MMI_HILOGE("Check data is nullptr"); return; } - std::unique_ptr cb = GetCallbackInfo(work); - CHKPV(cb); + sptr cb(static_cast(work->data)); + JsUtil::DeletePtr(work); + cb->DecStrongRef(nullptr); CHKPV(cb->env); napi_handle_scope scope = nullptr; napi_open_handle_scope(cb->env, &scope); + if (scope == nullptr) { + MMI_HILOGE("scope is nullptr"); + return; + } napi_value object = JsUtil::GetStateInfo(cb); if (object == nullptr) { MMI_HILOGE("object is nullptr"); @@ -557,21 +501,30 @@ void JsEventTarget::CallGetStateAsyncWork(uv_work_t *work, int32_t status) CHKPV(work); if (work->data == nullptr) { JsUtil::DeletePtr(work); - MMI_HILOGE("Check data is null"); + MMI_HILOGE("Check data is nullptr"); return; } - std::unique_ptr cb = GetCallbackInfo(work); - CHKPV(cb); + sptr cb(static_cast(work->data)); + JsUtil::DeletePtr(work); + cb->DecStrongRef(nullptr); + CHKPV(cb->env); napi_handle_scope scope = nullptr; napi_open_handle_scope(cb->env, &scope); - - napi_value object[2] = { 0 }; - CHKRV_SCOPE(cb->env, napi_get_undefined(cb->env, &object[0]), GET_UNDEFINED, scope); - object[1] = JsUtil::GetStateInfo(cb); + if (scope == nullptr) { + MMI_HILOGE("scope is nullptr"); + return; + } + napi_value resultObj[2]; + CHKRV_SCOPE(cb->env, napi_get_undefined(cb->env, &resultObj[0]), GET_UNDEFINED, scope); + resultObj[1] = JsUtil::GetStateInfo(cb); + if (resultObj[1] == nullptr) { + MMI_HILOGE("Object is nullptr"); + napi_close_handle_scope(cb->env, scope); + } napi_value handler = nullptr; CHKRV_SCOPE(cb->env, napi_get_reference_value(cb->env, cb->ref, &handler), GET_REFERENCE_VALUE, scope); napi_value result = nullptr; - CHKRV_SCOPE(cb->env, napi_call_function(cb->env, nullptr, handler, 2, object, &result), CALL_FUNCTION, scope); + CHKRV_SCOPE(cb->env, napi_call_function(cb->env, nullptr, handler, 2, resultObj, &result), CALL_FUNCTION, scope); napi_close_handle_scope(cb->env, scope); } @@ -582,7 +535,7 @@ void JsEventTarget::EmitCooperateMessageEvent(uv_work_t *work, int32_t status) CHKPV(work); if (work->data == nullptr) { JsUtil::DeletePtr(work); - MMI_HILOGE("Check data is null"); + MMI_HILOGE("Check data is nullptr"); return; } @@ -604,7 +557,7 @@ void JsEventTarget::EmitCooperateMessageEvent(uv_work_t *work, int32_t status) } napi_value deviceDescriptor = nullptr; CHKRV_SCOPE(item->env, napi_create_string_utf8(item->env, item->data.deviceDescriptor.c_str(), - NAPI_AUTO_LENGTH, &deviceDescriptor), CREATE_STRING, scope); + NAPI_AUTO_LENGTH, &deviceDescriptor), CREATE_STRING_UTF8, scope); napi_value eventMsg = nullptr; CHKRV_SCOPE(item->env, napi_create_int32(item->env, static_cast(item->data.msg), &eventMsg), CREATE_INT32, scope); @@ -623,25 +576,6 @@ void JsEventTarget::EmitCooperateMessageEvent(uv_work_t *work, int32_t status) } } -std::unique_ptr JsEventTarget::GetCallbackInfo(uv_work_t *work) -{ - CALL_INFO_TRACE; - std::lock_guard guard(mutex_); - int32_t *uData = static_cast(work->data); - int32_t userData = *uData; - JsUtil::DeletePtr(work); - JsUtil::DeletePtr(uData); - - auto iter = callback_.find(userData); - if (iter == callback_.end()) { - MMI_HILOGE("Find userData failed"); - return nullptr; - } - auto cb = std::move(iter->second); - callback_.erase(iter); - return cb; -} - void JsEventTarget::HandleExecuteResult(napi_env env, int32_t errCode) { if (errCode != OTHER_ERROR && errCode != RET_OK) { diff --git a/frameworks/napi/input_device_cooperate/src/js_input_device_cooperate_context.cpp b/frameworks/napi/input_device_cooperate/src/js_input_device_cooperate_context.cpp index 65dd12af2dde0d1c67b84e8c8b23363841a79323..2af0c11bbb84c94139065286b00e55ed739ec733 100755 --- a/frameworks/napi/input_device_cooperate/src/js_input_device_cooperate_context.cpp +++ b/frameworks/napi/input_device_cooperate/src/js_input_device_cooperate_context.cpp @@ -63,7 +63,7 @@ napi_value JsInputDeviceCooperateContext::Enable(napi_env env, napi_callback_inf CALL_INFO_TRACE; size_t argc = 2; napi_value argv[2] = {}; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc == 0) { MMI_HILOGE("Wrong number of parameters"); @@ -76,9 +76,10 @@ napi_value JsInputDeviceCooperateContext::Enable(napi_env env, napi_callback_inf return nullptr; } bool enable = false; - CHKRP(env, napi_get_value_bool(env, argv[0], &enable), GET_BOOL); + CHKRP(napi_get_value_bool(env, argv[0], &enable), GET_VALUE_BOOL); JsInputDeviceCooperateContext *jsDev = JsInputDeviceCooperateContext::GetInstance(env); + CHKPP(jsDev); auto jsInputDeviceMgr = jsDev->GetJsInputDeviceCooperateMgr(); if (argc == 1) { return jsInputDeviceMgr->Enable(env, enable); @@ -96,7 +97,7 @@ napi_value JsInputDeviceCooperateContext::Start(napi_env env, napi_callback_info CALL_INFO_TRACE; size_t argc = 3; napi_value argv[3] = {}; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc < 2) { MMI_HILOGE("Wrong number of parameters"); @@ -116,12 +117,13 @@ napi_value JsInputDeviceCooperateContext::Start(napi_env env, napi_callback_info char sinkDeviceDescriptor[MAX_STRING_LEN] = {}; int32_t srcInputDeviceId = 0; size_t length = 0; - CHKRP(env, napi_get_value_string_utf8(env, argv[0], sinkDeviceDescriptor, - sizeof(sinkDeviceDescriptor), &length), GET_STRING); + CHKRP(napi_get_value_string_utf8(env, argv[0], sinkDeviceDescriptor, + sizeof(sinkDeviceDescriptor), &length), GET_VALUE_STRING_UTF8); std::string sinkDeviceDescriptor_ = sinkDeviceDescriptor; - CHKRP(env, napi_get_value_int32(env, argv[1], &srcInputDeviceId), GET_INT32); + CHKRP(napi_get_value_int32(env, argv[1], &srcInputDeviceId), GET_VALUE_INT32); JsInputDeviceCooperateContext *jsDev = JsInputDeviceCooperateContext::GetInstance(env); + CHKPP(jsDev); auto jsInputDeviceMgr = jsDev->GetJsInputDeviceCooperateMgr(); if (argc == 2) { return jsInputDeviceMgr->Start(env, sinkDeviceDescriptor, srcInputDeviceId); @@ -139,9 +141,10 @@ napi_value JsInputDeviceCooperateContext::Stop(napi_env env, napi_callback_info CALL_INFO_TRACE; size_t argc = 1; napi_value argv[1] = {}; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); JsInputDeviceCooperateContext *jsDev = JsInputDeviceCooperateContext::GetInstance(env); + CHKPP(jsDev); auto jsInputDeviceMgr = jsDev->GetJsInputDeviceCooperateMgr(); if (argc == 0) { return jsInputDeviceMgr->Stop(env); @@ -159,7 +162,7 @@ napi_value JsInputDeviceCooperateContext::GetState(napi_env env, napi_callback_i CALL_INFO_TRACE; size_t argc = 2; napi_value argv[2] = {}; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc == 0) { MMI_HILOGE("Wrong number of parameters"); @@ -167,17 +170,18 @@ napi_value JsInputDeviceCooperateContext::GetState(napi_env env, napi_callback_i return nullptr; } if (!UtilNapi::TypeOf(env, argv[0], napi_string)) { - MMI_HILOGE("The first paramter is not string"); + MMI_HILOGE("The first parameter is not string"); THROWERR_API9(env, COMMON_PARAMETER_ERROR, "deviceDescriptor", "string"); return nullptr; } char deviceDescriptor[MAX_STRING_LEN] = { 0 }; size_t length = 0; - CHKRP(env, napi_get_value_string_utf8(env, argv[0], deviceDescriptor, - sizeof(deviceDescriptor), &length), GET_STRING); + CHKRP(napi_get_value_string_utf8(env, argv[0], deviceDescriptor, + sizeof(deviceDescriptor), &length), GET_VALUE_STRING_UTF8); std::string deviceDescriptor_ = deviceDescriptor; JsInputDeviceCooperateContext *jsDev = JsInputDeviceCooperateContext::GetInstance(env); + CHKPP(jsDev); auto jsInputDeviceMgr = jsDev->GetJsInputDeviceCooperateMgr(); if (argc == 1) { return jsInputDeviceMgr->GetState(env, deviceDescriptor_); @@ -195,7 +199,7 @@ napi_value JsInputDeviceCooperateContext::On(napi_env env, napi_callback_info in CALL_INFO_TRACE; size_t argc = 2; napi_value argv[2] = {}; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc == 0) { MMI_HILOGE("Wrong number of parameters"); @@ -209,17 +213,21 @@ napi_value JsInputDeviceCooperateContext::On(napi_env env, napi_callback_info in } char type[MAX_STRING_LEN] = {}; size_t length = 0; - CHKRP(env, napi_get_value_string_utf8(env, argv[0], type, sizeof(type), &length), GET_STRING); - std::string type_ = type; - + CHKRP(napi_get_value_string_utf8(env, argv[0], type, sizeof(type), &length), GET_VALUE_STRING_UTF8); + if (std::strcmp(type, "cooperation") != 0) { + THROWERR(env, "Register listener failed, the first parameter is invalid"); + MMI_HILOGE("Register listener failed, the first parameter is invalid"); + return nullptr; + } JsInputDeviceCooperateContext *jsDev = JsInputDeviceCooperateContext::GetInstance(env); + CHKPP(jsDev); auto jsInputDeviceMgr = jsDev->GetJsInputDeviceCooperateMgr(); if (!UtilNapi::TypeOf(env, argv[1], napi_function)) { - MMI_HILOGE("The seocond parameter is not function"); + MMI_HILOGE("The second parameter is not function"); THROWERR_API9(env, COMMON_PARAMETER_ERROR, "callback", "function"); return nullptr; } - jsInputDeviceMgr->RegisterListener(env, type_, argv[1]); + jsInputDeviceMgr->RegisterListener(env, type, argv[1]); return nullptr; } @@ -228,7 +236,7 @@ napi_value JsInputDeviceCooperateContext::Off(napi_env env, napi_callback_info i CALL_INFO_TRACE; size_t argc = 2; napi_value argv[2] = {}; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc == 0) { MMI_HILOGE("Wrong number of parameters"); @@ -242,10 +250,11 @@ napi_value JsInputDeviceCooperateContext::Off(napi_env env, napi_callback_info i } char type[MAX_STRING_LEN] = {}; size_t length = 0; - CHKRP(env, napi_get_value_string_utf8(env, argv[0], type, sizeof(type), &length), GET_STRING); + CHKRP(napi_get_value_string_utf8(env, argv[0], type, sizeof(type), &length), GET_VALUE_STRING_UTF8); std::string type_ = type; JsInputDeviceCooperateContext *jsDev = JsInputDeviceCooperateContext::GetInstance(env); + CHKPP(jsDev); auto jsInputDeviceMgr = jsDev->GetJsInputDeviceCooperateMgr(); if (argc == 1) { jsInputDeviceMgr->UnregisterListener(env, type_); @@ -270,27 +279,27 @@ napi_value JsInputDeviceCooperateContext::CreateInstance(napi_env env) { CALL_INFO_TRACE; napi_value global = nullptr; - CHKRP(env, napi_get_global(env, &global), GET_GLOBAL); + CHKRP(napi_get_global(env, &global), GET_GLOBAL); constexpr char className[] = "JsInputDeviceCooperateContext"; napi_value jsClass = nullptr; napi_property_descriptor desc[] = {}; napi_status status = napi_define_class(env, className, sizeof(className), JsInputDeviceCooperateContext::JsConstructor, nullptr, sizeof(desc) / sizeof(desc[0]), nullptr, &jsClass); - CHKRP(env, status, DEFINE_CLASS); + CHKRP(status, DEFINE_CLASS); status = napi_set_named_property(env, global, INPUT_DEVICE_CLASS, jsClass); - CHKRP(env, status, SET_NAMED_PROPERTY); + CHKRP(status, SET_NAMED_PROPERTY); napi_value jsInstance = nullptr; - CHKRP(env, napi_new_instance(env, jsClass, 0, nullptr, &jsInstance), NEW_INSTANCE); - CHKRP(env, napi_set_named_property(env, global, INPUT_DEVICE_COOPERATE, jsInstance), + CHKRP(napi_new_instance(env, jsClass, 0, nullptr, &jsInstance), NEW_INSTANCE); + CHKRP(napi_set_named_property(env, global, INPUT_DEVICE_COOPERATE, jsInstance), SET_NAMED_PROPERTY); JsInputDeviceCooperateContext *jsContext = nullptr; - CHKRP(env, napi_unwrap(env, jsInstance, (void**)&jsContext), UNWRAP); + CHKRP(napi_unwrap(env, jsInstance, (void**)&jsContext), UNWRAP); CHKPP(jsContext); - CHKRP(env, napi_create_reference(env, jsInstance, 1, &(jsContext->contextRef_)), CREATE_REFERENCE); + CHKRP(napi_create_reference(env, jsInstance, 1, &(jsContext->contextRef_)), CREATE_REFERENCE); uint32_t refCount = 0; status = napi_reference_ref(env, jsContext->contextRef_, &refCount); @@ -307,7 +316,7 @@ napi_value JsInputDeviceCooperateContext::JsConstructor(napi_env env, napi_callb CALL_INFO_TRACE; napi_value thisVar = nullptr; void *data = nullptr; - CHKRP(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, &data), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, &data), GET_CB_INFO); JsInputDeviceCooperateContext *jsContext = new (std::nothrow) JsInputDeviceCooperateContext(); CHKPP(jsContext); @@ -330,24 +339,24 @@ JsInputDeviceCooperateContext *JsInputDeviceCooperateContext::GetInstance(napi_e { CALL_INFO_TRACE; napi_value global = nullptr; - CHKRP(env, napi_get_global(env, &global), GET_GLOBAL); + CHKRP(napi_get_global(env, &global), GET_GLOBAL); bool result = false; - CHKRP(env, napi_has_named_property(env, global, INPUT_DEVICE_COOPERATE, &result), HAS_NAMED_PROPERTY); + CHKRP(napi_has_named_property(env, global, INPUT_DEVICE_COOPERATE, &result), HAS_NAMED_PROPERTY); if (!result) { MMI_HILOGE("multimodal_input_device_cooperate was not found"); return nullptr; } napi_value object = nullptr; - CHKRP(env, napi_get_named_property(env, global, INPUT_DEVICE_COOPERATE, &object), GET_NAMED_PROPERTY); + CHKRP(napi_get_named_property(env, global, INPUT_DEVICE_COOPERATE, &object), GET_NAMED_PROPERTY); if (object == nullptr) { MMI_HILOGE("object is nullptr"); return nullptr; } JsInputDeviceCooperateContext *instance = nullptr; - CHKRP(env, napi_unwrap(env, object, (void**)&instance), UNWRAP); + CHKRP(napi_unwrap(env, object, (void**)&instance), UNWRAP); if (instance == nullptr) { MMI_HILOGE("instance is nullptr"); return nullptr; @@ -357,62 +366,34 @@ JsInputDeviceCooperateContext *JsInputDeviceCooperateContext::GetInstance(napi_e void JsInputDeviceCooperateContext::DeclareDeviceCooperateInterface(napi_env env, napi_value exports) { - napi_value openSuccess = nullptr; - CHKRV(env, napi_create_int32(env, static_cast(CooperationMessage::OPEN_SUCCESS), &openSuccess), - CREATE_INT32); - napi_value openFail = nullptr; - CHKRV(env, napi_create_int32(env, static_cast(CooperationMessage::OPEN_FAIL), &openFail), - CREATE_INT32); napi_value infoStart = nullptr; - CHKRV(env, napi_create_int32(env, static_cast(CooperationMessage::INFO_START), &infoStart), + CHKRV(napi_create_int32(env, static_cast(CooperationMessage::INFO_START), &infoStart), CREATE_INT32); napi_value infoSuccess = nullptr; - CHKRV(env, napi_create_int32(env, static_cast(CooperationMessage::INFO_SUCCESS), &infoSuccess), + CHKRV(napi_create_int32(env, static_cast(CooperationMessage::INFO_SUCCESS), &infoSuccess), CREATE_INT32); napi_value infoFail = nullptr; - CHKRV(env, napi_create_int32(env, static_cast(CooperationMessage::INFO_FAIL), &infoFail), - CREATE_INT32); - napi_value close = nullptr; - CHKRV(env, napi_create_int32(env, static_cast(CooperationMessage::CLOSE), &close), - CREATE_INT32); - napi_value closeSuccess = nullptr; - CHKRV(env, napi_create_int32(env, static_cast(CooperationMessage::CLOSE_SUCCESS), &closeSuccess), - CREATE_INT32); - napi_value stop = nullptr; - CHKRV(env, napi_create_int32(env, static_cast(CooperationMessage::STOP), &stop), - CREATE_INT32); - napi_value stopSuccess = nullptr; - CHKRV(env, napi_create_int32(env, static_cast(CooperationMessage::STOP_SUCCESS), &stopSuccess), - CREATE_INT32); - napi_value stopFail = nullptr; - CHKRV(env, napi_create_int32(env, static_cast(CooperationMessage::STOP_FAIL), &stopFail), + CHKRV(napi_create_int32(env, static_cast(CooperationMessage::INFO_FAIL), &infoFail), CREATE_INT32); napi_value stateOn = nullptr; - CHKRV(env, napi_create_int32(env, static_cast(CooperationMessage::STATE_ON), &stateOn), + CHKRV(napi_create_int32(env, static_cast(CooperationMessage::STATE_ON), &stateOn), CREATE_INT32); napi_value stateOff = nullptr; - CHKRV(env, napi_create_int32(env, static_cast(CooperationMessage::STATE_OFF), &stateOff), + CHKRV(napi_create_int32(env, static_cast(CooperationMessage::STATE_OFF), &stateOff), CREATE_INT32); napi_property_descriptor msg[] = { - DECLARE_NAPI_STATIC_PROPERTY("MSG_COOPERATE_OPEN_SUCCESS", openSuccess), - DECLARE_NAPI_STATIC_PROPERTY("MSG_COOPERATE_OPEN_FAIL", openFail), DECLARE_NAPI_STATIC_PROPERTY("MSG_COOPERATE_INFO_START", infoStart), DECLARE_NAPI_STATIC_PROPERTY("MSG_COOPERATE_INFO_SUCCESS", infoSuccess), DECLARE_NAPI_STATIC_PROPERTY("MSG_COOPERATE_INFO_FAIL", infoFail), - DECLARE_NAPI_STATIC_PROPERTY("MSG_COOPERATE_CLOSE", close), - DECLARE_NAPI_STATIC_PROPERTY("MSG_COOPERATE_CLOSE_SUCCESS", closeSuccess), - DECLARE_NAPI_STATIC_PROPERTY("MSG_COOPERATE_STOP", stop), - DECLARE_NAPI_STATIC_PROPERTY("MSG_COOPERATE_STOP_SUCCESS", stopSuccess), - DECLARE_NAPI_STATIC_PROPERTY("MSG_COOPERATE_STOP_FAIL", stopFail), DECLARE_NAPI_STATIC_PROPERTY("MSG_COOPERATE_STATE_ON", stateOn), DECLARE_NAPI_STATIC_PROPERTY("MSG_COOPERATE_STATE_OFF", stateOff), }; napi_value eventMsg = nullptr; - CHKRV(env, napi_define_class(env, "EventMsg", NAPI_AUTO_LENGTH, EnumClassConstructor, nullptr, + CHKRV(napi_define_class(env, "EventMsg", NAPI_AUTO_LENGTH, EnumClassConstructor, nullptr, sizeof(msg) / sizeof(*msg), msg, &eventMsg), DEFINE_CLASS); - CHKRV(env, napi_set_named_property(env, exports, "EventMsg", eventMsg), SET_NAMED_PROPERTY); + CHKRV(napi_set_named_property(env, exports, "EventMsg", eventMsg), SET_NAMED_PROPERTY); } void JsInputDeviceCooperateContext::DeclareDeviceCooperateData(napi_env env, napi_value exports) @@ -425,7 +406,7 @@ void JsInputDeviceCooperateContext::DeclareDeviceCooperateData(napi_env env, nap DECLARE_NAPI_STATIC_FUNCTION("on", On), DECLARE_NAPI_STATIC_FUNCTION("off", Off), }; - CHKRV(env, napi_define_properties(env, exports, + CHKRV(napi_define_properties(env, exports, sizeof(functions) / sizeof(*functions), functions), DEFINE_PROPERTIES); } @@ -435,7 +416,7 @@ napi_value JsInputDeviceCooperateContext::EnumClassConstructor(napi_env env, nap napi_value args[1] = {}; napi_value result = nullptr; void *data = nullptr; - CHKRP(env, napi_get_cb_info(env, info, &argc, args, &result, &data), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, args, &result, &data), GET_CB_INFO); return result; } } // namespace MMI diff --git a/frameworks/napi/input_device_cooperate/src/js_input_device_cooperate_manager.cpp b/frameworks/napi/input_device_cooperate/src/js_input_device_cooperate_manager.cpp old mode 100755 new mode 100644 index e725929cbe52218c83a6b1a62c793d5b42da3e8b..9951a63e2d4db53e07a1d5ff0c6310bc881a47b9 --- a/frameworks/napi/input_device_cooperate/src/js_input_device_cooperate_manager.cpp +++ b/frameworks/napi/input_device_cooperate/src/js_input_device_cooperate_manager.cpp @@ -19,7 +19,7 @@ #include "define_multimodal.h" #include "input_device_cooperate_impl.h" -#include "input_manager.h" +#include "input_manager_impl.h" #include "mmi_log.h" #include "napi_constants.h" #include "util_napi.h" @@ -33,62 +33,50 @@ constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "JsInp napi_value JsInputDeviceCooperateManager::Enable(napi_env env, bool enable, napi_value handle) { CALL_INFO_TRACE; - std::lock_guard guard(mutex_); - int32_t userData = InputDevCooperateImpl.GetUserData(); - napi_value result = CreateCallbackInfo(env, handle, userData); - auto callback = std::bind(EmitJsEnable, userData, std::placeholders::_1, std::placeholders::_2); - int32_t errCode = InputMgr->EnableInputDeviceCooperate(enable, callback); + sptr cb = new (std::nothrow) JsUtil::CallbackInfo(); + CHKPP(cb); + napi_value ret = CreateCallbackInfo(env, handle, cb); + auto callback = std::bind(EmitJsEnable, cb, std::placeholders::_1, std::placeholders::_2); + int32_t errCode = InputMgrImpl.EnableInputDeviceCooperate(enable, callback); HandleExecuteResult(env, errCode); - if (errCode != RET_OK) { - RemoveCallbackInfo(userData); - } - return result; + return ret; } napi_value JsInputDeviceCooperateManager::Start(napi_env env, const std::string &sinkDeviceDescriptor, int32_t srcInputDeviceId, napi_value handle) { CALL_INFO_TRACE; - std::lock_guard guard(mutex_); - int32_t userData = InputDevCooperateImpl.GetUserData(); - napi_value result = CreateCallbackInfo(env, handle, userData); - auto callback = std::bind(EmitJsStart, userData, std::placeholders::_1, std::placeholders::_2); - int32_t errCode = InputMgr->StartInputDeviceCooperate(sinkDeviceDescriptor, srcInputDeviceId, callback); + sptr cb = new (std::nothrow) JsUtil::CallbackInfo(); + CHKPP(cb); + napi_value ret = CreateCallbackInfo(env, handle, cb); + auto callback = std::bind(EmitJsStart, cb, std::placeholders::_1, std::placeholders::_2); + int32_t errCode = InputMgrImpl.StartInputDeviceCooperate(sinkDeviceDescriptor, srcInputDeviceId, callback); HandleExecuteResult(env, errCode); - if (errCode != RET_OK) { - RemoveCallbackInfo(userData); - } - return result; + return ret; } napi_value JsInputDeviceCooperateManager::Stop(napi_env env, napi_value handle) { CALL_INFO_TRACE; - std::lock_guard guard(mutex_); - int32_t userData = InputDevCooperateImpl.GetUserData(); - napi_value result = CreateCallbackInfo(env, handle, userData); - auto callback = std::bind(EmitJsStop, userData, std::placeholders::_1, std::placeholders::_2); - int32_t errCode = InputMgr->StopDeviceCooperate(callback); + sptr cb = new (std::nothrow) JsUtil::CallbackInfo(); + CHKPP(cb); + napi_value ret = CreateCallbackInfo(env, handle, cb); + auto callback = std::bind(EmitJsStop, cb, std::placeholders::_1, std::placeholders::_2); + int32_t errCode = InputMgrImpl.StopDeviceCooperate(callback); HandleExecuteResult(env, errCode); - if (errCode != RET_OK) { - RemoveCallbackInfo(userData); - } - return result; + return ret; } napi_value JsInputDeviceCooperateManager::GetState(napi_env env, const std::string &deviceDescriptor, napi_value handle) { CALL_INFO_TRACE; - std::lock_guard guard(mutex_); - int32_t userData = InputDevCooperateImpl.GetUserData(); - napi_value result = CreateCallbackInfo(env, handle, userData); - auto callback = std::bind(EmitJsGetState, userData, std::placeholders::_1); - int32_t errCode = InputMgr->GetInputDeviceCooperateState(deviceDescriptor, callback); + sptr cb = new (std::nothrow) JsUtil::CallbackInfo(); + CHKPP(cb); + napi_value ret = CreateCallbackInfo(env, handle, cb); + auto callback = std::bind(EmitJsGetState, cb, std::placeholders::_1); + int32_t errCode = InputMgrImpl.GetInputDeviceCooperateState(deviceDescriptor, callback); HandleExecuteResult(env, errCode); - if (errCode != RET_OK) { - RemoveCallbackInfo(userData); - } - return result; + return ret; } void JsInputDeviceCooperateManager::RegisterListener(napi_env env, const std::string &type, napi_value handle) diff --git a/frameworks/napi/input_device_cooperate/src/js_util.cpp b/frameworks/napi/input_device_cooperate/src/js_util.cpp old mode 100755 new mode 100644 index 86f657b7af27462099a8afc16ebe0b159b518c04..42bb514f116dba4b185f04d93706f3d33637bf41 --- a/frameworks/napi/input_device_cooperate/src/js_util.cpp +++ b/frameworks/napi/input_device_cooperate/src/js_util.cpp @@ -17,8 +17,8 @@ #include "mmi_log.h" #include "napi_constants.h" -#include "util_napi_error.h" #include "util_napi.h" +#include "util_napi_error.h" namespace OHOS { namespace MMI { @@ -29,42 +29,81 @@ constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "JsUti JsUtil::CallbackInfo::~CallbackInfo() { CALL_DEBUG_ENTER; - if (ref != nullptr && env != nullptr) { - CHKRV(env, napi_delete_reference(env, ref), DELETE_REFERENCE); - env = nullptr; + if (ref == nullptr || env == nullptr) { + return; + } + DeleteNapiRef(env, ref); +} + +void JsUtil::DeleteNapiRef(napi_env env, napi_ref ref) +{ + uv_loop_s *loop = nullptr; + CHKRV(napi_get_uv_event_loop(env, &loop), GET_UV_EVENT_LOOP); + CallbackReceiveInfoWorker *dataWorker = new (std::nothrow) CallbackReceiveInfoWorker(); + if (dataWorker == nullptr) { + return; + } + + dataWorker->env = env; + dataWorker->ref = ref; + uv_work_t *work = new (std::nothrow) uv_work_t; + if (work == nullptr) { + MMI_HILOGE("deleteNapiRef new work falied."); + DeletePtr(dataWorker); + return; + } + work->data = static_cast(dataWorker); + int32_t ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, UvQueueWorkDeleteRef); + if (ret != 0) { + MMI_HILOGE("uv_queue_work failed"); + DeletePtr(dataWorker); + DeletePtr(work); + } +} + +void JsUtil::UvQueueWorkDeleteRef(uv_work_t *work, int32_t status) +{ + CHKPV(work); + CallbackReceiveInfoWorker *dataWorkerData = static_cast(work->data); + if (dataWorkerData == nullptr) { + DeletePtr(work); + return; } + CHKRV(napi_delete_reference(dataWorkerData->env, dataWorkerData->ref), DELETE_REFERENCE); + DeletePtr(dataWorkerData); + DeletePtr(work); } -napi_value JsUtil::GetEnableInfo(const std::unique_ptr &cb) +napi_value JsUtil::GetEnableInfo(sptr cb) { CHKPP(cb); CHKPP(cb->env); return GetResult(cb->env, cb->data.enableResult, cb->data.errCode); } -napi_value JsUtil::GetStartInfo(const std::unique_ptr &cb) +napi_value JsUtil::GetStartInfo(sptr cb) { CHKPP(cb); CHKPP(cb->env); return GetResult(cb->env, cb->data.startResult, cb->data.errCode); } -napi_value JsUtil::GetStopInfo(const std::unique_ptr &cb) +napi_value JsUtil::GetStopInfo(sptr cb) { CHKPP(cb); CHKPP(cb->env); return GetResult(cb->env, cb->data.stopResult, cb->data.errCode); } -napi_value JsUtil::GetStateInfo(const std::unique_ptr &cb) +napi_value JsUtil::GetStateInfo(sptr cb) { CHKPP(cb); CHKPP(cb->env); napi_value ret = nullptr; napi_value state = nullptr; - CHKRP(cb->env, napi_create_int32(cb->env, cb->data.cooperateOpened ? 1 : 0, &ret), + CHKRP(napi_create_int32(cb->env, cb->data.cooperateOpened ? 1 : 0, &ret), CREATE_INT32); - CHKRP(cb->env, napi_coerce_to_bool(cb->env, ret, &state), COERCE_TO_BOOL); + CHKRP(napi_coerce_to_bool(cb->env, ret, &state), COERCE_TO_BOOL); return state; } @@ -81,21 +120,33 @@ napi_value JsUtil::GetResult(napi_env env, bool result, int32_t errCode) return nullptr; } napi_value resultCode = nullptr; + CHKRP(napi_create_int32(env, errCode, &resultCode), CREATE_INT32); napi_value resultMessage = nullptr; - CHKRP(env, napi_create_int32(env, errCode, &resultCode), CREATE_INT32); - CHKRP(env, napi_create_string_utf8(env, napiError.msg.data(), NAPI_AUTO_LENGTH, &resultMessage), CREATE_INT32); - CHKRP(env, napi_create_error(env, nullptr, resultMessage, &object), CREATE_ERROR); - CHKRP(env, napi_set_named_property(env, object, ERR_CODE.c_str(), resultCode), SET_NAMED_PROPERTY); + CHKRP(napi_create_string_utf8(env, napiError.msg.data(), NAPI_AUTO_LENGTH, &resultMessage), + CREATE_STRING_UTF8); + CHKRP(napi_create_error(env, nullptr, resultMessage, &object), CREATE_ERROR); + CHKRP(napi_set_named_property(env, object, ERR_CODE.c_str(), resultCode), SET_NAMED_PROPERTY); } return object; } +napi_value JsUtil::GetStateResult(napi_env env, bool result) +{ + CHKPP(env); + napi_value state = nullptr; + CHKRP(napi_get_boolean(env, result, &state), GET_BOOLEAN); + napi_value object = nullptr; + CHKRP(napi_create_object(env, &object), CREATE_OBJECT); + CHKRP(napi_set_named_property(env, object, "state", state), SET_NAMED_PROPERTY); + return object; +} + bool JsUtil::IsSameHandle(napi_env env, napi_value handle, napi_ref ref) { napi_value handlerTemp = nullptr; - CHKRF(env, napi_get_reference_value(env, ref, &handlerTemp), GET_REFERENCE_VALUE); + CHKRF(napi_get_reference_value(env, ref, &handlerTemp), GET_REFERENCE_VALUE); bool isEqual = false; - CHKRF(env, napi_strict_equals(env, handle, handlerTemp, &isEqual), STRICT_EQUALS); + CHKRF(napi_strict_equals(env, handle, handlerTemp, &isEqual), STRICT_EQUALS); return isEqual; } } // namespace MMI diff --git a/frameworks/napi/input_device_cooperate/src/native_register_module.cpp b/frameworks/napi/input_device_cooperate/src/native_register_module.cpp old mode 100755 new mode 100644 index e7da0f9abd9390d284bb84b852be9540e7cd1777..10ba0342d241678f32b9ba737a997dbfc8bd84e5 --- a/frameworks/napi/input_device_cooperate/src/native_register_module.cpp +++ b/frameworks/napi/input_device_cooperate/src/native_register_module.cpp @@ -19,19 +19,19 @@ namespace OHOS { namespace MMI { -static napi_module mmiInputDeviceCooperateMoudle = { +static napi_module mmiInputDeviceCooperateModule = { .nm_version = 1, .nm_flags = 0, .nm_filename = nullptr, .nm_register_func = JsInputDeviceCooperateContext::Export, .nm_modname = "multimodalInput.inputDeviceCooperate", .nm_priv = ((void *)0), - .reserved = {0}, + .reserved = { 0 }, }; extern "C" __attribute__((constructor)) void RegisterModule(void) { - napi_module_register(&mmiInputDeviceCooperateMoudle); + napi_module_register(&mmiInputDeviceCooperateModule); } } // namespace MMI } // namespace OHOS diff --git a/frameworks/napi/input_event_client/BUILD.gn b/frameworks/napi/input_event_client/BUILD.gn index 61077014f1b83499d031501c918babad5bbd2b92..72b61719702056803e280a46f1d6cd1065c06647 100644 --- a/frameworks/napi/input_event_client/BUILD.gn +++ b/frameworks/napi/input_event_client/BUILD.gn @@ -23,15 +23,6 @@ config("inputeventclient_config") { "//foundation/multimodalinput/input/interfaces/native/innerkits/proxy/include", "//commonlibrary/c_utils/base/include", ] - - defines = [] - if (input_feature_libinput) { - defines += [ "OHOS_BUILD_LIBINPUT" ] - } - - if (input_feature_hdf) { - defines += [ "OHOS_BUILD_HDF" ] - } } ohos_shared_library("inputeventclient") { diff --git a/frameworks/napi/input_event_client/include/js_register_module.h b/frameworks/napi/input_event_client/include/js_register_module.h index dc32413b6572e6a37438a35e1629d1099be40948..bc5551a3d2446f2482393b1049d3fe9ab761c2b7 100644 --- a/frameworks/napi/input_event_client/include/js_register_module.h +++ b/frameworks/napi/input_event_client/include/js_register_module.h @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef JS_REGISTER_MODULE_H #define JS_REGISTER_MODULE_H diff --git a/frameworks/napi/input_event_client/include/js_register_util.h b/frameworks/napi/input_event_client/include/js_register_util.h index cda971976562046755790601e4a7b0790ab2047b..079284042e769b41c7470d9bbb8afc7c309272c5 100644 --- a/frameworks/napi/input_event_client/include/js_register_util.h +++ b/frameworks/napi/input_event_client/include/js_register_util.h @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef JS_REGISTER_UTIL_H #define JS_REGISTER_UTIL_H diff --git a/frameworks/napi/input_event_client/src/js_register_module.cpp b/frameworks/napi/input_event_client/src/js_register_module.cpp index 10da3d8c989ca7537985755846f71bce24d28ecb..f452b735bdd396dbd31cb32a90490403867eda5e 100644 --- a/frameworks/napi/input_event_client/src/js_register_module.cpp +++ b/frameworks/napi/input_event_client/src/js_register_module.cpp @@ -35,27 +35,27 @@ static napi_value InjectEvent(napi_env env, napi_callback_info info) napi_value result = nullptr; size_t argc = 1; napi_value argv[1] = { 0 }; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc < 1) { - MMI_HILOGE("Paramater number error"); + MMI_HILOGE("Parameter number error"); THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "parameter number error"); return nullptr; } napi_valuetype tmpType = napi_undefined; - CHKRP(env, napi_typeof(env, argv[0], &tmpType), TYPEOF); + CHKRP(napi_typeof(env, argv[0], &tmpType), TYPEOF); if (tmpType != napi_object) { MMI_HILOGE("KeyEvent is not napi_object"); THROWERR_API9(env, COMMON_PARAMETER_ERROR, "KeyEvent", "object"); return nullptr; } napi_value keyHandle = nullptr; - CHKRP(env, napi_get_named_property(env, argv[0], "KeyEvent", &keyHandle), GET_NAMED_PROPERTY); + CHKRP(napi_get_named_property(env, argv[0], "KeyEvent", &keyHandle), GET_NAMED_PROPERTY); if (keyHandle == nullptr) { MMI_HILOGE("KeyEvent is nullptr"); THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "KeyEvent not found"); return nullptr; } - CHKRP(env, napi_typeof(env, keyHandle, &tmpType), TYPEOF); + CHKRP(napi_typeof(env, keyHandle, &tmpType), TYPEOF); if (tmpType != napi_object) { MMI_HILOGE("KeyEvent is not napi_object"); THROWERR_API9(env, COMMON_PARAMETER_ERROR, "KeyEvent", "object"); @@ -111,7 +111,7 @@ static napi_value InjectEvent(napi_env env, napi_callback_info info) item.SetDownTime(static_cast(keyDownDuration)); keyEvent->AddKeyItem(item); InputManager::GetInstance()->SimulateInputEvent(keyEvent); - CHKRP(env, napi_create_int32(env, 0, &result), CREATE_INT32); + CHKRP(napi_create_int32(env, 0, &result), CREATE_INT32); return result; } diff --git a/frameworks/napi/input_event_client/src/js_register_util.cpp b/frameworks/napi/input_event_client/src/js_register_util.cpp index dc8c9d09be39d07e8aa132b7e7e9b1b2436f97bd..6426d245df034ef656b37ea5ef5d2c4af22911b3 100644 --- a/frameworks/napi/input_event_client/src/js_register_util.cpp +++ b/frameworks/napi/input_event_client/src/js_register_util.cpp @@ -17,10 +17,10 @@ #include +#include "js_register_module.h" #include "napi_constants.h" #include "util_napi.h" #include "util_napi_error.h" -#include "js_register_module.h" namespace OHOS { namespace MMI { @@ -30,20 +30,20 @@ constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "JSReg int32_t GetNamedPropertyBool(const napi_env& env, const napi_value& object, const std::string& name, bool& ret) { napi_value napiValue = {}; - CHKRF(env, napi_get_named_property(env, object, name.c_str(), &napiValue), GET_NAMED_PROPERTY); + CHKRF(napi_get_named_property(env, object, name.c_str(), &napiValue), GET_NAMED_PROPERTY); if (napiValue == nullptr) { MMI_HILOGE("The value is null"); THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "Invalid KeyEvent"); return RET_ERR; } napi_valuetype tmpType = napi_undefined; - CHKRF(env, napi_typeof(env, napiValue, &tmpType), TYPEOF); + CHKRF(napi_typeof(env, napiValue, &tmpType), TYPEOF); if (tmpType != napi_boolean) { MMI_HILOGE("The name is not bool"); THROWERR_API9(env, COMMON_PARAMETER_ERROR, name.c_str(), "bool"); return RET_ERR; } - CHKRF(env, napi_get_value_bool(env, napiValue, &ret), GET_BOOL); + CHKRF(napi_get_value_bool(env, napiValue, &ret), GET_VALUE_BOOL); return RET_OK; } diff --git a/frameworks/napi/input_monitor/BUILD.gn b/frameworks/napi/input_monitor/BUILD.gn index 3e5d38555541ae6e9519cd52da83558abd2b97f6..e28274bdf1ecef222d789eb17a3d6c035f931f47 100644 --- a/frameworks/napi/input_monitor/BUILD.gn +++ b/frameworks/napi/input_monitor/BUILD.gn @@ -22,33 +22,16 @@ config("inputmonitor_config") { "//foundation/multimodalinput/input/interfaces/native/innerkits/proxy/include", ] - defines = [] - if (input_feature_libinput) { - defines += [ "OHOS_BUILD_LIBINPUT" ] - } - - if (input_feature_hdf) { - defines += [ "OHOS_BUILD_HDF" ] - } - - if (input_feature_input_cooperation) { - defines += [ "OHOS_BUILD_ENABLE_COOPERATE" ] - } + defines = input_default_defines } ohos_shared_library("inputmonitor") { - sources = [ - "src/js_input_monitor.cpp", - "src/js_input_monitor_manager.cpp", - "src/js_input_monitor_module.cpp", - "src/js_input_monitor_util.cpp", - ] + sources = inputmonitor_sources configs = [ ":inputmonitor_config" ] deps = [ "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", - "//foundation/multimodalinput/input/frameworks/proxy:libmmi-common", "//foundation/multimodalinput/input/util:libmmi-util", ] diff --git a/frameworks/napi/input_monitor/include/js_input_monitor.h b/frameworks/napi/input_monitor/include/js_input_monitor.h index 3d39198271f592d4a9e314cbfe64f18461d44f34..0bba34f04b06e043eeea1618887a1b721a15010d 100644 --- a/frameworks/napi/input_monitor/include/js_input_monitor.h +++ b/frameworks/napi/input_monitor/include/js_input_monitor.h @@ -34,21 +34,21 @@ namespace MMI { using MapFun = std::map>; -class InputMonitor : public IInputEventConsumer, - public std::enable_shared_from_this { +class InputMonitor final : public IInputEventConsumer, + public std::enable_shared_from_this { public: InputMonitor() = default; DISALLOW_COPY_AND_MOVE(InputMonitor); - virtual ~InputMonitor() = default; + ~InputMonitor() override = default; int32_t Start(); void Stop(); void MarkConsumed(int32_t eventId); void SetCallback(std::function)> callback); void SetId(int32_t id); - virtual void OnInputEvent(std::shared_ptr keyEvent) const override; - virtual void OnInputEvent(std::shared_ptr pointerEvent) const override; - virtual void OnInputEvent(std::shared_ptr axisEvent) const override; + void OnInputEvent(std::shared_ptr keyEvent) const override; + void OnInputEvent(std::shared_ptr pointerEvent) const override; + void OnInputEvent(std::shared_ptr axisEvent) const override; private: std::function)> callback_; @@ -58,8 +58,7 @@ private: mutable std::mutex mutex_; }; - -class JsInputMonitor { +class JsInputMonitor final { public: static void JsCallback(uv_work_t *work, int32_t status); JsInputMonitor(napi_env jsEnv, const std::string &typeName, napi_value callback, int32_t id); diff --git a/frameworks/napi/input_monitor/include/js_input_monitor_manager.h b/frameworks/napi/input_monitor/include/js_input_monitor_manager.h index 89fcdf03be7d79e0ab059b3703e42d340df23ed3..839bbe229a6bb43f66755b3e12c8f7ddd52c54c3 100644 --- a/frameworks/napi/input_monitor/include/js_input_monitor_manager.h +++ b/frameworks/napi/input_monitor/include/js_input_monitor_manager.h @@ -29,7 +29,7 @@ namespace OHOS { namespace MMI { -class JsInputMonitorManager { +class JsInputMonitorManager final { public: static JsInputMonitorManager& GetInstance(); DISALLOW_COPY_AND_MOVE(JsInputMonitorManager); diff --git a/frameworks/napi/input_monitor/include/js_input_monitor_util.h b/frameworks/napi/input_monitor/include/js_input_monitor_util.h index 5207d8299c32a19d5b120dc1393a9b0dffc6e3e1..e6f5afbee6f50fcb39628bef68ee6aba8de3dd88 100644 --- a/frameworks/napi/input_monitor/include/js_input_monitor_util.h +++ b/frameworks/napi/input_monitor/include/js_input_monitor_util.h @@ -20,21 +20,21 @@ namespace OHOS { namespace MMI { - napi_status SetNameProperty(const napi_env& env, napi_value object, const std::string& name, bool value); - napi_status SetNameProperty(const napi_env& env, napi_value object, const std::string& name, uint16_t value); - napi_status SetNameProperty(const napi_env& env, napi_value object, const std::string& name, int32_t value); - napi_status SetNameProperty(const napi_env& env, napi_value object, const std::string& name, uint32_t value); - napi_status SetNameProperty(const napi_env& env, napi_value object, const std::string& name, float value); - napi_status SetNameProperty(const napi_env& env, napi_value object, const std::string& name, double value); - napi_status SetNameProperty(const napi_env& env, napi_value object, const std::string& name, int64_t value); - napi_status SetNameProperty(const napi_env& env, napi_value object, const std::string& name, std::string value); - napi_status SetNameProperty(const napi_env& env, napi_value object, const std::string& name, napi_value value); +napi_status SetNameProperty(const napi_env& env, napi_value object, const std::string& name, bool value); +napi_status SetNameProperty(const napi_env& env, napi_value object, const std::string& name, uint16_t value); +napi_status SetNameProperty(const napi_env& env, napi_value object, const std::string& name, int32_t value); +napi_status SetNameProperty(const napi_env& env, napi_value object, const std::string& name, uint32_t value); +napi_status SetNameProperty(const napi_env& env, napi_value object, const std::string& name, float value); +napi_status SetNameProperty(const napi_env& env, napi_value object, const std::string& name, double value); +napi_status SetNameProperty(const napi_env& env, napi_value object, const std::string& name, int64_t value); +napi_status SetNameProperty(const napi_env& env, napi_value object, const std::string& name, std::string value); +napi_status SetNameProperty(const napi_env& env, napi_value object, const std::string& name, napi_value value); - bool GetNamePropertyBool(const napi_env& env, const napi_value& object, const std::string& name); - std::string GetNamePropertyString(const napi_env& env, const napi_value& object, const std::string& name); - int32_t GetNamePropertyInt32(const napi_env& env, const napi_value& object, const std::string& name); - int64_t GetNamePropertyInt64(const napi_env& env, const napi_value& object, const std::string& name); - uint32_t GetNamePropertyUint32(const napi_env& env, const napi_value& object, const std::string& name); +bool GetNamePropertyBool(const napi_env& env, const napi_value& object, const std::string& name); +std::string GetNamePropertyString(const napi_env& env, const napi_value& object, const std::string& name); +int32_t GetNamePropertyInt32(const napi_env& env, const napi_value& object, const std::string& name); +int64_t GetNamePropertyInt64(const napi_env& env, const napi_value& object, const std::string& name); +uint32_t GetNamePropertyUint32(const napi_env& env, const napi_value& object, const std::string& name); } // namespace MMI } // namespace OHOS #endif // JS_INPUT_MONITOR_UTIL_H diff --git a/frameworks/napi/input_monitor/src/js_input_monitor.cpp b/frameworks/napi/input_monitor/src/js_input_monitor.cpp index 0d23b047e06f573e94cd8ad67f816f0115dcd589..87e13266041069c226927542e08588c3c88e3662 100644 --- a/frameworks/napi/input_monitor/src/js_input_monitor.cpp +++ b/frameworks/napi/input_monitor/src/js_input_monitor.cpp @@ -48,7 +48,7 @@ int32_t InputMonitor::Start() CALL_DEBUG_ENTER; std::lock_guard guard(mutex_); if (monitorId_ < 0) { - monitorId_ = InputMgr->AddMonitor(shared_from_this()); + monitorId_ = InputManager::GetInstance()->AddMonitor(shared_from_this()); } return monitorId_; } @@ -61,7 +61,7 @@ void InputMonitor::Stop() MMI_HILOGE("Invalid values"); return; } - InputMgr->RemoveMonitor(monitorId_); + InputManager::GetInstance()->RemoveMonitor(monitorId_); monitorId_ = -1; return; } @@ -120,7 +120,8 @@ void InputMonitor::OnInputEvent(std::shared_ptr pointerEvent) cons callback(pointerEvent); } -void InputMonitor::SetId(int32_t id) { +void InputMonitor::SetId(int32_t id) +{ id_ = id; } @@ -139,7 +140,7 @@ void InputMonitor::MarkConsumed(int32_t eventId) MMI_HILOGE("Invalid values"); return; } - InputMgr->MarkConsumed(monitorId_, eventId); + InputManager::GetInstance()->MarkConsumed(monitorId_, eventId); consumed_ = true; } @@ -154,7 +155,7 @@ JsInputMonitor::JsInputMonitor(napi_env jsEnv, const std::string &typeName, napi MMI_HILOGE("The monitor is null"); return; } - monitor_->SetCallback([jsId=id](std::shared_ptr pointerEvent) { + monitor_->SetCallback([jsId = id](std::shared_ptr pointerEvent) { auto& jsMonitor {JsInputMonMgr.GetMonitor(jsId)}; CHKPV(jsMonitor); jsMonitor->OnPointerEvent(pointerEvent); @@ -241,28 +242,28 @@ std::string JsInputMonitor::GetAction(int32_t action) const int32_t JsInputMonitor::GetJsPointerItem(const PointerEvent::PointerItem &item, napi_value value) const { if (SetNameProperty(jsEnv_, value, "globalX", item.GetDisplayX()) != napi_ok) { - THROWERR(jsEnv_, "Set globalX property failed"); + MMI_HILOGE("Set globalX property failed"); return RET_ERR; } if (SetNameProperty(jsEnv_, value, "globalY", item.GetDisplayY()) != napi_ok) { - THROWERR(jsEnv_, "Set globalY property failed"); + MMI_HILOGE("Set globalY property failed"); return RET_ERR; } if (SetNameProperty(jsEnv_, value, "localX", 0) != napi_ok) { - THROWERR(jsEnv_, "Set localX property failed"); + MMI_HILOGE("Set localX property failed"); return RET_ERR; } if (SetNameProperty(jsEnv_, value, "localY", 0) != napi_ok) { - THROWERR(jsEnv_, "Set localY property failed"); + MMI_HILOGE("Set localY property failed"); return RET_ERR; } int32_t touchArea = (item.GetWidth() + item.GetHeight()) / 2; if (SetNameProperty(jsEnv_, value, "size", touchArea) != napi_ok) { - THROWERR(jsEnv_, "Set size property failed"); + MMI_HILOGE("Set size property failed"); return RET_ERR; } if (SetNameProperty(jsEnv_, value, "force", item.GetPressure()) != napi_ok) { - THROWERR(jsEnv_, "Set force property failed"); + MMI_HILOGE("Set force property failed"); return RET_ERR; } return RET_OK; @@ -272,13 +273,13 @@ int32_t JsInputMonitor::TransformPointerEvent(const std::shared_ptrGetPointerAction())) != napi_ok) { - THROWERR(jsEnv_, "Set type property failed"); + MMI_HILOGE("Set type property failed"); return RET_ERR; } napi_value pointers = nullptr; auto status = napi_create_array(jsEnv_, &pointers); if (status != napi_ok) { - THROWERR(jsEnv_, "napi_create_array is failed"); + MMI_HILOGE("napi_create_array is failed"); return RET_ERR; } std::vector pointerItems; @@ -297,13 +298,13 @@ int32_t JsInputMonitor::TransformPointerEvent(const std::shared_ptrGetActionTime()) != napi_ok) { - THROWERR(jsEnv_, "Set timestamp property failed"); + MMI_HILOGE("Set timestamp property failed"); return RET_ERR; } if (SetNameProperty(jsEnv_, result, "deviceId", it.GetDeviceId()) != napi_ok) { - THROWERR(jsEnv_, "Set deviceId property failed"); + MMI_HILOGE("Set deviceId property failed"); return RET_ERR; } } @@ -325,17 +326,17 @@ int32_t JsInputMonitor::TransformPointerEvent(const std::shared_ptr pointerEvent, mapFun["screenId"] = std::bind(&PointerEvent::GetTargetDisplayId, pointerEvent); mapFun["windowId"] = std::bind(&PointerEvent::GetTargetWindowId, pointerEvent); mapFun["deviceId"] = std::bind(&PointerEvent::PointerItem::GetDeviceId, item); - mapFun["windowX"] = std::bind(&PointerEvent::PointerItem::GetDisplayX, item); - mapFun["windowY"] = std::bind(&PointerEvent::PointerItem::GetDisplayY, item); - mapFun["screenX"] = std::bind(&PointerEvent::PointerItem::GetWindowX, item); - mapFun["screenY"] = std::bind(&PointerEvent::PointerItem::GetWindowY, item); -#ifdef OHOS_BUILD_ENABLE_COOPERATE + mapFun["windowX"] = std::bind(&PointerEvent::PointerItem::GetWindowX, item); + mapFun["windowY"] = std::bind(&PointerEvent::PointerItem::GetWindowY, item); + mapFun["screenX"] = std::bind(&PointerEvent::PointerItem::GetDisplayX, item); + mapFun["screenY"] = std::bind(&PointerEvent::PointerItem::GetDisplayY, item); mapFun["rawDeltaX"] = std::bind(&PointerEvent::PointerItem::GetRawDx, item); mapFun["rawDeltaY"] = std::bind(&PointerEvent::PointerItem::GetRawDy, item); -#endif // OHOS_BUILD_ENABLE_COOPERATE return mapFun; } @@ -576,13 +575,15 @@ int32_t JsInputMonitor::TransformTsActionValue(int32_t pointerAction) case PointerEvent::POINTER_ACTION_CANCEL: { return CANCEL; } - case PointerEvent::POINTER_ACTION_MOVE: { + case PointerEvent::POINTER_ACTION_MOVE: + case PointerEvent::POINTER_ACTION_PULL_MOVE: { return MOVE; } case PointerEvent::POINTER_ACTION_BUTTON_DOWN: { return BUTTON_DOWN; } - case PointerEvent::POINTER_ACTION_BUTTON_UP: { + case PointerEvent::POINTER_ACTION_BUTTON_UP: + case PointerEvent::POINTER_ACTION_PULL_UP: { return BUTTON_UP; } case PointerEvent::POINTER_ACTION_AXIS_BEGIN: { @@ -611,7 +612,7 @@ int32_t JsInputMonitor::TransformMousePointerEvent(const std::shared_ptr pressedKeys = pointerEvent->GetPressedKeys(); @@ -698,22 +699,25 @@ void JsInputMonitor::OnPointerEvent(std::shared_ptr pointerEvent) } CHKPV(monitor_); CHKPV(pointerEvent); - int32_t num = 0; { std::lock_guard guard(mutex_); - std::queue> tmp; if (!evQueue_.empty()) { - auto markProcessedEvent = evQueue_.front(); - CHKPV(markProcessedEvent); - markProcessedEvent->MarkProcessed(); + if (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_DOWN || + pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_UP) { + auto markProcessedEvent = evQueue_.front(); + CHKPV(markProcessedEvent); + markProcessedEvent->MarkProcessed(); + std::queue> tmp; + std::swap(evQueue_, tmp); + evQueue_.push(pointerEvent); + } + } else { + evQueue_.push(pointerEvent); } - std::swap(evQueue_, tmp); - evQueue_.push(pointerEvent); - num = jsTaskNum_; jsTaskNum_ = 1; } - if (num < 1) { + if (!evQueue_.empty()) { int32_t *id = &monitorId_; uv_work_t *work = new (std::nothrow) uv_work_t; CHKPV(work); @@ -729,7 +733,7 @@ void JsInputMonitor::OnPointerEvent(std::shared_ptr pointerEvent) } return; } - uv_queue_work(loop, work, [](uv_work_t *work){}, &JsInputMonitor::JsCallback); + uv_queue_work(loop, work, [](uv_work_t *work) {}, &JsInputMonitor::JsCallback); } } @@ -804,6 +808,7 @@ void JsInputMonitor::OnPointerEventInJsThread(const std::string &typeName) bool retValue = false; status = napi_get_value_bool(jsEnv_, result, &retValue); if (status != napi_ok) { + napi_close_handle_scope(jsEnv_, scope); return; } if (retValue) { diff --git a/frameworks/napi/input_monitor/src/js_input_monitor_manager.cpp b/frameworks/napi/input_monitor/src/js_input_monitor_manager.cpp index 405943fa35774d8301b2f41e99a397e5d208ba89..6ac0390ebe1e577ae08e79d3cd554b7b8541096c 100644 --- a/frameworks/napi/input_monitor/src/js_input_monitor_manager.cpp +++ b/frameworks/napi/input_monitor/src/js_input_monitor_manager.cpp @@ -24,7 +24,7 @@ namespace OHOS { namespace MMI { namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "JsInputMonitorManager" }; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "JsInputMonitorManager" }; const std::string REFERENCE_UNREF = "napi_reference_unref"; constexpr int32_t MONITOR_REGISTER_EXCEED_MAX { 4100001 }; @@ -47,7 +47,6 @@ void JsInputMonitorManager::AddMonitor(napi_env jsEnv, const std::string &typeNa } } auto monitor = std::make_shared(jsEnv, typeName, callback, nextId_++); - CHKPV(monitor); int32_t ret = monitor->Start(); if (ret < 0) { MMI_HILOGE("js monitor startup failed"); @@ -216,7 +215,7 @@ void JsInputMonitorManager::RemoveEnv(std::map::iterator it) { CALL_DEBUG_ENTER; uint32_t refCount; - CHKRV(it->first, napi_reference_unref(it->first, it->second, &refCount), REFERENCE_UNREF); + CHKRV(napi_reference_unref(it->first, it->second, &refCount), REFERENCE_UNREF); envManager_.erase(it); } diff --git a/frameworks/napi/input_monitor/src/js_input_monitor_module.cpp b/frameworks/napi/input_monitor/src/js_input_monitor_module.cpp index 90beff3f0ebf5d22b3ad8ba6e58e3ae2706ed159..75e6f0b4c0e30cfc1214aa9fb2c848a5e57bfc7f 100644 --- a/frameworks/napi/input_monitor/src/js_input_monitor_module.cpp +++ b/frameworks/napi/input_monitor/src/js_input_monitor_module.cpp @@ -20,8 +20,8 @@ #include #include "define_multimodal.h" -#include "napi_constants.h" #include "js_input_monitor_manager.h" +#include "napi_constants.h" #include "proto.h" #include "util_napi_error.h" @@ -37,9 +37,9 @@ static napi_value JsOnApi9(napi_env env, napi_callback_info info) size_t argc = 2; napi_value argv[2]; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); napi_valuetype valueType = napi_undefined; - CHKRP(env, napi_typeof(env, argv[0], &valueType), TYPEOF); + CHKRP(napi_typeof(env, argv[0], &valueType), TYPEOF); if (valueType != napi_string) { MMI_HILOGE("First Parameter type error"); THROWERR_API9(env, COMMON_PARAMETER_ERROR, "EventType", "string"); @@ -47,12 +47,12 @@ static napi_value JsOnApi9(napi_env env, napi_callback_info info) } char typeName[MAX_STRING_LEN] = { 0 }; size_t len = 0; - CHKRP(env, napi_get_value_string_utf8(env, argv[0], typeName, MAX_STRING_LEN - 1, &len), GET_STRING_UTF8); + CHKRP(napi_get_value_string_utf8(env, argv[0], typeName, MAX_STRING_LEN - 1, &len), GET_VALUE_STRING_UTF8); if (std::strcmp(typeName, "touch") != 0 && std::strcmp(typeName, "mouse") != 0) { THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "EventType must be mouse or touch"); return nullptr; } - CHKRP(env, napi_typeof(env, argv[1], &valueType), TYPEOF); + CHKRP(napi_typeof(env, argv[1], &valueType), TYPEOF); if (valueType != napi_function) { MMI_HILOGE("Second Parameter type error"); THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "Second Parameter type error"); @@ -71,7 +71,7 @@ static napi_value JsOn(napi_env env, napi_callback_info info) CALL_DEBUG_ENTER; size_t argc = 2; napi_value argv[2]; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc < 2) { THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "parameter number error"); return nullptr; @@ -85,9 +85,9 @@ static napi_value JsOffApi9(napi_env env, napi_callback_info info) CALL_DEBUG_ENTER; size_t argc = 2; napi_value argv[2]; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); napi_valuetype valueType = napi_undefined; - CHKRP(env, napi_typeof(env, argv[0], &valueType), TYPEOF); + CHKRP(napi_typeof(env, argv[0], &valueType), TYPEOF); if (valueType != napi_string) { MMI_HILOGE("First Parameter type error"); THROWERR_API9(env, COMMON_PARAMETER_ERROR, "EventType", "string"); @@ -95,7 +95,7 @@ static napi_value JsOffApi9(napi_env env, napi_callback_info info) } char typeName[MAX_STRING_LEN] = { 0 }; size_t len = 0; - CHKRP(env, napi_get_value_string_utf8(env, argv[0], typeName, MAX_STRING_LEN - 1, &len), GET_STRING_UTF8); + CHKRP(napi_get_value_string_utf8(env, argv[0], typeName, MAX_STRING_LEN - 1, &len), GET_VALUE_STRING_UTF8); if (std::strcmp(typeName, "touch") != 0 && std::strcmp(typeName, "mouse") != 0) { THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "EventType must be mouse or touch"); return nullptr; @@ -106,7 +106,7 @@ static napi_value JsOffApi9(napi_env env, napi_callback_info info) return nullptr; } - CHKRP(env, napi_typeof(env, argv[1], &valueType), TYPEOF); + CHKRP(napi_typeof(env, argv[1], &valueType), TYPEOF); if (valueType != napi_function) { MMI_HILOGE("Second Parameter type error"); THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "Second Parameter type error"); @@ -128,7 +128,7 @@ static napi_value JsOff(napi_env env, napi_callback_info info) size_t argc = 2; napi_value argv[2]; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc < 1) { THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "parameter number error"); return nullptr; @@ -145,7 +145,7 @@ static napi_value MmiInputMonitorInit(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("on", JsOn), DECLARE_NAPI_FUNCTION("off", JsOff), }; - CHKRP(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc), DEFINE_PROPERTIES); + CHKRP(napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc), DEFINE_PROPERTIES); return exports; } EXTERN_C_END diff --git a/frameworks/napi/key_code/BUILD.gn b/frameworks/napi/key_code/BUILD.gn index 2d0158f11969a53325f58abcce611ab99ac63517..419b5650716ed9d9d420f5f18445da8dfe8ed61b 100644 --- a/frameworks/napi/key_code/BUILD.gn +++ b/frameworks/napi/key_code/BUILD.gn @@ -22,15 +22,6 @@ config("keyCode_config") { "//foundation/multimodalinput/input/util/network/include", "//commonlibrary/c_utils/base/include", ] - - defines = [] - if (input_feature_libinput) { - defines += [ "OHOS_BUILD_LIBINPUT" ] - } - - if (input_feature_hdf) { - defines += [ "OHOS_BUILD_HDF" ] - } } ohos_shared_library("keycode") { diff --git a/frameworks/napi/key_code/include/js_key_code.h b/frameworks/napi/key_code/include/js_key_code.h index 36c7affd72cc158cb457de290c7e8f477393954b..c2d5a1b9dcc92f7d64f97d166f0cb54f998bdfdd 100644 --- a/frameworks/napi/key_code/include/js_key_code.h +++ b/frameworks/napi/key_code/include/js_key_code.h @@ -22,7 +22,7 @@ namespace OHOS { namespace MMI { -class JsKeyCode { +class JsKeyCode final { public: JsKeyCode() = default; ~JsKeyCode() = default; diff --git a/frameworks/napi/key_code/src/js_key_code.cpp b/frameworks/napi/key_code/src/js_key_code.cpp index 52f33f550567b25949a407e2112efca70442f750..b2576134cbe657e7b9e00b2f2458147e44fd066e 100644 --- a/frameworks/napi/key_code/src/js_key_code.cpp +++ b/frameworks/napi/key_code/src/js_key_code.cpp @@ -30,7 +30,7 @@ napi_value JsKeyCode::GetNapiInt32(napi_env env, int32_t code) { CALL_DEBUG_ENTER; napi_value keyCode = nullptr; - CHKRP(env, napi_create_int32(env, code, &keyCode), CREATE_INT32); + CHKRP(napi_create_int32(env, code, &keyCode), CREATE_INT32); return keyCode; } @@ -38,10 +38,10 @@ napi_value JsKeyCode::EnumClassConstructor(napi_env env, napi_callback_info info { CALL_DEBUG_ENTER; size_t argc = 0; - napi_value args[1] = {0}; + napi_value args[1] = { 0 }; napi_value ret = nullptr; void *data = nullptr; - CHKRP(env, napi_get_cb_info(env, info, &argc, args, &ret, &data), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, args, &ret, &data), GET_CB_INFO); return ret; } @@ -397,9 +397,9 @@ napi_value JsKeyCode::Export(napi_env env, napi_value exports) }; napi_value result = nullptr; - CHKRP(env, napi_define_class(env, "KeyCode", NAPI_AUTO_LENGTH, EnumClassConstructor, nullptr, + CHKRP(napi_define_class(env, "KeyCode", NAPI_AUTO_LENGTH, EnumClassConstructor, nullptr, sizeof(desc) / sizeof(*desc), desc, &result), DEFINE_CLASS); - CHKRP(env, napi_set_named_property(env, exports, "KeyCode", result), SET_NAMED_PROPERTY); + CHKRP(napi_set_named_property(env, exports, "KeyCode", result), SET_NAMED_PROPERTY); return exports; } } // namespace MMI diff --git a/frameworks/napi/key_event/BUILD.gn b/frameworks/napi/key_event/BUILD.gn index a2369b51518fc6fd7c44cc4f3660ec2193971c53..18cba57691b245eb32db5fc3a8dc96c486694d24 100644 --- a/frameworks/napi/key_event/BUILD.gn +++ b/frameworks/napi/key_event/BUILD.gn @@ -22,15 +22,6 @@ config("keyEvent_config") { "//foundation/multimodalinput/input/util/network/include", "//commonlibrary/c_utils/base/include", ] - - defines = [] - if (input_feature_libinput) { - defines += [ "OHOS_BUILD_LIBINPUT" ] - } - - if (input_feature_hdf) { - defines += [ "OHOS_BUILD_HDF" ] - } } ohos_shared_library("keyevent") { diff --git a/frameworks/napi/key_event/include/js_key_event.h b/frameworks/napi/key_event/include/js_key_event.h index 9e8e15217ceb4d58380a7ae55ce4a53a988a1b78..e24767edc85b6862f5c877a1ac8a47ec99a4c480 100644 --- a/frameworks/napi/key_event/include/js_key_event.h +++ b/frameworks/napi/key_event/include/js_key_event.h @@ -22,7 +22,7 @@ namespace OHOS { namespace MMI { -class JsKeyEvent { +class JsKeyEvent final { public: JsKeyEvent() = default; ~JsKeyEvent() = default; diff --git a/frameworks/napi/key_event/src/js_key_event.cpp b/frameworks/napi/key_event/src/js_key_event.cpp index 5cdbf9cdd89bb83deca34ae30281062c71a95be3..e9c8101f5a7cf70c1ca0cc0cefaa0f03c83b4360 100644 --- a/frameworks/napi/key_event/src/js_key_event.cpp +++ b/frameworks/napi/key_event/src/js_key_event.cpp @@ -35,7 +35,7 @@ napi_value JsKeyEvent::GetNapiInt32(napi_env env, int32_t code) { CALL_DEBUG_ENTER; napi_value ret = nullptr; - CHKRP(env, napi_create_int32(env, code, &ret), CREATE_INT32); + CHKRP(napi_create_int32(env, code, &ret), CREATE_INT32); return ret; } @@ -43,10 +43,10 @@ napi_value JsKeyEvent::EnumClassConstructor(napi_env env, napi_callback_info inf { CALL_DEBUG_ENTER; size_t argc = 0; - napi_value args[1] = {0}; + napi_value args[1] = { 0 }; napi_value ret = nullptr; void *data = nullptr; - CHKRP(env, napi_get_cb_info(env, info, &argc, args, &ret, &data), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, args, &ret, &data), GET_CB_INFO); return ret; } @@ -60,9 +60,9 @@ napi_value JsKeyEvent::Export(napi_env env, napi_value exports) }; napi_value action = nullptr; - CHKRP(env, napi_define_class(env, "Action", NAPI_AUTO_LENGTH, EnumClassConstructor, nullptr, + CHKRP(napi_define_class(env, "Action", NAPI_AUTO_LENGTH, EnumClassConstructor, nullptr, sizeof(desc) / sizeof(*desc), desc, &action), DEFINE_CLASS); - CHKRP(env, napi_set_named_property(env, exports, "Action", action), SET_NAMED_PROPERTY); + CHKRP(napi_set_named_property(env, exports, "Action", action), SET_NAMED_PROPERTY); return exports; } } // namespace MMI diff --git a/frameworks/napi/mouse_event/BUILD.gn b/frameworks/napi/mouse_event/BUILD.gn index 77c6ec7cabeaba19ce3493dc67f925049aa84c64..5bbbf920ca5bc77e73da6e6a61e5050aa97080db 100644 --- a/frameworks/napi/mouse_event/BUILD.gn +++ b/frameworks/napi/mouse_event/BUILD.gn @@ -22,15 +22,6 @@ config("mouseEvent_config") { "//foundation/multimodalinput/input/util/network/include", "//commonlibrary/c_utils/base/include", ] - - defines = [] - if (input_feature_libinput) { - defines += [ "OHOS_BUILD_LIBINPUT" ] - } - - if (input_feature_hdf) { - defines += [ "OHOS_BUILD_HDF" ] - } } ohos_shared_library("mouseevent") { diff --git a/frameworks/napi/mouse_event/include/js_mouse_event.h b/frameworks/napi/mouse_event/include/js_mouse_event.h index 9dcc6d2d14891b315a7c4725aad44be031d150ad..f0d5782dad6a96a212d3ee349dd37791a5a82d57 100644 --- a/frameworks/napi/mouse_event/include/js_mouse_event.h +++ b/frameworks/napi/mouse_event/include/js_mouse_event.h @@ -22,7 +22,7 @@ namespace OHOS { namespace MMI { -class JsMouseEvent { +class JsMouseEvent final { public: JsMouseEvent() = default; ~JsMouseEvent() = default; diff --git a/frameworks/napi/mouse_event/src/js_mouse_event.cpp b/frameworks/napi/mouse_event/src/js_mouse_event.cpp index 4ddd3aa75d5a67ea865a82d64ade17c48a0d7236..cc81b9229a897aca938d88ae06338458243e6aaf 100644 --- a/frameworks/napi/mouse_event/src/js_mouse_event.cpp +++ b/frameworks/napi/mouse_event/src/js_mouse_event.cpp @@ -56,7 +56,7 @@ napi_value JsMouseEvent::GetNapiInt32(napi_env env, int32_t code) { CALL_DEBUG_ENTER; napi_value ret = nullptr; - CHKRP(env, napi_create_int32(env, code, &ret), CREATE_INT32); + CHKRP(napi_create_int32(env, code, &ret), CREATE_INT32); return ret; } @@ -64,10 +64,10 @@ napi_value JsMouseEvent::EnumClassConstructor(napi_env env, napi_callback_info i { CALL_DEBUG_ENTER; size_t argc = 0; - napi_value args[1] = {0}; + napi_value args[1] = { 0 }; napi_value ret = nullptr; void *data = nullptr; - CHKRP(env, napi_get_cb_info(env, info, &argc, args, &ret, &data), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, args, &ret, &data), GET_CB_INFO); return ret; } @@ -84,9 +84,9 @@ napi_value JsMouseEvent::Export(napi_env env, napi_value exports) DECLARE_NAPI_STATIC_PROPERTY("AXIS_END", GetNapiInt32(env, static_cast(Action::AXIS_END))), }; napi_value action = nullptr; - CHKRP(env, napi_define_class(env, "Action", NAPI_AUTO_LENGTH, EnumClassConstructor, nullptr, + CHKRP(napi_define_class(env, "Action", NAPI_AUTO_LENGTH, EnumClassConstructor, nullptr, sizeof(actionArr) / sizeof(*actionArr), actionArr, &action), DEFINE_CLASS); - CHKRP(env, napi_set_named_property(env, exports, "Action", action), SET_NAMED_PROPERTY); + CHKRP(napi_set_named_property(env, exports, "Action", action), SET_NAMED_PROPERTY); napi_property_descriptor buttonArr[] = { DECLARE_NAPI_STATIC_PROPERTY("LEFT", GetNapiInt32(env, static_cast(Button::LEFT))), @@ -99,9 +99,9 @@ napi_value JsMouseEvent::Export(napi_env env, napi_value exports) DECLARE_NAPI_STATIC_PROPERTY("TASK", GetNapiInt32(env, static_cast(Button::TASK))), }; napi_value button = nullptr; - CHKRP(env, napi_define_class(env, "Button", NAPI_AUTO_LENGTH, EnumClassConstructor, nullptr, + CHKRP(napi_define_class(env, "Button", NAPI_AUTO_LENGTH, EnumClassConstructor, nullptr, sizeof(buttonArr) / sizeof(*buttonArr), buttonArr, &button), DEFINE_CLASS); - CHKRP(env, napi_set_named_property(env, exports, "Button", button), SET_NAMED_PROPERTY); + CHKRP(napi_set_named_property(env, exports, "Button", button), SET_NAMED_PROPERTY); napi_property_descriptor axisArr[] = { DECLARE_NAPI_STATIC_PROPERTY("SCROLL_VERTICAL", GetNapiInt32(env, static_cast(Axis::SCROLL_VERTICAL))), @@ -110,9 +110,9 @@ napi_value JsMouseEvent::Export(napi_env env, napi_value exports) DECLARE_NAPI_STATIC_PROPERTY("PINCH", GetNapiInt32(env, static_cast(Axis::PINCH))), }; napi_value axis = nullptr; - CHKRP(env, napi_define_class(env, "Axis", NAPI_AUTO_LENGTH, EnumClassConstructor, nullptr, + CHKRP(napi_define_class(env, "Axis", NAPI_AUTO_LENGTH, EnumClassConstructor, nullptr, sizeof(axisArr) / sizeof(*axisArr), axisArr, &axis), DEFINE_CLASS); - CHKRP(env, napi_set_named_property(env, exports, "Axis", axis), SET_NAMED_PROPERTY); + CHKRP(napi_set_named_property(env, exports, "Axis", axis), SET_NAMED_PROPERTY); return exports; } } // namespace MMI diff --git a/frameworks/napi/pointer/BUILD.gn b/frameworks/napi/pointer/BUILD.gn index 1437797fc1830fea221704933aad781e728bf32d..3df7a24a7586d0d04ad6f335771096615e8ac5f9 100644 --- a/frameworks/napi/pointer/BUILD.gn +++ b/frameworks/napi/pointer/BUILD.gn @@ -21,15 +21,6 @@ config("pointer_config") { "//foundation/multimodalinput/input/util/common/include", "//foundation/multimodalinput/input/util/network/include", ] - - defines = [] - if (input_feature_libinput) { - defines += [ "OHOS_BUILD_LIBINPUT" ] - } - - if (input_feature_hdf) { - defines += [ "OHOS_BUILD_HDF" ] - } } ohos_shared_library("pointer") { diff --git a/frameworks/napi/pointer/include/js_pointer_context.h b/frameworks/napi/pointer/include/js_pointer_context.h index a0aedec5d32c451e1f72a341547ddff4d7f3f135..ba02393ae3a49c6495141db504e32c9fd90f1285 100644 --- a/frameworks/napi/pointer/include/js_pointer_context.h +++ b/frameworks/napi/pointer/include/js_pointer_context.h @@ -33,6 +33,8 @@ public: static napi_value SetPointerSpeed(napi_env env, napi_callback_info info); static napi_value GetPointerSpeed(napi_env env, napi_callback_info info); static napi_value SetPointerLocation(napi_env env, napi_callback_info info); + static napi_value EnterCaptureMode(napi_env env, napi_callback_info info); + static napi_value LeaveCaptureMode(napi_env env, napi_callback_info info); private: static napi_value CreateInstance(napi_env env); diff --git a/frameworks/napi/pointer/include/js_pointer_manager.h b/frameworks/napi/pointer/include/js_pointer_manager.h index a98bbbb16aed7fe6034fc332926a361edbc0164a..49632cb985ef4d8e513eca9ab1c91855d816e1ce 100644 --- a/frameworks/napi/pointer/include/js_pointer_manager.h +++ b/frameworks/napi/pointer/include/js_pointer_manager.h @@ -21,13 +21,14 @@ #include "napi/native_api.h" #include "napi/native_node_api.h" #include "napi_constants.h" -#include "utils/log.h" #include "refbase.h" +#include "utils/log.h" -#include "stream_buffer.h" #include "define_multimodal.h" #include "error_multimodal.h" #include "input_manager.h" +#include "pointer_style.h" +#include "stream_buffer.h" #include "util_napi.h" #include "util_napi_error.h" @@ -49,7 +50,7 @@ struct AsyncContext : RefBase { ~AsyncContext(); }; -class JsPointerManager { +class JsPointerManager final { public: JsPointerManager() = default; ~JsPointerManager() = default; @@ -63,6 +64,8 @@ public: napi_value SetPointerStyle(napi_env env, int32_t windowid, int32_t pointerStyle, napi_value handle = nullptr); napi_value GetPointerStyle(napi_env env, int32_t windowid, napi_value handle = nullptr); napi_value SetPointerLocation(napi_env env, napi_value handle, int32_t x, int32_t y); + napi_value EnterCaptureMode(napi_env env, int32_t windowId, napi_value handle = nullptr); + napi_value LeaveCaptureMode(napi_env env, int32_t windowId, napi_value handle = nullptr); }; } // namespace MMI } // namespace OHOS diff --git a/frameworks/napi/pointer/src/js_pointer_context.cpp b/frameworks/napi/pointer/src/js_pointer_context.cpp index f4849eeec0f639e2ad23e768174b0db647636699..efc24d636f7d4a20f34040581031beeb8213d420 100644 --- a/frameworks/napi/pointer/src/js_pointer_context.cpp +++ b/frameworks/napi/pointer/src/js_pointer_context.cpp @@ -30,29 +30,29 @@ napi_value JsPointerContext::CreateInstance(napi_env env) { CALL_DEBUG_ENTER; napi_value global = nullptr; - CHKRP(env, napi_get_global(env, &global), GET_GLOBAL); + CHKRP(napi_get_global(env, &global), GET_GLOBAL); constexpr char className[] = "JsPointerContext"; napi_value jsClass = nullptr; napi_property_descriptor desc[] = {}; napi_status status = napi_define_class(env, className, sizeof(className), JsPointerContext::CreateJsObject, nullptr, sizeof(desc) / sizeof(desc[0]), nullptr, &jsClass); - CHKRP(env, status, DEFINE_CLASS); + CHKRP(status, DEFINE_CLASS); status = napi_set_named_property(env, global, "multimodalinput_pointer_class", jsClass); - CHKRP(env, status, SET_NAMED_PROPERTY); + CHKRP(status, SET_NAMED_PROPERTY); napi_value jsInstance = nullptr; - CHKRP(env, napi_new_instance(env, jsClass, 0, nullptr, &jsInstance), NEW_INSTANCE); - CHKRP(env, napi_set_named_property(env, global, "multimodal_pointer", jsInstance), SET_NAMED_PROPERTY); + CHKRP(napi_new_instance(env, jsClass, 0, nullptr, &jsInstance), NEW_INSTANCE); + CHKRP(napi_set_named_property(env, global, "multimodal_pointer", jsInstance), SET_NAMED_PROPERTY); JsPointerContext *jsContext = nullptr; - CHKRP(env, napi_unwrap(env, jsInstance, (void**)&jsContext), UNWRAP); + CHKRP(napi_unwrap(env, jsInstance, (void**)&jsContext), UNWRAP); CHKPP(jsContext); - CHKRP(env, napi_create_reference(env, jsInstance, 1, &(jsContext->contextRef_)), CREATE_REFERENCE); + CHKRP(napi_create_reference(env, jsInstance, 1, &(jsContext->contextRef_)), CREATE_REFERENCE); uint32_t refCount = 0; - CHKRP(env, napi_reference_ref(env, jsContext->contextRef_, &refCount), REFERENCE_REF); + CHKRP(napi_reference_ref(env, jsContext->contextRef_, &refCount), REFERENCE_REF); return jsInstance; } @@ -61,7 +61,7 @@ napi_value JsPointerContext::CreateJsObject(napi_env env, napi_callback_info inf CALL_DEBUG_ENTER; napi_value thisVar = nullptr; void *data = nullptr; - CHKRP(env, napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, &data), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, &data), GET_CB_INFO); JsPointerContext *jsContext = new (std::nothrow) JsPointerContext(); CHKPP(jsContext); @@ -82,24 +82,24 @@ JsPointerContext* JsPointerContext::GetInstance(napi_env env) { CALL_DEBUG_ENTER; napi_value global = nullptr; - CHKRP(env, napi_get_global(env, &global), GET_GLOBAL); + CHKRP(napi_get_global(env, &global), GET_GLOBAL); bool result = false; - CHKRP(env, napi_has_named_property(env, global, "multimodal_pointer", &result), HAS_NAMED_PROPERTY); + CHKRP(napi_has_named_property(env, global, "multimodal_pointer", &result), HAS_NAMED_PROPERTY); if (!result) { THROWERR(env, "multimodal_pointer was not found"); return nullptr; } napi_value object = nullptr; - CHKRP(env, napi_get_named_property(env, global, "multimodal_pointer", &object), SET_NAMED_PROPERTY); + CHKRP(napi_get_named_property(env, global, "multimodal_pointer", &object), SET_NAMED_PROPERTY); if (object == nullptr) { THROWERR(env, "object is nullptr"); return nullptr; } JsPointerContext *instance = nullptr; - CHKRP(env, napi_unwrap(env, object, (void**)&instance), UNWRAP); + CHKRP(napi_unwrap(env, object, (void**)&instance), UNWRAP); if (instance == nullptr) { THROWERR(env, "instance is nullptr"); return nullptr; @@ -117,19 +117,19 @@ napi_value JsPointerContext::SetPointerVisible(napi_env env, napi_callback_info CALL_DEBUG_ENTER; size_t argc = 2; napi_value argv[2]; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc == 0) { MMI_HILOGE("At least one parameter is required"); - THROWERR_API9(env, COMMON_PARAMETER_ERROR, "visible" , "boolean"); + THROWERR_API9(env, COMMON_PARAMETER_ERROR, "visible", "boolean"); return nullptr; } if (!JsCommon::TypeOf(env, argv[0], napi_boolean)) { - MMI_HILOGE("visible parameter type is wrong"); - THROWERR_API9(env, COMMON_PARAMETER_ERROR, "visible" , "boolean"); + MMI_HILOGE("visible parameter type is invalid"); + THROWERR_API9(env, COMMON_PARAMETER_ERROR, "visible", "boolean"); return nullptr; } bool visible = true; - CHKRP(env, napi_get_value_bool(env, argv[0], &visible), GET_BOOL); + CHKRP(napi_get_value_bool(env, argv[0], &visible), GET_VALUE_BOOL); JsPointerContext *jsPointer = JsPointerContext::GetInstance(env); auto jsPointerMgr = jsPointer->GetJsPointerMgr(); @@ -137,7 +137,7 @@ napi_value JsPointerContext::SetPointerVisible(napi_env env, napi_callback_info return jsPointerMgr->SetPointerVisible(env, visible); } if (!JsCommon::TypeOf(env, argv[1], napi_function)) { - MMI_HILOGE("callback parameter type is wrong "); + MMI_HILOGE("callback parameter type is invalid "); THROWERR_API9(env, COMMON_PARAMETER_ERROR, "callback", "function"); return nullptr; } @@ -149,7 +149,7 @@ napi_value JsPointerContext::IsPointerVisible(napi_env env, napi_callback_info i CALL_DEBUG_ENTER; size_t argc = 1; napi_value argv[1]; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); JsPointerContext *jsPointer = JsPointerContext::GetInstance(env); auto jsPointerMgr = jsPointer->GetJsPointerMgr(); @@ -157,7 +157,7 @@ napi_value JsPointerContext::IsPointerVisible(napi_env env, napi_callback_info i return jsPointerMgr->IsPointerVisible(env); } if (!JsCommon::TypeOf(env, argv[0], napi_function)) { - MMI_HILOGE("callback parameter type is wrong"); + MMI_HILOGE("callback parameter type is invalid"); THROWERR_API9(env, COMMON_PARAMETER_ERROR, "callback", "function"); return nullptr; } @@ -170,19 +170,19 @@ napi_value JsPointerContext::SetPointerSpeed(napi_env env, napi_callback_info in CALL_DEBUG_ENTER; size_t argc = 2; napi_value argv[2]; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc == 0) { MMI_HILOGE("At least 1 parameter is required"); THROWERR_API9(env, COMMON_PARAMETER_ERROR, "speed", "number"); return nullptr; } if (!JsCommon::TypeOf(env, argv[0], napi_number)) { - MMI_HILOGE("speed parameter type is wrong"); + MMI_HILOGE("speed parameter type is invalid"); THROWERR_API9(env, COMMON_PARAMETER_ERROR, "speed", "number"); return nullptr; } int32_t pointerSpeed = STANDARD_SPEED; - CHKRP(env, napi_get_value_int32(env, argv[0], &pointerSpeed), GET_INT32); + CHKRP(napi_get_value_int32(env, argv[0], &pointerSpeed), GET_VALUE_INT32); if (pointerSpeed < MIN_SPEED) { pointerSpeed = MIN_SPEED; } else if (pointerSpeed > MAX_SPEED) { @@ -194,7 +194,7 @@ napi_value JsPointerContext::SetPointerSpeed(napi_env env, napi_callback_info in return jsPointerMgr->SetPointerSpeed(env, pointerSpeed); } if (!JsCommon::TypeOf(env, argv[1], napi_function)) { - MMI_HILOGE("callback parameter type is wrong"); + MMI_HILOGE("callback parameter type is invalid"); THROWERR_API9(env, COMMON_PARAMETER_ERROR, "callback", "function"); return nullptr; } @@ -206,14 +206,14 @@ napi_value JsPointerContext::GetPointerSpeed(napi_env env, napi_callback_info in CALL_DEBUG_ENTER; size_t argc = 1; napi_value argv[1]; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); JsPointerContext *jsPointer = JsPointerContext::GetInstance(env); auto jsPointerMgr = jsPointer->GetJsPointerMgr(); if (argc == 0) { return jsPointerMgr->GetPointerSpeed(env); } if (!JsCommon::TypeOf(env, argv[0], napi_function)) { - MMI_HILOGE("callback parameter type is wrong"); + MMI_HILOGE("callback parameter type is invalid"); THROWERR_API9(env, COMMON_PARAMETER_ERROR, "callback", "function"); return nullptr; } @@ -226,31 +226,31 @@ napi_value JsPointerContext::SetPointerStyle(napi_env env, napi_callback_info in CALL_DEBUG_ENTER; size_t argc = 3; napi_value argv[3]; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc < 2) { MMI_HILOGE("At least 2 parameter is required"); THROWERR_API9(env, COMMON_PARAMETER_ERROR, "windowId", "number"); return nullptr; } if (!JsCommon::TypeOf(env, argv[0], napi_number)) { - MMI_HILOGE("windowId parameter type is wrong"); + MMI_HILOGE("windowId parameter type is invalid"); THROWERR_API9(env, COMMON_PARAMETER_ERROR, "windowId", "number"); return nullptr; } int32_t windowid = 0; - CHKRP(env, napi_get_value_int32(env, argv[0], &windowid), GET_INT32); + CHKRP(napi_get_value_int32(env, argv[0], &windowid), GET_VALUE_INT32); if (windowid < 0) { MMI_HILOGE("Invalid windowid"); THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "Windowid is invalid"); return nullptr; } if (!JsCommon::TypeOf(env, argv[1], napi_number)) { - MMI_HILOGE("pointerStyle parameter type is wrong"); + MMI_HILOGE("pointerStyle parameter type is invalid"); THROWERR_API9(env, COMMON_PARAMETER_ERROR, "pointerStyle", "number"); return nullptr; } int32_t pointerStyle = 0; - CHKRP(env, napi_get_value_int32(env, argv[1], &pointerStyle), GET_INT32); + CHKRP(napi_get_value_int32(env, argv[1], &pointerStyle), GET_VALUE_INT32); if (pointerStyle < DEFAULT || pointerStyle > MIDDLE_BTN_NORTH_SOUTH_WEST_EAST) { MMI_HILOGE("Undefined pointer style"); THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "Pointer style does not exist"); @@ -262,7 +262,7 @@ napi_value JsPointerContext::SetPointerStyle(napi_env env, napi_callback_info in return jsPointerMgr->SetPointerStyle(env, windowid, pointerStyle); } if (!JsCommon::TypeOf(env, argv[2], napi_function)) { - MMI_HILOGE("callback parameter type is wrong"); + MMI_HILOGE("callback parameter type is invalid"); THROWERR_API9(env, COMMON_PARAMETER_ERROR, "callback", "function"); return nullptr; } @@ -274,19 +274,19 @@ napi_value JsPointerContext::GetPointerStyle(napi_env env, napi_callback_info in CALL_DEBUG_ENTER; size_t argc = 2; napi_value argv[2]; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); if (argc == 0) { MMI_HILOGE("At least 1 parameter is required"); THROWERR_API9(env, COMMON_PARAMETER_ERROR, "windowId", "number"); return nullptr; } if (!JsCommon::TypeOf(env, argv[0], napi_number)) { - MMI_HILOGE("windowId parameter type is wrong"); + MMI_HILOGE("windowId parameter type is invalid"); THROWERR_API9(env, COMMON_PARAMETER_ERROR, "windowId", "number"); return nullptr; } int32_t windowid = 0; - CHKRP(env, napi_get_value_int32(env, argv[0], &windowid), GET_INT32); + CHKRP(napi_get_value_int32(env, argv[0], &windowid), GET_VALUE_INT32); if (windowid < 0) { MMI_HILOGE("Invalid windowid"); THROWERR_CUSTOM(env, COMMON_PARAMETER_ERROR, "Windowid is invalid"); @@ -298,7 +298,7 @@ napi_value JsPointerContext::GetPointerStyle(napi_env env, napi_callback_info in return jsPointerMgr->GetPointerStyle(env, windowid); } if (!JsCommon::TypeOf(env, argv[1], napi_function)) { - MMI_HILOGE("callback parameter type is wrong"); + MMI_HILOGE("callback parameter type is invalid"); THROWERR_API9(env, COMMON_PARAMETER_ERROR, "callback", "function"); return nullptr; } @@ -309,83 +309,83 @@ napi_value JsPointerContext::CreatePointerStyle(napi_env env, napi_value exports { CALL_DEBUG_ENTER; napi_value defaults = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::DEFAULT, &defaults), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::DEFAULT, &defaults), CREATE_INT32); napi_value east = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::EAST, &east), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::EAST, &east), CREATE_INT32); napi_value west = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::WEST, &west), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::WEST, &west), CREATE_INT32); napi_value south = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::SOUTH, &south), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::SOUTH, &south), CREATE_INT32); napi_value north = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::NORTH, &north), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::NORTH, &north), CREATE_INT32); napi_value west_east = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::WEST_EAST, &west_east), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::WEST_EAST, &west_east), CREATE_INT32); napi_value north_south = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::NORTH_SOUTH, &north_south), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::NORTH_SOUTH, &north_south), CREATE_INT32); napi_value north_east = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::NORTH_EAST, &north_east), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::NORTH_EAST, &north_east), CREATE_INT32); napi_value north_west = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::NORTH_WEST, &north_west), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::NORTH_WEST, &north_west), CREATE_INT32); napi_value south_east = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::SOUTH_EAST, &south_east), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::SOUTH_EAST, &south_east), CREATE_INT32); napi_value south_west = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::SOUTH_WEST, &south_west), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::SOUTH_WEST, &south_west), CREATE_INT32); napi_value north_east_south_west = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::NORTH_EAST_SOUTH_WEST, &north_east_south_west), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::NORTH_EAST_SOUTH_WEST, &north_east_south_west), CREATE_INT32); napi_value north_west_south_east = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::NORTH_WEST_SOUTH_EAST, &north_west_south_east), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::NORTH_WEST_SOUTH_EAST, &north_west_south_east), CREATE_INT32); napi_value cross = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::CROSS, &cross), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::CROSS, &cross), CREATE_INT32); napi_value cursor_copy = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::CURSOR_COPY, &cursor_copy), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::CURSOR_COPY, &cursor_copy), CREATE_INT32); napi_value cursor_forbid = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::CURSOR_FORBID, &cursor_forbid), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::CURSOR_FORBID, &cursor_forbid), CREATE_INT32); napi_value color_sucker = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::COLOR_SUCKER, &color_sucker), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::COLOR_SUCKER, &color_sucker), CREATE_INT32); napi_value hand_grabbing = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::HAND_GRABBING, &hand_grabbing), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::HAND_GRABBING, &hand_grabbing), CREATE_INT32); napi_value hand_open = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::HAND_OPEN, &hand_open), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::HAND_OPEN, &hand_open), CREATE_INT32); napi_value hand_pointing = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::HAND_POINTING, &hand_pointing), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::HAND_POINTING, &hand_pointing), CREATE_INT32); napi_value help = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::HELP, &help), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::HELP, &help), CREATE_INT32); napi_value move = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::CURSOR_MOVE, &move), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::CURSOR_MOVE, &move), CREATE_INT32); napi_value resize_up_down = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::RESIZE_LEFT_RIGHT, &resize_up_down), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::RESIZE_LEFT_RIGHT, &resize_up_down), CREATE_INT32); napi_value resize_left_right = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::RESIZE_UP_DOWN, &resize_left_right), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::RESIZE_UP_DOWN, &resize_left_right), CREATE_INT32); napi_value screenshot_choose = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::SCREENSHOT_CHOOSE, &screenshot_choose), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::SCREENSHOT_CHOOSE, &screenshot_choose), CREATE_INT32); napi_value screenshot_cursor = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::SCREENSHOT_CURSOR, &screenshot_cursor), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::SCREENSHOT_CURSOR, &screenshot_cursor), CREATE_INT32); napi_value text_cursor = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::TEXT_CURSOR, &text_cursor), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::TEXT_CURSOR, &text_cursor), CREATE_INT32); napi_value zoom_in = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::ZOOM_IN, &zoom_in), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::ZOOM_IN, &zoom_in), CREATE_INT32); napi_value zoom_out = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::ZOOM_OUT, &zoom_out), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::ZOOM_OUT, &zoom_out), CREATE_INT32); napi_value middle_btn_east = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::MIDDLE_BTN_EAST, &middle_btn_east), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::MIDDLE_BTN_EAST, &middle_btn_east), CREATE_INT32); napi_value middle_btn_west = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::MIDDLE_BTN_WEST, &middle_btn_west), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::MIDDLE_BTN_WEST, &middle_btn_west), CREATE_INT32); napi_value middle_btn_south = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::MIDDLE_BTN_SOUTH, &middle_btn_south), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::MIDDLE_BTN_SOUTH, &middle_btn_south), CREATE_INT32); napi_value middle_btn_north = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::MIDDLE_BTN_NORTH, &middle_btn_north), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::MIDDLE_BTN_NORTH, &middle_btn_north), CREATE_INT32); napi_value middle_btn_north_south = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::MIDDLE_BTN_NORTH_SOUTH, &middle_btn_north_south), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::MIDDLE_BTN_NORTH_SOUTH, &middle_btn_north_south), CREATE_INT32); napi_value middle_btn_north_east = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::MIDDLE_BTN_NORTH_EAST, &middle_btn_north_east), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::MIDDLE_BTN_NORTH_EAST, &middle_btn_north_east), CREATE_INT32); napi_value middle_btn_north_west = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::MIDDLE_BTN_NORTH_WEST, &middle_btn_north_west), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::MIDDLE_BTN_NORTH_WEST, &middle_btn_north_west), CREATE_INT32); napi_value middle_btn_south_east = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::MIDDLE_BTN_SOUTH_EAST, &middle_btn_south_east), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::MIDDLE_BTN_SOUTH_EAST, &middle_btn_south_east), CREATE_INT32); napi_value middle_btn_south_west = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::MIDDLE_BTN_SOUTH_WEST, &middle_btn_south_west), CREATE_INT32); + CHKRP(napi_create_int32(env, MOUSE_ICON::MIDDLE_BTN_SOUTH_WEST, &middle_btn_south_west), CREATE_INT32); napi_value middle_btn_north_south_west_east = nullptr; - CHKRP(env, napi_create_int32(env, MOUSE_ICON::MIDDLE_BTN_NORTH_SOUTH_WEST_EAST, + CHKRP(napi_create_int32(env, MOUSE_ICON::MIDDLE_BTN_NORTH_SOUTH_WEST_EAST, &middle_btn_north_south_west_east), CREATE_INT32); napi_property_descriptor desc[] = { @@ -430,9 +430,9 @@ napi_value JsPointerContext::CreatePointerStyle(napi_env env, napi_value exports DECLARE_NAPI_STATIC_PROPERTY("MIDDLE_BTN_NORTH_SOUTH_WEST_EAST", middle_btn_north_south_west_east), }; napi_value result = nullptr; - CHKRP(env, napi_define_class(env, "PointerStyle", NAPI_AUTO_LENGTH, EnumConstructor, nullptr, + CHKRP(napi_define_class(env, "PointerStyle", NAPI_AUTO_LENGTH, EnumConstructor, nullptr, sizeof(desc) / sizeof(*desc), desc, &result), DEFINE_CLASS); - CHKRP(env, napi_set_named_property(env, exports, "PointerStyle", result), SET_NAMED_PROPERTY); + CHKRP(napi_set_named_property(env, exports, "PointerStyle", result), SET_NAMED_PROPERTY); return exports; } @@ -443,10 +443,71 @@ napi_value JsPointerContext::EnumConstructor(napi_env env, napi_callback_info in napi_value args[1] = { 0 }; napi_value ret = nullptr; void *data = nullptr; - CHKRP(env, napi_get_cb_info(env, info, &argc, args, &ret, &data), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, args, &ret, &data), GET_CB_INFO); return ret; } +napi_value JsPointerContext::EnterCaptureMode(napi_env env, napi_callback_info info) +{ + CALL_DEBUG_ENTER; + size_t argc = 2; + napi_value argv[2]; + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + if (argc < 1 || argc > 2) { + THROWERR(env, "The number of parameters is not as expected"); + return nullptr; + } + if (!JsCommon::TypeOf(env, argv[0], napi_number)) { + THROWERR(env, "The first parameter type is invalid"); + return nullptr; + } + + int32_t windowId = 0; + CHKRP(napi_get_value_int32(env, argv[0], &windowId), GET_VALUE_INT32); + JsPointerContext *jsPointer = JsPointerContext::GetInstance(env); + CHKPP(jsPointer); + auto jsPointerMgr = jsPointer->GetJsPointerMgr(); + if(argc == 1) { + return jsPointerMgr->EnterCaptureMode(env, windowId); + } + if (!JsCommon::TypeOf(env, argv[1], napi_function)) { + THROWERR(env, "The second parameter type is invalid"); + return nullptr; + } + return jsPointerMgr->EnterCaptureMode(env, windowId, argv[1]); +} + +napi_value JsPointerContext::LeaveCaptureMode(napi_env env, napi_callback_info info) +{ + CALL_DEBUG_ENTER; + size_t argc = 2; + napi_value argv[2]; + CHKRP(napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); + if (argc < 1 || argc > 2) { + THROWERR(env, "The number of parameters is not as expected"); + return nullptr; + } + if (!JsCommon::TypeOf(env, argv[0], napi_number)) { + THROWERR(env, "The first parameter type is invalid"); + return nullptr; + } + + int32_t windowId = 0; + CHKRP(napi_get_value_int32(env, argv[0], &windowId), GET_VALUE_INT32); + + JsPointerContext *jsPointer = JsPointerContext::GetInstance(env); + CHKPP(jsPointer); + auto jsPointerMgr = jsPointer->GetJsPointerMgr(); + if(argc == 1) { + return jsPointerMgr->LeaveCaptureMode(env, windowId); + } + if (!JsCommon::TypeOf(env, argv[1], napi_function)) { + THROWERR(env, "The second parameter type is invalid"); + return nullptr; + } + return jsPointerMgr->LeaveCaptureMode(env, windowId, argv[1]); +} + napi_value JsPointerContext::Export(napi_env env, napi_value exports) { CALL_DEBUG_ENTER; @@ -462,47 +523,15 @@ napi_value JsPointerContext::Export(napi_env env, napi_value exports) DECLARE_NAPI_STATIC_FUNCTION("getPointerSpeed", GetPointerSpeed), DECLARE_NAPI_STATIC_FUNCTION("setPointerStyle", SetPointerStyle), DECLARE_NAPI_STATIC_FUNCTION("getPointerStyle", GetPointerStyle), + DECLARE_NAPI_STATIC_FUNCTION("enterCaptureMode", EnterCaptureMode), + DECLARE_NAPI_STATIC_FUNCTION("leaveCaptureMode", LeaveCaptureMode), }; - CHKRP(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc), DEFINE_PROPERTIES); + CHKRP(napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc), DEFINE_PROPERTIES); if (CreatePointerStyle(env, exports) == nullptr) { THROWERR(env, "Failed to create pointer style"); return nullptr; } return exports; } - -napi_value JsPointerContext::SetPointerLocation(napi_env env, napi_callback_info info) -{ - CALL_INFO_TRACE; - size_t argc = 3; - napi_value argv[3]; - CHKRP(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), GET_CB_INFO); - if (argc > 3 || argc < 2) { - THROWERR(env, "the number of parameters is not as expected"); - return nullptr; - } - if (!JsCommon::TypeOf(env, argv[0], napi_number)) { - THROWERR(env, "The first parameter type is wrong"); - return nullptr; - } - if (!JsCommon::TypeOf(env, argv[1], napi_number)) { - THROWERR(env, "The second parameter type is wrong"); - return nullptr; - } - int32_t x = 0; - int32_t y = 0; - CHKRP(env, napi_get_value_int32(env, argv[0], &x), GET_INT32); - CHKRP(env, napi_get_value_int32(env, argv[1], &y), GET_INT32); - JsPointerContext *jsPointer = JsPointerContext::GetInstance(env); - auto jsPointerMgr = jsPointer->GetJsPointerMgr(); - if (argc == 2) { - return jsPointerMgr->SetPointerLocation(env, nullptr, x, y); - } - if (!JsCommon::TypeOf(env, argv[2], napi_function)) { - THROWERR(env, "The third parameter type is wrong"); - return nullptr; - } - return jsPointerMgr->SetPointerLocation(env, argv[2], x, y); -} } // namespace MMI } // namespace OHOS diff --git a/frameworks/napi/pointer/src/js_pointer_manager.cpp b/frameworks/napi/pointer/src/js_pointer_manager.cpp index 468c5e4c2b2b679767d99874b8908f8c31b48ca2..7a58266548f398f2959cfee6448fdf1d5d9de4d8 100644 --- a/frameworks/napi/pointer/src/js_pointer_manager.cpp +++ b/frameworks/napi/pointer/src/js_pointer_manager.cpp @@ -32,7 +32,7 @@ enum class ReturnType { bool JsCommon::TypeOf(napi_env env, napi_value value, napi_valuetype type) { napi_valuetype valueType = napi_undefined; - CHKRF(env, napi_typeof(env, value, &valueType), TYPEOF); + CHKRF(napi_typeof(env, value, &valueType), TYPEOF); if (valueType != type) { return false; } @@ -43,10 +43,10 @@ AsyncContext::~AsyncContext() { CALL_DEBUG_ENTER; if (work != nullptr) { - CHKRV(env, napi_delete_async_work(env, work), DELETE_ASYNC_WORK); + CHKRV(napi_delete_async_work(env, work), DELETE_ASYNC_WORK); } if (callback != nullptr && env != nullptr) { - CHKRV(env, napi_delete_reference(env, callback), DELETE_REFERENCE); + CHKRV(napi_delete_reference(env, callback), DELETE_REFERENCE); env = nullptr; } } @@ -68,14 +68,14 @@ bool getResult(sptr asyncContext, napi_value * results) napi_value errCode = nullptr; napi_value errMsg = nullptr; napi_value businessError = nullptr; - CHKRF(env, napi_create_int32(env, asyncContext->errorCode, &errCode), CREATE_INT32); - CHKRF(env, napi_create_string_utf8(env, codeMsg.msg.c_str(), + CHKRF(napi_create_int32(env, asyncContext->errorCode, &errCode), CREATE_INT32); + CHKRF(napi_create_string_utf8(env, codeMsg.msg.c_str(), NAPI_AUTO_LENGTH, &errMsg), CREATE_STRING_UTF8); - CHKRF(env, napi_create_error(env, nullptr, errMsg, &businessError), CREATE_ERROR); - CHKRF(env, napi_set_named_property(env, businessError, ERR_CODE.c_str(), errCode), SET_NAMED_PROPERTY); + CHKRF(napi_create_error(env, nullptr, errMsg, &businessError), CREATE_ERROR); + CHKRF(napi_set_named_property(env, businessError, ERR_CODE.c_str(), errCode), SET_NAMED_PROPERTY); results[0] = businessError; } else { - CHKRF(env, napi_get_undefined(env, &results[0]), GET_UNDEFINED); + CHKRF(napi_get_undefined(env, &results[0]), GET_UNDEFINED); } ReturnType resultType; @@ -83,13 +83,13 @@ bool getResult(sptr asyncContext, napi_value * results) if (resultType == ReturnType::BOOL) { bool temp; asyncContext->reserve >> temp; - CHKRF(env, napi_get_boolean(env, temp, &results[1]), CREATE_BOOL); + CHKRF(napi_get_boolean(env, temp, &results[1]), GET_BOOLEAN); } else if (resultType == ReturnType::NUMBER) { int32_t temp; asyncContext->reserve >> temp; - CHKRF(env, napi_create_int32(env, temp, &results[1]), CREATE_INT32); + CHKRF(napi_create_int32(env, temp, &results[1]), CREATE_INT32); } else { - CHKRF(env, napi_get_undefined(env, &results[1]), GET_UNDEFINED); + CHKRF(napi_get_undefined(env, &results[1]), GET_UNDEFINED); } return true; } @@ -101,14 +101,14 @@ void AsyncCallbackWork(sptr asyncContext) CHKPV(asyncContext->env); napi_env env = asyncContext->env; napi_value resource = nullptr; - CHKRV(env, napi_create_string_utf8(env, "AsyncCallbackWork", NAPI_AUTO_LENGTH, &resource), CREATE_STRING_UTF8); + CHKRV(napi_create_string_utf8(env, "AsyncCallbackWork", NAPI_AUTO_LENGTH, &resource), CREATE_STRING_UTF8); asyncContext->IncStrongRef(nullptr); napi_status status = napi_create_async_work(env, nullptr, resource, [](napi_env env, void* data) {}, [](napi_env env, napi_status status, void* data) { sptr asyncContext(static_cast(data)); /** * After the asynchronous task is created, the asyncCallbackInfo reference count is reduced - * to 0 destructions, so you need to add 1 to the asyncCallbackInfo reference count when the + * to 0 destruction, so you need to add 1 to the asyncCallbackInfo reference count when the * asynchronous task is created, and subtract 1 from the reference count after the naked * pointer is converted to a pointer when the asynchronous task is executed, the reference * count of the smart pointer is guaranteed to be 1. @@ -121,15 +121,15 @@ void AsyncCallbackWork(sptr asyncContext) } if (asyncContext->deferred) { if (asyncContext->errorCode == RET_OK) { - CHKRV(env, napi_resolve_deferred(env, asyncContext->deferred, results[1]), RESOLVE_DEFERRED); + CHKRV(napi_resolve_deferred(env, asyncContext->deferred, results[1]), RESOLVE_DEFERRED); } else { - CHKRV(env, napi_reject_deferred(env, asyncContext->deferred, results[0]), REJECT_DEFERRED); + CHKRV(napi_reject_deferred(env, asyncContext->deferred, results[0]), REJECT_DEFERRED); } } else { napi_value callback = nullptr; - CHKRV(env, napi_get_reference_value(env, asyncContext->callback, &callback), GET_REFERENCE); + CHKRV(napi_get_reference_value(env, asyncContext->callback, &callback), GET_REFERENCE_VALUE); napi_value callResult = nullptr; - CHKRV(env, napi_call_function(env, nullptr, callback, 2, results, &callResult), CALL_FUNCTION); + CHKRV(napi_call_function(env, nullptr, callback, 2, results, &callResult), CALL_FUNCTION); } }, asyncContext.GetRefPtr(), &asyncContext->work); @@ -150,10 +150,10 @@ napi_value JsPointerManager::SetPointerVisible(napi_env env, bool visible, napi_ napi_value promise = nullptr; if (handle != nullptr) { - CHKRP(env, napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE); - CHKRP(env, napi_get_undefined(env, &promise), GET_UNDEFINED); + CHKRP(napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE); + CHKRP(napi_get_undefined(env, &promise), GET_UNDEFINED); } else { - CHKRP(env, napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE); + CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE); } AsyncCallbackWork(asyncContext); return promise; @@ -171,10 +171,10 @@ napi_value JsPointerManager::IsPointerVisible(napi_env env, napi_value handle) napi_value promise = nullptr; if (handle != nullptr) { - CHKRP(env, napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE); - CHKRP(env, napi_get_undefined(env, &promise), GET_UNDEFINED); + CHKRP(napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE); + CHKRP(napi_get_undefined(env, &promise), GET_UNDEFINED); } else { - CHKRP(env, napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE); + CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE); } AsyncCallbackWork(asyncContext); return promise; @@ -189,10 +189,10 @@ napi_value JsPointerManager::SetPointerSpeed(napi_env env, int32_t pointerSpeed, asyncContext->reserve << ReturnType::VOID; napi_value promise = nullptr; if (handle != nullptr) { - CHKRP(env, napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE); - CHKRP(env, napi_get_undefined(env, &promise), GET_UNDEFINED); + CHKRP(napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE); + CHKRP(napi_get_undefined(env, &promise), GET_UNDEFINED); } else { - CHKRP(env, napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE); + CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE); } AsyncCallbackWork(asyncContext); return promise; @@ -209,71 +209,95 @@ napi_value JsPointerManager::GetPointerSpeed(napi_env env, napi_value handle) napi_value promise = nullptr; uint32_t initial_refcount = 1; if (handle != nullptr) { - CHKRP(env, napi_create_reference(env, handle, initial_refcount, &asyncContext->callback), CREATE_REFERENCE); - CHKRP(env, napi_get_undefined(env, &promise), GET_UNDEFINED); + CHKRP(napi_create_reference(env, handle, initial_refcount, &asyncContext->callback), CREATE_REFERENCE); + CHKRP(napi_get_undefined(env, &promise), GET_UNDEFINED); } else { - CHKRP(env, napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE); + CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE); } AsyncCallbackWork(asyncContext); return promise; } -napi_value JsPointerManager::SetPointerLocation(napi_env env, napi_value handle, int32_t x, int32_t y) +napi_value JsPointerManager::SetPointerStyle(napi_env env, int32_t windowid, int32_t pointerStyle, napi_value handle) { CALL_DEBUG_ENTER; sptr asyncContext = new (std::nothrow) AsyncContext(env); - if (asyncContext == nullptr) { - THROWERR(env, "create AsyncContext failed"); - return nullptr; - } - asyncContext->errorCode = InputManager::GetInstance()->SetPointerLocation(x, y); + CHKPP(asyncContext); + PointerStyle style; + style.id = pointerStyle; + asyncContext->errorCode = InputManager::GetInstance()->SetPointerStyle(windowid, style); asyncContext->reserve << ReturnType::VOID; + napi_value promise = nullptr; - uint32_t initial_refcount = 1; if (handle != nullptr) { - CHKRP(env, napi_create_reference(env, handle, initial_refcount, &asyncContext->callback), CREATE_REFERENCE); - CHKRP(env, napi_get_undefined(env, &promise), GET_UNDEFINED); - napi_delete_reference(env, asyncContext->callback); + CHKRP(napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE); + CHKRP(napi_get_undefined(env, &promise), GET_UNDEFINED); } else { - CHKRP(env, napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE); + CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE); } AsyncCallbackWork(asyncContext); return promise; } -napi_value JsPointerManager::SetPointerStyle(napi_env env, int32_t windowid, int32_t pointerStyle, napi_value handle) +napi_value JsPointerManager::GetPointerStyle(napi_env env, int32_t windowid, napi_value handle) { CALL_DEBUG_ENTER; sptr asyncContext = new (std::nothrow) AsyncContext(env); CHKPP(asyncContext); - asyncContext->errorCode = InputManager::GetInstance()->SetPointerStyle(windowid, pointerStyle); + PointerStyle pointerStyle; + asyncContext->errorCode = InputManager::GetInstance()->GetPointerStyle(windowid, pointerStyle); + asyncContext->reserve << ReturnType::NUMBER << pointerStyle.id; + napi_value promise = nullptr; + if (handle != nullptr) { + CHKRP(napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE); + CHKRP(napi_get_undefined(env, &promise), GET_UNDEFINED); + } else { + CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE); + } + AsyncCallbackWork(asyncContext); + return promise; +} + +napi_value JsPointerManager::EnterCaptureMode(napi_env env, int32_t windowId, napi_value handle) +{ + CALL_DEBUG_ENTER; + sptr asyncContext = new (std::nothrow) AsyncContext(env); + if(asyncContext == nullptr) { + THROWERR(env, "Create AsyncContext failed"); + return nullptr; + } + asyncContext->errorCode = InputManager::GetInstance()->EnterCaptureMode(windowId); asyncContext->reserve << ReturnType::VOID; napi_value promise = nullptr; - if (handle != nullptr) { - CHKRP(env, napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE); - CHKRP(env, napi_get_undefined(env, &promise), GET_UNDEFINED); + if(handle != nullptr) { + CHKRP(napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE); + CHKRP(napi_get_undefined(env, &promise), GET_UNDEFINED); } else { - CHKRP(env, napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE); + CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE); } AsyncCallbackWork(asyncContext); return promise; } -napi_value JsPointerManager::GetPointerStyle(napi_env env, int32_t windowid, napi_value handle) +napi_value JsPointerManager::LeaveCaptureMode(napi_env env, int32_t windowId, napi_value handle) { CALL_DEBUG_ENTER; sptr asyncContext = new (std::nothrow) AsyncContext(env); - CHKPP(asyncContext); - int32_t pointerStyle = 0; - asyncContext->errorCode = InputManager::GetInstance()->GetPointerStyle(windowid, pointerStyle); - asyncContext->reserve << ReturnType::NUMBER << pointerStyle; + if(asyncContext == nullptr) { + THROWERR(env, "Create AsyncContext failed"); + return nullptr; + } + + asyncContext->errorCode = InputManager::GetInstance()->LeaveCaptureMode(windowId); + asyncContext->reserve << ReturnType::VOID; + napi_value promise = nullptr; - if (handle != nullptr) { - CHKRP(env, napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE); - CHKRP(env, napi_get_undefined(env, &promise), GET_UNDEFINED); + if(handle != nullptr) { + CHKRP(napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE); + CHKRP(napi_get_undefined(env, &promise), GET_UNDEFINED); } else { - CHKRP(env, napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE); + CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE); } AsyncCallbackWork(asyncContext); return promise; diff --git a/frameworks/napi/touch_event/BUILD.gn b/frameworks/napi/touch_event/BUILD.gn index a7528c29b83cf45669abd2454864f49b0fe4cac6..173f2c7bcfa07561b7834a37d5fe1cb359b0d965 100644 --- a/frameworks/napi/touch_event/BUILD.gn +++ b/frameworks/napi/touch_event/BUILD.gn @@ -22,15 +22,6 @@ config("touchEvent_config") { "//foundation/multimodalinput/input/util/network/include", "//commonlibrary/c_utils/base/include", ] - - defines = [] - if (input_feature_libinput) { - defines += [ "OHOS_BUILD_LIBINPUT" ] - } - - if (input_feature_hdf) { - defines += [ "OHOS_BUILD_HDF" ] - } } ohos_shared_library("touchevent") { diff --git a/frameworks/napi/touch_event/include/js_touch_event.h b/frameworks/napi/touch_event/include/js_touch_event.h index 20363bf6754bb544c55714121069863d3a186fc5..77ceab88d4aa195343a24dd41cdc63b1fd983f12 100644 --- a/frameworks/napi/touch_event/include/js_touch_event.h +++ b/frameworks/napi/touch_event/include/js_touch_event.h @@ -22,7 +22,7 @@ namespace OHOS { namespace MMI { -class JsTouchEvent { +class JsTouchEvent final { public: JsTouchEvent() = default; ~JsTouchEvent() = default; diff --git a/frameworks/napi/touch_event/src/js_touch_event.cpp b/frameworks/napi/touch_event/src/js_touch_event.cpp index 3e2fe32323e0cef9c44fe6a58b41db9483cdc00b..18a8f2a70ea804525911cc51afce074bfbfcdd98 100644 --- a/frameworks/napi/touch_event/src/js_touch_event.cpp +++ b/frameworks/napi/touch_event/src/js_touch_event.cpp @@ -53,7 +53,7 @@ napi_value JsTouchEvent::GetNapiInt32(napi_env env, int32_t code) { CALL_DEBUG_ENTER; napi_value ret = nullptr; - CHKRP(env, napi_create_int32(env, code, &ret), CREATE_INT32); + CHKRP(napi_create_int32(env, code, &ret), CREATE_INT32); return ret; } @@ -61,10 +61,10 @@ napi_value JsTouchEvent::EnumClassConstructor(napi_env env, napi_callback_info i { CALL_DEBUG_ENTER; size_t argc = 0; - napi_value args[1] = {0}; + napi_value args[1] = { 0 }; napi_value ret = nullptr; void *data = nullptr; - CHKRP(env, napi_get_cb_info(env, info, &argc, args, &ret, &data), GET_CB_INFO); + CHKRP(napi_get_cb_info(env, info, &argc, args, &ret, &data), GET_CB_INFO); return ret; } @@ -78,9 +78,9 @@ napi_value JsTouchEvent::Export(napi_env env, napi_value exports) DECLARE_NAPI_STATIC_PROPERTY("UP", GetNapiInt32(env, static_cast(Action::UP))), }; napi_value action = nullptr; - CHKRP(env, napi_define_class(env, "Action", NAPI_AUTO_LENGTH, EnumClassConstructor, nullptr, + CHKRP(napi_define_class(env, "Action", NAPI_AUTO_LENGTH, EnumClassConstructor, nullptr, sizeof(actionArr) / sizeof(*actionArr), actionArr, &action), DEFINE_CLASS); - CHKRP(env, napi_set_named_property(env, exports, "Action", action), SET_NAMED_PROPERTY); + CHKRP(napi_set_named_property(env, exports, "Action", action), SET_NAMED_PROPERTY); napi_property_descriptor toolTypeArr[] = { DECLARE_NAPI_STATIC_PROPERTY("FINGER", GetNapiInt32(env, static_cast(ToolType::FINGER))), @@ -93,9 +93,9 @@ napi_value JsTouchEvent::Export(napi_env env, napi_value exports) DECLARE_NAPI_STATIC_PROPERTY("LENS", GetNapiInt32(env, static_cast(ToolType::LENS))), }; napi_value toolType = nullptr; - CHKRP(env, napi_define_class(env, "ToolType", NAPI_AUTO_LENGTH, EnumClassConstructor, nullptr, + CHKRP(napi_define_class(env, "ToolType", NAPI_AUTO_LENGTH, EnumClassConstructor, nullptr, sizeof(toolTypeArr) / sizeof(*toolTypeArr), toolTypeArr, &toolType), DEFINE_CLASS); - CHKRP(env, napi_set_named_property(env, exports, "ToolType", toolType), SET_NAMED_PROPERTY); + CHKRP(napi_set_named_property(env, exports, "ToolType", toolType), SET_NAMED_PROPERTY); napi_property_descriptor sourceTypeArr[] = { DECLARE_NAPI_STATIC_PROPERTY("TOUCH_SCREEN", GetNapiInt32(env, static_cast(SourceType::TOUCH_SCREEN))), @@ -103,9 +103,9 @@ napi_value JsTouchEvent::Export(napi_env env, napi_value exports) DECLARE_NAPI_STATIC_PROPERTY("TOUCH_PAD", GetNapiInt32(env, static_cast(SourceType::TOUCH_PAD))), }; napi_value sourceType = nullptr; - CHKRP(env, napi_define_class(env, "SourceType", NAPI_AUTO_LENGTH, EnumClassConstructor, nullptr, + CHKRP(napi_define_class(env, "SourceType", NAPI_AUTO_LENGTH, EnumClassConstructor, nullptr, sizeof(sourceTypeArr) / sizeof(*sourceTypeArr), sourceTypeArr, &sourceType), DEFINE_CLASS); - CHKRP(env, napi_set_named_property(env, exports, "SourceType", sourceType), SET_NAMED_PROPERTY); + CHKRP(napi_set_named_property(env, exports, "SourceType", sourceType), SET_NAMED_PROPERTY); return exports; } } // namespace MMI diff --git a/frameworks/proxy/BUILD.gn b/frameworks/proxy/BUILD.gn old mode 100755 new mode 100644 index 4a9d0dccf7e47a0c4cd526af69a859fbf28be8bf..df4d53592e5ebea95df8137822ab234794d5b72b --- a/frameworks/proxy/BUILD.gn +++ b/frameworks/proxy/BUILD.gn @@ -14,6 +14,9 @@ import("//build/ohos.gni") import("//build/test.gni") import("//foundation/multimodalinput/input/multimodalinput_mini.gni") + +defines = input_default_defines + module_output_path = "multimodalinput/unit_out" config("libmmi_client_config") { @@ -56,24 +59,9 @@ config("libmmi_test_util") { } ohos_source_set("libmmi-common") { - sources = [ - "events/src/input_device.cpp", - "events/src/input_event.cpp", - "events/src/key_event.cpp", - "events/src/key_option.cpp", - "events/src/pointer_event.cpp", - ] - - defines = [] - - if (input_feature_debug) { - defines += [ "OHOS_BUILD_MMI_DEBUG" ] - } - - if (input_feature_input_cooperation) { - defines += [ "OHOS_BUILD_ENABLE_COOPERATE" ] - } + sources = libmmi_common_sources public_configs = [ ":libmmi_client_config" ] + visibility = [ "${mmi_path}/*" ] external_deps = [ "c_utils:utils", @@ -85,47 +73,13 @@ ohos_source_set("libmmi-common") { } ohos_shared_library("libmmi-client") { - sources = [ - "event_handler/src/bytrace_adapter.cpp", - "event_handler/src/client_msg_handler.cpp", - "event_handler/src/input_device_impl.cpp", - "event_handler/src/input_handler_manager.cpp", - "event_handler/src/input_manager_impl.cpp", - "event_handler/src/multimodal_event_handler.cpp", - "events/src/axis_event.cpp", - "events/src/input_manager.cpp", - "module_loader/src/mmi_client.cpp", - "module_loader/src/mmi_fd_listener.cpp", - ] + sources = libmmi_client_sources + version_script = "${mmi_path}/interfaces/native/innerkits/libmmi-client-map" + innerapi_tags = [ "platformsdk" ] if (input_feature_input_cooperation) { sources += [ "event_handler/src/input_device_cooperate_impl.cpp" ] } - defines = [] - - if (input_feature_debug) { - defines += [ "OHOS_BUILD_MMI_DEBUG" ] - } - - if (input_feature_pointer_drawing) { - defines += [ "OHOS_BUILD_ENABLE_POINTER_DRAWING" ] - } - if (input_feature_monitor) { - defines += [ "OHOS_BUILD_ENABLE_MONITOR" ] - } - if (input_feature_interceptor) { - defines += [ "OHOS_BUILD_ENABLE_INTERCEPTOR" ] - } - if (input_feature_keyboard) { - defines += [ "OHOS_BUILD_ENABLE_KEYBOARD" ] - } - if (input_feature_mouse) { - defines += [ "OHOS_BUILD_ENABLE_POINTER" ] - } - if (input_feature_touchscreen) { - defines += [ "OHOS_BUILD_ENABLE_TOUCH" ] - } - if (input_feature_interceptor) { sources += [ "event_handler/src/input_interceptor_manager.cpp" ] } @@ -138,14 +92,6 @@ ohos_shared_library("libmmi-client") { sources += [ "event_handler/src/key_event_input_subscribe_manager.cpp" ] } - if (input_feature_input_cooperation) { - defines += [ "OHOS_BUILD_ENABLE_COOPERATE" ] - } - - if (input_feature_joystick) { - defines += [ "OHOS_BUILD_ENABLE_JOYSTICK" ] - } - configs = [ ":libmmi_client_config", "//foundation/multimodalinput/input/util:libmmi_util_public_config", @@ -169,31 +115,16 @@ ohos_shared_library("libmmi-client") { "eventhandler:libeventhandler", "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", + "ipc:ipc_single", ] } ohos_unittest("ut-mmi-proxy-out") { module_out_path = module_output_path - include_dirs = [ "//commonlibrary/c_utils/base/include" ] - - if (input_feature_libinput) { - include_dirs += [ "$root_out_dir/diff_libinput_mmi/export_include" ] - } - - defines = [] - - if (input_feature_debug) { - defines += [ "OHOS_BUILD_MMI_DEBUG" ] - } - - if (input_feature_libinput) { - defines += [ "OHOS_BUILD_LIBINPUT" ] - } - - if (input_feature_hdf) { - defines += [ "OHOS_BUILD_HDF" ] - } + include_dirs = [ + "//commonlibrary/c_utils/base/include", + "$root_out_dir/diff_libinput_mmi/export_include", + ] sources = [ "module_loader/test/mmi_client_test.cpp" ] @@ -208,31 +139,16 @@ ohos_unittest("ut-mmi-proxy-out") { external_deps = [ "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", + "ipc:ipc_single", ] } ohos_unittest("KeyEventTest") { module_out_path = module_output_path - include_dirs = [ "//commonlibrary/c_utils/base/include" ] - - if (input_feature_libinput) { - include_dirs += [ "$root_out_dir/diff_libinput_mmi/export_include" ] - } - - defines = [] - - if (input_feature_debug) { - defines += [ "OHOS_BUILD_MMI_DEBUG" ] - } - - if (input_feature_libinput) { - defines += [ "OHOS_BUILD_LIBINPUT" ] - } - - if (input_feature_hdf) { - defines += [ "OHOS_BUILD_HDF" ] - } + include_dirs = [ + "//commonlibrary/c_utils/base/include", + "$root_out_dir/diff_libinput_mmi/export_include", + ] sources = [ "${mmi_path}/test/unittest/common/src/event_util_test.cpp", @@ -254,55 +170,20 @@ ohos_unittest("KeyEventTest") { "access_token:libnativetoken", "access_token:libtoken_setproc", "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", + "ipc:ipc_single", "window_manager:libwm", ] } ohos_unittest("InputManagerTest") { module_out_path = module_output_path - include_dirs = [ "${mmi_path}/frameworks/proxy/events/test" ] - - if (input_feature_libinput) { - include_dirs += [ "$root_out_dir/diff_libinput_mmi/export_include" ] - } - - defines = [] - - if (input_feature_debug) { - defines += [ "OHOS_BUILD_MMI_DEBUG" ] - } - - if (input_feature_pointer_drawing) { - defines += [ "OHOS_BUILD_ENABLE_POINTER_DRAWING" ] - } - - if (input_feature_libinput) { - defines += [ "OHOS_BUILD_LIBINPUT" ] - } - - if (input_feature_hdf) { - defines += [ "OHOS_BUILD_HDF" ] - } + include_dirs = [ + "${mmi_path}/frameworks/proxy/events/test", + "${mmi_path}/frameworks/proxy/event_handler/include", + "$root_out_dir/diff_libinput_mmi/export_include", + "${mmi_path}/service/filter/include", + ] - if (input_feature_keyboard) { - defines += [ "OHOS_BUILD_ENABLE_KEYBOARD" ] - } - if (input_feature_mouse) { - defines += [ "OHOS_BUILD_ENABLE_POINTER" ] - } - if (input_feature_touchscreen) { - defines += [ "OHOS_BUILD_ENABLE_TOUCH" ] - } - if (input_feature_interceptor) { - defines += [ "OHOS_BUILD_ENABLE_INTERCEPTOR" ] - } - if (input_feature_monitor) { - defines += [ "OHOS_BUILD_ENABLE_MONITOR" ] - } - if (input_feature_joystick) { - defines += [ "OHOS_BUILD_ENABLE_JOYSTICK" ] - } sources = [ "${mmi_path}/test/unittest/common/src/event_util_test.cpp", "${mmi_path}/test/unittest/common/src/system_info.cpp", @@ -325,7 +206,7 @@ ohos_unittest("InputManagerTest") { "access_token:libtoken_setproc", "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", + "ipc:ipc_single", "window_manager:libwm", ] } @@ -334,30 +215,6 @@ ohos_unittest("InputManagerManualTest") { module_out_path = module_output_path include_dirs = [ "//commonlibrary/c_utils/base/include" ] - if (input_feature_libinput) { - include_dirs += [ "$root_out_dir/diff_libinput_mmi/export_include" ] - } - - defines = [] - - if (input_feature_debug) { - defines += [ "OHOS_BUILD_MMI_DEBUG" ] - } - - if (input_feature_libinput) { - defines += [ "OHOS_BUILD_LIBINPUT" ] - } - - if (input_feature_hdf) { - defines += [ "OHOS_BUILD_HDF" ] - } - - if (input_feature_mouse) { - defines += [ "OHOS_BUILD_ENABLE_POINTER" ] - } - if (input_feature_touchscreen) { - defines += [ "OHOS_BUILD_ENABLE_TOUCH" ] - } sources = [ "events/test/input_manager_manual_test.cpp" ] configs = [ ":libmmi_test_util" ] @@ -373,34 +230,37 @@ ohos_unittest("InputManagerManualTest") { "access_token:libnativetoken", "access_token:libtoken_setproc", "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", + "ipc:ipc_single", ] } -ohos_unittest("PointerEventTest") { +ohos_unittest("InputManagerFilterManualTest") { module_out_path = module_output_path + include_dirs = [ "//commonlibrary/c_utils/base/include" ] - if (input_feature_libinput) { - include_dirs = [ "$root_out_dir/diff_libinput_mmi/export_include" ] - } - - defines = [] + sources = [ "events/test/input_manager_filter_manual_test.cpp" ] - if (input_feature_debug) { - defines += [ "OHOS_BUILD_MMI_DEBUG" ] - } + configs = [ ":libmmi_test_util" ] - if (input_feature_libinput) { - defines += [ "OHOS_BUILD_LIBINPUT" ] - } + deps = [ + "${mmi_path}/frameworks/proxy:libmmi-client", + "${mmi_path}/util:libmmi-util", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_single", + ] +} - if (input_feature_hdf) { - defines += [ "OHOS_BUILD_HDF" ] - } +ohos_unittest("PointerEventTest") { + module_out_path = module_output_path + include_dirs = [ "$root_out_dir/diff_libinput_mmi/export_include" ] - if (input_feature_mouse) { - defines += [ "OHOS_BUILD_ENABLE_POINTER" ] - } sources = [ "${mmi_path}/test/unittest/common/src/event_util_test.cpp", "${mmi_path}/test/unittest/common/src/window_utils_test.cpp", @@ -421,7 +281,7 @@ ohos_unittest("PointerEventTest") { "access_token:libnativetoken", "access_token:libtoken_setproc", "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", + "ipc:ipc_single", "window_manager:libwm", ] } diff --git a/service/dinput/include/call_dinput_proxy.h b/frameworks/proxy/event_handler/include/anr_handler.h similarity index 42% rename from service/dinput/include/call_dinput_proxy.h rename to frameworks/proxy/event_handler/include/anr_handler.h index dccc3816b23934e7602867ee4aaeb4ac2ca2eec5..7153e4da680df2513991d68c2ea08a4cfe99f70d 100644 --- a/service/dinput/include/call_dinput_proxy.h +++ b/frameworks/proxy/event_handler/include/anr_handler.h @@ -13,30 +13,42 @@ * limitations under the License. */ -#ifndef CALL_DINPUT_PROXY_H -#define CALL_DINPUT_PROXY_H -#ifdef OHOS_DISTRIBUTED_INPUT_MODEL +#ifndef ANR_HANDLER_H +#define ANR_HANDLER_H -#include "iremote_object.h" -#include "iremote_proxy.h" +#include -#include "i_call_dinput.h" +#include "singleton.h" + +#include "proto.h" namespace OHOS { namespace MMI { -class CallDinputProxy final : public IRemoteProxy { +class ANRHandler { + DECLARE_DELAYED_SINGLETON(ANRHandler); public: - explicit CallDinputProxy(const sptr &impl) {} - ~CallDinputProxy() = default; - int32_t HandlePrepareDinput(const std::string &deviceId, int32_t status) override; - int32_t HandleUnprepareDinput(const std::string &deviceId, int32_t status) override; - int32_t HandleStartDinput(const std::string &deviceId, uint32_t inputTypes, int32_t status) override; - int32_t HandleStopDinput(const std::string &deviceId, uint32_t inputTypes, int32_t status) override; - int32_t HandleRemoteInputAbility(const std::set &remoteInputAbility) override; + DISALLOW_COPY_AND_MOVE(ANRHandler); + + void SetLastProcessedEventId(int32_t eventType, int32_t eventId, uint64_t actionTime); + void MarkProcessed(int32_t eventType); + void ResetAnrArray(); + std::mutex anrMtx_; + private: - static BrokerDelegator delegator_; + struct ANREvent { + bool sendStatus { false }; + int32_t lastEventId { -1 }; + int32_t lastReportId { -1 }; + }; + ANREvent event_[ANR_EVENT_TYPE_NUM]; + + void UpdateLastProcessedEventId(int32_t eventType, int32_t eventId); + void SetLastProcessedEventStatus(int32_t eventType, bool status); + int32_t GetLastProcessedEventId(int32_t eventType); + void SendEvent(int32_t eventType, int64_t delayTime); }; + +#define ANRHdl ::OHOS::DelayedSingleton::GetInstance() } // namespace MMI } // namespace OHOS -#endif // OHOS_DISTRIBUTED_INPUT_MODEL -#endif // CALL_DINPUT_PROXY_H +#endif // ANR_HANDLER_H \ No newline at end of file diff --git a/frameworks/proxy/event_handler/include/bytrace_adapter.h b/frameworks/proxy/event_handler/include/bytrace_adapter.h index c8dcd3b1903ba12410eef634f9715cb24c90739e..d6bb08c6338b26501ed66dbde422764a99b36f11 100644 --- a/frameworks/proxy/event_handler/include/bytrace_adapter.h +++ b/frameworks/proxy/event_handler/include/bytrace_adapter.h @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef BYTRACE_ADAPTER_H #define BYTRACE_ADAPTER_H @@ -22,7 +23,7 @@ namespace OHOS { namespace MMI { -class BytraceAdapter { +class BytraceAdapter final { public: enum TraceBtn { TRACE_STOP = 0, diff --git a/frameworks/proxy/event_handler/include/client_msg_handler.h b/frameworks/proxy/event_handler/include/client_msg_handler.h index 385f030b7ecf3bf0c5ba1d04b8e630971718736a..79ccb83310f516699cc0e4b2f9d06d4fe3d167ee 100644 --- a/frameworks/proxy/event_handler/include/client_msg_handler.h +++ b/frameworks/proxy/event_handler/include/client_msg_handler.h @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef CLIENT_MSG_HANDLER_H #define CLIENT_MSG_HANDLER_H @@ -23,11 +24,11 @@ namespace OHOS { namespace MMI { typedef std::function ClientMsgFun; -class ClientMsgHandler : public MsgHandler { +class ClientMsgHandler final : public MsgHandler { public: ClientMsgHandler() = default; DISALLOW_COPY_AND_MOVE(ClientMsgHandler); - virtual ~ClientMsgHandler(); + ~ClientMsgHandler() override = default; void Init(); void InitProcessedCallback(); @@ -59,16 +60,16 @@ protected: int32_t OnDevListener(const UDSClient& client, NetPacket& pkt); int32_t OnAnr(const UDSClient& client, NetPacket& pkt); #ifdef OHOS_BUILD_ENABLE_COOPERATE - int32_t OnCooperationListiner(const UDSClient& client, NetPacket& pkt); + int32_t OnCooperationListener(const UDSClient& client, NetPacket& pkt); int32_t OnCooperationMessage(const UDSClient& client, NetPacket& pkt); int32_t OnCooperationState(const UDSClient& client, NetPacket& pkt); #endif // OHOS_BUILD_ENABLE_COOPERATE private: - static void OnDispatchEventProcessed(int32_t eventId); + static void OnDispatchEventProcessed(int32_t eventId, int64_t actionTime); private: - std::function dispatchCallback_ { nullptr }; + std::function dispatchCallback_ { nullptr }; }; } // namespace MMI } // namespace OHOS diff --git a/frameworks/proxy/event_handler/include/input_device_cooperate_impl.h b/frameworks/proxy/event_handler/include/input_device_cooperate_impl.h index bcdb0788f0ea19b8a9b5d0f82efc714e6773beb2..0383f2710caa93bbb72ee5351c4afad45d7d34bc 100755 --- a/frameworks/proxy/event_handler/include/input_device_cooperate_impl.h +++ b/frameworks/proxy/event_handler/include/input_device_cooperate_impl.h @@ -27,23 +27,23 @@ namespace OHOS { namespace MMI { -class InputDeviceCooperateImpl { +class InputDeviceCooperateImpl final { public: static InputDeviceCooperateImpl &GetInstance(); DISALLOW_COPY_AND_MOVE(InputDeviceCooperateImpl); ~InputDeviceCooperateImpl() = default; using FuncCooperationMessage = std::function; - using FuncCooperateionState = std::function; + using FuncCooperationState = std::function; using DevCooperationMsg = FuncCooperationMessage; - using DevCooperateionState = FuncCooperateionState; + using DevCooperationState = FuncCooperationState; using InputDevCooperateListenerPtr = std::shared_ptr; struct CooperateEvent { DevCooperationMsg msg; - DevCooperateionState state; + DevCooperationState state; }; int32_t RegisterCooperateListener(InputDevCooperateListenerPtr listener); @@ -52,15 +52,15 @@ public: int32_t StartInputDeviceCooperate(const std::string &sinkDeviceId, int32_t srcInputDeviceId, FuncCooperationMessage callback); int32_t StopDeviceCooperate(FuncCooperationMessage callback); - int32_t GetInputDeviceCooperateState(const std::string &deviceId, FuncCooperateionState callback); - void OnDevCooperateListener(const std::string deviceId, CooperationMessage msg); - void OnCooprationMessage(int32_t userData, const std::string deviceId, CooperationMessage msg); + int32_t GetInputDeviceCooperateState(const std::string &deviceId, FuncCooperationState callback); + void OnDevCooperateListener(const std::string &deviceId, const CooperationMessage &msg); + void OnCooperationMessage(int32_t userData, const std::string &deviceId, const CooperationMessage &msg); void OnCooperationState(int32_t userData, bool state); int32_t GetUserData(); private: - const DevCooperationMsg *GetCooprateMessageEvent(int32_t userData) const; - const DevCooperateionState *GetCooprateStateEvent(int32_t userData) const; + const DevCooperationMsg *GetCooperateMessageEvent(int32_t userData) const; + const DevCooperationState *GetCooperateStateEvent(int32_t userData) const; private: InputDeviceCooperateImpl() = default; diff --git a/frameworks/proxy/event_handler/include/input_device_impl.h b/frameworks/proxy/event_handler/include/input_device_impl.h old mode 100755 new mode 100644 index 792833e227ac3e93544114611c7360ed490229b2..4c35a83edfc3f0cec3fa6adf9b6664728305bf56 --- a/frameworks/proxy/event_handler/include/input_device_impl.h +++ b/frameworks/proxy/event_handler/include/input_device_impl.h @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef OHOS_INPUT_DEVICE_EVENT_H #define OHOS_INPUT_DEVICE_EVENT_H @@ -29,7 +30,7 @@ namespace OHOS { namespace MMI { class NetPacket; -class InputDeviceImpl { +class InputDeviceImpl final { public: static InputDeviceImpl& GetInstance(); DISALLOW_COPY_AND_MOVE(InputDeviceImpl); @@ -39,18 +40,12 @@ public: using FunInputDevIds = std::function&)>; using FunInputDevKeys = std::function&)>; using FunKeyboardTypes = std::function; - struct InputDeviceData { - FunInputDevInfo inputDevice; - FunInputDevIds ids; - FunInputDevKeys keys; - FunKeyboardTypes kbTypes; - }; using InputDevListenerPtr = std::shared_ptr; int32_t RegisterDevListener(const std::string &type, InputDevListenerPtr listener); int32_t UnregisterDevListener(const std::string &type, InputDevListenerPtr listener = nullptr); - int32_t GetInputDeviceIdsAsync(FunInputDevIds callback); - int32_t GetInputDeviceAsync(int32_t deviceId, FunInputDevInfo callback); + int32_t GetInputDeviceIds(FunInputDevIds callback); + int32_t GetInputDevice(int32_t deviceId, FunInputDevInfo callback); int32_t SupportKeys(int32_t deviceId, std::vector keyCodes, FunInputDevKeys callback); int32_t GetKeyboardType(int32_t deviceId, FunKeyboardTypes callback); void OnInputDevice(int32_t userData, std::shared_ptr devData); @@ -59,16 +54,9 @@ public: void OnDevListener(int32_t deviceId, const std::string &type); void OnKeyboardType(int32_t userData, int32_t keyboardType); int32_t GetUserData(); - std::shared_ptr DevDataUnmarshalling(NetPacket &pkt); -private: - const FunInputDevInfo* GetDeviceInfo(int32_t) const; - const FunInputDevIds* GetDeviceIds(int32_t) const; - const FunInputDevKeys* GetDeviceKeys(int32_t) const; - const FunKeyboardTypes* GetKeyboardTypes(int32_t) const; private: InputDeviceImpl() = default; - std::map inputDevices_; std::map> devListener_ = { { "change", {} } }; int32_t userData_ { 0 }; bool isListeningProcess_ { false }; diff --git a/frameworks/proxy/event_handler/include/input_handler_manager.h b/frameworks/proxy/event_handler/include/input_handler_manager.h old mode 100755 new mode 100644 index 0b0f94ae0a3523dd5e3c02f4ed48394064836dd1..e97ac584f7292d7194d4e2e71a251a0a29b7200c --- a/frameworks/proxy/event_handler/include/input_handler_manager.h +++ b/frameworks/proxy/event_handler/include/input_handler_manager.h @@ -20,6 +20,7 @@ #include #include +#include "input_device.h" #include "input_handler_type.h" #include "i_input_event_consumer.h" #include "pointer_event.h" @@ -34,10 +35,10 @@ public: public: #ifdef OHOS_BUILD_ENABLE_KEYBOARD - void OnInputEvent(std::shared_ptr keyEvent); + void OnInputEvent(std::shared_ptr keyEvent, uint32_t deviceTags); #endif // OHOS_BUILD_ENABLE_KEYBOARD #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) - void OnInputEvent(std::shared_ptr pointerEvent); + void OnInputEvent(std::shared_ptr pointerEvent, uint32_t deviceTags); #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH #if defined(OHOS_BUILD_ENABLE_INTERCEPTOR) || defined(OHOS_BUILD_ENABLE_MONITOR) void OnConnected(); @@ -45,39 +46,48 @@ public: bool HasHandler(int32_t handlerId); virtual InputHandlerType GetHandlerType() const = 0; HandleEventType GetEventType() const; + int32_t GetPriority() const; + uint32_t GetDeviceTags() const; protected: int32_t AddHandler(InputHandlerType handlerType, std::shared_ptr consumer, - HandleEventType eventType = HANDLE_EVENT_TYPE_ALL); - void RemoveHandler(int32_t handlerId, InputHandlerType handlerType); + HandleEventType eventType = HANDLE_EVENT_TYPE_ALL, int32_t priority = DEFUALT_INTERCEPTOR_PRIORITY, + uint32_t deviceTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX)); + void RemoveHandler(int32_t handlerId, InputHandlerType IsValidHandlerType); private: struct Handler { int32_t handlerId_ { 0 }; InputHandlerType handlerType_ { NONE }; HandleEventType eventType_ { HANDLE_EVENT_TYPE_ALL }; + int32_t priority_ { DEFUALT_INTERCEPTOR_PRIORITY }; + uint32_t deviceTags_ { CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX) }; std::shared_ptr consumer_ { nullptr }; }; private: int32_t GetNextId(); - int32_t AddLocal(int32_t handlerId, InputHandlerType handlerType, - HandleEventType eventType, std::shared_ptr monitor); - int32_t AddToServer(InputHandlerType handlerType, HandleEventType eventType); + int32_t AddLocal(int32_t handlerId, InputHandlerType handlerType, HandleEventType eventType, + int32_t priority, uint32_t deviceTags, std::shared_ptr monitor); + int32_t AddToServer(InputHandlerType handlerType, HandleEventType eventType, int32_t priority, + uint32_t deviceTags); int32_t RemoveLocal(int32_t handlerId, InputHandlerType handlerType); - void RemoveFromServer(InputHandlerType handlerType, HandleEventType eventType); + void RemoveFromServer(InputHandlerType handlerType, HandleEventType eventType, int32_t priority, + uint32_t deviceTags); std::shared_ptr FindHandler(int32_t handlerId); - void OnDispatchEventProcessed(int32_t eventId); + void OnDispatchEventProcessed(int32_t eventId, int64_t actionTime); #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) - void GetConsumerInfos(std::shared_ptr pointerEvent, + void GetConsumerInfos(std::shared_ptr pointerEvent, uint32_t deviceTags, std::map> &consumerInfos); #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH private: + std::list interHandlers_; std::map inputHandlers_; std::map processedEvents_; - std::function monitorCallback_ { nullptr }; + std::set mouseEventIds_; + std::function monitorCallback_ { nullptr }; int32_t nextId_ { 1 }; std::mutex mtxHandlers_; }; diff --git a/frameworks/proxy/event_handler/include/input_handler_type.h b/frameworks/proxy/event_handler/include/input_handler_type.h index c85d66116911b804b5ac70f3d6710fde0bd80883..e5812fbc29085abe0af1f59f1f2b8da33bd493b8 100644 --- a/frameworks/proxy/event_handler/include/input_handler_type.h +++ b/frameworks/proxy/event_handler/include/input_handler_type.h @@ -24,6 +24,7 @@ inline constexpr size_t MAX_N_INPUT_INTERCEPTORS { MAX_N_INPUT_HANDLERS }; inline constexpr int32_t MIN_HANDLER_ID { 1 }; inline constexpr int32_t INVALID_HANDLER_ID { -1 }; inline constexpr int32_t ERROR_EXCEED_MAX_COUNT { -4100001 }; +inline constexpr int32_t DEFUALT_INTERCEPTOR_PRIORITY { 500 }; enum InputHandlerType : int32_t { NONE, diff --git a/frameworks/proxy/event_handler/include/input_interceptor_manager.h b/frameworks/proxy/event_handler/include/input_interceptor_manager.h index 853bfba30700530b43ff60ca9c1ca65fd4256190..a7b64cb8e525492ac52d0ac280b98c2babee3dbb 100644 --- a/frameworks/proxy/event_handler/include/input_interceptor_manager.h +++ b/frameworks/proxy/event_handler/include/input_interceptor_manager.h @@ -21,18 +21,19 @@ #include "singleton.h" #include "input_handler_manager.h" -#include "i_input_event_consumer.h" #include "input_handler_type.h" namespace OHOS { namespace MMI { -class InputInterceptorManager : public InputHandlerManager { +class InputInterceptorManager final : public InputHandlerManager { DECLARE_DELAYED_SINGLETON(InputInterceptorManager); public: DISALLOW_COPY_AND_MOVE(InputInterceptorManager); int32_t AddInterceptor(std::shared_ptr interceptor, HandleEventType eventType); + int32_t AddInterceptor(std::shared_ptr interceptor, HandleEventType eventType, + int32_t priority, uint32_t deviceTags); void RemoveInterceptor(int32_t interceptorId); - virtual InputHandlerType GetHandlerType() const override; + InputHandlerType GetHandlerType() const override; }; inline InputHandlerType InputInterceptorManager::GetHandlerType() const diff --git a/frameworks/proxy/event_handler/include/input_manager_impl.h b/frameworks/proxy/event_handler/include/input_manager_impl.h old mode 100755 new mode 100644 index 1abd4c3dff62988d1715d4737ec963b82093180f..e32dd1026ccafecc3f2801dbd62f8a6a4a9ca75d --- a/frameworks/proxy/event_handler/include/input_manager_impl.h +++ b/frameworks/proxy/event_handler/include/input_manager_impl.h @@ -16,15 +16,17 @@ #ifndef INPUT_MANAGER_IMPL_H #define INPUT_MANAGER_IMPL_H +#include #include #include "singleton.h" #include "net_packet.h" -#include "display_info.h" +#include "window_info.h" #include "event_filter_service.h" #include "event_handler.h" +#include "extra_data.h" #include "if_mmi_client.h" #include "input_device_impl.h" #include "input_device_cooperate_impl.h" @@ -35,12 +37,9 @@ #include "input_monitor_manager.h" #endif // OHOS_BUILD_ENABLE_MONITOR #include "i_anr_observer.h" -#include "i_input_event_consumer.h" #include "key_option.h" #include "pointer_event.h" -#ifdef OHOS_DISTRIBUTED_INPUT_MODEL -#include "call_dinput_service.h" -#endif // OHOS_DISTRIBUTED_INPUT_MODEL +#include "pointer_style.h" namespace OHOS { namespace MMI { @@ -50,13 +49,17 @@ class InputManagerImpl final { public: DISALLOW_MOVE(InputManagerImpl); + int32_t GetDisplayBindInfo(DisplayBindInfos &infos); + int32_t SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg); + int32_t GetWindowPid(int32_t windowId); void UpdateDisplayInfo(const DisplayGroupInfo &displayGroupInfo); int32_t SubscribeKeyEvent( std::shared_ptr keyOption, std::function)> callback ); void UnsubscribeKeyEvent(int32_t subscriberId); - int32_t AddInputEventFilter(std::function)> filter); + int32_t AddInputEventFilter(std::shared_ptr filter, int32_t priority, uint32_t deviceTags); + int32_t RemoveInputEventFilter(int32_t filterId); void SetWindowInputEventConsumer(std::shared_ptr inputEventConsumer, std::shared_ptr eventHandler); @@ -77,8 +80,12 @@ public: void MarkConsumed(int32_t monitorId, int32_t eventId); void MoveMouse(int32_t offsetX, int32_t offsetY); - int32_t AddInterceptor(std::shared_ptr interceptor); - int32_t AddInterceptor(std::function)> interceptor); + int32_t AddInterceptor(std::shared_ptr interceptor, + int32_t priority = DEFUALT_INTERCEPTOR_PRIORITY, + uint32_t deviceTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX)); + int32_t AddInterceptor(std::function)> interceptor, + int32_t priority = DEFUALT_INTERCEPTOR_PRIORITY, + uint32_t deviceTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX)); void RemoveInterceptor(int32_t interceptorId); void SimulateInputEvent(std::shared_ptr keyEvent); @@ -95,8 +102,8 @@ public: int32_t SetPointerVisible(bool visible); bool IsPointerVisible(); - int32_t SetPointerStyle(int32_t windowId, int32_t pointerStyle); - int32_t GetPointerStyle(int32_t windowId, int32_t &pointerStyle); + int32_t SetPointerStyle(int32_t windowId, const PointerStyle& pointerStyle); + int32_t GetPointerStyle(int32_t windowId, PointerStyle &pointerStyle); int32_t SetPointerSpeed(int32_t speed); int32_t GetPointerSpeed(int32_t &speed); @@ -104,15 +111,9 @@ public: void SetAnrObserver(std::shared_ptr observer); void OnAnr(int32_t pid); - int32_t SetPointerLocation(int32_t x, int32_t y); - - int32_t GetRemoteInputAbility(std::string deviceId, std::function)> remoteTypes); - int32_t PrepareRemoteInput(const std::string& deviceId, std::function callback); - int32_t UnprepareRemoteInput(const std::string& deviceId, std::function callback); - int32_t StartRemoteInput(const std::string& deviceId, uint32_t inputAbility, std::function callback); - int32_t StopRemoteInput(const std::string& deviceId, uint32_t inputAbility, std::function callback); - int32_t RegisterCooperateListener(std::shared_ptr listener); + int32_t EnterCaptureMode(int32_t windowId); + int32_t LeaveCaptureMode(int32_t windowId); int32_t UnregisterCooperateListener(std::shared_ptr listener = nullptr); int32_t EnableInputDeviceCooperate(bool enabled, std::function callback); int32_t StartInputDeviceCooperate(const std::string &sinkDeviceId, int32_t srcInputDeviceId, @@ -122,12 +123,16 @@ public: int32_t SetInputDevice(const std::string& dhid, const std::string& screenId); bool GetFunctionKeyState(int32_t funcKey); int32_t SetFunctionKeyState(int32_t funcKey, bool enable); + void SetPointerLocation(int32_t x, int32_t y); + EventHandlerPtr GetEventHandler() const; + void AppendExtraData(const ExtraData& extraData); private: int32_t PackWindowInfo(NetPacket &pkt); int32_t PackDisplayInfo(NetPacket &pkt); void PrintDisplayInfo(); void SendDisplayInfo(); + void ReAddInputEventFilter(); #ifdef OHOS_BUILD_ENABLE_KEYBOARD void OnKeyEventTask(std::shared_ptr consumer, @@ -138,7 +143,7 @@ private: std::shared_ptr pointerEvent); #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH private: - sptr eventFilterService_ { nullptr }; + std::map, int32_t, uint32_t>> eventFilterServices_; std::shared_ptr consumer_ { nullptr }; std::vector> anrObservers_; @@ -148,12 +153,9 @@ private: std::condition_variable cv_; std::thread ehThread_; std::shared_ptr eventHandler_ { nullptr }; -#ifdef OHOS_DISTRIBUTED_INPUT_MODEL - sptr callDinputService_ { nullptr }; -#endif // OHOS_DISTRIBUTED_INPUT_MODEL }; #define InputMgrImpl ::OHOS::Singleton::GetInstance() } // namespace MMI } // namespace OHOS -#endif // INPUT_MANAGER_IMPL_H \ No newline at end of file +#endif // INPUT_MANAGER_IMPL_H diff --git a/frameworks/proxy/event_handler/include/input_monitor_manager.h b/frameworks/proxy/event_handler/include/input_monitor_manager.h index 7292d5d281a91d503b1b87c09baa7a874b1995fc..c9cbb71a0c5d8a6c9b0096fac93292c919893ef3 100644 --- a/frameworks/proxy/event_handler/include/input_monitor_manager.h +++ b/frameworks/proxy/event_handler/include/input_monitor_manager.h @@ -21,19 +21,19 @@ #include "singleton.h" #include "input_handler_manager.h" -#include "i_input_event_consumer.h" #include "input_handler_type.h" +#include "i_input_event_consumer.h" namespace OHOS { namespace MMI { -class InputMonitorManager : public InputHandlerManager { +class InputMonitorManager final : public InputHandlerManager { DECLARE_DELAYED_SINGLETON(InputMonitorManager); public: DISALLOW_COPY_AND_MOVE(InputMonitorManager); int32_t AddMonitor(std::shared_ptr monitor); void RemoveMonitor(int32_t monitorId); void MarkConsumed(int32_t monitorId, int32_t eventId); - virtual InputHandlerType GetHandlerType() const override; + InputHandlerType GetHandlerType() const override; public: static bool IsValidMonitorId(int32_t monitorId); diff --git a/frameworks/proxy/event_handler/src/anr_handler.cpp b/frameworks/proxy/event_handler/src/anr_handler.cpp new file mode 100644 index 0000000000000000000000000000000000000000..550ef4d381168321cc6d01a8669b0880a5a563f1 --- /dev/null +++ b/frameworks/proxy/event_handler/src/anr_handler.cpp @@ -0,0 +1,135 @@ +/* + * 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. + */ + +#include "anr_handler.h" + +#include + +#include "define_multimodal.h" + +#include "input_manager_impl.h" +#include "multimodal_input_connect_manager.h" + +namespace OHOS { +namespace MMI { +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "ANRHandler" }; +constexpr int64_t MAX_MARK_PROCESS_DELAY_TIME = 3500000; +constexpr int64_t MIN_MARK_PROCESS_DELAY_TIME = 50000; +constexpr int32_t INVALID_OR_PROCESSED_ID = -1; +} // namespace + +ANRHandler::ANRHandler() {} + +ANRHandler::~ANRHandler() {} + +void ANRHandler::SetLastProcessedEventStatus(int32_t eventType, bool status) +{ + std::lock_guard guard(anrMtx_); + event_[eventType].sendStatus = status; +} + +void ANRHandler::UpdateLastProcessedEventId(int32_t eventType, int32_t eventId) +{ + std::lock_guard guard(anrMtx_); + event_[eventType].lastEventId = eventId; +} + +void ANRHandler::SetLastProcessedEventId(int32_t eventType, int32_t eventId, uint64_t actionTime) +{ + CALL_DEBUG_ENTER; + if (event_[eventType].lastEventId > eventId) { + MMI_HILOGE("Event type:%{public}d, id %{public}d less then last processed lastEventId %{public}d", + eventType, eventId, event_[eventType].lastEventId); + return; + } + UpdateLastProcessedEventId(eventType, eventId); + + int64_t currentTime = GetSysClockTime(); + int64_t timeoutTime = INPUT_UI_TIMEOUT_TIME - (currentTime - actionTime); + MMI_HILOGD("Processed event type:%{public}d, id:%{public}d, actionTime:%{public}" PRId64 ", " + "currentTime:%{public}" PRId64 ", timeoutTime:%{public}" PRId64, + eventType, eventId, actionTime, currentTime, timeoutTime); + + if (!event_[eventType].sendStatus) { + if (timeoutTime < MIN_MARK_PROCESS_DELAY_TIME) { + SendEvent(eventType, 0); + } else { + int64_t delayTime; + if (timeoutTime >= MAX_MARK_PROCESS_DELAY_TIME) { + delayTime = MAX_MARK_PROCESS_DELAY_TIME / 1000; + } else { + delayTime = timeoutTime / 1000; + } + SendEvent(eventType, delayTime); + } + } +} + +int32_t ANRHandler::GetLastProcessedEventId(int32_t eventType) +{ + CALL_DEBUG_ENTER; + std::lock_guard guard(anrMtx_); + if (event_[eventType].lastEventId == INVALID_OR_PROCESSED_ID + || event_[eventType].lastEventId <= event_[eventType].lastReportId) { + MMI_HILOGD("Invalid or processed event type:%{public}d, lastEventId:%{public}d, lastReportId:%{public}d", + eventType, event_[eventType].lastEventId, event_[eventType].lastReportId); + return INVALID_OR_PROCESSED_ID; + } + + event_[eventType].lastReportId = event_[eventType].lastEventId; + MMI_HILOGD("Processed event type:%{public}d, lastEventId:%{public}d, lastReportId:%{public}d", + eventType, event_[eventType].lastEventId, event_[eventType].lastReportId); + return event_[eventType].lastEventId; +} + +void ANRHandler::MarkProcessed(int32_t eventType) +{ + CALL_DEBUG_ENTER; + int32_t eventId = GetLastProcessedEventId(eventType); + if (eventId == INVALID_OR_PROCESSED_ID) { + return; + } + MMI_HILOGD("Processed event type:%{public}d, id:%{public}d", eventType, eventId); + int32_t ret = MultimodalInputConnMgr->MarkProcessed(eventType, eventId); + if (ret != 0) { + MMI_HILOGE("Send to server failed, ret:%{public}d", ret); + } + SetLastProcessedEventStatus(eventType, false); +} + + +void ANRHandler::SendEvent(int32_t eventType, int64_t delayTime) +{ + CALL_DEBUG_ENTER; + MMI_HILOGD("Event type:%{public}d, delayTime:%{public}" PRId64, eventType, delayTime); + SetLastProcessedEventStatus(eventType, true); + auto eventHandler = InputMgrImpl.GetEventHandler(); + CHKPV(eventHandler); + std::function eventFunc = std::bind(&ANRHandler::MarkProcessed, this, eventType); + if (!eventHandler->PostHighPriorityTask(eventFunc, delayTime)) { + MMI_HILOGE("Send dispatch event failed"); + } +} + +void ANRHandler::ResetAnrArray() { + for(int i = 0; i < ANR_EVENT_TYPE_NUM; i++) { + event_[i].sendStatus = false; + event_[i].lastEventId = -1; + event_[i].lastReportId = -1; + } +} +} // namespace MMI +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/proxy/event_handler/src/bytrace_adapter.cpp b/frameworks/proxy/event_handler/src/bytrace_adapter.cpp index a5074b42a46aed3496257030d881ff45c9bf5c84..cba64e06eab8c37940077893bff964ba57ad1608 100644 --- a/frameworks/proxy/event_handler/src/bytrace_adapter.cpp +++ b/frameworks/proxy/event_handler/src/bytrace_adapter.cpp @@ -24,25 +24,23 @@ namespace OHOS { namespace MMI { namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "BytraceAdapter" }; +const std::string onKeyEvent { "OnKeyEvent" }; +const std::string onTouchEvent { "OnTouchEvent" }; +const std::string onPointerEvent { "OnPointerEvent" }; +const std::string keyEventDispatch { "KeyEventDispatch" }; +const std::string touchEventDispatch { "touchEventDispatch" }; +const std::string pointerEventDispatch { "PointerEventDispatch" }; +const std::string keyEventSubscribe { "KeyEventSubscribe" }; +const std::string pointerEventIntercept { "PointerEventIntercept" }; +const std::string touchEventIntercept { "TouchEventIntercept" }; +const std::string keyEventIntercept { "KeyEventIntercept" }; +const std::string startEvent { "StartEvent" }; +const std::string launchEvent { "LaunchEvent" }; +const std::string stopEvent { "StopEvent" }; +constexpr int32_t START_ID = 1; +constexpr int32_t LAUNCH_ID = 2; +constexpr int32_t STOP_ID = 3; } // namespace -namespace { - std::string onKeyEvent = "OnKeyEvent"; - std::string onTouchEvent = "OnTouchEvent"; - std::string onPointerEvent = "OnPointerEvent"; - std::string keyEventDispatch = "KeyEventDispatch"; - std::string touchEventDispatch = "touchEventDispatch"; - std::string pointerEventDispatch = "PointerEventDispatch"; - std::string keyEventSubscribe = "KeyEventSubscribe"; - std::string pointerEventIntercept = "PointerEventIntercept"; - std::string touchEventIntercept = "TouchEventIntercept"; - std::string keyEventIntercept = "KeyEventIntercept"; - std::string startEvent = "StartEvent"; - std::string launchEvent = "LaunchEvent"; - std::string stopEvent = "StopEvent"; - constexpr int32_t START_ID = 1; - constexpr int32_t LAUNCH_ID = 2; - constexpr int32_t STOP_ID = 3; -} void BytraceAdapter::StartBytrace(std::shared_ptr keyEvent) { @@ -96,7 +94,7 @@ void BytraceAdapter::StartBytrace(std::shared_ptr key, HandlerType han break; } default: { - checkKeyCode = "Unknow keycode:" + std::to_string(keyCode); + checkKeyCode = "Unknown keycode:" + std::to_string(keyCode); break; } } @@ -128,7 +126,7 @@ void BytraceAdapter::StartBytrace(std::shared_ptr keyEvent, TraceBtn t break; } default: { - HITRACE_METER_NAME(HITRACE_TAG_MULTIMODALINPUT, "Unknow keycode:" + std::to_string(keyCode)); + HITRACE_METER_NAME(HITRACE_TAG_MULTIMODALINPUT, "Unknown keycode:" + std::to_string(keyCode)); break; } } @@ -147,7 +145,7 @@ void BytraceAdapter::StartBytrace(std::shared_ptr keyEvent, TraceBtn t break; } default: { - HITRACE_METER_NAME(HITRACE_TAG_MULTIMODALINPUT, "Unknow keycode:" + std::to_string(keyCode)); + HITRACE_METER_NAME(HITRACE_TAG_MULTIMODALINPUT, "Unknown keycode:" + std::to_string(keyCode)); break; } } diff --git a/frameworks/proxy/event_handler/src/client_msg_handler.cpp b/frameworks/proxy/event_handler/src/client_msg_handler.cpp index 6625570063ef520762aaafd50ad69277642558f3..22453bcfe3be6168a892b79bf6e6c02aea5d3175 100644 --- a/frameworks/proxy/event_handler/src/client_msg_handler.cpp +++ b/frameworks/proxy/event_handler/src/client_msg_handler.cpp @@ -29,6 +29,7 @@ #include "input_event_data_transformation.h" #include "input_handler_manager.h" #include "input_manager_impl.h" +#include "anr_handler.h" #ifdef OHOS_BUILD_ENABLE_MONITOR #include "input_monitor_manager.h" #endif // OHOS_BUILD_ENABLE_MONITOR @@ -44,43 +45,34 @@ namespace OHOS { namespace MMI { namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "ClientMsgHandler"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "ClientMsgHandler" }; } // namespace -ClientMsgHandler::~ClientMsgHandler() -{ - dispatchCallback_ = nullptr; -} - void ClientMsgHandler::Init() { MsgCallback funs[] = { #ifdef OHOS_BUILD_ENABLE_KEYBOARD - {MmiMessageId::ON_KEYEVENT, MsgCallbackBind2(&ClientMsgHandler::OnKeyEvent, this)}, - {MmiMessageId::ON_SUBSCRIBE_KEY, std::bind(&ClientMsgHandler::OnSubscribeKeyEventCallback, - this, std::placeholders::_1, std::placeholders::_2)}, + { MmiMessageId::ON_KEY_EVENT, MsgCallbackBind2(&ClientMsgHandler::OnKeyEvent, this) }, + { MmiMessageId::ON_SUBSCRIBE_KEY, std::bind(&ClientMsgHandler::OnSubscribeKeyEventCallback, + this, std::placeholders::_1, std::placeholders::_2) }, #endif // OHOS_BUILD_ENABLE_KEYBOARD #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) - {MmiMessageId::ON_POINTER_EVENT, MsgCallbackBind2(&ClientMsgHandler::OnPointerEvent, this)}, + { MmiMessageId::ON_POINTER_EVENT, MsgCallbackBind2(&ClientMsgHandler::OnPointerEvent, this) }, #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH - {MmiMessageId::INPUT_DEVICE, MsgCallbackBind2(&ClientMsgHandler::OnInputDevice, this)}, - {MmiMessageId::INPUT_DEVICE_IDS, MsgCallbackBind2(&ClientMsgHandler::OnInputDeviceIds, this)}, - {MmiMessageId::INPUT_DEVICE_SUPPORT_KEYS, MsgCallbackBind2(&ClientMsgHandler::OnSupportKeys, this)}, - {MmiMessageId::INPUT_DEVICE_KEYBOARD_TYPE, MsgCallbackBind2(&ClientMsgHandler::OnInputKeyboardType, this)}, - {MmiMessageId::ADD_INPUT_DEVICE_LISTENER, MsgCallbackBind2(&ClientMsgHandler::OnDevListener, this)}, - {MmiMessageId::NOTICE_ANR, MsgCallbackBind2(&ClientMsgHandler::OnAnr, this)}, + { MmiMessageId::ADD_INPUT_DEVICE_LISTENER, MsgCallbackBind2(&ClientMsgHandler::OnDevListener, this) }, + { MmiMessageId::NOTICE_ANR, MsgCallbackBind2(&ClientMsgHandler::OnAnr, this) }, #if defined(OHOS_BUILD_ENABLE_KEYBOARD) && (defined(OHOS_BUILD_ENABLE_INTERCEPTOR) || \ defined(OHOS_BUILD_ENABLE_MONITOR)) - {MmiMessageId::REPORT_KEY_EVENT, MsgCallbackBind2(&ClientMsgHandler::ReportKeyEvent, this)}, + { MmiMessageId::REPORT_KEY_EVENT, MsgCallbackBind2(&ClientMsgHandler::ReportKeyEvent, this) }, #endif // OHOS_BUILD_ENABLE_KEYBOARD #if (defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)) && \ (defined(OHOS_BUILD_ENABLE_INTERCEPTOR) || defined(OHOS_BUILD_ENABLE_MONITOR)) - {MmiMessageId::REPORT_POINTER_EVENT, MsgCallbackBind2(&ClientMsgHandler::ReportPointerEvent, this)}, + { MmiMessageId::REPORT_POINTER_EVENT, MsgCallbackBind2(&ClientMsgHandler::ReportPointerEvent, this) }, #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH #ifdef OHOS_BUILD_ENABLE_COOPERATE - {MmiMessageId::COOPERATION_ADD_LISTENER, MsgCallbackBind2(&ClientMsgHandler::OnCooperationListiner, this)}, - {MmiMessageId::COOPERATION_MESSAGE, MsgCallbackBind2(&ClientMsgHandler::OnCooperationMessage, this)}, - {MmiMessageId::COOPERATION_GET_STATE, MsgCallbackBind2(&ClientMsgHandler::OnCooperationState, this)}, + { MmiMessageId::COOPERATION_ADD_LISTENER, MsgCallbackBind2(&ClientMsgHandler::OnCooperationListener, this) }, + { MmiMessageId::COOPERATION_MESSAGE, MsgCallbackBind2(&ClientMsgHandler::OnCooperationMessage, this) }, + { MmiMessageId::COOPERATION_GET_STATE, MsgCallbackBind2(&ClientMsgHandler::OnCooperationState, this) }, #endif // OHOS_BUILD_ENABLE_COOPERATE }; for (auto &it : funs) { @@ -97,7 +89,8 @@ void ClientMsgHandler::InitProcessedCallback() int32_t tokenType = MultimodalInputConnMgr->GetTokenType(); if (tokenType == TokenType::TOKEN_HAP) { MMI_HILOGD("Current session is hap"); - dispatchCallback_ = std::bind(&ClientMsgHandler::OnDispatchEventProcessed, std::placeholders::_1); + dispatchCallback_ = std::bind(&ClientMsgHandler::OnDispatchEventProcessed, std::placeholders::_1, + std::placeholders::_2); } else if (tokenType == static_cast(TokenType::TOKEN_NATIVE)) { MMI_HILOGD("Current session is native"); } else { @@ -165,6 +158,9 @@ int32_t ClientMsgHandler::OnPointerEvent(const UDSClient& client, NetPacket& pkt pointerEvent->SetProcessedCallback(dispatchCallback_); BytraceAdapter::StartBytrace(pointerEvent, BytraceAdapter::TRACE_START, BytraceAdapter::POINT_DISPATCH_EVENT); InputMgrImpl.OnPointerEvent(pointerEvent); + if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_JOYSTICK) { + pointerEvent->MarkProcessed(); + } return RET_OK; } #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH @@ -186,88 +182,27 @@ int32_t ClientMsgHandler::OnSubscribeKeyEventCallback(const UDSClient &client, N MMI_HILOGE("Packet read fd failed"); return PACKET_READ_FAIL; } - MMI_HILOGD("Subscribe:%{public}d,Fd:%{public}d,KeyEvent:%{public}d," - "KeyCode:%{public}d,ActionTime:%{public}" PRId64 ",ActionStartTime:%{public}" PRId64 "," - "Action:%{public}d,KeyAction:%{public}d,EventType:%{public}d,Flag:%{public}u", + if (keyEvent->GetKeyCode() == KeyEvent::KEYCODE_POWER) { + MMI_HILOGI("Subscribe:%{public}d,Fd:%{public}d,KeyEvent:%{public}d," + "KeyCode:%{public}d,ActionTime:%{public}" PRId64 ",ActionStartTime:%{public}" PRId64 "," + "Action:%{public}d,KeyAction:%{public}d,EventType:%{public}d,Flag:%{public}u", + subscribeId, fd, keyEvent->GetId(), keyEvent->GetKeyCode(), keyEvent->GetActionTime(), + keyEvent->GetActionStartTime(), keyEvent->GetAction(), keyEvent->GetKeyAction(), + keyEvent->GetEventType(), keyEvent->GetFlag()); + } else { + MMI_HILOGD("Subscribe:%{public}d,Fd:%{public}d,KeyEvent:%{public}d," + "KeyCode:%{public}d,ActionTime:%{public}" PRId64 ",ActionStartTime:%{public}" PRId64 "," + "Action:%{public}d,KeyAction:%{public}d,EventType:%{public}d,Flag:%{public}u", subscribeId, fd, keyEvent->GetId(), keyEvent->GetKeyCode(), keyEvent->GetActionTime(), keyEvent->GetActionStartTime(), keyEvent->GetAction(), keyEvent->GetKeyAction(), keyEvent->GetEventType(), keyEvent->GetFlag()); + } + BytraceAdapter::StartBytrace(keyEvent, BytraceAdapter::TRACE_START, BytraceAdapter::KEY_SUBSCRIBE_EVENT); return KeyEventInputSubscribeMgr.OnSubscribeKeyEventCallback(keyEvent, subscribeId); } #endif // OHOS_BUILD_ENABLE_KEYBOARD -int32_t ClientMsgHandler::OnInputDeviceIds(const UDSClient& client, NetPacket& pkt) -{ - CALL_DEBUG_ENTER; - int32_t userData; - std::vector inputDeviceIds; - pkt >> userData >> inputDeviceIds; - if (inputDeviceIds.size() > MAX_INPUT_DEVICE) { - MMI_HILOGE("Device exceeds the max range"); - return RET_ERR; - } - if (pkt.ChkRWError()) { - MMI_HILOGE("Packet read cooperate msg failed"); - return RET_ERR; - } - InputDevImpl.OnInputDeviceIds(userData, inputDeviceIds); - return RET_OK; -} - -int32_t ClientMsgHandler::OnInputDevice(const UDSClient& client, NetPacket& pkt) -{ - CALL_DEBUG_ENTER; - int32_t userData; - pkt >> userData; - std::shared_ptr devData = InputDevImpl.DevDataUnmarshalling(pkt); - CHKPR(devData, RET_ERR); - if (pkt.ChkRWError()) { - MMI_HILOGE("Packet read cooperate msg failed"); - return RET_ERR; - } - InputDevImpl.OnInputDevice(userData, devData); - return RET_OK; -} - -int32_t ClientMsgHandler::OnSupportKeys(const UDSClient& client, NetPacket& pkt) -{ - CALL_DEBUG_ENTER; - int32_t userData; - size_t size; - pkt >> userData >> size; - if (size > MAX_SUPPORT_KEY) { - MMI_HILOGE("Keys exceeds the max range"); - return RET_ERR; - } - std::vector abilityRet; - bool ret; - for (size_t i = 0; i < size; ++i) { - pkt >> ret; - abilityRet.push_back(ret); - } - if (pkt.ChkRWError()) { - MMI_HILOGE("Packet read key Data failed"); - return RET_ERR; - } - InputDevImpl.OnSupportKeys(userData, abilityRet); - return RET_OK; -} - -int32_t ClientMsgHandler::OnInputKeyboardType(const UDSClient& client, NetPacket& pkt) -{ - CALL_DEBUG_ENTER; - int32_t userData; - int32_t KeyboardType; - pkt >> userData >> KeyboardType; - if (pkt.ChkRWError()) { - MMI_HILOGE("Packet read failed"); - return PACKET_WRITE_FAIL; - } - InputDevImpl.OnKeyboardType(userData, KeyboardType); - return RET_OK; -} - int32_t ClientMsgHandler::OnDevListener(const UDSClient& client, NetPacket& pkt) { CALL_DEBUG_ENTER; @@ -288,7 +223,8 @@ int32_t ClientMsgHandler::ReportKeyEvent(const UDSClient& client, NetPacket& pkt { CALL_DEBUG_ENTER; InputHandlerType handlerType; - pkt >> handlerType; + uint32_t deviceTags; + pkt >> handlerType >> deviceTags; if (pkt.ChkRWError()) { MMI_HILOGE("Packet read handler failed"); return RET_ERR; @@ -303,13 +239,13 @@ int32_t ClientMsgHandler::ReportKeyEvent(const UDSClient& client, NetPacket& pkt switch (handlerType) { case INTERCEPTOR: { #ifdef OHOS_BUILD_ENABLE_INTERCEPTOR - InputInterMgr->OnInputEvent(keyEvent); + InputInterMgr->OnInputEvent(keyEvent, deviceTags); #endif // OHOS_BUILD_ENABLE_INTERCEPTOR break; } case MONITOR: { #ifdef OHOS_BUILD_ENABLE_MONITOR - IMonitorMgr->OnInputEvent(keyEvent); + IMonitorMgr->OnInputEvent(keyEvent, deviceTags); #endif // OHOS_BUILD_ENABLE_MONITOR break; } @@ -328,7 +264,8 @@ int32_t ClientMsgHandler::ReportPointerEvent(const UDSClient& client, NetPacket& { CALL_DEBUG_ENTER; InputHandlerType handlerType; - pkt >> handlerType; + uint32_t deviceTags; + pkt >> handlerType >> deviceTags; if (pkt.ChkRWError()) { MMI_HILOGE("Packet read Pointer data failed"); return RET_ERR; @@ -344,13 +281,13 @@ int32_t ClientMsgHandler::ReportPointerEvent(const UDSClient& client, NetPacket& switch (handlerType) { case INTERCEPTOR: { #ifdef OHOS_BUILD_ENABLE_INTERCEPTOR - InputInterMgr->OnInputEvent(pointerEvent); + InputInterMgr->OnInputEvent(pointerEvent, deviceTags); #endif // OHOS_BUILD_ENABLE_INTERCEPTOR break; } case MONITOR: { #ifdef OHOS_BUILD_ENABLE_MONITOR - IMonitorMgr->OnInputEvent(pointerEvent); + IMonitorMgr->OnInputEvent(pointerEvent, deviceTags); #endif // OHOS_BUILD_ENABLE_MONITOR break; } @@ -363,21 +300,10 @@ int32_t ClientMsgHandler::ReportPointerEvent(const UDSClient& client, NetPacket& } #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH -void ClientMsgHandler::OnDispatchEventProcessed(int32_t eventId) +void ClientMsgHandler::OnDispatchEventProcessed(int32_t eventId, int64_t actionTime) { CALL_DEBUG_ENTER; - MMIClientPtr client = MMIEventHdl.GetMMIClient(); - CHKPV(client); - NetPacket pkt(MmiMessageId::MARK_PROCESS); - pkt << eventId << ANR_DISPATCH; - if (pkt.ChkRWError()) { - MMI_HILOGE("Packet write event failed"); - return; - } - if (!client->SendMessage(pkt)) { - MMI_HILOGE("Send message failed, errCode:%{public}d", MSG_SEND_FAIL); - return; - } + ANRHdl->SetLastProcessedEventId(ANR_DISPATCH, eventId, actionTime); } int32_t ClientMsgHandler::OnAnr(const UDSClient& client, NetPacket& pkt) @@ -395,7 +321,7 @@ int32_t ClientMsgHandler::OnAnr(const UDSClient& client, NetPacket& pkt) } #ifdef OHOS_BUILD_ENABLE_COOPERATE -int32_t ClientMsgHandler::OnCooperationListiner(const UDSClient& client, NetPacket& pkt) +int32_t ClientMsgHandler::OnCooperationListener(const UDSClient& client, NetPacket& pkt) { CALL_DEBUG_ENTER; int32_t userData; @@ -421,7 +347,7 @@ int32_t ClientMsgHandler::OnCooperationMessage(const UDSClient& client, NetPacke MMI_HILOGE("Packet read cooperate msg failed"); return RET_ERR; } - InputDevCooperateImpl.OnCooprationMessage(userData, deviceId, CooperationMessage(nType)); + InputDevCooperateImpl.OnCooperationMessage(userData, deviceId, CooperationMessage(nType)); return RET_OK; } diff --git a/frameworks/proxy/event_handler/src/input_device_cooperate_impl.cpp b/frameworks/proxy/event_handler/src/input_device_cooperate_impl.cpp index 04ca6c4466f2ff866b686dda8885387be5f4e7e4..caa7fcac175383d5bb6e1544c9feee15fcce3bd1 100755 --- a/frameworks/proxy/event_handler/src/input_device_cooperate_impl.cpp +++ b/frameworks/proxy/event_handler/src/input_device_cooperate_impl.cpp @@ -22,7 +22,7 @@ namespace OHOS { namespace MMI { namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "InputDeviceCooperateImpl"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "InputDeviceCooperateImpl" }; } // namespace InputDeviceCooperateImpl &InputDeviceCooperateImpl::GetInstance() @@ -118,7 +118,7 @@ int32_t InputDeviceCooperateImpl::StopDeviceCooperate(FuncCooperationMessage cal } int32_t InputDeviceCooperateImpl::GetInputDeviceCooperateState( - const std::string &deviceId, FuncCooperateionState callback) + const std::string &deviceId, FuncCooperationState callback) { CALL_DEBUG_ENTER; std::lock_guard guard(mtx_); @@ -132,7 +132,7 @@ int32_t InputDeviceCooperateImpl::GetInputDeviceCooperateState( return MultimodalInputConnMgr->GetInputDeviceCooperateState(userData_++, deviceId); } -void InputDeviceCooperateImpl::OnDevCooperateListener(const std::string deviceId, CooperationMessage msg) +void InputDeviceCooperateImpl::OnDevCooperateListener(const std::string &deviceId, const CooperationMessage &msg) { CALL_DEBUG_ENTER; std::lock_guard guard(mtx_); @@ -141,12 +141,12 @@ void InputDeviceCooperateImpl::OnDevCooperateListener(const std::string deviceId } } -void InputDeviceCooperateImpl::OnCooprationMessage(int32_t userData, const std::string deviceId, CooperationMessage msg) +void InputDeviceCooperateImpl::OnCooperationMessage(int32_t userData, const std::string &deviceId, const CooperationMessage &msg) { CALL_DEBUG_ENTER; CHK_PID_AND_TID(); std::lock_guard guard(mtx_); - auto event = GetCooprateMessageEvent(userData); + auto event = GetCooperateMessageEvent(userData); CHKPV(event); (*event)(deviceId, msg); } @@ -156,10 +156,10 @@ void InputDeviceCooperateImpl::OnCooperationState(int32_t userData, bool state) CALL_DEBUG_ENTER; CHK_PID_AND_TID(); std::lock_guard guard(mtx_); - auto event = GetCooprateStateEvent(userData); + auto event = GetCooperateStateEvent(userData); CHKPV(event); (*event)(state); - MMI_HILOGD("Cooperatinon state event callback userData:%{public}d state:(%{public}d)", userData, state); + MMI_HILOGD("Cooperation state event callback userData:%{public}d state:(%{public}d)", userData, state); } int32_t InputDeviceCooperateImpl::GetUserData() @@ -168,14 +168,14 @@ int32_t InputDeviceCooperateImpl::GetUserData() return userData_; } -const InputDeviceCooperateImpl::DevCooperationMsg *InputDeviceCooperateImpl::GetCooprateMessageEvent( +const InputDeviceCooperateImpl::DevCooperationMsg *InputDeviceCooperateImpl::GetCooperateMessageEvent( int32_t userData) const { auto iter = devCooperateEvent_.find(userData); return iter == devCooperateEvent_.end() ? nullptr : &iter->second.msg; } -const InputDeviceCooperateImpl::DevCooperateionState *InputDeviceCooperateImpl::GetCooprateStateEvent( +const InputDeviceCooperateImpl::DevCooperationState *InputDeviceCooperateImpl::GetCooperateStateEvent( int32_t userData) const { auto iter = devCooperateEvent_.find(userData); diff --git a/frameworks/proxy/event_handler/src/input_device_impl.cpp b/frameworks/proxy/event_handler/src/input_device_impl.cpp old mode 100755 new mode 100644 index d22fb0636d79dceeec3c4f77c6a492786444bccc..3beff89dee60f1cd0cd824e31c5d0d9b32d0d4b9 --- a/frameworks/proxy/event_handler/src/input_device_impl.cpp +++ b/frameworks/proxy/event_handler/src/input_device_impl.cpp @@ -15,6 +15,8 @@ #include "input_device_impl.h" +#include + #include "mmi_log.h" #include "multimodal_event_handler.h" #include "multimodal_input_connect_manager.h" @@ -24,7 +26,7 @@ namespace OHOS { namespace MMI { namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "InputDeviceImpl"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "InputDeviceImpl" }; } // namespace InputDeviceImpl& InputDeviceImpl::GetInstance() @@ -46,18 +48,25 @@ int32_t InputDeviceImpl::RegisterDevListener(const std::string &type, InputDevLi MMI_HILOGE("Find change failed"); return RET_ERR; } - for (const auto &item : iter->second) { - if (item == listener) { - MMI_HILOGW("The listener already exists"); - return RET_ERR; - } - } - auto monitor = listener; - iter->second.push_back(monitor); + auto &listeners = iter->second; + if (!isListeningProcess_) { MMI_HILOGI("Start monitoring"); isListeningProcess_ = true; - return MultimodalInputConnMgr->RegisterDevListener(); + int32_t ret = MultimodalInputConnMgr->RegisterDevListener(); + if (ret != RET_OK) { + MMI_HILOGE("Failed to register"); + return ret; + } + } + if (std::all_of(listeners.cbegin(), listeners.cend(), + [listener](InputDevListenerPtr tListener) { + return (tListener != listener); + })) { + MMI_HILOGI("Add device listener"); + listeners.push_back(listener); + } else { + MMI_HILOGW("The listener already exists"); } return RET_OK; } @@ -112,238 +121,65 @@ void InputDeviceImpl::OnDevListener(int32_t deviceId, const std::string &type) } } -int32_t InputDeviceImpl::GetInputDeviceIdsAsync(FunInputDevIds callback) +int32_t InputDeviceImpl::GetInputDeviceIds(FunInputDevIds callback) { CALL_DEBUG_ENTER; - std::lock_guard guard(mtx_); - InputDeviceData data; - data.ids = callback; - if (userData_ == INT32_MAX) { - MMI_HILOGE("userData exceeds the maximum"); + CHKPR(callback, RET_ERR); + std::vector ids; + int32_t ret = MultimodalInputConnMgr->GetDeviceIds(ids); + if (ret != RET_OK) { + MMI_HILOGE("GetInputDeviceIds failed"); return RET_ERR; } - inputDevices_[userData_] = data; - return MultimodalInputConnMgr->GetDeviceIds(userData_++); + callback(ids); + return ret; } -int32_t InputDeviceImpl::GetInputDeviceAsync(int32_t deviceId, FunInputDevInfo callback) +int32_t InputDeviceImpl::GetInputDevice(int32_t deviceId, FunInputDevInfo callback) { CALL_DEBUG_ENTER; - std::lock_guard guard(mtx_); - InputDeviceData data; - data.inputDevice = callback; - if (userData_ == INT32_MAX) { - MMI_HILOGE("UserData exceeds the maximum"); + CHKPR(callback, RET_ERR); + std::shared_ptr inputDevice = std::make_shared(); + int32_t ret = MultimodalInputConnMgr->GetDevice(deviceId, inputDevice); + if (ret != RET_OK) { + MMI_HILOGE("GetDevice failed"); return RET_ERR; } - inputDevices_[userData_] = data; - return MultimodalInputConnMgr->GetDevice(userData_++, deviceId); + callback(inputDevice); + return RET_OK; } int32_t InputDeviceImpl::SupportKeys(int32_t deviceId, std::vector keyCodes, FunInputDevKeys callback) { CALL_DEBUG_ENTER; - std::lock_guard guard(mtx_); - if (keyCodes.size() > MAX_SUPPORT_KEY) { - MMI_HILOGE("Keys exceeds the max range"); - return RET_ERR; - } - InputDeviceData data; - data.keys = callback; - if (userData_ == INT32_MAX) { - MMI_HILOGE("UserData exceeds the maximum"); + CHKPR(callback, RET_ERR); + std::vector keystroke; + int32_t ret = MultimodalInputConnMgr->SupportKeys(deviceId, keyCodes, keystroke); + if (ret != RET_OK) { + MMI_HILOGE("SupportKeys failed"); return RET_ERR; } - inputDevices_[userData_] = data; - return MultimodalInputConnMgr->SupportKeys(userData_++, deviceId, keyCodes); + callback(keystroke); + return RET_OK; } int32_t InputDeviceImpl::GetKeyboardType(int32_t deviceId, FunKeyboardTypes callback) { CALL_DEBUG_ENTER; - std::lock_guard guard(mtx_); - InputDeviceData data; - data.kbTypes = callback; - if (userData_ == INT32_MAX) { - MMI_HILOGE("UserData exceeds the maximum"); + CHKPR(callback, RET_ERR); + int32_t keyboardType = 0; + int32_t ret = MultimodalInputConnMgr->GetKeyboardType(deviceId, keyboardType); + if (ret != RET_OK) { + MMI_HILOGE("GetKeyboardType failed"); return RET_ERR; } - inputDevices_[userData_] = data; - return MultimodalInputConnMgr->GetKeyboardType(userData_++, deviceId); -} - -void InputDeviceImpl::OnInputDevice(int32_t userData, std::shared_ptr devData) -{ - CALL_DEBUG_ENTER; - CHK_PID_AND_TID(); - std::lock_guard guard(mtx_); - auto iter = inputDevices_.find(userData); - if (iter == inputDevices_.end()) { - MMI_HILOGI("Find userData failed"); - return; - } - auto devInfo = GetDeviceInfo(userData); - CHKPV(devInfo); - CHKPV(devData); - (*devInfo)(devData); - MMI_HILOGD("Report device info, userData:%{public}d name:%{public}s type:%{public}d", - userData, devData->GetName().c_str(), devData->GetType()); -} - -void InputDeviceImpl::OnInputDeviceIds(int32_t userData, std::vector &ids) -{ - CHK_PID_AND_TID(); - std::lock_guard guard(mtx_); - auto iter = inputDevices_.find(userData); - if (iter == inputDevices_.end()) { - MMI_HILOGI("Find userData failed"); - return; - } - auto devIds = GetDeviceIds(userData); - CHKPV(devIds); - (*devIds)(ids); - MMI_HILOGD("Report all device, userData:%{public}d device:(%{public}s)", - userData, IdsListToString(ids).c_str()); -} - -void InputDeviceImpl::OnSupportKeys(int32_t userData, std::vector &keystrokeAbility) -{ - CHK_PID_AND_TID(); - std::lock_guard guard(mtx_); - auto iter = inputDevices_.find(userData); - if (iter == inputDevices_.end()) { - MMI_HILOGI("Find userData failed"); - return; - } - auto devKeys = GetDeviceKeys(userData); - CHKPV(devKeys); - (*devKeys)(keystrokeAbility); -} - -void InputDeviceImpl::OnKeyboardType(int32_t userData, int32_t keyboardType) -{ - CHK_PID_AND_TID(); - std::lock_guard guard(mtx_); - if (auto iter = inputDevices_.find(userData); iter == inputDevices_.end()) { - MMI_HILOGI("Find userData failed"); - return; - } - auto devKbTypes = GetKeyboardTypes(userData); - CHKPV(devKbTypes); - (*devKbTypes)(keyboardType); - MMI_HILOGD("Keyboard type event userData:%{public}d keyboardType:%{public}d", - userData, keyboardType); -} - -const InputDeviceImpl::FunInputDevInfo* InputDeviceImpl::GetDeviceInfo(int32_t userData) const -{ - auto iter = inputDevices_.find(userData); - if (iter == inputDevices_.end()) { - return nullptr; - } - return &iter->second.inputDevice; -} - -const InputDeviceImpl::FunInputDevIds* InputDeviceImpl::GetDeviceIds(int32_t userData) const -{ - auto iter = inputDevices_.find(userData); - if (iter == inputDevices_.end()) { - return nullptr; - } - return &iter->second.ids; -} - -const InputDeviceImpl::FunInputDevKeys* InputDeviceImpl::GetDeviceKeys(int32_t userData) const -{ - auto iter = inputDevices_.find(userData); - if (iter == inputDevices_.end()) { - return nullptr; - } - return &iter->second.keys; -} - -const InputDeviceImpl::FunKeyboardTypes* InputDeviceImpl::GetKeyboardTypes(int32_t userData) const -{ - auto iter = inputDevices_.find(userData); - return iter == inputDevices_.end()? nullptr : &iter->second.kbTypes; + callback(keyboardType); + return RET_OK; } int32_t InputDeviceImpl::GetUserData() { return userData_; } - -std::shared_ptr InputDeviceImpl::DevDataUnmarshalling(NetPacket &pkt) -{ - auto devData = std::make_shared(); - CHKPP(devData); - int32_t deviceId; - pkt >> deviceId; - devData->SetId(deviceId); - - std::string name; - pkt >> name; - devData->SetName(name); - - int32_t deviceType; - pkt >> deviceType; - devData->SetType(deviceType); - - int32_t bus; - pkt >> bus; - devData->SetBus(bus); - - int32_t product; - pkt >> product; - devData->SetProduct(product); - - int32_t vendor; - pkt >> vendor; - devData->SetVendor(vendor); - - int32_t version; - pkt >> version; - devData->SetVersion(version); - - std::string phys; - pkt >> phys; - devData->SetPhys(phys); - - std::string uniq; - pkt >> uniq; - devData->SetUniq(uniq); - - size_t size; - pkt >> size; - std::vector axisInfo; - for (size_t i = 0; i < size; ++i) { - InputDevice::AxisInfo axis; - int32_t type; - pkt >> type; - axis.SetAxisType(type); - - int32_t min; - pkt >> min; - axis.SetMinimum(min); - - int32_t max; - pkt >> max; - axis.SetMaximum(max); - - int32_t fuzz; - pkt >> fuzz; - axis.SetFuzz(fuzz); - - int32_t flat; - pkt >> flat; - axis.SetFlat(flat); - - int32_t resolution; - pkt >> resolution; - axis.SetResolution(resolution); - devData->AddAxisInfo(axis); - } - return devData; -} } // namespace MMI } // namespace OHOS diff --git a/frameworks/proxy/event_handler/src/input_handler_manager.cpp b/frameworks/proxy/event_handler/src/input_handler_manager.cpp index 40ba6f77106985e25fd67e48e0044031287286d7..467aabea1d4fe861b746cbcbe17931ef24ba0270 100644 --- a/frameworks/proxy/event_handler/src/input_handler_manager.cpp +++ b/frameworks/proxy/event_handler/src/input_handler_manager.cpp @@ -19,6 +19,7 @@ #include "bytrace_adapter.h" #include "input_handler_type.h" +#include "anr_handler.h" #include "multimodal_event_handler.h" #include "multimodal_input_connect_manager.h" #include "mmi_log.h" @@ -34,11 +35,12 @@ constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "Input InputHandlerManager::InputHandlerManager() { - monitorCallback_ = std::bind(&InputHandlerManager::OnDispatchEventProcessed, this, std::placeholders::_1); + monitorCallback_ = std::bind(&InputHandlerManager::OnDispatchEventProcessed, this, std::placeholders::_1, + std::placeholders::_2); } -int32_t InputHandlerManager::AddHandler(InputHandlerType handlerType, - std::shared_ptr consumer, HandleEventType eventType) +int32_t InputHandlerManager::AddHandler(InputHandlerType handlerType, std::shared_ptr consumer, + HandleEventType eventType, int32_t priority, uint32_t deviceTags) { CALL_INFO_TRACE; CHKPR(consumer, INVALID_HANDLER_ID); @@ -59,11 +61,11 @@ int32_t InputHandlerManager::AddHandler(InputHandlerType handlerType, } const HandleEventType currentType = GetEventType(); MMI_HILOGD("Register new handler:%{public}d", handlerId); - if (RET_OK == AddLocal(handlerId, handlerType, eventType, consumer)) { + if (RET_OK == AddLocal(handlerId, handlerType, eventType, priority, deviceTags, consumer)) { MMI_HILOGD("New handler successfully registered, report to server"); const HandleEventType newType = GetEventType(); if (currentType != newType) { - int32_t ret = AddToServer(handlerType, newType); + int32_t ret = AddToServer(handlerType, newType, priority, deviceTags); if (ret != RET_OK) { MMI_HILOGD("Handler:%{public}d permissions failed, remove the monitor", handlerId); RemoveLocal(handlerId, handlerType); @@ -85,19 +87,23 @@ void InputHandlerManager::RemoveHandler(int32_t handlerId, InputHandlerType hand if (RET_OK == RemoveLocal(handlerId, handlerType)) { MMI_HILOGD("Handler:%{public}d unregistered, report to server", handlerId); const HandleEventType newType = GetEventType(); + const int32_t newLevel = GetPriority(); + const uint64_t newTags = GetDeviceTags(); if (currentType != newType) { - RemoveFromServer(handlerType, newType); + RemoveFromServer(handlerType, newType, newLevel, newTags); } } } -int32_t InputHandlerManager::AddLocal(int32_t handlerId, InputHandlerType handlerType, - HandleEventType eventType, std::shared_ptr monitor) +int32_t InputHandlerManager::AddLocal(int32_t handlerId, InputHandlerType handlerType, HandleEventType eventType, + int32_t priority, uint32_t deviceTags, std::shared_ptr monitor) { InputHandlerManager::Handler handler { .handlerId_ = handlerId, .handlerType_ = handlerType, .eventType_ = eventType, + .priority_ = priority, + .deviceTags_ = deviceTags, .consumer_ = monitor, }; auto ret = inputHandlers_.emplace(handler.handlerId_, handler); @@ -105,12 +111,26 @@ int32_t InputHandlerManager::AddLocal(int32_t handlerId, InputHandlerType handle MMI_HILOGE("Duplicate handler:%{public}d", handler.handlerId_); return RET_ERR; } + if (handlerType == InputHandlerType::INTERCEPTOR) { + auto iterIndex = interHandlers_.begin(); + for (; iterIndex != interHandlers_.end(); ++iterIndex) { + if (handler.priority_ < iterIndex->priority_) { + break; + } + } + auto iter = interHandlers_.emplace(iterIndex, handler); + if (iter == interHandlers_.end()) { + MMI_HILOGE("Add new handler failed"); + return RET_ERR; + } + } return RET_OK; } -int32_t InputHandlerManager::AddToServer(InputHandlerType handlerType, HandleEventType eventType) +int32_t InputHandlerManager::AddToServer(InputHandlerType handlerType, HandleEventType eventType, + int32_t priority, uint32_t deviceTags) { - int32_t ret = MultimodalInputConnMgr->AddInputHandler(handlerType, eventType); + int32_t ret = MultimodalInputConnMgr->AddInputHandler(handlerType, eventType, priority, deviceTags); if (ret != RET_OK) { MMI_HILOGE("Send to server failed, ret:%{public}d", ret); } @@ -130,12 +150,22 @@ int32_t InputHandlerManager::RemoveLocal(int32_t handlerId, InputHandlerType han return RET_ERR; } inputHandlers_.erase(tItr); + + if (handlerType == InputHandlerType::INTERCEPTOR) { + for (auto it = interHandlers_.begin(); it != interHandlers_.end(); ++it) { + if (handlerId == it->handlerId_) { + interHandlers_.erase(it); + break; + } + } + } return RET_OK; } -void InputHandlerManager::RemoveFromServer(InputHandlerType handlerType, HandleEventType eventType) +void InputHandlerManager::RemoveFromServer(InputHandlerType handlerType, HandleEventType eventType, + int32_t priority, uint32_t deviceTags) { - int32_t ret = MultimodalInputConnMgr->RemoveInputHandler(handlerType, eventType); + int32_t ret = MultimodalInputConnMgr->RemoveInputHandler(handlerType, eventType, priority, deviceTags); if (ret != 0) { MMI_HILOGE("Send to server failed, ret:%{public}d", ret); } @@ -160,66 +190,105 @@ std::shared_ptr InputHandlerManager::FindHandler(int32_t ha } #ifdef OHOS_BUILD_ENABLE_KEYBOARD -void InputHandlerManager::OnInputEvent(std::shared_ptr keyEvent) +void InputHandlerManager::OnInputEvent(std::shared_ptr keyEvent, uint32_t deviceTags) { CHK_PID_AND_TID(); CHKPV(keyEvent); std::lock_guard guard(mtxHandlers_); BytraceAdapter::StartBytrace(keyEvent, BytraceAdapter::TRACE_STOP, BytraceAdapter::KEY_INTERCEPT_EVENT); - for (const auto &handler : inputHandlers_) { - if ((handler.second.eventType_ & HANDLE_EVENT_TYPE_KEY) != HANDLE_EVENT_TYPE_KEY) { - continue; + if (!interHandlers_.empty()) { + for (const auto &item : interHandlers_) { + if ((item.deviceTags_ != deviceTags) && + ((item.eventType_ & HANDLE_EVENT_TYPE_KEY) != HANDLE_EVENT_TYPE_KEY)) { + continue; + } + int32_t handlerId = item.handlerId_; + auto consumer = item.consumer_; + CHKPV(consumer); + consumer->OnInputEvent(keyEvent); + MMI_HILOGD("Key event id:%{public}d keyCode:%{public}d", handlerId, keyEvent->GetKeyCode()); + break; + } + } else { + for (const auto &item : inputHandlers_) { + if ((item.second.eventType_ & HANDLE_EVENT_TYPE_KEY) != HANDLE_EVENT_TYPE_KEY) { + continue; + } + int32_t handlerId = item.first; + auto consumer = item.second.consumer_; + CHKPV(consumer); + consumer->OnInputEvent(keyEvent); + MMI_HILOGD("Key event id:%{public}d keyCode:%{public}d", handlerId, keyEvent->GetKeyCode()); } - int32_t handlerId = handler.first; - auto consumer = handler.second.consumer_; - CHKPV(consumer); - consumer->OnInputEvent(keyEvent); - MMI_HILOGD("Key event id:%{public}d keyCode:%{public}d", handlerId, keyEvent->GetKeyCode()); } } #endif // OHOS_BUILD_ENABLE_KEYBOARD #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) -void InputHandlerManager::GetConsumerInfos(std::shared_ptr pointerEvent, +void InputHandlerManager::GetConsumerInfos(std::shared_ptr pointerEvent, uint32_t deviceTags, std::map> &consumerInfos) { std::lock_guard guard(mtxHandlers_); int32_t consumerCount = 0; - for (const auto &iter : inputHandlers_) { - if ((iter.second.eventType_ & HANDLE_EVENT_TYPE_POINTER) != HANDLE_EVENT_TYPE_POINTER) { - continue; + if (!interHandlers_.empty()) { + for (const auto &item : interHandlers_) { + if ((item.deviceTags_ != deviceTags) && + ((item.eventType_ & HANDLE_EVENT_TYPE_POINTER) != HANDLE_EVENT_TYPE_POINTER)) { + continue; + } + int32_t handlerId = item.handlerId_; + auto consumer = item.consumer_; + CHKPV(consumer); + auto ret = consumerInfos.emplace(handlerId, consumer); + if (!ret.second) { + MMI_HILOGI("Duplicate handler:%{public}d", handlerId); + continue; + } + consumerCount++; + break; } - int32_t handlerId = iter.first; - auto consumer = iter.second.consumer_; - CHKPV(consumer); - auto ret = consumerInfos.emplace(handlerId, consumer); - if (!ret.second) { - MMI_HILOGI("Duplicate handler:%{public}d", handlerId); - continue; + } else { + for (const auto &item : inputHandlers_) { + if ((item.second.eventType_ & HANDLE_EVENT_TYPE_POINTER) != HANDLE_EVENT_TYPE_POINTER) { + continue; + } + int32_t handlerId = item.first; + auto consumer = item.second.consumer_; + CHKPV(consumer); + auto ret = consumerInfos.emplace(handlerId, consumer); + if (!ret.second) { + MMI_HILOGI("Duplicate handler:%{public}d", handlerId); + continue; + } + consumerCount++; } - consumerCount++; } + if (consumerCount == 0) { MMI_HILOGE("All task post failed"); return; } int32_t tokenType = MultimodalInputConnMgr->GetTokenType(); - if (tokenType == TokenType::TOKEN_HAP && - pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHSCREEN) { + if (tokenType != TokenType::TOKEN_HAP) { + return; + } + if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_MOUSE) { + mouseEventIds_.emplace(pointerEvent->GetId()); + } + if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHSCREEN) { processedEvents_.emplace(pointerEvent->GetId(), consumerCount); } } -void InputHandlerManager::OnInputEvent(std::shared_ptr pointerEvent) +void InputHandlerManager::OnInputEvent(std::shared_ptr pointerEvent, uint32_t deviceTags) { CHK_PID_AND_TID(); CHKPV(pointerEvent); BytraceAdapter::StartBytrace(pointerEvent, BytraceAdapter::TRACE_STOP, BytraceAdapter::POINT_INTERCEPT_EVENT); std::map> consumerInfos; - GetConsumerInfos(pointerEvent, consumerInfos); + GetConsumerInfos(pointerEvent, deviceTags, consumerInfos); for (const auto &iter : consumerInfos) { auto tempEvent = std::make_shared(*pointerEvent); - CHKPV(tempEvent); tempEvent->SetProcessedCallback(monitorCallback_); CHKPV(iter.second); auto consumer = iter.second; @@ -234,8 +303,10 @@ void InputHandlerManager::OnConnected() { CALL_DEBUG_ENTER; HandleEventType eventType = GetEventType(); + int32_t priority = GetPriority(); + uint32_t deviceTags = GetDeviceTags(); if (eventType != HANDLE_EVENT_TYPE_NONE) { - AddToServer(GetHandlerType(), eventType); + AddToServer(GetHandlerType(), eventType, priority, deviceTags); } } #endif // OHOS_BUILD_ENABLE_INTERCEPTOR || OHOS_BUILD_ENABLE_MONITOR @@ -254,18 +325,52 @@ HandleEventType InputHandlerManager::GetEventType() const return HANDLE_EVENT_TYPE_NONE; } HandleEventType eventType { HANDLE_EVENT_TYPE_NONE }; - for (const auto &inputHandler : inputHandlers_) { - eventType |= inputHandler.second.eventType_; + if (!interHandlers_.empty()) { + eventType |= interHandlers_.front().eventType_; + } else { + for (const auto &inputHandler : inputHandlers_) { + eventType |= inputHandler.second.eventType_; + } } return eventType; } -void InputHandlerManager::OnDispatchEventProcessed(int32_t eventId) +int32_t InputHandlerManager::GetPriority() const +{ + if (inputHandlers_.empty()) { + MMI_HILOGD("InputHandlers is empty"); + return DEFUALT_INTERCEPTOR_PRIORITY; + } + int32_t priority { DEFUALT_INTERCEPTOR_PRIORITY }; + if (!interHandlers_.empty()) { + priority = interHandlers_.front().priority_; + } + return priority; +} + +uint32_t InputHandlerManager::GetDeviceTags() const +{ + if (inputHandlers_.empty()) { + MMI_HILOGD("InputHandlers is empty"); + return DEFUALT_INTERCEPTOR_PRIORITY; + } + uint32_t deviceTags { CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX) }; + if (!interHandlers_.empty()) { + deviceTags = interHandlers_.front().deviceTags_; + } + return deviceTags; +} + +void InputHandlerManager::OnDispatchEventProcessed(int32_t eventId, int64_t actionTime) { - CALL_DEBUG_ENTER; std::lock_guard guard(mtxHandlers_); + CALL_DEBUG_ENTER; MMIClientPtr client = MMIEventHdl.GetMMIClient(); CHKPV(client); + if (mouseEventIds_.find(eventId) != mouseEventIds_.end()) { + mouseEventIds_.erase(eventId); + return; + } auto iter = processedEvents_.find(eventId); if (iter == processedEvents_.end()) { MMI_HILOGE("EventId not in processedEvents_"); @@ -278,16 +383,7 @@ void InputHandlerManager::OnDispatchEventProcessed(int32_t eventId) processedEvents_.emplace(eventId, count); return; } - NetPacket pkt(MmiMessageId::MARK_PROCESS); - pkt << eventId << ANR_MONITOR; - if (pkt.ChkRWError()) { - MMI_HILOGE("Packet write event failed"); - return; - } - if (!client->SendMessage(pkt)) { - MMI_HILOGE("Send message failed, errCode:%{public}d", MSG_SEND_FAIL); - return; - } + ANRHdl->SetLastProcessedEventId(ANR_MONITOR, eventId, actionTime); } } // namespace MMI } // namespace OHOS diff --git a/frameworks/proxy/event_handler/src/input_interceptor_manager.cpp b/frameworks/proxy/event_handler/src/input_interceptor_manager.cpp index da44746cd2e8ca213aac95f6babf4060579bb3f2..2d2965b02f0a65bcd8bc8192b11a005f749aac9c 100644 --- a/frameworks/proxy/event_handler/src/input_interceptor_manager.cpp +++ b/frameworks/proxy/event_handler/src/input_interceptor_manager.cpp @@ -37,6 +37,16 @@ int32_t InputInterceptorManager::AddInterceptor(std::shared_ptr interceptor, + HandleEventType eventType, int32_t priority, uint32_t deviceTags) +{ + if (interceptor == nullptr) { + MMI_HILOGE("No interceptor was specified."); + return INVALID_HANDLER_ID; + } + return AddHandler(InputHandlerType::INTERCEPTOR, interceptor, eventType, priority, deviceTags); +} + void InputInterceptorManager::RemoveInterceptor(int32_t interceptorId) { RemoveHandler(interceptorId, InputHandlerType::INTERCEPTOR); diff --git a/frameworks/proxy/event_handler/src/input_manager_impl.cpp b/frameworks/proxy/event_handler/src/input_manager_impl.cpp old mode 100755 new mode 100644 index e68a025613f4575d98ebc6321683e9e7a6d7437d..ab03247cd0392c7e468cd61e8305f9b83e6a2b71 --- a/frameworks/proxy/event_handler/src/input_manager_impl.cpp +++ b/frameworks/proxy/event_handler/src/input_manager_impl.cpp @@ -31,6 +31,7 @@ namespace OHOS { namespace MMI { namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "InputManagerImpl" }; +constexpr size_t MAX_FILTER_NUM = 4; } // namespace struct MonitorEventConsumer : public IInputEventConsumer { @@ -70,6 +71,36 @@ private: InputManagerImpl::InputManagerImpl() {} InputManagerImpl::~InputManagerImpl() {} + +int32_t InputManagerImpl::GetDisplayBindInfo(DisplayBindInfos &infos) +{ + CALL_DEBUG_ENTER; + std::lock_guard guard(mtx_); + int32_t ret = MultimodalInputConnMgr->GetDisplayBindInfo(infos); + if (ret != RET_OK) { + MMI_HILOGE("GetDisplayBindInfo failed, ret:%{public}d", ret); + return RET_ERR; + } + return RET_OK; +} + +int32_t InputManagerImpl::SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg) +{ + std::lock_guard guard(mtx_); + int32_t ret = MultimodalInputConnMgr->SetDisplayBind(deviceId, displayId, msg); + if (ret != RET_OK) { + MMI_HILOGE("SetDisplayBind failed, ret:%{public}d", ret); + return RET_ERR; + } + return RET_OK; +} + +int32_t InputManagerImpl::GetWindowPid(int32_t windowId) +{ + std::lock_guard guard(mtx_); + return MultimodalInputConnMgr->GetWindowPid(windowId); +} + void InputManagerImpl::UpdateDisplayInfo(const DisplayGroupInfo &displayGroupInfo) { CALL_DEBUG_ENTER; @@ -97,33 +128,66 @@ void InputManagerImpl::UpdateDisplayInfo(const DisplayGroupInfo &displayGroupInf PrintDisplayInfo(); } -int32_t InputManagerImpl::AddInputEventFilter(std::function)> filter) +int32_t InputManagerImpl::AddInputEventFilter(std::shared_ptr filter, int32_t priority, + uint32_t deviceTags) { CALL_INFO_TRACE; -#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) std::lock_guard guard(mtx_); - bool hasSendToMmiServer = true; - if (eventFilterService_ == nullptr) { - hasSendToMmiServer = false; - eventFilterService_ = new (std::nothrow) EventFilterService(); - CHKPR(eventFilterService_, RET_ERR); + CHKPR(filter, RET_ERR); + if (eventFilterServices_.size() >= MAX_FILTER_NUM) { + MMI_HILOGE("Too many filters, size:%{public}zu", eventFilterServices_.size()); + return RET_ERR; } + sptr service = new (std::nothrow) EventFilterService(filter); + CHKPR(service, RET_ERR); + const int32_t filterId = EventFilterService::GetNextId(); + int32_t ret = MultimodalInputConnMgr->AddInputEventFilter(service, filterId, priority, deviceTags); + if (ret != RET_OK) { + MMI_HILOGE("AddInputEventFilter has send to server failed, priority:%{public}d, ret:%{public}d", priority, ret); + service = nullptr; + return RET_ERR; + } + auto it = eventFilterServices_.emplace(filterId, std::make_tuple(service, priority, deviceTags)); + if (!it.second) { + MMI_HILOGW("Filter id duplicate"); + } + return filterId; +} - eventFilterService_->SetPointerEventPtr(filter); - if (!hasSendToMmiServer) { - int32_t ret = MultimodalInputConnMgr->AddInputEventFilter(eventFilterService_); - if (ret != RET_OK) { - MMI_HILOGE("AddInputEventFilter has send to server failed, ret:%{public}d", ret); - eventFilterService_ = nullptr; - return RET_ERR; - } +int32_t InputManagerImpl::RemoveInputEventFilter(int32_t filterId) +{ + CALL_INFO_TRACE; + std::lock_guard guard(mtx_); + if (eventFilterServices_.empty()) { + MMI_HILOGE("Filters is empty, size:%{public}zu", eventFilterServices_.size()); return RET_OK; } + std::map, int32_t, uint32_t>>::iterator it; + if (filterId != -1) { + it = eventFilterServices_.find(filterId); + if (it == eventFilterServices_.end()) { + MMI_HILOGE("Filter not found"); + return RET_OK; + } + } + int32_t ret = MultimodalInputConnMgr->RemoveInputEventFilter(filterId); + if (ret != RET_OK) { + MMI_HILOGE("Remove filter failed, filter id:%{public}d, ret:%{public}d", filterId, ret); + return RET_ERR; + } + if (filterId != -1) { + eventFilterServices_.erase(it); + } else { + eventFilterServices_.clear(); + } + MMI_HILOGI("Filter remove success"); return RET_OK; -#else - MMI_HILOGW("Pointer and touchscreen device does not support"); - return ERROR_UNSUPPORT; -#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH +} + +EventHandlerPtr InputManagerImpl::GetEventHandler() const +{ + CHKPP(eventHandler_); + return eventHandler_; } void InputManagerImpl::SetWindowInputEventConsumer(std::shared_ptr inputEventConsumer, @@ -288,7 +352,7 @@ int32_t InputManagerImpl::PackDisplayInfo(NetPacket &pkt) pkt << num; for (const auto &item : displayGroupInfo_.displaysInfo) { pkt << item.id << item.x << item.y << item.width - << item.height << item.name << item.uniq << item.direction; + << item.height << item.dpi << item.name << item.uniq << item.direction; } if (pkt.ChkRWError()) { MMI_HILOGE("Packet write display data failed"); @@ -299,11 +363,11 @@ int32_t InputManagerImpl::PackDisplayInfo(NetPacket &pkt) void InputManagerImpl::PrintDisplayInfo() { - MMI_HILOGI("logicalInfo,width:%{public}d,height:%{public}d,focusWindowId:%{public}d", + MMI_HILOGD("logicalInfo,width:%{public}d,height:%{public}d,focusWindowId:%{public}d", displayGroupInfo_.width, displayGroupInfo_.height, displayGroupInfo_.focusWindowId); - MMI_HILOGI("windowsInfos,num:%{public}zu", displayGroupInfo_.windowsInfo.size()); + MMI_HILOGD("windowsInfos,num:%{public}zu", displayGroupInfo_.windowsInfo.size()); for (const auto &item : displayGroupInfo_.windowsInfo) { - MMI_HILOGI("windowsInfos,id:%{public}d,pid:%{public}d,uid:%{public}d," + MMI_HILOGD("windowsInfos,id:%{public}d,pid:%{public}d,uid:%{public}d," "area.x:%{public}d,area.y:%{public}d,area.width:%{public}d,area.height:%{public}d," "defaultHotAreas.size:%{public}zu,pointerHotAreas.size:%{public}zu," "agentWindowId:%{public}d,flags:%{public}d", @@ -311,21 +375,21 @@ void InputManagerImpl::PrintDisplayInfo() item.area.height, item.defaultHotAreas.size(), item.pointerHotAreas.size(), item.agentWindowId, item.flags); for (const auto &win : item.defaultHotAreas) { - MMI_HILOGI("defaultHotAreas:x:%{public}d,y:%{public}d,width:%{public}d,height:%{public}d", + MMI_HILOGD("defaultHotAreas:x:%{public}d,y:%{public}d,width:%{public}d,height:%{public}d", win.x, win.y, win.width, win.height); } for (const auto &pointer : item.pointerHotAreas) { - MMI_HILOGI("pointerHotAreas:x:%{public}d,y:%{public}d,width:%{public}d,height:%{public}d", + MMI_HILOGD("pointerHotAreas:x:%{public}d,y:%{public}d,width:%{public}d,height:%{public}d", pointer.x, pointer.y, pointer.width, pointer.height); } } - MMI_HILOGI("displayInfos,num:%{public}zu", displayGroupInfo_.displaysInfo.size()); + MMI_HILOGD("displayInfos,num:%{public}zu", displayGroupInfo_.displaysInfo.size()); for (const auto &item : displayGroupInfo_.displaysInfo) { - MMI_HILOGI("displayInfos,id:%{public}d,x:%{public}d,y:%{public}d," - "width:%{public}d,height:%{public}d,name:%{public}s," + MMI_HILOGD("displayInfos,id:%{public}d,x:%{public}d,y:%{public}d," + "width:%{public}d,height:%{public}d,dpi:%{public}d,name:%{public}s," "uniq:%{public}s,direction:%{public}d", - item.id, item.x, item.y, item.width, item.height, item.name.c_str(), + item.id, item.x, item.y, item.width, item.height, item.dpi, item.name.c_str(), item.uniq.c_str(), item.direction); } } @@ -336,7 +400,6 @@ int32_t InputManagerImpl::AddMonitor(std::function(monitor); - CHKPR(consumer, INVALID_HANDLER_ID); return AddMonitor(consumer); #else MMI_HILOGW("Keyboard device or monitor function does not support"); @@ -350,7 +413,6 @@ int32_t InputManagerImpl::AddMonitor(std::function(monitor); - CHKPR(consumer, INVALID_HANDLER_ID); return AddMonitor(consumer); #else MMI_HILOGW("Pointer/touchscreen device or monitor function does not support"); @@ -392,7 +454,7 @@ void InputManagerImpl::RemoveMonitor(int32_t monitorId) void InputManagerImpl::MarkConsumed(int32_t monitorId, int32_t eventId) { - CALL_INFO_TRACE; + CALL_DEBUG_ENTER; #ifdef OHOS_BUILD_ENABLE_MONITOR std::lock_guard guard(mtx_); if (!MMIEventHdl.InitClient()) { @@ -417,7 +479,8 @@ void InputManagerImpl::MoveMouse(int32_t offsetX, int32_t offsetY) #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING } -int32_t InputManagerImpl::AddInterceptor(std::shared_ptr interceptor) +int32_t InputManagerImpl::AddInterceptor(std::shared_ptr interceptor, + int32_t priority, uint32_t deviceTags) { CALL_INFO_TRACE; #ifdef OHOS_BUILD_ENABLE_INTERCEPTOR @@ -427,26 +490,26 @@ int32_t InputManagerImpl::AddInterceptor(std::shared_ptr in MMI_HILOGE("Client init failed"); return RET_ERR; } - return InputInterMgr->AddInterceptor(interceptor, HANDLE_EVENT_TYPE_ALL); + return InputInterMgr->AddInterceptor(interceptor, HANDLE_EVENT_TYPE_ALL, priority, deviceTags); #else MMI_HILOGW("Interceptor function does not support"); return ERROR_UNSUPPORT; #endif // OHOS_BUILD_ENABLE_INTERCEPTOR } -int32_t InputManagerImpl::AddInterceptor(std::function)> interceptor) +int32_t InputManagerImpl::AddInterceptor(std::function)> interceptor, + int32_t priority, uint32_t deviceTags) { CALL_INFO_TRACE; #if defined(OHOS_BUILD_ENABLE_KEYBOARD) && defined(OHOS_BUILD_ENABLE_INTERCEPTOR) CHKPR(interceptor, INVALID_HANDLER_ID); std::lock_guard guard(mtx_); auto consumer = std::make_shared(interceptor); - CHKPR(consumer, INVALID_HANDLER_ID); if (!MMIEventHdl.InitClient()) { MMI_HILOGE("Client init failed"); return RET_ERR; } - return InputInterMgr->AddInterceptor(consumer, HANDLE_EVENT_TYPE_KEY); + return InputInterMgr->AddInterceptor(consumer, HANDLE_EVENT_TYPE_KEY, priority, deviceTags); #else MMI_HILOGW("Keyboard device or interceptor function does not support"); return ERROR_UNSUPPORT; @@ -470,7 +533,7 @@ void InputManagerImpl::RemoveInterceptor(int32_t interceptorId) void InputManagerImpl::SimulateInputEvent(std::shared_ptr keyEvent) { - CALL_INFO_TRACE; + CALL_DEBUG_ENTER; #ifdef OHOS_BUILD_ENABLE_KEYBOARD CHKPV(keyEvent); std::lock_guard guard(mtx_); @@ -484,7 +547,7 @@ void InputManagerImpl::SimulateInputEvent(std::shared_ptr keyEvent) void InputManagerImpl::SimulateInputEvent(std::shared_ptr pointerEvent) { - CALL_INFO_TRACE; + CALL_DEBUG_ENTER; #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) CHKPV(pointerEvent); if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_MOUSE || @@ -519,6 +582,7 @@ int32_t InputManagerImpl::SetPointerVisible(bool visible) { #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING) CALL_DEBUG_ENTER; + std::lock_guard guard(mtx_); int32_t ret = MultimodalInputConnMgr->SetPointerVisible(visible); if (ret != RET_OK) { MMI_HILOGE("Set pointer visible failed, ret:%{public}d", ret); @@ -534,6 +598,7 @@ bool InputManagerImpl::IsPointerVisible() { #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING) CALL_DEBUG_ENTER; + std::lock_guard guard(mtx_); bool visible; int32_t ret = MultimodalInputConnMgr->IsPointerVisible(visible); if (ret != 0) { @@ -578,10 +643,10 @@ int32_t InputManagerImpl::GetPointerSpeed(int32_t &speed) #endif // OHOS_BUILD_ENABLE_POINTER } -int32_t InputManagerImpl::SetPointerStyle(int32_t windowId, int32_t pointerStyle) +int32_t InputManagerImpl::SetPointerStyle(int32_t windowId, const PointerStyle& pointerStyle) { CALL_DEBUG_ENTER; - if (windowId < 0 || pointerStyle < 0) { + if (pointerStyle.id < 0) { MMI_HILOGE("The param is invalid"); return RET_ERR; } @@ -593,13 +658,9 @@ int32_t InputManagerImpl::SetPointerStyle(int32_t windowId, int32_t pointerStyle return RET_OK; } -int32_t InputManagerImpl::GetPointerStyle(int32_t windowId, int32_t &pointerStyle) +int32_t InputManagerImpl::GetPointerStyle(int32_t windowId, PointerStyle &pointerStyle) { CALL_DEBUG_ENTER; - if (windowId < 0) { - MMI_HILOGE("The param is invalid"); - return RET_ERR; - } int32_t ret = MultimodalInputConnMgr->GetPointerStyle(windowId, pointerStyle); if (ret != RET_OK) { MMI_HILOGE("Get pointer style failed, ret:%{public}d", ret); @@ -611,8 +672,9 @@ int32_t InputManagerImpl::GetPointerStyle(int32_t windowId, int32_t &pointerStyl void InputManagerImpl::OnConnected() { CALL_DEBUG_ENTER; + ReAddInputEventFilter(); if (displayGroupInfo_.windowsInfo.empty() || displayGroupInfo_.displaysInfo.empty()) { - MMI_HILOGE("The windows info or display info is empty"); + MMI_HILOGI("The windows info or display info is empty"); return; } SendDisplayInfo(); @@ -622,7 +684,7 @@ void InputManagerImpl::OnConnected() } int32_t ret = MultimodalInputConnMgr->SetAnrObserver(); if (ret != RET_OK) { - MMI_HILOGE("Set anr observerfailed, ret:%{public}d", ret); + MMI_HILOGE("Set anr observer failed, ret:%{public}d", ret); } } @@ -640,6 +702,23 @@ void InputManagerImpl::SendDisplayInfo() } } +void InputManagerImpl::ReAddInputEventFilter() +{ + CALL_INFO_TRACE; + if (eventFilterServices_.size() > MAX_FILTER_NUM) { + MMI_HILOGE("Too many filters, size:%{public}zu", eventFilterServices_.size()); + return; + } + for (const auto &[filterId, t] : eventFilterServices_) { + const auto &[service, priority, deviceTags] = t; + int32_t ret = MultimodalInputConnMgr->AddInputEventFilter(service, filterId, priority, deviceTags); + if (ret != RET_OK) { + MMI_HILOGE("AddInputEventFilter has send to server failed, filterId:%{public}d, priority:%{public}d," + "deviceTags:%{public}u, ret:%{public}d", filterId, priority, deviceTags, ret); + } + } +} + int32_t InputManagerImpl::RegisterDevListener(std::string type, std::shared_ptr listener) { std::lock_guard guard(mtx_); @@ -668,7 +747,7 @@ int32_t InputManagerImpl::GetDeviceIds(std::function&) MMI_HILOGE("Client init failed"); return RET_ERR; } - return InputDevImpl.GetInputDeviceIdsAsync(callback); + return InputDevImpl.GetInputDeviceIds(callback); } int32_t InputManagerImpl::GetDevice(int32_t deviceId, @@ -679,7 +758,7 @@ int32_t InputManagerImpl::GetDevice(int32_t deviceId, MMI_HILOGE("Client init failed"); return RET_ERR; } - return InputDevImpl.GetInputDeviceAsync(deviceId, callback); + return InputDevImpl.GetInputDevice(deviceId, callback); } int32_t InputManagerImpl::SupportKeys(int32_t deviceId, std::vector &keyCodes, @@ -758,138 +837,6 @@ int32_t InputManagerImpl::SetInputDevice(const std::string &dhid, const std::str #endif // OHOS_BUILD_ENABLE_COOPERATE } -int32_t InputManagerImpl::SetPointerLocation(int32_t x, int32_t y) -{ - CALL_INFO_TRACE; -#ifdef OHOS_DISTRIBUTED_INPUT_MODEL - std::lock_guard guard(mtx_); - int32_t ret = MultimodalInputConnectManager::GetInstance()->SetPointerLocation(x, y); - if (ret != RET_OK) { - MMI_HILOGE("SetPointerLocation has send to server failed, ret:%{public}d", ret); - return RET_ERR; - } - return RET_OK; -#else - MMI_HILOGW("Set pointer location dose not support"); - return RET_OK; -#endif // OHOS_DISTRIBUTED_INPUT_MODEL -} - -int32_t InputManagerImpl::GetRemoteInputAbility(std::string deviceId, - std::function)> remoteTypes) -{ -#ifdef OHOS_DISTRIBUTED_INPUT_MODEL - CALL_INFO_TRACE; - std::lock_guard guard(mtx_); - if (callDinputService_ == nullptr) { - callDinputService_ = new (std::nothrow) CallDinputService(); - } - CHKPR(callDinputService_, RET_ERR); - callDinputService_->SetRemoteAbilityCallback(remoteTypes); - int32_t ret = MultimodalInputConnectManager::GetInstance()->GetRemoteInputAbility(deviceId, callDinputService_); - if (ret != RET_OK) { - MMI_HILOGE("Send to server failed, ret:%{public}d", ret); - return RET_ERR; - } - return RET_OK; -#else - MMI_HILOGW("Get remote input ability dose not support"); - return RET_OK; -#endif // OHOS_DISTRIBUTED_INPUT_MODEL -} - -int32_t InputManagerImpl::PrepareRemoteInput(const std::string &deviceId, std::function callback) -{ -#ifdef OHOS_DISTRIBUTED_INPUT_MODEL - CALL_INFO_TRACE; - std::lock_guard guard(mtx_); - if (callDinputService_ == nullptr) { - callDinputService_ = new (std::nothrow) CallDinputService(); - } - CHKPR(callDinputService_, RET_ERR); - callDinputService_->SetPrepareCallback(callback); - int32_t ret = MultimodalInputConnectManager::GetInstance()->PrepareRemoteInput(deviceId, callDinputService_); - if (ret != RET_OK) { - MMI_HILOGE("Send to server failed, ret:%{public}d", ret); - return RET_ERR; - } - return RET_OK; -#else - MMI_HILOGW("Prepare remote input dose not support"); - return RET_OK; -#endif // OHOS_DISTRIBUTED_INPUT_MODEL -} - -int32_t InputManagerImpl::UnprepareRemoteInput(const std::string &deviceId, std::function callback) -{ -#ifdef OHOS_DISTRIBUTED_INPUT_MODEL - CALL_INFO_TRACE; - std::lock_guard guard(mtx_); - if (callDinputService_ == nullptr) { - callDinputService_ = new (std::nothrow) CallDinputService(); - } - CHKPR(callDinputService_, RET_ERR); - callDinputService_->SetUnprepareCallback(callback); - int32_t ret = MultimodalInputConnectManager::GetInstance()->UnprepareRemoteInput(deviceId, callDinputService_); - if (ret != RET_OK) { - MMI_HILOGE("Send to server failed, ret:%{public}d", ret); - return RET_ERR; - } - return RET_OK; -#else - MMI_HILOGW("Unprepare remote input dose not support"); - return RET_OK; -#endif // OHOS_DISTRIBUTED_INPUT_MODEL -} - -int32_t InputManagerImpl::StartRemoteInput(const std::string &deviceId, - uint32_t inputAbility, std::function callback) -{ -#ifdef OHOS_DISTRIBUTED_INPUT_MODEL - CALL_INFO_TRACE; - std::lock_guard guard(mtx_); - if (callDinputService_ == nullptr) { - callDinputService_ = new (std::nothrow) CallDinputService(); - } - CHKPR(callDinputService_, RET_ERR); - callDinputService_->SetStartCallback(callback); - int32_t ret = MultimodalInputConnectManager::GetInstance()->StartRemoteInput(deviceId, - inputAbility, callDinputService_); - if (ret != RET_OK) { - MMI_HILOGE("Send to server failed, ret:%{public}d", ret); - return RET_ERR; - } - return RET_OK; -#else - MMI_HILOGW("Start remote input dose not support"); - return RET_OK; -#endif // OHOS_DISTRIBUTED_INPUT_MODEL -} - -int32_t InputManagerImpl::StopRemoteInput(const std::string &deviceId, - uint32_t inputAbility, std::function callback) -{ -#ifdef OHOS_DISTRIBUTED_INPUT_MODEL - CALL_INFO_TRACE; - std::lock_guard guard(mtx_); - if (callDinputService_ == nullptr) { - callDinputService_ = new (std::nothrow) CallDinputService(); - } - CHKPR(callDinputService_, RET_ERR); - callDinputService_->SetStopCallback(callback); - int32_t ret = MultimodalInputConnectManager::GetInstance()->StopRemoteInput(deviceId, - inputAbility, callDinputService_); - if (ret != RET_OK) { - MMI_HILOGE("Send to server failed, ret:%{public}d", ret); - return RET_ERR; - } - return RET_OK; -#else - MMI_HILOGW("Stop remote input dose not support"); - return RET_OK; -#endif // OHOS_DISTRIBUTED_INPUT_MODEL -} - int32_t InputManagerImpl::RegisterCooperateListener(std::shared_ptr listener) { CALL_DEBUG_ENTER; @@ -1029,5 +976,64 @@ int32_t InputManagerImpl::SetFunctionKeyState(int32_t funcKey, bool enable) return ERROR_UNSUPPORT; #endif // OHOS_BUILD_ENABLE_KEYBOARD } + +void InputManagerImpl::SetPointerLocation(int32_t x, int32_t y) +{ + CALL_DEBUG_ENTER; +#if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING) + int32_t ret = MultimodalInputConnMgr->SetPointerLocation(x, y); + if (ret != RET_OK) { + MMI_HILOGE("Set Pointer Location failed, ret:%{public}d", ret); + } +#else + MMI_HILOGW("Pointer device or pointer drawing module does not support"); +#endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING +} + +int32_t InputManagerImpl::EnterCaptureMode(int32_t windowId) +{ +#if defined(OHOS_BUILD_ENABLE_POINTER) + CALL_DEBUG_ENTER; + std::lock_guard guard(mtx_); + int32_t ret = MultimodalInputConnMgr->SetMouseCaptureMode(windowId, true); + if (ret != RET_OK) { + MMI_HILOGE("Enter captrue mode failed"); + } + return ret; +#else + MMI_HILOGW("Pointer device module does not support"); + return ERROR_UNSUPPORT; +#endif // OHOS_BUILD_ENABLE_POINTER +} + +int32_t InputManagerImpl::LeaveCaptureMode(int32_t windowId) +{ +#if defined(OHOS_BUILD_ENABLE_POINTER) + CALL_DEBUG_ENTER; + std::lock_guard guard(mtx_); + int32_t ret = MultimodalInputConnMgr->SetMouseCaptureMode(windowId, false); + if (ret != RET_OK) { + MMI_HILOGE("Leave captrue mode failed"); + } + return ret; +#else + MMI_HILOGW("Pointer device module does not support"); + return ERROR_UNSUPPORT; +#endif // OHOS_BUILD_ENABLE_POINTER +} + +void InputManagerImpl::AppendExtraData(const ExtraData& extraData) +{ + CALL_DEBUG_ENTER; + std::lock_guard guard(mtx_); + if (extraData.buffer.size() > ExtraData::MAX_BUFFER_SIZE) { + MMI_HILOGE("Append extra data failed, buffer is oversize:%{public}zu", extraData.buffer.size()); + return; + } + int32_t ret = MultimodalInputConnMgr->AppendExtraData(extraData); + if (ret != RET_OK) { + MMI_HILOGE("Append extra data failed:%{public}d", ret); + } +} } // namespace MMI } // namespace OHOS diff --git a/frameworks/proxy/event_handler/src/input_monitor_manager.cpp b/frameworks/proxy/event_handler/src/input_monitor_manager.cpp index 24d87e207d90373537f2cd0b66bab1283ecc8f0f..4e267e27dbc45c4e7e5317c86727b703a8023408 100644 --- a/frameworks/proxy/event_handler/src/input_monitor_manager.cpp +++ b/frameworks/proxy/event_handler/src/input_monitor_manager.cpp @@ -14,6 +14,7 @@ */ #include "input_monitor_manager.h" + #include "multimodal_input_connect_manager.h" #include "util.h" diff --git a/frameworks/proxy/event_handler/src/key_event_input_subscribe_manager.cpp b/frameworks/proxy/event_handler/src/key_event_input_subscribe_manager.cpp index e9dd5ee27eb51dddbd0e47312eacd02854b7a5cd..81b2b04609c9e25c19f7c39ffb8b33fee1b63a3f 100755 --- a/frameworks/proxy/event_handler/src/key_event_input_subscribe_manager.cpp +++ b/frameworks/proxy/event_handler/src/key_event_input_subscribe_manager.cpp @@ -113,6 +113,8 @@ int32_t KeyEventInputSubscribeManager::SubscribeKeyEvent(std::shared_ptrfinalKey:%{public}d," diff --git a/frameworks/proxy/event_handler/src/multimodal_event_handler.cpp b/frameworks/proxy/event_handler/src/multimodal_event_handler.cpp index f815b9e9e6e59d9321f2ae209dcd22ce1faf9d66..00346be84daaccd2184abebdfdad4580e882feee 100755 --- a/frameworks/proxy/event_handler/src/multimodal_event_handler.cpp +++ b/frameworks/proxy/event_handler/src/multimodal_event_handler.cpp @@ -28,7 +28,7 @@ namespace OHOS { namespace MMI { namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "MultimodalEventHandler"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "MultimodalEventHandler" }; } // namespace void OnConnected(const IfMMIClient& client) @@ -91,7 +91,6 @@ bool MultimodalEventHandler::InitClient(EventHandlerPtr eventHandler) return true; } client_ = std::make_shared(); - CHKPF(client_); client_->SetEventHandler(eventHandler); client_->RegisterConnectedFunction(&OnConnected); if (!(client_->Start())) { diff --git a/frameworks/proxy/events/include/event_log_helper.h b/frameworks/proxy/events/include/event_log_helper.h index 936bc47a3a18e45eabcdf6c1b09f99fa3035cd6b..6ad6c7499a4e1caf489eee12eb89101bed085c80 100644 --- a/frameworks/proxy/events/include/event_log_helper.h +++ b/frameworks/proxy/events/include/event_log_helper.h @@ -25,7 +25,7 @@ namespace OHOS { namespace MMI { -class EventLogHelper { +class EventLogHelper final { static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "EventLogHelper" }; public: @@ -37,18 +37,22 @@ public: private: static void Print(const std::shared_ptr event) { + if (!HiLogIsLoggable(OHOS::MMI::MMI_LOG_DOMAIN, LABEL.tag, LOG_DEBUG) + && event->GetKeyCode() != KeyEvent::KEYCODE_POWER) { + return; + } std::vector eventItems { event->GetKeyItems() }; - MMI_HILOGD("KeyCode:%{public}d,ActionTime:%{public}" PRId64 ",ActionStartTime:%{public}" PRId64 + MMI_HILOGD("KeyCode:%{public}d,KeyIntention:%{public}d,ActionTime:%{public}" PRId64 ",ActionStartTime:%{public}" PRId64 ",EventType:%{public}s,Flag:%{public}d,KeyAction:%{public}s,NumLock:%{public}d," "CapsLock:%{public}d,ScrollLock:%{public}d,EventNumber:%{public}d,keyItemsCount:%{public}zu", - event->GetKeyCode(), event->GetActionTime(), event->GetActionStartTime(), + event->GetKeyCode(), event->GetKeyIntention(), event->GetActionTime(), event->GetActionStartTime(), InputEvent::EventTypeToString(event->GetEventType()), event->GetFlag(), KeyEvent::ActionToString(event->GetKeyAction()), event->GetFunctionKey(KeyEvent::NUM_LOCK_FUNCTION_KEY), event->GetFunctionKey(KeyEvent::CAPS_LOCK_FUNCTION_KEY), event->GetFunctionKey(KeyEvent::SCROLL_LOCK_FUNCTION_KEY), event->GetId(), eventItems.size()); for (const auto &item : eventItems) { - MMI_HILOGD("DeviceNumber:%{public}d,KeyCode:%{public}d,DownTime:%{public}" PRId64 ",IsPressed:%{public}d," + MMI_HILOGI("DeviceNumber:%{public}d,KeyCode:%{public}d,DownTime:%{public}" PRId64 ",IsPressed:%{public}d," "GetUnicode:%{public}d", item.GetDeviceId(), item.GetKeyCode(), item.GetDownTime(), item.IsPressed(), item.GetUnicode()); } @@ -59,26 +63,44 @@ private: for (; cItr != pressedKeys.cend(); ++cItr) { tmpStr += ("," + std::to_string(*cItr)); } - MMI_HILOGD("%{public}s]", tmpStr.c_str()); + MMI_HILOGI("%{public}s]", tmpStr.c_str()); } } static void Print(const std::shared_ptr event) { std::vector pointerIds { event->GetPointerIds() }; + std::string str; + std::vector buffer = event->GetBuffer(); + for (const auto& buff : buffer) { + str += std::to_string(buff); + } MMI_HILOGD("EventType:%{public}s,ActionTime:%{public}" PRId64 ",Action:%{public}d," "ActionStartTime:%{public}" PRId64 ",Flag:%{public}d,PointerAction:%{public}s," "SourceType:%{public}s,ButtonId:%{public}d,VerticalAxisValue:%{public}.2f," - "HorizontalAxisValue:%{public}.2f,PinchAxisValue:%{public}.2f,PointerId:%{public}d," - "PointerCount:%{public}zu,EventNumber:%{public}d", + "HorizontalAxisValue:%{public}.2f,PinchAxisValue:%{public}.2f," + "XAbsValue:%{public}.2f,YAbsValue:%{public}.2f,ZAbsValue:%{public}.2f," + "RzAbsValue:%{public}.2f,GasAbsValue:%{public}.2f,BrakeAbsValue:%{public}.2f," + "Hat0xAbsValue:%{public}.2f,Hat0yAbsValue:%{public}.2f,ThrottleAbsValue:%{public}.2f," + "PointerId:%{public}d,PointerCount:%{public}zu,EventNumber:%{public}d," + "BufferCount:%{public}zu,Buffer:%{public}s", InputEvent::EventTypeToString(event->GetEventType()), event->GetActionTime(), event->GetAction(), event->GetActionStartTime(), event->GetFlag(), event->DumpPointerAction(), event->DumpSourceType(), event->GetButtonId(), event->GetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_VERTICAL), event->GetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_HORIZONTAL), event->GetAxisValue(PointerEvent::AXIS_TYPE_PINCH), - event->GetPointerId(), pointerIds.size(), event->GetId()); - + event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_X), + event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_Y), + event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_Z), + event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_RZ), + event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_GAS), + event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_BRAKE), + event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_HAT0X), + event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_HAT0Y), + event->GetAxisValue(PointerEvent::AXIS_TYPE_ABS_THROTTLE), + event->GetPointerId(), pointerIds.size(), event->GetId(), buffer.size(), str.c_str()); + for (const auto& pointerId : pointerIds) { PointerEvent::PointerItem item; if (!event->GetPointerItem(pointerId, item)) { @@ -89,12 +111,13 @@ private: "DisplayY:%{public}d,WindowX:%{public}d,WindowY:%{public}d,Width:%{public}d,Height:%{public}d," "TiltX:%{public}.2f,TiltY:%{public}.2f,ToolDisplayX:%{public}d,ToolDisplayY:%{public}d," "ToolWindowX:%{public}d,ToolWindowY:%{public}d,ToolWidth:%{public}d,ToolHeight:%{public}d," - "Pressure:%{public}.2f,ToolType:%{public}d,LongAxis:%{public}d,ShortAxis:%{public}d", + "Pressure:%{public}.2f,ToolType:%{public}d,LongAxis:%{public}d,ShortAxis:%{public}d,RawDx:%{public}d," + "RawDy:%{public}d", pointerId, item.GetDownTime(), item.IsPressed(), item.GetDisplayX(), item.GetDisplayY(), item.GetWindowX(), item.GetWindowY(), item.GetWidth(), item.GetHeight(), - item.GetTiltX(), item.GetTiltY(), item.GetToolDisplayX(), item.GetToolDisplayY(), item.GetToolWindowX(), - item.GetToolWindowY(), item.GetToolWidth(), item.GetToolHeight(), item.GetPressure(), item.GetToolType(), - item.GetLongAxis(), item.GetShortAxis()); + item.GetTiltX(), item.GetTiltY(), item.GetToolDisplayX(), item.GetToolDisplayY(), + item.GetToolWindowX(), item.GetToolWindowY(), item.GetToolWidth(), item.GetToolHeight(), + item.GetPressure(), item.GetToolType(), item.GetLongAxis(), item.GetShortAxis(), item.GetRawDx(), item.GetRawDy()); } std::vector pressedKeys = event->GetPressedKeys(); std::vector::const_iterator cItr = pressedKeys.cbegin(); @@ -134,10 +157,11 @@ template void EventLogHelper::PrintEventData(std::shared_ptr event) { CHKPV(event); - if (HiLogIsLoggable(OHOS::MMI::MMI_LOG_DOMAIN, LABEL.tag, LOG_DEBUG)) { + if (HiLogIsLoggable(OHOS::MMI::MMI_LOG_DOMAIN, LABEL.tag, LOG_DEBUG) + || (event->GetAction() == InputEvent::EVENT_TYPE_KEY)) { EventLogHelper::Print(event); } } } // namespace MMI } // namespace OHOS -#endif // EVENT_LOG_HELPER_H \ No newline at end of file +#endif // EVENT_LOG_HELPER_H diff --git a/frameworks/proxy/events/src/input_device.cpp b/frameworks/proxy/events/src/input_device.cpp index 8e2f254d385ccbde85ddd8514e47d7547d04cc45..e6705c2f379b5db78309c28aeb1e2811797c40cf 100644 --- a/frameworks/proxy/events/src/input_device.cpp +++ b/frameworks/proxy/events/src/input_device.cpp @@ -112,6 +112,37 @@ std::string InputDevice::GetUniq() const return uniq_; } +void InputDevice::AddCapability(InputDeviceCapability cap) +{ + if (cap >= INPUT_DEV_CAP_KEYBOARD && cap < INPUT_DEV_CAP_MAX) { + capabilities_.set(cap); + } +} + +bool InputDevice::HasCapability(InputDeviceCapability cap) const +{ + if (cap >= INPUT_DEV_CAP_KEYBOARD && cap < INPUT_DEV_CAP_MAX) { + return capabilities_.test(cap); + } + return false; +} + +bool InputDevice::HasCapability(uint32_t deviceTags) const +{ + int32_t min = static_cast(INPUT_DEV_CAP_KEYBOARD); + int32_t max = static_cast(INPUT_DEV_CAP_MAX); + for (int32_t cap = min; cap < max; ++cap) { + if (!capabilities_.test(static_cast(cap))) { + continue; + } + uint32_t tags = CapabilityToTags(static_cast(cap)); + if ((tags & deviceTags) == tags) { + return true; + } + } + return false; +} + void InputDevice::AddAxisInfo(AxisInfo axis) { axis_.push_back(axis); diff --git a/frameworks/proxy/events/src/input_event.cpp b/frameworks/proxy/events/src/input_event.cpp index 13055a4671686c47d881d2cca860da7c91301d52..dcbd4fbea6e7c261ea1543f15ca042e767bc7796 100644 --- a/frameworks/proxy/events/src/input_event.cpp +++ b/frameworks/proxy/events/src/input_event.cpp @@ -24,7 +24,7 @@ namespace OHOS { namespace MMI { namespace { int64_t g_nextEventId = 1; -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "InputEvent"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "InputEvent" }; } // namespace InputEvent::InputEvent(int32_t eventType) : eventType_(eventType) @@ -200,7 +200,7 @@ void InputEvent::ClearFlag() bitwise_ = EVENT_FLAG_NONE; } -void InputEvent::SetProcessedCallback(std::function callback) +void InputEvent::SetProcessedCallback(std::function callback) { processedCallback_ = callback; } @@ -211,57 +211,37 @@ void InputEvent::MarkProcessed() return; } auto func = processedCallback_; - processedCallback_ = std::function(); - func(id_); + processedCallback_ = std::function(); + func(id_, actionTime_); } bool InputEvent::WriteToParcel(Parcel &out) const { WRITEINT32(out, eventType_); - WRITEINT32(out, id_); - WRITEINT64(out, actionTime_); - WRITEINT32(out, action_); - WRITEINT64(out, actionStartTime_); - WRITEINT32(out, deviceId_); - WRITEINT32(out, targetDisplayId_); - WRITEINT32(out, targetWindowId_); - WRITEINT32(out, agentWindowId_); - WRITEUINT32(out, bitwise_); - return true; } bool InputEvent::ReadFromParcel(Parcel &in) { READINT32(in, eventType_); - READINT32(in, id_); - READINT64(in, actionTime_); - READINT32(in, action_); - READINT64(in, actionStartTime_); - READINT32(in, deviceId_); - READINT32(in, targetDisplayId_); - READINT32(in, targetWindowId_); - READINT32(in, agentWindowId_); - READUINT32(in, bitwise_); - return true; } } // namespace MMI diff --git a/frameworks/proxy/events/src/input_manager.cpp b/frameworks/proxy/events/src/input_manager.cpp index 0bd9570e166b287c7c85f76ec39ff9fe62891dbb..865060d8b8f2b0111dcba00e86004eea76cde0a5 100644 --- a/frameworks/proxy/events/src/input_manager.cpp +++ b/frameworks/proxy/events/src/input_manager.cpp @@ -32,14 +32,35 @@ InputManager *InputManager::GetInstance() return instance_; } +int32_t InputManager::GetDisplayBindInfo(DisplayBindInfos &infos) +{ + return InputMgrImpl.GetDisplayBindInfo(infos); +} + +int32_t InputManager::SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg) +{ + return InputMgrImpl.SetDisplayBind(deviceId, displayId, msg); +} + +int32_t InputManager::GetWindowPid(int32_t windowId) +{ + return InputMgrImpl.GetWindowPid(windowId); +} + void InputManager::UpdateDisplayInfo(const DisplayGroupInfo &displayGroupInfo) { InputMgrImpl.UpdateDisplayInfo(displayGroupInfo); } -int32_t InputManager::AddInputEventFilter(std::function)> filter) +int32_t InputManager::AddInputEventFilter(std::shared_ptr filter, int32_t priority, + uint32_t deviceTags) +{ + return InputMgrImpl.AddInputEventFilter(filter, priority, deviceTags); +} + +int32_t InputManager::RemoveInputEventFilter(int32_t filterId) { - return InputMgrImpl.AddInputEventFilter(filter); + return InputMgrImpl.RemoveInputEventFilter(filterId); } void InputManager::SetWindowInputEventConsumer(std::shared_ptr inputEventConsumer) @@ -105,6 +126,12 @@ int32_t InputManager::AddInterceptor(std::function interceptor, int32_t priority, + uint32_t deviceTags) +{ + return InputMgrImpl.AddInterceptor(interceptor, priority, deviceTags); +} + void InputManager::RemoveInterceptor(int32_t interceptorId) { InputMgrImpl.RemoveInterceptor(interceptorId); @@ -177,12 +204,12 @@ void InputManager::SetAnrObserver(std::shared_ptr observer) InputMgrImpl.SetAnrObserver(observer); } -int32_t InputManager::SetPointerStyle(int32_t windowId, int32_t pointerStyle) +int32_t InputManager::SetPointerStyle(int32_t windowId, PointerStyle pointerStyle) { return InputMgrImpl.SetPointerStyle(windowId, pointerStyle); } -int32_t InputManager::GetPointerStyle(int32_t windowId, int32_t &pointerStyle) +int32_t InputManager::GetPointerStyle(int32_t windowId, PointerStyle &pointerStyle) { return InputMgrImpl.GetPointerStyle(windowId, pointerStyle); } @@ -192,79 +219,34 @@ int32_t InputManager::SetInputDevice(const std::string& dhid, const std::string& return InputMgrImpl.SetInputDevice(dhid, screenId); } -int32_t InputManager::SetPointerLocation(int32_t x, int32_t y) -{ - return InputMgrImpl.SetPointerLocation(x, y); -} - -int32_t InputManager::GetRemoteInputAbility(std::string deviceId, - std::function)> remoteTypes) -{ - return InputMgrImpl.GetRemoteInputAbility(deviceId, remoteTypes); -} - -int32_t InputManager::PrepareRemoteInput(const std::string& deviceId, std::function callback) -{ - return InputMgrImpl.PrepareRemoteInput(deviceId, callback); -} - -int32_t InputManager::UnprepareRemoteInput(const std::string& deviceId, std::function callback) -{ - return InputMgrImpl.UnprepareRemoteInput(deviceId, callback); -} - -int32_t InputManager::StartRemoteInput(const std::string& deviceId, - uint32_t inputAbility, std::function callback) -{ - return InputMgrImpl.StartRemoteInput(deviceId, inputAbility, callback); -} - -int32_t InputManager::StopRemoteInput(const std::string& deviceId, uint32_t inputAbility, - std::function callback) -{ - return InputMgrImpl.StopRemoteInput(deviceId, inputAbility, callback); -} - -int32_t InputManager::RegisterCooperateListener(std::shared_ptr listener) -{ - return InputMgrImpl.RegisterCooperateListener(listener); -} - -int32_t InputManager::UnregisterCooperateListener(std::shared_ptr listener) -{ - return InputMgrImpl.UnregisterCooperateListener(listener); -} - -int32_t InputManager::EnableInputDeviceCooperate(bool enabled, - std::function callback) +bool InputManager::GetFunctionKeyState(int32_t funcKey) { - return InputMgrImpl.EnableInputDeviceCooperate(enabled, callback); + return InputMgrImpl.GetFunctionKeyState(funcKey); } -int32_t InputManager::StartInputDeviceCooperate(const std::string &sinkDeviceId, int32_t srcInputDeviceId, - std::function callback) +int32_t InputManager::SetFunctionKeyState(int32_t funcKey, bool enable) { - return InputMgrImpl.StartInputDeviceCooperate(sinkDeviceId, srcInputDeviceId, callback); + return InputMgrImpl.SetFunctionKeyState(funcKey, enable); } -int32_t InputManager::StopDeviceCooperate(std::function callback) +void InputManager::SetPointerLocation(int32_t x, int32_t y) { - return InputMgrImpl.StopDeviceCooperate(callback); + InputMgrImpl.SetPointerLocation(x, y); } -int32_t InputManager::GetInputDeviceCooperateState(const std::string &deviceId, std::function callback) +int32_t InputManager::EnterCaptureMode(int32_t windowId) { - return InputMgrImpl.GetInputDeviceCooperateState(deviceId, callback); + return InputMgrImpl.EnterCaptureMode(windowId); } -bool InputManager::GetFunctionKeyState(int32_t funcKey) +int32_t InputManager::LeaveCaptureMode(int32_t windowId) { - return InputMgrImpl.GetFunctionKeyState(funcKey); + return InputMgrImpl.LeaveCaptureMode(windowId); } -int32_t InputManager::SetFunctionKeyState(int32_t funcKey, bool enable) +void InputManager::AppendExtraData(const ExtraData& extraData) { - return InputMgrImpl.SetFunctionKeyState(funcKey, enable); + InputMgrImpl.AppendExtraData(extraData); } } // namespace MMI } // namespace OHOS \ No newline at end of file diff --git a/frameworks/proxy/events/src/key_event.cpp b/frameworks/proxy/events/src/key_event.cpp index 2f402a91e1a7b33138aa51db0250545b728a21bb..0467114b41cc7fb1b4763c61dada044b7bf7344e 100644 --- a/frameworks/proxy/events/src/key_event.cpp +++ b/frameworks/proxy/events/src/key_event.cpp @@ -22,9 +22,400 @@ using namespace OHOS::HiviewDFX; namespace OHOS { namespace MMI { namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "KeyEvent"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "KeyEvent" }; +const std::map KEYCODE_TO_STRING = { + {KeyEvent::KEYCODE_FN, "KEYCODE_FN"}, + {KeyEvent::KEYCODE_UNKNOWN, "KEYCODE_UNKNOWN"}, + {KeyEvent::KEYCODE_HOME, "KEYCODE_HOME"}, + {KeyEvent::KEYCODE_BACK, "KEYCODE_BACK"}, + {KeyEvent::KEYCODE_CALL, "KEYCODE_CALL"}, + {KeyEvent::KEYCODE_ENDCALL, "KEYCODE_ENDCALL"}, + {KeyEvent::KEYCODE_CLEAR, "KEYCODE_CLEAR"}, + {KeyEvent::KEYCODE_HEADSETHOOK, "KEYCODE_HEADSETHOOK"}, + {KeyEvent::KEYCODE_FOCUS, "KEYCODE_FOCUS"}, + {KeyEvent::KEYCODE_NOTIFICATION, "KEYCODE_NOTIFICATION"}, + {KeyEvent::KEYCODE_SEARCH, "KEYCODE_SEARCH"}, + {KeyEvent::KEYCODE_MEDIA_PLAY_PAUSE, "KEYCODE_MEDIA_PLAY_PAUSE"}, + {KeyEvent::KEYCODE_MEDIA_STOP, "KEYCODE_MEDIA_STOP"}, + {KeyEvent::KEYCODE_MEDIA_NEXT, "KEYCODE_MEDIA_NEXT"}, + {KeyEvent::KEYCODE_MEDIA_PREVIOUS, "KEYCODE_MEDIA_PREVIOUS"}, + {KeyEvent::KEYCODE_MEDIA_REWIND, "KEYCODE_MEDIA_REWIND"}, + {KeyEvent::KEYCODE_MEDIA_FAST_FORWARD, "KEYCODE_MEDIA_FAST_FORWARD"}, + {KeyEvent::KEYCODE_VOLUME_UP, "KEYCODE_VOLUME_UP"}, + {KeyEvent::KEYCODE_VOLUME_DOWN, "KEYCODE_VOLUME_DOWN"}, + {KeyEvent::KEYCODE_POWER, "KEYCODE_POWER"}, + {KeyEvent::KEYCODE_CAMERA, "KEYCODE_CAMERA"}, + {KeyEvent::KEYCODE_VOICE_ASSISTANT, "KEYCODE_VOICE_ASSISTANT"}, + {KeyEvent::KEYCODE_CUSTOM1, "KEYCODE_CUSTOM1"}, + {KeyEvent::KEYCODE_VOLUME_MUTE, "KEYCODE_VOLUME_MUTE"}, + {KeyEvent::KEYCODE_MUTE, "KEYCODE_MUTE"}, + {KeyEvent::KEYCODE_BRIGHTNESS_UP, "KEYCODE_BRIGHTNESS_UP"}, + {KeyEvent::KEYCODE_BRIGHTNESS_DOWN, "KEYCODE_BRIGHTNESS_DOWN"}, + {KeyEvent::KEYCODE_WEAR_1, "KEYCODE_WEAR_1"}, + {KeyEvent::KEYCODE_0, "KEYCODE_0"}, + {KeyEvent::KEYCODE_1, "KEYCODE_1"}, + {KeyEvent::KEYCODE_2, "KEYCODE_2"}, + {KeyEvent::KEYCODE_3, "KEYCODE_3"}, + {KeyEvent::KEYCODE_4, "KEYCODE_4"}, + {KeyEvent::KEYCODE_5, "KEYCODE_5"}, + {KeyEvent::KEYCODE_6, "KEYCODE_6"}, + {KeyEvent::KEYCODE_7, "KEYCODE_7"}, + {KeyEvent::KEYCODE_8, "KEYCODE_8"}, + {KeyEvent::KEYCODE_9, "KEYCODE_9"}, + {KeyEvent::KEYCODE_STAR, "KEYCODE_STAR"}, + {KeyEvent::KEYCODE_POUND, "KEYCODE_POUND"}, + {KeyEvent::KEYCODE_DPAD_UP, "KEYCODE_DPAD_UP"}, + {KeyEvent::KEYCODE_DPAD_DOWN, "KEYCODE_DPAD_DOWN"}, + {KeyEvent::KEYCODE_DPAD_LEFT, "KEYCODE_DPAD_LEFT"}, + {KeyEvent::KEYCODE_DPAD_RIGHT, "KEYCODE_DPAD_RIGHT"}, + {KeyEvent::KEYCODE_DPAD_CENTER, "KEYCODE_DPAD_CENTER"}, + {KeyEvent::KEYCODE_A, "KEYCODE_A"}, + {KeyEvent::KEYCODE_B, "KEYCODE_B"}, + {KeyEvent::KEYCODE_C, "KEYCODE_C"}, + {KeyEvent::KEYCODE_D, "KEYCODE_D"}, + {KeyEvent::KEYCODE_E, "KEYCODE_E"}, + {KeyEvent::KEYCODE_F, "KEYCODE_F"}, + {KeyEvent::KEYCODE_G, "KEYCODE_G"}, + {KeyEvent::KEYCODE_H, "KEYCODE_H"}, + {KeyEvent::KEYCODE_I, "KEYCODE_I"}, + {KeyEvent::KEYCODE_J, "KEYCODE_J"}, + {KeyEvent::KEYCODE_K, "KEYCODE_K"}, + {KeyEvent::KEYCODE_L, "KEYCODE_L"}, + {KeyEvent::KEYCODE_M, "KEYCODE_M"}, + {KeyEvent::KEYCODE_N, "KEYCODE_N"}, + {KeyEvent::KEYCODE_O, "KEYCODE_O"}, + {KeyEvent::KEYCODE_P, "KEYCODE_P"}, + {KeyEvent::KEYCODE_Q, "KEYCODE_Q"}, + {KeyEvent::KEYCODE_R, "KEYCODE_R"}, + {KeyEvent::KEYCODE_S, "KEYCODE_S"}, + {KeyEvent::KEYCODE_T, "KEYCODE_T"}, + {KeyEvent::KEYCODE_U, "KEYCODE_U"}, + {KeyEvent::KEYCODE_V, "KEYCODE_V"}, + {KeyEvent::KEYCODE_W, "KEYCODE_W"}, + {KeyEvent::KEYCODE_X, "KEYCODE_X"}, + {KeyEvent::KEYCODE_Y, "KEYCODE_Y"}, + {KeyEvent::KEYCODE_Z, "KEYCODE_Z"}, + {KeyEvent::KEYCODE_COMMA, "KEYCODE_COMMA"}, + {KeyEvent::KEYCODE_PERIOD, "KEYCODE_PERIOD"}, + {KeyEvent::KEYCODE_ALT_LEFT, "KEYCODE_ALT_LEFT"}, + {KeyEvent::KEYCODE_ALT_RIGHT, "KEYCODE_ALT_RIGHT"}, + {KeyEvent::KEYCODE_SHIFT_LEFT, "KEYCODE_SHIFT_LEFT"}, + {KeyEvent::KEYCODE_SHIFT_RIGHT, "KEYCODE_SHIFT_RIGHT"}, + {KeyEvent::KEYCODE_TAB, "KEYCODE_TAB"}, + {KeyEvent::KEYCODE_SPACE, "KEYCODE_SPACE"}, + {KeyEvent::KEYCODE_SYM, "KEYCODE_SYM"}, + {KeyEvent::KEYCODE_EXPLORER, "KEYCODE_EXPLORER"}, + {KeyEvent::KEYCODE_ENVELOPE, "KEYCODE_ENVELOPE"}, + {KeyEvent::KEYCODE_ENTER, "KEYCODE_ENTER"}, + {KeyEvent::KEYCODE_DEL, "KEYCODE_DEL"}, + {KeyEvent::KEYCODE_GRAVE, "KEYCODE_GRAVE"}, + {KeyEvent::KEYCODE_MINUS, "KEYCODE_MINUS"}, + {KeyEvent::KEYCODE_EQUALS, "KEYCODE_EQUALS"}, + {KeyEvent::KEYCODE_LEFT_BRACKET, "KEYCODE_LEFT_BRACKET"}, + {KeyEvent::KEYCODE_RIGHT_BRACKET, "KEYCODE_RIGHT_BRACKET"}, + {KeyEvent::KEYCODE_BACKSLASH, "KEYCODE_BACKSLASH"}, + {KeyEvent::KEYCODE_SEMICOLON, "KEYCODE_SEMICOLON"}, + {KeyEvent::KEYCODE_APOSTROPHE, "KEYCODE_APOSTROPHE"}, + {KeyEvent::KEYCODE_SLASH, "KEYCODE_SLASH"}, + {KeyEvent::KEYCODE_AT, "KEYCODE_AT"}, + {KeyEvent::KEYCODE_PLUS, "KEYCODE_PLUS"}, + {KeyEvent::KEYCODE_MENU, "KEYCODE_MENU"}, + {KeyEvent::KEYCODE_PAGE_UP, "KEYCODE_PAGE_UP"}, + {KeyEvent::KEYCODE_PAGE_DOWN, "KEYCODE_PAGE_DOWN"}, + {KeyEvent::KEYCODE_ESCAPE, "KEYCODE_ESCAPE"}, + {KeyEvent::KEYCODE_FORWARD_DEL, "KEYCODE_FORWARD_DEL"}, + {KeyEvent::KEYCODE_CTRL_LEFT, "KEYCODE_CTRL_LEFT"}, + {KeyEvent::KEYCODE_CTRL_RIGHT, "KEYCODE_CTRL_RIGHT"}, + {KeyEvent::KEYCODE_CAPS_LOCK, "KEYCODE_CAPS_LOCK"}, + {KeyEvent::KEYCODE_SCROLL_LOCK, "KEYCODE_SCROLL_LOCK"}, + {KeyEvent::KEYCODE_META_LEFT, "KEYCODE_META_LEFT"}, + {KeyEvent::KEYCODE_META_RIGHT, "KEYCODE_META_RIGHT"}, + {KeyEvent::KEYCODE_FUNCTION, "KEYCODE_FUNCTION"}, + {KeyEvent::KEYCODE_SYSRQ, "KEYCODE_SYSRQ"}, + {KeyEvent::KEYCODE_BREAK, "KEYCODE_BREAK"}, + {KeyEvent::KEYCODE_MOVE_HOME, "KEYCODE_MOVE_HOME"}, + {KeyEvent::KEYCODE_MOVE_END, "KEYCODE_MOVE_END"}, + {KeyEvent::KEYCODE_INSERT, "KEYCODE_INSERT"}, + {KeyEvent::KEYCODE_FORWARD, "KEYCODE_FORWARD"}, + {KeyEvent::KEYCODE_MEDIA_PLAY, "KEYCODE_MEDIA_PLAY"}, + {KeyEvent::KEYCODE_MEDIA_PAUSE, "KEYCODE_MEDIA_PAUSE"}, + {KeyEvent::KEYCODE_MEDIA_CLOSE, "KEYCODE_MEDIA_CLOSE"}, + {KeyEvent::KEYCODE_MEDIA_EJECT, "KEYCODE_MEDIA_EJECT"}, + {KeyEvent::KEYCODE_MEDIA_RECORD, "KEYCODE_MEDIA_RECORD"}, + {KeyEvent::KEYCODE_F1, "KEYCODE_F1"}, + {KeyEvent::KEYCODE_F2, "KEYCODE_F2"}, + {KeyEvent::KEYCODE_F3, "KEYCODE_F3"}, + {KeyEvent::KEYCODE_F4, "KEYCODE_F4"}, + {KeyEvent::KEYCODE_F5, "KEYCODE_F5"}, + {KeyEvent::KEYCODE_F6, "KEYCODE_F6"}, + {KeyEvent::KEYCODE_F7, "KEYCODE_F7"}, + {KeyEvent::KEYCODE_F8, "KEYCODE_F8"}, + {KeyEvent::KEYCODE_F9, "KEYCODE_F9"}, + {KeyEvent::KEYCODE_F10, "KEYCODE_F10"}, + {KeyEvent::KEYCODE_F11, "KEYCODE_F11"}, + {KeyEvent::KEYCODE_F12, "KEYCODE_F12"}, + {KeyEvent::KEYCODE_NUM_LOCK, "KEYCODE_NUM_LOCK"}, + {KeyEvent::KEYCODE_NUMPAD_0, "KEYCODE_NUMPAD_0"}, + {KeyEvent::KEYCODE_NUMPAD_1, "KEYCODE_NUMPAD_1"}, + {KeyEvent::KEYCODE_NUMPAD_2, "KEYCODE_NUMPAD_2"}, + {KeyEvent::KEYCODE_NUMPAD_3, "KEYCODE_NUMPAD_3"}, + {KeyEvent::KEYCODE_NUMPAD_4, "KEYCODE_NUMPAD_4"}, + {KeyEvent::KEYCODE_NUMPAD_5, "KEYCODE_NUMPAD_5"}, + {KeyEvent::KEYCODE_NUMPAD_6, "KEYCODE_NUMPAD_6"}, + {KeyEvent::KEYCODE_NUMPAD_7, "KEYCODE_NUMPAD_7"}, + {KeyEvent::KEYCODE_NUMPAD_8, "KEYCODE_NUMPAD_8"}, + {KeyEvent::KEYCODE_NUMPAD_9, "KEYCODE_NUMPAD_9"}, + {KeyEvent::KEYCODE_NUMPAD_DIVIDE, "KEYCODE_NUMPAD_DIVIDE"}, + {KeyEvent::KEYCODE_NUMPAD_MULTIPLY, "KEYCODE_NUMPAD_MULTIPLY"}, + {KeyEvent::KEYCODE_NUMPAD_SUBTRACT, "KEYCODE_NUMPAD_SUBTRACT"}, + {KeyEvent::KEYCODE_NUMPAD_ADD, "KEYCODE_NUMPAD_ADD"}, + {KeyEvent::KEYCODE_NUMPAD_DOT, "KEYCODE_NUMPAD_DOT"}, + {KeyEvent::KEYCODE_NUMPAD_COMMA, "KEYCODE_NUMPAD_COMMA"}, + {KeyEvent::KEYCODE_NUMPAD_ENTER, "KEYCODE_NUMPAD_ENTER"}, + {KeyEvent::KEYCODE_NUMPAD_EQUALS, "KEYCODE_NUMPAD_EQUALS"}, + {KeyEvent::KEYCODE_NUMPAD_LEFT_PAREN, "KEYCODE_NUMPAD_LEFT_PAREN"}, + {KeyEvent::KEYCODE_NUMPAD_RIGHT_PAREN, "KEYCODE_NUMPAD_RIGHT_PAREN"}, + {KeyEvent::KEYCODE_VIRTUAL_MULTITASK, "KEYCODE_VIRTUAL_MULTITASK"}, + {KeyEvent::KEYCODE_BUTTON_A, "KEYCODE_BUTTON_A"}, + {KeyEvent::KEYCODE_BUTTON_B, "KEYCODE_BUTTON_B"}, + {KeyEvent::KEYCODE_BUTTON_C, "KEYCODE_BUTTON_C"}, + {KeyEvent::KEYCODE_BUTTON_X, "KEYCODE_BUTTON_X"}, + {KeyEvent::KEYCODE_BUTTON_Y, "KEYCODE_BUTTON_Y"}, + {KeyEvent::KEYCODE_BUTTON_Z, "KEYCODE_BUTTON_Z"}, + {KeyEvent::KEYCODE_BUTTON_L1, "KEYCODE_BUTTON_L1"}, + {KeyEvent::KEYCODE_BUTTON_R1, "KEYCODE_BUTTON_R1"}, + {KeyEvent::KEYCODE_BUTTON_L2, "KEYCODE_BUTTON_L2"}, + {KeyEvent::KEYCODE_BUTTON_R2, "KEYCODE_BUTTON_R2"}, + {KeyEvent::KEYCODE_BUTTON_SELECT, "KEYCODE_BUTTON_SELECT"}, + {KeyEvent::KEYCODE_BUTTON_START, "KEYCODE_BUTTON_START"}, + {KeyEvent::KEYCODE_BUTTON_MODE, "KEYCODE_BUTTON_MODE"}, + {KeyEvent::KEYCODE_BUTTON_THUMBL, "KEYCODE_BUTTON_THUMBL"}, + {KeyEvent::KEYCODE_BUTTON_THUMBR, "KEYCODE_BUTTON_THUMBR"}, + {KeyEvent::KEYCODE_BUTTON_TRIGGER, "KEYCODE_BUTTON_TRIGGER"}, + {KeyEvent::KEYCODE_BUTTON_THUMB, "KEYCODE_BUTTON_THUMB"}, + {KeyEvent::KEYCODE_BUTTON_THUMB2, "KEYCODE_BUTTON_THUMB2"}, + {KeyEvent::KEYCODE_BUTTON_TOP, "KEYCODE_BUTTON_TOP"}, + {KeyEvent::KEYCODE_BUTTON_TOP2, "KEYCODE_BUTTON_TOP2"}, + {KeyEvent::KEYCODE_BUTTON_PINKIE, "KEYCODE_BUTTON_PINKIE"}, + {KeyEvent::KEYCODE_BUTTON_BASE1, "KEYCODE_BUTTON_BASE1"}, + {KeyEvent::KEYCODE_BUTTON_BASE2, "KEYCODE_BUTTON_BASE2"}, + {KeyEvent::KEYCODE_BUTTON_BASE3, "KEYCODE_BUTTON_BASE3"}, + {KeyEvent::KEYCODE_BUTTON_BASE4, "KEYCODE_BUTTON_BASE4"}, + {KeyEvent::KEYCODE_BUTTON_BASE5, "KEYCODE_BUTTON_BASE5"}, + {KeyEvent::KEYCODE_BUTTON_BASE6, "KEYCODE_BUTTON_BASE6"}, + {KeyEvent::KEYCODE_BUTTON_BASE7, "KEYCODE_BUTTON_BASE7"}, + {KeyEvent::KEYCODE_BUTTON_BASE8, "KEYCODE_BUTTON_BASE8"}, + {KeyEvent::KEYCODE_BUTTON_BASE9, "KEYCODE_BUTTON_BASE9"}, + {KeyEvent::KEYCODE_BUTTON_DEAD, "KEYCODE_BUTTON_DEAD"}, + {KeyEvent::KEYCODE_SLEEP, "KEYCODE_SLEEP"}, + {KeyEvent::KEYCODE_ZENKAKU_HANKAKU, "KEYCODE_ZENKAKU_HANKAKU"}, + {KeyEvent::KEYCODE_102ND, "KEYCODE_102ND"}, + {KeyEvent::KEYCODE_RO, "KEYCODE_RO"}, + {KeyEvent::KEYCODE_KATAKANA, "KEYCODE_KATAKANA"}, + {KeyEvent::KEYCODE_HIRAGANA, "KEYCODE_HIRAGANA"}, + {KeyEvent::KEYCODE_HENKAN, "KEYCODE_HENKAN"}, + {KeyEvent::KEYCODE_KATAKANA_HIRAGANA, "KEYCODE_KATAKANA_HIRAGANA"}, + {KeyEvent::KEYCODE_MUHENKAN, "KEYCODE_MUHENKAN"}, + {KeyEvent::KEYCODE_LINEFEED, "KEYCODE_LINEFEED"}, + {KeyEvent::KEYCODE_MACRO, "KEYCODE_MACRO"}, + {KeyEvent::KEYCODE_NUMPAD_PLUSMINUS, "KEYCODE_NUMPAD_PLUSMINUS"}, + {KeyEvent::KEYCODE_SCALE, "KEYCODE_SCALE"}, + {KeyEvent::KEYCODE_HANGUEL, "KEYCODE_HANGUEL"}, + {KeyEvent::KEYCODE_HANJA, "KEYCODE_HANJA"}, + {KeyEvent::KEYCODE_YEN, "KEYCODE_YEN"}, + {KeyEvent::KEYCODE_STOP, "KEYCODE_STOP"}, + {KeyEvent::KEYCODE_AGAIN, "KEYCODE_AGAIN"}, + {KeyEvent::KEYCODE_PROPS, "KEYCODE_PROPS"}, + {KeyEvent::KEYCODE_UNDO, "KEYCODE_UNDO"}, + {KeyEvent::KEYCODE_COPY, "KEYCODE_COPY"}, + {KeyEvent::KEYCODE_OPEN, "KEYCODE_OPEN"}, + {KeyEvent::KEYCODE_PASTE, "KEYCODE_PASTE"}, + {KeyEvent::KEYCODE_FIND, "KEYCODE_FIND"}, + {KeyEvent::KEYCODE_CUT, "KEYCODE_CUT"}, + {KeyEvent::KEYCODE_HELP, "KEYCODE_HELP"}, + {KeyEvent::KEYCODE_CALC, "KEYCODE_CALC"}, + {KeyEvent::KEYCODE_FILE, "KEYCODE_FILE"}, + {KeyEvent::KEYCODE_BOOKMARKS, "KEYCODE_BOOKMARKS"}, + {KeyEvent::KEYCODE_NEXT, "KEYCODE_NEXT"}, + {KeyEvent::KEYCODE_PLAYPAUSE, "KEYCODE_PLAYPAUSE"}, + {KeyEvent::KEYCODE_PREVIOUS, "KEYCODE_PREVIOUS"}, + {KeyEvent::KEYCODE_STOPCD, "KEYCODE_STOPCD"}, + {KeyEvent::KEYCODE_CONFIG, "KEYCODE_CONFIG"}, + {KeyEvent::KEYCODE_REFRESH, "KEYCODE_REFRESH"}, + {KeyEvent::KEYCODE_EXIT, "KEYCODE_EXIT"}, + {KeyEvent::KEYCODE_EDIT, "KEYCODE_EDIT"}, + {KeyEvent::KEYCODE_SCROLLUP, "KEYCODE_SCROLLUP"}, + {KeyEvent::KEYCODE_SCROLLDOWN, "KEYCODE_SCROLLDOWN"}, + {KeyEvent::KEYCODE_NEW, "KEYCODE_NEW"}, + {KeyEvent::KEYCODE_REDO, "KEYCODE_REDO"}, + {KeyEvent::KEYCODE_CLOSE, "KEYCODE_CLOSE"}, + {KeyEvent::KEYCODE_PLAY, "KEYCODE_PLAY"}, + {KeyEvent::KEYCODE_BASSBOOST, "KEYCODE_BASSBOOST"}, + {KeyEvent::KEYCODE_PRINT, "KEYCODE_PRINT"}, + {KeyEvent::KEYCODE_CHAT, "KEYCODE_CHAT"}, + {KeyEvent::KEYCODE_FINANCE, "KEYCODE_FINANCE"}, + {KeyEvent::KEYCODE_CANCEL, "KEYCODE_CANCEL"}, + {KeyEvent::KEYCODE_KBDILLUM_TOGGLE, "KEYCODE_KBDILLUM_TOGGLE"}, + {KeyEvent::KEYCODE_KBDILLUM_DOWN, "KEYCODE_KBDILLUM_DOWN"}, + {KeyEvent::KEYCODE_KBDILLUM_UP, "KEYCODE_KBDILLUM_UP"}, + {KeyEvent::KEYCODE_SEND, "KEYCODE_SEND"}, + {KeyEvent::KEYCODE_REPLY, "KEYCODE_REPLY"}, + {KeyEvent::KEYCODE_FORWARDMAIL, "KEYCODE_FORWARDMAIL"}, + {KeyEvent::KEYCODE_SAVE, "KEYCODE_SAVE"}, + {KeyEvent::KEYCODE_DOCUMENTS, "KEYCODE_DOCUMENTS"}, + {KeyEvent::KEYCODE_VIDEO_NEXT, "KEYCODE_VIDEO_NEXT"}, + {KeyEvent::KEYCODE_VIDEO_PREV, "KEYCODE_VIDEO_PREV"}, + {KeyEvent::KEYCODE_BRIGHTNESS_CYCLE, "KEYCODE_BRIGHTNESS_CYCLE"}, + {KeyEvent::KEYCODE_BRIGHTNESS_ZERO, "KEYCODE_BRIGHTNESS_ZERO"}, + {KeyEvent::KEYCODE_DISPLAY_OFF, "KEYCODE_DISPLAY_OFF"}, + {KeyEvent::KEYCODE_BTN_MISC, "KEYCODE_BTN_MISC"}, + {KeyEvent::KEYCODE_GOTO, "KEYCODE_GOTO"}, + {KeyEvent::KEYCODE_INFO, "KEYCODE_INFO"}, + {KeyEvent::KEYCODE_PROGRAM, "KEYCODE_PROGRAM"}, + {KeyEvent::KEYCODE_PVR, "KEYCODE_PVR"}, + {KeyEvent::KEYCODE_SUBTITLE, "KEYCODE_SUBTITLE"}, + {KeyEvent::KEYCODE_FULL_SCREEN, "KEYCODE_FULL_SCREEN"}, + {KeyEvent::KEYCODE_KEYBOARD, "KEYCODE_KEYBOARD"}, + {KeyEvent::KEYCODE_ASPECT_RATIO, "KEYCODE_ASPECT_RATIO"}, + {KeyEvent::KEYCODE_PC, "KEYCODE_PC"}, + {KeyEvent::KEYCODE_TV, "KEYCODE_TV"}, + {KeyEvent::KEYCODE_TV2, "KEYCODE_TV2"}, + {KeyEvent::KEYCODE_VCR, "KEYCODE_VCR"}, + {KeyEvent::KEYCODE_VCR2, "KEYCODE_VCR2"}, + {KeyEvent::KEYCODE_SAT, "KEYCODE_SAT"}, + {KeyEvent::KEYCODE_CD, "KEYCODE_CD"}, + {KeyEvent::KEYCODE_TAPE, "KEYCODE_TAPE"}, + {KeyEvent::KEYCODE_TUNER, "KEYCODE_TUNER"}, + {KeyEvent::KEYCODE_PLAYER, "KEYCODE_PLAYER"}, + {KeyEvent::KEYCODE_DVD, "KEYCODE_DVD"}, + {KeyEvent::KEYCODE_AUDIO, "KEYCODE_AUDIO"}, + {KeyEvent::KEYCODE_VIDEO, "KEYCODE_VIDEO"}, + {KeyEvent::KEYCODE_MEMO, "KEYCODE_MEMO"}, + {KeyEvent::KEYCODE_CALENDAR, "KEYCODE_CALENDAR"}, + {KeyEvent::KEYCODE_RED, "KEYCODE_RED"}, + {KeyEvent::KEYCODE_GREEN, "KEYCODE_GREEN"}, + {KeyEvent::KEYCODE_YELLOW, "KEYCODE_YELLOW"}, + {KeyEvent::KEYCODE_BLUE, "KEYCODE_BLUE"}, + {KeyEvent::KEYCODE_CHANNELUP, "KEYCODE_CHANNELUP"}, + {KeyEvent::KEYCODE_CHANNELDOWN, "KEYCODE_CHANNELDOWN"}, + {KeyEvent::KEYCODE_LAST, "KEYCODE_LAST"}, + {KeyEvent::KEYCODE_RESTART, "KEYCODE_RESTART"}, + {KeyEvent::KEYCODE_SLOW, "KEYCODE_SLOW"}, + {KeyEvent::KEYCODE_SHUFFLE, "KEYCODE_SHUFFLE"}, + {KeyEvent::KEYCODE_VIDEOPHONE, "KEYCODE_VIDEOPHONE"}, + {KeyEvent::KEYCODE_GAMES, "KEYCODE_GAMES"}, + {KeyEvent::KEYCODE_ZOOMIN, "KEYCODE_ZOOMIN"}, + {KeyEvent::KEYCODE_ZOOMOUT, "KEYCODE_ZOOMOUT"}, + {KeyEvent::KEYCODE_ZOOMRESET, "KEYCODE_ZOOMRESET"}, + {KeyEvent::KEYCODE_WORDPROCESSOR, "KEYCODE_WORDPROCESSOR"}, + {KeyEvent::KEYCODE_EDITOR, "KEYCODE_EDITOR"}, + {KeyEvent::KEYCODE_SPREADSHEET, "KEYCODE_SPREADSHEET"}, + {KeyEvent::KEYCODE_GRAPHICSEDITOR, "KEYCODE_GRAPHICSEDITOR"}, + {KeyEvent::KEYCODE_PRESENTATION, "KEYCODE_PRESENTATION"}, + {KeyEvent::KEYCODE_DATABASE, "KEYCODE_DATABASE"}, + {KeyEvent::KEYCODE_NEWS, "KEYCODE_NEWS"}, + {KeyEvent::KEYCODE_VOICEMAIL, "KEYCODE_VOICEMAIL"}, + {KeyEvent::KEYCODE_ADDRESSBOOK, "KEYCODE_ADDRESSBOOK"}, + {KeyEvent::KEYCODE_MESSENGER, "KEYCODE_MESSENGER"}, + {KeyEvent::KEYCODE_BRIGHTNESS_TOGGLE, "KEYCODE_BRIGHTNESS_TOGGLE"}, + {KeyEvent::KEYCODE_SPELLCHECK, "KEYCODE_SPELLCHECK"}, + {KeyEvent::KEYCODE_COFFEE, "KEYCODE_COFFEE"}, + {KeyEvent::KEYCODE_MEDIA_REPEAT, "KEYCODE_MEDIA_REPEAT"}, + {KeyEvent::KEYCODE_IMAGES, "KEYCODE_IMAGES"}, + {KeyEvent::KEYCODE_BUTTONCONFIG, "KEYCODE_BUTTONCONFIG"}, + {KeyEvent::KEYCODE_TASKMANAGER, "KEYCODE_TASKMANAGER"}, + {KeyEvent::KEYCODE_JOURNAL, "KEYCODE_JOURNAL"}, + {KeyEvent::KEYCODE_CONTROLPANEL, "KEYCODE_CONTROLPANEL"}, + {KeyEvent::KEYCODE_APPSELECT, "KEYCODE_APPSELECT"}, + {KeyEvent::KEYCODE_SCREENSAVER, "KEYCODE_SCREENSAVER"}, + {KeyEvent::KEYCODE_ASSISTANT, "KEYCODE_ASSISTANT"}, + {KeyEvent::KEYCODE_KBD_LAYOUT_NEXT, "KEYCODE_KBD_LAYOUT_NEXT"}, + {KeyEvent::KEYCODE_BRIGHTNESS_MIN, "KEYCODE_BRIGHTNESS_MIN"}, + {KeyEvent::KEYCODE_BRIGHTNESS_MAX, "KEYCODE_BRIGHTNESS_MAX"}, + {KeyEvent::KEYCODE_KBDINPUTASSIST_PREV, "KEYCODE_KBDINPUTASSIST_PREV"}, + {KeyEvent::KEYCODE_KBDINPUTASSIST_NEXT, "KEYCODE_KBDINPUTASSIST_NEXT"}, + {KeyEvent::KEYCODE_KBDINPUTASSIST_PREVGROUP, "KEYCODE_KBDINPUTASSIST_PREVGROUP"}, + {KeyEvent::KEYCODE_KBDINPUTASSIST_NEXTGROUP, "KEYCODE_KBDINPUTASSIST_NEXTGROUP"}, + {KeyEvent::KEYCODE_KBDINPUTASSIST_ACCEPT, "KEYCODE_KBDINPUTASSIST_ACCEPT"}, + {KeyEvent::KEYCODE_KBDINPUTASSIST_CANCEL, "KEYCODE_KBDINPUTASSIST_CANCEL"}, + {KeyEvent::KEYCODE_FRONT, "KEYCODE_FRONT"}, + {KeyEvent::KEYCODE_SETUP, "KEYCODE_SETUP"}, + {KeyEvent::KEYCODE_WAKEUP, "KEYCODE_WAKEUP"}, + {KeyEvent::KEYCODE_SENDFILE, "KEYCODE_SENDFILE"}, + {KeyEvent::KEYCODE_DELETEFILE, "KEYCODE_DELETEFILE"}, + {KeyEvent::KEYCODE_XFER, "KEYCODE_XFER"}, + {KeyEvent::KEYCODE_PROG1, "KEYCODE_PROG1"}, + {KeyEvent::KEYCODE_PROG2, "KEYCODE_PROG2"}, + {KeyEvent::KEYCODE_MSDOS, "KEYCODE_MSDOS"}, + {KeyEvent::KEYCODE_SCREENLOCK, "KEYCODE_SCREENLOCK"}, + {KeyEvent::KEYCODE_DIRECTION_ROTATE_DISPLAY, "KEYCODE_DIRECTION_ROTATE_DISPLAY"}, + {KeyEvent::KEYCODE_CYCLEWINDOWS, "KEYCODE_CYCLEWINDOWS"}, + {KeyEvent::KEYCODE_COMPUTER, "KEYCODE_COMPUTER"}, + {KeyEvent::KEYCODE_EJECTCLOSECD, "KEYCODE_EJECTCLOSECD"}, + {KeyEvent::KEYCODE_ISO, "KEYCODE_ISO"}, + {KeyEvent::KEYCODE_MOVE, "KEYCODE_MOVE"}, + {KeyEvent::KEYCODE_F13, "KEYCODE_F13"}, + {KeyEvent::KEYCODE_F14, "KEYCODE_F14"}, + {KeyEvent::KEYCODE_F15, "KEYCODE_F15"}, + {KeyEvent::KEYCODE_F16, "KEYCODE_F16"}, + {KeyEvent::KEYCODE_F17, "KEYCODE_F17"}, + {KeyEvent::KEYCODE_F18, "KEYCODE_F18"}, + {KeyEvent::KEYCODE_F19, "KEYCODE_F19"}, + {KeyEvent::KEYCODE_F20, "KEYCODE_F20"}, + {KeyEvent::KEYCODE_F21, "KEYCODE_F21"}, + {KeyEvent::KEYCODE_F22, "KEYCODE_F22"}, + {KeyEvent::KEYCODE_F23, "KEYCODE_F23"}, + {KeyEvent::KEYCODE_F24, "KEYCODE_F24"}, + {KeyEvent::KEYCODE_PROG3, "KEYCODE_PROG3"}, + {KeyEvent::KEYCODE_PROG4, "KEYCODE_PROG4"}, + {KeyEvent::KEYCODE_DASHBOARD, "KEYCODE_DASHBOARD"}, + {KeyEvent::KEYCODE_SUSPEND, "KEYCODE_SUSPEND"}, + {KeyEvent::KEYCODE_HP, "KEYCODE_HP"}, + {KeyEvent::KEYCODE_SOUND, "KEYCODE_SOUND"}, + {KeyEvent::KEYCODE_QUESTION, "KEYCODE_QUESTION"}, + {KeyEvent::KEYCODE_CONNECT, "KEYCODE_CONNECT"}, + {KeyEvent::KEYCODE_SPORT, "KEYCODE_SPORT"}, + {KeyEvent::KEYCODE_SHOP, "KEYCODE_SHOP"}, + {KeyEvent::KEYCODE_ALTERASE, "KEYCODE_ALTERASE"}, + {KeyEvent::KEYCODE_SWITCHVIDEOMODE, "KEYCODE_SWITCHVIDEOMODE"}, + {KeyEvent::KEYCODE_BATTERY, "KEYCODE_BATTERY"}, + {KeyEvent::KEYCODE_BLUETOOTH, "KEYCODE_BLUETOOTH"}, + {KeyEvent::KEYCODE_WLAN, "KEYCODE_WLAN"}, + {KeyEvent::KEYCODE_UWB, "KEYCODE_UWB"}, + {KeyEvent::KEYCODE_WWAN_WIMAX, "KEYCODE_WWAN_WIMAX"}, + {KeyEvent::KEYCODE_RFKILL, "KEYCODE_RFKILL"}, + {KeyEvent::KEYCODE_CHANNEL, "KEYCODE_CHANNEL"}, + {KeyEvent::KEYCODE_BTN_0, "KEYCODE_BTN_0"}, + {KeyEvent::KEYCODE_BTN_1, "KEYCODE_BTN_1"}, + {KeyEvent::KEYCODE_BTN_2, "KEYCODE_BTN_2"}, + {KeyEvent::KEYCODE_BTN_3, "KEYCODE_BTN_3"}, + {KeyEvent::KEYCODE_BTN_4, "KEYCODE_BTN_4"}, + {KeyEvent::KEYCODE_BTN_5, "KEYCODE_BTN_5"}, + {KeyEvent::KEYCODE_BTN_6, "KEYCODE_BTN_6"}, + {KeyEvent::KEYCODE_BTN_7, "KEYCODE_BTN_7"}, + {KeyEvent::KEYCODE_BTN_8, "KEYCODE_BTN_8"}, + {KeyEvent::KEYCODE_BTN_9, "KEYCODE_BTN_9"}, + {KeyEvent::KEYCODE_BRL_DOT1, "KEYCODE_BRL_DOT1"}, + {KeyEvent::KEYCODE_BRL_DOT2, "KEYCODE_BRL_DOT2"}, + {KeyEvent::KEYCODE_BRL_DOT3, "KEYCODE_BRL_DOT3"}, + {KeyEvent::KEYCODE_BRL_DOT4, "KEYCODE_BRL_DOT4"}, + {KeyEvent::KEYCODE_BRL_DOT5, "KEYCODE_BRL_DOT5"}, + {KeyEvent::KEYCODE_BRL_DOT6, "KEYCODE_BRL_DOT6"}, + {KeyEvent::KEYCODE_BRL_DOT7, "KEYCODE_BRL_DOT7"}, + {KeyEvent::KEYCODE_BRL_DOT8, "KEYCODE_BRL_DOT8"}, + {KeyEvent::KEYCODE_BRL_DOT9, "KEYCODE_BRL_DOT9"}, + {KeyEvent::KEYCODE_BRL_DOT10, "KEYCODE_BRL_DOT10"}, + {KeyEvent::KEYCODE_LEFT_KNOB_ROLL_UP, "KEYCODE_LEFT_KNOB_ROLL_UP"}, + {KeyEvent::KEYCODE_LEFT_KNOB_ROLL_DOWN, "KEYCODE_LEFT_KNOB_ROLL_DOWN"}, + {KeyEvent::KEYCODE_LEFT_KNOB, "KEYCODE_LEFT_KNOB"}, + {KeyEvent::KEYCODE_RIGHT_KNOB_ROLL_UP, "KEYCODE_RIGHT_KNOB_ROLL_UP"}, + {KeyEvent::KEYCODE_RIGHT_KNOB_ROLL_DOWN, "KEYCODE_RIGHT_KNOB_ROLL_DOWN"}, + {KeyEvent::KEYCODE_RIGHT_KNOB, "KEYCODE_RIGHT_KNOB"}, + {KeyEvent::KEYCODE_VOICE_SOURCE_SWITCH, "KEYCODE_VOICE_SOURCE_SWITCH"}, + {KeyEvent::KEYCODE_LAUNCHER_MENU, "KEYCODE_LAUNCHER_MENU"}, +}; } // namespace -const int32_t KeyEvent::UNKOWN_FUNCTION_KEY = -1; +const int32_t KeyEvent::UNKNOWN_FUNCTION_KEY = -1; const int32_t KeyEvent::NUM_LOCK_FUNCTION_KEY = 0; const int32_t KeyEvent::CAPS_LOCK_FUNCTION_KEY = 1; const int32_t KeyEvent::SCROLL_LOCK_FUNCTION_KEY = 2; @@ -211,6 +602,7 @@ const int32_t KeyEvent::KEYCODE_BUTTON_BASE7 = 2413; const int32_t KeyEvent::KEYCODE_BUTTON_BASE8 = 2414; const int32_t KeyEvent::KEYCODE_BUTTON_BASE9 = 2415; const int32_t KeyEvent::KEYCODE_BUTTON_DEAD = 2416; +const int32_t KeyEvent::KEYCODE_COMPOSE = 2466; const int32_t KeyEvent::KEYCODE_SLEEP = 2600; const int32_t KeyEvent::KEYCODE_ZENKAKU_HANKAKU = 2601; const int32_t KeyEvent::KEYCODE_102ND = 2602; @@ -424,6 +816,38 @@ const int32_t KeyEvent::KEY_ACTION_CANCEL = 0X00000001; const int32_t KeyEvent::KEY_ACTION_DOWN = 0x00000002; const int32_t KeyEvent::KEY_ACTION_UP = 0X00000003; +const int32_t KeyEvent::INTENTION_UNKNOWN = -1; +const int32_t KeyEvent::INTENTION_UP = 1; +const int32_t KeyEvent::INTENTION_DOWN = 2; +const int32_t KeyEvent::INTENTION_LEFT = 3; +const int32_t KeyEvent::INTENTION_RIGHT = 4; +const int32_t KeyEvent::INTENTION_SELECT = 5; +const int32_t KeyEvent::INTENTION_ESCAPE = 6; +const int32_t KeyEvent::INTENTION_BACK = 7; +const int32_t KeyEvent::INTENTION_FORWARD = 8; +const int32_t KeyEvent::INTENTION_MENU = 9; +const int32_t KeyEvent::INTENTION_HOME = 10; +const int32_t KeyEvent::INTENTION_PAGE_UP = 11; +const int32_t KeyEvent::INTENTION_PAGE_DOWN = 12; +const int32_t KeyEvent::INTENTION_ZOOM_OUT = 13; +const int32_t KeyEvent::INTENTION_ZOOM_IN = 14; + +const int32_t KeyEvent::INTENTION_MEDIA_PLAY_PAUSE = 100; +const int32_t KeyEvent::INTENTION_MEDIA_FAST_FORWARD = 101; +const int32_t KeyEvent::INTENTION_MEDIA_FAST_REWIND = 102; +const int32_t KeyEvent::INTENTION_MEDIA_FAST_PLAYBACK = 103; +const int32_t KeyEvent::INTENTION_MEDIA_NEXT = 104; +const int32_t KeyEvent::INTENTION_MEDIA_PREVIOUS = 105; +const int32_t KeyEvent::INTENTION_MEDIA_MUTE = 106; +const int32_t KeyEvent::INTENTION_VOLUTE_UP = 107; +const int32_t KeyEvent::INTENTION_VOLUTE_DOWN = 108; + +const int32_t KeyEvent::INTENTION_CALL = 200; +const int32_t KeyEvent::INTENTION_ENDCALL = 201; +const int32_t KeyEvent::INTENTION_REJECTCALL = 202; + +const int32_t KeyEvent::INTENTION_CAMERA = 300; + KeyEvent::KeyItem::KeyItem() {} KeyEvent::KeyItem::~KeyItem() {} @@ -509,7 +933,8 @@ KeyEvent::KeyEvent(const KeyEvent& other) : InputEvent(other), keyCode_(other.keyCode_), keys_(other.keys_), - keyAction_(other.keyAction_) {} + keyAction_(other.keyAction_), + keyIntention_(other.keyIntention_) {} KeyEvent::~KeyEvent() {} @@ -573,29 +998,31 @@ void KeyEvent::AddPressedKeyItems(const KeyItem& keyItem) void KeyEvent::RemoveReleasedKeyItems(const KeyItem& keyItem) { + if (keyItem.IsPressed()) { + return; + } int32_t keyCode = keyItem.GetKeyCode(); - std::vector tempKeyItems = keys_; - keys_.clear(); - for (const auto &item : tempKeyItems) { - if (item.GetKeyCode() != keyCode) { - keys_.push_back(item); + for (auto it = keys_.begin(); it != keys_.end(); ++it) { + if (it->GetKeyCode() == keyCode) { + keys_.erase(it); + return; } } } -const KeyEvent::KeyItem* KeyEvent::GetKeyItem() const +std::optional KeyEvent::GetKeyItem() const { return GetKeyItem(keyCode_); } -const KeyEvent::KeyItem* KeyEvent::GetKeyItem(int32_t keyCode) const +std::optional KeyEvent::GetKeyItem(int32_t keyCode) const { for (const auto &item : keys_) { if (item.GetKeyCode() == keyCode) { - return &item; + return std::make_optional(item); } } - return nullptr; + return std::nullopt; } const char* KeyEvent::ActionToString(int32_t action) @@ -622,399 +1049,8 @@ const char* KeyEvent::ActionToString(int32_t action) const char* KeyEvent::KeyCodeToString(int32_t keyCode) { CALL_DEBUG_ENTER; - static const std::map keyCodeToString = { - {KEYCODE_FN, "KEYCODE_FN"}, - {KEYCODE_UNKNOWN, "KEYCODE_UNKNOWN"}, - {KEYCODE_HOME, "KEYCODE_HOME"}, - {KEYCODE_BACK, "KEYCODE_BACK"}, - {KEYCODE_CALL, "KEYCODE_CALL"}, - {KEYCODE_ENDCALL, "KEYCODE_ENDCALL"}, - {KEYCODE_CLEAR, "KEYCODE_CLEAR"}, - {KEYCODE_HEADSETHOOK, "KEYCODE_HEADSETHOOK"}, - {KEYCODE_FOCUS, "KEYCODE_FOCUS"}, - {KEYCODE_NOTIFICATION, "KEYCODE_NOTIFICATION"}, - {KEYCODE_SEARCH, "KEYCODE_SEARCH"}, - {KEYCODE_MEDIA_PLAY_PAUSE, "KEYCODE_MEDIA_PLAY_PAUSE"}, - {KEYCODE_MEDIA_STOP, "KEYCODE_MEDIA_STOP"}, - {KEYCODE_MEDIA_NEXT, "KEYCODE_MEDIA_NEXT"}, - {KEYCODE_MEDIA_PREVIOUS, "KEYCODE_MEDIA_PREVIOUS"}, - {KEYCODE_MEDIA_REWIND, "KEYCODE_MEDIA_REWIND"}, - {KEYCODE_MEDIA_FAST_FORWARD, "KEYCODE_MEDIA_FAST_FORWARD"}, - {KEYCODE_VOLUME_UP, "KEYCODE_VOLUME_UP"}, - {KEYCODE_VOLUME_DOWN, "KEYCODE_VOLUME_DOWN"}, - {KEYCODE_POWER, "KEYCODE_POWER"}, - {KEYCODE_CAMERA, "KEYCODE_CAMERA"}, - {KEYCODE_VOICE_ASSISTANT, "KEYCODE_VOICE_ASSISTANT"}, - {KEYCODE_CUSTOM1, "KEYCODE_CUSTOM1"}, - {KEYCODE_VOLUME_MUTE, "KEYCODE_VOLUME_MUTE"}, - {KEYCODE_MUTE, "KEYCODE_MUTE"}, - {KEYCODE_BRIGHTNESS_UP, "KEYCODE_BRIGHTNESS_UP"}, - {KEYCODE_BRIGHTNESS_DOWN, "KEYCODE_BRIGHTNESS_DOWN"}, - {KEYCODE_WEAR_1, "KEYCODE_WEAR_1"}, - {KEYCODE_0, "KEYCODE_0"}, - {KEYCODE_1, "KEYCODE_1"}, - {KEYCODE_2, "KEYCODE_2"}, - {KEYCODE_3, "KEYCODE_3"}, - {KEYCODE_4, "KEYCODE_4"}, - {KEYCODE_5, "KEYCODE_5"}, - {KEYCODE_6, "KEYCODE_6"}, - {KEYCODE_7, "KEYCODE_7"}, - {KEYCODE_8, "KEYCODE_8"}, - {KEYCODE_9, "KEYCODE_9"}, - {KEYCODE_STAR, "KEYCODE_STAR"}, - {KEYCODE_POUND, "KEYCODE_POUND"}, - {KEYCODE_DPAD_UP, "KEYCODE_DPAD_UP"}, - {KEYCODE_DPAD_DOWN, "KEYCODE_DPAD_DOWN"}, - {KEYCODE_DPAD_LEFT, "KEYCODE_DPAD_LEFT"}, - {KEYCODE_DPAD_RIGHT, "KEYCODE_DPAD_RIGHT"}, - {KEYCODE_DPAD_CENTER, "KEYCODE_DPAD_CENTER"}, - {KEYCODE_A, "KEYCODE_A"}, - {KEYCODE_B, "KEYCODE_B"}, - {KEYCODE_C, "KEYCODE_C"}, - {KEYCODE_D, "KEYCODE_D"}, - {KEYCODE_E, "KEYCODE_E"}, - {KEYCODE_F, "KEYCODE_F"}, - {KEYCODE_G, "KEYCODE_G"}, - {KEYCODE_H, "KEYCODE_H"}, - {KEYCODE_I, "KEYCODE_I"}, - {KEYCODE_J, "KEYCODE_J"}, - {KEYCODE_K, "KEYCODE_K"}, - {KEYCODE_L, "KEYCODE_L"}, - {KEYCODE_M, "KEYCODE_M"}, - {KEYCODE_N, "KEYCODE_N"}, - {KEYCODE_O, "KEYCODE_O"}, - {KEYCODE_P, "KEYCODE_P"}, - {KEYCODE_Q, "KEYCODE_Q"}, - {KEYCODE_R, "KEYCODE_R"}, - {KEYCODE_S, "KEYCODE_S"}, - {KEYCODE_T, "KEYCODE_T"}, - {KEYCODE_U, "KEYCODE_U"}, - {KEYCODE_V, "KEYCODE_V"}, - {KEYCODE_W, "KEYCODE_W"}, - {KEYCODE_X, "KEYCODE_X"}, - {KEYCODE_Y, "KEYCODE_Y"}, - {KEYCODE_Z, "KEYCODE_Z"}, - {KEYCODE_COMMA, "KEYCODE_COMMA"}, - {KEYCODE_PERIOD, "KEYCODE_PERIOD"}, - {KEYCODE_ALT_LEFT, "KEYCODE_ALT_LEFT"}, - {KEYCODE_ALT_RIGHT, "KEYCODE_ALT_RIGHT"}, - {KEYCODE_SHIFT_LEFT, "KEYCODE_SHIFT_LEFT"}, - {KEYCODE_SHIFT_RIGHT, "KEYCODE_SHIFT_RIGHT"}, - {KEYCODE_TAB, "KEYCODE_TAB"}, - {KEYCODE_SPACE, "KEYCODE_SPACE"}, - {KEYCODE_SYM, "KEYCODE_SYM"}, - {KEYCODE_EXPLORER, "KEYCODE_EXPLORER"}, - {KEYCODE_ENVELOPE, "KEYCODE_ENVELOPE"}, - {KEYCODE_ENTER, "KEYCODE_ENTER"}, - {KEYCODE_DEL, "KEYCODE_DEL"}, - {KEYCODE_GRAVE, "KEYCODE_GRAVE"}, - {KEYCODE_MINUS, "KEYCODE_MINUS"}, - {KEYCODE_EQUALS, "KEYCODE_EQUALS"}, - {KEYCODE_LEFT_BRACKET, "KEYCODE_LEFT_BRACKET"}, - {KEYCODE_RIGHT_BRACKET, "KEYCODE_RIGHT_BRACKET"}, - {KEYCODE_BACKSLASH, "KEYCODE_BACKSLASH"}, - {KEYCODE_SEMICOLON, "KEYCODE_SEMICOLON"}, - {KEYCODE_APOSTROPHE, "KEYCODE_APOSTROPHE"}, - {KEYCODE_SLASH, "KEYCODE_SLASH"}, - {KEYCODE_AT, "KEYCODE_AT"}, - {KEYCODE_PLUS, "KEYCODE_PLUS"}, - {KEYCODE_MENU, "KEYCODE_MENU"}, - {KEYCODE_PAGE_UP, "KEYCODE_PAGE_UP"}, - {KEYCODE_PAGE_DOWN, "KEYCODE_PAGE_DOWN"}, - {KEYCODE_ESCAPE, "KEYCODE_ESCAPE"}, - {KEYCODE_FORWARD_DEL, "KEYCODE_FORWARD_DEL"}, - {KEYCODE_CTRL_LEFT, "KEYCODE_CTRL_LEFT"}, - {KEYCODE_CTRL_RIGHT, "KEYCODE_CTRL_RIGHT"}, - {KEYCODE_CAPS_LOCK, "KEYCODE_CAPS_LOCK"}, - {KEYCODE_SCROLL_LOCK, "KEYCODE_SCROLL_LOCK"}, - {KEYCODE_META_LEFT, "KEYCODE_META_LEFT"}, - {KEYCODE_META_RIGHT, "KEYCODE_META_RIGHT"}, - {KEYCODE_FUNCTION, "KEYCODE_FUNCTION"}, - {KEYCODE_SYSRQ, "KEYCODE_SYSRQ"}, - {KEYCODE_BREAK, "KEYCODE_BREAK"}, - {KEYCODE_MOVE_HOME, "KEYCODE_MOVE_HOME"}, - {KEYCODE_MOVE_END, "KEYCODE_MOVE_END"}, - {KEYCODE_INSERT, "KEYCODE_INSERT"}, - {KEYCODE_FORWARD, "KEYCODE_FORWARD"}, - {KEYCODE_MEDIA_PLAY, "KEYCODE_MEDIA_PLAY"}, - {KEYCODE_MEDIA_PAUSE, "KEYCODE_MEDIA_PAUSE"}, - {KEYCODE_MEDIA_CLOSE, "KEYCODE_MEDIA_CLOSE"}, - {KEYCODE_MEDIA_EJECT, "KEYCODE_MEDIA_EJECT"}, - {KEYCODE_MEDIA_RECORD, "KEYCODE_MEDIA_RECORD"}, - {KEYCODE_F1, "KEYCODE_F1"}, - {KEYCODE_F2, "KEYCODE_F2"}, - {KEYCODE_F3, "KEYCODE_F3"}, - {KEYCODE_F4, "KEYCODE_F4"}, - {KEYCODE_F5, "KEYCODE_F5"}, - {KEYCODE_F6, "KEYCODE_F6"}, - {KEYCODE_F7, "KEYCODE_F7"}, - {KEYCODE_F8, "KEYCODE_F8"}, - {KEYCODE_F9, "KEYCODE_F9"}, - {KEYCODE_F10, "KEYCODE_F10"}, - {KEYCODE_F11, "KEYCODE_F11"}, - {KEYCODE_F12, "KEYCODE_F12"}, - {KEYCODE_NUM_LOCK, "KEYCODE_NUM_LOCK"}, - {KEYCODE_NUMPAD_0, "KEYCODE_NUMPAD_0"}, - {KEYCODE_NUMPAD_1, "KEYCODE_NUMPAD_1"}, - {KEYCODE_NUMPAD_2, "KEYCODE_NUMPAD_2"}, - {KEYCODE_NUMPAD_3, "KEYCODE_NUMPAD_3"}, - {KEYCODE_NUMPAD_4, "KEYCODE_NUMPAD_4"}, - {KEYCODE_NUMPAD_5, "KEYCODE_NUMPAD_5"}, - {KEYCODE_NUMPAD_6, "KEYCODE_NUMPAD_6"}, - {KEYCODE_NUMPAD_7, "KEYCODE_NUMPAD_7"}, - {KEYCODE_NUMPAD_8, "KEYCODE_NUMPAD_8"}, - {KEYCODE_NUMPAD_9, "KEYCODE_NUMPAD_9"}, - {KEYCODE_NUMPAD_DIVIDE, "KEYCODE_NUMPAD_DIVIDE"}, - {KEYCODE_NUMPAD_MULTIPLY, "KEYCODE_NUMPAD_MULTIPLY"}, - {KEYCODE_NUMPAD_SUBTRACT, "KEYCODE_NUMPAD_SUBTRACT"}, - {KEYCODE_NUMPAD_ADD, "KEYCODE_NUMPAD_ADD"}, - {KEYCODE_NUMPAD_DOT, "KEYCODE_NUMPAD_DOT"}, - {KEYCODE_NUMPAD_COMMA, "KEYCODE_NUMPAD_COMMA"}, - {KEYCODE_NUMPAD_ENTER, "KEYCODE_NUMPAD_ENTER"}, - {KEYCODE_NUMPAD_EQUALS, "KEYCODE_NUMPAD_EQUALS"}, - {KEYCODE_NUMPAD_LEFT_PAREN, "KEYCODE_NUMPAD_LEFT_PAREN"}, - {KEYCODE_NUMPAD_RIGHT_PAREN, "KEYCODE_NUMPAD_RIGHT_PAREN"}, - {KEYCODE_VIRTUAL_MULTITASK, "KEYCODE_VIRTUAL_MULTITASK"}, - {KEYCODE_BUTTON_A, "KEYCODE_BUTTON_A"}, - {KEYCODE_BUTTON_B, "KEYCODE_BUTTON_B"}, - {KEYCODE_BUTTON_C, "KEYCODE_BUTTON_C"}, - {KEYCODE_BUTTON_X, "KEYCODE_BUTTON_X"}, - {KEYCODE_BUTTON_Y, "KEYCODE_BUTTON_Y"}, - {KEYCODE_BUTTON_Z, "KEYCODE_BUTTON_Z"}, - {KEYCODE_BUTTON_L1, "KEYCODE_BUTTON_L1"}, - {KEYCODE_BUTTON_R1, "KEYCODE_BUTTON_R1"}, - {KEYCODE_BUTTON_L2, "KEYCODE_BUTTON_L2"}, - {KEYCODE_BUTTON_R2, "KEYCODE_BUTTON_R2"}, - {KEYCODE_BUTTON_SELECT, "KEYCODE_BUTTON_SELECT"}, - {KEYCODE_BUTTON_START, "KEYCODE_BUTTON_START"}, - {KEYCODE_BUTTON_MODE, "KEYCODE_BUTTON_MODE"}, - {KEYCODE_BUTTON_THUMBL, "KEYCODE_BUTTON_THUMBL"}, - {KEYCODE_BUTTON_THUMBR, "KEYCODE_BUTTON_THUMBR"}, - {KEYCODE_BUTTON_TRIGGER, "KEYCODE_BUTTON_TRIGGER"}, - {KEYCODE_BUTTON_THUMB, "KEYCODE_BUTTON_THUMB"}, - {KEYCODE_BUTTON_THUMB2, "KEYCODE_BUTTON_THUMB2"}, - {KEYCODE_BUTTON_TOP, "KEYCODE_BUTTON_TOP"}, - {KEYCODE_BUTTON_TOP2, "KEYCODE_BUTTON_TOP2"}, - {KEYCODE_BUTTON_PINKIE, "KEYCODE_BUTTON_PINKIE"}, - {KEYCODE_BUTTON_BASE1, "KEYCODE_BUTTON_BASE1"}, - {KEYCODE_BUTTON_BASE2, "KEYCODE_BUTTON_BASE2"}, - {KEYCODE_BUTTON_BASE3, "KEYCODE_BUTTON_BASE3"}, - {KEYCODE_BUTTON_BASE4, "KEYCODE_BUTTON_BASE4"}, - {KEYCODE_BUTTON_BASE5, "KEYCODE_BUTTON_BASE5"}, - {KEYCODE_BUTTON_BASE6, "KEYCODE_BUTTON_BASE6"}, - {KEYCODE_BUTTON_BASE7, "KEYCODE_BUTTON_BASE7"}, - {KEYCODE_BUTTON_BASE8, "KEYCODE_BUTTON_BASE8"}, - {KEYCODE_BUTTON_BASE9, "KEYCODE_BUTTON_BASE9"}, - {KEYCODE_BUTTON_DEAD, "KEYCODE_BUTTON_DEAD"}, - {KEYCODE_SLEEP, "KEYCODE_SLEEP"}, - {KEYCODE_ZENKAKU_HANKAKU, "KEYCODE_ZENKAKU_HANKAKU"}, - {KEYCODE_102ND, "KEYCODE_102ND"}, - {KEYCODE_RO, "KEYCODE_RO"}, - {KEYCODE_KATAKANA, "KEYCODE_KATAKANA"}, - {KEYCODE_HIRAGANA, "KEYCODE_HIRAGANA"}, - {KEYCODE_HENKAN, "KEYCODE_HENKAN"}, - {KEYCODE_KATAKANA_HIRAGANA, "KEYCODE_KATAKANA_HIRAGANA"}, - {KEYCODE_MUHENKAN, "KEYCODE_MUHENKAN"}, - {KEYCODE_LINEFEED, "KEYCODE_LINEFEED"}, - {KEYCODE_MACRO, "KEYCODE_MACRO"}, - {KEYCODE_NUMPAD_PLUSMINUS, "KEYCODE_NUMPAD_PLUSMINUS"}, - {KEYCODE_SCALE, "KEYCODE_SCALE"}, - {KEYCODE_HANGUEL, "KEYCODE_HANGUEL"}, - {KEYCODE_HANJA, "KEYCODE_HANJA"}, - {KEYCODE_YEN, "KEYCODE_YEN"}, - {KEYCODE_STOP, "KEYCODE_STOP"}, - {KEYCODE_AGAIN, "KEYCODE_AGAIN"}, - {KEYCODE_PROPS, "KEYCODE_PROPS"}, - {KEYCODE_UNDO, "KEYCODE_UNDO"}, - {KEYCODE_COPY, "KEYCODE_COPY"}, - {KEYCODE_OPEN, "KEYCODE_OPEN"}, - {KEYCODE_PASTE, "KEYCODE_PASTE"}, - {KEYCODE_FIND, "KEYCODE_FIND"}, - {KEYCODE_CUT, "KEYCODE_CUT"}, - {KEYCODE_HELP, "KEYCODE_HELP"}, - {KEYCODE_CALC, "KEYCODE_CALC"}, - {KEYCODE_FILE, "KEYCODE_FILE"}, - {KEYCODE_BOOKMARKS, "KEYCODE_BOOKMARKS"}, - {KEYCODE_NEXT, "KEYCODE_NEXT"}, - {KEYCODE_PLAYPAUSE, "KEYCODE_PLAYPAUSE"}, - {KEYCODE_PREVIOUS, "KEYCODE_PREVIOUS"}, - {KEYCODE_STOPCD, "KEYCODE_STOPCD"}, - {KEYCODE_CONFIG, "KEYCODE_CONFIG"}, - {KEYCODE_REFRESH, "KEYCODE_REFRESH"}, - {KEYCODE_EXIT, "KEYCODE_EXIT"}, - {KEYCODE_EDIT, "KEYCODE_EDIT"}, - {KEYCODE_SCROLLUP, "KEYCODE_SCROLLUP"}, - {KEYCODE_SCROLLDOWN, "KEYCODE_SCROLLDOWN"}, - {KEYCODE_NEW, "KEYCODE_NEW"}, - {KEYCODE_REDO, "KEYCODE_REDO"}, - {KEYCODE_CLOSE, "KEYCODE_CLOSE"}, - {KEYCODE_PLAY, "KEYCODE_PLAY"}, - {KEYCODE_BASSBOOST, "KEYCODE_BASSBOOST"}, - {KEYCODE_PRINT, "KEYCODE_PRINT"}, - {KEYCODE_CHAT, "KEYCODE_CHAT"}, - {KEYCODE_FINANCE, "KEYCODE_FINANCE"}, - {KEYCODE_CANCEL, "KEYCODE_CANCEL"}, - {KEYCODE_KBDILLUM_TOGGLE, "KEYCODE_KBDILLUM_TOGGLE"}, - {KEYCODE_KBDILLUM_DOWN, "KEYCODE_KBDILLUM_DOWN"}, - {KEYCODE_KBDILLUM_UP, "KEYCODE_KBDILLUM_UP"}, - {KEYCODE_SEND, "KEYCODE_SEND"}, - {KEYCODE_REPLY, "KEYCODE_REPLY"}, - {KEYCODE_FORWARDMAIL, "KEYCODE_FORWARDMAIL"}, - {KEYCODE_SAVE, "KEYCODE_SAVE"}, - {KEYCODE_DOCUMENTS, "KEYCODE_DOCUMENTS"}, - {KEYCODE_VIDEO_NEXT, "KEYCODE_VIDEO_NEXT"}, - {KEYCODE_VIDEO_PREV, "KEYCODE_VIDEO_PREV"}, - {KEYCODE_BRIGHTNESS_CYCLE, "KEYCODE_BRIGHTNESS_CYCLE"}, - {KEYCODE_BRIGHTNESS_ZERO, "KEYCODE_BRIGHTNESS_ZERO"}, - {KEYCODE_DISPLAY_OFF, "KEYCODE_DISPLAY_OFF"}, - {KEYCODE_BTN_MISC, "KEYCODE_BTN_MISC"}, - {KEYCODE_GOTO, "KEYCODE_GOTO"}, - {KEYCODE_INFO, "KEYCODE_INFO"}, - {KEYCODE_PROGRAM, "KEYCODE_PROGRAM"}, - {KEYCODE_PVR, "KEYCODE_PVR"}, - {KEYCODE_SUBTITLE, "KEYCODE_SUBTITLE"}, - {KEYCODE_FULL_SCREEN, "KEYCODE_FULL_SCREEN"}, - {KEYCODE_KEYBOARD, "KEYCODE_KEYBOARD"}, - {KEYCODE_ASPECT_RATIO, "KEYCODE_ASPECT_RATIO"}, - {KEYCODE_PC, "KEYCODE_PC"}, - {KEYCODE_TV, "KEYCODE_TV"}, - {KEYCODE_TV2, "KEYCODE_TV2"}, - {KEYCODE_VCR, "KEYCODE_VCR"}, - {KEYCODE_VCR2, "KEYCODE_VCR2"}, - {KEYCODE_SAT, "KEYCODE_SAT"}, - {KEYCODE_CD, "KEYCODE_CD"}, - {KEYCODE_TAPE, "KEYCODE_TAPE"}, - {KEYCODE_TUNER, "KEYCODE_TUNER"}, - {KEYCODE_PLAYER, "KEYCODE_PLAYER"}, - {KEYCODE_DVD, "KEYCODE_DVD"}, - {KEYCODE_AUDIO, "KEYCODE_AUDIO"}, - {KEYCODE_VIDEO, "KEYCODE_VIDEO"}, - {KEYCODE_MEMO, "KEYCODE_MEMO"}, - {KEYCODE_CALENDAR, "KEYCODE_CALENDAR"}, - {KEYCODE_RED, "KEYCODE_RED"}, - {KEYCODE_GREEN, "KEYCODE_GREEN"}, - {KEYCODE_YELLOW, "KEYCODE_YELLOW"}, - {KEYCODE_BLUE, "KEYCODE_BLUE"}, - {KEYCODE_CHANNELUP, "KEYCODE_CHANNELUP"}, - {KEYCODE_CHANNELDOWN, "KEYCODE_CHANNELDOWN"}, - {KEYCODE_LAST, "KEYCODE_LAST"}, - {KEYCODE_RESTART, "KEYCODE_RESTART"}, - {KEYCODE_SLOW, "KEYCODE_SLOW"}, - {KEYCODE_SHUFFLE, "KEYCODE_SHUFFLE"}, - {KEYCODE_VIDEOPHONE, "KEYCODE_VIDEOPHONE"}, - {KEYCODE_GAMES, "KEYCODE_GAMES"}, - {KEYCODE_ZOOMIN, "KEYCODE_ZOOMIN"}, - {KEYCODE_ZOOMOUT, "KEYCODE_ZOOMOUT"}, - {KEYCODE_ZOOMRESET, "KEYCODE_ZOOMRESET"}, - {KEYCODE_WORDPROCESSOR, "KEYCODE_WORDPROCESSOR"}, - {KEYCODE_EDITOR, "KEYCODE_EDITOR"}, - {KEYCODE_SPREADSHEET, "KEYCODE_SPREADSHEET"}, - {KEYCODE_GRAPHICSEDITOR, "KEYCODE_GRAPHICSEDITOR"}, - {KEYCODE_PRESENTATION, "KEYCODE_PRESENTATION"}, - {KEYCODE_DATABASE, "KEYCODE_DATABASE"}, - {KEYCODE_NEWS, "KEYCODE_NEWS"}, - {KEYCODE_VOICEMAIL, "KEYCODE_VOICEMAIL"}, - {KEYCODE_ADDRESSBOOK, "KEYCODE_ADDRESSBOOK"}, - {KEYCODE_MESSENGER, "KEYCODE_MESSENGER"}, - {KEYCODE_BRIGHTNESS_TOGGLE, "KEYCODE_BRIGHTNESS_TOGGLE"}, - {KEYCODE_SPELLCHECK, "KEYCODE_SPELLCHECK"}, - {KEYCODE_COFFEE, "KEYCODE_COFFEE"}, - {KEYCODE_MEDIA_REPEAT, "KEYCODE_MEDIA_REPEAT"}, - {KEYCODE_IMAGES, "KEYCODE_IMAGES"}, - {KEYCODE_BUTTONCONFIG, "KEYCODE_BUTTONCONFIG"}, - {KEYCODE_TASKMANAGER, "KEYCODE_TASKMANAGER"}, - {KEYCODE_JOURNAL, "KEYCODE_JOURNAL"}, - {KEYCODE_CONTROLPANEL, "KEYCODE_CONTROLPANEL"}, - {KEYCODE_APPSELECT, "KEYCODE_APPSELECT"}, - {KEYCODE_SCREENSAVER, "KEYCODE_SCREENSAVER"}, - {KEYCODE_ASSISTANT, "KEYCODE_ASSISTANT"}, - {KEYCODE_KBD_LAYOUT_NEXT, "KEYCODE_KBD_LAYOUT_NEXT"}, - {KEYCODE_BRIGHTNESS_MIN, "KEYCODE_BRIGHTNESS_MIN"}, - {KEYCODE_BRIGHTNESS_MAX, "KEYCODE_BRIGHTNESS_MAX"}, - {KEYCODE_KBDINPUTASSIST_PREV, "KEYCODE_KBDINPUTASSIST_PREV"}, - {KEYCODE_KBDINPUTASSIST_NEXT, "KEYCODE_KBDINPUTASSIST_NEXT"}, - {KEYCODE_KBDINPUTASSIST_PREVGROUP, "KEYCODE_KBDINPUTASSIST_PREVGROUP"}, - {KEYCODE_KBDINPUTASSIST_NEXTGROUP, "KEYCODE_KBDINPUTASSIST_NEXTGROUP"}, - {KEYCODE_KBDINPUTASSIST_ACCEPT, "KEYCODE_KBDINPUTASSIST_ACCEPT"}, - {KEYCODE_KBDINPUTASSIST_CANCEL, "KEYCODE_KBDINPUTASSIST_CANCEL"}, - {KEYCODE_FRONT, "KEYCODE_FRONT"}, - {KEYCODE_SETUP, "KEYCODE_SETUP"}, - {KEYCODE_WAKEUP, "KEYCODE_WAKEUP"}, - {KEYCODE_SENDFILE, "KEYCODE_SENDFILE"}, - {KEYCODE_DELETEFILE, "KEYCODE_DELETEFILE"}, - {KEYCODE_XFER, "KEYCODE_XFER"}, - {KEYCODE_PROG1, "KEYCODE_PROG1"}, - {KEYCODE_PROG2, "KEYCODE_PROG2"}, - {KEYCODE_MSDOS, "KEYCODE_MSDOS"}, - {KEYCODE_SCREENLOCK, "KEYCODE_SCREENLOCK"}, - {KEYCODE_DIRECTION_ROTATE_DISPLAY, "KEYCODE_DIRECTION_ROTATE_DISPLAY"}, - {KEYCODE_CYCLEWINDOWS, "KEYCODE_CYCLEWINDOWS"}, - {KEYCODE_COMPUTER, "KEYCODE_COMPUTER"}, - {KEYCODE_EJECTCLOSECD, "KEYCODE_EJECTCLOSECD"}, - {KEYCODE_ISO, "KEYCODE_ISO"}, - {KEYCODE_MOVE, "KEYCODE_MOVE"}, - {KEYCODE_F13, "KEYCODE_F13"}, - {KEYCODE_F14, "KEYCODE_F14"}, - {KEYCODE_F15, "KEYCODE_F15"}, - {KEYCODE_F16, "KEYCODE_F16"}, - {KEYCODE_F17, "KEYCODE_F17"}, - {KEYCODE_F18, "KEYCODE_F18"}, - {KEYCODE_F19, "KEYCODE_F19"}, - {KEYCODE_F20, "KEYCODE_F20"}, - {KEYCODE_F21, "KEYCODE_F21"}, - {KEYCODE_F22, "KEYCODE_F22"}, - {KEYCODE_F23, "KEYCODE_F23"}, - {KEYCODE_F24, "KEYCODE_F24"}, - {KEYCODE_PROG3, "KEYCODE_PROG3"}, - {KEYCODE_PROG4, "KEYCODE_PROG4"}, - {KEYCODE_DASHBOARD, "KEYCODE_DASHBOARD"}, - {KEYCODE_SUSPEND, "KEYCODE_SUSPEND"}, - {KEYCODE_HP, "KEYCODE_HP"}, - {KEYCODE_SOUND, "KEYCODE_SOUND"}, - {KEYCODE_QUESTION, "KEYCODE_QUESTION"}, - {KEYCODE_CONNECT, "KEYCODE_CONNECT"}, - {KEYCODE_SPORT, "KEYCODE_SPORT"}, - {KEYCODE_SHOP, "KEYCODE_SHOP"}, - {KEYCODE_ALTERASE, "KEYCODE_ALTERASE"}, - {KEYCODE_SWITCHVIDEOMODE, "KEYCODE_SWITCHVIDEOMODE"}, - {KEYCODE_BATTERY, "KEYCODE_BATTERY"}, - {KEYCODE_BLUETOOTH, "KEYCODE_BLUETOOTH"}, - {KEYCODE_WLAN, "KEYCODE_WLAN"}, - {KEYCODE_UWB, "KEYCODE_UWB"}, - {KEYCODE_WWAN_WIMAX, "KEYCODE_WWAN_WIMAX"}, - {KEYCODE_RFKILL, "KEYCODE_RFKILL"}, - {KEYCODE_CHANNEL, "KEYCODE_CHANNEL"}, - {KEYCODE_BTN_0, "KEYCODE_BTN_0"}, - {KEYCODE_BTN_1, "KEYCODE_BTN_1"}, - {KEYCODE_BTN_2, "KEYCODE_BTN_2"}, - {KEYCODE_BTN_3, "KEYCODE_BTN_3"}, - {KEYCODE_BTN_4, "KEYCODE_BTN_4"}, - {KEYCODE_BTN_5, "KEYCODE_BTN_5"}, - {KEYCODE_BTN_6, "KEYCODE_BTN_6"}, - {KEYCODE_BTN_7, "KEYCODE_BTN_7"}, - {KEYCODE_BTN_8, "KEYCODE_BTN_8"}, - {KEYCODE_BTN_9, "KEYCODE_BTN_9"}, - {KEYCODE_BRL_DOT1, "KEYCODE_BRL_DOT1"}, - {KEYCODE_BRL_DOT2, "KEYCODE_BRL_DOT2"}, - {KEYCODE_BRL_DOT3, "KEYCODE_BRL_DOT3"}, - {KEYCODE_BRL_DOT4, "KEYCODE_BRL_DOT4"}, - {KEYCODE_BRL_DOT5, "KEYCODE_BRL_DOT5"}, - {KEYCODE_BRL_DOT6, "KEYCODE_BRL_DOT6"}, - {KEYCODE_BRL_DOT7, "KEYCODE_BRL_DOT7"}, - {KEYCODE_BRL_DOT8, "KEYCODE_BRL_DOT8"}, - {KEYCODE_BRL_DOT9, "KEYCODE_BRL_DOT9"}, - {KEYCODE_BRL_DOT10, "KEYCODE_BRL_DOT10"}, - {KEYCODE_LEFT_KNOB_ROLL_UP, "KEYCODE_LEFT_KNOB_ROLL_UP"}, - {KEYCODE_LEFT_KNOB_ROLL_DOWN, "KEYCODE_LEFT_KNOB_ROLL_DOWN"}, - {KEYCODE_LEFT_KNOB, "KEYCODE_LEFT_KNOB"}, - {KEYCODE_RIGHT_KNOB_ROLL_UP, "KEYCODE_RIGHT_KNOB_ROLL_UP"}, - {KEYCODE_RIGHT_KNOB_ROLL_DOWN, "KEYCODE_RIGHT_KNOB_ROLL_DOWN"}, - {KEYCODE_RIGHT_KNOB, "KEYCODE_RIGHT_KNOB"}, - {KEYCODE_VOICE_SOURCE_SWITCH, "KEYCODE_VOICE_SOURCE_SWITCH"}, - {KEYCODE_LAUNCHER_MENU, "KEYCODE_LAUNCHER_MENU"}, - }; - auto iter = keyCodeToString.find(keyCode); - if (iter == keyCodeToString.end()) { + auto iter = KEYCODE_TO_STRING.find(keyCode); + if (iter == KEYCODE_TO_STRING.end()) { MMI_HILOGD("Failed to find the keycode"); return "KEYCODE_INVALID"; } @@ -1125,7 +1161,7 @@ bool KeyEvent::WriteToParcel(Parcel &out) const } } WRITEINT32(out, keyAction_); - + WRITEINT32(out, keyIntention_); return true; } @@ -1147,7 +1183,7 @@ bool KeyEvent::ReadFromParcel(Parcel &in) keys_.push_back(val); } READINT32(in, keyAction_); - + READINT32(in, keyIntention_); return true; } @@ -1165,7 +1201,7 @@ int32_t KeyEvent::TransitionFunctionKey(int32_t keyCode) } default: { MMI_HILOGW("Unknown key code"); - return UNKOWN_FUNCTION_KEY; + return UNKNOWN_FUNCTION_KEY; } } } @@ -1207,9 +1243,19 @@ int32_t KeyEvent::SetFunctionKey(int32_t funcKey, int32_t value) } default: { MMI_HILOGW("Unknown function key"); - return UNKOWN_FUNCTION_KEY; + return UNKNOWN_FUNCTION_KEY; } } } + +int32_t KeyEvent::GetKeyIntention() const +{ + return keyIntention_; +} + +void KeyEvent::SetKeyIntention(int32_t keyIntention) +{ + keyIntention_ = keyIntention; +} } // namespace MMI } // namespace OHOS diff --git a/frameworks/proxy/events/src/key_option.cpp b/frameworks/proxy/events/src/key_option.cpp index 1461a3102c46eade10f7bd6eabc2a5ff03621514..46fe96b6d68e5d43be0c36ab460678520cb6ba7d 100644 --- a/frameworks/proxy/events/src/key_option.cpp +++ b/frameworks/proxy/events/src/key_option.cpp @@ -20,8 +20,8 @@ namespace OHOS { namespace MMI { namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "KeyOption"}; -constexpr int32_t PRE_KEYS_MAX_SIZE = 3; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "KeyOption" }; +constexpr int32_t PRE_KEYS_MAX_SIZE = 4; } std::set KeyOption::GetPreKeys() const { @@ -57,11 +57,21 @@ int32_t KeyOption::GetFinalKeyDownDuration() const return finalKeyDownDuration_; } +int32_t KeyOption::GetFinalKeyUpDelay() const +{ + return finalKeyUpDelay_; +} + void KeyOption::SetFinalKeyDownDuration(int32_t duration) { finalKeyDownDuration_ = duration; } +void KeyOption::SetFinalKeyUpDelay(int32_t delay) +{ + finalKeyUpDelay_ = delay; +} + bool KeyOption::ReadFromParcel(Parcel &in) { int32_t preKeysSize; @@ -82,7 +92,8 @@ bool KeyOption::ReadFromParcel(Parcel &in) return ( in.ReadInt32(finalKey_) && in.ReadBool(isFinalKeyDown_) && - in.ReadInt32(finalKeyDownDuration_) + in.ReadInt32(finalKeyDownDuration_) && + in.ReadInt32(finalKeyUpDelay_) ); } @@ -101,7 +112,8 @@ bool KeyOption::WriteToParcel(Parcel &out) const return ( out.WriteInt32(finalKey_) && out.WriteBool(isFinalKeyDown_) && - out.WriteInt32(finalKeyDownDuration_) + out.WriteInt32(finalKeyDownDuration_) && + out.WriteInt32(finalKeyUpDelay_) ); } } // namespace MMI diff --git a/frameworks/proxy/events/src/pointer_event.cpp b/frameworks/proxy/events/src/pointer_event.cpp index e93f8d94ced4ff4de63845795dcedbf5cdc65897..e1ae1cfa76f75b66dc48aa6bab8b7b5b96138728 100644 --- a/frameworks/proxy/events/src/pointer_event.cpp +++ b/frameworks/proxy/events/src/pointer_event.cpp @@ -355,7 +355,7 @@ PointerEvent::PointerEvent(const PointerEvent& other) pressedButtons_(other.pressedButtons_), sourceType_(other.sourceType_), pointerAction_(other.pointerAction_), buttonId_(other.buttonId_), axes_(other.axes_), axisValues_(other.axisValues_), - pressedKeys_(other.pressedKeys_) {} + pressedKeys_(other.pressedKeys_), buffer_(other.buffer_) {} PointerEvent::~PointerEvent() {} @@ -426,6 +426,21 @@ const char* PointerEvent::DumpPointerAction() const case PointerEvent::POINTER_ACTION_LEAVE_WINDOW: { return "leave-window"; } + case PointerEvent::POINTER_ACTION_PULL_DOWN: { + return "pull-down"; + } + case PointerEvent::POINTER_ACTION_PULL_MOVE: { + return "pull-move"; + } + case PointerEvent::POINTER_ACTION_PULL_UP: { + return "pull-up"; + } + case PointerEvent::POINTER_ACTION_PULL_IN_WINDOW: { + return "pull-in-window"; + } + case PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW: { + return "pull-out-window"; + } default: { break; } @@ -866,13 +881,7 @@ bool PointerEvent::IsValidCheckTouch() const bool PointerEvent::IsValid() const { CALL_DEBUG_ENTER; - int32_t sourceType = GetSourceType(); - if (sourceType != SOURCE_TYPE_MOUSE && sourceType != SOURCE_TYPE_TOUCHSCREEN && - sourceType != SOURCE_TYPE_TOUCHPAD) { - MMI_HILOGE("SourceType is invalid"); - return false; - } - switch (sourceType) { + switch (GetSourceType()) { case SOURCE_TYPE_MOUSE: { if (!IsValidCheckMouse()) { MMI_HILOGE("IsValidCheckMouse is invalid"); @@ -888,6 +897,8 @@ bool PointerEvent::IsValid() const } break; } + case SOURCE_TYPE_JOYSTICK: + break; default: { MMI_HILOGE("SourceType is invalid"); return false; @@ -895,5 +906,20 @@ bool PointerEvent::IsValid() const } return true; } + +void PointerEvent::SetBuffer(std::vector buffer) +{ + buffer_ = buffer; +} + +void PointerEvent::ClearBuffer() +{ + buffer_.clear(); +} + +std::vector PointerEvent::GetBuffer() const +{ + return buffer_; +} } // namespace MMI } // namespace OHOS diff --git a/frameworks/proxy/events/test/input_manager_filter_manual_test.cpp b/frameworks/proxy/events/test/input_manager_filter_manual_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..aafb1f44b37ef1873b87b7c3a6a305cf5d0565cb --- /dev/null +++ b/frameworks/proxy/events/test/input_manager_filter_manual_test.cpp @@ -0,0 +1,613 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "accesstoken_kit.h" +#include "define_multimodal.h" +#include "error_multimodal.h" +#include "input_handler_manager.h" +#include "input_manager.h" +#include "multimodal_event_handler.h" +#include "multimodal_event_handler.h" +#include "nativetoken_kit.h" +#include "pointer_event.h" +#include "proto.h" +#include "token_setproc.h" + +namespace OHOS { +namespace MMI { +using namespace Security::AccessToken; +using Security::AccessToken::AccessTokenID; +namespace { +using namespace testing::ext; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "InputManagerFilterManualTest" }; +static const int SIG_KILL = 9; + +HapInfoParams infoManagerTestInfoParms = { + .userID = 1, + .bundleName = "accesstoken_test", + .instIndex = 0, + .appIDDesc = "test" +}; + +PermissionDef infoManagerTestPermDef = { + .permissionName = "ohos.permission.test", + .bundleName = "accesstoken_test", + .grantMode = 1, + .availableLevel = APL_SYSTEM_CORE, + .label = "label", + .labelId = 1, + .description = "test filter", + .descriptionId = 1, +}; + +PermissionStateFull infoManagerTestState = { + .permissionName = "ohos.permission.test", + .isGeneral = true, + .resDeviceID = {"local"}, + .grantStatus = {PermissionState::PERMISSION_GRANTED}, + .grantFlags = {1}, +}; + +HapPolicyParams infoManagerTestPolicyPrams = { + .apl = APL_SYSTEM_CORE, + .domain = "test.domain", + .permList = {infoManagerTestPermDef}, + .permStateList = {infoManagerTestState} +}; +} // namespace + +class AccessToken { +public: + AccessToken() + { + currentID_ = GetSelfTokenID(); + AccessTokenIDEx tokenIdEx = AccessTokenKit::AllocHapToken(infoManagerTestInfoParms, infoManagerTestPolicyPrams); + accessID_ = tokenIdEx.tokenIdExStruct.tokenID; + SetSelfTokenID(accessID_); + } + ~AccessToken() + { + AccessTokenKit::DeleteToken(accessID_); + SetSelfTokenID(currentID_); + } +private: + AccessTokenID currentID_ = 0; + AccessTokenID accessID_ = 0; +}; + +class InputManagerFilterManualTest : public testing::Test { +public: + static void SetUpTestCase(void) {} + static void TearDownTestCase(void) {} + + void SetUp() {} + void TearDown() {} + pid_t GetMmiServerPid() const + { + const std::string mmiServerProcessName = "multimodalinput"; + return GetProcessPidByName(mmiServerProcessName.c_str()); + } + int32_t StopExecutable(pid_t pid) const + { + if (pid != INVALID_PID) { + MMI_HILOGI("Kill pid = %{public}d, before", pid); + kill(pid, SIG_KILL); + MMI_HILOGI("Kill pid = %{public}d, finished", pid); + } + return RET_OK; + } + pid_t GetProcessPidByName(const char* proc_name) const + { + FILE *fp; + char buf[100]; + char cmd[200] = {'\0'}; + pid_t pid = -1; + sprintf(cmd, "pidof %s", proc_name); + MMI_HILOGI("cmd:%{public}s", cmd); + if ((fp = popen(cmd, "r")) != NULL) { + if (fgets(buf, 255, fp) != NULL) { + pid = atoi(buf); + } + } + pclose(fp); + return pid; + } + int32_t GetSelfHidumperFilterNum() const + { + std::set> info; + auto ret = GetSelfHidumperFilter(info); + if (ret != RET_OK) { + return 0; + } + return info.size(); + } + int32_t GetSelfHidumperFilter(std::set> &info) const + { + const char *cmd = "hidumper -s 3101 -a -f"; + FILE *fp = popen(cmd, "r"); + if (fp == NULL) { + MMI_HILOGE("Call popen fail, cmd:%{public}s", cmd); + return RET_ERR; + } + pid_t pid = getpid(); + std::string strPid = std::to_string(pid); + MMI_HILOGE("Self pid:%{public}s", strPid.c_str()); + std::regex itemRegex("priority:(\\d+) \\| filterId:(\\d+) \\| Pid:(\\d+)\r?\n?"); + char *buf = NULL; + size_t bufLen = 0; + ssize_t nRead = 0; + while ((nRead = getline(&buf, &bufLen, fp)) != -1) { + std::string line(buf); + std::smatch match; + if (!std::regex_match(line, match, itemRegex)) { + MMI_HILOGI("Not match line:%{public}s", line.c_str()); + continue; + } + MMI_HILOGI("Line match: %{public}s", line.c_str()); + if (match.size() != 4) { + MMI_HILOGI("Check itemRegex,it is error"); + continue; + } + std::string priority = match[1].str(); + std::string filterId = match[2].str(); + std::string pid = match[3].str(); + if (pid != strPid) { + continue; + } + auto ret = info.emplace(std::make_pair(priority, filterId)); + if (!ret.second) { + MMI_HILOGE("Duplicate priority:%{public}s,filterId:%{public}s,", + priority.c_str(), filterId.c_str()); + } + info.insert(std::make_pair(priority, filterId)); + }; + if (buf != nullptr) { + free(buf); + buf = nullptr; + } + if (fp != nullptr) { + pclose(fp); + fp = nullptr; + } + return RET_OK; + } +}; + +#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) +/** + * @tc.name: HandlePointerEventFilter_001 + * @tc.desc: Verify pointer event filter + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerFilterManualTest, HandlePointerEventFilter_001, TestSize.Level1) +{ + CALL_DEBUG_ENTER; + MMI_HILOGI("enter HandlePointerEventFilter_001"); + struct PointerFilter : public IInputEventFilter { + const int32_t exceptX_; + const int32_t exceptY_; + sem_t &sem_; + bool &result_; + PointerFilter(int32_t exceptX, int32_t exceptY, sem_t &sem, bool &result) + : exceptX_(exceptX), exceptY_(exceptY), sem_(sem), result_(result) {} + virtual bool OnInputEvent(std::shared_ptr keyEvent) const override { return false; } + bool OnInputEvent(std::shared_ptr pointerEvent) const override + { + MMI_HILOGD("Callback enter"); + result_ = false; + do { + CHKPB(pointerEvent); + const std::vector ids = pointerEvent->GetPointerIds(); + if (ids.empty()) { + MMI_HILOGE("The ids is empty"); + break; + } + const int32_t firstPointerId = ids[0]; + PointerEvent::PointerItem item; + if (!pointerEvent->GetPointerItem(firstPointerId, item)) { + MMI_HILOGE("GetPointerItem:%{public}d fail", firstPointerId); + break; + } + const int32_t x = item.GetDisplayX(); + const int32_t y = item.GetDisplayY(); + if (x == exceptX_ && y == exceptY_) { + MMI_HILOGI("The values of X and y are both 10, which meets the expectation and callbackRet is set to 1"); + result_ = true; + break; + } + MMI_HILOGI("The values of X and y are not 10, which meets the expectation and callbackRet is set to 2"); + } while (0); + int ret = sem_post(&sem_); + EXPECT_EQ(ret, 0); + return result_; + } + }; + AccessToken accessToken; + sem_t sem; + int ret = sem_init(&sem, 0, 0); + ASSERT_EQ(ret, 0); + bool result = false; + auto filter = std::make_shared(10, 10, sem, result); + const int32_t priority = 201; + uint32_t touchTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX); + const int32_t filterId = InputManager::GetInstance()->AddInputEventFilter(filter, priority, touchTags); + ASSERT_NE(filterId, -1); + ASSERT_EQ(GetSelfHidumperFilterNum(), 1); + + auto simulate = [](int32_t x, int32_t y) { + //MMI_HILOGI("SimulateInputEvent prepare, x:%{public}d, y:{public}d", x, y); + const int32_t pointerId = 0; + PointerEvent::PointerItem item; + item.SetPointerId(pointerId); + item.SetDisplayX(x); + item.SetDisplayY(y); + auto pointerEvent = PointerEvent::Create(); + ASSERT_NE(pointerEvent, nullptr); + pointerEvent->AddPointerItem(item); + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); + pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); + pointerEvent->SetPointerId(pointerId); + MMI_HILOGI("SimulateInputEvent begin"); + InputManager::GetInstance()->SimulateInputEvent(pointerEvent); + MMI_HILOGI("SimulateInputEvent finished"); + }; + + auto waitEnd = [&sem]() { + struct timespec ts; + int ret = clock_gettime(CLOCK_REALTIME, &ts); + ASSERT_NE(ret, -1); + int32_t waitForSeconds = 3; + ts.tv_sec += waitForSeconds; + ret = sem_timedwait(&sem, &ts); + ASSERT_EQ(ret, 0); + }; + // set physical x and physical y are 10, will expect value is 1 + simulate(10, 10); + waitEnd(); + ASSERT_EQ(result, true); + // set physical x and physical y are not 10, will expect value is 2 + simulate(0, 0); + waitEnd(); + ASSERT_EQ(result, false); + auto retCode = InputManager::GetInstance()->RemoveInputEventFilter(filterId); + ASSERT_EQ(retCode, RET_OK); + ASSERT_EQ(GetSelfHidumperFilterNum(), 0); +} +#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH + +#ifdef OHOS_BUILD_ENABLE_KEYBOARD +/** + * @tc.name: HandlePointerEventFilter_002 + * @tc.desc: Verify key event filter + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerFilterManualTest, HandleKeyEventFilter_002, TestSize.Level1) +{ + CALL_DEBUG_ENTER; + MMI_HILOGI("enter HandlePointerEventFilter_002"); + struct KeyFilter : public IInputEventFilter { + const int32_t exceptKeyCode_; + sem_t &sem_; + bool &result_; + KeyFilter(int32_t exceptKeyCode, sem_t &sem, bool &result) + : exceptKeyCode_(exceptKeyCode), sem_(sem), result_(result) {} + bool OnInputEvent(std::shared_ptr keyEvent) const override + { + MMI_HILOGI("KeyFilter::OnInputEvent enter, pid: %{public}d, exceptKeyCode:%{public}d", getpid(), exceptKeyCode_); + do { + result_ = false; + CHKPB(keyEvent); + auto keyCode = keyEvent->GetKeyCode(); + MMI_HILOGI("KeyFilter::OnInputEvent receive keyCode: %{public}d return true", keyCode); + if (keyCode == exceptKeyCode_) { + result_ = true; + break; + } + } while(0); + int ret = sem_post(&sem_); + EXPECT_EQ(ret, 0); + return result_; + } + bool OnInputEvent(std::shared_ptr pointerEvent) const override { return false; } + }; + AccessToken accessToken; + ASSERT_EQ(GetSelfHidumperFilterNum(), 0); + + sem_t semA; + int ret = sem_init(&semA, 0, 0); + ASSERT_EQ(ret, 0); + bool resultA = false; + auto filterA = std::make_shared(KeyEvent::KEYCODE_A, semA, resultA); + uint32_t touchTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX); + const int32_t filterIdA = InputManager::GetInstance()->AddInputEventFilter(filterA, 220, touchTags); + ASSERT_NE(filterIdA, RET_ERR); + + sem_t semB; + ret = sem_init(&semB, 0, 0); + ASSERT_EQ(ret, 0); + bool resultB = false; + auto filterB = std::make_shared(KeyEvent::KEYCODE_B, semB, resultB); + const int32_t filterIdB = InputManager::GetInstance()->AddInputEventFilter(filterB, 210, touchTags); + ASSERT_NE(filterIdB, RET_ERR); + ASSERT_EQ(GetSelfHidumperFilterNum(), 2); + + auto waitEnd = [](sem_t &sem) { + struct timespec ts; + int ret = clock_gettime(CLOCK_REALTIME, &ts); + ASSERT_NE(ret, -1); + int32_t waitForSeconds = 5; + ts.tv_sec += waitForSeconds; + ret = sem_timedwait(&sem, &ts); + ASSERT_EQ(ret, 0); + }; + + resultA = false; + resultB = false; + auto keyAEvent = KeyEvent::Create(); + ASSERT_NE(keyAEvent, nullptr); + KeyEvent::KeyItem kitDownA; + kitDownA.SetKeyCode(KeyEvent::KEYCODE_A); + kitDownA.SetPressed(true); + kitDownA.SetDeviceId(1); + keyAEvent->SetKeyCode(KeyEvent::KEYCODE_A); + keyAEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN); + keyAEvent->AddPressedKeyItems(kitDownA); + MMI_HILOGI("SimulateInputEvent key event KEYCODE_A(2017)"); + InputManager::GetInstance()->SimulateInputEvent(keyAEvent); + waitEnd(semA); + ASSERT_EQ(resultA, true); + ASSERT_EQ(resultB, false); + + resultA = false; + resultB = false; + auto keyBEvent = KeyEvent::Create(); + ASSERT_NE(keyAEvent, nullptr); + KeyEvent::KeyItem kitDownB; + kitDownB.SetKeyCode(KeyEvent::KEYCODE_B); + kitDownB.SetPressed(true); + kitDownB.SetDeviceId(1); + keyBEvent->SetKeyCode(KeyEvent::KEYCODE_B); + keyBEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN); + keyBEvent->AddPressedKeyItems(kitDownB); + MMI_HILOGI("SimulateInputEvent key event KEYCODE_B(2018)"); + InputManager::GetInstance()->SimulateInputEvent(keyBEvent); + waitEnd(semB); + ASSERT_EQ(resultA, false); + ASSERT_EQ(resultB, true); + + auto retCode = InputManager::GetInstance()->RemoveInputEventFilter(filterIdA); + ASSERT_EQ(retCode, RET_OK); + ASSERT_EQ(GetSelfHidumperFilterNum(), 1); + retCode = InputManager::GetInstance()->RemoveInputEventFilter(filterIdB); + ASSERT_EQ(retCode, RET_OK); + ASSERT_EQ(GetSelfHidumperFilterNum(), 0); +} + +/** + * @tc.name: HandlePointerEventFilter_002 + * @tc.desc: Max filter number check + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerFilterManualTest, HandleKeyEventFilter_003, TestSize.Level1) +{ + CALL_DEBUG_ENTER; + MMI_HILOGI("enter HandlePointerEventFilter_003"); + struct KeyFilter : public IInputEventFilter { + bool OnInputEvent(std::shared_ptr keyEvent) const override + { + MMI_HILOGI("KeyFilter::OnInputEvent enter,pid: %{public}d", getpid()); + return false; + } + bool OnInputEvent(std::shared_ptr pointerEvent) const override { return false; } + }; + AccessToken accessToken; + auto addFilter = []() -> int32_t { + auto filter = std::make_shared(); + uint32_t touchTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX); + const int32_t filterId = InputManager::GetInstance()->AddInputEventFilter(filter, 220, touchTags); + return filterId; + }; + ASSERT_EQ(GetSelfHidumperFilterNum(), 0); + const size_t testMaxNum = 10; + const size_t singleClientSuportMaxNum = 4; + std::vector filterIds; + for (size_t i = 0; i < testMaxNum; ++i) { + const int32_t filterId = addFilter(); + if (i < singleClientSuportMaxNum) { + ASSERT_NE(filterId, RET_ERR); + filterIds.push_back(filterId); + } else { + ASSERT_EQ(filterId, RET_ERR); + } + } + ASSERT_EQ(filterIds.size(), singleClientSuportMaxNum); + ASSERT_EQ(GetSelfHidumperFilterNum(), singleClientSuportMaxNum); + + int32_t cnt = singleClientSuportMaxNum; + for (auto &filterId : filterIds) { + auto retCode = InputManager::GetInstance()->RemoveInputEventFilter(filterId); + ASSERT_EQ(retCode, RET_OK); + --cnt; + ASSERT_EQ(GetSelfHidumperFilterNum(), cnt); + } + ASSERT_EQ(GetSelfHidumperFilterNum(), 0); +} + +/** + * @tc.name: HandlePointerEventFilter_004 + * @tc.desc: Add filter but not remove filter, depend on process dead auto kill + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerFilterManualTest, DISABLED_HandleKeyEventFilter_004, TestSize.Level1) +{ + CALL_DEBUG_ENTER; + MMI_HILOGI("enter DISABLED_HandleKeyEventFilter_004"); + struct KeyFilter : public IInputEventFilter { + bool OnInputEvent(std::shared_ptr keyEvent) const override + { + MMI_HILOGI("KeyFilter::OnInputEvent enter,pid: %{public}d", getpid()); + return false; + } + bool OnInputEvent(std::shared_ptr pointerEvent) const override { return false; } + }; + AccessToken accessToken; + auto addFilter = []() -> int32_t { + auto filter = std::make_shared(); + uint32_t touchTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX); + const int32_t filterId = InputManager::GetInstance()->AddInputEventFilter(filter, 220, touchTags); + return filterId; + }; + const size_t singleClientSuportMaxNum = 4; + for (size_t i = 0; i < singleClientSuportMaxNum; ++i) { + const int32_t filterId = addFilter(); + ASSERT_NE(filterId, RET_ERR); + } + ASSERT_EQ(GetSelfHidumperFilterNum(), singleClientSuportMaxNum); +} + +/** + * @tc.name: HandlePointerEventFilter_005 + * @tc.desc: Delete all filter of this process + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerFilterManualTest, HandleKeyEventFilter_005, TestSize.Level1) +{ + CALL_DEBUG_ENTER; + MMI_HILOGI("enter HandleKeyEventFilter_005"); + struct KeyFilter : public IInputEventFilter { + bool OnInputEvent(std::shared_ptr keyEvent) const override + { + MMI_HILOGI("KeyFilter::OnInputEvent enter,pid: %{public}d", getpid()); + return false; + } + bool OnInputEvent(std::shared_ptr pointerEvent) const override { return false; } + }; + AccessToken accessToken; + auto addFilter = []() -> int32_t { + auto filter = std::make_shared(); + uint32_t touchTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX); + const int32_t filterId = InputManager::GetInstance()->AddInputEventFilter(filter, 220, touchTags); + return filterId; + }; + ASSERT_EQ(GetSelfHidumperFilterNum(), 0); + const size_t singleClientSuportMaxNum = 4; + for (size_t i = 0; i < singleClientSuportMaxNum; ++i) { + const int32_t filterId = addFilter(); + ASSERT_NE(filterId, RET_ERR); + } + ASSERT_EQ(GetSelfHidumperFilterNum(), singleClientSuportMaxNum); + auto ret = InputManager::GetInstance()->RemoveInputEventFilter(-1); + ASSERT_EQ(ret, RET_OK); + ASSERT_EQ(GetSelfHidumperFilterNum(), 0); +} + +/** + * @tc.name: HandlePointerEventFilter_006 + * @tc.desc: After add the filter, the mmi client does not exit the reset mmi server + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerFilterManualTest, HandleKeyEventFilter_006, TestSize.Level1) +{ + CALL_DEBUG_ENTER; + MMI_HILOGI("enter HandleKeyEventFilter_006"); + struct KeyFilter : public IInputEventFilter { + bool OnInputEvent(std::shared_ptr keyEvent) const override + { + MMI_HILOGI("KeyFilter::OnInputEvent enter,pid: %{public}d", getpid()); + return false; + } + bool OnInputEvent(std::shared_ptr pointerEvent) const override { return false; } + }; + AccessToken accessToken; + auto addFilter = []() -> int32_t { + auto filter = std::make_shared(); + uint32_t touchTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX); + const int32_t filterId = InputManager::GetInstance()->AddInputEventFilter(filter, 220, touchTags); + return filterId; + }; + const size_t singleClientSuportMaxNum = 4; + for (size_t i = 0; i < singleClientSuportMaxNum; ++i) { + const int32_t filterId = addFilter(); + ASSERT_NE(filterId, RET_ERR); + } + pid_t serverPid1 = GetMmiServerPid(); + ASSERT_NE(serverPid1, -1); + MMI_HILOGI("Origin serverPid1:%{public}d", serverPid1); + std::set> filterInfo1; + auto ret = GetSelfHidumperFilter(filterInfo1); + ASSERT_EQ(ret, RET_OK); + ret = StopExecutable(serverPid1); + ASSERT_EQ(ret, RET_OK); + pid_t serverPid2 = -1; + int32_t cnt = 20; + do { + MMI_HILOGI("Sleep 1s, wait mmi server started, cnt:%{public}d", cnt--); + sleep(1); + serverPid2 = GetMmiServerPid(); + MMI_HILOGI("ServerPid2:%{public}d", serverPid2); + } while (serverPid2 == -1); + ASSERT_NE(serverPid2, -1); + sleep(1); + cnt = 20; + bool retInitClient = false; + do { + MMI_HILOGI("Sleep 1s, wait init client success cnt:%{public}d", cnt--); + sleep(1); + --cnt; + retInitClient = MMIEventHdl.InitClient(); + } while (cnt > 0 && !retInitClient); + ASSERT_EQ(retInitClient, true); + std::set> filterInfo2; + cnt = 20; + do { + MMI_HILOGI("Sleep 1s, wait add filter finished, cnt:%{public}d", cnt--); + sleep(1); + filterInfo2.clear(); + GetSelfHidumperFilter(filterInfo2); + } while (cnt > 0 && filterInfo1.size() != filterInfo2.size()); + auto printFilter = [](const std::string title, const std::set> &s) { + MMI_HILOGI("title:%{public}s, size:%{public}u", title.c_str(), s.size()); + for (const auto &[priority, filterId] : s) { + MMI_HILOGI("priority:%{public}s,filterId:%{pulbic}s", priority.c_str(), filterId.c_str()); + } + }; + printFilter("filterInfo1", filterInfo1); + printFilter("filterInfo2", filterInfo2); + ASSERT_TRUE(filterInfo1 == filterInfo2); +} +#endif // OHOS_BUILD_ENABLE_KEYBOARD +} // namespace MMI +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/proxy/events/test/input_manager_manual_test.cpp b/frameworks/proxy/events/test/input_manager_manual_test.cpp index a5ad896a7c1e5cd83cd8ad7e99dbe06ef523610f..edcb674ce115fbe6b584b22d1a33899d16a15d95 100644 --- a/frameworks/proxy/events/test/input_manager_manual_test.cpp +++ b/frameworks/proxy/events/test/input_manager_manual_test.cpp @@ -14,8 +14,10 @@ */ #include +#include #include "accesstoken_kit.h" +#include "bytrace_adapter.h" #include "define_multimodal.h" #include "error_multimodal.h" #include "input_handler_manager.h" @@ -24,7 +26,6 @@ #include "nativetoken_kit.h" #include "pointer_event.h" #include "proto.h" -#include "run_shell_util.h" #include "token_setproc.h" namespace OHOS { @@ -34,13 +35,12 @@ using Security::AccessToken::AccessTokenID; namespace { using namespace testing::ext; #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) -constexpr int32_t TIME_WAIT_FOR_OP = 500; constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "InputManagerManualTest" }; #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH HapInfoParams infoManagerTestInfoParms = { - .bundleName = "accesstoken_test", .userID = 1, + .bundleName = "accesstoken_test", .instIndex = 0, .appIDDesc = "test" }; @@ -49,26 +49,26 @@ PermissionDef infoManagerTestPermDef = { .permissionName = "ohos.permission.test", .bundleName = "accesstoken_test", .grantMode = 1, + .availableLevel = APL_SYSTEM_CORE, .label = "label", .labelId = 1, .description = "test input event filter", .descriptionId = 1, - .availableLevel = APL_SYSTEM_CORE }; PermissionStateFull infoManagerTestState = { - .grantFlags = {1}, - .grantStatus = {PermissionState::PERMISSION_GRANTED}, - .isGeneral = true, .permissionName = "ohos.permission.test", - .resDeviceID = {"local"} + .isGeneral = true, + .resDeviceID = { "local" }, + .grantStatus = { PermissionState::PERMISSION_GRANTED }, + .grantFlags = { 1 }, }; HapPolicyParams infoManagerTestPolicyPrams = { .apl = APL_SYSTEM_CORE, .domain = "test.domain", - .permList = {infoManagerTestPermDef}, - .permStateList = {infoManagerTestState} + .permList = { infoManagerTestPermDef }, + .permStateList = { infoManagerTestState } }; } // namespace @@ -96,95 +96,115 @@ public: static void SetUpTestCase(void) {} static void TearDownTestCase(void) {} - void SetUp(); + void SetUp() {} void TearDown() {} - -protected: -#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) - void AddInputEventFilter(); - void SimulateInputEventHelper(int32_t physicalX, int32_t physicalY, int32_t expectVal); -#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH -private: - int32_t callbackRet = 0; }; -void InputManagerManualTest::SetUp() +/** + * @tc.name: StartBytrace_001 + * @tc.desc: Verify keyevent start bytrace + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerManualTest, StartBytrace_001, TestSize.Level1) { - callbackRet = 0; + CALL_TEST_DEBUG; + std::shared_ptr keyEvent = KeyEvent::Create(); + ASSERT_NE(keyEvent, nullptr); + keyEvent->SetId(0); + BytraceAdapter::StartBytrace(keyEvent); + ASSERT_EQ(keyEvent->GetId(), 0); } -#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) -void InputManagerManualTest::AddInputEventFilter() +/** + * @tc.name: StartBytrace_002 + * @tc.desc: Verify keyevent start bytrace + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerManualTest, StartBytrace_002, TestSize.Level1) { - CALL_DEBUG_ENTER; - auto callback = [this](std::shared_ptr pointer) -> bool { - MMI_HILOGD("Callback enter"); - CHKPF(pointer); - const std::vector ids = pointer->GetPointerIds(); - if (ids.empty()) { - MMI_HILOGE("The ids is empty"); - return false; - } - - const int32_t firstPointerId = ids[0]; - PointerEvent::PointerItem item; - if (!pointer->GetPointerItem(firstPointerId, item)) { - MMI_HILOGE("GetPointerItem:%{public}d fail", firstPointerId); - return false; - } - - const int32_t x = item.GetDisplayX(); - const int32_t y = item.GetDisplayY(); - if (x == 10 && y == 10) { - MMI_HILOGI("The values of X and y are both 10, which meets the expectation and callbackRet is set to 1"); - callbackRet = 1; - return true; - } - - MMI_HILOGI("The values of X and y are not 10, which meets the expectation and callbackRet is set to 2"); - callbackRet = 2; - return false; - }; - AccessToken accessToken; - int32_t ret = InputManager::GetInstance()->AddInputEventFilter(callback); - ASSERT_EQ(ret, RET_OK); + CALL_TEST_DEBUG; + std::shared_ptr keyEvent = KeyEvent::Create(); + ASSERT_NE(keyEvent, nullptr); + keyEvent->SetId(0); + keyEvent->SetKeyCode(0); + BytraceAdapter::StartBytrace(keyEvent, BytraceAdapter::KEY_INTERCEPT_EVENT); + BytraceAdapter::StartBytrace(keyEvent, BytraceAdapter::KEY_LAUNCH_EVENT); + BytraceAdapter::StartBytrace(keyEvent, BytraceAdapter::KEY_SUBSCRIBE_EVENT); + BytraceAdapter::StartBytrace(keyEvent, BytraceAdapter::KEY_DISPATCH_EVENT); + BytraceAdapter::StartBytrace(keyEvent, BytraceAdapter::POINT_INTERCEPT_EVENT); + ASSERT_EQ(keyEvent->GetKeyCode(), 0); } -void InputManagerManualTest::SimulateInputEventHelper(int32_t physicalX, int32_t physicalY, int32_t expectVal) +/** + * @tc.name: StartBytrace_003 + * @tc.desc: Verify pointerEvent start bytrace + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerManualTest, StartBytrace_003, TestSize.Level1) { - CALL_DEBUG_ENTER; - const int32_t pointerId = 0; - PointerEvent::PointerItem item; - item.SetPointerId(pointerId); - item.SetDisplayX(physicalX); - item.SetDisplayY(physicalY); - - auto pointerEvent = PointerEvent::Create(); + CALL_TEST_DEBUG; + std::shared_ptr pointerEvent = PointerEvent::Create(); ASSERT_NE(pointerEvent, nullptr); - pointerEvent->AddPointerItem(item); - pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); - pointerEvent->SetPointerId(pointerId); + BytraceAdapter::StartBytrace(pointerEvent, BytraceAdapter::TRACE_START); + pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); + BytraceAdapter::StartBytrace(pointerEvent, BytraceAdapter::TRACE_START); + pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); + BytraceAdapter::StartBytrace(pointerEvent, BytraceAdapter::TRACE_STOP); + pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); + BytraceAdapter::StartBytrace(pointerEvent, BytraceAdapter::TRACE_STOP); + ASSERT_EQ(pointerEvent->GetSourceType(), PointerEvent::SOURCE_TYPE_TOUCHSCREEN); +} - MMI_HILOGI("Call InputManager::SimulateInputEvent"); - InputManager::GetInstance()->SimulateInputEvent(pointerEvent); - std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); - EXPECT_EQ(callbackRet, expectVal); +/** + * @tc.name: StartBytrace_004 + * @tc.desc: Verify pointerEvent start bytrace + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerManualTest, StartBytrace_004, TestSize.Level1) +{ + CALL_TEST_DEBUG; + std::shared_ptr pointerEvent = PointerEvent::Create(); + ASSERT_NE(pointerEvent, nullptr); + pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); + BytraceAdapter::StartBytrace(BytraceAdapter::TRACE_START, BytraceAdapter::START_EVENT); + BytraceAdapter::StartBytrace(BytraceAdapter::TRACE_START, BytraceAdapter::LAUNCH_EVENT); + BytraceAdapter::StartBytrace(BytraceAdapter::TRACE_START, BytraceAdapter::STOP_EVENT); + BytraceAdapter::StartBytrace(BytraceAdapter::TRACE_STOP, BytraceAdapter::START_EVENT); + BytraceAdapter::StartBytrace(BytraceAdapter::TRACE_STOP, BytraceAdapter::LAUNCH_EVENT); + BytraceAdapter::StartBytrace(BytraceAdapter::TRACE_STOP, BytraceAdapter::STOP_EVENT); + ASSERT_EQ(pointerEvent->GetSourceType(), PointerEvent::SOURCE_TYPE_MOUSE); } +#ifdef OHOS_BUILD_ENABLE_KEYBOARD /** - * @tc.name:HandlePointerEventFilter_001 - * @tc.desc:Verify pointer event filter + * @tc.name: HandlePointerEventFilter_002 + * @tc.desc: Max filter number check * @tc.type: FUNC * @tc.require: */ -HWTEST_F(InputManagerManualTest, HandlePointerEventFilter_001, TestSize.Level1) +HWTEST_F(InputManagerManualTest, HandleKeyEventFilter_003, TestSize.Level1) { - CALL_DEBUG_ENTER; - AddInputEventFilter(); - SimulateInputEventHelper(10, 10, 1); // set physical x and physical y are 10, will expect value is 1 - SimulateInputEventHelper(0, 0, 2); // set physical x and physical y are not 10, will expect value is 2 + CALL_TEST_DEBUG; + struct KeyFilter : public IInputEventFilter { + bool OnInputEvent(std::shared_ptr keyEvent) const override + { + MMI_HILOGI("KeyFilter::OnInputEvent enter,pid: %{public}d", getpid()); + return false; + } + bool OnInputEvent(std::shared_ptr pointerEvent) const override { return false; } + }; + AccessToken accessToken;auto filter = std::make_shared(); + uint32_t touchTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX); + const int32_t filterId = InputManager::GetInstance()->AddInputEventFilter(filter, 220, touchTags); + ASSERT_NE(filterId, RET_ERR); + auto retCode = InputManager::GetInstance()->RemoveInputEventFilter(filterId); + ASSERT_EQ(retCode, RET_OK); } -#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH +#endif // OHOS_BUILD_ENABLE_KEYBOARD } // namespace MMI } // namespace OHOS \ No newline at end of file diff --git a/frameworks/proxy/events/test/input_manager_test.cpp b/frameworks/proxy/events/test/input_manager_test.cpp old mode 100755 new mode 100644 index 4cf44cf3012e0bca24bc9557e47dc4764c2a475d..b8379c456e5ff9e317f6b2b9f45467515bdeebc3 --- a/frameworks/proxy/events/test/input_manager_test.cpp +++ b/frameworks/proxy/events/test/input_manager_test.cpp @@ -16,6 +16,7 @@ #include "event_log_helper.h" #include "event_util_test.h" #include "input_handler_type.h" +#include "input_manager_impl.h" #include "mmi_log.h" #include "multimodal_event_handler.h" #include "system_info.h" @@ -40,6 +41,8 @@ public: void TearDown(); static void SetUpTestCase(); std::string GetEventDump(); + std::shared_ptr InitOption(const std::set &preKeys, + int32_t finalKey, bool isFinalKeyDown, int32_t duration); std::shared_ptr SetupPointerEvent001(); std::shared_ptr SetupPointerEvent002(); std::shared_ptr SetupPointerEvent003(); @@ -101,22 +104,22 @@ std::shared_ptr InputManagerTest::SetupPointerEvent001() auto pointerEvent = PointerEvent::Create(); CHKPP(pointerEvent); PointerEvent::PointerItem item; - item.SetPointerId(0); // test code,set the PointerId = 0 - item.SetDisplayX(523); // test code,set the DisplayX = 523 - item.SetDisplayY(723); // test code,set the DisplayY = 723 - item.SetPressure(5); // test code,set the Pressure = 5 - item.SetDeviceId(1); // test code,set the DeviceId = 1 + item.SetPointerId(0); + item.SetDisplayX(523); + item.SetDisplayY(723); + item.SetPressure(5); + item.SetDeviceId(1); pointerEvent->AddPointerItem(item); - item.SetPointerId(1); // test code,set the PointerId = 1 - item.SetDisplayX(610); // test code,set the DisplayX = 610 - item.SetDisplayY(910); // test code,set the DisplayY = 910 - item.SetPressure(7); // test code,set the Pressure = 7 - item.SetDeviceId(1); // test code,set the DeviceId = 1 + item.SetPointerId(1); + item.SetDisplayX(610); + item.SetDisplayY(910); + item.SetPressure(7); + item.SetDeviceId(1); pointerEvent->AddPointerItem(item); pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); - pointerEvent->SetPointerId(1); // test code,set the PointerId = 1 + pointerEvent->SetPointerId(1); pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); return pointerEvent; } @@ -126,22 +129,22 @@ std::shared_ptr InputManagerTest::SetupPointerEvent002() auto pointerEvent = PointerEvent::Create(); CHKPP(pointerEvent); PointerEvent::PointerItem item; - item.SetPointerId(0); // test code,set the PointerId = 0 - item.SetDisplayX(523); // test code,set the DisplayX = 523 - item.SetDisplayY(723); // test code,set the DisplayY = 723 - item.SetPressure(5); // test code,set the Pressure = 5 - item.SetDeviceId(1); // test code,set the DeviceId = 1 + item.SetPointerId(0); + item.SetDisplayX(523); + item.SetDisplayY(723); + item.SetPressure(5); + item.SetDeviceId(1); pointerEvent->AddPointerItem(item); - item.SetPointerId(1); // test code,set the PointerId = 1 - item.SetDisplayX(600); // test code,set the DisplayX = 600 - item.SetDisplayY(610); // test code,set the DisplayY = 610 - item.SetPressure(7); // test code,set the Pressure = 7 - item.SetDeviceId(1); // test code,set the DeviceId = 1 + item.SetPointerId(1); + item.SetDisplayX(600); + item.SetDisplayY(610); + item.SetPressure(7); + item.SetDeviceId(1); pointerEvent->AddPointerItem(item); pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE); - pointerEvent->SetPointerId(1); // test code,set the PointerId = 1 + pointerEvent->SetPointerId(1); pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); return pointerEvent; } @@ -151,22 +154,22 @@ std::shared_ptr InputManagerTest::SetupPointerEvent003() auto pointerEvent = PointerEvent::Create(); CHKPP(pointerEvent); PointerEvent::PointerItem item; - item.SetPointerId(0); // test code,set the PointerId = 0 - item.SetDisplayX(523); // test code,set the DisplayX = 523 - item.SetDisplayY(723); // test code,set the DisplayY = 723 - item.SetPressure(5); // test code,set the Pressure = 5 - item.SetDeviceId(1); // test code,set the DeviceId = 1 + item.SetPointerId(0); + item.SetDisplayX(523); + item.SetDisplayY(723); + item.SetPressure(5); + item.SetDeviceId(1); pointerEvent->AddPointerItem(item); - item.SetPointerId(1); // test code,set the PointerId = 1 - item.SetDisplayX(623); // test code,set the DisplayX = 623 - item.SetDisplayY(823); // test code,set the DisplayY = 823 - item.SetPressure(0); // test code,set the Pressure = 0 - item.SetDeviceId(1); // test code,set the DeviceId = 1 + item.SetPointerId(1); + item.SetDisplayX(623); + item.SetDisplayY(823); + item.SetPressure(0); + item.SetDeviceId(1); pointerEvent->AddPointerItem(item); pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP); - pointerEvent->SetPointerId(1); // test code,set the PointerId = 1 + pointerEvent->SetPointerId(1); pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); return pointerEvent; } @@ -532,16 +535,16 @@ std::shared_ptr InputManagerTest::TestMarkConsumedStep1() auto pointerEvent = PointerEvent::Create(); CHKPP(pointerEvent); PointerEvent::PointerItem item; - item.SetPointerId(0); // test code,set the PointerId = 0 - item.SetDisplayX(523); // test code,set the DisplayX = 523 - item.SetDisplayY(723); // test code,set the DisplayY = 723 - item.SetPressure(5); // test code,set the Pressure = 5 - item.SetDeviceId(1); // test code,set the DeviceId = 1 + item.SetPointerId(0); + item.SetDisplayX(523); + item.SetDisplayY(723); + item.SetPressure(5); + item.SetDeviceId(1); pointerEvent->AddPointerItem(item); pointerEvent->SetId(std::numeric_limits::max() - INDEX_THIRD); pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); - pointerEvent->SetPointerId(0); // test code,set the PointerId = 1 + pointerEvent->SetPointerId(0); pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); #if defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR) @@ -556,16 +559,16 @@ std::shared_ptr InputManagerTest::TestMarkConsumedStep2() auto pointerEvent = PointerEvent::Create(); CHKPP(pointerEvent); PointerEvent::PointerItem item; - item.SetPointerId(0); // test code,set the PointerId = 0 - item.SetDisplayX(623); // test code,set the DisplayX = 623 - item.SetDisplayY(723); // test code,set the DisplayY = 723 - item.SetPressure(5); // test code,set the Pressure = 5 - item.SetDeviceId(1); // test code,set the DeviceId = 1 + item.SetPointerId(0); + item.SetDisplayX(623); + item.SetDisplayY(723); + item.SetPressure(5); + item.SetDeviceId(1); pointerEvent->AddPointerItem(item); pointerEvent->SetId(std::numeric_limits::max() - INDEX_SECOND); pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE); - pointerEvent->SetPointerId(0); // test code,set the PointerId = 1 + pointerEvent->SetPointerId(0); pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); #if defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR) @@ -588,16 +591,16 @@ void InputManagerTest::TestMarkConsumedStep4() auto pointerEvent = PointerEvent::Create(); CHKPV(pointerEvent); PointerEvent::PointerItem item; - item.SetPointerId(0); // test code,set the PointerId = 0 - item.SetDisplayX(523); // test code,set the DisplayX = 523 - item.SetDisplayY(723); // test code,set the DisplayY = 723 - item.SetPressure(5); // test code,set the Pressure = 5 - item.SetDeviceId(1); // test code,set the DeviceId = 1 + item.SetPointerId(0); + item.SetDisplayX(523); + item.SetDisplayY(723); + item.SetPressure(5); + item.SetDeviceId(1); pointerEvent->AddPointerItem(item); pointerEvent->SetId(std::numeric_limits::max() - INDEX_FIRST); pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE); - pointerEvent->SetPointerId(0); // test code,set the PointerId = 1 + pointerEvent->SetPointerId(0); pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); #if defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR) @@ -611,16 +614,16 @@ void InputManagerTest::TestMarkConsumedStep5() auto pointerEvent = PointerEvent::Create(); CHKPV(pointerEvent); PointerEvent::PointerItem item; - item.SetPointerId(0); // test code,set the PointerId = 0 - item.SetDisplayX(523); // test code,set the DisplayX = 523 - item.SetDisplayY(723); // test code,set the DisplayY = 723 - item.SetPressure(5); // test code,set the Pressure = 5 - item.SetDeviceId(1); // test code,set the DeviceId = 1 + item.SetPointerId(0); + item.SetDisplayX(523); + item.SetDisplayY(723); + item.SetPressure(5); + item.SetDeviceId(1); pointerEvent->AddPointerItem(item); pointerEvent->SetId(std::numeric_limits::max()); pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP); - pointerEvent->SetPointerId(0); // test code,set the PointerId = 0 + pointerEvent->SetPointerId(0); pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); #if defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR) @@ -635,16 +638,16 @@ void InputManagerTest::TestMarkConsumedStep6() auto pointerEvent = PointerEvent::Create(); CHKPV(pointerEvent); PointerEvent::PointerItem item; - item.SetPointerId(0); // test code,set the PointerId = 0 - item.SetDisplayX(523); // test code,set the DisplayX = 523 - item.SetDisplayY(723); // test code,set the DisplayY = 723 - item.SetPressure(5); // test code,set the Pressure = 5 - item.SetDeviceId(1); // test code,set the DeviceId = 1 + item.SetPointerId(0); + item.SetDisplayX(523); + item.SetDisplayY(723); + item.SetPressure(5); + item.SetDeviceId(1); pointerEvent->AddPointerItem(item); pointerEvent->SetId(std::numeric_limits::max()); pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); - pointerEvent->SetPointerId(0); // test code,set the PointerId = 0 + pointerEvent->SetPointerId(0); pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); TestUtil->SetRecvFlag(RECV_FLAG::RECV_FOCUS); @@ -756,6 +759,46 @@ void InputManagerTest::TestMarkConsumed(int32_t monitorId, int32_t eventId) InputManager::GetInstance()->MarkConsumed(monitorId, eventId); } +/** + * @tc.name: InputManagerTest_AddMonitor_001 + * @tc.desc: Verify pointerevent monitor + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerTest, InputManagerTest_AddMonitor_001, TestSize.Level1) +{ + CALL_TEST_DEBUG; + auto PointerEventFun = [](std::shared_ptr event) { + MMI_HILOGD("Add monitor success"); + }; + int32_t monitorId = InputManager::GetInstance()->AddMonitor(PointerEventFun); +#if (defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)) && defined(OHOS_BUILD_ENABLE_MONITOR) + ASSERT_NE(monitorId, INVALID_HANDLER_ID); +#else + ASSERT_EQ(monitorId, ERROR_UNSUPPORT); +#endif // OHOS_BUILD_ENABLE_MONITOR || OHOS_BUILD_ENABLE_TOUCH && OHOS_BUILD_ENABLE_MONITOR +} + +/** + * @tc.name: InputManagerTest_AddMonitor_002 + * @tc.desc: Verify keyevent monitor + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerTest, InputManagerTest_AddMonitor_002, TestSize.Level1) +{ + CALL_TEST_DEBUG; + auto keyEventFun = [](std::shared_ptr event) { + MMI_HILOGD("Add monitor success"); + }; + int32_t monitorId = InputManager::GetInstance()->AddMonitor(keyEventFun); +#if defined(OHOS_BUILD_ENABLE_KEYBOARD) && defined(OHOS_BUILD_ENABLE_MONITOR) + ASSERT_NE(monitorId, INVALID_HANDLER_ID); +#else + ASSERT_EQ(monitorId, ERROR_UNSUPPORT); +#endif // OHOS_BUILD_ENABLE_KEYBOARD || OHOS_BUILD_ENABLE_MONITOR +} + /** * @tc.name: MultimodalEventHandler_SimulateKeyEvent_001 * @tc.desc: Verify simulate the back key is long pressed and lifted @@ -764,7 +807,7 @@ void InputManagerTest::TestMarkConsumed(int32_t monitorId, int32_t eventId) */ HWTEST_F(InputManagerTest, InputManagerTest_SimulateKeyEvent_001, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND; std::shared_ptr injectDownEvent = KeyEvent::Create(); ASSERT_TRUE(injectDownEvent != nullptr); @@ -802,7 +845,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_SimulateKeyEvent_001, TestSize.Level */ HWTEST_F(InputManagerTest, InputManagerTest_SimulateKeyEvent_002, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; std::shared_ptr injectDownEvent = KeyEvent::Create(); ASSERT_TRUE(injectDownEvent != nullptr); int64_t downTime = -1; @@ -826,7 +869,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_SimulateKeyEvent_002, TestSize.Level */ HWTEST_F(InputManagerTest, InputManagerTest_SimulateKeyEvent_003, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; std::shared_ptr injectDownEvent = KeyEvent::Create(); ASSERT_TRUE(injectDownEvent != nullptr); int64_t downTime = 0; @@ -863,7 +906,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_SimulateKeyEvent_003, TestSize.Level */ HWTEST_F(InputManagerTest, InputManagerTest_SimulateKeyEvent_004, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; std::shared_ptr injectDownEvent = KeyEvent::Create(); ASSERT_TRUE(injectDownEvent != nullptr); int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND; @@ -887,7 +930,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_SimulateKeyEvent_004, TestSize.Level */ HWTEST_F(InputManagerTest, InputManagerTest_SimulateKeyEvent_005, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; std::shared_ptr injectDownEvent = KeyEvent::Create(); ASSERT_TRUE(injectDownEvent != nullptr); int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND; @@ -925,7 +968,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_SimulateKeyEvent_005, TestSize.Level */ HWTEST_F(InputManagerTest, InputManagerTest_SimulatePointerEvent_001, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; std::shared_ptr pointerEvent { SetupPointerEvent001() }; ASSERT_TRUE(pointerEvent != nullptr); #ifdef OHOS_BUILD_ENABLE_TOUCH @@ -941,7 +984,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_SimulatePointerEvent_001, TestSize.L */ HWTEST_F(InputManagerTest, InputManagerTest_SimulatePointerEvent_002, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; std::shared_ptr pointerEvent { SetupPointerEvent002() }; ASSERT_TRUE(pointerEvent != nullptr); #ifdef OHOS_BUILD_ENABLE_TOUCH @@ -957,7 +1000,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_SimulatePointerEvent_002, TestSize.L */ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_003, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; std::shared_ptr pointerEvent { SetupPointerEvent003() }; ASSERT_TRUE(pointerEvent != nullptr); #ifdef OHOS_BUILD_ENABLE_TOUCH @@ -973,7 +1016,7 @@ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_003, Test */ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_004, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto pointerEvent = PointerEvent::Create(); ASSERT_TRUE(pointerEvent != nullptr); pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP); @@ -992,7 +1035,7 @@ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_004, Test */ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_005, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; std::shared_ptr pointerEvent { SetupPointerEvent005() }; ASSERT_TRUE(pointerEvent != nullptr); #ifdef OHOS_BUILD_ENABLE_POINTER @@ -1008,7 +1051,7 @@ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_005, Test */ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_006, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; std::shared_ptr pointerEvent { SetupPointerEvent006() }; ASSERT_TRUE(pointerEvent != nullptr); #ifdef OHOS_BUILD_ENABLE_POINTER @@ -1024,7 +1067,7 @@ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_006, Test */ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_007, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; std::shared_ptr pointerEvent { SetupPointerEvent007() }; ASSERT_TRUE(pointerEvent != nullptr); #ifdef OHOS_BUILD_ENABLE_POINTER @@ -1040,7 +1083,7 @@ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_007, Test */ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_008, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto pointerEvent = PointerEvent::Create(); ASSERT_TRUE(pointerEvent != nullptr); pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP); @@ -1059,7 +1102,7 @@ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_008, Test */ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_009, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; std::shared_ptr pointerEvent { SetupPointerEvent009() }; ASSERT_TRUE(pointerEvent != nullptr); #ifdef OHOS_BUILD_ENABLE_POINTER @@ -1075,7 +1118,7 @@ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_009, Test */ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_010, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; std::shared_ptr pointerEvent { SetupPointerEvent010() }; ASSERT_TRUE(pointerEvent != nullptr); #ifdef OHOS_BUILD_ENABLE_POINTER @@ -1091,7 +1134,7 @@ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_010, Test */ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_011, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto pointerEvent = PointerEvent::Create(); ASSERT_TRUE(pointerEvent != nullptr); pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); @@ -1127,7 +1170,7 @@ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_011, Test */ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_012, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto pointerEvent = PointerEvent::Create(); ASSERT_TRUE(pointerEvent != nullptr); pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); @@ -1163,7 +1206,7 @@ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_012, Test */ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_013, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto pointerEvent = PointerEvent::Create(); ASSERT_TRUE(pointerEvent != nullptr); pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); @@ -1200,7 +1243,7 @@ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_013, Test */ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_014, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; std::shared_ptr pointerEvent { SetupPointerEvent016() }; ASSERT_TRUE(pointerEvent != nullptr); TestSimulateInputEvent(pointerEvent); @@ -1215,7 +1258,7 @@ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePointerEvent_014, Test */ HWTEST_F(InputManagerTest, InputManagerTest_MouseEventEnterAndLeave_001, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; std::shared_ptr pointerEvent { SetupPointerEvent014() }; ASSERT_TRUE(pointerEvent != nullptr); #ifdef OHOS_BUILD_ENABLE_POINTER @@ -1231,7 +1274,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_MouseEventEnterAndLeave_001, TestSiz */ HWTEST_F(InputManagerTest, InputManagerTest_MouseEventEnterAndLeave_002, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; std::shared_ptr keyEvent { SetupKeyEvent002() }; ASSERT_TRUE(keyEvent != nullptr); #ifdef OHOS_BUILD_ENABLE_KEYBOARD @@ -1247,7 +1290,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_MouseEventEnterAndLeave_002, TestSiz */ HWTEST_F(InputManagerTest, InputManagerTest_MouseEventEnterAndLeave_003, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; std::shared_ptr keyEvent { SetupKeyEvent003() }; ASSERT_TRUE(keyEvent != nullptr); #ifdef OHOS_BUILD_ENABLE_KEYBOARD @@ -1263,7 +1306,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_MouseEventEnterAndLeave_003, TestSiz */ HWTEST_F(InputManagerTest, InputManagerTest_MouseEventEnterAndLeave_004, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; std::shared_ptr pointerEvent { SetupPointerEvent015() }; ASSERT_TRUE(pointerEvent != nullptr); #ifdef OHOS_BUILD_ENABLE_POINTER @@ -1279,7 +1322,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_MouseEventEnterAndLeave_004, TestSiz */ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePencil2Event_001, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; std::shared_ptr pointerEvent { SetupPointerEvent011() }; ASSERT_TRUE(pointerEvent != nullptr); #ifdef OHOS_BUILD_ENABLE_TOUCH @@ -1295,7 +1338,7 @@ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePencil2Event_001, Test */ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePencil2Event_002, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; std::shared_ptr pointerEvent { SetupPointerEvent012() }; ASSERT_TRUE(pointerEvent != nullptr); #ifdef OHOS_BUILD_ENABLE_TOUCH @@ -1311,7 +1354,7 @@ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePencil2Event_002, Test */ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePencil2Event_003, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; std::shared_ptr pointerEvent { SetupPointerEvent013() }; ASSERT_TRUE(pointerEvent != nullptr); #ifdef OHOS_BUILD_ENABLE_TOUCH @@ -1327,7 +1370,7 @@ HWTEST_F(InputManagerTest, MultimodalEventHandler_SimulatePencil2Event_003, Test */ HWTEST_F(InputManagerTest, InputManager_Pencil2InputEvent_004, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto pointerEvent = PointerEvent::Create(); ASSERT_TRUE(pointerEvent != nullptr); pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE); @@ -1346,7 +1389,7 @@ HWTEST_F(InputManagerTest, InputManager_Pencil2InputEvent_004, TestSize.Level1) */ HWTEST_F(InputManagerTest, InputManager_NotResponse_001, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto pointerEvent = PointerEvent::Create(); ASSERT_NE(pointerEvent, nullptr); @@ -1372,7 +1415,7 @@ HWTEST_F(InputManagerTest, InputManager_NotResponse_001, TestSize.Level1) */ HWTEST_F(InputManagerTest, InputManager_NotResponse_002, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto pointerEvent = PointerEvent::Create(); ASSERT_NE(pointerEvent, nullptr); @@ -1390,6 +1433,17 @@ HWTEST_F(InputManagerTest, InputManager_NotResponse_002, TestSize.Level1) InputManager::GetInstance()->SimulateInputEvent(pointerEvent); } +std::shared_ptr InputManagerTest::InitOption(const std::set &preKeys, + int32_t finalKey, bool isFinalKeyDown, int32_t duration) +{ + std::shared_ptr keyOption = std::make_shared(); + keyOption->SetPreKeys(preKeys); + keyOption->SetFinalKey(finalKey); + keyOption->SetFinalKeyDown(isFinalKeyDown); + keyOption->SetFinalKeyDownDuration(duration); + return keyOption; +} + /** * @tc.name: InputManagerTest_SubscribeKeyEvent_001 * @tc.desc: Verify invalid parameter. @@ -1399,13 +1453,9 @@ HWTEST_F(InputManagerTest, InputManager_NotResponse_002, TestSize.Level1) */ HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_001, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; std::set preKeys; - std::shared_ptr keyOption = std::make_shared(); - keyOption->SetPreKeys(preKeys); - keyOption->SetFinalKey(KeyEvent::KEYCODE_VOLUME_MUTE); - keyOption->SetFinalKeyDown(true); - keyOption->SetFinalKeyDownDuration(0); + std::shared_ptr keyOption = InitOption(preKeys, KeyEvent::KEYCODE_VOLUME_MUTE, true, 0); int32_t response = -1; response = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, nullptr); EXPECT_TRUE(response < 0); @@ -1422,15 +1472,11 @@ HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_001, TestSize.Leve */ HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_02, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; ASSERT_TRUE(MMIEventHdl.InitClient()); // 电源键长按按下订阅 std::set preKeys; - std::shared_ptr keyOption = std::make_shared(); - keyOption->SetPreKeys(preKeys); - keyOption->SetFinalKey(KeyEvent::KEYCODE_POWER); - keyOption->SetFinalKeyDown(true); - keyOption->SetFinalKeyDownDuration(2000); + std::shared_ptr keyOption = InitOption(preKeys, KeyEvent::KEYCODE_POWER, true, 2000); int32_t subscribeId1 = -1; subscribeId1 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr keyEvent) { @@ -1444,11 +1490,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_02, TestSize.Level #endif // OHOS_BUILD_ENABLE_KEYBOARD // 电源键抬起订阅 - std::shared_ptr keyOption2 = std::make_shared(); - keyOption2->SetPreKeys(preKeys); - keyOption2->SetFinalKey(KeyEvent::KEYCODE_POWER); - keyOption2->SetFinalKeyDown(false); - keyOption2->SetFinalKeyDownDuration(0); + std::shared_ptr keyOption2 = InitOption(preKeys, KeyEvent::KEYCODE_POWER, false, 0); int32_t subscribeId2 = -1; subscribeId2 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption2, [](std::shared_ptr keyEvent) { @@ -1475,47 +1517,31 @@ HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_02, TestSize.Level */ HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_03, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; ASSERT_TRUE(MMIEventHdl.InitClient()); std::set preKeys; - std::shared_ptr keyOption1 = std::make_shared(); - keyOption1->SetPreKeys(preKeys); - keyOption1->SetFinalKey(KeyEvent::KEYCODE_VOLUME_UP); - keyOption1->SetFinalKeyDown(true); - keyOption1->SetFinalKeyDownDuration(10); + std::shared_ptr keyOption1 = InitOption(preKeys, KeyEvent::KEYCODE_VOLUME_UP, true, 10); int32_t subscribeId1 = -1; subscribeId1 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption1, [](std::shared_ptr keyEvent) { EventLogHelper::PrintEventData(keyEvent); MMI_HILOGD("Subscribe key event KEYCODE_VOLUME_UP down trigger callback"); }); - std::shared_ptr keyOption2 = std::make_shared(); - keyOption2->SetPreKeys(preKeys); - keyOption2->SetFinalKey(KeyEvent::KEYCODE_VOLUME_UP); - keyOption2->SetFinalKeyDown(false); - keyOption2->SetFinalKeyDownDuration(0); + std::shared_ptr keyOption2 = InitOption(preKeys, KeyEvent::KEYCODE_VOLUME_UP, false, 0); int32_t subscribeId2 = -1; subscribeId2 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption2, [](std::shared_ptr keyEvent) { EventLogHelper::PrintEventData(keyEvent); MMI_HILOGD("Subscribe key event KEYCODE_VOLUME_UP up trigger callback"); }); - std::shared_ptr keyOption3 = std::make_shared(); - keyOption3->SetPreKeys(preKeys); - keyOption3->SetFinalKey(KeyEvent::KEYCODE_VOLUME_UP); - keyOption3->SetFinalKeyDown(true); - keyOption3->SetFinalKeyDownDuration(0); + std::shared_ptr keyOption3 = InitOption(preKeys, KeyEvent::KEYCODE_VOLUME_UP, true, 0); int32_t subscribeId3 = -1; subscribeId3 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption3, [](std::shared_ptr keyEvent) { EventLogHelper::PrintEventData(keyEvent); MMI_HILOGD("Subscribe key event KEYCODE_VOLUME_UP down trigger callback"); }); - std::shared_ptr keyOption4 = std::make_shared(); - keyOption4->SetPreKeys(preKeys); - keyOption4->SetFinalKey(KeyEvent::KEYCODE_VOLUME_UP); - keyOption4->SetFinalKeyDown(false); - keyOption4->SetFinalKeyDownDuration(0); + std::shared_ptr keyOption4 = InitOption(preKeys, KeyEvent::KEYCODE_VOLUME_UP, false, 0); int32_t subscribeId4 = -1; subscribeId4 = InputManager::GetInstance()->SubscribeKeyEvent(keyOption4, [](std::shared_ptr keyEvent) { @@ -1531,6 +1557,47 @@ HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_03, TestSize.Level std::this_thread::sleep_for(std::chrono::milliseconds(1000)); } +/** + * @tc.name: InputManagerTest_SubscribeKeyEvent_04 + * @tc.desc: Verify subscribe key event. + * @tc.type: FUNC + * @tc.require: + * @tc.author: + */ +HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_04, TestSize.Level1) +{ + CALL_TEST_DEBUG; + std::set preKeys; + std::shared_ptr keyOption = std::make_shared(); + keyOption->SetPreKeys(preKeys); + keyOption->SetFinalKey(KeyEvent::KEYCODE_VOLUME_DOWN); + keyOption->SetFinalKeyDown(true); + keyOption->SetFinalKeyDownDuration(-1); + int32_t subscribeId = -1; + subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, + [](std::shared_ptr keyEvent) { + EventLogHelper::PrintEventData(keyEvent); + MMI_HILOGD("Subscribe key event KEYCODE_POWER down trigger callback"); + }); +#ifdef OHOS_BUILD_ENABLE_KEYBOARD + EXPECT_TRUE(subscribeId >= 0); +#else + EXPECT_TRUE(subscribeId < 0); +#endif // OHOS_BUILD_ENABLE_KEYBOARD + std::shared_ptr injectDownEvent = KeyEvent::Create(); + ASSERT_TRUE(injectDownEvent != nullptr); + int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND; + KeyEvent::KeyItem kitDown; + kitDown.SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN); + kitDown.SetPressed(true); + kitDown.SetDownTime(downTime); + injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN); + injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN); + injectDownEvent->AddPressedKeyItems(kitDown); + InputManager::GetInstance()->SimulateInputEvent(injectDownEvent); + ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN); +} + /** * @tc.name: TestGetKeystrokeAbility_001 * @tc.desc: Verify SupportKeys @@ -1539,8 +1606,8 @@ HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_03, TestSize.Level */ HWTEST_F(InputManagerTest, TestGetKeystrokeAbility_001, TestSize.Level1) { - CALL_DEBUG_ENTER; - std::vector keyCodes = {17, 22, 2055}; + CALL_TEST_DEBUG; + std::vector keyCodes = { 17, 22, 2055 }; InputManager::GetInstance()->SupportKeys(0, keyCodes, [](std::vector keystrokeAbility) { MMI_HILOGD("TestGetKeystrokeAbility_001 callback ok"); }); @@ -1555,7 +1622,7 @@ HWTEST_F(InputManagerTest, TestGetKeystrokeAbility_001, TestSize.Level1) */ HWTEST_F(InputManagerTest, TestInputEventInterceptor_001, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto pointerEvent = PointerEvent::Create(); ASSERT_TRUE(pointerEvent != nullptr); PointerEvent::PointerItem item; @@ -1597,7 +1664,7 @@ HWTEST_F(InputManagerTest, TestInputEventInterceptor_001, TestSize.Level1) */ HWTEST_F(InputManagerTest, TestInputEventInterceptor_002, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto pointerEvent = PointerEvent::Create(); ASSERT_TRUE(pointerEvent != nullptr); PointerEvent::PointerItem item; @@ -1639,7 +1706,7 @@ HWTEST_F(InputManagerTest, TestInputEventInterceptor_002, TestSize.Level1) */ HWTEST_F(InputManagerTest, TestInputEventInterceptor_003, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto pointerEvent = PointerEvent::Create(); ASSERT_TRUE(pointerEvent != nullptr); PointerEvent::PointerItem item; @@ -1681,7 +1748,7 @@ HWTEST_F(InputManagerTest, TestInputEventInterceptor_003, TestSize.Level1) */ HWTEST_F(InputManagerTest, TestInputEventInterceptor_004, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; TestUtil->SetRecvFlag(RECV_FLAG::RECV_INTERCEPT); auto pointerEvent = PointerEvent::Create(); ASSERT_TRUE(pointerEvent != nullptr); @@ -1713,16 +1780,20 @@ HWTEST_F(InputManagerTest, TestInputEventInterceptor_004, TestSize.Level1) InputManager::GetInstance()->SimulateInputEvent(pointerEvent); - for (const auto &id : ids) { + for (size_t i = 0; i < ids.size(); ++i) { std::string sPointerEs = InputManagerTest::GetEventDump(); MMI_HILOGD("sPointerEs:%{public}s", sPointerEs.c_str()); #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_INTERCEPTOR) - ASSERT_TRUE(!sPointerEs.empty()); + if (i == 0) { + ASSERT_TRUE(!sPointerEs.empty()); + } else { + ASSERT_TRUE(sPointerEs.empty()); + } #else ASSERT_TRUE(sPointerEs.empty()); #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_INTERCEPTOR - if (IsValidHandlerId(id)) { - InputManager::GetInstance()->RemoveInterceptor(id); + if (IsValidHandlerId(ids[i])) { + InputManager::GetInstance()->RemoveInterceptor(ids[i]); } std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); } @@ -1736,7 +1807,7 @@ HWTEST_F(InputManagerTest, TestInputEventInterceptor_004, TestSize.Level1) */ HWTEST_F(InputManagerTest, TestInputEventInterceptor_005, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto pointerEvent = PointerEvent::Create(); ASSERT_TRUE(pointerEvent != nullptr); pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); @@ -1779,24 +1850,24 @@ HWTEST_F(InputManagerTest, TestInputEventInterceptor_005, TestSize.Level1) */ HWTEST_F(InputManagerTest, TestInputEventInterceptor_006, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto pointerEvent = PointerEvent::Create(); ASSERT_TRUE(pointerEvent != nullptr); PointerEvent::PointerItem item; - item.SetPointerId(0); // test code,set the PointerId = 0 - item.SetDisplayX(523); // test code,set the DisplayX = 523 - item.SetDisplayY(723); // test code,set the DisplayY = 723 - item.SetPressure(5); // test code,set the Pressure = 5 - item.SetDeviceId(1); // test code,set the DeviceId = 1 + item.SetPointerId(0); + item.SetDisplayX(523); + item.SetDisplayY(723); + item.SetPressure(5); + item.SetDeviceId(1); pointerEvent->AddPointerItem(item); - item.SetPointerId(1); // test code,set the PointerId = 1 - item.SetDisplayX(710); // test code,set the DisplayX = 710 - item.SetDisplayY(910); // test code,set the DisplayY = 910 - item.SetPressure(7); // test code,set the Pressure = 7 - item.SetDeviceId(1); // test code,set the DeviceId = 1 + item.SetPointerId(1); + item.SetDisplayX(710); + item.SetDisplayY(910); + item.SetPressure(7); + item.SetDeviceId(1); pointerEvent->AddPointerItem(item); pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP); - pointerEvent->SetPointerId(1); // test code,set the PointerId = 1 + pointerEvent->SetPointerId(1); pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); auto interceptor = GetPtr(); @@ -1826,7 +1897,7 @@ HWTEST_F(InputManagerTest, TestInputEventInterceptor_006, TestSize.Level1) */ HWTEST_F(InputManagerTest, TestInputEventInterceptor_007, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; std::shared_ptr injectDownEvent = KeyEvent::Create(); ASSERT_TRUE(injectDownEvent != nullptr); int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND; @@ -1865,7 +1936,7 @@ HWTEST_F(InputManagerTest, TestInputEventInterceptor_007, TestSize.Level1) */ HWTEST_F(InputManagerTest, TestInputEventInterceptor_008, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; TestUtil->SetRecvFlag(RECV_FLAG::RECV_INTERCEPT); auto pointerEvent = PointerEvent::Create(); ASSERT_TRUE(pointerEvent != nullptr); @@ -1913,7 +1984,7 @@ HWTEST_F(InputManagerTest, TestInputEventInterceptor_008, TestSize.Level1) */ HWTEST_F(InputManagerTest, TestInputEventInterceptor_009, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; TestUtil->SetRecvFlag(RECV_FLAG::RECV_INTERCEPT); auto pointerEvent = PointerEvent::Create(); ASSERT_TRUE(pointerEvent != nullptr); @@ -1961,7 +2032,7 @@ HWTEST_F(InputManagerTest, TestInputEventInterceptor_009, TestSize.Level1) */ HWTEST_F(InputManagerTest, TestInputEventInterceptor_010, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; TestUtil->SetRecvFlag(RECV_FLAG::RECV_INTERCEPT); std::shared_ptr injectDownEvent = KeyEvent::Create(); ASSERT_TRUE(injectDownEvent != nullptr); @@ -1970,6 +2041,7 @@ HWTEST_F(InputManagerTest, TestInputEventInterceptor_010, TestSize.Level1) kitDown.SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN); kitDown.SetPressed(true); kitDown.SetDownTime(downTime); + kitDown.SetDeviceId(1); injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN); injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN); injectDownEvent->AddPressedKeyItems(kitDown); @@ -2006,7 +2078,7 @@ HWTEST_F(InputManagerTest, TestInputEventInterceptor_010, TestSize.Level1) */ HWTEST_F(InputManagerTest, TestInputEventInterceptor_011, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; TestUtil->SetRecvFlag(RECV_FLAG::RECV_INTERCEPT); std::shared_ptr injectDownEvent = KeyEvent::Create(); ASSERT_TRUE(injectDownEvent != nullptr); @@ -2015,12 +2087,14 @@ HWTEST_F(InputManagerTest, TestInputEventInterceptor_011, TestSize.Level1) kitDown.SetKeyCode(KeyEvent::KEYCODE_SPACE); kitDown.SetPressed(true); kitDown.SetDownTime(downTime); + kitDown.SetDeviceId(1); injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_SPACE); injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN); injectDownEvent->AddPressedKeyItems(kitDown); auto interceptor = GetPtr(); - int32_t interceptorId { InputManager::GetInstance()->AddInterceptor(interceptor) }; + uint32_t touchTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX); + int32_t interceptorId { InputManager::GetInstance()->AddInterceptor(interceptor, 400, touchTags) }; #ifdef OHOS_BUILD_ENABLE_INTERCEPTOR EXPECT_TRUE(IsValidHandlerId(interceptorId)); #else @@ -2031,7 +2105,7 @@ HWTEST_F(InputManagerTest, TestInputEventInterceptor_011, TestSize.Level1) InputManager::GetInstance()->SimulateInputEvent(injectDownEvent); std::string sPointerEs = InputManagerTest::GetEventDump(); - MMI_HILOGD("sPointerEs:%{public}s", sPointerEs.c_str()); + MMI_HILOGD("PriorityLevel Test:sPointerEs:%{public}s", sPointerEs.c_str()); #if defined(OHOS_BUILD_ENABLE_KEYBOARD) && defined(OHOS_BUILD_ENABLE_INTERCEPTOR) ASSERT_TRUE(!sPointerEs.empty()); #else @@ -2043,6 +2117,265 @@ HWTEST_F(InputManagerTest, TestInputEventInterceptor_011, TestSize.Level1) } } +/** + * @tc.name: TestInputEventInterceptor_012 + * @tc.desc: Verify mouse interceptor + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerTest, TestInputEventInterceptor_012, TestSize.Level1) +{ + CALL_TEST_DEBUG; + TestUtil->SetRecvFlag(RECV_FLAG::RECV_INTERCEPT); + auto pointerEvent = PointerEvent::Create(); + ASSERT_TRUE(pointerEvent != nullptr); + PointerEvent::PointerItem item; + item.SetPointerId(0); + item.SetDownTime(10010); + item.SetPressed(true); + item.SetDisplayX(523); + item.SetDisplayY(723); + item.SetDeviceId(1); + pointerEvent->AddPointerItem(item); + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); + pointerEvent->SetPointerId(0); + pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); + + auto interceptor = GetPtr(); + uint32_t touchTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX); + int32_t interceptorId = InputManager::GetInstance()->AddInterceptor(interceptor, 400, touchTags); +#ifdef OHOS_BUILD_ENABLE_INTERCEPTOR + EXPECT_TRUE(IsValidHandlerId(interceptorId)); +#else + EXPECT_EQ(interceptorId, ERROR_UNSUPPORT); +#endif // OHOS_BUILD_ENABLE_INTERCEPTOR + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); + + InputManager::GetInstance()->SimulateInputEvent(pointerEvent); + + std::string sPointerEs = InputManagerTest::GetEventDump(); + MMI_HILOGD("sPointerEs:%{public}s", sPointerEs.c_str()); +#if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_INTERCEPTOR) + ASSERT_TRUE(!sPointerEs.empty()); +#else + ASSERT_TRUE(sPointerEs.empty()); +#endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_INTERCEPTOR + if (IsValidHandlerId(interceptorId)) { + InputManager::GetInstance()->RemoveInterceptor(interceptorId); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); + } +} + +/** + * @tc.name: TestInputEventInterceptor_013 + * @tc.desc: Verify mouse interceptor + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerTest, TestInputEventInterceptor_013, TestSize.Level1) +{ + CALL_TEST_DEBUG; + TestUtil->SetRecvFlag(RECV_FLAG::RECV_INTERCEPT); + auto pointerEvent = PointerEvent::Create(); + ASSERT_TRUE(pointerEvent != nullptr); + PointerEvent::PointerItem item; + item.SetPointerId(0); + item.SetDownTime(10010); + item.SetPressed(true); + item.SetDisplayX(523); + item.SetDisplayY(723); + item.SetDeviceId(1); + pointerEvent->AddPointerItem(item); + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); + pointerEvent->SetPointerId(0); + pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); + + auto interceptor1 = GetPtr(); + auto interceptor2 = GetPtr(); + uint32_t touchTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX); + int32_t interceptorId1 { InputManager::GetInstance()->AddInterceptor(interceptor1, 400, touchTags) }; + int32_t interceptorId2 { InputManager::GetInstance()->AddInterceptor(interceptor2, 500, touchTags) }; +#ifdef OHOS_BUILD_ENABLE_INTERCEPTOR + EXPECT_TRUE(IsValidHandlerId(interceptorId1)); + EXPECT_TRUE(IsValidHandlerId(interceptorId2)); +#else + EXPECT_EQ(interceptorId1, ERROR_UNSUPPORT); + EXPECT_EQ(interceptorId2, ERROR_UNSUPPORT); +#endif // OHOS_BUILD_ENABLE_INTERCEPTOR + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); + InputManager::GetInstance()->SimulateInputEvent(pointerEvent); + + for (size_t i = 0; i < 2; ++i) { + std::string sPointerEs = InputManagerTest::GetEventDump(); + MMI_HILOGD("sPointerEs:%{public}s", sPointerEs.c_str()); + #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_INTERCEPTOR) + if (i == 0) { + EXPECT_EQ(sPointerEs, "Call high interceptor"); + } else { + ASSERT_TRUE(sPointerEs.empty()); + } + #else + ASSERT_TRUE(sPointerEs.empty()); + #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_INTERCEPTOR + } + + if (IsValidHandlerId(interceptorId1)) { + InputManager::GetInstance()->RemoveInterceptor(interceptorId1); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); + } + + if (IsValidHandlerId(interceptorId2)) { + InputManager::GetInstance()->RemoveInterceptor(interceptorId2); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); + } +} + +/** + * @tc.name: TestInputEventInterceptor_014 + * @tc.desc: Verify space key interceptor + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerTest, TestInputEventInterceptor_014, TestSize.Level1) +{ + CALL_TEST_DEBUG; + TestUtil->SetRecvFlag(RECV_FLAG::RECV_INTERCEPT); + std::shared_ptr injectDownEvent = KeyEvent::Create(); + ASSERT_TRUE(injectDownEvent != nullptr); + int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND; + KeyEvent::KeyItem kitDown; + kitDown.SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN); + kitDown.SetPressed(true); + kitDown.SetDownTime(downTime); + kitDown.SetDeviceId(1); + injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN); + injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN); + injectDownEvent->AddPressedKeyItems(kitDown); + + auto interceptor1 = GetPtr(); + auto interceptor2 = GetPtr(); + uint32_t touchTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX); + int32_t interceptorId1 { InputManager::GetInstance()->AddInterceptor(interceptor1, 400, touchTags) }; + int32_t interceptorId2 { InputManager::GetInstance()->AddInterceptor(interceptor2, 500, touchTags) }; +#ifdef OHOS_BUILD_ENABLE_INTERCEPTOR + EXPECT_TRUE(IsValidHandlerId(interceptorId1)); + EXPECT_TRUE(IsValidHandlerId(interceptorId2)); +#else + EXPECT_EQ(interceptorId1, ERROR_UNSUPPORT); + EXPECT_EQ(interceptorId2, ERROR_UNSUPPORT); +#endif // OHOS_BUILD_ENABLE_INTERCEPTOR + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); + + InputManager::GetInstance()->SimulateInputEvent(injectDownEvent); + for (size_t i = 0; i < 2; ++i) { + std::string sPointerEs = InputManagerTest::GetEventDump(); + MMI_HILOGD("PriorityLevel Test:sPointerEs:%{public}s", sPointerEs.c_str()); + #if defined(OHOS_BUILD_ENABLE_KEYBOARD) && defined(OHOS_BUILD_ENABLE_INTERCEPTOR) + if (i == 0) { + EXPECT_EQ(sPointerEs, "Call high interceptor"); + } else { + ASSERT_TRUE(sPointerEs.empty()); + } + #else + ASSERT_TRUE(sPointerEs.empty()); + #endif // OHOS_BUILD_ENABLE_KEYBOARD && OHOS_BUILD_ENABLE_INTERCEPTOR + } + + if (IsValidHandlerId(interceptorId1)) { + InputManager::GetInstance()->RemoveInterceptor(interceptorId1); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); + } + + if (IsValidHandlerId(interceptorId2)) { + InputManager::GetInstance()->RemoveInterceptor(interceptorId2); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); + } +} + +/** + * @tc.name: TestInputEventInterceptor_015 + * @tc.desc: Verify space key interceptor + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerTest, TestInputEventInterceptor_015, TestSize.Level1) +{ + CALL_TEST_DEBUG; + TestUtil->SetRecvFlag(RECV_FLAG::RECV_INTERCEPT); + std::shared_ptr injectDownEvent = KeyEvent::Create(); + ASSERT_TRUE(injectDownEvent != nullptr); + int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND; + KeyEvent::KeyItem kitDown; + kitDown.SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN); + kitDown.SetPressed(true); + kitDown.SetDownTime(downTime); + kitDown.SetDeviceId(1); + injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_VOLUME_DOWN); + injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN); + injectDownEvent->AddPressedKeyItems(kitDown); + + auto interceptor1 = GetPtr(); + auto interceptor2 = GetPtr(); + uint32_t touchTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX); + int32_t interceptorId1 { InputManager::GetInstance()->AddInterceptor(interceptor1, 400, touchTags) }; + int32_t interceptorId2 { InputManager::GetInstance()->AddInterceptor(interceptor2, 500, touchTags) }; +#ifdef OHOS_BUILD_ENABLE_INTERCEPTOR + EXPECT_TRUE(IsValidHandlerId(interceptorId1)); + EXPECT_TRUE(IsValidHandlerId(interceptorId2)); +#else + EXPECT_EQ(interceptorId1, ERROR_UNSUPPORT); + EXPECT_EQ(interceptorId2, ERROR_UNSUPPORT); +#endif // OHOS_BUILD_ENABLE_INTERCEPTOR + if (IsValidHandlerId(interceptorId1)) { + InputManager::GetInstance()->RemoveInterceptor(interceptorId1); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); + } + + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); + InputManager::GetInstance()->SimulateInputEvent(injectDownEvent); + for (size_t i = 0; i < 3; ++i) { + std::string sPointerEs = InputManagerTest::GetEventDump(); + MMI_HILOGD("PriorityLevel Test:sPointerEs:%{public}s", sPointerEs.c_str()); + #if defined(OHOS_BUILD_ENABLE_KEYBOARD) && defined(OHOS_BUILD_ENABLE_INTERCEPTOR) + if (i == 0) { + EXPECT_EQ(sPointerEs, "Call middle interceptor"); + } else { + ASSERT_TRUE(sPointerEs.empty()); + } + #else + ASSERT_TRUE(sPointerEs.empty()); + #endif // OHOS_BUILD_ENABLE_KEYBOARD && OHOS_BUILD_ENABLE_INTERCEPTOR + } + + if (IsValidHandlerId(interceptorId2)) { + InputManager::GetInstance()->RemoveInterceptor(interceptorId2); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); + } +} + +/** + * @tc.name: TestInputEventInterceptor_016 + * @tc.desc: Verify keyevent interceptor + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerTest, TestInputEventInterceptor_016, TestSize.Level1) +{ + CALL_TEST_DEBUG; + auto fun = [](std::shared_ptr keyEvent) { + MMI_HILOGD("Add interceptor success"); + }; + int32_t interceptorId = InputManager::GetInstance()->AddInterceptor(fun); +#if defined(OHOS_BUILD_ENABLE_KEYBOARD) && defined(OHOS_BUILD_ENABLE_INTERCEPTOR) + ASSERT_NE(interceptorId, INVALID_HANDLER_ID); +#else + ASSERT_EQ(interceptorId, ERROR_UNSUPPORT); +#endif // OHOS_BUILD_ENABLE_KEYBOARD && OHOS_BUILD_ENABLE_INTERCEPTOR + if (IsValidHandlerId(interceptorId)) { + InputManager::GetInstance()->RemoveInterceptor(interceptorId); + } +} + /** * @tc.name: InputManagerTest_OnAddScreenMonitor_001 * @tc.desc: Verify touchscreen down event monitor @@ -2051,7 +2384,7 @@ HWTEST_F(InputManagerTest, TestInputEventInterceptor_011, TestSize.Level1) */ HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_001, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto pointerEvent = SetupPointerEvent001(); ASSERT_TRUE(pointerEvent != nullptr); @@ -2083,7 +2416,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_001, TestSize.Lev */ HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_002, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; TestUtil->SetRecvFlag(RECV_FLAG::RECV_MONITOR); const std::vector::size_type N_TEST_CASES { 3 }; std::vector ids(N_TEST_CASES); @@ -2127,7 +2460,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_002, TestSize.Lev */ HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_003, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto pointerEvent = SetupPointerEvent003(); ASSERT_TRUE(pointerEvent != nullptr); @@ -2159,7 +2492,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_003, TestSize.Lev */ HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_004, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto callbackPtr = GetPtr(); ASSERT_TRUE(callbackPtr != nullptr); int32_t monitorId = TestAddMonitor(callbackPtr); @@ -2192,7 +2525,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_004, TestSize.Lev */ HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_005, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto callbackPtr = GetPtr(); ASSERT_TRUE(callbackPtr != nullptr); int32_t monitorId = TestAddMonitor(callbackPtr); @@ -2224,7 +2557,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddScreenMonitor_005, TestSize.Lev */ HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_001, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto pointerEvent = PointerEvent::Create(); ASSERT_TRUE(pointerEvent != nullptr); PointerEvent::PointerItem item; @@ -2267,7 +2600,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_001, TestSize.L */ HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_002, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto pointerEvent = PointerEvent::Create(); ASSERT_TRUE(pointerEvent != nullptr); PointerEvent::PointerItem item; @@ -2310,7 +2643,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_002, TestSize.L */ HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_003, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto pointerEvent = PointerEvent::Create(); ASSERT_TRUE(pointerEvent != nullptr); PointerEvent::PointerItem item; @@ -2353,7 +2686,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_003, TestSize.L */ HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_004, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; TestUtil->SetRecvFlag(RECV_FLAG::RECV_MONITOR); auto pointerEvent = PointerEvent::Create(); ASSERT_TRUE(pointerEvent != nullptr); @@ -2408,7 +2741,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_004, TestSize.L */ HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_005, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto pointerEvent = PointerEvent::Create(); ASSERT_TRUE(pointerEvent != nullptr); PointerEvent::PointerItem item; @@ -2451,7 +2784,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddTouchPadMonitor_005, TestSize.L */ HWTEST_F(InputManagerTest, InputManager_TouchPadSimulateInputEvent_001, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto callbackPtr = GetPtr(); ASSERT_TRUE(callbackPtr != nullptr); int32_t monitorId { TestAddMonitor(callbackPtr) }; @@ -2496,7 +2829,7 @@ HWTEST_F(InputManagerTest, InputManager_TouchPadSimulateInputEvent_001, TestSize */ HWTEST_F(InputManagerTest, InputManager_TouchPadSimulateInputEvent_002, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto callbackPtr = GetPtr(); ASSERT_TRUE(callbackPtr != nullptr); int32_t monitorId { TestAddMonitor(callbackPtr) }; @@ -2541,7 +2874,7 @@ HWTEST_F(InputManagerTest, InputManager_TouchPadSimulateInputEvent_002, TestSize */ HWTEST_F(InputManagerTest, InputManager_TouchPadSimulateInputEvent_003, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto callbackPtr = GetPtr(); ASSERT_TRUE(callbackPtr != nullptr); int32_t monitorId { TestAddMonitor(callbackPtr) }; @@ -2586,7 +2919,7 @@ HWTEST_F(InputManagerTest, InputManager_TouchPadSimulateInputEvent_003, TestSize */ HWTEST_F(InputManagerTest, InputManager_TouchPadSimulateInputEvent_004, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto callbackPtr = GetPtr(); ASSERT_TRUE(callbackPtr != nullptr); int32_t monitorId { TestAddMonitor(callbackPtr) }; @@ -2645,7 +2978,7 @@ HWTEST_F(InputManagerTest, InputManager_TouchPadSimulateInputEvent_004, TestSize */ HWTEST_F(InputManagerTest, InputManagerTest_AddMouseMonitor_001, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto callbackPtr = GetPtr(); ASSERT_TRUE(callbackPtr != nullptr); int32_t monitorId = TestAddMonitor(callbackPtr); @@ -2675,7 +3008,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_AddMouseMonitor_001, TestSize.Level1 */ HWTEST_F(InputManagerTest, InputManagerTest_AddMouseMonitor_002, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto callbackPtr = GetPtr(); ASSERT_TRUE(callbackPtr != nullptr); int32_t monitorId = TestAddMonitor(callbackPtr); @@ -2709,7 +3042,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_AddMouseMonitor_002, TestSize.Level1 */ HWTEST_F(InputManagerTest, InputManagerTest_AddMouseMonitor_003, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto callbackPtr = GetPtr(); ASSERT_TRUE(callbackPtr != nullptr); int32_t monitorId = TestAddMonitor(callbackPtr); @@ -2740,7 +3073,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_AddMouseMonitor_003, TestSize.Level1 */ HWTEST_F(InputManagerTest, InputManagerTest_AddMouseMonitor_004, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; TestUtil->SetRecvFlag(RECV_FLAG::RECV_MONITOR); const std::vector::size_type N_TEST_CASES { MAX_N_INPUT_HANDLERS - 1 }; std::vector ids; @@ -2784,7 +3117,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_AddMouseMonitor_004, TestSize.Level1 */ HWTEST_F(InputManagerTest, InputManagerTest_OnAddKeyboardMonitor_001, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; TestUtil->SetRecvFlag(RECV_FLAG::RECV_MONITOR); const std::vector::size_type N_TEST_CASES { 3 }; std::vector ids; @@ -2825,7 +3158,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddKeyboardMonitor_001, TestSize.L */ HWTEST_F(InputManagerTest, InputManagerTest_OnAddKeyboardMonitor_002, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; const std::vector::size_type N_TEST_CASES { 3 }; std::vector ids; auto callbackPtr = GetPtr(); @@ -2862,7 +3195,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_OnAddKeyboardMonitor_002, TestSize.L */ HWTEST_F(InputManagerTest, InputManagerTest_RemoteControlAutoRepeat, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND; std::shared_ptr injectDownEvent = KeyEvent::Create(); ASSERT_TRUE(injectDownEvent != nullptr); @@ -2902,7 +3235,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_RemoteControlAutoRepeat, TestSize.Le */ HWTEST_F(InputManagerTest, InputManagerTest_MoveMouse_01, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; InputManager::GetInstance()->MoveMouse(50, 50); } @@ -2914,7 +3247,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_MoveMouse_01, TestSize.Level1) */ HWTEST_F(InputManagerTest, InputManagerTest_MoveMouse_02, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; InputManager::GetInstance()->MoveMouse(-1000, 100); } @@ -2975,12 +3308,12 @@ HWTEST_F(InputManagerTest, InputManagerTest_GetKeyboardType, TestSize.Level1) HWTEST_F(InputManagerTest, InputManagerTest_GetProcCpuUsage, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; SYSTEM_INFO::CpuInfo cpuInfo; const std::string process_name = "multimodalinput"; auto usage = cpuInfo.GetProcCpuUsage(process_name); MMI_HILOGD("The CPU usage of the %{public}s process is %{public}.2f", process_name.c_str(), usage); - ASSERT_TRUE(usage < SYSTEM_INFO::CPU_USAGE_LOAD && usage != SYSTEM_INFO::CPU_USAGE_UNKONW); + ASSERT_TRUE(usage < SYSTEM_INFO::CPU_USAGE_LOAD && usage != SYSTEM_INFO::CPU_USAGE_UNKNOWN); } /** @@ -2991,14 +3324,14 @@ HWTEST_F(InputManagerTest, InputManagerTest_GetProcCpuUsage, TestSize.Level1) */ HWTEST_F(InputManagerTest, InputManagerTest_SetWindowInputEventConsumer_001, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto runner = AppExecFwk::EventRunner::Create(true); ASSERT_TRUE(runner != nullptr); auto eventHandler = std::make_shared(runner); ASSERT_TRUE(eventHandler != nullptr); uint64_t runnerThreadId = 0; - auto fun = [&]() { + auto fun = [&runnerThreadId]() { runnerThreadId = GetThisThreadId(); MMI_HILOGD("Create eventHandler is threadId:%{public}" PRIu64, runnerThreadId); ASSERT_TRUE(runnerThreadId != 0); @@ -3028,7 +3361,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_SetWindowInputEventConsumer_001, Tes */ HWTEST_F(InputManagerTest, InputManagerTest_SetWindowInputEventConsumer_002, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; const std::string threadTest = "threadNameTest"; auto runner = AppExecFwk::EventRunner::Create(threadTest); ASSERT_TRUE(runner != nullptr); @@ -3036,7 +3369,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_SetWindowInputEventConsumer_002, Tes ASSERT_TRUE(eventHandler != nullptr); uint64_t runnerThreadId = 0; - auto fun = [&]() { + auto fun = [&runnerThreadId]() { runnerThreadId = GetThisThreadId(); MMI_HILOGD("Create eventHandler is threadId:%{public}" PRIu64, runnerThreadId); ASSERT_TRUE(runnerThreadId != 0); @@ -3095,7 +3428,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_SetPointerVisible_002, TestSize.Leve */ HWTEST_F(InputManagerTest, InputManagerTest_SetPointSpeed_001, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; const int32_t speed = -1; InputManager::GetInstance()->SetPointerSpeed(speed); int32_t speed1; @@ -3124,7 +3457,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_SetPointSpeed_001, TestSize.Level1) */ HWTEST_F(InputManagerTest, InputManagerTest_SetPointSpeed_002, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; const int32_t speed = 1; InputManager::GetInstance()->SetPointerSpeed(speed); int32_t speed1; @@ -3153,7 +3486,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_SetPointSpeed_002, TestSize.Level1) */ HWTEST_F(InputManagerTest, InputManagerTest_SetPointSpeed_003, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; const int32_t speed = 4; InputManager::GetInstance()->SetPointerSpeed(speed); int32_t speed1; @@ -3182,7 +3515,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_SetPointSpeed_003, TestSize.Level1) */ HWTEST_F(InputManagerTest, InputManagerTest_SetPointSpeed_004, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; const int32_t speed = 11; InputManager::GetInstance()->SetPointerSpeed(speed); int32_t speed1; @@ -3211,7 +3544,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_SetPointSpeed_004, TestSize.Level1) */ HWTEST_F(InputManagerTest, InputManagerTest_SetPointSpeed_005, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; const int32_t speed = 20; InputManager::GetInstance()->SetPointerSpeed(speed); int32_t speed1; @@ -3240,13 +3573,32 @@ HWTEST_F(InputManagerTest, InputManagerTest_SetPointSpeed_005, TestSize.Level1) */ HWTEST_F(InputManagerTest, InputManagerTest_SetPointerStyle_001, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto window = WindowUtilsTest::GetInstance()->GetWindow(); uint32_t windowId = window->GetWindowId(); - int32_t pointerStyle; - if (InputManager::GetInstance()->SetPointerStyle(windowId, MOUSE_ICON::CROSS) == RET_OK) { + PointerStyle pointerStyle; + pointerStyle.id = MOUSE_ICON::CROSS; + if (InputManager::GetInstance()->SetPointerStyle(windowId, pointerStyle) == RET_OK) { ASSERT_TRUE(InputManager::GetInstance()->GetPointerStyle(windowId, pointerStyle) == RET_OK); - ASSERT_EQ(pointerStyle, MOUSE_ICON::CROSS); + ASSERT_EQ(pointerStyle.id, MOUSE_ICON::CROSS); + } +} + +/** + * @tc.name: InputManagerTest_SetPointerStyle_002 + * @tc.desc: Sets the pointer style of the window + * @tc.type: FUNC + * @tc.require: I530XS + */ +HWTEST_F(InputManagerTest, InputManagerTest_SetPointerStyle_002, TestSize.Level1) +{ + CALL_TEST_DEBUG; + uint32_t windowId = -1; + PointerStyle pointerStyle; + pointerStyle.id = MOUSE_ICON::CROSS; + if (InputManager::GetInstance()->SetPointerStyle(windowId, pointerStyle) == RET_OK) { + ASSERT_TRUE(InputManager::GetInstance()->GetPointerStyle(windowId, pointerStyle) == RET_OK); + ASSERT_EQ(pointerStyle.id, MOUSE_ICON::CROSS); } } @@ -3258,7 +3610,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_SetPointerStyle_001, TestSize.Level1 */ HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_001, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::NUM_LOCK_FUNCTION_KEY, true); InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::NUM_LOCK_FUNCTION_KEY); } @@ -3271,7 +3623,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_001, TestSize.Level */ HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_002, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::NUM_LOCK_FUNCTION_KEY, false); bool result = InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::NUM_LOCK_FUNCTION_KEY); ASSERT_FALSE(result); @@ -3285,7 +3637,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_002, TestSize.Level */ HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_003, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::SCROLL_LOCK_FUNCTION_KEY, true); InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::SCROLL_LOCK_FUNCTION_KEY); } @@ -3298,7 +3650,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_003, TestSize.Level */ HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_004, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::SCROLL_LOCK_FUNCTION_KEY, false); bool result = InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::SCROLL_LOCK_FUNCTION_KEY); ASSERT_FALSE(result); @@ -3312,7 +3664,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_004, TestSize.Level */ HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_005, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::CAPS_LOCK_FUNCTION_KEY, true); InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::CAPS_LOCK_FUNCTION_KEY); } @@ -3325,7 +3677,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_005, TestSize.Level */ HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_006, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::CAPS_LOCK_FUNCTION_KEY, false); bool result = InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::CAPS_LOCK_FUNCTION_KEY); ASSERT_FALSE(result); @@ -3339,13 +3691,13 @@ HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_006, TestSize.Level */ HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_007, TestSize.Level1) { - CALL_DEBUG_ENTER; - InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::UNKOWN_FUNCTION_KEY, true); - bool result = InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::UNKOWN_FUNCTION_KEY); + CALL_TEST_DEBUG; + InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::UNKNOWN_FUNCTION_KEY, true); + bool result = InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::UNKNOWN_FUNCTION_KEY); ASSERT_FALSE(result); - InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::UNKOWN_FUNCTION_KEY, false); - result = InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::UNKOWN_FUNCTION_KEY); + InputManager::GetInstance()->SetFunctionKeyState(KeyEvent::UNKNOWN_FUNCTION_KEY, false); + result = InputManager::GetInstance()->GetFunctionKeyState(KeyEvent::UNKNOWN_FUNCTION_KEY); ASSERT_FALSE(result); } @@ -3357,7 +3709,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_FunctionKeyState_007, TestSize.Level */ HWTEST_F(InputManagerTest, InputManagerTest_TouchScreenHotArea_001, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; std::shared_ptr pointerEvent { SetupTouchScreenEvent001() }; ASSERT_TRUE(pointerEvent != nullptr); InputManager::GetInstance()->SimulateInputEvent(pointerEvent); @@ -3372,7 +3724,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_TouchScreenHotArea_001, TestSize.Lev */ HWTEST_F(InputManagerTest, InputManagerTest_TouchScreenHotArea_002, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; std::shared_ptr pointerEvent { SetupTouchScreenEvent002() }; ASSERT_TRUE(pointerEvent != nullptr); InputManager::GetInstance()->SimulateInputEvent(pointerEvent); @@ -3381,13 +3733,13 @@ HWTEST_F(InputManagerTest, InputManagerTest_TouchScreenHotArea_002, TestSize.Lev /** * @tc.name: InputManagerTest_MouseHotArea_001 - * @tc.desc: mouse event Search window by pointerHotAreas + * @tc.desc: Mouse event Search window by pointerHotAreas * @tc.type: FUNC * @tc.require: I5HMCB */ HWTEST_F(InputManagerTest, InputManagerTest_MouseHotArea_001, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; std::shared_ptr pointerEvent { SetupmouseEvent001() }; ASSERT_TRUE(pointerEvent != nullptr); InputManager::GetInstance()->SimulateInputEvent(pointerEvent); @@ -3396,35 +3748,378 @@ HWTEST_F(InputManagerTest, InputManagerTest_MouseHotArea_001, TestSize.Level1) /** * @tc.name: InputManagerTest_MouseHotArea_002 - * @tc.desc: mouse event Search window by pointerHotAreas + * @tc.desc: Mouse event Search window by pointerHotAreas * @tc.type: FUNC * @tc.require: I5HMCB */ HWTEST_F(InputManagerTest, InputManagerTest_MouseHotArea_002, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; std::shared_ptr pointerEvent { SetupmouseEvent002() }; ASSERT_TRUE(pointerEvent != nullptr); ASSERT_EQ(pointerEvent->GetSourceType(), PointerEvent::SOURCE_TYPE_MOUSE); } +/** + * @tc.name: InputManagerTest_UpdateDisplayInfo + * @tc.desc: Update window information + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerTest, InputManagerTest_UpdateDisplayInfo, TestSize.Level1) +{ + CALL_TEST_DEBUG; + DisplayGroupInfo displayGroupInfo; + displayGroupInfo.focusWindowId = 0; + displayGroupInfo.width = 0; + displayGroupInfo.height = 0; + InputManager::GetInstance()->UpdateDisplayInfo(displayGroupInfo); + ASSERT_TRUE(displayGroupInfo.displaysInfo.empty()); +} + +/** + * @tc.name: InputManagerTest_SetInputDevice + * @tc.desc: Set input device + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerTest, InputManagerTest_SetInputDevice, TestSize.Level1) +{ + CALL_TEST_DEBUG; + std::string dhid(""); + std::string screenId(""); + int32_t ret = InputManager::GetInstance()->SetInputDevice(dhid, screenId); +#ifdef OHOS_BUILD_ENABLE_COOPERATE + ASSERT_EQ(ret, RET_ERR); +#else + ASSERT_EQ(ret, ERROR_UNSUPPORT); +#endif // OHOS_BUILD_ENABLE_COOPERATE +} + +/** + * @tc.name: InputManagerTest_RegisterCooperateListener_001 + * @tc.desc: Register cooperate listener + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerTest, InputManagerTest_RegisterCooperateListener_001, TestSize.Level1) +{ + CALL_TEST_DEBUG; + std::shared_ptr consumer = nullptr; + int32_t ret = InputMgrImpl.RegisterCooperateListener(consumer); +#ifdef OHOS_BUILD_ENABLE_COOPERATE + ASSERT_EQ(ret, RET_ERR); +#else + ASSERT_EQ(ret, ERROR_UNSUPPORT); +#endif // OHOS_BUILD_ENABLE_COOPERATE +} + +/** + * @tc.name: InputManagerTest_RegisterCooperateListener_002 + * @tc.desc: Register cooperate listener + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerTest, InputManagerTest_RegisterCooperateListener_002, TestSize.Level1) +{ + CALL_TEST_DEBUG; + class InputDeviceCooperateListenerTest : public IInputDeviceCooperateListener { + public: + InputDeviceCooperateListenerTest() : IInputDeviceCooperateListener() {} + void OnCooperateMessage(const std::string &deviceId, CooperationMessage msg) override + { + MMI_HILOGD("RegisterCooperateListenerTest"); + }; + }; + std::shared_ptr consumer = std::make_shared(); + int32_t ret = InputMgrImpl.RegisterCooperateListener(consumer); +#ifdef OHOS_BUILD_ENABLE_COOPERATE + ASSERT_EQ(ret, RET_OK); +#else + ASSERT_EQ(ret, ERROR_UNSUPPORT); +#endif // OHOS_BUILD_ENABLE_COOPERATE + ret = InputMgrImpl.UnregisterCooperateListener(consumer); +#ifdef OHOS_BUILD_ENABLE_COOPERATE + ASSERT_EQ(ret, RET_OK); +#else + ASSERT_EQ(ret, ERROR_UNSUPPORT); +#endif // OHOS_BUILD_ENABLE_COOPERATE +} + +/** + * @tc.name: InputManagerTest_UnregisterCooperateListener + * @tc.desc: Unregister cooperate listener + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerTest, InputManagerTest_UnregisterCooperateListener, TestSize.Level1) +{ + CALL_TEST_DEBUG; + std::shared_ptr consumer = nullptr; + int32_t ret = InputMgrImpl.UnregisterCooperateListener(consumer); +#ifdef OHOS_BUILD_ENABLE_COOPERATE + ASSERT_EQ(ret, RET_OK); +#else + ASSERT_EQ(ret, ERROR_UNSUPPORT); +#endif // OHOS_BUILD_ENABLE_COOPERATE +} + +/** + * @tc.name: InputManagerTest_EnableInputDeviceCooperate + * @tc.desc: Enable input device cooperate + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerTest, InputManagerTest_EnableInputDeviceCooperate, TestSize.Level1) +{ + CALL_TEST_DEBUG; + bool enabled = false; + auto fun = [](std::string listener, CooperationMessage cooperateMessages) { + MMI_HILOGD("Enable input device cooperate success"); + }; + int32_t ret = InputMgrImpl.EnableInputDeviceCooperate(enabled, fun); +#ifdef OHOS_BUILD_ENABLE_COOPERATE + ASSERT_EQ(ret, RET_OK); +#else + ASSERT_EQ(ret, ERROR_UNSUPPORT); +#endif // OHOS_BUILD_ENABLE_COOPERATE +} + +/** + * @tc.name: InputManagerTest_StartInputDeviceCooperate + * @tc.desc: Start input device cooperate + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerTest, InputManagerTest_StartInputDeviceCooperate, TestSize.Level1) +{ + CALL_TEST_DEBUG; + std::string sinkDeviceId(""); + int32_t srcInputDeviceId = -1; + auto fun = [](std::string listener, CooperationMessage cooperateMessages) { + MMI_HILOGD("Start input device cooperate success"); + }; + int32_t ret = InputMgrImpl.StartInputDeviceCooperate(sinkDeviceId, srcInputDeviceId, fun); +#ifdef OHOS_BUILD_ENABLE_COOPERATE + ASSERT_NE(ret, RET_OK); +#else + ASSERT_EQ(ret, ERROR_UNSUPPORT); +#endif // OHOS_BUILD_ENABLE_COOPERATE +} + +/** + * @tc.name: InputManagerTest_StopDeviceCooperate + * @tc.desc: Stop device cooperate + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerTest, InputManagerTest_StopDeviceCooperate, TestSize.Level1) +{ + CALL_TEST_DEBUG; + auto fun = [](std::string listener, CooperationMessage cooperateMessages) { + MMI_HILOGD("Start input device cooperate success"); + }; + int32_t ret = InputMgrImpl.StopDeviceCooperate(fun); +#ifdef OHOS_BUILD_ENABLE_COOPERATE + ASSERT_NE(ret, ERROR_UNSUPPORT); +#else + ASSERT_EQ(ret, ERROR_UNSUPPORT); +#endif // OHOS_BUILD_ENABLE_COOPERATE +} + +/** + * @tc.name: InputManagerTest_GetInputDeviceCooperateState + * @tc.desc: Get input device cooperate state + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerTest, InputManagerTest_GetInputDeviceCooperateState, TestSize.Level1) +{ + CALL_TEST_DEBUG; + const std::string deviceId(""); + auto fun = [](bool state) { + MMI_HILOGD("Get inputdevice state success"); + }; + int32_t ret = InputMgrImpl.GetInputDeviceCooperateState(deviceId, fun); +#ifdef OHOS_BUILD_ENABLE_COOPERATE + ASSERT_EQ(ret, RET_OK); +#else + ASSERT_EQ(ret, ERROR_UNSUPPORT); +#endif // OHOS_BUILD_ENABLE_COOPERATE +} + +/** + * @tc.name: InputManagerTest_GetDevice_001 + * @tc.desc: Verify the fetch device info + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerTest, InputManagerTest_GetDevice_001, TestSize.Level1) +{ + CALL_TEST_DEBUG; + int32_t deviceId = 0; + auto callback = [](std::shared_ptr inputDevice) { + MMI_HILOGD("Get device success"); + ASSERT_TRUE(inputDevice != nullptr); + }; + int32_t ret = InputManager::GetInstance()->GetDevice(deviceId, callback); + ASSERT_EQ(ret, RET_OK); +} + +/** + * @tc.name: InputManagerTest_GetDevice_002 + * @tc.desc: Verify the fetch device info + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerTest, InputManagerTest_GetDevice_002, TestSize.Level1) +{ + CALL_TEST_DEBUG; + int32_t deviceId = -1; + auto callback = [](std::shared_ptr inputDevice) { + MMI_HILOGD("Get device success"); + ASSERT_TRUE(inputDevice != nullptr); + }; + int32_t ret = InputManager::GetInstance()->GetDevice(deviceId, callback); + ASSERT_NE(ret, RET_OK); +} + +/** + * @tc.name: InputManagerTest_GetDeviceIds + * @tc.desc: Verify the fetch device list + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerTest, InputManagerTest_GetDeviceIds, TestSize.Level1) +{ + CALL_TEST_DEBUG; + auto callback = [](std::vector ids) { + MMI_HILOGD("Get device success"); + }; + int32_t ret = InputManager::GetInstance()->GetDeviceIds(callback); + ASSERT_EQ(ret, RET_OK); +} + +/** + * @tc.name: InputManagerTest_EventTypeToString + * @tc.desc: Verify inputevent interface + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerTest, InputManagerTest_EventTypeToString, TestSize.Level1) +{ + CALL_TEST_DEBUG; + auto inputEvent = InputEvent::Create(); + ASSERT_NE(inputEvent, nullptr); + auto ret = inputEvent->EventTypeToString(InputEvent::EVENT_TYPE_BASE); + ASSERT_STREQ(ret, "base"); + ret = inputEvent->EventTypeToString(InputEvent::EVENT_TYPE_KEY); + ASSERT_STREQ(ret, "key"); + ret = inputEvent->EventTypeToString(InputEvent::EVENT_TYPE_AXIS); + ASSERT_STREQ(ret, "axis"); + ret = inputEvent->EventTypeToString(-1); + ASSERT_STREQ(ret, "unknown"); +} + +/** + * @tc.name: InputManagerTest_InputDeviceInterface_001 + * @tc.desc: Verify inputdevice interface + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerTest, InputManagerTest_InputDeviceInterface_001, TestSize.Level1) +{ + CALL_TEST_DEBUG; + std::shared_ptr inputDevice = std::make_shared(); + ASSERT_NE(inputDevice, nullptr); + inputDevice->SetId(0); + ASSERT_EQ(inputDevice->GetId(), 0); + inputDevice->SetName("name"); + ASSERT_STREQ(inputDevice->GetName().c_str(), "name"); + inputDevice->SetType(0); + ASSERT_EQ(inputDevice->GetType(), 0); + inputDevice->SetBus(0); + ASSERT_EQ(inputDevice->GetBus(), 0); + inputDevice->SetVersion(0); + ASSERT_EQ(inputDevice->GetVersion(), 0); + inputDevice->SetProduct(0); + ASSERT_EQ(inputDevice->GetProduct(), 0); + inputDevice->SetVendor(0); + ASSERT_EQ(inputDevice->GetVendor(), 0); + inputDevice->SetPhys("phys"); + ASSERT_STREQ(inputDevice->GetPhys().c_str(), "phys"); + inputDevice->SetUniq("uniq"); + ASSERT_STREQ(inputDevice->GetUniq().c_str(), "uniq"); +} + +/** + * @tc.name: InputManagerTest_InputDeviceInterface_002 + * @tc.desc: Verify inputdevice interface + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerTest, InputManagerTest_InputDeviceInterface_002, TestSize.Level1) +{ + CALL_TEST_DEBUG; + std::shared_ptr inputDevice = std::make_shared(); + ASSERT_NE(inputDevice, nullptr); + InputDevice::AxisInfo axis; + axis.SetAxisType(0); + axis.SetMinimum(0); + axis.SetMaximum(1); + axis.SetFuzz(0); + axis.SetFlat(1); + axis.SetResolution(0); + inputDevice->AddAxisInfo(axis); + auto iter = inputDevice->GetAxisInfo(); + ASSERT_EQ(iter[0].GetAxisType(), 0); + ASSERT_EQ(iter[0].GetMinimum(), 0); + ASSERT_EQ(iter[0].GetMaximum(), 1); + ASSERT_EQ(iter[0].GetFuzz(), 0); + ASSERT_EQ(iter[0].GetFlat(), 1); + ASSERT_EQ(iter[0].GetResolution(), 0); +} + +/** + * @tc.name: InputManagerTest_SetAnrObserver + * @tc.desc: Verify the observer for events + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputManagerTest, InputManagerTest_SetAnrObserver, TestSize.Level1) +{ + CALL_TEST_DEBUG; + class IAnrObserverTest : public IAnrObserver { + public: + IAnrObserverTest() : IAnrObserver() {} + virtual ~IAnrObserverTest() {} + void OnAnr(int32_t pid) const override + { + MMI_HILOGD("Set anr success"); + }; + }; + + std::shared_ptr observer = std::make_shared(); + InputManager::GetInstance()->SetAnrObserver(observer); +} + std::shared_ptr InputManagerTest::SetupTabletToolEvent001() { auto pointerEvent = PointerEvent::Create(); CHKPP(pointerEvent); PointerEvent::PointerItem item; - item.SetPointerId(DEFAULT_POINTER_ID); // test code,set the PointerId = 0 - item.SetDisplayX(523); // test code,set the DisplayX = 523 - item.SetDisplayY(723); // test code,set the DisplayY = 723 - item.SetPressure(0.7); // test code,set the Pressure = 0.7 - item.SetTiltX(10.0); // test code,set the TiltX = 10.0 - item.SetTiltY(-9.0); // test code,set the TiltX = -9.0 - item.SetDeviceId(DEFAULT_DEVICE_ID); // test code,set the DeviceId = 0 + item.SetPointerId(DEFAULT_POINTER_ID); + item.SetDisplayX(523); + item.SetDisplayY(723); + item.SetPressure(0.7); + item.SetTiltX(10.0); + item.SetTiltY(-9.0); + item.SetDeviceId(DEFAULT_DEVICE_ID); item.SetToolType(PointerEvent::TOOL_TYPE_PEN); pointerEvent->AddPointerItem(item); pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); - pointerEvent->SetPointerId(DEFAULT_POINTER_ID); // test code,set the PointerId = 0 + pointerEvent->SetPointerId(DEFAULT_POINTER_ID); pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); return pointerEvent; } @@ -3438,7 +4133,7 @@ std::shared_ptr InputManagerTest::SetupTabletToolEvent001() */ HWTEST_F(InputManagerTest, InputManagerTest_MonitorTabletToolEvent_001, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto callbackPtr = GetPtr(); ASSERT_TRUE(callbackPtr != nullptr); int32_t monitorId = TestAddMonitor(callbackPtr); @@ -3470,7 +4165,7 @@ HWTEST_F(InputManagerTest, InputManagerTest_MonitorTabletToolEvent_001, TestSize */ HWTEST_F(InputManagerTest, InputManagerTest_InterceptTabletToolEvent_001, TestSize.Level1) { - CALL_DEBUG_ENTER; + CALL_TEST_DEBUG; auto interceptor = GetPtr(); int32_t interceptorId { InputManager::GetInstance()->AddInterceptor(interceptor) }; EXPECT_TRUE(IsValidHandlerId(interceptorId)); @@ -3491,5 +4186,62 @@ HWTEST_F(InputManagerTest, InputManagerTest_InterceptTabletToolEvent_001, TestSi } } #endif // OHOS_BUILD_ENABLE_INTERCEPTOR + +#ifdef OHOS_BUILD_ENABLE_TOUCH +HWTEST_F(InputManagerTest, AppendExtraData_001, TestSize.Level1) +{ + CALL_TEST_DEBUG; + auto consumer = GetPtr(); + ASSERT_TRUE(consumer != nullptr); + const std::string threadTest = "EventUtilTest"; + auto runner = AppExecFwk::EventRunner::Create(threadTest); + ASSERT_TRUE(runner != nullptr); + auto eventHandler = std::make_shared(runner); + MMI::InputManager::GetInstance()->SetWindowInputEventConsumer(consumer, eventHandler); + std::vector buffer(512, 1); + ExtraData extraData; + extraData.appended = true; + extraData.buffer = buffer; + extraData.sourceType = PointerEvent::SOURCE_TYPE_TOUCHSCREEN; + extraData.pointerId = 1; + InputManager::GetInstance()->AppendExtraData(extraData); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); + auto pointerEvent = SetupPointerEvent001(); + ASSERT_TRUE(pointerEvent != nullptr); + TestSimulateInputEvent(pointerEvent, TestScene::EXCEPTION_TEST); + + extraData.appended = false; + extraData.buffer.clear(); + extraData.pointerId = -1; + InputManager::GetInstance()->AppendExtraData(extraData); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); + ASSERT_TRUE(pointerEvent != nullptr); + TestSimulateInputEvent(pointerEvent); +} +#endif // OHOS_BUILD_ENABLE_TOUCH + +#ifdef OHOS_BUILD_ENABLE_POINTER +HWTEST_F(InputManagerTest, AppendExtraData_002, TestSize.Level1) +{ + CALL_TEST_DEBUG; + std::vector buffer(512, 1); + ExtraData extraData; + extraData.appended = true; + extraData.buffer = buffer; + extraData.sourceType = PointerEvent::SOURCE_TYPE_MOUSE; + InputManager::GetInstance()->AppendExtraData(extraData); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); + auto pointerEvent = SetupPointerEvent006(); + ASSERT_TRUE(pointerEvent != nullptr); + TestSimulateInputEvent(pointerEvent, TestScene::EXCEPTION_TEST); + + extraData.appended = false; + extraData.buffer.clear(); + InputManager::GetInstance()->AppendExtraData(extraData); + std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); + ASSERT_TRUE(pointerEvent != nullptr); + TestSimulateInputEvent(pointerEvent); +} +#endif // OHOS_BUILD_ENABLE_POINTER } // namespace MMI } // namespace OHOS diff --git a/frameworks/proxy/events/test/key_event_test.cpp b/frameworks/proxy/events/test/key_event_test.cpp index bee91caa209614355593cb6bacb2e5d20259ccec..ecc8be8341c42ab5c244ae13c1bc1cdb0a43d947 100755 --- a/frameworks/proxy/events/test/key_event_test.cpp +++ b/frameworks/proxy/events/test/key_event_test.cpp @@ -20,13 +20,11 @@ #include "input_manager.h" #include "key_event.h" #include "proto.h" -#include "run_shell_util.h" namespace OHOS { namespace MMI { namespace { using namespace testing::ext; -using namespace OHOS::MMI; } // namespace class KeyEventTest : public testing::Test { @@ -36,8 +34,8 @@ public: }; /** - * @tc.name:KeyEventTest_OnCheckKeyEvent_001 - * @tc.desc:Verify key event + * @tc.name: KeyEventTest_OnCheckKeyEvent_001 + * @tc.desc: Verify key event * @tc.type: FUNC * @tc.require: */ @@ -59,8 +57,8 @@ HWTEST_F(KeyEventTest, KeyEventTest_OnCheckKeyEvent_001, TestSize.Level1) } /** - * @tc.name:KeyEventTest_OnCheckKeyEvent_002 - * @tc.desc:Verify key event + * @tc.name: KeyEventTest_OnCheckKeyEvent_002 + * @tc.desc: Verify key event * @tc.type: FUNC * @tc.require: */ @@ -88,8 +86,8 @@ HWTEST_F(KeyEventTest, KeyEventTest_OnCheckKeyEvent_002, TestSize.Level1) } /** - * @tc.name:KeyEventTest_OnCheckKeyEvent_003 - * @tc.desc:Verify key event + * @tc.name: KeyEventTest_OnCheckKeyEvent_003 + * @tc.desc: Verify key event * @tc.type: FUNC * @tc.require: */ @@ -120,8 +118,8 @@ HWTEST_F(KeyEventTest, KeyEventTest_OnCheckKeyEvent_003, TestSize.Level1) } /** - * @tc.name:KeyEventTest_OnCheckKeyEvent_004 - * @tc.desc:Verify key event + * @tc.name: KeyEventTest_OnCheckKeyEvent_004 + * @tc.desc: Verify key event * @tc.type: FUNC * @tc.require: */ @@ -153,8 +151,8 @@ HWTEST_F(KeyEventTest, KeyEventTest_OnCheckKeyEvent_004, TestSize.Level1) } /** - * @tc.name:KeyEventTest_OnCheckKeyEvent_005 - * @tc.desc:Verify key event + * @tc.name: KeyEventTest_OnCheckKeyEvent_005 + * @tc.desc: Verify key event * @tc.type: FUNC * @tc.require: */ @@ -190,8 +188,8 @@ HWTEST_F(KeyEventTest, KeyEventTest_OnCheckKeyEvent_005, TestSize.Level1) } /** - * @tc.name:KeyEventTest_OnCheckKeyEvent_006 - * @tc.desc:Verify key event + * @tc.name: KeyEventTest_OnCheckKeyEvent_006 + * @tc.desc: Verify key event * @tc.type: FUNC * @tc.require: I5QSN3 */ @@ -216,6 +214,7 @@ HWTEST_F(KeyEventTest, KeyEventTest_OnCheckKeyEvent_006, TestSize.Level1) item.SetKeyCode(KeyEvent::KEYCODE_BACK); item.SetDownTime(100); item.SetPressed(true); + item.SetUnicode(0); keyEvent->AddKeyItem(item); ASSERT_TRUE(keyEvent->IsValid()); std::vector items = keyEvent->GetKeyItems(); @@ -365,7 +364,98 @@ HWTEST_F(KeyEventTest, KeyEventTest_TransitionFunctionKey_004, TestSize.Level1) std::shared_ptr keyEvent = KeyEvent::Create(); ASSERT_NE(keyEvent, nullptr); int32_t lockCode = keyEvent->TransitionFunctionKey(KeyEvent::KEYCODE_A); - ASSERT_EQ(lockCode, KeyEvent::UNKOWN_FUNCTION_KEY); + ASSERT_EQ(lockCode, KeyEvent::UNKNOWN_FUNCTION_KEY); +} + +/** + * @tc.name: KeyEventTest_ReadFromParcel_001 + * @tc.desc: Read from parcel + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(KeyEventTest, KeyEventTest_ReadFromParcel_001, TestSize.Level1) +{ + std::shared_ptr keyEvent = KeyEvent::Create(); + ASSERT_NE(keyEvent, nullptr); + keyEvent->SetKeyCode(KeyEvent::KEYCODE_HOME); + keyEvent->SetActionTime(100); + keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN); + keyEvent->ActionToString(KeyEvent::KEY_ACTION_DOWN); + keyEvent->KeyCodeToString(KeyEvent::KEYCODE_HOME); + KeyEvent::KeyItem item; + item.SetKeyCode(KeyEvent::KEYCODE_HOME); + item.SetDownTime(100); + item.SetPressed(true); + keyEvent->AddKeyItem(item); + MessageParcel data; + bool ret = keyEvent->WriteToParcel(data); + ASSERT_TRUE(ret); + ret = keyEvent->ReadFromParcel(data); + ASSERT_TRUE(ret); +} + +/** + * @tc.name: KeyEventTest_ReadFromParcel_002 + * @tc.desc: Read from parcel + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(KeyEventTest, KeyEventTest_ReadFromParcel_002, TestSize.Level1) +{ + std::shared_ptr keyEvent = KeyEvent::Create(); + ASSERT_NE(keyEvent, nullptr); + keyEvent->SetKeyCode(KeyEvent::KEYCODE_HOME); + keyEvent->SetActionTime(100); + keyEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN); + keyEvent->ActionToString(KeyEvent::KEY_ACTION_DOWN); + keyEvent->KeyCodeToString(KeyEvent::KEYCODE_HOME); + KeyEvent::KeyItem item; + item.SetKeyCode(KeyEvent::KEYCODE_HOME); + item.SetDownTime(100); + item.SetPressed(true); + keyEvent->AddKeyItem(item); + MessageParcel data; + bool ret = keyEvent->WriteToParcel(data); + ASSERT_TRUE(ret); + std::shared_ptr inputEvent = InputEvent::Create(); + ret = inputEvent->ReadFromParcel(data); + ASSERT_TRUE(ret); + int32_t keyCode; + ret = data.ReadInt32(keyCode); + ASSERT_TRUE(ret); + const int32_t keysSize = data.ReadInt32(); + ASSERT_FALSE(keysSize < 0); + for (int32_t i = 0; i < keysSize; ++i) { + KeyEvent::KeyItem keyItem = {}; + ret = keyItem.ReadFromParcel(data); + ASSERT_TRUE(ret); + } +} + +/** + * @tc.name: KeyEventTest_ReadFromParcel_003 + * @tc.desc: Verify keyoption read from parcel + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(KeyEventTest, KeyEventTest_ReadFromParcel_003, TestSize.Level1) +{ + std::set preKeys; + std::shared_ptr keyOption = std::make_shared(); + keyOption->SetPreKeys(preKeys); + MessageParcel data; + bool ret = keyOption->ReadFromParcel(data); + ASSERT_FALSE(ret); + preKeys.insert(0); + preKeys.insert(1); + keyOption->SetPreKeys(preKeys); + keyOption->SetFinalKey(0); + keyOption->SetFinalKeyDown(0); + keyOption->SetFinalKeyDownDuration(0); + keyOption->SetFinalKeyUpDelay(0); + keyOption->WriteToParcel(data); + ret = keyOption->ReadFromParcel(data); + ASSERT_TRUE(ret); } } // namespace MMI } // namespace OHOS diff --git a/frameworks/proxy/events/test/pointer_event_test.cpp b/frameworks/proxy/events/test/pointer_event_test.cpp index c7b0110e12b9e851b9ff4bfada196b36a6b25e54..666661dc1bf0937213f25dced596c6f682cc1abf 100755 --- a/frameworks/proxy/events/test/pointer_event_test.cpp +++ b/frameworks/proxy/events/test/pointer_event_test.cpp @@ -22,7 +22,7 @@ namespace OHOS { namespace MMI { namespace { #ifdef OHOS_BUILD_ENABLE_POINTER -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "PointerEventTest"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "PointerEventTest" }; #endif // OHOS_BUILD_ENABLE_POINTER using namespace testing::ext; } // namespace @@ -68,8 +68,8 @@ std::shared_ptr PointerEventTest::CreatePointEvent() } /** - * @tc.name:PointerEventTest_keyEventAndPointerEvent_001 - * @tc.desc:Verify ctrl(left) + point event + * @tc.name: PointerEventTest_keyEventAndPointerEvent_001 + * @tc.desc: Verify ctrl(left) + point event * @tc.type: FUNC * @tc.require: AR000GOACS * @tc.author: yangguang @@ -84,8 +84,8 @@ HWTEST_F(PointerEventTest, PointerEventTest_keyEventAndPointerEvent_001, TestSiz } /** - * @tc.name:PointerEventTest_keyEventAndPointerEvent_002 - * @tc.desc:Verify ctrl(right) + point event + * @tc.name: PointerEventTest_keyEventAndPointerEvent_002 + * @tc.desc: Verify ctrl(right) + point event * @tc.type: FUNC * @tc.require: AR000GOACS * @tc.author: yangguang @@ -100,8 +100,8 @@ HWTEST_F(PointerEventTest, PointerEventTest_keyEventAndPointerEvent_002, TestSiz } /** - * @tc.name:PointerEventTest_keyEventAndPointerEvent_003 - * @tc.desc:Verify ctrl(left and right) + point event + * @tc.name: PointerEventTest_keyEventAndPointerEvent_003 + * @tc.desc: Verify ctrl(left and right) + point event * @tc.type: FUNC * @tc.require: AR000GOACS * @tc.author: yangguang @@ -117,8 +117,8 @@ HWTEST_F(PointerEventTest, PointerEventTest_keyEventAndPointerEvent_003, TestSiz #endif // OHOS_BUILD_ENABLE_POINTER /** - * @tc.name:PointerEventTest_CheckMousePointEvent_001 - * @tc.desc:Verify mouse point event + * @tc.name: PointerEventTest_CheckMousePointEvent_001 + * @tc.desc: Verify mouse point event * @tc.type: FUNC * @tc.require: */ @@ -169,8 +169,8 @@ HWTEST_F(PointerEventTest, PointerEventTest_CheckMousePointEvent_001, TestSize.L } /** - * @tc.name:PointerEventTest_CheckMousePointEvent_002 - * @tc.desc:Verify mouse point event + * @tc.name: PointerEventTest_CheckMousePointEvent_002 + * @tc.desc: Verify mouse point event * @tc.type: FUNC * @tc.require: */ @@ -209,8 +209,8 @@ HWTEST_F(PointerEventTest, PointerEventTest_CheckMousePointEvent_002, TestSize.L } /** - * @tc.name:PointerEventTest_CheckMousePointEvent_003 - * @tc.desc:Verify mouse point event + * @tc.name: PointerEventTest_CheckMousePointEvent_003 + * @tc.desc: Verify mouse point event * @tc.type: FUNC * @tc.require: */ @@ -241,8 +241,8 @@ HWTEST_F(PointerEventTest, PointerEventTest_CheckMousePointEvent_003, TestSize.L } /** - * @tc.name:PointerEventTest_CheckMousePointEvent_004 - * @tc.desc:Verify mouse point event + * @tc.name: PointerEventTest_CheckMousePointEvent_004 + * @tc.desc: Verify mouse point event * @tc.type: FUNC * @tc.require: */ @@ -287,8 +287,8 @@ HWTEST_F(PointerEventTest, PointerEventTest_CheckMousePointEvent_004, TestSize.L } /** - * @tc.name:PointerEventTest_CheckMousePointEvent_005 - * @tc.desc:Verify mouse point event + * @tc.name: PointerEventTest_CheckMousePointEvent_005 + * @tc.desc: Verify mouse point event * @tc.type: FUNC * @tc.require: */ @@ -310,8 +310,59 @@ HWTEST_F(PointerEventTest, PointerEventTest_CheckMousePointEvent_005, TestSize.L } /** - * @tc.name:PointerEventTest_CheckTouchPointEvent_001 - * @tc.desc:Verify touch screen event + * @tc.name: PointerEventTest_CheckMousePointEvent_006 + * @tc.desc: Verify mouse point event + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PointerEventTest, PointerEventTest_CheckMousePointEvent_006, TestSize.Level1) +{ + auto inputEvent = InputEvent::Create(); + ASSERT_NE(inputEvent, nullptr); + inputEvent->SetDeviceId(1); + inputEvent->SetTargetWindowId(1); + inputEvent->SetAgentWindowId(1); + auto event = PointerEvent::from(inputEvent); + ASSERT_EQ(event, nullptr); + + auto pointerEvent = PointerEvent::Create(); + ASSERT_NE(pointerEvent, nullptr); + pointerEvent->Reset(); + pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); + pointerEvent->SetPointerId(0); + pointerEvent->SetDeviceId(inputEvent->GetDeviceId()); + pointerEvent->SetTargetWindowId(inputEvent->GetTargetWindowId()); + pointerEvent->SetAgentWindowId(inputEvent->GetAgentWindowId()); + PointerEvent::PointerItem item1; + item1.SetPointerId(0); + item1.SetDownTime(0); + item1.SetPressed(true); + item1.SetWindowX(10); + item1.SetWindowY(10); + item1.SetDeviceId(inputEvent->GetDeviceId()); + item1.SetRawDx(60); + item1.SetRawDy(60); + pointerEvent->AddPointerItem(item1); + PointerEvent::PointerItem item2; + item2.SetPointerId(1); + item2.SetDownTime(0); + item2.SetPressed(false); + item2.SetWindowX(item1.GetWindowX()); + item2.SetWindowY(item1.GetWindowY()); + item2.SetDeviceId(inputEvent->GetDeviceId()); + item2.SetRawDx(100); + item2.SetRawDy(100); + pointerEvent->AddPointerItem(item2); + ASSERT_TRUE(pointerEvent != nullptr); +#ifdef OHOS_BUILD_ENABLE_POINTER + TestSimulateInputEvent(pointerEvent); +#endif // OHOS_BUILD_ENABLE_POINTER +} + +/** + * @tc.name: PointerEventTest_CheckTouchPointEvent_001 + * @tc.desc: Verify touch screen event * @tc.type: FUNC * @tc.require: */ @@ -345,8 +396,8 @@ HWTEST_F(PointerEventTest, PointerEventTest_CheckTouchPointEvent_001, TestSize.L } /** - * @tc.name:PointerEventTest_CheckTouchPointEvent_002 - * @tc.desc:Verify touch screen event + * @tc.name: PointerEventTest_CheckTouchPointEvent_002 + * @tc.desc: Verify touch screen event * @tc.type: FUNC * @tc.require: */ @@ -377,8 +428,8 @@ HWTEST_F(PointerEventTest, PointerEventTest_CheckTouchPointEvent_002, TestSize.L } /** - * @tc.name:PointerEventTest_CheckTouchPointEvent_003 - * @tc.desc:Verify touch screen event + * @tc.name: PointerEventTest_CheckTouchPointEvent_003 + * @tc.desc: Verify touch screen event * @tc.type: FUNC * @tc.require: */ @@ -417,8 +468,8 @@ HWTEST_F(PointerEventTest, PointerEventTest_CheckTouchPointEvent_003, TestSize.L } /** - * @tc.name:PointerEventTest_CheckTouchPointEvent_004 - * @tc.desc:Verify touch screen event + * @tc.name: PointerEventTest_CheckTouchPointEvent_004 + * @tc.desc: Verify touch screen event * @tc.type: FUNC * @tc.require: */ @@ -444,8 +495,8 @@ HWTEST_F(PointerEventTest, PointerEventTest_CheckTouchPointEvent_004, TestSize.L } /** - * @tc.name:PointerEventTest_CheckTouchPointEvent_005 - * @tc.desc:Verify touch screen event + * @tc.name: PointerEventTest_CheckTouchPointEvent_005 + * @tc.desc: Verify touch screen event * @tc.type: FUNC * @tc.require: */ @@ -471,8 +522,8 @@ HWTEST_F(PointerEventTest, PointerEventTest_CheckTouchPointEvent_005, TestSize.L } /** - * @tc.name:PointerEventTest_CheckTouchPointEvent_006 - * @tc.desc:Verify touch screen event + * @tc.name: PointerEventTest_CheckTouchPointEvent_006 + * @tc.desc: Verify touch screen event * @tc.type: FUNC * @tc.require: I5QSN3 */ @@ -509,8 +560,8 @@ HWTEST_F(PointerEventTest, PointerEventTest_CheckTouchPointEvent_006, TestSize.L } /** - * @tc.name:PointerEventTest_CheckTouchInputEvent_001 - * @tc.desc:Verify touch screen event + * @tc.name: PointerEventTest_CheckTouchInputEvent_001 + * @tc.desc: Verify touch screen event * @tc.type: FUNC * @tc.require: I5QSN3 */ diff --git a/frameworks/proxy/module_loader/include/mmi_client.h b/frameworks/proxy/module_loader/include/mmi_client.h old mode 100755 new mode 100644 index 6f5d1ad2eef76415c727c54767efc98e8254555b..a2ba101d2423c4bf00a6f2bb4862376120ba9c24 --- a/frameworks/proxy/module_loader/include/mmi_client.h +++ b/frameworks/proxy/module_loader/include/mmi_client.h @@ -12,8 +12,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef MMI_CLIENT_H #define MMI_CLIENT_H + #include "nocopyable.h" #include "if_mmi_client.h" diff --git a/frameworks/proxy/module_loader/include/mmi_fd_listener.h b/frameworks/proxy/module_loader/include/mmi_fd_listener.h index 67a475b4309a6beb9bc30370af8ca0b61a62376f..d3fbbec64f5e8cee7f7eba9c8d904b28a54c6c4e 100644 --- a/frameworks/proxy/module_loader/include/mmi_fd_listener.h +++ b/frameworks/proxy/module_loader/include/mmi_fd_listener.h @@ -12,23 +12,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef MMI_FD_LISTENER_H #define MMI_FD_LISTENER_H + #include "file_descriptor_listener.h" #include "if_mmi_client.h" namespace OHOS { namespace MMI { -class MMIFdListener : public AppExecFwk::FileDescriptorListener { +class MMIFdListener final : public AppExecFwk::FileDescriptorListener { public: explicit MMIFdListener(MMIClientPtr client); DISALLOW_COPY_AND_MOVE(MMIFdListener); - virtual ~MMIFdListener(); + ~MMIFdListener() override = default; - virtual void OnReadable(int32_t fd) override; - virtual void OnShutdown(int32_t fd) override; - virtual void OnException(int32_t fd) override; + void OnReadable(int32_t fd) override; + void OnShutdown(int32_t fd) override; + void OnException(int32_t fd) override; private: MMIClientPtr mmiClient_ { nullptr }; diff --git a/frameworks/proxy/module_loader/src/mmi_client.cpp b/frameworks/proxy/module_loader/src/mmi_client.cpp index c12757511de2befec861aca03434255292cc434c..c8c66c4ad6fa78aaa7a82b8e4e4b8b9e861d1bd0 100755 --- a/frameworks/proxy/module_loader/src/mmi_client.cpp +++ b/frameworks/proxy/module_loader/src/mmi_client.cpp @@ -17,6 +17,7 @@ #include #include +#include "anr_handler.h" #include "mmi_log.h" #include "proto.h" #include "util.h" @@ -105,7 +106,6 @@ bool MMIClient::StartEventRunner() if (eventHandler_ == nullptr) { auto runner = AppExecFwk::EventRunner::Create(THREAD_NAME); eventHandler_ = std::make_shared(runner); - CHKPF(eventHandler_); MMI_HILOGI("Create event handler, thread name:%{public}s", runner->GetRunnerThreadName().c_str()); } @@ -136,7 +136,6 @@ bool MMIClient::AddFdListener(int32_t fd) } CHKPF(eventHandler_); auto fdListener = std::make_shared(GetSharedPtr()); - CHKPF(fdListener); auto errCode = eventHandler_->AddFileDescriptorListener(fd, FILE_DESCRIPTOR_INPUT_EVENT, fdListener); if (errCode != ERR_OK) { MMI_HILOGE("Add fd listener failed,fd:%{public}d code:%{public}u str:%{public}s", fd, errCode, @@ -155,6 +154,7 @@ bool MMIClient::DelFdListener(int32_t fd) CHKPF(eventHandler_); if (fd >= 0) { eventHandler_->RemoveFileDescriptorListener(fd); + MMI_HILOGI("Remove file descriptor listener success"); } else { MMI_HILOGE("Invalid fd:%{public}d", fd); } @@ -162,6 +162,7 @@ bool MMIClient::DelFdListener(int32_t fd) CHKPF(runner); if (runner->GetRunnerThreadName() == THREAD_NAME) { eventHandler_->RemoveAllEvents(); + MMI_HILOGI("Remove all events success"); } isRunning_ = false; return true; @@ -223,6 +224,7 @@ void MMIClient::OnDisconnected() MMI_HILOGI("Disconnected from server, fd:%{public}d", fd_); isConnected_ = false; isListening_ = false; + ANRHdl->ResetAnrArray(); if (funDisconnected_) { funDisconnected_(*this); } @@ -261,7 +263,7 @@ int32_t MMIClient::Socket() int32_t ret = MultimodalInputConnMgr->AllocSocketPair(IMultimodalInputConnect::CONNECT_MODULE_TYPE_MMI_CLIENT); if (ret != RET_OK) { MMI_HILOGE("Call AllocSocketPair return %{public}d", ret); - return RET_ERR; + return IMultimodalInputConnect::INVALID_SOCKET_FD; } fd_ = MultimodalInputConnMgr->GetClientSocketFdOfAllocedSocketPair(); if (fd_ == IMultimodalInputConnect::INVALID_SOCKET_FD) { @@ -283,6 +285,7 @@ void MMIClient::Stop() runner->Stop(); eventHandler_->RemoveAllEvents(); eventHandler_->RemoveAllFileDescriptorListeners(); + MMI_HILOGI("Remove all file descriptor listeners success"); } } } diff --git a/frameworks/proxy/module_loader/src/mmi_fd_listener.cpp b/frameworks/proxy/module_loader/src/mmi_fd_listener.cpp index 3575f229baf8b07eb994fd0718ede77adf5a598d..0229b7026db0a089cf878db54aa7d85574d36923 100644 --- a/frameworks/proxy/module_loader/src/mmi_fd_listener.cpp +++ b/frameworks/proxy/module_loader/src/mmi_fd_listener.cpp @@ -32,10 +32,6 @@ MMIFdListener::MMIFdListener(MMIClientPtr client) : mmiClient_(client) { CALL_DEBUG_ENTER; } -MMIFdListener::~MMIFdListener() -{ - CALL_DEBUG_ENTER; -} void MMIFdListener::OnReadable(int32_t fd) { diff --git a/frameworks/proxy/module_loader/test/mmi_client_test.cpp b/frameworks/proxy/module_loader/test/mmi_client_test.cpp index d357673843897aa159138165145062a569a19fb0..4df3dc89f0b20d6c6df75abed12938e274b856b7 100644 --- a/frameworks/proxy/module_loader/test/mmi_client_test.cpp +++ b/frameworks/proxy/module_loader/test/mmi_client_test.cpp @@ -17,24 +17,10 @@ #include "mmi_client.h" -#ifdef OHOS_BUILD_MMI_DEBUG -#include -#include -#include -#include "display_info.h" -#include "multimodal_event_handler.h" -#include "util.h" -#endif // OHOS_BUILD_MMI_DEBUG - namespace OHOS { namespace MMI { namespace { using namespace testing::ext; -using namespace OHOS::MMI; -#ifdef OHOS_BUILD_MMI_DEBUG -constexpr int32_t DISPLAY_WIDTH = 720; -constexpr int32_t DISPLAY_HEIGHT = 1280; -#endif // OHOS_BUILD_MMI_DEBUG } // namespace class MMIClientTest : public testing::Test { @@ -43,100 +29,11 @@ public: static void TearDownTestCase(void) {} }; -class MMIClientUnitTest { -public: -#ifdef OHOS_BUILD_MMI_DEBUG -public: - static bool Write(const WindowInfo& info, NetPacket& pkt) - { - pkt << info.id << info.pid << info.uid << info.area << info.defaultHotAreas << info.pointerHotAreas - << info.agentWindowId << info.flags; - return (!pkt.ChkRWError()); - } - static bool Write(const DisplayInfo& info, NetPacket& pkt) - { - pkt << info.id << info.x << info.y << info.width << info.height << info.name << info.uniq - << info.direction; - return (!pkt.ChkRWError()); - } - static int32_t GetRandomInt(int32_t min, int32_t max) - { - std::mt19937 gen(std::random_device{}()); - std::uniform_int_distribution<> dis(min, max); - return dis(gen); - } - static void RandomHotAreasInfo(std::vector& hotAreas) - { - Rect area; - area.x = 0; - area.y = 0; - area.width = DISPLAY_WIDTH; - area.height = DISPLAY_HEIGHT; - hotAreas.push_back(area); - } - static void RandomWindowInfo(int32_t id, int32_t pid, WindowInfo& info) - { - info.id = id; - info.pid = pid; - info.uid = pid; - Rect area; - area.x = 0; - area.y = 0; - area.width = DISPLAY_WIDTH; - area.height = DISPLAY_HEIGHT; - info.area = area; - RandomHotAreasInfo(info.defaultHotAreas); - RandomHotAreasInfo(info.pointerHotAreas); - info.agentWindowId = id; - info.flags = 0; - } - static void RandomDisplayInfo(int32_t id, DisplayInfo& info) - { - info.id = id; - info.x = 0; - info.y = 0; - info.width = DISPLAY_WIDTH; - info.height = DISPLAY_HEIGHT; - info.name = StringFmt("pd-%d", id); - info.uniq = "default0"; - info.direction = Direction::Direction0; - } - static bool RandomDisplayPacket(NetPacket& pkt, int32_t pid) - { - int32_t width = DISPLAY_WIDTH; - int32_t height = DISPLAY_HEIGHT; - int32_t focusWindowId = 1; - pkt << width << height << focusWindowId; - uint32_t windowNum = 1; - pkt << windowNum; - for (auto i = 0; i < windowNum; i++) { - WindowInfo info = {}; - RandomWindowInfo(i + 1, pid, info); - if (!Write(info, pkt)) { - printf("write WindowInfo failed\n"); - return false; - } - } - uint32_t displayNum = 1; - pkt << displayNum; - for (auto i = 0; i < displayNum; i++) { - DisplayInfo info = {}; - RandomDisplayInfo(i + 1, info); - if (!Write(info, pkt)) { - printf("write DisplayInfo failed\n"); - return false; - } - } - return true; - } -#endif // OHOS_BUILD_MMI_DEBUG -}; - ConnectCallback connectFun; /** - * @tc.name:RegisterConnectedFunction - * @tc.desc:Verify register connected + * @tc.name: RegisterConnectedFunction + * @tc.desc: Verify register connected * @tc.type: FUNC * @tc.require: */ @@ -147,8 +44,8 @@ HWTEST_F(MMIClientTest, RegisterConnectedFunction, TestSize.Level1) } /** - * @tc.name:RegisterDisconnectedFunction - * @tc.desc:Verify register disconnected + * @tc.name: RegisterDisconnectedFunction + * @tc.desc: Verify register disconnected * @tc.type: FUNC * @tc.require: */ @@ -157,25 +54,5 @@ HWTEST_F(MMIClientTest, RegisterDisconnectedFunction, TestSize.Level1) MMIClient mmiClient; mmiClient.RegisterDisconnectedFunction(connectFun); } - -#ifdef OHOS_BUILD_MMI_DEBUG -HWTEST_F(MMIClientTest, BigPacketTest, TestSize.Level1) -{ - ASSERT_TRUE(MMIEventHdl.InitClient()); - auto client = MMIEventHdl.GetMMIClient(); - ASSERT_NE(client, nullptr); - const int32_t pid = GetPid(); - const int32_t maxLimit = MMIClientUnitTest::GetRandomInt(1000, 2000); - auto beginTime = GetSysClockTime(); - printf(" begin: maxLimit:%d beginTime:%" PRId64 "\n", maxLimit, beginTime); - for (auto i = 1; i <= maxLimit; i++) { - NetPacket pkt(MmiMessageId::BIGPACKET_TEST); - ASSERT_TRUE(MMIClientUnitTest::RandomDisplayPacket(pkt, pid)); - EXPECT_TRUE(client->SendMessage(pkt)); - } - auto endTime = GetSysClockTime(); - printf(" end: endTime:%" PRId64 " D-Value:%" PRId64 "\n", endTime, (endTime - beginTime)); -} -#endif // OHOS_BUILD_MMI_DEBUG } // namespace MMI } // namespace OHOS \ No newline at end of file diff --git a/tools/event_inject/include/send_message.h b/interfaces/native/innerkits/event/include/i_input_event_filter.h similarity index 60% rename from tools/event_inject/include/send_message.h rename to interfaces/native/innerkits/event/include/i_input_event_filter.h index 310e0bec74fcb3f802ad5ecb366a2bd776661f60..fb00fc227f10817e214db9cbbeca1f55198c46ef 100644 --- a/tools/event_inject/include/send_message.h +++ b/interfaces/native/innerkits/event/include/i_input_event_filter.h @@ -13,22 +13,24 @@ * limitations under the License. */ -#ifndef SEND_MESSAGE_H -#define SEND_MESSAGE_H +#ifndef I_INPUT_EVENT_FILTER_H +#define I_INPUT_EVENT_FILTER_H -#include "nocopyable.h" +#include -#include "msg_head.h" +#include "axis_event.h" +#include "key_event.h" +#include "pointer_event.h" namespace OHOS { namespace MMI { -class SendMessage { +struct IInputEventFilter { public: - SendMessage() = default; - DISALLOW_COPY_AND_MOVE(SendMessage); - ~SendMessage() = default; - int32_t GetDevIndexName(const std::string& deviceName); + IInputEventFilter() = default; + virtual ~IInputEventFilter() = default; + virtual bool OnInputEvent(std::shared_ptr keyEvent) const = 0; + virtual bool OnInputEvent(std::shared_ptr pointerEvent) const = 0; }; } // namespace MMI } // namespace OHOS -#endif // SEND_MESSAGE_H \ No newline at end of file +#endif // I_INPUT_EVENT_FILTER_H diff --git a/interfaces/native/innerkits/event/include/input_device.h b/interfaces/native/innerkits/event/include/input_device.h index da843d7995976c14bdfb41118c81e2f73515f02a..06f526e264d1a8d11bbe7693292c49f648d34aee 100644 --- a/interfaces/native/innerkits/event/include/input_device.h +++ b/interfaces/native/innerkits/event/include/input_device.h @@ -16,6 +16,7 @@ #ifndef INPUT_DEVICE_H #define INPUT_DEVICE_H +#include #include #include @@ -23,6 +24,33 @@ namespace OHOS { namespace MMI { +enum InputDeviceCapability { + INPUT_DEV_CAP_KEYBOARD, + INPUT_DEV_CAP_POINTER, + INPUT_DEV_CAP_TOUCH, + INPUT_DEV_CAP_TABLET_TOOL, + INPUT_DEV_CAP_TABLET_PAD, + INPUT_DEV_CAP_GESTURE, + INPUT_DEV_CAP_SWITCH, + INPUT_DEV_CAP_JOYSTICK, + INPUT_DEV_CAP_MAX +}; + +inline constexpr uint32_t CapabilityToTags(InputDeviceCapability capability) +{ + return static_cast((1 << capability) - (capability / INPUT_DEV_CAP_MAX)); +} + +enum KeyboardType { + KEYBOARD_TYPE_NONE, + KEYBOARD_TYPE_UNKNOWN, + KEYBOARD_TYPE_ALPHABETICKEYBOARD, + KEYBOARD_TYPE_DIGITALKEYBOARD, + KEYBOARD_TYPE_HANDWRITINGPEN, + KEYBOARD_TYPE_REMOTECONTROL, + KEYBOARD_TYPE_MAX +}; + class InputDevice { public: InputDevice() = default; @@ -47,6 +75,12 @@ public: std::string GetPhys() const; void SetUniq(std::string uniq); std::string GetUniq() const; + void AddCapability(InputDeviceCapability cap); + bool HasCapability(InputDeviceCapability cap) const; + bool HasCapability(uint32_t deviceTags) const; + + unsigned long GetCapabilities() const; + void SetCapabilities(unsigned long caps); class AxisInfo { public: @@ -74,10 +108,12 @@ public: int32_t flat_ { 0 }; int32_t resolution_ { 0 }; }; + void AddAxisInfo(AxisInfo axis); std::vector GetAxisInfo(); InputDevice(int32_t id, std::string name, int32_t deviceType, int32_t bus, int32_t version, int32_t product, int32_t vendor, std::string phys, std::string uniq, std::vector axis); + private: int32_t id_ { -1 }; std::string name_ { "null" }; @@ -89,8 +125,18 @@ private: std::string phys_ { "null" }; std::string uniq_ { "null" }; std::vector axis_; - std::vector deviceIdList_; + std::bitset capabilities_; }; + +inline unsigned long InputDevice::GetCapabilities() const +{ + return capabilities_.to_ulong(); +} + +inline void InputDevice::SetCapabilities(unsigned long caps) +{ + capabilities_ = std::bitset(caps % (1 << INPUT_DEV_CAP_MAX)); +} } // namespace MMI } // namespace OHOS #endif // INPUT_DEVICE_H \ No newline at end of file diff --git a/interfaces/native/innerkits/event/include/input_event.h b/interfaces/native/innerkits/event/include/input_event.h index 4db8f5b29de350543ee2280badcaa8aaba8943e0..06c64e1e94493bd0f7a2221d3bd7ef1a57b84713 100644 --- a/interfaces/native/innerkits/event/include/input_event.h +++ b/interfaces/native/innerkits/event/include/input_event.h @@ -294,13 +294,6 @@ public: */ void ClearFlag(); - /** - * @brief Assigns a new ID for an input event. - * @return void - * @since 9 - */ - void AssignNewId(); - /** * @brief Marks an input event as completed. * This method can only be called once. @@ -315,7 +308,7 @@ public: * @return void * @since 9 */ - void SetProcessedCallback(std::function callback); + void SetProcessedCallback(std::function callback); public: /** @@ -353,7 +346,7 @@ private: int32_t targetWindowId_; int32_t agentWindowId_; uint32_t bitwise_; - std::function processedCallback_; + std::function processedCallback_; }; } // namespace MMI } // namespace OHOS diff --git a/interfaces/native/innerkits/event/include/key_event.h b/interfaces/native/innerkits/event/include/key_event.h index f661ea99d021edee2708ddb3f2e8f4942de7179b..8b634d39d70275885b4db75ea0327b66abdcb764 100644 --- a/interfaces/native/innerkits/event/include/key_event.h +++ b/interfaces/native/innerkits/event/include/key_event.h @@ -12,11 +12,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef KEY_EVENT_H #define KEY_EVENT_H + #include #include +#include #include "nocopyable.h" #include "parcel.h" @@ -28,28 +31,28 @@ namespace MMI { class KeyEvent : public InputEvent { public: /** - * 未知的功能按键 + * Unknown function key * * @since 9 */ - static const int32_t UNKOWN_FUNCTION_KEY; + static const int32_t UNKNOWN_FUNCTION_KEY; /** - * Num Lock功能按键 + * Num Lock key * * @since 9 */ static const int32_t NUM_LOCK_FUNCTION_KEY; /** - * Caps Lock功能按键 + * Caps Lock key * * @since 9 */ static const int32_t CAPS_LOCK_FUNCTION_KEY; /** - * Scroll Lock功能按键 + * Scroll Lock key * * @since 9 */ @@ -1368,6 +1371,13 @@ public: */ static const int32_t KEYCODE_BUTTON_DEAD; + /** + * List Menu key on keyboard + * + * @since 9 + */ + static const int32_t KEYCODE_COMPOSE; + /** * Sleep key * @@ -2858,6 +2868,202 @@ public: */ static const int32_t KEY_ACTION_UP; + /** + * Unknown intention + * + * @since 9 + */ + static const int32_t INTENTION_UNKNOWN; + + /** + * Up intention + * + * @since 9 + */ + static const int32_t INTENTION_UP; + + /** + * Down intention + * + * @since 9 + */ + static const int32_t INTENTION_DOWN; + + /** + * Left intention + * + * @since 9 + */ + static const int32_t INTENTION_LEFT; + + /** + * Right intention + * + * @since 9 + */ + static const int32_t INTENTION_RIGHT; + + /** + * Select intention + * + * @since 9 + */ + static const int32_t INTENTION_SELECT; + + /** + * Escape intention + * + * @since 9 + */ + static const int32_t INTENTION_ESCAPE; + + /** + * Back intention + * + * @since 9 + */ + static const int32_t INTENTION_BACK; + + /** + * Forward intention + * + * @since 9 + */ + static const int32_t INTENTION_FORWARD; + + /** + * Menu intention + * + * @since 9 + */ + static const int32_t INTENTION_MENU; + + /** + * Home intention + * + * @since 9 + */ + static const int32_t INTENTION_HOME; + + /** + * Page Up intention + * + * @since 9 + */ + static const int32_t INTENTION_PAGE_UP; + + /** + * Page down intention + * + * @since 9 + */ + static const int32_t INTENTION_PAGE_DOWN; + + /** + * Zoom out intention + * + * @since 9 + */ + static const int32_t INTENTION_ZOOM_OUT; + + /** + * Zoom in intention + * + * @since 9 + */ + static const int32_t INTENTION_ZOOM_IN; + + /** + * Media play/pause intention + * + * @since 9 + */ + static const int32_t INTENTION_MEDIA_PLAY_PAUSE; + + /** + * Media fast forward intention + * + * @since 9 + */ + static const int32_t INTENTION_MEDIA_FAST_FORWARD; + + /** + * Media fast rewind intention + * + * @since 9 + */ + static const int32_t INTENTION_MEDIA_FAST_REWIND; + + /** + * Media fast playback intention + * + * @since 9 + */ + static const int32_t INTENTION_MEDIA_FAST_PLAYBACK; + + /** + * Media next intention + * + * @since 9 + */ + static const int32_t INTENTION_MEDIA_NEXT; + + /** + * Media previous intention + * + * @since 9 + */ + static const int32_t INTENTION_MEDIA_PREVIOUS; + + /** + * Media mute intention + * + * @since 9 + */ + static const int32_t INTENTION_MEDIA_MUTE; + + /** + * Volume up intention + * + * @since 9 + */ + static const int32_t INTENTION_VOLUTE_UP; + + /** + * Volume down intention + * + * @since 9 + */ + static const int32_t INTENTION_VOLUTE_DOWN; + + /** + * Call intention + * + * @since 9 + */ + static const int32_t INTENTION_CALL; + + /** + * End call intention + * + * @since 9 + */ + static const int32_t INTENTION_ENDCALL; + + /** + * Reject call intention + * + * @since 9 + */ + static const int32_t INTENTION_REJECTCALL; + + /** + * Camera intention + * + * @since 9 + */ + static const int32_t INTENTION_CAMERA; + public: class KeyItem { public: @@ -2927,16 +3133,16 @@ public: void SetPressed(bool pressed); /** - * @brief 设置当前按键对应的unicode值 - * @param unicode 指定的unicode值 - * @return 空 + * @brief Sets the Unicode value corresponding to the current key. + * @param unicode Unicode value. + * @return Null * @since 9 */ void SetUnicode(uint32_t unicode); /** - * @brief 获取当前按键的unicode值 - * @return 返回unicode值 + * @brief Obtains the Unicode value of the current key. + * @return Returns the Unicode value. * @since 9 */ uint32_t GetUnicode() const; @@ -3079,18 +3285,18 @@ public: /** * @brief Obtains the key item of this key event. - * @return Returns the pointer to the key item. + * @return Returns the key item. * @since 9 */ - const KeyItem* GetKeyItem() const; + std::optional GetKeyItem() const; /** * @brief Obtains the key item based on a key code. * @param keyCode Indicates the key code. - * @return Returns the pointer to the key item. + * @return Returns the key item. * @since 9 */ - const KeyItem* GetKeyItem(int32_t keyCode) const; + std::optional GetKeyItem(int32_t keyCode) const; /** * @brief Checks whether this key event is valid. @@ -3100,30 +3306,46 @@ public: bool IsValid() const; /** - * @brief 把指定的按键转换为功能按键。 - * @param keyCode 待转换的键值。 - * @return 返回转换后的功能按键。 + * @brief Converts a specific key to a function key. + * @param keyCode Indicates the keycode of the key to convert. + * @return Returns the converted function key. * @since 9 */ int32_t TransitionFunctionKey(int32_t keyCode); /** - * @brief 给指定的功能按键设置使能状态。 - * @param funcKey 指定的功能按键。 - * @param value 待设置的功能按键状态。 - * @return 返回是否设置成功。 + * @brief Sets the enable status of the specified function key. + * @param funcKey Indicates the function key. + * @param value Indicates the enable status of the function key. + * @return Returns the result indicating whether the setting is successful. * @since 9 */ int32_t SetFunctionKey(int32_t funcKey, int32_t value); /** - * @brief 获取指定功能按键的使能状态。 - * @param funcKey 指定的功能按键。 - * @return 返回指定功能按键的使能状态。 + * @brief Obtains the enable status of the specified function key. + * @param funcKey Indicates the function key. + * @return Returns the enable status of the function key. * @since 9 */ bool GetFunctionKey(int32_t funcKey) const; + /** + * @brief Obtains the key intention of the current event. + * @param void + * @return Returns the key intention of the current event. + * @since 9 + */ + int32_t GetKeyIntention() const; + + /** + * @brief Sets the key intention for the current key event. + * @param keyIntention Specified key intention. + * @return void + * @since 9 + */ + void SetKeyIntention(int32_t keyIntention); + public: /** * @brief Writes data to a Parcel object. @@ -3156,6 +3378,7 @@ private: int32_t keyCode_ { -1 }; std::vector keys_; int32_t keyAction_ { 0 }; + int32_t keyIntention_ { -1 }; bool numLock_ { false }; bool capsLock_ { false }; bool scrollLock_ { false }; diff --git a/interfaces/native/innerkits/event/include/key_option.h b/interfaces/native/innerkits/event/include/key_option.h index 34d8eb846a91b2a039af4912a8b2527e911fe23d..310fb292bb668ceb616717ef181488edaa252993 100644 --- a/interfaces/native/innerkits/event/include/key_option.h +++ b/interfaces/native/innerkits/event/include/key_option.h @@ -87,6 +87,14 @@ public: */ int32_t GetFinalKeyDownDuration() const; + /** + * @brief Get the delay time of lifting the last key. When the last key is lifted, the subscription + * will be delayed and triggered. + * @return Return to the delay time of lifting the last key. + * @since 9 + */ + int32_t GetFinalKeyUpDelay() const; + /** * @brief Sets the duration when the final key is held down or the maximum duration between when * the key is pressed and when the key is released. @@ -100,6 +108,14 @@ public: */ void SetFinalKeyDownDuration(int32_t duration); + /** + * @brief Set the delay time for lifting the last key. + * @param delay Delay time for lifting the last key. + * @return void + * @since 9 + */ + void SetFinalKeyUpDelay(int32_t delay); + public: /** * @brief Writes data to a Parcel object. @@ -122,6 +138,7 @@ private: int32_t finalKey_ { -1 }; bool isFinalKeyDown_ { false }; int32_t finalKeyDownDuration_ { 0 }; + int32_t finalKeyUpDelay_ { 0 }; }; } // namespace MMI } // namespace OHOS diff --git a/interfaces/native/innerkits/event/include/pointer_event.h b/interfaces/native/innerkits/event/include/pointer_event.h index b17a9b0658a7230fa7b559205dc1d010cf8d7183..9780435611d27e20738df4366c7a83f3322fc48f 100644 --- a/interfaces/native/innerkits/event/include/pointer_event.h +++ b/interfaces/native/innerkits/event/include/pointer_event.h @@ -19,7 +19,6 @@ #include #include #include -#include #include #include @@ -117,6 +116,16 @@ public: */ static constexpr int32_t POINTER_ACTION_LEAVE_WINDOW = 11; + static constexpr int32_t POINTER_ACTION_PULL_DOWN = 12; + + static constexpr int32_t POINTER_ACTION_PULL_MOVE = 13; + + static constexpr int32_t POINTER_ACTION_PULL_UP = 14; + + static constexpr int32_t POINTER_ACTION_PULL_IN_WINDOW = 15; + + static constexpr int32_t POINTER_ACTION_PULL_OUT_WINDOW = 16; + enum AxisType { /** * Indicates an unknown axis type. It is generally used as the initial value. @@ -148,6 +157,69 @@ public: */ AXIS_TYPE_PINCH, + /** + * Indicates the x axis. The status of the x axis changes when you operate the joystick. + * + * @since 9 + */ + AXIS_TYPE_ABS_X, + + /** + * Indicates the y axis. The status of the y axis changes when you operate the joystick. + * + * @since 9 + */ + AXIS_TYPE_ABS_Y, + + /** + * Indicates the z axis. The status of the z axis changes when you operate the joystick. + * + * @since 9 + */ + AXIS_TYPE_ABS_Z, + + /** + * Indicates the rz axis. The status of the rz axis changes when you operate the joystick. + * + * @since 9 + */ + AXIS_TYPE_ABS_RZ, + + /** + * Indicates the gas axis. The status of the gas axis changes when you operate the joystick. + * + * @since 9 + */ + AXIS_TYPE_ABS_GAS, + + /** + * Indicates the brake axis. The status of the brake axis changes when you operate the joystick. + * + * @since 9 + */ + AXIS_TYPE_ABS_BRAKE, + + /** + * Indicates the hat0x axis. The status of the hat0x axis changes when you operate the joystick. + * + * @since 9 + */ + AXIS_TYPE_ABS_HAT0X, + + /** + * Indicates the hat0y axis. The status of the hat0y axis changes when you operate the joystick. + * + * @since 9 + */ + AXIS_TYPE_ABS_HAT0Y, + + /** + * Indicates the throttle axis. The status of the throttle axis changes when you operate the joystick. + * + * @since 9 + */ + AXIS_TYPE_ABS_THROTTLE, + /** * Indicates the maximum number of defined axis types. * @@ -186,7 +258,8 @@ public: static constexpr int32_t SOURCE_TYPE_TOUCHPAD = 3; /** - * 表明输入源产生类似于操纵杆的事件,包含按钮按下、按钮抬起、滚轮滚动。 + * Indicates joystick-like events generated by the input source, such as button pressing, button lifting, + * and wheel scrolling. * * @since 9 */ @@ -311,6 +384,209 @@ public: */ static constexpr int32_t TOOL_TYPE_LENS = 7; + /** + * Indicates the TL2 key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_TL2 = 0; + + /** + * Indicates the TR2 key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_TR2 = 1; + + /** + * Indicates the TL key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_TL = 2; + + /** + * Indicates the TR key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_TR = 3; + + /** + * Indicates the WEST key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_WEST = 4; + + /** + * Indicates the SOUTH key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_SOUTH = 5; + + /** + * Indicates the NORTH key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_NORTH = 6; + + /** + * Indicates the EAST key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_EAST = 7; + + /** + * Indicates the START key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_START = 8; + + /** + * Indicates the SELECT key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_SELECT = 9; + + /** + * Indicates the HOMEPAGE key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_HOMEPAGE = 10; + + /** + * Indicates the THUMBL key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_THUMBL = 11; + + /** + * Indicates the THUMBR key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_THUMBR = 12; + + /** + * Indicates the TRIGGER key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_TRIGGER = 13; + + /** + * Indicates the THUMB key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_THUMB = 14; + + /** + * Indicates the THUMB2 key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_THUMB2 = 15; + + /** + * Indicates the TOP key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_TOP = 16; + + /** + * Indicates the TOP2 key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_TOP2 = 17; + + /** + * Indicates the PINKIE key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_PINKIE = 18; + + /** + * Indicates the BASE key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_BASE = 19; + + /** + * Indicates the BASE2 key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_BASE2 = 20; + + /** + * Indicates the BASE3 key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_BASE3 = 21; + + /** + * Indicates the BASE4 key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_BASE4 = 22; + + /** + * Indicates the BASE5 key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_BASE5 = 23; + + /** + * Indicates the BASE6 key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_BASE6 = 24; + + /** + * Indicates the DEAD key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_DEAD = 25; + + /** + * Indicates the C key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_C = 26; + + /** + * Indicates the Z key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_Z = 27; + + /** + * Indicates the MODE key on the joystick. + * + * @since 9 + */ + static constexpr int32_t JOYSTICK_BUTTON_MODE = 28; + public: static std::shared_ptr from(std::shared_ptr inputEvent); @@ -697,29 +973,29 @@ public: bool ReadFromParcel(Parcel &in); /** - * @brief 获取原始X坐标数值. - * @return 返回原始X坐标值. + * @brief Obtains the raw X coordinate. + * @return Returns the raw X coordinate. * @since 9 */ int32_t GetRawDx() const; /** - * @brief 设置原始X坐标值. - * @param rawDx 待设置的原始X坐标值. + * @brief Sets the raw X coordinate. + * @param rawDx Indicates the raw X coordinate to set. * @return void * @since 9 */ void SetRawDx(int32_t rawDx); /** - * @brief 获取原始Y坐标数值. - * @return 返回原始Y坐标值. + * @brief Obtains the raw Y coordinate. + * @return Returns the raw Y coordinate. * @since 9 */ int32_t GetRawDy() const; /** - * @brief 设置原始Y坐标值. - * @param rawDy 待设置的原始Y坐标值. + * @brief Sets the raw Y coordinate. + * @param rawDy Indicates the raw Y coordinate to set. * @return void * @since 9 */ @@ -991,6 +1267,29 @@ public: * @since 9 */ bool IsValid() const; + + /** + * @brief 设置buffer值. + * @param buffer 表示该事件所携带的buffer值. + * @return void. + * @since 9 + */ + void SetBuffer(std::vector buffer); + + /** + * @brief 清空buffer值. + * @param void. + * @return void. + * @since 9 + */ + void ClearBuffer(); + + /** + * @brief 获取buffer值. + * @return Returns buffer. + * @since 9 + */ + std::vector GetBuffer() const; public: /** * @brief Checks whether the axes set represented by axes contains a specified type of axis. @@ -1040,8 +1339,9 @@ private: int32_t pointerAction_ { POINTER_ACTION_UNKNOWN }; int32_t buttonId_ { -1 }; uint32_t axes_ { 0U }; - std::array axisValues_ {}; + std::array axisValues_ {}; std::vector pressedKeys_; + std::vector buffer_; }; inline bool PointerEvent::HasAxis(AxisType axis) const @@ -1055,4 +1355,4 @@ inline uint32_t PointerEvent::GetAxes() const } } // namespace MMI } // namespace OHOS -#endif // POINTER_EVENT_H +#endif // POINTER_EVENT_H \ No newline at end of file diff --git a/service/hdi_inject/test/hdi_inject_test.cpp b/interfaces/native/innerkits/event/include/pointer_style.h similarity index 64% rename from service/hdi_inject/test/hdi_inject_test.cpp rename to interfaces/native/innerkits/event/include/pointer_style.h index 27746d2b2f7ee2e64817c53e6692557885155ebb..721b728f590f054405fe63fc305c5d2b2b7f3bee 100644 --- a/service/hdi_inject/test/hdi_inject_test.cpp +++ b/interfaces/native/innerkits/event/include/pointer_style.h @@ -1,33 +1,35 @@ -/* - * 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 - -#include "define_multimodal.h" - -namespace OHOS { -namespace MMI { -namespace { -using namespace testing::ext; -using namespace OHOS::MMI; -} // namespace - -class HdiInjectTest : public testing::Test { -public: - static void SetUpTestCase(void) {} - static void TearDownTestCase(void) {} -}; -} // namespace MMI -} // namespace OHOS +/* + * 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 POINTER_STYLE_H +#define POINTER_STYLE_H +#include + +namespace OHOS { +namespace MMI { +struct PointerStyleColor { + uint8_t r; + uint8_t g; + uint8_t b; +}; + +struct PointerStyle { + int32_t size { -1 }; + PointerStyleColor color { 0 }; + int32_t id { 0 }; +}; +} // namespace MMI +} // namespace OHOS +#endif // POINTER_STYLE_H \ No newline at end of file diff --git a/service/filter/include/event_filter_parcel.h b/interfaces/native/innerkits/libmmi-client-map similarity index 38% rename from service/filter/include/event_filter_parcel.h rename to interfaces/native/innerkits/libmmi-client-map index fafc24478b6e6b9a9498102e807a4d6393c502ea..479e5bc61ba84550bf154fb1c865cd7aa2e2490b 100644 --- a/service/filter/include/event_filter_parcel.h +++ b/interfaces/native/innerkits/libmmi-client-map @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2023 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 @@ -12,27 +12,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -#ifndef EVENT_FILTER_PARCEL_H -#define EVENT_FILTER_PARCEL_H - -#include "nocopyable.h" -#include "parcel.h" - -#include "pointer_event.h" - -namespace OHOS { -namespace MMI { -class PointerEventParcel final : public Parcelable { -public: - PointerEventParcel() = default; - DISALLOW_COPY_AND_MOVE(PointerEventParcel); - ~PointerEventParcel() override = default; - - bool Marshalling(Parcel& out) const override; - static PointerEventParcel *Unmarshalling(Parcel& in); - mutable std::shared_ptr data_ { nullptr }; -}; -} // namespace MMI -} // namespace OHOS -#endif // EVENT_FILTER_PARCEL_H \ No newline at end of file + 1.0 { + global: + extern "C++" { + OHOS::MMI::AxisEvent*; + OHOS::MMI::BytraceAdapter*; + OHOS::MMI::CooperationMessage*; + OHOS::MMI::InputDevice*; + OHOS::MMI::InputDeviceCooperateImpl*; + OHOS::MMI::InputEvent*; + OHOS::MMI::InputInterceptorManager*; + OHOS::MMI::InputManager*; + OHOS::MMI::InputManagerImpl*; + OHOS::MMI::InputMonitorManager*; + OHOS::MMI::KeyEvent*; + OHOS::MMI::KeyEventInputSubscribeManager*; + OHOS::MMI::KeyOption*; + OHOS::MMI::PointerEvent*; + OHOS::MMI::PointerStyle*; + OHOS::MMI::PointerStyleColor*; + OHOS::MMI::MultimodalEventHandler*; + OHOS::MMI::MMIClient*; + "vtable for OHOS::MMI::MMIClient"; + }; + local: + *; +}; \ No newline at end of file diff --git a/service/dinput/include/call_dinput_death_recipient.h b/interfaces/native/innerkits/proxy/include/extra_data.h similarity index 50% rename from service/dinput/include/call_dinput_death_recipient.h rename to interfaces/native/innerkits/proxy/include/extra_data.h index fb6035d5bb38af586a17f59bdf3dd6715e472418..912e8060c13a062d0a267afdd7f4e6fb70bb3f8f 100644 --- a/service/dinput/include/call_dinput_death_recipient.h +++ b/interfaces/native/innerkits/proxy/include/extra_data.h @@ -1,37 +1,57 @@ -/* - * 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 CALL_DINPUT_DEATH_RECIPIENT_H -#define CALL_DINPUT_DEATH_RECIPIENT_H -#ifdef OHOS_DISTRIBUTED_INPUT_MODEL - -#include "iremote_broker.h" - -namespace OHOS { -namespace MMI { -class CALLDinputDeathRecipient : public IRemoteObject::DeathRecipient { -public: - explicit CALLDinputDeathRecipient(const std::function &object)> - &deathCallback); - ~CALLDinputDeathRecipient() = default; - void OnRemoteDied(const wptr &object) override; - -private: - std::function &object)> deathCallback_ { nullptr }; -}; -} // namespace MMI -} // namespace OHOS -#endif // OHOS_DISTRIBUTED_INPUT_MODEL -#endif // REMOTE_INPUT_ABILITY_DEATH_RECIPIENT_H +/* + * 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 EXTRA_DATA_H +#define EXTRA_DATA_H + +#include + +namespace OHOS { +namespace MMI { +struct ExtraData { + /** + * buffer的最大个数 + * + * @since 9 + */ + static constexpr int32_t MAX_BUFFER_SIZE = 1024; + /** + * 是否添加buffer信息 + * + * @since 9 + */ + bool appended { false }; + /** + * buffer信息 + * + * @since 9 + */ + std::vector buffer; + /** + * 事件类型 + * + * @since 9 + */ + int32_t sourceType { -1 }; + /** + * 事件触发的pointer id + * + * @since 9 + */ + int32_t pointerId { -1 }; +}; +} // namespace MMI +} // namespace OHOS +#endif // EXTRA_DATA_H \ No newline at end of file diff --git a/interfaces/native/innerkits/proxy/include/input_manager.h b/interfaces/native/innerkits/proxy/include/input_manager.h index 0a94da1d89d569d3426b3f95ed87784754997f2e..a3ea74df257988f612e51f8051190bdb2330aa4e 100644 --- a/interfaces/native/innerkits/proxy/include/input_manager.h +++ b/interfaces/native/innerkits/proxy/include/input_manager.h @@ -16,22 +16,25 @@ #ifndef INPUT_MANAGER_H #define INPUT_MANAGER_H +#include #include #include -#include #include "event_handler.h" #include "nocopyable.h" #include "cooperation_message.h" -#include "i_anr_observer.h" -#include "display_info.h" #include "error_multimodal.h" -#include "i_input_device_listener.h" +#include "extra_data.h" +#include "i_anr_observer.h" #include "i_input_device_cooperate_listener.h" +#include "i_input_device_listener.h" #include "i_input_event_consumer.h" +#include "i_input_event_filter.h" #include "input_device.h" #include "key_option.h" +#include "pointer_style.h" +#include "window_info.h" namespace OHOS { namespace MMI { @@ -45,6 +48,9 @@ public: static InputManager *GetInstance(); virtual ~InputManager() = default; + int32_t GetDisplayBindInfo(DisplayBindInfos &infos); + int32_t SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg); + /** * @brief Updates the screen and window information. * @param displayGroupInfo Indicates the logical screen information. @@ -52,17 +58,8 @@ public: */ void UpdateDisplayInfo(const DisplayGroupInfo &displayGroupInfo); - /** - * @brief Sets a globally unique input event filter. - * @param filter Indicates the input event filter to set. When an input event occurs, this filter is - * called and returns a value indicating whether to continue processing the input event.If the filter - * returns true, the processing of the input event ends. If the filter returns false, - * the processing of the input event continues. - * @return return Returns a value greater than or equal to 0 if the input event filter is added - * successfully; returns a value less than 0 otherwise. - * @since 9 - */ - int32_t AddInputEventFilter(std::function)> filter); + int32_t AddInputEventFilter(std::shared_ptr filter, int32_t priority, uint32_t deviceTags); + int32_t RemoveInputEventFilter(int32_t filterId); /** * @brief Sets a consumer for the window input event of the current process. @@ -177,6 +174,7 @@ public: */ int32_t AddInterceptor(std::shared_ptr interceptor); int32_t AddInterceptor(std::function)> interceptor); + int32_t AddInterceptor(std::shared_ptr interceptor, int32_t priority, uint32_t deviceTags); /** * @brief Removes an interceptor. @@ -244,7 +242,7 @@ public: * @brief Checks whether the specified key codes of an input device are supported. * @param deviceId Indicates the ID of the input device. * @param keyCodes Indicates the key codes of the input device. - * @param callback Callback function, receive reported data. + * @param callback Indicates the callback used to receive the reported data. * @return Returns 0 if success; returns a non-0 value otherwise. * @since 9 */ @@ -253,7 +251,7 @@ public: /** * @brief Sets whether the pointer icon is visible. - * @param visible Whether the pointer icon is visible. The value true indicates that + * @param visible Indicates whether the pointer icon is visible. The value true indicates that * the pointer icon is visible, and the value false indicates the opposite. * @return Returns 0 if success; returns a non-0 value otherwise. * @since 9 @@ -268,22 +266,22 @@ public: bool IsPointerVisible(); /** - * @brief 设置鼠标指针样式 - * @param windowId 指定要更改鼠标指针样式的窗口ID - * @param pointerStyle 指定要更改的鼠标指针样式ID - * @return 成功返回0,否则返回失败 + * @brief Sets the mouse pointer style. + * @param windowId Indicates the ID of the window for which the mouse pointer style is set. + * @param pointerStyle Indicates the ID of the mouse pointer style. + * @return Returns 0 if the operation is successful; returns an error code otherwise. * @since 9 */ - int32_t SetPointerStyle(int32_t windowId, int32_t pointerStyle); + int32_t SetPointerStyle(int32_t windowId, PointerStyle pointerStyle); /** - * @brief 获取鼠标指针样式 - * @param windowId 指定要获取鼠标指针样式的窗口ID - * @param pointerStyle 返回获取的鼠标指针样式ID - * @return 成功返回0,否则返回失败 + * @brief Obtains the mouse pointer style. + * @param windowId Indicates the ID of the window for which the mouse pointer style is obtained. + * @param pointerStyle Indicates the ID of the mouse pointer style. + * @return Returns 0 if the operation is successful; returns an error code otherwise. * @since 9 */ - int32_t GetPointerStyle(int32_t windowId, int32_t &pointerStyle); + int32_t GetPointerStyle(int32_t windowId, PointerStyle &pointerStyle); /** * @brief Sets the mouse pointer speed, which ranges from 1 to 11. @@ -319,145 +317,68 @@ public: void SetAnrObserver(std::shared_ptr observer); /** - * @brief 设置鼠标光标的位置. - * @param x x 坐标 - * @param y y 坐标 - * @return 0表示返回成功,否则表示返回失败 - */ - int32_t SetPointerLocation(int32_t x, int32_t y); - - /** - * @brief 获取远端输入能力. - * @param deviceId 远端的deviceId - * @param remoteTypes 返回远端输入能力 - * @return 0表示返回成功,否则表示返回失败 - * @since 9 - */ - int32_t GetRemoteInputAbility(std::string deviceId, std::function)> remoteTypes); - - /** - * @brief 准备分布式. - * @param deviceId 准备分布式的那台设备的ID - * @param callback 准备分布式的回调,如果准备分布式执行完了,此回调被调用 - * 如果准备分布式成功,则返回大于或等于 0 的值 - * 否则返回小于 0 的值. - * @return 0表示返回成功,否则表示返回失败 - */ - int32_t PrepareRemoteInput(const std::string& deviceId, std::function callback); - - /** - * @brief 取消准备分布式. - * @param deviceId 取消准备分布式的那台设备的ID - * @param callback 取消准备分布式的回调,如果取消准备分布式执行完了,此回调被调用 - * 如果取消准备分布式成功,则返回大于或等于 0 的值 - * 否则返回小于 0 的值. - * @return 0表示返回成功,否则表示返回失败 - */ - int32_t UnprepareRemoteInput(const std::string& deviceId, std::function callback); - - /** - * @brief 开始分布式. - * @param deviceId 开始分布式的那台设备的ID - * @param callback 开始分布式的回调,如果开始分布式执行完了,此回调被调用 - * 如果开始分布式成功,则返回大于或等于 0 的值 - * 否则返回小于 0 的值. - * @return 0表示返回成功,否则表示返回失败 - */ - int32_t StartRemoteInput(const std::string& deviceId, uint32_t inputAbility, std::function callback); - - /** - * @brief 取消分布式. - * @param deviceId 取消分布式的那台设备的ID - * @param callback 取消分布式的回调,如果取消分布式执行完了,此回调被调用 - * 如果取消分布式成功,则返回大于或等于 0 的值 - * 否则返回小于 0 的值. - * @return 0表示返回成功,否则表示返回失败 + * @brief Sets the screen ID corresponding to the specified input device. + * @param dhid Indicates the ID of the input device. + * @param screenId Indicates the screen ID corresponding to the input device. + * @return Returns 0 if success; returns a non-0 value otherwise. */ - int32_t StopRemoteInput(const std::string& deviceId, uint32_t inputAbility, std::function callback); + int32_t SetInputDevice(const std::string &dhid, const std::string &screenId); /** - * @brief 设置指定输入设备对应的屏幕ID - * @param dhid 输入设备唯一ID - * @param screenId 输入设备对应的屏幕ID - * @return 0表示返回成功,否则表示返回失败 + * @brief Obtains the enablement status of the specified function key on the keyboard. + * @param funcKey Indicates the function key. Currently, the following function keys are supported: + * NUM_LOCK_FUNCTION_KEY + * CAPS_LOCK_FUNCTION_KEY + * SCROLL_LOCK_FUNCTION_KEY + * @return Returns true if the function key is enabled; + * returns false otherwise. */ - int32_t SetInputDevice(const std::string& dhid, const std::string& screenId); + bool GetFunctionKeyState(int32_t funcKey); /** - * @brief 注册键鼠穿越管理事件监听。 - * @param listener 穿越管理事件监听回调。 - * @return 返回值如果是0表示接口调用成功,返回其他值表示接口调用失败。 - * @since 9 + * @brief Sets the enablement status of the specified function key on the keyboard. + * @param funcKey Indicates the function key. Currently, the following function keys are supported: + * NUM_LOCK_FUNCTION_KEY + * CAPS_LOCK_FUNCTION_KEY + * SCROLL_LOCK_FUNCTION_KEY + * @param isEnable Indicates the enablement status to set. + * @return Returns 0 if success; returns a non-0 value otherwise. */ - int32_t RegisterCooperateListener(std::shared_ptr listener); + int32_t SetFunctionKeyState(int32_t funcKey, bool enable); /** - * @brief 注销键鼠穿越管理事件监听。 - * @param listener 事件监听回调. - * @return 返回值如果是0表示接口调用成功,返回其他值表示接口调用失败。 - * @since 9 + * @brief Sets the absolute coordinate of mouse. + * @param x Specifies the x coordinate of the mouse to be set. + * @param y Specifies the y coordinate of the mouse to be set. + * @return void */ - int32_t UnregisterCooperateListener(std::shared_ptr listener = nullptr); + void SetPointerLocation(int32_t x, int32_t y); /** - * @brief 开启/关闭键鼠穿越管理接口。 - * @param enabled 开启/关闭。 - * @param callback 开启/关闭键鼠穿越,此回调被调用 - * @return 返回值如果是0表示接口调用成功,返回其他值表示接口调用失败。 + * @brief 进入捕获模式 + * @param windowId 窗口id. + * @return 进入捕获模式成功或失败. * @since 9 */ - int32_t EnableInputDeviceCooperate(bool enabled, std::function callback); + int32_t EnterCaptureMode(int32_t windowId); /** - * @brief 启动跨设备键鼠穿越。 - * @param sinkDeviceId 键鼠穿越目标设备描述符(networkID) - * @param srcInputDeviceId 键鼠穿越待穿越输入外设标识符(设备ID句柄) - * @param callback 启动跨设备键鼠穿越,此回调被调用 - * @return 返回值如果是0表示接口调用成功,返回其他值表示接口调用失败。 + * @brief 退出捕获模式 + * @param windowId 窗口id. + * @return 退出捕获模式成功或失败. * @since 9 */ - int32_t StartInputDeviceCooperate(const std::string &sinkDeviceId, int32_t srcInputDeviceId, - std::function callback); + int32_t LeaveCaptureMode(int32_t windowId); - /** - * @brief 停止跨设备键鼠穿越。 - * @param callback 停止跨设备键鼠穿越,此回调被调用 - * @return 返回值如果是0表示接口调用成功,返回其他值表示接口调用失败。 - * @since 9 - */ - int32_t StopDeviceCooperate(std::function callback); + int32_t GetWindowPid(int32_t windowId); /** - * @brief 获取指定设备键鼠穿越状态。 - * @param deviceId 指定设备描述符。 - * @param callback 获取穿越管理设备状态,此回调被调用 - * @return 返回值如果是0表示接口调用成功,返回其他值表示接口调用失败。 + * @brief pointer event添加辅助信息 + * @param extraData 添加的信息. + * @return void * @since 9 */ - int32_t GetInputDeviceCooperateState(const std::string &deviceId, std::function callback); - - /** - * @brief 获取键盘设备指定功能按键的使能状态。 - * @param funcKey 指定的功能按键,当前支持的功能按键有: - * NUM_LOCK_FUNCTION_KEY - * CAPS_LOCK_FUNCTION_KEY - * SCROLL_LOCK_FUNCTION_KEY。 - * @return 返回功能按键的使能状态,true表示功能按键使能, - * false表示功能按键未使能。 - */ - bool GetFunctionKeyState(int32_t funcKey); - - /** - * @brief 设置键盘设备指定功能按键的使能状态。 - * @param funcKey 指定的功能按键,当前支持的功能按键有: - * NUM_LOCK_FUNCTION_KEY - * CAPS_LOCK_FUNCTION_KEY - * SCROLL_LOCK_FUNCTION_KEY。 - * @param isEnable 待设置的使能状态。 - * @return 0 表示设置成功,其他值表示设置失败。 - */ - int32_t SetFunctionKeyState(int32_t funcKey, bool enable); - + void AppendExtraData(const ExtraData& extraData); private: InputManager() = default; DISALLOW_COPY_AND_MOVE(InputManager); @@ -465,5 +386,4 @@ private: }; } // namespace MMI } // namespace OHOS -#define InputMgr OHOS::MMI::InputManager::GetInstance() #endif // INPUT_MANAGER_H diff --git a/interfaces/native/innerkits/proxy/include/display_info.h b/interfaces/native/innerkits/proxy/include/window_info.h similarity index 91% rename from interfaces/native/innerkits/proxy/include/display_info.h rename to interfaces/native/innerkits/proxy/include/window_info.h index baa44133aebfb4cd2c8b54a1209246ef8ac7c235..544d6d69a62eaf1bb4c0deb352a5a95b467ff0c1 100644 --- a/interfaces/native/innerkits/proxy/include/display_info.h +++ b/interfaces/native/innerkits/proxy/include/window_info.h @@ -16,39 +16,40 @@ #ifndef DISPLAY_INFO_H #define DISPLAY_INFO_H -#include #include +#include namespace OHOS { namespace MMI { +inline constexpr int32_t GLOBAL_WINDOW_ID = -1; enum Direction { /** * Rotating the display clockwise by 0 degree * * @since 9 */ - Direction0, + DIRECTION0, /** * Rotating the display clockwise by 90 degrees * * @since 9 */ - Direction90, + DIRECTION90, /** * Rotating the display clockwise by 180 degrees * * @since 9 */ - Direction180, + DIRECTION180, /** * Rotating the display clockwise by 270 degrees * * @since 9 */ - Direction270 + DIRECTION270 }; struct Rect { @@ -199,6 +200,13 @@ struct DisplayInfo { */ int32_t height; + /** + * Pixel density, which indicates the number of pixels in an inch + * + * @since 10 + */ + int32_t dpi; + /** * Name of the physical display, which is used for debugging * @@ -262,6 +270,15 @@ struct DisplayGroupInfo { */ std::vector displaysInfo; }; + +struct DisplayBindInfo +{ + int32_t inputDeviceId = -1; + std::string inputDeviceName; + int32_t displayId = -1; + std::string displayName; +}; +using DisplayBindInfos = std::vector; } // namespace MMI } // namespace OHOS #endif // DISPLAY_INFO_H \ No newline at end of file diff --git a/multimodalinput.cfg b/multimodalinput.cfg index 4355408f3886490c7047ad7211814a0ee2d3e289..bb184e05b64396dfbbaf8b60139b392c1275eade 100644 --- a/multimodalinput.cfg +++ b/multimodalinput.cfg @@ -10,13 +10,14 @@ "cmds" : [ "start udevd_service", "start mmi_uinput_service", - "exec /system/bin/udevadm trigger", + "exec /system/bin/udevadm trigger -s input", "start multimodalinput" ] },{ "name" : "early-boot", "cmds" : [ - "mkdir /data/service/el1/public/udev 0711 root system" + "mkdir /data/service/el1/public/udev 0711 root system", + "mkdir /data/service/el1/public/multimodalinput 0644 input input" ] } ], @@ -25,7 +26,7 @@ "path" : ["/system/bin/sa_main", "/system/profile/multimodalinput.xml"], "uid" : "input", "gid" : ["input"], - "permission" : ["ohos.permission.DISTRIBUTED_DATASYNC"], + "permission" : ["ohos.permission.DISTRIBUTED_DATASYNC", "ohos.permission.ACCESS_SERVICE_DM"], "start-mode" : "condition", "secon" : "u:r:multimodalinput:s0" }, { diff --git a/multimodalinput_mini.gni b/multimodalinput_mini.gni index 5db4f16d405146d1ee06ea8c4cc175f3a365d762..04755ae59dc0c1d54581675cdd84f5f221040803 100644 --- a/multimodalinput_mini.gni +++ b/multimodalinput_mini.gni @@ -16,10 +16,6 @@ import("//build/ohos.gni") mmi_path = "//foundation/multimodalinput/input" ability_runtime_path = "//foundation/ability/ability_runtime" ability_runtime_kits_path = "${ability_runtime_path}/frameworks/kits" -input_feature_libinput = true -input_feature_hdf = false -input_feature_debug = false -input_feature_distributed = false declare_args() { resource_schedule_service_enabled = false @@ -38,23 +34,230 @@ declare_args() { defined(global_parts_info.resourceschedule_resource_schedule_service)) { resource_schedule_service_enabled = true } + + uinput_inject_sources = [ + "uinput/hdf_device_event_dispatch.cpp", + "uinput/hdf_device_event_manager.cpp", + "uinput/inject_thread.cpp", + "uinput/keyboard_inject.cpp", + "uinput/virtual_device.cpp", + "uinput/virtual_keyboard.cpp", + "uinput/virtual_touch_screen.cpp", + ] + + libmmi_common_sources = [ + "events/src/input_device.cpp", + "events/src/input_event.cpp", + "events/src/key_event.cpp", + "events/src/key_option.cpp", + "events/src/pointer_event.cpp", + ] + + libmmi_client_sources = [ + "event_handler/src/anr_handler.cpp", + "event_handler/src/bytrace_adapter.cpp", + "event_handler/src/client_msg_handler.cpp", + "event_handler/src/input_device_impl.cpp", + "event_handler/src/input_handler_manager.cpp", + "event_handler/src/input_manager_impl.cpp", + "event_handler/src/multimodal_event_handler.cpp", + "events/src/axis_event.cpp", + "events/src/input_manager.cpp", + "module_loader/src/mmi_client.cpp", + "module_loader/src/mmi_fd_listener.cpp", + ] + + libmmi_service_sources = [ + "$mmi_path/frameworks/proxy/event_handler/src/bytrace_adapter.cpp", + "delegate_task/src/delegate_tasks.cpp", + "device_config/src/device_config_file_parser.cpp", + "device_manager/src/input_device_manager.cpp", + "dfx/src/dfx_hisysevent.cpp", + "event_dispatch/src/event_dispatch_handler.cpp", + "event_dump/src/event_dump.cpp", + "event_handler/src/anr_manager.cpp", + "event_handler/src/event_normalize_handler.cpp", + "event_handler/src/input_event_handler.cpp", + "event_handler/src/key_auto_repeat.cpp", + "event_handler/src/key_event_value_transformation.cpp", + "event_handler/src/key_map_manager.cpp", + "libinput_adapter/src/libinput_adapter.cpp", + "message_handle/src/server_msg_handler.cpp", + "module_loader/src/mmi_service.cpp", + "module_loader/src/uds_server.cpp", + "permission_helper/src/permission_helper.cpp", + "timer_manager/src/timer_manager.cpp", + "window_manager/src/input_display_bind_helper.cpp", + "window_manager/src/input_windows_manager.cpp", + ] + + inputdevice_sources = [ + "src/js_event_target.cpp", + "src/js_input_device_context.cpp", + "src/js_input_device_manager.cpp", + "src/js_util.cpp", + "src/native_register_module.cpp", + ] + + inputdevicecooperate_sources = [ + "src/js_event_target.cpp", + "src/js_input_device_cooperate_context.cpp", + "src/js_input_device_cooperate_manager.cpp", + "src/js_util.cpp", + "src/native_register_module.cpp", + ] + + inputmonitor_sources = [ + "src/js_input_monitor.cpp", + "src/js_input_monitor_manager.cpp", + "src/js_input_monitor_module.cpp", + "src/js_input_monitor_util.cpp", + ] + + patch_gen_libinput_third_mmi_sources = [ + root_out_dir + "/diff_libinput_mmi/src/evdev-debounce.c", + root_out_dir + "/diff_libinput_mmi/src/evdev-fallback.c", + root_out_dir + "/diff_libinput_mmi/src/evdev-joystick.c", + root_out_dir + "/diff_libinput_mmi/src/evdev-middle-button.c", + root_out_dir + "/diff_libinput_mmi/src/evdev-mt-touchpad-buttons.c", + root_out_dir + "/diff_libinput_mmi/src/evdev-mt-touchpad-edge-scroll.c", + root_out_dir + "/diff_libinput_mmi/src/evdev-mt-touchpad-gestures.c", + root_out_dir + "/diff_libinput_mmi/src/evdev-mt-touchpad-tap.c", + root_out_dir + "/diff_libinput_mmi/src/evdev-mt-touchpad-thumb.c", + root_out_dir + "/diff_libinput_mmi/src/evdev-mt-touchpad.c", + root_out_dir + "/diff_libinput_mmi/src/evdev-tablet-pad-leds.c", + root_out_dir + "/diff_libinput_mmi/src/evdev-tablet-pad.c", + root_out_dir + "/diff_libinput_mmi/src/evdev-tablet.c", + root_out_dir + "/diff_libinput_mmi/src/evdev-totem.c", + root_out_dir + "/diff_libinput_mmi/src/evdev.c", + root_out_dir + "/diff_libinput_mmi/src/filter-flat.c", + root_out_dir + "/diff_libinput_mmi/src/filter-low-dpi.c", + root_out_dir + "/diff_libinput_mmi/src/filter-mouse.c", + root_out_dir + "/diff_libinput_mmi/src/filter-tablet.c", + root_out_dir + "/diff_libinput_mmi/src/filter-touchpad-flat.c", + root_out_dir + "/diff_libinput_mmi/src/filter-touchpad-x230.c", + root_out_dir + "/diff_libinput_mmi/src/filter-touchpad.c", + root_out_dir + "/diff_libinput_mmi/src/filter-trackpoint.c", + root_out_dir + "/diff_libinput_mmi/src/filter.c", + root_out_dir + "/diff_libinput_mmi/src/libinput-util.c", + root_out_dir + "/diff_libinput_mmi/src/libinput.c", + root_out_dir + "/diff_libinput_mmi/src/path-seat.c", + root_out_dir + "/diff_libinput_mmi/src/quirks.c", + root_out_dir + "/diff_libinput_mmi/src/timer.c", + root_out_dir + "/diff_libinput_mmi/src/udev-seat.c", + root_out_dir + "/diff_libinput_mmi/src/util-list.c", + root_out_dir + "/diff_libinput_mmi/src/util-prop-parsers.c", + root_out_dir + "/diff_libinput_mmi/src/util-ratelimit.c", + root_out_dir + "/diff_libinput_mmi/src/util-strings.c", + ] + + event_injection_sources = [ + "src/device_base.cpp", + "src/get_device_node.cpp", + "src/get_device_object.cpp", + "src/injection_event_dispatch.cpp", + "src/injection_tools_help_func.cpp", + "src/input_parse.cpp", + "src/manage_inject_device.cpp", + "src/processing_finger_device.cpp", + "src/processing_game_pad_device.cpp", + "src/processing_joystick_device.cpp", + "src/processing_keyboard_device.cpp", + "src/processing_mouse_device.cpp", + "src/processing_pad_device.cpp", + "src/processing_pen_device.cpp", + "src/processing_touch_screen_device.cpp", + ] + + libmmi_virtual_device_sources = [ + "src/virtual_device.cpp", + "src/virtual_finger.cpp", + "src/virtual_gamepad.cpp", + "src/virtual_joystick.cpp", + "src/virtual_keyboard.cpp", + "src/virtual_keyboard_consumer_ctrl.cpp", + "src/virtual_keyboard_ext.cpp", + "src/virtual_keyboard_sys_ctrl.cpp", + "src/virtual_knob.cpp", + "src/virtual_knob_consumer_ctrl.cpp", + "src/virtual_knob_mouse.cpp", + "src/virtual_knob_sys_ctrl.cpp", + "src/virtual_mouse.cpp", + "src/virtual_pen.cpp", + "src/virtual_pen_keyboard.cpp", + "src/virtual_pen_mouse.cpp", + "src/virtual_remote_control.cpp", + "src/virtual_single_finger.cpp", + "src/virtual_single_touchscreen.cpp", + "src/virtual_stylus.cpp", + "src/virtual_touchpad.cpp", + "src/virtual_touchscreen.cpp", + "src/virtual_trackball.cpp", + "src/virtual_trackpad.cpp", + "src/virtual_trackpad_mouse.cpp", + "src/virtual_trackpad_sys_ctrl.cpp", + ] + + libmmi_util_sources = [ + "common/src/input_event_data_transformation.cpp", + "common/src/klog.cpp", + "common/src/util.cpp", + "common/src/util_napi.cpp", + "common/src/util_napi_error.cpp", + "network/src/circle_stream_buffer.cpp", + "network/src/net_packet.cpp", + "network/src/stream_buffer.cpp", + "socket/src/uds_client.cpp", + "socket/src/uds_session.cpp", + "socket/src/uds_socket.cpp", + ] } if (input_feature_joystick) { input_feature_mouse = true } -print("input_feature_libinput = ${input_feature_libinput}") -print("input_feature_hdf = ${input_feature_hdf}") -print("input_feature_debug = ${input_feature_debug}") print("input_feature_combination_key = ${input_feature_combination_key}") print("input_feature_pointer_drawing = ${input_feature_pointer_drawing}") print("input_feature_monitor = ${input_feature_monitor}") print("input_feature_interceptor = ${input_feature_interceptor}") -print("input_feature_distributed = ${input_feature_distributed}") print("input_feature_keyboard = ${input_feature_keyboard}") print("input_feature_mouse = ${input_feature_mouse}") print("input_feature_joystick = ${input_feature_joystick}") print("input_feature_touchscreen = ${input_feature_touchscreen}") print("input_feature_input_device = ${input_feature_input_device}") print("input_feature_input_cooperation = ${input_feature_input_cooperation}") + +input_default_defines = [] + +if (input_feature_pointer_drawing) { + input_default_defines += [ "OHOS_BUILD_ENABLE_POINTER_DRAWING" ] +} + +if (input_feature_interceptor) { + input_default_defines += [ "OHOS_BUILD_ENABLE_INTERCEPTOR" ] +} + +if (input_feature_keyboard) { + input_default_defines += [ "OHOS_BUILD_ENABLE_KEYBOARD" ] +} + +if (input_feature_monitor) { + input_default_defines += [ "OHOS_BUILD_ENABLE_MONITOR" ] +} + +if (input_feature_input_cooperation) { + input_default_defines += [ "OHOS_BUILD_ENABLE_COOPERATE" ] +} + +if (input_feature_touchscreen) { + input_default_defines += [ "OHOS_BUILD_ENABLE_TOUCH" ] +} + +if (input_feature_mouse) { + input_default_defines += [ "OHOS_BUILD_ENABLE_POINTER" ] +} + +if (input_feature_joystick) { + input_default_defines += [ "OHOS_BUILD_ENABLE_JOYSTICK" ] +} diff --git a/patch/BUILD.gn b/patch/BUILD.gn index ed05cf8beb89aa7b9e8f5062985a3f26e949bce3..6915135e3d6218c5bd6fc7fb4decbfec883605f1 100644 --- a/patch/BUILD.gn +++ b/patch/BUILD.gn @@ -18,22 +18,10 @@ group("patch_packages") { deps = [ "diff_libinput_mmi:libinput-third-mmi", "prebuild_eudev:prebuild_eudev", + "prebuild_libinput:prebuild_libinput", + "//third_party/eudev:libudev", + "//third_party/eudev:udev_conf", + "//third_party/eudev:udevd", + "//third_party/eudev:udevd.rc", ] - - if (input_feature_hdf) { - deps += [ - "diff_libevdev_hdf:libevdev-hdf", - "diff_mtdev_hdf:libmtdev-hdf", - ] - } - - if (input_feature_libinput) { - deps += [ - "prebuild_libinput:prebuild_libinput", - "//third_party/eudev:libudev", - "//third_party/eudev:udev_conf", - "//third_party/eudev:udevd", - "//third_party/eudev:udevd.rc", - ] - } } diff --git a/patch/apply_patch.sh b/patch/apply_patch.sh index 3a1a8e708f05f1c074149385f6516cdef9d7bbb8..9b934fcd073e894a53fc2a7f03195c819d8c789e 100755 --- a/patch/apply_patch.sh +++ b/patch/apply_patch.sh @@ -60,7 +60,7 @@ if [ $? -ne 0 ]; then exit 0 fi -PATCH_FILE=$(realpath $(ls -l $path_file_dir/*.diff | tail -n 1 | awk '{print $9}')) +PATCH_FILE=$(realpath $(ls $path_file_dir/*.diff | tail -n 1)) echo "PATCH_FILE: $PATCH_FILE" diff --git a/patch/diff_libevdev_hdf/BUILD.gn b/patch/diff_libevdev_hdf/BUILD.gn deleted file mode 100644 index fa0b2c748cac6f9372422c98079c2d0216a4010a..0000000000000000000000000000000000000000 --- a/patch/diff_libevdev_hdf/BUILD.gn +++ /dev/null @@ -1,89 +0,0 @@ -# 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. - -import("//build/ohos.gni") - -gen_src_dir = "//third_party/libevdev" -gen_dst_dir = root_out_dir + "/diff_libevdev_hdf" -patches_root_dir = "//foundation/multimodalinput/input/patch" -build_gn_dir = "$patches_root_dir/diff_libevdev_hdf" - -action("apply_patch") { - visibility = [ ":*" ] - script = "$patches_root_dir/apply_patch.sh" - inputs = [ "$gen_src_dir" ] - outputs = [ - "$gen_dst_dir/export_include", - "$gen_dst_dir/libevdev", - "$gen_dst_dir/include", - "$gen_dst_dir/libevdev/libevdev-uinput.c", - "$gen_dst_dir/libevdev/libevdev.c", - "$gen_dst_dir/libevdev/libevdev-names.c", - ] - args = [ - rebase_path(gen_src_dir, root_build_dir), - rebase_path(gen_dst_dir, root_build_dir), - rebase_path(build_gn_dir, root_build_dir), - ] -} - -config("libevdev_config") { - visibility = [ ":*" ] - - include_dirs = [ - "$gen_dst_dir/libevdev", - "$gen_dst_dir/include", - ] - - cflags = [ - "-Wno-unused-parameter", - "-Wno-missing-braces", - ] -} - -config("libevdev_public_config") { - include_dirs = [ "$gen_dst_dir/export_include" ] - - cflags = [] -} - -ohos_source_set("patch_gen_libevdev") { - sources = [ - "$gen_dst_dir/libevdev/libevdev-names.c", - "$gen_dst_dir/libevdev/libevdev-uinput.c", - "$gen_dst_dir/libevdev/libevdev.c", - ] - - configs = [ ":libevdev_config" ] - - public_configs = [ ":libevdev_public_config" ] - - deps = [ ":apply_patch" ] - - public_deps = [] -} - -ohos_shared_library("libevdev-hdf") { - sources = [] - - configs = [ ":libevdev_config" ] - - public_configs = [ ":libevdev_public_config" ] - - deps = [ ":patch_gen_libevdev" ] - - public_deps = [] - - part_name = "input" - subsystem_name = "multimodalinput" -} diff --git a/patch/diff_libevdev_hdf/libevdev_hdf_0000.diff b/patch/diff_libevdev_hdf/libevdev_hdf_0000.diff deleted file mode 100644 index ae28bf7eacbb2abf31976f40949dc605062f6640..0000000000000000000000000000000000000000 --- a/patch/diff_libevdev_hdf/libevdev_hdf_0000.diff +++ /dev/null @@ -1,310 +0,0 @@ -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. - -diff -Naur old/BUILD.gn new/BUILD.gn ---- old/BUILD.gn 2021-01-01 00:00:00.000000000 +0800 -+++ new/BUILD.gn 2021-01-01 00:00:00.000000000 +0800 -@@ -24,7 +24,7 @@ - ] - } - --ohos_shared_library("libevdev") { -+ohos_shared_library("libevdev-hdf") { - sources = [ - "libevdev/libevdev-uinput.c", - "libevdev/libevdev.c", -diff -Naur old/export_include/libevdev/libevdev.h new/export_include/libevdev/libevdev.h ---- old/export_include/libevdev/libevdev.h 2021-01-01 00:00:00.000000000 +0800 -+++ new/export_include/libevdev/libevdev.h 2021-01-01 00:00:00.000000000 +0800 -@@ -2359,6 +2359,10 @@ - */ - int libevdev_get_repeat(const struct libevdev *dev, int *delay, int *period); - -+/* for hdf drv interface */ -+typedef int (*libevdev_ioctl)(int hdiindex,int cmd, void * iobuff); -+int libevdev_new_from_index(int index, struct libevdev **dev,libevdev_ioctl func); -+ - /********* DEPRECATED SECTION *********/ - #if defined(__GNUC__) && __GNUC__ >= 4 - #define LIBEVDEV_DEPRECATED __attribute__ ((deprecated)) -diff -Naur old/libevdev/libevdev-int.h new/libevdev/libevdev-int.h ---- old/libevdev/libevdev-int.h 2021-01-01 00:00:00.000000000 +0800 -+++ new/libevdev/libevdev-int.h 2021-01-01 00:00:00.000000000 +0800 -@@ -37,6 +37,8 @@ - #define ABS_MT_CNT (ABS_MT_MAX - ABS_MT_MIN + 1) - #define LIBEVDEV_EXPORT __attribute__((visibility("default"))) - #define ALIAS(_to) __attribute__((alias(#_to))) -+/*for hdf drv interface*/ -+typedef int (*libevdev_ioctl)(int hdiindex,int cmd, void * iobuff); - - /** - * Sync state machine: -@@ -108,6 +110,7 @@ - struct timeval last_event_time; - - struct logdata log; -+ libevdev_ioctl fn; //新增加数据必须放到结尾 - }; - - #define log_msg_cond(dev, priority, ...) \ -diff -Naur old/libevdev/libevdev-uinput.c new/libevdev/libevdev-uinput.c ---- old/libevdev/libevdev-uinput.c 2021-01-01 00:00:00.000000000 +0800 -+++ new/libevdev/libevdev-uinput.c 2021-01-01 00:00:00.000000000 +0800 -@@ -488,7 +488,12 @@ - #ifndef __MUSL__ - struct input_event ev = { {0,0}, type, code, value }; - #else -- struct input_event ev = { type, code, value }; -+ struct input_event ev; -+ ev.input_event_sec = 0; -+ ev.input_event_usec = 0; -+ ev.type = type; -+ ev.code = code; -+ ev.value = value; - #endif - int fd = libevdev_uinput_get_fd(uinput_dev); - int rc, max; -diff -Naur old/libevdev/libevdev.c new/libevdev/libevdev.c ---- old/libevdev/libevdev.c 2021-01-01 00:00:00.000000000 +0800 -+++ new/libevdev/libevdev.c 2021-01-01 00:00:00.000000000 +0800 -@@ -1401,8 +1401,8 @@ - e.code = code; - e.value = value; - -- if (sanitize_event(dev, &e, SYNC_NONE) != EVENT_FILTER_NONE) -- return -1; -+ // if (sanitize_event(dev, &e, SYNC_NONE) != EVENT_FILTER_NONE) -+ // return -1; - - switch(type) { - case EV_ABS: rc = update_abs_state(dev, &e); break; -@@ -1885,3 +1885,205 @@ - - return ioctl(dev->fd, EVIOCSCLOCKID, &clockid) ? -errno : 0; - } -+ -+LIBEVDEV_EXPORT int -+libevdev_set_index(struct libevdev* dev, int index,libevdev_ioctl func) -+{ -+ -+ int rc; -+ int i; -+ char buf[256]; -+ -+ if (dev->initialized) { -+ log_bug(dev, "device already initialized.\n"); -+ return -EBADF; -+ } -+ -+ if (index < 0) { -+ return -EBADF; -+ } -+ -+ libevdev_reset(dev); -+ dev->fn = func; -+ dev->fd =index; -+ rc = func(index, EVIOCGBIT(0, sizeof(dev->bits)), dev->bits); -+ if (rc < 0) -+ goto out; -+ -+ memset(buf, 0, sizeof(buf)); -+ rc = func(index, EVIOCGNAME(sizeof(buf) - 1), buf); -+ if (rc < 0) -+ goto out; -+ -+ free(dev->name); -+ dev->name = strdup(buf); -+ if (!dev->name) { -+ errno = ENOMEM; -+ goto out; -+ } -+ -+ free(dev->phys); -+ dev->phys = NULL; -+ memset(buf, 0, sizeof(buf)); -+ rc = func(index, EVIOCGPHYS(sizeof(buf) - 1), buf); -+ if (rc < 0) { -+ /* uinput has no phys */ -+ if (errno != ENOENT) -+ goto out; -+ } else { -+ dev->phys = strdup(buf); -+ if (!dev->phys) { -+ errno = ENOMEM; -+ goto out; -+ } -+ } -+ -+ free(dev->uniq); -+ dev->uniq = NULL; -+ memset(buf, 0, sizeof(buf)); -+ rc = func(index, EVIOCGUNIQ(sizeof(buf) - 1), buf); -+ if (rc < 0) { -+ if (errno != ENOENT) -+ goto out; -+ } else { -+ dev->uniq = strdup(buf); -+ if (!dev->uniq) { -+ errno = ENOMEM; -+ goto out; -+ } -+ } -+ -+ rc = func(index, EVIOCGID, &dev->ids); -+ if (rc < 0) -+ goto out; -+ -+ rc = func(index, EVIOCGVERSION, &dev->driver_version); -+ if (rc < 0) -+ goto out; -+ -+ /* Built on a kernel with props, running against a kernel without property -+ support. This should not be a fatal case, we'll be missing properties but other -+ than that everything is as expected. -+ */ -+ rc = func(index, EVIOCGPROP(sizeof(dev->props)), dev->props); -+ if (rc < 0 && errno != EINVAL) -+ goto out; -+ -+ rc = func(index, EVIOCGBIT(EV_REL, sizeof(dev->rel_bits)), dev->rel_bits); -+ if (rc < 0) -+ goto out; -+ -+ rc = func(index, EVIOCGBIT(EV_ABS, sizeof(dev->abs_bits)), dev->abs_bits); -+ if (rc < 0) -+ goto out; -+ -+ rc = func(index, EVIOCGBIT(EV_LED, sizeof(dev->led_bits)), dev->led_bits); -+ if (rc < 0) -+ goto out; -+ -+ rc = func(index, EVIOCGBIT(EV_KEY, sizeof(dev->key_bits)), dev->key_bits); -+ if (rc < 0) -+ goto out; -+ -+ rc = func(index, EVIOCGBIT(EV_SW, sizeof(dev->sw_bits)), dev->sw_bits); -+ if (rc < 0) -+ goto out; -+ -+ rc = func(index, EVIOCGBIT(EV_MSC, sizeof(dev->msc_bits)), dev->msc_bits); -+ if (rc < 0) -+ goto out; -+ -+ rc = func(index, EVIOCGBIT(EV_FF, sizeof(dev->ff_bits)), dev->ff_bits); -+ if (rc < 0) -+ goto out; -+ -+ rc = func(index, EVIOCGBIT(EV_SND, sizeof(dev->snd_bits)), dev->snd_bits); -+ if (rc < 0) -+ goto out; -+ -+ rc = func(index, EVIOCGKEY(sizeof(dev->key_values)), dev->key_values); -+ if (rc < 0) -+ goto out; -+ -+ rc = func(index, EVIOCGLED(sizeof(dev->led_values)), dev->led_values); -+ if (rc < 0) -+ goto out; -+ -+ rc = func(index, EVIOCGSW(sizeof(dev->sw_values)), dev->sw_values); -+ if (rc < 0) -+ goto out; -+ -+ /* rep is a special case, always set it to 1 for both values if EV_REP is set */ -+ if (bit_is_set(dev->bits, EV_REP)) { -+ for (i = 0; i < REP_CNT; i++) -+ set_bit(dev->rep_bits, i); -+ func(index, EVIOCGREP, dev->rep_values); -+ if (rc < 0) -+ goto out; -+ } -+ -+ for (i = ABS_X; i <= ABS_MAX; i++) { -+ if (bit_is_set(dev->abs_bits, i)) { -+ struct input_absinfo abs_info; -+ rc = func(index, EVIOCGABS(i), &abs_info); -+ if (rc < 0) -+ goto out; -+ -+ fix_invalid_absinfo(dev, i, &abs_info); -+ -+ dev->abs_info[i] = abs_info; -+ } -+ } -+ -+ dev->fd = index; -+ -+ rc = init_slots(dev); -+ if (rc != 0) -+ goto out; -+ -+ if (dev->num_slots != -1) { -+ struct slot_change_state unused[dev->num_slots]; -+ sync_mt_state(dev, unused); -+ } -+ -+ rc = init_event_queue(dev); -+ if (rc < 0) { -+ dev->fd = -1; -+ return -rc; -+ } -+ -+ /* not copying key state because we won't know when we'll start to -+ * use this fd and key's are likely to change state by then. -+ * Same with the valuators, really, but they may not change. -+ */ -+ -+ dev->initialized = true; -+out: -+ if (rc) -+ libevdev_reset(dev); -+ return rc ? -errno : 0; -+ -+ -+ -+} -+ -+ -+int -+libevdev_new_from_index(int index, struct libevdev **dev,libevdev_ioctl func) -+{ -+ struct libevdev *d; -+ int rc; -+ -+ d = libevdev_new(); -+ if (!d) -+ return -ENOMEM; -+ -+ rc = libevdev_set_index(d, index,func); -+ -+ -+ if (rc < 0) -+ libevdev_free(d); -+ else -+ *dev = d; -+ return rc; -+} -diff -Naur old/libevdev/libevdev.h new/libevdev/libevdev.h ---- old/libevdev/libevdev.h 2021-01-01 00:00:00.000000000 +0800 -+++ new/libevdev/libevdev.h 2021-01-01 00:00:00.000000000 +0800 -@@ -2359,6 +2359,10 @@ - */ - int libevdev_get_repeat(const struct libevdev *dev, int *delay, int *period); - -+/* for hdf drv interface */ -+typedef int (*libevdev_ioctl)(int hdiindex,int cmd, void * iobuff); -+int libevdev_new_from_index(int index, struct libevdev **dev,libevdev_ioctl func); -+ - /********* DEPRECATED SECTION *********/ - #if defined(__GNUC__) && __GNUC__ >= 4 - #define LIBEVDEV_DEPRECATED __attribute__ ((deprecated)) diff --git a/patch/diff_libinput_mmi/BUILD.gn b/patch/diff_libinput_mmi/BUILD.gn index 08f78c70d015e1954d42ffcae6cdc7f78006f14c..adb6e77d6c2b93d00bd2a661bf888d737b70dd6e 100644 --- a/patch/diff_libinput_mmi/BUILD.gn +++ b/patch/diff_libinput_mmi/BUILD.gn @@ -18,9 +18,6 @@ gen_src_dir = "//third_party/libinput" gen_dst_dir = root_out_dir + "/diff_libinput_mmi" patches_root_dir = "//foundation/multimodalinput/input/patch" build_gn_dir = "$patches_root_dir/diff_libinput_mmi/libinput" -if (input_feature_hdf) { - build_gn_dir = "$patches_root_dir/diff_libinput_mmi/hdf" -} action("apply_patch") { visibility = [ ":*" ] @@ -66,23 +63,14 @@ action("apply_patch") { "$gen_dst_dir/tools/libinput-debug-events.c", "$gen_dst_dir/tools/libinput-list-devices.c", "$gen_dst_dir/tools/libinput-debug-tablet.c", + "$gen_dst_dir/hm_src/hm_missing.h", + "$gen_dst_dir/hm_src/hm_missing.c", + "$gen_dst_dir/tools/libinput-record.c", + "$gen_dst_dir/tools/libinput-analyze.c", + "$gen_dst_dir/tools/libinput-measure.c", + "$gen_dst_dir/tools/libinput-quirks.c", ] - if (input_feature_libinput) { - outputs += [ - "$gen_dst_dir/hm_src/hm_missing.h", - "$gen_dst_dir/hm_src/hm_missing.c", - - "$gen_dst_dir/tools/libinput-record.c", - - "$gen_dst_dir/tools/libinput-analyze.c", - - "$gen_dst_dir/tools/libinput-measure.c", - - "$gen_dst_dir/tools/libinput-quirks.c", - ] - } - args = [ rebase_path(gen_src_dir, root_build_dir), rebase_path(gen_dst_dir, root_build_dir), @@ -96,30 +84,18 @@ config("libinput-third_config") { include_dirs = [ "$gen_dst_dir/src", "$gen_dst_dir/include", + "$gen_dst_dir/hm_src", ] - if (input_feature_libinput) { - include_dirs += [ "$gen_dst_dir/hm_src" ] - } - - if (input_feature_hdf) { - include_dirs += [ "$root_out_dir/diff_mtdev_hdf/include" ] - } - cflags = [ "-Wno-unused-parameter", "-Wno-implicit-int", "-Wno-return-type", "-Wno-unused-function", "-Wno-string-conversion", + "-DHAVE_LIBINPUT_LOG_CONSOLE_ENABLE", + "-DHAVE_LIBINPUT_LOG_ENABLE", ] - - if (input_feature_libinput) { - cflags += [ - "-DHAVE_LIBINPUT_LOG_CONSOLE_ENABLE", - "-DHAVE_LIBINPUT_LOG_ENABLE", - ] - } } config("libinput-third_public_config") { @@ -130,52 +106,13 @@ config("libinput-third_public_config") { "$gen_dst_dir/src", ] - if (input_feature_hdf) { - include_dirs += [ "$root_out_dir/diff_mtdev_hdf/include" ] - } - cflags = [] } ohos_source_set("patch_gen_libinput-third-mmi") { part_name = "input" subsystem_name = "multimodalinput" - sources = [ - "$gen_dst_dir/src/evdev-debounce.c", - "$gen_dst_dir/src/evdev-fallback.c", - "$gen_dst_dir/src/evdev-joystick.c", - "$gen_dst_dir/src/evdev-middle-button.c", - "$gen_dst_dir/src/evdev-mt-touchpad-buttons.c", - "$gen_dst_dir/src/evdev-mt-touchpad-edge-scroll.c", - "$gen_dst_dir/src/evdev-mt-touchpad-gestures.c", - "$gen_dst_dir/src/evdev-mt-touchpad-tap.c", - "$gen_dst_dir/src/evdev-mt-touchpad-thumb.c", - "$gen_dst_dir/src/evdev-mt-touchpad.c", - "$gen_dst_dir/src/evdev-tablet-pad-leds.c", - "$gen_dst_dir/src/evdev-tablet-pad.c", - "$gen_dst_dir/src/evdev-tablet.c", - "$gen_dst_dir/src/evdev-totem.c", - "$gen_dst_dir/src/evdev.c", - "$gen_dst_dir/src/filter-flat.c", - "$gen_dst_dir/src/filter-low-dpi.c", - "$gen_dst_dir/src/filter-mouse.c", - "$gen_dst_dir/src/filter-tablet.c", - "$gen_dst_dir/src/filter-touchpad-flat.c", - "$gen_dst_dir/src/filter-touchpad-x230.c", - "$gen_dst_dir/src/filter-touchpad.c", - "$gen_dst_dir/src/filter-trackpoint.c", - "$gen_dst_dir/src/filter.c", - "$gen_dst_dir/src/libinput-util.c", - "$gen_dst_dir/src/libinput.c", - "$gen_dst_dir/src/path-seat.c", - "$gen_dst_dir/src/quirks.c", - "$gen_dst_dir/src/timer.c", - "$gen_dst_dir/src/udev-seat.c", - "$gen_dst_dir/src/util-list.c", - "$gen_dst_dir/src/util-prop-parsers.c", - "$gen_dst_dir/src/util-ratelimit.c", - "$gen_dst_dir/src/util-strings.c", - ] + sources = patch_gen_libinput_third_mmi_sources configs = [ ":libinput-third_config" ] @@ -183,21 +120,11 @@ ohos_source_set("patch_gen_libinput-third-mmi") { deps = [ ":apply_patch" ] - public_deps = [ "//third_party/eudev:libudev" ] - - if (input_feature_libinput) { - public_deps += [ - "//third_party/libevdev:libevdev", - "//third_party/mtdev:libmtdev", - ] - } - - if (input_feature_hdf) { - public_deps += [ - "//foundation/multimodalinput/input/patch/diff_libevdev_hdf:libevdev-hdf", - "//foundation/multimodalinput/input/patch/diff_mtdev_hdf:libmtdev-hdf", - ] - } + public_deps = [ + "//third_party/eudev:libudev", + "//third_party/libevdev:libevdev", + "//third_party/mtdev:libmtdev", + ] } ohos_shared_library("libinput-third-mmi") { @@ -209,347 +136,335 @@ ohos_shared_library("libinput-third-mmi") { deps = [ ":patch_gen_libinput-third-mmi" ] - public_deps = [ "//third_party/eudev:libudev" ] - - if (input_feature_libinput) { - public_deps += [ - "//third_party/libevdev:libevdev", - "//third_party/mtdev:libmtdev", - ] - } - - if (input_feature_hdf) { - public_deps += [ - "//foundation/multimodalinput/input/patch/diff_libevdev_hdf:libevdev-hdf", - "//foundation/multimodalinput/input/patch/diff_mtdev_hdf:libmtdev-hdf", - ] - } + public_deps = [ + "//third_party/eudev:libudev", + "//third_party/libevdev:libevdev", + "//third_party/mtdev:libmtdev", + ] part_name = "input" subsystem_name = "multimodalinput" } -if (input_feature_libinput) { - ohos_source_set("patch_gen_libinput-debug") { - part_name = "input" - subsystem_name = "multimodalinput" - sources = [ - "$gen_dst_dir/tools/libinput-debug-events.c", - "$gen_dst_dir/tools/shared.c", - "$gen_dst_dir/tools/shared.h", - ] +ohos_source_set("patch_gen_libinput-debug") { + part_name = "input" + subsystem_name = "multimodalinput" + sources = [ + "$gen_dst_dir/tools/libinput-debug-events.c", + "$gen_dst_dir/tools/shared.c", + "$gen_dst_dir/tools/shared.h", + ] - configs = [ ":libinput-third_config" ] + configs = [ ":libinput-third_config" ] - public_configs = [ ":libinput-third_public_config" ] + public_configs = [ ":libinput-third_public_config" ] - deps = [ ":apply_patch" ] + deps = [ ":apply_patch" ] - public_deps = [ - "//third_party/eudev:libudev", - "//third_party/libevdev:libevdev", - "//third_party/mtdev:libmtdev", - ] - } + public_deps = [ + "//third_party/eudev:libudev", + "//third_party/libevdev:libevdev", + "//third_party/mtdev:libmtdev", + ] +} - ohos_executable("libinput-debug-mmi") { - install_enable = true +ohos_executable("libinput-debug-mmi") { + install_enable = true - sources = [] + sources = [] - configs = [ ":libinput-third_config" ] + configs = [ ":libinput-third_config" ] - public_configs = [ ":libinput-third_public_config" ] + public_configs = [ ":libinput-third_public_config" ] - deps = [ - ":libinput-third-mmi", - ":patch_gen_libinput-debug", - ] + deps = [ + ":libinput-third-mmi", + ":patch_gen_libinput-debug", + ] - public_deps = [ - "//third_party/eudev:libudev", - "//third_party/libevdev:libevdev", - "//third_party/mtdev:libmtdev", - ] + public_deps = [ + "//third_party/eudev:libudev", + "//third_party/libevdev:libevdev", + "//third_party/mtdev:libmtdev", + ] - part_name = "input" - subsystem_name = "multimodalinput" - } + part_name = "input" + subsystem_name = "multimodalinput" +} - ohos_source_set("patch_gen_libinput-list") { - part_name = "input" - subsystem_name = "multimodalinput" - sources = [ - "$gen_dst_dir/tools/libinput-list-devices.c", - "$gen_dst_dir/tools/shared.c", - "$gen_dst_dir/tools/shared.h", - ] +ohos_source_set("patch_gen_libinput-list") { + part_name = "input" + subsystem_name = "multimodalinput" + sources = [ + "$gen_dst_dir/tools/libinput-list-devices.c", + "$gen_dst_dir/tools/shared.c", + "$gen_dst_dir/tools/shared.h", + ] - configs = [ ":libinput-third_config" ] + configs = [ ":libinput-third_config" ] - public_configs = [ ":libinput-third_public_config" ] + public_configs = [ ":libinput-third_public_config" ] - deps = [ ":apply_patch" ] + deps = [ ":apply_patch" ] - public_deps = [ - "//third_party/eudev:libudev", - "//third_party/libevdev:libevdev", - "//third_party/mtdev:libmtdev", - ] - } + public_deps = [ + "//third_party/eudev:libudev", + "//third_party/libevdev:libevdev", + "//third_party/mtdev:libmtdev", + ] +} - ohos_executable("libinput-list-mmi") { - install_enable = true +ohos_executable("libinput-list-mmi") { + install_enable = true - sources = [] + sources = [] - configs = [ ":libinput-third_config" ] + configs = [ ":libinput-third_config" ] - public_configs = [ ":libinput-third_public_config" ] + public_configs = [ ":libinput-third_public_config" ] - deps = [ - ":libinput-third-mmi", - ":patch_gen_libinput-list", - ] + deps = [ + ":libinput-third-mmi", + ":patch_gen_libinput-list", + ] - public_deps = [ - "//third_party/eudev:libudev", - "//third_party/libevdev:libevdev", - "//third_party/mtdev:libmtdev", - ] + public_deps = [ + "//third_party/eudev:libudev", + "//third_party/libevdev:libevdev", + "//third_party/mtdev:libmtdev", + ] - part_name = "input" - subsystem_name = "multimodalinput" - } + part_name = "input" + subsystem_name = "multimodalinput" +} - ohos_source_set("patch_gen_libinput-tablet") { - part_name = "input" - subsystem_name = "multimodalinput" - sources = [ - "$gen_dst_dir/tools/libinput-debug-tablet.c", - "$gen_dst_dir/tools/shared.c", - "$gen_dst_dir/tools/shared.h", - ] +ohos_source_set("patch_gen_libinput-tablet") { + part_name = "input" + subsystem_name = "multimodalinput" + sources = [ + "$gen_dst_dir/tools/libinput-debug-tablet.c", + "$gen_dst_dir/tools/shared.c", + "$gen_dst_dir/tools/shared.h", + ] - configs = [ ":libinput-third_config" ] + configs = [ ":libinput-third_config" ] - public_configs = [ ":libinput-third_public_config" ] + public_configs = [ ":libinput-third_public_config" ] - deps = [ ":apply_patch" ] + deps = [ ":apply_patch" ] - public_deps = [ - "//third_party/eudev:libudev", - "//third_party/libevdev:libevdev", - "//third_party/mtdev:libmtdev", - ] - } + public_deps = [ + "//third_party/eudev:libudev", + "//third_party/libevdev:libevdev", + "//third_party/mtdev:libmtdev", + ] +} - ohos_executable("libinput-tablet-mmi") { - install_enable = true +ohos_executable("libinput-tablet-mmi") { + install_enable = true - sources = [] + sources = [] - configs = [ ":libinput-third_config" ] + configs = [ ":libinput-third_config" ] - public_configs = [ ":libinput-third_public_config" ] + public_configs = [ ":libinput-third_public_config" ] - deps = [ - ":libinput-third-mmi", - ":patch_gen_libinput-tablet", - ] + deps = [ + ":libinput-third-mmi", + ":patch_gen_libinput-tablet", + ] - public_deps = [ - "//third_party/eudev:libudev", - "//third_party/libevdev:libevdev", - "//third_party/mtdev:libmtdev", - ] + public_deps = [ + "//third_party/eudev:libudev", + "//third_party/libevdev:libevdev", + "//third_party/mtdev:libmtdev", + ] - part_name = "input" - subsystem_name = "multimodalinput" - } + part_name = "input" + subsystem_name = "multimodalinput" +} - ohos_source_set("patch_gen_libinput-record") { - part_name = "input" - subsystem_name = "multimodalinput" - sources = [ - "$gen_dst_dir/hm_src/hm_missing.c", - "$gen_dst_dir/tools/libinput-record.c", - "$gen_dst_dir/tools/shared.c", - "$gen_dst_dir/tools/shared.h", - ] +ohos_source_set("patch_gen_libinput-record") { + part_name = "input" + subsystem_name = "multimodalinput" + sources = [ + "$gen_dst_dir/hm_src/hm_missing.c", + "$gen_dst_dir/tools/libinput-record.c", + "$gen_dst_dir/tools/shared.c", + "$gen_dst_dir/tools/shared.h", + ] - configs = [ ":libinput-third_config" ] + configs = [ ":libinput-third_config" ] - public_configs = [ ":libinput-third_public_config" ] + public_configs = [ ":libinput-third_public_config" ] - deps = [ ":apply_patch" ] + deps = [ ":apply_patch" ] - public_deps = [ - "//third_party/eudev:libudev", - "//third_party/libevdev:libevdev", - "//third_party/mtdev:libmtdev", - ] - } + public_deps = [ + "//third_party/eudev:libudev", + "//third_party/libevdev:libevdev", + "//third_party/mtdev:libmtdev", + ] +} - ohos_executable("libinput-record-mmi") { - install_enable = true +ohos_executable("libinput-record-mmi") { + install_enable = true - sources = [] + sources = [] - configs = [ ":libinput-third_config" ] + configs = [ ":libinput-third_config" ] - public_configs = [ ":libinput-third_public_config" ] + public_configs = [ ":libinput-third_public_config" ] - deps = [ - ":libinput-third-mmi", - ":patch_gen_libinput-record", - ] + deps = [ + ":libinput-third-mmi", + ":patch_gen_libinput-record", + ] - public_deps = [ - "//third_party/eudev:libudev", - "//third_party/libevdev:libevdev", - "//third_party/mtdev:libmtdev", - ] + public_deps = [ + "//third_party/eudev:libudev", + "//third_party/libevdev:libevdev", + "//third_party/mtdev:libmtdev", + ] - part_name = "input" - subsystem_name = "multimodalinput" - } + part_name = "input" + subsystem_name = "multimodalinput" +} - ohos_source_set("patch_gen_libinput-analyze") { - part_name = "input" - subsystem_name = "multimodalinput" - sources = [ - "$gen_dst_dir/tools/libinput-analyze.c", - "$gen_dst_dir/tools/shared.c", - "$gen_dst_dir/tools/shared.h", - ] +ohos_source_set("patch_gen_libinput-analyze") { + part_name = "input" + subsystem_name = "multimodalinput" + sources = [ + "$gen_dst_dir/tools/libinput-analyze.c", + "$gen_dst_dir/tools/shared.c", + "$gen_dst_dir/tools/shared.h", + ] - configs = [ ":libinput-third_config" ] + configs = [ ":libinput-third_config" ] - public_configs = [ ":libinput-third_public_config" ] + public_configs = [ ":libinput-third_public_config" ] - deps = [ ":apply_patch" ] + deps = [ ":apply_patch" ] - public_deps = [ - "//third_party/eudev:libudev", - "//third_party/libevdev:libevdev", - "//third_party/mtdev:libmtdev", - ] - } + public_deps = [ + "//third_party/eudev:libudev", + "//third_party/libevdev:libevdev", + "//third_party/mtdev:libmtdev", + ] +} - ohos_executable("libinput-analyze-mmi") { - install_enable = true +ohos_executable("libinput-analyze-mmi") { + install_enable = true - sources = [] + sources = [] - configs = [ ":libinput-third_config" ] + configs = [ ":libinput-third_config" ] - public_configs = [ ":libinput-third_public_config" ] + public_configs = [ ":libinput-third_public_config" ] - deps = [ - ":libinput-third-mmi", - ":patch_gen_libinput-analyze", - ] + deps = [ + ":libinput-third-mmi", + ":patch_gen_libinput-analyze", + ] - public_deps = [ - "//third_party/eudev:libudev", - "//third_party/libevdev:libevdev", - "//third_party/mtdev:libmtdev", - ] + public_deps = [ + "//third_party/eudev:libudev", + "//third_party/libevdev:libevdev", + "//third_party/mtdev:libmtdev", + ] - part_name = "input" - subsystem_name = "multimodalinput" - } + part_name = "input" + subsystem_name = "multimodalinput" +} - ohos_source_set("patch_gen_libinput-measure") { - part_name = "input" - subsystem_name = "multimodalinput" - sources = [ - "$gen_dst_dir/tools/libinput-measure.c", - "$gen_dst_dir/tools/shared.c", - "$gen_dst_dir/tools/shared.h", - ] +ohos_source_set("patch_gen_libinput-measure") { + part_name = "input" + subsystem_name = "multimodalinput" + sources = [ + "$gen_dst_dir/tools/libinput-measure.c", + "$gen_dst_dir/tools/shared.c", + "$gen_dst_dir/tools/shared.h", + ] - configs = [ ":libinput-third_config" ] + configs = [ ":libinput-third_config" ] - public_configs = [ ":libinput-third_public_config" ] + public_configs = [ ":libinput-third_public_config" ] - deps = [ ":apply_patch" ] + deps = [ ":apply_patch" ] - public_deps = [ - "//third_party/eudev:libudev", - "//third_party/libevdev:libevdev", - "//third_party/mtdev:libmtdev", - ] - } + public_deps = [ + "//third_party/eudev:libudev", + "//third_party/libevdev:libevdev", + "//third_party/mtdev:libmtdev", + ] +} - ohos_executable("libinput-measure-mmi") { - install_enable = true +ohos_executable("libinput-measure-mmi") { + install_enable = true - sources = [] + sources = [] - configs = [ ":libinput-third_config" ] + configs = [ ":libinput-third_config" ] - public_configs = [ ":libinput-third_public_config" ] + public_configs = [ ":libinput-third_public_config" ] - deps = [ - ":libinput-third-mmi", - ":patch_gen_libinput-measure", - ] + deps = [ + ":libinput-third-mmi", + ":patch_gen_libinput-measure", + ] - public_deps = [ - "//third_party/eudev:libudev", - "//third_party/libevdev:libevdev", - "//third_party/mtdev:libmtdev", - ] + public_deps = [ + "//third_party/eudev:libudev", + "//third_party/libevdev:libevdev", + "//third_party/mtdev:libmtdev", + ] - part_name = "input" - subsystem_name = "multimodalinput" - } + part_name = "input" + subsystem_name = "multimodalinput" +} - ohos_source_set("patch_gen_libinput-quirks") { - part_name = "input" - subsystem_name = "multimodalinput" - sources = [ - "$gen_dst_dir/tools/libinput-quirks.c", - "$gen_dst_dir/tools/shared.c", - "$gen_dst_dir/tools/shared.h", - ] +ohos_source_set("patch_gen_libinput-quirks") { + part_name = "input" + subsystem_name = "multimodalinput" + sources = [ + "$gen_dst_dir/tools/libinput-quirks.c", + "$gen_dst_dir/tools/shared.c", + "$gen_dst_dir/tools/shared.h", + ] - configs = [ ":libinput-third_config" ] + configs = [ ":libinput-third_config" ] - public_configs = [ ":libinput-third_public_config" ] + public_configs = [ ":libinput-third_public_config" ] - deps = [ ":apply_patch" ] + deps = [ ":apply_patch" ] - public_deps = [ - "//third_party/eudev:libudev", - "//third_party/libevdev:libevdev", - "//third_party/mtdev:libmtdev", - ] - } + public_deps = [ + "//third_party/eudev:libudev", + "//third_party/libevdev:libevdev", + "//third_party/mtdev:libmtdev", + ] +} - ohos_executable("libinput-quirks-mmi") { - install_enable = true +ohos_executable("libinput-quirks-mmi") { + install_enable = true - sources = [] + sources = [] - configs = [ ":libinput-third_config" ] + configs = [ ":libinput-third_config" ] - public_configs = [ ":libinput-third_public_config" ] + public_configs = [ ":libinput-third_public_config" ] - deps = [ - ":libinput-third-mmi", - ":patch_gen_libinput-quirks", - ] + deps = [ + ":libinput-third-mmi", + ":patch_gen_libinput-quirks", + ] - public_deps = [ - "//third_party/eudev:libudev", - "//third_party/libevdev:libevdev", - "//third_party/mtdev:libmtdev", - ] + public_deps = [ + "//third_party/eudev:libudev", + "//third_party/libevdev:libevdev", + "//third_party/mtdev:libmtdev", + ] - part_name = "input" - subsystem_name = "multimodalinput" - } + part_name = "input" + subsystem_name = "multimodalinput" } diff --git a/patch/diff_libinput_mmi/hdf/libinput_hdf_0000.diff b/patch/diff_libinput_mmi/hdf/libinput_hdf_0000.diff deleted file mode 100644 index d0ef53907e59c543291e1659250ebd10a1e82a4d..0000000000000000000000000000000000000000 --- a/patch/diff_libinput_mmi/hdf/libinput_hdf_0000.diff +++ /dev/null @@ -1,4956 +0,0 @@ -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. - -diff -Naur old/BUILD.gn new/BUILD.gn ---- old/BUILD.gn 2021-01-01 00:00:00.000000000 +0800 -+++ new/BUILD.gn 2021-01-01 00:00:00.000000000 +0800 -@@ -15,19 +15,23 @@ - "-Wno-return-type", - "-Wno-unused-function", - "-Wno-string-conversion", -+ "-Bsymbolic", - ] - } - - config("libinput-third_public_config") { - include_dirs = [ - "export_include", -+ "include", -+ "include/linux/linux", -+ "src", - ] - - cflags = [ - ] - } - --ohos_shared_library("libinput-third") { -+ohos_shared_library("libinput-third-hdf") { - sources = [ - "src/util-list.c", - "src/util-ratelimit.c", -@@ -61,7 +65,8 @@ - "src/path-seat.c", - "src/udev-seat.c", - "src/timer.c", --# "src/libinput-util.c", -+ "src/libinput-util.c", -+ "src/evdev-joystick.c", - ] - - configs = [ -@@ -76,9 +81,9 @@ - ] - - public_deps = [ -- "//third_party/libevdev:libevdev", -+ "//third_party/patch_libevdev_hdf:libevdev-hdf", - "//third_party/eudev:libudev", -- "//third_party/mtdev:libmtdev", -+ "//third_party/patch_mtdev_hdf:libmtdev-hdf", - ] - - part_name = "input" -@@ -86,92 +91,3 @@ - ## Build libinput-third.so }}} - --ohos_executable("libinput-debug") { -- install_enable = true -- -- sources = [ -- "tools/shared.h", -- "tools/shared.c", -- "tools/libinput-debug-events.c", -- ] -- -- configs = [ -- ":libinput-third_config", -- ] -- -- public_configs = [ -- ":libinput-third_public_config", -- ] -- -- deps = [ -- ":libinput-third", -- ] -- -- public_deps = [ -- "//third_party/libevdev:libevdev", -- "//third_party/eudev:libudev", -- "//third_party/mtdev:libmtdev", -- ] -- -- part_name = "multimodalinput_base" --} -- --ohos_executable("libinput-list") { -- install_enable = true -- -- sources = [ -- "tools/shared.h", -- "tools/shared.c", -- "tools/libinput-list-devices.c", -- ] -- -- configs = [ -- ":libinput-third_config", -- ] -- -- public_configs = [ -- ":libinput-third_public_config", -- ] -- -- deps = [ -- ":libinput-third", -- ] -- -- public_deps = [ -- "//third_party/libevdev:libevdev", -- "//third_party/eudev:libudev", -- "//third_party/mtdev:libmtdev", -- ] -- -- part_name = "multimodalinput_base" --} -- --ohos_executable("libinput-tablet") { -- install_enable = true -- -- sources = [ -- "tools/shared.h", -- "tools/shared.c", -- "tools/libinput-debug-tablet.c", -- ] -- -- configs = [ -- ":libinput-third_config", -- ] -- -- public_configs = [ -- ":libinput-third_public_config", -- ] -- -- deps = [ -- ":libinput-third", -- ] -- -- public_deps = [ -- "//third_party/libevdev:libevdev", -- "//third_party/eudev:libudev", -- "//third_party/mtdev:libmtdev", -- ] -- -- part_name = "multimodalinput_base" --} -\ No newline at end of file -diff -Naur old/export_include/libinput.h new/export_include/libinput.h ---- old/export_include/libinput.h 2021-01-01 00:00:00.000000000 +0800 -+++ new/export_include/libinput.h 2021-01-01 00:00:00.000000000 +0800 -@@ -33,6 +33,7 @@ - #include - #include - #include -+#include "util-bits.h" - - #define LIBINPUT_ATTRIBUTE_PRINTF(_format, _args) \ - __attribute__ ((format (printf, _format, _args))) -@@ -196,6 +197,22 @@ - LIBINPUT_DEVICE_CAP_TABLET_PAD = 4, - LIBINPUT_DEVICE_CAP_GESTURE = 5, - LIBINPUT_DEVICE_CAP_SWITCH = 6, -+ LIBINPUT_DEVICE_CAP_JOYSTICK = 7, -+}; -+ -+enum evdev_device_udev_tags { -+ EVDEV_UDEV_TAG_INPUT = bit(0), -+ EVDEV_UDEV_TAG_KEYBOARD = bit(1), -+ EVDEV_UDEV_TAG_MOUSE = bit(2), -+ EVDEV_UDEV_TAG_TOUCHPAD = bit(3), -+ EVDEV_UDEV_TAG_TOUCHSCREEN = bit(4), -+ EVDEV_UDEV_TAG_TABLET = bit(5), -+ EVDEV_UDEV_TAG_JOYSTICK = bit(6), -+ EVDEV_UDEV_TAG_ACCELEROMETER = bit(7), -+ EVDEV_UDEV_TAG_TABLET_PAD = bit(8), -+ EVDEV_UDEV_TAG_POINTINGSTICK = bit(9), -+ EVDEV_UDEV_TAG_TRACKBALL = bit(10), -+ EVDEV_UDEV_TAG_SWITCH = bit(11), - }; - - /** -@@ -315,6 +332,49 @@ - }; - - /** -+ * @ingroup event_joystick -+ * -+ * The source for a @ref LIBINPUT_EVENT_POINTER_AXIS event. See -+ * libinput_event_get_joystick_axis_event() for details. -+ * -+ * @since 1.16.4 -+ */ -+enum libinput_joystick_axis_source { -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_UNKNOW = 0, -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_X = bit(0), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_Y = bit(1), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_Z = bit(2), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_RX = bit(3), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_RY = bit(4), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_RZ = bit(5), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_THROTTLE = bit(6), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_RUDDER = bit(7), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_WHEEL = bit(8), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_GAS = bit(9), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_BRAKE = bit(10), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_HAT0X = bit(11), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_HAT0Y = bit(12), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_HAT1X = bit(13), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_HAT1Y = bit(14), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_HAT2X = bit(15), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_HAT2Y = bit(16), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_HAT3X = bit(17), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_HAT3Y = bit(18), -+}; -+ -+#define MAX_SOLTED_COORDS_NUM 10 -+struct sloted_coords { -+ bool is_active; -+ float x; -+ float y; -+}; -+ -+struct sloted_coords_info { -+ struct sloted_coords coords[MAX_SOLTED_COORDS_NUM]; -+ unsigned int active_count; -+}; -+ -+/** - * @ingroup device - * - * Available tool types for a device with the @ref -@@ -387,6 +447,17 @@ - LIBINPUT_TABLET_TOOL_TIP_DOWN = 1, - }; - -+struct libinput_event_joystick_axis_abs_info { -+ int32_t code; -+ int32_t value; -+ int32_t minimum; -+ int32_t maximum; -+ int32_t fuzz; -+ int32_t flat; -+ int32_t resolution; -+ float standardValue; -+}; -+ - /** - * @defgroup tablet_pad_modes Tablet pad modes - * -@@ -1893,6 +1964,12 @@ - libinput_event_gesture_get_angle_delta(struct libinput_event_gesture *event); - - /** -+ * 获取带slot的touches信息, 仅支持LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE -+ */ -+struct sloted_coords_info * -+libinput_event_gesture_get_solt_touches(struct libinput_event_gesture *event); -+ -+/** - * @defgroup event_tablet Tablet events - * - * Events that come from tools on tablet devices. For events from the pad, -@@ -3466,6 +3543,46 @@ - int - libinput_dispatch(struct libinput *libinput); - -+/**************************************************************************** -+* @brief : brief -+* @author : fms -+* @date : 2021/3/8 20:55 -+* @version : ver 1.0 -+* @inparam :libinput event -+* @outparam : -+*****************************************************************************/ -+void -+libinput_post_handle_event(struct libinput* libinput, -+ struct libinput_event* event); -+ -+/**************************************************************************** -+* @brief : get joystick button event -+* @author : fms -+* @date : 2021/3/12 10:56 -+* @version : ver 1.0 -+* @inparam : -+* @outparam : -+*****************************************************************************/ -+struct libinput_event_joystick_axis * -+libinput_event_get_joystick_axis_event(struct libinput_event *event); -+ -+/** -+ * @brief 获取轴事件的时间 -+ */ -+uint64_t -+libinput_event_get_joystick_axis_time(struct libinput_event_joystick_axis *event); -+ -+/** -+ * @brief 获取joystick指定轴的数据是否变化 -+*/ -+bool libinput_event_get_joystick_axis_value_is_changed(struct libinput_event_joystick_axis *event, enum libinput_joystick_axis_source axis); -+ -+/** -+ * @brief 获取joystick指定轴的abs信息 -+*/ -+struct libinput_event_joystick_axis_abs_info * -+libinput_event_get_joystick_axis_abs_info(struct libinput_event_joystick_axis *event, enum libinput_joystick_axis_source axis); -+ - /** - * @ingroup base - * -@@ -3936,6 +4053,10 @@ - const char * - libinput_device_get_name(struct libinput_device *device); - -+/** @brief 获取设备类型*/ -+enum evdev_device_udev_tags -+libinput_device_get_tags(struct libinput_device* device); -+ - /** - * @ingroup device - * -@@ -5928,7 +6049,97 @@ - unsigned int - libinput_device_config_rotation_get_default_angle(struct libinput_device *device); - -+struct uhdf; -+ -+int uhdfdevice_added(struct libinput *input,struct uhdf *uhdf,const char *seat_name); -+ -+struct libinput * libinput_hdf_create_context(const struct libinput_interface *interface,void *user_data); -+ -+void uhdfdevice_removed(struct uhdf *uhdf); -+ -+struct evdev_device; -+struct input_event; -+void evdev_device_dispatch_two(struct evdev_device *device, -+ struct input_event *ev); -+ -+/** -+ * @ingroup event -+ * -+ * Get the struct libinput_event_joystick_button from the event. -+ * -+ * @param event The libinput event -+ * @return The libinput_event_joystick_button for this event. -+ */ -+struct libinput_event_joystick_button* -+libinput_event_get_joystick_pointer_button_event(struct libinput_event* event); -+ -+/** -+ * @ingroup event -+ * -+ * Get the time from the event. -+ * -+ * @param event The libinput_event_joystick_button -+ * @return The time for this event. -+ */ -+uint64_t libinput_event_joystick_button_time(struct libinput_event_joystick_button* event); -+ -+/** -+ * @ingroup event -+ * -+ * Get the key value from the event. -+ * -+ * @param event The libinput_event_joystick_button -+ * @return The key value for this event. -+ */ -+uint32_t libinput_event_joystick_button_get_key(struct libinput_event_joystick_button* event); -+ -+/** -+ * @ingroup event -+ * -+ * Get the seat key count from the event. -+ * -+ * @param event The libinput_event_joystick_button -+ * @return The seat key count for this event. -+ */ -+uint32_t libinput_event_joystick_button_get_seat_key_count(struct libinput_event_joystick_button* event); -+ -+/** -+ * @ingroup event -+ * -+ * Get the value count from the event. -+ * -+ * @param event The libinput_event_joystick_button -+ * @return The value for this event. -+ */ -+int libinput_event_joystick_button_get_value(struct libinput_event_joystick_button* event); -+ -+/** -+ * @ingroup config -+ * -+ * Get the pressure of the touch screen -+ * -+ * @param Carried libinput event -+ * @return Pressure value of touch screen -+ * -+ * @since 1.4 -+ */ -+double -+libinput_event_get_touch_pressure(struct libinput_event* event); -+ -+const char* -+libinput_device_get_phys(struct libinput_device* device); -+bool libinput_pipe(struct libinput *libinput); -+int libinput_pipe_write(struct libinput *libinput, int index,const void *buf, int count); -+ -+int libinput_pipe_read(struct libinput *libinput, int index,void *buf, int count); -+int libinput_devpipe_write(struct libinput *libinput,void *buf, int count); -+int libinput_devpipe_read(struct libinput *libinput, void *buf, int count); -+int libinput_get_pipe_bytes(struct libinput *libinput, int index); -+ -+enum libinput_key_state -+libinput_event_joystick_button_get_key_state(struct libinput_event_joystick_button* event); - #ifdef __cplusplus - } - #endif - #endif /* LIBINPUT_H */ -+ -diff -Naur old/include/config.h new/include/config.h ---- old/include/config.h 2021-01-01 00:00:00.000000000 +0800 -+++ new/include/config.h 2021-01-01 00:00:00.000000000 +0800 -@@ -18,14 +18,17 @@ - #endif - #define HTTP_DOC_LINK "https://wayland.freedesktop.org/libinput/doc/latest" - --#define LIBINPUT_QUIRKS_DIR "/usr/share/libinput" -+#define LIBINPUT_QUIRKS_DIR "/etc/libinput/quirks" - --#define LIBINPUT_QUIRKS_OVERRIDE_FILE "/etc/libinput/local-overrides.quirks" -+#define LIBINPUT_QUIRKS_OVERRIDE_FILE "/etc/libinput/quirks/local-overrides.quirks" -+ -+#define LIBINPUT_QUIRKS_SRCDIR "/etc/libinput/quirks" -+ -+#define LIBINPUT_TOOL_PATH "/data/libinput" -+ -+#define MESON_BUILD_ROOT "/data/libinput" - - #undef NDEBUG --#define LIBINPUT_TOOL_PATH "" --#define LIBINPUT_QUIRKS_SRCDIR "" --#define MESON_BUILD_ROOT "" - #ifndef static_assert - # ifdef _Static_assert - # define static_assert(cond, msg) _Static_assert(cond, msg) -@@ -36,3 +39,10 @@ - - #define index strchr - #define ffs __builtin_ffs -+ -+#ifdef HAVE_LIBINPUT_LOG_ENABLE -+#define _LIBINPUT_LOG_DIR "/data/log/libinput" -+#define _LIBINPUT_LOG_PATH "/data/log/libinput/libinput.log" -+#endif -+ -+ -diff -Naur old/include/linux/linux/input-event-codes.h new/include/linux/linux/input-event-codes.h ---- old/include/linux/linux/input-event-codes.h 2021-01-01 00:00:00.000000000 +0800 -+++ new/include/linux/linux/input-event-codes.h 1970-01-01 08:00:00.000000000 +0800 -@@ -1,945 +0,0 @@ --/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */ --/* -- * Input event codes -- * -- * *** IMPORTANT *** -- * This file is not only included from C-code but also from devicetree source -- * files. As such this file MUST only contain comments and defines. -- * -- * Copyright (c) 1999-2002 Vojtech Pavlik -- * Copyright (c) 2015 Hans de Goede -- * -- * This program is free software; you can redistribute it and/or modify it -- * under the terms of the GNU General Public License version 2 as published by -- * the Free Software Foundation. -- */ --#ifndef _UAPI_INPUT_EVENT_CODES_H --#define _UAPI_INPUT_EVENT_CODES_H -- --/* -- * Device properties and quirks -- */ -- --#define INPUT_PROP_POINTER 0x00 /* needs a pointer */ --#define INPUT_PROP_DIRECT 0x01 /* direct input devices */ --#define INPUT_PROP_BUTTONPAD 0x02 /* has button(s) under pad */ --#define INPUT_PROP_SEMI_MT 0x03 /* touch rectangle only */ --#define INPUT_PROP_TOPBUTTONPAD 0x04 /* softbuttons at top of pad */ --#define INPUT_PROP_POINTING_STICK 0x05 /* is a pointing stick */ --#define INPUT_PROP_ACCELEROMETER 0x06 /* has accelerometer */ -- --#define INPUT_PROP_MAX 0x1f --#define INPUT_PROP_CNT (INPUT_PROP_MAX + 1) -- --/* -- * Event types -- */ -- --#define EV_SYN 0x00 --#define EV_KEY 0x01 --#define EV_REL 0x02 --#define EV_ABS 0x03 --#define EV_MSC 0x04 --#define EV_SW 0x05 --#define EV_LED 0x11 --#define EV_SND 0x12 --#define EV_REP 0x14 --#define EV_FF 0x15 --#define EV_PWR 0x16 --#define EV_FF_STATUS 0x17 --#define EV_MAX 0x1f --#define EV_CNT (EV_MAX+1) -- --/* -- * Synchronization events. -- */ -- --#define SYN_REPORT 0 --#define SYN_CONFIG 1 --#define SYN_MT_REPORT 2 --#define SYN_DROPPED 3 --#define SYN_MAX 0xf --#define SYN_CNT (SYN_MAX+1) -- --/* -- * Keys and buttons -- * -- * Most of the keys/buttons are modeled after USB HUT 1.12 -- * (see http://www.usb.org/developers/hidpage). -- * Abbreviations in the comments: -- * AC - Application Control -- * AL - Application Launch Button -- * SC - System Control -- */ -- --#define KEY_RESERVED 0 --#define KEY_ESC 1 --#define KEY_1 2 --#define KEY_2 3 --#define KEY_3 4 --#define KEY_4 5 --#define KEY_5 6 --#define KEY_6 7 --#define KEY_7 8 --#define KEY_8 9 --#define KEY_9 10 --#define KEY_0 11 --#define KEY_MINUS 12 --#define KEY_EQUAL 13 --#define KEY_BACKSPACE 14 --#define KEY_TAB 15 --#define KEY_Q 16 --#define KEY_W 17 --#define KEY_E 18 --#define KEY_R 19 --#define KEY_T 20 --#define KEY_Y 21 --#define KEY_U 22 --#define KEY_I 23 --#define KEY_O 24 --#define KEY_P 25 --#define KEY_LEFTBRACE 26 --#define KEY_RIGHTBRACE 27 --#define KEY_ENTER 28 --#define KEY_LEFTCTRL 29 --#define KEY_A 30 --#define KEY_S 31 --#define KEY_D 32 --#define KEY_F 33 --#define KEY_G 34 --#define KEY_H 35 --#define KEY_J 36 --#define KEY_K 37 --#define KEY_L 38 --#define KEY_SEMICOLON 39 --#define KEY_APOSTROPHE 40 --#define KEY_GRAVE 41 --#define KEY_LEFTSHIFT 42 --#define KEY_BACKSLASH 43 --#define KEY_Z 44 --#define KEY_X 45 --#define KEY_C 46 --#define KEY_V 47 --#define KEY_B 48 --#define KEY_N 49 --#define KEY_M 50 --#define KEY_COMMA 51 --#define KEY_DOT 52 --#define KEY_SLASH 53 --#define KEY_RIGHTSHIFT 54 --#define KEY_KPASTERISK 55 --#define KEY_LEFTALT 56 --#define KEY_SPACE 57 --#define KEY_CAPSLOCK 58 --#define KEY_F1 59 --#define KEY_F2 60 --#define KEY_F3 61 --#define KEY_F4 62 --#define KEY_F5 63 --#define KEY_F6 64 --#define KEY_F7 65 --#define KEY_F8 66 --#define KEY_F9 67 --#define KEY_F10 68 --#define KEY_NUMLOCK 69 --#define KEY_SCROLLLOCK 70 --#define KEY_KP7 71 --#define KEY_KP8 72 --#define KEY_KP9 73 --#define KEY_KPMINUS 74 --#define KEY_KP4 75 --#define KEY_KP5 76 --#define KEY_KP6 77 --#define KEY_KPPLUS 78 --#define KEY_KP1 79 --#define KEY_KP2 80 --#define KEY_KP3 81 --#define KEY_KP0 82 --#define KEY_KPDOT 83 -- --#define KEY_ZENKAKUHANKAKU 85 --#define KEY_102ND 86 --#define KEY_F11 87 --#define KEY_F12 88 --#define KEY_RO 89 --#define KEY_KATAKANA 90 --#define KEY_HIRAGANA 91 --#define KEY_HENKAN 92 --#define KEY_KATAKANAHIRAGANA 93 --#define KEY_MUHENKAN 94 --#define KEY_KPJPCOMMA 95 --#define KEY_KPENTER 96 --#define KEY_RIGHTCTRL 97 --#define KEY_KPSLASH 98 --#define KEY_SYSRQ 99 --#define KEY_RIGHTALT 100 --#define KEY_LINEFEED 101 --#define KEY_HOME 102 --#define KEY_UP 103 --#define KEY_PAGEUP 104 --#define KEY_LEFT 105 --#define KEY_RIGHT 106 --#define KEY_END 107 --#define KEY_DOWN 108 --#define KEY_PAGEDOWN 109 --#define KEY_INSERT 110 --#define KEY_DELETE 111 --#define KEY_MACRO 112 --#define KEY_MUTE 113 --#define KEY_VOLUMEDOWN 114 --#define KEY_VOLUMEUP 115 --#define KEY_POWER 116 /* SC System Power Down */ --#define KEY_KPEQUAL 117 --#define KEY_KPPLUSMINUS 118 --#define KEY_PAUSE 119 --#define KEY_SCALE 120 /* AL Compiz Scale (Expose) */ -- --#define KEY_KPCOMMA 121 --#define KEY_HANGEUL 122 --#define KEY_HANGUEL KEY_HANGEUL --#define KEY_HANJA 123 --#define KEY_YEN 124 --#define KEY_LEFTMETA 125 --#define KEY_RIGHTMETA 126 --#define KEY_COMPOSE 127 -- --#define KEY_STOP 128 /* AC Stop */ --#define KEY_AGAIN 129 --#define KEY_PROPS 130 /* AC Properties */ --#define KEY_UNDO 131 /* AC Undo */ --#define KEY_FRONT 132 --#define KEY_COPY 133 /* AC Copy */ --#define KEY_OPEN 134 /* AC Open */ --#define KEY_PASTE 135 /* AC Paste */ --#define KEY_FIND 136 /* AC Search */ --#define KEY_CUT 137 /* AC Cut */ --#define KEY_HELP 138 /* AL Integrated Help Center */ --#define KEY_MENU 139 /* Menu (show menu) */ --#define KEY_CALC 140 /* AL Calculator */ --#define KEY_SETUP 141 --#define KEY_SLEEP 142 /* SC System Sleep */ --#define KEY_WAKEUP 143 /* System Wake Up */ --#define KEY_FILE 144 /* AL Local Machine Browser */ --#define KEY_SENDFILE 145 --#define KEY_DELETEFILE 146 --#define KEY_XFER 147 --#define KEY_PROG1 148 --#define KEY_PROG2 149 --#define KEY_WWW 150 /* AL Internet Browser */ --#define KEY_MSDOS 151 --#define KEY_COFFEE 152 /* AL Terminal Lock/Screensaver */ --#define KEY_SCREENLOCK KEY_COFFEE --#define KEY_ROTATE_DISPLAY 153 /* Display orientation for e.g. tablets */ --#define KEY_DIRECTION KEY_ROTATE_DISPLAY --#define KEY_CYCLEWINDOWS 154 --#define KEY_MAIL 155 --#define KEY_BOOKMARKS 156 /* AC Bookmarks */ --#define KEY_COMPUTER 157 --#define KEY_BACK 158 /* AC Back */ --#define KEY_FORWARD 159 /* AC Forward */ --#define KEY_CLOSECD 160 --#define KEY_EJECTCD 161 --#define KEY_EJECTCLOSECD 162 --#define KEY_NEXTSONG 163 --#define KEY_PLAYPAUSE 164 --#define KEY_PREVIOUSSONG 165 --#define KEY_STOPCD 166 --#define KEY_RECORD 167 --#define KEY_REWIND 168 --#define KEY_PHONE 169 /* Media Select Telephone */ --#define KEY_ISO 170 --#define KEY_CONFIG 171 /* AL Consumer Control Configuration */ --#define KEY_HOMEPAGE 172 /* AC Home */ --#define KEY_REFRESH 173 /* AC Refresh */ --#define KEY_EXIT 174 /* AC Exit */ --#define KEY_MOVE 175 --#define KEY_EDIT 176 --#define KEY_SCROLLUP 177 --#define KEY_SCROLLDOWN 178 --#define KEY_KPLEFTPAREN 179 --#define KEY_KPRIGHTPAREN 180 --#define KEY_NEW 181 /* AC New */ --#define KEY_REDO 182 /* AC Redo/Repeat */ -- --#define KEY_F13 183 --#define KEY_F14 184 --#define KEY_F15 185 --#define KEY_F16 186 --#define KEY_F17 187 --#define KEY_F18 188 --#define KEY_F19 189 --#define KEY_F20 190 --#define KEY_F21 191 --#define KEY_F22 192 --#define KEY_F23 193 --#define KEY_F24 194 -- --#define KEY_PLAYCD 200 --#define KEY_PAUSECD 201 --#define KEY_PROG3 202 --#define KEY_PROG4 203 --#define KEY_DASHBOARD 204 /* AL Dashboard */ --#define KEY_SUSPEND 205 --#define KEY_CLOSE 206 /* AC Close */ --#define KEY_PLAY 207 --#define KEY_FASTFORWARD 208 --#define KEY_BASSBOOST 209 --#define KEY_PRINT 210 /* AC Print */ --#define KEY_HP 211 --#define KEY_CAMERA 212 --#define KEY_SOUND 213 --#define KEY_QUESTION 214 --#define KEY_EMAIL 215 --#define KEY_CHAT 216 --#define KEY_SEARCH 217 --#define KEY_CONNECT 218 --#define KEY_FINANCE 219 /* AL Checkbook/Finance */ --#define KEY_SPORT 220 --#define KEY_SHOP 221 --#define KEY_ALTERASE 222 --#define KEY_CANCEL 223 /* AC Cancel */ --#define KEY_BRIGHTNESSDOWN 224 --#define KEY_BRIGHTNESSUP 225 --#define KEY_MEDIA 226 -- --#define KEY_SWITCHVIDEOMODE 227 /* Cycle between available video -- outputs (Monitor/LCD/TV-out/etc) */ --#define KEY_KBDILLUMTOGGLE 228 --#define KEY_KBDILLUMDOWN 229 --#define KEY_KBDILLUMUP 230 -- --#define KEY_SEND 231 /* AC Send */ --#define KEY_REPLY 232 /* AC Reply */ --#define KEY_FORWARDMAIL 233 /* AC Forward Msg */ --#define KEY_SAVE 234 /* AC Save */ --#define KEY_DOCUMENTS 235 -- --#define KEY_BATTERY 236 -- --#define KEY_BLUETOOTH 237 --#define KEY_WLAN 238 --#define KEY_UWB 239 -- --#define KEY_UNKNOWN 240 -- --#define KEY_VIDEO_NEXT 241 /* drive next video source */ --#define KEY_VIDEO_PREV 242 /* drive previous video source */ --#define KEY_BRIGHTNESS_CYCLE 243 /* brightness up, after max is min */ --#define KEY_BRIGHTNESS_AUTO 244 /* Set Auto Brightness: manual -- brightness control is off, -- rely on ambient */ --#define KEY_BRIGHTNESS_ZERO KEY_BRIGHTNESS_AUTO --#define KEY_DISPLAY_OFF 245 /* display device to off state */ -- --#define KEY_WWAN 246 /* Wireless WAN (LTE, UMTS, GSM, etc.) */ --#define KEY_WIMAX KEY_WWAN --#define KEY_RFKILL 247 /* Key that controls all radios */ -- --#define KEY_MICMUTE 248 /* Mute / unmute the microphone */ -- --/* Code 255 is reserved for special needs of AT keyboard driver */ -- --#define BTN_MISC 0x100 --#define BTN_0 0x100 --#define BTN_1 0x101 --#define BTN_2 0x102 --#define BTN_3 0x103 --#define BTN_4 0x104 --#define BTN_5 0x105 --#define BTN_6 0x106 --#define BTN_7 0x107 --#define BTN_8 0x108 --#define BTN_9 0x109 -- --#define BTN_MOUSE 0x110 --#define BTN_LEFT 0x110 --#define BTN_RIGHT 0x111 --#define BTN_MIDDLE 0x112 --#define BTN_SIDE 0x113 --#define BTN_EXTRA 0x114 --#define BTN_FORWARD 0x115 --#define BTN_BACK 0x116 --#define BTN_TASK 0x117 -- --#define BTN_JOYSTICK 0x120 --#define BTN_TRIGGER 0x120 --#define BTN_THUMB 0x121 --#define BTN_THUMB2 0x122 --#define BTN_TOP 0x123 --#define BTN_TOP2 0x124 --#define BTN_PINKIE 0x125 --#define BTN_BASE 0x126 --#define BTN_BASE2 0x127 --#define BTN_BASE3 0x128 --#define BTN_BASE4 0x129 --#define BTN_BASE5 0x12a --#define BTN_BASE6 0x12b --#define BTN_DEAD 0x12f -- --#define BTN_GAMEPAD 0x130 --#define BTN_SOUTH 0x130 --#define BTN_A BTN_SOUTH --#define BTN_EAST 0x131 --#define BTN_B BTN_EAST --#define BTN_C 0x132 --#define BTN_NORTH 0x133 --#define BTN_X BTN_NORTH --#define BTN_WEST 0x134 --#define BTN_Y BTN_WEST --#define BTN_Z 0x135 --#define BTN_TL 0x136 --#define BTN_TR 0x137 --#define BTN_TL2 0x138 --#define BTN_TR2 0x139 --#define BTN_SELECT 0x13a --#define BTN_START 0x13b --#define BTN_MODE 0x13c --#define BTN_THUMBL 0x13d --#define BTN_THUMBR 0x13e -- --#define BTN_DIGI 0x140 --#define BTN_TOOL_PEN 0x140 --#define BTN_TOOL_RUBBER 0x141 --#define BTN_TOOL_BRUSH 0x142 --#define BTN_TOOL_PENCIL 0x143 --#define BTN_TOOL_AIRBRUSH 0x144 --#define BTN_TOOL_FINGER 0x145 --#define BTN_TOOL_MOUSE 0x146 --#define BTN_TOOL_LENS 0x147 --#define BTN_TOOL_QUINTTAP 0x148 /* Five fingers on trackpad */ --#define BTN_STYLUS3 0x149 --#define BTN_TOUCH 0x14a --#define BTN_STYLUS 0x14b --#define BTN_STYLUS2 0x14c --#define BTN_TOOL_DOUBLETAP 0x14d --#define BTN_TOOL_TRIPLETAP 0x14e --#define BTN_TOOL_QUADTAP 0x14f /* Four fingers on trackpad */ -- --#define BTN_WHEEL 0x150 --#define BTN_GEAR_DOWN 0x150 --#define BTN_GEAR_UP 0x151 -- --#define KEY_OK 0x160 --#define KEY_SELECT 0x161 --#define KEY_GOTO 0x162 --#define KEY_CLEAR 0x163 --#define KEY_POWER2 0x164 --#define KEY_OPTION 0x165 --#define KEY_INFO 0x166 /* AL OEM Features/Tips/Tutorial */ --#define KEY_TIME 0x167 --#define KEY_VENDOR 0x168 --#define KEY_ARCHIVE 0x169 --#define KEY_PROGRAM 0x16a /* Media Select Program Guide */ --#define KEY_CHANNEL 0x16b --#define KEY_FAVORITES 0x16c --#define KEY_EPG 0x16d --#define KEY_PVR 0x16e /* Media Select Home */ --#define KEY_MHP 0x16f --#define KEY_LANGUAGE 0x170 --#define KEY_TITLE 0x171 --#define KEY_SUBTITLE 0x172 --#define KEY_ANGLE 0x173 --#define KEY_FULL_SCREEN 0x174 /* AC View Toggle */ --#define KEY_ZOOM KEY_FULL_SCREEN --#define KEY_MODE 0x175 --#define KEY_KEYBOARD 0x176 --#define KEY_ASPECT_RATIO 0x177 /* HUTRR37: Aspect */ --#define KEY_SCREEN KEY_ASPECT_RATIO --#define KEY_PC 0x178 /* Media Select Computer */ --#define KEY_TV 0x179 /* Media Select TV */ --#define KEY_TV2 0x17a /* Media Select Cable */ --#define KEY_VCR 0x17b /* Media Select VCR */ --#define KEY_VCR2 0x17c /* VCR Plus */ --#define KEY_SAT 0x17d /* Media Select Satellite */ --#define KEY_SAT2 0x17e --#define KEY_CD 0x17f /* Media Select CD */ --#define KEY_TAPE 0x180 /* Media Select Tape */ --#define KEY_RADIO 0x181 --#define KEY_TUNER 0x182 /* Media Select Tuner */ --#define KEY_PLAYER 0x183 --#define KEY_TEXT 0x184 --#define KEY_DVD 0x185 /* Media Select DVD */ --#define KEY_AUX 0x186 --#define KEY_MP3 0x187 --#define KEY_AUDIO 0x188 /* AL Audio Browser */ --#define KEY_VIDEO 0x189 /* AL Movie Browser */ --#define KEY_DIRECTORY 0x18a --#define KEY_LIST 0x18b --#define KEY_MEMO 0x18c /* Media Select Messages */ --#define KEY_CALENDAR 0x18d --#define KEY_RED 0x18e --#define KEY_GREEN 0x18f --#define KEY_YELLOW 0x190 --#define KEY_BLUE 0x191 --#define KEY_CHANNELUP 0x192 /* Channel Increment */ --#define KEY_CHANNELDOWN 0x193 /* Channel Decrement */ --#define KEY_FIRST 0x194 --#define KEY_LAST 0x195 /* Recall Last */ --#define KEY_AB 0x196 --#define KEY_NEXT 0x197 --#define KEY_RESTART 0x198 --#define KEY_SLOW 0x199 --#define KEY_SHUFFLE 0x19a --#define KEY_BREAK 0x19b --#define KEY_PREVIOUS 0x19c --#define KEY_DIGITS 0x19d --#define KEY_TEEN 0x19e --#define KEY_TWEN 0x19f --#define KEY_VIDEOPHONE 0x1a0 /* Media Select Video Phone */ --#define KEY_GAMES 0x1a1 /* Media Select Games */ --#define KEY_ZOOMIN 0x1a2 /* AC Zoom In */ --#define KEY_ZOOMOUT 0x1a3 /* AC Zoom Out */ --#define KEY_ZOOMRESET 0x1a4 /* AC Zoom */ --#define KEY_WORDPROCESSOR 0x1a5 /* AL Word Processor */ --#define KEY_EDITOR 0x1a6 /* AL Text Editor */ --#define KEY_SPREADSHEET 0x1a7 /* AL Spreadsheet */ --#define KEY_GRAPHICSEDITOR 0x1a8 /* AL Graphics Editor */ --#define KEY_PRESENTATION 0x1a9 /* AL Presentation App */ --#define KEY_DATABASE 0x1aa /* AL Database App */ --#define KEY_NEWS 0x1ab /* AL Newsreader */ --#define KEY_VOICEMAIL 0x1ac /* AL Voicemail */ --#define KEY_ADDRESSBOOK 0x1ad /* AL Contacts/Address Book */ --#define KEY_MESSENGER 0x1ae /* AL Instant Messaging */ --#define KEY_DISPLAYTOGGLE 0x1af /* Turn display (LCD) on and off */ --#define KEY_BRIGHTNESS_TOGGLE KEY_DISPLAYTOGGLE --#define KEY_SPELLCHECK 0x1b0 /* AL Spell Check */ --#define KEY_LOGOFF 0x1b1 /* AL Logoff */ -- --#define KEY_DOLLAR 0x1b2 --#define KEY_EURO 0x1b3 -- --#define KEY_FRAMEBACK 0x1b4 /* Consumer - transport controls */ --#define KEY_FRAMEFORWARD 0x1b5 --#define KEY_CONTEXT_MENU 0x1b6 /* GenDesc - system context menu */ --#define KEY_MEDIA_REPEAT 0x1b7 /* Consumer - transport control */ --#define KEY_10CHANNELSUP 0x1b8 /* 10 channels up (10+) */ --#define KEY_10CHANNELSDOWN 0x1b9 /* 10 channels down (10-) */ --#define KEY_IMAGES 0x1ba /* AL Image Browser */ -- --#define KEY_DEL_EOL 0x1c0 --#define KEY_DEL_EOS 0x1c1 --#define KEY_INS_LINE 0x1c2 --#define KEY_DEL_LINE 0x1c3 -- --#define KEY_FN 0x1d0 --#define KEY_FN_ESC 0x1d1 --#define KEY_FN_F1 0x1d2 --#define KEY_FN_F2 0x1d3 --#define KEY_FN_F3 0x1d4 --#define KEY_FN_F4 0x1d5 --#define KEY_FN_F5 0x1d6 --#define KEY_FN_F6 0x1d7 --#define KEY_FN_F7 0x1d8 --#define KEY_FN_F8 0x1d9 --#define KEY_FN_F9 0x1da --#define KEY_FN_F10 0x1db --#define KEY_FN_F11 0x1dc --#define KEY_FN_F12 0x1dd --#define KEY_FN_1 0x1de --#define KEY_FN_2 0x1df --#define KEY_FN_D 0x1e0 --#define KEY_FN_E 0x1e1 --#define KEY_FN_F 0x1e2 --#define KEY_FN_S 0x1e3 --#define KEY_FN_B 0x1e4 -- --#define KEY_BRL_DOT1 0x1f1 --#define KEY_BRL_DOT2 0x1f2 --#define KEY_BRL_DOT3 0x1f3 --#define KEY_BRL_DOT4 0x1f4 --#define KEY_BRL_DOT5 0x1f5 --#define KEY_BRL_DOT6 0x1f6 --#define KEY_BRL_DOT7 0x1f7 --#define KEY_BRL_DOT8 0x1f8 --#define KEY_BRL_DOT9 0x1f9 --#define KEY_BRL_DOT10 0x1fa -- --#define KEY_NUMERIC_0 0x200 /* used by phones, remote controls, */ --#define KEY_NUMERIC_1 0x201 /* and other keypads */ --#define KEY_NUMERIC_2 0x202 --#define KEY_NUMERIC_3 0x203 --#define KEY_NUMERIC_4 0x204 --#define KEY_NUMERIC_5 0x205 --#define KEY_NUMERIC_6 0x206 --#define KEY_NUMERIC_7 0x207 --#define KEY_NUMERIC_8 0x208 --#define KEY_NUMERIC_9 0x209 --#define KEY_NUMERIC_STAR 0x20a --#define KEY_NUMERIC_POUND 0x20b --#define KEY_NUMERIC_A 0x20c /* Phone key A - HUT Telephony 0xb9 */ --#define KEY_NUMERIC_B 0x20d --#define KEY_NUMERIC_C 0x20e --#define KEY_NUMERIC_D 0x20f -- --#define KEY_CAMERA_FOCUS 0x210 --#define KEY_WPS_BUTTON 0x211 /* WiFi Protected Setup key */ -- --#define KEY_TOUCHPAD_TOGGLE 0x212 /* Request switch touchpad on or off */ --#define KEY_TOUCHPAD_ON 0x213 --#define KEY_TOUCHPAD_OFF 0x214 -- --#define KEY_CAMERA_ZOOMIN 0x215 --#define KEY_CAMERA_ZOOMOUT 0x216 --#define KEY_CAMERA_UP 0x217 --#define KEY_CAMERA_DOWN 0x218 --#define KEY_CAMERA_LEFT 0x219 --#define KEY_CAMERA_RIGHT 0x21a -- --#define KEY_ATTENDANT_ON 0x21b --#define KEY_ATTENDANT_OFF 0x21c --#define KEY_ATTENDANT_TOGGLE 0x21d /* Attendant call on or off */ --#define KEY_LIGHTS_TOGGLE 0x21e /* Reading light on or off */ -- --#define BTN_DPAD_UP 0x220 --#define BTN_DPAD_DOWN 0x221 --#define BTN_DPAD_LEFT 0x222 --#define BTN_DPAD_RIGHT 0x223 -- --#define KEY_ALS_TOGGLE 0x230 /* Ambient light sensor */ --#define KEY_ROTATE_LOCK_TOGGLE 0x231 /* Display rotation lock */ -- --#define KEY_BUTTONCONFIG 0x240 /* AL Button Configuration */ --#define KEY_TASKMANAGER 0x241 /* AL Task/Project Manager */ --#define KEY_JOURNAL 0x242 /* AL Log/Journal/Timecard */ --#define KEY_CONTROLPANEL 0x243 /* AL Control Panel */ --#define KEY_APPSELECT 0x244 /* AL Select Task/Application */ --#define KEY_SCREENSAVER 0x245 /* AL Screen Saver */ --#define KEY_VOICECOMMAND 0x246 /* Listening Voice Command */ --#define KEY_ASSISTANT 0x247 /* AL Context-aware desktop assistant */ --#define KEY_KBD_LAYOUT_NEXT 0x248 /* AC Next Keyboard Layout Select */ -- --#define KEY_BRIGHTNESS_MIN 0x250 /* Set Brightness to Minimum */ --#define KEY_BRIGHTNESS_MAX 0x251 /* Set Brightness to Maximum */ -- --#define KEY_KBDINPUTASSIST_PREV 0x260 --#define KEY_KBDINPUTASSIST_NEXT 0x261 --#define KEY_KBDINPUTASSIST_PREVGROUP 0x262 --#define KEY_KBDINPUTASSIST_NEXTGROUP 0x263 --#define KEY_KBDINPUTASSIST_ACCEPT 0x264 --#define KEY_KBDINPUTASSIST_CANCEL 0x265 -- --/* Diagonal movement keys */ --#define KEY_RIGHT_UP 0x266 --#define KEY_RIGHT_DOWN 0x267 --#define KEY_LEFT_UP 0x268 --#define KEY_LEFT_DOWN 0x269 -- --#define KEY_ROOT_MENU 0x26a /* Show Device's Root Menu */ --/* Show Top Menu of the Media (e.g. DVD) */ --#define KEY_MEDIA_TOP_MENU 0x26b --#define KEY_NUMERIC_11 0x26c --#define KEY_NUMERIC_12 0x26d --/* -- * Toggle Audio Description: refers to an audio service that helps blind and -- * visually impaired consumers understand the action in a program. Note: in -- * some countries this is referred to as "Video Description". -- */ --#define KEY_AUDIO_DESC 0x26e --#define KEY_3D_MODE 0x26f --#define KEY_NEXT_FAVORITE 0x270 --#define KEY_STOP_RECORD 0x271 --#define KEY_PAUSE_RECORD 0x272 --#define KEY_VOD 0x273 /* Video on Demand */ --#define KEY_UNMUTE 0x274 --#define KEY_FASTREVERSE 0x275 --#define KEY_SLOWREVERSE 0x276 --/* -- * Control a data application associated with the currently viewed channel, -- * e.g. teletext or data broadcast application (MHEG, MHP, HbbTV, etc.) -- */ --#define KEY_DATA 0x277 --#define KEY_ONSCREEN_KEYBOARD 0x278 --/* Electronic privacy screen control */ --#define KEY_PRIVACY_SCREEN_TOGGLE 0x279 -- --/* Select an area of screen to be copied */ --#define KEY_SELECTIVE_SCREENSHOT 0x27a -- --/* -- * Some keyboards have keys which do not have a defined meaning, these keys -- * are intended to be programmed / bound to macros by the user. For most -- * keyboards with these macro-keys the key-sequence to inject, or action to -- * take, is all handled by software on the host side. So from the kernel's -- * point of view these are just normal keys. -- * -- * The KEY_MACRO# codes below are intended for such keys, which may be labeled -- * e.g. G1-G18, or S1 - S30. The KEY_MACRO# codes MUST NOT be used for keys -- * where the marking on the key does indicate a defined meaning / purpose. -- * -- * The KEY_MACRO# codes MUST also NOT be used as fallback for when no existing -- * KEY_FOO define matches the marking / purpose. In this case a new KEY_FOO -- * define MUST be added. -- */ --#define KEY_MACRO1 0x290 --#define KEY_MACRO2 0x291 --#define KEY_MACRO3 0x292 --#define KEY_MACRO4 0x293 --#define KEY_MACRO5 0x294 --#define KEY_MACRO6 0x295 --#define KEY_MACRO7 0x296 --#define KEY_MACRO8 0x297 --#define KEY_MACRO9 0x298 --#define KEY_MACRO10 0x299 --#define KEY_MACRO11 0x29a --#define KEY_MACRO12 0x29b --#define KEY_MACRO13 0x29c --#define KEY_MACRO14 0x29d --#define KEY_MACRO15 0x29e --#define KEY_MACRO16 0x29f --#define KEY_MACRO17 0x2a0 --#define KEY_MACRO18 0x2a1 --#define KEY_MACRO19 0x2a2 --#define KEY_MACRO20 0x2a3 --#define KEY_MACRO21 0x2a4 --#define KEY_MACRO22 0x2a5 --#define KEY_MACRO23 0x2a6 --#define KEY_MACRO24 0x2a7 --#define KEY_MACRO25 0x2a8 --#define KEY_MACRO26 0x2a9 --#define KEY_MACRO27 0x2aa --#define KEY_MACRO28 0x2ab --#define KEY_MACRO29 0x2ac --#define KEY_MACRO30 0x2ad -- --/* -- * Some keyboards with the macro-keys described above have some extra keys -- * for controlling the host-side software responsible for the macro handling: -- * -A macro recording start/stop key. Note that not all keyboards which emit -- * KEY_MACRO_RECORD_START will also emit KEY_MACRO_RECORD_STOP if -- * KEY_MACRO_RECORD_STOP is not advertised, then KEY_MACRO_RECORD_START -- * should be interpreted as a recording start/stop toggle; -- * -Keys for switching between different macro (pre)sets, either a key for -- * cycling through the configured presets or keys to directly select a preset. -- */ --#define KEY_MACRO_RECORD_START 0x2b0 --#define KEY_MACRO_RECORD_STOP 0x2b1 --#define KEY_MACRO_PRESET_CYCLE 0x2b2 --#define KEY_MACRO_PRESET1 0x2b3 --#define KEY_MACRO_PRESET2 0x2b4 --#define KEY_MACRO_PRESET3 0x2b5 -- --/* -- * Some keyboards have a buildin LCD panel where the contents are controlled -- * by the host. Often these have a number of keys directly below the LCD -- * intended for controlling a menu shown on the LCD. These keys often don't -- * have any labeling so we just name them KEY_KBD_LCD_MENU# -- */ --#define KEY_KBD_LCD_MENU1 0x2b8 --#define KEY_KBD_LCD_MENU2 0x2b9 --#define KEY_KBD_LCD_MENU3 0x2ba --#define KEY_KBD_LCD_MENU4 0x2bb --#define KEY_KBD_LCD_MENU5 0x2bc -- --#define BTN_TRIGGER_HAPPY 0x2c0 --#define BTN_TRIGGER_HAPPY1 0x2c0 --#define BTN_TRIGGER_HAPPY2 0x2c1 --#define BTN_TRIGGER_HAPPY3 0x2c2 --#define BTN_TRIGGER_HAPPY4 0x2c3 --#define BTN_TRIGGER_HAPPY5 0x2c4 --#define BTN_TRIGGER_HAPPY6 0x2c5 --#define BTN_TRIGGER_HAPPY7 0x2c6 --#define BTN_TRIGGER_HAPPY8 0x2c7 --#define BTN_TRIGGER_HAPPY9 0x2c8 --#define BTN_TRIGGER_HAPPY10 0x2c9 --#define BTN_TRIGGER_HAPPY11 0x2ca --#define BTN_TRIGGER_HAPPY12 0x2cb --#define BTN_TRIGGER_HAPPY13 0x2cc --#define BTN_TRIGGER_HAPPY14 0x2cd --#define BTN_TRIGGER_HAPPY15 0x2ce --#define BTN_TRIGGER_HAPPY16 0x2cf --#define BTN_TRIGGER_HAPPY17 0x2d0 --#define BTN_TRIGGER_HAPPY18 0x2d1 --#define BTN_TRIGGER_HAPPY19 0x2d2 --#define BTN_TRIGGER_HAPPY20 0x2d3 --#define BTN_TRIGGER_HAPPY21 0x2d4 --#define BTN_TRIGGER_HAPPY22 0x2d5 --#define BTN_TRIGGER_HAPPY23 0x2d6 --#define BTN_TRIGGER_HAPPY24 0x2d7 --#define BTN_TRIGGER_HAPPY25 0x2d8 --#define BTN_TRIGGER_HAPPY26 0x2d9 --#define BTN_TRIGGER_HAPPY27 0x2da --#define BTN_TRIGGER_HAPPY28 0x2db --#define BTN_TRIGGER_HAPPY29 0x2dc --#define BTN_TRIGGER_HAPPY30 0x2dd --#define BTN_TRIGGER_HAPPY31 0x2de --#define BTN_TRIGGER_HAPPY32 0x2df --#define BTN_TRIGGER_HAPPY33 0x2e0 --#define BTN_TRIGGER_HAPPY34 0x2e1 --#define BTN_TRIGGER_HAPPY35 0x2e2 --#define BTN_TRIGGER_HAPPY36 0x2e3 --#define BTN_TRIGGER_HAPPY37 0x2e4 --#define BTN_TRIGGER_HAPPY38 0x2e5 --#define BTN_TRIGGER_HAPPY39 0x2e6 --#define BTN_TRIGGER_HAPPY40 0x2e7 -- --/* We avoid low common keys in module aliases so they don't get huge. */ --#define KEY_MIN_INTERESTING KEY_MUTE --#define KEY_MAX 0x2ff --#define KEY_CNT (KEY_MAX+1) -- --/* -- * Relative axes -- */ -- --#define REL_X 0x00 --#define REL_Y 0x01 --#define REL_Z 0x02 --#define REL_RX 0x03 --#define REL_RY 0x04 --#define REL_RZ 0x05 --#define REL_HWHEEL 0x06 --#define REL_DIAL 0x07 --#define REL_WHEEL 0x08 --#define REL_MISC 0x09 --/* -- * 0x0a is reserved and should not be used in input drivers. -- * It was used by HID as REL_MISC+1 and userspace needs to detect if -- * the next REL_* event is correct or is just REL_MISC + n. -- * We define here REL_RESERVED so userspace can rely on it and detect -- * the situation described above. -- */ --#define REL_RESERVED 0x0a --#define REL_WHEEL_HI_RES 0x0b --#define REL_HWHEEL_HI_RES 0x0c --#define REL_MAX 0x0f --#define REL_CNT (REL_MAX+1) -- --/* -- * Absolute axes -- */ -- --#define ABS_X 0x00 --#define ABS_Y 0x01 --#define ABS_Z 0x02 --#define ABS_RX 0x03 --#define ABS_RY 0x04 --#define ABS_RZ 0x05 --#define ABS_THROTTLE 0x06 --#define ABS_RUDDER 0x07 --#define ABS_WHEEL 0x08 --#define ABS_GAS 0x09 --#define ABS_BRAKE 0x0a --#define ABS_HAT0X 0x10 --#define ABS_HAT0Y 0x11 --#define ABS_HAT1X 0x12 --#define ABS_HAT1Y 0x13 --#define ABS_HAT2X 0x14 --#define ABS_HAT2Y 0x15 --#define ABS_HAT3X 0x16 --#define ABS_HAT3Y 0x17 --#define ABS_PRESSURE 0x18 --#define ABS_DISTANCE 0x19 --#define ABS_TILT_X 0x1a --#define ABS_TILT_Y 0x1b --#define ABS_TOOL_WIDTH 0x1c -- --#define ABS_VOLUME 0x20 -- --#define ABS_MISC 0x28 -- --/* -- * 0x2e is reserved and should not be used in input drivers. -- * It was used by HID as ABS_MISC+6 and userspace needs to detect if -- * the next ABS_* event is correct or is just ABS_MISC + n. -- * We define here ABS_RESERVED so userspace can rely on it and detect -- * the situation described above. -- */ --#define ABS_RESERVED 0x2e -- --#define ABS_MT_SLOT 0x2f /* MT slot being modified */ --#define ABS_MT_TOUCH_MAJOR 0x30 /* Major axis of touching ellipse */ --#define ABS_MT_TOUCH_MINOR 0x31 /* Minor axis (omit if circular) */ --#define ABS_MT_WIDTH_MAJOR 0x32 /* Major axis of approaching ellipse */ --#define ABS_MT_WIDTH_MINOR 0x33 /* Minor axis (omit if circular) */ --#define ABS_MT_ORIENTATION 0x34 /* Ellipse orientation */ --#define ABS_MT_POSITION_X 0x35 /* Center X touch position */ --#define ABS_MT_POSITION_Y 0x36 /* Center Y touch position */ --#define ABS_MT_TOOL_TYPE 0x37 /* Type of touching device */ --#define ABS_MT_BLOB_ID 0x38 /* Group a set of packets as a blob */ --#define ABS_MT_TRACKING_ID 0x39 /* Unique ID of initiated contact */ --#define ABS_MT_PRESSURE 0x3a /* Pressure on contact area */ --#define ABS_MT_DISTANCE 0x3b /* Contact hover distance */ --#define ABS_MT_TOOL_X 0x3c /* Center X tool position */ --#define ABS_MT_TOOL_Y 0x3d /* Center Y tool position */ -- -- --#define ABS_MAX 0x3f --#define ABS_CNT (ABS_MAX+1) -- --/* -- * Switch events -- */ -- --#define SW_LID 0x00 /* set = lid shut */ --#define SW_TABLET_MODE 0x01 /* set = tablet mode */ --#define SW_HEADPHONE_INSERT 0x02 /* set = inserted */ --#define SW_RFKILL_ALL 0x03 /* rfkill master switch, type "any" -- set = radio enabled */ --#define SW_RADIO SW_RFKILL_ALL /* deprecated */ --#define SW_MICROPHONE_INSERT 0x04 /* set = inserted */ --#define SW_DOCK 0x05 /* set = plugged into dock */ --#define SW_LINEOUT_INSERT 0x06 /* set = inserted */ --#define SW_JACK_PHYSICAL_INSERT 0x07 /* set = mechanical switch set */ --#define SW_VIDEOOUT_INSERT 0x08 /* set = inserted */ --#define SW_CAMERA_LENS_COVER 0x09 /* set = lens covered */ --#define SW_KEYPAD_SLIDE 0x0a /* set = keypad slide out */ --#define SW_FRONT_PROXIMITY 0x0b /* set = front proximity sensor active */ --#define SW_ROTATE_LOCK 0x0c /* set = rotate locked/disabled */ --#define SW_LINEIN_INSERT 0x0d /* set = inserted */ --#define SW_MUTE_DEVICE 0x0e /* set = device disabled */ --#define SW_PEN_INSERTED 0x0f /* set = pen inserted */ --#define SW_MACHINE_COVER 0x10 /* set = cover closed */ --#define SW_MAX 0x10 --#define SW_CNT (SW_MAX+1) -- --/* -- * Misc events -- */ -- --#define MSC_SERIAL 0x00 --#define MSC_PULSELED 0x01 --#define MSC_GESTURE 0x02 --#define MSC_RAW 0x03 --#define MSC_SCAN 0x04 --#define MSC_TIMESTAMP 0x05 --#define MSC_MAX 0x07 --#define MSC_CNT (MSC_MAX+1) -- --/* -- * LEDs -- */ -- --#define LED_NUML 0x00 --#define LED_CAPSL 0x01 --#define LED_SCROLLL 0x02 --#define LED_COMPOSE 0x03 --#define LED_KANA 0x04 --#define LED_SLEEP 0x05 --#define LED_SUSPEND 0x06 --#define LED_MUTE 0x07 --#define LED_MISC 0x08 --#define LED_MAIL 0x09 --#define LED_CHARGING 0x0a --#define LED_MAX 0x0f --#define LED_CNT (LED_MAX+1) -- --/* -- * Autorepeat values -- */ -- --#define REP_DELAY 0x00 --#define REP_PERIOD 0x01 --#define REP_MAX 0x01 --#define REP_CNT (REP_MAX+1) -- --/* -- * Sounds -- */ -- --#define SND_CLICK 0x00 --#define SND_BELL 0x01 --#define SND_TONE 0x02 --#define SND_MAX 0x07 --#define SND_CNT (SND_MAX+1) -- --#endif -diff -Naur old/src/evdev-fallback.c new/src/evdev-fallback.c ---- old/src/evdev-fallback.c 2021-01-01 00:00:00.000000000 +0800 -+++ new/src/evdev-fallback.c 2021-01-01 00:00:00.000000000 +0800 -@@ -689,26 +689,9 @@ - - if (event->type != LIBINPUT_EVENT_KEYBOARD_KEY) - return; -- -- if (dispatch->lid.reliability == RELIABILITY_WRITE_OPEN) { -- int fd = libevdev_get_fd(dispatch->device->evdev); -- int rc; -- struct input_event ev[2]; -- -- ev[0] = input_event_init(0, EV_SW, SW_LID, 0); -- ev[1] = input_event_init(0, EV_SYN, SYN_REPORT, 0); -- -- rc = write(fd, ev, sizeof(ev)); -- -- if (rc < 0) -- evdev_log_error(dispatch->device, -- "failed to write SW_LID state (%s)", -- strerror(errno)); -- -- /* In case write() fails, we sync the lid state manually -- * regardless. */ -- } -- -+ -+ // hdf has no write fd operation. -+ - /* Posting the event here means we preempt the keyboard events that - * caused us to wake up, so the lid event is always passed on before - * the key event. -@@ -1031,6 +1014,9 @@ - if (dispatch->arbitration.in_arbitration) - return; - -+ libinput_log_printf("1.event divice_name:%s divice_fd:%d type:%d code:%d value:%d time:%llu curtime:%llu \r\n", -+ device->devname, device->fd, event->type, event->code, event->value, getTranTime(event), getMicrotime()); -+ - switch (event->type) { - case EV_REL: - fallback_process_relative(dispatch, device, event, time); -@@ -1575,7 +1561,7 @@ - Devices with ABS_MT_POSITION_* but not ABS_MT_SLOT - require mtdev for conversion. */ - if (evdev_need_mtdev(device)) { -- device->mtdev = mtdev_new_open(device->fd); -+ device->mtdev = mtdev_new_open_hdi(device->uhdf->index,device->uhdf->fn); - if (!device->mtdev) - return -1; - -diff -Naur old/src/evdev-fallback.h new/src/evdev-fallback.h ---- old/src/evdev-fallback.h 2021-01-01 00:00:00.000000000 +0800 -+++ new/src/evdev-fallback.h 2021-01-01 00:00:00.000000000 +0800 -@@ -169,6 +169,7 @@ - static inline enum key_type - get_key_type(uint16_t code) - { -+ const uint16_t KEY_ENDCALL = 0x2e8; - switch (code) { - case BTN_TOOL_PEN: - case BTN_TOOL_RUBBER: -@@ -198,6 +199,8 @@ - return KEY_TYPE_KEY; - if (code >= BTN_TRIGGER_HAPPY && code <= BTN_TRIGGER_HAPPY40) - return KEY_TYPE_BUTTON; -+ if (code == KEY_ENDCALL) -+ return KEY_TYPE_KEY; - return KEY_TYPE_NONE; - } - -diff -Naur old/src/evdev-joystick.c new/src/evdev-joystick.c ---- old/src/evdev-joystick.c 1970-01-01 08:00:00.000000000 +0800 -+++ new/src/evdev-joystick.c 2021-01-01 00:00:00.000000000 +0800 -@@ -0,0 +1,583 @@ -+/* -+ * 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 -+#include -+ -+#include "config.h" -+#include "libinput-version.h" -+#include "evdev-joystick.h" -+#include "input-event-codes.h" -+#include "libinput.h" -+#include "libinput-util.h" -+ -+static inline struct -+joystick_dispatch* get_joystick_dispatch(struct evdev_dispatch* dispatch) -+{ -+ if (dispatch == NULL) { -+ return NULL; -+ } -+ evdev_verify_dispatch_type(dispatch, DISPATCH_JOYSTICK); -+ -+ struct joystick_dispatch* joystick_dispatch = NULL; -+ joystick_dispatch = container_of(dispatch, struct joystick_dispatch, base); -+ -+ return joystick_dispatch; -+} -+ -+static int -+update_seat_joystick_button_count(struct libinput_seat* pSeat, int32_t key, uint32_t *pRetcount, enum libinput_key_state state) -+{ -+ if (pSeat == NULL || pRetcount == NULL || key < SYN_REPORT || key > KEY_MAX) { -+ return false; -+ } -+ -+ switch (state) { -+ case LIBINPUT_KEY_STATE_PRESSED: -+ { -+ *(pRetcount) = ++pSeat->button_count[key]; -+ } -+ break; -+ case LIBINPUT_KEY_STATE_RELEASED: -+ { -+ if (pSeat->button_count[key] == 0) { -+ *(pRetcount) = pSeat->button_count[key]; -+ } -+ else { -+ *(pRetcount) = --pSeat->button_count[key]; -+ } -+ } -+ break; -+ default: -+ *(pRetcount) = 0; -+ break; -+ } -+ return true; -+} -+ -+static void -+joystick_notify_axis(struct evdev_device* device, uint64_t time) -+{ -+ if (device == NULL) { -+ return; -+ } -+ -+ struct joystick_dispatch *joystick_dispatch = get_joystick_dispatch(device->dispatch); -+ if (joystick_dispatch == NULL) { -+ libinput_log_printf("joystick_dispatch is NULL.\n"); -+ return; -+ } -+ -+ struct libinput_event_joystick_axis* joystick_axis_event = zalloc(sizeof * joystick_axis_event); -+ if (joystick_axis_event == NULL) { -+ libinput_log_printf("pJoystickEvent is NULL.\n"); -+ return; -+ } -+ -+ *joystick_axis_event = (struct libinput_event_joystick_axis){ -+ .base.type = LIBINPUT_EVENT_POINTER_AXIS, -+ .base.device = &device->base, -+ .type = EV_ABS, -+ .time = time, -+ .axis_value_mask = joystick_dispatch->axis_value_mask, -+ .abs_throttle = joystick_dispatch->abs_throttle, -+ .abs_hat0x = joystick_dispatch->abs_hat0x, -+ .abs_hat0y = joystick_dispatch->abs_hat0y, -+ .abs_x = joystick_dispatch->abs_x, -+ .abs_y = joystick_dispatch->abs_y, -+ .abs_z = joystick_dispatch->abs_z, -+ .abs_rx = joystick_dispatch->abs_rx, -+ .abs_ry = joystick_dispatch->abs_ry, -+ .abs_rz = joystick_dispatch->abs_rz, -+ }; -+ -+ struct libinput_event_listener* listener = NULL; -+ struct libinput_event_listener* tmp_listener = NULL; -+ list_for_each_safe(listener, tmp_listener, &device->base.event_listeners, link) { -+ listener->notify_func(time, &joystick_axis_event->base, listener->notify_func_data); -+ } -+ -+ libinput_post_handle_event(device->base.seat->libinput, &joystick_axis_event->base); -+} -+ -+static void -+joystick_notify_key_event(struct evdev_device* device, struct input_event* pEvent, uint64_t time) -+{ -+ if (device == NULL || pEvent == NULL) { -+ return; -+ } -+ -+ struct libinput_event_joystick_button* pKeyEvent = {0}; -+ uint32_t uiSeatCount = 0; -+ -+ int iRet = update_seat_joystick_button_count(device->base.seat, pEvent->code, &uiSeatCount, pEvent->value); -+ if (iRet == false) { -+ return; -+ } -+ -+ pKeyEvent = zalloc(sizeof * pKeyEvent); -+ if (pKeyEvent == NULL) { -+ return; -+ } -+ -+ *pKeyEvent = (struct libinput_event_joystick_button) { -+ .base.type = LIBINPUT_EVENT_POINTER_BUTTON, -+ .base.device = &device->base, -+ .time = time, -+ .type = pEvent->type, -+ .key = pEvent->code, -+ .value = pEvent->value, -+ .seat_key_count = uiSeatCount, -+ .state = pEvent->value, -+ }; -+ -+ struct libinput_event_listener* listener = NULL; -+ struct libinput_event_listener* tmp_listener = NULL; -+ list_for_each_safe(listener, tmp_listener, &device->base.event_listeners, link) -+ { -+ listener->notify_func(time, &pKeyEvent->base, listener->notify_func_data); -+ } -+ -+ libinput_post_handle_event(device->base.seat->libinput, &pKeyEvent->base); -+} -+ -+static float -+abs_value_standardize(int32_t value, int32_t minimum, int32_t maximum, float standard_min, float standard_max) -+{ -+ return standard_min + ((float)value - (float)minimum) * ((float)(standard_max - standard_min)) / ((float)(maximum - minimum)); -+} -+ -+static float -+get_joystick_abs_standard_value(struct libinput_event_joystick_axis_abs_info *absinfo) -+{ -+ const int32_t value = absinfo->value; -+ const int32_t minimum = absinfo->minimum; -+ const int32_t maximum = absinfo->maximum; -+ if (minimum >= maximum) { -+ libinput_log_printf("joystick abs: minimum(%u) >= maximum(%u).\n", minimum, maximum); -+ return 0.f; -+ } else if (value < minimum || value > maximum) { -+ libinput_log_printf("joystick abs: value(%d) not between minimum(%u) and maximum(%u).\n", value, minimum, maximum); -+ return 0.f; -+ } -+ -+ const int32_t code = absinfo->code; -+ switch (code) { -+ case ABS_THROTTLE: -+ { -+ return abs_value_standardize(value, minimum, maximum, 0, 1.0); -+ } -+ case ABS_X: -+ case ABS_Y: -+ case ABS_Z: -+ case ABS_RX: -+ case ABS_RY: -+ case ABS_RZ: -+ { -+ return abs_value_standardize(value, minimum, maximum, -1.0, 1.0); -+ } -+ case ABS_HAT0X: -+ case ABS_HAT0Y: -+ { -+ return (float)value; -+ } -+ default: -+ return (float)value; -+ } -+} -+ -+static void joystick_set_axis_value_mask(struct joystick_dispatch *joystick_dispatch, enum libinput_joystick_axis_source axis) -+{ -+ joystick_dispatch->axis_value_mask |= (uint32_t)axis; -+} -+ -+static void joystick_reset_axis_value_mask(struct joystick_dispatch *joystick_dispatch) -+{ -+ joystick_dispatch->axis_value_mask = 0; -+} -+ -+static bool joystick_is_axis_value_mask(struct joystick_dispatch *joystick_dispatch) -+{ -+ return (joystick_dispatch->axis_value_mask != 0); -+} -+ -+static void joystick_get_one_abs_info(struct joystick_dispatch *joystick_dispatch, struct evdev_device *device, struct input_event *event, -+ const uint32_t code) -+{ -+ struct libinput_event_joystick_axis_abs_info *absinfo = NULL; -+ switch (code) { -+ case ABS_THROTTLE: -+ joystick_set_axis_value_mask(joystick_dispatch, LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_THROTTLE); -+ absinfo = &joystick_dispatch->abs_throttle; -+ break; -+ case ABS_HAT0X: -+ joystick_set_axis_value_mask(joystick_dispatch, LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_HAT0X); -+ absinfo = &joystick_dispatch->abs_hat0x; -+ break; -+ case ABS_HAT0Y: -+ joystick_set_axis_value_mask(joystick_dispatch, LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_HAT0Y); -+ absinfo = &joystick_dispatch->abs_hat0y; -+ break; -+ case ABS_X: -+ joystick_set_axis_value_mask(joystick_dispatch, LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_X); -+ absinfo = &joystick_dispatch->abs_x; -+ break; -+ case ABS_Y: -+ joystick_set_axis_value_mask(joystick_dispatch, LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_Y); -+ absinfo = &joystick_dispatch->abs_y; -+ break; -+ case ABS_Z: -+ joystick_set_axis_value_mask(joystick_dispatch, LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_Z); -+ absinfo = &joystick_dispatch->abs_z; -+ break; -+ case ABS_RX: -+ joystick_set_axis_value_mask(joystick_dispatch, LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_RX); -+ absinfo = &joystick_dispatch->abs_rx; -+ break; -+ case ABS_RY: -+ joystick_set_axis_value_mask(joystick_dispatch, LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_RY); -+ absinfo = &joystick_dispatch->abs_ry; -+ break; -+ case ABS_RZ: -+ joystick_set_axis_value_mask(joystick_dispatch, LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_RZ); -+ absinfo = &joystick_dispatch->abs_rz; -+ break; -+ default: -+ break; -+ } -+ -+ if (absinfo == NULL) { -+ libinput_log_printf("unsupported joystick abs event: divice_name:%s code:%d value:%d.\n", -+ device->devname, code, event->value); -+ return; -+ } -+ -+ struct libevdev *evdev = device->evdev; -+ evdev_device_check_abs_axis_range(device, event->code, event->value); -+ const struct input_absinfo *absinfo_raw = libevdev_get_abs_info(evdev, event->code); -+ absinfo->code = event->code; -+ absinfo->value = event->value; -+ absinfo->minimum = absinfo_raw->minimum; -+ absinfo->maximum = absinfo_raw->maximum; -+ absinfo->fuzz = absinfo_raw->fuzz; -+ absinfo->flat = absinfo_raw->flat; -+ absinfo->resolution = absinfo_raw->resolution; -+ absinfo->standardValue = get_joystick_abs_standard_value(absinfo); -+} -+ -+static void -+joystick_notify_absolute_event(struct joystick_dispatch* pJoystick, -+ struct evdev_device* device, struct input_event* event, uint64_t time) -+{ -+ if (pJoystick == NULL || device == NULL || event == NULL) { -+ return; -+ } -+ -+ joystick_get_one_abs_info(pJoystick, device, event, event->code); -+} -+ -+static void -+joystick_flush(struct joystick_dispatch* joystick_dispatch, struct evdev_device* device, uint64_t time) -+{ -+ if (joystick_dispatch == NULL || device == NULL) { -+ return; -+ } -+ -+ if (joystick_dispatch->axis_value_mask != 0) { -+ joystick_notify_axis(device, time); -+ joystick_reset_axis_value_mask(joystick_dispatch); -+ } -+} -+ -+static void -+joystick_process(struct evdev_dispatch* dispatch, struct evdev_device* device, -+ struct input_event* event, uint64_t time) -+{ -+ if (dispatch == NULL || device == NULL || event == NULL) { -+ return; -+ } -+ -+ struct joystick_dispatch* joystick_dispatch = get_joystick_dispatch(dispatch); -+ if (joystick_dispatch == NULL) { -+ return; -+ } -+ -+ libinput_log_printf("1.event divice_name:%s divice_fd:%d type:%d code:%d value:%d time:%llu curtime:%llu\r\n", -+ device->devname, device->fd, event->type, event->code, event->value, getTranTime(event), getMicrotime()); -+ -+ switch (event->type) { -+ case EV_ABS: { -+ joystick_notify_absolute_event(joystick_dispatch, device, event, time); -+ } -+ break; -+ case EV_KEY: { -+ joystick_notify_key_event(device, event, time); -+ } -+ break; -+ case EV_SYN: { -+ joystick_flush(joystick_dispatch, device, time); -+ } -+ break; -+ case EV_MSC: -+ /* ignore do not process */ -+ break; -+ case EV_REL: -+ case EV_SW: -+ case EV_LED: -+ case EV_SND: -+ case EV_REP: -+ case EV_FF: -+ case EV_PWR: -+ case EV_FF_STATUS: -+ case EV_MAX: -+ case EV_CNT: -+ default: -+ libinput_log_printf("unsupported joystick event type: %d, devname: %s.\n", event->type, device->devname); -+ break; -+ } -+} -+ -+static void joystick_suspend(struct evdev_dispatch* dispatch, struct evdev_device* device) -+{ -+ if (dispatch == NULL || device == NULL) { -+ return; -+ } -+ struct joystick_dispatch* joystick_dispatch = get_joystick_dispatch(dispatch); -+ if (joystick_dispatch == NULL) { -+ return; -+ } -+ joystick_flush(joystick_dispatch, device, 0); -+} -+ -+static void -+joystick_destroy(struct evdev_dispatch* dispatch) -+{ -+ if (dispatch == NULL) { -+ return; -+ } -+ struct joystick_dispatch* joystick_dispatch = get_joystick_dispatch(dispatch); -+ if (dispatch == NULL) { -+ return; -+ } -+ -+ free(joystick_dispatch); -+} -+ -+static void -+joystick_device_added(struct evdev_device* device, -+ struct evdev_device* added_device) -+{ -+ if (device == NULL || added_device == NULL) { -+ return; -+ } -+ struct joystick_dispatch* joystick_dispatch = get_joystick_dispatch(device->dispatch); -+ if (joystick_dispatch == NULL) { -+ return; -+ } -+ -+ bool is_joystick = false; -+ if (libinput_device_get_device_group(&device->base) != -+ libinput_device_get_device_group(&added_device->base)) { -+ return; -+ } -+ is_joystick = evdev_device_has_capability(added_device, -+ LIBINPUT_DEVICE_CAP_JOYSTICK); -+ -+ if (is_joystick) { -+ evdev_log_debug(device, -+ "joystick: activated for %s<->%s\n", -+ device->devname, -+ added_device->devname); -+ joystick_dispatch->device = added_device; -+ } -+} -+ -+static void -+joystick_device_removed(struct evdev_device* device, -+ struct evdev_device* removed_device) -+{ -+ if (device == NULL || removed_device == NULL) { -+ return; -+ } -+ struct joystick_dispatch* joystick_dispatch = get_joystick_dispatch(device->dispatch); -+ if (joystick_dispatch == NULL) { -+ return; -+ } -+ -+ if (joystick_dispatch->device == removed_device) { -+ joystick_dispatch->device = NULL; -+ } -+} -+ -+static struct evdev_dispatch_interface joystick_interface = { -+ .process = joystick_process, -+ .suspend = joystick_suspend, -+ .remove = NULL, -+ .destroy = joystick_destroy, -+ .device_added = joystick_device_added, -+ .device_removed = joystick_device_removed, -+ .device_suspended = NULL, -+ .device_resumed = NULL, -+ .post_added = NULL, -+ .touch_arbitration_toggle = NULL, -+ .touch_arbitration_update_rect = NULL, -+ .get_switch_state = NULL, -+}; -+ -+static enum libinput_config_status -+joystick_sendevents_set_mode(struct libinput_device* device, -+ enum libinput_config_send_events_mode mode) -+{ -+ if (device == NULL) { -+ return LIBINPUT_CONFIG_STATUS_INVALID; -+ } -+ -+ struct evdev_device* ev_device = evdev_device(device); -+ struct joystick_dispatch* joystick_dispatch = (struct joystick_dispatch*)ev_device->dispatch; -+ -+ if (ev_device == NULL || joystick_dispatch == NULL) { -+ return LIBINPUT_CONFIG_STATUS_INVALID; -+ } -+ -+ if (mode == joystick_dispatch->sendevents.current_mode) { -+ return LIBINPUT_CONFIG_STATUS_SUCCESS; -+ } -+ -+ switch (mode) { -+ case LIBINPUT_CONFIG_SEND_EVENTS_ENABLED: -+ break; -+ case LIBINPUT_CONFIG_SEND_EVENTS_DISABLED: -+ joystick_suspend(ev_device->dispatch, ev_device); -+ break; -+ default: -+ return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; -+ } -+ -+ joystick_dispatch->sendevents.current_mode = mode; -+ -+ return LIBINPUT_CONFIG_STATUS_SUCCESS; -+} -+ -+static uint32_t -+joystick_sendevents_get_modes(struct libinput_device* device) -+{ -+ return LIBINPUT_CONFIG_SEND_EVENTS_DISABLED; -+} -+ -+static enum libinput_config_send_events_mode -+joystick_sendevents_get_mode(struct libinput_device* device) -+{ -+ if (device == NULL) { -+ return LIBINPUT_CONFIG_SEND_EVENTS_DISABLED; -+ } -+ -+ struct evdev_device* ev_device = evdev_device(device); -+ struct joystick_dispatch* pDispatch = (struct joystick_dispatch*)ev_device->dispatch; -+ -+ if (ev_device == NULL || pDispatch == NULL) { -+ return LIBINPUT_CONFIG_SEND_EVENTS_DISABLED; -+ } -+ -+ return pDispatch->sendevents.current_mode; -+} -+ -+static enum libinput_config_send_events_mode -+joystick_sendevents_get_default_mode(struct libinput_device* device) -+{ -+ return LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; -+} -+ -+#ifdef _DEBUG -+void printf_joystick_absinfo(const char *abs_name, struct libinput_event_joystick_axis_abs_info *absinfo) -+{ -+ printf("%s: code: %d, value: %d, minimum: %d, maximum: %d, fuzz: %d, flat: %d, resolution: %d, standardValue: %f\n", -+ abs_name, -+ absinfo->code, -+ absinfo->value, -+ absinfo->minimum, -+ absinfo->maximum, -+ absinfo->fuzz, -+ absinfo->flat, -+ absinfo->resolution, -+ absinfo->standardValue -+ ); -+} -+ -+void print_libinput_event_joystick_axis(struct libinput_event_joystick_axis *p) -+{ -+ printf("JOYSTICK:\n" -+ "type: %d, device: %p, type: %d, time: 0x%x\n", -+ p->base.type, -+ p->base.device, -+ p->type, -+ p->time); -+ printf_joystick_absinfo("abs_throttle", &p->abs_throttle); -+ printf_joystick_absinfo("abs_hat0x", &p->abs_hat0x); -+ printf_joystick_absinfo("abs_hat0y", &p->abs_hat0y); -+ printf_joystick_absinfo("abs_x", &p->abs_x); -+ printf_joystick_absinfo("abs_y", &p->abs_y); -+ printf_joystick_absinfo("abs_z", &p->abs_z); -+ printf_joystick_absinfo("abs_rx", &p->abs_rx); -+ printf_joystick_absinfo("abs_ry", &p->abs_ry); -+ printf_joystick_absinfo("abs_rz", &p->abs_rz); -+} -+#endif // _DEBUG -+ -+/** -+ * @brief 初始化joystick_dispatch -+ * @param joystick -+ * @param device -+ * @return bool true - 成功, false - 失败 -+*/ -+bool -+joystick_init(struct joystick_dispatch* pJoystick, struct evdev_device* device) -+{ -+ if (pJoystick == NULL || device == NULL) { -+ return false; -+ } -+ -+ pJoystick->base.dispatch_type = DISPATCH_JOYSTICK; -+ pJoystick->base.interface = &joystick_interface; -+ pJoystick->device = device; -+ -+ return true; -+} -+ -+struct evdev_dispatch* -+evdev_joystick_create(struct evdev_device* device) -+{ -+ if (device == NULL) { -+ return NULL; -+ } -+ -+ struct joystick_dispatch* joystick = {0}; -+ joystick = zalloc(sizeof * joystick); -+ -+ if (joystick_init(joystick, device) != true) { -+ joystick_destroy(&joystick->base); -+ joystick = NULL; -+ return NULL; -+ } -+ -+ device->base.config.sendevents = &joystick->sendevents.config; -+ joystick->sendevents.current_mode = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; -+ joystick->sendevents.config.get_modes = joystick_sendevents_get_modes; -+ joystick->sendevents.config.set_mode = joystick_sendevents_set_mode; -+ joystick->sendevents.config.get_mode = joystick_sendevents_get_mode; -+ joystick->sendevents.config.get_default_mode = joystick_sendevents_get_default_mode; -+ -+ return &joystick->base; -+} -+ -diff -Naur old/src/evdev-joystick.h new/src/evdev-joystick.h ---- old/src/evdev-joystick.h 1970-01-01 08:00:00.000000000 +0800 -+++ new/src/evdev-joystick.h 2021-01-01 00:00:00.000000000 +0800 -@@ -0,0 +1,77 @@ -+/* -+ * 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 LIBINPUT_EVDEV_JOYSTICK_H -+#define LIBINPUT_EVDEV_JOYSTICK_H -+ -+#include "evdev.h" -+#include "libinput-private.h" -+ -+struct joystick_dispatch { -+ struct evdev_dispatch base; -+ struct evdev_device* device; -+ uint32_t axis_value_mask; -+ struct libinput_event_joystick_axis_abs_info abs_throttle; -+ struct libinput_event_joystick_axis_abs_info abs_hat0x; -+ struct libinput_event_joystick_axis_abs_info abs_hat0y; -+ struct libinput_event_joystick_axis_abs_info abs_x; -+ struct libinput_event_joystick_axis_abs_info abs_y; -+ struct libinput_event_joystick_axis_abs_info abs_z; -+ struct libinput_event_joystick_axis_abs_info abs_rx; -+ struct libinput_event_joystick_axis_abs_info abs_ry; -+ struct libinput_event_joystick_axis_abs_info abs_rz; -+ struct { -+ struct libinput_device_config_send_events config; -+ enum libinput_config_send_events_mode current_mode; -+ } sendevents; -+}; -+ -+struct libinput_event_joystick_button { -+ struct libinput_event base; -+ uint32_t type; -+ uint64_t time; -+ uint32_t key; -+ uint32_t seat_key_count; -+ enum libinput_key_state state; -+ int value; -+}; -+ -+struct libinput_event_joystick_axis { -+ struct libinput_event base; -+ uint32_t type; -+ uint64_t time; -+ uint32_t axis_value_mask; -+ struct libinput_event_joystick_axis_abs_info abs_throttle; -+ struct libinput_event_joystick_axis_abs_info abs_hat0x; -+ struct libinput_event_joystick_axis_abs_info abs_hat0y; -+ struct libinput_event_joystick_axis_abs_info abs_x; -+ struct libinput_event_joystick_axis_abs_info abs_y; -+ struct libinput_event_joystick_axis_abs_info abs_z; -+ struct libinput_event_joystick_axis_abs_info abs_rx; -+ struct libinput_event_joystick_axis_abs_info abs_ry; -+ struct libinput_event_joystick_axis_abs_info abs_rz; -+}; -+ -+#ifdef _DEBUG -+void print_libinput_event_joystick_axis(struct libinput_event_joystick_axis* p); -+#endif // _DEBUG -+ -+/** -+ * @brief 创建evdev_dispatch结构体 -+ * @param device -+ * @return struct evdev_dispatch* -+*/ -+struct evdev_dispatch* evdev_joystick_create(struct evdev_device* device); -+ -+#endif -diff -Naur old/src/evdev-mt-touchpad-gestures.c new/src/evdev-mt-touchpad-gestures.c ---- old/src/evdev-mt-touchpad-gestures.c 2021-01-01 00:00:00.000000000 +0800 -+++ new/src/evdev-mt-touchpad-gestures.c 2021-01-01 00:00:00.000000000 +0800 -@@ -80,6 +80,37 @@ - } - - static void -+tp_get_raw_touches(struct tp_dispatch *tp, struct sloted_coords_info *raw_touches) -+{ -+ struct tp_touch *t; -+ unsigned int i; -+ raw_touches->active_count = 0; -+ -+ if (tp->num_slots > MAX_SOLTED_COORDS_NUM) { -+ evdev_log_bug_libinput(tp->device, -+ "in %s, num_slots: %d, more than %d\n", -+ __func__, tp->num_slots, MAX_SOLTED_COORDS_NUM); -+ } -+ const unsigned int num_slots = (tp->num_slots > MAX_SOLTED_COORDS_NUM) ? MAX_SOLTED_COORDS_NUM : tp->num_slots; -+ -+ for (i = 0; i < num_slots; i++) { -+ t = &tp->touches[i]; -+ -+ if (!tp_touch_active_for_gesture(tp, t)) -+ continue; -+ -+ if (t->dirty) { -+ struct device_coords d; -+ d = tp_get_delta(t); -+ raw_touches->coords[i].x = d.x; -+ raw_touches->coords[i].y = d.y; -+ } -+ raw_touches->coords[i].is_active = true; -+ raw_touches->active_count++; -+ } -+} -+ -+static void - tp_gesture_init_scroll(struct tp_dispatch *tp) - { - struct phys_coords zero = {0.0, 0.0}; -@@ -131,7 +162,7 @@ - gesture_notify_swipe(&tp->device->base, time, - LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, - tp->gesture.finger_count, -- &zero, &zero); -+ &zero, &zero, NULL); - break; - } - -@@ -630,10 +661,12 @@ - tp_gesture_handle_state_swipe(struct tp_dispatch *tp, uint64_t time) - { - struct device_float_coords raw; -+ struct sloted_coords_info raw_touches = {}; - struct normalized_coords delta, unaccel; - - raw = tp_get_average_touches_delta(tp); - delta = tp_filter_motion(tp, &raw, time); -+ tp_get_raw_touches(tp, &raw_touches); - - if (!normalized_is_zero(delta) || !device_float_is_zero(raw)) { - unaccel = tp_normalize_delta(tp, raw); -@@ -641,7 +674,7 @@ - gesture_notify_swipe(&tp->device->base, time, - LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE, - tp->gesture.finger_count, -- &delta, &unaccel); -+ &delta, &unaccel, &raw_touches); - } - - return GESTURE_STATE_SWIPE; -diff -Naur old/src/evdev-mt-touchpad-thumb.c new/src/evdev-mt-touchpad-thumb.c ---- old/src/evdev-mt-touchpad-thumb.c 2021-01-01 00:00:00.000000000 +0800 -+++ new/src/evdev-mt-touchpad-thumb.c 2021-01-01 00:00:00.000000000 +0800 -@@ -418,7 +418,7 @@ - tp->thumb.lower_thumb_line = edges.y; - - quirks = evdev_libinput_context(device)->quirks; -- q = quirks_fetch_for_device(quirks, device->udev_device); -+ q = quirks_fetch_for_device(quirks, device->uhdf); - - if (libevdev_has_event_code(device->evdev, EV_ABS, ABS_MT_PRESSURE)) { - if (quirks_get_uint32(q, -diff -Naur old/src/evdev-mt-touchpad.c new/src/evdev-mt-touchpad.c ---- old/src/evdev-mt-touchpad.c 2021-01-01 00:00:00.000000000 +0800 -+++ new/src/evdev-mt-touchpad.c 2021-01-01 00:00:00.000000000 +0800 -@@ -1936,6 +1936,9 @@ - uint64_t time) - { - struct tp_dispatch *tp = tp_dispatch(dispatch); -+ -+ libinput_log_printf("1.event divice_name:%s divice_fd:%d type:%d code:%d value:%d time:%llu curtime:%llu\r\n", -+ device->devname, device->fd, e->type, e->code, e->value, getTranTime(e), getMicrotime()); - - switch (e->type) { - case EV_ABS: -@@ -2686,12 +2689,12 @@ - - static void - evdev_tag_touchpad(struct evdev_device *device, -- struct udev_device *udev_device) -+ struct uhdf *uhdf ) - { - int bustype, vendor; - const char *prop; - -- prop = udev_device_get_property_value(udev_device, -+ prop = uhdf_device_get_property_value(uhdf, - "ID_INPUT_TOUCHPAD_INTEGRATION"); - if (prop) { - if (streq(prop, "internal")) { -@@ -3197,7 +3200,7 @@ - int rc = false; - - quirks = evdev_libinput_context(device)->quirks; -- q = quirks_fetch_for_device(quirks, device->udev_device); -+ q = quirks_fetch_for_device(quirks, device->uhdf); - if (!q) - return false; - -@@ -3281,7 +3284,7 @@ - struct quirks *q; - - quirks = evdev_libinput_context(device)->quirks; -- q = quirks_fetch_for_device(quirks, device->udev_device); -+ q = quirks_fetch_for_device(quirks, device->uhdf); - if (!q) - return threshold; - -@@ -3317,7 +3320,7 @@ - uint32_t threshold; - - quirks = evdev_libinput_context(device)->quirks; -- q = quirks_fetch_for_device(quirks, device->udev_device); -+ q = quirks_fetch_for_device(quirks, device->uhdf); - if (!q) - return; - -@@ -3511,7 +3514,7 @@ - assert(abs); - - quirks = evdev_libinput_context(device)->quirks; -- q = quirks_fetch_for_device(quirks, device->udev_device); -+ q = quirks_fetch_for_device(quirks, device->uhdf); - if (q && quirks_get_range(q, QUIRK_ATTR_PRESSURE_RANGE, &r)) { - hi = r.upper; - lo = r.lower; -@@ -3567,7 +3570,7 @@ - } - - quirks = evdev_libinput_context(device)->quirks; -- q = quirks_fetch_for_device(quirks, device->udev_device); -+ q = quirks_fetch_for_device(quirks, device->uhdf); - if (q && quirks_get_range(q, QUIRK_ATTR_TOUCH_SIZE_RANGE, &r)) { - hi = r.upper; - lo = r.lower; -@@ -3839,7 +3842,7 @@ - { - struct tp_dispatch *tp; - -- evdev_tag_touchpad(device, device->udev_device); -+ evdev_tag_touchpad(device,device->uhdf); - - tp = zalloc(sizeof *tp); - -diff -Naur old/src/evdev-tablet-pad-leds.c new/src/evdev-tablet-pad-leds.c ---- old/src/evdev-tablet-pad-leds.c 2021-01-01 00:00:00.000000000 +0800 -+++ new/src/evdev-tablet-pad-leds.c 2021-01-01 00:00:00.000000000 +0800 -@@ -186,7 +186,7 @@ - static inline bool - is_litest_device(struct evdev_device *device) - { -- return !!udev_device_get_property_value(device->udev_device, -+ return !!uhdf_device_get_property_value(device->uhdf, - "LIBINPUT_TEST_DEVICE"); - } - -@@ -239,34 +239,7 @@ - char *path_out, - size_t path_out_sz) - { -- struct udev_device *parent, *udev_device; -- const char *test_path; -- int rc; -- -- udev_device = device->udev_device; -- -- /* For testing purposes only allow for a base path set through a -- * udev rule. We still expect the normal directory hierarchy inside */ -- test_path = udev_device_get_property_value(udev_device, -- "LIBINPUT_TEST_TABLET_PAD_SYSFS_PATH"); -- if (test_path) { -- rc = snprintf(path_out, path_out_sz, "%s", test_path); -- return rc != -1; -- } -- -- parent = udev_device_get_parent_with_subsystem_devtype(udev_device, -- "input", -- NULL); -- if (!parent) -- return false; -- -- rc = snprintf(path_out, -- path_out_sz, -- "%s/%s::wacom-", -- udev_device_get_syspath(parent), -- udev_device_get_sysname(parent)); -- -- return rc != -1; -+ return false; - } - - #if HAVE_LIBWACOM -diff -Naur old/src/evdev-tablet-pad.c new/src/evdev-tablet-pad.c ---- old/src/evdev-tablet-pad.c 2021-01-01 00:00:00.000000000 +0800 -+++ new/src/evdev-tablet-pad.c 2021-01-01 00:00:00.000000000 +0800 -@@ -482,6 +482,9 @@ - { - struct pad_dispatch *pad = pad_dispatch(dispatch); - -+ libinput_log_printf("1.event divice_name:%s divice_fd:%d type:%d code:%d value:%d time:%llu curtime:%llu\r\n", -+ device->devname, device->fd, e->type, e->code, e->value, getTranTime(e), getMicrotime()); -+ - switch (e->type) { - case EV_ABS: - pad_process_absolute(pad, device, e, time); -diff -Naur old/src/evdev-tablet.c new/src/evdev-tablet.c ---- old/src/evdev-tablet.c 2021-01-01 00:00:00.000000000 +0800 -+++ new/src/evdev-tablet.c 2021-01-01 00:00:00.000000000 +0800 -@@ -1089,7 +1089,7 @@ - goto out; - - quirks = evdev_libinput_context(device)->quirks; -- q = quirks_fetch_for_device(quirks, device->udev_device); -+ q = quirks_fetch_for_device(quirks, device->uhdf); - - tool->pressure_offset = pressure->minimum; - -diff -Naur old/src/evdev-totem.c new/src/evdev-totem.c ---- old/src/evdev-totem.c 2021-01-01 00:00:00.000000000 +0800 -+++ new/src/evdev-totem.c 2021-01-01 00:00:00.000000000 +0800 -@@ -520,6 +520,9 @@ - enum totem_slot_state global_state; - bool enable_touch; - -+ libinput_log_printf("1.event divice_name:%s divice_fd:%d type:%d code:%d value:%d time:%llu curtime:%llu\r\n", -+ device->devname, device->fd, e->type, e->code, e->value, getTranTime(e), getMicrotime()); -+ - switch(e->type) { - case EV_ABS: - totem_process_abs(totem, device, e, time); -diff -Naur old/src/evdev.c new/src/evdev.c ---- old/src/evdev.c 2021-01-01 00:00:00.000000000 +0800 -+++ new/src/evdev.c 2021-01-01 00:00:00.000000000 +0800 -@@ -38,7 +38,7 @@ - #include - #include - #include -- -+#include - #include "libinput.h" - #include "evdev.h" - #include "filter.h" -@@ -54,25 +54,7 @@ - #define DEFAULT_BUTTON_SCROLL_TIMEOUT ms2us(200) - #define MAX_RETRY_OPEN_DEVICE_COUNT 10 - --enum evdev_device_udev_tags { -- EVDEV_UDEV_TAG_INPUT = bit(0), -- EVDEV_UDEV_TAG_KEYBOARD = bit(1), -- EVDEV_UDEV_TAG_MOUSE = bit(2), -- EVDEV_UDEV_TAG_TOUCHPAD = bit(3), -- EVDEV_UDEV_TAG_TOUCHSCREEN = bit(4), -- EVDEV_UDEV_TAG_TABLET = bit(5), -- EVDEV_UDEV_TAG_JOYSTICK = bit(6), -- EVDEV_UDEV_TAG_ACCELEROMETER = bit(7), -- EVDEV_UDEV_TAG_TABLET_PAD = bit(8), -- EVDEV_UDEV_TAG_POINTINGSTICK = bit(9), -- EVDEV_UDEV_TAG_TRACKBALL = bit(10), -- EVDEV_UDEV_TAG_SWITCH = bit(11), --}; - --struct evdev_udev_tag_match { -- const char *name; -- enum evdev_device_udev_tags tag; --}; - - static const struct evdev_udev_tag_match evdev_udev_tag_matches[] = { - {"ID_INPUT", EVDEV_UDEV_TAG_INPUT}, -@@ -90,14 +72,20 @@ - {"ID_INPUT_SWITCH", EVDEV_UDEV_TAG_SWITCH}, - }; - -+const char * uhdf_device_get_property_value(struct uhdf *uhdf, -+ const char *key) -+{ -+ return NULL; -+} -+ - static inline bool - parse_udev_flag(struct evdev_device *device, -- struct udev_device *udev_device, -+ struct uhdf *uhdf, - const char *property) - { - const char *val; - -- val = udev_device_get_property_value(udev_device, property); -+ val = uhdf_device_get_property_value(uhdf, property); - if (!val) - return false; - -@@ -409,7 +397,7 @@ - - static void - evdev_tag_external_mouse(struct evdev_device *device, -- struct udev_device *udev_device) -+ struct uhdf *uhdf) - { - int bustype; - -@@ -420,7 +408,7 @@ - - static void - evdev_tag_trackpoint(struct evdev_device *device, -- struct udev_device *udev_device) -+ struct uhdf *uhdf) - { - struct quirks_context *quirks; - struct quirks *q; -@@ -428,13 +416,13 @@ - - if (!libevdev_has_property(device->evdev, - INPUT_PROP_POINTING_STICK) && -- !parse_udev_flag(device, udev_device, "ID_INPUT_POINTINGSTICK")) -+ !parse_udev_flag(device, uhdf, "ID_INPUT_POINTINGSTICK")) - return; - - device->tags |= EVDEV_TAG_TRACKPOINT; - - quirks = evdev_libinput_context(device)->quirks; -- q = quirks_fetch_for_device(quirks, device->udev_device); -+ q = quirks_fetch_for_device(quirks, device->uhdf); - if (q && quirks_get_string(q, QUIRK_ATTR_TRACKPOINT_INTEGRATION, &prop)) { - if (streq(prop, "internal")) { - /* noop, this is the default anyway */ -@@ -467,8 +455,7 @@ - } - - static void --evdev_tag_keyboard(struct evdev_device *device, -- struct udev_device *udev_device) -+evdev_tag_keyboard(struct evdev_device *device) - { - struct quirks_context *quirks; - struct quirks *q; -@@ -486,7 +473,7 @@ - } - - quirks = evdev_libinput_context(device)->quirks; -- q = quirks_fetch_for_device(quirks, device->udev_device); -+ q = quirks_fetch_for_device(quirks, device->uhdf); - if (q && quirks_get_string(q, QUIRK_ATTR_KEYBOARD_INTEGRATION, &prop)) { - if (streq(prop, "internal")) { - evdev_tag_keyboard_internal(device); -@@ -918,7 +905,7 @@ - char *prop; - - quirks = evdev_libinput_context(device)->quirks; -- q = quirks_fetch_for_device(quirks, device->udev_device); -+ q = quirks_fetch_for_device(quirks, device->uhdf); - if (!q || !quirks_get_string(q, QUIRK_ATTR_LID_SWITCH_RELIABILITY, &prop)) { - r = RELIABILITY_UNKNOWN; - } else if (!parse_switch_reliability_property(prop, &r)) { -@@ -1003,6 +990,24 @@ - } - } - -+void -+evdev_device_dispatch_two(struct evdev_device *device, -+ struct input_event *ev) -+{ -+ if (!device->mtdev) { -+ evdev_process_event(device, ev); -+ } else { -+ mtdev_put_event(device->mtdev, ev); -+ if (libevdev_event_is_code(ev, EV_SYN, SYN_REPORT)) { -+ while (!mtdev_empty(device->mtdev)) { -+ struct input_event e; -+ mtdev_get_event(device->mtdev, &e); -+ evdev_process_event(device, &e); -+ } -+ } -+ } -+} -+ - static int - evdev_sync_device(struct evdev_device *device) - { -@@ -1045,6 +1050,34 @@ - } - } - -+void -+evdev_device_hdfdispatch(void *data) -+{ -+ struct libinput *libinput = data; -+ int len; -+ int readcount = 0; -+ struct input_event event[256]; -+ int index = -1; -+ do { -+ len = read(libinput->pipes[0], event, sizeof(event)); -+ atomic_fetch_sub_explicit(&libinput->pipesbytes,len,memory_order_release); -+ if(len > 0 && len % sizeof(struct input_event) != 0) { -+ -+ return ; -+ } -+ if(len < 0){ -+ break; -+ } -+ for(unsigned int i = 0;i>8)&0xff; -+ event[i].type = event[i].type&0xff; -+ libevdev_set_event_value(libinput->device[index]->evdev, event[i].type,event[i].code,event[i].value); -+ evdev_device_dispatch_one(libinput->device[index], &event[i]); -+ } -+ readcount =atomic_load_explicit(&libinput->pipesbytes,__ATOMIC_SEQ_CST); -+ } while (readcount > 0); -+} -+ - static void - evdev_device_dispatch(void *data) - { -@@ -1238,7 +1271,7 @@ - int val; - - *angle = DEFAULT_WHEEL_CLICK_ANGLE; -- prop = udev_device_get_property_value(device->udev_device, prop); -+ prop = uhdf_device_get_property_value(device->uhdf, prop); - if (!prop) - return false; - -@@ -1263,7 +1296,7 @@ - { - int val; - -- prop = udev_device_get_property_value(device->udev_device, prop); -+ prop = uhdf_device_get_property_value(device->uhdf, prop); - if (!prop) - return false; - -@@ -1319,7 +1352,7 @@ - return 1.0; - - quirks = evdev_libinput_context(device)->quirks; -- q = quirks_fetch_for_device(quirks, device->udev_device); -+ q = quirks_fetch_for_device(quirks, device->uhdf); - if (q) { - quirks_get_double(q, QUIRK_ATTR_TRACKPOINT_MULTIPLIER, &multiplier); - quirks_unref(q); -@@ -1348,7 +1381,7 @@ - bool use_velocity_averaging = false; /* default off unless we have quirk */ - - quirks = evdev_libinput_context(device)->quirks; -- q = quirks_fetch_for_device(quirks, device->udev_device); -+ q = quirks_fetch_for_device(quirks, device->uhdf); - if (q) { - quirks_get_bool(q, - QUIRK_ATTR_USE_VELOCITY_AVERAGING, -@@ -1372,7 +1405,7 @@ - if (device->tags & EVDEV_TAG_TRACKPOINT) - return DEFAULT_MOUSE_DPI; - -- mouse_dpi = udev_device_get_property_value(device->udev_device, -+ mouse_dpi = uhdf_device_get_property_value(device->uhdf, - "MOUSE_DPI"); - if (mouse_dpi) { - dpi = parse_mouse_dpi_property(mouse_dpi); -@@ -1416,7 +1449,7 @@ - struct quirks *q; - - quirks = evdev_libinput_context(device)->quirks; -- q = quirks_fetch_for_device(quirks, device->udev_device); -+ q = quirks_fetch_for_device(quirks, device->uhdf); - - while (q && m->quirk) { - bool is_set; -@@ -1445,7 +1478,7 @@ - quirks_unref(q); - - if (parse_udev_flag(device, -- device->udev_device, -+ device->uhdf, - "ID_INPUT_TRACKBALL")) { - evdev_log_debug(device, "tagged as trackball\n"); - model_flags |= EVDEV_MODEL_TRACKBALL; -@@ -1457,13 +1490,13 @@ - * usage, so we need to keep this for backwards compat. - */ - if (parse_udev_flag(device, -- device->udev_device, -+ device->uhdf, - "LIBINPUT_MODEL_LENOVO_X220_TOUCHPAD_FW81")) { - evdev_log_debug(device, "tagged as trackball\n"); - model_flags |= EVDEV_MODEL_LENOVO_X220_TOUCHPAD_FW81; - } - -- if (parse_udev_flag(device, device->udev_device, -+ if (parse_udev_flag(device, device->uhdf, - "LIBINPUT_TEST_DEVICE")) { - evdev_log_debug(device, "is a test device\n"); - model_flags |= EVDEV_MODEL_TEST_DEVICE; -@@ -1483,7 +1516,7 @@ - bool rc = false; - - quirks = evdev_libinput_context(device)->quirks; -- q = quirks_fetch_for_device(quirks, device->udev_device); -+ q = quirks_fetch_for_device(quirks, device->uhdf); - if (!q) - return false; - -@@ -1509,7 +1542,7 @@ - bool rc = false; - - quirks = evdev_libinput_context(device)->quirks; -- q = quirks_fetch_for_device(quirks, device->udev_device); -+ q = quirks_fetch_for_device(quirks, device->uhdf); - if (!q) - return false; - -@@ -1572,21 +1605,17 @@ - - static enum evdev_device_udev_tags - evdev_device_get_udev_tags(struct evdev_device *device, -- struct udev_device *udev_device) -+ struct uhdf *uhdf) - { -+ - enum evdev_device_udev_tags tags = 0; -- int i; - -- for (i = 0; i < 2 && udev_device; i++) { -- unsigned j; -- for (j = 0; j < ARRAY_LENGTH(evdev_udev_tag_matches); j++) { -- const struct evdev_udev_tag_match match = evdev_udev_tag_matches[j]; -- if (parse_udev_flag(device, -- udev_device, -- match.name)) -- tags |= match.tag; -- } -- udev_device = udev_device_get_parent(udev_device); -+ unsigned j; -+ for (j = 0; j < ARRAY_LENGTH(evdev_udev_tag_matches); j++) { -+ const struct evdev_udev_tag_match match = evdev_udev_tag_matches[j]; -+ -+ if(uhdf->type & match.tag) -+ tags |= match.tag; - } - - return tags; -@@ -1778,13 +1807,18 @@ - enum evdev_device_udev_tags udev_tags; - unsigned int tablet_tags; - struct evdev_dispatch *dispatch; -+ -+ udev_tags = evdev_device_get_udev_tags(device, device->uhdf); -+ -+ device->model_flags = udev_tags; - -- udev_tags = evdev_device_get_udev_tags(device, device->udev_device); -+ libinput_log_printf("----evdev_configure_device tagged as supported input device---- %d \r\n", udev_tags); - - if ((udev_tags & EVDEV_UDEV_TAG_INPUT) == 0 || - (udev_tags & ~EVDEV_UDEV_TAG_INPUT) == 0) { - evdev_log_info(device, - "not tagged as supported input device\n"); -+ libinput_log_printf("----evdev_configure_device not tagged as supported input device---- \r\n"); - return NULL; - } - -@@ -1812,12 +1846,6 @@ - evdev_disable_accelerometer_axes(device); - } - -- if (udev_tags == (EVDEV_UDEV_TAG_INPUT|EVDEV_UDEV_TAG_JOYSTICK)) { -- evdev_log_info(device, -- "device is a joystick, ignoring\n"); -- return NULL; -- } -- - if (evdev_reject_device(device)) { - evdev_log_info(device, "was rejected\n"); - return NULL; -@@ -1833,8 +1861,16 @@ - udev_tags &= ~EVDEV_UDEV_TAG_TOUCHSCREEN; - } - -+ if (udev_tags & EVDEV_UDEV_TAG_JOYSTICK) { -+ libinput_log_printf("----evdev_configure_device--_LIBINPUT_JOYSTICK_BULID-- \r\n"); -+ dispatch = evdev_joystick_create(device); -+ device->seat_caps |= EVDEV_DEVICE_JOYSTICK; -+ return dispatch; -+ } -+ - if (evdev_device_has_model_quirk(device, - QUIRK_MODEL_DELL_CANVAS_TOTEM)) { -+ libinput_log_printf("----evdev_configure_device--_LIBINPUT_TOTEM_BULID-- \r\n"); - dispatch = evdev_totem_create(device); - device->seat_caps |= EVDEV_DEVICE_TABLET; - evdev_log_info(device, "device is a totem\n"); -@@ -1850,12 +1886,14 @@ - - /* libwacom assigns tablet _and_ tablet_pad to the pad devices */ - if (udev_tags & EVDEV_UDEV_TAG_TABLET_PAD) { -+ libinput_log_printf("----evdev_configure_device--_LIBINPUT_TABLET_PAD_BULID-- \r\n"); - dispatch = evdev_tablet_pad_create(device); - device->seat_caps |= EVDEV_DEVICE_TABLET_PAD; - evdev_log_info(device, "device is a tablet pad\n"); - return dispatch; - - } else if ((udev_tags & tablet_tags) == EVDEV_UDEV_TAG_TABLET) { -+ libinput_log_printf("----evdev_configure_device--_LIBINPUT_TABLET_BULID-- \r\n"); - dispatch = evdev_tablet_create(device); - device->seat_caps |= EVDEV_DEVICE_TABLET; - evdev_log_info(device, "device is a tablet\n"); -@@ -1863,6 +1901,7 @@ - } - - if (udev_tags & EVDEV_UDEV_TAG_TOUCHPAD) { -+ libinput_log_printf("----evdev_configure_device--_LIBINPUT_TOUCHPAD_BULID-- \r\n"); - if (udev_tags & EVDEV_UDEV_TAG_TABLET) - evdev_tag_tablet_touchpad(device); - /* whether velocity should be averaged, false by default */ -@@ -1874,8 +1913,8 @@ - - if (udev_tags & EVDEV_UDEV_TAG_MOUSE || - udev_tags & EVDEV_UDEV_TAG_POINTINGSTICK) { -- evdev_tag_external_mouse(device, device->udev_device); -- evdev_tag_trackpoint(device, device->udev_device); -+ evdev_tag_external_mouse(device, device->uhdf); -+ evdev_tag_trackpoint(device, device->uhdf); - device->dpi = evdev_read_dpi_prop(device); - device->trackpoint_multiplier = evdev_get_trackpoint_multiplier(device); - /* whether velocity should be averaged, false by default */ -@@ -1906,7 +1945,7 @@ - device->seat_caps |= EVDEV_DEVICE_POINTER; - } - -- evdev_tag_keyboard(device, device->udev_device); -+ evdev_tag_keyboard(device); - } - - if (udev_tags & EVDEV_UDEV_TAG_TOUCHSCREEN) { -@@ -1987,38 +2026,18 @@ - } - - static bool --evdev_device_have_same_syspath(struct udev_device *udev_device, int fd) -+evdev_device_have_same_syspath(struct uhdf *uhdf, int fd) - { -- struct udev *udev = udev_device_get_udev(udev_device); -- struct udev_device *udev_device_new = NULL; -- struct stat st; -- bool rc = false; -- -- if (fstat(fd, &st) < 0) -- goto out; -- -- udev_device_new = udev_device_new_from_devnum(udev, 'c', st.st_rdev); -- if (!udev_device_new) -- goto out; -- -- rc = streq(udev_device_get_syspath(udev_device_new), -- udev_device_get_syspath(udev_device)); --out: -- if (udev_device_new) -- udev_device_unref(udev_device_new); -- return rc; -+ return false; - } - - static bool - evdev_set_device_group(struct evdev_device *device, -- struct udev_device *udev_device) -+ struct uhdf *uhdf) - { - struct libinput *libinput = evdev_libinput_context(device); - struct libinput_device_group *group = NULL; -- const char *udev_group; -- -- udev_group = udev_device_get_property_value(udev_device, -- "LIBINPUT_DEVICE_GROUP"); -+ const char *udev_group = "LIBINPUT_DEVICE_GROUP"; - if (udev_group) - group = libinput_device_group_find_group(libinput, udev_group); - -@@ -2078,7 +2097,7 @@ - * unnecessary wakeups but on some devices we need to watch it for - * pointer jumps */ - quirks = evdev_libinput_context(device)->quirks; -- q = quirks_fetch_for_device(quirks, device->udev_device); -+ q = quirks_fetch_for_device(quirks, device->uhdf); - if (!q || - !quirks_get_string(q, QUIRK_ATTR_MSC_TIMESTAMP, &prop) || - !streq(prop, "watch")) { -@@ -2145,11 +2164,11 @@ - } - - static bool --udev_device_should_be_ignored(struct udev_device *udev_device) -+udev_device_should_be_ignored(struct uhdf *uhdf) - { - const char *value; - -- value = udev_device_get_property_value(udev_device, -+ value = uhdf_device_get_property_value(uhdf, - "LIBINPUT_IGNORE_DEVICE"); - - return value && !streq(value, "0"); -@@ -2157,73 +2176,38 @@ - - struct evdev_device * - evdev_device_create(struct libinput_seat *seat, -- struct udev_device *udev_device) -+ struct uhdf *uhdf) - { -+ char devname[256]={0}; - struct libinput *libinput = seat->libinput; - struct evdev_device *device = NULL; - int rc; -- int fd; - int unhandled_device = 0; -- const char *devnode = udev_device_get_devnode(udev_device); -- const char *sysname = udev_device_get_sysname(udev_device); -- -- if (!devnode) { -- log_info(libinput, "%s: no device node associated\n", sysname); -- return NULL; -- } -- -- if (udev_device_should_be_ignored(udev_device)) { -- log_debug(libinput, "%s: device is ignored\n", sysname); -- return NULL; -- } -- -- int loop_count = 0; -- loop_open_restricted: -- /* Use non-blocking mode so that we can loop on read on -- * evdev_device_data() until all events on the fd are -- * read. mtdev_get() also expects this. */ -- fd = open_restricted(libinput, devnode, -- O_RDWR | O_NONBLOCK | O_CLOEXEC); -- loop_count++; -- if (fd < 0) { -- log_info(libinput, -- "%s: opening input device '%s' failed (%s).\n", -- sysname, -- devnode, -- strerror(-fd)); -- if (loop_count < MAX_RETRY_OPEN_DEVICE_COUNT) { -- usleep(1 * 1000); -- goto loop_open_restricted; -- } -- return NULL; -- } -- -- if (!evdev_device_have_same_syspath(udev_device, fd)) -- goto err; - - device = zalloc(sizeof *device); - - libinput_device_init(&device->base, seat); - libinput_seat_ref(seat); - -- evdev_drain_fd(fd); -- -- rc = libevdev_new_from_fd(fd, &device->evdev); -+ rc = libevdev_new_from_index(uhdf->index, &device->evdev,uhdf->fn); - if (rc != 0) - goto err; -- -- libevdev_set_clock_id(device->evdev, CLOCK_MONOTONIC); -+ - libevdev_set_device_log_function(device->evdev, - libevdev_log_func, - LIBEVDEV_LOG_ERROR, - libinput); - device->seat_caps = 0; - device->is_mt = 0; -+ device->udev_device = NULL; - device->mtdev = NULL; -- device->udev_device = udev_device_ref(udev_device); -+ device->uhdf = uhdf; - device->dispatch = NULL; -- device->fd = fd; -- device->devname = libevdev_get_name(device->evdev); -+ device->fd = -1;//uhdf->index; -+ device->source = NULL; -+ device->output_name = NULL; -+ sprintf(devname,"HDI_%2d",uhdf->index); -+ device->devname = strdup(devname);//libevdev_get_name(device->evdev); - device->scroll.threshold = 5.0; /* Default may be overridden */ - device->scroll.direction_lock_threshold = 5.0; /* Default may be overridden */ - device->scroll.direction = 0; -@@ -2231,7 +2215,7 @@ - evdev_read_wheel_click_props(device); - device->model_flags = evdev_read_model_flags(device); - device->dpi = DEFAULT_MOUSE_DPI; -- -+ libinput->device[uhdf->index] = device; - /* at most 5 SYN_DROPPED log-messages per 30s */ - ratelimit_init(&device->syn_drop_limit, s2us(30), 5); - /* at most 5 "delayed processing" log messages per hour */ -@@ -2242,19 +2226,18 @@ - matrix_init_identity(&device->abs.calibration); - matrix_init_identity(&device->abs.usermatrix); - matrix_init_identity(&device->abs.default_calibration); -- -+ - evdev_pre_configure_model_quirks(device); -- -+ - device->dispatch = evdev_configure_device(device); - if (device->dispatch == NULL || device->seat_caps == 0) -- goto err; -- -- device->source = -- libinput_add_fd(libinput, fd, evdev_device_dispatch, device); -+ goto err; -+ -+ device->source = NULL; -+/* libinput_add_fd(libinput, libinput->pipes[0], evdev_device_hdfdispatch, libinput); - if (!device->source) -- goto err; -- -- if (!evdev_set_device_group(device, udev_device)) -+ goto err;*/ -+ if (!evdev_set_device_group(device, uhdf)) - goto err; - - list_insert(seat->devices_list.prev, &device->base.link); -@@ -2264,7 +2247,6 @@ - return device; - - err: -- close_restricted(libinput, fd); - if (device) { - unhandled_device = device->seat_caps == 0; - evdev_device_destroy(device); -@@ -2282,7 +2264,7 @@ - const char * - evdev_device_get_sysname(struct evdev_device *device) - { -- return udev_device_get_sysname(device->udev_device); -+ return "hdf_path"; - } - - const char * -@@ -2306,7 +2288,8 @@ - struct udev_device * - evdev_device_get_udev_device(struct evdev_device *device) - { -- return udev_device_ref(device->udev_device); -+ -+ return NULL; - } - - void -@@ -2387,7 +2370,7 @@ - const char *prop; - float calibration[6]; - -- prop = udev_device_get_property_value(device->udev_device, -+ prop = uhdf_device_get_property_value(device->uhdf, - "LIBINPUT_CALIBRATION_MATRIX"); - - if (prop == NULL) -@@ -2423,7 +2406,7 @@ - if (rc == -1) - return 0; - -- prop = udev_device_get_property_value(device->udev_device, name); -+ prop = uhdf_device_get_property_value(device->uhdf, name); - if (prop && (safe_atoi(prop, &fuzz) == false || fuzz < 0)) { - evdev_log_bug_libinput(device, - "invalid LIBINPUT_FUZZ property value: %s\n", -@@ -2476,6 +2459,9 @@ - return !!(device->seat_caps & EVDEV_DEVICE_TABLET_PAD); - case LIBINPUT_DEVICE_CAP_SWITCH: - return !!(device->seat_caps & EVDEV_DEVICE_SWITCH); -+ case LIBINPUT_DEVICE_CAP_JOYSTICK: -+ return !!(device->seat_caps & EVDEV_DEVICE_JOYSTICK); -+ - default: - return false; - } -@@ -2751,64 +2737,6 @@ - int - evdev_device_resume(struct evdev_device *device) - { -- struct libinput *libinput = evdev_libinput_context(device); -- int fd; -- const char *devnode; -- struct input_event ev; -- enum libevdev_read_status status; -- -- if (device->fd != -1) -- return 0; -- -- if (device->was_removed) -- return -ENODEV; -- -- devnode = udev_device_get_devnode(device->udev_device); -- if (!devnode) -- return -ENODEV; -- -- fd = open_restricted(libinput, devnode, -- O_RDWR | O_NONBLOCK | O_CLOEXEC); -- -- if (fd < 0) -- return -errno; -- -- if (!evdev_device_have_same_syspath(device->udev_device, fd)) { -- close_restricted(libinput, fd); -- return -ENODEV; -- } -- -- evdev_drain_fd(fd); -- -- device->fd = fd; -- -- if (evdev_need_mtdev(device)) { -- device->mtdev = mtdev_new_open(device->fd); -- if (!device->mtdev) -- return -ENODEV; -- } -- -- libevdev_change_fd(device->evdev, fd); -- libevdev_set_clock_id(device->evdev, CLOCK_MONOTONIC); -- -- /* re-sync libevdev's view of the device, but discard the actual -- events. Our device is in a neutral state already */ -- libevdev_next_event(device->evdev, -- LIBEVDEV_READ_FLAG_FORCE_SYNC, -- &ev); -- do { -- status = libevdev_next_event(device->evdev, -- LIBEVDEV_READ_FLAG_SYNC, -- &ev); -- } while (status == LIBEVDEV_READ_STATUS_SYNC); -- -- device->source = -- libinput_add_fd(libinput, fd, evdev_device_dispatch, device); -- if (!device->source) { -- mtdev_close_delete(device->mtdev); -- return -ENOMEM; -- } -- - evdev_notify_resumed_device(device); - - return 0; -@@ -2861,12 +2789,12 @@ - libinput_device_group_unref(device->base.group); - - free(device->output_name); -+ free((char*)device->devname); - filter_destroy(device->pointer.filter); - libinput_timer_destroy(&device->scroll.timer); - libinput_timer_destroy(&device->middlebutton.timer); - libinput_seat_unref(device->base.seat); - libevdev_free(device->evdev); -- udev_device_unref(device->udev_device); - free(device); - } - -diff -Naur old/src/evdev.h new/src/evdev.h ---- old/src/evdev.h 2021-01-01 00:00:00.000000000 +0800 -+++ new/src/evdev.h 2021-01-01 00:00:00.000000000 +0800 -@@ -61,6 +61,7 @@ - EVDEV_DEVICE_TABLET_PAD = bit(4), - EVDEV_DEVICE_GESTURE = bit(5), - EVDEV_DEVICE_SWITCH = bit(6), -+ EVDEV_DEVICE_JOYSTICK = bit(7), - }; - - enum evdev_device_tags { -@@ -76,6 +77,11 @@ - EVDEV_TAG_TABLET_TOUCHPAD = bit(9), - }; - -+struct evdev_udev_tag_match { -+ const char* name; -+ enum evdev_device_udev_tags tag; -+}; -+ - enum evdev_middlebutton_state { - MIDDLEBUTTON_IDLE, - MIDDLEBUTTON_LEFT_DOWN, -@@ -159,6 +165,8 @@ - ARBITRATION_IGNORE_RECT, - }; - -+struct uhdf; -+ - struct evdev_device { - struct libinput_device base; - -@@ -269,6 +277,7 @@ - uint32_t button_mask; - uint64_t first_event_time; - } middlebutton; -+ struct uhdf *uhdf; - }; - - static inline struct evdev_device * -@@ -353,6 +362,7 @@ - DISPATCH_TABLET, - DISPATCH_TABLET_PAD, - DISPATCH_TOTEM, -+ DISPATCH_JOYSTICK, - }; - - struct evdev_dispatch { -@@ -375,7 +385,7 @@ - - struct evdev_device * - evdev_device_create(struct libinput_seat *seat, -- struct udev_device *device); -+ struct uhdf *uhdf); - - static inline struct libinput * - evdev_libinput_context(const struct evdev_device *device) -@@ -386,19 +396,8 @@ - static inline bool - evdev_device_has_model_quirk(struct evdev_device *device, - enum quirk model_quirk) --{ -- struct quirks_context *quirks; -- struct quirks *q; -- bool result = false; -- -- assert(quirk_get_name(model_quirk) != NULL); -- -- quirks = evdev_libinput_context(device)->quirks; -- q = quirks_fetch_for_device(quirks, device->udev_device); -- quirks_get_bool(q, model_quirk, &result); -- quirks_unref(q); -- -- return result; -+{ -+ return model_quirk == (enum quirk)(device->uhdf->modeltype); - } - - void -@@ -430,6 +429,10 @@ - evdev_device_init_pointer_acceleration(struct evdev_device *device, - struct motion_filter *filter); - -+struct evdev_dispatch* -+evdev_joystick_create(struct evdev_device* device); -+ -+ - struct evdev_dispatch * - evdev_touchpad_create(struct evdev_device *device); - -@@ -481,6 +484,11 @@ - struct udev_device * - evdev_device_get_udev_device(struct evdev_device *device); - -+/** @brief 获取设备类型 */ -+enum evdev_device_udev_tags -+evdev_device_get_udev_device_tags(struct evdev_device* device); -+ -+ - void - evdev_device_set_default_calibration(struct evdev_device *device, - const float calibration[6]); -@@ -1005,7 +1013,8 @@ - "Axis %#x value %d is outside expected range [%d, %d]\n" - "See %sabsolute_coordinate_ranges.html for details\n", - code, value, min, max, -- HTTP_DOC_LINK); -+ ""); -+ //HTTP_DOC_LINK); - } - } - -@@ -1024,4 +1033,7 @@ - free(kbd); - } - -+const char * uhdf_device_get_property_value(struct uhdf *uhdf, -+ const char *key); -+ - #endif /* EVDEV_H */ -diff -Naur old/src/libinput-git-version.h new/src/libinput-git-version.h ---- old/src/libinput-git-version.h 1970-01-01 08:00:00.000000000 +0800 -+++ new/src/libinput-git-version.h 2021-01-01 00:00:00.000000000 +0800 -@@ -0,0 +1,3 @@ -+#pragma once -+ -+#define LIBINPUT_GIT_VERSION "@VCS_TAG@" -diff -Naur old/src/libinput-private.h new/src/libinput-private.h ---- old/src/libinput-private.h 2021-01-01 00:00:00.000000000 +0800 -+++ new/src/libinput-private.h 2021-01-01 00:00:00.000000000 +0800 -@@ -30,7 +30,7 @@ - #include - #include - #include -- -+#include - #if HAVE_LIBWACOM - #include - #endif -@@ -118,7 +118,7 @@ - int (*device_change_seat)(struct libinput_device *device, - const char *seat_name); - }; -- -+#define PIPE_NUM 64 - struct libinput { - int epoll_fd; - struct list source_destroy_list; -@@ -162,6 +162,14 @@ - size_t refcount; - } libwacom; - #endif -+ int pipes[2]; -+ atomic_int pipesbytes; -+ atomic_int pipesbytesbyindex[PIPE_NUM]; -+ bool pipesstatus[PIPE_NUM]; -+ struct evdev_device *device[PIPE_NUM]; -+ int devpipes[2]; -+ struct libinput_source *devsource; -+ struct libinput_source *eventsource; - }; - - typedef void (*libinput_seat_destroy_func) (struct libinput_seat *seat); -@@ -600,7 +608,8 @@ - enum libinput_event_type type, - int finger_count, - const struct normalized_coords *delta, -- const struct normalized_coords *unaccel); -+ const struct normalized_coords *unaccel, -+ const struct sloted_coords_info *raw_touches); - - void - gesture_notify_swipe_end(struct libinput_device *device, -@@ -867,5 +876,6 @@ - static inline void libinput_libwacom_unref(struct libinput *li) {} - #endif - -+struct libinput * uhdflibinput_unref(struct libinput *libinput); - - #endif /* LIBINPUT_PRIVATE_H */ -diff -Naur old/src/libinput-util.c new/src/libinput-util.c ---- old/src/libinput-util.c 1970-01-01 08:00:00.000000000 +0800 -+++ new/src/libinput-util.c 2021-01-01 00:00:00.000000000 +0800 -@@ -0,0 +1,102 @@ -+/* -+ * Copyright © 2008-2011 Kristian Høgsberg -+ * Copyright © 2011 Intel Corporation -+ * Copyright © 2013-2015 Red Hat, Inc. -+ * -+ * Permission is hereby granted, free of charge, to any person obtaining a -+ * copy of this software and associated documentation files (the "Software"), -+ * to deal in the Software without restriction, including without limitation -+ * the rights to use, copy, modify, merge, publish, distribute, sublicense, -+ * and/or sell copies of the Software, and to permit persons to whom the -+ * Software is furnished to do so, subject to the following conditions: -+ * -+ * The above copyright notice and this permission notice (including the next -+ * paragraph) shall be included in all copies or substantial portions of the -+ * Software. -+ * -+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -+ * DEALINGS IN THE SOFTWARE. -+ */ -+ -+/* -+ * This list data structure is verbatim copy from wayland-util.h from the -+ * Wayland project; except that wl_ prefix has been removed. -+ */ -+ -+#include "libinput-util.h" -+ -+#ifdef HAVE_LIBINPUT_LOG_ENABLE -+ -+static FILE* p_log_fp = NULL; -+ -+FILE *libinput_get_log_fp() -+{ -+ if (p_log_fp == NULL) { -+ const char *pLogDir = getenv("LIBINPUT_LOG_DIR"); -+ if (pLogDir == NULL) { -+ pLogDir = (char *)_LIBINPUT_LOG_DIR; -+ } -+ -+ const int r = mkdir(pLogDir, 0755); -+ if (r < 0 && errno != EEXIST) { -+ const int saved_errno = errno; -+ printf("could not create %s, errno: %d\n", pLogDir, saved_errno); -+ return NULL; -+ } -+ -+ const char *p_log_path = getenv("LIBINPUT_LOG_PATH"); -+ if (p_log_path == NULL) { -+ p_log_path = (char *)_LIBINPUT_LOG_PATH; -+ } -+ p_log_fp = fopen(p_log_path, "w+"); -+ } -+ -+ return p_log_fp; -+} -+ -+void libinput_log_printf(const char* fmt, ...) -+{ -+ p_log_fp = libinput_get_log_fp(); -+#ifdef HAVE_LIBINPUT_LOG_CONSOLE_ENABLE -+ char buf[1024] = {0}; -+ -+ va_list args; -+ va_start(args, fmt); -+ vsprintf(buf, fmt, args); -+ va_end(args); -+ buf[1024 - 1] = '\0'; -+ -+ printf("%s\n", buf); -+ -+ if (p_log_fp != NULL) { -+ fputs(buf, p_log_fp); -+ fflush(p_log_fp); -+ } -+#else -+ if (p_log_fp != NULL) { -+ va_list args; -+ va_start(args, fmt); -+ vfprintf(p_log_fp, fmt, args); -+ va_end(args); -+ fflush(p_log_fp); -+ } -+#endif -+} -+ -+uint64_t getMicrotime() -+{ -+ struct timeval currentTime; -+ gettimeofday(¤tTime, NULL); -+ return currentTime.tv_sec * 1000000 + currentTime.tv_usec; -+} -+ -+uint64_t getTranTime(struct input_event *event) -+{ -+ return event->input_event_sec * 1000000 + event->input_event_usec; -+} -+#endif -diff -Naur old/src/libinput-util.h new/src/libinput-util.h ---- old/src/libinput-util.h 2021-01-01 00:00:00.000000000 +0800 -+++ new/src/libinput-util.h 2021-01-01 00:00:00.000000000 +0800 -@@ -27,10 +27,9 @@ - - #include "config.h" - --#ifdef NDEBUG --#warning "libinput relies on assert(). #defining NDEBUG is not recommended" --#endif -- -+//#ifdef NDEBUG -+//#warning "libinput relies on assert(). #defining NDEBUG is not recommended" -+//#endif - - #include "libinput.h" - -@@ -57,6 +56,15 @@ - #define DEFAULT_MOUSE_DPI 1000 - #define DEFAULT_TRACKPOINT_SENSITIVITY 128 - -+ -+#ifdef HAVE_LIBINPUT_LOG_ENABLE -+void libinput_log_printf(const char* fmt, ...); -+uint64_t getMicrotime(); -+uint64_t getTranTime(struct input_event *event); -+#else -+#define libinput_log_printf(fmt, ...) -+#endif -+ - #define trace(...) \ - do { \ - printf("%s() - \033[0;31m", __func__); \ -diff -Naur old/src/libinput-version.h new/src/libinput-version.h ---- old/src/libinput-version.h 1970-01-01 08:00:00.000000000 +0800 -+++ new/src/libinput-version.h 2021-01-01 00:00:00.000000000 +0800 -@@ -0,0 +1,32 @@ -+/* -+ * Copyright © 2013 Jonas Ådahl -+ * -+ * Permission is hereby granted, free of charge, to any person obtaining a -+ * copy of this software and associated documentation files (the "Software"), -+ * to deal in the Software without restriction, including without limitation -+ * the rights to use, copy, modify, merge, publish, distribute, sublicense, -+ * and/or sell copies of the Software, and to permit persons to whom the -+ * Software is furnished to do so, subject to the following conditions: -+ * -+ * The above copyright notice and this permission notice (including the next -+ * paragraph) shall be included in all copies or substantial portions of the -+ * Software. -+ * -+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -+ * DEALINGS IN THE SOFTWARE. -+ */ -+ -+#ifndef LIBINPUT_VERSION_H -+#define LIBINPUT_VERSION_H -+ -+#define LIBINPUT_VERSION_MAJOR //@LIBINPUT_VERSION_MAJOR@ -+#define LIBINPUT_VERSION_MINOR //@LIBINPUT_VERSION_MINOR@ -+#define LIBINPUT_VERSION_MICRO //@LIBINPUT_VERSION_MICRO@ -+#define LIBINPUT_VERSION "@LIBINPUT_VERSION@" -+ -+#endif -diff -Naur old/src/libinput.c new/src/libinput.c ---- old/src/libinput.c 2021-01-01 00:00:00.000000000 +0800 -+++ new/src/libinput.c 2021-01-01 00:00:00.000000000 +0800 -@@ -33,12 +33,13 @@ - #include - #include - #include -- -+#include - #include "libinput.h" - #include "libinput-private.h" - #include "evdev.h" - #include "timer.h" - #include "quirks.h" -+#include "evdev-joystick.h" - - #define require_event_type(li_, type_, retval_, ...) \ - if (type_ == LIBINPUT_EVENT_NONE) abort(); \ -@@ -193,6 +194,7 @@ - int cancelled; - struct normalized_coords delta; - struct normalized_coords delta_unaccel; -+ struct sloted_coords_info solt_touches; - double scale; - double angle; - }; -@@ -1031,6 +1033,18 @@ - return event->angle; - } - -+LIBINPUT_EXPORT struct sloted_coords_info * -+libinput_event_gesture_get_solt_touches( -+ struct libinput_event_gesture *event) -+{ -+ require_event_type(libinput_event_get_context(&event->base), -+ event->base.type, -+ NULL, -+ LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE); -+ -+ return &event->solt_touches; -+} -+ - LIBINPUT_EXPORT int - libinput_event_tablet_tool_x_has_changed( - struct libinput_event_tablet_tool *event) -@@ -1757,7 +1771,122 @@ - source->fd = -1; - list_insert(&libinput->source_destroy_list, &source->link); - } -+extern void * -+libinput_load_module(const char *name, const char *entrypoint); -+typedef int (*HdfDevHandle)(int index,int cmd); -+static void -+evdev_dev_handler(void *data) -+{ -+ struct libinput *libinput = (struct libinput *)data; -+ int cmd[2]; -+ int len = sizeof(int); -+ static HdfDevHandle handle = NULL; -+ printf("libinput_add_fd epoll_fd =%d,fd=%d ,function addr = %p \n",libinput->epoll_fd,libinput->devpipes[0], evdev_dev_handler); -+ if( handle == NULL) { -+ handle = (HdfDevHandle)libinput_load_module("libmmi-server.z.so","HdfDevHandle"); -+ } -+ { -+ len = read(libinput->devpipes[0],cmd,sizeof(cmd)); -+ //printf("evdev_dev_handler cmd len =%d\n" ,len); -+ if(len >= 0 ) { -+ if(handle) { -+ handle(cmd[0],cmd[1]); -+ } -+ } -+ } -+ return; -+} -+void uhdflibinput_unpipe(struct libinput *libinput) -+{ -+ close(libinput->devpipes[0]); -+ close(libinput->devpipes[1]); -+ close(libinput->pipes[0]); -+ close(libinput->pipes[1]); -+} -+bool libinput_pipe(struct libinput *libinput) { -+ -+ -+ libinput->pipes[0]=-1; -+ libinput->pipes[1]=-1; -+ libinput->pipesbytes = 0; -+ if (0 != pipe(libinput->pipes)) { -+ return false; -+ } -+ if (fcntl(libinput->pipes[0], F_SETFL, O_NONBLOCK) == -1) { -+ return false; -+ } -+ if (fcntl(libinput->pipes[1], F_SETFL, O_NONBLOCK) == -1) { -+ return false; -+ } -+ libinput->devpipes[0]=-1; -+ libinput->devpipes[1]=-1; -+ if (0 != pipe(libinput->devpipes)) { -+ return false; -+ } -+ -+ -+ libinput->devsource = libinput_add_fd(libinput, -+ libinput->devpipes[0], -+ evdev_dev_handler, -+ libinput); -+ if (!libinput->devsource) { -+ return false; -+ } -+ -+ libinput->eventsource = -+ libinput_add_fd(libinput, libinput->pipes[0], evdev_device_hdfdispatch, libinput); -+ if (!libinput->eventsource) { -+ return false; -+ } -+ libinput->pipesbytes = 0 ; -+ return true; -+} -+ -+/** -+* Write in a pipe. -+*/ -+LIBINPUT_EXPORT int libinput_pipe_write(struct libinput *libinput, int index , const void *buf, int count) { -+ int readcount =atomic_load_explicit(&libinput->pipesbytes,__ATOMIC_SEQ_CST); -+ -+ if(readcount > 56*1024) { // more then 56k data will be discard -+ libinput->pipesstatus[index] = true; -+ } -+ if(readcount < 1024) {//less then 1k data will do translate -+ libinput->pipesstatus[index] = false; -+ } -+ if(!libinput->pipesstatus[index]) { -+ write(libinput->pipes[1], buf, count); -+ atomic_fetch_add_explicit(&libinput->pipesbytes, count, memory_order_release); -+ } -+ return count ; -+} - -+ -+LIBINPUT_EXPORT int libinput_get_pipe_bytes(struct libinput *libinput, int index) { -+ return libinput->pipesbytes; -+} -+ -+/** -+* Read in a pipe. -+*/ -+LIBINPUT_EXPORT int libinput_pipe_read(struct libinput *libinput, int index , void *buf, int count) { -+ return (int) read(libinput->pipes[0], buf, count); -+} -+ -+/** -+* Write in a pipe. -+*/ -+LIBINPUT_EXPORT int libinput_devpipe_write(struct libinput *libinput, void *buf, int count) { -+ return (int) write(libinput->devpipes[1], buf, count); -+} -+ -+/** -+* Read in a pipe. -+*/ -+LIBINPUT_EXPORT int libinput_devpipe_read(struct libinput *libinput,void *buf, int count) { -+ -+ return (int) read(libinput->devpipes[0], buf, count); -+} - int - libinput_init(struct libinput *libinput, - const struct libinput_interface *interface, -@@ -1770,7 +1899,11 @@ - libinput->epoll_fd = epoll_create1(EPOLL_CLOEXEC); - if (libinput->epoll_fd < 0) - return -1; -- -+ if (!libinput_pipe(libinput)) { -+ uhdflibinput_unpipe(libinput); -+ close(libinput->epoll_fd); -+ return -1; -+ } - libinput->events_len = 4; - libinput->events = zalloc(libinput->events_len * sizeof(*libinput->events)); - libinput->log_handler = libinput_default_log_func; -@@ -1806,11 +1939,8 @@ - /* If we fail, we'll fail next time too */ - libinput->quirks_initialized = true; - -- data_path = getenv("LIBINPUT_QUIRKS_DIR"); -- if (!data_path) { -- data_path = LIBINPUT_QUIRKS_DIR; -- override_file = LIBINPUT_QUIRKS_OVERRIDE_FILE; -- } -+ data_path = (char *)LIBINPUT_QUIRKS_DIR; -+ override_file = (char *)LIBINPUT_QUIRKS_OVERRIDE_FILE; - - quirks = quirks_init_subsystem(data_path, - override_file, -@@ -1856,10 +1986,9 @@ - return libinput; - } - --LIBINPUT_EXPORT struct libinput * --libinput_unref(struct libinput *libinput) -+struct libinput * uhdflibinput_unref(struct libinput *libinput) - { -- struct libinput_event *event; -+ struct libinput_event *event; - struct libinput_device *device, *next_device; - struct libinput_seat *seat, *next_seat; - struct libinput_tablet_tool *tool, *next_tool; -@@ -1873,10 +2002,6 @@ - if (libinput->refcount > 0) - return libinput; - -- libinput_suspend(libinput); -- -- libinput->interface_backend->destroy(libinput); -- - while ((event = libinput_get_event(libinput))) - libinput_event_destroy(event); - -@@ -1901,16 +2026,25 @@ - list_for_each_safe(tool, next_tool, &libinput->tool_list, link) { - libinput_tablet_tool_unref(tool); - } -- -+ libinput_remove_source(libinput,libinput->devsource); -+ libinput_remove_source(libinput,libinput->eventsource); -+ uhdflibinput_unpipe(libinput); - libinput_timer_subsys_destroy(libinput); - libinput_drop_destroyed_sources(libinput); -- quirks_context_unref(libinput->quirks); - close(libinput->epoll_fd); - free(libinput); - - return NULL; - } - -+LIBINPUT_EXPORT struct libinput * -+libinput_unref(struct libinput *libinput) -+{ -+ uhdflibinput_unref(libinput); -+ -+ return NULL; -+} -+ - static void - libinput_event_tablet_tool_destroy(struct libinput_event_tablet_tool *event) - { -@@ -2311,6 +2445,9 @@ - case LIBINPUT_DEVICE_CAP_SWITCH: - capability = "CAP_SWITCH"; - break; -+ case LIBINPUT_DEVICE_CAP_JOYSTICK: -+ capability = "CAP_JOYSTICK"; -+ break; - } - - log_bug_libinput(device->seat->libinput, -@@ -2814,6 +2951,7 @@ - int cancelled, - const struct normalized_coords *delta, - const struct normalized_coords *unaccel, -+ const struct sloted_coords_info *solt_touches, - double scale, - double angle) - { -@@ -2834,6 +2972,12 @@ - .angle = angle, - }; - -+ if (solt_touches != NULL) { -+ gesture_event->solt_touches = *solt_touches; -+ } else { -+ memset(&gesture_event->solt_touches, 0, sizeof(struct sloted_coords_info)); -+ } -+ - post_device_event(device, time, type, - &gesture_event->base); - } -@@ -2844,9 +2988,10 @@ - enum libinput_event_type type, - int finger_count, - const struct normalized_coords *delta, -- const struct normalized_coords *unaccel) -+ const struct normalized_coords *unaccel, -+ const struct sloted_coords_info *solt_touches) - { -- gesture_notify(device, time, type, finger_count, 0, delta, unaccel, -+ gesture_notify(device, time, type, finger_count, 0, delta, unaccel, solt_touches, - 0.0, 0.0); - } - -@@ -2859,7 +3004,7 @@ - const struct normalized_coords zero = { 0.0, 0.0 }; - - gesture_notify(device, time, LIBINPUT_EVENT_GESTURE_SWIPE_END, -- finger_count, cancelled, &zero, &zero, 0.0, 0.0); -+ finger_count, cancelled, &zero, &zero, NULL, 0.0, 0.0); - } - - void -@@ -2873,7 +3018,7 @@ - double angle) - { - gesture_notify(device, time, type, finger_count, 0, -- delta, unaccel, scale, angle); -+ delta, unaccel, NULL, scale, angle); - } - - void -@@ -2886,7 +3031,7 @@ - const struct normalized_coords zero = { 0.0, 0.0 }; - - gesture_notify(device, time, LIBINPUT_EVENT_GESTURE_PINCH_END, -- finger_count, cancelled, &zero, &zero, scale, 0.0); -+ finger_count, cancelled, &zero, &zero, NULL, scale, 0.0); - } - - void -@@ -2972,6 +3117,92 @@ - libinput->events_in = (libinput->events_in + 1) % libinput->events_len; - } - -+ -+LIBINPUT_EXPORT void -+libinput_post_handle_event(struct libinput* libinput, struct libinput_event* event) -+{ -+ libinput_post_event(libinput, event); -+} -+ -+LIBINPUT_EXPORT struct libinput_event_joystick_button* -+libinput_event_get_joystick_button_event(struct libinput_event* event) -+{ -+ require_event_type(libinput_event_get_context(event), -+ event->type, -+ NULL, -+ LIBINPUT_EVENT_POINTER_BUTTON); -+ -+ return (struct libinput_event_joystick_button*)event; -+} -+ -+LIBINPUT_EXPORT struct libinput_event_joystick_axis* -+libinput_event_get_joystick_axis_event(struct libinput_event* event) -+{ -+ require_event_type(libinput_event_get_context(event), -+ event->type, -+ NULL, -+ LIBINPUT_EVENT_POINTER_AXIS); -+ -+ return (struct libinput_event_joystick_axis*)event; -+} -+ -+/** -+ * @brief 获取joystick指定轴的数据是否变化 -+*/ -+bool libinput_event_get_joystick_axis_value_is_changed(struct libinput_event_joystick_axis *event, enum libinput_joystick_axis_source axis) -+{ -+ if (event == NULL) { -+ return 0; -+ } -+ -+ return (bool)(event->axis_value_mask & (uint32_t)axis); -+} -+ -+/** -+ * @brief 获取轴事件的时间 -+ */ -+uint64_t -+libinput_event_get_joystick_axis_time(struct libinput_event_joystick_axis *event) -+{ -+ if (event == NULL) { -+ return 0; -+ } -+ -+ return event->time; -+} -+ -+/** -+ * @brief 获取joystick指定轴的abs信息 -+*/ -+struct libinput_event_joystick_axis_abs_info * -+libinput_event_get_joystick_axis_abs_info(struct libinput_event_joystick_axis *event, enum libinput_joystick_axis_source axis) -+{ -+ switch (axis) { -+ case LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_X: -+ return &event->abs_x; -+ case LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_Y: -+ return &event->abs_y; -+ case LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_Z: -+ return &event->abs_z; -+ case LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_RX: -+ return &event->abs_rx; -+ case LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_RY: -+ return &event->abs_ry; -+ case LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_RZ: -+ return &event->abs_rz; -+ case LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_THROTTLE: -+ return &event->abs_throttle; -+ case LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_HAT0X: -+ return &event->abs_hat0x; -+ case LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_HAT0Y: -+ return &event->abs_hat0y; -+ default: -+ break; -+ } -+ -+ return NULL; -+} -+ - LIBINPUT_EXPORT struct libinput_event * - libinput_get_event(struct libinput *libinput) - { -@@ -3016,13 +3247,13 @@ - LIBINPUT_EXPORT int - libinput_resume(struct libinput *libinput) - { -- return libinput->interface_backend->resume(libinput); -+ return 0; - } - - LIBINPUT_EXPORT void - libinput_suspend(struct libinput *libinput) - { -- libinput->interface_backend->suspend(libinput); -+ - } - - LIBINPUT_EXPORT void -@@ -3055,12 +3286,37 @@ - return evdev_device_get_sysname((struct evdev_device *) device); - } - -+LIBINPUT_EXPORT const char* -+libinput_device_get_phys(struct libinput_device* device) -+{ -+ struct libevdev* evdev = ((struct evdev_device*)device)->evdev; -+ if (evdev == NULL) { -+ return NULL; -+ } -+ return libevdev_get_phys(evdev); -+} -+ - LIBINPUT_EXPORT const char * - libinput_device_get_name(struct libinput_device *device) - { - return evdev_device_get_name((struct evdev_device *) device); - } - -+LIBINPUT_EXPORT enum evdev_device_udev_tags -+libinput_device_get_tags(struct libinput_device* device) -+{ -+ if(device == NULL) -+ return EVDEV_UDEV_TAG_INPUT; -+ -+ struct evdev_device* evdevDevice = (struct evdev_device*)device; -+ enum evdev_device_udev_tags udev_tags; -+ -+ if (evdevDevice->udev_device) -+ return EVDEV_UDEV_TAG_INPUT; -+ -+ return udev_tags = (enum evdev_device_udev_tags)evdevDevice->model_flags; -+} -+ - LIBINPUT_EXPORT unsigned int - libinput_device_get_id_product(struct libinput_device *device) - { -@@ -3076,7 +3332,7 @@ - LIBINPUT_EXPORT const char * - libinput_device_get_output_name(struct libinput_device *device) - { -- return evdev_device_get_output((struct evdev_device *) device); -+ return NULL; - } - - LIBINPUT_EXPORT struct libinput_seat * -@@ -4378,3 +4634,93 @@ - } - } - #endif -+ -+LIBINPUT_EXPORT struct libinput_event_joystick_button* -+libinput_event_get_joystick_pointer_button_event(struct libinput_event* event) -+{ -+ if (!event) -+ return 0; -+ -+ require_event_type(libinput_event_get_context(event), -+ event->type, -+ NULL, -+ LIBINPUT_EVENT_POINTER_BUTTON); -+ -+ return (struct libinput_event_joystick_button*)event; -+} -+ -+LIBINPUT_EXPORT uint64_t -+libinput_event_joystick_button_time(struct libinput_event_joystick_button* event) -+{ -+ if (!event) -+ return 0; -+ -+ require_event_type(libinput_event_get_context(&event->base), -+ event->base.type, -+ 0, -+ LIBINPUT_EVENT_POINTER_BUTTON); -+ -+ return event->time; -+} -+ -+LIBINPUT_EXPORT uint32_t -+libinput_event_joystick_button_get_key(struct libinput_event_joystick_button* event) -+{ -+ if (!event) -+ return 0; -+ -+ require_event_type(libinput_event_get_context(&event->base), -+ event->base.type, -+ 0, -+ LIBINPUT_EVENT_POINTER_BUTTON); -+ -+ return event->key; -+} -+ -+LIBINPUT_EXPORT enum libinput_key_state -+libinput_event_joystick_button_get_key_state(struct libinput_event_joystick_button* event) -+{ -+ if (!event) -+ return 0; -+ -+ require_event_type(libinput_event_get_context(&event->base), -+ event->base.type, -+ 0, -+ LIBINPUT_EVENT_POINTER_BUTTON); -+ -+ return event->state; -+} -+ -+LIBINPUT_EXPORT uint32_t -+libinput_event_joystick_button_get_seat_key_count(struct libinput_event_joystick_button* event) -+{ -+ if (!event) -+ return 0; -+ -+ require_event_type(libinput_event_get_context(&event->base), -+ event->base.type, -+ 0, -+ LIBINPUT_EVENT_POINTER_BUTTON); -+ -+ return event->seat_key_count; -+} -+ -+LIBINPUT_EXPORT int -+libinput_event_joystick_button_get_value(struct libinput_event_joystick_button* event) -+{ -+ if (!event) -+ return 0; -+ -+ require_event_type(libinput_event_get_context(&event->base), -+ event->base.type, -+ 0, -+ LIBINPUT_EVENT_POINTER_BUTTON); -+ -+ return event->value; -+} -+ -+LIBINPUT_EXPORT double -+libinput_event_get_touch_pressure(struct libinput_event *event) -+{ -+ return 0.0F; -+} -diff -Naur old/src/libinput.h new/src/libinput.h ---- old/src/libinput.h 2021-01-01 00:00:00.000000000 +0800 -+++ new/src/libinput.h 2021-01-01 00:00:00.000000000 +0800 -@@ -33,6 +33,7 @@ - #include - #include - #include -+#include "util-bits.h" - - #define LIBINPUT_ATTRIBUTE_PRINTF(_format, _args) \ - __attribute__ ((format (printf, _format, _args))) -@@ -196,6 +197,22 @@ - LIBINPUT_DEVICE_CAP_TABLET_PAD = 4, - LIBINPUT_DEVICE_CAP_GESTURE = 5, - LIBINPUT_DEVICE_CAP_SWITCH = 6, -+ LIBINPUT_DEVICE_CAP_JOYSTICK = 7, -+}; -+ -+enum evdev_device_udev_tags { -+ EVDEV_UDEV_TAG_INPUT = bit(0), -+ EVDEV_UDEV_TAG_KEYBOARD = bit(1), -+ EVDEV_UDEV_TAG_MOUSE = bit(2), -+ EVDEV_UDEV_TAG_TOUCHPAD = bit(3), -+ EVDEV_UDEV_TAG_TOUCHSCREEN = bit(4), -+ EVDEV_UDEV_TAG_TABLET = bit(5), -+ EVDEV_UDEV_TAG_JOYSTICK = bit(6), -+ EVDEV_UDEV_TAG_ACCELEROMETER = bit(7), -+ EVDEV_UDEV_TAG_TABLET_PAD = bit(8), -+ EVDEV_UDEV_TAG_POINTINGSTICK = bit(9), -+ EVDEV_UDEV_TAG_TRACKBALL = bit(10), -+ EVDEV_UDEV_TAG_SWITCH = bit(11), - }; - - /** -@@ -315,6 +332,49 @@ - }; - - /** -+ * @ingroup event_joystick -+ * -+ * The source for a @ref LIBINPUT_EVENT_POINTER_AXIS event. See -+ * libinput_event_get_joystick_axis_event() for details. -+ * -+ * @since 1.16.4 -+ */ -+enum libinput_joystick_axis_source { -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_UNKNOW = 0, -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_X = bit(0), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_Y = bit(1), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_Z = bit(2), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_RX = bit(3), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_RY = bit(4), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_RZ = bit(5), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_THROTTLE = bit(6), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_RUDDER = bit(7), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_WHEEL = bit(8), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_GAS = bit(9), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_BRAKE = bit(10), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_HAT0X = bit(11), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_HAT0Y = bit(12), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_HAT1X = bit(13), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_HAT1Y = bit(14), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_HAT2X = bit(15), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_HAT2Y = bit(16), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_HAT3X = bit(17), -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_HAT3Y = bit(18), -+}; -+ -+#define MAX_SOLTED_COORDS_NUM 10 -+struct sloted_coords { -+ bool is_active; -+ float x; -+ float y; -+}; -+ -+struct sloted_coords_info { -+ struct sloted_coords coords[MAX_SOLTED_COORDS_NUM]; -+ unsigned int active_count; -+}; -+ -+/** - * @ingroup device - * - * Available tool types for a device with the @ref -@@ -387,6 +447,17 @@ - LIBINPUT_TABLET_TOOL_TIP_DOWN = 1, - }; - -+struct libinput_event_joystick_axis_abs_info { -+ int32_t code; -+ int32_t value; -+ int32_t minimum; -+ int32_t maximum; -+ int32_t fuzz; -+ int32_t flat; -+ int32_t resolution; -+ float standardValue; -+}; -+ - /** - * @defgroup tablet_pad_modes Tablet pad modes - * -@@ -1893,6 +1964,12 @@ - libinput_event_gesture_get_angle_delta(struct libinput_event_gesture *event); - - /** -+ * 获取带slot的touches信息, 仅支持LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE -+ */ -+struct sloted_coords_info * -+libinput_event_gesture_get_solt_touches(struct libinput_event_gesture *event); -+ -+/** - * @defgroup event_tablet Tablet events - * - * Events that come from tools on tablet devices. For events from the pad, -@@ -3466,6 +3543,46 @@ - int - libinput_dispatch(struct libinput *libinput); - -+/**************************************************************************** -+* @brief : brief -+* @author : fms -+* @date : 2021/3/8 20:55 -+* @version : ver 1.0 -+* @inparam :libinput event -+* @outparam : -+*****************************************************************************/ -+void -+libinput_post_handle_event(struct libinput* libinput, -+ struct libinput_event* event); -+ -+/**************************************************************************** -+* @brief : get joystick button event -+* @author : fms -+* @date : 2021/3/12 10:56 -+* @version : ver 1.0 -+* @inparam : -+* @outparam : -+*****************************************************************************/ -+struct libinput_event_joystick_axis * -+libinput_event_get_joystick_axis_event(struct libinput_event *event); -+ -+/** -+ * @brief 获取轴事件的时间 -+ */ -+uint64_t -+libinput_event_get_joystick_axis_time(struct libinput_event_joystick_axis *event); -+ -+/** -+ * @brief 获取joystick指定轴的数据是否变化 -+*/ -+bool libinput_event_get_joystick_axis_value_is_changed(struct libinput_event_joystick_axis *event, enum libinput_joystick_axis_source axis); -+ -+/** -+ * @brief 获取joystick指定轴的abs信息 -+*/ -+struct libinput_event_joystick_axis_abs_info * -+libinput_event_get_joystick_axis_abs_info(struct libinput_event_joystick_axis *event, enum libinput_joystick_axis_source axis); -+ - /** - * @ingroup base - * -@@ -3936,6 +4053,10 @@ - const char * - libinput_device_get_name(struct libinput_device *device); - -+/** @brief 获取设备类型*/ -+enum evdev_device_udev_tags -+libinput_device_get_tags(struct libinput_device* device); -+ - /** - * @ingroup device - * -@@ -5928,7 +6049,96 @@ - unsigned int - libinput_device_config_rotation_get_default_angle(struct libinput_device *device); - -+struct uhdf; -+ -+int uhdfdevice_added(struct libinput *input,struct uhdf *uhdf,const char *seat_name); -+ -+struct libinput * libinput_hdf_create_context(const struct libinput_interface *interface,void *user_data); -+ -+void uhdfdevice_removed(struct uhdf *uhdf); -+ -+struct evdev_device; -+struct input_event; -+void evdev_device_dispatch_two(struct evdev_device *device, -+ struct input_event *ev); -+ -+/** -+ * @ingroup event -+ * -+ * Get the struct libinput_event_joystick_button from the event. -+ * -+ * @param event The libinput event -+ * @return The libinput_event_joystick_button for this event. -+ */ -+struct libinput_event_joystick_button* -+libinput_event_get_joystick_pointer_button_event(struct libinput_event* event); -+ -+/** -+ * @ingroup event -+ * -+ * Get the time from the event. -+ * -+ * @param event The libinput_event_joystick_button -+ * @return The time for this event. -+ */ -+uint64_t libinput_event_joystick_button_time(struct libinput_event_joystick_button* event); -+ -+/** -+ * @ingroup event -+ * -+ * Get the key value from the event. -+ * -+ * @param event The libinput_event_joystick_button -+ * @return The key value for this event. -+ */ -+uint32_t libinput_event_joystick_button_get_key(struct libinput_event_joystick_button* event); -+ -+/** -+ * @ingroup event -+ * -+ * Get the seat key count from the event. -+ * -+ * @param event The libinput_event_joystick_button -+ * @return The seat key count for this event. -+ */ -+uint32_t libinput_event_joystick_button_get_seat_key_count(struct libinput_event_joystick_button* event); -+ -+/** -+ * @ingroup event -+ * -+ * Get the value count from the event. -+ * -+ * @param event The libinput_event_joystick_button -+ * @return The value for this event. -+ */ -+int libinput_event_joystick_button_get_value(struct libinput_event_joystick_button* event); -+ -+/** -+ * @ingroup config -+ * -+ * Get the pressure of the touch screen -+ * -+ * @param Carried libinput event -+ * @return Pressure value of touch screen -+ * -+ * @since 1.4 -+ */ -+double -+libinput_event_get_touch_pressure(struct libinput_event* event); -+ -+const char* -+libinput_device_get_phys(struct libinput_device* device);bool libinput_pipe(struct libinput *libinput); -+bool libinput_pipe(struct libinput *libinput); -+int libinput_pipe_write(struct libinput *libinput, int index,const void *buf, int count); -+int libinput_pipe_read(struct libinput *libinput, int index,void *buf, int count); -+int libinput_devpipe_write(struct libinput *libinput,void *buf, int count); -+int libinput_devpipe_read(struct libinput *libinput, void *buf, int count); -+int libinput_get_pipe_bytes(struct libinput *libinput, int index); -+void evdev_device_hdfdispatch(void *data); -+enum libinput_key_state -+libinput_event_joystick_button_get_key_state(struct libinput_event_joystick_button* event); - #ifdef __cplusplus - } - #endif - #endif /* LIBINPUT_H */ -+ -diff -Naur old/src/path-seat.c new/src/path-seat.c ---- old/src/path-seat.c 2021-01-01 00:00:00.000000000 +0800 -+++ new/src/path-seat.c 2021-01-01 00:00:00.000000000 +0800 -@@ -176,42 +176,7 @@ - struct udev_device *udev_device, - const char *seat_logical_name_override) - { -- struct path_seat *seat; -- struct evdev_device *device = NULL; -- const char *output_name; -- const char *devnode, *sysname; -- -- devnode = udev_device_get_devnode(udev_device); -- sysname = udev_device_get_sysname(udev_device); -- -- seat = path_seat_get_for_device(input, udev_device, seat_logical_name_override); -- if (!seat) -- goto out; -- -- device = evdev_device_create(&seat->base, udev_device); -- libinput_seat_unref(&seat->base); -- -- if (device == EVDEV_UNHANDLED_DEVICE) { -- device = NULL; -- log_info(&input->base, -- "%-7s - not using input device '%s'.\n", -- sysname, -- devnode); -- goto out; -- } else if (device == NULL) { -- log_info(&input->base, -- "%-7s - failed to create input device '%s'.\n", -- sysname, -- devnode); -- goto out; -- } -- -- evdev_read_calibration_prop(device); -- output_name = udev_device_get_property_value(udev_device, "WL_OUTPUT"); -- device->output_name = safe_strdup(output_name); -- --out: -- return device ? &device->base : NULL; -+ return NULL; - } - - static int -@@ -277,19 +242,7 @@ - path_device_change_seat(struct libinput_device *device, - const char *seat_name) - { -- struct libinput *libinput = device->seat->libinput; -- struct evdev_device *evdev = evdev_device(device); -- struct udev_device *udev_device = NULL; -- int rc = -1; -- -- udev_device = evdev->udev_device; -- udev_device_ref(udev_device); -- libinput_path_remove_device(device); -- -- if (path_create_device(libinput, udev_device, seat_name) != NULL) -- rc = 0; -- udev_device_unref(udev_device); -- return rc; -+ return -1; - } - - static const struct libinput_interface_backend interface_backend = { -@@ -404,26 +357,5 @@ - LIBINPUT_EXPORT void - libinput_path_remove_device(struct libinput_device *device) - { -- struct libinput *libinput = device->seat->libinput; -- struct path_input *input = (struct path_input*)libinput; -- struct libinput_seat *seat; -- struct evdev_device *evdev = evdev_device(device); -- struct path_device *dev; -- -- if (libinput->interface_backend != &interface_backend) { -- log_bug_client(libinput, "Mismatching backends.\n"); -- return; -- } -- -- list_for_each(dev, &input->path_list, link) { -- if (dev->udev_device == evdev->udev_device) { -- path_device_destroy(dev); -- break; -- } -- } -- -- seat = device->seat; -- libinput_seat_ref(seat); -- path_disable_device(libinput, evdev); -- libinput_seat_unref(seat); -+ // hdf no need - } -diff -Naur old/src/quirks.c new/src/quirks.c ---- old/src/quirks.c 2021-01-01 00:00:00.000000000 +0800 -+++ new/src/quirks.c 2021-01-01 00:00:00.000000000 +0800 -@@ -1382,36 +1382,9 @@ - - struct quirks * - quirks_fetch_for_device(struct quirks_context *ctx, -- struct udev_device *udev_device) -+ struct uhdf *uhdf) - { -- struct quirks *q = NULL; -- struct section *s; -- struct match *m; -- -- if (!ctx) -- return NULL; -- -- qlog_debug(ctx, "%s: fetching quirks\n", -- udev_device_get_devnode(udev_device)); -- -- q = quirks_new(); -- -- m = match_new(udev_device, ctx->dmi, ctx->dt); -- -- list_for_each(s, &ctx->sections, link) { -- quirk_match_section(ctx, q, s, m, udev_device); -- } -- -- match_free(m); -- -- if (q->nproperties == 0) { -- quirks_unref(q); -- return NULL; -- } -- -- list_insert(&ctx->quirks, &q->link); -- -- return q; -+ return uhdf->quirkpop; - } - - -diff -Naur old/src/quirks.h new/src/quirks.h ---- old/src/quirks.h 2021-01-01 00:00:00.000000000 +0800 -+++ new/src/quirks.h 2021-01-01 00:00:00.000000000 +0800 -@@ -31,6 +31,7 @@ - #include - - #include "libinput.h" -+#include "udev-seat.h" - - /** - * Handle to the quirks context. -@@ -189,7 +190,7 @@ - */ - struct quirks * - quirks_fetch_for_device(struct quirks_context *ctx, -- struct udev_device *device); -+ struct uhdf *uhdf); - - /** - * Reduce the refcount by one. When the refcount reaches zero, the -diff -Naur old/src/udev-seat.c new/src/udev-seat.c ---- old/src/udev-seat.c 2021-01-01 00:00:00.000000000 +0800 -+++ new/src/udev-seat.c 2021-01-01 00:00:00.000000000 +0800 -@@ -27,10 +27,17 @@ - #include - #include - #include -- -+#include - #include "evdev.h" - #include "udev-seat.h" - -+#ifdef __aarch64__ -+#define LIB_MODULEDIR "/system/lib64" -+#define MODULEDIR "/system/lib64" -+#else -+#define LIB_MODULEDIR "/system/lib" -+#define MODULEDIR "/system/lib" -+#endif - static const char default_seat[] = "seat0"; - static const char default_seat_name[] = "default"; - -@@ -40,6 +47,86 @@ - const char *seat_name); - static struct udev_seat * - udev_seat_get_named(struct udev_input *input, const char *seat_name); -+size_t -+module_path_from_env(const char *name, char *path, size_t path_len) -+{ -+ const char *mapping = getenv("WESTON_MODULE_MAP"); -+ const char *end; -+ const int name_len = strlen(name); -+ -+ if (!mapping) -+ return 0; -+ -+ end = mapping + strlen(mapping); -+ while (mapping < end && *mapping) { -+ const char *filename, *next; -+ -+ /* early out: impossibly short string */ -+ if (end - mapping < name_len + 1) -+ return 0; -+ -+ filename = &mapping[name_len + 1]; -+ next = strchrnul(mapping, ';'); -+ -+ if (strncmp(mapping, name, name_len) == 0 && -+ mapping[name_len] == '=') { -+ size_t file_len = next - filename; /* no trailing NUL */ -+ if (file_len >= path_len) -+ return 0; -+ strncpy(path, filename, file_len); -+ path[file_len] = '\0'; -+ return file_len; -+ } -+ -+ mapping = next + 1; -+ } -+ -+ return 0; -+} -+ -+void * -+libinput_load_module(const char *name, const char *entrypoint) -+{ -+ char path[PATH_MAX]; -+ void *module, *init; -+ size_t len; -+ -+ if (name == NULL) -+ return NULL; -+ if (name[0] != '/') { -+ len = module_path_from_env(name, path, sizeof path); -+ if (len == 0) -+ len = snprintf(path, sizeof path, "%s/%s", -+ LIB_MODULEDIR, name); -+ } else { -+ len = snprintf(path, sizeof path, "%s", name); -+ } -+ len = snprintf(path, sizeof path, "%s", name); -+ /* snprintf returns the length of the string it would've written, -+ * _excluding_ the NUL byte. So even being equal to the size of -+ * our buffer is an error here. */ -+ if (len >= sizeof path) -+ return NULL; -+ -+ module = dlopen(path, RTLD_NOW | RTLD_NOLOAD); -+ if (module) { -+ libinput_log_printf("Module '%s' already loaded\n", path); -+ } else { -+ libinput_log_printf("Loading module '%s'\n", path); -+ module = dlopen(path, RTLD_NOW); -+ if (!module) { -+ libinput_log_printf("Failed to load module: %s\n", dlerror()); -+ return NULL; -+ } -+ } -+ -+ init = dlsym(module, entrypoint); -+ if (!init) { -+ return NULL; -+ } -+ -+ return init; -+} - - - static inline bool -@@ -78,90 +165,12 @@ - struct udev_input *input, - const char *seat_name) - { -- struct evdev_device *device; -- const char *devnode, *sysname; -- const char *device_seat, *output_name; -- struct udev_seat *seat; -- -- device_seat = udev_device_get_property_value(udev_device, "ID_SEAT"); -- if (!device_seat) -- device_seat = default_seat; -- -- if (!streq(device_seat, input->seat_id)) -- return 0; -- -- if (ignore_litest_test_suite_device(udev_device)) -- return 0; -- -- devnode = udev_device_get_devnode(udev_device); -- sysname = udev_device_get_sysname(udev_device); -- -- /* Search for matching logical seat */ -- if (!seat_name) -- seat_name = udev_device_get_property_value(udev_device, "WL_SEAT"); -- if (!seat_name) -- seat_name = default_seat_name; -- -- seat = udev_seat_get_named(input, seat_name); -- -- /* There is a race at startup: a device added between setting -- * up the udev monitor and enumerating all current devices may show -- * up in both lists. Filter those out. -- */ -- if (filter_duplicates(seat, udev_device)) -- return 0; -- -- if (seat) -- libinput_seat_ref(&seat->base); -- else { -- seat = udev_seat_create(input, device_seat, seat_name); -- if (!seat) -- return -1; -- } -- -- device = evdev_device_create(&seat->base, udev_device); -- libinput_seat_unref(&seat->base); -- -- if (device == EVDEV_UNHANDLED_DEVICE) { -- log_info(&input->base, -- "%-7s - not using input device '%s'\n", -- sysname, -- devnode); -- return 0; -- } else if (device == NULL) { -- log_info(&input->base, -- "%-7s - failed to create input device '%s'\n", -- sysname, -- devnode); -- return 0; -- } -- -- evdev_read_calibration_prop(device); -- -- output_name = udev_device_get_property_value(udev_device, "WL_OUTPUT"); -- device->output_name = safe_strdup(output_name); -- - return 0; - } - - static void - device_removed(struct udev_device *udev_device, struct udev_input *input) - { -- struct evdev_device *device, *next; -- struct udev_seat *seat; -- const char *syspath; -- -- syspath = udev_device_get_syspath(udev_device); -- list_for_each(seat, &input->base.seat_list, base.link) { -- list_for_each_safe(device, next, -- &seat->base.devices_list, base.link) { -- if (streq(syspath, -- udev_device_get_syspath(device->udev_device))) { -- evdev_device_remove(device); -- break; -- } -- } -- } - } - - static int -@@ -368,55 +377,36 @@ - udev_device_change_seat(struct libinput_device *device, - const char *seat_name) - { -- struct libinput *libinput = device->seat->libinput; -- struct udev_input *input = (struct udev_input *)libinput; -- struct evdev_device *evdev = evdev_device(device); -- struct udev_device *udev_device = evdev->udev_device; -- int rc; -- -- udev_device_ref(udev_device); -- device_removed(udev_device, input); -- rc = device_added(udev_device, input, seat_name); -- udev_device_unref(udev_device); -- -- return rc; -+ return 0; - } -- -+#if 0 - static const struct libinput_interface_backend interface_backend = { - .resume = udev_input_enable, - .suspend = udev_input_disable, - .destroy = udev_input_destroy, - .device_change_seat = udev_device_change_seat, - }; -- -+#endif -+typedef struct libinput * (*HdfAdfInit)(); - LIBINPUT_EXPORT struct libinput * - libinput_udev_create_context(const struct libinput_interface *interface, - void *user_data, - struct udev *udev) - { -- struct udev_input *input; -- -- if (!interface || !udev) -- return NULL; -- -- input = zalloc(sizeof *input); -- -- if (libinput_init(&input->base, interface, -- &interface_backend, user_data) != 0) { -- libinput_unref(&input->base); -- free(input); -- return NULL; -- } -- -- input->udev = udev_ref(udev); -- -- return &input->base; -+ HdfAdfInit init = (HdfAdfInit)libinput_load_module("libmmi-server.z.so","HdfAdfInit"); -+ if(init == NULL) { -+ return NULL; -+ } -+ struct libinput * plibinput = init(); -+ libinput_set_user_data(plibinput,user_data); -+ return plibinput; - } - - LIBINPUT_EXPORT int - libinput_udev_assign_seat(struct libinput *libinput, - const char *seat_id) - { -+#if 0 - struct udev_input *input = (struct udev_input*)libinput; - - if (!seat_id) -@@ -447,6 +437,109 @@ - - if (udev_input_enable(&input->base) < 0) - return -1; -- -+#endif - return 0; - } -+ -+// change libinput for hdf frame -+static const struct libinput_interface_backend simplyinterface_backend = { -+ .resume = NULL, -+ .suspend = NULL, -+ .destroy = NULL, -+ .device_change_seat = NULL, -+}; -+ -+static struct udev_seat * -+uhdf_seat_get_named(struct uhdf_input *input, const char *seat_name) -+{ -+ struct udev_seat *seat; -+ -+ list_for_each(seat, &input->base.seat_list, base.link) { -+ if (streq(seat->base.logical_name, seat_name)) -+ return seat; -+ } -+ -+ return NULL; -+} -+ -+static struct udev_seat * -+uhdf_seat_create(struct uhdf_input *input, -+ const char *device_seat, -+ const char *seat_name) -+{ -+ struct udev_seat *seat; -+ -+ seat = zalloc(sizeof *seat); -+ -+ libinput_seat_init(&seat->base, &input->base, -+ device_seat, seat_name, -+ udev_seat_destroy); -+ -+ return seat; -+} -+ -+struct libinput * -+libinput_hdf_create_context(const struct libinput_interface *interface, -+ void *user_data) -+{ -+ struct uhdf_input *input; -+ input = zalloc(sizeof *input); -+ -+ if (libinput_init(&input->base, interface, -+ &simplyinterface_backend, user_data) != 0) { -+ free(input); -+ return NULL; -+ } -+ -+ return &input->base; -+} -+ -+void uhdfdevice_removed(struct uhdf *uhdf) -+{ -+ evdev_device_remove(uhdf->device); -+} -+ -+int -+uhdfdevice_added(struct libinput *libinput, -+ struct uhdf *uhdf, -+ const char *seat_name) -+{ -+ struct uhdf_input *input =(struct uhdf_input *)libinput; -+ struct udev_seat *seat; -+ struct evdev_device *device; -+ const char *device_seat; -+ device_seat = default_seat; -+ -+ if (!seat_name) -+ seat_name = default_seat_name; -+ -+ seat = uhdf_seat_get_named(input, seat_name); -+ -+ if (seat) -+ libinput_seat_ref(&seat->base); -+ else { -+ seat = uhdf_seat_create(input, device_seat, seat_name); -+ if (!seat) -+ return -1; -+ } -+ -+ device = evdev_device_create(&seat->base, uhdf); -+ libinput_seat_unref(&seat->base); -+ -+ if (device == EVDEV_UNHANDLED_DEVICE) { -+ log_info(&input->base, -+ "- not using input device \n"); -+ return 0; -+ } else if (device == NULL) { -+ log_info(&input->base, -+ " - failed to create input device\n"); -+ return 0; -+ } -+ -+ uhdf->device = device; -+ libinput->pipesbytesbyindex[uhdf->index] = 0; -+ libinput->pipesstatus[uhdf->index] = false ; -+ evdev_read_calibration_prop(device); -+ -+ return 0; -+} -diff -Naur old/src/udev-seat.h new/src/udev-seat.h ---- old/src/udev-seat.h 2021-01-01 00:00:00.000000000 +0800 -+++ new/src/udev-seat.h 2021-01-01 00:00:00.000000000 +0800 -@@ -41,4 +41,23 @@ - char *seat_id; - }; - -+struct quirks; -+struct uhdf -+{ -+ int index; -+ int type; -+ int modeltype; -+ int prop; -+ struct quirks *quirkpop; -+ int nproperties; -+ int (*fn)(int index,int code, void * iobuff); -+ struct evdev_device *device; -+ void * deviceinfo; -+}; -+ -+struct uhdf_input { -+ struct libinput base; -+ char *seat_id; -+}; -+ - #endif -diff -Naur old/src/util-strings.h new/src/util-strings.h ---- old/src/util-strings.h 2021-01-01 00:00:00.000000000 +0800 -+++ new/src/util-strings.h 2021-01-01 00:00:00.000000000 +0800 -@@ -281,7 +281,7 @@ - if (npairs == 0) - goto error; - -- result = zalloc(npairs * sizeof *result); -+ result = (struct key_value_double *)zalloc(npairs * sizeof *result); - - for (pair = pairs; *pair; pair++) { - char **kv = strv_from_string(*pair, kv_separator); -diff -Naur old/src/util-time.h new/src/util-time.h ---- old/src/util-time.h 2021-01-01 00:00:00.000000000 +0800 -+++ new/src/util-time.h 2021-01-01 00:00:00.000000000 +0800 -@@ -97,7 +97,8 @@ - static inline struct human_time - to_human_time(uint64_t us) - { -- struct human_time t; -+ uint64_t l = 0; -+ struct human_time t = {0, NULL}; - struct c { - const char *unit; - unsigned int change_from_previous; -@@ -108,7 +109,7 @@ - {"s", 1000, 120}, - {"min", 60, 120}, - {"h", 60, 48}, -- {"d", 24, ~0}, -+ {"d", 24, ~l}, - }; - struct c *c; - uint64_t value = us; -@@ -121,6 +122,6 @@ - return t; - } - } -- -- assert(!"We should never get here"); -+return t; -+ //assert(1); - } -diff -Naur old/tools/libinput-debug-events.c new/tools/libinput-debug-events.c ---- old/tools/libinput-debug-events.c 2021-01-01 00:00:00.000000000 +0800 -+++ new/tools/libinput-debug-events.c 2021-01-01 00:00:00.000000000 +0800 -@@ -274,6 +274,10 @@ - LIBINPUT_DEVICE_CAP_SWITCH)) - printq("S"); - -+ if (libinput_device_has_capability(dev, -+ LIBINPUT_DEVICE_CAP_JOYSTICK)) -+ printq("JOYSTICK"); -+ - if (libinput_device_get_size(dev, &w, &h) == 0) - printq(" size %.0fx%.0fmm", w, h); - -diff -Naur old/udev/libinput-device-group.c new/udev/libinput-device-group.c ---- old/udev/libinput-device-group.c 2021-01-01 00:00:00.000000000 +0800 -+++ new/udev/libinput-device-group.c 2021-01-01 00:00:00.000000000 +0800 -@@ -138,7 +138,7 @@ - *product_id = pid; - best_dist = dist; - -- free(*phys_attr); -+ free((char*)*phys_attr); - *phys_attr = strdup(phys); - } - } diff --git a/patch/diff_libinput_mmi/libinput/libinput_0000.diff b/patch/diff_libinput_mmi/libinput/libinput_0000.diff index fb3c6ff880c5d85cc547f7206148c4bbfe57d4b0..d595f88b3ee48993c300a9d6e17152f392e6bc6b 100644 --- a/patch/diff_libinput_mmi/libinput/libinput_0000.diff +++ b/patch/diff_libinput_mmi/libinput/libinput_0000.diff @@ -22,7 +22,7 @@ diff -Naur old/BUILD.gn new/BUILD.gn + "//third_party/FreeBSD/sys/dev/evdev", + "src", ] - + cflags = [ + "-DHAVE_LIBEVDEV_DISABLE_PROPERTY=0", + "-DHAVE_LIBWACOM=0", @@ -30,7 +30,7 @@ diff -Naur old/BUILD.gn new/BUILD.gn + "-UHAVE_VERSIONSORT", ] } - + @@ -61,7 +68,8 @@ "src/path-seat.c", "src/udev-seat.c", @@ -39,39 +39,39 @@ diff -Naur old/BUILD.gn new/BUILD.gn + "src/libinput-util.c", + "src/evdev-joystick.c", ] - + configs = [ @@ -81,7 +89,7 @@ "//third_party/mtdev:libmtdev", ] - + - part_name = "multimodalinput_base" + part_name = "input" } ## Build libinput-third.so }}} - + @@ -113,7 +121,7 @@ "//third_party/mtdev:libmtdev", ] - + - part_name = "multimodalinput_base" + part_name = "input" } - + ohos_executable("libinput-list") { @@ -143,7 +151,7 @@ "//third_party/mtdev:libmtdev", ] - + - part_name = "multimodalinput_base" + part_name = "input" } - + ohos_executable("libinput-tablet") { @@ -173,5 +181,5 @@ "//third_party/mtdev:libmtdev", ] - + - part_name = "multimodalinput_base" + part_name = "input" } @@ -100,11 +100,11 @@ diff -Naur old/export_include/libinput.h new/export_include/libinput.h + EVDEV_UDEV_TAG_TRACKBALL = 1 << 10, + EVDEV_UDEV_TAG_SWITCH = 1 << 11, }; - + /** @@ -315,6 +331,49 @@ }; - + /** + * @ingroup event_joystick + * @@ -114,7 +114,7 @@ diff -Naur old/export_include/libinput.h new/export_include/libinput.h + * @since 1.16.4 + */ +enum libinput_joystick_axis_source { -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_UNKNOW = 0, ++ LIBINPUT_JOYSTICK_AXIS_SOURCE_UNKNOWN = 0, + LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_X = 1 << 0, + LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_Y = 1 << 1, + LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_Z = 1 << 2, @@ -155,7 +155,7 @@ diff -Naur old/export_include/libinput.h new/export_include/libinput.h @@ -387,6 +446,17 @@ LIBINPUT_TABLET_TOOL_TIP_DOWN = 1, }; - + +struct libinput_event_joystick_axis_abs_info { + int32_t code; + int32_t value; @@ -170,10 +170,20 @@ diff -Naur old/export_include/libinput.h new/export_include/libinput.h /** * @defgroup tablet_pad_modes Tablet pad modes * -@@ -754,6 +824,10 @@ +@@ -744,6 +814,9 @@ + LIBINPUT_EVENT_POINTER_BUTTON, + LIBINPUT_EVENT_POINTER_AXIS, + ++ LIBINPUT_EVENT_JOYSTICK_BUTTON = 450, ++ LIBINPUT_EVENT_JOYSTICK_AXIS, ++ + LIBINPUT_EVENT_TOUCH_DOWN = 500, + LIBINPUT_EVENT_TOUCH_UP, + LIBINPUT_EVENT_TOUCH_MOTION, +@@ -754,6 +827,10 @@ */ LIBINPUT_EVENT_TOUCH_FRAME, - + + LIBINPUT_EVENT_TOUCHPAD_DOWN = 550, + LIBINPUT_EVENT_TOUCHPAD_UP, + LIBINPUT_EVENT_TOUCHPAD_MOTION, @@ -181,7 +191,7 @@ diff -Naur old/export_include/libinput.h new/export_include/libinput.h /** * One or more axes have changed state on a device with the @ref * LIBINPUT_DEVICE_CAP_TABLET_TOOL capability. This event is only sent -@@ -1001,6 +1075,19 @@ +@@ -1001,6 +1078,19 @@ /** * @ingroup event * @@ -201,9 +211,9 @@ diff -Naur old/export_include/libinput.h new/export_include/libinput.h * Return the gesture event that is this input event. If the event type does * not match the gesture event types, this function returns NULL. * -@@ -1673,6 +1760,120 @@ +@@ -1673,6 +1763,120 @@ uint32_t height); - + /** + * @brief 获取触摸屏的工具类型区域属性 + */ @@ -322,9 +332,9 @@ diff -Naur old/export_include/libinput.h new/export_include/libinput.h * @ingroup event_touch * * @return The generic libinput_event of this event -@@ -1681,6 +1882,228 @@ +@@ -1681,6 +1885,228 @@ libinput_event_touch_get_base_event(struct libinput_event_touch *event); - + /** + * @defgroup event_touch Touchpad events + * @@ -551,9 +561,9 @@ diff -Naur old/export_include/libinput.h new/export_include/libinput.h * @defgroup event_gesture Gesture events * * Gesture events are generated when a gesture is recognized on a touchpad. -@@ -1893,6 +2316,42 @@ +@@ -1893,6 +2319,42 @@ libinput_event_gesture_get_angle_delta(struct libinput_event_gesture *event); - + /** + * 获取带slot的touches信息, 仅支持LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE + */ @@ -594,7 +604,7 @@ diff -Naur old/export_include/libinput.h new/export_include/libinput.h * @defgroup event_tablet Tablet events * * Events that come from tools on tablet devices. For events from the pad, -@@ -2620,6 +3079,19 @@ +@@ -2620,6 +3082,19 @@ /** * @ingroup event_tablet * @@ -614,10 +624,10 @@ diff -Naur old/export_include/libinput.h new/export_include/libinput.h * Return the high-level tool type for a tool object. * * The high level tool describes general interaction expected with the tool. -@@ -3466,6 +3938,46 @@ +@@ -3466,6 +3941,56 @@ int libinput_dispatch(struct libinput *libinput); - + +/**************************************************************************** +* @brief : brief +* @author : fms @@ -638,9 +648,19 @@ diff -Naur old/export_include/libinput.h new/export_include/libinput.h +* @inparam : +* @outparam : +*****************************************************************************/ -+struct libinput_event_joystick_axis * -+libinput_event_get_joystick_axis_event(struct libinput_event *event); ++struct libinput_event_joystick_button* ++libinput_event_get_joystick_button_event(struct libinput_event* event); + ++/**************************************************************************** ++* @brief : get joystick axis event ++* @author : fms ++* @date : 2021/3/12 10:56 ++* @version : ver 1.0 ++* @inparam : ++* @outparam : ++*****************************************************************************/ ++struct libinput_event_joystick_axis* ++ libinput_event_get_joystick_axis_event(struct libinput_event* event); +/** + * @brief 获取轴事件的时间 + */ @@ -661,10 +681,10 @@ diff -Naur old/export_include/libinput.h new/export_include/libinput.h /** * @ingroup base * -@@ -3936,6 +4448,42 @@ +@@ -3936,6 +4461,42 @@ const char * libinput_device_get_name(struct libinput_device *device); - + +/** @brief 获取设备类型*/ +enum evdev_device_udev_tags +libinput_device_get_tags(struct libinput_device* device); @@ -704,9 +724,9 @@ diff -Naur old/export_include/libinput.h new/export_include/libinput.h /** * @ingroup device * -@@ -4146,6 +4694,12 @@ +@@ -4146,6 +4707,12 @@ libinput_device_touch_get_touch_count(struct libinput_device *device); - + /** + * @brief 获取触摸屏工具类型按钮是否按下 + */ @@ -717,10 +737,10 @@ diff -Naur old/export_include/libinput.h new/export_include/libinput.h * @ingroup device * * Check if a @ref LIBINPUT_DEVICE_CAP_SWITCH device has a switch of the -@@ -5928,7 +6482,102 @@ +@@ -5928,7 +6495,102 @@ unsigned int libinput_device_config_rotation_get_default_angle(struct libinput_device *device); - + +/** + * @ingroup event + * @@ -813,7 +833,7 @@ diff -Naur old/export_include/libinput.h new/export_include/libinput.h +const char* +libinput_device_get_uniq(struct libinput_device* device); + -+enum libinput_key_state ++enum libinput_button_state +libinput_event_joystick_button_get_key_state(struct libinput_event_joystick_button* event); #ifdef __cplusplus } @@ -882,10 +902,10 @@ diff -Naur old/include/config.h new/include/config.h @@ -18,14 +18,17 @@ #endif #define HTTP_DOC_LINK "https://wayland.freedesktop.org/libinput/doc/latest" - + -#define LIBINPUT_QUIRKS_DIR "/usr/share/libinput" +#define LIBINPUT_QUIRKS_DIR "/etc/libinput/quirks" - + -#define LIBINPUT_QUIRKS_OVERRIDE_FILE "/etc/libinput/local-overrides.quirks" +#define LIBINPUT_QUIRKS_OVERRIDE_FILE "/etc/libinput/quirks/local-overrides.quirks" + @@ -894,7 +914,7 @@ diff -Naur old/include/config.h new/include/config.h +#define LIBINPUT_TOOL_PATH "/data/libinput" + +#define MESON_BUILD_ROOT "/data/libinput" - + #undef NDEBUG -#define LIBINPUT_TOOL_PATH "" -#define LIBINPUT_QUIRKS_SRCDIR "" @@ -903,7 +923,7 @@ diff -Naur old/include/config.h new/include/config.h # ifdef _Static_assert # define static_assert(cond, msg) _Static_assert(cond, msg) @@ -36,3 +39,10 @@ - + #define index strchr #define ffs __builtin_ffs + @@ -1874,13 +1894,13 @@ diff -Naur old/src/evdev-fallback.c new/src/evdev-fallback.c int seat_slot; + struct touch_axis axis; + int tool_type; - + if (!(device->seat_caps & EVDEV_DEVICE_TOUCH)) return false; @@ -308,8 +311,12 @@ slot->hysteresis_center = point; evdev_transform_absolute(device, &point); - + - touch_notify_touch_down(base, time, slot_idx, seat_slot, - &point); + tool_type = slot->tool_type; @@ -1889,7 +1909,7 @@ diff -Naur old/src/evdev-fallback.c new/src/evdev-fallback.c + evdev_transform_absolute_rect(device, &rect); + touch_notify_touch_down(base, time, slot_idx, seat_slot, slot->pressure, + &axis, &point, tool_type, &rect); - + return true; } @@ -322,8 +329,11 @@ @@ -1901,7 +1921,7 @@ diff -Naur old/src/evdev-fallback.c new/src/evdev-fallback.c int seat_slot; + struct touch_axis axis; + int tool_type; - + if (!(device->seat_caps & EVDEV_DEVICE_TOUCH)) return false; @@ -331,6 +341,7 @@ @@ -1909,12 +1929,12 @@ diff -Naur old/src/evdev-fallback.c new/src/evdev-fallback.c seat_slot = slot->seat_slot; point = slot->point; + axis = slot->axis; - + if (seat_slot == -1) return false; @@ -339,8 +350,12 @@ return false; - + evdev_transform_absolute(device, &point); - touch_notify_touch_motion(base, time, slot_idx, seat_slot, - &point); @@ -1924,7 +1944,7 @@ diff -Naur old/src/evdev-fallback.c new/src/evdev-fallback.c + evdev_transform_absolute_rect(device, &rect); + touch_notify_touch_motion(base, time, slot_idx, seat_slot, slot->pressure, + &axis, &point, tool_type, &rect); - + return true; } @@ -355,6 +370,7 @@ @@ -1932,18 +1952,18 @@ diff -Naur old/src/evdev-fallback.c new/src/evdev-fallback.c struct mt_slot *slot; int seat_slot; + int tool_type; - + if (!(device->seat_caps & EVDEV_DEVICE_TOUCH)) return false; @@ -368,7 +384,9 @@ - + seat->slot_map &= ~bit(seat_slot); - + - touch_notify_touch_up(base, time, slot_idx, seat_slot); + tool_type = slot->tool_type; + + touch_notify_touch_up(base, time, slot_idx, seat_slot, tool_type); - + return true; } @@ -409,7 +427,11 @@ @@ -1955,18 +1975,18 @@ diff -Naur old/src/evdev-fallback.c new/src/evdev-fallback.c int seat_slot; + int tool_type; + int32_t pressure = dispatch->abs.pressure; - + if (!(device->seat_caps & EVDEV_DEVICE_TOUCH)) return false; @@ -431,7 +453,9 @@ point = dispatch->abs.point; evdev_transform_absolute(device, &point); - + - touch_notify_touch_down(base, time, -1, seat_slot, &point); + tool_type = -1; + + touch_notify_touch_down(base, time, -1, seat_slot, pressure, &axis, &point, tool_type, &rect); - + return true; } @@ -443,7 +467,11 @@ @@ -1978,18 +1998,18 @@ diff -Naur old/src/evdev-fallback.c new/src/evdev-fallback.c int seat_slot; + int tool_type; + int32_t pressure = dispatch->abs.pressure; - + point = dispatch->abs.point; evdev_transform_absolute(device, &point); @@ -453,7 +481,9 @@ if (seat_slot == -1) return false; - + - touch_notify_touch_motion(base, time, -1, seat_slot, &point); + tool_type = -1; + + touch_notify_touch_motion(base, time, -1, seat_slot, pressure, &axis, &point, tool_type, &rect); - + return true; } @@ -466,6 +496,7 @@ @@ -1997,18 +2017,18 @@ diff -Naur old/src/evdev-fallback.c new/src/evdev-fallback.c struct libinput_seat *seat = base->seat; int seat_slot; + int tool_type; - + if (!(device->seat_caps & EVDEV_DEVICE_TOUCH)) return false; @@ -478,7 +509,9 @@ - + seat->slot_map &= ~bit(seat_slot); - + - touch_notify_touch_up(base, time, -1, seat_slot); + tool_type = -1; + + touch_notify_touch_up(base, time, -1, seat_slot, tool_type); - + return true; } @@ -653,6 +686,42 @@ @@ -2064,17 +2084,17 @@ diff -Naur old/src/evdev-fallback.c new/src/evdev-fallback.c + break; } } - + @@ -1592,6 +1665,7 @@ - + for (slot = 0; slot < num_slots; ++slot) { slots[slot].seat_slot = -1; + slots[slot].tool_type = -1; - + if (evdev_need_mtdev(device)) continue; @@ -1751,3 +1825,11 @@ - + return &dispatch->base; } + @@ -2097,7 +2117,7 @@ diff -Naur old/src/evdev-fallback.h new/src/evdev-fallback.h + struct touch_axis axis; + int32_t tool_type; }; - + struct fallback_dispatch { @@ -84,6 +88,7 @@ struct { @@ -2105,7 +2125,7 @@ diff -Naur old/src/evdev-fallback.h new/src/evdev-fallback.h int32_t seat_slot; + int32_t pressure; } abs; - + struct { @@ -169,6 +174,7 @@ static inline enum key_type @@ -2123,11 +2143,11 @@ diff -Naur old/src/evdev-fallback.h new/src/evdev-fallback.h + return KEY_TYPE_KEY; return KEY_TYPE_NONE; } - + diff -Naur old/src/evdev-joystick.c new/src/evdev-joystick.c --- old/src/evdev-joystick.c 1970-01-01 08:00:00.000000000 +0800 +++ new/src/evdev-joystick.c 2021-01-01 00:00:00.000000000 +0800 -@@ -0,0 +1,580 @@ +@@ -0,0 +1,593 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); @@ -2168,31 +2188,35 @@ diff -Naur old/src/evdev-joystick.c new/src/evdev-joystick.c +} + +static int -+update_seat_joystick_button_count(struct libinput_seat* pSeat, int32_t key, uint32_t *pRetcount, enum libinput_key_state state) ++update_seat_joystick_button_count(struct libinput_seat* seat, int32_t key, uint32_t *seat_count, enum libinput_button_state state) +{ -+ if (pSeat == NULL || pRetcount == NULL || key < SYN_REPORT || key > KEY_MAX) { ++ if (seat == NULL || seat_count == NULL || key < SYN_REPORT || key > KEY_MAX) { + return false; + } + + switch (state) { -+ case LIBINPUT_KEY_STATE_PRESSED: ++ case LIBINPUT_BUTTON_STATE_PRESSED: + { -+ *(pRetcount) = ++pSeat->button_count[key]; ++ *(seat_count) = ++seat->button_count[key]; ++ break; + } -+ break; -+ case LIBINPUT_KEY_STATE_RELEASED: ++ case LIBINPUT_BUTTON_STATE_RELEASED: + { -+ if (pSeat->button_count[key] == 0) { -+ *(pRetcount) = pSeat->button_count[key]; ++ if (seat->button_count[key] == 0) ++ { ++ *(seat_count) = seat->button_count[key]; + } -+ else { -+ *(pRetcount) = --pSeat->button_count[key]; ++ else ++ { ++ *(seat_count) = --seat->button_count[key]; + } ++ break; + } -+ break; + default: -+ *(pRetcount) = 0; ++ { ++ *(seat_count) = 0; + break; ++ } + } + return true; +} @@ -2216,21 +2240,21 @@ diff -Naur old/src/evdev-joystick.c new/src/evdev-joystick.c + return; + } + -+ *joystick_axis_event = (struct libinput_event_joystick_axis){ ++ *joystick_axis_event = (struct libinput_event_joystick_axis) { + .base.type = LIBINPUT_EVENT_POINTER_AXIS, + .base.device = &device->base, + .type = EV_ABS, + .time = time, + .axis_value_mask = joystick_dispatch->axis_value_mask, -+ .abs_throttle = joystick_dispatch->abs_throttle, -+ .abs_hat0x = joystick_dispatch->abs_hat0x, -+ .abs_hat0y = joystick_dispatch->abs_hat0y, -+ .abs_x = joystick_dispatch->abs_x, -+ .abs_y = joystick_dispatch->abs_y, -+ .abs_z = joystick_dispatch->abs_z, -+ .abs_rx = joystick_dispatch->abs_rx, -+ .abs_ry = joystick_dispatch->abs_ry, -+ .abs_rz = joystick_dispatch->abs_rz, ++ .abs_throttle = joystick_dispatch->axis_abs_infos.abs_throttle, ++ .abs_hat0x = joystick_dispatch->axis_abs_infos.abs_hat0x, ++ .abs_hat0y = joystick_dispatch->axis_abs_infos.abs_hat0y, ++ .abs_x = joystick_dispatch->axis_abs_infos.abs_x, ++ .abs_y = joystick_dispatch->axis_abs_infos.abs_y, ++ .abs_z = joystick_dispatch->axis_abs_infos.abs_z, ++ .abs_rx = joystick_dispatch->axis_abs_infos.abs_rx, ++ .abs_ry = joystick_dispatch->axis_abs_infos.abs_ry, ++ .abs_rz = joystick_dispatch->axis_abs_infos.abs_rz, + }; + + struct libinput_event_listener* listener = NULL; @@ -2243,44 +2267,44 @@ diff -Naur old/src/evdev-joystick.c new/src/evdev-joystick.c +} + +static void -+joystick_notify_key_event(struct evdev_device* device, struct input_event* pEvent, uint64_t time) ++joystick_notify_key_event(struct evdev_device* device, struct input_event* event, uint64_t time) +{ -+ if (device == NULL || pEvent == NULL) { ++ if (device == NULL || event == NULL) { + return; + } + -+ struct libinput_event_joystick_button* pKeyEvent = {0}; -+ uint32_t uiSeatCount = 0; ++ struct libinput_event_joystick_button* button_event = {0}; ++ uint32_t seat_count = 0; + -+ int iRet = update_seat_joystick_button_count(device->base.seat, pEvent->code, &uiSeatCount, pEvent->value); -+ if (iRet == false) { ++ int ret = update_seat_joystick_button_count(device->base.seat, event->code, &seat_count, event->value); ++ if (ret == 0) { + return; + } + -+ pKeyEvent = zalloc(sizeof * pKeyEvent); -+ if (pKeyEvent == NULL) { ++ button_event = zalloc(sizeof * button_event); ++ if (button_event == NULL) { + return; + } + -+ *pKeyEvent = (struct libinput_event_joystick_button) { -+ .base.type = LIBINPUT_EVENT_POINTER_BUTTON, ++ *button_event = (struct libinput_event_joystick_button) { ++ .base.type = LIBINPUT_EVENT_JOYSTICK_BUTTON, + .base.device = &device->base, + .time = time, -+ .type = pEvent->type, -+ .key = pEvent->code, -+ .value = pEvent->value, -+ .seat_key_count = uiSeatCount, -+ .state = pEvent->value, ++ .type = event->type, ++ .key = event->code, ++ .value = event->value, ++ .seat_key_count = seat_count, ++ .state = event->value, + }; + + struct libinput_event_listener* listener = NULL; + struct libinput_event_listener* tmp_listener = NULL; + list_for_each_safe(listener, tmp_listener, &device->base.event_listeners, link) + { -+ listener->notify_func(time, &pKeyEvent->base, listener->notify_func_data); ++ listener->notify_func(time, &button_event->base, listener->notify_func_data); + } + -+ libinput_post_handle_event(device->base.seat->libinput, &pKeyEvent->base); ++ libinput_post_handle_event(device->base.seat->libinput, &button_event->base); +} + +static float @@ -2350,46 +2374,54 @@ diff -Naur old/src/evdev-joystick.c new/src/evdev-joystick.c + switch (code) { + case ABS_THROTTLE: + joystick_set_axis_value_mask(joystick_dispatch, LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_THROTTLE); -+ absinfo = &joystick_dispatch->abs_throttle; ++ absinfo = &joystick_dispatch->axis_abs_infos.abs_throttle; + break; + case ABS_HAT0X: + joystick_set_axis_value_mask(joystick_dispatch, LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_HAT0X); -+ absinfo = &joystick_dispatch->abs_hat0x; ++ absinfo = &joystick_dispatch->axis_abs_infos.abs_hat0x; + break; + case ABS_HAT0Y: + joystick_set_axis_value_mask(joystick_dispatch, LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_HAT0Y); -+ absinfo = &joystick_dispatch->abs_hat0y; ++ absinfo = &joystick_dispatch->axis_abs_infos.abs_hat0y; + break; + case ABS_X: + joystick_set_axis_value_mask(joystick_dispatch, LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_X); -+ absinfo = &joystick_dispatch->abs_x; ++ absinfo = &joystick_dispatch->axis_abs_infos.abs_x; + break; + case ABS_Y: + joystick_set_axis_value_mask(joystick_dispatch, LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_Y); -+ absinfo = &joystick_dispatch->abs_y; ++ absinfo = &joystick_dispatch->axis_abs_infos.abs_y; + break; + case ABS_Z: + joystick_set_axis_value_mask(joystick_dispatch, LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_Z); -+ absinfo = &joystick_dispatch->abs_z; ++ absinfo = &joystick_dispatch->axis_abs_infos.abs_z; + break; + case ABS_RX: + joystick_set_axis_value_mask(joystick_dispatch, LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_RX); -+ absinfo = &joystick_dispatch->abs_rx; ++ absinfo = &joystick_dispatch->axis_abs_infos.abs_rx; + break; + case ABS_RY: + joystick_set_axis_value_mask(joystick_dispatch, LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_RY); -+ absinfo = &joystick_dispatch->abs_ry; ++ absinfo = &joystick_dispatch->axis_abs_infos.abs_ry; + break; + case ABS_RZ: + joystick_set_axis_value_mask(joystick_dispatch, LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_RZ); -+ absinfo = &joystick_dispatch->abs_rz; ++ absinfo = &joystick_dispatch->axis_abs_infos.abs_rz; ++ break; ++ case ABS_GAS: ++ joystick_set_axis_value_mask(joystick_dispatch, LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_GAS); ++ absinfo = &joystick_dispatch->axis_abs_infos.abs_gas; ++ break; ++ case ABS_BRAKE: ++ joystick_set_axis_value_mask(joystick_dispatch, LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_BRAKE); ++ absinfo = &joystick_dispatch->axis_abs_infos.abs_brake; + break; + default: + break; + } + + if (absinfo == NULL) { -+ libinput_log_printf("unsupported joystick abs event: divice_name:%s code:%d value:%d.\n", ++ libinput_log_printf("unsupported joystick abs event: device_name:%s code:%d value:%d.\n", + device->devname, code, event->value); + return; + } @@ -2426,7 +2458,8 @@ diff -Naur old/src/evdev-joystick.c new/src/evdev-joystick.c + } + + if (joystick_dispatch->axis_value_mask != 0) { -+ joystick_notify_axis(device, time); ++ joysticks_notify_axis(&device->base, time, joystick_dispatch->axis_value_mask, ++ &joystick_dispatch->axis_abs_infos); + joystick_reset_axis_value_mask(joystick_dispatch); + } +} @@ -2711,7 +2744,7 @@ diff -Naur old/src/evdev-joystick.c new/src/evdev-joystick.c diff -Naur old/src/evdev-joystick.h new/src/evdev-joystick.h --- old/src/evdev-joystick.h 1970-01-01 08:00:00.000000000 +0800 +++ new/src/evdev-joystick.h 2021-01-01 00:00:00.000000000 +0800 -@@ -0,0 +1,77 @@ +@@ -0,0 +1,71 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); @@ -2736,15 +2769,7 @@ diff -Naur old/src/evdev-joystick.h new/src/evdev-joystick.h + struct evdev_dispatch base; + struct evdev_device* device; + uint32_t axis_value_mask; -+ struct libinput_event_joystick_axis_abs_info abs_throttle; -+ struct libinput_event_joystick_axis_abs_info abs_hat0x; -+ struct libinput_event_joystick_axis_abs_info abs_hat0y; -+ struct libinput_event_joystick_axis_abs_info abs_x; -+ struct libinput_event_joystick_axis_abs_info abs_y; -+ struct libinput_event_joystick_axis_abs_info abs_z; -+ struct libinput_event_joystick_axis_abs_info abs_rx; -+ struct libinput_event_joystick_axis_abs_info abs_ry; -+ struct libinput_event_joystick_axis_abs_info abs_rz; ++ struct joystick_axis_abs_infos axis_abs_infos; + struct { + struct libinput_device_config_send_events config; + enum libinput_config_send_events_mode current_mode; @@ -2757,7 +2782,7 @@ diff -Naur old/src/evdev-joystick.h new/src/evdev-joystick.h + uint64_t time; + uint32_t key; + uint32_t seat_key_count; -+ enum libinput_key_state state; ++ enum libinput_button_state state; + int value; +}; + @@ -2775,6 +2800,8 @@ diff -Naur old/src/evdev-joystick.h new/src/evdev-joystick.h + struct libinput_event_joystick_axis_abs_info abs_rx; + struct libinput_event_joystick_axis_abs_info abs_ry; + struct libinput_event_joystick_axis_abs_info abs_rz; ++ struct libinput_event_joystick_axis_abs_info abs_gas; ++ struct libinput_event_joystick_axis_abs_info abs_brake; +}; + +#ifdef _DEBUG @@ -2794,7 +2821,7 @@ diff -Naur old/src/evdev-mt-touchpad-gestures.c new/src/evdev-mt-touchpad-gestur +++ new/src/evdev-mt-touchpad-gestures.c 2021-01-01 00:00:00.000000000 +0800 @@ -80,6 +80,37 @@ } - + static void +tp_get_raw_touches(struct tp_dispatch *tp, struct sloted_coords_info *raw_touches) +{ @@ -2838,18 +2865,18 @@ diff -Naur old/src/evdev-mt-touchpad-gestures.c new/src/evdev-mt-touchpad-gestur + &zero, &zero, NULL); break; } - + @@ -630,10 +661,12 @@ tp_gesture_handle_state_swipe(struct tp_dispatch *tp, uint64_t time) { struct device_float_coords raw; + struct sloted_coords_info raw_touches = {}; struct normalized_coords delta, unaccel; - + raw = tp_get_average_touches_delta(tp); delta = tp_filter_motion(tp, &raw, time); + tp_get_raw_touches(tp, &raw_touches); - + if (!normalized_is_zero(delta) || !device_float_is_zero(raw)) { unaccel = tp_normalize_delta(tp, raw); @@ -641,7 +674,7 @@ @@ -2859,11 +2886,11 @@ diff -Naur old/src/evdev-mt-touchpad-gestures.c new/src/evdev-mt-touchpad-gestur - &delta, &unaccel); + &delta, &unaccel, &raw_touches); } - + return GESTURE_STATE_SWIPE; diff -Naur old/src/evdev-mt-touchpad-tap.c new/src/evdev-mt-touchpad-tap.c --- old/src/evdev-mt-touchpad-tap.c 2021-01-01 00:00:00.000000000 +0800 -+++ new/src/evdev-mt-touchpad-tap.c 2021-01-01 00:00:00.000000000 +0800 ++++ new/src/evdev-mt-touchpad-tap.c 2022-12-12 19:49:27.376953599 +0800 @@ -72,6 +72,7 @@ CASE_RETURN_STRING(TAP_STATE_DRAGGING_OR_TAP); CASE_RETURN_STRING(TAP_STATE_DRAGGING_2); @@ -2873,9 +2900,9 @@ diff -Naur old/src/evdev-mt-touchpad-tap.c new/src/evdev-mt-touchpad-tap.c return NULL; } @@ -122,6 +123,10 @@ - + button = button_map[tp->tap.map][nfingers - 1]; - + + if (tp->device->key_count[button] == 0 && + state == LIBINPUT_BUTTON_STATE_RELEASED) + return; @@ -2954,7 +2981,7 @@ diff -Naur old/src/evdev-mt-touchpad-tap.c new/src/evdev-mt-touchpad-tap.c + LIBINPUT_BUTTON_STATE_RELEASED); + } } - + static void @@ -796,6 +851,9 @@ case TAP_STATE_DEAD: @@ -2964,8 +2991,17 @@ diff -Naur old/src/evdev-mt-touchpad-tap.c new/src/evdev-mt-touchpad-tap.c + tp_tap_holding_handle_event(tp, t, event, time); + break; } - + if (tp->tap.state == TAP_STATE_IDLE || tp->tap.state == TAP_STATE_DEAD) +@@ -1154,7 +1212,7 @@ + static inline enum libinput_config_drag_state + tp_drag_default(struct evdev_device *device) + { +- return LIBINPUT_CONFIG_DRAG_ENABLED; ++ return LIBINPUT_CONFIG_DRAG_DISABLED; + } + + static enum libinput_config_drag_state @@ -1295,3 +1353,63 @@ return false; } @@ -3036,7 +3072,7 @@ diff -Naur old/src/evdev-mt-touchpad.c new/src/evdev-mt-touchpad.c +++ new/src/evdev-mt-touchpad.c 2021-01-01 00:00:00.000000000 +0800 @@ -308,6 +308,35 @@ } - + static inline void +tp_tool_key_set(struct tp_dispatch *tp, + unsigned int code, @@ -3077,11 +3113,11 @@ diff -Naur old/src/evdev-mt-touchpad.c new/src/evdev-mt-touchpad.c + t->seat_slot = -1; tp->queued |= TOUCHPAD_EVENT_MOTION; } - + @@ -496,6 +526,81 @@ return absinfo->maximum - (value - absinfo->minimum); } - + +void tp_ext_post_event(struct tp_dispatch* dispatch, bool is_up, uint64_t time) +{ + struct tp_touch * t = tp_current_touch(dispatch); @@ -3161,7 +3197,7 @@ diff -Naur old/src/evdev-mt-touchpad.c new/src/evdev-mt-touchpad.c tp_process_absolute(struct tp_dispatch *tp, const struct input_event *e, @@ -505,6 +610,7 @@ - + switch(e->code) { case ABS_MT_POSITION_X: + tp_ext_on_xy_update(tp); @@ -3228,7 +3264,7 @@ diff -Naur old/src/evdev-mt-touchpad.c new/src/evdev-mt-touchpad.c + break; } } - + @@ -772,6 +903,20 @@ tp_process_trackpoint_button(tp, e, time); break; @@ -3248,7 +3284,7 @@ diff -Naur old/src/evdev-mt-touchpad.c new/src/evdev-mt-touchpad.c + break; + } } - + static void @@ -1951,6 +2096,7 @@ tp_process_msc(tp, e, time); @@ -3265,23 +3301,23 @@ diff -Naur old/src/evdev-mt-touchpad.c new/src/evdev-mt-touchpad.c + t->seat_slot = -1; + t->tool_type = -1; } - + static inline void @@ -3660,6 +3808,10 @@ if (tp->gesture.enabled) device->seat_caps |= EVDEV_DEVICE_GESTURE; - + + tp->orginal.seat_slot_id = 0; + tp->orginal.active_slot_count = 0; + tp->orginal.xy_updated = 0; + return true; } - + @@ -3843,6 +3995,14 @@ - + tp = zalloc(sizeof *tp); - + + const struct input_absinfo* absInfo = device->is_mt ? libevdev_get_abs_info(device->evdev, ABS_MT_PRESSURE) + : libevdev_get_abs_info(device->evdev, ABS_PRESSURE); + if (absInfo == NULL) { @@ -3294,7 +3330,7 @@ diff -Naur old/src/evdev-mt-touchpad.c new/src/evdev-mt-touchpad.c tp_interface_destroy(&tp->base); return NULL; @@ -3860,3 +4020,27 @@ - + return &tp->base; } + @@ -3331,17 +3367,17 @@ diff -Naur old/src/evdev-mt-touchpad.h new/src/evdev-mt-touchpad.h TAP_STATE_DEAD, /**< finger count exceeded */ + TAP_STATE_HOLDING, }; - + enum tp_tap_touch_state { @@ -176,10 +177,14 @@ int pressure; bool is_tool_palm; /* MT_TOOL_PALM */ int major, minor; + struct device_coord_rect tool_rect; - + bool was_down; /* if distance == 0, false for pure hovering touches */ - + + int seat_slot; + int tool_type; + @@ -3351,7 +3387,7 @@ diff -Naur old/src/evdev-mt-touchpad.h new/src/evdev-mt-touchpad.h @@ -294,6 +299,17 @@ */ unsigned int fake_touches; - + + /* bit 0: BTN_TOOL_PEN + * bit 1: BTN_TOOL_RUBBER + * bit 2: BTN_TOOL_BRUSH @@ -3377,12 +3413,12 @@ diff -Naur old/src/evdev-mt-touchpad.h new/src/evdev-mt-touchpad.h + int xy_updated; + } orginal; }; - + static inline struct tp_dispatch* @@ -730,4 +752,19 @@ void tp_init_thumb(struct tp_dispatch *tp); - + +void +tp_tap_original_down(struct tp_dispatch *tp, + struct tp_touch *t, @@ -3424,12 +3460,26 @@ diff -Naur old/src/evdev-tablet.c new/src/evdev-tablet.c .refcount = 1, + .mt_tool_type = tablet->current_value[LIBINPUT_TABLET_TOOL_AXIS_TYPE], }; - + tool_set_pressure_thresholds(tablet, tool); +@@ -2117,11 +2118,11 @@ + { + struct tablet_dispatch *tablet = tablet_dispatch(device->dispatch); + bool is_touchscreen, is_ext_touchpad; +- ++/* + if (libinput_device_get_device_group(&device->base) != + libinput_device_get_device_group(&added_device->base)) + return; +- ++*/ + is_touchscreen = evdev_device_has_capability(added_device, + LIBINPUT_DEVICE_CAP_TOUCH); + is_ext_touchpad = evdev_device_has_capability(added_device, @@ -2368,6 +2369,34 @@ return true; } - + +static void +tablet_reset_abs_resolution(struct evdev_device *device) +{ @@ -3466,7 +3516,7 @@ diff -Naur old/src/evdev-tablet.c new/src/evdev-tablet.c tablet->current_tool.type = LIBINPUT_TOOL_NONE; list_init(&tablet->tool_list); + tablet_reset_abs_resolution(device); - + if (tablet_reject_device(device)) return -1; diff -Naur old/src/evdev-tablet.h new/src/evdev-tablet.h @@ -3498,7 +3548,7 @@ diff -Naur old/src/evdev.c new/src/evdev.c @@ -54,25 +54,7 @@ #define DEFAULT_BUTTON_SCROLL_TIMEOUT ms2us(200) #define MAX_RETRY_OPEN_DEVICE_COUNT 10 - + -enum evdev_device_udev_tags { - EVDEV_UDEV_TAG_INPUT = bit(0), - EVDEV_UDEV_TAG_KEYBOARD = bit(1), @@ -3513,17 +3563,17 @@ diff -Naur old/src/evdev.c new/src/evdev.c - EVDEV_UDEV_TAG_TRACKBALL = bit(10), - EVDEV_UDEV_TAG_SWITCH = bit(11), -}; - + -struct evdev_udev_tag_match { - const char *name; - enum evdev_device_udev_tags tag; -}; - + static const struct evdev_udev_tag_match evdev_udev_tag_matches[] = { {"ID_INPUT", EVDEV_UDEV_TAG_INPUT}, @@ -341,6 +323,17 @@ } - + void +evdev_transform_absolute_rect(struct evdev_device *device, + struct device_coord_rect *rect) @@ -3552,7 +3602,7 @@ diff -Naur old/src/evdev.c new/src/evdev.c @@ -1771,6 +1767,9 @@ libevdev_disable_event_code(evdev, EV_ABS, REL_Z); } - + +static enum evdev_device_udev_tags +update_device_capability(struct evdev_device *device); + @@ -3561,10 +3611,10 @@ diff -Naur old/src/evdev.c new/src/evdev.c { @@ -1780,11 +1779,17 @@ struct evdev_dispatch *dispatch; - + udev_tags = evdev_device_get_udev_tags(device, device->udev_device); + libinput_log_printf("----evdev_configure_device tagged as supported input device---- %d \r\n", udev_tags); - + if ((udev_tags & EVDEV_UDEV_TAG_INPUT) == 0 || (udev_tags & ~EVDEV_UDEV_TAG_INPUT) == 0) { + udev_tags = update_device_capability(device); @@ -3576,11 +3626,11 @@ diff -Naur old/src/evdev.c new/src/evdev.c + libinput_log_printf("----evdev_configure_device not tagged as supported input device---- \r\n"); return NULL; } - + @@ -1812,12 +1817,6 @@ evdev_disable_accelerometer_axes(device); } - + - if (udev_tags == (EVDEV_UDEV_TAG_INPUT|EVDEV_UDEV_TAG_JOYSTICK)) { - evdev_log_info(device, - "device is a joystick, ignoring\n"); @@ -3593,7 +3643,7 @@ diff -Naur old/src/evdev.c new/src/evdev.c @@ -1833,8 +1832,16 @@ udev_tags &= ~EVDEV_UDEV_TAG_TOUCHSCREEN; } - + + if (udev_tags & EVDEV_UDEV_TAG_JOYSTICK) { + libinput_log_printf("----evdev_configure_device--_LIBINPUT_JOYSTICK_BULID-- \r\n"); + dispatch = evdev_joystick_create(device); @@ -3608,7 +3658,7 @@ diff -Naur old/src/evdev.c new/src/evdev.c device->seat_caps |= EVDEV_DEVICE_TABLET; evdev_log_info(device, "device is a totem\n"); @@ -1850,12 +1857,14 @@ - + /* libwacom assigns tablet _and_ tablet_pad to the pad devices */ if (udev_tags & EVDEV_UDEV_TAG_TABLET_PAD) { + libinput_log_printf("----evdev_configure_device--_LIBINPUT_TABLET_PAD_BULID-- \r\n"); @@ -3616,7 +3666,7 @@ diff -Naur old/src/evdev.c new/src/evdev.c device->seat_caps |= EVDEV_DEVICE_TABLET_PAD; evdev_log_info(device, "device is a tablet pad\n"); return dispatch; - + } else if ((udev_tags & tablet_tags) == EVDEV_UDEV_TAG_TABLET) { + libinput_log_printf("----evdev_configure_device--_LIBINPUT_TABLET_BULID-- \r\n"); dispatch = evdev_tablet_create(device); @@ -3624,7 +3674,7 @@ diff -Naur old/src/evdev.c new/src/evdev.c evdev_log_info(device, "device is a tablet\n"); @@ -1863,6 +1872,7 @@ } - + if (udev_tags & EVDEV_UDEV_TAG_TOUCHPAD) { + libinput_log_printf("----evdev_configure_device--_LIBINPUT_TOUCHPAD_BULID-- \r\n"); if (udev_tags & EVDEV_UDEV_TAG_TABLET) @@ -3632,7 +3682,7 @@ diff -Naur old/src/evdev.c new/src/evdev.c /* whether velocity should be averaged, false by default */ @@ -2292,6 +2302,18 @@ } - + unsigned int +evdev_device_get_id_bustype(struct evdev_device *device) +{ @@ -3652,7 +3702,7 @@ diff -Naur old/src/evdev.c new/src/evdev.c @@ -2309,6 +2331,33 @@ return udev_device_ref(device->udev_device); } - + +enum evdev_device_udev_tags + evdev_device_get_udev_device_tags(struct evdev_device* device) +{ @@ -3693,7 +3743,7 @@ diff -Naur old/src/evdev.c new/src/evdev.c default: return false; } -@@ -2917,3 +2969,45 @@ +@@ -2917,3 +2969,57 @@ #endif return has_left_handed; } @@ -3723,10 +3773,20 @@ diff -Naur old/src/evdev.c new/src/evdev.c + !libevdev_has_event_type(evdev, EV_REL)); +} + ++static inline bool ++is_tablet_tool(const struct libevdev *evdev) ++{ ++ return (libevdev_has_event_type(evdev, EV_KEY) && ++ (libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_PEN) || ++ libevdev_has_event_code(evdev, EV_KEY, BTN_STYLUS)) && ++ libevdev_has_event_type(evdev, EV_ABS) && ++ libevdev_has_event_code(evdev, EV_ABS, ABS_X) && ++ libevdev_has_event_code(evdev, EV_ABS, ABS_Y)); ++} ++ +static enum evdev_device_udev_tags +update_device_capability(struct evdev_device *device) +{ -+ evdev_log_info(device, "update_device_capability() enter\n"); + if (is_touchscreen(device->evdev)) { + return (EVDEV_UDEV_TAG_INPUT | EVDEV_UDEV_TAG_TOUCHSCREEN); + } @@ -3736,7 +3796,9 @@ diff -Naur old/src/evdev.c new/src/evdev.c + if (is_keyboard(device->evdev)) { + return (EVDEV_UDEV_TAG_INPUT | EVDEV_UDEV_TAG_KEYBOARD); + } -+ evdev_log_info(device, "update_device_capability() leave\n"); ++ if (is_tablet_tool(device->evdev)) { ++ return (EVDEV_UDEV_TAG_INPUT | EVDEV_UDEV_TAG_TABLET); ++ } + return 0; +} diff -Naur old/src/evdev.h new/src/evdev.h @@ -3748,12 +3810,12 @@ diff -Naur old/src/evdev.h new/src/evdev.h EVDEV_DEVICE_SWITCH = bit(6), + EVDEV_DEVICE_JOYSTICK = bit(7), }; - + enum evdev_device_tags { @@ -76,6 +77,11 @@ EVDEV_TAG_TABLET_TOUCHPAD = bit(9), }; - + +struct evdev_udev_tag_match { + const char* name; + enum evdev_device_udev_tags tag; @@ -3776,11 +3838,11 @@ diff -Naur old/src/evdev.h new/src/evdev.h DISPATCH_TOTEM, + DISPATCH_JOYSTICK, }; - + struct evdev_dispatch { @@ -406,6 +414,10 @@ struct device_coords *point); - + void +evdev_transform_absolute_rect(struct evdev_device *device, + struct device_coord_rect *rect); @@ -3788,30 +3850,30 @@ diff -Naur old/src/evdev.h new/src/evdev.h +void evdev_transform_relative(struct evdev_device *device, struct device_coords *point); - + @@ -430,12 +442,19 @@ evdev_device_init_pointer_acceleration(struct evdev_device *device, struct motion_filter *filter); - + +struct evdev_dispatch* +evdev_joystick_create(struct evdev_device* device); + + struct evdev_dispatch * evdev_touchpad_create(struct evdev_device *device); - + struct evdev_dispatch * evdev_mt_touchpad_create(struct evdev_device *device); - + +bool +evdev_device_touchpad_btn_tool_type_down(struct evdev_device *device, int32_t btnToolType); + struct evdev_dispatch * evdev_tablet_create(struct evdev_device *device); - + @@ -473,6 +492,12 @@ evdev_device_get_name(struct evdev_device *device); - + unsigned int +evdev_device_get_id_bustype(struct evdev_device *device); + @@ -3820,12 +3882,12 @@ diff -Naur old/src/evdev.h new/src/evdev.h + +unsigned int evdev_device_get_id_product(struct evdev_device *device); - + unsigned int @@ -481,6 +506,19 @@ struct udev_device * evdev_device_get_udev_device(struct evdev_device *device); - + +/** @brief 获取设备类型 */ +enum evdev_device_udev_tags +evdev_device_get_udev_device_tags(struct evdev_device* device); @@ -3845,7 +3907,7 @@ diff -Naur old/src/evdev.h new/src/evdev.h @@ -506,6 +544,9 @@ int evdev_device_get_touch_count(struct evdev_device *device); - + +bool +evdev_device_touch_btn_tool_type_down(struct evdev_device *device, int32_t btnToolType); + @@ -3863,7 +3925,7 @@ diff -Naur old/src/evdev.h new/src/evdev.h return value/absinfo->resolution; } @@ -764,12 +808,15 @@ - + if (!is_logged(evdev_libinput_context(device), priority)) return; - @@ -3889,7 +3951,7 @@ diff -Naur old/src/evdev.h new/src/evdev.h + //HTTP_DOC_LINK); } } - + diff -Naur old/src/libinput-git-version.h new/src/libinput-git-version.h --- old/src/libinput-git-version.h 1970-01-01 08:00:00.000000000 +0800 +++ new/src/libinput-git-version.h 2021-01-01 00:00:00.000000000 +0800 @@ -3903,7 +3965,7 @@ diff -Naur old/src/libinput-private.h new/src/libinput-private.h @@ -48,6 +48,12 @@ int x, y; }; - + +/* Size of touch point region (major and minor axes of ellipse) */ +struct touch_axis { + int32_t major; @@ -3921,7 +3983,7 @@ diff -Naur old/src/libinput-private.h new/src/libinput-private.h + LIBINPUT_TABLET_TOOL_AXIS_TYPE = 11, + LIBINPUT_TABLET_TOOL_AXIS_SIZE_MINOR = 12, }; - + #define LIBINPUT_TABLET_TOOL_AXIS_MAX LIBINPUT_TABLET_TOOL_AXIS_SIZE_MINOR @@ -383,6 +390,7 @@ /* pressure_offset includes axis->minimum */ @@ -3929,9 +3991,30 @@ diff -Naur old/src/libinput-private.h new/src/libinput-private.h bool has_pressure_offset; + int32_t mt_tool_type; }; - + struct libinput_tablet_pad_mode_group { -@@ -569,20 +577,29 @@ +@@ -415,6 +423,20 @@ + void *notify_func_data; + }; + ++struct joystick_axis_abs_infos { ++ struct libinput_event_joystick_axis_abs_info abs_throttle; ++ struct libinput_event_joystick_axis_abs_info abs_hat0x; ++ struct libinput_event_joystick_axis_abs_info abs_hat0y; ++ struct libinput_event_joystick_axis_abs_info abs_x; ++ struct libinput_event_joystick_axis_abs_info abs_y; ++ struct libinput_event_joystick_axis_abs_info abs_z; ++ struct libinput_event_joystick_axis_abs_info abs_rx; ++ struct libinput_event_joystick_axis_abs_info abs_ry; ++ struct libinput_event_joystick_axis_abs_info abs_rz; ++ struct libinput_event_joystick_axis_abs_info abs_gas; ++ struct libinput_event_joystick_axis_abs_info abs_brake; ++}; ++ + typedef void (*libinput_source_dispatch_t)(void *data); + + #define log_debug(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_DEBUG, __VA_ARGS__) +@@ -569,20 +591,29 @@ uint64_t time, int32_t slot, int32_t seat_slot, @@ -3941,7 +4024,7 @@ diff -Naur old/src/libinput-private.h new/src/libinput-private.h + const struct device_coords *point, + int32_t tool_type, + const struct device_coord_rect *tool_rect); - + void touch_notify_touch_motion(struct libinput_device *device, uint64_t time, @@ -3953,7 +4036,7 @@ diff -Naur old/src/libinput-private.h new/src/libinput-private.h + const struct device_coords *point, + int32_t tool_type, + const struct device_coord_rect *tool_rect); - + void touch_notify_touch_up(struct libinput_device *device, uint64_t time, @@ -3961,12 +4044,12 @@ diff -Naur old/src/libinput-private.h new/src/libinput-private.h - int32_t seat_slot); + int32_t seat_slot, + int32_t tool_type); - + void touch_notify_touch_cancel(struct libinput_device *device, -@@ -595,12 +612,43 @@ +@@ -595,12 +626,43 @@ uint64_t time); - + void +touchpad_notify_touch_down(struct libinput_device *device, + uint64_t time, @@ -4006,9 +4089,22 @@ diff -Naur old/src/libinput-private.h new/src/libinput-private.h - const struct normalized_coords *unaccel); + const struct normalized_coords *unaccel, + const struct sloted_coords_info *raw_touches); - + void gesture_notify_swipe_end(struct libinput_device *device, +@@ -689,6 +751,12 @@ + enum libinput_switch sw, + enum libinput_switch_state state); + ++void ++joysticks_notify_axis(struct libinput_device *device, ++ uint64_t time, ++ uint32_t axes, ++ const struct joystick_axis_abs_infos *axis_abs); ++ + static inline uint64_t + libinput_now(struct libinput *libinput) + { diff -Naur old/src/libinput-util.c new/src/libinput-util.c --- old/src/libinput-util.c 1970-01-01 08:00:00.000000000 +0800 +++ new/src/libinput-util.c 2021-01-01 00:00:00.000000000 +0800 @@ -4119,9 +4215,9 @@ diff -Naur old/src/libinput-util.h new/src/libinput-util.h --- old/src/libinput-util.h 2021-01-01 00:00:00.000000000 +0800 +++ new/src/libinput-util.h 2021-01-01 00:00:00.000000000 +0800 @@ -27,10 +27,9 @@ - + #include "config.h" - + -#ifdef NDEBUG -#warning "libinput relies on assert(). #defining NDEBUG is not recommended" -#endif @@ -4129,13 +4225,13 @@ diff -Naur old/src/libinput-util.h new/src/libinput-util.h +//#ifdef NDEBUG +//#warning "libinput relies on assert(). #defining NDEBUG is not recommended" +//#endif - + #include "libinput.h" - + @@ -57,6 +56,15 @@ #define DEFAULT_MOUSE_DPI 1000 #define DEFAULT_TRACKPOINT_SENSITIVITY 128 - + + +#ifdef HAVE_LIBINPUT_LOG_ENABLE +void libinput_log_printf(const char* fmt, ...); @@ -4192,10 +4288,18 @@ diff -Naur old/src/libinput.c new/src/libinput.c #include "timer.h" #include "quirks.h" +#include "evdev-joystick.h" - + #define require_event_type(li_, type_, retval_, ...) \ if (type_ == LIBINPUT_EVENT_NONE) abort(); \ -@@ -123,6 +124,9 @@ +@@ -117,12 +118,17 @@ + CASE_RETURN_STRING(LIBINPUT_EVENT_POINTER_MOTION); + CASE_RETURN_STRING(LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE); + CASE_RETURN_STRING(LIBINPUT_EVENT_POINTER_BUTTON); ++ CASE_RETURN_STRING(LIBINPUT_EVENT_JOYSTICK_AXIS); ++ CASE_RETURN_STRING(LIBINPUT_EVENT_JOYSTICK_BUTTON); + CASE_RETURN_STRING(LIBINPUT_EVENT_POINTER_AXIS); + CASE_RETURN_STRING(LIBINPUT_EVENT_TOUCH_DOWN); + CASE_RETURN_STRING(LIBINPUT_EVENT_TOUCH_UP); CASE_RETURN_STRING(LIBINPUT_EVENT_TOUCH_MOTION); CASE_RETURN_STRING(LIBINPUT_EVENT_TOUCH_CANCEL); CASE_RETURN_STRING(LIBINPUT_EVENT_TOUCH_FRAME); @@ -4205,7 +4309,7 @@ diff -Naur old/src/libinput.c new/src/libinput.c CASE_RETURN_STRING(LIBINPUT_EVENT_TABLET_TOOL_AXIS); CASE_RETURN_STRING(LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); CASE_RETURN_STRING(LIBINPUT_EVENT_TABLET_TOOL_TIP); -@@ -184,6 +188,10 @@ +@@ -184,6 +190,10 @@ int32_t slot; int32_t seat_slot; struct device_coords point; @@ -4214,9 +4318,9 @@ diff -Naur old/src/libinput.c new/src/libinput.c + struct touch_axis axis; + int32_t tool_type; }; - + struct libinput_event_gesture { -@@ -193,6 +201,7 @@ +@@ -193,6 +203,7 @@ int cancelled; struct normalized_coords delta; struct normalized_coords delta_unaccel; @@ -4224,18 +4328,18 @@ diff -Naur old/src/libinput.c new/src/libinput.c double scale; double angle; }; -@@ -208,6 +217,7 @@ +@@ -208,6 +219,7 @@ struct libinput_tablet_tool *tool; enum libinput_tablet_tool_proximity_state proximity_state; enum libinput_tablet_tool_tip_state tip_state; + int32_t mt_tool_type; }; - + struct libinput_event_tablet_pad { -@@ -392,6 +402,18 @@ +@@ -392,6 +404,18 @@ return (struct libinput_event_touch *) event; } - + +LIBINPUT_EXPORT struct libinput_event_touch * +libinput_event_get_touchpad_event(struct libinput_event *event) +{ @@ -4251,10 +4355,10 @@ diff -Naur old/src/libinput.c new/src/libinput.c LIBINPUT_EXPORT struct libinput_event_gesture * libinput_event_get_gesture_event(struct libinput_event *event) { -@@ -459,6 +481,19 @@ +@@ -459,6 +483,19 @@ return (struct libinput_event_switch *) event; } - + +LIBINPUT_EXPORT int32_t +libinput_event_tablet_tool_get_tool_type(struct libinput_event_tablet_tool *event) +{ @@ -4271,9 +4375,9 @@ diff -Naur old/src/libinput.c new/src/libinput.c LIBINPUT_EXPORT uint32_t libinput_event_keyboard_get_time(struct libinput_event_keyboard *event) { -@@ -851,6 +886,20 @@ +@@ -851,6 +888,20 @@ } - + LIBINPUT_EXPORT double +libinput_event_touch_get_y(struct libinput_event_touch *event) +{ @@ -4292,19 +4396,21 @@ diff -Naur old/src/libinput.c new/src/libinput.c libinput_event_touch_get_y_transformed(struct libinput_event_touch *event, uint32_t height) { -@@ -866,7 +915,7 @@ +@@ -866,7 +917,109 @@ } - + LIBINPUT_EXPORT double -libinput_event_touch_get_y(struct libinput_event_touch *event) +libinput_event_touch_get_tool_x(struct libinput_event_touch *event) - { - struct evdev_device *device = evdev_device(event->base.device); - -@@ -876,9 +925,358 @@ - LIBINPUT_EVENT_TOUCH_DOWN, - LIBINPUT_EVENT_TOUCH_MOTION); - ++{ ++ struct evdev_device *device = evdev_device(event->base.device); ++ ++ require_event_type(libinput_event_get_context(&event->base), ++ event->base.type, ++ 0, ++ LIBINPUT_EVENT_TOUCH_DOWN, ++ LIBINPUT_EVENT_TOUCH_MOTION); ++ + return evdev_convert_to_mm(device->abs.absinfo_x, event->tool_rect.x); +} + @@ -4398,15 +4504,13 @@ diff -Naur old/src/libinput.c new/src/libinput.c +LIBINPUT_EXPORT double +libinput_event_touch_get_tool_height_transformed(struct libinput_event_touch *event, + uint32_t height) -+{ -+ struct evdev_device *device = evdev_device(event->base.device); -+ -+ require_event_type(libinput_event_get_context(&event->base), -+ event->base.type, -+ 0, -+ LIBINPUT_EVENT_TOUCH_DOWN, -+ LIBINPUT_EVENT_TOUCH_MOTION); -+ + { + struct evdev_device *device = evdev_device(event->base.device); + +@@ -876,9 +1029,256 @@ + LIBINPUT_EVENT_TOUCH_DOWN, + LIBINPUT_EVENT_TOUCH_MOTION); + + return evdev_device_transform_y(device, event->tool_rect.h, height); +} + @@ -4489,7 +4593,7 @@ diff -Naur old/src/libinput.c new/src/libinput.c + return evdev_convert_to_mm(device->abs.absinfo_y, event->point.y); } - + +LIBINPUT_EXPORT double +libinput_event_touchpad_get_tool_x(struct libinput_event_touch *event) +{ @@ -4660,10 +4764,10 @@ diff -Naur old/src/libinput.c new/src/libinput.c LIBINPUT_EXPORT uint32_t libinput_event_gesture_get_time(struct libinput_event_gesture *event) { -@@ -1031,6 +1429,18 @@ +@@ -1031,6 +1431,18 @@ return event->angle; } - + +LIBINPUT_EXPORT struct sloted_coords_info * +libinput_event_gesture_get_solt_touches( + struct libinput_event_gesture *event) @@ -4679,9 +4783,9 @@ diff -Naur old/src/libinput.c new/src/libinput.c LIBINPUT_EXPORT int libinput_event_tablet_tool_x_has_changed( struct libinput_event_tablet_tool *event) -@@ -1048,6 +1458,24 @@ +@@ -1048,6 +1460,24 @@ } - + LIBINPUT_EXPORT int +libinput_has_event_led_type(struct libinput_device *device) +{ @@ -4704,10 +4808,10 @@ diff -Naur old/src/libinput.c new/src/libinput.c libinput_event_tablet_tool_y_has_changed( struct libinput_event_tablet_tool *event) { -@@ -1806,11 +2234,8 @@ +@@ -1806,11 +2236,8 @@ /* If we fail, we'll fail next time too */ libinput->quirks_initialized = true; - + - data_path = getenv("LIBINPUT_QUIRKS_DIR"); - if (!data_path) { - data_path = LIBINPUT_QUIRKS_DIR; @@ -4715,10 +4819,10 @@ diff -Naur old/src/libinput.c new/src/libinput.c - } + data_path = (char *)LIBINPUT_QUIRKS_DIR; + override_file = (char *)LIBINPUT_QUIRKS_OVERRIDE_FILE; - + quirks = quirks_init_subsystem(data_path, override_file, -@@ -2311,6 +2736,9 @@ +@@ -2311,6 +2738,9 @@ case LIBINPUT_DEVICE_CAP_SWITCH: capability = "CAP_SWITCH"; break; @@ -4726,9 +4830,9 @@ diff -Naur old/src/libinput.c new/src/libinput.c + capability = "CAP_JOYSTICK"; + break; } - + log_bug_libinput(device->seat->libinput, -@@ -2458,7 +2886,11 @@ +@@ -2458,7 +2888,11 @@ uint64_t time, int32_t slot, int32_t seat_slot, @@ -4740,8 +4844,8 @@ diff -Naur old/src/libinput.c new/src/libinput.c + const struct device_coord_rect *tool_rect) { struct libinput_event_touch *touch_event; - -@@ -2472,6 +2904,10 @@ + +@@ -2472,6 +2906,10 @@ .slot = slot, .seat_slot = seat_slot, .point = *point, @@ -4750,9 +4854,9 @@ diff -Naur old/src/libinput.c new/src/libinput.c + .axis = *axis, + .tool_type = tool_type, }; - + post_device_event(device, time, -@@ -2484,7 +2920,11 @@ +@@ -2484,7 +2922,11 @@ uint64_t time, int32_t slot, int32_t seat_slot, @@ -4764,8 +4868,8 @@ diff -Naur old/src/libinput.c new/src/libinput.c + const struct device_coord_rect *tool_rect) { struct libinput_event_touch *touch_event; - -@@ -2498,6 +2938,10 @@ + +@@ -2498,6 +2940,10 @@ .slot = slot, .seat_slot = seat_slot, .point = *point, @@ -4774,9 +4878,9 @@ diff -Naur old/src/libinput.c new/src/libinput.c + .axis = *axis, + .tool_type = tool_type, }; - + post_device_event(device, time, -@@ -2509,7 +2953,8 @@ +@@ -2509,7 +2955,8 @@ touch_notify_touch_up(struct libinput_device *device, uint64_t time, int32_t slot, @@ -4785,18 +4889,18 @@ diff -Naur old/src/libinput.c new/src/libinput.c + int32_t tool_type) { struct libinput_event_touch *touch_event; - -@@ -2522,6 +2967,7 @@ + +@@ -2522,6 +2969,7 @@ .time = time, .slot = slot, .seat_slot = seat_slot, + .tool_type = tool_type, }; - + post_device_event(device, time, -@@ -2574,6 +3020,90 @@ +@@ -2574,6 +3022,90 @@ } - + void +touchpad_notify_touch_down(struct libinput_device *device, + uint64_t time, @@ -4885,15 +4989,15 @@ diff -Naur old/src/libinput.c new/src/libinput.c tablet_notify_axis(struct libinput_device *device, uint64_t time, struct libinput_tablet_tool *tool, -@@ -2591,6 +3121,7 @@ +@@ -2591,6 +3123,7 @@ .proximity_state = LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN, .tip_state = tip_state, .axes = *axes, + .mt_tool_type = tool->mt_tool_type, }; - + memcpy(axis_event->changed_axes, -@@ -2621,6 +3152,7 @@ +@@ -2621,6 +3154,7 @@ .tip_state = LIBINPUT_TABLET_TOOL_TIP_UP, .proximity_state = proximity_state, .axes = *axes, @@ -4901,7 +5005,7 @@ diff -Naur old/src/libinput.c new/src/libinput.c }; memcpy(proximity_event->changed_axes, changed_axes, -@@ -2650,6 +3182,7 @@ +@@ -2650,6 +3184,7 @@ .tip_state = tip_state, .proximity_state = LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN, .axes = *axes, @@ -4909,15 +5013,15 @@ diff -Naur old/src/libinput.c new/src/libinput.c }; memcpy(tip_event->changed_axes, changed_axes, -@@ -2688,6 +3221,7 @@ +@@ -2688,6 +3223,7 @@ .proximity_state = LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN, .tip_state = tip_state, .axes = *axes, + .mt_tool_type = tool->mt_tool_type, }; - + post_device_event(device, -@@ -2814,6 +3348,7 @@ +@@ -2814,6 +3350,7 @@ int cancelled, const struct normalized_coords *delta, const struct normalized_coords *unaccel, @@ -4925,10 +5029,10 @@ diff -Naur old/src/libinput.c new/src/libinput.c double scale, double angle) { -@@ -2834,6 +3369,12 @@ +@@ -2834,6 +3371,12 @@ .angle = angle, }; - + + if (solt_touches != NULL) { + gesture_event->solt_touches = *solt_touches; + } else { @@ -4938,7 +5042,7 @@ diff -Naur old/src/libinput.c new/src/libinput.c post_device_event(device, time, type, &gesture_event->base); } -@@ -2844,9 +3385,10 @@ +@@ -2844,9 +3387,10 @@ enum libinput_event_type type, int finger_count, const struct normalized_coords *delta, @@ -4950,38 +5054,85 @@ diff -Naur old/src/libinput.c new/src/libinput.c + gesture_notify(device, time, type, finger_count, 0, delta, unaccel, solt_touches, 0.0, 0.0); } - -@@ -2859,7 +3401,7 @@ + +@@ -2859,7 +3403,7 @@ const struct normalized_coords zero = { 0.0, 0.0 }; - + gesture_notify(device, time, LIBINPUT_EVENT_GESTURE_SWIPE_END, - finger_count, cancelled, &zero, &zero, 0.0, 0.0); + finger_count, cancelled, &zero, &zero, NULL, 0.0, 0.0); } - + void -@@ -2873,7 +3415,7 @@ +@@ -2873,7 +3417,7 @@ double angle) { gesture_notify(device, time, type, finger_count, 0, - delta, unaccel, scale, angle); + delta, unaccel, NULL, scale, angle); } - + void -@@ -2886,7 +3428,7 @@ +@@ -2886,7 +3430,7 @@ const struct normalized_coords zero = { 0.0, 0.0 }; - + gesture_notify(device, time, LIBINPUT_EVENT_GESTURE_PINCH_END, - finger_count, cancelled, &zero, &zero, scale, 0.0); + finger_count, cancelled, &zero, &zero, NULL, scale, 0.0); } - + void -@@ -2972,6 +3514,92 @@ +@@ -2919,6 +3463,46 @@ + #endif + } + ++void ++joysticks_notify_axis(struct libinput_device *device, ++ uint64_t time, ++ uint32_t axes, ++ const struct joystick_axis_abs_infos *axis_abs) ++{ ++ struct libinput_event_joystick_axis* joystick_axis_event; ++ ++ joystick_axis_event = zalloc(sizeof * joystick_axis_event); ++ ++ *joystick_axis_event = (struct libinput_event_joystick_axis){ ++ .type = EV_ABS, ++ .time = time, ++ .axis_value_mask = axes, ++ .abs_throttle = axis_abs->abs_throttle, ++ .abs_hat0x = axis_abs->abs_hat0x, ++ .abs_hat0y = axis_abs->abs_hat0y, ++ .abs_x = axis_abs->abs_x, ++ .abs_y = axis_abs->abs_y, ++ .abs_z = axis_abs->abs_z, ++ .abs_rx = axis_abs->abs_rx, ++ .abs_ry = axis_abs->abs_ry, ++ .abs_rz = axis_abs->abs_rz, ++ .abs_gas = axis_abs->abs_gas, ++ .abs_brake = axis_abs->abs_brake, ++ }; ++ libinput_log_printf("code:%d value:%d \r\n", axis_abs->abs_x.code, axis_abs->abs_x.value); ++ libinput_log_printf("code:%d value:%d \r\n", axis_abs->abs_y.code, axis_abs->abs_y.value); ++ libinput_log_printf("code:%d value:%d \r\n", axis_abs->abs_z.code, axis_abs->abs_z.value); ++ libinput_log_printf("code:%d value:%d \r\n", axis_abs->abs_rz.code, axis_abs->abs_rz.value); ++ libinput_log_printf("code:%d value:%d \r\n", axis_abs->abs_gas.code, axis_abs->abs_gas.value); ++ libinput_log_printf("code:%d value:%d \r\n", axis_abs->abs_brake.code, axis_abs->abs_brake.value); ++ libinput_log_printf("code:%d value:%d \r\n", axis_abs->abs_hat0x.code, axis_abs->abs_hat0x.value); ++ libinput_log_printf("code:%d value:%d \r\n", axis_abs->abs_hat0y.code, axis_abs->abs_hat0y.value); ++ libinput_log_printf("code:%d value:%d \r\n", axis_abs->abs_throttle.code, axis_abs->abs_throttle.value); ++ post_device_event(device, time, ++ LIBINPUT_EVENT_JOYSTICK_AXIS, ++ &joystick_axis_event->base); ++} ++ + static void + libinput_post_event(struct libinput *libinput, + struct libinput_event *event) +@@ -2972,6 +3556,96 @@ libinput->events_in = (libinput->events_in + 1) % libinput->events_len; } - + + +LIBINPUT_EXPORT void +libinput_post_handle_event(struct libinput* libinput, struct libinput_event* event) @@ -4995,7 +5146,7 @@ diff -Naur old/src/libinput.c new/src/libinput.c + require_event_type(libinput_event_get_context(event), + event->type, + NULL, -+ LIBINPUT_EVENT_POINTER_BUTTON); ++ LIBINPUT_EVENT_JOYSTICK_BUTTON); + + return (struct libinput_event_joystick_button*)event; +} @@ -5006,7 +5157,7 @@ diff -Naur old/src/libinput.c new/src/libinput.c + require_event_type(libinput_event_get_context(event), + event->type, + NULL, -+ LIBINPUT_EVENT_POINTER_AXIS); ++ LIBINPUT_EVENT_JOYSTICK_AXIS); + + return (struct libinput_event_joystick_axis*)event; +} @@ -5061,6 +5212,10 @@ diff -Naur old/src/libinput.c new/src/libinput.c + return &event->abs_hat0x; + case LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_HAT0Y: + return &event->abs_hat0y; ++ case LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_GAS: ++ return &event->abs_gas; ++ case LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_BRAKE: ++ return &event->abs_brake; + default: + break; + } @@ -5071,10 +5226,10 @@ diff -Naur old/src/libinput.c new/src/libinput.c LIBINPUT_EXPORT struct libinput_event * libinput_get_event(struct libinput *libinput) { -@@ -3055,12 +3683,169 @@ +@@ -3055,12 +3729,169 @@ return evdev_device_get_sysname((struct evdev_device *) device); } - + +LIBINPUT_EXPORT const char* +libinput_device_get_phys(struct libinput_device* device) +{ @@ -5100,7 +5255,7 @@ diff -Naur old/src/libinput.c new/src/libinput.c { return evdev_device_get_name((struct evdev_device *) device); } - + +LIBINPUT_EXPORT enum evdev_device_udev_tags +libinput_device_get_tags(struct libinput_device* device) +{ @@ -5241,9 +5396,9 @@ diff -Naur old/src/libinput.c new/src/libinput.c LIBINPUT_EXPORT unsigned int libinput_device_get_id_product(struct libinput_device *device) { -@@ -3148,6 +3933,15 @@ +@@ -3148,6 +3979,15 @@ } - + LIBINPUT_EXPORT int +libinput_device_touch_btn_tool_type_down(struct libinput_device *device, int32_t btnToolType) +{ @@ -5257,9 +5412,9 @@ diff -Naur old/src/libinput.c new/src/libinput.c libinput_device_switch_has_switch(struct libinput_device *device, enum libinput_switch sw) { -@@ -3347,6 +4141,19 @@ +@@ -3347,6 +4187,19 @@ } - + LIBINPUT_EXPORT struct libinput_event * +libinput_event_touchpad_get_base_event(struct libinput_event_touch *event) +{ @@ -5277,7 +5432,7 @@ diff -Naur old/src/libinput.c new/src/libinput.c libinput_event_gesture_get_base_event(struct libinput_event_gesture *event) { require_event_type(libinput_event_get_context(&event->base), -@@ -4378,3 +5185,162 @@ +@@ -4378,3 +5231,162 @@ } } #endif @@ -5291,7 +5446,7 @@ diff -Naur old/src/libinput.c new/src/libinput.c + require_event_type(libinput_event_get_context(event), + event->type, + NULL, -+ LIBINPUT_EVENT_POINTER_BUTTON); ++ LIBINPUT_EVENT_JOYSTICK_BUTTON); + + return (struct libinput_event_joystick_button*)event; +} @@ -5305,7 +5460,7 @@ diff -Naur old/src/libinput.c new/src/libinput.c + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, -+ LIBINPUT_EVENT_POINTER_BUTTON); ++ LIBINPUT_EVENT_JOYSTICK_BUTTON); + + return event->time; +} @@ -5319,12 +5474,12 @@ diff -Naur old/src/libinput.c new/src/libinput.c + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, -+ LIBINPUT_EVENT_POINTER_BUTTON); ++ LIBINPUT_EVENT_JOYSTICK_BUTTON); + + return event->key; +} + -+LIBINPUT_EXPORT enum libinput_key_state ++LIBINPUT_EXPORT enum libinput_button_state +libinput_event_joystick_button_get_key_state(struct libinput_event_joystick_button* event) +{ + if (!event) @@ -5333,7 +5488,7 @@ diff -Naur old/src/libinput.c new/src/libinput.c + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, -+ LIBINPUT_EVENT_POINTER_BUTTON); ++ LIBINPUT_EVENT_JOYSTICK_BUTTON); + + return event->state; +} @@ -5347,7 +5502,7 @@ diff -Naur old/src/libinput.c new/src/libinput.c + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, -+ LIBINPUT_EVENT_POINTER_BUTTON); ++ LIBINPUT_EVENT_JOYSTICK_BUTTON); + + return event->seat_key_count; +} @@ -5361,7 +5516,7 @@ diff -Naur old/src/libinput.c new/src/libinput.c + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, -+ LIBINPUT_EVENT_POINTER_BUTTON); ++ LIBINPUT_EVENT_JOYSTICK_BUTTON); + + return event->value; +} @@ -5464,11 +5619,11 @@ diff -Naur old/src/libinput.h new/src/libinput.h + EVDEV_UDEV_TAG_TRACKBALL = 1 << 10, + EVDEV_UDEV_TAG_SWITCH = 1 << 11, }; - + /** @@ -315,6 +331,49 @@ }; - + /** + * @ingroup event_joystick + * @@ -5478,7 +5633,7 @@ diff -Naur old/src/libinput.h new/src/libinput.h + * @since 1.16.4 + */ +enum libinput_joystick_axis_source { -+ LIBINPUT_JOYSTICK_AXIS_SOURCE_UNKNOW = 0, ++ LIBINPUT_JOYSTICK_AXIS_SOURCE_UNKNOWN = 0, + LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_X = 1 << 0, + LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_Y = 1 << 1, + LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_Z = 1 << 2, @@ -5519,7 +5674,7 @@ diff -Naur old/src/libinput.h new/src/libinput.h @@ -387,6 +446,17 @@ LIBINPUT_TABLET_TOOL_TIP_DOWN = 1, }; - + +struct libinput_event_joystick_axis_abs_info { + int32_t code; + int32_t value; @@ -5534,10 +5689,20 @@ diff -Naur old/src/libinput.h new/src/libinput.h /** * @defgroup tablet_pad_modes Tablet pad modes * -@@ -754,6 +824,10 @@ +@@ -744,6 +814,9 @@ + LIBINPUT_EVENT_POINTER_BUTTON, + LIBINPUT_EVENT_POINTER_AXIS, + ++ LIBINPUT_EVENT_JOYSTICK_BUTTON = 450, ++ LIBINPUT_EVENT_JOYSTICK_AXIS, ++ + LIBINPUT_EVENT_TOUCH_DOWN = 500, + LIBINPUT_EVENT_TOUCH_UP, + LIBINPUT_EVENT_TOUCH_MOTION, +@@ -754,6 +827,10 @@ */ LIBINPUT_EVENT_TOUCH_FRAME, - + + LIBINPUT_EVENT_TOUCHPAD_DOWN = 550, + LIBINPUT_EVENT_TOUCHPAD_UP, + LIBINPUT_EVENT_TOUCHPAD_MOTION, @@ -5545,7 +5710,7 @@ diff -Naur old/src/libinput.h new/src/libinput.h /** * One or more axes have changed state on a device with the @ref * LIBINPUT_DEVICE_CAP_TABLET_TOOL capability. This event is only sent -@@ -1001,6 +1075,19 @@ +@@ -1001,6 +1078,19 @@ /** * @ingroup event * @@ -5565,9 +5730,9 @@ diff -Naur old/src/libinput.h new/src/libinput.h * Return the gesture event that is this input event. If the event type does * not match the gesture event types, this function returns NULL. * -@@ -1673,6 +1760,120 @@ +@@ -1673,6 +1763,120 @@ uint32_t height); - + /** + * @brief 获取触摸屏的工具类型区域属性 + */ @@ -5686,9 +5851,9 @@ diff -Naur old/src/libinput.h new/src/libinput.h * @ingroup event_touch * * @return The generic libinput_event of this event -@@ -1681,6 +1882,228 @@ +@@ -1681,6 +1885,228 @@ libinput_event_touch_get_base_event(struct libinput_event_touch *event); - + /** + * @defgroup event_touch Touchpad events + * @@ -5915,9 +6080,9 @@ diff -Naur old/src/libinput.h new/src/libinput.h * @defgroup event_gesture Gesture events * * Gesture events are generated when a gesture is recognized on a touchpad. -@@ -1893,6 +2316,42 @@ +@@ -1893,6 +2319,42 @@ libinput_event_gesture_get_angle_delta(struct libinput_event_gesture *event); - + /** + * 获取带slot的touches信息, 仅支持LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE + */ @@ -5958,7 +6123,7 @@ diff -Naur old/src/libinput.h new/src/libinput.h * @defgroup event_tablet Tablet events * * Events that come from tools on tablet devices. For events from the pad, -@@ -2620,6 +3079,19 @@ +@@ -2620,6 +3082,19 @@ /** * @ingroup event_tablet * @@ -5978,10 +6143,10 @@ diff -Naur old/src/libinput.h new/src/libinput.h * Return the high-level tool type for a tool object. * * The high level tool describes general interaction expected with the tool. -@@ -3466,6 +3938,46 @@ +@@ -3466,6 +3941,56 @@ int libinput_dispatch(struct libinput *libinput); - + +/**************************************************************************** +* @brief : brief +* @author : fms @@ -6002,9 +6167,19 @@ diff -Naur old/src/libinput.h new/src/libinput.h +* @inparam : +* @outparam : +*****************************************************************************/ -+struct libinput_event_joystick_axis * -+libinput_event_get_joystick_axis_event(struct libinput_event *event); ++struct libinput_event_joystick_button* ++libinput_event_get_joystick_button_event(struct libinput_event* event); + ++/**************************************************************************** ++* @brief : get joystick axis event ++* @author : fms ++* @date : 2021/3/12 10:56 ++* @version : ver 1.0 ++* @inparam : ++* @outparam : ++*****************************************************************************/ ++struct libinput_event_joystick_axis* ++ libinput_event_get_joystick_axis_event(struct libinput_event* event); +/** + * @brief 获取轴事件的时间 + */ @@ -6025,10 +6200,10 @@ diff -Naur old/src/libinput.h new/src/libinput.h /** * @ingroup base * -@@ -3936,6 +4448,42 @@ +@@ -3936,6 +4461,42 @@ const char * libinput_device_get_name(struct libinput_device *device); - + +/** @brief 获取设备类型*/ +enum evdev_device_udev_tags +libinput_device_get_tags(struct libinput_device* device); @@ -6068,9 +6243,9 @@ diff -Naur old/src/libinput.h new/src/libinput.h /** * @ingroup device * -@@ -4146,6 +4694,12 @@ +@@ -4146,6 +4707,12 @@ libinput_device_touch_get_touch_count(struct libinput_device *device); - + /** + * @brief 获取触摸屏工具类型按钮是否按下 + */ @@ -6081,10 +6256,10 @@ diff -Naur old/src/libinput.h new/src/libinput.h * @ingroup device * * Check if a @ref LIBINPUT_DEVICE_CAP_SWITCH device has a switch of the -@@ -5928,7 +6482,102 @@ +@@ -5928,7 +6495,102 @@ unsigned int libinput_device_config_rotation_get_default_angle(struct libinput_device *device); - + +/** + * @ingroup event + * @@ -6177,7 +6352,7 @@ diff -Naur old/src/libinput.h new/src/libinput.h +const char* +libinput_device_get_uniq(struct libinput_device* device); + -+enum libinput_key_state ++enum libinput_button_state +libinput_event_joystick_button_get_key_state(struct libinput_event_joystick_button* event); #ifdef __cplusplus } @@ -6188,7 +6363,7 @@ diff -Naur old/src/udev-seat.c new/src/udev-seat.c --- old/src/udev-seat.c 2021-01-01 00:00:00.000000000 +0800 +++ new/src/udev-seat.c 2021-01-01 00:00:00.000000000 +0800 @@ -189,6 +189,7 @@ - + /* Skip unconfigured device. udev will send an event * when device is fully configured */ +/* @@ -6206,7 +6381,7 @@ diff -Naur old/src/udev-seat.c new/src/udev-seat.c + sysname, + udev_device_get_devnode(device)); + } - + if (device_added(device, input, NULL) < 0) { udev_device_unref(device); diff -Naur old/src/util-strings.h new/src/util-strings.h @@ -6215,10 +6390,10 @@ diff -Naur old/src/util-strings.h new/src/util-strings.h @@ -281,7 +281,7 @@ if (npairs == 0) goto error; - + - result = zalloc(npairs * sizeof *result); + result = (struct key_value_double *)zalloc(npairs * sizeof *result); - + for (pair = pairs; *pair; pair++) { char **kv = strv_from_string(*pair, kv_separator); diff -Naur old/src/util-time.h new/src/util-time.h @@ -6271,20 +6446,29 @@ diff -Naur old/tools/libinput-debug-events.c new/tools/libinput-debug-events.c case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN: type = "GESTURE_SWIPE_BEGIN"; break; -@@ -274,6 +283,10 @@ +@@ -146,6 +155,8 @@ + case LIBINPUT_EVENT_SWITCH_TOGGLE: + type = "SWITCH_TOGGLE"; + break; ++ default: ++ break; + } + + prefix = (last_device != dev) ? '-' : ' '; +@@ -274,6 +285,10 @@ LIBINPUT_DEVICE_CAP_SWITCH)) printq("S"); - + + if (libinput_device_has_capability(dev, + LIBINPUT_DEVICE_CAP_JOYSTICK)) + printq("JOYSTICK"); + if (libinput_device_get_size(dev, &w, &h) == 0) printq(" size %.0fx%.0fmm", w, h); - -@@ -530,6 +543,15 @@ + +@@ -530,6 +545,15 @@ } - + static void +print_touchpad_event_without_coords(struct libinput_event *ev) +{ @@ -6298,9 +6482,9 @@ diff -Naur old/tools/libinput-debug-events.c new/tools/libinput-debug-events.c print_proximity_event(struct libinput_event *ev) { struct libinput_event_tablet_tool *t = libinput_event_get_tablet_tool_event(ev); -@@ -647,6 +669,21 @@ +@@ -647,6 +671,21 @@ } - + static void +print_touchpad_event_with_coords(struct libinput_event *ev) +{ @@ -6320,7 +6504,7 @@ diff -Naur old/tools/libinput-debug-events.c new/tools/libinput-debug-events.c print_gesture_event_without_coords(struct libinput_event *ev) { struct libinput_event_gesture *t = libinput_event_get_gesture_event(ev); -@@ -869,6 +906,15 @@ +@@ -869,6 +908,15 @@ case LIBINPUT_EVENT_TOUCH_FRAME: print_touch_event_without_coords(ev); break; @@ -6336,6 +6520,15 @@ diff -Naur old/tools/libinput-debug-events.c new/tools/libinput-debug-events.c case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN: print_gesture_event_without_coords(ev); break; +@@ -914,6 +962,8 @@ + case LIBINPUT_EVENT_SWITCH_TOGGLE: + print_switch_event(ev); + break; ++ default: ++ break; + } + + libinput_event_destroy(ev); diff -Naur old/tools/libinput-record.c new/tools/libinput-record.c --- old/tools/libinput-record.c 2021-01-01 00:00:00.000000000 +0800 +++ new/tools/libinput-record.c 2021-01-01 00:00:00.000000000 +0800 @@ -6344,16 +6537,16 @@ diff -Naur old/tools/libinput-record.c new/tools/libinput-record.c #include "util-input-event.h" #include "util-macros.h" +#include "hm_missing.h" - + static const int FILE_VERSION_NUMBER = 1; - + diff -Naur old/udev/libinput-device-group.c new/udev/libinput-device-group.c --- old/udev/libinput-device-group.c 2021-01-01 00:00:00.000000000 +0800 +++ new/udev/libinput-device-group.c 2021-01-01 00:00:00.000000000 +0800 @@ -138,7 +138,7 @@ *product_id = pid; best_dist = dist; - + - free(*phys_attr); + free((char*)*phys_attr); *phys_attr = strdup(phys); diff --git a/patch/diff_mtdev_hdf/mtdev_hdf_0000.diff b/patch/diff_mtdev_hdf/mtdev_hdf_0000.diff deleted file mode 100644 index 9544c1dbce33b8d7e8a224230630f5f5899e04fb..0000000000000000000000000000000000000000 --- a/patch/diff_mtdev_hdf/mtdev_hdf_0000.diff +++ /dev/null @@ -1,251 +0,0 @@ -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. - -diff -Naur old/BUILD.gn new/BUILD.gn ---- old/BUILD.gn 2021-01-01 00:00:00.000000000 +0800 -+++ new/BUILD.gn 2021-01-01 00:00:00.000000000 +0800 -@@ -23,7 +23,7 @@ - ] - } - --ohos_shared_library("libmtdev") { -+ohos_shared_library("libmtdev-hdf") { - sources = [ - "src/caps.c", - "src/core.c", -diff -Naur old/include/mtdev.h new/include/mtdev.h ---- old/include/mtdev.h 2021-01-01 00:00:00.000000000 +0800 -+++ new/include/mtdev.h 2021-01-01 00:00:00.000000000 +0800 -@@ -77,6 +77,21 @@ - #define MT_ID_MIN 0 - #define MT_ID_MAX 65535 - -+typedef int (*mtdev_ioctl)(int hdiindex,int cmd, void * iobuff); -+ -+/** -+ * mtdev_new_open - create and open a new mtdev -+ * @fd: file descriptor of the kernel device -+ * -+ * Create a new mtdev and open the conversion. -+ * -+ * Returns zero in case of failure. -+ * -+ * This call combines the plumbing functions mtdev_new() and -+ * mtdev_open(). -+ */ -+struct mtdev *mtdev_new_open_hdi(int fd,mtdev_ioctl func); -+ - /** - * mtdev_new_open - create and open a new mtdev - * @fd: file descriptor of the kernel device -diff -Naur old/src/caps.c new/src/caps.c ---- old/src/caps.c 2021-01-01 00:00:00.000000000 +0800 -+++ new/src/caps.c 2021-01-01 00:00:00.000000000 +0800 -@@ -35,6 +35,8 @@ - #define LONG_BITS (sizeof(long) * 8) - #define NLONGS(x) (((x) + LONG_BITS - 1) / LONG_BITS) - -+typedef int (*mtdev_ioctl)(int hdiindex,int cmd, void * iobuff); -+ - static inline int getbit(const unsigned long *map, int key) - { - return (map[key / LONG_BITS] >> (key % LONG_BITS)) & 0x01; -@@ -47,6 +49,13 @@ - return rc >= 0; - } - -+static int hdigetabs(struct input_absinfo *abs, int key, int fd,mtdev_ioctl func) -+{ -+ int rc; -+ rc = func(fd, EVIOCGABS(key), abs); -+ return rc >= 0; -+} -+ - static struct input_absinfo *get_info(struct mtdev *dev, int code) - { - int ix; -@@ -70,6 +79,13 @@ - mtdev_set_mt_event(dev, code, has); - } - -+static void hdiset_info(struct mtdev *dev, int code, -+ const unsigned long *bits, int fd,mtdev_ioctl func) -+{ -+ int has = getbit(bits, code) && hdigetabs(get_info(dev, code), code, fd,func); -+ mtdev_set_mt_event(dev, code, has); -+} -+ - static void default_fuzz(struct mtdev *dev, int code, int sn) - { - struct input_absinfo *abs = get_info(dev, code); -@@ -78,6 +94,29 @@ - abs->fuzz = (abs->maximum - abs->minimum) / sn; - } - -+static int hdimtdev_set_slots(struct mtdev *dev, int fd,mtdev_ioctl func) -+{ -+ struct { unsigned code; int values[DIM_FINGER]; } req; -+ struct mtdev_state *state = dev->state; -+ int rc, i, s, nslot; -+ -+ nslot = mtdev_get_abs_maximum(dev, ABS_MT_SLOT) + 1; -+ -+ for (i = 0; i < MT_ABS_SIZE; i++) { -+ req.code = mtdev_mt2abs(i); -+ if (!mtdev_has_mt_event(dev, req.code)) -+ continue; -+ rc = func(fd, EVIOCGMTSLOTS(sizeof(req)), &req); -+ if (rc < 0) -+ return rc; -+ for (s = 0; s < DIM_FINGER && s < nslot; s++) -+ set_sval(&state->data[s], i, req.values[s]); -+ } -+ -+ return 0; -+} -+ -+ - static int mtdev_set_slots(struct mtdev *dev, int fd) - { - struct { unsigned code; int values[DIM_FINGER]; } req; -@@ -99,6 +138,48 @@ - - return 0; - } -+ -+int mtdev_configure_hdi(struct mtdev *dev, int fd,mtdev_ioctl func) -+{ -+ unsigned long absbits[NLONGS(ABS_MAX)]; -+ int rc, i; -+ -+ rc = func(fd, EVIOCGBIT(EV_ABS, sizeof(absbits)), absbits); -+ if (rc < 0) -+ return rc; -+ -+ hdiset_info(dev, ABS_MT_SLOT, absbits, fd,func); -+ for (i = 0; i < MT_ABS_SIZE; i++) -+ hdiset_info(dev, mtdev_mt2abs(i), absbits, fd,func); -+ -+ dev->has_mtdata = mtdev_has_mt_event(dev, ABS_MT_POSITION_X) && -+ mtdev_has_mt_event(dev, ABS_MT_POSITION_Y); -+ -+ if (!mtdev_has_mt_event(dev, ABS_MT_POSITION_X)) -+ hdigetabs(get_info(dev, ABS_MT_POSITION_X), ABS_X, fd,func); -+ if (!mtdev_has_mt_event(dev, ABS_MT_POSITION_Y)) -+ hdigetabs(get_info(dev, ABS_MT_POSITION_Y), ABS_Y, fd,func); -+ if (!mtdev_has_mt_event(dev, ABS_MT_PRESSURE)) -+ hdigetabs(get_info(dev, ABS_MT_PRESSURE), ABS_PRESSURE, fd,func); -+ -+ if (!mtdev_has_mt_event(dev, ABS_MT_TRACKING_ID)) { -+ mtdev_set_abs_minimum(dev, ABS_MT_TRACKING_ID, MT_ID_MIN); -+ mtdev_set_abs_maximum(dev, ABS_MT_TRACKING_ID, MT_ID_MAX); -+ } -+ -+ default_fuzz(dev, ABS_MT_POSITION_X, SN_COORD); -+ default_fuzz(dev, ABS_MT_POSITION_Y, SN_COORD); -+ default_fuzz(dev, ABS_MT_TOUCH_MAJOR, SN_WIDTH); -+ default_fuzz(dev, ABS_MT_TOUCH_MINOR, SN_WIDTH); -+ default_fuzz(dev, ABS_MT_WIDTH_MAJOR, SN_WIDTH); -+ default_fuzz(dev, ABS_MT_WIDTH_MINOR, SN_WIDTH); -+ default_fuzz(dev, ABS_MT_ORIENTATION, SN_ORIENT); -+ -+ if (dev->has_slot) -+ hdimtdev_set_slots(dev, fd,func); -+ -+ return 0; -+} - - int mtdev_configure(struct mtdev *dev, int fd) - { -diff -Naur old/src/common.h new/src/common.h ---- old/src/common.h 2021-01-01 00:00:00.000000000 +0800 -+++ new/src/common.h 2021-01-01 00:00:00.000000000 +0800 -@@ -95,6 +95,8 @@ - */ - #define LEGACY_API_NUM_MT_AXES 11 - -+typedef int (*mtdev_ioctl)(int hdiindex,int cmd, void * iobuff); -+ - /** - * struct mtdev - represents an input MT device - * @has_mtdata: true if the device has MT capabilities -diff -Naur old/src/core.c new/src/core.c ---- old/src/core.c 2021-01-01 00:00:00.000000000 +0800 -+++ new/src/core.c 2021-01-01 00:00:00.000000000 +0800 -@@ -36,6 +36,8 @@ - #define input_event_usec time.tv_usec - #endif - -+typedef int (*mtdev_ioctl)(int hdiindex,int cmd, void * iobuff); -+ - static inline int istouch(const struct mtdev_slot *data, - const struct mtdev *dev) - { -@@ -382,6 +384,36 @@ - return ret; - } - -+extern int mtdev_configure_hdi(struct mtdev *dev, int fd,mtdev_ioctl func); -+ -+struct mtdev *mtdev_new_open_hdi(int fd,mtdev_ioctl func) -+{ -+ struct mtdev *dev; -+ int ret; -+ -+ dev = mtdev_new(); -+ if (!dev) -+ return NULL; -+ -+ if (!dev || fd < 0) -+ goto error; -+ -+ ret = mtdev_init(dev); -+ if (ret) -+ goto error; -+ ret = mtdev_configure_hdi(dev, fd,func); -+ -+ if (ret) -+ goto error; -+ -+ return dev; -+ -+error: -+ mtdev_close(dev); -+ mtdev_delete(dev); -+ return NULL; -+} -+ - struct mtdev *mtdev_new_open(int fd) - { - struct mtdev *dev; -diff -Naur old/src/iobuf.c new/src/iobuf.c ---- old/src/iobuf.c 2021-01-01 00:00:00.000000000 +0800 -+++ new/src/iobuf.c 2021-01-01 00:00:00.000000000 +0800 -@@ -65,6 +65,17 @@ - return evbuf_empty(&dev->state->outbuf); - } - -+int mtdev_count(struct mtdev *dev) -+{ -+ return dev->state->outbuf.head - dev->state->outbuf.tail; -+} -+ -+ -+int mtdev_countin(struct mtdev *dev) -+{ -+ return dev->state->inbuf.head - dev->state->inbuf.tail; -+} -+ - void mtdev_get_event(struct mtdev *dev, struct input_event* ev) - { - evbuf_get(&dev->state->outbuf, ev); diff --git a/patch/prebuild_eudev/rules.d/50-udev-default.rules b/patch/prebuild_eudev/rules.d/50-udev-default.rules index f7815fa7c1ebf6a0adc3ad71e36c4c2402d72a39..a64fbd405da34b39d43db210b7e8e70669cee7c5 100644 --- a/patch/prebuild_eudev/rules.d/50-udev-default.rules +++ b/patch/prebuild_eudev/rules.d/50-udev-default.rules @@ -79,7 +79,7 @@ SUBSYSTEM=="aoe", KERNEL=="err", MODE="0440" KERNEL=="rfkill", MODE="0664" KERNEL=="tun", MODE="0666", OPTIONS+="static_node=net/tun" -KERNEL=="fuse", MODE="0666", OPTIONS+="static_node=fuse" +KERNEL=="fuse", MODE="0660", OPTIONS+="static_node=fuse" # The static_node is required on s390x and ppc (they are using MODULE_ALIAS) KERNEL=="kvm", GROUP="kvm", MODE="0660", OPTIONS+="static_node=kvm" diff --git a/patch/prebuild_eudev/rules.d/99-fuse.rules b/patch/prebuild_eudev/rules.d/99-fuse.rules index 958511146e7c33e25273a8240f8d9b88cc0d7be1..bda279d13808fc5e5c4f8990b3c6fb49cb0b1227 100644 --- a/patch/prebuild_eudev/rules.d/99-fuse.rules +++ b/patch/prebuild_eudev/rules.d/99-fuse.rules @@ -1 +1 @@ -KERNEL=="fuse", MODE="0666" +KERNEL=="fuse", MODE="0660" diff --git a/service/BUILD.gn b/service/BUILD.gn index ea69d60e165230314494be063c58e9cf354213d0..5e3ccd178d7113334cb6547b5303f5cbb6522a45 100644 --- a/service/BUILD.gn +++ b/service/BUILD.gn @@ -13,11 +13,22 @@ import("//build/ohos.gni") import("//foundation/multimodalinput/input/multimodalinput_mini.gni") + +defines = input_default_defines + mmi_service_path = "${mmi_path}/service" +ohos_prebuilt_etc("mmi_device_config.ini") { + source = "mmi_device_config.ini" + relative_install_dir = "." + subsystem_name = "multimodalinput" + part_name = "input" +} + config("libmmi_server_config") { include_dirs = [ "input_device_cooperate/include", + "device_config/include", "device_manager/include", "device_scalability/include", "delegate_task/include", @@ -54,404 +65,30 @@ config("libmmi_server_config") { "//third_party/cJSON", ] - if (input_feature_input_cooperation) { - include_dirs += [ - "input_device_cooperate/include", - "//foundation/deviceprofile/device_profile_core/interfaces/innerkits/core/include", - "//foundation/distributedhardware/device_manager/interfaces/inner_kits/native_cpp/include", - ] - } - - if (input_feature_hdf) { - include_dirs += [ - "hdf_adapter/include", - "hdi_inject/include", - "$root_out_dir/diff_libinput_mmi/export_include", - "//third_party/eudev/export_include/", - "$root_out_dir/diff_libevdev_hdf/export_include", - "$root_out_dir/diff_libinput_mmi/include/linux", - ] - } - - defines = [] - - if (input_feature_debug) { - defines += [ "OHOS_BUILD_MMI_DEBUG" ] - } - - if (input_feature_libinput) { - defines += [ "OHOS_BUILD_LIBINPUT" ] - } - - if (input_feature_hdf) { - defines += [ "OHOS_BUILD_HDF" ] - } - if (input_feature_combination_key) { defines += [ "OHOS_BUILD_ENABLE_COMBINATION_KEY" ] } - if (input_feature_pointer_drawing) { - defines += [ "OHOS_BUILD_ENABLE_POINTER_DRAWING" ] - } - - if (input_feature_interceptor) { - defines += [ "OHOS_BUILD_ENABLE_INTERCEPTOR" ] - } - if (resource_schedule_service_enabled) { defines += [ "OHOS_RSS_CLIENT" ] } - if (input_feature_pointer_drawing) { - defines += [ "OHOS_BUILD_ENABLE_POINTER_DRAWING" ] - } - if (input_feature_keyboard) { - defines += [ "OHOS_BUILD_ENABLE_KEYBOARD" ] - } - - if (input_feature_mouse) { - defines += [ "OHOS_BUILD_ENABLE_POINTER" ] - } - - if (input_feature_touchscreen) { - defines += [ "OHOS_BUILD_ENABLE_TOUCH" ] - } - if (input_feature_monitor) { - defines += [ "OHOS_BUILD_ENABLE_MONITOR" ] - } - if (input_feature_input_cooperation) { - defines += [ "OHOS_BUILD_ENABLE_COOPERATE" ] - } - - if (input_feature_joystick) { - defines += [ "OHOS_BUILD_ENABLE_JOYSTICK" ] + include_dirs += [ + "input_device_cooperate/include", + "//foundation/deviceprofile/device_profile_core/interfaces/innerkits/core/include", + "//foundation/distributedhardware/device_manager/interfaces/inner_kits/native_cpp/include", + ] } } -ohos_prebuilt_etc("multimodalinput_config_ability.json") { - source = "key_command/etc/ability_launch_config.json" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput" -} - -ohos_prebuilt_etc("drawing_pointer_image_Default") { - source = "//foundation/multimodalinput/input/util/source_icon/Default.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_East") { - source = "//foundation/multimodalinput/input/util/source_icon/East.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_West") { - source = "//foundation/multimodalinput/input/util/source_icon/West.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_South") { - source = "//foundation/multimodalinput/input/util/source_icon/South.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_North") { - source = "//foundation/multimodalinput/input/util/source_icon/North.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_West_East") { - source = "//foundation/multimodalinput/input/util/source_icon/West_East.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_North_South") { - source = "//foundation/multimodalinput/input/util/source_icon/North_South.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_North_East") { - source = "//foundation/multimodalinput/input/util/source_icon/North_East.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_North_West") { - source = "//foundation/multimodalinput/input/util/source_icon/North_West.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_South_East") { - source = "//foundation/multimodalinput/input/util/source_icon/South_East.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_South_West") { - source = "//foundation/multimodalinput/input/util/source_icon/South_West.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_North_East_South_West") { - source = "//foundation/multimodalinput/input/util/source_icon/North_East_South_West.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_North_West_South_East") { - source = "//foundation/multimodalinput/input/util/source_icon/North_West_South_East.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_Cross") { - source = "//foundation/multimodalinput/input/util/source_icon/Cross.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_Copy") { - source = "//foundation/multimodalinput/input/util/source_icon/Copy.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_Forbid") { - source = "//foundation/multimodalinput/input/util/source_icon/Forbid.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_Colorsucker") { - source = "//foundation/multimodalinput/input/util/source_icon/Colorsucker.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_Hand_Grabbing") { - source = - "//foundation/multimodalinput/input/util/source_icon/Hand_Grabbing.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_Hand_Open") { - source = "//foundation/multimodalinput/input/util/source_icon/Hand_Open.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_Hand_Pointing") { - source = - "//foundation/multimodalinput/input/util/source_icon/Hand_Pointing.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_Help") { - source = "//foundation/multimodalinput/input/util/source_icon/Help.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_Move") { - source = "//foundation/multimodalinput/input/util/source_icon/Move.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_Resize_Left_Right") { - source = "//foundation/multimodalinput/input/util/source_icon/Resize_Left_Right.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_Resize_Up_Down") { - source = - "//foundation/multimodalinput/input/util/source_icon/Resize_Up_Down.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_Screenshot_Cross") { - source = - "//foundation/multimodalinput/input/util/source_icon/Screenshot_Cross.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_Screenshot_Cursor") { - source = "//foundation/multimodalinput/input/util/source_icon/Screenshot_Cursor.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_Text_Cursor") { - source = "//foundation/multimodalinput/input/util/source_icon/Text_Cursor.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_Zoom_In") { - source = "//foundation/multimodalinput/input/util/source_icon/Zoom_In.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_Zoom_Out") { - source = "//foundation/multimodalinput/input/util/source_icon/Zoom_Out.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_MID_Btn_East") { - source = - "//foundation/multimodalinput/input/util/source_icon/MID_Btn_East.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_MID_Btn_West") { - source = - "//foundation/multimodalinput/input/util/source_icon/MID_Btn_West.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_MID_Btn_South") { - source = - "//foundation/multimodalinput/input/util/source_icon/MID_Btn_South.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_MID_Btn_North") { - source = - "//foundation/multimodalinput/input/util/source_icon/MID_Btn_North.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_MID_Btn_North_South") { - source = "//foundation/multimodalinput/input/util/source_icon/MID_Btn_North_South.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_MID_Btn_North_East") { - source = "//foundation/multimodalinput/input/util/source_icon/MID_Btn_North_East.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_MID_Btn_North_West") { - source = "//foundation/multimodalinput/input/util/source_icon/MID_Btn_North_West.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_MID_Btn_South_East") { - source = "//foundation/multimodalinput/input/util/source_icon/MID_Btn_South_East.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_MID_Btn_South_West") { - source = "//foundation/multimodalinput/input/util/source_icon/MID_Btn_South_West.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("drawing_pointer_image_MID_Btn_North_South_West_East") { - source = "//foundation/multimodalinput/input/util/source_icon/MID_Btn_North_South_West_East.png" - part_name = "input" - subsystem_name = "multimodalinput" - relative_install_dir = "multimodalinput/mouse_icon" -} - -ohos_prebuilt_etc("multimodalinput.para.dac") { - source = "${mmi_path}/etc/multimodalinput.para.dac" - part_name = "input" - subsystem_name = "multimodalinput" - module_install_dir = "etc/param" -} - ohos_shared_library("libmmi-server") { - sources = [ - "//foundation/multimodalinput/input/frameworks/proxy/event_handler/src/bytrace_adapter.cpp", - "delegate_task/src/delegate_tasks.cpp", - "device_manager/src/input_device_manager.cpp", - "dfx/src/dfx_hisysevent.cpp", - "event_dispatch/src/event_dispatch_handler.cpp", - "event_dump/src/event_dump.cpp", - "event_handler/src/anr_manager.cpp", - "event_handler/src/event_normalize_handler.cpp", - "event_handler/src/input_event_handler.cpp", - "event_handler/src/key_auto_repeat.cpp", - "event_handler/src/key_event_value_transformation.cpp", - "event_handler/src/key_map_manager.cpp", - "libinput_adapter/src/libinput_adapter.cpp", - "message_handle/src/server_msg_handler.cpp", - "module_loader/src/mmi_service.cpp", - "module_loader/src/uds_server.cpp", - "permission_helper/src/permission_helper.cpp", - "timer_manager/src/timer_manager.cpp", - "window_manager/src/input_windows_manager.cpp", - ] - + sources = libmmi_service_sources if (input_feature_input_cooperation) { sources += [ "input_device_cooperate/src/cooperate_event_handler.cpp", "input_device_cooperate/src/cooperate_event_manager.cpp", + "input_device_cooperate/src/device_cooperate_softbus_adapter.cpp", "input_device_cooperate/src/device_profile_adapter.cpp", "input_device_cooperate/src/distributed_input_adapter.cpp", "input_device_cooperate/src/i_input_device_cooperate_state.cpp", @@ -459,13 +96,7 @@ ohos_shared_library("libmmi-server") { "input_device_cooperate/src/input_device_cooperate_state_free.cpp", "input_device_cooperate/src/input_device_cooperate_state_in.cpp", "input_device_cooperate/src/input_device_cooperate_state_out.cpp", - ] - } - - if (input_feature_hdf) { - sources += [ - "hdf_adapter/src/hdf_event_manager.cpp", - "hdi_inject/src/hdi_inject.cpp", + "input_device_cooperate/src/input_device_cooperate_util.cpp", ] } @@ -486,6 +117,7 @@ ohos_shared_library("libmmi-server") { sources += [ "mouse_event_normalize/src/mouse_device_state.cpp", "mouse_event_normalize/src/mouse_event_normalize.cpp", + "mouse_event_normalize/src/mouse_transform_processor.cpp", "touch_event_normalize/src/gesture_transform_processor.cpp", "touch_event_normalize/src/touchpad_transform_processor.cpp", ] @@ -502,6 +134,9 @@ ohos_shared_library("libmmi-server") { ] } } + if (input_feature_joystick) { + sources += [ "touch_event_normalize/src/joystick_transform_processor.cpp" ] + } if (input_feature_monitor) { sources += [ "monitor/src/event_monitor_handler.cpp" ] } @@ -512,63 +147,18 @@ ohos_shared_library("libmmi-server") { configs = [ ":libmmi_server_config" ] deps = [ - ":drawing_pointer_image_Colorsucker", - ":drawing_pointer_image_Copy", - ":drawing_pointer_image_Cross", - ":drawing_pointer_image_Default", - ":drawing_pointer_image_East", - ":drawing_pointer_image_Forbid", - ":drawing_pointer_image_Hand_Grabbing", - ":drawing_pointer_image_Hand_Open", - ":drawing_pointer_image_Hand_Pointing", - ":drawing_pointer_image_Help", - ":drawing_pointer_image_MID_Btn_East", - ":drawing_pointer_image_MID_Btn_North", - ":drawing_pointer_image_MID_Btn_North_East", - ":drawing_pointer_image_MID_Btn_North_South", - ":drawing_pointer_image_MID_Btn_North_South_West_East", - ":drawing_pointer_image_MID_Btn_North_West", - ":drawing_pointer_image_MID_Btn_South", - ":drawing_pointer_image_MID_Btn_South_East", - ":drawing_pointer_image_MID_Btn_South_West", - ":drawing_pointer_image_MID_Btn_West", - ":drawing_pointer_image_Move", - ":drawing_pointer_image_North", - ":drawing_pointer_image_North_East", - ":drawing_pointer_image_North_East_South_West", - ":drawing_pointer_image_North_South", - ":drawing_pointer_image_North_West", - ":drawing_pointer_image_North_West_South_East", - ":drawing_pointer_image_Resize_Left_Right", - ":drawing_pointer_image_Resize_Up_Down", - ":drawing_pointer_image_Screenshot_Cross", - ":drawing_pointer_image_Screenshot_Cursor", - ":drawing_pointer_image_South", - ":drawing_pointer_image_South_East", - ":drawing_pointer_image_South_West", - ":drawing_pointer_image_Text_Cursor", - ":drawing_pointer_image_West", - ":drawing_pointer_image_West_East", - ":drawing_pointer_image_Zoom_In", - ":drawing_pointer_image_Zoom_Out", ":mmi_device_config.ini", - ":multimodalinput.para.dac", - ":multimodalinput_config_ability.json", "${ability_runtime_path}/frameworks/native/ability/native:abilitykit_native", "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics", "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", - "//foundation/multimodalinput/input/frameworks/proxy:libmmi-common", + "//foundation/multimodalinput/input/etc/mouse_icon:input_mouse_icon", + "//foundation/multimodalinput/input/patch/diff_libinput_mmi:libinput-third-mmi", "//foundation/multimodalinput/input/service/connect_manager:mmi_connect_manager_service", "//foundation/multimodalinput/input/service/filter:mmi_event_filter_proxy", "//foundation/multimodalinput/input/util:libmmi-util", - "//third_party/cJSON:cjson_static", - "//third_party/json:nlohmann_json_static", + "//third_party/cJSON:cjson", ] - if (input_feature_libinput || input_feature_hdf) { - deps += [ "//foundation/multimodalinput/input/patch/diff_libinput_mmi:libinput-third-mmi" ] - } - if (resource_schedule_service_enabled) { deps += [ "//foundation/resourceschedule/resource_schedule_service/ressched/interfaces/innerkits/ressched_client:ressched_client" ] } @@ -578,7 +168,6 @@ ohos_shared_library("libmmi-server") { "//base/notification/eventhandler/frameworks/eventhandler:libeventhandler", "//foundation/deviceprofile/device_info_manager/interfaces/innerkits/core:distributed_device_profile_client", "//foundation/distributedhardware/distributed_input/interfaces/inner_kits:libdinput_sdk", - "//foundation/multimodalinput/input/service/connect_manager:mmi_connect_manager_proxy", ] } @@ -586,12 +175,14 @@ ohos_shared_library("libmmi-server") { "ability_base:want", "ability_runtime:ability_manager", "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", "config_policy:configpolicy_util", + "hicollie_native:libhicollie", "hisysevent_native:libhisysevent", "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", "init:libbegetutil", - "ipc:ipc_core", + "ipc:ipc_single", "multimedia_image_framework:image_native", "safwk:system_ability_fwk", ] @@ -611,13 +202,6 @@ ohos_shared_library("libmmi-server") { subsystem_name = "multimodalinput" } -ohos_prebuilt_etc("mmi_device_config.ini") { - source = "mmi_device_config.ini" - relative_install_dir = "." - subsystem_name = "multimodalinput" - part_name = "input" -} - import("//build/test.gni") module_output_path = "multimodalinput/unit_out" @@ -647,75 +231,35 @@ ohos_unittest("ut-mmi-service-out") { "${mmi_path}/service/event_dispatch/include", "${mmi_path}/service/key_event_normalize/include", "${mmi_path}/service/event_handler/include", - "${mmi_path}/service/hdi_inject/include", "${mmi_path}/service/event_dump/include", - "${mmi_path}/service/hdf_adapter/include", "${mmi_path}/service/libinput_adapter/include", "${mmi_path}/service/message_handle/include", "${mmi_path}/service/module_loader/include", "${mmi_path}/service/window_manager/include", "${mmi_path}/uinput", + "$root_out_dir/diff_libinput_mmi/export_include", ] - if (input_feature_libinput || input_feature_hdf) { - include_dirs += [ "$root_out_dir/diff_libinput_mmi/export_include" ] - } - sources = [ "event_dispatch/test/event_dispatch_test.cpp", - "hdi_inject/test/hdi_inject_test.cpp", - "message_handle/test/server_msg_handler_test.cpp", "module_loader/test/uds_server_test.cpp", + "window_manager/test/input_display_bind_helper_test.cpp", "window_manager/test/input_windows_manager_test.cpp", ] - defines = [] - - if (input_feature_debug) { - defines += [ "OHOS_BUILD_MMI_DEBUG" ] - } - - if (input_feature_libinput) { - defines += [ "OHOS_BUILD_LIBINPUT" ] - } - - if (input_feature_hdf) { - defines += [ "OHOS_BUILD_HDF" ] - } - - if (input_feature_pointer_drawing) { - defines += [ "OHOS_BUILD_ENABLE_POINTER_DRAWING" ] - } - if (input_feature_keyboard) { - defines += [ "OHOS_BUILD_ENABLE_KEYBOARD" ] - } - if (input_feature_mouse) { - defines += [ "OHOS_BUILD_ENABLE_POINTER" ] - } - if (input_feature_touchscreen) { - defines += [ "OHOS_BUILD_ENABLE_TOUCH" ] - } - if (input_feature_monitor) { - defines += [ "OHOS_BUILD_ENABLE_MONITOR" ] - } - configs = [ ":libmmi_server_config" ] deps = [ "${mmi_path}/frameworks/proxy:libmmi-client", "${mmi_path}/service:libmmi-server", "${mmi_path}/util:libmmi-util", + "//foundation/multimodalinput/input/patch/diff_libinput_mmi:libinput-third-mmi", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] - if (input_feature_libinput || input_feature_hdf) { - deps += [ "//foundation/multimodalinput/input/patch/diff_libinput_mmi:libinput-third-mmi" ] - } - external_deps = [ "c_utils:utils", - "drivers_interface_input:hdi_input", "hiviewdfx_hilog_native:libhilog", ] } @@ -730,12 +274,6 @@ ohos_unittest("TransformPointTest") { sources = [ "touch_event_normalize/test/transform_point_test.cpp" ] - defines = [] - - if (input_feature_debug) { - defines += [ "OHOS_BUILD_MMI_DEBUG" ] - } - deps = [ "${mmi_path}/tools/vuinput:libmmi-virtual-device", "//third_party/googletest:gmock_main", diff --git a/service/connect_manager/BUILD.gn b/service/connect_manager/BUILD.gn index e612df100ae4dc31681276af0e857666997e9698..e332bba91f739ceb2250beeabd418a2c6be36d7d 100644 --- a/service/connect_manager/BUILD.gn +++ b/service/connect_manager/BUILD.gn @@ -19,6 +19,7 @@ config("mmi_connect_manager_config") { include_dirs = [ "//foundation/multimodalinput/input/interfaces/native/innerkits/common/include", "//foundation/multimodalinput/input/interfaces/native/innerkits/event/include", + "//foundation/multimodalinput/input/interfaces/native/innerkits/proxy/include", "//foundation/multimodalinput/input/util/common/include", "//foundation/multimodalinput/input/util/network/include", "//foundation/multimodalinput/input/util/socket/include", @@ -34,21 +35,17 @@ config("mmi_connect_manager_config") { ohos_source_set("mmi_connect_manager_service") { part_name = "input" subsystem_name = "multimodalinput" - sources = - [ "${mmi_connect_manager_path}/src/multimodal_input_connect_stub.cpp" ] - - if (!input_feature_input_cooperation) { - sources += [ - "${mmi_connect_manager_path}/src/multimodal_input_connect_def_parcel.cpp", - ] - } + sources = [ + "${mmi_connect_manager_path}/src/multimodal_input_connect_def_parcel.cpp", + "${mmi_connect_manager_path}/src/multimodal_input_connect_stub.cpp", + ] configs = [ ":mmi_connect_manager_config" ] external_deps = [ "access_token:libaccesstoken_sdk", "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", + "ipc:ipc_single", "safwk:system_ability_fwk", "samgr:samgr_proxy", ] @@ -64,17 +61,11 @@ ohos_source_set("mmi_connect_manager_proxy") { "${mmi_connect_manager_path}/src/multimodal_input_connect_proxy.cpp", ] - if (input_feature_input_cooperation) { - sources += [ - "${mmi_connect_manager_path}/src/multimodal_input_connect_remoter.cpp", - ] - } - configs = [ ":mmi_connect_manager_config" ] external_deps = [ "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", + "ipc:ipc_single", "safwk:system_ability_fwk", "samgr:samgr_proxy", ] diff --git a/service/connect_manager/include/i_multimodal_input_connect.h b/service/connect_manager/include/i_multimodal_input_connect.h index 3e6f6f0914d6500a692616355b08dbb55e7cbcb3..b1e429bc44e3ee13aaa92fb4c250a58d768793fc 100644 --- a/service/connect_manager/include/i_multimodal_input_connect.h +++ b/service/connect_manager/include/i_multimodal_input_connect.h @@ -18,11 +18,17 @@ #include "iremote_broker.h" +#include "extra_data.h" #include "i_event_filter.h" +#include "i_input_event_filter.h" +#include "input_device.h" #include "input_handler_type.h" #include "key_event.h" #include "key_option.h" #include "pointer_event.h" +#include "pointer_style.h" +#include "system_ability_definition.h" +#include "window_info.h" namespace OHOS { namespace MMI { @@ -33,6 +39,7 @@ public: ADD_INPUT_EVENT_FILTER = 1, SET_POINTER_VISIBLE = 2, IS_POINTER_VISIBLE = 3, + MARK_PROCESSED = 4, SUBSCRIBE_KEY_EVENT = 6, UNSUBSCRIBE_KEY_EVENT = 7, ADD_INPUT_HANDLER = 8, @@ -54,44 +61,51 @@ public: GET_POINTER_STYLE = 24, SET_FUNCTION_KEY_STATE = 25, GET_FUNCTION_KEY_STATE = 26, + RMV_INPUT_EVENT_FILTER = 27, + SET_CAPTURE_MODE = 28, + GET_DISPLAY_BIND_INFO = 29, REGISTER_COOPERATE_MONITOR = 30, UNREGISTER_COOPERATE_MONITOR = 31, ENABLE_INPUT_DEVICE_COOPERATE = 32, START_INPUT_DEVICE_COOPERATE = 33, STOP_DEVICE_COOPERATE = 34, - GET_INPUT_DEVICE_COOPERATE_STATE = 35, - REMOTE_COOPERATE_START = 40, - REMOTE_COOPERATE_START_RES = 41, - REMOTE_COOPERATE_STOP = 42, - REMOTE_COOPERATE_STOP_RES = 43, - REMOTE_COOPERATE_STOP_OTHER_RES = 44, + GET_INPUT_DEVICE_COOPERATE_STATE = 35, + SET_DISPLAY_BIND = 36, SET_INPUT_DEVICE_TO_SCREEN = 50, + SET_POINTER_LOCATION = 51, + GET_WINDOW_PID = 52, + APPEND_EXTRA_DATA = 53, }; enum { CONNECT_MODULE_TYPE_MMI_CLIENT = 0, }; static constexpr int32_t INVALID_SOCKET_FD = -1; - static constexpr int32_t MULTIMODAL_INPUT_CONNECT_SERVICE_ID = 3101; + static constexpr int32_t MULTIMODAL_INPUT_CONNECT_SERVICE_ID = MULTIMODAL_INPUT_SERVICE_ID; DECLARE_INTERFACE_DESCRIPTOR(u"ohos.multimodalinput.IConnectManager"); virtual int32_t AllocSocketFd(const std::string &programName, const int32_t moduleType, int32_t &socketFd, int32_t &tokenType) = 0; - virtual int32_t AddInputEventFilter(sptr filter) = 0; + virtual int32_t AddInputEventFilter(sptr filter, int32_t filterId, int32_t priority, + uint32_t deviceTags) = 0; + virtual int32_t RemoveInputEventFilter(int32_t filterId) = 0; virtual int32_t SetPointerVisible(bool visible) = 0; virtual int32_t IsPointerVisible(bool &visible) = 0; + virtual int32_t MarkProcessed(int32_t eventType, int32_t eventId) = 0; virtual int32_t SetPointerSpeed(int32_t speed) = 0; virtual int32_t GetPointerSpeed(int32_t &speed) = 0; - virtual int32_t SetPointerStyle(int32_t windowId, int32_t pointerStyle) = 0; - virtual int32_t GetPointerStyle(int32_t windowId, int32_t &pointerStyle) = 0; - virtual int32_t SupportKeys(int32_t userData, int32_t deviceId, std::vector &keys) = 0; - virtual int32_t GetDeviceIds(int32_t userData) = 0; - virtual int32_t GetDevice(int32_t userData, int32_t id) = 0; + virtual int32_t SetPointerStyle(int32_t windowId, PointerStyle pointerStyle) = 0; + virtual int32_t GetPointerStyle(int32_t windowId, PointerStyle &pointerStyle) = 0; + virtual int32_t SupportKeys(int32_t deviceId, std::vector &keys, std::vector &keystroke) = 0; + virtual int32_t GetDeviceIds(std::vector &ids) = 0; + virtual int32_t GetDevice(int32_t deviceId, std::shared_ptr &inputDevice) = 0; virtual int32_t RegisterDevListener() = 0; virtual int32_t UnregisterDevListener() = 0; - virtual int32_t GetKeyboardType(int32_t userData, int32_t deviceId) = 0; - virtual int32_t AddInputHandler(InputHandlerType handlerType, HandleEventType eventType) = 0; - virtual int32_t RemoveInputHandler(InputHandlerType handlerType, HandleEventType eventType) = 0; + virtual int32_t GetKeyboardType(int32_t deviceId, int32_t &keyboardType) = 0; + virtual int32_t AddInputHandler(InputHandlerType handlerType, HandleEventType eventType, + int32_t priority, uint32_t deviceTags) = 0; + virtual int32_t RemoveInputHandler(InputHandlerType handlerType, HandleEventType eventType, + int32_t priority, uint32_t deviceTags) = 0; virtual int32_t MarkEventConsumed(int32_t eventId) = 0; virtual int32_t MoveMouseEvent(int32_t offsetX, int32_t offsetY) = 0; virtual int32_t InjectKeyEvent(const std::shared_ptr keyEvent) = 0; @@ -99,6 +113,8 @@ public: virtual int32_t UnsubscribeKeyEvent(int32_t subscribeId) = 0; virtual int32_t InjectPointerEvent(const std::shared_ptr pointerEvent) = 0; virtual int32_t SetAnrObserver() = 0; + virtual int32_t GetDisplayBindInfo(DisplayBindInfos &infos) = 0; + virtual int32_t SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg) = 0; virtual int32_t RegisterCooperateListener() = 0; virtual int32_t UnregisterCooperateListener() = 0; virtual int32_t EnableInputDeviceCooperate(int32_t userData, bool enabled) = 0; @@ -107,15 +123,13 @@ public: virtual int32_t StopDeviceCooperate(int32_t userData) = 0; virtual int32_t GetInputDeviceCooperateState(int32_t userData, const std::string &deviceId) = 0; virtual int32_t SetInputDevice(const std::string& dhid, const std::string& screenId) = 0; - virtual int32_t StartRemoteCooperate(const std::string& localDeviceId) = 0; - virtual int32_t StartRemoteCooperateResult(bool isSuccess, const std::string& startDhid, - int32_t xPercent, int32_t yPercent) = 0; - virtual int32_t StopRemoteCooperate() = 0; - virtual int32_t StopRemoteCooperateResult(bool isSuccess) = 0; - virtual int32_t StartCooperateOtherResult(const std::string &srcNetworkId) = 0; virtual int32_t GetFunctionKeyState(int32_t funckey, bool &state) = 0; virtual int32_t SetFunctionKeyState(int32_t funcKey, bool enable) = 0; + virtual int32_t SetPointerLocation(int32_t x, int32_t y) = 0; + virtual int32_t SetMouseCaptureMode(int32_t windowId, bool isCaptureMode) = 0; + virtual int32_t GetWindowPid(int32_t windowId) = 0; + virtual int32_t AppendExtraData(const ExtraData& extraData) = 0; }; } // namespace MMI } // namespace OHOS -#endif // I_MULTIMODAL_INPUT_CONNECT_H \ No newline at end of file +#endif // I_MULTIMODAL_INPUT_CONNECT_H diff --git a/service/connect_manager/include/multimodal_input_connect_death_recipient.h b/service/connect_manager/include/multimodal_input_connect_death_recipient.h index b55a96d69200a4ea8a4bde5524083e716ba9a9c3..c74f4d513669e9f47e13ddc70497facc341f844e 100644 --- a/service/connect_manager/include/multimodal_input_connect_death_recipient.h +++ b/service/connect_manager/include/multimodal_input_connect_death_recipient.h @@ -21,12 +21,12 @@ namespace OHOS { namespace MMI { -class MultimodalInputConnectDeathRecipient : public IRemoteObject::DeathRecipient { +class MultimodalInputConnectDeathRecipient final : public IRemoteObject::DeathRecipient { public: explicit MultimodalInputConnectDeathRecipient(const std::function &object)> &deathCallback); DISALLOW_COPY_AND_MOVE(MultimodalInputConnectDeathRecipient); - virtual ~MultimodalInputConnectDeathRecipient() = default; + ~MultimodalInputConnectDeathRecipient() override = default; void OnRemoteDied(const wptr &object) override; private: diff --git a/service/connect_manager/include/multimodal_input_connect_def_parcel.h b/service/connect_manager/include/multimodal_input_connect_def_parcel.h index f9255fe0b25699f0e91c0ad84540f91bb1c18643..725e247aa1434c33b638e3f75ce0eb53f59ccf43 100644 --- a/service/connect_manager/include/multimodal_input_connect_def_parcel.h +++ b/service/connect_manager/include/multimodal_input_connect_def_parcel.h @@ -30,15 +30,6 @@ public: bool Marshalling(Parcel &out) const override; ConnectDefReq data; }; - -class ConnectRespParcel final : public Parcelable { -public: - static ConnectRespParcel *Unmarshalling(Parcel &in); - ConnectRespParcel() = default; - ~ConnectRespParcel() override = default; - bool Marshalling(Parcel &out) const override; - ConnectDefResp data; -}; } // namespace MMI } // namespace OHOS #endif // MULTIMODAL_INPUT_CONNECT_DEF_PARCEL_H \ No newline at end of file diff --git a/service/connect_manager/include/multimodal_input_connect_manager.h b/service/connect_manager/include/multimodal_input_connect_manager.h index 0ffc175114a27f00b90c0cec8805e07dd38b0f13..76287a807b8ce435a81d8ca46346b731b6910df3 100644 --- a/service/connect_manager/include/multimodal_input_connect_manager.h +++ b/service/connect_manager/include/multimodal_input_connect_manager.h @@ -27,9 +27,9 @@ namespace OHOS { namespace MMI { -class MultimodalInputConnectManager : public std::enable_shared_from_this { +class MultimodalInputConnectManager final : public std::enable_shared_from_this { public: - virtual ~MultimodalInputConnectManager() = default; + ~MultimodalInputConnectManager() = default; static std::shared_ptr GetInstance(); int32_t AllocSocketPair(const int32_t moduleType); int32_t GetClientSocketFdOfAllocedSocketPair() const; @@ -37,21 +37,27 @@ public: { return tokenType_; } - int32_t AddInputEventFilter(sptr filter); + int32_t AddInputEventFilter(sptr filter, int32_t filterId, int32_t priority, uint32_t deviceTags); + int32_t RemoveInputEventFilter(int32_t filterId); + int32_t GetDisplayBindInfo(DisplayBindInfos &infos); + int32_t SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg); int32_t SetPointerVisible(bool visible); int32_t IsPointerVisible(bool &visible); + int32_t MarkProcessed(int32_t eventType, int32_t eventId); int32_t SetPointerSpeed(int32_t speed); int32_t GetPointerSpeed(int32_t &speed); - int32_t SetPointerStyle(int32_t windowId, int32_t pointerStyle); - int32_t GetPointerStyle(int32_t windowId, int32_t &pointerStyle); - int32_t SupportKeys(int32_t userData, int32_t deviceId, std::vector &keys); - int32_t GetDeviceIds(int32_t userData); - int32_t GetDevice(int32_t userData, int32_t id); + int32_t SetPointerStyle(int32_t windowId, PointerStyle pointerStyle); + int32_t GetPointerStyle(int32_t windowId, PointerStyle &pointerStyle); + int32_t SupportKeys(int32_t deviceId, std::vector &keys, std::vector &keystroke); + int32_t GetDeviceIds(std::vector &ids); + int32_t GetDevice(int32_t deviceId, std::shared_ptr &inputDevice); int32_t RegisterDevListener(); int32_t UnregisterDevListener(); - int32_t GetKeyboardType(int32_t userData, int32_t deviceId); - int32_t AddInputHandler(InputHandlerType handlerType, HandleEventType eventType); - int32_t RemoveInputHandler(InputHandlerType handlerType, HandleEventType eventType); + int32_t GetKeyboardType(int32_t deviceId, int32_t &keyboardType); + int32_t AddInputHandler(InputHandlerType handlerType, HandleEventType eventType, int32_t priority, + uint32_t deviceTags); + int32_t RemoveInputHandler(InputHandlerType handlerType, HandleEventType eventType, int32_t priority, + uint32_t deviceTags); int32_t MarkEventConsumed(int32_t eventId); int32_t MoveMouseEvent(int32_t offsetX, int32_t offsetY); int32_t InjectKeyEvent(const std::shared_ptr keyEvent); @@ -68,6 +74,10 @@ public: int32_t SetInputDevice(const std::string& dhid, const std::string& screenId); int32_t GetFunctionKeyState(int32_t funcKey, bool &state); int32_t SetFunctionKeyState(int32_t funcKey, bool enable); + int32_t SetPointerLocation(int32_t x, int32_t y); + int32_t SetMouseCaptureMode(int32_t windowId, bool isCaptureMode); + int32_t GetWindowPid(int32_t windowId); + int32_t AppendExtraData(const ExtraData& extraData); private: MultimodalInputConnectManager() = default; diff --git a/service/connect_manager/include/multimodal_input_connect_proxy.h b/service/connect_manager/include/multimodal_input_connect_proxy.h index cff5fad68583eb33573c61b7d30185732fc41da9..1079dcff2e92eedeec4094fde98eeff8dabdb70b 100644 --- a/service/connect_manager/include/multimodal_input_connect_proxy.h +++ b/service/connect_manager/include/multimodal_input_connect_proxy.h @@ -29,51 +29,56 @@ class MultimodalInputConnectProxy final : public IRemoteProxy &impl); DISALLOW_COPY_AND_MOVE(MultimodalInputConnectProxy); - virtual ~MultimodalInputConnectProxy() override; - virtual int32_t AllocSocketFd(const std::string &programName, const int32_t moduleType, + ~MultimodalInputConnectProxy() override = default; + int32_t AllocSocketFd(const std::string &programName, const int32_t moduleType, int32_t &socketFd, int32_t &tokenType) override; - virtual int32_t AddInputEventFilter(sptr filter) override; - virtual int32_t SetPointerVisible(bool visible) override; - virtual int32_t IsPointerVisible(bool &visible) override; - virtual int32_t SetPointerSpeed(int32_t speed) override; - virtual int32_t GetPointerSpeed(int32_t &speed) override; - virtual int32_t SetPointerStyle(int32_t windowId, int32_t pointerStyle) override; - virtual int32_t GetPointerStyle(int32_t windowId, int32_t &pointerStyle) override; - virtual int32_t SupportKeys(int32_t userData, int32_t deviceId, std::vector &keys) override; - virtual int32_t GetDeviceIds(int32_t userData) override; - virtual int32_t GetDevice(int32_t userData, int32_t deviceId) override; - virtual int32_t RegisterDevListener() override; - virtual int32_t UnregisterDevListener() override; - virtual int32_t GetKeyboardType(int32_t userData, int32_t deviceId) override; - virtual int32_t AddInputHandler(InputHandlerType handlerType, HandleEventType eventType) override; - virtual int32_t RemoveInputHandler(InputHandlerType handlerType, HandleEventType eventType) override; - virtual int32_t MarkEventConsumed(int32_t eventId) override; - virtual int32_t MoveMouseEvent(int32_t offsetX, int32_t offsetY) override; - virtual int32_t InjectKeyEvent(const std::shared_ptr keyEvent) override; - virtual int32_t SubscribeKeyEvent(int32_t subscribeId, const std::shared_ptr option) override; - virtual int32_t UnsubscribeKeyEvent(int32_t subscribeId) override; - virtual int32_t InjectPointerEvent(const std::shared_ptr pointerEvent) override; - virtual int32_t SetAnrObserver() override; - virtual int32_t RegisterCooperateListener() override; - virtual int32_t UnregisterCooperateListener() override; - virtual int32_t EnableInputDeviceCooperate(int32_t userData, bool enabled) override; - virtual int32_t StartInputDeviceCooperate(int32_t userData, const std::string &sinkDeviceId, + int32_t AddInputEventFilter(sptr filter, int32_t filterId, int32_t priority, + uint32_t deviceTags) override; + int32_t RemoveInputEventFilter(int32_t filterId) override; + int32_t SetPointerVisible(bool visible) override; + int32_t IsPointerVisible(bool &visible) override; + int32_t MarkProcessed(int32_t eventType, int32_t eventId) override; + int32_t SetPointerSpeed(int32_t speed) override; + int32_t GetPointerSpeed(int32_t &speed) override; + int32_t SetPointerStyle(int32_t windowId, PointerStyle pointerStyle) override; + int32_t GetPointerStyle(int32_t windowId, PointerStyle &pointerStyle) override; + int32_t SupportKeys(int32_t deviceId, std::vector &keys, std::vector &keystroke) override; + int32_t GetDeviceIds(std::vector &ids) override; + int32_t GetDevice(int32_t deviceId, std::shared_ptr &inputDevice) override; + int32_t RegisterDevListener() override; + int32_t UnregisterDevListener() override; + int32_t GetKeyboardType(int32_t deviceId, int32_t &keyboardType) override; + int32_t AddInputHandler(InputHandlerType handlerType, HandleEventType eventType, + int32_t priority, uint32_t deviceTags) override; + int32_t RemoveInputHandler(InputHandlerType handlerType, HandleEventType eventType, + int32_t priority, uint32_t deviceTags) override; + int32_t MarkEventConsumed(int32_t eventId) override; + int32_t MoveMouseEvent(int32_t offsetX, int32_t offsetY) override; + int32_t InjectKeyEvent(const std::shared_ptr keyEvent) override; + int32_t SubscribeKeyEvent(int32_t subscribeId, const std::shared_ptr option) override; + int32_t UnsubscribeKeyEvent(int32_t subscribeId) override; + int32_t InjectPointerEvent(const std::shared_ptr pointerEvent) override; + int32_t SetAnrObserver() override; + int32_t GetDisplayBindInfo(DisplayBindInfos &infos) override; + int32_t SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg) override; + int32_t RegisterCooperateListener() override; + int32_t UnregisterCooperateListener() override; + int32_t EnableInputDeviceCooperate(int32_t userData, bool enabled) override; + int32_t StartInputDeviceCooperate(int32_t userData, const std::string &sinkDeviceId, int32_t srcInputDeviceId) override; - virtual int32_t StopDeviceCooperate(int32_t userData) override; - virtual int32_t GetInputDeviceCooperateState(int32_t userData, const std::string &deviceId) override; - virtual int32_t SetInputDevice(const std::string& dhid, const std::string& screenId) override; - virtual int32_t StartRemoteCooperate(const std::string &localDeviceId) override; - virtual int32_t StartRemoteCooperateResult(bool isSuccess, const std::string& startDhid, - int32_t xPercent, int32_t yPercent) override; - virtual int32_t StopRemoteCooperate() override; - virtual int32_t StopRemoteCooperateResult(bool isSuccess) override; - virtual int32_t StartCooperateOtherResult(const std::string &srcNetworkId) override; - virtual int32_t GetFunctionKeyState(int32_t funcKey, bool &state) override; - virtual int32_t SetFunctionKeyState(int32_t funcKey, bool enable) override; + int32_t StopDeviceCooperate(int32_t userData) override; + int32_t GetInputDeviceCooperateState(int32_t userData, const std::string &deviceId) override; + int32_t SetInputDevice(const std::string& dhid, const std::string& screenId) override; + int32_t GetFunctionKeyState(int32_t funcKey, bool &state) override; + int32_t SetFunctionKeyState(int32_t funcKey, bool enable) override; + int32_t SetPointerLocation(int32_t x, int32_t y) override; + virtual int32_t SetMouseCaptureMode(int32_t windowId, bool isCaptureMode) override; + int32_t GetWindowPid(int32_t windowId) override; + int32_t AppendExtraData(const ExtraData& extraData) override; private: static inline BrokerDelegator delegator_; }; } // namespace MMI } // namespace OHOS -#endif // MULTIMODAL_INPUT_CONNECT_PROXY_H \ No newline at end of file +#endif // MULTIMODAL_INPUT_CONNECT_PROXY_H diff --git a/service/connect_manager/include/multimodal_input_connect_stub.h b/service/connect_manager/include/multimodal_input_connect_stub.h index 66666a841fa17b5b45f7dbd93bd78e6b27a31ca0..ff114bada60c7fb4354549a2bbd7b928dc48e589 100644 --- a/service/connect_manager/include/multimodal_input_connect_stub.h +++ b/service/connect_manager/include/multimodal_input_connect_stub.h @@ -30,7 +30,7 @@ class MultimodalInputConnectStub : public IRemoteStub { public: MultimodalInputConnectStub() = default; DISALLOW_COPY_AND_MOVE(MultimodalInputConnectStub); - ~MultimodalInputConnectStub() = default; + virtual ~MultimodalInputConnectStub() = default; virtual bool IsRunning() const = 0; virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, @@ -39,10 +39,12 @@ public: protected: int32_t StubHandleAllocSocketFd(MessageParcel &data, MessageParcel &reply); int32_t StubAddInputEventFilter(MessageParcel& data, MessageParcel& reply); + int32_t StubRemoveInputEventFilter(MessageParcel& data, MessageParcel& reply); int32_t StubSetPointerVisible(MessageParcel& data, MessageParcel& reply); int32_t StubSetPointerStyle(MessageParcel& data, MessageParcel& reply); int32_t StubGetPointerStyle(MessageParcel& data, MessageParcel& reply); int32_t StubIsPointerVisible(MessageParcel& data, MessageParcel& reply); + int32_t StubMarkProcessed(MessageParcel& data, MessageParcel& reply); int32_t StubSupportKeys(MessageParcel& data, MessageParcel& reply); int32_t StubGetDeviceIds(MessageParcel& data, MessageParcel& reply); int32_t StubGetDevice(MessageParcel& data, MessageParcel& reply); @@ -58,6 +60,8 @@ protected: int32_t StubUnsubscribeKeyEvent(MessageParcel& data, MessageParcel& reply); int32_t StubInjectPointerEvent(MessageParcel& data, MessageParcel& reply); int32_t StubSetAnrListener(MessageParcel& data, MessageParcel& reply); + int32_t StubGetDisplayBindInfo(MessageParcel& data, MessageParcel& reply); + int32_t StubSetDisplayBind(MessageParcel& data, MessageParcel& reply); int32_t StubSetPointerSpeed(MessageParcel& data, MessageParcel& reply); int32_t StubGetPointerSpeed(MessageParcel& data, MessageParcel& reply); int32_t StubRegisterCooperateMonitor(MessageParcel& data, MessageParcel& reply); @@ -67,14 +71,13 @@ protected: int32_t StubStopDeviceCooperate(MessageParcel& data, MessageParcel& reply); int32_t StubGetInputDeviceCooperateState(MessageParcel& data, MessageParcel& reply); int32_t StubSetInputDevice(MessageParcel& data, MessageParcel& reply); - int32_t StubStartRemoteCooperate(MessageParcel& data, MessageParcel& reply); - int32_t StubStartRemoteCooperateRes(MessageParcel& data, MessageParcel& reply); - int32_t StubStopRemoteCooperate(MessageParcel& data, MessageParcel& reply); - int32_t StubStopRemoteCooperateRes(MessageParcel& data, MessageParcel& reply); - int32_t StubStartCooperateOtherRes(MessageParcel& data, MessageParcel& reply); int32_t StubGetFunctionKeyState(MessageParcel &data, MessageParcel &reply); int32_t StubSetFunctionKeyState(MessageParcel &data, MessageParcel &reply); + int32_t StubSetPointerLocation(MessageParcel &data, MessageParcel &reply); + int32_t StubSetMouseCaptureMode(MessageParcel& data, MessageParcel& reply); + int32_t StubGetWindowPid(MessageParcel& data, MessageParcel& reply); + int32_t StubAppendExtraData(MessageParcel& data, MessageParcel& reply); }; } // namespace MMI } // namespace OHOS -#endif // MULTIMODAL_INPUT_CONNECT_STUB_H \ No newline at end of file +#endif // MULTIMODAL_INPUT_CONNECT_STUB_H diff --git a/service/connect_manager/src/multimodal_input_connect_def_parcel.cpp b/service/connect_manager/src/multimodal_input_connect_def_parcel.cpp index a6ef69b52f47b1bea4cd40416aa98258e1933291..f3876ef976a7b38030d413ea043a273f11a9ee15 100644 --- a/service/connect_manager/src/multimodal_input_connect_def_parcel.cpp +++ b/service/connect_manager/src/multimodal_input_connect_def_parcel.cpp @@ -25,10 +25,7 @@ constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "Multi bool ConnectReqParcel::Marshalling(Parcel& out) const { WRITEINT32(out, data.moduleId); - if (!out.WriteString(data.clientName)) { - return false; - } - return true; + return out.WriteString(data.clientName); } ConnectReqParcel *ConnectReqParcel::Unmarshalling(Parcel& in) @@ -47,33 +44,5 @@ ConnectReqParcel *ConnectReqParcel::Unmarshalling(Parcel& in) request->data.clientName = in.ReadString(); return request; } - -bool ConnectRespParcel::Marshalling(Parcel &out) const -{ - WRITEINT32(out, data.returnCode); - WRITEINT32(out, data.allocedSocketId); - return true; -} - -ConnectRespParcel *ConnectRespParcel::Unmarshalling(Parcel &in) -{ - auto *response = new (std::nothrow) ConnectRespParcel(); - if (response == nullptr) { - return nullptr; - } - - if (!in.ReadInt32(response->data.returnCode)) { - delete response; - response = nullptr; - return nullptr; - } - - if (!in.ReadInt32(response->data.allocedSocketId)) { - delete response; - response = nullptr; - return nullptr; - } - return response; -} } // namespace MMI } // namespace OHOS diff --git a/service/connect_manager/src/multimodal_input_connect_manager.cpp b/service/connect_manager/src/multimodal_input_connect_manager.cpp index 38be4017e2848bec20a7de30c1290845120b6ca5..611c528f8680cd5cf8bf58dcda18d00b29723506 100644 --- a/service/connect_manager/src/multimodal_input_connect_manager.cpp +++ b/service/connect_manager/src/multimodal_input_connect_manager.cpp @@ -30,7 +30,7 @@ namespace OHOS { namespace MMI { namespace { std::shared_ptr g_instance = nullptr; -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "MultimodalInputConnectManager"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "MultimodalInputConnectManager" }; } // namespace std::shared_ptr MultimodalInputConnectManager::GetInstance() @@ -73,14 +73,55 @@ int32_t MultimodalInputConnectManager::GetClientSocketFdOfAllocedSocketPair() co return socketFd_; } -int32_t MultimodalInputConnectManager::AddInputEventFilter(sptr filter) +int32_t MultimodalInputConnectManager::GetDisplayBindInfo(DisplayBindInfos &infos) { std::lock_guard guard(lock_); if (multimodalInputConnectService_ == nullptr) { MMI_HILOGE("The multimodalInputConnectService_ is nullptr"); return RET_ERR; } - return multimodalInputConnectService_->AddInputEventFilter(filter); + return multimodalInputConnectService_->GetDisplayBindInfo(infos); +} + +int32_t MultimodalInputConnectManager::SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg) +{ + std::lock_guard guard(lock_); + if (multimodalInputConnectService_ == nullptr) { + MMI_HILOGE("The multimodalInputConnectService_ is nullptr"); + return RET_ERR; + } + return multimodalInputConnectService_->SetDisplayBind(deviceId, displayId, msg); +} + +int32_t MultimodalInputConnectManager::GetWindowPid(int32_t windowId) +{ + std::lock_guard guard(lock_); + if (multimodalInputConnectService_ == nullptr) { + MMI_HILOGE("The multimodalInputConnectService_ is nullptr"); + return RET_ERR; + } + return multimodalInputConnectService_->GetWindowPid(windowId); +} + +int32_t MultimodalInputConnectManager::AddInputEventFilter(sptr filter, int32_t filterId, int32_t priority, + uint32_t deviceTags) +{ + std::lock_guard guard(lock_); + if (multimodalInputConnectService_ == nullptr) { + MMI_HILOGE("The multimodalInputConnectService_ is nullptr"); + return RET_ERR; + } + return multimodalInputConnectService_->AddInputEventFilter(filter, filterId, priority, deviceTags); +} + +int32_t MultimodalInputConnectManager::RemoveInputEventFilter(int32_t filterId) +{ + std::lock_guard guard(lock_); + if (multimodalInputConnectService_ == nullptr) { + MMI_HILOGE("The multimodalInputConnectService_ is nullptr"); + return RET_ERR; + } + return multimodalInputConnectService_->RemoveInputEventFilter(filterId); } int32_t MultimodalInputConnectManager::SetPointerVisible(bool visible) @@ -95,6 +136,12 @@ int32_t MultimodalInputConnectManager::IsPointerVisible(bool &visible) return multimodalInputConnectService_->IsPointerVisible(visible); } +int32_t MultimodalInputConnectManager::MarkProcessed(int32_t eventType, int32_t eventId) +{ + CHKPR(multimodalInputConnectService_, INVALID_HANDLER_ID); + return multimodalInputConnectService_->MarkProcessed(eventType, eventId); +} + int32_t MultimodalInputConnectManager::SetPointerSpeed(int32_t speed) { CHKPR(multimodalInputConnectService_, RET_ERR); @@ -107,13 +154,13 @@ int32_t MultimodalInputConnectManager::GetPointerSpeed(int32_t &speed) return multimodalInputConnectService_->GetPointerSpeed(speed); } -int32_t MultimodalInputConnectManager::SetPointerStyle(int32_t windowId, int32_t pointerStyle) +int32_t MultimodalInputConnectManager::SetPointerStyle(int32_t windowId, PointerStyle pointerStyle) { CHKPR(multimodalInputConnectService_, RET_ERR); return multimodalInputConnectService_->SetPointerStyle(windowId, pointerStyle); } -int32_t MultimodalInputConnectManager::GetPointerStyle(int32_t windowId, int32_t &pointerStyle) +int32_t MultimodalInputConnectManager::GetPointerStyle(int32_t windowId, PointerStyle &pointerStyle) { CHKPR(multimodalInputConnectService_, RET_ERR); return multimodalInputConnectService_->GetPointerStyle(windowId, pointerStyle); @@ -131,40 +178,43 @@ int32_t MultimodalInputConnectManager::UnregisterDevListener() return multimodalInputConnectService_->UnregisterDevListener(); } -int32_t MultimodalInputConnectManager::SupportKeys(int32_t userData, int32_t deviceId, std::vector &keys) +int32_t MultimodalInputConnectManager::SupportKeys(int32_t deviceId, std::vector &keys, + std::vector &keystroke) { CHKPR(multimodalInputConnectService_, RET_ERR); - return multimodalInputConnectService_->SupportKeys(userData, deviceId, keys); + return multimodalInputConnectService_->SupportKeys(deviceId, keys, keystroke); } -int32_t MultimodalInputConnectManager::GetDeviceIds(int32_t userData) +int32_t MultimodalInputConnectManager::GetDeviceIds(std::vector &ids) { CHKPR(multimodalInputConnectService_, RET_ERR); - return multimodalInputConnectService_->GetDeviceIds(userData); + return multimodalInputConnectService_->GetDeviceIds(ids); } -int32_t MultimodalInputConnectManager::GetDevice(int32_t userData, int32_t id) +int32_t MultimodalInputConnectManager::GetDevice(int32_t deviceId, std::shared_ptr &inputDevice) { CHKPR(multimodalInputConnectService_, RET_ERR); - return multimodalInputConnectService_->GetDevice(userData, id); + return multimodalInputConnectService_->GetDevice(deviceId, inputDevice); } -int32_t MultimodalInputConnectManager::GetKeyboardType(int32_t userData, int32_t deviceId) +int32_t MultimodalInputConnectManager::GetKeyboardType(int32_t deviceId, int32_t &keyboardType) { CHKPR(multimodalInputConnectService_, RET_ERR); - return multimodalInputConnectService_->GetKeyboardType(userData, deviceId); + return multimodalInputConnectService_->GetKeyboardType(deviceId, keyboardType); } -int32_t MultimodalInputConnectManager::AddInputHandler(InputHandlerType handlerType, HandleEventType eventType) +int32_t MultimodalInputConnectManager::AddInputHandler(InputHandlerType handlerType, HandleEventType eventType, + int32_t priority, uint32_t deviceTags) { CHKPR(multimodalInputConnectService_, INVALID_HANDLER_ID); - return multimodalInputConnectService_->AddInputHandler(handlerType, eventType); + return multimodalInputConnectService_->AddInputHandler(handlerType, eventType, priority, deviceTags); } -int32_t MultimodalInputConnectManager::RemoveInputHandler(InputHandlerType handlerType, HandleEventType eventType) +int32_t MultimodalInputConnectManager::RemoveInputHandler(InputHandlerType handlerType, HandleEventType eventType, + int32_t priority, uint32_t deviceTags) { CHKPR(multimodalInputConnectService_, INVALID_HANDLER_ID); - return multimodalInputConnectService_->RemoveInputHandler(handlerType, eventType); + return multimodalInputConnectService_->RemoveInputHandler(handlerType, eventType, priority, deviceTags); } int32_t MultimodalInputConnectManager::MarkEventConsumed(int32_t eventId) @@ -264,6 +314,12 @@ int32_t MultimodalInputConnectManager::SetFunctionKeyState(int32_t funcKey, bool return multimodalInputConnectService_->SetFunctionKeyState(funcKey, enable); } +int32_t MultimodalInputConnectManager::SetPointerLocation(int32_t x, int32_t y) +{ + CHKPR(multimodalInputConnectService_, INVALID_HANDLER_ID); + return multimodalInputConnectService_->SetPointerLocation(x, y); +} + bool MultimodalInputConnectManager::ConnectMultimodalInputService() { CALL_DEBUG_ENTER; @@ -337,5 +393,17 @@ void MultimodalInputConnectManager::NotifyDeath() } } while (--retryCount > 0); } + +int32_t MultimodalInputConnectManager::SetMouseCaptureMode(int32_t windowId, bool isCaptureMode) +{ + CHKPR(multimodalInputConnectService_, INVALID_HANDLER_ID); + return multimodalInputConnectService_->SetMouseCaptureMode(windowId, isCaptureMode); +} + +int32_t MultimodalInputConnectManager::AppendExtraData(const ExtraData& extraData) +{ + CHKPR(multimodalInputConnectService_, INVALID_HANDLER_ID); + return multimodalInputConnectService_->AppendExtraData(extraData); +} } // namespace MMI } // namespace OHOS diff --git a/service/connect_manager/src/multimodal_input_connect_proxy.cpp b/service/connect_manager/src/multimodal_input_connect_proxy.cpp index ac46ceb23f4b4443f836e9a89054eb69e9f5d642..441ed619303d2eed662216ff43f52dbe90ad8e9c 100644 --- a/service/connect_manager/src/multimodal_input_connect_proxy.cpp +++ b/service/connect_manager/src/multimodal_input_connect_proxy.cpp @@ -25,6 +25,56 @@ namespace OHOS { namespace MMI { namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "MultimodalInputConnectProxy" }; + +int32_t ParseInputDevice(MessageParcel &reply, std::shared_ptr &inputDevice) +{ + int32_t value; + READINT32(reply, value, IPC_PROXY_DEAD_OBJECT_ERR); + inputDevice->SetId(value); + READINT32(reply, value, IPC_PROXY_DEAD_OBJECT_ERR); + inputDevice->SetType(value); + std::string name; + READSTRING(reply, name, IPC_PROXY_DEAD_OBJECT_ERR); + inputDevice->SetName(name); + READINT32(reply, value, IPC_PROXY_DEAD_OBJECT_ERR); + inputDevice->SetBus(value); + READINT32(reply, value, IPC_PROXY_DEAD_OBJECT_ERR); + inputDevice->SetVersion(value); + READINT32(reply, value, IPC_PROXY_DEAD_OBJECT_ERR); + inputDevice->SetProduct(value); + READINT32(reply, value, IPC_PROXY_DEAD_OBJECT_ERR); + inputDevice->SetVendor(value); + std::string phys; + READSTRING(reply, phys, IPC_PROXY_DEAD_OBJECT_ERR); + inputDevice->SetPhys(phys); + std::string uniq; + READSTRING(reply, uniq, IPC_PROXY_DEAD_OBJECT_ERR); + inputDevice->SetUniq(uniq); + uint64_t caps; + READUINT64(reply, caps, IPC_PROXY_DEAD_OBJECT_ERR); + inputDevice->SetCapabilities(static_cast(caps)); + + uint32_t size; + READUINT32(reply, size, IPC_PROXY_DEAD_OBJECT_ERR); + InputDevice::AxisInfo axis; + for (uint32_t i = 0; i < size; ++i) { + int32_t val; + READINT32(reply, val, IPC_PROXY_DEAD_OBJECT_ERR); + axis.SetMinimum(val); + READINT32(reply, val, IPC_PROXY_DEAD_OBJECT_ERR); + axis.SetMaximum(val); + READINT32(reply, val, IPC_PROXY_DEAD_OBJECT_ERR); + axis.SetAxisType(val); + READINT32(reply, val, IPC_PROXY_DEAD_OBJECT_ERR); + axis.SetFuzz(val); + READINT32(reply, val, IPC_PROXY_DEAD_OBJECT_ERR); + axis.SetFlat(val); + READINT32(reply, val, IPC_PROXY_DEAD_OBJECT_ERR); + axis.SetResolution(val); + inputDevice->AddAxisInfo(axis); + } + return RET_OK; +} } // namespace MultimodalInputConnectProxy::MultimodalInputConnectProxy(const sptr &impl) @@ -33,11 +83,6 @@ MultimodalInputConnectProxy::MultimodalInputConnectProxy(const sptr filter) +int32_t MultimodalInputConnectProxy::AddInputEventFilter(sptr filter, int32_t filterId, int32_t priority, + uint32_t deviceTags) { CALL_DEBUG_ENTER; MessageParcel data; @@ -79,19 +129,41 @@ int32_t MultimodalInputConnectProxy::AddInputEventFilter(sptr filt MMI_HILOGE("Failed to write descriptor"); return ERR_INVALID_VALUE; } - if (!data.WriteRemoteObject(filter->AsObject().GetRefPtr())) { MMI_HILOGE("Failed to write filter"); return ERR_INVALID_VALUE; } - + WRITEINT32(data, filterId, ERR_INVALID_VALUE); + WRITEINT32(data, priority, ERR_INVALID_VALUE); + WRITEUINT32(data, deviceTags, ERR_INVALID_VALUE); MessageParcel reply; MessageOption option; sptr remote = Remote(); CHKPR(remote, RET_ERR); int32_t ret = remote->SendRequest(ADD_INPUT_EVENT_FILTER, data, reply, option); if (ret != RET_OK) { - MMI_HILOGE("Reply readint32 error:%{public}d", ret); + MMI_HILOGE("Send request message failed, ret:%{public}d", ret); + return ret; + } + return RET_OK; +} + +int32_t MultimodalInputConnectProxy::RemoveInputEventFilter(int32_t filterId) +{ + CALL_DEBUG_ENTER; + MessageParcel data; + if (!data.WriteInterfaceToken(MultimodalInputConnectProxy::GetDescriptor())) { + MMI_HILOGE("Failed to write descriptor"); + return ERR_INVALID_VALUE; + } + WRITEINT32(data, filterId, ERR_INVALID_VALUE); + MessageParcel reply; + MessageOption option; + sptr remote = Remote(); + CHKPR(remote, RET_ERR); + int32_t ret = remote->SendRequest(RMV_INPUT_EVENT_FILTER, data, reply, option); + if (ret != RET_OK) { + MMI_HILOGE("Send request message failed, ret:%{public}d", ret); return ret; } return RET_OK; @@ -138,7 +210,30 @@ int32_t MultimodalInputConnectProxy::IsPointerVisible(bool &visible) MMI_HILOGE("Send request failed, ret:%{public}d", ret); return ret; } - visible = reply.ReadBool(); + READBOOL(reply, visible, IPC_PROXY_DEAD_OBJECT_ERR); + return RET_OK; +} + +int32_t MultimodalInputConnectProxy::MarkProcessed(int32_t eventType, int32_t eventId) +{ + CALL_DEBUG_ENTER; + MessageParcel data; + if (!data.WriteInterfaceToken(MultimodalInputConnectProxy::GetDescriptor())) { + MMI_HILOGE("Failed to write descriptor"); + return ERR_INVALID_VALUE; + } + WRITEINT32(data, eventType, ERR_INVALID_VALUE); + WRITEINT32(data, eventId, ERR_INVALID_VALUE); + + MessageParcel reply; + MessageOption option; + sptr remote = Remote(); + CHKPR(remote, RET_ERR); + int32_t ret = remote->SendRequest(MARK_PROCESSED, data, reply, option); + if (ret != RET_OK) { + MMI_HILOGE("Send request fail, ret:%{public}d", ret); + return ret; + } return RET_OK; } @@ -180,11 +275,11 @@ int32_t MultimodalInputConnectProxy::GetPointerSpeed(int32_t &speed) MMI_HILOGE("Send request failed, ret:%{public}d", ret); return RET_ERR; } - speed = reply.ReadInt32(); + READINT32(reply, speed, IPC_PROXY_DEAD_OBJECT_ERR); return RET_OK; } -int32_t MultimodalInputConnectProxy::SetPointerStyle(int32_t windowId, int32_t pointerStyle) +int32_t MultimodalInputConnectProxy::SetPointerStyle(int32_t windowId, PointerStyle pointerStyle) { CALL_DEBUG_ENTER; MessageParcel data; @@ -194,7 +289,11 @@ int32_t MultimodalInputConnectProxy::SetPointerStyle(int32_t windowId, int32_t p } WRITEINT32(data, windowId, RET_ERR); - WRITEINT32(data, pointerStyle, RET_ERR); + WRITEINT32(data, pointerStyle.size, RET_ERR); + WRITEUINT8(data, pointerStyle.color.r, RET_ERR); + WRITEUINT8(data, pointerStyle.color.g, RET_ERR); + WRITEUINT8(data, pointerStyle.color.b, RET_ERR); + WRITEINT32(data, pointerStyle.id, RET_ERR); MessageParcel reply; MessageOption option; @@ -208,7 +307,7 @@ int32_t MultimodalInputConnectProxy::SetPointerStyle(int32_t windowId, int32_t p return RET_OK; } -int32_t MultimodalInputConnectProxy::GetPointerStyle(int32_t windowId, int32_t &pointerStyle) +int32_t MultimodalInputConnectProxy::GetPointerStyle(int32_t windowId, PointerStyle &pointerStyle) { CALL_DEBUG_ENTER; MessageParcel data; @@ -226,7 +325,11 @@ int32_t MultimodalInputConnectProxy::GetPointerStyle(int32_t windowId, int32_t & MMI_HILOGE("Send request fail, ret:%{public}d", ret); return ret; } - pointerStyle = reply.ReadInt32(); + READINT32(reply, pointerStyle.size, IPC_PROXY_DEAD_OBJECT_ERR); + READUINT8(reply, pointerStyle.color.r, IPC_PROXY_DEAD_OBJECT_ERR); + READUINT8(reply, pointerStyle.color.g, IPC_PROXY_DEAD_OBJECT_ERR); + READUINT8(reply, pointerStyle.color.b, IPC_PROXY_DEAD_OBJECT_ERR); + READINT32(reply, pointerStyle.id, IPC_PROXY_DEAD_OBJECT_ERR); return RET_OK; } @@ -270,7 +373,8 @@ int32_t MultimodalInputConnectProxy::UnregisterDevListener() return RET_OK; } -int32_t MultimodalInputConnectProxy::SupportKeys(int32_t userData, int32_t deviceId, std::vector &keys) +int32_t MultimodalInputConnectProxy::SupportKeys(int32_t deviceId, std::vector &keys, + std::vector &keystroke) { CALL_DEBUG_ENTER; MessageParcel data; @@ -278,7 +382,6 @@ int32_t MultimodalInputConnectProxy::SupportKeys(int32_t userData, int32_t devic MMI_HILOGE("Failed to write descriptor"); return RET_ERR; } - WRITEINT32(data, userData); WRITEINT32(data, deviceId); WRITEINT32(data, static_cast(keys.size())); for (const auto &item : keys) { @@ -294,10 +397,15 @@ int32_t MultimodalInputConnectProxy::SupportKeys(int32_t userData, int32_t devic MMI_HILOGE("Send request failed, ret:%{public}d", ret); return ret; } + if (!reply.ReadBoolVector(&keystroke)) { + MMI_HILOGE("Read ids failed"); + return RET_ERR; + } + MMI_HILOGE("keystroke size:%{public}zu", keystroke.size()); return RET_OK; } -int32_t MultimodalInputConnectProxy::GetDeviceIds(int32_t userData) +int32_t MultimodalInputConnectProxy::GetDeviceIds(std::vector &ids) { CALL_DEBUG_ENTER; MessageParcel data; @@ -305,7 +413,6 @@ int32_t MultimodalInputConnectProxy::GetDeviceIds(int32_t userData) MMI_HILOGE("Failed to write descriptor"); return RET_ERR; } - WRITEINT32(data, userData); MessageParcel reply; MessageOption option; sptr remote = Remote(); @@ -315,10 +422,15 @@ int32_t MultimodalInputConnectProxy::GetDeviceIds(int32_t userData) MMI_HILOGE("Send request failed, ret:%{public}d", ret); return ret; } + if (!reply.ReadInt32Vector(&ids)) { + MMI_HILOGE("Read vector failed"); + return RET_ERR; + } + MMI_HILOGE("ids size:%{public}zu", ids.size()); return RET_OK; } -int32_t MultimodalInputConnectProxy::GetDevice(int32_t userData, int32_t deviceId) +int32_t MultimodalInputConnectProxy::GetDevice(int32_t deviceId, std::shared_ptr &inputDevice) { CALL_DEBUG_ENTER; MessageParcel data; @@ -326,7 +438,6 @@ int32_t MultimodalInputConnectProxy::GetDevice(int32_t userData, int32_t deviceI MMI_HILOGE("Failed to write descriptor"); return RET_ERR; } - WRITEINT32(data, userData); WRITEINT32(data, deviceId); MessageParcel reply; MessageOption option; @@ -337,10 +448,15 @@ int32_t MultimodalInputConnectProxy::GetDevice(int32_t userData, int32_t deviceI MMI_HILOGE("Send request failed, ret:%{public}d", ret); return ret; } + ret = ParseInputDevice(reply, inputDevice); + if (ret != RET_OK) { + MMI_HILOGE("ParseInputDevice failed"); + return RET_ERR; + } return RET_OK; } -int32_t MultimodalInputConnectProxy::GetKeyboardType(int32_t userData, int32_t deviceId) +int32_t MultimodalInputConnectProxy::GetKeyboardType(int32_t deviceId, int32_t &keyboardType) { CALL_DEBUG_ENTER; MessageParcel data; @@ -348,7 +464,6 @@ int32_t MultimodalInputConnectProxy::GetKeyboardType(int32_t userData, int32_t d MMI_HILOGE("Failed to write descriptor"); return RET_ERR; } - WRITEINT32(data, userData); WRITEINT32(data, deviceId); MessageParcel reply; MessageOption option; @@ -359,11 +474,12 @@ int32_t MultimodalInputConnectProxy::GetKeyboardType(int32_t userData, int32_t d MMI_HILOGE("Send request failed, ret:%{public}d", ret); return ret; } + READINT32(reply, keyboardType, IPC_PROXY_DEAD_OBJECT_ERR); return RET_OK; } int32_t MultimodalInputConnectProxy::AddInputHandler(InputHandlerType handlerType, - HandleEventType eventType) + HandleEventType eventType, int32_t priority, uint32_t deviceTags) { CALL_DEBUG_ENTER; MessageParcel data; @@ -373,6 +489,8 @@ int32_t MultimodalInputConnectProxy::AddInputHandler(InputHandlerType handlerTyp } WRITEINT32(data, handlerType, ERR_INVALID_VALUE); WRITEUINT32(data, eventType, ERR_INVALID_VALUE); + WRITEINT32(data, priority, ERR_INVALID_VALUE); + WRITEUINT32(data, deviceTags, ERR_INVALID_VALUE); MessageParcel reply; MessageOption option; sptr remote = Remote(); @@ -385,7 +503,8 @@ int32_t MultimodalInputConnectProxy::AddInputHandler(InputHandlerType handlerTyp return RET_OK; } -int32_t MultimodalInputConnectProxy::RemoveInputHandler(InputHandlerType handlerType, HandleEventType eventType) +int32_t MultimodalInputConnectProxy::RemoveInputHandler(InputHandlerType handlerType, + HandleEventType eventType, int32_t priority, uint32_t deviceTags) { CALL_DEBUG_ENTER; MessageParcel data; @@ -395,6 +514,8 @@ int32_t MultimodalInputConnectProxy::RemoveInputHandler(InputHandlerType handler } WRITEINT32(data, handlerType, ERR_INVALID_VALUE); WRITEUINT32(data, eventType, ERR_INVALID_VALUE); + WRITEINT32(data, priority, ERR_INVALID_VALUE); + WRITEUINT32(data, eventType, ERR_INVALID_VALUE); MessageParcel reply; MessageOption option; sptr remote = Remote(); @@ -571,7 +692,7 @@ int32_t MultimodalInputConnectProxy::SetAnrObserver() return RET_OK; } -int32_t MultimodalInputConnectProxy::SetInputDevice(const std::string& dhid, const std::string& screenId) +int32_t MultimodalInputConnectProxy::GetDisplayBindInfo(DisplayBindInfos &infos) { CALL_DEBUG_ENTER; MessageParcel data; @@ -579,15 +700,46 @@ int32_t MultimodalInputConnectProxy::SetInputDevice(const std::string& dhid, con MMI_HILOGE("Failed to write descriptor"); return ERR_INVALID_VALUE; } + MessageParcel reply; + MessageOption option; + sptr remote = Remote(); + CHKPR(remote, RET_ERR); + int32_t ret = remote->SendRequest(GET_DISPLAY_BIND_INFO, data, reply, option); + if (ret != RET_OK) { + MMI_HILOGE("Send request failed, ret:%{public}d", ret); + return ret; + } + int32_t size = 0; + READINT32(reply, size, ERR_INVALID_VALUE); + infos.reserve(size); + for (int32_t i = 0; i < size; ++i) { + DisplayBindInfo info; + READINT32(reply, info.inputDeviceId, ERR_INVALID_VALUE); + READSTRING(reply, info.inputDeviceName, ERR_INVALID_VALUE); + READINT32(reply, info.displayId, ERR_INVALID_VALUE); + READSTRING(reply, info.displayName, ERR_INVALID_VALUE); + infos.push_back(info); + } + return RET_OK; +} - WRITESTRING(data, dhid, ERR_INVALID_VALUE); - WRITESTRING(data, screenId, ERR_INVALID_VALUE); +int32_t MultimodalInputConnectProxy::SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg) +{ + CALL_DEBUG_ENTER; + MessageParcel data; + if (!data.WriteInterfaceToken(MultimodalInputConnectProxy::GetDescriptor())) { + MMI_HILOGE("Failed to write descriptor"); + return ERR_INVALID_VALUE; + } + + WRITEINT32(data, deviceId, ERR_INVALID_VALUE); + WRITEINT32(data, displayId, ERR_INVALID_VALUE); MessageParcel reply; MessageOption option; sptr remote = Remote(); CHKPR(remote, RET_ERR); - int32_t ret = remote->SendRequest(SET_INPUT_DEVICE_TO_SCREEN, data, reply, option); + int32_t ret = remote->SendRequest(SET_DISPLAY_BIND, data, reply, option); if (ret != RET_OK) { MMI_HILOGE("Send request fail, result:%{public}d", ret); return ret; @@ -595,7 +747,7 @@ int32_t MultimodalInputConnectProxy::SetInputDevice(const std::string& dhid, con return RET_OK; } -int32_t MultimodalInputConnectProxy::RegisterCooperateListener() +int32_t MultimodalInputConnectProxy::GetWindowPid(int32_t windowId) { CALL_DEBUG_ENTER; MessageParcel data; @@ -603,18 +755,24 @@ int32_t MultimodalInputConnectProxy::RegisterCooperateListener() MMI_HILOGE("Failed to write descriptor"); return ERR_INVALID_VALUE; } + + WRITEINT32(data, windowId, ERR_INVALID_VALUE); + MessageParcel reply; MessageOption option; sptr remote = Remote(); CHKPR(remote, RET_ERR); - int32_t ret = remote->SendRequest(REGISTER_COOPERATE_MONITOR, data, reply, option); + int32_t ret = remote->SendRequest(GET_WINDOW_PID, data, reply, option); if (ret != RET_OK) { - MMI_HILOGE("Send request fail, ret:%{public}d", ret); + MMI_HILOGE("Send request fail, result:%{public}d", ret); + return ret; } - return ret; + int32_t windowPid = -1; + READINT32(reply, windowPid, ERR_INVALID_VALUE); + return windowPid; } -int32_t MultimodalInputConnectProxy::UnregisterCooperateListener() +int32_t MultimodalInputConnectProxy::SetInputDevice(const std::string& dhid, const std::string& screenId) { CALL_DEBUG_ENTER; MessageParcel data; @@ -622,18 +780,23 @@ int32_t MultimodalInputConnectProxy::UnregisterCooperateListener() MMI_HILOGE("Failed to write descriptor"); return ERR_INVALID_VALUE; } + + WRITESTRING(data, dhid, ERR_INVALID_VALUE); + WRITESTRING(data, screenId, ERR_INVALID_VALUE); + MessageParcel reply; MessageOption option; sptr remote = Remote(); CHKPR(remote, RET_ERR); - int32_t ret = remote->SendRequest(UNREGISTER_COOPERATE_MONITOR, data, reply, option); + int32_t ret = remote->SendRequest(SET_INPUT_DEVICE_TO_SCREEN, data, reply, option); if (ret != RET_OK) { - MMI_HILOGE("Send request fail, ret:%{public}d", ret); + MMI_HILOGE("Send request fail, result:%{public}d", ret); + return ret; } - return ret; + return RET_OK; } -int32_t MultimodalInputConnectProxy::EnableInputDeviceCooperate(int32_t userData, bool enabled) +int32_t MultimodalInputConnectProxy::RegisterCooperateListener() { CALL_DEBUG_ENTER; MessageParcel data; @@ -641,21 +804,18 @@ int32_t MultimodalInputConnectProxy::EnableInputDeviceCooperate(int32_t userData MMI_HILOGE("Failed to write descriptor"); return ERR_INVALID_VALUE; } - WRITEINT32(data, userData, ERR_INVALID_VALUE); - WRITEBOOL(data, enabled, ERR_INVALID_VALUE); MessageParcel reply; MessageOption option; sptr remote = Remote(); CHKPR(remote, RET_ERR); - int32_t ret = remote->SendRequest(ENABLE_INPUT_DEVICE_COOPERATE, data, reply, option); + int32_t ret = remote->SendRequest(REGISTER_COOPERATE_MONITOR, data, reply, option); if (ret != RET_OK) { MMI_HILOGE("Send request fail, ret:%{public}d", ret); } return ret; } -int32_t MultimodalInputConnectProxy::StartInputDeviceCooperate(int32_t userData, const std::string &sinkDeviceId, - int32_t srcInputDeviceId) +int32_t MultimodalInputConnectProxy::UnregisterCooperateListener() { CALL_DEBUG_ENTER; MessageParcel data; @@ -663,21 +823,18 @@ int32_t MultimodalInputConnectProxy::StartInputDeviceCooperate(int32_t userData, MMI_HILOGE("Failed to write descriptor"); return ERR_INVALID_VALUE; } - WRITEINT32(data, userData, ERR_INVALID_VALUE); - WRITESTRING(data, sinkDeviceId, ERR_INVALID_VALUE); - WRITEINT32(data, srcInputDeviceId, ERR_INVALID_VALUE); MessageParcel reply; MessageOption option; sptr remote = Remote(); CHKPR(remote, RET_ERR); - int32_t ret = remote->SendRequest(START_INPUT_DEVICE_COOPERATE, data, reply, option); + int32_t ret = remote->SendRequest(UNREGISTER_COOPERATE_MONITOR, data, reply, option); if (ret != RET_OK) { MMI_HILOGE("Send request fail, ret:%{public}d", ret); } return ret; } -int32_t MultimodalInputConnectProxy::StopDeviceCooperate(int32_t userData) +int32_t MultimodalInputConnectProxy::EnableInputDeviceCooperate(int32_t userData, bool enabled) { CALL_DEBUG_ENTER; MessageParcel data; @@ -686,18 +843,20 @@ int32_t MultimodalInputConnectProxy::StopDeviceCooperate(int32_t userData) return ERR_INVALID_VALUE; } WRITEINT32(data, userData, ERR_INVALID_VALUE); + WRITEBOOL(data, enabled, ERR_INVALID_VALUE); MessageParcel reply; MessageOption option; sptr remote = Remote(); CHKPR(remote, RET_ERR); - int32_t ret = remote->SendRequest(STOP_DEVICE_COOPERATE, data, reply, option); + int32_t ret = remote->SendRequest(ENABLE_INPUT_DEVICE_COOPERATE, data, reply, option); if (ret != RET_OK) { MMI_HILOGE("Send request fail, ret:%{public}d", ret); } return ret; } -int32_t MultimodalInputConnectProxy::GetInputDeviceCooperateState(int32_t userData, const std::string &deviceId) +int32_t MultimodalInputConnectProxy::StartInputDeviceCooperate(int32_t userData, const std::string &sinkDeviceId, + int32_t srcInputDeviceId) { CALL_DEBUG_ENTER; MessageParcel data; @@ -706,65 +865,63 @@ int32_t MultimodalInputConnectProxy::GetInputDeviceCooperateState(int32_t userDa return ERR_INVALID_VALUE; } WRITEINT32(data, userData, ERR_INVALID_VALUE); - WRITESTRING(data, deviceId, ERR_INVALID_VALUE); + WRITESTRING(data, sinkDeviceId, ERR_INVALID_VALUE); + WRITEINT32(data, srcInputDeviceId, ERR_INVALID_VALUE); MessageParcel reply; MessageOption option; sptr remote = Remote(); CHKPR(remote, RET_ERR); - int32_t ret = remote->SendRequest(GET_INPUT_DEVICE_COOPERATE_STATE, data, reply, option); + int32_t ret = remote->SendRequest(START_INPUT_DEVICE_COOPERATE, data, reply, option); if (ret != RET_OK) { MMI_HILOGE("Send request fail, ret:%{public}d", ret); } return ret; } -int32_t MultimodalInputConnectProxy::StartRemoteCooperate(const std::string& localDeviceId) +int32_t MultimodalInputConnectProxy::StopDeviceCooperate(int32_t userData) { - CALL_INFO_TRACE; + CALL_DEBUG_ENTER; MessageParcel data; if (!data.WriteInterfaceToken(MultimodalInputConnectProxy::GetDescriptor())) { MMI_HILOGE("Failed to write descriptor"); return ERR_INVALID_VALUE; } - WRITESTRING(data, localDeviceId, ERR_INVALID_VALUE); + WRITEINT32(data, userData, ERR_INVALID_VALUE); MessageParcel reply; MessageOption option; sptr remote = Remote(); CHKPR(remote, RET_ERR); - int32_t ret = remote->SendRequest(REMOTE_COOPERATE_START, data, reply, option); + int32_t ret = remote->SendRequest(STOP_DEVICE_COOPERATE, data, reply, option); if (ret != RET_OK) { MMI_HILOGE("Send request fail, ret:%{public}d", ret); } return ret; } -int32_t MultimodalInputConnectProxy::StartRemoteCooperateResult(bool isSuccess, - const std::string& startDhid, int32_t xPercent, int32_t yPercent) +int32_t MultimodalInputConnectProxy::GetInputDeviceCooperateState(int32_t userData, const std::string &deviceId) { - CALL_INFO_TRACE; + CALL_DEBUG_ENTER; MessageParcel data; if (!data.WriteInterfaceToken(MultimodalInputConnectProxy::GetDescriptor())) { MMI_HILOGE("Failed to write descriptor"); return ERR_INVALID_VALUE; } - WRITEBOOL(data, isSuccess, ERR_INVALID_VALUE); - WRITESTRING(data, startDhid, ERR_INVALID_VALUE); - WRITEINT32(data, xPercent, ERR_INVALID_VALUE); - WRITEINT32(data, yPercent, ERR_INVALID_VALUE); + WRITEINT32(data, userData, ERR_INVALID_VALUE); + WRITESTRING(data, deviceId, ERR_INVALID_VALUE); MessageParcel reply; MessageOption option; sptr remote = Remote(); CHKPR(remote, RET_ERR); - int32_t ret = remote->SendRequest(REMOTE_COOPERATE_START_RES, data, reply, option); + int32_t ret = remote->SendRequest(GET_INPUT_DEVICE_COOPERATE_STATE, data, reply, option); if (ret != RET_OK) { MMI_HILOGE("Send request fail, ret:%{public}d", ret); } return ret; } -int32_t MultimodalInputConnectProxy::StopRemoteCooperate() +int32_t MultimodalInputConnectProxy::GetFunctionKeyState(int32_t funcKey, bool &state) { - CALL_INFO_TRACE; + CALL_DEBUG_ENTER; MessageParcel data; if (!data.WriteInterfaceToken(MultimodalInputConnectProxy::GetDescriptor())) { MMI_HILOGE("Failed to write descriptor"); @@ -772,56 +929,61 @@ int32_t MultimodalInputConnectProxy::StopRemoteCooperate() } MessageParcel reply; MessageOption option; + WRITEINT32(data, funcKey, ERR_INVALID_VALUE); sptr remote = Remote(); CHKPR(remote, RET_ERR); - int32_t ret = remote->SendRequest(REMOTE_COOPERATE_STOP, data, reply, option); + int32_t ret = remote->SendRequest(GET_FUNCTION_KEY_STATE, data, reply, option); if (ret != RET_OK) { - MMI_HILOGE("Send request fail, ret:%{public}d", ret); + MMI_HILOGE("Send request failed, ret:%{public}d", ret); + return ret; } - return ret; + READBOOL(reply, state, ERR_INVALID_VALUE); + return RET_OK; } -int32_t MultimodalInputConnectProxy::StopRemoteCooperateResult(bool isSuccess) +int32_t MultimodalInputConnectProxy::SetFunctionKeyState(int32_t funcKey, bool enable) { - CALL_INFO_TRACE; + CALL_DEBUG_ENTER; MessageParcel data; if (!data.WriteInterfaceToken(MultimodalInputConnectProxy::GetDescriptor())) { MMI_HILOGE("Failed to write descriptor"); return ERR_INVALID_VALUE; } - WRITEBOOL(data, isSuccess, ERR_INVALID_VALUE); MessageParcel reply; MessageOption option; + WRITEINT32(data, funcKey, ERR_INVALID_VALUE); + WRITEBOOL(data, enable, ERR_INVALID_VALUE); sptr remote = Remote(); CHKPR(remote, RET_ERR); - int32_t ret = remote->SendRequest(REMOTE_COOPERATE_STOP_RES, data, reply, option); + int32_t ret = remote->SendRequest(SET_FUNCTION_KEY_STATE, data, reply, option); if (ret != RET_OK) { - MMI_HILOGE("Send request fail, ret:%{public}d", ret); + MMI_HILOGE("Send request failed, ret:%{public}d", ret); } return ret; } -int32_t MultimodalInputConnectProxy::StartCooperateOtherResult(const std::string& srcNetworkId) +int32_t MultimodalInputConnectProxy::SetPointerLocation(int32_t x, int32_t y) { - CALL_INFO_TRACE; + CALL_DEBUG_ENTER; MessageParcel data; if (!data.WriteInterfaceToken(MultimodalInputConnectProxy::GetDescriptor())) { MMI_HILOGE("Failed to write descriptor"); return ERR_INVALID_VALUE; } - WRITESTRING(data, srcNetworkId, ERR_INVALID_VALUE); MessageParcel reply; MessageOption option; + WRITEINT32(data, x, ERR_INVALID_VALUE); + WRITEINT32(data, y, ERR_INVALID_VALUE); sptr remote = Remote(); CHKPR(remote, RET_ERR); - int32_t ret = remote->SendRequest(REMOTE_COOPERATE_STOP_OTHER_RES, data, reply, option); + int32_t ret = remote->SendRequest(SET_POINTER_LOCATION, data, reply, option); if (ret != RET_OK) { - MMI_HILOGE("Send request fail, ret:%{public}d", ret); + MMI_HILOGE("Send request failed, ret:%{public}d", ret); } return ret; } -int32_t MultimodalInputConnectProxy::GetFunctionKeyState(int32_t funcKey, bool &state) +int32_t MultimodalInputConnectProxy::SetMouseCaptureMode(int32_t windowId, bool isCaptureMode) { CALL_DEBUG_ENTER; MessageParcel data; @@ -829,21 +991,20 @@ int32_t MultimodalInputConnectProxy::GetFunctionKeyState(int32_t funcKey, bool & MMI_HILOGE("Failed to write descriptor"); return ERR_INVALID_VALUE; } + WRITEINT32(data, windowId, ERR_INVALID_VALUE); + WRITEBOOL(data, isCaptureMode, ERR_INVALID_VALUE); MessageParcel reply; MessageOption option; - WRITEINT32(data, funcKey, ERR_INVALID_VALUE); sptr remote = Remote(); CHKPR(remote, RET_ERR); - int32_t ret = remote->SendRequest(GET_FUNCTION_KEY_STATE, data, reply, option); + int32_t ret = remote->SendRequest(SET_CAPTURE_MODE, data, reply, option); if (ret != RET_OK) { - MMI_HILOGE("Send request failed, ret:%{public}d", ret); - return ret; + MMI_HILOGE("Send request fail, ret:%{public}d", ret); } - READBOOL(reply, state, ERR_INVALID_VALUE); - return RET_OK; + return ret; } -int32_t MultimodalInputConnectProxy::SetFunctionKeyState(int32_t funcKey, bool enable) +int32_t MultimodalInputConnectProxy::AppendExtraData(const ExtraData& extraData) { CALL_DEBUG_ENTER; MessageParcel data; @@ -851,15 +1012,20 @@ int32_t MultimodalInputConnectProxy::SetFunctionKeyState(int32_t funcKey, bool e MMI_HILOGE("Failed to write descriptor"); return ERR_INVALID_VALUE; } + WRITEBOOL(data, extraData.appended, ERR_INVALID_VALUE); + WRITEINT32(data, static_cast(extraData.buffer.size())); + for (const auto &item : extraData.buffer) { + WRITEUINT8(data, item); + } + WRITEINT32(data, extraData.sourceType, ERR_INVALID_VALUE); + WRITEINT32(data, extraData.pointerId, ERR_INVALID_VALUE); MessageParcel reply; MessageOption option; - WRITEINT32(data, funcKey, ERR_INVALID_VALUE); - WRITEBOOL(data, enable, ERR_INVALID_VALUE); sptr remote = Remote(); CHKPR(remote, RET_ERR); - int32_t ret = remote->SendRequest(SET_FUNCTION_KEY_STATE, data, reply, option); + int32_t ret = remote->SendRequest(APPEND_EXTRA_DATA, data, reply, option); if (ret != RET_OK) { - MMI_HILOGE("Send request failed, ret:%{public}d", ret); + MMI_HILOGE("Send request fail, ret:%{public}d", ret); } return ret; } diff --git a/service/connect_manager/src/multimodal_input_connect_remoter.cpp b/service/connect_manager/src/multimodal_input_connect_remoter.cpp deleted file mode 100755 index 9f959b0905ee2c226dd48d0dfc2676a739ab74e1..0000000000000000000000000000000000000000 --- a/service/connect_manager/src/multimodal_input_connect_remoter.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/* - * 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. - */ - -#include "multimodal_input_connect_remoter.h" - -#include -#include - -#include "iservice_registry.h" -#include "system_ability_definition.h" - -#include "mmi_log.h" -#include "multimodal_input_connect_death_recipient.h" -#include "multimodal_input_connect_define.h" -#include "util.h" - -namespace OHOS { -namespace MMI { -namespace { -std::shared_ptr g_instance = nullptr; -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "MultimodalInputConnectRemoter"}; -} // namespace - -std::shared_ptr MultimodalInputConnectRemoter::GetInstance() -{ - static std::once_flag flag; - std::call_once(flag, [&]() { - g_instance.reset(new (std::nothrow) MultimodalInputConnectRemoter()); - }); - return g_instance; -} - -int32_t MultimodalInputConnectRemoter::StartRemoteCooperate(const std::string &localDeviceId, - const std::string &remoteDeviceId) -{ - CALL_DEBUG_ENTER; - auto proxy = GetProxyById(remoteDeviceId); - CHKPR(proxy, RET_ERR); - return proxy->StartRemoteCooperate(localDeviceId); -} - -int32_t MultimodalInputConnectRemoter::StartRemoteCooperateResult(const std::string &remoteDeviceId, bool isSuccess, - const std::string &startDhid, int32_t xPercent, int32_t yPercent) -{ - CALL_DEBUG_ENTER; - auto proxy = GetProxyById(remoteDeviceId); - CHKPR(proxy, RET_ERR); - return proxy->StartRemoteCooperateResult(isSuccess, startDhid, xPercent, yPercent); -} - -int32_t MultimodalInputConnectRemoter::StopRemoteCooperate(const std::string &remoteDeviceId) -{ - CALL_DEBUG_ENTER; - auto proxy = GetProxyById(remoteDeviceId); - CHKPR(proxy, RET_ERR); - return proxy->StopRemoteCooperate(); -} - -int32_t MultimodalInputConnectRemoter::StopRemoteCooperateResult(const std::string &remoteDeviceId, bool isSuccess) -{ - CALL_DEBUG_ENTER; - auto proxy = GetProxyById(remoteDeviceId); - CHKPR(proxy, RET_ERR); - return proxy->StopRemoteCooperateResult(isSuccess); -} - -int32_t MultimodalInputConnectRemoter::StartCooperateOtherResult(const std::string &remoteDeviceId, - const std::string &srcNetworkId) -{ - CALL_DEBUG_ENTER; - auto proxy = GetProxyById(remoteDeviceId); - CHKPR(proxy, RET_ERR); - return proxy->StartCooperateOtherResult(srcNetworkId); -} - -sptr MultimodalInputConnectRemoter::GetProxyById(const std::string &remoteDeviceId) -{ - CALL_DEBUG_ENTER; - std::lock_guard guard(lock_); - auto iterService = mmiRemoteServices_.find(remoteDeviceId); - if (iterService != mmiRemoteServices_.end()) { - return iterService->second; - } - auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - CHKPP(sm); - auto sa = sm->GetSystemAbility(IMultimodalInputConnect::MULTIMODAL_INPUT_CONNECT_SERVICE_ID, remoteDeviceId); - CHKPP(sa); - std::weak_ptr weakPtr = shared_from_this(); - auto deathCallback = [remoteDeviceId, weakPtr](const wptr &object) { - auto sharedPtr = weakPtr.lock(); - if (sharedPtr != nullptr) { - sharedPtr->OnRemoteDeath(remoteDeviceId); - } - }; - sptr deathRecipient = - new (std::nothrow) MultimodalInputConnectDeathRecipient(deathCallback); - CHKPP(deathRecipient); - sa->AddDeathRecipient(deathRecipient); - auto retDeath = mmiDeathRecipients_.emplace(remoteDeviceId, deathRecipient); - if (!retDeath.second) { - MMI_HILOGE("Get proxy faild, death recipient not set"); - return nullptr; - } - sptr remoteService = iface_cast(sa); - if (remoteService == nullptr) { - MMI_HILOGE("Get proxy faild, get remote service is null!"); - OnRemoteDeath(remoteDeviceId); - return nullptr; - } - auto retService = mmiRemoteServices_.emplace(remoteDeviceId, remoteService); - if (!retService.second) { - MMI_HILOGE("Get proxy faild, remote service not set!"); - OnRemoteDeath(remoteDeviceId); - return nullptr; - } - return remoteService; -} - -void MultimodalInputConnectRemoter::OnRemoteDeath(const std::string &remoteDeviceId) -{ - CALL_DEBUG_ENTER; - auto iterService = mmiRemoteServices_.find(remoteDeviceId); - if (iterService != mmiRemoteServices_.end()) { - mmiRemoteServices_.erase(iterService); - } - auto iterRecipient = mmiDeathRecipients_.find(remoteDeviceId); - if (iterRecipient != mmiDeathRecipients_.end()) { - mmiDeathRecipients_.erase(iterRecipient); - } -} -} // namespace MMI -} // namespace OHOS \ No newline at end of file diff --git a/service/connect_manager/src/multimodal_input_connect_stub.cpp b/service/connect_manager/src/multimodal_input_connect_stub.cpp index 68bb4edbeca50d797396ea79c7d169bfc967bd71..fb4899d710e0782e1a3eba85e40518e04ad4d205 100644 --- a/service/connect_manager/src/multimodal_input_connect_stub.cpp +++ b/service/connect_manager/src/multimodal_input_connect_stub.cpp @@ -15,16 +15,16 @@ #include "multimodal_input_connect_stub.h" -#include #include #include +#include #include "string_ex.h" #include "error_multimodal.h" #include "multimodal_input_connect_def_parcel.h" -#include "time_cost_chk.h" #include "permission_helper.h" +#include "time_cost_chk.h" namespace OHOS { namespace MMI { @@ -49,6 +49,7 @@ int32_t MultimodalInputConnectStub::OnRemoteRequest(uint32_t code, MessageParcel const static std::map mapConnFunc = { {IMultimodalInputConnect::ALLOC_SOCKET_FD, &MultimodalInputConnectStub::StubHandleAllocSocketFd}, {IMultimodalInputConnect::ADD_INPUT_EVENT_FILTER, &MultimodalInputConnectStub::StubAddInputEventFilter}, + {IMultimodalInputConnect::RMV_INPUT_EVENT_FILTER, &MultimodalInputConnectStub::StubRemoveInputEventFilter}, {IMultimodalInputConnect::SET_POINTER_VISIBLE, &MultimodalInputConnectStub::StubSetPointerVisible}, {IMultimodalInputConnect::SET_POINTER_STYLE, &MultimodalInputConnectStub::StubSetPointerStyle}, {IMultimodalInputConnect::GET_POINTER_STYLE, &MultimodalInputConnectStub::StubGetPointerStyle}, @@ -64,6 +65,7 @@ int32_t MultimodalInputConnectStub::OnRemoteRequest(uint32_t code, MessageParcel {IMultimodalInputConnect::GET_POINTER_SPEED, &MultimodalInputConnectStub::StubGetPointerSpeed}, {IMultimodalInputConnect::SUBSCRIBE_KEY_EVENT, &MultimodalInputConnectStub::StubSubscribeKeyEvent}, {IMultimodalInputConnect::UNSUBSCRIBE_KEY_EVENT, &MultimodalInputConnectStub::StubUnsubscribeKeyEvent}, + {IMultimodalInputConnect::MARK_PROCESSED, &MultimodalInputConnectStub::StubMarkProcessed}, {IMultimodalInputConnect::ADD_INPUT_HANDLER, &MultimodalInputConnectStub::StubAddInputHandler}, {IMultimodalInputConnect::REMOVE_INPUT_HANDLER, &MultimodalInputConnectStub::StubRemoveInputHandler}, {IMultimodalInputConnect::MARK_EVENT_CONSUMED, &MultimodalInputConnectStub::StubMarkEventConsumed}, @@ -71,6 +73,8 @@ int32_t MultimodalInputConnectStub::OnRemoteRequest(uint32_t code, MessageParcel {IMultimodalInputConnect::INJECT_KEY_EVENT, &MultimodalInputConnectStub::StubInjectKeyEvent}, {IMultimodalInputConnect::INJECT_POINTER_EVENT, &MultimodalInputConnectStub::StubInjectPointerEvent}, {IMultimodalInputConnect::SET_ANR_OBSERVER, &MultimodalInputConnectStub::StubSetAnrListener}, + {IMultimodalInputConnect::GET_DISPLAY_BIND_INFO, &MultimodalInputConnectStub::StubGetDisplayBindInfo}, + {IMultimodalInputConnect::SET_DISPLAY_BIND, &MultimodalInputConnectStub::StubSetDisplayBind}, {IMultimodalInputConnect::REGISTER_COOPERATE_MONITOR, &MultimodalInputConnectStub::StubRegisterCooperateMonitor}, {IMultimodalInputConnect::UNREGISTER_COOPERATE_MONITOR, @@ -83,14 +87,12 @@ int32_t MultimodalInputConnectStub::OnRemoteRequest(uint32_t code, MessageParcel {IMultimodalInputConnect::GET_INPUT_DEVICE_COOPERATE_STATE, &MultimodalInputConnectStub::StubGetInputDeviceCooperateState}, {IMultimodalInputConnect::SET_INPUT_DEVICE_TO_SCREEN, &MultimodalInputConnectStub::StubSetInputDevice}, - {IMultimodalInputConnect::REMOTE_COOPERATE_START, &MultimodalInputConnectStub::StubStartRemoteCooperate}, - {IMultimodalInputConnect::REMOTE_COOPERATE_START_RES, &MultimodalInputConnectStub::StubStartRemoteCooperateRes}, - {IMultimodalInputConnect::REMOTE_COOPERATE_STOP, &MultimodalInputConnectStub::StubStopRemoteCooperate}, - {IMultimodalInputConnect::REMOTE_COOPERATE_STOP_RES, &MultimodalInputConnectStub::StubStopRemoteCooperateRes}, - {IMultimodalInputConnect::REMOTE_COOPERATE_STOP_OTHER_RES, - &MultimodalInputConnectStub::StubStartCooperateOtherRes}, {IMultimodalInputConnect::GET_FUNCTION_KEY_STATE, &MultimodalInputConnectStub::StubGetFunctionKeyState}, - {IMultimodalInputConnect::SET_FUNCTION_KEY_STATE, &MultimodalInputConnectStub::StubSetFunctionKeyState} + {IMultimodalInputConnect::SET_FUNCTION_KEY_STATE, &MultimodalInputConnectStub::StubSetFunctionKeyState}, + {IMultimodalInputConnect::SET_POINTER_LOCATION, &MultimodalInputConnectStub::StubSetPointerLocation}, + {IMultimodalInputConnect::SET_CAPTURE_MODE, &MultimodalInputConnectStub::StubSetMouseCaptureMode}, + {IMultimodalInputConnect::GET_WINDOW_PID, &MultimodalInputConnectStub::StubGetWindowPid}, + {IMultimodalInputConnect::APPEND_EXTRA_DATA, &MultimodalInputConnectStub::StubAppendExtraData}, }; auto it = mapConnFunc.find(code); if (it != mapConnFunc.end()) { @@ -121,7 +123,12 @@ int32_t MultimodalInputConnectStub::StubHandleAllocSocketFd(MessageParcel& data, } return ret; } - reply.WriteFileDescriptor(clientFd); + + if (!reply.WriteFileDescriptor(clientFd)) { + MMI_HILOGE("Write file descriptor failed"); + return IPC_STUB_WRITE_PARCEL_ERR; + } + WRITEINT32(reply, tokenType, IPC_STUB_WRITE_PARCEL_ERR); MMI_HILOGI("Send clientFd to client, clientFd:%{public}d, tokenType:%{public}d", clientFd, tokenType); close(clientFd); @@ -140,8 +147,13 @@ int32_t MultimodalInputConnectStub::StubAddInputEventFilter(MessageParcel& data, CHKPR(client, ERR_INVALID_VALUE); sptr filter = iface_cast(client); CHKPR(filter, ERROR_NULL_POINTER); - - int32_t ret = AddInputEventFilter(filter); + int32_t filterId = -1; + READINT32(data, filterId, IPC_PROXY_DEAD_OBJECT_ERR); + int32_t priority = 0; + READINT32(data, priority, IPC_PROXY_DEAD_OBJECT_ERR); + uint32_t deviceTags = 0; + READUINT32(data, deviceTags, IPC_PROXY_DEAD_OBJECT_ERR); + int32_t ret = AddInputEventFilter(filter, filterId, priority, deviceTags); if (ret != RET_OK) { MMI_HILOGE("Call AddInputEventFilter failed ret:%{public}d", ret); return ret; @@ -150,14 +162,27 @@ int32_t MultimodalInputConnectStub::StubAddInputEventFilter(MessageParcel& data, return RET_OK; } -int32_t MultimodalInputConnectStub::StubSetPointerVisible(MessageParcel& data, MessageParcel& reply) +int32_t MultimodalInputConnectStub::StubRemoveInputEventFilter(MessageParcel& data, MessageParcel& reply) { CALL_DEBUG_ENTER; - if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) { + if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_CORE)) { MMI_HILOGE("Permission check failed"); return CHECK_PERMISSION_FAIL; } + int32_t filterId = -1; + READINT32(data, filterId, IPC_PROXY_DEAD_OBJECT_ERR); + int32_t ret = RemoveInputEventFilter(filterId); + if (ret != RET_OK) { + MMI_HILOGE("Call RemoveInputEventFilter failed ret:%{public}d", ret); + return ret; + } + MMI_HILOGD("Success pid:%{public}d", GetCallingPid()); + return RET_OK; +} +int32_t MultimodalInputConnectStub::StubSetPointerVisible(MessageParcel& data, MessageParcel& reply) +{ + CALL_DEBUG_ENTER; bool visible = false; READBOOL(data, visible, IPC_PROXY_DEAD_OBJECT_ERR); int32_t ret = SetPointerVisible(visible); @@ -172,11 +197,6 @@ int32_t MultimodalInputConnectStub::StubSetPointerVisible(MessageParcel& data, M int32_t MultimodalInputConnectStub::StubIsPointerVisible(MessageParcel& data, MessageParcel& reply) { CALL_DEBUG_ENTER; - if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) { - MMI_HILOGE("Permission check failed"); - return CHECK_PERMISSION_FAIL; - } - bool visible = false; int32_t ret = IsPointerVisible(visible); if (ret != RET_OK) { @@ -188,6 +208,24 @@ int32_t MultimodalInputConnectStub::StubIsPointerVisible(MessageParcel& data, Me return RET_OK; } +int32_t MultimodalInputConnectStub::StubMarkProcessed(MessageParcel& data, MessageParcel& reply) +{ + CALL_DEBUG_ENTER; + if (!IsRunning()) { + MMI_HILOGE("Service is not running"); + } + int32_t eventType; + READINT32(data, eventType, IPC_PROXY_DEAD_OBJECT_ERR); + int32_t eventId; + READINT32(data, eventId, IPC_PROXY_DEAD_OBJECT_ERR); + int32_t ret = MarkProcessed(eventType, eventId); + if (ret != RET_OK) { + MMI_HILOGE("MarkProcessed failed, ret:%{public}d", ret); + return ret; + } + return RET_OK; +} + int32_t MultimodalInputConnectStub::StubSetPointerSpeed(MessageParcel& data, MessageParcel& reply) { CALL_DEBUG_ENTER; @@ -228,14 +266,18 @@ int32_t MultimodalInputConnectStub::StubSetPointerStyle(MessageParcel& data, Mes CALL_DEBUG_ENTER; int32_t windowId; READINT32(data, windowId, RET_ERR); - int32_t pointerStyle; - READINT32(data, pointerStyle, RET_ERR); + PointerStyle pointerStyle; + READINT32(data, pointerStyle.size, RET_ERR); + READUINT8(data, pointerStyle.color.r, RET_ERR); + READUINT8(data, pointerStyle.color.g, RET_ERR); + READUINT8(data, pointerStyle.color.b, RET_ERR); + READINT32(data, pointerStyle.id, RET_ERR); int32_t ret = SetPointerStyle(windowId, pointerStyle); if (ret != RET_OK) { MMI_HILOGE("Call SetPointerStyle failed ret:%{public}d", ret); return ret; } - MMI_HILOGD("Successfully set window:%{public}d, icon:%{public}d", windowId, pointerStyle); + MMI_HILOGD("Successfully set window:%{public}d, icon:%{public}d", windowId, pointerStyle.id); return RET_OK; } @@ -244,22 +286,24 @@ int32_t MultimodalInputConnectStub::StubGetPointerStyle(MessageParcel& data, Mes CALL_DEBUG_ENTER; int32_t windowId; READINT32(data, windowId, RET_ERR); - int32_t pointerStyle; + PointerStyle pointerStyle; int32_t ret = GetPointerStyle(windowId, pointerStyle); if (ret != RET_OK) { MMI_HILOGE("Call GetPointerStyle failed ret:%{public}d", ret); return ret; } - WRITEINT32(reply, pointerStyle, RET_ERR); - MMI_HILOGD("Successfully get window:%{public}d, icon:%{public}d", windowId, pointerStyle); + WRITEINT32(reply, pointerStyle.size, RET_ERR); + WRITEUINT8(reply, pointerStyle.color.r, RET_ERR); + WRITEUINT8(reply, pointerStyle.color.g, RET_ERR); + WRITEUINT8(reply, pointerStyle.color.b, RET_ERR); + WRITEINT32(reply, pointerStyle.id, RET_ERR); + MMI_HILOGD("Successfully get window:%{public}d, icon:%{public}d", windowId, pointerStyle.id); return RET_OK; } int32_t MultimodalInputConnectStub::StubSupportKeys(MessageParcel& data, MessageParcel& reply) { CALL_DEBUG_ENTER; - int32_t userData = 0; - READINT32(data, userData, IPC_PROXY_DEAD_OBJECT_ERR); int32_t deviceId = -1; READINT32(data, deviceId, IPC_PROXY_DEAD_OBJECT_ERR); int32_t size = 0; @@ -270,9 +314,15 @@ int32_t MultimodalInputConnectStub::StubSupportKeys(MessageParcel& data, Message READINT32(data, key, IPC_PROXY_DEAD_OBJECT_ERR); keys.push_back(key); } - int32_t ret = SupportKeys(userData, deviceId, keys); + std::vector keystroke; + int32_t ret = SupportKeys(deviceId, keys, keystroke); if (ret != RET_OK) { MMI_HILOGE("Call SupportKeys failed ret:%{public}d", ret); + return RET_ERR; + } + if (!reply.WriteBoolVector(keystroke)) { + MMI_HILOGE("Write keyStroke failed"); + return RET_ERR; } return ret; } @@ -280,11 +330,15 @@ int32_t MultimodalInputConnectStub::StubSupportKeys(MessageParcel& data, Message int32_t MultimodalInputConnectStub::StubGetDeviceIds(MessageParcel& data, MessageParcel& reply) { CALL_DEBUG_ENTER; - int32_t userData = 0; - READINT32(data, userData, IPC_PROXY_DEAD_OBJECT_ERR); - int32_t ret = GetDeviceIds(userData); + std::vector ids; + int32_t ret = GetDeviceIds(ids); if (ret != RET_OK) { MMI_HILOGE("Call GetDeviceIds failed ret:%{public}d", ret); + return RET_ERR; + } + if (!reply.WriteInt32Vector(ids)) { + MMI_HILOGE("Write ids failed"); + return RET_ERR; } return ret; } @@ -292,15 +346,34 @@ int32_t MultimodalInputConnectStub::StubGetDeviceIds(MessageParcel& data, Messag int32_t MultimodalInputConnectStub::StubGetDevice(MessageParcel& data, MessageParcel& reply) { CALL_DEBUG_ENTER; - int32_t userData = 0; - READINT32(data, userData, IPC_PROXY_DEAD_OBJECT_ERR); int32_t deviceId = -1; READINT32(data, deviceId, IPC_PROXY_DEAD_OBJECT_ERR); - int32_t ret = GetDevice(userData, deviceId); + std::shared_ptr inputDevice = std::make_shared(); + int32_t ret = GetDevice(deviceId, inputDevice); if (ret != RET_OK) { MMI_HILOGE("Call GetDevice failed ret:%{public}d", ret); + return RET_ERR; } - return ret; + WRITEINT32(reply, inputDevice->GetId(), IPC_STUB_WRITE_PARCEL_ERR); + WRITEINT32(reply, inputDevice->GetType(), IPC_STUB_WRITE_PARCEL_ERR); + WRITESTRING(reply, inputDevice->GetName(), IPC_STUB_WRITE_PARCEL_ERR); + WRITEINT32(reply, inputDevice->GetBus(), IPC_STUB_WRITE_PARCEL_ERR); + WRITEINT32(reply, inputDevice->GetVersion(), IPC_STUB_WRITE_PARCEL_ERR); + WRITEINT32(reply, inputDevice->GetProduct(), IPC_STUB_WRITE_PARCEL_ERR); + WRITEINT32(reply, inputDevice->GetVendor(), IPC_STUB_WRITE_PARCEL_ERR); + WRITESTRING(reply, inputDevice->GetPhys(), IPC_STUB_WRITE_PARCEL_ERR); + WRITESTRING(reply, inputDevice->GetUniq(), IPC_STUB_WRITE_PARCEL_ERR); + WRITEUINT64(reply, static_cast(inputDevice->GetCapabilities()), IPC_STUB_WRITE_PARCEL_ERR); + WRITEUINT32(reply, static_cast(inputDevice->GetAxisInfo().size()), IPC_STUB_WRITE_PARCEL_ERR); + for (const auto &item : inputDevice->GetAxisInfo()) { + WRITEINT32(reply, item.GetMinimum(), IPC_STUB_WRITE_PARCEL_ERR); + WRITEINT32(reply, item.GetMaximum(), IPC_STUB_WRITE_PARCEL_ERR); + WRITEINT32(reply, item.GetAxisType(), IPC_STUB_WRITE_PARCEL_ERR); + WRITEINT32(reply, item.GetFuzz(), IPC_STUB_WRITE_PARCEL_ERR); + WRITEINT32(reply, item.GetFlat(), IPC_STUB_WRITE_PARCEL_ERR); + WRITEINT32(reply, item.GetResolution(), IPC_STUB_WRITE_PARCEL_ERR); + } + return RET_OK; } int32_t MultimodalInputConnectStub::StubRegisterInputDeviceMonitor(MessageParcel& data, MessageParcel& reply) @@ -326,20 +399,26 @@ int32_t MultimodalInputConnectStub::StubUnregisterInputDeviceMonitor(MessageParc int32_t MultimodalInputConnectStub::StubGetKeyboardType(MessageParcel& data, MessageParcel& reply) { CALL_DEBUG_ENTER; - int32_t userData = 0; - READINT32(data, userData, IPC_PROXY_DEAD_OBJECT_ERR); int32_t deviceId = -1; READINT32(data, deviceId, IPC_PROXY_DEAD_OBJECT_ERR); - int32_t ret = GetKeyboardType(userData, deviceId); + int32_t keyboardType = 0; + int32_t ret = GetKeyboardType(deviceId, keyboardType); if (ret != RET_OK) { MMI_HILOGE("Call GetKeyboardType failed ret:%{public}d", ret); + return RET_ERR; } + WRITEINT32(reply, keyboardType, IPC_STUB_WRITE_PARCEL_ERR); return ret; } int32_t MultimodalInputConnectStub::StubAddInputHandler(MessageParcel& data, MessageParcel& reply) { CALL_DEBUG_ENTER; + if (!PerHelper->VerifySystemApp()) { + MMI_HILOGE("verify system APP failed"); + return ERROR_NOT_SYSAPI; + } + if (!IsRunning()) { MMI_HILOGE("Service is not running"); return MMISERVICE_NOT_RUNNING; @@ -357,7 +436,12 @@ int32_t MultimodalInputConnectStub::StubAddInputHandler(MessageParcel& data, Mes } uint32_t eventType; READUINT32(data, eventType, IPC_PROXY_DEAD_OBJECT_ERR); - int32_t ret = AddInputHandler(static_cast(handlerType), eventType); + int32_t priority; + READINT32(data, priority, IPC_PROXY_DEAD_OBJECT_ERR); + int32_t deviceTags; + READINT32(data, deviceTags, IPC_PROXY_DEAD_OBJECT_ERR); + int32_t ret = AddInputHandler(static_cast(handlerType), eventType, priority, + deviceTags); if (ret != RET_OK) { MMI_HILOGE("Call AddInputHandler failed ret:%{public}d", ret); return ret; @@ -368,6 +452,11 @@ int32_t MultimodalInputConnectStub::StubAddInputHandler(MessageParcel& data, Mes int32_t MultimodalInputConnectStub::StubRemoveInputHandler(MessageParcel& data, MessageParcel& reply) { CALL_DEBUG_ENTER; + if (!PerHelper->VerifySystemApp()) { + MMI_HILOGE("verify system APP failed"); + return ERROR_NOT_SYSAPI; + } + if (!IsRunning()) { MMI_HILOGE("Service is not running"); return MMISERVICE_NOT_RUNNING; @@ -385,7 +474,12 @@ int32_t MultimodalInputConnectStub::StubRemoveInputHandler(MessageParcel& data, } uint32_t eventType; READUINT32(data, eventType, IPC_PROXY_DEAD_OBJECT_ERR); - int32_t ret = RemoveInputHandler(static_cast(handlerType), eventType); + int32_t priority; + READINT32(data, priority, IPC_PROXY_DEAD_OBJECT_ERR); + int32_t deviceTags; + READINT32(data, deviceTags, IPC_PROXY_DEAD_OBJECT_ERR); + int32_t ret = RemoveInputHandler(static_cast(handlerType), eventType, priority, + deviceTags); if (ret != RET_OK) { MMI_HILOGE("Call RemoveInputHandler failed ret:%{public}d", ret); return ret; @@ -418,6 +512,11 @@ int32_t MultimodalInputConnectStub::StubMarkEventConsumed(MessageParcel& data, M int32_t MultimodalInputConnectStub::StubSubscribeKeyEvent(MessageParcel& data, MessageParcel& reply) { CALL_DEBUG_ENTER; + if (!PerHelper->VerifySystemApp()) { + MMI_HILOGE("verify system APP failed"); + return ERROR_NOT_SYSAPI; + } + if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) { MMI_HILOGE("Permission check failed"); return CHECK_PERMISSION_FAIL; @@ -432,7 +531,6 @@ int32_t MultimodalInputConnectStub::StubSubscribeKeyEvent(MessageParcel& data, M READINT32(data, subscribeId, IPC_PROXY_DEAD_OBJECT_ERR); auto keyOption = std::make_shared(); - CHKPR(keyOption, IPC_STUB_WRITE_PARCEL_ERR); if (!keyOption->ReadFromParcel(data)) { MMI_HILOGE("Read keyOption failed"); return IPC_PROXY_DEAD_OBJECT_ERR; @@ -448,6 +546,11 @@ int32_t MultimodalInputConnectStub::StubSubscribeKeyEvent(MessageParcel& data, M int32_t MultimodalInputConnectStub::StubUnsubscribeKeyEvent(MessageParcel& data, MessageParcel& reply) { CALL_DEBUG_ENTER; + if (!PerHelper->VerifySystemApp()) { + MMI_HILOGE("verify system APP failed"); + return ERROR_NOT_SYSAPI; + } + if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) { MMI_HILOGE("Permission check failed"); return CHECK_PERMISSION_FAIL; @@ -497,6 +600,11 @@ int32_t MultimodalInputConnectStub::StubMoveMouseEvent(MessageParcel& data, Mess int32_t MultimodalInputConnectStub::StubInjectKeyEvent(MessageParcel& data, MessageParcel& reply) { CALL_DEBUG_ENTER; + if (!PerHelper->VerifySystemApp()) { + MMI_HILOGE("verify system APP failed"); + return ERROR_NOT_SYSAPI; + } + if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) { MMI_HILOGE("Permission check failed"); return CHECK_PERMISSION_FAIL; @@ -511,6 +619,7 @@ int32_t MultimodalInputConnectStub::StubInjectKeyEvent(MessageParcel& data, Mess MMI_HILOGE("Read Key Event failed"); return IPC_PROXY_DEAD_OBJECT_ERR; } + event->UpdateId(); int32_t ret = InjectKeyEvent(event); if (ret != RET_OK) { MMI_HILOGE("InjectKeyEvent failed, ret:%{public}d", ret); @@ -562,9 +671,68 @@ int32_t MultimodalInputConnectStub::StubSetAnrListener(MessageParcel& data, Mess return ret; } + +int32_t MultimodalInputConnectStub::StubGetDisplayBindInfo(MessageParcel& data, MessageParcel& reply) +{ + CALL_DEBUG_ENTER; + if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) { + MMI_HILOGE("Permission check failed"); + return CHECK_PERMISSION_FAIL; + } + if (!IsRunning()) { + MMI_HILOGE("Service is not running"); + return MMISERVICE_NOT_RUNNING; + } + DisplayBindInfos infos; + int32_t ret = GetDisplayBindInfo(infos); + if (ret != RET_OK) { + MMI_HILOGE("Call GetDisplayBindInfo failed, ret:%{public}d", ret); + return ret; + } + int32_t size = static_cast(infos.size()); + WRITEINT32(reply, size, ERR_INVALID_VALUE); + infos.reserve(size); + for (const auto &info : infos) { + WRITEINT32(reply, info.inputDeviceId, ERR_INVALID_VALUE); + WRITESTRING(reply, info.inputDeviceName, ERR_INVALID_VALUE); + WRITEINT32(reply, info.displayId, ERR_INVALID_VALUE); + WRITESTRING(reply, info.displayName, ERR_INVALID_VALUE); + } + return RET_OK; +} + +int32_t MultimodalInputConnectStub::StubSetDisplayBind(MessageParcel& data, MessageParcel& reply) +{ + CALL_DEBUG_ENTER; + if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) { + MMI_HILOGE("Permission check failed"); + return CHECK_PERMISSION_FAIL; + } + if (!IsRunning()) { + MMI_HILOGE("Service is not running"); + return MMISERVICE_NOT_RUNNING; + } + int32_t inputDeviceId = -1; + READINT32(data, inputDeviceId, ERR_INVALID_VALUE); + int32_t displayId = -1; + READINT32(data, displayId, ERR_INVALID_VALUE); + std::string msg; + int32_t ret = SetDisplayBind(inputDeviceId, displayId, msg); + if (ret != RET_OK) { + MMI_HILOGE("Call SetDisplayBind failed, ret:%{public}d", ret); + } + WRITESTRING(reply, msg, ERR_INVALID_VALUE); + return ret; +} + int32_t MultimodalInputConnectStub::StubRegisterCooperateMonitor(MessageParcel& data, MessageParcel& reply) { CALL_DEBUG_ENTER; + if (!PerHelper->VerifySystemApp()) { + MMI_HILOGE("verify system APP failed"); + return ERROR_NOT_SYSAPI; + } + if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) { MMI_HILOGE("Permission check failed"); return CHECK_PERMISSION_FAIL; @@ -583,6 +751,11 @@ int32_t MultimodalInputConnectStub::StubRegisterCooperateMonitor(MessageParcel& int32_t MultimodalInputConnectStub::StubUnregisterCooperateMonitor(MessageParcel& data, MessageParcel& reply) { CALL_DEBUG_ENTER; + if (!PerHelper->VerifySystemApp()) { + MMI_HILOGE("verify system APP failed"); + return ERROR_NOT_SYSAPI; + } + if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) { MMI_HILOGE("Permission check failed"); return CHECK_PERMISSION_FAIL; @@ -601,6 +774,11 @@ int32_t MultimodalInputConnectStub::StubUnregisterCooperateMonitor(MessageParcel int32_t MultimodalInputConnectStub::StubEnableInputDeviceCooperate(MessageParcel& data, MessageParcel& reply) { CALL_DEBUG_ENTER; + if (!PerHelper->VerifySystemApp()) { + MMI_HILOGE("verify system APP failed"); + return ERROR_NOT_SYSAPI; + } + if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) { MMI_HILOGE("Permission check failed"); return CHECK_PERMISSION_FAIL; @@ -623,6 +801,11 @@ int32_t MultimodalInputConnectStub::StubEnableInputDeviceCooperate(MessageParcel int32_t MultimodalInputConnectStub::StubStartInputDeviceCooperate(MessageParcel& data, MessageParcel& reply) { CALL_DEBUG_ENTER; + if (!PerHelper->VerifySystemApp()) { + MMI_HILOGE("verify system APP failed"); + return ERROR_NOT_SYSAPI; + } + if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) { MMI_HILOGE("Permission check failed"); return CHECK_PERMISSION_FAIL; @@ -647,6 +830,11 @@ int32_t MultimodalInputConnectStub::StubStartInputDeviceCooperate(MessageParcel& int32_t MultimodalInputConnectStub::StubStopDeviceCooperate(MessageParcel& data, MessageParcel& reply) { CALL_DEBUG_ENTER; + if (!PerHelper->VerifySystemApp()) { + MMI_HILOGE("verify system APP failed"); + return ERROR_NOT_SYSAPI; + } + if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) { MMI_HILOGE("Permission check failed"); return CHECK_PERMISSION_FAIL; @@ -667,6 +855,11 @@ int32_t MultimodalInputConnectStub::StubStopDeviceCooperate(MessageParcel& data, int32_t MultimodalInputConnectStub::StubGetInputDeviceCooperateState(MessageParcel& data, MessageParcel& reply) { CALL_DEBUG_ENTER; + if (!PerHelper->VerifySystemApp()) { + MMI_HILOGE("verify system APP failed"); + return ERROR_NOT_SYSAPI; + } + if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) { MMI_HILOGE("Permission check failed"); return CHECK_PERMISSION_FAIL; @@ -686,91 +879,115 @@ int32_t MultimodalInputConnectStub::StubGetInputDeviceCooperateState(MessageParc return ret; } -int32_t MultimodalInputConnectStub::StubStartRemoteCooperate(MessageParcel& data, MessageParcel& reply) +int32_t MultimodalInputConnectStub::StubSetInputDevice(MessageParcel& data, MessageParcel& reply) { CALL_DEBUG_ENTER; + if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) { + MMI_HILOGE("Permission check failed"); + return CHECK_PERMISSION_FAIL; + } if (!IsRunning()) { MMI_HILOGE("Service is not running"); return MMISERVICE_NOT_RUNNING; } - std::string remoteDeviceId; - READSTRING(data, remoteDeviceId, IPC_PROXY_DEAD_OBJECT_ERR); - int32_t ret = StartRemoteCooperate(remoteDeviceId); + std::string dhid; + READSTRING(data, dhid, IPC_PROXY_DEAD_OBJECT_ERR); + std::string screenId; + READSTRING(data, screenId, IPC_PROXY_DEAD_OBJECT_ERR); + int32_t ret = SetInputDevice(dhid, screenId); if (ret != RET_OK) { - MMI_HILOGE("Call StartRemoteCooperate failed, ret:%{public}d", ret); + MMI_HILOGE("Call SetInputDevice failed ret:%{public}d", ret); + return ret; } - return ret; + return RET_OK; } -int32_t MultimodalInputConnectStub::StubStartRemoteCooperateRes(MessageParcel& data, MessageParcel& reply) +int32_t MultimodalInputConnectStub::StubGetFunctionKeyState(MessageParcel &data, MessageParcel &reply) { CALL_DEBUG_ENTER; + if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) { + MMI_HILOGE("Permission check failed"); + return CHECK_PERMISSION_FAIL; + } if (!IsRunning()) { MMI_HILOGE("Service is not running"); return MMISERVICE_NOT_RUNNING; } - bool isSuccess; - READBOOL(data, isSuccess, IPC_PROXY_DEAD_OBJECT_ERR); - std::string startDhid; - READSTRING(data, startDhid, IPC_PROXY_DEAD_OBJECT_ERR); - int32_t xPercent; - READINT32(data, xPercent, IPC_PROXY_DEAD_OBJECT_ERR); - int32_t yPercent; - READINT32(data, yPercent, IPC_PROXY_DEAD_OBJECT_ERR); - int32_t ret = StartRemoteCooperateResult(isSuccess, startDhid, xPercent, yPercent); + + int32_t funcKey { 0 }; + bool state { false }; + READINT32(data, funcKey, IPC_PROXY_DEAD_OBJECT_ERR); + int32_t ret = GetFunctionKeyState(funcKey, state); if (ret != RET_OK) { - MMI_HILOGE("Call StartRemoteCooperateResult failed, ret:%{public}d", ret); + MMI_HILOGE("Call GetKeyboardEnableState failed ret:%{public}d", ret); + return ret; } - return ret; + + WRITEBOOL(reply, state, IPC_PROXY_DEAD_OBJECT_ERR); + return RET_OK; } -int32_t MultimodalInputConnectStub::StubStopRemoteCooperate(MessageParcel& data, MessageParcel& reply) +int32_t MultimodalInputConnectStub::StubSetFunctionKeyState(MessageParcel &data, MessageParcel &reply) { CALL_DEBUG_ENTER; + if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) { + MMI_HILOGE("Permission check failed"); + return CHECK_PERMISSION_FAIL; + } if (!IsRunning()) { MMI_HILOGE("Service is not running"); return MMISERVICE_NOT_RUNNING; } - int32_t ret = StopRemoteCooperate(); + + int32_t funcKey { 0 }; + bool enable { false }; + READINT32(data, funcKey, IPC_PROXY_DEAD_OBJECT_ERR); + READBOOL(data, enable, IPC_PROXY_DEAD_OBJECT_ERR); + int32_t ret = SetFunctionKeyState(funcKey, enable); if (ret != RET_OK) { - MMI_HILOGE("Call StopRemoteCooperate failed, ret:%{public}d", ret); + MMI_HILOGE("Call SetFunctionKeyState failed ret:%{public}d", ret); } return ret; } -int32_t MultimodalInputConnectStub::StubStopRemoteCooperateRes(MessageParcel& data, MessageParcel& reply) +int32_t MultimodalInputConnectStub::StubSetPointerLocation(MessageParcel &data, MessageParcel &reply) { CALL_DEBUG_ENTER; + if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) { + MMI_HILOGE("Permission check failed"); + return CHECK_PERMISSION_FAIL; + } if (!IsRunning()) { MMI_HILOGE("Service is not running"); return MMISERVICE_NOT_RUNNING; } - bool isSuccess; - READBOOL(data, isSuccess, IPC_PROXY_DEAD_OBJECT_ERR); - int32_t ret = StopRemoteCooperateResult(isSuccess); + + int32_t x = 0; + int32_t y = 0; + READINT32(data, x, IPC_PROXY_DEAD_OBJECT_ERR); + READINT32(data, y, IPC_PROXY_DEAD_OBJECT_ERR); + int32_t ret = SetPointerLocation(x, y); if (ret != RET_OK) { - MMI_HILOGE("Call StopRemoteCooperateResult failed, ret:%{public}d", ret); + MMI_HILOGE("Call SetFunctionKeyState failed ret:%{public}d", ret); } return ret; } -int32_t MultimodalInputConnectStub::StubStartCooperateOtherRes(MessageParcel& data, MessageParcel& reply) +int32_t MultimodalInputConnectStub::StubSetMouseCaptureMode(MessageParcel& data, MessageParcel& reply) { CALL_DEBUG_ENTER; - if (!IsRunning()) { - MMI_HILOGE("Service is not running"); - return MMISERVICE_NOT_RUNNING; - } - std::string peerNetworkId; - READSTRING(data, peerNetworkId, IPC_PROXY_DEAD_OBJECT_ERR); - int32_t ret = StartCooperateOtherResult(peerNetworkId); + int32_t windowId = -1; + bool isCaptureMode = false; + READINT32(data, windowId, IPC_PROXY_DEAD_OBJECT_ERR); + READBOOL(data, isCaptureMode, IPC_PROXY_DEAD_OBJECT_ERR); + int32_t ret = SetMouseCaptureMode(windowId, isCaptureMode); if (ret != RET_OK) { - MMI_HILOGE("Call StartCooperateOtherRes failed, ret:%{public}d", ret); + MMI_HILOGE("Fail to call SetMouseCaptureMode, ret:%{public}d", ret); } return ret; } -int32_t MultimodalInputConnectStub::StubSetInputDevice(MessageParcel& data, MessageParcel& reply) +int32_t MultimodalInputConnectStub::StubGetWindowPid(MessageParcel& data, MessageParcel& reply) { CALL_DEBUG_ENTER; if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) { @@ -781,62 +998,42 @@ int32_t MultimodalInputConnectStub::StubSetInputDevice(MessageParcel& data, Mess MMI_HILOGE("Service is not running"); return MMISERVICE_NOT_RUNNING; } - std::string dhid; - READSTRING(data, dhid, IPC_PROXY_DEAD_OBJECT_ERR); - std::string screenId; - READSTRING(data, screenId, IPC_PROXY_DEAD_OBJECT_ERR); - int32_t ret = SetInputDevice(dhid, screenId); - if (ret != RET_OK) { - MMI_HILOGE("Call SetInputDevice failed ret:%{public}d", ret); - return ret; + + int32_t windowId = 0; + READINT32(data, windowId, IPC_PROXY_DEAD_OBJECT_ERR); + int32_t ret = GetWindowPid(windowId); + if (ret == RET_ERR) { + MMI_HILOGE("Get window pid failed"); } + WRITEINT32(reply, ret, ERR_INVALID_VALUE); return RET_OK; } -int32_t MultimodalInputConnectStub::StubGetFunctionKeyState(MessageParcel &data, MessageParcel &reply) +int32_t MultimodalInputConnectStub::StubAppendExtraData(MessageParcel& data, MessageParcel& reply) { CALL_DEBUG_ENTER; - if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) { - MMI_HILOGE("Permission check failed"); - return CHECK_PERMISSION_FAIL; - } if (!IsRunning()) { MMI_HILOGE("Service is not running"); return MMISERVICE_NOT_RUNNING; } - - int32_t funcKey { 0 }; - bool state { false }; - READINT32(data, funcKey, IPC_PROXY_DEAD_OBJECT_ERR); - int32_t ret = GetFunctionKeyState(funcKey, state); - if (ret != RET_OK) { - MMI_HILOGE("Call GetKeyboardEnableState failed ret:%{public}d", ret); - return ret; - } - - WRITEBOOL(reply, state, IPC_PROXY_DEAD_OBJECT_ERR); - return RET_OK; -} - -int32_t MultimodalInputConnectStub::StubSetFunctionKeyState(MessageParcel &data, MessageParcel &reply) -{ - CALL_DEBUG_ENTER; - if (!PerHelper->CheckPermission(PermissionHelper::APL_SYSTEM_BASIC_CORE)) { - MMI_HILOGE("Permission check failed"); - return CHECK_PERMISSION_FAIL; + ExtraData extraData; + READBOOL(data, extraData.appended, IPC_PROXY_DEAD_OBJECT_ERR); + int32_t size = 0; + READINT32(data, size, IPC_PROXY_DEAD_OBJECT_ERR); + if (size > ExtraData::MAX_BUFFER_SIZE) { + MMI_HILOGE("Append extra data failed, buffer is oversize:%{public}d", size); + return ERROR_OVER_SIZE_BUFFER; } - if (!IsRunning()) { - MMI_HILOGE("Service is not running"); - return MMISERVICE_NOT_RUNNING; + uint8_t buffer = 0; + for (int32_t i = 0; i < size; ++i) { + READUINT8(data, buffer, IPC_PROXY_DEAD_OBJECT_ERR); + extraData.buffer.push_back(buffer); } - - int32_t funcKey { 0 }; - bool enable { false }; - READINT32(data, funcKey, IPC_PROXY_DEAD_OBJECT_ERR); - READBOOL(data, enable, IPC_PROXY_DEAD_OBJECT_ERR); - int32_t ret = SetFunctionKeyState(funcKey, enable); + READINT32(data, extraData.sourceType, IPC_PROXY_DEAD_OBJECT_ERR); + READINT32(data, extraData.pointerId, IPC_PROXY_DEAD_OBJECT_ERR); + int32_t ret = AppendExtraData(extraData); if (ret != RET_OK) { - MMI_HILOGE("Call SetFunctionKeyState failed ret:%{public}d", ret); + MMI_HILOGE("Fail to call AppendExtraData, ret:%{public}d", ret); } return ret; } diff --git a/service/delegate_task/include/delegate_tasks.h b/service/delegate_task/include/delegate_tasks.h index da2c8d9f45cb8cb544fe0170c1a7078aa1383fe3..a4a898b54e2349737fb387aa86bf01da630a5963 100644 --- a/service/delegate_task/include/delegate_tasks.h +++ b/service/delegate_task/include/delegate_tasks.h @@ -12,8 +12,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef DELEGATE_TASKS_H #define DELEGATE_TASKS_H + #include #include #include @@ -27,7 +29,7 @@ namespace OHOS { namespace MMI { using DTaskCallback = std::function; -class DelegateTasks : public IdFactory { +class DelegateTasks final : public IdFactory { public: struct TaskData { uint64_t tid { 0 }; @@ -68,7 +70,7 @@ public: public: DelegateTasks() = default; - virtual ~DelegateTasks() = default; + ~DelegateTasks(); bool Init(); void ProcessTasks(); diff --git a/service/delegate_task/src/delegate_tasks.cpp b/service/delegate_task/src/delegate_tasks.cpp index 71fd9e3fb875383ae7943fa8318fb7539d038387..61c8d41373958c0c36d83bffbfbdc7c39d7fd55f 100644 --- a/service/delegate_task/src/delegate_tasks.cpp +++ b/service/delegate_task/src/delegate_tasks.cpp @@ -12,10 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include "delegate_tasks.h" -#include #include +#include #include #include "error_multimodal.h" @@ -42,6 +43,18 @@ void DelegateTasks::Task::ProcessTask() } } +DelegateTasks::~DelegateTasks() +{ + if (fds_[0] >= 0) { + close(fds_[0]); + fds_[0] = -1; + } + if (fds_[1] >= 0) { + close(fds_[1]); + fds_[1] = -1; + } +} + bool DelegateTasks::Init() { CALL_DEBUG_ENTER; @@ -52,10 +65,12 @@ bool DelegateTasks::Init() } if (fcntl(fds_[0], F_SETFL, O_NONBLOCK) == -1) { MMI_HILOGE("The fcntl read failed,errno:%{public}d", errno); + close(fds_[0]); return false; } if (fcntl(fds_[1], F_SETFL, O_NONBLOCK) == -1) { MMI_HILOGE("The fcntl write failed,errno:%{public}d", errno); + close(fds_[1]); return false; } return true; @@ -145,7 +160,7 @@ DelegateTasks::TaskPtr DelegateTasks::PostTask(DTaskCallback callback, Promise * return nullptr; } int32_t id = GenerateId(); - TaskData data = {GetThisThreadId(), id}; + TaskData data = { GetThisThreadId(), id }; auto res = write(fds_[1], &data, sizeof(data)); if (res == -1) { RecoveryId(id); @@ -153,11 +168,6 @@ DelegateTasks::TaskPtr DelegateTasks::PostTask(DTaskCallback callback, Promise * return nullptr; } TaskPtr task = std::make_shared(id, callback, promise); - if (task == nullptr) { - RecoveryId(id); - MMI_HILOGE("Make task failed"); - return nullptr; - } tasks_.push(task); std::string taskType = ((promise == nullptr) ? "Async" : "Sync"); MMI_HILOGD("Post %{public}s", taskType.c_str()); diff --git a/util/common/include/run_shell_util.h b/service/device_config/include/device_config_file_parser.h similarity index 46% rename from util/common/include/run_shell_util.h rename to service/device_config/include/device_config_file_parser.h index 84076f333befc5a6f6c905ce3208f583c672f23b..8cf49180b6d3e0c219d3c6da0f774430460eb8f0 100644 --- a/util/common/include/run_shell_util.h +++ b/service/device_config/include/device_config_file_parser.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * 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 @@ -13,31 +13,37 @@ * limitations under the License. */ -#ifndef RUN_SHELL_UTIL_H -#define RUN_SHELL_UTIL_H +#ifndef DEVICE_CONFIG_FILE_PARSER_H +#define DEVICE_CONFIG_FILE_PARSER_H -#include +#include #include -#include -#include "nocopyable.h" +struct libinput_device; + +struct VendorConfig { + int32_t pointerSpeed { -1 }; +}; namespace OHOS { namespace MMI { -class RunShellUtil { +enum class ConfigFileItem { + INVALID = -1, + POINTER_BASE = 0, + POINTER_SPEED, +}; +class DeviceConfigManagement { public: - RunShellUtil(); - DISALLOW_COPY_AND_MOVE(RunShellUtil); - ~RunShellUtil(); - int32_t RunShellCommand(const std::string &command, std::vector &vLog); - int32_t SetLogMaxSize(int32_t logSize); - - static int32_t StringToVectorByRegex(const std::string &log, std::vector &vLog, const std::regex &r); + DeviceConfigManagement() = default; + ~DeviceConfigManagement() = default; +public: + VendorConfig GetVendorConfig(struct libinput_device *device) const; private: - FILE *fp_ { nullptr }; - int32_t logMaxSize_ { 0 }; + std::string CombDeviceFileName(struct libinput_device *device) const; + std::map ReadConfigFile(const std::string &filePath) const; + ConfigFileItem ConfigItemName2Id(const std::string &name) const; }; } // namespace MMI } // namespace OHOS -#endif // RUN_SHELL_UTIL_H \ No newline at end of file +#endif // DEVICE_CONFIG_FILE_PARSER_H \ No newline at end of file diff --git a/service/device_config/src/device_config_file_parser.cpp b/service/device_config/src/device_config_file_parser.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6b1e6c3886882ae930293d031a027bc02826fc19 --- /dev/null +++ b/service/device_config/src/device_config_file_parser.cpp @@ -0,0 +1,137 @@ +/* + * 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. + */ + +#include "device_config_file_parser.h" + +#include +#include + +#include "error_multimodal.h" +#include "input_device.h" +#include "libinput.h" +#include "util.h" + +namespace OHOS { +namespace MMI { +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "DeviceConfigManagement" }; +constexpr int32_t COMMENT_SUBSCRIPT = 0; +} // namespace + +enum evdev_device_udev_tags { + EVDEV_UDEV_TAG_INPUT = 1 << 0, + EVDEV_UDEV_TAG_KEYBOARD = 1 << 1, + EVDEV_UDEV_TAG_MOUSE = 1 << 2, + EVDEV_UDEV_TAG_TOUCHPAD = 1 << 3, + EVDEV_UDEV_TAG_TOUCHSCREEN = 1 << 4, + EVDEV_UDEV_TAG_TABLET = 1 << 5, + EVDEV_UDEV_TAG_JOYSTICK = 1 << 6, + EVDEV_UDEV_TAG_ACCELEROMETER = 1 << 7, + EVDEV_UDEV_TAG_TABLET_PAD = 1 << 8, + EVDEV_UDEV_TAG_POINTINGSTICK = 1 << 9, + EVDEV_UDEV_TAG_TRACKBALL = 1 << 10, + EVDEV_UDEV_TAG_SWITCH = 1 << 11, +}; + +std::string DeviceConfigManagement::CombDeviceFileName(struct libinput_device *device) const +{ + CALL_DEBUG_ENTER; + CHKPS(device); + uint32_t vendor = libinput_device_get_id_vendor(device); + uint32_t product = libinput_device_get_id_product(device); + uint32_t version = libinput_device_get_id_version(device); + const char *name = libinput_device_get_name(device); + CHKPS(name); + std::string fileName = std::to_string(vendor) + "_" + std::to_string(product) + "_" + + std::to_string(version) + "_" + name; + RemoveSpace(fileName); + return fileName; +} + +ConfigFileItem DeviceConfigManagement::ConfigItemName2Id(const std::string &name) const +{ + static const std::map configList = { + {"speed", ConfigFileItem::POINTER_SPEED}, + }; + + auto iter = configList.find(name); + if (iter == configList.end()) { + MMI_HILOGE("Device name failed"); + return ConfigFileItem::INVALID; + } + return configList.at(name); +} + +std::map DeviceConfigManagement::ReadConfigFile(const std::string &filePath) const +{ + std::map configList; + std::ifstream cfgFile(filePath); + if (!cfgFile.is_open()) { + MMI_HILOGE("Failed to open config file"); + return configList; + } + std::string tmp; + + while (std::getline(cfgFile, tmp)) { + RemoveSpace(tmp); + size_t pos = tmp.find('#'); + if (pos != tmp.npos && pos != COMMENT_SUBSCRIPT) { + continue; + } + if (tmp.empty() || tmp.front() == '#') { + continue; + } + pos = tmp.find('='); + if (pos == (tmp.size() - 1) || pos == tmp.npos) { + continue; + } + std::string key = tmp.substr(0, pos); + + std::smatch match; + bool isNumber = std::regex_search(tmp, match, std::regex("\\d+")); + if (!isNumber) { + continue; + } + configList[ConfigItemName2Id(key)] = std::stoi(match[0]); + } + cfgFile.close(); + return configList; +} + +VendorConfig DeviceConfigManagement::GetVendorConfig(struct libinput_device *device) const +{ + CALL_DEBUG_ENTER; + CHKPO(device); + std::string filePath = "/vendor/etc/pointer/" + CombDeviceFileName(device) + ".TOML"; + VendorConfig vendorConfigTmp = {}; + auto path = FileVerification(filePath, "TOML"); + if(path.empty()) { + MMI_HILOGE("File validation failed"); + return vendorConfigTmp; + } + auto configList = ReadConfigFile(path); + if (configList.empty()) { + MMI_HILOGE("configList is empty"); + return vendorConfigTmp; + } + if (configList.find(ConfigFileItem::POINTER_SPEED) == configList.end()) { + MMI_HILOGE("configList not find POINTER_SPEED"); + return vendorConfigTmp; + } + vendorConfigTmp.pointerSpeed = configList[ConfigFileItem::POINTER_SPEED]; + return vendorConfigTmp; +} +} // namespace MMI +} // namespace OHOS \ No newline at end of file diff --git a/service/device_manager/include/input_device_manager.h b/service/device_manager/include/input_device_manager.h index 8660b320f4bcde6bda5ffffad26baf95f6baec50..325aa9eac3bbe08b5b71e791692e76e612feeecd 100644 --- a/service/device_manager/include/input_device_manager.h +++ b/service/device_manager/include/input_device_manager.h @@ -19,15 +19,13 @@ #include #include +#include "device_config_file_parser.h" #include "device_observer.h" -#include "event_dispatch_handler.h" -#include "key_event_normalize.h" #include "input_device.h" -#include "key_auto_repeat.h" -#include "key_map_manager.h" #include "msg_handler.h" #include "nocopyable.h" #include "singleton.h" +#include "uds_session.h" #include "util.h" namespace OHOS { @@ -36,10 +34,14 @@ class InputDeviceManager final : public IDeviceObject { DECLARE_DELAYED_SINGLETON(InputDeviceManager); struct InputDeviceInfo { - struct libinput_device *inputDeviceOrigin_ { nullptr }; - std::string networkIdOrigin_; - bool isRemote_ { false }; - std::string dhid_; + struct libinput_device *inputDeviceOrigin { nullptr }; + std::string networkIdOrigin; + bool isRemote { false }; + bool isPointerDevice { false }; + bool isTouchableDevice { false }; + std::string dhid; + std::string sysUid; + VendorConfig vendorConfig; }; public: DISALLOW_COPY_AND_MOVE(InputDeviceManager); @@ -60,27 +62,33 @@ public: void RemoveDevListener(SessionPtr sess); void Dump(int32_t fd, const std::vector &args); void DumpDeviceList(int32_t fd, const std::vector &args); + bool IsRemote(struct libinput_device *inputDevice) const; + bool IsRemote(int32_t id) const; #ifdef OHOS_BUILD_ENABLE_COOPERATE std::string GetOriginNetworkId(int32_t id); std::string GetOriginNetworkId(const std::string &dhid); - void GetLocalDeviceId(std::string &local); std::string GetDhid(int32_t deviceId) const; std::vector GetCooperateDhids(int32_t deviceId); std::vector GetCooperateDhids(const std::string &dhid); bool HasLocalPointerDevice() const; - bool IsRemote(struct libinput_device *inputDevice) const; - bool IsRemote(int32_t id) const; + void NotifyVirtualKeyBoardStatus(int32_t deviceId, bool isAvailable) const; #endif // OHOS_BUILD_ENABLE_COOPERATE bool IsKeyboardDevice(struct libinput_device* device) const; bool IsPointerDevice(struct libinput_device* device) const; + bool IsTouchDevice(struct libinput_device* device) const; struct libinput_device* GetKeyboardDevice() const; #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING bool HasPointerDevice(); #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING + bool HasTouchDevice(); int32_t SetInputDevice(const std::string& dhid, const std::string& screenId); const std::string& GetScreenId(int32_t deviceId) const; + using inputDeviceCallback = std::function; + void SetInputStatusChangeCallback(inputDeviceCallback callback); + VendorConfig GetVendorConfig(int32_t deviceId) const; private: + int32_t ParseDeviceId(const std::string &sysName); void MakeDeviceInfo(struct libinput_device *inputDevice, struct InputDeviceInfo& info); bool IsMatchKeys(struct libinput_device* device, const std::vector &keyCodes) const; void ScanPointerDevice(); @@ -89,11 +97,16 @@ private: std::string Sha256(const std::string &in) const; std::string GenerateDescriptor(struct libinput_device *inputDevice, bool isRemote) const; #endif // OHOS_BUILD_ENABLE_COOPERATE + std::string GetInputIdentification(struct libinput_device* inputDevice); + void NotifyDevCallback(int32_t deviceId, struct InputDeviceInfo inDevice); +private: std::map inputDevice_; std::map inputDeviceScreens_; - int32_t nextId_ { 0 }; std::list> observers_; std::map> devListener_; + inputDeviceCallback devCallbacks_ = { nullptr }; + std::map displayInputBindInfos_; + DeviceConfigManagement configManagement_; }; #define InputDevMgr ::OHOS::DelayedSingleton::GetInstance() diff --git a/service/device_manager/src/input_device_manager.cpp b/service/device_manager/src/input_device_manager.cpp index 1f744c7e50c72b68eea3c9fc506a02981332c6a4..04ea13c85c4d6bf6ea1281fdb9c768bdf42e6c35 100644 --- a/service/device_manager/src/input_device_manager.cpp +++ b/service/device_manager/src/input_device_manager.cpp @@ -19,18 +19,23 @@ #include #ifdef OHOS_BUILD_ENABLE_COOPERATE #include -#include #endif // OHOS_BUILD_ENABLE_COOPERATE +#include #include #include "dfx_hisysevent.h" #ifdef OHOS_BUILD_ENABLE_COOPERATE #include "input_device_cooperate_sm.h" +#include "input_device_cooperate_util.h" #endif // OHOS_BUILD_ENABLE_COOPERATE +#include "event_dispatch_handler.h" #include "input_windows_manager.h" +#include "key_auto_repeat.h" +#include "key_event_normalize.h" #include "key_event_value_transformation.h" +#include "key_map_manager.h" +#include "pointer_drawing_manager.h" #ifdef OHOS_BUILD_ENABLE_COOPERATE -#include "softbus_bus_center.h" #include "util.h" #endif // OHOS_BUILD_ENABLE_COOPERATE #include "util_ex.h" @@ -39,27 +44,39 @@ namespace OHOS { namespace MMI { namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "InputDeviceManager"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "InputDeviceManager" }; constexpr int32_t INVALID_DEVICE_ID = -1; constexpr int32_t SUPPORT_KEY = 1; - const std::string UNKNOWN_SCREEN_ID = ""; #ifdef OHOS_BUILD_ENABLE_COOPERATE const char *SPLIT_SYMBOL = "|"; -const std::string BUNDLE_NAME = "DBinderBus_" + std::to_string(getpid()); const std::string DH_ID_PREFIX = "Input_"; #endif // OHOS_BUILD_ENABLE_COOPERATE +const std::string INPUT_VIRTUAL_DEVICE_NAME = "DistributedInput "; +std::unordered_map axisType { + { ABS_MT_TOUCH_MAJOR, "TOUCH_MAJOR" }, + { ABS_MT_TOUCH_MINOR, "TOUCH_MINOR" }, + { ABS_MT_ORIENTATION, "ORIENTATION" }, + { ABS_MT_POSITION_X, "POSITION_X" }, + { ABS_MT_POSITION_Y, "POSITION_Y" }, + { ABS_MT_PRESSURE, "PRESSURE" }, + { ABS_MT_WIDTH_MAJOR, "WIDTH_MAJOR" }, + { ABS_MT_WIDTH_MINOR, "WIDTH_MINOR" } +}; -std::unordered_map axisType = { - {ABS_MT_TOUCH_MAJOR, "TOUCH_MAJOR"}, - {ABS_MT_TOUCH_MINOR, "TOUCH_MINOR"}, - {ABS_MT_ORIENTATION, "ORIENTATION"}, - {ABS_MT_POSITION_X, "POSITION_X"}, - {ABS_MT_POSITION_Y, "POSITION_Y"}, - {ABS_MT_PRESSURE, "PRESSURE"}, - {ABS_MT_WIDTH_MAJOR, "WIDTH_MAJOR"}, - {ABS_MT_WIDTH_MINOR, "WIDTH_MINOR"} +std::vector> devCapEnumMaps { + { LIBINPUT_DEVICE_CAP_KEYBOARD, InputDeviceCapability::INPUT_DEV_CAP_KEYBOARD }, + { LIBINPUT_DEVICE_CAP_POINTER, InputDeviceCapability::INPUT_DEV_CAP_POINTER }, + { LIBINPUT_DEVICE_CAP_TOUCH, InputDeviceCapability::INPUT_DEV_CAP_TOUCH }, + { LIBINPUT_DEVICE_CAP_TABLET_TOOL, InputDeviceCapability::INPUT_DEV_CAP_TABLET_TOOL }, + { LIBINPUT_DEVICE_CAP_TABLET_PAD, InputDeviceCapability::INPUT_DEV_CAP_TABLET_PAD }, + { LIBINPUT_DEVICE_CAP_GESTURE, InputDeviceCapability::INPUT_DEV_CAP_GESTURE }, + { LIBINPUT_DEVICE_CAP_SWITCH, InputDeviceCapability::INPUT_DEV_CAP_SWITCH }, + { LIBINPUT_DEVICE_CAP_JOYSTICK, InputDeviceCapability::INPUT_DEV_CAP_JOYSTICK }, }; + +constexpr size_t EXPECTED_N_SUBMATCHES { 2 }; +constexpr size_t EXPECTED_SUBMATCH { 1 }; } // namespace InputDeviceManager::InputDeviceManager() {} @@ -75,9 +92,8 @@ std::shared_ptr InputDeviceManager::GetInputDevice(int32_t id) cons } std::shared_ptr inputDevice = std::make_shared(); - CHKPP(inputDevice); inputDevice->SetId(iter->first); - struct libinput_device *inputDeviceOrigin = iter->second.inputDeviceOrigin_; + struct libinput_device *inputDeviceOrigin = iter->second.inputDeviceOrigin; inputDevice->SetType(static_cast(libinput_device_get_tags(inputDeviceOrigin))); const char* name = libinput_device_get_name(inputDeviceOrigin); inputDevice->SetName((name == nullptr) ? ("null") : (name)); @@ -90,6 +106,12 @@ std::shared_ptr InputDeviceManager::GetInputDevice(int32_t id) cons const char* uniq = libinput_device_get_uniq(inputDeviceOrigin); inputDevice->SetUniq((uniq == nullptr) ? ("null") : (uniq)); + for (const auto &[first, second] : devCapEnumMaps) { + if (libinput_device_has_capability(inputDeviceOrigin, first)) { + inputDevice->AddCapability(second); + } + } + InputDevice::AxisInfo axis; for (const auto &item : axisType) { int32_t min = libinput_device_get_axis_min(inputDeviceOrigin, item.first); @@ -118,6 +140,13 @@ std::vector InputDeviceManager::GetInputDeviceIds() const CALL_DEBUG_ENTER; std::vector ids; for (const auto &item : inputDevice_) { +#ifdef OHOS_BUILD_ENABLE_COOPERATE + if (IsRemote(item.second.inputDeviceOrigin) && + InputDevCooSM->GetCurrentCooperateState() == CooperateState::STATE_FREE) { + MMI_HILOGW("Current device is remote and in STATUS_STATE"); + continue; + } +#endif // OHOS_BUILD_ENABLE_COOPERATE ids.push_back(item.first); } return ids; @@ -133,7 +162,7 @@ int32_t InputDeviceManager::SupportKeys(int32_t deviceId, std::vector & for (const auto &item : keyCodes) { bool ret = false; for (const auto &it : KeyMapMgr->InputTransferKeyValue(deviceId, item)) { - ret |= libinput_device_has_key(iter->second.inputDeviceOrigin_, it) == SUPPORT_KEY; + ret |= libinput_device_has_key(iter->second.inputDeviceOrigin, it) == SUPPORT_KEY; } keystroke.push_back(ret); } @@ -234,6 +263,12 @@ int32_t InputDeviceManager::GetKeyboardType(int32_t deviceId, int32_t &keyboardT return GetDeviceSupportKey(deviceId, keyboardType); } +void InputDeviceManager::SetInputStatusChangeCallback(inputDeviceCallback callback) +{ + CALL_DEBUG_ENTER; + devCallbacks_ = callback; +} + void InputDeviceManager::AddDevListener(SessionPtr sess, std::function callback) { CALL_DEBUG_ENTER; @@ -259,7 +294,7 @@ void InputDeviceManager::RemoveDevListener(SessionPtr sess) bool InputDeviceManager::HasPointerDevice() { for (auto it = inputDevice_.begin(); it != inputDevice_.end(); ++it) { - if (IsPointerDevice(it->second.inputDeviceOrigin_)) { + if (it->second.isPointerDevice) { return true; } } @@ -267,65 +302,155 @@ bool InputDeviceManager::HasPointerDevice() } #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING +bool InputDeviceManager::HasTouchDevice() +{ + CALL_DEBUG_ENTER; + for (auto it = inputDevice_.begin(); it != inputDevice_.end(); ++it) { + if (it->second.isTouchableDevice) { + return true; + } + } + return false; +} + +std::string InputDeviceManager::GetInputIdentification(struct libinput_device* inputDevice) +{ + CALL_DEBUG_ENTER; + uint32_t deviceVendor = libinput_device_get_id_vendor(inputDevice); + uint32_t deviceProduct = libinput_device_get_id_product(inputDevice); + struct udev_device* udevDevice = libinput_device_get_udev_device(inputDevice); + std::string sysPath = udev_device_get_syspath(udevDevice); + if ((deviceVendor < 0) || (deviceProduct < 0) || sysPath.empty()) { + MMI_HILOGE("Get device identification failed"); + return ""; + } + const size_t bufSize = 10; + char vid[bufSize] = ""; + char pid[bufSize] = ""; + sprintf_s(vid, sizeof(vid), "%04X", deviceVendor); + sprintf_s(pid, sizeof(pid), "%04X", deviceProduct); + std::string strVid(vid); + std::string strPid(pid); + std::string vendorProduct = strVid + ":" + strPid; + std::string deviceIdentification = sysPath.substr(0, sysPath.find(vendorProduct)) + vendorProduct; + MMI_HILOGI("Device identification is:%{public}s", deviceIdentification.c_str()); + return deviceIdentification; +} + +void InputDeviceManager::NotifyDevCallback(int32_t deviceId, struct InputDeviceInfo inDevice) +{ + if (!inDevice.isTouchableDevice || (deviceId < 0)) { + MMI_HILOGI("The device is not touchable device already existent"); + return; + } + if (!inDevice.sysUid.empty()) { + devCallbacks_(deviceId, inDevice.sysUid, "add"); + MMI_HILOGI("Send device info to window manager, device id:%{public}d, system uid:%{public}s, status:add", + deviceId, inDevice.sysUid.c_str()); + } else { + MMI_HILOGE("Get device system uid id is empty, deviceId:%{public}d", deviceId); + } +} + +int32_t InputDeviceManager::ParseDeviceId(const std::string &sysName) +{ + CALL_DEBUG_ENTER; + std::regex pattern("^event(\\d+)$"); + std::smatch mr; + + if (std::regex_match(sysName, mr, pattern)) { + if (mr.ready() && mr.size() == EXPECTED_N_SUBMATCHES) { + return std::stoi(mr[EXPECTED_SUBMATCH].str()); + } + } + return -1; +} + void InputDeviceManager::OnInputDeviceAdded(struct libinput_device *inputDevice) { CALL_DEBUG_ENTER; CHKPV(inputDevice); - bool hasLocalPointer = false; + bool hasPointer = false; for (const auto &item : inputDevice_) { - if (item.second.inputDeviceOrigin_ == inputDevice) { + if (item.second.inputDeviceOrigin == inputDevice) { MMI_HILOGI("The device is already existent"); DfxHisysevent::OnDeviceConnect(item.first, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT); return; } - if (!item.second.isRemote_ && IsPointerDevice(item.second.inputDeviceOrigin_)) { - hasLocalPointer = true; + if (item.second.isPointerDevice) { + hasPointer = true; } } - if (nextId_ == INT32_MAX) { - MMI_HILOGE("The nextId_ exceeded the upper limit"); - DfxHisysevent::OnDeviceConnect(INT32_MAX, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT); + + const char *sysName = libinput_device_get_sysname(inputDevice); + CHKPV(sysName); + int32_t deviceId = ParseDeviceId(std::string(sysName)); + if (deviceId < 0) { + MMI_HILOGE("Parsing sysname failed: \'%{public}s\'", sysName); return; } -#ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING - if (IsPointerDevice(inputDevice) && !HasPointerDevice()) { -#ifdef OHOS_BUILD_ENABLE_POINTER - WinMgr->DispatchPointer(PointerEvent::POINTER_ACTION_ENTER_WINDOW); -#endif // OHOS_BUILD_ENABLE_POINTER - } -#endif // OHOS_BUILD_ENABLE_POINTER_DRAWING + struct InputDeviceInfo info; MakeDeviceInfo(inputDevice, info); - inputDevice_[nextId_] = info; + inputDevice_[deviceId] = info; +#ifdef OHOS_BUILD_ENABLE_COOPERATE + if (!IsRemote(inputDevice) || InputDevCooSM->GetCurrentCooperateState() != CooperateState::STATE_FREE) { + for (const auto &item : devListener_) { + CHKPC(item.first); + item.second(deviceId, "add"); + } + } +#else for (const auto &item : devListener_) { CHKPC(item.first); - item.second(nextId_, "add"); + item.second(deviceId, "add"); } - ++nextId_; +#endif // OHOS_BUILD_ENABLE_COOPERATE + NotifyDevCallback(deviceId, info); + #ifdef OHOS_BUILD_ENABLE_COOPERATE if (IsKeyboardDevice(inputDevice)) { - InputDevCooSM->OnKeyboardOnline(info.dhid_); + if (IsRemote(inputDevice)) { + InputDevCooSM->SetVirtualKeyBoardDevId(deviceId); + } + InputDevCooSM->OnKeyboardOnline(info.dhid); } #endif // OHOS_BUILD_ENABLE_COOPERATE - if (IsPointerDevice(inputDevice)) { - bool visible = !info.isRemote_ || hasLocalPointer; - NotifyPointerDevice(true, visible); + if (!hasPointer && info.isPointerDevice) { +#ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING + if (HasTouchDevice()) { + IPointerDrawingManager::GetInstance()->SetMouseDisplayState(false); + } +#endif // OHOS_BUILD_ENABLE_POINTER_DRAWING + NotifyPointerDevice(true, true); OHOS::system::SetParameter(INPUT_POINTER_DEVICE, "true"); MMI_HILOGI("Set para input.pointer.device true"); } - DfxHisysevent::OnDeviceConnect(nextId_ - 1, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR); +#ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING + if (IsPointerDevice(inputDevice) && !HasPointerDevice() && + IPointerDrawingManager::GetInstance()->GetMouseDisplayState()) { +#ifdef OHOS_BUILD_ENABLE_POINTER + WinMgr->DispatchPointer(PointerEvent::POINTER_ACTION_ENTER_WINDOW); +#endif // OHOS_BUILD_ENABLE_POINTER + } +#endif // OHOS_BUILD_ENABLE_POINTER_DRAWING + DfxHisysevent::OnDeviceConnect(deviceId, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR); } void InputDeviceManager::MakeDeviceInfo(struct libinput_device *inputDevice, struct InputDeviceInfo& info) { - info.inputDeviceOrigin_ = inputDevice; + info.inputDeviceOrigin = inputDevice; + info.isRemote = IsRemote(inputDevice); + info.isPointerDevice = IsPointerDevice(inputDevice); + info.isTouchableDevice = IsTouchDevice(inputDevice); + info.sysUid = GetInputIdentification(inputDevice); #ifdef OHOS_BUILD_ENABLE_COOPERATE - info.isRemote_ = IsRemote(inputDevice); - if (info.isRemote_) { - info.networkIdOrigin_ = MakeNetworkId(libinput_device_get_phys(inputDevice)); + if (info.isRemote) { + info.networkIdOrigin = MakeNetworkId(libinput_device_get_phys(inputDevice)); } - info.dhid_ = GenerateDescriptor(inputDevice, info.isRemote_); + info.dhid = GenerateDescriptor(inputDevice, info.isRemote); #endif // OHOS_BUILD_ENABLE_COOPERATE + info.vendorConfig = configManagement_.GetVendorConfig(inputDevice); } void InputDeviceManager::OnInputDeviceRemoved(struct libinput_device *inputDevice) @@ -338,7 +463,7 @@ void InputDeviceManager::OnInputDeviceRemoved(struct libinput_device *inputDevic std::vector dhids; #endif // OHOS_BUILD_ENABLE_COOPERATE for (auto it = inputDevice_.begin(); it != inputDevice_.end(); ++it) { - if (it->second.inputDeviceOrigin_ == inputDevice) { + if (it->second.inputDeviceOrigin == inputDevice) { deviceId = it->first; #ifdef OHOS_BUILD_ENABLE_COOPERATE removedInfo = it->second; @@ -349,21 +474,38 @@ void InputDeviceManager::OnInputDeviceRemoved(struct libinput_device *inputDevic break; } } + std::string sysUid = GetInputIdentification(inputDevice); + if (!sysUid.empty()) { + devCallbacks_(deviceId, sysUid, "remove"); + MMI_HILOGI("Send device info to window manager, device id:%{public}d, system uid:%{public}s, status:remove", + deviceId, sysUid.c_str()); + } + #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING - if (IsPointerDevice(inputDevice) && !HasPointerDevice()) { + if (IsPointerDevice(inputDevice) && !HasPointerDevice() && + IPointerDrawingManager::GetInstance()->GetMouseDisplayState()) { #ifdef OHOS_BUILD_ENABLE_POINTER WinMgr->DispatchPointer(PointerEvent::POINTER_ACTION_LEAVE_WINDOW); #endif // OHOS_BUILD_ENABLE_POINTER } #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING +#ifdef OHOS_BUILD_ENABLE_COOPERATE + if (!IsRemote(inputDevice) || InputDevCooSM->GetCurrentCooperateState() != CooperateState::STATE_FREE) { + for (const auto &item : devListener_) { + CHKPC(item.first); + item.second(deviceId, "remove"); + } + } +#else for (const auto &item : devListener_) { CHKPC(item.first); item.second(deviceId, "remove"); } +#endif // OHOS_BUILD_ENABLE_COOPERATE ScanPointerDevice(); #ifdef OHOS_BUILD_ENABLE_COOPERATE if (IsPointerDevice(inputDevice)) { - InputDevCooSM->OnPointerOffline(removedInfo.dhid_, removedInfo.networkIdOrigin_, dhids); + InputDevCooSM->OnPointerOffline(removedInfo.dhid, removedInfo.networkIdOrigin, dhids); } #endif // OHOS_BUILD_ENABLE_COOPERATE if (deviceId == INVALID_DEVICE_ID) { @@ -375,7 +517,7 @@ void InputDeviceManager::ScanPointerDevice() { bool hasPointerDevice = false; for (auto it = inputDevice_.begin(); it != inputDevice_.end(); ++it) { - if (IsPointerDevice(it->second.inputDeviceOrigin_)) { + if (it->second.isPointerDevice) { hasPointerDevice = true; break; } @@ -404,6 +546,12 @@ bool InputDeviceManager::IsKeyboardDevice(struct libinput_device* device) const return udevTags & EVDEV_UDEV_TAG_KEYBOARD; } +bool InputDeviceManager::IsTouchDevice(struct libinput_device* device) const +{ + CHKPF(device); + return libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH); +} + void InputDeviceManager::Attach(std::shared_ptr observer) { CALL_DEBUG_ENTER; @@ -429,7 +577,7 @@ int32_t InputDeviceManager::FindInputDeviceId(struct libinput_device* inputDevic CALL_DEBUG_ENTER; CHKPR(inputDevice, INVALID_DEVICE_ID); for (const auto &item : inputDevice_) { - if (item.second.inputDeviceOrigin_ == inputDevice) { + if (item.second.inputDeviceOrigin == inputDevice) { MMI_HILOGI("Find input device id success"); return item.first; } @@ -445,7 +593,7 @@ struct libinput_device* InputDeviceManager::GetKeyboardDevice() const keyCodes.push_back(KeyEvent::KEYCODE_Q); keyCodes.push_back(KeyEvent::KEYCODE_NUMPAD_1); for (const auto &item : inputDevice_) { - const auto &device = item.second.inputDeviceOrigin_; + const auto &device = item.second.inputDeviceOrigin; if (IsMatchKeys(device, keyCodes)) { MMI_HILOGI("Find keyboard device success"); return device; @@ -501,6 +649,35 @@ void InputDeviceManager::DumpDeviceList(int32_t fd, const std::vectorsecond.isRemote; + } + MMI_HILOGD("isRemote:%{public}s", isRemote ? "true" : "false"); + return isRemote; +} + #ifdef OHOS_BUILD_ENABLE_COOPERATE std::vector InputDeviceManager::GetCooperateDhids(int32_t deviceId) { @@ -510,18 +687,17 @@ std::vector InputDeviceManager::GetCooperateDhids(int32_t deviceId) MMI_HILOGI("Find pointer id failed"); return dhids; } - if (!IsPointerDevice(iter->second.inputDeviceOrigin_)) { + if (!iter->second.isPointerDevice) { MMI_HILOGI("Not pointer device"); return dhids; } - dhids.push_back(iter->second.dhid_); + dhids.push_back(iter->second.dhid); MMI_HILOGI("unq: %{public}s, type:%{public}s", dhids.back().c_str(), "pointer"); - auto pointerNetworkId = iter->second.networkIdOrigin_; - std::string localNetworkId; - GetLocalDeviceId(localNetworkId); - pointerNetworkId = iter->second.isRemote_ ? iter->second.networkIdOrigin_ : localNetworkId; + auto pointerNetworkId = iter->second.networkIdOrigin; + std::string localNetworkId = GetLocalDeviceId(); + pointerNetworkId = iter->second.isRemote ? iter->second.networkIdOrigin : localNetworkId; for (const auto &item : inputDevice_) { - auto networkId = item.second.isRemote_ ? item.second.networkIdOrigin_ : localNetworkId; + auto networkId = item.second.isRemote ? item.second.networkIdOrigin : localNetworkId; if (networkId != pointerNetworkId) { continue; } @@ -531,7 +707,7 @@ std::vector InputDeviceManager::GetCooperateDhids(int32_t deviceId) return dhids; } if (keyboardType == KEYBOARD_TYPE_ALPHABETICKEYBOARD) { - dhids.push_back(item.second.dhid_); + dhids.push_back(item.second.dhid); MMI_HILOGI("unq: %{public}s, type:%{public}s", dhids.back().c_str(), "supportkey"); } } @@ -540,14 +716,14 @@ std::vector InputDeviceManager::GetCooperateDhids(int32_t deviceId) std::vector InputDeviceManager::GetCooperateDhids(const std::string &dhid) { - int32_t pointerId = -1; + int32_t inputDeviceId = INVALID_DEVICE_ID; for (const auto &iter : inputDevice_) { - if (iter.second.dhid_ == dhid) { - pointerId = iter.first; + if (iter.second.dhid == dhid) { + inputDeviceId = iter.first; break; } } - return GetCooperateDhids(pointerId); + return GetCooperateDhids(inputDeviceId); } std::string InputDeviceManager::GetOriginNetworkId(int32_t id) @@ -557,9 +733,9 @@ std::string InputDeviceManager::GetOriginNetworkId(int32_t id) MMI_HILOGE("Failed to search for the device: id %{public}d", id); return ""; } - auto networkId = iter->second.networkIdOrigin_; + auto networkId = iter->second.networkIdOrigin; if (networkId.empty()) { - GetLocalDeviceId(networkId); + networkId = GetLocalDeviceId(); } return networkId; } @@ -571,35 +747,19 @@ std::string InputDeviceManager::GetOriginNetworkId(const std::string &dhid) } std::string networkId; for (const auto &iter : inputDevice_) { - if (iter.second.dhid_ == dhid) { - networkId = iter.second.networkIdOrigin_; - if (networkId.empty()) { - GetLocalDeviceId(networkId); - break; - } + if (iter.second.isRemote && iter.second.dhid == dhid) { + networkId = iter.second.networkIdOrigin; + break; } } return networkId; } -void InputDeviceManager::GetLocalDeviceId(std::string &local) -{ - local = ""; - auto localNode = std::make_unique(); - CHKPV(localNode); - int32_t errCode = GetLocalNodeDeviceInfo(BUNDLE_NAME.c_str(), localNode.get()); - if (errCode != RET_OK) { - MMI_HILOGE("GetLocalNodeDeviceInfo errCode: %{public}d", errCode); - return; - } - local = localNode->networkId; -} - std::string InputDeviceManager::GetDhid(int32_t deviceId) const { auto dev = inputDevice_.find(deviceId); if (dev != inputDevice_.end()) { - return dev->second.dhid_; + return dev->second.dhid; } return ""; } @@ -607,39 +767,25 @@ std::string InputDeviceManager::GetDhid(int32_t deviceId) const bool InputDeviceManager::HasLocalPointerDevice() const { for (auto it = inputDevice_.begin(); it != inputDevice_.end(); ++it) { - if (!it->second.isRemote_ && IsPointerDevice(it->second.inputDeviceOrigin_)) { + if (!it->second.isRemote && it->second.isPointerDevice) { return true; } } return false; } -bool InputDeviceManager::IsRemote(struct libinput_device *inputDevice) const +void InputDeviceManager::NotifyVirtualKeyBoardStatus(int32_t deviceId, bool isAvailable) const { - CHKPR(inputDevice, false); - bool isRemote = false; - const char* name = libinput_device_get_name(inputDevice); - if (name == nullptr || name[0] == '\0') { - return false; - } - std::string strName = name; - std::string::size_type pos = strName.find(VIRTUAL_DEVICE_NAME); - if (pos != std::string::npos) { - isRemote = true; + MMI_HILOGI("virtual keyboard device %{public}s", isAvailable ? "online" : "offline"); + if (deviceId == -1) { + MMI_HILOGE("no virtual keyboard device for this device!"); + return; } - MMI_HILOGD("isRemote: %{public}s", isRemote == true ? "true" : "false"); - return isRemote; -} -bool InputDeviceManager::IsRemote(int32_t id) const -{ - bool isRemote = false; - auto device = inputDevice_.find(id); - if (device != inputDevice_.end()) { - isRemote = device->second.isRemote_; + for (const auto &item : devListener_) { + CHKPC(item.first); + item.second(deviceId, isAvailable ? "add" : "remove"); } - MMI_HILOGD("isRemote: %{public}s", isRemote == true ? "true" : "false"); - return isRemote; } std::string InputDeviceManager::MakeNetworkId(const char *phys) const @@ -659,7 +805,7 @@ std::string InputDeviceManager::MakeNetworkId(const char *phys) const std::string InputDeviceManager::Sha256(const std::string &in) const { - unsigned char out[SHA256_DIGEST_LENGTH * 2 + 1] = {0}; + unsigned char out[SHA256_DIGEST_LENGTH * 2 + 1] = { 0 }; SHA256_CTX ctx; SHA256_Init(&ctx); SHA256_Update(&ctx, in.data(), in.size()); @@ -699,11 +845,11 @@ std::string InputDeviceManager::GenerateDescriptor(struct libinput_device *input uint16_t product = libinput_device_get_id_product(inputDevice); std::string rawDescriptor; rawDescriptor += StringPrintf(":%04x:%04x:", vendor, product); - // add handling for USB devices to not uniqueify kbs that show up twice + // add handling for USB devices to not unique kbs that show up twice if (uniqueId != nullptr && uniqueId[0] != '\0') { rawDescriptor += "uniqueId:" + std::string(uniqueId); } - if (physicalPath != nullptr) { + if (physicalPath != nullptr && physicalPath[0] != '\0') { rawDescriptor += "physicalPath:" + std::string(physicalPath); } if (name != nullptr && name[0] != '\0') { @@ -737,14 +883,25 @@ const std::string& InputDeviceManager::GetScreenId(int32_t deviceId) const #ifdef OHOS_BUILD_ENABLE_COOPERATE auto item = inputDevice_.find(deviceId); if (item != inputDevice_.end()) { - auto iter = inputDeviceScreens_.find(item->second.dhid_); + auto iter = inputDeviceScreens_.find(item->second.dhid); if (iter != inputDeviceScreens_.end()) { return iter->second; } } -#endif // OHOS_BUILD_ENABLE_COOPERATE MMI_HILOGE("Find input device screen id failed"); +#endif // OHOS_BUILD_ENABLE_COOPERATE return UNKNOWN_SCREEN_ID; } + +VendorConfig InputDeviceManager::GetVendorConfig(int32_t deviceId) const +{ + CALL_DEBUG_ENTER; + auto it = inputDevice_.find(deviceId); + if (it == inputDevice_.end()) { + MMI_HILOGE("Device info not find id: %{public}d", deviceId); + return {}; + } + return it->second.vendorConfig; +} } // namespace MMI } // namespace OHOS diff --git a/service/dfx/include/dfx_hisysevent.h b/service/dfx/include/dfx_hisysevent.h index 2b762ccae4eeeeea65fa0dd208fad93dfef89a80..cf85026b2cea5a66e000f6c2d3aafc26ce1364b9 100644 --- a/service/dfx/include/dfx_hisysevent.h +++ b/service/dfx/include/dfx_hisysevent.h @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef DFX_HISYSEVENT_H #define DFX_HISYSEVENT_H @@ -70,6 +71,7 @@ public: static void CalcComboStartTimes(int32_t keyDownDuration); static void ReportDispTimes(); static void ReportComboStartTimes(); + static void ReportPowerInfo(std::shared_ptr key, OHOS::HiviewDFX::HiSysEvent::EventType type); static inline void GetComboStartTime() { comboStartTime_ = GetSysClockTime(); diff --git a/service/dfx/src/dfx_hisysevent.cpp b/service/dfx/src/dfx_hisysevent.cpp index 5b6c7d160b2b9931e4b7e53db0f0b38f520490bf..a979ae4c519a425e0927ba3b5fbfca5c7ea43942 100644 --- a/service/dfx/src/dfx_hisysevent.cpp +++ b/service/dfx/src/dfx_hisysevent.cpp @@ -12,8 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include "dfx_hisysevent.h" +#include "input_windows_manager.h" + namespace OHOS { namespace MMI { namespace { @@ -43,7 +46,7 @@ void DfxHisysevent::OnDeviceConnect(int32_t id, OHOS::HiviewDFX::HiSysEvent::Eve name = "INPUT_DEV_CONNECTION_SUCCESS"; } if (id == INT32_MAX) { - int32_t ret = OHOS::HiviewDFX::HiSysEvent::Write( + int32_t ret = HiSysEventWrite( OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MODAL_INPUT, name, type, @@ -52,7 +55,7 @@ void DfxHisysevent::OnDeviceConnect(int32_t id, OHOS::HiviewDFX::HiSysEvent::Eve MMI_HILOGE("HiviewDFX Write failed, ret:%{public}d", ret); } } else { - int32_t ret = OHOS::HiviewDFX::HiSysEvent::Write( + int32_t ret = HiSysEventWrite( OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MODAL_INPUT, name, type, @@ -70,7 +73,7 @@ void DfxHisysevent::OnDeviceConnect(int32_t id, OHOS::HiviewDFX::HiSysEvent::Eve void DfxHisysevent::OnDeviceDisconnect(int32_t id, OHOS::HiviewDFX::HiSysEvent::EventType type) { if (id == INVALID_DEVICE_ID) { - int32_t ret = OHOS::HiviewDFX::HiSysEvent::Write( + int32_t ret = HiSysEventWrite( OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MODAL_INPUT, "INPUT_DEV_DISCONNECTION_FAILURE", type, @@ -81,7 +84,7 @@ void DfxHisysevent::OnDeviceDisconnect(int32_t id, OHOS::HiviewDFX::HiSysEvent:: } else { std::shared_ptr dev = InputDevMgr->GetInputDevice(id); CHKPV(dev); - int32_t ret = OHOS::HiviewDFX::HiSysEvent::Write( + int32_t ret = HiSysEventWrite( OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MODAL_INPUT, "INPUT_DEV_DISCONNECTION_SUCCESS", type, @@ -99,7 +102,7 @@ void DfxHisysevent::OnDeviceDisconnect(int32_t id, OHOS::HiviewDFX::HiSysEvent:: void DfxHisysevent::OnClientConnect(const ClientConnectData &data, OHOS::HiviewDFX::HiSysEvent::EventType type) { if (type == OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR) { - int32_t ret = OHOS::HiviewDFX::HiSysEvent::Write( + int32_t ret = HiSysEventWrite( OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MODAL_INPUT, "CLIENT_CONNECTION_SUCCESS", type, @@ -113,7 +116,7 @@ void DfxHisysevent::OnClientConnect(const ClientConnectData &data, OHOS::HiviewD MMI_HILOGE("HiviewDFX Write failed, ret:%{public}d", ret); } } else { - int32_t ret = OHOS::HiviewDFX::HiSysEvent::Write( + int32_t ret = HiSysEventWrite( OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MODAL_INPUT, "CLIENT_CONNECTION_FAILURE", type, @@ -133,7 +136,7 @@ void DfxHisysevent::OnClientDisconnect(const SessionPtr& secPtr, int32_t fd, { CHKPV(secPtr); if (type == OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR) { - int32_t ret = OHOS::HiviewDFX::HiSysEvent::Write( + int32_t ret = HiSysEventWrite( OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MODAL_INPUT, "CLIENT_DISCONNECTION_SUCCESS", type, @@ -148,7 +151,7 @@ void DfxHisysevent::OnClientDisconnect(const SessionPtr& secPtr, int32_t fd, } } else { if (secPtr == nullptr) { - int32_t ret = OHOS::HiviewDFX::HiSysEvent::Write( + int32_t ret = HiSysEventWrite( OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MODAL_INPUT, "CLIENT_DISCONNECTION_FAILURE", type, @@ -157,7 +160,7 @@ void DfxHisysevent::OnClientDisconnect(const SessionPtr& secPtr, int32_t fd, MMI_HILOGE("HiviewDFX Write failed, ret:%{public}d", ret); } } else { - int32_t ret = OHOS::HiviewDFX::HiSysEvent::Write( + int32_t ret = HiSysEventWrite( OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MODAL_INPUT, "CLIENT_DISCONNECTION_FAILURE", type, @@ -174,7 +177,7 @@ void DfxHisysevent::OnUpdateTargetPointer(std::shared_ptr pointer, { CHKPV(pointer); if (type == OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR) { - int32_t ret = OHOS::HiviewDFX::HiSysEvent::Write( + int32_t ret = HiSysEventWrite( OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MODAL_INPUT, "TARGET_POINTER_EVENT_SUCCESS", type, @@ -188,7 +191,7 @@ void DfxHisysevent::OnUpdateTargetPointer(std::shared_ptr pointer, MMI_HILOGE("HiviewDFX Write failed, ret:%{public}d", ret); } } else { - int32_t ret = OHOS::HiviewDFX::HiSysEvent::Write( + int32_t ret = HiSysEventWrite( OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MODAL_INPUT, "TARGET_POINTER_EVENT_FAILURE", OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, @@ -205,7 +208,7 @@ void DfxHisysevent::OnUpdateTargetKey(std::shared_ptr key, int32_t fd, { CHKPV(key); if (type == OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR) { - int32_t ret = OHOS::HiviewDFX::HiSysEvent::Write( + int32_t ret = HiSysEventWrite( OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MODAL_INPUT, "TARGET_KEY_EVENT_SUCCESS", type, @@ -225,7 +228,7 @@ void DfxHisysevent::OnUpdateTargetKey(std::shared_ptr key, int32_t fd, MMI_HILOGE("HiviewDFX Write failed, ret:%{public}d", ret); } } else { - int32_t ret = OHOS::HiviewDFX::HiSysEvent::Write( + int32_t ret = HiSysEventWrite( OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MODAL_INPUT, "TARGET_KEY_EVENT_FAILURE", type, @@ -246,7 +249,7 @@ void DfxHisysevent::OnUpdateTargetKey(std::shared_ptr key, int32_t fd, void DfxHisysevent::OnFocusWindowChanged(int32_t oldFocusWindowId, int32_t newFocusWindowId, int32_t oldFocusWindowPid, int32_t newFocusWindowPid) { - int32_t ret = OHOS::HiviewDFX::HiSysEvent::Write( + int32_t ret = HiSysEventWrite( OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MODAL_INPUT, "FOCUS_WINDOW_CHANGE", OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, @@ -263,7 +266,7 @@ void DfxHisysevent::OnFocusWindowChanged(int32_t oldFocusWindowId, int32_t newFo void DfxHisysevent::OnZorderWindowChanged(int32_t oldZorderFirstWindowId, int32_t newZorderFirstWindowId, int32_t oldZorderFirstWindowPid, int32_t newZorderFirstWindowPid) { - int32_t ret = OHOS::HiviewDFX::HiSysEvent::Write( + int32_t ret = HiSysEventWrite( OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MODAL_INPUT, "Z_ORDER_WINDOW_CHANGE", OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, @@ -279,7 +282,7 @@ void DfxHisysevent::OnZorderWindowChanged(int32_t oldZorderFirstWindowId, int32_ void DfxHisysevent::ApplicationBlockInput(const SessionPtr& sess) { - int32_t ret = OHOS::HiviewDFX::HiSysEvent::Write( + int32_t ret = HiSysEventWrite( OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MODAL_INPUT, "APPLICATION_BLOCK_INPUT", OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, @@ -332,7 +335,7 @@ void DfxHisysevent::CalcPointerDispTimes() void DfxHisysevent::ReportDispTimes() { if (dispCastTime_.totalTimes >= REPORT_DISPATCH_TIMES) { - int32_t ret = OHOS::HiviewDFX::HiSysEvent::Write( + int32_t ret = HiSysEventWrite( OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MODAL_INPUT, "INPUT_DISPATCH_TIME", OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC, @@ -373,7 +376,7 @@ void DfxHisysevent::CalcComboStartTimes(const int32_t keyDownDuration) void DfxHisysevent::ReportComboStartTimes() { if (comboStartCastTime_.totalTimes >= REPORT_COMBO_START_TIMES) { - int32_t ret = OHOS::HiviewDFX::HiSysEvent::Write( + int32_t ret = HiSysEventWrite( OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MODAL_INPUT, "COMBO_START_TIME", OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC, @@ -393,6 +396,33 @@ void DfxHisysevent::ReportComboStartTimes() } } } + +void DfxHisysevent::ReportPowerInfo(std::shared_ptr key, OHOS::HiviewDFX::HiSysEvent::EventType type) +{ + if (key == nullptr) { + MMI_HILOGE("get key is failed"); + return; + } + if (key->GetKeyAction() == KeyEvent::KEY_ACTION_UP) { + int32_t ret = HiSysEventWrite( + OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MODAL_INPUT, + "INPUT_POWER_UP", + type); + if (ret != RET_OK) { + MMI_HILOGE("HiviewDFX Write failed, ret:%{public}d", ret); + } + } else if (key->GetKeyAction() == KeyEvent::KEY_ACTION_DOWN) { + int32_t ret = HiSysEventWrite( + OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MODAL_INPUT, + "INPUT_POWER_DOWN", + type); + if (ret != RET_OK) { + MMI_HILOGE("HiviewDFX Write failed, ret:%{public}d", ret); + } + } else { + MMI_HILOGW("press power key is error"); + } +} } } diff --git a/service/dinput/BUILD.gn b/service/dinput/BUILD.gn deleted file mode 100644 index 4363d91e62ad53fd0b112bb5096df170aec308df..0000000000000000000000000000000000000000 --- a/service/dinput/BUILD.gn +++ /dev/null @@ -1,75 +0,0 @@ -# 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. - -import("//build/ohos.gni") -import("//foundation/multimodalinput/input/multimodalinput_mini.gni") -dinput_path = "${mmi_path}/service/dinput" - -config("mmi_dinput_config") { - include_dirs = [ - "//foundation/multimodalinput/input/common/include", - "//foundation/multimodalinput/input/interfaces/native/innerkits/common/include", - "//foundation/multimodalinput/input/interfaces/native/innerkits/event/include", - "//foundation/multimodalinput/input/util/common/include", - "${dinput_path}/include", - ] - - if (input_feature_distributed) { - include_dirs += [ - "//foundation/distributedhardware/distributed_input/common/include", - "//foundation/distributedhardware/distributed_input/frameworks/include", - "//foundation/distributedhardware/distributed_input/interfaces/ipc/include", - ] - } -} -if (input_feature_distributed) { - ohos_source_set("mmi_dinput_service") { - sources = [ - "${dinput_path}/src/call_dinput_service.cpp", - "${dinput_path}/src/call_dinput_stub.cpp", - ] - - public_configs = [ ":mmi_dinput_config" ] - - configs = [ ":mmi_dinput_config" ] - - defines = [ "OHOS_DISTRIBUTED_INPUT_MODEL" ] - - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - ] - - if (input_feature_distributed) { - external_deps += [ "distributed_input:libdinput_sdk" ] - } - } - ohos_source_set("mmi_dinput_proxy") { - sources = [ - "${dinput_path}/src/call_dinput_death_recipient.cpp", - "${dinput_path}/src/call_dinput_proxy.cpp", - ] - - public_configs = [ ":mmi_dinput_config" ] - - configs = [ ":mmi_dinput_config" ] - - defines = [ "OHOS_DISTRIBUTED_INPUT_MODEL" ] - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - ] - } -} diff --git a/service/dinput/include/call_dinput_service.h b/service/dinput/include/call_dinput_service.h deleted file mode 100644 index 60065d71cf94e003f9ee0329a89cc893fdab3bb2..0000000000000000000000000000000000000000 --- a/service/dinput/include/call_dinput_service.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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 CALL_DINPUT_SERVICE_H -#define CALL_DINPUT_SERVICE_H -#ifdef OHOS_DISTRIBUTED_INPUT_MODEL - -#include "iremote_object.h" - -#include "call_dinput_stub.h" - -namespace OHOS { -namespace MMI { -class CallDinputService final : public CallDinputStub { -public: - CallDinputService() = default; - ~CallDinputService() = default; - int32_t HandlePrepareDinput(const std::string& deviceId, int32_t status) override; - int32_t HandleUnprepareDinput(const std::string& deviceId, int32_t status) override; - int32_t HandleStartDinput(const std::string& deviceId, uint32_t inputTypes, int32_t status) override; - int32_t HandleStopDinput(const std::string& deviceId, uint32_t inputTypes, int32_t status) override; - int32_t HandleRemoteInputAbility(const std::set& remoteInputAbility) override; - void SetPrepareCallback(const std::function& callback); - void SetUnprepareCallback(const std::function& callback); - void SetStartCallback(const std::function& callback); - void SetStopCallback(const std::function& callback); - void SetRemoteAbilityCallback(std::function)>& callback); -private: - std::function prepareCallback_ { nullptr }; - std::function unprepareCallback_ { nullptr }; - std::function startCallback_ { nullptr }; - std::function stopCallback_ { nullptr }; - std::function)> remoteAbilityCallback_ { nullptr }; -}; -} // namespace MMI -} // namespace OHOS -#endif // OHOS_DISTRIBUTED_INPUT_MODEL -#endif // CALL_DINPUT_SERVICE_H diff --git a/service/dinput/include/dinput_callback.h b/service/dinput/include/dinput_callback.h deleted file mode 100644 index 2c556240078f77a795da8e2362fb0d033a8e989a..0000000000000000000000000000000000000000 --- a/service/dinput/include/dinput_callback.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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 DINPUT_CALLBACK_H -#define DINPUT_CALLBACK_H -#ifdef OHOS_DISTRIBUTED_INPUT_MODEL - -#include -#include - -#include "prepare_d_input_call_back_stub.h" -#include "start_d_input_call_back_stub.h" -#include "stop_d_input_call_back_stub.h" -#include "unprepare_d_input_call_back_stub.h" - -#include "i_call_dinput.h" - -namespace OHOS { -namespace MMI { -class PrepareDInputCallback : public OHOS::DistributedHardware::DistributedInput::PrepareDInputCallbackStub { -public: - explicit PrepareDInputCallback(sptr prepareDinput) : callback_(prepareDinput) {} - ~PrepareDInputCallback() = default; - void OnResult(const std::string& deviceId, const int32_t& status) override; -private: - sptr callback_ { nullptr }; -}; - -class StartDInputCallback : public OHOS::DistributedHardware::DistributedInput::StartDInputCallbackStub { -public: - explicit StartDInputCallback(sptr prepareDinput) : callback_(prepareDinput) {} - ~StartDInputCallback() = default; - void OnResult(const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status) override; -private: - sptr callback_ { nullptr }; -}; - -class StopDInputCallback : public OHOS::DistributedHardware::DistributedInput::StopDInputCallbackStub { -public: - explicit StopDInputCallback(sptr prepareDinput) : callback_(prepareDinput) {} - ~StopDInputCallback() = default; - void OnResult(const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status) override; -private: - sptr callback_ { nullptr }; -}; - -class UnprepareDInputCallback : public OHOS::DistributedHardware::DistributedInput::UnprepareDInputCallbackStub { -public: - explicit UnprepareDInputCallback(sptr prepareDinput) : callback_(prepareDinput) {} - ~UnprepareDInputCallback() = default; - void OnResult(const std::string& deviceId, const int32_t& status) override; -private: - sptr callback_ { nullptr }; -}; -} -} -#endif // OHOS_DISTRIBUTED_INPUT_MODEL -#endif // DINPUT_CALLBACK_H diff --git a/service/dinput/include/dinput_manager.h b/service/dinput/include/dinput_manager.h deleted file mode 100644 index 7a273976f3a51596b9e8ed8bdc9e907bac12c1a9..0000000000000000000000000000000000000000 --- a/service/dinput/include/dinput_manager.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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_DINPUT_MANAGER_H -#define OHOS_DINPUT_MANAGER_H -#ifdef OHOS_DISTRIBUTED_INPUT_MODEL - -#include -#include - -#include "constants_dinput.h" -#include "i_call_dinput.h" -#include "key_event.h" -#include "singleton.h" - -namespace OHOS { -namespace MMI { -struct DMouseLocation { - int32_t globalX { 0 }; - int32_t globalY { 0 }; - int32_t dx { 0 }; - int32_t dy { 0 }; - int32_t displayId { 0 }; -}; - -class DInputManager final { - DECLARE_DELAYED_SINGLETON(DInputManager); -public: - static const uint32_t DEFAULT_ABILITY; - static const uint32_t MOUSE_ABILITY; - static const uint32_t KEYBOARD_ABILITY; - static const uint32_t TOUCH_ABILITY; - static const uint32_t FULL_ABILITY; -public: - DISALLOW_COPY_AND_MOVE(DInputManager); - void SetMouseLocation(const DMouseLocation& info); - DMouseLocation& GetMouseLocation(); - bool IsControllerSide(uint32_t inputAbility); - bool IsDistributedInput(uint32_t inputAbility); - bool IsNeedFilterOut(const std::string& deviceId, const std::shared_ptr& key); - bool CheckWhiteList(const std::shared_ptr& key, bool &jumpIntercept); - OHOS::DistributedHardware::DistributedInput::DInputServerType GetDInputServerType(uint32_t inputAbility); - - int32_t PrepareRemoteInput(const std::string& deviceId, sptr prepareDinput); - int32_t UnprepareRemoteInput(const std::string& deviceId, sptr prepareDinput); - int32_t StartRemoteInput(const std::string& deviceId, uint32_t inputAbility, - sptr prepareDinput); - int32_t StopRemoteInput(const std::string& deviceId, uint32_t inputAbility, - sptr prepareDinput); - void OnStartRemoteInput(const std::string& deviceId, uint32_t inputTypes); - void OnStopRemoteInput(const std::string& deviceId, uint32_t inputTypes); -private: - DMouseLocation mouseLocation_; - int32_t inputTypes_ { 0 }; -}; - -#define DInputMgr ::OHOS::DelayedSingleton::GetInstance() -} // namespace MMI -} // namespace OHOS -#endif // OHOS_DISTRIBUTED_INPUT_MODEL -#endif // OHOS_DINPUT_MANAGER_H diff --git a/service/dinput/src/call_dinput_proxy.cpp b/service/dinput/src/call_dinput_proxy.cpp deleted file mode 100644 index a1f22fbaa8bb3f620b5953769a149f449575c2ec..0000000000000000000000000000000000000000 --- a/service/dinput/src/call_dinput_proxy.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/* - * 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. - */ - -#include "call_dinput_proxy.h" - -#include "message_option.h" -#include "string_ex.h" - -#include "error_multimodal.h" -#include "mmi_log.h" - -namespace OHOS { -namespace MMI { -namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "CallDinputProxy" }; -} // namespace - -int32_t CallDinputProxy::HandlePrepareDinput(const std::string &deviceId, int32_t status) -{ - CALL_INFO_TRACE; - MessageParcel data; - if (!data.WriteInterfaceToken(CallDinputProxy::GetDescriptor())) { - MMI_HILOGW("Failed to write descriptor"); - return false; - } - WRITESTRING(data, deviceId, RET_ERR); - WRITEINT32(data, status, RET_ERR); - MessageParcel reply; - MessageOption option; - sptr remote = Remote(); - CHKPR(remote, ERROR_NULL_POINTER); - int32_t ret = remote->SendRequest(HANDLE_PREPARE_DINPUT, data, reply, option); - if (ret != NO_ERROR) { - MMI_HILOGW("Send request failed, result:%{public}d", ret); - return false; - } - return ret; -} - -int32_t CallDinputProxy::HandleUnprepareDinput(const std::string &deviceId, int32_t status) -{ - CALL_INFO_TRACE; - MessageParcel data; - if (!data.WriteInterfaceToken(CallDinputProxy::GetDescriptor())) { - MMI_HILOGW("Failed to write descriptor"); - return false; - } - WRITESTRING(data, deviceId, RET_ERR); - WRITEINT32(data, status, RET_ERR); - MessageParcel reply; - MessageOption option; - sptr remote = Remote(); - CHKPR(remote, ERROR_NULL_POINTER); - int32_t ret = remote->SendRequest(HANDLE_UNPREPARE_DINPUT, data, reply, option); - if (ret != NO_ERROR) { - MMI_HILOGW("Send request failed, result:%{public}d", ret); - return false; - } - return ret; -} - -int32_t CallDinputProxy::HandleStartDinput(const std::string &deviceId, uint32_t inputTypes, int32_t status) -{ - CALL_INFO_TRACE; - MessageParcel data; - if (!data.WriteInterfaceToken(CallDinputProxy::GetDescriptor())) { - MMI_HILOGW("Failed to write descriptor"); - return false; - } - WRITESTRING(data, deviceId, RET_ERR); - WRITEINT32(data, inputTypes, RET_ERR); - WRITEINT32(data, status, RET_ERR); - MessageParcel reply; - MessageOption option; - sptr remote = Remote(); - CHKPR(remote, ERROR_NULL_POINTER); - int32_t ret = remote->SendRequest(HANDLE_START_DINPUT, data, reply, option); - if (ret != NO_ERROR) { - MMI_HILOGW("Send request failed, result:%{public}d", ret); - return false; - } - return ret; -} - -int32_t CallDinputProxy::HandleStopDinput(const std::string &deviceId, uint32_t inputTypes, int32_t status) -{ - CALL_INFO_TRACE; - MessageParcel data; - if (!data.WriteInterfaceToken(CallDinputProxy::GetDescriptor())) { - MMI_HILOGW("Failed to write descriptor"); - return false; - } - WRITESTRING(data, deviceId, RET_ERR); - WRITEINT32(data, inputTypes, RET_ERR); - WRITEINT32(data, status, RET_ERR); - MessageParcel reply; - MessageOption option; - sptr remote = Remote(); - CHKPR(remote, ERROR_NULL_POINTER); - int32_t ret = remote->SendRequest(HANDLE_STOP_DINPUT, data, reply, option); - if (ret != NO_ERROR) { - MMI_HILOGW("Send request failed, result:%{public}d", ret); - return false; - } - return ret; -} - -int32_t CallDinputProxy::HandleRemoteInputAbility(const std::set &remoteInputAbility) -{ - CALL_INFO_TRACE; - MessageParcel data; - if (!data.WriteInterfaceToken(CallDinputProxy::GetDescriptor())) { - MMI_HILOGW("Failed to write descriptor"); - return false; - } - WRITEINT32(data, remoteInputAbility.size(), RET_ERR); - for (const auto &item : remoteInputAbility) { - WRITEINT32(data, item, RET_ERR); - } - MessageParcel reply; - MessageOption option; - sptr remote = Remote(); - CHKPR(remote, ERROR_NULL_POINTER); - int32_t ret = remote->SendRequest(HANDLE_REMOTE_INPUT_ABILITY, data, reply, option); - if (ret != NO_ERROR) { - MMI_HILOGW("Send request failed, result:%{public}d", ret); - return false; - } - return ret; -} -} // namespace MMI -} // namespace OHOS diff --git a/service/dinput/src/call_dinput_service.cpp b/service/dinput/src/call_dinput_service.cpp deleted file mode 100644 index f8ef65af3fb8d26afeba2f40a3a227e2d65dac0d..0000000000000000000000000000000000000000 --- a/service/dinput/src/call_dinput_service.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* - * 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. - */ - -#include "call_dinput_service.h" - -#include -#include -#include - -#include "error_multimodal.h" -#include "mmi_log.h" -#include "string_ex.h" - -namespace OHOS { -namespace MMI { -namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "CallDinputService" }; -} // namespace - -void CallDinputService::SetPrepareCallback(const std::function& callback) -{ - CALL_INFO_TRACE; - prepareCallback_ = callback; -} - -void CallDinputService::SetUnprepareCallback(const std::function& callback) -{ - CALL_INFO_TRACE; - unprepareCallback_ = callback; -} - -void CallDinputService::SetStartCallback(const std::function& callback) -{ - CALL_INFO_TRACE; - startCallback_ = callback; -} - -void CallDinputService::SetStopCallback(const std::function& callback) -{ - CALL_INFO_TRACE; - stopCallback_ = callback; -} - -void CallDinputService::SetRemoteAbilityCallback(std::function)>& callback) -{ - CALL_INFO_TRACE; - remoteAbilityCallback_ = callback; -} - -int32_t CallDinputService::HandlePrepareDinput(const std::string& deviceId, int32_t status) -{ - CALL_INFO_TRACE; - CHKPR(prepareCallback_, ERROR_NULL_POINTER); - prepareCallback_(status); - return RET_OK; -} - -int32_t CallDinputService::HandleUnprepareDinput(const std::string& deviceId, int32_t status) -{ - CALL_INFO_TRACE; - CHKPR(unprepareCallback_, ERROR_NULL_POINTER); - unprepareCallback_(status); - return RET_OK; -} - -int32_t CallDinputService::HandleStartDinput(const std::string& deviceId, uint32_t inputTypes, int32_t status) -{ - CALL_INFO_TRACE; - CHKPR(startCallback_, ERROR_NULL_POINTER); - startCallback_(status); - return RET_OK; -} - -int32_t CallDinputService::HandleStopDinput(const std::string& deviceId, uint32_t inputTypes, int32_t status) -{ - CALL_INFO_TRACE; - CHKPR(stopCallback_, ERROR_NULL_POINTER); - stopCallback_(status); - return RET_OK; -} - -int32_t CallDinputService::HandleRemoteInputAbility(const std::set& remoteInputAbility) -{ - CALL_INFO_TRACE; - CHKPR(remoteAbilityCallback_, ERROR_NULL_POINTER); - remoteAbilityCallback_(remoteInputAbility); - return RET_OK; -} -} // namespace MMI -} // namespace OHOS diff --git a/service/dinput/src/call_dinput_stub.cpp b/service/dinput/src/call_dinput_stub.cpp deleted file mode 100644 index 9dd43fe766437db58029bcbc3df53fd0039a5fae..0000000000000000000000000000000000000000 --- a/service/dinput/src/call_dinput_stub.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/* - * 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. - */ - -#include "call_dinput_stub.h" - -#include -#include - -#include "ipc_skeleton.h" -#include "mmi_log.h" -#include "string_ex.h" - -namespace OHOS { -namespace MMI { -namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "CallDinputStub" }; -} // namespace - -int32_t CallDinputStub::OnRemoteRequest( - uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) -{ - MMI_HILOGI("Enter, code:%{public}d", code); - - std::u16string descriptor = data.ReadInterfaceToken(); - if (descriptor != ICallDinput::GetDescriptor()) { - MMI_HILOGW("Get unexpect descriptor:%{public}s", Str16ToStr8(descriptor).c_str()); - return ERR_INVALID_STATE; - } - - switch (code) { - case HANDLE_PREPARE_DINPUT: { - return StubHandlePrepareDinput(data, reply); - } - case HANDLE_UNPREPARE_DINPUT: { - return StubHandleUnprepareDinput(data, reply); - } - case HANDLE_START_DINPUT: { - return StubHandleStartDinput(data, reply); - } - case HANDLE_STOP_DINPUT: { - return StubHandleStopDinput(data, reply); - } - case HANDLE_REMOTE_INPUT_ABILITY: { - return StubHandleRemoteInputAbility(data, reply); - } - default: { - MMI_HILOGW("Unknown code:%{public}u, go switch defaut", code); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - } -} - -int32_t CallDinputStub::StubHandlePrepareDinput(MessageParcel& data, MessageParcel& reply) -{ - CALL_INFO_TRACE; - std::string deviceId; - READSTRING(data, deviceId, RET_ERR); - int32_t status; - READINT32(data, status, RET_ERR); - return HandlePrepareDinput(deviceId, status); -} - -int32_t CallDinputStub::StubHandleUnprepareDinput(MessageParcel& data, MessageParcel& reply) -{ - CALL_INFO_TRACE; - std::string deviceId; - READSTRING(data, deviceId, RET_ERR); - int32_t status; - READINT32(data, status, RET_ERR); - return HandleUnprepareDinput(deviceId, status); -} - -int32_t CallDinputStub::StubHandleStartDinput(MessageParcel& data, MessageParcel& reply) -{ - CALL_INFO_TRACE; - std::string deviceId; - READSTRING(data, deviceId, RET_ERR); - int32_t inputAbility; - READINT32(data, inputAbility, RET_ERR); - int32_t status; - READINT32(data, status, RET_ERR); - return HandleStartDinput(deviceId, inputAbility, status); -} - -int32_t CallDinputStub::StubHandleStopDinput(MessageParcel& data, MessageParcel& reply) -{ - CALL_INFO_TRACE; - std::string deviceId; - READSTRING(data, deviceId, RET_ERR); - int32_t inputAbility; - READINT32(data, inputAbility, RET_ERR); - int32_t status; - READINT32(data, status, RET_ERR); - return HandleStopDinput(deviceId, inputAbility, status); -} - -int32_t CallDinputStub::StubHandleRemoteInputAbility(MessageParcel& data, MessageParcel& reply) -{ - CALL_INFO_TRACE; - std::set remoteInputAbility; - int32_t size; - READINT32(data, size, RET_ERR); - int32_t value; - for (size_t i = 0; i < size; i++) { - READINT32(data, value, RET_ERR); - remoteInputAbility.insert(value); - } - return HandleRemoteInputAbility(remoteInputAbility); -} -} // namespace MMI -} // namespace OHOS \ No newline at end of file diff --git a/service/dinput/src/dinput_callback.cpp b/service/dinput/src/dinput_callback.cpp deleted file mode 100644 index d5283095f249718cd954b4926734bcf87c09ef17..0000000000000000000000000000000000000000 --- a/service/dinput/src/dinput_callback.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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. - */ - -#include "dinput_callback.h" - -#include "define_multimodal.h" - -#include "dinput_manager.h" - -namespace OHOS { -namespace MMI { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "EventDinputService" }; -} - -void PrepareDInputCallback::OnResult(const std::string& deviceId, const int32_t& status) -{ - MMI_HILOGI("PrepareDInputCallback OnResult deviceId:%{public}s, status:%{public}d", - GetAnonyString(deviceId).c_str(), status); - CHKPV(callback_); - callback_->HandlePrepareDinput(deviceId, status); -} - -void StartDInputCallback::OnResult(const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status) -{ - MMI_HILOGI("StartDInputCallback OnResult deviceId:%{public}s, status:%{public}d", - GetAnonyString(deviceId).c_str(), status); - CHKPV(callback_); - callback_->HandleStartDinput(deviceId, inputTypes, status); - if (status != 0) { - MMI_HILOGI("StartDInputCallback OnResult status:%{public}d", status); - } - DInputMgr->OnStartRemoteInput(deviceId, inputTypes); -} - -void StopDInputCallback::OnResult(const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status) -{ - MMI_HILOGI("StopDInputCallback OnResult:%{public}s, status:%{public}d", GetAnonyString(deviceId).c_str(), status); - CHKPV(callback_); - callback_->HandleStopDinput(deviceId, inputTypes, status); - if (status != 0) { - MMI_HILOGI("StopDInputCallback OnResult status:%{public}d", status); - } - DInputMgr->OnStopRemoteInput(deviceId, inputTypes); -} - -void UnprepareDInputCallback::OnResult(const std::string& deviceId, const int32_t& status) -{ - MMI_HILOGI("UnprepareDInputCallback OnResult:%{public}s, status:%{public}d", - GetAnonyString(deviceId).c_str(), status); - CHKPV(callback_); - callback_->HandleUnprepareDinput(deviceId, status); -} -} // namespace MMI -} // namespace OHOS diff --git a/service/dinput/src/dinput_manager.cpp b/service/dinput/src/dinput_manager.cpp deleted file mode 100644 index 2c3c8be186e07318ceee997a1b75bfe4223511bd..0000000000000000000000000000000000000000 --- a/service/dinput/src/dinput_manager.cpp +++ /dev/null @@ -1,188 +0,0 @@ -/* - * 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. - */ - -#include "define_multimodal.h" -#include "dinput_callback.h" -#include "distributed_input_kit.h" -#include "input_device_manager.h" -#include "dinput_manager.h" - -using namespace OHOS::DistributedHardware::DistributedInput; -namespace OHOS { -namespace MMI { -namespace { -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "DInputManager" }; -} -const uint32_t DInputManager::DEFAULT_ABILITY = 0; -const uint32_t DInputManager::MOUSE_ABILITY = 1; -const uint32_t DInputManager::KEYBOARD_ABILITY = 2; -const uint32_t DInputManager::TOUCH_ABILITY = 4; -const uint32_t DInputManager::FULL_ABILITY = 7; - -DInputManager::DInputManager() {} -DInputManager::~DInputManager() {} - -void DInputManager::SetMouseLocation(const DMouseLocation& info) -{ - mouseLocation_ = info; -} - -DMouseLocation& DInputManager::GetMouseLocation() -{ - return mouseLocation_; -} - -bool DInputManager::IsControllerSide(uint32_t inputAbility) -{ - CALL_INFO_TRACE; - DInputServerType type = GetDInputServerType(inputAbility); - MMI_HILOGI("type:%{public}d", type); - return type != DInputServerType::SINK_SERVER_TYPE; -} - -bool DInputManager::IsDistributedInput(uint32_t inputAbility) -{ - CALL_INFO_TRACE; - DInputServerType type = GetDInputServerType(inputAbility); - MMI_HILOGI("type:%{public}d", type); - return type != DInputServerType::NULL_SERVER_TYPE; -} - -bool DInputManager::CheckWhiteList(const std::shared_ptr& key, bool &jumpIntercept) -{ - CALL_INFO_TRACE; - jumpIntercept = false; - std::string deviceId = ""; - DInputServerType type = GetDInputServerType(DInputManager::KEYBOARD_ABILITY); - if (DInputServerType::SOURCE_SERVER_TYPE == type) { - std::shared_ptr inputDevice = InputDevMgr->GetRemoteInputDevice(key->GetDeviceId()); - if (inputDevice != nullptr) { - deviceId = inputDevice->GetNetworkId(); - if (!IsNeedFilterOut(deviceId, key)) { - return true; - } - } - } else if (DInputServerType::SINK_SERVER_TYPE == type) { - if (!IsNeedFilterOut(deviceId, key)) { - return true; - } else { - jumpIntercept = true; - MMI_HILOGW("Events are filtered"); - } - } - return false; -} - -DInputServerType DInputManager::GetDInputServerType(uint32_t inputAbility) -{ - CALL_INFO_TRACE; - DInputServerType type = DistributedInputKit::IsStartDistributedInput(inputAbility); - MMI_HILOGI("type:%{public}d", type); - return type; -} - -bool DInputManager::IsNeedFilterOut(const std::string& deviceId, const std::shared_ptr& key) -{ - CALL_INFO_TRACE; - CHKPF(key); - const std::vector& pressedKeys = key->GetKeyItems(); - std::vector pressedKeysForDInput; - pressedKeysForDInput.reserve(pressedKeys.size()); - for (size_t i = 0; i < pressedKeys.size(); i++) { - pressedKeysForDInput.push_back(pressedKeys[i].GetKeyCode()); - } - BusinessEvent businessEvent; - businessEvent.keyCode = key->GetKeyCode(); - businessEvent.keyAction = key->GetKeyAction(); - businessEvent.pressedKeys = pressedKeysForDInput; - for (const auto &item : businessEvent.pressedKeys) { - MMI_HILOGI("pressedKeys:%{public}d", item); - } - MMI_HILOGI("deviceId:%{public}s, keyCode:%{public}d, keyAction:%{public}d", - GetAnonyString(deviceId).c_str(), businessEvent.keyCode, businessEvent.keyAction); - if (!DistributedInputKit::IsNeedFilterOut(deviceId, businessEvent)) { - MMI_HILOGI("IsNeedFilterOut:%{public}s", "false"); - } - return true; -} - -int32_t DInputManager::PrepareRemoteInput(const std::string& deviceId, sptr prepareDinput) -{ - CALL_INFO_TRACE; - sptr callback = new PrepareDInputCallback(prepareDinput); - CHKPR(callback, ERROR_NULL_POINTER); - return DistributedInputKit::PrepareRemoteInput(deviceId, callback); -} - -int32_t DInputManager::UnprepareRemoteInput(const std::string& deviceId, sptr prepareDinput) -{ - CALL_INFO_TRACE; - sptr callback = new UnprepareDInputCallback(prepareDinput); - CHKPR(callback, ERROR_NULL_POINTER); - return DistributedInputKit::UnprepareRemoteInput(deviceId, callback); -} - -int32_t DInputManager::StartRemoteInput(const std::string& deviceId, uint32_t inputAbility, - sptr prepareDinput) -{ - CALL_INFO_TRACE; - sptr callback = new StartDInputCallback(prepareDinput); - CHKPR(callback, ERROR_NULL_POINTER); - DistributedInputKit::IsStartDistributedInput(inputAbility); - return DistributedInputKit::StartRemoteInput(deviceId, inputAbility, callback); -} - -int32_t DInputManager::StopRemoteInput(const std::string& deviceId, uint32_t inputAbility, - sptr prepareDinput) -{ - CALL_INFO_TRACE; - sptr callback = new StopDInputCallback(prepareDinput); - CHKPR(callback, ERROR_NULL_POINTER); - return DistributedInputKit::StopRemoteInput(deviceId, - inputAbility, callback); -} - -void DInputManager::OnStartRemoteInput(const std::string& deviceId, uint32_t inputTypes) -{ - MMI_HILOGI("Enter: inputTypes:%{public}d", inputTypes); - int32_t diffBit = (inputTypes_ & DInputManager::FULL_ABILITY) ^ (inputTypes & DInputManager::FULL_ABILITY); - MMI_HILOGI("diffBit:%{public}d", diffBit); - if (diffBit == 0) { - return; - } - inputTypes_ = (inputTypes_ & DInputManager::FULL_ABILITY) | (inputTypes & DInputManager::FULL_ABILITY); - MMI_HILOGI("inputTypes_:%{public}d", inputTypes_); - int32_t addTypes = diffBit & (inputTypes & DInputManager::FULL_ABILITY); - MMI_HILOGI("addTypes:%{public}d", addTypes); - if (addTypes != 0) { - InputDevMgr->OnStartRemoteInput(deviceId, addTypes); - } -} - -void DInputManager::OnStopRemoteInput(const std::string& deviceId, uint32_t inputTypes) -{ - MMI_HILOGI("Enter: inputTypes:%{public}d", inputTypes); - int32_t removeTypes = (inputTypes_ & DInputManager::FULL_ABILITY) & (inputTypes & DInputManager::FULL_ABILITY); - MMI_HILOGI("removeTypes:%{public}d", removeTypes); - if (removeTypes == 0) { - MMI_HILOGE("Stop remoteInput failed"); - return; - } - inputTypes_ = inputTypes_ ^ removeTypes; - MMI_HILOGI("inputTypes_:%{public}d", inputTypes_); - InputDevMgr->OnStopRemoteInput(deviceId, removeTypes); -} -} // namespace MMI -} // namespace OHOS diff --git a/service/event_dispatch/include/event_dispatch_handler.h b/service/event_dispatch/include/event_dispatch_handler.h index b7990681eed5249dae8091a1ae4d173ff45993b3..b6e53142fda4edeae1d067423b2d47e6c1d1f8d6 100644 --- a/service/event_dispatch/include/event_dispatch_handler.h +++ b/service/event_dispatch/include/event_dispatch_handler.h @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef EVENT_DISPATCH_HANDLER_H #define EVENT_DISPATCH_HANDLER_H @@ -27,8 +28,8 @@ namespace OHOS { namespace MMI { -class EventDispatchHandler : public IInputEventHandler { - struct MouseState { +class EventDispatchHandler final : public IInputEventHandler { + struct DinputSimulateEvent { uint32_t type { PointerEvent::SOURCE_TYPE_UNKNOWN }; uint32_t code { PointerEvent::BUTTON_NONE }; int32_t value { PointerEvent::POINTER_ACTION_UNKNOWN }; @@ -36,7 +37,7 @@ class EventDispatchHandler : public IInputEventHandler { public: EventDispatchHandler(); DISALLOW_COPY_AND_MOVE(EventDispatchHandler); - virtual ~EventDispatchHandler(); + ~EventDispatchHandler() override = default; #ifdef OHOS_BUILD_ENABLE_KEYBOARD void HandleKeyEvent(const std::shared_ptr keyEvent) override; #endif // OHOS_BUILD_ENABLE_KEYBOARD @@ -53,16 +54,18 @@ public: void HandlePointerEventInner(const std::shared_ptr point); #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH #ifdef OHOS_BUILD_ENABLE_COOPERATE - void OnMouseStateChange(uint32_t type, uint32_t code, int32_t value); -#endif // OHOS_BUILD_ENABLE_COOPERATE + void OnDinputSimulateEvent(uint32_t type, uint32_t code, int32_t value); bool CheckPointerEvent(std::shared_ptr pointerEvent); +#endif // OHOS_BUILD_ENABLE_COOPERATE private: #ifdef OHOS_BUILD_ENABLE_COOPERATE std::mutex lock_; - std::vector mouseState_; + std::vector dinputSimulateEvent_; #endif // OHOS_BUILD_ENABLE_COOPERATE + int32_t eventTime_ { 0 }; + int32_t currentTime_ { 0 }; }; } // namespace MMI } // namespace OHOS -#endif // EVENT_DISPATCH_HANDLER_H \ No newline at end of file +#endif // EVENT_DISPATCH_HANDLER_H diff --git a/service/event_dispatch/src/event_dispatch_handler.cpp b/service/event_dispatch/src/event_dispatch_handler.cpp index 8583482fb0249643b52ee89654539f9ca9b41a0b..6f7bacb2f3cae031ef8497b7470664847802dce9 100644 --- a/service/event_dispatch/src/event_dispatch_handler.cpp +++ b/service/event_dispatch/src/event_dispatch_handler.cpp @@ -30,6 +30,7 @@ #include "input_event_handler.h" #include "input_windows_manager.h" #include "input-event-codes.h" +#include "mouse_device_state.h" #include "napi_constants.h" #include "proto.h" #include "util.h" @@ -40,18 +41,17 @@ namespace { #if defined(OHOS_BUILD_ENABLE_KEYBOARD) || defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "EventDispatchHandler" }; #endif // OHOS_BUILD_ENABLE_KEYBOARD || OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH +constexpr int32_t INTERVAL_TIME = 3000; // log time interval is 3 seconds. } // namespace EventDispatchHandler::EventDispatchHandler() { #ifdef OHOS_BUILD_ENABLE_COOPERATE - DistributedAdapter->RegisterEventCallback(std::bind(&EventDispatchHandler::OnMouseStateChange, this, + DistributedAdapter->RegisterEventCallback(std::bind(&EventDispatchHandler::OnDinputSimulateEvent, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); #endif // OHOS_BUILD_ENABLE_COOPERATE } -EventDispatchHandler::~EventDispatchHandler() {} - #ifdef OHOS_BUILD_ENABLE_KEYBOARD void EventDispatchHandler::HandleKeyEvent(const std::shared_ptr keyEvent) { @@ -84,15 +84,19 @@ void EventDispatchHandler::HandlePointerEventInner(const std::shared_ptrGetClientFd(point); - if (fd < 0) { + currentTime_ = point->GetActionTime(); + if (fd < 0 && currentTime_ - eventTime_ > INTERVAL_TIME) { + eventTime_ = currentTime_; MMI_HILOGE("The fd less than 0, fd:%{public}d", fd); DfxHisysevent::OnUpdateTargetPointer(point, fd, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT); return; } +#ifdef OHOS_BUILD_ENABLE_COOPERATE if (CheckPointerEvent(point)) { MMI_HILOGE("Check pointer event return true,filter out this pointer event"); return; } +#endif // OHOS_BUILD_ENABLE_COOPERATE auto udsServer = InputHandler->GetUDSServer(); CHKPV(udsServer); auto session = udsServer->GetSession(fd); @@ -102,18 +106,17 @@ void EventDispatchHandler::HandlePointerEventInner(const std::shared_ptrGetClientPid(fd); auto pointerEvent = std::make_shared(*point); auto pointerIdList = pointerEvent->GetPointerIds(); if (pointerIdList.size() > 1) { for (const auto& id : pointerIdList) { PointerEvent::PointerItem pointeritem; if (!pointerEvent->GetPointerItem(id, pointeritem)) { - MMI_HILOGW("Can't find this poinerItem"); + MMI_HILOGW("Can't find this pointerItem"); continue; } auto itemPid = WinMgr->GetWindowPid(pointeritem.GetTargetWindowId()); - if (itemPid >= 0 && itemPid != pid) { + if ((itemPid >= 0) && (itemPid != udsServer->GetClientPid(fd))) { pointerEvent->RemovePointerItem(id); MMI_HILOGD("pointerIdList size:%{public}zu", pointerEvent->GetPointerIds().size()); } @@ -136,7 +139,9 @@ int32_t EventDispatchHandler::DispatchKeyEventPid(UDSServer& udsServer, std::sha CALL_DEBUG_ENTER; CHKPR(key, PARAM_INPUT_INVALID); auto fd = WinMgr->UpdateTarget(key); - if (fd < 0) { + currentTime_ = key->GetActionTime(); + if (fd < 0 && currentTime_ - eventTime_ > INTERVAL_TIME) { + eventTime_ = currentTime_; MMI_HILOGE("Invalid fd, fd:%{public}d", fd); DfxHisysevent::OnUpdateTargetKey(key, fd, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT); return RET_ERR; @@ -151,7 +156,7 @@ int32_t EventDispatchHandler::DispatchKeyEventPid(UDSServer& udsServer, std::sha return RET_OK; } - NetPacket pkt(MmiMessageId::ON_KEYEVENT); + NetPacket pkt(MmiMessageId::ON_KEY_EVENT); InputEventDataTransformation::KeyEventToNetPacket(key, pkt); BytraceAdapter::StartBytrace(key, BytraceAdapter::KEY_DISPATCH_EVENT); pkt << fd; @@ -168,32 +173,35 @@ int32_t EventDispatchHandler::DispatchKeyEventPid(UDSServer& udsServer, std::sha } #endif // OHOS_BUILD_ENABLE_KEYBOARD +#ifdef OHOS_BUILD_ENABLE_COOPERATE bool EventDispatchHandler::CheckPointerEvent(std::shared_ptr pointerEvent) { CHKPF(pointerEvent); -#ifdef OHOS_BUILD_ENABLE_COOPERATE - if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_MOUSE) { - std::lock_guard guard(lock_); - if (!mouseState_.empty()) { - if (pointerEvent->GetSourceType() == static_cast(mouseState_[0].type) && - pointerEvent->GetButtonId() == static_cast(mouseState_[0].code) && - pointerEvent->GetPointerAction() == mouseState_[0].value) { - mouseState_.clear(); - return true; - } - } + if (pointerEvent->GetSourceType() != PointerEvent::SOURCE_TYPE_MOUSE) { + return false; + } + std::lock_guard guard(lock_); + if (dinputSimulateEvent_.empty()) { + return false; + } + int32_t pointerAction = PointerEvent::POINTER_ACTION_BUTTON_DOWN; + if (dinputSimulateEvent_[0].value == BUTTON_STATE_RELEASED) { + pointerAction = PointerEvent::POINTER_ACTION_BUTTON_UP; + } + if ((dinputSimulateEvent_[0].type == EV_KEY) && + (pointerAction == pointerEvent->GetPointerAction()) && + (MouseState->LibinputChangeToPointer(dinputSimulateEvent_[0].code) == pointerEvent->GetButtonId())) { + dinputSimulateEvent_.clear(); + return true; } -#endif // OHOS_BUILD_ENABLE_COOPERATE return false; } -#ifdef OHOS_BUILD_ENABLE_COOPERATE -void EventDispatchHandler::OnMouseStateChange(uint32_t type, uint32_t code, int32_t value) +void EventDispatchHandler::OnDinputSimulateEvent(uint32_t type, uint32_t code, int32_t value) { std::lock_guard guard(lock_); - mouseState_.clear(); - MouseState state = {type, code, value}; - mouseState_.push_back(state); + dinputSimulateEvent_.clear(); + dinputSimulateEvent_.push_back({type, code, value}); } #endif // OHOS_BUILD_ENABLE_COOPERATE } // namespace MMI diff --git a/service/event_dispatch/test/event_dispatch_test.cpp b/service/event_dispatch/test/event_dispatch_test.cpp index a0a1f9e942f3b03786579ad478af0a7e860cb2fc..05a52f53b0008726027d685dcc325a2d9c24a793 100644 --- a/service/event_dispatch/test/event_dispatch_test.cpp +++ b/service/event_dispatch/test/event_dispatch_test.cpp @@ -15,14 +15,13 @@ #include -#include "event_dispatch_handler.h" #include "define_multimodal.h" +#include "event_dispatch_handler.h" namespace OHOS { namespace MMI { namespace { using namespace testing::ext; -using namespace OHOS::MMI; } // namespace class EventDispatchTest : public testing::Test { diff --git a/service/event_dump/src/event_dump.cpp b/service/event_dump/src/event_dump.cpp index 4d30ac2aa8128320e653a4111b3a04f6fbeac0c3..bcfad7b03e9cb3ae69e0f3c4e30484d43a4300f2 100644 --- a/service/event_dump/src/event_dump.cpp +++ b/service/event_dump/src/event_dump.cpp @@ -27,9 +27,6 @@ #include "event_interceptor_handler.h" #include "event_monitor_handler.h" -#ifdef OHOS_BUILD_ENABLE_COOPERATE -#include "input_device_cooperate_sm.h" -#endif // OHOS_BUILD_ENABLE_COOPERATE #include "input_device_manager.h" #include "input_event_handler.h" #include "input_windows_manager.h" @@ -52,16 +49,6 @@ EventDump::~EventDump() {} void ChkConfig(int32_t fd) { mprintf(fd, "ChkMMIConfig: "); -#ifdef OHOS_BUILD_LIBINPUT - mprintf(fd, "OHOS_BUILD_LIBINPUT"); -#endif -#ifdef OHOS_BUILD_HDF - mprintf(fd, "OHOS_BUILD_HDF"); -#endif -#ifdef OHOS_BUILD_MMI_DEBUG - mprintf(fd, "OHOS_BUILD_MMI_DEBUG"); -#endif // OHOS_BUILD_MMI_DEBUG - mprintf(fd, "DEF_MMI_DATA_ROOT: %s\n", DEF_MMI_DATA_ROOT); mprintf(fd, "EXP_CONFIG: %s\n", DEF_EXP_CONFIG); mprintf(fd, "EXP_SOPATH: %s\n", DEF_EXP_SOPATH); @@ -88,20 +75,22 @@ void EventDump::ParseCommand(int32_t fd, const std::vector &args) } int32_t optionIndex = 0; struct option dumpOptions[] = { - {"help", no_argument, 0, 'h'}, - {"device", no_argument, 0, 'd'}, - {"devicelist", no_argument, 0, 'l'}, - {"windows", no_argument, 0, 'w'}, - {"udsserver", no_argument, 0, 'u'}, - {"subscriber", no_argument, 0, 's'}, - {"monitor", no_argument, 0, 'o'}, - {"interceptor", no_argument, 0, 'i'}, - {"mouse", no_argument, 0, 'm'}, -#ifdef OHOS_BUILD_ENABLE_COOPERATE - {"inputdevcoosm", no_argument, 0, 'k'}, -#endif // OHOS_BUILD_ENABLE_COOPERATE - {NULL, 0, 0, 0} + { "help", no_argument, 0, 'h' }, + { "device", no_argument, 0, 'd' }, + { "devicelist", no_argument, 0, 'l' }, + { "windows", no_argument, 0, 'w' }, + { "udsserver", no_argument, 0, 'u' }, + { "subscriber", no_argument, 0, 's' }, + { "monitor", no_argument, 0, 'o' }, + { "interceptor", no_argument, 0, 'i' }, + { "filter", no_argument, 0, 'f' }, + { "mouse", no_argument, 0, 'm' }, + { NULL, 0, 0, 0 } }; + if (args.empty()) { + MMI_HILOGE("size of args can't be zero"); + return; + } char **argv = new (std::nothrow) char *[args.size()]; CHKPV(argv); if (memset_s(argv, args.size() * sizeof(char*), 0, args.size() * sizeof(char*)) != EOK) { @@ -122,7 +111,7 @@ void EventDump::ParseCommand(int32_t fd, const std::vector &args) } optind = 1; int32_t c; - while ((c = getopt_long (args.size(), argv, "hdlwusoimc", dumpOptions, &optionIndex)) != -1) { + while ((c = getopt_long (args.size(), argv, "hdlwusoifmc", dumpOptions, &optionIndex)) != -1) { switch (c) { case 'h': { DumpEventHelp(fd, args); @@ -146,14 +135,6 @@ void EventDump::ParseCommand(int32_t fd, const std::vector &args) udsServer->Dump(fd, args); break; } - case 'c': { -#ifdef OHOS_BUILD_ENABLE_COOPERATE - InputDevCooSM->Dump(fd, args); -#else - mprintf(fd, "Input device cooperate does not support"); -#endif // OHOS_BUILD_ENABLE_COOPERATE - break; - } case 's': { #ifdef OHOS_BUILD_ENABLE_KEYBOARD auto subscriberHandler = InputHandler->GetSubscriberHandler(); @@ -184,6 +165,12 @@ void EventDump::ParseCommand(int32_t fd, const std::vector &args) #endif // OHOS_BUILD_ENABLE_INTERCEPTOR break; } + case 'f': { + auto filterHandler = InputHandler->GetFilterHandler(); + CHKPV(filterHandler); + filterHandler->Dump(fd, args); + break; + } case 'm': { #ifdef OHOS_BUILD_ENABLE_POINTER MouseEventHdr->Dump(fd, args); @@ -201,7 +188,9 @@ void EventDump::ParseCommand(int32_t fd, const std::vector &args) } RELEASE_RES: for (size_t i = 0; i < args.size(); ++i) { - delete[] argv[i]; + if (argv[i] != nullptr) { + delete[] argv[i]; + } } delete[] argv; } @@ -222,8 +211,8 @@ void EventDump::DumpHelp(int32_t fd) mprintf(fd, " -o, --monitor: dump the monitor information\t"); mprintf(fd, " -s, --subscriber: dump the subscriber information\t"); mprintf(fd, " -i, --interceptor: dump the interceptor information\t"); + mprintf(fd, " -f, --filter: dump the filter information\t"); mprintf(fd, " -m, --mouse: dump the mouse information\t"); - mprintf(fd, " -c, --dump Keyboard and mouse crossing information\t"); } } // namespace MMI } // namespace OHOS diff --git a/service/event_handler/include/anr_manager.h b/service/event_handler/include/anr_manager.h index 677bfc610a3b68ea1438535fbb970b88bd7203d6..f40e5507f3b9bbeb241d48e5c86924d4e7c36181 100644 --- a/service/event_handler/include/anr_manager.h +++ b/service/event_handler/include/anr_manager.h @@ -33,7 +33,7 @@ public: int32_t SetANRNoticedPid(int32_t anrPid); void OnSessionLost(SessionPtr session); void AddTimer(int32_t type, int32_t id, int64_t currentTime, SessionPtr sess); - void MarkProcessed(int32_t eventType, int32_t eventId, SessionPtr sess); + int32_t MarkProcessed(int32_t pid, int32_t eventType, int32_t eventId); void RemoveTimers(SessionPtr sess); private: int32_t anrNoticedPid_ { -1 }; diff --git a/service/event_handler/include/event_normalize_handler.h b/service/event_handler/include/event_normalize_handler.h index 1dba71cc17a48ea19ed1fe5904fa1a37565a63d6..e42c30dd7318616ee12ce0c16e3d0e90b9d9ada4 100644 --- a/service/event_handler/include/event_normalize_handler.h +++ b/service/event_handler/include/event_normalize_handler.h @@ -50,6 +50,7 @@ private: int32_t HandleMouseEvent(libinput_event* event); int32_t HandleTouchEvent(libinput_event* event); int32_t HandleTableToolEvent(libinput_event* event); + int32_t HandleJoystickEvent(libinput_event* event); #ifdef OHOS_BUILD_ENABLE_COOPERATE bool IsNeedFilterOut(const std::string& deviceId, const std::shared_ptr keyEvent); #endif // OHOS_BUILD_ENABLE_COOPERATE diff --git a/service/event_handler/include/input_event_handler.h b/service/event_handler/include/input_event_handler.h index 4461d6d5b2ce2838a98cae0b72055e90f8ab6b86..f8cf962038aa225cbdce7351b1a6dbfa71329f62 100644 --- a/service/event_handler/include/input_event_handler.h +++ b/service/event_handler/include/input_event_handler.h @@ -27,6 +27,7 @@ #include "event_normalize_handler.h" #include "i_event_filter.h" #include "i_input_event_handler.h" +#include "key_command_handler.h" #include "key_subscriber_handler.h" #include "mouse_event_normalize.h" @@ -45,6 +46,7 @@ public: std::shared_ptr GetEventNormalizeHandler() const; std::shared_ptr GetInterceptorHandler() const; std::shared_ptr GetSubscriberHandler() const; + std::shared_ptr GetKeyCommandHandler() const; std::shared_ptr GetMonitorHandler() const; std::shared_ptr GetFilterHandler() const; #ifdef OHOS_BUILD_ENABLE_COOPERATE @@ -60,6 +62,7 @@ private: std::shared_ptr eventFilterHandler_ { nullptr }; std::shared_ptr eventInterceptorHandler_ { nullptr }; std::shared_ptr eventSubscriberHandler_ { nullptr }; + std::shared_ptr eventKeyCommandHandler_ { nullptr }; std::shared_ptr eventMonitorHandler_ { nullptr }; uint64_t idSeed_ { 0 }; diff --git a/service/event_handler/include/key_auto_repeat.h b/service/event_handler/include/key_auto_repeat.h index 71f0cc3673b05ff524e4bca0dd903aa9115e0e44..a128c1cd0830cce885e440a1bad7cc6635710fab 100644 --- a/service/event_handler/include/key_auto_repeat.h +++ b/service/event_handler/include/key_auto_repeat.h @@ -20,8 +20,8 @@ #include #include "event_dispatch_handler.h" -#include "key_map_manager.h" #include "key_event.h" +#include "key_map_manager.h" #include "libinput.h" #include "singleton.h" #include "util.h" @@ -38,6 +38,7 @@ public: void RemoveDeviceConfig(struct libinput_device *device); int32_t GetIntervalTime(int32_t deviceId) const; std::map GetDeviceConfig() const; + void RemoveTimer(); private: std::string GetTomlFilePath(const std::string &fileName) const; DeviceConfig GetAutoSwitch(int32_t deviceId); diff --git a/service/event_handler/include/key_event_value_transformation.h b/service/event_handler/include/key_event_value_transformation.h index d6c23856e2f8133a69d782140f1a4b9eb9e51c4c..e4c6d7900b9e6592659984a730b7966f616e0180 100644 --- a/service/event_handler/include/key_event_value_transformation.h +++ b/service/event_handler/include/key_event_value_transformation.h @@ -18,6 +18,8 @@ #include +#include "key_event.h" + namespace OHOS { namespace MMI { struct KeyEventValueTransformation { @@ -29,6 +31,7 @@ struct KeyEventValueTransformation { KeyEventValueTransformation TransferKeyValue(int32_t keyValueOfInput); int32_t InputTransformationKeyValue(int32_t keyCode); +int32_t keyItemsTransKeyIntention(const std::vector &items); } // namespace MMI } // namespace OHOS #endif // KEY_EVENT_VALUE_TRANSFORMATION_H \ No newline at end of file diff --git a/service/event_handler/src/anr_manager.cpp b/service/event_handler/src/anr_manager.cpp index fdb9995c9b1c72266e83828ce5adf1a633c2a05d..51dc3e323718ce5adbb8e822b8f61f2cdbec8820 100644 --- a/service/event_handler/src/anr_manager.cpp +++ b/service/event_handler/src/anr_manager.cpp @@ -28,7 +28,6 @@ namespace OHOS { namespace MMI { namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "ANRManager" }; -constexpr int64_t INPUT_UI_TIMEOUT_TIME = 5 * 1000000; const std::string FOUNDATION = "foundation"; constexpr int32_t MAX_ANR_TIMER_COUNT = 50; } // namespace @@ -44,18 +43,22 @@ void ANRManager::Init(UDSServer &udsServer) udsServer_->AddSessionDeletedCallback(std::bind(&ANRManager::OnSessionLost, this, std::placeholders::_1)); } -void ANRManager::MarkProcessed(int32_t eventType, int32_t eventId, SessionPtr sess) +int32_t ANRManager::MarkProcessed(int32_t pid, int32_t eventType, int32_t eventId) { - CHKPV(sess); + CALL_DEBUG_ENTER; + MMI_HILOGD("pid:%{public}d, eventType:%{public}d, eventId:%{public}d", pid, eventType, eventId); + SessionPtr sess = udsServer_->GetSessionByPid(pid); + CHKPR(sess, RET_ERR); std::list timerIds = sess->DelEvents(eventType, eventId); for (int32_t item : timerIds) { if (item != -1) { TimerMgr->RemoveTimer(item); anrTimerCount_--; - MMI_HILOGD("Remove anr timer, anr type:%{public}d, eventId:%{public}d, timer id:%{public}d, count:%{public}d", - eventType, eventId, item, anrTimerCount_); + MMI_HILOGD("Remove anr timer, anr type:%{public}d, eventId:%{public}d, timer id:%{public}d," + "count:%{public}d", eventType, eventId, item, anrTimerCount_); } } + return RET_OK; } void ANRManager::RemoveTimers(SessionPtr sess) diff --git a/service/event_handler/src/event_normalize_handler.cpp b/service/event_handler/src/event_normalize_handler.cpp index 51721173b4e215b68f7f27000229e606f8be5138..614fd7c75c95c42881906332684799a83a75cdca 100644 --- a/service/event_handler/src/event_normalize_handler.cpp +++ b/service/event_handler/src/event_normalize_handler.cpp @@ -15,13 +15,15 @@ #include "event_normalize_handler.h" -#include "dfx_hisysevent.h" #include "bytrace_adapter.h" #include "define_multimodal.h" +#include "dfx_hisysevent.h" + #include "error_multimodal.h" #include "event_log_helper.h" #ifdef OHOS_BUILD_ENABLE_COOPERATE #include "input_device_cooperate_sm.h" +#include "input_device_cooperate_util.h" #endif // OHOS_BUILD_ENABLE_COOPERATE #include "input_device_manager.h" #include "input_event_handler.h" @@ -103,6 +105,12 @@ void EventNormalizeHandler::HandleEvent(libinput_event* event) HandleTableToolEvent(event); break; } + case LIBINPUT_EVENT_JOYSTICK_BUTTON: + case LIBINPUT_EVENT_JOYSTICK_AXIS: { + HandleJoystickEvent(event); + DfxHisysevent::CalcPointerDispTimes(); + break; + } default: { MMI_HILOGW("This device does not support"); break; @@ -272,8 +280,7 @@ bool EventNormalizeHandler::CheckKeyboardWhiteList(std::shared_ptr key return !IsNeedFilterOut(networkId, keyEvent); } } else if (state == CooperateState::STATE_OUT) { - std::string networkId; - InputDevMgr->GetLocalDeviceId(networkId); + std::string networkId = GetLocalDeviceId(); if (!IsNeedFilterOut(networkId, keyEvent)) { if (keyEvent->GetKeyAction() == KeyEvent::KEY_ACTION_UP) { KeyRepeat->SelectAutoRepeat(keyEvent); @@ -322,7 +329,7 @@ int32_t EventNormalizeHandler::HandleMouseEvent(libinput_event* event) const auto &keyEvent = KeyEventHdr->GetKeyEvent(); CHKPR(keyEvent, ERROR_NULL_POINTER); #endif // OHOS_BUILD_ENABLE_KEYBOARD - MouseEventHdr->Normalize(event); + MouseEventHdr->OnEvent(event); auto pointerEvent = MouseEventHdr->GetPointerEvent(); CHKPR(pointerEvent, ERROR_NULL_POINTER); #ifdef OHOS_BUILD_ENABLE_KEYBOARD @@ -348,7 +355,7 @@ int32_t EventNormalizeHandler::HandleTouchPadEvent(libinput_event* event) } #ifdef OHOS_BUILD_ENABLE_POINTER CHKPR(event, ERROR_NULL_POINTER); - auto pointerEvent = TouchEventHdr->OnLibInput(event, INPUT_DEVICE_CAP_TOUCH_PAD); + auto pointerEvent = TouchEventHdr->OnLibInput(event, TouchEventNormalize::DeviceType::TOUCH_PAD); CHKPR(pointerEvent, ERROR_NULL_POINTER); nextHandler_->HandlePointerEvent(pointerEvent); auto type = libinput_event_get_type(event); @@ -374,7 +381,7 @@ int32_t EventNormalizeHandler::HandleGestureEvent(libinput_event* event) } #ifdef OHOS_BUILD_ENABLE_POINTER CHKPR(event, ERROR_NULL_POINTER); - auto pointerEvent = TouchEventHdr->OnLibInput(event, INPUT_DEVICE_CAP_GESTURE); + auto pointerEvent = TouchEventHdr->OnLibInput(event, TouchEventNormalize::DeviceType::GESTURE); CHKPR(pointerEvent, GESTURE_EVENT_PKG_FAIL); MMI_HILOGD("GestureEvent package, eventType:%{public}d,actionTime:%{public}" PRId64 "," "action:%{public}d,actionStartTime:%{public}" PRId64 "," @@ -409,15 +416,8 @@ int32_t EventNormalizeHandler::HandleTouchEvent(libinput_event* event) } #ifdef OHOS_BUILD_ENABLE_TOUCH CHKPR(event, ERROR_NULL_POINTER); - auto pointerEvent = TouchEventHdr->OnLibInput(event, INPUT_DEVICE_CAP_TOUCH); + auto pointerEvent = TouchEventHdr->OnLibInput(event, TouchEventNormalize::DeviceType::TOUCH); CHKPR(pointerEvent, ERROR_NULL_POINTER); -#ifdef OHOS_DISTRIBUTED_INPUT_MODEL - if (InputDevCooSM->CheckTouchEvent(event)) { - MMI_HILOGW("Touch event filter out"); - ResetTouchUpEvent(pointerEvent, event); - return RET_OK; - } -#endif // OHOS_DISTRIBUTED_INPUT_MODEL BytraceAdapter::StartBytrace(pointerEvent, BytraceAdapter::TRACE_START); nextHandler_->HandleTouchEvent(pointerEvent); ResetTouchUpEvent(pointerEvent, event); @@ -446,12 +446,12 @@ void EventNormalizeHandler::ResetTouchUpEvent(std::shared_ptr poin int32_t EventNormalizeHandler::HandleTableToolEvent(libinput_event* event) { if (nextHandler_ == nullptr) { - MMI_HILOGW("Touchscreen device does not support"); + MMI_HILOGW("TableTool device does not support"); return ERROR_UNSUPPORT; } #ifdef OHOS_BUILD_ENABLE_TOUCH CHKPR(event, ERROR_NULL_POINTER); - auto pointerEvent = TouchEventHdr->OnLibInput(event, INPUT_DEVICE_CAP_TABLET_TOOL); + auto pointerEvent = TouchEventHdr->OnLibInput(event, TouchEventNormalize::DeviceType::TABLET_TOOL); CHKPR(pointerEvent, ERROR_NULL_POINTER); BytraceAdapter::StartBytrace(pointerEvent, BytraceAdapter::TRACE_START); nextHandler_->HandleTouchEvent(pointerEvent); @@ -459,11 +459,30 @@ int32_t EventNormalizeHandler::HandleTableToolEvent(libinput_event* event) pointerEvent->Reset(); } #else - MMI_HILOGW("Touchscreen device does not support"); + MMI_HILOGW("TableTool device does not support"); #endif // OHOS_BUILD_ENABLE_TOUCH return RET_OK; } +int32_t EventNormalizeHandler::HandleJoystickEvent(libinput_event* event) +{ + CALL_DEBUG_ENTER; + if (nextHandler_ == nullptr) { + MMI_HILOGW("Joystick device does not support"); + return ERROR_UNSUPPORT; + } +#ifdef OHOS_BUILD_ENABLE_JOYSTICK + CHKPR(event, ERROR_NULL_POINTER); + auto pointerEvent = TouchEventHdr->OnLibInput(event, TouchEventNormalize::DeviceType::JOYSTICK); + CHKPR(pointerEvent, ERROR_NULL_POINTER); + BytraceAdapter::StartBytrace(pointerEvent, BytraceAdapter::TRACE_START); + nextHandler_->HandlePointerEvent(pointerEvent); +#else + MMI_HILOGW("Joystick device does not support"); +#endif // OHOS_BUILD_ENABLE_JOYSTICK + return RET_OK; +} + int32_t EventNormalizeHandler::AddHandleTimer(int32_t timeout) { CALL_DEBUG_ENTER; diff --git a/service/event_handler/src/input_event_handler.cpp b/service/event_handler/src/input_event_handler.cpp index 59f5b6a6c55ac22280ec95806d4119df4ea9c3fe..06b980a2eff286129a174b8f4727a1d7d8f8d589 100644 --- a/service/event_handler/src/input_event_handler.cpp +++ b/service/event_handler/src/input_event_handler.cpp @@ -15,11 +15,11 @@ #include "input_event_handler.h" +#include #include #include #include #include -#include #include #include @@ -69,7 +69,11 @@ void InputEventHandler::OnEvent(void *event) "beginTime:%{public}" PRId64, idSeed_, GetThisThreadId(), eventType, beginTime); CHKPV(eventNormalizeHandler_); #ifdef OHOS_BUILD_ENABLE_COOPERATE - InputDevCooSM->HandleEvent(lpEvent); + if (InputDevCooSM->GetCooperateEnableState()) { + InputDevCooSM->HandleEvent(lpEvent); + } else { + eventNormalizeHandler_->HandleEvent(lpEvent); + } #else eventNormalizeHandler_->HandleEvent(lpEvent); #endif // OHOS_BUILD_ENABLE_COOPERATE @@ -82,7 +86,6 @@ void InputEventHandler::OnEvent(void *event) int32_t InputEventHandler::BuildInputHandlerChain() { eventNormalizeHandler_ = std::make_shared(); - CHKPR(eventNormalizeHandler_, ERROR_NULL_POINTER); #if !defined(OHOS_BUILD_ENABLE_KEYBOARD) && !defined(OHOS_BUILD_ENABLE_POINTER) && !defined(OHOS_BUILD_ENABLE_TOUCH) return RET_OK; #endif // !OHOS_BUILD_ENABLE_KEYBOARD && !OHOS_BUILD_ENABLE_POINTER && !OHOS_BUILD_ENABLE_TOUCH @@ -90,38 +93,32 @@ int32_t InputEventHandler::BuildInputHandlerChain() std::shared_ptr handler = eventNormalizeHandler_; #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) eventFilterHandler_ = std::make_shared(); - CHKPR(eventFilterHandler_, ERROR_NULL_POINTER); handler->SetNext(eventFilterHandler_); handler = eventFilterHandler_; #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH #ifdef OHOS_BUILD_ENABLE_INTERCEPTOR eventInterceptorHandler_ = std::make_shared(); - CHKPR(eventInterceptorHandler_, ERROR_NULL_POINTER); handler->SetNext(eventInterceptorHandler_); handler = eventInterceptorHandler_; #endif // OHOS_BUILD_ENABLE_INTERCEPTOR #ifdef OHOS_BUILD_ENABLE_KEYBOARD #ifdef OHOS_BUILD_ENABLE_COMBINATION_KEY - auto keyCommandHandler = std::make_shared(); - CHKPR(keyCommandHandler, ERROR_NULL_POINTER); - handler->SetNext(keyCommandHandler); - handler = keyCommandHandler; + eventKeyCommandHandler_ = std::make_shared(); + handler->SetNext(eventKeyCommandHandler_); + handler = eventKeyCommandHandler_; #endif // OHOS_BUILD_ENABLE_COMBINATION_KEY eventSubscriberHandler_ = std::make_shared(); - CHKPR(eventSubscriberHandler_, ERROR_NULL_POINTER); handler->SetNext(eventSubscriberHandler_); handler = eventSubscriberHandler_; #endif // OHOS_BUILD_ENABLE_KEYBOARD #ifdef OHOS_BUILD_ENABLE_MONITOR eventMonitorHandler_ = std::make_shared(); - CHKPR(eventMonitorHandler_, ERROR_NULL_POINTER); handler->SetNext(eventMonitorHandler_); handler = eventMonitorHandler_; #endif // OHOS_BUILD_ENABLE_MONITOR auto dispatchHandler = std::make_shared(); - CHKPR(dispatchHandler, ERROR_NULL_POINTER); handler->SetNext(dispatchHandler); return RET_OK; } @@ -146,6 +143,11 @@ std::shared_ptr InputEventHandler::GetSubscriberHandler() return eventSubscriberHandler_; } +std::shared_ptr InputEventHandler::GetKeyCommandHandler() const +{ + return eventKeyCommandHandler_; +} + std::shared_ptr InputEventHandler::GetMonitorHandler() const { return eventMonitorHandler_; diff --git a/service/event_handler/src/key_auto_repeat.cpp b/service/event_handler/src/key_auto_repeat.cpp index 1201a633df2d9179a8ae269f2d55007a3d63cc74..054e61794e47d738cc9ead86a5b3da07f2ca0804 100644 --- a/service/event_handler/src/key_auto_repeat.cpp +++ b/service/event_handler/src/key_auto_repeat.cpp @@ -48,7 +48,7 @@ int32_t KeyAutoRepeat::AddDeviceConfig(struct libinput_device *device) DeviceConfig devConf; auto ret = ReadTomlFile(GetTomlFilePath(fileName), devConf); if (ret == RET_ERR) { - MMI_HILOGE("Read device config file error"); + MMI_HILOGI("Can not read device config file"); return RET_ERR; } int32_t deviceId = InputDevMgr->FindInputDeviceId(device); @@ -83,13 +83,13 @@ void KeyAutoRepeat::SelectAutoRepeat(std::shared_ptr& keyEvent) if (keyEvent_->GetKeyAction() == KeyEvent::KEY_ACTION_UP && TimerMgr->IsExist(timerId_)) { TimerMgr->RemoveTimer(timerId_); timerId_ = -1; - MMI_HILOGI("Stop kayboard autorepeat, keyCode:%{public}d", keyEvent_->GetKeyCode()); + MMI_HILOGI("Stop keyboard autorepeat, keyCode:%{public}d", keyEvent_->GetKeyCode()); if (repeatKeyCode_ != keyEvent_->GetKeyCode()) { - auto pressedKeyItem = keyEvent_->GetKeyItem(keyEvent_->GetKeyCode()); - if (pressedKeyItem != nullptr) { + std::optional pressedKeyItem = keyEvent_->GetKeyItem(keyEvent_->GetKeyCode()); + if (pressedKeyItem) { keyEvent_->RemoveReleasedKeyItems(*pressedKeyItem); } else { - MMI_HILOGW("The pressedKeyItem is nullptr"); + MMI_HILOGW("The pressedKeyItem is nullopt"); } keyEvent_->SetKeyCode(repeatKeyCode_); keyEvent_->SetAction(KeyEvent::KEY_ACTION_DOWN); @@ -147,10 +147,16 @@ void KeyAutoRepeat::RemoveDeviceConfig(struct libinput_device *device) int32_t deviceId = InputDevMgr->FindInputDeviceId(device); auto iter = deviceConfig_.find(deviceId); if (iter == deviceConfig_.end()) { - MMI_HILOGE("Device config file remove failed"); + MMI_HILOGI("Can not remove device config file"); return; } deviceConfig_.erase(iter); } + +void KeyAutoRepeat::RemoveTimer() +{ + CALL_DEBUG_ENTER; + TimerMgr->RemoveTimer(timerId_); +} } // namespace MMI } // namespace OHOS \ No newline at end of file diff --git a/service/event_handler/src/key_event_value_transformation.cpp b/service/event_handler/src/key_event_value_transformation.cpp index 52b7b3cbcf124d99e00c59950741f3f1fb4c2279..fb84fa1c37b1bb4a762260afd178991199ea2113 100644 --- a/service/event_handler/src/key_event_value_transformation.cpp +++ b/service/event_handler/src/key_event_value_transformation.cpp @@ -459,5 +459,58 @@ int32_t InputTransformationKeyValue(int32_t keyCode) } return INVALID_KEY_CODE; } + +namespace { +const std::map MAP_KEY_INTENTION = { + {(int64_t)KeyEvent::KEYCODE_DPAD_UP, KeyEvent::INTENTION_UP}, + {(int64_t)KeyEvent::KEYCODE_DPAD_DOWN, KeyEvent::INTENTION_DOWN}, + {(int64_t)KeyEvent::KEYCODE_DPAD_LEFT, KeyEvent::INTENTION_LEFT}, + {(int64_t)KeyEvent::KEYCODE_DPAD_RIGHT, KeyEvent::INTENTION_RIGHT}, + {(int64_t)KeyEvent::KEYCODE_SPACE, KeyEvent::INTENTION_SELECT}, + {(int64_t)KeyEvent::KEYCODE_NUMPAD_ENTER, KeyEvent::INTENTION_SELECT}, + {(int64_t)KeyEvent::KEYCODE_ESCAPE, KeyEvent::INTENTION_ESCAPE}, + {((int64_t)KeyEvent::KEYCODE_ALT_LEFT << 16) + KeyEvent::KEYCODE_DPAD_LEFT, KeyEvent::INTENTION_BACK}, + {((int64_t)KeyEvent::KEYCODE_ALT_LEFT << 16) + KeyEvent::KEYCODE_DPAD_RIGHT, KeyEvent::INTENTION_FORWARD}, + {((int64_t)KeyEvent::KEYCODE_ALT_RIGHT << 16) + KeyEvent::KEYCODE_DPAD_LEFT, KeyEvent::INTENTION_BACK}, + {((int64_t)KeyEvent::KEYCODE_ALT_RIGHT << 16) + KeyEvent::KEYCODE_DPAD_RIGHT, KeyEvent::INTENTION_FORWARD}, + {((int64_t)KeyEvent::KEYCODE_SHIFT_LEFT << 16) + KeyEvent::KEYCODE_F10, KeyEvent::INTENTION_MENU}, + {((int64_t)KeyEvent::KEYCODE_SHIFT_RIGHT << 16) + KeyEvent::KEYCODE_F10, KeyEvent::INTENTION_MENU}, + {(int64_t)KeyEvent::KEYCODE_COMPOSE, KeyEvent::INTENTION_MENU}, + {(int64_t)KeyEvent::KEYCODE_PAGE_UP, KeyEvent::INTENTION_PAGE_UP}, + {(int64_t)KeyEvent::KEYCODE_PAGE_DOWN, KeyEvent::INTENTION_PAGE_DOWN}, + {((int64_t)KeyEvent::KEYCODE_CTRL_LEFT << 16) + KeyEvent::KEYCODE_PLUS, KeyEvent::INTENTION_ZOOM_OUT}, + {((int64_t)KeyEvent::KEYCODE_CTRL_RIGHT << 16) + KeyEvent::KEYCODE_PLUS, KeyEvent::INTENTION_ZOOM_OUT}, + {((int64_t)KeyEvent::KEYCODE_CTRL_LEFT << 16) + KeyEvent::KEYCODE_NUMPAD_ADD, KeyEvent::INTENTION_ZOOM_OUT}, + {((int64_t)KeyEvent::KEYCODE_CTRL_RIGHT << 16) + KeyEvent::KEYCODE_NUMPAD_ADD, KeyEvent::INTENTION_ZOOM_OUT}, + {((int64_t)KeyEvent::KEYCODE_CTRL_LEFT << 16) + KeyEvent::KEYCODE_MINUS, KeyEvent::INTENTION_ZOOM_IN}, + {((int64_t)KeyEvent::KEYCODE_CTRL_RIGHT << 16) + KeyEvent::KEYCODE_MINUS, KeyEvent::INTENTION_ZOOM_IN}, + {((int64_t)KeyEvent::KEYCODE_CTRL_LEFT << 16) + KeyEvent::KEYCODE_NUMPAD_SUBTRACT, KeyEvent::INTENTION_ZOOM_IN}, + {((int64_t)KeyEvent::KEYCODE_CTRL_RIGHT << 16) + KeyEvent::KEYCODE_NUMPAD_SUBTRACT, KeyEvent::INTENTION_ZOOM_IN}, + {(int64_t)KeyEvent::KEYCODE_VOLUME_MUTE, KeyEvent::INTENTION_MEDIA_MUTE}, + {(int64_t)KeyEvent::KEYCODE_MUTE, KeyEvent::INTENTION_MEDIA_MUTE}, + {(int64_t)KeyEvent::KEYCODE_VOLUME_UP, KeyEvent::INTENTION_VOLUTE_UP}, + {(int64_t)KeyEvent::KEYCODE_VOLUME_DOWN, KeyEvent::INTENTION_VOLUTE_DOWN}, + {(int64_t)KeyEvent::KEYCODE_APPSELECT, KeyEvent::INTENTION_SELECT}, + {(int64_t)KeyEvent::KEYCODE_BACK, KeyEvent::INTENTION_BACK}, + {(int64_t)KeyEvent::KEYCODE_MOVE_HOME, KeyEvent::INTENTION_HOME}, +}; +} // namespace + +int32_t keyItemsTransKeyIntention(const std::vector &items) +{ + if (items.size() < 1 || items.size() > 3) { + return KeyEvent::INTENTION_UNKNOWN; + } + + int64_t keyCodes = 0; + for (const auto &item : items) { + keyCodes = (keyCodes << 16) + item.GetKeyCode(); + } + auto iter = MAP_KEY_INTENTION.find(keyCodes); + if (iter == MAP_KEY_INTENTION.end()) { + return KeyEvent::INTENTION_UNKNOWN; + } + return iter->second; +} } // namespace MMI } // namespace OHOS \ No newline at end of file diff --git a/service/event_handler/src/key_map_manager.cpp b/service/event_handler/src/key_map_manager.cpp index 267557475860d9a5f22336ca98ea9e9b073a1816..985166849346f082ecbdb57216974120effb6115 100644 --- a/service/event_handler/src/key_map_manager.cpp +++ b/service/event_handler/src/key_map_manager.cpp @@ -57,7 +57,7 @@ void KeyMapManager::RemoveKeyValue(struct libinput_device *device) int32_t deviceId = InputDevMgr->FindInputDeviceId(device); auto iter = configKeyValue_.find(deviceId); if (iter == configKeyValue_.end()) { - MMI_HILOGE("Device config file does not exist"); + MMI_HILOGI("Device config file does not exist"); return; } configKeyValue_.erase(iter); diff --git a/service/filter/BUILD.gn b/service/filter/BUILD.gn index 6d7e23e5f3cfe2eeff396eb8fbe8352223592d0a..6cce741deae2b35088f1b833fcd04d423e945600 100644 --- a/service/filter/BUILD.gn +++ b/service/filter/BUILD.gn @@ -19,8 +19,12 @@ config("mmi_event_filter_config") { include_dirs = [ "//foundation/multimodalinput/input/interfaces/native/innerkits/common/include", "//foundation/multimodalinput/input/interfaces/native/innerkits/event/include", + "//foundation/multimodalinput/input/service/device_config/include", "//foundation/multimodalinput/input/service/event_handler/include", + "//foundation/multimodalinput/input/service/device_manager/include", "//foundation/multimodalinput/input/util/common/include", + "//foundation/multimodalinput/input/util/network/include", + "//foundation/multimodalinput/input/util/socket/include", "${event_filter_path}/include", ] } @@ -29,7 +33,6 @@ ohos_source_set("mmi_event_filter_service") { part_name = "input" subsystem_name = "multimodalinput" sources = [ - "${event_filter_path}/src/event_filter_parcel.cpp", "${event_filter_path}/src/event_filter_service.cpp", "${event_filter_path}/src/event_filter_stub.cpp", ] @@ -38,7 +41,7 @@ ohos_source_set("mmi_event_filter_service") { external_deps = [ "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", + "ipc:ipc_single", "safwk:system_ability_fwk", ] } @@ -49,30 +52,16 @@ ohos_source_set("mmi_event_filter_proxy") { sources = [ "${event_filter_path}/src/event_filter_death_recipient.cpp", "${event_filter_path}/src/event_filter_handler.cpp", - "${event_filter_path}/src/event_filter_parcel.cpp", "${event_filter_path}/src/event_filter_proxy.cpp", ] configs = [ ":mmi_event_filter_config" ] - defines = [] - - if (input_feature_keyboard) { - defines += [ "OHOS_BUILD_ENABLE_KEYBOARD" ] - } - if (input_feature_touchscreen) { - defines += [ "OHOS_BUILD_ENABLE_TOUCH" ] - } - if (input_feature_mouse) { - defines += [ "OHOS_BUILD_ENABLE_POINTER" ] - } - if (input_feature_touchscreen) { - defines += [ "OHOS_BUILD_ENABLE_TOUCH" ] - } + defines = input_default_defines external_deps = [ "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", + "ipc:ipc_single", "safwk:system_ability_fwk", ] } diff --git a/service/filter/include/event_filter_death_recipient.h b/service/filter/include/event_filter_death_recipient.h index 9f37e958913be4aee591f70bfc910843dd218ff3..45ae94c80f6ce240dc1ce30cfa593ad1ce973877 100644 --- a/service/filter/include/event_filter_death_recipient.h +++ b/service/filter/include/event_filter_death_recipient.h @@ -21,12 +21,12 @@ namespace OHOS { namespace MMI { -class EventFilterDeathRecipient : public IRemoteObject::DeathRecipient { +class EventFilterDeathRecipient final : public IRemoteObject::DeathRecipient { public: explicit EventFilterDeathRecipient(const std::function &object)> &deathCallback); DISALLOW_COPY_AND_MOVE(EventFilterDeathRecipient); - virtual ~EventFilterDeathRecipient() = default; + ~EventFilterDeathRecipient() override = default; void OnRemoteDied(const wptr &object) override; private: diff --git a/service/filter/include/event_filter_handler.h b/service/filter/include/event_filter_handler.h index fcb8b10a6258eccae60214feafe5dc7f238ad749..527742e05200053af17e0395a1ebe35bf1fae4b9 100644 --- a/service/filter/include/event_filter_handler.h +++ b/service/filter/include/event_filter_handler.h @@ -16,19 +16,23 @@ #ifndef EVENT_FILTER_HANDLER_H #define EVENT_FILTER_HANDLER_H +#include #include +#include + #include "nocopyable.h" +#include "event_filter_death_recipient.h" #include "i_event_filter.h" #include "i_input_event_handler.h" namespace OHOS { namespace MMI { -class EventFilterHandler : public IInputEventHandler { +class EventFilterHandler final : public IInputEventHandler, public std::enable_shared_from_this { public: - EventFilterHandler(); + EventFilterHandler() = default; DISALLOW_COPY_AND_MOVE(EventFilterHandler); - ~EventFilterHandler(); + ~EventFilterHandler() override = default; #ifdef OHOS_BUILD_ENABLE_KEYBOARD void HandleKeyEvent(const std::shared_ptr keyEvent) override; #endif // OHOS_BUILD_ENABLE_KEYBOARD @@ -38,11 +42,25 @@ public: #ifdef OHOS_BUILD_ENABLE_TOUCH void HandleTouchEvent(const std::shared_ptr pointerEvent) override; #endif // OHOS_BUILD_ENABLE_TOUCH - int32_t AddInputEventFilter(sptr filter); - bool HandlePointerEventFilter(std::shared_ptr point); + int32_t AddInputEventFilter(sptr filter, int32_t filterId, int32_t priority, uint32_t deviceTags, + int32_t clientPid); + int32_t RemoveInputEventFilter(int32_t filterId, int32_t clientPid); + void Dump(int32_t fd, const std::vector &args); + bool HandleKeyEventFilter(std::shared_ptr event); + bool HandlePointerEventFilter(std::shared_ptr event); private: std::mutex lockFilter_; - sptr filter_ {nullptr}; + struct FilterInfo + { + const sptr filter; + sptr deathRecipient { nullptr }; + const int32_t filterId; + const int32_t priority; + const uint32_t deviceTags; + const int32_t clientPid; + bool IsSameClient(int32_t id, int32_t pid) const { return ((filterId == id) && (clientPid == pid)); } + }; + std::list filters_; }; } // namespace MMI } // namespace OHOS diff --git a/service/filter/include/event_filter_proxy.h b/service/filter/include/event_filter_proxy.h index f547440f1e6994e0ea4fa63544a18aa702f347a9..0f4308ae566c88260210456313ab1a99019309be 100644 --- a/service/filter/include/event_filter_proxy.h +++ b/service/filter/include/event_filter_proxy.h @@ -16,8 +16,8 @@ #ifndef EVENT_FILTER_PROXY_H #define EVENT_FILTER_PROXY_H -#include "iremote_proxy.h" #include "iremote_object.h" +#include "iremote_proxy.h" #include "nocopyable.h" #include "i_event_filter.h" @@ -28,8 +28,9 @@ class EventFilterProxy final : public IRemoteProxy { public: explicit EventFilterProxy(const sptr &impl); DISALLOW_COPY_AND_MOVE(EventFilterProxy); - virtual ~EventFilterProxy() override; - virtual bool HandlePointerEvent(const std::shared_ptr event) override; + ~EventFilterProxy() override = default; + bool HandleKeyEvent(const std::shared_ptr event) override; + bool HandlePointerEvent(const std::shared_ptr event) override; private: static inline BrokerDelegator delegator_; }; diff --git a/service/filter/include/event_filter_service.h b/service/filter/include/event_filter_service.h index 7dd1bac8d49fbff2087c65504107d65e12930fe6..3afad862196896d29e2643f184a1f8e6f32f0df2 100644 --- a/service/filter/include/event_filter_service.h +++ b/service/filter/include/event_filter_service.h @@ -16,25 +16,28 @@ #ifndef EVENT_FILTER_SERVICE_H #define EVENT_FILTER_SERVICE_H +#include + #include "iremote_object.h" #include "nocopyable.h" +#include "i_input_event_filter.h" #include "event_filter_stub.h" - namespace OHOS { namespace MMI { enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING }; class EventFilterService final : public EventFilterStub { public: - EventFilterService(); + static int32_t GetNextId(); + EventFilterService(std::shared_ptr filter) : filter_(filter) {} DISALLOW_COPY_AND_MOVE(EventFilterService); - ~EventFilterService(); - virtual bool HandlePointerEvent(const std::shared_ptr event) override; - void SetPointerEventPtr(std::function)> pointerFilter); - + ~EventFilterService() override = default; + bool HandleKeyEvent(const std::shared_ptr event) override; + bool HandlePointerEvent(const std::shared_ptr event) override; private: - std::function)> pointerFilter_ { nullptr }; + const std::shared_ptr filter_; + static inline int32_t filterIdSeed_ = 0; }; } // namespace MMI } // namespace OHOS diff --git a/service/filter/include/event_filter_stub.h b/service/filter/include/event_filter_stub.h index b75f436bb4ed4f3c06b2a46e040cc6843808a45f..4ed4584953455b23fbffabb0a1a41d159e1b33f6 100644 --- a/service/filter/include/event_filter_stub.h +++ b/service/filter/include/event_filter_stub.h @@ -32,6 +32,7 @@ public: virtual ~EventFilterStub() = default; int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& options) override; protected: + int32_t StubHandleKeyEvent(MessageParcel& data, MessageParcel& reply); int32_t StubHandlePointerEvent(MessageParcel& data, MessageParcel& reply); }; } // namespace MMI diff --git a/service/filter/include/i_event_filter.h b/service/filter/include/i_event_filter.h index 123c66cc5b47e6e9219a2fc47db7730e36dde37a..306f82f377828337f1d0148c31d7b26126499362 100644 --- a/service/filter/include/i_event_filter.h +++ b/service/filter/include/i_event_filter.h @@ -18,6 +18,8 @@ #include "iremote_broker.h" +#include "i_input_event_filter.h" +#include "key_event.h" #include "pointer_event.h" namespace OHOS { @@ -25,10 +27,11 @@ namespace MMI { class IEventFilter : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"ohos.multimodalinput.IEventFilter"); + virtual bool HandleKeyEvent(const std::shared_ptr event) = 0; virtual bool HandlePointerEvent(const std::shared_ptr event) = 0; - enum class OPERATOR_TYPE { - HANDLE_POINTER_EVENT = 0, + HANDLE_KEY_EVENT = 0, + HANDLE_POINTER_EVENT = 1, }; }; } // namespace MMI diff --git a/service/filter/src/event_filter_handler.cpp b/service/filter/src/event_filter_handler.cpp index 7dee1d024e79a273f7613d2afa4c988bcaf0cb07..b42eb397b16724d2dd5c4f39ca4f38f92d4a46ac 100644 --- a/service/filter/src/event_filter_handler.cpp +++ b/service/filter/src/event_filter_handler.cpp @@ -16,6 +16,7 @@ #include "event_filter_handler.h" #include "error_multimodal.h" +#include "input_device_manager.h" #include "mmi_log.h" namespace OHOS { @@ -24,20 +25,15 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "EventFilterHandler" }; } // namespace -EventFilterHandler::EventFilterHandler() -{ - CALL_DEBUG_ENTER; -} - -EventFilterHandler::~EventFilterHandler() -{ - CALL_DEBUG_ENTER; -} #ifdef OHOS_BUILD_ENABLE_KEYBOARD void EventFilterHandler::HandleKeyEvent(const std::shared_ptr keyEvent) { CALL_DEBUG_ENTER; CHKPV(keyEvent); + if (HandleKeyEventFilter(keyEvent)) { + MMI_HILOGD("Key event is filtered"); + return; + } CHKPV(nextHandler_); nextHandler_->HandleKeyEvent(keyEvent); } @@ -48,7 +44,7 @@ void EventFilterHandler::HandlePointerEvent(const std::shared_ptr { CHKPV(pointerEvent); if (HandlePointerEventFilter(pointerEvent)) { - MMI_HILOGI("Pointer event Filter succeeded"); + MMI_HILOGD("Pointer event is filtered"); return; } CHKPV(nextHandler_); @@ -61,7 +57,7 @@ void EventFilterHandler::HandleTouchEvent(const std::shared_ptr po { CHKPV(pointerEvent); if (HandlePointerEventFilter(pointerEvent)) { - MMI_HILOGI("Pointer event Filter succeeded"); + MMI_HILOGD("Touch event is filtered"); return; } CHKPV(nextHandler_); @@ -69,23 +65,144 @@ void EventFilterHandler::HandleTouchEvent(const std::shared_ptr po } #endif // OHOS_BUILD_ENABLE_TOUCH -int32_t EventFilterHandler::AddInputEventFilter(sptr filter) +int32_t EventFilterHandler::AddInputEventFilter(sptr filter, + int32_t filterId, int32_t priority, uint32_t deviceTags, int32_t clientPid) { CALL_INFO_TRACE; std::lock_guard guard(lockFilter_); - filter_ = filter; + CHKPR(filter, ERROR_NULL_POINTER); + MMI_HILOGI("Add filter,filterId:%{public}d,priority:%{public}d,clientPid:%{public}d,filters_ size:%{public}zu", + filterId, priority, clientPid, filters_.size()); + + std::weak_ptr weakPtr = shared_from_this(); + auto deathCallback = [weakPtr, filterId, clientPid](const wptr &object) { + auto sharedPtr = weakPtr.lock(); + if (sharedPtr != nullptr) { + auto ret = sharedPtr->RemoveInputEventFilter(filterId, clientPid); + if (ret != RET_OK) { + MMI_HILOGW("Remove filter on dead return:%{public}d, filterId:%{public}d,clientPid:%{public}d", + ret, filterId, clientPid); + } else { + MMI_HILOGW("Remove filter on dead success, filterId:%{public}d,clientPid:%{public}d", + filterId, clientPid); + } + } + }; + sptr deathRecipient = new (std::nothrow) EventFilterDeathRecipient(deathCallback); + CHKPR(deathRecipient, RET_ERR); + filter->AsObject()->AddDeathRecipient(deathRecipient); + + FilterInfo info { .filter = filter, .deathRecipient = deathRecipient, .filterId = filterId, + .priority = priority, .deviceTags = deviceTags, .clientPid = clientPid }; + auto it = filters_.cbegin(); + for (; it != filters_.cend(); ++it) { + if (info.priority < it->priority) { + break; + } + } + auto it2 = filters_.emplace(it, std::move(info)); + if (it2 == filters_.end()) { + MMI_HILOGE("Fail to add filter"); + return ERROR_FILTER_ADD_FAIL; + } + return RET_OK; +} + +int32_t EventFilterHandler::RemoveInputEventFilter(int32_t filterId, int32_t clientPid) +{ + CALL_INFO_TRACE; + std::lock_guard guard(lockFilter_); + if (filters_.empty()) { + MMI_HILOGI("Filter is empty"); + return RET_OK; + } + for (auto it = filters_.begin(); it != filters_.end();) { + if (filterId == -1) { + if (it->clientPid == clientPid) { + auto id = it->filterId; + filters_.erase(it++); + MMI_HILOGI("Filter remove success, filterId:%{public}d,clientPid:%{public}d", id, clientPid); + continue; + } + ++it; + continue; + } + if (it->IsSameClient(filterId, clientPid)) { + filters_.erase(it++); + MMI_HILOGI("Filter remove success, filterId:%{public}d,clientPid:%{public}d", filterId, clientPid); + return RET_OK; + } + ++it; + } + if (filterId == -1) { + return RET_OK; + } + MMI_HILOGI("Filter not found, filterId:%{public}d,clientPid:%{public}d", filterId, clientPid); return RET_OK; } -bool EventFilterHandler::HandlePointerEventFilter(std::shared_ptr point) +void EventFilterHandler::Dump(int32_t fd, const std::vector &args) +{ + CALL_DEBUG_ENTER; + std::lock_guard guard(lockFilter_); + dprintf(fd, "Filter information:\n"); + dprintf(fd, "Filters: count=%d\n", filters_.size()); + for (const auto &item : filters_) { + dprintf(fd, "priority:%d | filterId:%d | Pid:%d\n", item.priority, item.filterId, item.clientPid); + } +} + +bool EventFilterHandler::HandleKeyEventFilter(std::shared_ptr event) +{ + CALL_DEBUG_ENTER; + CHKPF(event); + std::lock_guard guard(lockFilter_); + if (filters_.empty()) { + return false; + } + std::vector keyItems = event->GetKeyItems(); + if (keyItems.empty()) { + MMI_HILOGE("keyItems is empty"); + return false; + } + std::shared_ptr inputDevice = InputDevMgr->GetInputDevice(keyItems.front().GetDeviceId()); + CHKPF(inputDevice); + for (auto &i: filters_) { + if (!inputDevice->HasCapability(i.deviceTags)) { + continue; + } + if (i.filter->HandleKeyEvent(event)) { + MMI_HILOGD("Call HandleKeyEventFilter return true"); + return true; + } + } + return false; +} + +bool EventFilterHandler::HandlePointerEventFilter(std::shared_ptr event) { CALL_DEBUG_ENTER; - CHKPF(point); + CHKPF(event); std::lock_guard guard(lockFilter_); - CHKPF(filter_); - if (filter_->HandlePointerEvent(point)) { - MMI_HILOGD("Call HandlePointerEvent return true"); - return true; + if (filters_.empty()) { + return false; + } + PointerEvent::PointerItem pointerItem; + int32_t pointerId = event->GetPointerId(); + if (!event->GetPointerItem(pointerId, pointerItem)) { + MMI_HILOGE("GetPointerItem:%{public}d fail", pointerId); + return false; + } + std::shared_ptr inputDevice = InputDevMgr->GetInputDevice(pointerItem.GetDeviceId()); + CHKPF(inputDevice); + for (auto &i: filters_) { + if (!inputDevice->HasCapability(i.deviceTags)) { + continue; + } + if (i.filter->HandlePointerEvent(event)) { + MMI_HILOGD("Call HandlePointerEvent return true"); + return true; + } } return false; } diff --git a/service/filter/src/event_filter_proxy.cpp b/service/filter/src/event_filter_proxy.cpp index 0cf9b0865be2ca783ad32710d2f86af7e06fc0fb..415f54dfd47217f52660e8a4b745c2078127c85a 100644 --- a/service/filter/src/event_filter_proxy.cpp +++ b/service/filter/src/event_filter_proxy.cpp @@ -18,7 +18,6 @@ #include "message_option.h" #include "string_ex.h" -#include "event_filter_parcel.h" #include "mmi_log.h" namespace OHOS { @@ -32,9 +31,35 @@ EventFilterProxy::EventFilterProxy(const sptr &impl) : IRemotePro MMI_HILOGI("EventFilterProxy()"); } -EventFilterProxy::~EventFilterProxy() +bool EventFilterProxy::HandleKeyEvent(const std::shared_ptr event) { - MMI_HILOGI("~EventFilterProxy()"); + CALL_DEBUG_ENTER; + CHKPF(event); + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(EventFilterProxy::GetDescriptor())) { + MMI_HILOGE("Failed to write descriptor"); + return false; + } + + if (!event->WriteToParcel(data)) { + MMI_HILOGE("Failed to write event to req"); + return false; + } + + sptr remote = Remote(); + CHKPF(remote); + const uint32_t code = static_cast(OPERATOR_TYPE::HANDLE_KEY_EVENT); + int32_t ret = remote->SendRequest(code, data, reply, option); + if (ret != NO_ERROR) { + MMI_HILOGE("Send request failed, ret:%{public}d", ret); + return false; + } + + bool result = false; + READBOOL(reply, result); + return result; } bool EventFilterProxy::HandlePointerEvent(const std::shared_ptr event) diff --git a/service/filter/src/event_filter_service.cpp b/service/filter/src/event_filter_service.cpp index eedf8202f64944b19a1bd46db20f5d75472b00eb..7aa6cfb53100441fa782574e707f46f022aa3667 100644 --- a/service/filter/src/event_filter_service.cpp +++ b/service/filter/src/event_filter_service.cpp @@ -30,25 +30,30 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "EventFilterService" }; } // namespace -EventFilterService::EventFilterService() +int32_t EventFilterService::GetNextId() { - CALL_DEBUG_ENTER; + if (filterIdSeed_ == std::numeric_limits::max()) { + filterIdSeed_ = 0; + } + return filterIdSeed_++; } -EventFilterService::~EventFilterService() +bool EventFilterService::HandleKeyEvent(const std::shared_ptr event) { - CALL_DEBUG_ENTER; -} - -void EventFilterService::SetPointerEventPtr(std::function)> pointerFilter) -{ - pointerFilter_ = pointerFilter; + if (filter_ == nullptr) { + MMI_HILOGE("Filter is nullptr"); + return false; + } + return filter_->OnInputEvent(event); } bool EventFilterService::HandlePointerEvent(const std::shared_ptr event) { - CHKPF(pointerFilter_); - return pointerFilter_(event); + if (filter_ == nullptr) { + MMI_HILOGE("Filter is nullptr"); + return false; + } + return filter_->OnInputEvent(event); } } // namespace MMI } // namespace OHOS diff --git a/service/filter/src/event_filter_stub.cpp b/service/filter/src/event_filter_stub.cpp index 6c971035e7af215eb0e51e22fff75ecdcd6d7640..1a958282eb30773ba225d5954b7cdac1109194a3 100644 --- a/service/filter/src/event_filter_stub.cpp +++ b/service/filter/src/event_filter_stub.cpp @@ -21,7 +21,6 @@ #include "ipc_skeleton.h" #include "string_ex.h" -#include "event_filter_parcel.h" #include "mmi_log.h" namespace OHOS { @@ -43,16 +42,38 @@ int32_t EventFilterStub::OnRemoteRequest( } switch (code) { + case static_cast(IEventFilter::OPERATOR_TYPE::HANDLE_KEY_EVENT): { + return StubHandleKeyEvent(data, reply); + } case static_cast(IEventFilter::OPERATOR_TYPE::HANDLE_POINTER_EVENT): { return StubHandlePointerEvent(data, reply); } default: { - MMI_HILOGE("Unknown code:%{public}u, go switch defaut", code); + MMI_HILOGE("Unknown code:%{public}u, go switch default", code); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } } } +int32_t EventFilterStub::StubHandleKeyEvent(MessageParcel& data, MessageParcel& reply) +{ + CALL_DEBUG_ENTER; + std::shared_ptr event = KeyEvent::Create(); + if (event == nullptr) { + MMI_HILOGE("The event is nullptr"); + return RET_ERR; + } + + if (!event->ReadFromParcel(data)) { + MMI_HILOGE("Read data error"); + return RET_ERR; + } + + bool ret = HandleKeyEvent(event); + WRITEBOOL(reply, ret, RET_ERR); + return RET_OK; +} + int32_t EventFilterStub::StubHandlePointerEvent(MessageParcel& data, MessageParcel& reply) { CALL_DEBUG_ENTER; diff --git a/service/hdf_adapter/include/hdf_event_manager.h b/service/hdf_adapter/include/hdf_event_manager.h deleted file mode 100644 index c37c78295e9bca28f166e7dba6fdb25684d8343e..0000000000000000000000000000000000000000 --- a/service/hdf_adapter/include/hdf_event_manager.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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 HDF_EVENT_MANAGER_H -#define HDF_EVENT_MANAGER_H - -#include -#include -#include -#include - -#include "evdev.h" -#include "input_type.h" -#include "libinput.h" -#include "nocopyable.h" - -#include "input_manager.h" -#include "libinput_adapter.h" - -#define MAX_INPUT_DEVICE_COUNT MAX_INPUT_DEV_NUM -#define TOTAL_INPUT_DEVICE_COUNT (2 * MAX_INPUT_DEV_NUM) -#define TOTAL_INPUT_DEVICE_STATUS_COUNT (TOTAL_INPUT_DEVICE_COUNT + 1) -#define IOCTL_CMD_MASK (0x3fff) -#define IOCTL_CMD_SHIFT (16) -#define USEC_PER_SEC (1000000) -#define MAX_EVENT_PKG_NUM (256) - -namespace OHOS { -namespace MMI { -enum hdf_event_type { - HDF_NONE = 0, - HDF_EVENT, - HDF_ADD_DEVICE, - HDF_RMV_DEVICE, -}; -struct Devcmd { - int32_t index { 0 }; - int32_t cmd { 0 }; -}; -class HdfEventManager { -public: - static int32_t EvdevSimIoctl(int32_t hdindex, int32_t pcmd, void *iobuff); - static int32_t EvdevIoctl(int32_t hdiindex, int32_t pcmd, void *iobuff); - static void HotPlugCallback(const HotPlugEvent *event); - static void GetEventCallback(const KeyEventNormalize **pkgs, uint32_t count, uint32_t devIndex); - static int32_t DeviceAddHandle(uint32_t devIndex, uint32_t devType); - static int32_t DeviceRemoveHandle(uint32_t devIndex, uint32_t devType); - static libinput *HdfLibinputInit(); - static int32_t HdfDevHandle(int32_t index, hdf_event_type cmd); - HdfEventManager(); - DISALLOW_COPY_AND_MOVE(HdfEventManager); - virtual ~HdfEventManager(); - bool Init(); - void SetupCallback(); - bool OpenHdfDevice(uint32_t devIndex, bool oper); - int32_t GetDeviceCount(); - int32_t GetJectDeviceCount(); - void AddDevice(uint32_t devIndex, uint32_t typeIndex); - int32_t HdfdevtypeMapLibinputType(uint32_t devIndex, uint32_t devType); -private: - static HdfEventManager *globleThis_; - libinput *hdiinput_ { nullptr }; - std::list hdflist_; - bool devStatus[TOTAL_INPUT_DEVICE_STATUS_COUNT] { false }; - DevDesc mountDevIndex_[TOTAL_INPUT_DEVICE_COUNT]; - IInputInterface *inputInterface_ { nullptr }; - IInputInterface *injectInterface_ { nullptr }; - InputEventCb eventCallBack_; - InputHostCb hostPlugCallBack_; -}; - -extern HdfEventManager hdfEventManager; -} // namespace MMI -} // namespace OHOS -#endif // HDF_EVENT_MANAGER_H \ No newline at end of file diff --git a/service/hdf_adapter/include/lib_hdf.h b/service/hdf_adapter/include/lib_hdf.h deleted file mode 100644 index 668d22d85fa5b9133ee0dd2c2e3718a6b8647d7e..0000000000000000000000000000000000000000 --- a/service/hdf_adapter/include/lib_hdf.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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 LIB_HDF_H -#define LIB_HDF_H -extern int32_t GetInputInterfaceFromInject(IInputInterface** interface); -#define hdfbit(y_) (1UL << (y_)) - -enum hdf_device_tags { - HDF_INPUT = hdfbit(0), - HDF_KEYBOARD = hdfbit(1), - HDF_MOUSE = hdfbit(2), - HDF_TOUCHPAD = hdfbit(3), - HDF_TOUCHSCREEN = hdfbit(4), - HDF_TABLET = hdfbit(5), - HDF_JOYSTICK = hdfbit(6), - HDF_ACCELEROMETER = hdfbit(7), - HDF_TABLET_PAD = hdfbit(8), - HDF_POINTINGSTICK = hdfbit(9), - HDF_TRACKBALL = hdfbit(10), - HDF_SWITCH = hdfbit(11), -}; - -enum io_ctl_cmd { - IO_BITS = 0x20, - IO_KEYBITS = 0x21, - IO_RELBITS = 0x22, - IO_ABSBITS = 0x23, - IO_MSCBITS = 0x24, - IO_SWBITS = 0x25, - IO_LEDBITS = 0x31, - IO_SNDBITS = 0x32, - IO_FFBITS = 0x35, - IO_PROPBITS = 0x9, - IO_KEYVALUES = 0x18, - IO_LEDVALUES = 0x19, - IO_SWVALUES = 0x1b, - IO_NAMES = 0x6, - IO_MTVABS = 0xa, - IO_IDS = 0x2, - IO_ABSBEGIN = 0x40, - IO_ABEND = 0x80, -}; -#endif // LIB_HDF_H \ No newline at end of file diff --git a/service/hdf_adapter/src/hdf_event_manager.cpp b/service/hdf_adapter/src/hdf_event_manager.cpp deleted file mode 100644 index ae80e9029e129113499dbd41aa5cb0eabc00a925..0000000000000000000000000000000000000000 --- a/service/hdf_adapter/src/hdf_event_manager.cpp +++ /dev/null @@ -1,546 +0,0 @@ -/* - * 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 "hdf_event_manager.h" - -#include -#include -#include - -#include -#include - -#include "hdf_inject_init.cpp" -#include "lib_hdf.h" -#include "define_multimodal.h" -#include "mmi_log.h" -#include "util.h" - -namespace OHOS { -namespace MMI { -namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "HdfEventManager"}; -} // namespace - -HdfEventManager *HdfEventManager::m_globleThis; -int32_t HdfEventManager::EvdevSimIoctl(int32_t hdindex, int32_t pcmd, void *iobuff) -{ - const int32_t size = (pcmd >> IOCTL_CMD_SHIFT) & IOCTL_CMD_MASK; - int32_t cmd = pcmd & 0xff; - - MMI_HILOGD("evdev_simioctl index:%{public}d,cmd:%{public}02x,size:%{public}d," - "pcmd:%{public}04x", hdindex, cmd, size, pcmd); - DrvType drvtype = g_index2DrvType[hdindex - MAX_INPUT_DEVICE_COUNT]; - MMI_HILOGD("evdev_simioctl drvtype:%{public}d", drvtype); - if (drvtype >= INVALD) { - MMI_HILOGE("Unknown device type"); - return 0; - } - for (const auto &item : m_globleThis->hdflist_) { - if (item.index == hdindex) { - break; - } - } - const int32_t iobuffSize = size; - errno_t ret = 0; - switch (cmd) { - case IO_BITS: { - ret = memcpy_s(iobuff, iobuffSize, &g_arrayBits[drvtype], size); - break; - } - case IO_KEYBITS: { - ret = memcpy_s(iobuff, iobuffSize, &g_arrayKeyBits[drvtype], size); - break; - } - case IO_RELBITS: { - ret = memcpy_s(iobuff, iobuffSize, &g_arrayRelBits[drvtype], size); - break; - } - case IO_ABSBITS: { - ret = memcpy_s(iobuff, iobuffSize, &g_arrayAbsBits[drvtype], size); - break; - } - case IO_MSCBITS: { - ret = memcpy_s(iobuff, iobuffSize, &g_arrayMscBits[drvtype], size); - break; - } - case IO_SWBITS: { - ret = memcpy_s(iobuff, iobuffSize, &g_arraySwBits[drvtype], size); - break; - } - case IO_LEDBITS: { - ret = memcpy_s(iobuff, iobuffSize, &g_arrayLedBits[drvtype], size); - break; - } - case IO_SNDBITS: { - ret = memcpy_s(iobuff, iobuffSize, &g_arraySndBits[drvtype], size); - break; - } - case IO_PROPBITS: { - ret = memcpy_s(iobuff, iobuffSize, &g_arrayPropsBits[drvtype], size); - break; - } - case IO_KEYVALUES: { - ret = memcpy_s(iobuff, iobuffSize, &g_arrayKeyValues[drvtype], size); - break; - } - case IO_LEDVALUES: { - ret = memcpy_s(iobuff, iobuffSize, &g_arrayLedValues[drvtype], size); - break; - } - case IO_SWVALUES: { - ret = memcpy_s(iobuff, iobuffSize, &g_arraySwValues[drvtype], size); - break; - } - case IO_MTVABS: { - break; - } - case IO_IDS: { - ret = memcpy_s(iobuff, iobuffSize, &g_arrayIds[drvtype], size); - break; - } - case IO_FFBITS: { - ret = memcpy_s(iobuff, iobuffSize, &g_arrayFfBits[drvtype], size); - break; - } - default: { - if (cmd >= IO_ABSBEGIN && cmd < IO_ABEND) { - ret = memcpy_s(iobuff, iobuffSize, &g_arrayAxisInfo[drvtype][cmd - IO_ABSBEGIN], size); - } - break; - } - } - if (ret != EOK) { - MMI_HILOGE("Call memcpy_s failed, cmd = %d, ret = %d", cmd, ret); - } - return RET_OK; -} -int32_t HdfEventManager::EvdevIoctl(int32_t hdiindex, int32_t pcmd, void *iobuff) -{ - int32_t size = (pcmd >> IOCTL_CMD_SHIFT) & IOCTL_CMD_MASK; - int32_t cmd = pcmd & 0xff; - MMI_HILOGD("index:%{public}d,cmd:%{public}02x,size:%{public}d," - "pcmd:%{public}04x", hdiindex, cmd, size, pcmd); - DeviceInfo *deviceinfo = nullptr; - for (const auto &item : globleThis_->hdflist_) { - if (item.index == hdiindex) { - deviceinfo = static_cast(item->deviceinfo); - break; - } - } - if (deviceinfo == nullptr) { - MMI_HILOGE("Deviceinfo is null"); - return 0; - } - const int32_t iobuffSize = size; - errno_t ret = 0; - switch (cmd) { - case IO_BITS: { - ret = memcpy_s(iobuff, iobuffSize, deviceinfo->abilitySet.eventType, size); - break; - } - case IO_KEYBITS: { - ret = memcpy_s(iobuff, iobuffSize, deviceinfo->abilitySet.keyCode, size); - break; - } - case IO_RELBITS: { - ret = memcpy_s(iobuff, iobuffSize, deviceinfo->abilitySet.relCode, size); - break; - } - case IO_ABSBITS: { - ret = memcpy_s(iobuff, iobuffSize, deviceinfo->abilitySet.absCode, size); - break; - } - case IO_MSCBITS: { - ret = memcpy_s(iobuff, iobuffSize, deviceinfo->abilitySet.miscCode, size); - break; - } - case IO_SWBITS: { - ret = memcpy_s(iobuff, iobuffSize, deviceinfo->abilitySet.switchCode, size); - break; - } - case IO_LEDBITS: { - ret = memcpy_s(iobuff, iobuffSize, deviceinfo->abilitySet.ledCode, size); - break; - } - case IO_SNDBITS: { - ret = memcpy_s(iobuff, iobuffSize, deviceinfo->abilitySet.forceCode, size); - break; - } - case IO_PROPBITS: { - ret = memcpy_s(iobuff, iobuffSize, deviceinfo->abilitySet.devProp, size); - break; - } - case IO_KEYVALUES: { - ret = memcpy_s(iobuff, iobuffSize, deviceinfo->abilitySet.keyType, size); - break; - } - case IO_LEDVALUES: { - ret = memcpy_s(iobuff, iobuffSize, deviceinfo->abilitySet.ledType, size); - break; - } - case IO_SWVALUES: { - ret = memcpy_s(iobuff, iobuffSize, deviceinfo->abilitySet.switchType, size); - break; - } - case IO_MTVABS: { - break; - } - case IO_IDS: { - ret = memcpy_s(iobuff, iobuffSize, &deviceinfo->attrSet.id, size); - break; - } - case IO_FFBITS: { - ret = memcpy_s(iobuff, iobuffSize, &deviceinfo->abilitySet.forceCode, size); - break; - } - default: { - if (cmd >= IO_ABSBEGIN && cmd < IO_ABEND) { - ret = memcpy_s(iobuff, iobuffSize, &deviceinfo->attrSet.axisInfo[cmd - IO_ABSBEGIN], size); - } - break; - } - } - if (ret != EOK) { - MMI_HILOGE("Call memcpy_s failed, cmd = %d, ret = %d", cmd, ret); - } - return 0; -} - -HdfEventManager::HdfEventManager() -{ - globleThis_ = this; - hdiinput_ = nullptr; -} -HdfEventManager::~HdfEventManager() -{ - uint32_t ret = inputInterface_->iInputReporter->UnregisterHotPlugCallback(); - if (ret == INPUT_SUCCESS) { - MMI_HILOGI("%{public}s:%{public}d INPUT_SUCCESS", __func__, __LINE__); - } else { - MMI_HILOGE("%{public}s:%{public}d INPUT_ERROR", __func__, __LINE__); - } -} -int32_t HdfEventManager::HdfdevtypeMapLibinputType(uint32_t devIndex, uint32_t devType) -{ - if (devIndex >= MAX_INPUT_DEVICE_COUNT) { - MMI_HILOGE("The maximum number of devices exceeded, devIndex:%{public}d", devIndex); - return devType; - } - int32_t ret = 0; - switch (devType) { - case INDEV_TYPE_TOUCH: { - ret = HDF_INPUT | HDF_TOUCHSCREEN; - break; - } - case INDEV_TYPE_MOUSE: { - ret = HDF_INPUT | HDF_MOUSE; - break; - } - case INDEV_TYPE_KEYBOARD: { - ret = HDF_INPUT | HDF_KEYBOARD; - break; - } - default: { - ret = devType; - break; - } - } - return ret; -} -#ifdef OHOS_BUILD_HDF -int32_t HdfEventManager::GetDeviceCount() -{ - errno_t ret = memset_s(mountDevIndex_, sizeof(DevDesc) * TOTAL_INPUT_DEVICE_COUNT, 0, - sizeof(DevDesc) * TOTAL_INPUT_DEVICE_COUNT); - if (ret != EOK) { - MMI_HILOGE("Call memset_s failed. ret = %d", ret); - } - int32_t devcount = 0; - if (inputInterface_ != nullptr || inputInterface_->iInputManager != nullptr) { - int32_t ret = inputInterface_->iInputManager->ScanInputDevice(MAX_INPUT_DEVICE_COUNT, mountDevIndex_); - if (ret) { - MMI_HILOGE("%{public}s:%{public}d Error:ScanInputDevice failed", __func__, __LINE__); - return 0; - } - - for (int32_t i = 0; i < MAX_INPUT_DEVICE_COUNT; i++) { - if (mountDevIndex_[i].devIndex != 0) { - devcount = devcount + 1; - } - } - } - int32_t jectcount = 0; - if (injectInterface_ != nullptr || injectInterface_->iInputManager != nullptr) { - int32_t ret = injectInterface_->iInputManager->ScanInputDevice(MAX_INPUT_DEVICE_COUNT, - &mountDevIndex_[devcount]); - if (ret) { - MMI_HILOGE("%{public}s:%{public}d Error:injectInterface_ ScanInputDevice failed", - __func__, __LINE__); - return devcount; - } - - for (int32_t i = 0; i < MAX_INPUT_DEVICE_COUNT; i++) { - if (mountDevIndex_[devcount + i].devIndex != 0) { - jectcount = jectcount + 1; - } - } - } - return devcount + jectcount; -} -void HdfEventManager::SetupCallback() -{ - MMI_HILOGD("%{public}s:%{public}d ThreadSetupCallback start", __func__, __LINE__); - uint32_t ret = GetInputInterface(&inputInterface_); - if (ret != 0 || inputInterface_ == nullptr - || inputInterface_->iInputManager == nullptr - || inputInterface_->iInputReporter == nullptr) { - MMI_HILOGD("%{public}s:%{public}d inputInterface_ init failed", __func__, __LINE__); - } - - ret = GetInputInterfaceFromInject(&injectInterface_); - if (ret != 0 || injectInterface_ == nullptr - || injectInterface_->iInputManager == nullptr - || injectInterface_->iInputReporter == nullptr) { - MMI_HILOGD("%{public}s:%{public}d injectInterface_ init failed", __func__, __LINE__); - } - - eventCallBack_.EventPkgCallback = globleThis_->GetEventCallback; - hostPlugCallBack_.HotPlugCallback = globleThis_->HotPlugCallback; - if (inputInterface_) { - ret = inputInterface_->iInputReporter->RegisterHotPlugCallback(&hostPlugCallBack_); - if (ret == INPUT_SUCCESS) { - MMI_HILOGI("%{public}s:%{public}d RegisterHotPlugCallback INPUT_SUCCESS", __func__, __LINE__); - } else { - MMI_HILOGE("%{public}s:%{public}d RegisterHotPlugCallback INPUT_ERROR", __func__, __LINE__); - } - } - - if (injectInterface_) { - ret = injectInterface_->iInputReporter->RegisterHotPlugCallback(&hostPlugCallBack_); - if (ret == INPUT_SUCCESS) { - MMI_HILOGI("%{public}s:%{public}d injectInterface_ RegisterHotPlugCallback INPUT_SUCCESS", - __func__, __LINE__); - } else { - MMI_HILOGE("%{public}s:%{public}d injectInterface_ RegisterHotPlugCallback INPUT_ERROR", - __func__, __LINE__); - } - } - - int32_t count = GetDeviceCount(); - MMI_HILOGD("ThreadSetupCallback count:%{public}d", count); - for (int32_t i = 0; i < count; i++) { - DeviceAddHandle(mountDevIndex_[i].devIndex, mountDevIndex_[i].devType); - } -} - -void HdfEventManager::AddDevice(uint32_t devIndex, uint32_t devType) -{ - uint32_t ret = 0; - if (devIndex >= MAX_INPUT_DEVICE_COUNT) { - ret = injectInterface_->iInputReporter->RegisterReportCallback(devIndex, &eventCallBack_); - return; - } - if (!OpenHdfDevice(devIndex, true)) { - return; - } - ret = inputInterface_->iInputReporter->RegisterReportCallback(devIndex, &eventcallback); - if (ret == INPUT_SUCCESS) { - MMI_HILOGI("%{public}s:%{public}d RegisterReportCallback eventcallback INPUT_SUCCESS" - "devindex:%{public}u, devType:%{public}u", __func__, __LINE__, devIndex, devType); - } else { - MMI_HILOGE("%{public}s:%{public}d RegisterReportCallback eventcallback INPUT_ERROR" - "devindex:%{public}u,devType:%{public}u", __func__, __LINE__, devIndex, devType); - } -} -bool HdfEventManager::OpenHdfDevice(uint32_t devIndex, bool oper) -{ - if (devIndex >= MAX_INPUT_DEVICE_COUNT) { - return true; - } - int32_t ret = -1; - if (oper) { - ret = inputInterface_->iInputManager->OpenInputDevice(devIndex); - } else { - ret = inputInterface_->iInputManager->CloseInputDevice(devIndex); - } - if (ret == 0) { - MMI_HILOGI("%{public}s:%{public}d Info: device success!", __func__, __LINE__); - return true; - } - - if (ret != 0) { - MMI_HILOGE("%{public}s:%{public}d Error: device fail! code:%{public}u", __func__, __LINE__, ret); - } - return false; -} -void HdfEventManager::HotPlugCallback(const HotPlugEvent *event) -{ - MMI_HILOGD("%{public}s:%{public}d HotPlugCallback status:%{public}u,devindex:%{public}u" - "devType:%{public}u", __func__, __LINE__, event->status, event->devIndex, event->devType); - - if (!event->status) { - DeviceAddHandle(event->devIndex, event->devType); - } else { - DeviceRemoveHandle(event->devIndex, event->devType); - } -} -int32_t HdfEventManager::DeviceRemoveHandle(uint32_t devIndex, uint32_t devType) -{ - MMI_HILOGD("%{public}s:%{public}d DeviceRemoveHandle devindex:%{public}u,devType:%{public}u", - __func__, __LINE__, devIndex, devType); - Devcmd cmd; - cmd.index = devIndex; - cmd.cmd = static_cast(HDF_RMV_DEVICE); - libinput_devpipe_write(m_globleThis->hdiinput_, &cmd, sizeof(Devcmd)); - if (devIndex < MAX_INPUT_DEVICE_COUNT) { - uint32_t ret = m_globleThis->inputInterface_->iInputReporter->UnregisterReportCallback(devIndex); - if (ret == INPUT_SUCCESS) { - MMI_HILOGI("%{public}s:%{public}d REMOVE_SUCCESS devindex:%{public}u,devType:%{public}u", - __func__, __LINE__, devIndex, devType); - } else { - MMI_HILOGE("%{public}s:%{public}d REMOVE_ERROR devindex:%{public}u,devType:%{public}u", - __func__, __LINE__, devIndex, devType); - } - } - globleThis_->OpenHdfDevice(devIndex, false); - return RET_OK; -} - - -void HdfEventManager::GetEventCallback(const KeyEventNormalize **pkgs, uint32_t count, uint32_t devIndex) -{ - static constexpr uint16_t byteSize = 8; - CHKPV(pkgs); - struct input_event eventarry[MAX_EVENT_PKG_NUM]; - for (uint32_t i = 0; i < count && i < MAX_EVENT_PKG_NUM; i++) { - eventarry[i].code = pkgs[i]->code; - eventarry[i].type = (pkgs[i]->type) | static_cast(devIndex<value; - eventarry[i].input_event_sec = (pkgs[i]->timestamp) / (USEC_PER_SEC); - eventarry[i].input_event_usec = (pkgs[i]->timestamp) % (USEC_PER_SEC); - } - if (!globleThis_->devStatus[devIndex]) { - return; - } - libinput_pipe_write(globleThis_->hdiinput_, devIndex, eventarry, count * sizeof(struct input_event)); -} - -int32_t HdfEventManager::DeviceAddHandle(uint32_t devIndex, uint32_t devType) -{ - MMI_HILOGD("%{public}s:%{public}d DeviceAddHandle devindex:%{public}u,devType:%{public}u", - __func__, __LINE__, devIndex, devType); - globleThis_->devStatus[devIndex] = false; - uhdf *hdiuhdf = nullptr; - hdiuhdf = new(uhdf); - hdiuhdf->index = devIndex; - hdiuhdf->type = globleThis_->HdfdevtypeMapLibinputType(devIndex, devType); - hdiuhdf->nproperties = 0; - hdiuhdf->quirkpop = nullptr; - hdiuhdf->modeltype = 0; - hdiuhdf->fn = (hdiuhdf->index >= MAX_INPUT_DEV_NUM) ? EvdevSimIoctl : EvdevIoctl; - globleThis_->hdflist_.push_back(hdiuhdf); - Devcmd cmd; - cmd.index = devIndex; - cmd.cmd = static_cast(HDF_ADD_DEVICE); - libinput_devpipe_write(globleThis_->hdiinput_, &cmd, sizeof(Devcmd)); - return RET_OK; -} -constexpr struct libinput_interface _hdfinterface = { - .open_restricted = [](const char *path, int32_t flags, void *user_data)->int32_t { - int32_t fd = -1; - MMI_HILOGI("libinput .open_restricted path:%{public}s,fd:%{public}d", path, fd); - return fd < 0 ? -errno : fd; - }, - .close_restricted = [](int32_t fd, void *user_data) - { - MMI_HILOGI("libinput .close_restricted fd:%{public}d", fd); - }, -}; -libinput *HdfEventManager::HdfLibinputInit() -{ - if (globleThis_->hdiinput_ == nullptr) { - globleThis_->hdiinput_ = libinput_hdf_create_context(&_hdfinterface, nullptr); - } - MMI_HILOGD("HdfLibinputInit function end"); - return globleThis_->hdiinput_; -} -int32_t HdfEventManager::HdfDevHandle(int32_t index, hdf_event_type cmd) -{ - if (cmd != HDF_ADD_DEVICE) { - MMI_HILOGD("HdfRmv function start"); - uhdf *hdiuhdf = nullptr; - for (std::list::iterator it = globleThis_->hdflist_.begin(); - it != globleThis_->hdflist_.end(); ++it) { - uhdf *hdiuhdfit = *it; - if (hdiuhdfit->index == static_cast(index)) { - hdiuhdf = *it; - globleThis_->hdflist_.remove(*it); - break; - } - } - if (hdiuhdf == nullptr) { - return RET_OK; - } - uhdfdevice_removed(hdiuhdf); - delete(hdiuhdf); - return RET_OK; - } - - uhdf *hdiuhdf = nullptr; - for (std::list::iterator it = globleThis_->hdflist_.begin(); - it != globleThis_->hdflist_.end(); ++it) { - uhdf *hdiuhdfit = *it; - if (hdiuhdfit->index != static_cast(index)) { - continue; - } - - hdiuhdf = *it; - DeviceInfo *deviceinfo = nullptr; - globleThis_->AddDevice(index, hdiuhdf->type); - if (index < MAX_INPUT_DEVICE_COUNT) { - uint32_t ret = globleThis_->inputInterface_->iInputManager->GetInputDevice(index, &deviceinfo); - if (ret != 0 || (deviceinfo == nullptr)) { - MMI_HILOGE("%{public}s:%{public}d inputInterface_ GetInputDevice ret:%{public}d", - __func__, __LINE__, ret); - return RET_ERR; - } - hdiuhdf->deviceinfo = (void*)deviceinfo; - } - uhdfdevice_added(globleThis_->hdiinput_, hdiuhdf, "default"); - globleThis_->devStatus[index] = true; - return RET_OK; - } - return RET_OK; -} -bool HdfEventManager::Init() -{ - return true; -} -HdfEventManager hdfEventManager; -extern "C" libinput *HdfAdfInit() -{ - MMI_HILOGD("HdfAdfInit function start"); - return hdfEventManager.HdfLibinputInit(); -} - -extern "C" int32_t HdfDevHandle(int32_t index, hdf_event_type cmd) -{ - MMI_HILOGD("HdfDevHandle function start index:%{public}d,cmd:%{public}d", index, cmd); - return hdfEventManager.HdfDevHandle(index, cmd); -} -#endif -} // namespace MMI -} // namespace OHOS \ No newline at end of file diff --git a/service/hdf_adapter/src/hdf_inject_init.cpp b/service/hdf_adapter/src/hdf_inject_init.cpp deleted file mode 100644 index a2c812dad7e7e13f5847ddcaf0847ebd3a8543da..0000000000000000000000000000000000000000 --- a/service/hdf_adapter/src/hdf_inject_init.cpp +++ /dev/null @@ -1,767 +0,0 @@ -/* - * 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 "hdf_inject_init.h" - -static DrvType g_index2DrvType[] = { - MOUSE, KEYBOARD, TOUCH, PEN, PAD, INVALD, FINGER, JOYSTICK, INVALD, INVALD, KEYBOARD, SWITCH5, TRACKPAD5, GAMEPAD -}; -static short g_arrayIds[][4] = { - {3, 24582, 24582, 1}, {3, 24582, 24582, 1}, {3, 24582, 24582, 1}, {3, 1386, 914, 272}, - {3, 1386, 914, 272}, {3, 1386, 914, 272}, {3, 1386, 914, 272}, {3, 1386, 914, 272}, - {3, 1386, 914, 272}, {3, 1386, 914, 272} -}; -static uint32_t g_arrayBits[] = { - 11, 7, 31, 27, 11, 43, 31, 1179671, 23, 31s -}; -static uint32_t g_arrayPropsBits[] = { - 2, 0, 0, 1, 0, 1, 0, 0, 0, 0 -}; -static uint32_t g_arrayKeyBits[][24] = { - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1024, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 1073741824, 0, 0, 0, 0xffffffff, 0xffffffff, 0xffffffff, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0}, - {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, - 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, - 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7903, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 127, 0, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 58656, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 65535, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, - 2031617, 0, 0, 3209970758, 397407021, 75759615, 0, 0, 0, 0, 196863, 0, 0, 0, 0, 0}, - {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, - 2031616, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, -}; -static uint32_t g_arrayRelBits[] = { - 0, 2307, 64, 0, 0, 0, 0, 323, 323, 0 -}; -static uint32_t g_arrayAbsBits[][2] = { - {16777219, 124977152}, - { 0, 0}, - { 0, 1}, - {251658503, 256}, - {259, 256}, - {3, 41123840}, - {196707, 0}, - {0, 1}, - {0, 0}, - {198207, 0}, -}; -static uint32_t g_arrayLedBits[] = { - 0, 0, 0, 0, 0, 0, 0, 7, 7, 0 -}; -static uint32_t g_arraySwBits[] = { - 0, 0, 0, 0, 0, 16384, 0, 0, 0, 0 -}; -static uint32_t g_arrayMscBits[] = { - 0, 0, 16, 1, 0, 0, 16, 16, 16, 0 -}; -static uint32_t g_arrayFfBits[][4] = { - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, -}; -static uint32_t g_arraySndBits[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; -static uint32_t g_arrayLedValues[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; -static uint32_t g_arraySwValues[] = { - 0, 0, 0, 0, 0, 16384, 0, 0, 0, 0 -}; -static uint32_t g_arrayKeyValues[][24] = { - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16384, 0, 6400, 0, 0, 4000, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, -}; -static input_absinfo g_arrayAxisInfo[][64] = { - { - {0, 0, 480, 0, 0, 0}, - {0, 0, 960, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 100, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 1, 0, 0, 0}, - {0, 0, 1, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, -90, 90, 0, 0, 0}, - {0, 0, 480, 0, 0, 0}, - {0, 0, 960, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 10, 0, 0, 0}, - {0, 0, 9, 0, 0, 0}, - {0, 0, 100, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - }, - { - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - }, - { - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 1300, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - }, - { - {0, 0, 31920, 4, 0, 200}, - {0, 0, 19950, 4, 0, 200}, - {0, -900, 899, 0, 0, 287}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 2047, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 8191, 0, 0, 0}, - {0, 0, 63, 0, 0, 0}, - {0, -64, 63, 0, 0, 57}, - {0, -64, 63, 0, 0, 57}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, -2147483648, 2147483647, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - }, - { - {0, 0, 1, 0, 0, 0}, - {0, 0, 1, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 71, 0, 0, 11 }, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - }, - { - {0, 0, 6400, 0, 0, 40}, - {0, 0, 4000, 0, 0, 40}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 9, 0, 0, 0}, - {0, 0, 21, 0, 0, 2}, - {0, 0, 21, 0, 0, 2}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 1, 0, 0, 0}, - {0, 0, 6400, 0, 0, 40}, - {0, 0, 4000, 0, 0, 40}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 65535, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - }, - { - {0, 0, 16383, 63, 1023, 0}, - {0, 0, 16383, 63, 1023, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 255, 0, 15, 0}, - {0, 0, 255, 0, 15, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, -1, 1, 0, 0, 0}, - {0, -1, 1, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - }, - { - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 572, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - }, - { - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - }, - { - {0, 0, 255, 0, 15, 0}, - {0, 0, 255, 0, 15, 0}, - {0, 0, 255, 0, 15, 0}, - {0, -32768, 32767, 16, 128, 0}, - {0, -32768, 32767, 16, 128, 0}, - {0, 0, 255, 0, 15, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 255, 0, 15, 0}, - {0, 0, 255, 0, 15, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, -1, 1, 0, 0, 0}, - {0, -1, 1, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0}, - }, -}; diff --git a/service/hdf_adapter/test/.gitkeep b/service/hdf_adapter/test/.gitkeep deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/service/hdi_inject/include/hdi_inject.h b/service/hdi_inject/include/hdi_inject.h deleted file mode 100644 index 0e9c588a3701a5c9105e7e50aaa617f564bf99ac..0000000000000000000000000000000000000000 --- a/service/hdi_inject/include/hdi_inject.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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 HDI_INJECT_H -#define HDI_INJECT_H -#ifdef OHOS_BUILD_HDF - -#include -#include - -#include "input_type.h" - -#include "input_manager.h" -#include "uds_server.h" - -namespace OHOS { -namespace MMI { -class HdiInject final { - DECLARE_DELAYED_SINGLETON(HdiInject); - -enum HdiInfoType { - GET_STATUS_INFO = 1001, - SET_HOT_PLUGS = 1002, - SET_EVENT_INJECT = 1003, - GET_DEVICE_INFO = 1004, - SHOW_DEVICE_INFO = 1005, - REPLY_STATUS_INFO = 2001, -}; - -enum HdiDeviceStatus { - HDI_DEVICE_ADD_STATUS = 0, - HDI_DEVICE_REMOVE_STATUS = 1, -}; - -struct DeviceInformation { - bool status { false }; - int32_t devIndex { 0 }; - int32_t devType { 0 }; - int16_t fd { 0 }; - char chipName[32]; -}; -public: - DISALLOW_COPY_AND_MOVE(HdiInject); - bool Init(UDSServer &sess); - void StartHdiserver(); - void ShowAllDeviceInfo(); - void InitDeviceInfo(); - int32_t GetDeviceCount(); - bool SyncDeviceHotStatus(); - bool ReportHotPlugEvent(); - void OnInitHdiServerStatus(); - int32_t GetDevTypeIndex(int32_t devIndex); - int32_t GetDevIndexType(int32_t devType); - int32_t ManageHdfInject(const MMI::SessionPtr sess, MMI::NetPacket &pkt); - void OnSetHotPlugs(uint32_t devIndex, uint32_t devSatatus); - int32_t OnSetEventInject(const RawInputEvent& allEvent, int32_t devType); - bool SetDeviceHotStatus(int32_t devIndex, int32_t status); - int32_t ScanInputDevice(uint32_t arrLen, DevDesc *staArr); - bool ReportHotPlugEvent(uint32_t devIndex, uint32_t status); -public: - InputHostCb hotPlugcallback_; - InputEventCb eventcallback_; -private: - bool initStatus_ { false }; - HotPlugEvent** event_ { nullptr }; - MMI::UDSServer* udsServerPtr_ { nullptr }; - std::vector deviceArray_ = {}; -}; - -#define MMIHdiInject ::OHOS::DelayedSingleton::GetInstance() -} // namespace MMI -} // namespace OHOS -#endif // OHOS_BUILD_HDF -#endif // HDI_INJECT_H \ No newline at end of file diff --git a/service/hdi_inject/src/hdi_inject.cpp b/service/hdi_inject/src/hdi_inject.cpp deleted file mode 100644 index 75566c9675fa150bfc5f103838574bd83c1e85a8..0000000000000000000000000000000000000000 --- a/service/hdi_inject/src/hdi_inject.cpp +++ /dev/null @@ -1,407 +0,0 @@ -/* - * 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 "hdi_inject.h" - -#include - -#include "singleton.h" - -#include "define_multimodal.h" -#include "proto.h" -#include "util.h" - - -#ifdef OHOS_BUILD_HDF -using namespace std; -using namespace OHOS::MMI; - -namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "HdiInject" }; -constexpr int32_t HDF_MOUSE_DEV_TYPE = 5; -constexpr int32_t HDF_KEYBOARD_DEV_TYPE = 3; -constexpr int32_t HDF_TOUCH_DEV_TYPE = 17; -constexpr int32_t HDF_TABLET_DEV_TYPE = 33; -constexpr int32_t HDF_TABLET_PAD_DEV_TYPE = 289; -constexpr int32_t HDF_SWITH_PAD_DEV_TYPE = 2089; -constexpr int32_t HDF_TOUCH_FINGER_DEV_TYPE = 2089; -constexpr int32_t HDF_SWITCH_DEV_TYPE = 7; -constexpr int32_t HDF_TRACK_PAD_DEV_TYPE = 7; -constexpr int32_t HDF_JOYSTICK_DEV_TYPE = 65; -constexpr int32_t HDF_GAMEPAD_DEV_TYPE = 65; -constexpr int32_t HDF_TOUCH_PAD_DEV_TYPE = 5; -constexpr int32_t HDF_TRACK_BALL_DEV_TYPE = 3; -constexpr int32_t HDF_DEVICE_FD_DEFAULT_STATUS = -1; -constexpr int32_t EVENT_PACKAGE_ARROW_SIZE = 1; -} // namespace - -HdiInject::HdiInject() {} -HdiInject::~HdiInject() {} - -bool HdiInject::Init(UDSServer &sess) -{ - udsServerPtr_ = &sess; - StartHdiserver(); - return true; -} - -int32_t HdiInject::ManageHdfInject(const SessionPtr sess, NetPacket &pkt) -{ - MMI_HILOGI("Into function ManageHdfInject"); - int32_t sendType = 0; - pkt >> sendType; - uint32_t devIndex = 0; - uint32_t devSatatus = 0; - RawInputEvent speechEvent = {}; - switch (sendType) { - case GET_STATUS_INFO: { - OnInitHdiServerStatus(); - return RET_OK; - } - case SET_EVENT_INJECT: { - pkt >> devIndex >> speechEvent; - if (pkt.ChkRWError()) { - MMI_HILOGE("Packet read recv massage failed"); - return RET_ERR; - } - MMI_HILOGI("Hdi server recv massage: devIndex:%{public}d", devIndex); - OnSetEventInject(speechEvent, devIndex); - return RET_OK; - } - case SHOW_DEVICE_INFO: { - ShowAllDeviceInfo(); - return RET_OK; - } - case SET_HOT_PLUGS: { - pkt >> devIndex >> devSatatus; - if (pkt.ChkRWError()) { - MMI_HILOGE("Packet read tool hot data failed"); - return RET_ERR; - } - MMI_HILOGI("Recv inject tool hot data, devIndex:%{public}d,status:%{public}d", devIndex, devSatatus); - OnSetHotPlugs(devIndex, devSatatus); - return RET_OK; - } - default: { - MMI_HILOGE("The message type:%{public}d cannot be processed", sendType); - return RET_ERR; - } - } -} - -int32_t HdiInject::OnSetEventInject(const RawInputEvent& allEvent, int32_t devIndex) -{ - CALL_DEBUG_ENTER; - KeyEventNormalize* pack[EVENT_PACKAGE_ARROW_SIZE]; - pack[0] = (KeyEventNormalize*)malloc(sizeof(KeyEventNormalize)); - pack[0]->type = static_cast(allEvent.ev_type); - pack[0]->code = static_castallEvent.ev_code; - pack[0]->value = static_cast(allEvent.ev_value); - pack[0]->timestamp = static_cast(GetSysClockTime()); - MMIHdiInject->eventcallback_.EventPkgCallback((const KeyEventNormalize**)pack, 1, devIndex); - free(pack[0]); - return RET_OK; -} - -void HdiInject::OnSetHotPlugs(uint32_t devIndex, uint32_t devSatatus) -{ - if (!(ReportHotPlugEvent(devIndex, devSatatus))) { - MMI_HILOGE("ReportHotPlugEvent failed"); - return; - } - MMI_HILOGI("ReportHotPlugEvent success"); -} - -void HdiInject::InitDeviceInfo() -{ - DeviceInformation deviceInfoArray[] = { - {HDI_DEVICE_REMOVE_STATUS, INPUT_DEVICE_POINTER_INDEX, HDF_MOUSE_DEV_TYPE, - HDF_DEVICE_FD_DEFAULT_STATUS, "mouse"}, - {HDI_DEVICE_REMOVE_STATUS, INPUT_DEVICE_KEYBOARD_INDEX, HDF_KEYBOARD_DEV_TYPE, - HDF_DEVICE_FD_DEFAULT_STATUS, "keyboard"}, - {HDI_DEVICE_REMOVE_STATUS, INPUT_DEVICE_TOUCH_INDEX, HDF_TOUCH_DEV_TYPE, - HDF_DEVICE_FD_DEFAULT_STATUS, "touch"}, - {HDI_DEVICE_REMOVE_STATUS, INPUT_DEVICE_TABLET_TOOL_INDEX, HDF_TABLET_DEV_TYPE, - HDF_DEVICE_FD_DEFAULT_STATUS, "pen"}, - {HDI_DEVICE_REMOVE_STATUS, INPUT_DEVICE_TABLET_PAD_INDEX, HDF_TABLET_PAD_DEV_TYPE, - HDF_DEVICE_FD_DEFAULT_STATUS, "pad"}, - {HDI_DEVICE_REMOVE_STATUS, INPUT_DEVICE_FINGER_INDEX, HDF_TOUCH_FINGER_DEV_TYPE, - HDF_DEVICE_FD_DEFAULT_STATUS, "finger"}, - {HDI_DEVICE_REMOVE_STATUS, INPUT_DEVICE_SWITCH_INDEX, HDF_SWITCH_DEV_TYPE, - HDF_DEVICE_FD_DEFAULT_STATUS, "knob"}, - {HDI_DEVICE_REMOVE_STATUS, INPUT_DEVICE_TRACKPAD5_INDEX, HDF_TRACK_PAD_DEV_TYPE, - HDF_DEVICE_FD_DEFAULT_STATUS, "trackPad"}, - {HDI_DEVICE_REMOVE_STATUS, INPUT_DEVICE_JOYSTICK_INDEX, HDF_JOYSTICK_DEV_TYPE, - HDF_DEVICE_FD_DEFAULT_STATUS, "joyStick"}, - {HDI_DEVICE_REMOVE_STATUS, INPUT_DEVICE_GAMEPAD_INDEX, HDF_GAMEPAD_DEV_TYPE, - HDF_DEVICE_FD_DEFAULT_STATUS, "gamePad"}, - {HDI_DEVICE_REMOVE_STATUS, INPUT_DEVICE_TOUCH_PAD, HDF_TOUCH_PAD_DEV_TYPE, - HDF_DEVICE_FD_DEFAULT_STATUS, "touchPad"}, - {HDI_DEVICE_REMOVE_STATUS, INPUT_DEVICE_REMOTE_CONTROL, HDF_TRACK_BALL_DEV_TYPE, - HDF_DEVICE_FD_DEFAULT_STATUS, "remoteControl"}, - }; - int32_t counts = sizeof(deviceInfoArray) / sizeof(DeviceInformation); - auto iter = deviceArray_.insert(deviceArray_.begin(), deviceInfoArray, deviceInfoArray + counts); - if (!iter.second) { - MMI_HILOGE("Insert value failed"); - } -} - -void HdiInject::StartHdiserver() -{ - initStatus_ = true; -} - -void HdiInject::OnInitHdiServerStatus() -{ - StartHdiserver(); -} - -void HdiInject::ShowAllDeviceInfo() -{ - for (const auto &item : deviceArray_) { - MMI_HILOGI("deviceName:%{public}s,devIndex:%{public}d,status:%{public}d,devType:%{public}d", - item.chipName, item.devIndex, item.status, item.devType); - } -} - -int32_t HdiInject::GetDeviceCount() -{ - return static_cast(deviceArray_.size()); -} - -bool HdiInject::SetDeviceHotStatus(int32_t devIndex, int32_t status) -{ - for (auto iter = deviceArray_.begin(); iter != deviceArray_.end(); ++iter) { - if (iter->devIndex == devIndex) { - if (iter->status == status) { - MMI_HILOGE("Failed to find status"); - return false; - } - iter->status = ~status + 1; - return true; - } - } - return false; -} - -bool HdiInject::SyncDeviceHotStatus() -{ - const uint16_t count = static_cast(deviceArray_.size()); - event_ = (HotPlugEvent**)malloc(count * sizeof(HotPlugEvent)); - CHKPF(event_); - for (int32_t i = 0; i < count; i++) { - event_[i]->devIndex = deviceArray_[i].devIndex; - event_[i]->devType = deviceArray_[i].devType; - event_[i]->status = deviceArray_[i].status; - MMIHdiInject->hotPlugcallback_.HotPlugCallback((const HotPlugEvent*)&event_[i]); - } - return true; -} - -bool HdiInject::ReportHotPlugEvent() -{ - SyncDeviceHotStatus(); - MMIHdiInject->hotPlugcallback_.HotPlugCallback(*event_); - return true; -} - -bool HdiInject::ReportHotPlugEvent(uint32_t devIndex, uint32_t status) -{ - if (!(SetDeviceHotStatus(devIndex, status))) { - MMI_HILOGE("SetDeviceHotStatus error devIndex:%{public}d,status:%{public}d", devIndex, status); - return false; - } - int32_t devType = GetDevTypeIndex(devIndex); - if (devType == -1) { - return false; - } - HotPlugEvent event = { - static_cast(devIndex), - static_cast(devType), - static_cast(status) - }; - MMIHdiInject->hotPlugcallback_.HotPlugCallback(&event); - return true; -} - -int32_t HdiInject::GetDevTypeIndex(int32_t devIndex) -{ - for (const auto &item : deviceArray_) { - if (item.devIndex == devIndex) { - return item.devType; - } - } - return RET_ERR; -} - -int32_t HdiInject::GetDevIndexType(int32_t devType) -{ - vector::iterator iter; - for (const auto &item : deviceArray_) { - if (item.devType == devType) { - return item.devIndex; - } - } - return RET_ERR; -} - -int32_t HdiInject::ScanInputDevice(uint32_t arrLen, DevDesc *staArr) -{ - uint16_t count = static_cast(deviceArray_.size()); - int32_t index = 0; - for (int i = 0; i < count; i++) { - if (deviceArray_[i].status == 1) { - continue; - } - staArr[index].devIndex = deviceArray_[i].devIndex; - staArr[index].devType = deviceArray_[i].devType; - index++; - } - return 0; -} - -static int32_t ScanInputDevice(uint32_t arrLen, DevDesc *staArr) -{ - return MMIHdiInject->ScanInputDevice(arrLen, staArr); -} - -static int32_t OpenInputDevice(uint32_t devIndex) -{ - return 0; -} - -static int32_t CloseInputDevice(uint32_t devIndex) -{ - return 0; -} - -static int32_t GetInputDevice(uint32_t devIndex, DeviceInfo **devInfo) -{ - return 0; -} - -static int32_t GetInputDeviceList(uint32_t *devNum, DeviceInfo **devList, uint32_t size) -{ - return 0; -} - -static int32_t SetPowerStatus(uint32_t devIndex, uint32_t status) -{ - return 0; -} - -static int32_t GetPowerStatus(uint32_t devIndex, uint32_t *status) -{ - return 0; -} - -static int32_t GetDeviceType(uint32_t devIndex, uint32_t *deviceType) -{ - return 0; -} - -static int32_t GetChipInfo(uint32_t devIndex, char *chipInfo, uint32_t length) -{ - return 0; -} - -static int32_t GetVendorName(uint32_t devIndex, char *vendorName, uint32_t length) -{ - return 0; -} - - -static int32_t GetChipName(uint32_t devIndex, char *chipName, uint32_t length) -{ - return 0; -} - -static int32_t SetGestureMode(uint32_t devIndex, uint32_t gestureMode) -{ - return 0; -} - -static int32_t RunCapacitanceTest(uint32_t devIndex, uint32_t testType, char *result, uint32_t length) -{ - return 0; -} - -static int32_t RunExtraCommand(uint32_t devIndex, InputExtraCmd *cmd) -{ - return 0; -} - -static int32_t RegisterReportCallback(uint32_t devIndex, InputEventCb *callback) -{ - MMIHdiInject->eventcallback_.EventPkgCallback = callback->EventPkgCallback; - return 0; -} - -static int32_t UnregisterReportCallback(uint32_t devIndex) -{ - return 0; -} - -static int32_t RegisterHotPlugCallback(InputHostCb *callback) -{ - MMIHdiInject->hotPlugcallback_.HotPlugCallback = callback->HotPlugCallback; - return 0; -} - -static int32_t UnregisterHotPlugCallback(void) -{ - return 0; -} - -static InputManager interfaceManager = { - .ScanInputDevice = ScanInputDevice, - .OpenInputDevice = OpenInputDevice, - .CloseInputDevice = CloseInputDevice, - .GetInputDevice = GetInputDevice, - .GetInputDeviceList = GetInputDeviceList, -}; - -static InputController interfaceControl = { - .SetPowerStatus = SetPowerStatus, - .GetPowerStatus = GetPowerStatus, - .GetDeviceType = GetDeviceType, - .GetChipInfo = GetChipInfo, - .GetVendorName = GetVendorName, - .GetChipName = GetChipName, - .SetGestureMode = SetGestureMode, - .RunCapacitanceTest = RunCapacitanceTest, - .RunExtraCommand = RunExtraCommand, -}; - -static InputReporter interfaceReport = { - .RegisterReportCallback = RegisterReportCallback, - .UnregisterReportCallback = UnregisterReportCallback, - .RegisterHotPlugCallback = RegisterHotPlugCallback, - .UnregisterHotPlugCallback = UnregisterHotPlugCallback, -}; - -int32_t GetInputInterfaceFromInject(IInputInterface **interface) -{ - MMIHdiInject->InitDeviceInfo(); - int32_t ret = 0; - IInputInterface* injectInterface = new(IInputInterface); - *interface = injectInterface; - injectInterface->iInputController = &interfaceControl; - injectInterface->iInputManager = &interfaceManager; - injectInterface->iInputReporter = &interfaceReport; - return ret; -} -#endif \ No newline at end of file diff --git a/service/hisysevent.yaml b/service/hisysevent.yaml index ac350c6b4000b9d30b27c06060d3a065e03a84cf..41f91c31f71ce25b910b0204a632e2ba439d2769 100644 --- a/service/hisysevent.yaml +++ b/service/hisysevent.yaml @@ -25,7 +25,7 @@ # // __BASE is used for defining the basic info of the event. # // "type" optional values are: FAULT, STATISTICS, SECURITY, BEHAVIOR. # // "level" optional values are: CRITICAL, MINOR. -# // "tag" set tags with may used by subscriber of this event, multiple tags devided by space. +# // "tag" set tags with may be used by subscriber of this event, multiple tags divided by space. # // "desc" full description of this event. # @PARAMETER: {type: parameter type, arrsize: array length(optional), desc: parameter description}. # // follow the __BASE block, each line defines a parameter of this event. @@ -77,8 +77,8 @@ INPUT_DEV_DISCONNECTION_FAILURE: CLIENT_CONNECTION_SUCCESS: __BASE: {type: BEHAVIOR, level: MINOR, tag: PowerStats, desc: client connection event success} - PID: {type: INT32, desc: pid} - UID: {type: INT32, desc: uid} + PID: {type: INT32, desc: session pid} + UID: {type: INT32, desc: session uid} MODULE_TYPE: {type: INT32, desc: module type} FD: {type: INT32, desc: server fd} PROGRAMNAME: {type: STRING, desc: program name} @@ -86,16 +86,16 @@ CLIENT_CONNECTION_SUCCESS: CLIENT_CONNECTION_FAILURE: __BASE: {type: FAULT, level: MINOR, tag: PowerStats, desc: client connection event failure} - PID: {type: INT32, desc: pid} - UID: {type: INT32, desc: uid} + PID: {type: INT32, desc: session pid} + UID: {type: INT32, desc: session uid} MODULE_TYPE: {type: INT32, desc: module type} PROGRAMNAME: {type: STRING, desc: program name} MSG: {type: STRING, desc: message} CLIENT_DISCONNECTION_SUCCESS: __BASE: {type: BEHAVIOR, level: MINOR, tag: PowerStats, desc: client disconnection event success} - PID: {type: INT32, desc: pid} - UID: {type: INT32, desc: uid} + PID: {type: INT32, desc: session pid} + UID: {type: INT32, desc: session uid} MODULE_TYPE: {type: INT32, desc: module type} FD: {type: INT32, desc: server fd} PROGRAMNAME: {type: STRING, desc: program name} @@ -110,7 +110,7 @@ TARGET_POINTER_EVENT_SUCCESS: EVENTTYPE: {type: INT32, desc: event type} AGENT_WINDOWID: {type: INT32, desc: agent windowid} TARGET_WINDOWID: {type: INT32, desc: target windowid} - PID: {type: INT32, desc: pid} + PID: {type: INT32, desc: session pid} FD: {type: INT32, desc: target fd} MSG: {type: STRING, desc: message} @@ -122,31 +122,31 @@ TARGET_POINTER_EVENT_FAILURE: TARGET_KEY_EVENT_SUCCESS: __BASE: {type: BEHAVIOR, level: MINOR, tag: PowerStats, desc: target key event success} EVENTTYPE: {type: INT32, desc: event type} - KEYCODE: {type: INT32, desc: keycode} - ACTION: {type: INT32, desc: action} + KEYCODE: {type: INT32, desc: key code} + ACTION: {type: INT32, desc: key action} ACTION_TIME: {type: UINT64, desc: action time} ACTION_STARTTIME: {type: UINT64, desc: action start time} - FLAG: {type: INT32, desc: flag} - KEYACTION: {type: INT32, desc: keyaction} + FLAG: {type: INT32, desc: key flag} + KEYACTION: {type: INT32, desc: key action} FD: {type: INT32, desc: target fd} AGENT_WINDOWID: {type: INT32, desc: agent windowid} TARGET_WINDOWID: {type: INT32, desc: target windowid} - PID: {type: INT32, desc: pid} + PID: {type: INT32, desc: session pid} MSG: {type: STRING, desc: message} TARGET_KEY_EVENT_FAILURE: __BASE: {type: FAULT, level: MINOR, tag: PowerStats, desc: target key event failure} EVENTTYPE: {type: INT32, desc: event type} - KEYCODE: {type: INT32, desc: keycode} - ACTION: {type: INT32, desc: action} + KEYCODE: {type: INT32, desc: key code} + ACTION: {type: INT32, desc: key action} ACTION_TIME: {type: UINT64, desc: action time} ACTION_STARTTIME: {type: UINT64, desc: action start time} - FLAG: {type: INT32, desc: flag} - KEYACTION: {type: INT32, desc: keyaction} + FLAG: {type: INT32, desc: key flag} + KEYACTION: {type: INT32, desc: key action} MSG: {type: STRING, desc: message} FOCUS_WINDOW_CHANGE: - __BASE: {type: BEHAVIOR, level: MINOR, tag: PowerStats, desc: foucs window change} + __BASE: {type: BEHAVIOR, level: MINOR, tag: PowerStats, desc: focus window change} OLD_FOCUS_WINDOWID: {type: INT32, desc: old focus windowid} NEW_FOCUS_WINDOWID: {type: INT32, desc: new focus windowid} OLD_FOCUS_WINDOWPID: {type: INT32, desc: old focus windowpid} @@ -176,3 +176,9 @@ COMBO_START_TIME: BELOW50MS: {type: UINT32, desc: times below 50ms} ABOVE50MS: {type: UINT32, desc: times above 50ms} MSG: {type: STRING, desc: message} + +INPUT_POWER_UP: + __BASE: {type: STATISTIC, level: CRITICAL, desc: power input up} + +INPUT_POWER_DOWN: + __BASE: {type: STATISTIC, level: CRITICAL, desc: power input down} \ No newline at end of file diff --git a/service/input_device_cooperate/include/cooperate_event_handler.h b/service/input_device_cooperate/include/cooperate_event_handler.h index 1157ee2a653ad7444436ba29cc7ff0678f5bb9f9..4ffc0a694e4b8ec9cde7be3f43719a76534ab3c1 100755 --- a/service/input_device_cooperate/include/cooperate_event_handler.h +++ b/service/input_device_cooperate/include/cooperate_event_handler.h @@ -23,10 +23,10 @@ namespace OHOS { namespace MMI { -class CooperateEventHandler : public AppExecFwk::EventHandler { +class CooperateEventHandler final : public AppExecFwk::EventHandler { public: explicit CooperateEventHandler(const std::shared_ptr &runner); - virtual ~CooperateEventHandler(); + ~CooperateEventHandler() override = default; bool ProxyPostTask(const Callback &callback, int64_t delayTime); bool ProxyPostTask(const Callback &callback, const std::string &name = std::string(), int64_t delayTime = 0); void ProxyRemoveTask(const std::string &name); diff --git a/service/input_device_cooperate/include/cooperate_event_manager.h b/service/input_device_cooperate/include/cooperate_event_manager.h index 10757f6850d10bc391a800e7d81f2e70ffd750b2..cb34321b9cd5291af80d6e19519b53f53f1ac90c 100755 --- a/service/input_device_cooperate/include/cooperate_event_manager.h +++ b/service/input_device_cooperate/include/cooperate_event_manager.h @@ -48,7 +48,7 @@ public: void AddCooperationEvent(sptr event); void RemoveCooperationEvent(sptr event); - void OnCooperateMessage(CooperationMessage msg, const std::string &deviceId = ""); + int32_t OnCooperateMessage(CooperationMessage msg, const std::string &deviceId = ""); void OnEnable(CooperationMessage msg, const std::string &deviceId = ""); void OnStart(CooperationMessage msg, const std::string &deviceId = ""); void OnStop(CooperationMessage msg, const std::string &deviceId = ""); diff --git a/service/connect_manager/include/multimodal_input_connect_remoter.h b/service/input_device_cooperate/include/device_cooperate_softbus_adapter.h similarity index 48% rename from service/connect_manager/include/multimodal_input_connect_remoter.h rename to service/input_device_cooperate/include/device_cooperate_softbus_adapter.h index d587c48e0d29607c7d12fde7bdc542bf65bd94e4..3c5684730af24ce261b48c872922d0688c061f9d 100755 --- a/service/connect_manager/include/multimodal_input_connect_remoter.h +++ b/service/input_device_cooperate/include/device_cooperate_softbus_adapter.h @@ -13,23 +13,24 @@ * limitations under the License. */ -#ifndef MULTIMODAL_INPUT_CONNECT_REMOTER_H -#define MULTIMODAL_INPUT_CONNECT_REMOTER_H +#ifndef DEVICE_COOPERATE_SOFTBUS_ADAPTER_H +#define DEVICE_COOPERATE_SOFTBUS_ADAPTER_H #include #include #include #include "nocopyable.h" +#include "session.h" #include "i_multimodal_input_connect.h" namespace OHOS { namespace MMI { -class MultimodalInputConnectRemoter : public std::enable_shared_from_this { +class DeviceCooperateSoftbusAdapter { public: - virtual ~MultimodalInputConnectRemoter() = default; - static std::shared_ptr GetInstance(); + virtual ~DeviceCooperateSoftbusAdapter(); + static std::shared_ptr GetInstance(); int32_t StartRemoteCooperate(const std::string &localDeviceId, const std::string &remoteDeviceId); int32_t StartRemoteCooperateResult(const std::string &remoteDeviceId, bool isSuccess, const std::string &startDhid, int32_t xPercent, int32_t yPercent); @@ -37,17 +38,31 @@ public: int32_t StopRemoteCooperateResult(const std::string &remoteDeviceId, bool isSuccess); int32_t StartCooperateOtherResult(const std::string &remoteDeviceId, const std::string &srcNetworkId); + int32_t Init(); + void Release(); + int32_t OpenInputSoftbus(const std::string &remoteDevId); + void CloseInputSoftbus(const std::string &remoteDevId); + + int32_t OnSessionOpened(int32_t sessionId, int32_t result); + void OnSessionClosed(int32_t sessionId); + void OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen); + private: - MultimodalInputConnectRemoter() = default; - DISALLOW_COPY_AND_MOVE(MultimodalInputConnectRemoter); - - sptr GetProxyById(const std::string &remoteDeviceId); - void OnRemoteDeath(const std::string &remoteDeviceId); - std::mutex lock_; - std::map> mmiRemoteServices_; - std::map> mmiDeathRecipients_; + DeviceCooperateSoftbusAdapter() = default; + DISALLOW_COPY_AND_MOVE(DeviceCooperateSoftbusAdapter); + std::string FindDevice(int32_t sessionId); + int32_t SendMsg(int32_t sessionId, const std::string &message); + bool CheckDeviceSessionState(const std::string &remoteDevId); + void HandleSessionData(int32_t sessionId, const std::string& messageData); + int32_t WaitSessionOpend(const std::string &remoteDevId, int32_t sessionId); + std::map sessionDevMap_; + std::map channelStatusMap_; + std::mutex operationMutex_; + std::string localSessionName_; + std::condition_variable openSessionWaitCond_; + ISessionListener sessListener_; }; } // namespace MMI } // namespace OHOS -#define RemoteMgr MultimodalInputConnectRemoter::GetInstance() -#endif // MULTIMODAL_INPUT_CONNECT_REMOTER_H +#define DevCooperateSoftbusAdapter DeviceCooperateSoftbusAdapter::GetInstance() +#endif // DEVICE_COOPERATE_SOFTBUS_ADAPTER_H diff --git a/service/dinput/include/call_dinput_stub.h b/service/input_device_cooperate/include/device_cooperate_softbus_define.h similarity index 31% rename from service/dinput/include/call_dinput_stub.h rename to service/input_device_cooperate/include/device_cooperate_softbus_define.h index f906129dd27a4f071bf99d62862de9677aa8e531..7b9a20dd767bc4cccfbf7e1c1a3fea76b775c9e7 100644 --- a/service/dinput/include/call_dinput_stub.h +++ b/service/input_device_cooperate/include/device_cooperate_softbus_define.h @@ -1,42 +1,54 @@ -/* - * 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 CALL_DINPUT_STUB_H -#define CALL_DINPUT_STUB_H -#ifdef OHOS_DISTRIBUTED_INPUT_MODEL - -#include "iremote_stub.h" - -#include "i_call_dinput.h" -#include "message_parcel.h" - -namespace OHOS { -namespace MMI { -class CallDinputStub : public IRemoteStub { -public: - CallDinputStub() = default; - ~CallDinputStub() = default; - int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& options) override; -protected: - int32_t StubHandlePrepareDinput(MessageParcel& data, MessageParcel& reply); - int32_t StubHandleUnprepareDinput(MessageParcel& data, MessageParcel& reply); - int32_t StubHandleStartDinput(MessageParcel& data, MessageParcel& reply); - int32_t StubHandleStopDinput(MessageParcel& data, MessageParcel& reply); - int32_t StubHandleRemoteInputAbility(MessageParcel& data, MessageParcel& reply); -}; -} // namespace MMI -} // namespace OHOS -#endif // OHOS_DISTRIBUTED_INPUT_MODEL -#endif // CALL_DINPUT_STUB_H +/* + * 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 DEVICE_COOPERATE_SOFTBUS_DEFINE_H +#define DEVICE_COOPERATE_SOFTBUS_DEFINE_H + +#include +#include + +namespace OHOS { +namespace MMI { +constexpr int32_t ENCRYPT_TAG_LEN = 32; +constexpr int32_t MSG_MAX_SIZE = 45 * 1024; +constexpr uint32_t SESSION_NAME_SIZE_MAX = 256; +constexpr uint32_t DEVICE_ID_SIZE_MAX = 65; +constexpr uint32_t INTERCEPT_STRING_LENGTH = 20; +constexpr int32_t SESSION_WAIT_TIMEOUT_SECOND = 5; +constexpr int32_t SESSION_SIDE_SERVER = 0; +constexpr int32_t SESSION_SIDE_CLIENT = 1; + +const std::string SESSION_NAME = "ohos.mmi."; +const std::string GROUP_ID = "mmi_softbus_group_id"; + +#define MMI_SOFTBUS_KEY_CMD_TYPE "mmi_softbus_key_cmd_type" +#define MMI_SOFTBUS_KEY_LOCAL_DEVICE_ID "mmi_softbus_key_local_device_id" +#define MMI_SOFTBUS_KEY_START_DHID "mmi_softbus_key_start_dhid" +#define MMI_SOFTBUS_KEY_POINTER_X "mmi_softbus_key_pointer_x" +#define MMI_SOFTBUS_KEY_POINTER_Y "mmi_softbus_key_pointer_y" +#define MMI_SOFTBUS_KEY_RESULT "mmi_softbus_key_result" +#define MMI_SOFTBUS_KEY_OTHER_DEVICE_ID "mmi_softbus_key_other_device_id" +#define MMI_SOFTBUS_KEY_SESSION_ID "mmi_softbus_key_session_id" + +enum { + REMOTE_COOPERATE_START = 1, + REMOTE_COOPERATE_START_RES = 2, + REMOTE_COOPERATE_STOP = 3, + REMOTE_COOPERATE_STOP_RES = 4, + REMOTE_COOPERATE_STOP_OTHER_RES = 5 +}; +} // namespace MMI +} // namespace OHOS +#endif // DEVICE_COOPERATE_SOFTBUS_DEFINE_H diff --git a/service/input_device_cooperate/include/device_profile_adapter.h b/service/input_device_cooperate/include/device_profile_adapter.h index fe55fd3d9e0f7aca6b5c56d467aa38ace088fcec..fe3c0f175e7e4240e296baca28037cde417563b6 100755 --- a/service/input_device_cooperate/include/device_profile_adapter.h +++ b/service/input_device_cooperate/include/device_profile_adapter.h @@ -30,7 +30,7 @@ namespace OHOS { namespace MMI { class DeviceProfileAdapter final { DECLARE_DELAYED_SINGLETON(DeviceProfileAdapter); - class ProfileEventCallbackImpl : public DeviceProfile::IProfileEventCallback { + class ProfileEventCallbackImpl final : public DeviceProfile::IProfileEventCallback { public: void OnSyncCompleted(const DeviceProfile::SyncResult &syncResults) override; void OnProfileChanged(const DeviceProfile::ProfileChangeNotification &changeNotification) override; diff --git a/service/input_device_cooperate/include/distributed_input_adapter.h b/service/input_device_cooperate/include/distributed_input_adapter.h index 1d1c9c55dee656e93336cf6a56f1353d04478fb1..e2ab8a2304eb47dd797adba368816335503b415d 100644 --- a/service/input_device_cooperate/include/distributed_input_adapter.h +++ b/service/input_device_cooperate/include/distributed_input_adapter.h @@ -42,7 +42,7 @@ class DistributedInputAdapter final { DECLARE_DELAYED_SINGLETON(DistributedInputAdapter); public: using DInputCallback = std::function; - using MouseStateChangeCallback = std::function; + using SimulateEventCallback = std::function; DISALLOW_COPY_AND_MOVE(DistributedInputAdapter); bool IsNeedFilterOut(const std::string &deviceId, @@ -69,19 +69,17 @@ public: int32_t PrepareRemoteInput(const std::string &deviceId, DInputCallback callback); int32_t UnPrepareRemoteInput(const std::string &deviceId, DInputCallback callback); - int32_t RegisterEventCallback(MouseStateChangeCallback callback); - int32_t UnregisterEventCallback(MouseStateChangeCallback callback); - - bool IsTouchEventNeedFilterOut(uint32_t absX, uint32_t absY); + int32_t RegisterEventCallback(SimulateEventCallback callback); + int32_t UnregisterEventCallback(SimulateEventCallback callback); private: enum class CallbackType { StartDInputCallback, StartDInputCallbackDHIds, - StartDInputCallbackFds, + StartDInputCallbackSink, StopDInputCallback, StopDInputCallbackDHIds, - StopDInputCallbackFds, + StopDInputCallbackSink, PrepareStartDInputCallback, UnPrepareStopDInputCallback, PrepareStartDInputCallbackSink, @@ -93,57 +91,66 @@ private: int32_t timerId { 0 }; }; - class StartDInputCallback : public DistributedHardware::DistributedInput::StartDInputCallbackStub { + class StartDInputCallback final : public DistributedHardware::DistributedInput::StartDInputCallbackStub { public: void OnResult(const std::string &devId, const uint32_t &inputTypes, const int32_t &status) override; }; - class StopDInputCallback : public DistributedHardware::DistributedInput::StopDInputCallbackStub { + class StopDInputCallback final : public DistributedHardware::DistributedInput::StopDInputCallbackStub { public: void OnResult(const std::string &devId, const uint32_t &inputTypes, const int32_t &status) override; }; - class StartDInputCallbackDHIds : public DistributedHardware::DistributedInput::StartStopDInputsCallbackStub { + class StartDInputCallbackDHIds final : + public DistributedHardware::DistributedInput::StartStopDInputsCallbackStub { public: void OnResultDhids(const std::string &devId, const int32_t &status) override; }; - class StopDInputCallbackDHIds : public DistributedHardware::DistributedInput::StartStopDInputsCallbackStub { + class StopDInputCallbackDHIds final : + public DistributedHardware::DistributedInput::StartStopDInputsCallbackStub { public: void OnResultDhids(const std::string &devId, const int32_t &status) override; }; - class StartDInputCallbackFds : public DistributedHardware::DistributedInput::StartStopDInputsCallbackStub { + class StartDInputCallbackSink final : + public DistributedHardware::DistributedInput::StartStopDInputsCallbackStub { public: void OnResultDhids(const std::string &devId, const int32_t &status) override; }; - class StopDInputCallbackFds : public DistributedHardware::DistributedInput::StartStopDInputsCallbackStub { + class StopDInputCallbackSink final : + public DistributedHardware::DistributedInput::StartStopDInputsCallbackStub { public: void OnResultDhids(const std::string &devId, const int32_t &status) override; }; - class PrepareStartDInputCallback : public DistributedHardware::DistributedInput::PrepareDInputCallbackStub { + class PrepareStartDInputCallback final : + public DistributedHardware::DistributedInput::PrepareDInputCallbackStub { public: void OnResult(const std::string &devId, const int32_t &status) override; }; - class UnPrepareStopDInputCallback : public DistributedHardware::DistributedInput::UnprepareDInputCallbackStub { + class UnPrepareStopDInputCallback final : + public DistributedHardware::DistributedInput::UnprepareDInputCallbackStub { public: void OnResult(const std::string &devId, const int32_t &status) override; }; - class PrepareStartDInputCallbackSink : public DistributedHardware::DistributedInput::PrepareDInputCallbackStub { + class PrepareStartDInputCallbackSink final : + public DistributedHardware::DistributedInput::PrepareDInputCallbackStub { public: void OnResult(const std::string &devId, const int32_t &status) override; }; - class UnPrepareStopDInputCallbackSink : public DistributedHardware::DistributedInput::UnprepareDInputCallbackStub { + class UnPrepareStopDInputCallbackSink final : + public DistributedHardware::DistributedInput::UnprepareDInputCallbackStub { public: void OnResult(const std::string &devId, const int32_t &status) override; }; - class MouseStateChangeCallbackImpl : public DistributedHardware::DistributedInput::SimulationEventListenerStub { + class SimulateEventCallbackImpl final : + public DistributedHardware::DistributedInput::SimulationEventListenerStub { public: int32_t OnSimulationEvent(uint32_t type, uint32_t code, int32_t value) override; }; @@ -155,8 +162,8 @@ private: void OnSimulationEvent(uint32_t type, uint32_t code, int32_t value); std::map watchingMap_; std::map callbackMap_; - MouseStateChangeCallback mouseStateChangeCallback_ = { nullptr }; - sptr mouseListener_ { nullptr }; + SimulateEventCallback SimulateEventCallback_ = { nullptr }; + sptr simulationEventListener_ { nullptr }; std::mutex adapterLock_; }; diff --git a/service/input_device_cooperate/include/input_device_cooperate_sm.h b/service/input_device_cooperate/include/input_device_cooperate_sm.h index 240ec4afb06bf774d8f81548f6fca4ee561dfbd3..76c24d48dce53e71c8526efd5bae5b76cd7ad677 100755 --- a/service/input_device_cooperate/include/input_device_cooperate_sm.h +++ b/service/input_device_cooperate/include/input_device_cooperate_sm.h @@ -35,16 +35,16 @@ enum class CooperateState { }; enum class CooperateMsg { - COOPERATE_ON_SUCESS = 0, + COOPERATE_ON_SUCCESS = 0, COOPERATE_ON_FAIL = 1, - COOPERATE_OFF_SUCESS = 2, + COOPERATE_OFF_SUCCESS = 2, COOPERATE_OFF_FAIL = 3, COOPERATE_START = 4, - COOPERATE_START_SUCESS = 5, + COOPERATE_START_SUCCESS = 5, COOPERATE_START_FAIL = 6, COOPERATE_STOP = 7, - COOPERATE_STOP_SUCESS = 8, - COOPERATE_STOP_FIAL = 9, + COOPERATE_STOP_SUCCESS = 8, + COOPERATE_STOP_FAIL = 9, COOPERATE_NULL = 10, }; @@ -61,12 +61,15 @@ class InputDeviceCooperateSM final { void OnDeviceOffline(const DistributedHardware::DmDeviceInfo &deviceInfo) override; }; public: + using DelegateTasksCallback = std::function)>; DISALLOW_COPY_AND_MOVE(InputDeviceCooperateSM); - void Init(); - void EnableInputDeviceCooperate(bool enabled); + void Init(DelegateTasksCallback delegateTasksCallback, UDSServer &udsServer); + void EnableInputDeviceCooperate(bool enabled, int32_t pid); int32_t StartInputDeviceCooperate(const std::string &remoteNetworkId, int32_t startInputDeviceId); int32_t StopInputDeviceCooperate(); void GetCooperateState(const std::string &deviceId); + void SetVirtualKeyBoardDevId(int32_t deviceId); + int32_t GetVirtualKeyBoardDevId(); void StartRemoteCooperate(const std::string &remoteNetworkId); void StartRemoteCooperateResult(bool isSuccess, const std::string &startDhid, int32_t xPercent, int32_t yPercent); void StopRemoteCooperate(); @@ -88,21 +91,24 @@ public: void OnStopFinish(bool isSuccess, const std::string &remoteNetworkId); bool IsStarting() const; bool IsStopping() const; + void Reset(const std::string &networkId); void Dump(int32_t fd, const std::vector &args); + bool GetCooperateEnableState() const; private: + void OnSessionLost(SessionPtr session); void Reset(bool adjustAbsolutionLocation = false); void CheckPointerEvent(struct libinput_event *event); - bool CheckTouchEvent(struct libinput_event* event); void OnCloseCooperation(const std::string &networkId, bool isLocal); void NotifyRemoteStartFail(const std::string &remoteNetworkId); - void NotifyRemoteStartSucess(const std::string &remoteNetworkId, const std::string &startDhid); + void NotifyRemoteStartSuccess(const std::string &remoteNetworkId, const std::string &startDhid); void NotifyRemoteStopFinish(bool isSuccess, const std::string &remoteNetworkId); bool UpdateMouseLocation(); std::shared_ptr currentStateSM_ { nullptr }; std::pair preparedNetworkId_; std::string startDhid_ ; std::string srcNetworkId_; + int32_t virtualKeyBoardId_ { -1 }; CooperateState cooperateState_ { CooperateState::STATE_FREE }; std::shared_ptr initCallback_ { nullptr }; std::shared_ptr stateCallback_ { nullptr }; @@ -111,8 +117,12 @@ private: std::atomic isStarting_ { false }; std::atomic isStopping_ { false }; std::pair mouseLocation_ { std::make_pair(0, 0) }; + DelegateTasksCallback delegateTasksCallback_ { nullptr }; + bool isEnable_ { false }; + int32_t pid_ { -1 }; }; +#define DisHardware DistributedHardware::DeviceManager::GetInstance() #define InputDevCooSM ::OHOS::DelayedSingleton::GetInstance() } // namespace MMI } // namespace OHOS diff --git a/service/input_device_cooperate/include/input_device_cooperate_state_free.h b/service/input_device_cooperate/include/input_device_cooperate_state_free.h index b0903d701157da75bef46c10a0e3ab1193236109..01c2e358f8731f8dec22bf66889d319dad52247f 100755 --- a/service/input_device_cooperate/include/input_device_cooperate_state_free.h +++ b/service/input_device_cooperate/include/input_device_cooperate_state_free.h @@ -16,18 +16,17 @@ #ifndef INPUT_DEVICE_COOPERATE_STATE_FREE_H #define INPUT_DEVICE_COOPERATE_STATE_FREE_H -#include "distributed_input_adapter.h" #include "i_input_device_cooperate_state.h" namespace OHOS { namespace MMI { -class InputDeviceCooperateStateFree : public IInputDeviceCooperateState { +class InputDeviceCooperateStateFree final : public IInputDeviceCooperateState { public: - virtual int32_t StartInputDeviceCooperate(const std::string &remoteNetworkId, int32_t startInputDeviceId) override; + int32_t StartInputDeviceCooperate(const std::string &remoteNetworkId, int32_t startInputDeviceId) override; private: int32_t ProcessStart(const std::string &remoteNetworkId, int32_t startInputDeviceId); }; } // namespace MMI } // namespace OHOS -#endif // INPUT_DEVICE_COOPERATE_STATE_FREE_H \ No newline at end of file +#endif // INPUT_DEVICE_COOPERATE_STATE_FREE_H diff --git a/service/input_device_cooperate/include/input_device_cooperate_state_in.h b/service/input_device_cooperate/include/input_device_cooperate_state_in.h index 585c5d7c58e0191cc99f3b01cca471f64bb3623e..31ecf179b385115f49ca24d5436dfb56ff85fba4 100755 --- a/service/input_device_cooperate/include/input_device_cooperate_state_in.h +++ b/service/input_device_cooperate/include/input_device_cooperate_state_in.h @@ -20,11 +20,11 @@ namespace OHOS { namespace MMI { -class InputDeviceCooperateStateIn : public IInputDeviceCooperateState { +class InputDeviceCooperateStateIn final : public IInputDeviceCooperateState { public: explicit InputDeviceCooperateStateIn(const std::string &startDhid); - virtual int32_t StartInputDeviceCooperate(const std::string &remoteNetworkId, int32_t startInputDeviceId) override; - virtual int32_t StopInputDeviceCooperate(const std::string &networkId) override; + int32_t StartInputDeviceCooperate(const std::string &remoteNetworkId, int32_t startInputDeviceId) override; + int32_t StopInputDeviceCooperate(const std::string &networkId) override; private: void ComeBack(const std::string &sinkNetworkId, int32_t startInputDeviceId); diff --git a/service/input_device_cooperate/include/input_device_cooperate_state_out.h b/service/input_device_cooperate/include/input_device_cooperate_state_out.h index 663a405ce79e619bee425bd15297b1c9ba0f445c..871778bb516cfa8c9b9449a0d7c47907efcc5180 100755 --- a/service/input_device_cooperate/include/input_device_cooperate_state_out.h +++ b/service/input_device_cooperate/include/input_device_cooperate_state_out.h @@ -20,11 +20,11 @@ namespace OHOS { namespace MMI { -class InputDeviceCooperateStateOut : public IInputDeviceCooperateState { +class InputDeviceCooperateStateOut final : public IInputDeviceCooperateState { public: explicit InputDeviceCooperateStateOut(const std::string &startDhid); - virtual int32_t StopInputDeviceCooperate(const std::string &networkId) override; - virtual void OnKeyboardOnline(const std::string &dhid) override; + int32_t StopInputDeviceCooperate(const std::string &networkId) override; + void OnKeyboardOnline(const std::string &dhid) override; private: void OnStopRemoteInput(bool isSuccess, const std::string &srcNetworkId); diff --git a/frameworks/napi/distributed_input/src/js_register_module.cpp b/service/input_device_cooperate/include/input_device_cooperate_util.h similarity index 56% rename from frameworks/napi/distributed_input/src/js_register_module.cpp rename to service/input_device_cooperate/include/input_device_cooperate_util.h index 557cc59e3a2184ac2047e1b3c0ed381af0d5a959..334684a1ee53babdcf934bb0f6a2e0e64488ece6 100644 --- a/frameworks/napi/distributed_input/src/js_register_module.cpp +++ b/service/input_device_cooperate/include/input_device_cooperate_util.h @@ -12,26 +12,31 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#ifndef INPUT_DEVICE_COOPERATE_UTIL_H +#define INPUT_DEVICE_COOPERATE_UTIL_H -#include +#include -#include "js_input_dinput_context.h" +#include "cJSON.h" namespace OHOS { namespace MMI { -static napi_module mmiInputDInputModule = { - .nm_version = 1, - .nm_flags = 0, - .nm_filename = nullptr, - .nm_register_func = JsInputDinputContext::Export, - .nm_modname = "multimodalInput.distributedInput", - .nm_priv = ((void*)0), - .reserved = { 0 }, +struct JsonParser { + JsonParser() = default; + ~JsonParser() + { + if (json_ != nullptr) { + cJSON_Delete(json_); + json_ = nullptr; + } + } + operator cJSON *() + { + return json_; + } + cJSON *json_ { nullptr }; }; - -extern "C" __attribute__((constructor)) void RegisterModule(void) -{ - napi_module_register(&mmiInputDInputModule); -} -} -} +std::string GetLocalDeviceId(); +} // namespace MMI +} // namespace OHOS +#endif // INPUT_DEVICE_COOPERATE_UTIL_H diff --git a/service/input_device_cooperate/src/cooperate_event_handler.cpp b/service/input_device_cooperate/src/cooperate_event_handler.cpp index ae3884ac47491ea90956c529aa56cabea6b935c2..770ee9834ce54ff52e51c2948d58d327700e3a14 100755 --- a/service/input_device_cooperate/src/cooperate_event_handler.cpp +++ b/service/input_device_cooperate/src/cooperate_event_handler.cpp @@ -15,28 +15,35 @@ #include "cooperate_event_handler.h" +#include "mmi_log.h" + namespace OHOS { namespace MMI { +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "CooperateEventHandler" }; +} // namespace CooperateEventHandler::CooperateEventHandler( const std::shared_ptr &runner) : AppExecFwk::EventHandler(runner) { } -CooperateEventHandler::~CooperateEventHandler() = default; bool CooperateEventHandler::ProxyPostTask(const Callback &callback, int64_t delayTime) { + CALL_DEBUG_ENTER; return AppExecFwk::EventHandler::PostTask(callback, delayTime); } bool CooperateEventHandler::ProxyPostTask(const Callback &callback, const std::string &name, int64_t delayTime) { + CALL_DEBUG_ENTER; return AppExecFwk::EventHandler::PostTask(callback, name, delayTime); } void CooperateEventHandler::ProxyRemoveTask(const std::string &name) { + CALL_DEBUG_ENTER; AppExecFwk::EventHandler::RemoveTask(name); } } // namespace MMI diff --git a/service/input_device_cooperate/src/cooperate_event_manager.cpp b/service/input_device_cooperate/src/cooperate_event_manager.cpp index 8e3618fa7489ecf0edb7ea188e20f761a082eb94..3761868ad65a005c119d6e38bc88c9d682550b0b 100755 --- a/service/input_device_cooperate/src/cooperate_event_manager.cpp +++ b/service/input_device_cooperate/src/cooperate_event_manager.cpp @@ -20,7 +20,7 @@ namespace OHOS { namespace MMI { namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "CooperateEventManager"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "CooperateEventManager" }; } // namespace CooperateEventManager::CooperateEventManager() {} @@ -29,10 +29,10 @@ CooperateEventManager::~CooperateEventManager() {} void CooperateEventManager::AddCooperationEvent(sptr event) { CALL_DEBUG_ENTER; + std::lock_guard guard(lock_); if (event->type == EventType::LISTENER) { remoteCooperateCallbacks_.emplace_back(event); } else { - std::lock_guard guard(lock_); cooperateCallbacks_[event->type] = event; } } @@ -52,18 +52,20 @@ void CooperateEventManager::RemoveCooperationEvent(sptr event) } } -void CooperateEventManager::OnCooperateMessage(CooperationMessage msg, const std::string &deviceId) +int32_t CooperateEventManager::OnCooperateMessage(CooperationMessage msg, const std::string &deviceId) { CALL_DEBUG_ENTER; + std::lock_guard guard(lock_); if (remoteCooperateCallbacks_.empty()) { MMI_HILOGE("No listener, send cooperate message failed"); - return; + return RET_ERR; } for (auto it = remoteCooperateCallbacks_.begin(); it != remoteCooperateCallbacks_.end(); ++it) { sptr info = *it; CHKPC(info); NotifyCooperateMessage(info->sess, info->msgId, info->userData, deviceId, msg); } + return RET_OK; } void CooperateEventManager::OnEnable(CooperationMessage msg, const std::string &deviceId) @@ -148,4 +150,4 @@ void CooperateEventManager::NotifyCooperateState(SessionPtr sess, MmiMessageId m } } } // namespace MMI -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/service/input_device_cooperate/src/device_cooperate_softbus_adapter.cpp b/service/input_device_cooperate/src/device_cooperate_softbus_adapter.cpp new file mode 100755 index 0000000000000000000000000000000000000000..839a7e5edccc68df9f11c1555ead58e136aaf7fb --- /dev/null +++ b/service/input_device_cooperate/src/device_cooperate_softbus_adapter.cpp @@ -0,0 +1,504 @@ +/* + * 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. + */ + +#include "device_cooperate_softbus_adapter.h" + +#include +#include + +#include "softbus_bus_center.h" +#include "softbus_common.h" + +#include "config_multimodal.h" +#include "device_cooperate_softbus_define.h" +#include "input_device_cooperate_sm.h" +#include "input_device_cooperate_util.h" +#include "mmi_log.h" +#include "util.h" + +namespace OHOS { +namespace MMI { +namespace { +std::shared_ptr g_instance = nullptr; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "DeviceCooperateSoftbusAdapter" }; +constexpr int32_t DINPUT_LINK_TYPE_MAX = 4; +const SessionAttribute g_sessionAttr = { + .dataType = SessionType::TYPE_BYTES, + .linkTypeNum = DINPUT_LINK_TYPE_MAX, + .linkType = { + LINK_TYPE_WIFI_WLAN_2G, + LINK_TYPE_WIFI_WLAN_5G, + LINK_TYPE_WIFI_P2P, + LINK_TYPE_BR + } +}; + +void ResponseStartRemoteCooperate(int32_t sessionId, const JsonParser& parser) +{ + CALL_DEBUG_ENTER; + cJSON* deviceId = cJSON_GetObjectItemCaseSensitive(parser.json_, MMI_SOFTBUS_KEY_LOCAL_DEVICE_ID); + if (!cJSON_IsString(deviceId)) { + MMI_HILOGE("OnBytesReceived cmdType is TRANS_SINK_MSG_ONPREPARE, data type is error"); + return; + } + InputDevCooSM->StartRemoteCooperate(deviceId->valuestring); +} + +void ResponseStartRemoteCooperateResult(int32_t sessionId, const JsonParser& parser) +{ + CALL_DEBUG_ENTER; + cJSON* result = cJSON_GetObjectItemCaseSensitive(parser.json_, MMI_SOFTBUS_KEY_RESULT); + cJSON* dhid = cJSON_GetObjectItemCaseSensitive(parser.json_, MMI_SOFTBUS_KEY_START_DHID); + cJSON* x = cJSON_GetObjectItemCaseSensitive(parser.json_, MMI_SOFTBUS_KEY_POINTER_X); + cJSON* y = cJSON_GetObjectItemCaseSensitive(parser.json_, MMI_SOFTBUS_KEY_POINTER_Y); + if (!cJSON_IsBool(result) || !cJSON_IsString(dhid) || !cJSON_IsNumber(x) || !cJSON_IsNumber(y)) { + MMI_HILOGE("OnBytesReceived cmdType is TRANS_SINK_MSG_ONPREPARE, data type is error"); + return; + } + InputDevCooSM->StartRemoteCooperateResult(cJSON_IsTrue(result), dhid->valuestring, x->valueint, y->valueint); +} + +void ResponseStopRemoteCooperate(int32_t sessionId, const JsonParser& parser) +{ + InputDevCooSM->StopRemoteCooperate(); +} + +void ResponseStopRemoteCooperateResult(int32_t sessionId, const JsonParser& parser) +{ + CALL_DEBUG_ENTER; + cJSON* result = cJSON_GetObjectItemCaseSensitive(parser.json_, MMI_SOFTBUS_KEY_RESULT); + + if (!cJSON_IsBool(result)) { + MMI_HILOGE("OnBytesReceived cmdType is TRANS_SINK_MSG_ONPREPARE, data type is error"); + return; + } + InputDevCooSM->StopRemoteCooperateResult(cJSON_IsTrue(result)); +} + +void ResponseStartCooperateOtherResult(int32_t sessionId, const JsonParser& parser) +{ + CALL_DEBUG_ENTER; + cJSON* deviceId = cJSON_GetObjectItemCaseSensitive(parser.json_, MMI_SOFTBUS_KEY_OTHER_DEVICE_ID); + + if (!cJSON_IsString(deviceId)) { + MMI_HILOGE("OnBytesReceived cmdType is TRANS_SINK_MSG_ONPREPARE, data type is error"); + return; + } + InputDevCooSM->StartCooperateOtherResult(deviceId->valuestring); +} +} // namespace + +static int32_t SessionOpened(int32_t sessionId, int32_t result) +{ + return DevCooperateSoftbusAdapter->OnSessionOpened(sessionId, result); +} + +static void SessionClosed(int32_t sessionId) +{ + DevCooperateSoftbusAdapter->OnSessionClosed(sessionId); +} + +static void BytesReceived(int32_t sessionId, const void *data, uint32_t dataLen) +{ + DevCooperateSoftbusAdapter->OnBytesReceived(sessionId, data, dataLen); +} + +static void MessageReceived(int32_t sessionId, const void *data, uint32_t dataLen) +{ + (void)sessionId; + (void)data; + (void)dataLen; +} + +static void StreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext, + const StreamFrameInfo *param) +{ + (void)sessionId; + (void)data; + (void)ext; + (void)param; +} + +int32_t DeviceCooperateSoftbusAdapter::Init() +{ + CALL_INFO_TRACE; + sessListener_ = { + .OnSessionOpened = SessionOpened, + .OnSessionClosed = SessionClosed, + .OnBytesReceived = BytesReceived, + .OnMessageReceived = MessageReceived, + .OnStreamReceived = StreamReceived + }; + std::string networkId = GetLocalDeviceId(); + if (networkId.empty()) { + MMI_HILOGE("Local networkid is empty"); + return RET_ERR; + } + localSessionName_ = SESSION_NAME + networkId.substr(0, INTERCEPT_STRING_LENGTH); + int32_t ret = CreateSessionServer(MMI_DINPUT_PKG_NAME, localSessionName_.c_str(), &sessListener_); + if (ret != RET_OK) { + MMI_HILOGE("Create session server failed, error code:%{public}d", ret); + return RET_ERR; + } + return RET_OK; +} + +DeviceCooperateSoftbusAdapter::~DeviceCooperateSoftbusAdapter() +{ + Release(); +} + +void DeviceCooperateSoftbusAdapter::Release() +{ + CALL_INFO_TRACE; + std::unique_lock sessionLock(operationMutex_); + std::for_each(sessionDevMap_.begin(), sessionDevMap_.end(), [](auto item) { + CloseSession(item.second); + MMI_HILOGD("Close session success"); + }); + int32_t ret = RemoveSessionServer(MMI_DINPUT_PKG_NAME, localSessionName_.c_str()); + MMI_HILOGD("RemoveSessionServer ret:%{public}d", ret); + sessionDevMap_.clear(); + channelStatusMap_.clear(); +} + +bool DeviceCooperateSoftbusAdapter::CheckDeviceSessionState(const std::string &devId) +{ + std::unique_lock sessionLock(operationMutex_); + if (sessionDevMap_.find(devId) == sessionDevMap_.end()) { + MMI_HILOGE("Check session state error"); + return false; + } + return true; +} + +int32_t DeviceCooperateSoftbusAdapter::OpenInputSoftbus(const std::string &remoteDevId) +{ + CALL_INFO_TRACE; + if (CheckDeviceSessionState(remoteDevId)) { + MMI_HILOGD("Softbus session has already opened"); + return RET_OK; + } + + int32_t ret = Init(); + if (ret != RET_OK) { + MMI_HILOGE("Init failed"); + return RET_ERR; + } + + std::string peerSessionName = SESSION_NAME + remoteDevId.substr(0, INTERCEPT_STRING_LENGTH); + int32_t sessionId = OpenSession(localSessionName_.c_str(), peerSessionName.c_str(), remoteDevId.c_str(), + GROUP_ID.c_str(), &g_sessionAttr); + if (sessionId < 0) { + MMI_HILOGE("OpenSession failed"); + return RET_ERR; + } + return WaitSessionOpend(remoteDevId, sessionId); +} + +int32_t DeviceCooperateSoftbusAdapter::WaitSessionOpend(const std::string &remoteDevId, int32_t sessionId) +{ + CALL_INFO_TRACE; + std::unique_lock waitLock(operationMutex_); + sessionDevMap_[remoteDevId] = sessionId; + auto status = openSessionWaitCond_.wait_for(waitLock, std::chrono::seconds(SESSION_WAIT_TIMEOUT_SECOND), + [this, remoteDevId] () { return channelStatusMap_[remoteDevId]; }); + if (!status) { + MMI_HILOGE("OpenSession timeout"); + return RET_ERR; + } + channelStatusMap_[remoteDevId] = false; + return RET_OK; +} + +void DeviceCooperateSoftbusAdapter::CloseInputSoftbus(const std::string &remoteDevId) +{ + CALL_INFO_TRACE; + std::unique_lock sessionLock(operationMutex_); + if (sessionDevMap_.find(remoteDevId) == sessionDevMap_.end()) { + MMI_HILOGI("SessionDevIdMap not find"); + return; + } + int32_t sessionId = sessionDevMap_[remoteDevId]; + + CloseSession(sessionId); + sessionDevMap_.erase(remoteDevId); + channelStatusMap_.erase(remoteDevId); +} + +std::shared_ptr DeviceCooperateSoftbusAdapter::GetInstance() +{ + static std::once_flag flag; + std::call_once(flag, [&]() { + g_instance.reset(new (std::nothrow) DeviceCooperateSoftbusAdapter()); + }); + return g_instance; +} + + +int32_t DeviceCooperateSoftbusAdapter::StartRemoteCooperate(const std::string &localDeviceId, + const std::string &remoteDeviceId) +{ + CALL_DEBUG_ENTER; + std::unique_lock sessionLock(operationMutex_); + if (sessionDevMap_.find(remoteDeviceId) == sessionDevMap_.end()) { + MMI_HILOGE("Start remote cooperate error, not find this device"); + return RET_ERR; + } + int32_t sessionId = sessionDevMap_[remoteDeviceId]; + cJSON *jsonStr = cJSON_CreateObject(); + cJSON_AddItemToObject(jsonStr, MMI_SOFTBUS_KEY_CMD_TYPE, cJSON_CreateNumber(REMOTE_COOPERATE_START)); + cJSON_AddItemToObject(jsonStr, MMI_SOFTBUS_KEY_LOCAL_DEVICE_ID, cJSON_CreateString(localDeviceId.c_str())); + cJSON_AddItemToObject(jsonStr, MMI_SOFTBUS_KEY_SESSION_ID, cJSON_CreateNumber(sessionId)); + char *smsg = cJSON_Print(jsonStr); + cJSON_Delete(jsonStr); + int32_t ret = SendMsg(sessionId, smsg); + cJSON_free(smsg); + if (ret != RET_OK) { + MMI_HILOGE("Start remote cooperate send session msg failed, ret:%{public}d", ret); + return RET_ERR; + } + return RET_OK; +} + +int32_t DeviceCooperateSoftbusAdapter::StartRemoteCooperateResult(const std::string &remoteDeviceId, bool isSuccess, + const std::string &startDhid, int32_t xPercent, int32_t yPercent) +{ + CALL_DEBUG_ENTER; + std::unique_lock sessionLock(operationMutex_); + if (sessionDevMap_.find(remoteDeviceId) == sessionDevMap_.end()) { + MMI_HILOGE("Stop remote cooperate error, not find this device"); + return RET_ERR; + } + int32_t sessionId = sessionDevMap_[remoteDeviceId]; + cJSON *jsonStr = cJSON_CreateObject(); + cJSON_AddItemToObject(jsonStr, MMI_SOFTBUS_KEY_CMD_TYPE, cJSON_CreateNumber(REMOTE_COOPERATE_START_RES)); + cJSON_AddItemToObject(jsonStr, MMI_SOFTBUS_KEY_RESULT, cJSON_CreateBool(isSuccess)); + cJSON_AddItemToObject(jsonStr, MMI_SOFTBUS_KEY_START_DHID, cJSON_CreateString(startDhid.c_str())); + cJSON_AddItemToObject(jsonStr, MMI_SOFTBUS_KEY_POINTER_X, cJSON_CreateNumber(xPercent)); + cJSON_AddItemToObject(jsonStr, MMI_SOFTBUS_KEY_POINTER_Y, cJSON_CreateNumber(yPercent)); + cJSON_AddItemToObject(jsonStr, MMI_SOFTBUS_KEY_SESSION_ID, cJSON_CreateNumber(sessionId)); + char *smsg = cJSON_Print(jsonStr); + cJSON_Delete(jsonStr); + int32_t ret = SendMsg(sessionId, smsg); + cJSON_free(smsg); + if (ret != RET_OK) { + MMI_HILOGE("Start remote cooperate result send session msg failed"); + return RET_ERR; + } + return RET_OK; +} + +int32_t DeviceCooperateSoftbusAdapter::StopRemoteCooperate(const std::string &remoteDeviceId) +{ + CALL_DEBUG_ENTER; + std::unique_lock sessionLock(operationMutex_); + if (sessionDevMap_.find(remoteDeviceId) == sessionDevMap_.end()) { + MMI_HILOGE("Stop remote cooperate error, not find this device"); + return RET_ERR; + } + int32_t sessionId = sessionDevMap_[remoteDeviceId]; + cJSON *jsonStr = cJSON_CreateObject(); + cJSON_AddItemToObject(jsonStr, MMI_SOFTBUS_KEY_CMD_TYPE, cJSON_CreateNumber(REMOTE_COOPERATE_STOP)); + cJSON_AddItemToObject(jsonStr, MMI_SOFTBUS_KEY_SESSION_ID, cJSON_CreateNumber(sessionId)); + char *smsg = cJSON_Print(jsonStr); + cJSON_Delete(jsonStr); + int32_t ret = SendMsg(sessionId, smsg); + cJSON_free(smsg); + if (ret != RET_OK) { + MMI_HILOGE("Stop remote cooperate send session msg failed"); + return RET_ERR; + } + return RET_OK; +} + +int32_t DeviceCooperateSoftbusAdapter::StopRemoteCooperateResult(const std::string &remoteDeviceId, bool isSuccess) +{ + CALL_DEBUG_ENTER; + std::unique_lock sessionLock(operationMutex_); + if (sessionDevMap_.find(remoteDeviceId) == sessionDevMap_.end()) { + MMI_HILOGE("Stop remote cooperate result error, not find this device"); + return RET_ERR; + } + int32_t sessionId = sessionDevMap_[remoteDeviceId]; + cJSON *jsonStr = cJSON_CreateObject(); + cJSON_AddItemToObject(jsonStr, MMI_SOFTBUS_KEY_CMD_TYPE, cJSON_CreateNumber(REMOTE_COOPERATE_STOP_RES)); + cJSON_AddItemToObject(jsonStr, MMI_SOFTBUS_KEY_RESULT, cJSON_CreateBool(isSuccess)); + cJSON_AddItemToObject(jsonStr, MMI_SOFTBUS_KEY_SESSION_ID, cJSON_CreateNumber(sessionId)); + char *smsg = cJSON_Print(jsonStr); + cJSON_Delete(jsonStr); + int32_t ret = SendMsg(sessionId, smsg); + cJSON_free(smsg); + if (ret != RET_OK) { + MMI_HILOGE("Stop remote cooperate result send session msg failed"); + return RET_ERR; + } + return RET_OK; +} + +int32_t DeviceCooperateSoftbusAdapter::StartCooperateOtherResult(const std::string &remoteDeviceId, + const std::string &srcNetworkId) +{ + CALL_DEBUG_ENTER; + std::unique_lock sessionLock(operationMutex_); + if (sessionDevMap_.find(remoteDeviceId) == sessionDevMap_.end()) { + MMI_HILOGE("Start cooperate other result error, not find this device"); + return RET_ERR; + } + int32_t sessionId = sessionDevMap_[remoteDeviceId]; + cJSON *jsonStr = cJSON_CreateObject(); + cJSON_AddItemToObject(jsonStr, MMI_SOFTBUS_KEY_CMD_TYPE, cJSON_CreateNumber(REMOTE_COOPERATE_STOP_OTHER_RES)); + cJSON_AddItemToObject(jsonStr, MMI_SOFTBUS_KEY_OTHER_DEVICE_ID, cJSON_CreateString(srcNetworkId.c_str())); + cJSON_AddItemToObject(jsonStr, MMI_SOFTBUS_KEY_SESSION_ID, cJSON_CreateNumber(sessionId)); + char *smsg = cJSON_Print(jsonStr); + cJSON_Delete(jsonStr); + int32_t ret = SendMsg(sessionId, smsg); + cJSON_free(smsg); + if (ret != RET_OK) { + MMI_HILOGE("Start cooperate other result send session msg failed"); + return RET_ERR; + } + return RET_OK; +} + +void DeviceCooperateSoftbusAdapter::HandleSessionData(int32_t sessionId, const std::string& message) +{ + JsonParser parser; + parser.json_ = cJSON_Parse(message.c_str()); + if (!cJSON_IsObject(parser.json_)) { + MMI_HILOGE("Parser.json_ is not object"); + return; + } + cJSON* comType = cJSON_GetObjectItemCaseSensitive(parser.json_, MMI_SOFTBUS_KEY_CMD_TYPE); + if (!cJSON_IsNumber(comType)) { + MMI_HILOGE("OnBytesReceived cmdType is not number type"); + return; + } + MMI_HILOGD("valueint: %{public}d", comType->valueint); + switch (comType->valueint) { + case REMOTE_COOPERATE_START: { + ResponseStartRemoteCooperate(sessionId, parser); + break; + } + case REMOTE_COOPERATE_START_RES: { + ResponseStartRemoteCooperateResult(sessionId, parser); + break; + } + case REMOTE_COOPERATE_STOP: { + ResponseStopRemoteCooperate(sessionId, parser); + break; + } + case REMOTE_COOPERATE_STOP_RES: { + ResponseStopRemoteCooperateResult(sessionId, parser); + break; + } + case REMOTE_COOPERATE_STOP_OTHER_RES: { + ResponseStartCooperateOtherResult(sessionId, parser); + break; + } + default: { + MMI_HILOGE("OnBytesReceived cmdType is undefined"); + break; + } + } +} + +void DeviceCooperateSoftbusAdapter::OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen) +{ + MMI_HILOGD("dataLen:%{public}d", dataLen); + if (sessionId < 0 || data == nullptr || dataLen <= 0) { + MMI_HILOGE("Param check failed"); + return; + } + std::string message = std::string(static_cast(data), dataLen); + HandleSessionData(sessionId, message); +} + +int32_t DeviceCooperateSoftbusAdapter::SendMsg(int32_t sessionId, const std::string &message) +{ + CALL_DEBUG_ENTER; + if (message.size() > MSG_MAX_SIZE) { + MMI_HILOGW("error:message.size() > MSG_MAX_SIZE message size:%{public}zu", message.size()); + return RET_ERR; + } + return SendBytes(sessionId, message.c_str(), strlen(message.c_str())); +} + +std::string DeviceCooperateSoftbusAdapter::FindDevice(int32_t sessionId) +{ + std::unique_lock sessionLock(operationMutex_); + auto find_item = std::find_if(sessionDevMap_.begin(), sessionDevMap_.end(), + [sessionId](const std::map::value_type item) { + return item.second == sessionId; + }); + if (find_item == sessionDevMap_.end()) { + MMI_HILOGE("FindDevice error"); + return {}; + } + return find_item->first; +} + +int32_t DeviceCooperateSoftbusAdapter::OnSessionOpened(int32_t sessionId, int32_t result) +{ + CALL_INFO_TRACE; + char peerDevId[DEVICE_ID_SIZE_MAX] = {}; + int32_t getPeerDeviceIdResult = GetPeerDeviceId(sessionId, peerDevId, sizeof(peerDevId)); + MMI_HILOGD("Get peer device id ret:%{public}d", getPeerDeviceIdResult); + if (result != RET_OK) { + std::string deviceId = FindDevice(sessionId); + MMI_HILOGE("Session open failed result:%{public}d", result); + std::unique_lock sessionLock(operationMutex_); + if (sessionDevMap_.find(deviceId) != sessionDevMap_.end()) { + sessionDevMap_.erase(deviceId); + } + if (getPeerDeviceIdResult == RET_OK) { + channelStatusMap_[peerDevId] = true; + } + openSessionWaitCond_.notify_all(); + return RET_OK; + } + + int32_t sessionSide = GetSessionSide(sessionId); + MMI_HILOGI("session open succeed, sessionId:%{public}d, sessionSide:%{public}d(1 is client side)", + sessionId, sessionSide); + std::lock_guard notifyLock(operationMutex_); + if (sessionSide == SESSION_SIDE_SERVER) { + if (getPeerDeviceIdResult == RET_OK) { + sessionDevMap_[peerDevId] = sessionId; + } + } else { + if (getPeerDeviceIdResult == RET_OK) { + channelStatusMap_[peerDevId] = true; + } + openSessionWaitCond_.notify_all(); + } + return RET_OK; +} + +void DeviceCooperateSoftbusAdapter::OnSessionClosed(int32_t sessionId) +{ + CALL_DEBUG_ENTER; + std::string deviceId = FindDevice(sessionId); + std::unique_lock sessionLock(operationMutex_); + if (sessionDevMap_.find(deviceId) != sessionDevMap_.end()) { + sessionDevMap_.erase(deviceId); + } + if (GetSessionSide(sessionId) != 0) { + channelStatusMap_.erase(deviceId); + } + InputDevCooSM->Reset(deviceId); +} +} // namespace MMI +} // namespace OHOS diff --git a/service/input_device_cooperate/src/device_profile_adapter.cpp b/service/input_device_cooperate/src/device_profile_adapter.cpp index 543e214b0d67f95ab362c791afb79d6e2d990b4f..26c0cab82d2405942df6d666b1267d09d318b7b0 100755 --- a/service/input_device_cooperate/src/device_profile_adapter.cpp +++ b/service/input_device_cooperate/src/device_profile_adapter.cpp @@ -18,12 +18,9 @@ #include #include -#include "nlohmann/json.hpp" - #include "distributed_device_profile_client.h" +#include "input_device_cooperate_util.h" #include "service_characteristic_profile.h" -#include "softbus_bus_center.h" -#include "softbus_common.h" #include "sync_options.h" namespace OHOS { @@ -47,21 +44,28 @@ DeviceProfileAdapter::~DeviceProfileAdapter() int32_t DeviceProfileAdapter::UpdateCrossingSwitchState(bool state, const std::vector &deviceIds) { + CALL_INFO_TRACE; ServiceCharacteristicProfile profile; profile.SetServiceId(SERVICE_ID); profile.SetServiceType(SERVICE_TYPE); - nlohmann::json data; - data[CHARACTERISTICS_NAME] = state; - profile.SetCharacteristicProfileJson(data.dump()); + cJSON *data = cJSON_CreateObject(); + cJSON_AddItemToObject(data, CHARACTERISTICS_NAME.c_str(), cJSON_CreateBool(state)); + char *smsg = cJSON_Print(data); + cJSON_Delete(data); + profile.SetCharacteristicProfileJson(smsg); + cJSON_free(smsg); int32_t ret = DistributedDeviceProfileClient::GetInstance().PutDeviceProfile(profile); if (ret != 0) { - MMI_HILOGE("Put device profile failed"); + MMI_HILOGE("Put device profile failed, ret:%{public}d", ret); return ret; } SyncOptions syncOptions; std::for_each(deviceIds.begin(), deviceIds.end(), - [&syncOptions](auto &deviceId) { syncOptions.AddDevice(deviceId); }); + [&syncOptions](auto &deviceId) { + syncOptions.AddDevice(deviceId); + MMI_HILOGD("Add device success"); + }); auto syncCallback = std::make_shared(); ret = DistributedDeviceProfileClient::GetInstance().SyncDeviceProfile(syncOptions, syncCallback); @@ -73,26 +77,38 @@ int32_t DeviceProfileAdapter::UpdateCrossingSwitchState(bool state, const std::v int32_t DeviceProfileAdapter::UpdateCrossingSwitchState(bool state) { + CALL_INFO_TRACE; ServiceCharacteristicProfile profile; profile.SetServiceId(SERVICE_ID); profile.SetServiceType(SERVICE_TYPE); - nlohmann::json data; - data[CHARACTERISTICS_NAME] = state; - profile.SetCharacteristicProfileJson(data.dump()); + cJSON *data = cJSON_CreateObject(); + cJSON_AddItemToObject(data, CHARACTERISTICS_NAME.c_str(), cJSON_CreateBool(state)); + char *smsg = cJSON_Print(data); + cJSON_Delete(data); + profile.SetCharacteristicProfileJson(smsg); + cJSON_free(smsg); + return DistributedDeviceProfileClient::GetInstance().PutDeviceProfile(profile); } bool DeviceProfileAdapter::GetCrossingSwitchState(const std::string &deviceId) { + CALL_INFO_TRACE; ServiceCharacteristicProfile profile; DistributedDeviceProfileClient::GetInstance().GetDeviceProfile(deviceId, SERVICE_ID, profile); std::string jsonData = profile.GetCharacteristicProfileJson(); - nlohmann::json jsonObject = nlohmann::json::parse(jsonData, nullptr, false); - if (jsonObject.is_discarded()) { - MMI_HILOGE("JsonData is discarded"); + JsonParser parser; + parser.json_ = cJSON_Parse(jsonData.c_str()); + if (!cJSON_IsObject(parser.json_)) { + MMI_HILOGE("Parser.json_ is not object"); return false; } - return jsonObject[CHARACTERISTICS_NAME].get(); + cJSON* state = cJSON_GetObjectItemCaseSensitive(parser.json_, CHARACTERISTICS_NAME.c_str()); + if (!cJSON_IsBool(state)) { + MMI_HILOGE("State is not bool type"); + return false; + } + return cJSON_IsTrue(state); } int32_t DeviceProfileAdapter::RegisterCrossingStateListener(const std::string &deviceId, DPCallback callback) @@ -120,6 +136,7 @@ int32_t DeviceProfileAdapter::RegisterCrossingStateListener(const std::string &d int32_t DeviceProfileAdapter::UnregisterCrossingStateListener(const std::string &deviceId) { + CALL_INFO_TRACE; if (deviceId.empty()) { MMI_HILOGE("DeviceId is empty"); return RET_ERR; @@ -145,6 +162,7 @@ int32_t DeviceProfileAdapter::UnregisterCrossingStateListener(const std::string int32_t DeviceProfileAdapter::RegisterProfileListener(const std::string &deviceId) { + CALL_INFO_TRACE; std::list serviceIdList; serviceIdList.emplace_back(SERVICE_ID); ExtraInfo extraInfo; @@ -198,4 +216,4 @@ void DeviceProfileAdapter::ProfileEventCallbackImpl::OnSyncCompleted(const Devic }); } } // namespace MMI -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/service/input_device_cooperate/src/distributed_input_adapter.cpp b/service/input_device_cooperate/src/distributed_input_adapter.cpp index 798393c47ff199dd81527d59b59db6d5957ad4ff..b4d17f426272948cde833cb1440ccdf36221fa4b 100755 --- a/service/input_device_cooperate/src/distributed_input_adapter.cpp +++ b/service/input_device_cooperate/src/distributed_input_adapter.cpp @@ -26,39 +26,37 @@ namespace OHOS { namespace MMI { using namespace DistributedHardware::DistributedInput; namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "DistributedInputAdapter"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "DistributedInputAdapter" }; constexpr int32_t DEFAULT_DELAY_TIME = 4000; constexpr int32_t RETRY_TIME = 2; } // namespace DistributedInputAdapter::DistributedInputAdapter() { - mouseListener_ = new (std::nothrow) MouseStateChangeCallbackImpl(); - CHKPL(mouseListener_); - DistributedInputKit::RegisterSimulationEventListener(mouseListener_); + CALL_INFO_TRACE; + simulationEventListener_ = new (std::nothrow) SimulateEventCallbackImpl(); + CHKPL(simulationEventListener_); + DistributedInputKit::RegisterSimulationEventListener(simulationEventListener_); } DistributedInputAdapter::~DistributedInputAdapter() { + CALL_INFO_TRACE; std::lock_guard guard(adapterLock_); - DistributedInputKit::UnregisterSimulationEventListener(mouseListener_); - mouseListener_ = nullptr; + DistributedInputKit::UnregisterSimulationEventListener(simulationEventListener_); + simulationEventListener_ = nullptr; callbackMap_.clear(); } bool DistributedInputAdapter::IsNeedFilterOut(const std::string &deviceId, const BusinessEvent &event) { + CALL_INFO_TRACE; return DistributedInputKit::IsNeedFilterOut(deviceId, event); } -bool DistributedInputAdapter::IsTouchEventNeedFilterOut(uint32_t absX, uint32_t absY) -{ - TouchScreenEvent touchScreenEvent{ absX, absY }; - return DistributedInputKit::IsTouchEventNeedFilterOut(touchScreenEvent); -} - int32_t DistributedInputAdapter::StartRemoteInput(const std::string &deviceId, const std::vector &dhIds, DInputCallback callback) { + CALL_INFO_TRACE; sptr cb = new (std::nothrow) StartDInputCallbackDHIds(); CHKPR(cb, ERROR_NULL_POINTER); SaveCallback(CallbackType::StartDInputCallbackDHIds, callback); @@ -68,6 +66,7 @@ int32_t DistributedInputAdapter::StartRemoteInput(const std::string &deviceId, c int32_t DistributedInputAdapter::StartRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, DInputCallback callback) { + CALL_INFO_TRACE; sptr cb = new (std::nothrow) StartDInputCallback(); CHKPR(cb, ERROR_NULL_POINTER); SaveCallback(CallbackType::StartDInputCallback, callback); @@ -77,15 +76,17 @@ int32_t DistributedInputAdapter::StartRemoteInput(const std::string &srcId, cons int32_t DistributedInputAdapter::StartRemoteInput(const std::string &srcId, const std::string &sinkId, const std::vector &dhIds, DInputCallback callback) { - sptr cb = new (std::nothrow) StartDInputCallbackFds(); + CALL_INFO_TRACE; + sptr cb = new (std::nothrow) StartDInputCallbackSink(); CHKPR(cb, ERROR_NULL_POINTER); - SaveCallback(CallbackType::StartDInputCallbackFds, callback); + SaveCallback(CallbackType::StartDInputCallbackSink, callback); return DistributedInputKit::StartRemoteInput(srcId, sinkId, dhIds, cb); } int32_t DistributedInputAdapter::StopRemoteInput(const std::string &deviceId, const std::vector &dhIds, DInputCallback callback) { + CALL_INFO_TRACE; sptr cb = new (std::nothrow) StopDInputCallbackDHIds(); CHKPR(cb, ERROR_NULL_POINTER); SaveCallback(CallbackType::StopDInputCallbackDHIds, callback); @@ -95,6 +96,7 @@ int32_t DistributedInputAdapter::StopRemoteInput(const std::string &deviceId, co int32_t DistributedInputAdapter::StopRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, DInputCallback callback) { + CALL_INFO_TRACE; sptr cb = new (std::nothrow) StopDInputCallback(); CHKPR(cb, ERROR_NULL_POINTER); SaveCallback(CallbackType::StopDInputCallback, callback); @@ -104,15 +106,17 @@ int32_t DistributedInputAdapter::StopRemoteInput(const std::string &srcId, const int32_t DistributedInputAdapter::StopRemoteInput(const std::string &srcId, const std::string &sinkId, const std::vector &dhIds, DInputCallback callback) { - sptr cb = new (std::nothrow) StopDInputCallbackFds(); + CALL_INFO_TRACE; + sptr cb = new (std::nothrow) StopDInputCallbackSink(); CHKPR(cb, ERROR_NULL_POINTER); - SaveCallback(CallbackType::StopDInputCallbackFds, callback); + SaveCallback(CallbackType::StopDInputCallbackSink, callback); return DistributedInputKit::StopRemoteInput(srcId, sinkId, dhIds, cb); } int32_t DistributedInputAdapter::PrepareRemoteInput(const std::string &srcId, const std::string &sinkId, DInputCallback callback) { + CALL_INFO_TRACE; sptr cb = new (std::nothrow) PrepareStartDInputCallbackSink(); CHKPR(cb, ERROR_NULL_POINTER); SaveCallback(CallbackType::PrepareStartDInputCallbackSink, callback); @@ -122,6 +126,7 @@ int32_t DistributedInputAdapter::PrepareRemoteInput(const std::string &srcId, co int32_t DistributedInputAdapter::UnPrepareRemoteInput(const std::string &srcId, const std::string &sinkId, DInputCallback callback) { + CALL_INFO_TRACE; sptr cb = new (std::nothrow) UnPrepareStopDInputCallbackSink(); CHKPR(cb, ERROR_NULL_POINTER); SaveCallback(CallbackType::UnPrepareStopDInputCallbackSink, callback); @@ -130,6 +135,7 @@ int32_t DistributedInputAdapter::UnPrepareRemoteInput(const std::string &srcId, int32_t DistributedInputAdapter::PrepareRemoteInput(const std::string &deviceId, DInputCallback callback) { + CALL_INFO_TRACE; sptr cb = new (std::nothrow) PrepareStartDInputCallback(); CHKPR(cb, ERROR_NULL_POINTER); SaveCallback(CallbackType::PrepareStartDInputCallback, callback); @@ -138,24 +144,25 @@ int32_t DistributedInputAdapter::PrepareRemoteInput(const std::string &deviceId, int32_t DistributedInputAdapter::UnPrepareRemoteInput(const std::string &deviceId, DInputCallback callback) { + CALL_INFO_TRACE; sptr cb = new (std::nothrow) UnPrepareStopDInputCallback(); CHKPR(cb, ERROR_NULL_POINTER); SaveCallback(CallbackType::UnPrepareStopDInputCallback, callback); return DistributedInputKit::UnprepareRemoteInput(deviceId, cb); } -int32_t DistributedInputAdapter::RegisterEventCallback(MouseStateChangeCallback callback) +int32_t DistributedInputAdapter::RegisterEventCallback(SimulateEventCallback callback) { std::lock_guard guard(adapterLock_); CHKPR(callback, RET_ERR); - mouseStateChangeCallback_ = callback; + SimulateEventCallback_ = callback; return RET_OK; } -int32_t DistributedInputAdapter::UnregisterEventCallback(MouseStateChangeCallback callback) +int32_t DistributedInputAdapter::UnregisterEventCallback(SimulateEventCallback callback) { std::lock_guard guard(adapterLock_); CHKPR(callback, RET_ERR); - mouseStateChangeCallback_ = nullptr; + SimulateEventCallback_ = nullptr; return RET_OK; } @@ -217,8 +224,8 @@ void DistributedInputAdapter::ProcessDInputCallback(CallbackType type, int32_t s void DistributedInputAdapter::OnSimulationEvent(uint32_t type, uint32_t code, int32_t value) { std::lock_guard guard(adapterLock_); - CHKPV(mouseStateChangeCallback_); - mouseStateChangeCallback_(type, code, value); + CHKPV(SimulateEventCallback_); + SimulateEventCallback_(type, code, value); } void DistributedInputAdapter::StartDInputCallback::OnResult(const std::string &devId, const uint32_t &inputTypes, @@ -243,14 +250,14 @@ void DistributedInputAdapter::StopDInputCallbackDHIds::OnResultDhids(const std:: DistributedAdapter->ProcessDInputCallback(CallbackType::StopDInputCallbackDHIds, status); } -void DistributedInputAdapter::StartDInputCallbackFds::OnResultDhids(const std::string &devId, const int32_t &status) +void DistributedInputAdapter::StartDInputCallbackSink::OnResultDhids(const std::string &devId, const int32_t &status) { - DistributedAdapter->ProcessDInputCallback(CallbackType::StartDInputCallbackFds, status); + DistributedAdapter->ProcessDInputCallback(CallbackType::StartDInputCallbackSink, status); } -void DistributedInputAdapter::StopDInputCallbackFds::OnResultDhids(const std::string &devId, const int32_t &status) +void DistributedInputAdapter::StopDInputCallbackSink::OnResultDhids(const std::string &devId, const int32_t &status) { - DistributedAdapter->ProcessDInputCallback(CallbackType::StopDInputCallbackFds, status); + DistributedAdapter->ProcessDInputCallback(CallbackType::StopDInputCallbackSink, status); } void DistributedInputAdapter::PrepareStartDInputCallback::OnResult(const std::string &devId, const int32_t &status) @@ -273,7 +280,7 @@ void DistributedInputAdapter::UnPrepareStopDInputCallbackSink::OnResult(const st DistributedAdapter->ProcessDInputCallback(CallbackType::UnPrepareStopDInputCallbackSink, status); } -int32_t DistributedInputAdapter::MouseStateChangeCallbackImpl::OnSimulationEvent(uint32_t type, uint32_t code, +int32_t DistributedInputAdapter::SimulateEventCallbackImpl::OnSimulationEvent(uint32_t type, uint32_t code, int32_t value) { DistributedAdapter->OnSimulationEvent(type, code, value); diff --git a/service/input_device_cooperate/src/i_input_device_cooperate_state.cpp b/service/input_device_cooperate/src/i_input_device_cooperate_state.cpp index 1f2a9cbbff15ff96365aa1f287d8cef473443696..a29607ea9ff5f81254311397f304aa93871268da 100755 --- a/service/input_device_cooperate/src/i_input_device_cooperate_state.cpp +++ b/service/input_device_cooperate/src/i_input_device_cooperate_state.cpp @@ -24,7 +24,7 @@ namespace OHOS { namespace MMI { namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "IInputDeviceCooperateState"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "IInputDeviceCooperateState" }; } // namespace IInputDeviceCooperateState::IInputDeviceCooperateState() @@ -32,7 +32,6 @@ IInputDeviceCooperateState::IInputDeviceCooperateState() runner_ = AppExecFwk::EventRunner::Create(true); CHKPL(runner_); eventHandler_ = std::make_shared(runner_); - CHKPL(eventHandler_); } int32_t IInputDeviceCooperateState::PrepareAndStart(const std::string &srcNetworkId, int32_t startInputDeviceId) @@ -47,7 +46,7 @@ int32_t IInputDeviceCooperateState::PrepareAndStart(const std::string &srcNetwor this->OnPrepareDistributedInput(isSuccess, srcNetworkId, startInputDeviceId); }); if (ret != RET_OK) { - MMI_HILOGE("Prepare remoteNetworkId input fail"); + MMI_HILOGE("Prepare remote input fail"); InputDevCooSM->OnStartFinish(false, sinkNetworkId, startInputDeviceId); InputDevCooSM->UpdatePreparedDevices("", ""); } @@ -73,7 +72,7 @@ void IInputDeviceCooperateState::OnPrepareDistributedInput( std::function handleStartDinputFunc = std::bind(&IInputDeviceCooperateState::StartRemoteInput, this, startInputDeviceId); CHKPV(eventHandler_); - eventHandler_->PostTask(handleStartDinputFunc, taskName, 0, AppExecFwk::EventQueue::Priority::HIGH); + eventHandler_->ProxyPostTask(handleStartDinputFunc, taskName, 0); } } @@ -105,7 +104,7 @@ void IInputDeviceCooperateState::OnStartRemoteInput( std::function handleStartFinishFunc = std::bind(&InputDeviceCooperateSM::OnStartFinish, InputDevCooSM, isSuccess, srcNetworkId, startInputDeviceId); CHKPV(eventHandler_); - eventHandler_->PostTask(handleStartFinishFunc, taskName, 0, AppExecFwk::EventQueue::Priority::HIGH); + eventHandler_->ProxyPostTask(handleStartFinishFunc, taskName, 0); } bool IInputDeviceCooperateState::NeedPrepare(const std::string &srcNetworkId, const std::string &sinkNetworkId) diff --git a/service/input_device_cooperate/src/input_device_cooperate_sm.cpp b/service/input_device_cooperate/src/input_device_cooperate_sm.cpp old mode 100755 new mode 100644 index de4e98643f60aabb5661bb3be2c03e58cfd54db0..3a013cb6cf82abba995ceb7690367d3cabc35ba8 --- a/service/input_device_cooperate/src/input_device_cooperate_sm.cpp +++ b/service/input_device_cooperate/src/input_device_cooperate_sm.cpp @@ -12,33 +12,35 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include "input_device_cooperate_sm.h" #include +#include "device_manager.h" #include "hitrace_meter.h" #include "bytrace_adapter.h" #include "cooperate_event_manager.h" #include "cooperation_message.h" #include "define_multimodal.h" -#include "device_manager.h" +#include "device_cooperate_softbus_adapter.h" #include "device_profile_adapter.h" #include "i_pointer_drawing_manager.h" #include "input_device_cooperate_state_free.h" #include "input_device_cooperate_state_in.h" #include "input_device_cooperate_state_out.h" +#include "input_device_cooperate_util.h" #include "input_device_manager.h" +#include "input_windows_manager.h" +#include "key_auto_repeat.h" #include "mouse_event_normalize.h" -#include "multimodal_input_connect_remoter.h" #include "timer_manager.h" -#include "util_ex.h" namespace OHOS { namespace MMI { namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "InputDeviceCooperateSM"}; -const std::string BUNDLE_NAME = "ohos.multimodalinput.input"; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "InputDeviceCooperateSM" }; constexpr int32_t INTERVAL_MS = 2000; constexpr int32_t MOUSE_ABS_LOCATION = 100; constexpr int32_t MOUSE_ABS_LOCATION_X = 50; @@ -48,15 +50,55 @@ constexpr int32_t MOUSE_ABS_LOCATION_Y = 50; InputDeviceCooperateSM::InputDeviceCooperateSM() {} InputDeviceCooperateSM::~InputDeviceCooperateSM() {} -void InputDeviceCooperateSM::Init() +void InputDeviceCooperateSM::Init(DelegateTasksCallback delegateTasksCallback, UDSServer &udsServer) { + CALL_INFO_TRACE; + CHKPL(delegateTasksCallback); + delegateTasksCallback_ = delegateTasksCallback; preparedNetworkId_ = std::make_pair("", ""); + udsServer.AddSessionDeletedCallback(std::bind( + &InputDeviceCooperateSM::OnSessionLost, this, std::placeholders::_1)); currentStateSM_ = std::make_shared(); + DevCooperateSoftbusAdapter->Init(); TimerMgr->AddTimer(INTERVAL_MS, 1, [this]() { this->InitDeviceManager(); }); } +void InputDeviceCooperateSM::OnSessionLost(SessionPtr session) +{ + CALL_INFO_TRACE; + CHKPV(session); + int32_t pid = session->GetPid(); + MMI_HILOGD("pid:%{public}d, pid_:%{public}d", pid, pid_); + if (pid == pid_) { + isEnable_ = false; + pid_ = -1; + } +} + +void InputDeviceCooperateSM::Reset(const std::string &networkId) +{ + CALL_INFO_TRACE; + std::lock_guard guard(mutex_); + bool needReset = true; + if (cooperateState_ == CooperateState::STATE_OUT) { + if (networkId != srcNetworkId_) { + needReset = false; + } + } + if (cooperateState_ == CooperateState::STATE_IN) { + std::string sinkNetwoekId = InputDevMgr->GetOriginNetworkId(startDhid_); + if (networkId != sinkNetwoekId) { + needReset = false; + } + } + if (needReset) { + preparedNetworkId_ = std::make_pair("", ""); + Reset(true); + } +} + void InputDeviceCooperateSM::Reset(bool adjustAbsolutionLocation) { CALL_INFO_TRACE; @@ -77,6 +119,8 @@ void InputDeviceCooperateSM::Reset(bool adjustAbsolutionLocation) void InputDeviceCooperateSM::OnCooperateChanged(const std::string &networkId, bool isOpen) { CALL_DEBUG_ENTER; + CooperationMessage msg = isOpen ? CooperationMessage::STATE_ON : CooperationMessage::STATE_OFF; + delegateTasksCallback_(std::bind(&CooperateEventManager::OnCooperateMessage, CooperateEventMgr, msg, networkId)); if (!isOpen) { OnCloseCooperation(networkId, false); } @@ -88,6 +132,13 @@ void InputDeviceCooperateSM::OnCloseCooperation(const std::string &networkId, bo std::lock_guard guard(mutex_); if (!preparedNetworkId_.first.empty() && !preparedNetworkId_.second.empty()) { if (networkId == preparedNetworkId_.first || networkId == preparedNetworkId_.second) { + if (cooperateState_ != CooperateState::STATE_FREE) { + auto dhids = InputDevMgr->GetCooperateDhids(startDhid_); + DistributedAdapter->StopRemoteInput(preparedNetworkId_.first, preparedNetworkId_.second, + dhids, [](bool isSuccess) { + MMI_HILOGI("Failed to stop remote"); + }); + } DistributedAdapter->UnPrepareRemoteInput(preparedNetworkId_.first, preparedNetworkId_.second, [](bool isSuccess) {}); } @@ -106,6 +157,17 @@ void InputDeviceCooperateSM::OnCloseCooperation(const std::string &networkId, bo } } +void InputDeviceCooperateSM::SetVirtualKeyBoardDevId(int32_t deviceId) +{ + virtualKeyBoardId_ = deviceId; + MMI_HILOGI("virtualKeyBoardId_ has been set to%{public}d", virtualKeyBoardId_); +} + +int32_t InputDeviceCooperateSM::GetVirtualKeyBoardDevId() +{ + return virtualKeyBoardId_; +} + void InputDeviceCooperateSM::GetCooperateState(const std::string &deviceId) { CALL_INFO_TRACE; @@ -113,7 +175,12 @@ void InputDeviceCooperateSM::GetCooperateState(const std::string &deviceId) CooperateEventMgr->OnGetState(state); } -void InputDeviceCooperateSM::EnableInputDeviceCooperate(bool enabled) +bool InputDeviceCooperateSM::GetCooperateEnableState() const +{ + return isEnable_; +} + +void InputDeviceCooperateSM::EnableInputDeviceCooperate(bool enabled, int32_t pid) { CALL_INFO_TRACE; if (enabled) { @@ -122,10 +189,11 @@ void InputDeviceCooperateSM::EnableInputDeviceCooperate(bool enabled) BytraceAdapter::StartBytrace(BytraceAdapter::TRACE_STOP, BytraceAdapter::START_EVENT); } else { DProfileAdapter->UpdateCrossingSwitchState(enabled, onlineDevice_); - std::string localNetworkId; - InputDevMgr->GetLocalDeviceId(localNetworkId); + std::string localNetworkId = GetLocalDeviceId(); OnCloseCooperation(localNetworkId, true); } + isEnable_ = enabled; + pid_ = pid; } int32_t InputDeviceCooperateSM::StartInputDeviceCooperate( @@ -140,6 +208,7 @@ int32_t InputDeviceCooperateSM::StartInputDeviceCooperate( CHKPR(currentStateSM_, ERROR_NULL_POINTER); BytraceAdapter::StartBytrace(BytraceAdapter::TRACE_START, BytraceAdapter::LAUNCH_EVENT); isStarting_ = true; + DevCooperateSoftbusAdapter->OpenInputSoftbus(remoteNetworkId); int32_t ret = currentStateSM_->StartInputDeviceCooperate(remoteNetworkId, startInputDeviceId); if (ret != RET_OK) { MMI_HILOGE("Start remote input fail"); @@ -184,8 +253,10 @@ int32_t InputDeviceCooperateSM::StopInputDeviceCooperate() void InputDeviceCooperateSM::StartRemoteCooperate(const std::string &remoteNetworkId) { CALL_INFO_TRACE; - CooperateEventMgr->OnCooperateMessage(CooperationMessage::INFO_START, remoteNetworkId); std::lock_guard guard(mutex_); + CHKPV(delegateTasksCallback_); + delegateTasksCallback_(std::bind(&CooperateEventManager::OnCooperateMessage, + CooperateEventMgr, CooperationMessage::INFO_START, remoteNetworkId)); isStarting_ = true; } @@ -200,8 +271,9 @@ void InputDeviceCooperateSM::StartRemoteCooperateResult(bool isSuccess, } startDhid_ = startDhid; CooperationMessage msg = - isSuccess ? CooperationMessage::INFO_SUCCESS : CooperationMessage::COOPERATE_FAIL; - CooperateEventMgr->OnCooperateMessage(msg); + isSuccess ? CooperationMessage::INFO_SUCCESS : CooperationMessage::INFO_FAIL; + delegateTasksCallback_(std::bind(&CooperateEventManager::OnCooperateMessage, CooperateEventMgr, msg, "")); + if (!isSuccess || cooperateState_ == CooperateState::STATE_IN) { isStarting_ = false; return; @@ -209,6 +281,7 @@ void InputDeviceCooperateSM::StartRemoteCooperateResult(bool isSuccess, if (cooperateState_ == CooperateState::STATE_FREE) { MouseEventHdr->SetAbsolutionLocation(MOUSE_ABS_LOCATION - xPercent, yPercent); UpdateState(CooperateState::STATE_IN); + InputDevMgr->NotifyVirtualKeyBoardStatus(GetVirtualKeyBoardDevId(), true); } if (cooperateState_ == CooperateState::STATE_OUT) { MouseEventHdr->SetAbsolutionLocation(MOUSE_ABS_LOCATION - xPercent, yPercent); @@ -220,7 +293,6 @@ void InputDeviceCooperateSM::StartRemoteCooperateResult(bool isSuccess, void InputDeviceCooperateSM::StopRemoteCooperate() { CALL_INFO_TRACE; - CooperateEventMgr->OnCooperateMessage(CooperationMessage::STOP); std::lock_guard guard(mutex_); isStopping_ = true; } @@ -233,12 +305,10 @@ void InputDeviceCooperateSM::StopRemoteCooperateResult(bool isSuccess) MMI_HILOGI("Not in stopping"); return; } - CooperationMessage msg = - isSuccess ? CooperationMessage::STOP_SUCCESS : CooperationMessage::COOPERATE_FAIL; - CooperateEventMgr->OnCooperateMessage(msg); if (isSuccess) { Reset(true); } + KeyRepeat->RemoveTimer(); isStopping_ = false; } @@ -265,15 +335,17 @@ void InputDeviceCooperateSM::OnStartFinish(bool isSuccess, NotifyRemoteStartFail(remoteNetworkId); } else { startDhid_ = InputDevMgr->GetDhid(startInputDeviceId); - NotifyRemoteStartSucess(remoteNetworkId, startDhid_); + NotifyRemoteStartSuccess(remoteNetworkId, startDhid_); if (cooperateState_ == CooperateState::STATE_FREE) { UpdateState(CooperateState::STATE_OUT); } else if (cooperateState_ == CooperateState::STATE_IN) { std::string sink = InputDevMgr->GetOriginNetworkId(startInputDeviceId); if (!sink.empty() && remoteNetworkId != sink) { - RemoteMgr->StartCooperateOtherResult(sink, remoteNetworkId); + DevCooperateSoftbusAdapter->StartCooperateOtherResult(sink, remoteNetworkId); } UpdateState(CooperateState::STATE_FREE); + InputDevMgr->NotifyVirtualKeyBoardStatus(GetVirtualKeyBoardDevId(), false); + KeyRepeat->RemoveTimer(); } else { MMI_HILOGI("Current state is out"); } @@ -301,20 +373,21 @@ void InputDeviceCooperateSM::OnStopFinish(bool isSuccess, const std::string &rem MMI_HILOGI("Current state is free"); } } + DevCooperateSoftbusAdapter->CloseInputSoftbus(remoteNetworkId); isStopping_ = false; } void InputDeviceCooperateSM::NotifyRemoteStartFail(const std::string &remoteNetworkId) { CALL_DEBUG_ENTER; - RemoteMgr->StartRemoteCooperateResult(remoteNetworkId, false, "", 0, 0); - CooperateEventMgr->OnStart(CooperationMessage::COOPERATE_FAIL); + DevCooperateSoftbusAdapter->StartRemoteCooperateResult(remoteNetworkId, false, "", 0, 0); + CooperateEventMgr->OnStart(CooperationMessage::INFO_FAIL); } -void InputDeviceCooperateSM::NotifyRemoteStartSucess(const std::string &remoteNetworkId, const std::string& startDhid) +void InputDeviceCooperateSM::NotifyRemoteStartSuccess(const std::string &remoteNetworkId, const std::string& startDhid) { CALL_DEBUG_ENTER; - RemoteMgr->StartRemoteCooperateResult(remoteNetworkId, + DevCooperateSoftbusAdapter->StartRemoteCooperateResult(remoteNetworkId, true, startDhid, mouseLocation_.first, mouseLocation_.second); CooperateEventMgr->OnStart(CooperationMessage::INFO_SUCCESS); } @@ -322,7 +395,7 @@ void InputDeviceCooperateSM::NotifyRemoteStartSucess(const std::string &remoteNe void InputDeviceCooperateSM::NotifyRemoteStopFinish(bool isSuccess, const std::string &remoteNetworkId) { CALL_DEBUG_ENTER; - RemoteMgr->StopRemoteCooperateResult(remoteNetworkId, isSuccess); + DevCooperateSoftbusAdapter->StopRemoteCooperateResult(remoteNetworkId, isSuccess); if (!isSuccess) { CooperateEventMgr->OnStop(CooperationMessage::COOPERATE_FAIL); } else { @@ -334,7 +407,7 @@ bool InputDeviceCooperateSM::UpdateMouseLocation() { CALL_DEBUG_ENTER; auto pointerEvent = MouseEventHdr->GetPointerEvent(); - CHKPR(pointerEvent, false); + CHKPF(pointerEvent); int32_t displayId = pointerEvent->GetTargetDisplayId(); auto displayGroupInfo = WinMgr->GetDisplayGroupInfo(); struct DisplayInfo physicalDisplayInfo; @@ -347,7 +420,7 @@ bool InputDeviceCooperateSM::UpdateMouseLocation() int32_t displayWidth = physicalDisplayInfo.width; int32_t displayHeight = physicalDisplayInfo.height; if (displayWidth == 0 || displayHeight == 0) { - MMI_HILOGE("diaplay width or height is 0"); + MMI_HILOGE("display width or height is 0"); return false; } auto mouseInfo = WinMgr->GetMouseInfo(); @@ -399,7 +472,6 @@ void InputDeviceCooperateSM::UpdatePreparedDevices(const std::string &srcNetwork std::pair InputDeviceCooperateSM::GetPreparedDevices() const { CALL_DEBUG_ENTER; - std::lock_guard guard(mutex_); return preparedNetworkId_; } @@ -512,35 +584,17 @@ void InputDeviceCooperateSM::CheckPointerEvent(struct libinput_event *event) inputEventNormalizeHandler->HandleEvent(event); } -bool InputDeviceCooperateSM::CheckTouchEvent(struct libinput_event* event) -{ - CALL_INFO_TRACE; - CHKPF(event); - auto device = libinput_event_get_device(event); - int32_t deviceId = InputDevMgr->FindInputDeviceId(device); - std::string dhid = InputDevMgr->GetDhid(deviceId); - auto touchEvent = libinput_event_get_touch_event(event); - CHKPF(touchEvent); - uint32_t absX = static_cast(libinput_event_touch_get_x(touchEvent)); - uint32_t absY = static_cast(libinput_event_touch_get_y(touchEvent)); - MMI_HILOGI("Check touch event absX:%{public}d, absY:%{public}d", absX, absY); - return DistributedAdapter->IsTouchEventNeedFilterOut(absX, absY); -} - bool InputDeviceCooperateSM::InitDeviceManager() { CALL_DEBUG_ENTER; initCallback_ = std::make_shared(); - CHKPR(initCallback_, false); - int32_t ret = - DistributedHardware::DeviceManager::GetInstance().InitDeviceManager(BUNDLE_NAME, initCallback_); + int32_t ret = DisHardware.InitDeviceManager(MMI_DINPUT_PKG_NAME, initCallback_); if (ret != 0) { MMI_HILOGE("Init device manager failed, ret:%{public}d", ret); return false; } stateCallback_ = std::make_shared(); - ret = - DistributedHardware::DeviceManager::GetInstance().RegisterDevStateCallback(BUNDLE_NAME, "", stateCallback_); + ret = DisHardware.RegisterDevStateCallback(MMI_DINPUT_PKG_NAME, "", stateCallback_); if (ret != 0) { MMI_HILOGE("Register devStateCallback failed, ret:%{public}d", ret); return false; @@ -548,7 +602,7 @@ bool InputDeviceCooperateSM::InitDeviceManager() return true; } -void InputDeviceCooperateSM::OnDeviceOnline(const std::string& networkId) +void InputDeviceCooperateSM::OnDeviceOnline(const std::string &networkId) { CALL_INFO_TRACE; std::lock_guard guard(mutex_); @@ -558,30 +612,12 @@ void InputDeviceCooperateSM::OnDeviceOnline(const std::string& networkId) InputDevCooSM, std::placeholders::_1, std::placeholders::_2)); } -void InputDeviceCooperateSM::OnDeviceOffline(const std::string& networkId) +void InputDeviceCooperateSM::OnDeviceOffline(const std::string &networkId) { CALL_INFO_TRACE; - std::lock_guard guard(mutex_); DProfileAdapter->UnregisterCrossingStateListener(networkId); - bool needReset = true; - if (cooperateState_ == CooperateState::STATE_OUT) { - if (networkId != srcNetworkId_) { - needReset = false; - MMI_HILOGE("OnDeviceOffline: needReset false"); - } - } - if (cooperateState_ == CooperateState::STATE_IN) { - std::string sinkNetwoekId = InputDevMgr->GetOriginNetworkId(startDhid_); - if (networkId != sinkNetwoekId) { - needReset = false; - MMI_HILOGE("OnDeviceOffline: needReset false"); - } - } - if (needReset) { - MMI_HILOGE("OnDeviceOffline: needReset true"); - preparedNetworkId_ = std::make_pair("", ""); - Reset(true); - } + Reset(networkId); + std::lock_guard guard(mutex_); if (!onlineDevice_.empty()) { auto it = std::find(onlineDevice_.begin(), onlineDevice_.end(), networkId); if (it != onlineDevice_.end()) { @@ -590,18 +626,6 @@ void InputDeviceCooperateSM::OnDeviceOffline(const std::string& networkId) } } -void InputDeviceCooperateSM::Dump(int32_t fd, const std::vector &args) -{ - CALL_DEBUG_ENTER; - std::lock_guard guard(mutex_); - mprintf(fd, "Keyboard and mouse crossing information:"); - mprintf(fd, "State machine status: %d\t", cooperateState_); - mprintf(fd, "Peripheral keyboard and mouse information: startDhid_ srcNetworkId_:\t"); - mprintf(fd, "%s", startDhid_.c_str()); - mprintf(fd, "%s", srcNetworkId_.c_str()); - mprintf(fd, "Run successfully"); -} - void InputDeviceCooperateSM::DeviceInitCallBack::OnRemoteDied() { CALL_INFO_TRACE; @@ -617,7 +641,7 @@ void InputDeviceCooperateSM::MmiDeviceStateCallback::OnDeviceOnline( void InputDeviceCooperateSM::MmiDeviceStateCallback::OnDeviceOffline( const DistributedHardware::DmDeviceInfo &deviceInfo) { - CALL_DEBUG_ENTER; + CALL_INFO_TRACE; InputDevCooSM->OnDeviceOffline(deviceInfo.deviceId); } diff --git a/service/input_device_cooperate/src/input_device_cooperate_state_free.cpp b/service/input_device_cooperate/src/input_device_cooperate_state_free.cpp index 302f2d85a9ebbdfb4f134d679c62d4cb22e0cda6..d90d5081b0abe549b5ee32e203fd15fb65eff190 100755 --- a/service/input_device_cooperate/src/input_device_cooperate_state_free.cpp +++ b/service/input_device_cooperate/src/input_device_cooperate_state_free.cpp @@ -15,15 +15,14 @@ #include "input_device_cooperate_state_free.h" +#include "device_cooperate_softbus_adapter.h" #include "input_device_cooperate_sm.h" -#include "input_device_manager.h" -#include "mouse_event_normalize.h" -#include "multimodal_input_connect_remoter.h" +#include "input_device_cooperate_util.h" namespace OHOS { namespace MMI { namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "InputDeviceCooperateStateFree"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "InputDeviceCooperateStateFree" }; } // namespace int32_t InputDeviceCooperateStateFree::StartInputDeviceCooperate( @@ -34,13 +33,12 @@ int32_t InputDeviceCooperateStateFree::StartInputDeviceCooperate( MMI_HILOGE("RemoteNetworkId is empty"); return static_cast(CooperationMessage::COOPERATION_DEVICE_ERROR); } - std::string localNetworkId; - InputDevMgr->GetLocalDeviceId(localNetworkId); + std::string localNetworkId = GetLocalDeviceId(); if (localNetworkId.empty() || remoteNetworkId == localNetworkId) { MMI_HILOGE("Input Parameters error"); return static_cast(CooperationMessage::COOPERATION_DEVICE_ERROR); } - int32_t ret = RemoteMgr->StartRemoteCooperate(localNetworkId, remoteNetworkId); + int32_t ret = DevCooperateSoftbusAdapter->StartRemoteCooperate(localNetworkId, remoteNetworkId); if (ret != RET_OK) { MMI_HILOGE("Start input device cooperate fail"); return static_cast(CooperationMessage::COOPERATE_FAIL); @@ -49,7 +47,7 @@ int32_t InputDeviceCooperateStateFree::StartInputDeviceCooperate( std::function handleProcessStartFunc = std::bind(&InputDeviceCooperateStateFree::ProcessStart, this, remoteNetworkId, startInputDeviceId); CHKPR(eventHandler_, RET_ERR); - eventHandler_->PostTask(handleProcessStartFunc, taskName, 0, AppExecFwk::EventQueue::Priority::HIGH); + eventHandler_->ProxyPostTask(handleProcessStartFunc, taskName, 0); return RET_OK; } diff --git a/service/input_device_cooperate/src/input_device_cooperate_state_in.cpp b/service/input_device_cooperate/src/input_device_cooperate_state_in.cpp index 1fa453f27a0d11cb6fd8e6d21e3d84577b75e8f4..401ae77f3d75b5ecd33716d3bf0ad59d71cd52f6 100755 --- a/service/input_device_cooperate/src/input_device_cooperate_state_in.cpp +++ b/service/input_device_cooperate/src/input_device_cooperate_state_in.cpp @@ -16,16 +16,17 @@ #include "input_device_cooperate_state_in.h" #include "cooperation_message.h" +#include "device_cooperate_softbus_adapter.h" #include "distributed_input_adapter.h" #include "input_device_cooperate_sm.h" +#include "input_device_cooperate_util.h" #include "input_device_manager.h" #include "mouse_event_normalize.h" -#include "multimodal_input_connect_remoter.h" namespace OHOS { namespace MMI { namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "InputDeviceCooperateStateIn"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "InputDeviceCooperateStateIn" }; } // namespace InputDeviceCooperateStateIn::InputDeviceCooperateStateIn(const std::string &startDhid) : startDhid_(startDhid) {} @@ -38,13 +39,12 @@ int32_t InputDeviceCooperateStateIn::StartInputDeviceCooperate(const std::string MMI_HILOGE("RemoteNetworkId is empty"); return static_cast(CooperationMessage::COOPERATION_DEVICE_ERROR); } - std::string localNetworkId; - InputDevMgr->GetLocalDeviceId(localNetworkId); + std::string localNetworkId = GetLocalDeviceId(); if (localNetworkId.empty() || remoteNetworkId == localNetworkId) { MMI_HILOGE("Input Parameters error"); return static_cast(CooperationMessage::COOPERATION_DEVICE_ERROR); } - int32_t ret = RemoteMgr->StartRemoteCooperate(localNetworkId, remoteNetworkId); + int32_t ret = DevCooperateSoftbusAdapter->StartRemoteCooperate(localNetworkId, remoteNetworkId); if (ret != RET_OK) { MMI_HILOGE("Start input device cooperate fail"); return static_cast(CooperationMessage::COOPERATE_FAIL); @@ -53,7 +53,7 @@ int32_t InputDeviceCooperateStateIn::StartInputDeviceCooperate(const std::string std::function handleProcessStartFunc = std::bind(&InputDeviceCooperateStateIn::ProcessStart, this, remoteNetworkId, startInputDeviceId); CHKPR(eventHandler_, RET_ERR); - eventHandler_->PostTask(handleProcessStartFunc, taskName, 0, AppExecFwk::EventQueue::Priority::HIGH); + eventHandler_->ProxyPostTask(handleProcessStartFunc, taskName, 0); return RET_OK; } @@ -72,7 +72,7 @@ int32_t InputDeviceCooperateStateIn::ProcessStart(const std::string &remoteNetwo int32_t InputDeviceCooperateStateIn::StopInputDeviceCooperate(const std::string &networkId) { CALL_DEBUG_ENTER; - int32_t ret = RemoteMgr->StopRemoteCooperate(networkId); + int32_t ret = DevCooperateSoftbusAdapter->StopRemoteCooperate(networkId); if (ret != RET_OK) { MMI_HILOGE("Stop input device cooperate fail"); return ret; @@ -80,7 +80,7 @@ int32_t InputDeviceCooperateStateIn::StopInputDeviceCooperate(const std::string std::string taskName = "process_stop_task"; std::function handleProcessStopFunc = std::bind(&InputDeviceCooperateStateIn::ProcessStop, this); CHKPR(eventHandler_, RET_ERR); - eventHandler_->PostTask(handleProcessStopFunc, taskName, 0, AppExecFwk::EventQueue::Priority::HIGH); + eventHandler_->ProxyPostTask(handleProcessStopFunc, taskName, 0); return RET_OK; } @@ -112,7 +112,7 @@ void InputDeviceCooperateStateIn::OnStartRemoteInput( std::function handleRelayStopFunc = std::bind(&InputDeviceCooperateStateIn::StopRemoteInput, this, sinkNetworkId, srcNetworkId, dhid, startInputDeviceId); CHKPV(eventHandler_); - eventHandler_->PostTask(handleRelayStopFunc, taskName, 0, AppExecFwk::EventQueue::Priority::HIGH); + eventHandler_->ProxyPostTask(handleRelayStopFunc, taskName, 0); } void InputDeviceCooperateStateIn::StopRemoteInput(const std::string &sinkNetworkId, @@ -136,13 +136,13 @@ void InputDeviceCooperateStateIn::OnStopRemoteInput(bool isSuccess, std::function handleStartFinishFunc = std::bind(&InputDeviceCooperateSM::OnStartFinish, InputDevCooSM, isSuccess, remoteNetworkId, startInputDeviceId); CHKPV(eventHandler_); - eventHandler_->PostTask(handleStartFinishFunc, taskName, 0, AppExecFwk::EventQueue::Priority::HIGH); + eventHandler_->ProxyPostTask(handleStartFinishFunc, taskName, 0); } else if (InputDevCooSM->IsStopping()) { std::string taskName = "stop_finish_task"; std::function handleStopFinishFunc = std::bind(&InputDeviceCooperateSM::OnStopFinish, InputDevCooSM, isSuccess, remoteNetworkId); CHKPV(eventHandler_); - eventHandler_->PostTask(handleStopFinishFunc, taskName, 0, AppExecFwk::EventQueue::Priority::HIGH); + eventHandler_->ProxyPostTask(handleStopFinishFunc, taskName, 0); } } diff --git a/service/input_device_cooperate/src/input_device_cooperate_state_out.cpp b/service/input_device_cooperate/src/input_device_cooperate_state_out.cpp index c60ca0aa8a45364a2dddc69f039874bd846994df..ea128d5f8ef35cf0845063b7b7fe107366a63593 100755 --- a/service/input_device_cooperate/src/input_device_cooperate_state_out.cpp +++ b/service/input_device_cooperate/src/input_device_cooperate_state_out.cpp @@ -16,22 +16,21 @@ #include "input_device_cooperate_state_out.h" #include "cooperation_message.h" +#include "device_cooperate_softbus_adapter.h" #include "distributed_input_adapter.h" #include "input_device_cooperate_sm.h" +#include "input_device_cooperate_util.h" #include "input_device_manager.h" -#include "mouse_event_normalize.h" -#include "multimodal_input_connect_remoter.h" namespace OHOS { namespace MMI { namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "InputDeviceCooperateStateOut"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "InputDeviceCooperateStateOut" }; } // namespace InputDeviceCooperateStateOut::InputDeviceCooperateStateOut(const std::string& startDhid) : startDhid_(startDhid) -{ -} +{} int32_t InputDeviceCooperateStateOut::StopInputDeviceCooperate(const std::string &networkId) { @@ -41,7 +40,7 @@ int32_t InputDeviceCooperateStateOut::StopInputDeviceCooperate(const std::string std::pair prepared = InputDevCooSM->GetPreparedDevices(); srcNetworkId = prepared.first; } - int32_t ret = RemoteMgr->StopRemoteCooperate(networkId); + int32_t ret = DevCooperateSoftbusAdapter->StopRemoteCooperate(networkId); if (ret != RET_OK) { MMI_HILOGE("Stop input device cooperate fail"); return static_cast(CooperationMessage::COOPERATE_FAIL); @@ -50,15 +49,14 @@ int32_t InputDeviceCooperateStateOut::StopInputDeviceCooperate(const std::string std::function handleProcessStopFunc = std::bind(&InputDeviceCooperateStateOut::ProcessStop, this, srcNetworkId); CHKPR(eventHandler_, RET_ERR); - eventHandler_->PostTask(handleProcessStopFunc, taskName, 0, - AppExecFwk::EventQueue::Priority::HIGH); + eventHandler_->ProxyPostTask(handleProcessStopFunc, taskName, 0); return RET_OK; } void InputDeviceCooperateStateOut::ProcessStop(const std::string& srcNetworkId) { CALL_DEBUG_ENTER; - std::string sink = InputDevMgr->GetOriginNetworkId(startDhid_); + std::string sink = GetLocalDeviceId(); std::vector dhids = InputDevMgr->GetCooperateDhids(startDhid_); if (dhids.empty()) { InputDevCooSM->OnStopFinish(false, srcNetworkId); @@ -78,8 +76,7 @@ void InputDeviceCooperateStateOut::OnStopRemoteInput(bool isSuccess, const std:: std::function handleStopFinishFunc = std::bind(&InputDeviceCooperateSM::OnStopFinish, InputDevCooSM, isSuccess, srcNetworkId); CHKPV(eventHandler_); - eventHandler_->PostTask(handleStopFinishFunc, taskName, 0, - AppExecFwk::EventQueue::Priority::HIGH); + eventHandler_->ProxyPostTask(handleStopFinishFunc, taskName, 0); } void InputDeviceCooperateStateOut::OnKeyboardOnline(const std::string &dhid) diff --git a/service/dinput/src/call_dinput_death_recipient.cpp b/service/input_device_cooperate/src/input_device_cooperate_util.cpp similarity index 61% rename from service/dinput/src/call_dinput_death_recipient.cpp rename to service/input_device_cooperate/src/input_device_cooperate_util.cpp index e7762596ce3840119b187a4897d36d3c55fb8856..9b5a68bd40bb7c720b761ca2728601ed973c88f9 100644 --- a/service/dinput/src/call_dinput_death_recipient.cpp +++ b/service/input_device_cooperate/src/input_device_cooperate_util.cpp @@ -13,23 +13,26 @@ * limitations under the License. */ -#include "call_dinput_death_recipient.h" +#include "input_device_cooperate_util.h" -#include "mmi_log.h" +#include "softbus_bus_center.h" +#include "config_multimodal.h" +#include "define_multimodal.h" namespace OHOS { namespace MMI { namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "CallDinputDeathRecipient" }; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "InputDeviceCooperateUtil" }; } // namespace -CALLDinputDeathRecipient::CALLDinputDeathRecipient( - const std::function &object)> &deathCallback) - : deathCallback_(deathCallback) {} - -void CALLDinputDeathRecipient::OnRemoteDied(const OHOS::wptr &object) +std::string GetLocalDeviceId() { - CHKPV(deathCallback_); - deathCallback_(object); + auto localNode = std::make_unique(); + int32_t ret = GetLocalNodeDeviceInfo(MMI_DINPUT_PKG_NAME, localNode.get()); + if (ret != RET_OK) { + MMI_HILOGE("GetLocalNodeDeviceInfo ret:%{public}d", ret); + return {}; + } + return localNode->networkId; } } // namespace MMI } // namespace OHOS diff --git a/service/interceptor/include/event_interceptor_handler.h b/service/interceptor/include/event_interceptor_handler.h index 1a87ee1a61cdd7ade74ee0e4438ad2df1721ad51..963b8f874da43a2597414f9e2ea16705986ca7bc 100644 --- a/service/interceptor/include/event_interceptor_handler.h +++ b/service/interceptor/include/event_interceptor_handler.h @@ -20,6 +20,7 @@ #include "i_input_event_handler.h" #include "i_input_event_collection_handler.h" +#include "input_device.h" #include "input_handler_type.h" #include "nocopyable.h" #include "uds_session.h" @@ -40,8 +41,10 @@ public: #ifdef OHOS_BUILD_ENABLE_TOUCH void HandleTouchEvent(const std::shared_ptr pointerEvent) override; #endif // OHOS_BUILD_ENABLE_TOUCH - int32_t AddInputHandler(InputHandlerType handlerType, HandleEventType eventType, SessionPtr session); - void RemoveInputHandler(InputHandlerType handlerType, HandleEventType eventType, SessionPtr session); + int32_t AddInputHandler(InputHandlerType handlerType, HandleEventType eventType, + int32_t priority, uint32_t deviceTags, SessionPtr session); + void RemoveInputHandler(InputHandlerType handlerType, HandleEventType eventType, + int32_t priority, uint32_t deviceTags, SessionPtr session); #ifdef OHOS_BUILD_ENABLE_KEYBOARD bool OnHandleEvent(std::shared_ptr keyEvent); #endif // OHOS_BUILD_ENABLE_KEYBOARD @@ -55,33 +58,32 @@ private: private: class SessionHandler { public: - SessionHandler(InputHandlerType handlerType, HandleEventType eventType, SessionPtr session) - : handlerType_(handlerType), eventType_(eventType & HANDLE_EVENT_TYPE_ALL), - session_(session) {} + SessionHandler(InputHandlerType handlerType, HandleEventType eventType, int32_t priority, + uint32_t deviceTags, SessionPtr session) : handlerType_(handlerType), + eventType_(eventType & HANDLE_EVENT_TYPE_ALL), priority_(priority), deviceTags_(deviceTags), + session_(session) {} void SendToClient(std::shared_ptr keyEvent) const; void SendToClient(std::shared_ptr pointerEvent) const; - bool operator<(const SessionHandler& other) const - { - return (session_ < other.session_); - } - InputHandlerType handlerType_; - HandleEventType eventType_; + InputHandlerType handlerType_ { NONE }; + HandleEventType eventType_ { HANDLE_EVENT_TYPE_ALL }; + int32_t priority_ { DEFUALT_INTERCEPTOR_PRIORITY }; + uint32_t deviceTags_ { CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX) }; SessionPtr session_ { nullptr }; }; - class InterceptorCollection : public IInputEventCollectionHandler, protected NoCopyable { + class InterceptorCollection final : public IInputEventCollectionHandler, protected NoCopyable { public: #ifdef OHOS_BUILD_ENABLE_KEYBOARD - virtual bool HandleEvent(std::shared_ptr keyEvent) override; + bool HandleEvent(std::shared_ptr keyEvent) override; #endif // OHOS_BUILD_ENABLE_KEYBOARD #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) - virtual bool HandleEvent(std::shared_ptr pointerEvent) override; + bool HandleEvent(std::shared_ptr pointerEvent) override; #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH int32_t AddInterceptor(const SessionHandler& interceptor); void RemoveInterceptor(const SessionHandler& interceptor); void OnSessionLost(SessionPtr session); void Dump(int32_t fd, const std::vector &args); - std::set interceptors_; + std::list interceptors_; }; private: diff --git a/service/interceptor/src/event_interceptor_handler.cpp b/service/interceptor/src/event_interceptor_handler.cpp index 846cf7f7f725c39e2801159267afd0484f3731c5..6108c0ca2c62cc8d800a4e46231776515bc36920 100644 --- a/service/interceptor/src/event_interceptor_handler.cpp +++ b/service/interceptor/src/event_interceptor_handler.cpp @@ -18,6 +18,7 @@ #include "bytrace_adapter.h" #include "define_multimodal.h" #include "event_dispatch_handler.h" +#include "input_device_manager.h" #include "input_event_data_transformation.h" #include "input_event_handler.h" #include "mmi_log.h" @@ -37,14 +38,14 @@ void EventInterceptorHandler::HandleKeyEvent(const std::shared_ptr key CHKPV(keyEvent); #ifdef OHOS_BUILD_ENABLE_COOPERATE if (!InputHandler->GetJumpInterceptState() && OnHandleEvent(keyEvent)) { - MMI_HILOGD("KeyEvent filter find a keyEvent from Original event keyCode:%{puiblic}d", + MMI_HILOGD("KeyEvent filter find a keyEvent from Original event keyCode:%{public}d", keyEvent->GetKeyCode()); BytraceAdapter::StartBytrace(keyEvent, BytraceAdapter::KEY_INTERCEPT_EVENT); return; } #else if (OnHandleEvent(keyEvent)) { - MMI_HILOGD("KeyEvent filter find a keyEvent from Original event keyCode:%{puiblic}d", + MMI_HILOGD("KeyEvent filter find a keyEvent from Original event keyCode:%{public}d", keyEvent->GetKeyCode()); BytraceAdapter::StartBytrace(keyEvent, BytraceAdapter::KEY_INTERCEPT_EVENT); return; @@ -84,7 +85,7 @@ void EventInterceptorHandler::HandleTouchEvent(const std::shared_ptr keyItems = keyEvent->GetKeyItems(); + if (keyItems.empty()) { + MMI_HILOGE("keyItems is empty"); + return false; + } + std::shared_ptr inputDevice = InputDevMgr->GetInputDevice(keyItems.front().GetDeviceId()); + CHKPF(inputDevice); for (const auto &interceptor : interceptors_) { + if (!inputDevice->HasCapability(interceptor.deviceTags_)) { + continue; + } if ((interceptor.eventType_ & HANDLE_EVENT_TYPE_KEY) == HANDLE_EVENT_TYPE_KEY) { interceptor.SendToClient(keyEvent); MMI_HILOGD("Key event was intercepted"); isInterceptor = true; + break; } } return isInterceptor; @@ -216,16 +228,28 @@ bool EventInterceptorHandler::InterceptorCollection::HandleEvent(std::shared_ptr { CHKPF(pointerEvent); if (interceptors_.empty()) { - MMI_HILOGE("Pointer interceptors is empty"); + MMI_HILOGD("Interceptors are empty"); return false; } MMI_HILOGD("There are currently:%{public}zu interceptors", interceptors_.size()); bool isInterceptor = false; + PointerEvent::PointerItem pointerItem; + int32_t pointerId = pointerEvent->GetPointerId(); + if (!pointerEvent->GetPointerItem(pointerId, pointerItem)) { + MMI_HILOGE("GetPointerItem:%{public}d fail", pointerId); + return false; + } + std::shared_ptr inputDevice = InputDevMgr->GetInputDevice(pointerItem.GetDeviceId()); + CHKPF(inputDevice); for (const auto &interceptor : interceptors_) { + if (!inputDevice->HasCapability(interceptor.deviceTags_)) { + continue; + } if ((interceptor.eventType_ & HANDLE_EVENT_TYPE_POINTER) == HANDLE_EVENT_TYPE_POINTER) { interceptor.SendToClient(pointerEvent); MMI_HILOGD("Pointer event was intercepted"); isInterceptor = true; + break; } } return isInterceptor; @@ -234,55 +258,53 @@ bool EventInterceptorHandler::InterceptorCollection::HandleEvent(std::shared_ptr int32_t EventInterceptorHandler::InterceptorCollection::AddInterceptor(const SessionHandler& interceptor) { + for (auto iter = interceptors_.begin(); iter != interceptors_.end(); ++iter) { + if (iter->session_ == interceptor.session_) { + interceptors_.erase(iter); + break; + } + } + if (interceptors_.size() >= MAX_N_INPUT_INTERCEPTORS) { MMI_HILOGE("The number of interceptors exceeds limit"); return RET_ERR; } - bool isFound = false; - auto iter = interceptors_.find(interceptor); - if (iter != interceptors_.end()) { - if (iter->eventType_ == interceptor.eventType_) { - MMI_HILOGD("Interceptor with event type (%{public}u) already exists", interceptor.eventType_); - return RET_OK; - } - isFound = true; - interceptors_.erase(iter); - } - auto [sIter, isOk] = interceptors_.insert(interceptor); - if (!isOk) { - if (isFound) { - MMI_HILOGE("Internal error: interceptor has been removed"); - } else { - MMI_HILOGE("Failed to add interceptor"); + auto iterIndex = interceptors_.cbegin(); + for (; iterIndex != interceptors_.cend(); ++iterIndex) { + if (interceptor.priority_ < iterIndex->priority_) { + break; } - return RET_ERR; } - - if (isFound) { - MMI_HILOGD("Event type is updated:%{public}u", interceptor.eventType_); - } else { - MMI_HILOGD("Service AddInterceptor Success"); + auto sIter = interceptors_.emplace(iterIndex, interceptor); + if (sIter == interceptors_.end()) { + MMI_HILOGE("Failed to add interceptor"); + return RET_ERR; } return RET_OK; } void EventInterceptorHandler::InterceptorCollection::RemoveInterceptor(const SessionHandler& interceptor) { - std::set::const_iterator iter = interceptors_.find(interceptor); - if (iter == interceptors_.cend()) { - MMI_HILOGE("Interceptor does not exist"); - return; + for (auto iter = interceptors_.begin(); iter != interceptors_.end(); ++iter) { + if (iter->session_ == interceptor.session_) { + interceptors_.erase(iter); + break; + } } - - interceptors_.erase(iter); if (interceptor.eventType_ == HANDLE_EVENT_TYPE_NONE) { MMI_HILOGD("Unregister interceptor successfully"); return; } - auto [sIter, isOk] = interceptors_.insert(interceptor); - if (!isOk) { + auto iterIndex = interceptors_.cbegin(); + for (; iterIndex != interceptors_.cend(); ++iterIndex) { + if (interceptor.priority_ < iterIndex->priority_) { + break; + } + } + auto sIter = interceptors_.emplace(iterIndex, interceptor); + if (sIter == interceptors_.end()) { MMI_HILOGE("Internal error, interceptor has been removed"); return; } @@ -292,15 +314,16 @@ void EventInterceptorHandler::InterceptorCollection::RemoveInterceptor(const Ses void EventInterceptorHandler::InterceptorCollection::OnSessionLost(SessionPtr session) { CALL_INFO_TRACE; - std::set::const_iterator cItr = interceptors_.cbegin(); - while (cItr != interceptors_.cend()) { - if (cItr->session_ != session) { - ++cItr; + auto iter = interceptors_.cbegin(); + while (iter != interceptors_.cend()) { + if (iter->session_ != session) { + ++iter; } else { - cItr = interceptors_.erase(cItr); + iter = interceptors_.erase(iter); } } } + void EventInterceptorHandler::Dump(int32_t fd, const std::vector &args) { return interceptors_.Dump(fd, args); diff --git a/service/key_command/etc/ability_launch_config.json b/service/key_command/etc/ability_launch_config.json deleted file mode 100644 index 37cf22f356336076047791f46a9f9224124a16c9..0000000000000000000000000000000000000000 --- a/service/key_command/etc/ability_launch_config.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "Shortkeys": [ - ], - "Sequences" : [ - ] -} \ No newline at end of file diff --git a/service/key_command/include/key_command_handler.h b/service/key_command/include/key_command_handler.h index 7eb5ef56766803b485e783e336b517d2d8b153fa..d0bedb5d112a95c99e54f29f943fcbf5787bd4f0 100755 --- a/service/key_command/include/key_command_handler.h +++ b/service/key_command/include/key_command_handler.h @@ -73,11 +73,11 @@ struct Sequence { Ability ability; }; -class KeyCommandHandler : public IInputEventHandler { +class KeyCommandHandler final : public IInputEventHandler { public: KeyCommandHandler() = default; DISALLOW_COPY_AND_MOVE(KeyCommandHandler); - ~KeyCommandHandler() = default; + ~KeyCommandHandler() override = default; #ifdef OHOS_BUILD_ENABLE_KEYBOARD void HandleKeyEvent(const std::shared_ptr keyEvent) override; #endif // OHOS_BUILD_ENABLE_KEYBOARD @@ -104,6 +104,9 @@ private: bool HandleSequences(const std::shared_ptr keyEvent); bool HandleShortKeys(const std::shared_ptr keyEvent); bool AddSequenceKey(const std::shared_ptr keyEvent); + void RemoveSubscribedTimer(int32_t keyCode); + void HandleSpecialKeys(int32_t keyCode, int32_t keyAction); + void InterruptTimers(); void ResetLastMatchedKey() { lastMatchedKey_.preKeys.clear(); @@ -125,6 +128,8 @@ private: std::vector filterSequences_; std::vector keys_; bool isParseConfig_ { false }; + std::map specialKeys_; + std::map> specialTimers_; }; } // namespace MMI } // namespace OHOS diff --git a/service/key_command/src/key_command_handler.cpp b/service/key_command/src/key_command_handler.cpp index e4758f51feb576ed3865b99080140f2f0112ff47..c03e8bf9d4af21a5dd2ee70f796521a7d5adc7df 100644 --- a/service/key_command/src/key_command_handler.cpp +++ b/service/key_command/src/key_command_handler.cpp @@ -15,24 +15,41 @@ #include "key_command_handler.h" -#include "dfx_hisysevent.h" #include "ability_manager_client.h" +#include "bytrace_adapter.h" #include "cJSON.h" #include "config_policy_utils.h" -#include "file_ex.h" -#include "bytrace_adapter.h" +#include "define_multimodal.h" +#include "dfx_hisysevent.h" #include "error_multimodal.h" +#include "file_ex.h" +#include "input_event_data_transformation.h" +#include "input_event_handler.h" #include "mmi_log.h" +#include "net_packet.h" +#include "proto.h" #include "timer_manager.h" +#include "util_ex.h" namespace OHOS { namespace MMI { namespace { constexpr int32_t MAX_PREKEYS_NUM = 4; constexpr int32_t MAX_SEQUENCEKEYS_NUM = 10; -constexpr int64_t MAX_DELAY_TIME = 3000000; +constexpr int64_t MAX_DELAY_TIME = 1000000; constexpr int64_t SECONDS_SYSTEM = 1000; +constexpr int32_t SPECIAL_KEY_DOWN_DELAY = 150; constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "KeyCommandHandler" }; +enum SpecialType { + SPECIAL_ALL = 0, + SUBSCRIBER_BEFORE_DELAY = 1, + KEY_DOWN_ACTION = 2 +}; +const std::map SPECIAL_KEYS = { + { KeyEvent::KEYCODE_POWER, SpecialType::KEY_DOWN_ACTION }, + { KeyEvent::KEYCODE_VOLUME_DOWN, SpecialType::SPECIAL_ALL }, + { KeyEvent::KEYCODE_VOLUME_UP, SpecialType::SPECIAL_ALL } +}; struct JsonParser { JsonParser() = default; ~JsonParser() @@ -48,6 +65,15 @@ struct JsonParser { cJSON *json_ { nullptr }; }; +bool IsSpecialType(int32_t keyCode, SpecialType type) +{ + auto it = SPECIAL_KEYS.find(keyCode); + if (it == SPECIAL_KEYS.end()) { + return false; + } + return (it->second == SpecialType::SPECIAL_ALL || it->second == type); +} + bool GetPreKeys(const cJSON* jsonData, ShortcutKey &shortcutKey) { if (!cJSON_IsObject(jsonData)) { @@ -584,8 +610,9 @@ bool KeyCommandHandler::ParseJson(const std::string &configFile) return false; } - if (!ParseShortcutKeys(parser, shortcutKeys_) && - !ParseSequences(parser, sequences_)) { + bool isParseShortKeys = ParseShortcutKeys(parser, shortcutKeys_); + bool isParseSequences = ParseSequences(parser, sequences_); + if (!isParseShortKeys && !isParseSequences) { MMI_HILOGE("Parse configFile failed"); return false; } @@ -638,12 +665,50 @@ bool KeyCommandHandler::OnHandleEvent(const std::shared_ptr key) } isParseConfig_ = true; } - if (!HandleShortKeys(key) || - !HandleSequences(key)) { - MMI_HILOGE("Handle key event failed"); - return false; + + bool isHandled = HandleShortKeys(key); + isHandled = HandleSequences(key) || isHandled; + if (isHandled) { + return true; } - return true; + + if (!specialKeys_.empty() && specialKeys_.find(key->GetKeyCode()) != specialKeys_.end()) { + HandleSpecialKeys(key->GetKeyCode(), key->GetAction()); + return true; + } + + if (IsSpecialType(key->GetKeyCode(), SpecialType::SUBSCRIBER_BEFORE_DELAY)) { + auto tmpKey = KeyEvent::Clone(key); + int32_t timerId = TimerMgr->AddTimer(SPECIAL_KEY_DOWN_DELAY, 1, [this, tmpKey] () { + MMI_HILOGD("Timer callback"); + auto it = specialTimers_.find(tmpKey->GetKeyCode()); + if (it != specialTimers_.end() && !it->second.empty()) { + it->second.pop_front(); + } + InputHandler->GetSubscriberHandler()->HandleKeyEvent(tmpKey); + }); + if (timerId < 0) { + MMI_HILOGE("Add timer failed"); + return false; + } + + auto it = specialTimers_.find(key->GetKeyCode()); + if (it == specialTimers_.end()) { + std::list timerIds; + timerIds.push_back(timerId); + auto it = specialTimers_.emplace(key->GetKeyCode(), timerIds); + if (!it.second) { + MMI_HILOGE("Keycode duplicated"); + return false; + } + } else { + it->second.push_back(timerId); + } + MMI_HILOGD("Add timer success"); + return true; + } + + return false; } bool KeyCommandHandler::HandleShortKeys(const std::shared_ptr keyEvent) @@ -655,12 +720,12 @@ bool KeyCommandHandler::HandleShortKeys(const std::shared_ptr keyEvent return false; } if (IsKeyMatch(lastMatchedKey_, keyEvent)) { - MMI_HILOGE("The same key is waiting timeout, skip"); + MMI_HILOGD("The same key is waiting timeout, skip"); return true; } DfxHisysevent::GetComboStartTime(); if (lastMatchedKey_.timerId >= 0) { - MMI_HILOGE("Remove timer:%{public}d", lastMatchedKey_.timerId); + MMI_HILOGD("Remove timer:%{public}d", lastMatchedKey_.timerId); TimerMgr->RemoveTimer(lastMatchedKey_.timerId); } ResetLastMatchedKey(); @@ -723,6 +788,16 @@ bool KeyCommandHandler::HandleSequences(const std::shared_ptr keyEvent } } + if (isLaunchAbility) { + for (const auto& item : keys_) { + if (IsSpecialType(item.keyCode, SpecialType::KEY_DOWN_ACTION)) { + HandleSpecialKeys(item.keyCode, item.keyAction); + } + InputHandler->GetSubscriberHandler()->RemoveSubscriberKeyUpTimer(item.keyCode); + RemoveSubscribedTimer(item.keyCode); + } + } + if (tempSeqs.empty()) { MMI_HILOGD("No matching sequence found"); } else { @@ -755,16 +830,9 @@ bool KeyCommandHandler::AddSequenceKey(const std::shared_ptr keyEvent) return false; } keys_[size - 1].delay = sequenceKey.actionTime - keys_[size - 1].actionTime; - for (Sequence& item : filterSequences_) { - if (item.timerId >= 0) { - MMI_HILOGD("The key sequence change, close the timer"); - TimerMgr->RemoveTimer(item.timerId); - item.timerId = -1; - } - } + InterruptTimers(); } } - if (size > MAX_SEQUENCEKEYS_NUM) { MMI_HILOGD("The save key size more than the max size"); return false; @@ -802,7 +870,7 @@ bool KeyCommandHandler::HandleSequence(Sequence &sequence, bool &isLaunchAbility isLaunchAbility = true; return true; } - sequence.timerId = TimerMgr->AddTimer(sequence.abilityStartDelay, 1, [this, sequence] () { + sequence.timerId = TimerMgr->AddTimer(sequence.abilityStartDelay/SECONDS_SYSTEM, 1, [this, sequence] () { MMI_HILOGD("Timer callback"); LaunchAbility(sequence); }); @@ -875,8 +943,11 @@ bool KeyCommandHandler::HandleKeyUp(const std::shared_ptr &keyEvent, c LaunchAbility(shortcutKey); return true; } - const KeyEvent::KeyItem* keyItem = keyEvent->GetKeyItem(); - CHKPF(keyItem); + std::optional keyItem = keyEvent->GetKeyItem(); + if (!keyItem) { + MMI_HILOGE("The keyItem is nullopt"); + return false; + } auto upTime = keyEvent->GetActionTime(); auto downTime = keyItem->GetDownTime(); MMI_HILOGD("upTime:%{public}" PRId64 ",downTime:%{public}" PRId64 ",keyDownDuration:%{public}d", @@ -905,6 +976,7 @@ bool KeyCommandHandler::HandleKeyCancel(ShortcutKey &shortcutKey) void KeyCommandHandler::LaunchAbility(const ShortcutKey &key) { + CALL_INFO_TRACE; AAFwk::Want want; want.SetElementName(key.ability.deviceId, key.ability.bundleName, key.ability.abilityName); want.SetAction(key.ability.action); @@ -929,6 +1001,7 @@ void KeyCommandHandler::LaunchAbility(const ShortcutKey &key) void KeyCommandHandler::LaunchAbility(const Sequence &sequence) { + CALL_INFO_TRACE; AAFwk::Want want; want.SetElementName(sequence.ability.deviceId, sequence.ability.bundleName, sequence.ability.abilityName); want.SetAction(sequence.ability.action); @@ -959,5 +1032,51 @@ void ShortcutKey::Print() const MMI_HILOGD("Eventkey matched, finalKey:%{public}d, bundleName:%{public}s", finalKey, ability.bundleName.c_str()); } + +void KeyCommandHandler::RemoveSubscribedTimer(int32_t keyCode) +{ + CALL_DEBUG_ENTER; + auto iter = specialTimers_.find(keyCode); + if (iter != specialTimers_.end()) { + for (auto& item : iter->second) { + TimerMgr->RemoveTimer(item); + } + specialTimers_.erase(keyCode); + MMI_HILOGD("Remove timer success"); + } +} + +void KeyCommandHandler::HandleSpecialKeys(int32_t keyCode, int32_t keyAction) +{ + CALL_DEBUG_ENTER; + auto iter = specialKeys_.find(keyCode); + if (keyAction == KeyEvent::KEY_ACTION_UP) { + if (iter != specialKeys_.end()) { + specialKeys_.erase(iter); + return; + } + } + + if (keyAction == KeyEvent::KEY_ACTION_DOWN) { + if (iter == specialKeys_.end()) { + auto it = specialKeys_.emplace(keyCode, keyAction); + if (!it.second) { + MMI_HILOGD("KeyCode duplicated"); + return; + } + } + } +} + +void KeyCommandHandler::InterruptTimers() +{ + for (Sequence& item : filterSequences_) { + if (item.timerId >= 0) { + MMI_HILOGD("The key sequence change, close the timer"); + TimerMgr->RemoveTimer(item.timerId); + item.timerId = -1; + } + } +} } // namespace MMI -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/service/key_event_normalize/src/key_event_normalize.cpp b/service/key_event_normalize/src/key_event_normalize.cpp index e1d4cff8765c0b03b37e94fba2874a2e27d36bbd..ce454a415db459767a33edac406fd6b31afafdef 100644 --- a/service/key_event_normalize/src/key_event_normalize.cpp +++ b/service/key_event_normalize/src/key_event_normalize.cpp @@ -57,11 +57,11 @@ int32_t KeyEventNormalize::Normalize(struct libinput_event *event, std::shared_p (KeyEvent::KEY_ACTION_UP) : (KeyEvent::KEY_ACTION_DOWN); auto preAction = keyEvent->GetAction(); if (preAction == KeyEvent::KEY_ACTION_UP) { - auto preUpKeyItem = keyEvent->GetKeyItem(); - if (preUpKeyItem != nullptr) { + std::optional preUpKeyItem = keyEvent->GetKeyItem(); + if (preUpKeyItem) { keyEvent->RemoveReleasedKeyItems(*preUpKeyItem); } else { - MMI_HILOGE("The preUpKeyItem is null"); + MMI_HILOGE("The preUpKeyItem is nullopt"); } } int64_t time = GetSysClockTime(); @@ -87,15 +87,15 @@ int32_t KeyEventNormalize::Normalize(struct libinput_event *event, std::shared_p } if (keyAction == KeyEvent::KEY_ACTION_UP) { int32_t funcKey = keyEvent->TransitionFunctionKey(keyCode); - if (funcKey != KeyEvent::UNKOWN_FUNCTION_KEY) { + if (funcKey != KeyEvent::UNKNOWN_FUNCTION_KEY) { int32_t ret = keyEvent->SetFunctionKey(funcKey, libinput_get_funckey_state(device, funcKey)); if (ret == funcKey) { MMI_HILOGD("Set function key:%{public}d to state:%{public}d succeed", funcKey, keyEvent->GetFunctionKey(funcKey)); } } - auto pressedKeyItem = keyEvent->GetKeyItem(keyCode); - if (pressedKeyItem != nullptr) { + std::optional pressedKeyItem = keyEvent->GetKeyItem(keyCode); + if (pressedKeyItem) { item.SetDownTime(pressedKeyItem->GetDownTime()); } else { MMI_HILOGE("Find pressed key failed, keyCode:%{public}d", keyCode); @@ -103,6 +103,8 @@ int32_t KeyEventNormalize::Normalize(struct libinput_event *event, std::shared_p keyEvent->RemoveReleasedKeyItems(item); keyEvent->AddPressedKeyItems(item); } + int32_t keyIntention = keyItemsTransKeyIntention(keyEvent->GetKeyItems()); + keyEvent->SetKeyIntention(keyIntention); return RET_OK; } diff --git a/service/libinput_adapter/include/libinput_adapter.h b/service/libinput_adapter/include/libinput_adapter.h index 5675aac98d5081e093659463048fbdcec894d3a0..75d585e2da781678b4bade443771fe7ce707e240 100644 --- a/service/libinput_adapter/include/libinput_adapter.h +++ b/service/libinput_adapter/include/libinput_adapter.h @@ -27,13 +27,13 @@ namespace OHOS { namespace MMI { typedef std::function FunInputEvent; -class LibinputAdapter { +class LibinputAdapter final { public: static void LoginfoPackagingTool(struct libinput_event *event); static int32_t DeviceLedUpdate(struct libinput_device *device, int32_t funcKey, bool isEnable); - LibinputAdapter(); + LibinputAdapter() = default; DISALLOW_COPY_AND_MOVE(LibinputAdapter); - virtual ~LibinputAdapter(); + ~LibinputAdapter() = default; bool Init(FunInputEvent funInputEvent, const std::string& seat_id = "seat0"); void EventDispatch(struct epoll_event& ev); void Stop(); diff --git a/service/libinput_adapter/src/libinput_adapter.cpp b/service/libinput_adapter/src/libinput_adapter.cpp index 326d04c8b47c5f1da506d2dce94906d572c1ad6c..49a0d3b487e180431a42b1f28c5c1cbe42a29b01 100644 --- a/service/libinput_adapter/src/libinput_adapter.cpp +++ b/service/libinput_adapter/src/libinput_adapter.cpp @@ -14,8 +14,9 @@ */ #include "libinput_adapter.h" -#include + #include +#include #include #include #include @@ -25,19 +26,18 @@ #include "input_windows_manager.h" #include "util.h" - namespace OHOS { namespace MMI { namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "LibinputAdapter" }; -constexpr int32_t WAIT_TIME_FOR_INPUT { 500 }; -constexpr int32_t MAX_RETRY_COUNT = 60; +constexpr int32_t WAIT_TIME_FOR_INPUT { 10 }; } // namespace static void HiLogFunc(struct libinput* input, libinput_log_priority priority, const char* fmt, va_list args) { CHKPV(input); - char buffer[256]; + CHKPV(fmt); + char buffer[256] = {}; if (vsnprintf_s(buffer, sizeof(buffer), sizeof(buffer) - 1, fmt, args) == -1) { MMI_HILOGE("Call vsnprintf_s failed"); va_end(args); @@ -79,14 +79,9 @@ constexpr static libinput_interface LIBINPUT_INTERFACE = { return RET_ERR; } char realPath[PATH_MAX] = {}; - int32_t count = 0; - while ((realpath(path, realPath) == nullptr) && (count < MAX_RETRY_COUNT)) { - MMI_HILOGWK("Path is error, count:%{public}d, path:%{public}s", count, path); + if (realpath(path, realPath) == nullptr) { std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_TIME_FOR_INPUT)); - ++count; - } - if (count >= MAX_RETRY_COUNT) { - MMI_HILOGWK("Retry %{public}d times realpath failed", count); + MMI_HILOGWK("The error path is %{public}s", path); return RET_ERR; } int32_t fd = open(realPath, flags); @@ -101,10 +96,6 @@ constexpr static libinput_interface LIBINPUT_INTERFACE = { }, }; -LibinputAdapter::LibinputAdapter() {} - -LibinputAdapter::~LibinputAdapter() {} - bool LibinputAdapter::Init(FunInputEvent funInputEvent, const std::string& seat_id) { CALL_DEBUG_ENTER; @@ -198,7 +189,8 @@ void LibinputAdapter::RetriggerHotplugEvents() MMI_HILOGE("Failed to open directory: \'/sys/class/input\'"); return; } - for (struct dirent *pdirent = readdir(pdir); pdirent != nullptr; pdirent = readdir(pdir)) { + struct dirent *pdirent = nullptr; + while ((pdirent = readdir(pdir)) != nullptr) { char path[PATH_MAX]; if (sprintf_s(path, sizeof(path), "/sys/class/input/%s/uevent", pdirent->d_name) < 0) { continue; diff --git a/service/message_handle/include/server_msg_handler.h b/service/message_handle/include/server_msg_handler.h index 48aa33d1244d295f2b11ef9a356a340f448c5d14..25e99b58f8770a7615e42b3b9c6db0a75841ce40 100644 --- a/service/message_handle/include/server_msg_handler.h +++ b/service/message_handle/include/server_msg_handler.h @@ -27,17 +27,19 @@ namespace OHOS { namespace MMI { typedef std::function ServerMsgFun; -class ServerMsgHandler : public MsgHandler { +class ServerMsgHandler final : public MsgHandler { public: - ServerMsgHandler(); + ServerMsgHandler() = default; DISALLOW_COPY_AND_MOVE(ServerMsgHandler); - virtual ~ServerMsgHandler() override; + ~ServerMsgHandler() override = default; void Init(UDSServer& udsServer); void OnMsgHandler(SessionPtr sess, NetPacket& pkt); #if defined(OHOS_BUILD_ENABLE_INTERCEPTOR) || defined(OHOS_BUILD_ENABLE_MONITOR) - int32_t OnAddInputHandler(SessionPtr sess, InputHandlerType handlerType, HandleEventType eventType); - int32_t OnRemoveInputHandler(SessionPtr sess, InputHandlerType handlerType, HandleEventType eventType); + int32_t OnAddInputHandler(SessionPtr sess, InputHandlerType handlerType, HandleEventType eventType, + int32_t priority, uint32_t deviceTags); + int32_t OnRemoveInputHandler(SessionPtr sess, InputHandlerType handlerType, HandleEventType eventType, + int32_t priority, uint32_t deviceTags); #endif // OHOS_BUILD_ENABLE_INTERCEPTOR || OHOS_BUILD_ENABLE_MONITOR #ifdef OHOS_BUILD_ENABLE_MONITOR int32_t OnMarkConsumed(SessionPtr sess, int32_t eventId); @@ -59,18 +61,19 @@ public: int32_t OnInjectPointerEvent(const std::shared_ptr pointerEvent); #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) - int32_t AddInputEventFilter(sptr filter); + int32_t AddInputEventFilter(sptr filter, int32_t filterId, int32_t priority, uint32_t deviceTags, + int32_t clientPid); + int32_t RemoveInputEventFilter(int32_t clientPid, int32_t filterId); #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH protected: - int32_t MarkProcessed(SessionPtr sess, NetPacket& pkt); int32_t OnRegisterMsgHandler(SessionPtr sess, NetPacket& pkt); -#ifdef OHOS_BUILD_HDF - int32_t OnHdiInject(SessionPtr sess, NetPacket& pkt); -#endif int32_t OnDisplayInfo(SessionPtr sess, NetPacket& pkt); -#ifdef OHOS_BUILD_MMI_DEBUG - int32_t OnBigPacketTest(SessionPtr sess, NetPacket& pkt); -#endif // OHOS_BUILD_MMI_DEBUG + +private: +#ifdef OHOS_BUILD_ENABLE_TOUCH + bool FixTargetWindowId(std::shared_ptr pointerEvent, int32_t action); +#endif // OHOS_BUILD_ENABLE_TOUCH + private: UDSServer *udsServer_ { nullptr }; int32_t targetWindowId_ { -1 }; diff --git a/service/message_handle/src/server_msg_handler.cpp b/service/message_handle/src/server_msg_handler.cpp index e4111e62a44d806e6e78a2890339dc7689e0dede..87b28704b516d234bc5caca8377a3e98169bb475 100644 --- a/service/message_handle/src/server_msg_handler.cpp +++ b/service/message_handle/src/server_msg_handler.cpp @@ -23,20 +23,17 @@ #include "event_monitor_handler.h" #include "hos_key_event.h" #include "input_device_manager.h" +#include "input_event.h" #include "input_event_data_transformation.h" #include "input_event_handler.h" -#include "input_event.h" #include "input_windows_manager.h" -#include "key_event_normalize.h" #include "i_pointer_drawing_manager.h" +#include "key_event_normalize.h" #include "key_subscriber_handler.h" #include "libinput_adapter.h" #include "mmi_func_callback.h" #include "mouse_event_normalize.h" #include "time_cost_chk.h" -#ifdef OHOS_BUILD_HDF -#include "hdi_inject.h" -#endif namespace OHOS { namespace MMI { @@ -44,28 +41,11 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "ServerMsgHandler" }; } // namespace -ServerMsgHandler::ServerMsgHandler() {} - -ServerMsgHandler::~ServerMsgHandler() {} - void ServerMsgHandler::Init(UDSServer& udsServer) { udsServer_ = &udsServer; -#ifdef OHOS_BUILD_HDF - if (!(MMIHdiInject->Init(udsServer))) { - MMI_HILOGE("Input device initialization failed"); - return; - } -#endif MsgCallback funs[] = { - {MmiMessageId::MARK_PROCESS, MsgCallbackBind2(&ServerMsgHandler::MarkProcessed, this)}, {MmiMessageId::DISPLAY_INFO, MsgCallbackBind2(&ServerMsgHandler::OnDisplayInfo, this)}, -#ifdef OHOS_BUILD_MMI_DEBUG - {MmiMessageId::BIGPACKET_TEST, MsgCallbackBind2(&ServerMsgHandler::OnBigPacketTest, this)}, -#endif // OHOS_BUILD_MMI_DEBUG -#ifdef OHOS_BUILD_HDF - {MmiMessageId::HDI_INJECT, MsgCallbackBind2(&ServerMsgHandler::OnHdiInject, this)}, -#endif // OHOS_BUILD_HDF }; for (auto &it : funs) { if (!RegistrationEvent(it)) { @@ -91,47 +71,10 @@ void ServerMsgHandler::OnMsgHandler(SessionPtr sess, NetPacket& pkt) } } -#ifdef OHOS_BUILD_HDF -int32_t ServerMsgHandler::OnHdiInject(SessionPtr sess, NetPacket& pkt) -{ - MMI_HILOGI("Hdfinject server access hditools info"); - CHKPR(sess, ERROR_NULL_POINTER); - CHKPR(udsServer_, ERROR_NULL_POINTER); - const int32_t processingCode = MMIHdiInject->ManageHdfInject(sess, pkt); - NetPacket pkt(MmiMessageId::HDI_INJECT); - pkt << processingCode; - if (pkt.ChkRWError()) { - MMI_HILOGE("Packet write reply message failed"); - return RET_ERR; - } - if (!sess->SendMsg(pkt)) { - MMI_HILOGE("OnHdiInject reply message error"); - return RET_ERR; - } - return RET_OK; -} -#endif // OHOS_BUILD_HDF - -int32_t ServerMsgHandler::MarkProcessed(SessionPtr sess, NetPacket& pkt) -{ - CALL_DEBUG_ENTER; - CHKPR(sess, ERROR_NULL_POINTER); - int32_t eventId = 0; - int32_t eventType = 0; - pkt >> eventId >> eventType; - MMI_HILOGD("Event type:%{public}d, id:%{public}d", eventType, eventId); - if (pkt.ChkRWError()) { - MMI_HILOGE("Packet read data failed"); - return PACKET_READ_FAIL; - } - ANRMgr->MarkProcessed(eventType, eventId, sess); - return RET_OK; -} - #ifdef OHOS_BUILD_ENABLE_KEYBOARD int32_t ServerMsgHandler::OnInjectKeyEvent(const std::shared_ptr keyEvent) { - CALL_INFO_TRACE; + CALL_DEBUG_ENTER; CHKPR(keyEvent, ERROR_NULL_POINTER); auto inputEventNormalizeHandler = InputHandler->GetEventNormalizeHandler(); CHKPR(inputEventNormalizeHandler, ERROR_NULL_POINTER); @@ -176,33 +119,19 @@ int32_t ServerMsgHandler::OnSetFunctionKeyState(int32_t funcKey, bool enable) #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) int32_t ServerMsgHandler::OnInjectPointerEvent(const std::shared_ptr pointerEvent) { - CALL_INFO_TRACE; + CALL_DEBUG_ENTER; CHKPR(pointerEvent, ERROR_NULL_POINTER); pointerEvent->UpdateId(); int32_t action = pointerEvent->GetPointerAction(); - if ((action == PointerEvent::POINTER_ACTION_MOVE || action == PointerEvent::POINTER_ACTION_UP) - && targetWindowId_ > 0) { - pointerEvent->SetTargetWindowId(targetWindowId_); - PointerEvent::PointerItem pointerItem; - auto pointerIds = pointerEvent->GetPointerIds(); - if (pointerIds.empty()) { - MMI_HILOGE("GetPointerIds is empty"); - return RET_ERR; - } - auto id = pointerIds.front(); - if (!pointerEvent->GetPointerItem(id, pointerItem)) { - MMI_HILOGE("Can't find pointer item"); - return RET_ERR; - } - pointerItem.SetTargetWindowId(targetWindowId_); - pointerEvent->UpdatePointerItem(id, pointerItem); - } auto source = pointerEvent->GetSourceType(); switch (source) { case PointerEvent::SOURCE_TYPE_TOUCHSCREEN: { #ifdef OHOS_BUILD_ENABLE_TOUCH auto inputEventNormalizeHandler = InputHandler->GetEventNormalizeHandler(); CHKPR(inputEventNormalizeHandler, ERROR_NULL_POINTER); + if (!FixTargetWindowId(pointerEvent, action)) { + return RET_ERR; + } inputEventNormalizeHandler->HandleTouchEvent(pointerEvent); #endif // OHOS_BUILD_ENABLE_TOUCH break; @@ -215,7 +144,9 @@ int32_t ServerMsgHandler::OnInjectPointerEvent(const std::shared_ptrGetEventNormalizeHandler(); CHKPR(inputEventNormalizeHandler, ERROR_NULL_POINTER); - if (!IPointerDrawingManager::GetInstance()->IsPointerVisible()) { + if ((action < PointerEvent::POINTER_ACTION_PULL_DOWN || + action > PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW) && + !IPointerDrawingManager::GetInstance()->IsPointerVisible()) { IPointerDrawingManager::GetInstance()->SetPointerVisible(getpid(), true); } inputEventNormalizeHandler->HandlePointerEvent(pointerEvent); @@ -227,13 +158,38 @@ int32_t ServerMsgHandler::OnInjectPointerEvent(const std::shared_ptrGetTargetWindowId(); } return RET_OK; } #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH +#ifdef OHOS_BUILD_ENABLE_TOUCH +bool ServerMsgHandler::FixTargetWindowId(std::shared_ptr pointerEvent, int32_t action) +{ + if (action == PointerEvent::POINTER_ACTION_DOWN || targetWindowId_ < 0) { + MMI_HILOGD("Down event or targetWindowId_ less 0 is not need fix window id"); + return true; + } + pointerEvent->SetTargetWindowId(targetWindowId_); + PointerEvent::PointerItem pointerItem; + auto pointerIds = pointerEvent->GetPointerIds(); + if (pointerIds.empty()) { + MMI_HILOGE("GetPointerIds is empty"); + return false; + } + auto id = pointerIds.front(); + if (!pointerEvent->GetPointerItem(id, pointerItem)) { + MMI_HILOGE("Can't find pointer item"); + return false; + } + pointerItem.SetTargetWindowId(targetWindowId_); + pointerEvent->UpdatePointerItem(id, pointerItem); + return true; +} +#endif // OHOS_BUILD_ENABLE_TOUCH + int32_t ServerMsgHandler::OnDisplayInfo(SessionPtr sess, NetPacket &pkt) { CALL_DEBUG_ENTER; @@ -260,7 +216,7 @@ int32_t ServerMsgHandler::OnDisplayInfo(SessionPtr sess, NetPacket &pkt) for (uint32_t i = 0; i < num; i++) { DisplayInfo info; pkt >> info.id >> info.x >> info.y >> info.width >> info.height - >> info.name >> info.uniq >> info.direction; + >> info.dpi >> info.name >> info.uniq >> info.direction; displayGroupInfo.displaysInfo.push_back(info); if (pkt.ChkRWError()) { MMI_HILOGE("Packet read display info failed"); @@ -277,7 +233,7 @@ int32_t ServerMsgHandler::OnDisplayInfo(SessionPtr sess, NetPacket &pkt) #if defined(OHOS_BUILD_ENABLE_INTERCEPTOR) || defined(OHOS_BUILD_ENABLE_MONITOR) int32_t ServerMsgHandler::OnAddInputHandler(SessionPtr sess, InputHandlerType handlerType, - HandleEventType eventType) + HandleEventType eventType, int32_t priority, uint32_t deviceTags) { CHKPR(sess, ERROR_NULL_POINTER); MMI_HILOGD("handlerType:%{public}d", handlerType); @@ -285,7 +241,7 @@ int32_t ServerMsgHandler::OnAddInputHandler(SessionPtr sess, InputHandlerType ha if (handlerType == InputHandlerType::INTERCEPTOR) { auto interceptorHandler = InputHandler->GetInterceptorHandler(); CHKPR(interceptorHandler, ERROR_NULL_POINTER); - return interceptorHandler->AddInputHandler(handlerType, eventType, sess); + return interceptorHandler->AddInputHandler(handlerType, eventType, priority, deviceTags, sess); } #endif // OHOS_BUILD_ENABLE_INTERCEPTOR #ifdef OHOS_BUILD_ENABLE_MONITOR @@ -299,7 +255,7 @@ int32_t ServerMsgHandler::OnAddInputHandler(SessionPtr sess, InputHandlerType ha } int32_t ServerMsgHandler::OnRemoveInputHandler(SessionPtr sess, InputHandlerType handlerType, - HandleEventType eventType) + HandleEventType eventType, int32_t priority, uint32_t deviceTags) { CHKPR(sess, ERROR_NULL_POINTER); MMI_HILOGD("OnRemoveInputHandler handlerType:%{public}d eventType:%{public}u", handlerType, eventType); @@ -307,7 +263,7 @@ int32_t ServerMsgHandler::OnRemoveInputHandler(SessionPtr sess, InputHandlerType if (handlerType == InputHandlerType::INTERCEPTOR) { auto interceptorHandler = InputHandler->GetInterceptorHandler(); CHKPR(interceptorHandler, ERROR_NULL_POINTER); - interceptorHandler->RemoveInputHandler(handlerType, eventType, sess); + interceptorHandler->RemoveInputHandler(handlerType, eventType, priority, deviceTags, sess); } #endif // OHOS_BUILD_ENABLE_INTERCEPTOR #ifdef OHOS_BUILD_ENABLE_MONITOR @@ -374,64 +330,20 @@ int32_t ServerMsgHandler::OnUnsubscribeKeyEvent(IUdsServer *server, int32_t pid, #endif // OHOS_BUILD_ENABLE_KEYBOARD #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) -int32_t ServerMsgHandler::AddInputEventFilter(sptr filter) +int32_t ServerMsgHandler::AddInputEventFilter(sptr filter, + int32_t filterId, int32_t priority, uint32_t deviceTags, int32_t clientPid) { auto filterHandler = InputHandler->GetFilterHandler(); CHKPR(filterHandler, ERROR_NULL_POINTER); - filterHandler->AddInputEventFilter(filter); - return RET_OK; + return filterHandler->AddInputEventFilter(filter, filterId, priority, deviceTags, clientPid); } -#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH -#ifdef OHOS_BUILD_MMI_DEBUG -int32_t ServerMsgHandler::OnBigPacketTest(SessionPtr sess, NetPacket& pkt) +int32_t ServerMsgHandler::RemoveInputEventFilter(int32_t clientPid, int32_t filterId) { - CHKPR(sess, ERROR_NULL_POINTER); - int32_t width = 0; - int32_t height = 0; - int32_t focusWindowId = 0; - pkt >> width >> height >> focusWindowId; - MMI_HILOGD("logicalInfo,width:%{public}d,height:%{public}d,focusWindowId:%{public}d", - width, height, focusWindowId); - uint32_t num = 0; - pkt >> num; - for (uint32_t i = 0; i < num; i++) { - WindowInfo info; - pkt >> info.id >> info.pid >> info.uid >> info.area >> info.defaultHotAreas - >> info.pointerHotAreas >> info.agentWindowId >> info.flags; - MMI_HILOGD("windowsInfos,id:%{public}d,pid:%{public}d,uid:%{public}d," - "area.x:%{public}d,area.y:%{public}d,area.width:%{public}d,area.height:%{public}d," - "defaultHotAreas:size:%{public}zu,pointerHotAreas:size:%{public}zu," - "agentWindowId:%{public}d,flags:%{public}d", - info.id, info.pid, info.uid, info.area.x, info.area.y, info.area.width, - info.area.height, info.defaultHotAreas.size(), info.pointerHotAreas.size(), - info.agentWindowId, info.flags); - for (const auto &win : info.defaultHotAreas) { - MMI_HILOGD("defaultHotAreas,x:%{public}d,y:%{public}d,width:%{public}d,height:%{public}d", - win.x, win.y, win.width, win.height); - } - for (const auto &pointer : info.pointerHotAreas) { - MMI_HILOGD("pointerHotAreas,x:%{public}d,y:%{public}d,width:%{public}d,height:%{public}d", - pointer.x, pointer.y, pointer.width, pointer.height); - } - } - pkt >> num; - for (uint32_t i = 0; i < num; i++) { - DisplayInfo info; - pkt >> info.id >> info.x >> info.y >> info.width >> info.height - >> info.name >> info.uniq >> info.direction; - MMI_HILOGD("displaysInfos,id:%{public}d,x:%{public}d,y:%{public}d," - "width:%{public}d,height:%{public}d,name:%{public}s," - "uniq:%{public}s,direction:%{public}d", - info.id, info.x, info.y, info.width, info.height, info.name.c_str(), - info.uniq.c_str(), info.direction); - } - if (pkt.ChkRWError()) { - MMI_HILOGE("Packet read data failed"); - return PACKET_READ_FAIL; - } - return RET_OK; + auto filterHandler = InputHandler->GetFilterHandler(); + CHKPR(filterHandler, ERROR_NULL_POINTER); + return filterHandler->RemoveInputEventFilter(clientPid, filterId); } -#endif // OHOS_BUILD_MMI_DEBUG +#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH } // namespace MMI } // namespace OHOS diff --git a/service/message_handle/test/server_msg_handler_test.cpp b/service/message_handle/test/server_msg_handler_test.cpp deleted file mode 100644 index 64c6c8c6a3a8d003e3294ff638e7ef3ab7043933..0000000000000000000000000000000000000000 --- a/service/message_handle/test/server_msg_handler_test.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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 - -#include "server_msg_handler.h" - - -namespace OHOS { -namespace MMI { -namespace { -using namespace testing::ext; -} // namespace - -class ServerMsgHandlerTest : public testing::Test { -public: - static void SetUpTestCase(void) {} - static void TearDownTestCase(void) {} -}; - -class ServerMsgHandlerUnitTest : public ServerMsgHandler { -public: - -#ifdef OHOS_BUILD_HDF - int32_t OnHdiInjectTest(SessionPtr sess, NetPacket& pkt) - { - return OnHdiInject(sess, pkt); - } -#endif // OHOS_BUILD_HDF - - int32_t OnInjectKeyEventTest(SessionPtr sess, std::shared_ptr keyEvent) - { -#ifdef OHOS_BUILD_ENABLE_KEYBOARD - return OnInjectKeyEvent(keyEvent); -#else - return ERROR_UNSUPPORT; -#endif // OHOS_BUILD_ENABLE_KEYBOARD - } -}; -} // namespace MMI -} // namespace OHOS diff --git a/service/module_loader/include/mmi_service.h b/service/module_loader/include/mmi_service.h index 701a6c12dd39c6f01f3edd1c9e659446ed0d84da..f43546a35bb0a49078a87e26b8850b61b459c903 100644 --- a/service/module_loader/include/mmi_service.h +++ b/service/module_loader/include/mmi_service.h @@ -26,79 +26,80 @@ #include "delegate_tasks.h" #include "input_event_handler.h" -#include "multimodal_input_connect_stub.h" #include "libinput_adapter.h" +#include "multimodal_input_connect_stub.h" #include "server_msg_handler.h" #include "uds_server.h" -#ifdef OHOS_BUILD_HDF - #include "hdf_event_manager.h" -#endif - namespace OHOS { namespace MMI { enum class ServiceRunningState {STATE_NOT_START, STATE_RUNNING, STATE_EXIT}; class MMIService final : public UDSServer, public SystemAbility, public MultimodalInputConnectStub { DECLARE_DELAYED_SINGLETON(MMIService); - DECLEAR_SYSTEM_ABILITY(MMIService); + DECLARE_SYSTEM_ABILITY(MMIService); DISALLOW_COPY_AND_MOVE(MMIService); public: - virtual void OnStart() override; - virtual void OnStop() override; + void OnStart() override; + void OnStop() override; int32_t Dump(int32_t fd, const std::vector &args) override; - virtual int32_t AllocSocketFd(const std::string &programName, const int32_t moduleType, + int32_t AllocSocketFd(const std::string &programName, const int32_t moduleType, int32_t &toReturnClientFd, int32_t &tokenType) override; - virtual int32_t AddInputEventFilter(sptr filter) override; - virtual int32_t SetPointerVisible(bool visible) override; - virtual int32_t IsPointerVisible(bool &visible) override; - virtual int32_t SetPointerSpeed(int32_t speed) override; - virtual int32_t GetPointerSpeed(int32_t &speed) override; - virtual int32_t SetPointerStyle(int32_t windowId, int32_t pointerStyle) override; - virtual int32_t GetPointerStyle(int32_t windowId, int32_t &pointerStyle) override; - virtual int32_t SupportKeys(int32_t userData, int32_t deviceId, std::vector &keys) override; - virtual int32_t GetDeviceIds(int32_t userData) override; - virtual int32_t GetDevice(int32_t userData, int32_t deviceId) override; - virtual int32_t RegisterDevListener() override; - virtual int32_t UnregisterDevListener() override; - virtual int32_t GetKeyboardType(int32_t userData, int32_t deviceId) override; - virtual int32_t AddInputHandler(InputHandlerType handlerType, HandleEventType eventType) override; - virtual int32_t RemoveInputHandler(InputHandlerType handlerType, HandleEventType eventType) override; - virtual int32_t MarkEventConsumed(int32_t eventId) override; - virtual int32_t MoveMouseEvent(int32_t offsetX, int32_t offsetY) override; - virtual int32_t InjectKeyEvent(const std::shared_ptr keyEvent) override; - virtual int32_t SubscribeKeyEvent(int32_t subscribeId, const std::shared_ptr option) override; - virtual int32_t UnsubscribeKeyEvent(int32_t subscribeId) override; - virtual int32_t InjectPointerEvent(const std::shared_ptr pointerEvent) override; - virtual int32_t SetAnrObserver() override; - virtual int32_t RegisterCooperateListener() override; - virtual int32_t UnregisterCooperateListener() override; - virtual int32_t EnableInputDeviceCooperate(int32_t userData, bool enabled) override; - virtual int32_t StartInputDeviceCooperate(int32_t userData, const std::string &sinkDeviceId, + int32_t AddInputEventFilter(sptr filter, int32_t filterId, int32_t priority, + uint32_t deviceTags) override; + int32_t RemoveInputEventFilter(int32_t filterId) override; + int32_t SetPointerVisible(bool visible) override; + int32_t IsPointerVisible(bool &visible) override; + int32_t MarkProcessed(int32_t eventType, int32_t eventId) override; + int32_t SetPointerSpeed(int32_t speed) override; + int32_t GetPointerSpeed(int32_t &speed) override; + int32_t SetPointerStyle(int32_t windowId, PointerStyle pointerStyle) override; + int32_t GetPointerStyle(int32_t windowId, PointerStyle &pointerStyle) override; + int32_t SupportKeys(int32_t deviceId, std::vector &keys, std::vector &keystroke) override; + int32_t GetDeviceIds(std::vector &ids) override; + int32_t GetDevice(int32_t deviceId, std::shared_ptr &inputDevice) override; + int32_t RegisterDevListener() override; + int32_t UnregisterDevListener() override; + int32_t GetKeyboardType(int32_t deviceId, int32_t &keyboardType) override; + int32_t AddInputHandler(InputHandlerType handlerType, HandleEventType eventType, + int32_t priority, uint32_t deviceTags) override; + int32_t RemoveInputHandler(InputHandlerType handlerType, HandleEventType eventType, + int32_t priority, uint32_t deviceTags) override; + int32_t MarkEventConsumed(int32_t eventId) override; + int32_t MoveMouseEvent(int32_t offsetX, int32_t offsetY) override; + int32_t InjectKeyEvent(const std::shared_ptr keyEvent) override; + int32_t SubscribeKeyEvent(int32_t subscribeId, const std::shared_ptr option) override; + int32_t UnsubscribeKeyEvent(int32_t subscribeId) override; + int32_t InjectPointerEvent(const std::shared_ptr pointerEvent) override; + int32_t SetAnrObserver() override; + int32_t GetDisplayBindInfo(DisplayBindInfos &infos) override; + int32_t SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg) override; + int32_t RegisterCooperateListener() override; + int32_t UnregisterCooperateListener() override; + int32_t EnableInputDeviceCooperate(int32_t userData, bool enabled) override; + int32_t StartInputDeviceCooperate(int32_t userData, const std::string &sinkDeviceId, int32_t srcInputDeviceId) override; - virtual int32_t StopDeviceCooperate(int32_t userData) override; - virtual int32_t GetInputDeviceCooperateState(int32_t userData, const std::string &deviceId) override; - virtual int32_t SetInputDevice(const std::string& dhid, const std::string& screenId) override; - virtual int32_t StartRemoteCooperate(const std::string& localDeviceId) override; - virtual int32_t StartRemoteCooperateResult(bool isSuccess, const std::string& startDhid, - int32_t xPercent, int32_t yPercent) override; - virtual int32_t StopRemoteCooperate() override; - virtual int32_t StopRemoteCooperateResult(bool isSuccess) override; - virtual int32_t StartCooperateOtherResult(const std::string& srcNetworkId) override; - virtual int32_t GetFunctionKeyState(int32_t funcKey, bool &state) override; - virtual int32_t SetFunctionKeyState(int32_t funcKey, bool enable) override; + int32_t StopDeviceCooperate(int32_t userData) override; + int32_t GetInputDeviceCooperateState(int32_t userData, const std::string &deviceId) override; + int32_t SetInputDevice(const std::string& dhid, const std::string& screenId) override; + int32_t GetFunctionKeyState(int32_t funcKey, bool &state) override; + int32_t SetFunctionKeyState(int32_t funcKey, bool enable) override; + int32_t SetPointerLocation(int32_t x, int32_t y) override; + virtual int32_t SetMouseCaptureMode(int32_t windowId, bool isCaptureMode) override; + int32_t GetWindowPid(int32_t windowId) override; + int32_t AppendExtraData(const ExtraData& extraData) override; #ifdef OHOS_RSS_CLIENT - virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; + void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; #endif protected: - virtual void OnConnected(SessionPtr s) override; - virtual void OnDisconnected(SessionPtr s) override; - virtual int32_t AddEpoll(EpollEventType type, int32_t fd) override; + void OnConnected(SessionPtr s) override; + void OnDisconnected(SessionPtr s) override; + int32_t AddEpoll(EpollEventType type, int32_t fd) override; int32_t DelEpoll(EpollEventType type, int32_t fd); - virtual bool IsRunning() const override; + bool IsRunning() const override; #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING) int32_t CheckPointerVisible(bool &visible); #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING @@ -107,13 +108,16 @@ protected: #endif // OHOS_BUILD_ENABLE_POINTER int32_t OnRegisterDevListener(int32_t pid); int32_t OnUnregisterDevListener(int32_t pid); - int32_t OnGetDeviceIds(int32_t pid, int32_t userData); - int32_t OnGetDevice(int32_t pid, int32_t userData, int32_t deviceId); - int32_t OnSupportKeys(int32_t pid, int32_t userData, int32_t deviceId, std::vector &keys); - int32_t OnGetKeyboardType(int32_t pid, int32_t userData, int32_t deviceId); + int32_t OnGetDeviceIds(std::vector &ids); + int32_t OnGetDevice(int32_t deviceId, std::shared_ptr &inputDevice); + int32_t OnSupportKeys(int32_t deviceId, std::vector &keys, std::vector &keystroke); + int32_t OnGetKeyboardType(int32_t deviceId, int32_t &keyboardType); + int32_t OnGetWindowPid(int32_t windowId, int32_t &windowPid); #if defined(OHOS_BUILD_ENABLE_INTERCEPTOR) || defined(OHOS_BUILD_ENABLE_MONITOR) - int32_t CheckAddInput(int32_t pid, InputHandlerType handlerType, HandleEventType eventType); - int32_t CheckRemoveInput(int32_t pid, InputHandlerType handlerType, HandleEventType eventType); + int32_t CheckAddInput(int32_t pid, InputHandlerType handlerType, HandleEventType eventType, + int32_t priority, uint32_t deviceTags); + int32_t CheckRemoveInput(int32_t pid, InputHandlerType handlerType, HandleEventType eventType, + int32_t priority, uint32_t deviceTags); #endif // OHOS_BUILD_ENABLE_INTERCEPTOR || OHOS_BUILD_ENABLE_MONITOR int32_t CheckMarkConsumed(int32_t pid, int32_t eventId); #ifdef OHOS_BUILD_ENABLE_KEYBOARD @@ -130,12 +134,6 @@ protected: int32_t srcInputDeviceId); int32_t OnStopDeviceCooperate(int32_t pid, int32_t userData); int32_t OnGetInputDeviceCooperateState(int32_t pid, int32_t userData, const std::string &deviceId); - int32_t OnStartRemoteCooperate(const std::string& remoteDeviceId); - int32_t OnStartRemoteCooperateResult(bool isSuccess, - const std::string& startDhid, int32_t xPercent, int32_t yPercent); - int32_t OnStopRemoteCooperate(); - int32_t OnStopRemoteCooperateResult(bool isSuccess); - int32_t OnStartCooperateOtherResult(const std::string& srcNetworkId); #endif // OHOS_BUILD_ENABLE_COOPERATE bool InitLibinputService(); bool InitService(); @@ -161,6 +159,8 @@ private: LibinputAdapter libinputAdapter_; ServerMsgHandler sMsgHandler_; DelegateTasks delegateTasks_; + + std::atomic_bool threadStatusFlag_ { false }; }; } // namespace MMI } // namespace OHOS diff --git a/service/module_loader/include/uds_server.h b/service/module_loader/include/uds_server.h index de5d2cfeb2507f8111093a6d242afe4a098aa10d..ee17916c00b839449b8b35421710d50b4f613853 100644 --- a/service/module_loader/include/uds_server.h +++ b/service/module_loader/include/uds_server.h @@ -41,7 +41,7 @@ enum EpollEventType { using MsgServerFunCallback = std::function; class UDSServer : public UDSSocket, public IUdsServer { public: - UDSServer(); + UDSServer() = default; DISALLOW_COPY_AND_MOVE(UDSServer); virtual ~UDSServer(); void UdsStop(); diff --git a/service/module_loader/src/mmi_service.cpp b/service/module_loader/src/mmi_service.cpp index d83b7108ea27a127ae756210c621628a4fe52a2c..ecc00c6a5c42dfb465954d0a936fcc4fb8019113 100644 --- a/service/module_loader/src/mmi_service.cpp +++ b/service/module_loader/src/mmi_service.cpp @@ -19,7 +19,6 @@ #include #include #include -#include "dfx_hisysevent.h" #ifdef OHOS_RSS_CLIENT #include #endif @@ -28,6 +27,7 @@ #ifdef OHOS_BUILD_ENABLE_COOPERATE #include "cooperate_event_manager.h" #endif // OHOS_BUILD_ENABLE_COOPERATE +#include "dfx_hisysevent.h" #include "event_dump.h" #ifdef OHOS_BUILD_ENABLE_COOPERATE #include "input_device_cooperate_sm.h" @@ -36,26 +36,29 @@ #include "input_windows_manager.h" #include "i_pointer_drawing_manager.h" #include "key_map_manager.h" -#include "mmi_log.h" -#include "string_ex.h" -#include "util_ex.h" -#include "util_napi_error.h" #include "multimodal_input_connect_def_parcel.h" +#include "permission_helper.h" +#include "string_ex.h" #ifdef OHOS_RSS_CLIENT #include "res_sched_client.h" #include "res_type.h" #include "system_ability_definition.h" #endif -#include "permission_helper.h" + +#include "mmi_log.h" #include "timer_manager.h" -#include "input_device_manager.h" #include "util.h" +#include "util_ex.h" +#include "util_napi_error.h" +#include "xcollie/watchdog.h" namespace OHOS { namespace MMI { namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "MMIService" }; const std::string DEF_INPUT_SEAT = "seat0"; +constexpr int32_t WATCHDOG_INTERVAL_TIME = 10000; +constexpr int32_t WATCHDOG_DELAY_TIME = 15000; } // namespace const bool REGISTER_RESULT = @@ -69,7 +72,6 @@ struct mmi_epoll_event { template void CheckDefineOutput(const char* fmt, Ts... args) { - using namespace OHOS::MMI; CHKPV(fmt); char buf[MAX_PACKET_BUF_SIZE] = {}; int32_t ret = snprintf_s(buf, MAX_PACKET_BUF_SIZE, MAX_PACKET_BUF_SIZE - 1, fmt, args...); @@ -84,15 +86,6 @@ void CheckDefineOutput(const char* fmt, Ts... args) static void CheckDefine() { CheckDefineOutput("ChkDefs:"); -#ifdef OHOS_BUILD_LIBINPUT - CheckDefineOutput("%-40s", "OHOS_BUILD_LIBINPUT"); -#endif -#ifdef OHOS_BUILD_HDF - CheckDefineOutput("%-40s", "OHOS_BUILD_HDF"); -#endif -#ifdef OHOS_BUILD_MMI_DEBUG - CheckDefineOutput("%-40s", "OHOS_BUILD_MMI_DEBUG"); -#endif #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING CheckDefineOutput("%-40s", "OHOS_BUILD_ENABLE_POINTER_DRAWING"); #endif @@ -186,10 +179,6 @@ bool MMIService::IsRunning() const bool MMIService::InitLibinputService() { -#ifdef OHOS_BUILD_HDF - MMI_HILOGD("HDF Init"); - hdfEventManager.SetupCallback(); -#endif if (!(libinputAdapter_.Init(std::bind(&InputEventHandler::OnEvent, InputHandler, std::placeholders::_1), DEF_INPUT_SEAT))) { MMI_HILOGE("Libinput init, bind failed"); @@ -214,11 +203,7 @@ bool MMIService::InitService() MMI_HILOGE("Service running status is not enabled"); return false; } - if (!(Publish(this))) { - MMI_HILOGE("Service initialization failed"); - return false; - } - if (EpollCreat(MAX_EVENT_SIZE) < 0) { + if (EpollCreate(MAX_EVENT_SIZE) < 0) { MMI_HILOGE("Create epoll failed"); return false; } @@ -228,6 +213,10 @@ bool MMIService::InitService() EpollClose(); return false; } + if (!(Publish(this))) { + MMI_HILOGE("Service initialization failed"); + return false; + } MMI_HILOGI("AddEpoll, epollfd:%{public}d,fd:%{public}d", mmiFd_, epollFd_); return true; } @@ -263,17 +252,17 @@ int32_t MMIService::Init() return POINTER_DRAW_INIT_FAIL; } #endif // OHOS_BUILD_ENABLE_POINTER - mmiFd_ = EpollCreat(MAX_EVENT_SIZE); + mmiFd_ = EpollCreate(MAX_EVENT_SIZE); if (mmiFd_ < 0) { MMI_HILOGE("Create epoll failed"); return EPOLL_CREATE_FAIL; } - if (!InitService()) { - MMI_HILOGE("Saservice init failed"); - return SASERVICE_INIT_FAIL; - } #ifdef OHOS_BUILD_ENABLE_COOPERATE - InputDevCooSM->Init(); + /* + * PostAsyncTask is used here to prevent InputDeviceCooperateSM:: StartRemoteCooperate() and + * CheckPointerEvent() from holding locks, resulting in deadlocks + */ + InputDevCooSM->Init(std::bind(&DelegateTasks::PostAsyncTask, &delegateTasks_, std::placeholders::_1), *this); #endif // OHOS_BUILD_ENABLE_COOPERATE MMI_HILOGD("Input msg handler init"); InputHandler->Init(*this); @@ -289,6 +278,10 @@ int32_t MMIService::Init() std::placeholders::_2)); KeyMapMgr->GetConfigKeyValue("default_keymap", KeyMapMgr->GetDefaultKeyId()); OHOS::system::SetParameter(INPUT_POINTER_DEVICE, "false"); + if (!InitService()) { + MMI_HILOGE("Saservice init failed"); + return SASERVICE_INIT_FAIL; + } MMI_HILOGI("Set para input.pointer.device false"); return RET_OK; } @@ -296,6 +289,7 @@ int32_t MMIService::Init() void MMIService::OnStart() { int sleepSeconds = 3; + std::string name = "mmi-service"; sleep(sleepSeconds); CHK_PID_AND_TID(); int32_t ret = Init(); @@ -307,9 +301,29 @@ void MMIService::OnStart() MMI_HILOGD("Started successfully"); AddReloadDeviceTimer(); t_ = std::thread(std::bind(&MMIService::OnThread, this)); + pthread_setname_np(t_.native_handle(), name.c_str()); #ifdef OHOS_RSS_CLIENT + MMI_HILOGI("Add system ability listener start"); AddSystemAbilityListener(RES_SCHED_SYS_ABILITY_ID); + MMI_HILOGI("Add system ability listener success"); #endif + + TimerMgr->AddTimer(WATCHDOG_INTERVAL_TIME, -1, [this]() { + MMI_HILOGD("Set thread status flag to true"); + threadStatusFlag_ = true; + }); + auto taskFunc = [this]() { + if (threadStatusFlag_) { + MMI_HILOGD("Set thread status flag to false"); + threadStatusFlag_ = false; + } else { + MMI_HILOGE("Watchdog happened"); + } + }; + MMI_HILOGI("Run periodical task start"); + HiviewDFX::Watchdog::GetInstance().RunPeriodicalTask("MMIService", taskFunc, + WATCHDOG_INTERVAL_TIME, WATCHDOG_DELAY_TIME); + MMI_HILOGI("Run periodical task success"); t_.join(); } @@ -320,7 +334,9 @@ void MMIService::OnStop() libinputAdapter_.Stop(); state_ = ServiceRunningState::STATE_NOT_START; #ifdef OHOS_RSS_CLIENT + MMI_HILOGI("Remove system ability listener start"); RemoveSystemAbilityListener(RES_SCHED_SYS_ABILITY_ID); + MMI_HILOGI("Remove system ability listener success"); #endif } @@ -353,18 +369,35 @@ int32_t MMIService::AllocSocketFd(const std::string &programName, const int32_t return RET_OK; } -int32_t MMIService::AddInputEventFilter(sptr filter) +int32_t MMIService::AddInputEventFilter(sptr filter, int32_t filterId, int32_t priority, + uint32_t deviceTags) { CALL_INFO_TRACE; -#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) +#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) || defined(OHOS_BUILD_ENABLE_KEYBOARD) CHKPR(filter, ERROR_NULL_POINTER); + int32_t clientPid = GetCallingPid(); int32_t ret = delegateTasks_.PostSyncTask(std::bind(&ServerMsgHandler::AddInputEventFilter, - &sMsgHandler_, filter)); + &sMsgHandler_, filter, filterId, priority, deviceTags, clientPid)); if (ret != RET_OK) { MMI_HILOGE("Add event filter failed,return %{public}d", ret); return ret; } -#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH +#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH || OHOS_BUILD_ENABLE_KEYBOARD + return RET_OK; +} + +int32_t MMIService::RemoveInputEventFilter(int32_t filterId) +{ + CALL_INFO_TRACE; +#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) || defined(OHOS_BUILD_ENABLE_KEYBOARD) + int32_t clientPid = GetCallingPid(); + int32_t ret = delegateTasks_.PostSyncTask(std::bind(&ServerMsgHandler::RemoveInputEventFilter, + &sMsgHandler_, filterId, clientPid)); + if (ret != RET_OK) { + MMI_HILOGE("Remove event filter failed,return %{public}d", ret); + return ret; + } +#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH || OHOS_BUILD_ENABLE_KEYBOARD return RET_OK; } @@ -378,6 +411,10 @@ void MMIService::OnDisconnected(SessionPtr s) { CHKPV(s); MMI_HILOGW("Enter, session desc:%{public}s, fd:%{public}d", s->GetDescript().c_str(), s->GetFd()); + auto ret = RemoveInputEventFilter(-1); + if (ret != RET_OK) { + MMI_HILOGF("Remove all filter failed, ret:%{public}d", ret); + } #ifdef OHOS_BUILD_ENABLE_POINTER IPointerDrawingManager::GetInstance()->DeletePointerVisible(s->GetPid()); #endif // OHOS_BUILD_ENABLE_POINTER @@ -418,6 +455,18 @@ int32_t MMIService::IsPointerVisible(bool &visible) return RET_OK; } +int32_t MMIService::MarkProcessed(int32_t eventType, int32_t eventId) +{ + CALL_DEBUG_ENTER; + int32_t ret = delegateTasks_.PostSyncTask( + std::bind(&ANRManager::MarkProcessed, ANRMgr, GetCallingPid(), eventType, eventId)); + if (ret != RET_OK) { + MMI_HILOGE("Mark event processed failed, ret:%{public}d", ret); + return RET_ERR; + } + return RET_OK; +} + int32_t MMIService::SetPointerSpeed(int32_t speed) { CALL_DEBUG_ENTER; @@ -453,7 +502,7 @@ int32_t MMIService::GetPointerSpeed(int32_t &speed) return RET_OK; } -int32_t MMIService::SetPointerStyle(int32_t windowId, int32_t pointerStyle) +int32_t MMIService::SetPointerStyle(int32_t windowId, PointerStyle pointerStyle) { CALL_DEBUG_ENTER; #ifdef OHOS_BUILD_ENABLE_POINTER @@ -467,7 +516,7 @@ int32_t MMIService::SetPointerStyle(int32_t windowId, int32_t pointerStyle) return RET_OK; } -int32_t MMIService::GetPointerStyle(int32_t windowId, int32_t &pointerStyle) +int32_t MMIService::GetPointerStyle(int32_t windowId, PointerStyle &pointerStyle) { CALL_DEBUG_ENTER; #ifdef OHOS_BUILD_ENABLE_POINTER @@ -481,12 +530,9 @@ int32_t MMIService::GetPointerStyle(int32_t windowId, int32_t &pointerStyle) return RET_OK; } -int32_t MMIService::OnSupportKeys(int32_t pid, int32_t userData, int32_t deviceId, std::vector &keys) +int32_t MMIService::OnSupportKeys(int32_t deviceId, std::vector &keys, std::vector &keystroke) { CALL_DEBUG_ENTER; - auto sess = GetSession(GetClientFd(pid)); - CHKPR(sess, RET_ERR); - std::vector keystroke; int32_t ret = InputDevMgr->SupportKeys(deviceId, keys, keystroke); if (keystroke.size() > MAX_SUPPORT_KEY) { MMI_HILOGE("Device exceeds the max range"); @@ -496,30 +542,14 @@ int32_t MMIService::OnSupportKeys(int32_t pid, int32_t userData, int32_t deviceI MMI_HILOGE("Device id not support"); return ret; } - - NetPacket pkt(MmiMessageId::INPUT_DEVICE_SUPPORT_KEYS); - pkt << userData << keystroke.size(); - for (const bool &item : keystroke) { - pkt << item; - } - - if (pkt.ChkRWError()) { - MMI_HILOGE("Packet write support keys info failed"); - return RET_ERR; - } - if (!sess->SendMsg(pkt)) { - MMI_HILOGE("Sending failed"); - return MSG_SEND_FAIL; - } return RET_OK; } -int32_t MMIService::SupportKeys(int32_t userData, int32_t deviceId, std::vector &keys) +int32_t MMIService::SupportKeys(int32_t deviceId, std::vector &keys, std::vector &keystroke) { CALL_DEBUG_ENTER; - int32_t pid = GetCallingPid(); int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::OnSupportKeys, this, - pid, userData, deviceId, keys)); + deviceId, keys, std::ref(keystroke))); if (ret != RET_OK) { MMI_HILOGE("Support keys info process failed, ret:%{public}d", ret); return ret; @@ -527,34 +557,17 @@ int32_t MMIService::SupportKeys(int32_t userData, int32_t deviceId, std::vector< return RET_OK; } -int32_t MMIService::OnGetDeviceIds(int32_t pid, int32_t userData) +int32_t MMIService::OnGetDeviceIds(std::vector &ids) { CALL_DEBUG_ENTER; - auto sess = GetSession(GetClientFd(pid)); - CHKPR(sess, RET_ERR); - std::vector ids = InputDevMgr->GetInputDeviceIds(); - if (ids.size() > MAX_INPUT_DEVICE) { - MMI_HILOGE("Device exceeds the max range"); - return RET_ERR; - } - NetPacket pkt(MmiMessageId::INPUT_DEVICE_IDS); - pkt << userData << ids; - if (pkt.ChkRWError()) { - MMI_HILOGE("Packet write data failed"); - return RET_ERR; - } - if (!sess->SendMsg(pkt)) { - MMI_HILOGE("Sending failed"); - return MSG_SEND_FAIL; - } + ids = InputDevMgr->GetInputDeviceIds(); return RET_OK; } -int32_t MMIService::GetDeviceIds(int32_t userData) +int32_t MMIService::GetDeviceIds(std::vector &ids) { CALL_DEBUG_ENTER; - int32_t pid = GetCallingPid(); - int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::OnGetDeviceIds, this, pid, userData)); + int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::OnGetDeviceIds, this, std::ref(ids))); if (ret != RET_OK) { MMI_HILOGE("Get deviceids failed, ret:%{public}d", ret); return RET_ERR; @@ -562,38 +575,22 @@ int32_t MMIService::GetDeviceIds(int32_t userData) return RET_OK; } -int32_t MMIService::OnGetDevice(int32_t pid, int32_t userData, int32_t deviceId) +int32_t MMIService::OnGetDevice(int32_t deviceId, std::shared_ptr &inputDevice) { CALL_DEBUG_ENTER; - auto sess = GetSession(GetClientFd(pid)); - CHKPR(sess, RET_ERR); - std::shared_ptr inputDevice = std::make_shared(); if (InputDevMgr->GetInputDevice(deviceId) == nullptr) { MMI_HILOGE("Input device not found"); return COMMON_PARAMETER_ERROR; } inputDevice = InputDevMgr->GetInputDevice(deviceId); - NetPacket pkt(MmiMessageId::INPUT_DEVICE); - pkt << userData << inputDevice->GetId() << inputDevice->GetName() << inputDevice->GetType() - << inputDevice->GetBus() << inputDevice->GetProduct() << inputDevice->GetVendor() - << inputDevice->GetVersion() << inputDevice->GetPhys() << inputDevice->GetUniq() - << inputDevice->GetAxisInfo().size(); - if (pkt.ChkRWError()) { - MMI_HILOGE("Packet write input device info failed"); - return RET_ERR; - } - if (!sess->SendMsg(pkt)) { - MMI_HILOGE("Sending failed"); - return MSG_SEND_FAIL; - } return RET_OK; } -int32_t MMIService::GetDevice(int32_t userData, int32_t deviceId) +int32_t MMIService::GetDevice(int32_t deviceId, std::shared_ptr &inputDevice) { CALL_DEBUG_ENTER; - int32_t pid = GetCallingPid(); - int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::OnGetDevice, this, pid, userData, deviceId)); + int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::OnGetDevice, this, + deviceId, std::ref(inputDevice))); if (ret != RET_OK) { MMI_HILOGE("Get input device info failed, ret:%{public}d", ret); return ret; @@ -653,59 +650,46 @@ int32_t MMIService::UnregisterDevListener() return RET_OK; } -int32_t MMIService::OnGetKeyboardType(int32_t pid, int32_t userData, int32_t deviceId) +int32_t MMIService::OnGetKeyboardType(int32_t deviceId, int32_t &keyboardType) { - auto sess = GetSession(GetClientFd(pid)); - CHKPR(sess, RET_ERR); - int32_t keyboardType = 0; int32_t ret = InputDevMgr->GetKeyboardType(deviceId, keyboardType); if (ret != RET_OK) { MMI_HILOGE("GetKeyboardType call failed"); return ret; } - NetPacket pkt(MmiMessageId::INPUT_DEVICE_KEYBOARD_TYPE); - pkt << userData << keyboardType; - if (pkt.ChkRWError()) { - MMI_HILOGE("Packet write keyboard type failed"); - return RET_ERR; - } - if (!sess->SendMsg(pkt)) { - MMI_HILOGE("Failed to send the keyboard package"); - return MSG_SEND_FAIL; - } return RET_OK; } -int32_t MMIService::GetKeyboardType(int32_t userData, int32_t deviceId) +int32_t MMIService::GetKeyboardType(int32_t deviceId, int32_t &keyboardType) { CALL_DEBUG_ENTER; - int32_t pid = GetCallingPid(); int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::OnGetKeyboardType, this, - pid, userData, deviceId)); + deviceId, std::ref(keyboardType))); if (ret != RET_OK) { MMI_HILOGE("Get keyboard type failed, ret:%{public}d", ret); - return RET_ERR; + return ret; } - return RET_OK; + return ret; } #if defined(OHOS_BUILD_ENABLE_INTERCEPTOR) || defined(OHOS_BUILD_ENABLE_MONITOR) int32_t MMIService::CheckAddInput(int32_t pid, InputHandlerType handlerType, - HandleEventType eventType) + HandleEventType eventType, int32_t priority, uint32_t deviceTags) { auto sess = GetSessionByPid(pid); CHKPR(sess, ERROR_NULL_POINTER); - return sMsgHandler_.OnAddInputHandler(sess, handlerType, eventType); + return sMsgHandler_.OnAddInputHandler(sess, handlerType, eventType, priority, deviceTags); } #endif // OHOS_BUILD_ENABLE_INTERCEPTOR || OHOS_BUILD_ENABLE_MONITOR -int32_t MMIService::AddInputHandler(InputHandlerType handlerType, HandleEventType eventType) +int32_t MMIService::AddInputHandler(InputHandlerType handlerType, HandleEventType eventType, + int32_t priority, uint32_t deviceTags) { CALL_INFO_TRACE; #if defined(OHOS_BUILD_ENABLE_INTERCEPTOR) || defined(OHOS_BUILD_ENABLE_MONITOR) int32_t pid = GetCallingPid(); int32_t ret = delegateTasks_.PostSyncTask( - std::bind(&MMIService::CheckAddInput, this, pid, handlerType, eventType)); + std::bind(&MMIService::CheckAddInput, this, pid, handlerType, eventType, priority, deviceTags)); if (ret != RET_OK) { MMI_HILOGE("Add input handler failed, ret:%{public}d", ret); return RET_ERR; @@ -715,21 +699,23 @@ int32_t MMIService::AddInputHandler(InputHandlerType handlerType, HandleEventTyp } #if defined(OHOS_BUILD_ENABLE_INTERCEPTOR) || defined(OHOS_BUILD_ENABLE_MONITOR) -int32_t MMIService::CheckRemoveInput(int32_t pid, InputHandlerType handlerType, HandleEventType eventType) +int32_t MMIService::CheckRemoveInput(int32_t pid, InputHandlerType handlerType, HandleEventType eventType, + int32_t priority, uint32_t deviceTags) { auto sess = GetSessionByPid(pid); CHKPR(sess, ERROR_NULL_POINTER); - return sMsgHandler_.OnRemoveInputHandler(sess, handlerType, eventType); + return sMsgHandler_.OnRemoveInputHandler(sess, handlerType, eventType, priority, deviceTags); } #endif // OHOS_BUILD_ENABLE_INTERCEPTOR || OHOS_BUILD_ENABLE_MONITOR -int32_t MMIService::RemoveInputHandler(InputHandlerType handlerType, HandleEventType eventType) +int32_t MMIService::RemoveInputHandler(InputHandlerType handlerType, HandleEventType eventType, + int32_t priority, uint32_t deviceTags) { CALL_INFO_TRACE; #if defined(OHOS_BUILD_ENABLE_INTERCEPTOR) || defined(OHOS_BUILD_ENABLE_MONITOR) int32_t pid = GetCallingPid(); int32_t ret = delegateTasks_.PostSyncTask( - std::bind(&MMIService::CheckRemoveInput, this, pid, handlerType, eventType)); + std::bind(&MMIService::CheckRemoveInput, this, pid, handlerType, eventType, priority, deviceTags)); if (ret != RET_OK) { MMI_HILOGE("Remove input handler failed, ret:%{public}d", ret); return RET_ERR; @@ -749,7 +735,7 @@ int32_t MMIService::CheckMarkConsumed(int32_t pid, int32_t eventId) int32_t MMIService::MarkEventConsumed(int32_t eventId) { - CALL_INFO_TRACE; + CALL_DEBUG_ENTER; #ifdef OHOS_BUILD_ENABLE_MONITOR int32_t pid = GetCallingPid(); int32_t ret = delegateTasks_.PostSyncTask( @@ -778,7 +764,7 @@ int32_t MMIService::MoveMouseEvent(int32_t offsetX, int32_t offsetY) int32_t MMIService::InjectKeyEvent(const std::shared_ptr keyEvent) { - CALL_INFO_TRACE; + CALL_DEBUG_ENTER; #ifdef OHOS_BUILD_ENABLE_KEYBOARD int32_t ret = delegateTasks_.PostSyncTask( std::bind(&MMIService::CheckInjectKeyEvent, this, keyEvent)); @@ -808,7 +794,7 @@ int32_t MMIService::CheckInjectPointerEvent(const std::shared_ptr int32_t MMIService::InjectPointerEvent(const std::shared_ptr pointerEvent) { - CALL_INFO_TRACE; + CALL_DEBUG_ENTER; #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) int32_t ret = delegateTasks_.PostSyncTask( std::bind(&MMIService::CheckInjectPointerEvent, this, pointerEvent)); @@ -823,6 +809,7 @@ int32_t MMIService::InjectPointerEvent(const std::shared_ptr point #ifdef OHOS_RSS_CLIENT void MMIService::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) { + CALL_INFO_TRACE; if (systemAbilityId == RES_SCHED_SYS_ABILITY_ID) { int sleepSeconds = 1; sleep(sleepSeconds); @@ -879,6 +866,30 @@ int32_t MMIService::SetAnrObserver() return RET_OK; } +int32_t MMIService::GetDisplayBindInfo(DisplayBindInfos &infos) +{ + CALL_DEBUG_ENTER; + int32_t ret = delegateTasks_.PostSyncTask( + std::bind(&InputWindowsManager::GetDisplayBindInfo, WinMgr, std::ref(infos))); + if (ret != RET_OK) { + MMI_HILOGE("GetDisplayBindInfo pid failed, ret:%{public}d", ret); + return RET_ERR; + } + return RET_OK; +} + +int32_t MMIService::SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg) +{ + CALL_DEBUG_ENTER; + int32_t ret = delegateTasks_.PostSyncTask( + std::bind(&InputWindowsManager::SetDisplayBind, WinMgr, deviceId, displayId, std::ref(msg))); + if (ret != RET_OK) { + MMI_HILOGE("SetDisplayBind pid failed, ret:%{public}d", ret); + return RET_ERR; + } + return RET_OK; +} + int32_t MMIService::GetFunctionKeyState(int32_t funcKey, bool &state) { CALL_INFO_TRACE; @@ -911,6 +922,19 @@ int32_t MMIService::SetFunctionKeyState(int32_t funcKey, bool enable) return RET_OK; } +int32_t MMIService::SetPointerLocation(int32_t x, int32_t y) +{ + CALL_DEBUG_ENTER; +#if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING) + int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MouseEventNormalize::SetPointerLocation, + MouseEventHdr, x, y)); + if (ret != RET_OK) { + MMI_HILOGE("Set pointer location failed,ret %{public}d", ret); + return RET_ERR; + } +#endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING + return RET_OK; +} void MMIService::OnDelegateTask(epoll_event& ev) { if ((ev.events & EPOLLIN) == 0) { @@ -969,7 +993,7 @@ void MMIService::OnThread() bool MMIService::InitSignalHandler() { CALL_DEBUG_ENTER; - sigset_t mask = {0}; + sigset_t mask = { 0 }; int32_t retCode = sigfillset(&mask); if (retCode < 0) { MMI_HILOGE("Fill signal set failed:%{public}d", errno); @@ -1209,7 +1233,7 @@ int32_t MMIService::OnUnregisterCooperateListener(int32_t pid) int32_t MMIService::OnEnableInputDeviceCooperate(int32_t pid, int32_t userData, bool enabled) { CALL_DEBUG_ENTER; - InputDevCooSM->EnableInputDeviceCooperate(enabled); + InputDevCooSM->EnableInputDeviceCooperate(enabled, pid); std::string deviceId = ""; CooperationMessage msg = enabled ? CooperationMessage::OPEN_SUCCESS : CooperationMessage::CLOSE_SUCCESS; @@ -1288,118 +1312,51 @@ int32_t MMIService::OnGetInputDeviceCooperateState(int32_t pid, int32_t userData } #endif // OHOS_BUILD_ENABLE_COOPERATE -int32_t MMIService::StartRemoteCooperate(const std::string& remoteDeviceId) +int32_t MMIService::SetMouseCaptureMode(int32_t windowId, bool isCaptureMode) { CALL_DEBUG_ENTER; -#ifdef OHOS_BUILD_ENABLE_COOPERATE - int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::OnStartRemoteCooperate, - this, remoteDeviceId)); - if (ret != RET_OK) { - MMI_HILOGE("Start remote cooperate failed,return %{public}d", ret); - return ret; - } -#endif // OHOS_BUILD_ENABLE_COOPERATE - return RET_OK; -} - -int32_t MMIService::StartRemoteCooperateResult(bool isSuccess, - const std::string& startDhid, int32_t xPercent, int32_t yPercent) -{ - CALL_DEBUG_ENTER; -#ifdef OHOS_BUILD_ENABLE_COOPERATE - MMI_HILOGI("StartRemoteCooperateResult:[%{public}d]", isSuccess); - int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::OnStartRemoteCooperateResult, - this, isSuccess, startDhid, xPercent, yPercent)); + int32_t ret = delegateTasks_.PostSyncTask( + std::bind(&InputWindowsManager::SetMouseCaptureMode, WinMgr, windowId, isCaptureMode)); if (ret != RET_OK) { - MMI_HILOGE("Start remote cooperate res failed,return %{public}d", ret); - return ret; + MMI_HILOGE("Set capture failed,return %{public}d", ret); + return RET_ERR; } -#else - (void)(isSuccess); - (void)(xPercent); - (void)(yPercent); -#endif // OHOS_BUILD_ENABLE_COOPERATE return RET_OK; } -int32_t MMIService::StopRemoteCooperate() +int32_t MMIService::OnGetWindowPid(int32_t windowId, int32_t &windowPid) { CALL_DEBUG_ENTER; -#ifdef OHOS_BUILD_ENABLE_COOPERATE - int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::OnStopRemoteCooperate, this)); - if (ret != RET_OK) { - MMI_HILOGE("Stop remote cooperate failed,return %{public}d", ret); - return ret; + windowPid = WinMgr->GetWindowPid(windowId); + if (windowPid == RET_ERR) { + MMI_HILOGE("Get window pid failed"); } -#endif // OHOS_BUILD_ENABLE_COOPERATE + MMI_HILOGD("windowpid is %{public}d", windowPid); return RET_OK; } -int32_t MMIService::StopRemoteCooperateResult(bool isSuccess) +int32_t MMIService::GetWindowPid(int32_t windowId) { CALL_DEBUG_ENTER; -#ifdef OHOS_BUILD_ENABLE_COOPERATE - MMI_HILOGI("Enter MMI StopRemoteCooperateResult [%{public}d]", isSuccess); - int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::OnStopRemoteCooperateResult, - this, isSuccess)); + int32_t windowPid = -1; + int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::OnGetWindowPid, this, windowId, std::ref(windowPid))); if (ret != RET_OK) { - MMI_HILOGE("Stop remote cooperate res failed,return %{public}d", ret); - return ret; + MMI_HILOGE("OnGetWindowPid failed, ret:%{public}d", ret); + return RET_ERR; } -#else - (void)(isSuccess); -#endif // OHOS_BUILD_ENABLE_COOPERATE - return RET_OK; + MMI_HILOGD("windowpid is %{public}d", windowPid); + return windowPid; } -int32_t MMIService::StartCooperateOtherResult(const std::string& srcNetworkId) +int32_t MMIService::AppendExtraData(const ExtraData& extraData) { CALL_DEBUG_ENTER; -#ifdef OHOS_BUILD_ENABLE_COOPERATE - MMI_HILOGI("Enter MMI StartCooperateOtherResult [%{public}s]", srcNetworkId.c_str()); - int32_t ret = delegateTasks_.PostSyncTask(std::bind(&MMIService::OnStartCooperateOtherResult, - this, srcNetworkId)); + int32_t ret = delegateTasks_.PostSyncTask(std::bind(&InputWindowsManager::AppendExtraData, + WinMgr, extraData)); if (ret != RET_OK) { - MMI_HILOGE("Start remote other res failed,return %{public}d", ret); - return ret; + MMI_HILOGE("Append extra data failed:%{public}d", ret); } -#else - (void)(srcNetworkId); -#endif // OHOS_BUILD_ENABLE_COOPERATE - return RET_OK; -} - -#ifdef OHOS_BUILD_ENABLE_COOPERATE -int32_t MMIService::OnStartRemoteCooperate(const std::string& remoteDeviceId) -{ - InputDevCooSM->StartRemoteCooperate(remoteDeviceId); - return RET_OK; -} - -int32_t MMIService::OnStartRemoteCooperateResult(bool isSuccess, - const std::string& startDhid, int32_t xPercent, int32_t yPercent) -{ - InputDevCooSM->StartRemoteCooperateResult(isSuccess, startDhid, xPercent, yPercent); - return RET_OK; -} - -int32_t MMIService::OnStopRemoteCooperate() -{ - InputDevCooSM->StopRemoteCooperate(); - return RET_OK; -} - -int32_t MMIService::OnStopRemoteCooperateResult(bool isSuccess) -{ - InputDevCooSM->StopRemoteCooperateResult(isSuccess); - return RET_OK; -} - -int32_t MMIService::OnStartCooperateOtherResult(const std::string& srcNetworkId) -{ - InputDevCooSM->StartCooperateOtherResult(srcNetworkId); - return RET_OK; + return ret; } -#endif // OHOS_BUILD_ENABLE_COOPERATE } // namespace MMI } // namespace OHOS diff --git a/service/module_loader/src/uds_server.cpp b/service/module_loader/src/uds_server.cpp old mode 100755 new mode 100644 index 1677e4a3d6a6386798edec5a5ca622ee8edaff54..aeb825ce464795137122633509b8dd0620806a6d --- a/service/module_loader/src/uds_server.cpp +++ b/service/module_loader/src/uds_server.cpp @@ -29,9 +29,8 @@ namespace OHOS { namespace MMI { namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "UDSServer"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "UDSServer" }; } // namespace -UDSServer::UDSServer() {} UDSServer::~UDSServer() { @@ -97,76 +96,72 @@ int32_t UDSServer::AddSocketPairInfo(const std::string& programName, int32_t& serverFd, int32_t& toReturnClientFd, int32_t& tokenType) { CALL_DEBUG_ENTER; - int32_t sockFds[2] = {}; + int32_t sockFds[2] = { -1 }; if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockFds) != 0) { MMI_HILOGE("Call socketpair failed, errno:%{public}d", errno); return RET_ERR; } - serverFd = sockFds[0]; toReturnClientFd = sockFds[1]; - if (toReturnClientFd < 0) { + if (serverFd < 0 || toReturnClientFd < 0) { MMI_HILOGE("Call fcntl failed, errno:%{public}d", errno); return RET_ERR; } - static constexpr size_t bufferSize = 32 * 1024; - setsockopt(sockFds[0], SOL_SOCKET, SO_SNDBUF, &bufferSize, sizeof(bufferSize)); - setsockopt(sockFds[0], SOL_SOCKET, SO_RCVBUF, &bufferSize, sizeof(bufferSize)); + static constexpr size_t nativeBufferSize = 64 * 1024; + SessionPtr sess = nullptr; + if (setsockopt(serverFd, SOL_SOCKET, SO_SNDBUF, &bufferSize, sizeof(bufferSize)) != 0) { + MMI_HILOGE("setsockopt serverFd failed, errno: %{public}d", errno); + goto CLOSE_SOCK; + } + if (setsockopt(serverFd, SOL_SOCKET, SO_RCVBUF, &bufferSize, sizeof(bufferSize)) != 0) { + MMI_HILOGE("setsockopt serverFd failed, errno: %{public}d", errno); + goto CLOSE_SOCK; + } if (tokenType == TokenType::TOKEN_NATIVE) { - static constexpr size_t nativeBufferSize = 64 * 1024; - setsockopt(sockFds[1], SOL_SOCKET, SO_SNDBUF, &nativeBufferSize, sizeof(nativeBufferSize)); - setsockopt(sockFds[1], SOL_SOCKET, SO_RCVBUF, &nativeBufferSize, sizeof(nativeBufferSize)); + if (setsockopt(toReturnClientFd, SOL_SOCKET, SO_SNDBUF, &nativeBufferSize, sizeof(nativeBufferSize)) != 0) { + MMI_HILOGE("setsockopt toReturnClientFd failed, errno: %{public}d", errno); + goto CLOSE_SOCK; + } + if (setsockopt(toReturnClientFd, SOL_SOCKET, SO_RCVBUF, &nativeBufferSize, sizeof(nativeBufferSize)) != 0) { + MMI_HILOGE("setsockopt toReturnClientFd failed, errno: %{public}d", errno); + goto CLOSE_SOCK; + } } else { - setsockopt(sockFds[1], SOL_SOCKET, SO_SNDBUF, &bufferSize, sizeof(bufferSize)); - setsockopt(sockFds[1], SOL_SOCKET, SO_RCVBUF, &bufferSize, sizeof(bufferSize)); - } - MMI_HILOGD("Alloc socketpair, serverFd:%{public}d,clientFd:%{public}d(%{public}d)", - serverFd, toReturnClientFd, sockFds[1]); - auto closeSocketFdWhenError = [&serverFd, &toReturnClientFd] { - close(serverFd); - close(toReturnClientFd); - serverFd = IMultimodalInputConnect::INVALID_SOCKET_FD; - toReturnClientFd = IMultimodalInputConnect::INVALID_SOCKET_FD; - }; - - std::list > cleanTaskList; - auto cleanTaskWhenError = [cleanTaskList] { - for (const auto &item : cleanTaskList) { - item(); + if (setsockopt(toReturnClientFd, SOL_SOCKET, SO_SNDBUF, &bufferSize, sizeof(bufferSize)) != 0) { + MMI_HILOGE("setsockopt toReturnClientFd failed, errno: %{public}d", errno); + goto CLOSE_SOCK; + } + if (setsockopt(toReturnClientFd, SOL_SOCKET, SO_RCVBUF, &bufferSize, sizeof(bufferSize)) != 0) { + MMI_HILOGE("setsockopt toReturnClientFd failed, errno: %{public}d", errno); + goto CLOSE_SOCK; } - }; - - cleanTaskList.push_back(closeSocketFdWhenError); - - int32_t ret = RET_OK; - ret = AddEpoll(EPOLL_EVENT_SOCKET, serverFd); - if (ret != RET_OK) { - cleanTaskWhenError(); - MMI_HILOGE("epoll_ctl EPOLL_CTL_ADD return %{public}d,errCode:%{public}d", ret, EPOLL_MODIFY_FAIL); - return ret; } - - SessionPtr sess = std::make_shared(programName, moduleType, serverFd, uid, pid); + if (AddEpoll(EPOLL_EVENT_SOCKET, serverFd) != RET_OK) { + MMI_HILOGE("epoll_ctl EPOLL_CTL_ADD failed, errCode:%{public}d", EPOLL_MODIFY_FAIL); + goto CLOSE_SOCK; + } + sess = std::make_shared(programName, moduleType, serverFd, uid, pid); if (sess == nullptr) { - cleanTaskWhenError(); MMI_HILOGE("make_shared fail. progName:%{public}s,pid:%{public}d,errCode:%{public}d", programName.c_str(), pid, MAKE_SHARED_FAIL); - return RET_ERR; + goto CLOSE_SOCK; } sess->SetTokenType(tokenType); -#ifdef OHOS_BUILD_MMI_DEBUG - sess->SetClientFd(toReturnClientFd); -#endif // OHOS__BUILD_MMI_DEBUG - if (!AddSession(sess)) { - cleanTaskWhenError(); MMI_HILOGE("AddSession fail errCode:%{public}d", ADD_SESSION_FAIL); - return RET_ERR; + goto CLOSE_SOCK; } OnConnected(sess); return RET_OK; + + CLOSE_SOCK: + close(serverFd); + serverFd = IMultimodalInputConnect::INVALID_SOCKET_FD; + close(toReturnClientFd); + toReturnClientFd = IMultimodalInputConnect::INVALID_SOCKET_FD; + return RET_ERR; } void UDSServer::Dump(int32_t fd, const std::vector &args) @@ -209,6 +204,7 @@ void UDSServer::SetRecvFun(MsgServerFunCallback fun) void UDSServer::ReleaseSession(int32_t fd, epoll_event& ev) { + CALL_INFO_TRACE; auto secPtr = GetSession(fd); if (secPtr != nullptr) { OnDisconnected(secPtr); @@ -248,9 +244,6 @@ void UDSServer::OnEpollRecv(int32_t fd, epoll_event& ev) for (int32_t i = 0; i < MAX_RECV_LIMIT; i++) { auto size = recv(fd, szBuf, MAX_PACKET_BUF_SIZE, MSG_DONTWAIT | MSG_NOSIGNAL); if (size > 0) { -#ifdef OHOS_BUILD_HAVE_DUMP_DATA - DumpData(szBuf, size, LINEINFO, "in %s, read message from fd: %d.", __func__, fd); -#endif if (!buf.Write(szBuf, size)) { MMI_HILOGW("Write data failed. size:%{public}zu", size); } diff --git a/service/module_loader/test/uds_server_test.cpp b/service/module_loader/test/uds_server_test.cpp index 17eaf0659af26e4502f152bda68d88dd85a3ddd2..5d52297dd919096f4d3a50b33364e9b6d54dbb97 100644 --- a/service/module_loader/test/uds_server_test.cpp +++ b/service/module_loader/test/uds_server_test.cpp @@ -22,7 +22,6 @@ namespace OHOS { namespace MMI { namespace { using namespace testing::ext; -using namespace OHOS::MMI; } // namespace class UDSServerTest : public testing::Test { diff --git a/service/monitor/include/event_monitor_handler.h b/service/monitor/include/event_monitor_handler.h index a8ea0524290a339fd37bd5011fae4e69b9fb1f69..8c0e9a571c7b0c900173bc113e6a8cdefde2ccf0 100644 --- a/service/monitor/include/event_monitor_handler.h +++ b/service/monitor/include/event_monitor_handler.h @@ -23,18 +23,18 @@ #include "nocopyable.h" -#include "i_input_event_handler.h" #include "i_input_event_collection_handler.h" +#include "i_input_event_handler.h" #include "input_handler_type.h" #include "uds_session.h" namespace OHOS { namespace MMI { -class EventMonitorHandler : public IInputEventHandler { +class EventMonitorHandler final : public IInputEventHandler { public: EventMonitorHandler() = default; DISALLOW_COPY_AND_MOVE(EventMonitorHandler); - ~EventMonitorHandler() = default; + ~EventMonitorHandler() override = default; #ifdef OHOS_BUILD_ENABLE_KEYBOARD void HandleKeyEvent(const std::shared_ptr keyEvent) override; #endif // OHOS_BUILD_ENABLE_KEYBOARD @@ -99,7 +99,7 @@ private: void Dump(int32_t fd, const std::vector &args); struct ConsumptionState { - std::unordered_set eventIds_; + std::set eventIds_; bool isMonitorConsumed_ { false }; std::shared_ptr lastPointerEvent_ { nullptr }; }; diff --git a/service/monitor/src/event_monitor_handler.cpp b/service/monitor/src/event_monitor_handler.cpp index ed756757c34d63c786d0dc3c899bfb7184caa372..41042d7d0fc7c5c4889f42a9caed15919a776990 100644 --- a/service/monitor/src/event_monitor_handler.cpp +++ b/service/monitor/src/event_monitor_handler.cpp @@ -30,6 +30,9 @@ namespace OHOS { namespace MMI { namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "EventMonitorHandler" }; +#ifdef OHOS_BUILD_ENABLE_TOUCH +constexpr size_t MAX_EVENTIDS_SIZE = 1000; +#endif // OHOS_BUILD_ENABLE_TOUCH } // namespace #ifdef OHOS_BUILD_ENABLE_KEYBOARD @@ -155,7 +158,7 @@ void EventMonitorHandler::SessionHandler::SendToClient(std::shared_ptr { CHKPV(keyEvent); NetPacket pkt(MmiMessageId::REPORT_KEY_EVENT); - pkt << handlerType_; + pkt << handlerType_ << static_cast(evdev_device_udev_tags::EVDEV_UDEV_TAG_INPUT); if (pkt.ChkRWError()) { MMI_HILOGE("Packet write key event failed"); return; @@ -184,7 +187,7 @@ void EventMonitorHandler::SessionHandler::SendToClient(std::shared_ptr(evdev_device_udev_tags::EVDEV_UDEV_TAG_INPUT); if (pkt.ChkRWError()) { MMI_HILOGE("Packet write pointer event failed"); return; @@ -291,7 +294,6 @@ void EventMonitorHandler::MonitorCollection::MarkConsumed(int32_t eventId, Sessi #ifdef OHOS_BUILD_ENABLE_TOUCH MMI_HILOGD("Cancel operation"); auto pointerEvent = std::make_shared(*state.lastPointerEvent_); - CHKPV(pointerEvent); pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_CANCEL); pointerEvent->SetActionTime(GetSysClockTime()); pointerEvent->UpdateId(); @@ -357,6 +359,10 @@ void EventMonitorHandler::MonitorCollection::UpdateConsumptionState(std::shared_ sIter = tIter; } ConsumptionState &state = sIter->second; + if (state.eventIds_.size() >= MAX_EVENTIDS_SIZE) { + auto iter = state.eventIds_.begin(); + state.eventIds_.erase(iter); + } auto [tIter, isOk] = state.eventIds_.emplace(pointerEvent->GetId()); if (!isOk) { MMI_HILOGW("Failed to stash event"); diff --git a/service/mouse_event_normalize/include/mouse_device_state.h b/service/mouse_event_normalize/include/mouse_device_state.h index 710290150696fc9c35bfe1671e1a0018762bd7f3..3c5d7019070de7330a67a785d70ecc751c727c85 100644 --- a/service/mouse_event_normalize/include/mouse_device_state.h +++ b/service/mouse_event_normalize/include/mouse_device_state.h @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef MOUSE_DEVICE_STATE_H #define MOUSE_DEVICE_STATE_H @@ -45,23 +46,22 @@ public: int32_t physicalY { 0 }; }; const std::map mapLibinputChangeToPointer = { - {LIBINPUT_LEFT_BUTTON_CODE, PointerEvent::MOUSE_BUTTON_LEFT}, - {LIBINPUT_RIGHT_BUTTON_CODE, PointerEvent::MOUSE_BUTTON_RIGHT}, - {LIBINPUT_MIDDLE_BUTTON_CODE, PointerEvent::MOUSE_BUTTON_MIDDLE}, - {LIBINPUT_SIDE_BUTTON_CODE, PointerEvent::MOUSE_BUTTON_SIDE}, - {LIBINPUT_EXTRA_BUTTON_CODE, PointerEvent::MOUSE_BUTTON_EXTRA}, - {LIBINPUT_FORWARD_BUTTON_CODE, PointerEvent::MOUSE_BUTTON_FORWARD}, - {LIBINPUT_BACK_BUTTON_CODE, PointerEvent::MOUSE_BUTTON_BACK}, - {LIBINPUT_TASK_BUTTON_CODE, PointerEvent::MOUSE_BUTTON_TASK}, + { LIBINPUT_LEFT_BUTTON_CODE, PointerEvent::MOUSE_BUTTON_LEFT }, + { LIBINPUT_RIGHT_BUTTON_CODE, PointerEvent::MOUSE_BUTTON_RIGHT }, + { LIBINPUT_MIDDLE_BUTTON_CODE, PointerEvent::MOUSE_BUTTON_MIDDLE }, + { LIBINPUT_SIDE_BUTTON_CODE, PointerEvent::MOUSE_BUTTON_SIDE }, + { LIBINPUT_EXTRA_BUTTON_CODE, PointerEvent::MOUSE_BUTTON_EXTRA }, + { LIBINPUT_FORWARD_BUTTON_CODE, PointerEvent::MOUSE_BUTTON_FORWARD }, + { LIBINPUT_BACK_BUTTON_CODE, PointerEvent::MOUSE_BUTTON_BACK }, + { LIBINPUT_TASK_BUTTON_CODE, PointerEvent::MOUSE_BUTTON_TASK }, }; public: DISALLOW_COPY_AND_MOVE(MouseDeviceState); int32_t GetMouseCoordsX() const; int32_t GetMouseCoordsY() const; - void SetMouseCoords(const int32_t x, const int32_t y); + void SetMouseCoords(int32_t x, int32_t y); bool IsLeftBtnPressed(); void GetPressedButtons(std::vector& pressedButtons); - std::map GetMouseBtnState() const; void MouseBtnStateCounts(uint32_t btnCode, const BUTTON_STATE btnState); int32_t LibinputChangeToPointer(const uint32_t keyValue); diff --git a/service/mouse_event_normalize/include/mouse_event_normalize.h b/service/mouse_event_normalize/include/mouse_event_normalize.h index 3b188fd543ab159a962368b574d0afea658135f6..d5b499a71f95e57bf4dcf1d583cc2eacdf4ff137 100644 --- a/service/mouse_event_normalize/include/mouse_event_normalize.h +++ b/service/mouse_event_normalize/include/mouse_event_normalize.h @@ -21,26 +21,18 @@ #include "libinput.h" #include "singleton.h" +#include "define_multimodal.h" +#include "mouse_transform_processor.h" #include "pointer_event.h" namespace OHOS { namespace MMI { -namespace { -constexpr int32_t DEFAULT_SPEED = 5; -} // namespace - -struct AccelerateCurve { - std::vector speeds; - std::vector slopes; - std::vector diffNums; -}; - class MouseEventNormalize final : public std::enable_shared_from_this { DECLARE_DELAYED_SINGLETON(MouseEventNormalize); public: DISALLOW_COPY_AND_MOVE(MouseEventNormalize); - std::shared_ptr GetPointerEvent() const; - int32_t Normalize(struct libinput_event *event); + std::shared_ptr GetPointerEvent(); + int32_t OnEvent(struct libinput_event *event); void Dump(int32_t fd, const std::vector &args); #ifdef OHOS_BUILD_ENABLE_COOPERATE void SetAbsolutionLocation(double xPercent, double yPercent); @@ -52,36 +44,20 @@ public: int32_t GetPointerSpeed() const; void OnDisplayLost(int32_t displayId); int32_t GetDisplayId() const; + int32_t SetPointerLocation(int32_t x, int32_t y); private: - int32_t HandleMotionInner(struct libinput_event_pointer* data); - int32_t HandleButtonInner(struct libinput_event_pointer* data); - int32_t HandleAxisInner(struct libinput_event_pointer* data); - void HandlePostInner(struct libinput_event_pointer* data, int32_t deviceId, PointerEvent::PointerItem &pointerItem); -#ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING - void HandleMotionMoveMouse(int32_t offsetX, int32_t offsetY); - void HandlePostMoveMouse(PointerEvent::PointerItem &pointerItem); -#endif // OHOS_BUILD_ENABLE_POINTER_DRAWING - int32_t HandleButtonValueInner(struct libinput_event_pointer* data); - int32_t HandleMotionAccelerate(struct libinput_event_pointer* data); - bool GetSpeedGain(double vin, double &gain) const; - void DumpInner(); - void InitAbsolution(); -#ifdef OHOS_BUILD_ENABLE_COOPERATE - void SetDxDyForDInput(PointerEvent::PointerItem& pointerItem, libinput_event_pointer* data); -#endif // OHOS_BUILD_ENABLE_COOPERATE + std::shared_ptr GetProcessor(int32_t deviceId) const; + std::shared_ptr GetCurrentProcessor() const; + void SetCurrentDeviceId(int32_t deviceId); + int32_t GetCurrentDeviceId() const; private: - std::shared_ptr pointerEvent_ { nullptr }; - int32_t timerId_ { -1 }; - double absolutionX_ { -1.0 }; - double absolutionY_ { -1.0 }; int32_t buttonId_ { -1 }; bool isPressed_ { false }; - int32_t currentDisplayId_ { -1 }; - int32_t speed_ { DEFAULT_SPEED }; + std::map> processors_; + int32_t currentDeviceId_ { -1 }; }; - #define MouseEventHdr ::OHOS::DelayedSingleton::GetInstance() } // namespace MMI } // namespace OHOS diff --git a/service/mouse_event_normalize/include/mouse_transform_processor.h b/service/mouse_event_normalize/include/mouse_transform_processor.h new file mode 100644 index 0000000000000000000000000000000000000000..3d450b1770cd1efa89a0ab75cb2c80cc75823f69 --- /dev/null +++ b/service/mouse_event_normalize/include/mouse_transform_processor.h @@ -0,0 +1,89 @@ +/* + * 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 MOUSE_TRANSFORM_PROCESSOR_H +#define MOUSE_TRANSFORM_PROCESSOR_H + +#include +#include + +#include "libinput.h" +#include "singleton.h" +#include "define_multimodal.h" + +#include "pointer_event.h" + +namespace OHOS { +namespace MMI { +struct AccelerateCurve { + std::vector speeds; + std::vector slopes; + std::vector diffNums; +}; +class MouseTransformProcessor final : public std::enable_shared_from_this { +public: + DISALLOW_COPY_AND_MOVE(MouseTransformProcessor); + explicit MouseTransformProcessor(int32_t deviceId); + ~MouseTransformProcessor() = default; + std::shared_ptr GetPointerEvent() const; + int32_t Normalize(struct libinput_event *event); + void Dump(int32_t fd, const std::vector &args); +#ifdef OHOS_BUILD_ENABLE_COOPERATE + static void SetAbsolutionLocation(double xPercent, double yPercent); +#endif // OHOS_BUILD_ENABLE_COOPERATE +#ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING + bool NormalizeMoveMouse(int32_t offsetX, int32_t offsetY); +#endif // OHOS_BUILD_ENABLE_POINTER_DRAWING +private: + int32_t HandleMotionInner(struct libinput_event_pointer* data); + int32_t HandleButtonInner(struct libinput_event_pointer* data); + int32_t HandleAxisInner(struct libinput_event_pointer* data); + void HandlePostInner(struct libinput_event_pointer* data, PointerEvent::PointerItem &pointerItem); +#ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING + void HandleMotionMoveMouse(int32_t offsetX, int32_t offsetY); + void HandlePostMoveMouse(PointerEvent::PointerItem &pointerItem); +#endif // OHOS_BUILD_ENABLE_POINTER_DRAWING + int32_t HandleButtonValueInner(struct libinput_event_pointer* data); + int32_t HandleMotionAccelerate(struct libinput_event_pointer* data); + void DumpInner(); + void SetDxDyForDInput(PointerEvent::PointerItem& pointerItem, struct libinput_event_pointer* data); +public: + static void InitAbsolution(); + static void OnDisplayLost(int32_t displayId); + static int32_t GetDisplayId(); + static int32_t SetPointerSpeed(int32_t speed); + static int32_t GetPointerSpeed(); + bool GetSpeedGain(double vin, double &gain); + static int32_t SetPointerLocation(int32_t x, int32_t y); + void SetConfigPointerSpeed(int32_t speed); + int32_t GetSpeed() const; + +private: + static double absolutionX_; + static double absolutionY_; + static int32_t currentDisplayId_; + static int32_t globalPointerSpeed_; + static bool isUserSetSpeedStatus_; + + std::shared_ptr pointerEvent_ { nullptr }; + int32_t timerId_ { -1 }; + int32_t buttonId_ { -1 }; + bool isPressed_ { false }; + int32_t deviceId_ { -1 }; + int32_t vendorConfigPointerSpeed_ { -1 }; +}; +} // namespace MMI +} // namespace OHOS +#endif // MOUSE_TRANSFORM_PROCESSOR_H \ No newline at end of file diff --git a/service/mouse_event_normalize/src/mouse_device_state.cpp b/service/mouse_event_normalize/src/mouse_device_state.cpp index af64b2917c8e2ff6163f8d8e159d7ab74bb8fb95..7a12d934aa2860296c10e42bc97dfbed7fddf72f 100644 --- a/service/mouse_event_normalize/src/mouse_device_state.cpp +++ b/service/mouse_event_normalize/src/mouse_device_state.cpp @@ -20,12 +20,12 @@ namespace OHOS { namespace MMI { namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "MouseDeviceState"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "MouseDeviceState" }; } // namespace MouseDeviceState::MouseDeviceState() { - mouseCoord_ = {0, 0}; + mouseCoord_ = { 0, 0 }; } MouseDeviceState::~MouseDeviceState() {} @@ -40,7 +40,7 @@ int32_t MouseDeviceState::GetMouseCoordsY() const return mouseCoord_.physicalY; } -void MouseDeviceState::SetMouseCoords(const int32_t x, const int32_t y) +void MouseDeviceState::SetMouseCoords(int32_t x, int32_t y) { mouseCoord_.physicalX = x; mouseCoord_.physicalY = y; @@ -64,11 +64,6 @@ void MouseDeviceState::GetPressedButtons(std::vector& pressedButtons) } } -std::map MouseDeviceState::GetMouseBtnState() const -{ - return mouseBtnState_; -} - void MouseDeviceState::MouseBtnStateCounts(uint32_t btnCode, const BUTTON_STATE btnState) { std::map::iterator iter = mouseBtnState_.find(btnCode); diff --git a/service/mouse_event_normalize/src/mouse_event_normalize.cpp b/service/mouse_event_normalize/src/mouse_event_normalize.cpp index 18535d648b162f2264ab33ae3347d55be75faa6c..374af0234b97481ca40be53a5a823928a314688a 100644 --- a/service/mouse_event_normalize/src/mouse_event_normalize.cpp +++ b/service/mouse_event_normalize/src/mouse_event_normalize.cpp @@ -34,446 +34,122 @@ namespace OHOS { namespace MMI { namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "MouseEventNormalize" }; -const std::vector ACCELERATE_CURVES { - { { 8, 32, 128 }, { 0.16, 0.30, 0.56 }, { 0.0, -1.12, -9.44 } }, - { { 8, 32, 128 }, { 0.32, 0.60, 1.12 }, { 0.0, -2.24, -18.88 } }, - { { 8, 32, 128 }, { 0.48, 0.90, 1.68 }, { 0.0, -3.36, -28.32 } }, - { { 8, 32, 128 }, { 0.64, 1.20, 2.24 }, { 0.0, -4.48, -37.76 } }, - { { 8, 32, 128 }, { 0.80, 1.50, 2.80 }, { 0.0, -5.60, -47.20 } }, - { { 8, 32, 128 }, { 0.86, 1.95, 3.64 }, { 0.0, -8.72, -62.80 } }, - { { 8, 32, 128 }, { 0.92, 2.40, 4.48 }, { 0.0, -11.84, -78.40 } }, - { { 8, 32, 128 }, { 0.98, 2.85, 5.32 }, { 0.0, -14.96, -94.00 } }, - { { 8, 32, 128 }, { 1.04, 3.30, 6.16 }, { 0.0, -18.08, -109.60 } }, - { { 8, 32, 128 }, { 1.10, 3.75, 7.00 }, { 0.0, -21.20, -125.20 } }, - { { 8, 32, 128 }, { 1.16, 4.20, 7.84 }, { 0.0, -24.32, -140.80 } } - }; -constexpr double DOUBLE_ZERO = 1e-6; -constexpr int32_t MIN_SPEED = 1; -constexpr int32_t MAX_SPEED = 11; -#ifdef OHOS_BUILD_ENABLE_COOPERATE -constexpr double PERCENT_CONST = 100.0; -#endif // OHOS_BUILD_ENABLE_COOPERATE } // namespace -MouseEventNormalize::MouseEventNormalize() -{ - pointerEvent_ = PointerEvent::Create(); - CHKPL(pointerEvent_); -} - +MouseEventNormalize::MouseEventNormalize() {} MouseEventNormalize::~MouseEventNormalize() {} -std::shared_ptr MouseEventNormalize::GetPointerEvent() const +std::shared_ptr MouseEventNormalize::GetProcessor(int32_t deviceId) const { - return pointerEvent_; -} - -bool MouseEventNormalize::GetSpeedGain(double vin, double &gain) const -{ - if (fabs(vin) < DOUBLE_ZERO) { - MMI_HILOGE("The value of the parameter passed in is 0"); - return false; - } - if (speed_ < 1) { - MMI_HILOGE("The speed value can't be less than 1"); - return false; - } - const AccelerateCurve& curve = ACCELERATE_CURVES[speed_ - 1]; - int32_t num = static_cast(ceil(fabs(vin))); - for (size_t i = 0; i < curve.speeds.size(); ++i) { - if (num <= curve.speeds[i]) { - gain = (curve.slopes[i] * vin + curve.diffNums[i]) / vin; - return true; - } + auto iter = processors_.find(deviceId); + if (iter == processors_.end()) { + MMI_HILOGE("Can't find mouse processor by deviceId:%{public}d", deviceId); + return nullptr; } - gain = (curve.slopes.back() * vin + curve.diffNums.back()) / vin; - return true; + return iter->second; } -int32_t MouseEventNormalize::HandleMotionInner(struct libinput_event_pointer* data) +std::shared_ptr MouseEventNormalize::GetCurrentProcessor() const { - CALL_DEBUG_ENTER; - CHKPR(data, ERROR_NULL_POINTER); - CHKPR(pointerEvent_, ERROR_NULL_POINTER); - pointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE); - pointerEvent_->SetButtonId(buttonId_); - - InitAbsolution(); - if (currentDisplayId_ == -1) { - absolutionX_ = -1; - absolutionY_ = -1; - MMI_HILOGI("The currentDisplayId_ is -1"); - return RET_ERR; - } - - int32_t ret = HandleMotionAccelerate(data); - if (ret != RET_OK) { - MMI_HILOGE("Failed to handle motion correction"); - return ret; + int32_t deviceId = GetCurrentDeviceId(); + auto iter = processors_.find(deviceId); + if (iter == processors_.end()) { + MMI_HILOGE("Can't find mouse processor by deviceId:%{public}d", deviceId); + return nullptr; } - WinMgr->UpdateAndAdjustMouseLocation(currentDisplayId_, absolutionX_, absolutionY_); - pointerEvent_->SetTargetDisplayId(currentDisplayId_); - MMI_HILOGD("Change coordinate: x:%{public}lf, y:%{public}lf, currentDisplayId_:%{public}d", - absolutionX_, absolutionY_, currentDisplayId_); - return RET_OK; + return iter->second; } -int32_t MouseEventNormalize::HandleMotionAccelerate(struct libinput_event_pointer* data) +void MouseEventNormalize::SetCurrentDeviceId(int32_t deviceId) { - CHKPR(data, ERROR_NULL_POINTER); - double dx = libinput_event_pointer_get_dx(data); - double dy = libinput_event_pointer_get_dy(data); - double vin = (fmax(abs(dx), abs(dy)) + fmin(abs(dx), abs(dy))) / 2.0; - double gain { 0.0 }; - if (!GetSpeedGain(vin, gain)) { - MMI_HILOGE("Get speed gain failed"); - return RET_ERR; - } - double correctionX = dx * gain; - double correctionY = dy * gain; - MMI_HILOGD("Get and process the movement coordinates, dx:%{public}lf, dy:%{public}lf," - "correctionX:%{public}lf, correctionY:%{public}lf, gain:%{public}lf", - dx, dy, correctionX, correctionY, gain); - absolutionX_ += correctionX; - absolutionY_ += correctionY; - return RET_OK; + currentDeviceId_ = deviceId; } -void MouseEventNormalize::InitAbsolution() +int32_t MouseEventNormalize::GetCurrentDeviceId() const { - if (absolutionX_ != -1 || absolutionY_ != -1 || currentDisplayId_ != -1) { - return; - } - MMI_HILOGD("Init absolution"); - auto dispalyGroupInfo = WinMgr->GetDisplayGroupInfo(); - if (dispalyGroupInfo.displaysInfo.empty()) { - MMI_HILOGI("The displayInfo is empty"); - return; - } - currentDisplayId_ = dispalyGroupInfo.displaysInfo[0].id; - absolutionX_ = dispalyGroupInfo.displaysInfo[0].width * 1.0 / 2; - absolutionY_ = dispalyGroupInfo.displaysInfo[0].height * 1.0 / 2; + return currentDeviceId_; } -int32_t MouseEventNormalize::HandleButtonInner(struct libinput_event_pointer* data) +std::shared_ptrMouseEventNormalize::GetPointerEvent() { - CALL_DEBUG_ENTER; - CHKPR(data, ERROR_NULL_POINTER); - MMI_HILOGD("Current action:%{public}d", pointerEvent_->GetPointerAction()); - - auto ret = HandleButtonValueInner(data); - if (ret != RET_OK) { - MMI_HILOGE("The button value does not exist"); - return RET_ERR; - } - uint32_t button = libinput_event_pointer_get_button(data); - auto state = libinput_event_pointer_get_button_state(data); - if (state == LIBINPUT_BUTTON_STATE_RELEASED) { - MouseState->MouseBtnStateCounts(button, BUTTON_STATE_RELEASED); - pointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_UP); - int32_t buttonId = MouseState->LibinputChangeToPointer(button); - pointerEvent_->DeleteReleaseButton(buttonId); - isPressed_ = false; - buttonId_ = PointerEvent::BUTTON_NONE; - } else if (state == LIBINPUT_BUTTON_STATE_PRESSED) { - MouseState->MouseBtnStateCounts(button, BUTTON_STATE_PRESSED); - pointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN); - int32_t buttonId = MouseState->LibinputChangeToPointer(button); - pointerEvent_->SetButtonPressed(buttonId); - isPressed_ = true; - buttonId_ = pointerEvent_->GetButtonId(); - } else { - MMI_HILOGE("Unknown state, state:%{public}u", state); - return RET_ERR; - } - return RET_OK; + auto processor = GetCurrentProcessor(); + CHKPP(processor); + return processor->GetPointerEvent(); } -int32_t MouseEventNormalize::HandleButtonValueInner(struct libinput_event_pointer* data) +int32_t MouseEventNormalize::OnEvent(struct libinput_event *event) { - CALL_DEBUG_ENTER; - CHKPR(data, ERROR_NULL_POINTER); - - uint32_t button = libinput_event_pointer_get_button(data); - int32_t buttonId = MouseState->LibinputChangeToPointer(button); - if (buttonId == PointerEvent::BUTTON_NONE) { - MMI_HILOGE("Unknown btn, btn:%{public}u", button); + CHKPR(event, RET_ERR); + auto device = libinput_event_get_device(event); + CHKPR(device, RET_ERR); + int32_t deviceId = InputDevMgr->FindInputDeviceId(device); + if (deviceId < 0) { + MMI_HILOGE("The deviceId:%{public}d is invalid", deviceId); return RET_ERR; } - pointerEvent_->SetButtonId(buttonId); - return RET_OK; -} - -int32_t MouseEventNormalize::HandleAxisInner(struct libinput_event_pointer* data) -{ - CALL_DEBUG_ENTER; - CHKPR(data, ERROR_NULL_POINTER); - if (buttonId_ == PointerEvent::BUTTON_NONE && pointerEvent_->GetButtonId() != PointerEvent::BUTTON_NONE) { - pointerEvent_->SetButtonId(PointerEvent::BUTTON_NONE); - } - if (TimerMgr->IsExist(timerId_)) { - pointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_AXIS_UPDATE); - TimerMgr->ResetTimer(timerId_); - MMI_HILOGD("Axis update"); + SetCurrentDeviceId(deviceId); + std::shared_ptrprocessor { nullptr }; + if (auto it = processors_.find(deviceId); it != processors_.end()) { + processor = it->second; } else { - static constexpr int32_t timeout = 100; - std::weak_ptr weakPtr = shared_from_this(); - timerId_ = TimerMgr->AddTimer(timeout, 1, [weakPtr]() { - CALL_DEBUG_ENTER; - auto sharedPtr = weakPtr.lock(); - CHKPV(sharedPtr); - MMI_HILOGD("timer:%{public}d", sharedPtr->timerId_); - sharedPtr->timerId_ = -1; - auto pointerEvent = sharedPtr->GetPointerEvent(); - CHKPV(pointerEvent); - pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_AXIS_END); - pointerEvent->UpdateId(); - auto inputEventNormalizeHandler = InputHandler->GetEventNormalizeHandler(); - CHKPV(inputEventNormalizeHandler); - inputEventNormalizeHandler->HandlePointerEvent(pointerEvent); - }); - - pointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_AXIS_BEGIN); - MMI_HILOGD("Axis begin"); - } - - if (libinput_event_pointer_has_axis(data, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) { - double axisValue = libinput_event_pointer_get_axis_value(data, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); - pointerEvent_->SetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_VERTICAL, axisValue); - } - if (libinput_event_pointer_has_axis(data, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)) { - double axisValue = libinput_event_pointer_get_axis_value(data, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL); - pointerEvent_->SetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_HORIZONTAL, axisValue); - } - return RET_OK; -} - -void MouseEventNormalize::HandlePostInner(struct libinput_event_pointer* data, int32_t deviceId, - PointerEvent::PointerItem &pointerItem) -{ - CALL_DEBUG_ENTER; - CHKPV(data); - auto mouseInfo = WinMgr->GetMouseInfo(); - MouseState->SetMouseCoords(mouseInfo.physicalX, mouseInfo.physicalY); - pointerItem.SetDisplayX(mouseInfo.physicalX); - pointerItem.SetDisplayY(mouseInfo.physicalY); - pointerItem.SetWindowX(0); - pointerItem.SetWindowY(0); - pointerItem.SetPointerId(0); - pointerItem.SetPressed(isPressed_); - - int64_t time = GetSysClockTime(); - pointerItem.SetDownTime(time); - pointerItem.SetWidth(0); - pointerItem.SetHeight(0); - pointerItem.SetPressure(0); - pointerItem.SetToolType(PointerEvent::TOOL_TYPE_FINGER); - pointerItem.SetDeviceId(deviceId); -#ifdef OHOS_BUILD_ENABLE_COOPERATE - SetDxDyForDInput(pointerItem, data); -#endif // OHOS_BUILD_ENABLE_COOPERATE - pointerEvent_->UpdateId(); - pointerEvent_->UpdatePointerItem(pointerEvent_->GetPointerId(), pointerItem); - pointerEvent_->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); - pointerEvent_->SetActionTime(time); - pointerEvent_->SetActionStartTime(time); - pointerEvent_->SetDeviceId(deviceId); - pointerEvent_->SetPointerId(0); - pointerEvent_->SetTargetDisplayId(currentDisplayId_); - pointerEvent_->SetTargetWindowId(-1); - pointerEvent_->SetAgentWindowId(-1); -} - -int32_t MouseEventNormalize::Normalize(struct libinput_event *event) -{ - CALL_DEBUG_ENTER; - CHKPR(event, ERROR_NULL_POINTER); - auto data = libinput_event_get_pointer_event(event); - CHKPR(data, ERROR_NULL_POINTER); - CHKPR(pointerEvent_, ERROR_NULL_POINTER); - pointerEvent_->ClearAxisValue(); - int32_t result; - const int32_t type = libinput_event_get_type(event); - switch (type) { - case LIBINPUT_EVENT_POINTER_MOTION: - case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: { - result = HandleMotionInner(data); - break; - } - case LIBINPUT_EVENT_POINTER_BUTTON: { - result = HandleButtonInner(data); - break; + processor = std::make_shared(deviceId); + auto vendorConfig = InputDevMgr->GetVendorConfig(deviceId); + if (vendorConfig.pointerSpeed != -1) { + processor->SetConfigPointerSpeed(vendorConfig.pointerSpeed); } - case LIBINPUT_EVENT_POINTER_AXIS: { - result = HandleAxisInner(data); - break; - } - default: { - MMI_HILOGE("Unknow type:%{public}d", type); - return RET_ERR; + auto [tIter, isOk] = processors_.emplace(deviceId, processor); + if (!isOk) { + MMI_HILOGE("Duplicate device record:%{public}d", deviceId); } } - int32_t deviceId = InputDevMgr->FindInputDeviceId(libinput_event_get_device(event)); - PointerEvent::PointerItem pointerItem; - HandlePostInner(data, deviceId, pointerItem); - WinMgr->UpdateTargetPointer(pointerEvent_); - DumpInner(); - return result; -} -#ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING -void MouseEventNormalize::HandleMotionMoveMouse(int32_t offsetX, int32_t offsetY) -{ - CALL_DEBUG_ENTER; - CHKPV(pointerEvent_); - pointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE); - InitAbsolution(); - absolutionX_ += offsetX; - absolutionY_ += offsetY; - WinMgr->UpdateAndAdjustMouseLocation(currentDisplayId_, absolutionX_, absolutionY_); + return processor->Normalize(event); } +#ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING void MouseEventNormalize::OnDisplayLost(int32_t displayId) { - if (currentDisplayId_ != displayId) { - currentDisplayId_ = -1; - absolutionX_ = -1; - absolutionY_ = -1; - InitAbsolution(); - WinMgr->UpdateAndAdjustMouseLocation(currentDisplayId_, absolutionX_, absolutionY_); - } + MouseTransformProcessor::OnDisplayLost(displayId); } int32_t MouseEventNormalize::GetDisplayId() const { - return currentDisplayId_; -} - -void MouseEventNormalize::HandlePostMoveMouse(PointerEvent::PointerItem& pointerItem) -{ - CALL_DEBUG_ENTER; - auto mouseInfo = WinMgr->GetMouseInfo(); - CHKPV(pointerEvent_); - MouseState->SetMouseCoords(mouseInfo.physicalX, mouseInfo.physicalY); - pointerItem.SetDisplayX(mouseInfo.physicalX); - pointerItem.SetDisplayY(mouseInfo.physicalY); - pointerItem.SetWindowX(0); - pointerItem.SetWindowY(0); - pointerItem.SetPointerId(0); - pointerItem.SetPressed(isPressed_); - - int64_t time = GetSysClockTime(); - pointerItem.SetDownTime(time); - pointerItem.SetWidth(0); - pointerItem.SetHeight(0); - pointerItem.SetPressure(0); - - pointerEvent_->UpdateId(); - pointerEvent_->UpdatePointerItem(pointerEvent_->GetPointerId(), pointerItem); - pointerEvent_->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); - pointerEvent_->SetActionTime(time); - pointerEvent_->SetActionStartTime(time); - - pointerEvent_->SetPointerId(0); - pointerEvent_->SetTargetDisplayId(-1); - pointerEvent_->SetTargetWindowId(-1); - pointerEvent_->SetAgentWindowId(-1); + return MouseTransformProcessor::GetDisplayId(); } bool MouseEventNormalize::NormalizeMoveMouse(int32_t offsetX, int32_t offsetY) { CALL_DEBUG_ENTER; - CHKPF(pointerEvent_); - bool bHasPoinerDevice = InputDevMgr->HasPointerDevice(); - if (!bHasPoinerDevice) { - MMI_HILOGE("There hasn't any pointer device"); - return false; - } - - PointerEvent::PointerItem pointerItem; - HandleMotionMoveMouse(offsetX, offsetY); - HandlePostMoveMouse(pointerItem); - DumpInner(); - return bHasPoinerDevice; + auto processor = GetCurrentProcessor(); + CHKPF(processor); + return processor->NormalizeMoveMouse(offsetX, offsetY); } #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING -void MouseEventNormalize::DumpInner() -{ - EventLogHelper::PrintEventData(pointerEvent_); -} - void MouseEventNormalize::Dump(int32_t fd, const std::vector &args) { - CALL_DEBUG_ENTER; - PointerEvent::PointerItem item; - CHKPV(pointerEvent_); - pointerEvent_->GetPointerItem(pointerEvent_->GetPointerId(), item); - mprintf(fd, "Mouse device state information:\t"); - mprintf(fd, - "PointerId:%d | SourceType:%s | PointerAction:%s | WindowX:%d | WindowY:%d | ButtonId:%d " - "| AgentWindowId:%d | TargetWindowId:%d | DownTime:%" PRId64 " | IsPressed:%s \t", - pointerEvent_->GetPointerId(), pointerEvent_->DumpSourceType(), pointerEvent_->DumpPointerAction(), - item.GetWindowX(), item.GetWindowY(), pointerEvent_->GetButtonId(), pointerEvent_->GetAgentWindowId(), - pointerEvent_->GetTargetWindowId(), item.GetDownTime(), item.IsPressed() ? "true" : "false"); + auto processor = GetCurrentProcessor(); + CHKPV(processor); + processor->Dump(fd, args); } int32_t MouseEventNormalize::SetPointerSpeed(int32_t speed) { - CALL_DEBUG_ENTER; - if (speed < MIN_SPEED) { - speed_ = MIN_SPEED; - } else if (speed > MAX_SPEED) { - speed_ = MAX_SPEED; - } else { - speed_ = speed; - } - MMI_HILOGD("Set pointer speed:%{public}d", speed_); - return RET_OK; + return MouseTransformProcessor::SetPointerSpeed(speed); } int32_t MouseEventNormalize::GetPointerSpeed() const { - CALL_DEBUG_ENTER; - MMI_HILOGD("Get pointer speed:%{public}d", speed_); - return speed_; + return MouseTransformProcessor::GetPointerSpeed(); } -#ifdef OHOS_BUILD_ENABLE_COOPERATE -void MouseEventNormalize::SetDxDyForDInput(PointerEvent::PointerItem& pointerItem, libinput_event_pointer* data) +int32_t MouseEventNormalize::SetPointerLocation(int32_t x, int32_t y) { - double dx = libinput_event_pointer_get_dx(data); - double dy = libinput_event_pointer_get_dy(data); - int32_t rawDx = static_cast(dx); - int32_t rawDy = static_cast(dy); - pointerItem.SetRawDx(rawDx); - pointerItem.SetRawDy(rawDy); - MMI_HILOGD("MouseEventNormalize SetDxDyForDInput : dx:%{public}d, dy:%{public}d", rawDx, rawDy); + return MouseTransformProcessor::SetPointerLocation(x, y); } +#ifdef OHOS_BUILD_ENABLE_COOPERATE void MouseEventNormalize::SetAbsolutionLocation(double xPercent, double yPercent) { - MMI_HILOGI("MouseEventNormalize cross screen location : xPercent:%{public}lf, yPercent:%{public}lf", - xPercent, yPercent); - auto displayGroupInfo = WinMgr->GetDisplayGroupInfo(); - if (currentDisplayId_ == -1) { - if (displayGroupInfo.displaysInfo.empty()) { - MMI_HILOGI("The displayInfo is empty"); - return; - } - currentDisplayId_ = displayGroupInfo.displaysInfo[0].id; - } - struct DisplayInfo display; - for (auto &it : displayGroupInfo.displaysInfo) { - if (it.id == currentDisplayId_) { - display = it; - break; - } - } - absolutionX_ = display.width * xPercent / PERCENT_CONST; - absolutionY_ = display.height * yPercent / PERCENT_CONST; - WinMgr->UpdateAndAdjustMouseLocation(currentDisplayId_, absolutionX_, absolutionY_); - int32_t physicalX = WinMgr->GetMouseInfo().physicalX; - int32_t physicalY = WinMgr->GetMouseInfo().physicalY; - IPointerDrawingManager::GetInstance()->SetPointerLocation(getpid(), physicalX, physicalY); + MouseTransformProcessor::SetAbsolutionLocation(xPercent, yPercent); } #endif // OHOS_BUILD_ENABLE_COOPERATE } // namespace MMI diff --git a/service/mouse_event_normalize/src/mouse_transform_processor.cpp b/service/mouse_event_normalize/src/mouse_transform_processor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a57b48216decfb1545444b4f926cf7cf59cb496e --- /dev/null +++ b/service/mouse_event_normalize/src/mouse_transform_processor.cpp @@ -0,0 +1,536 @@ +/* + * 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. + */ + +#include "mouse_transform_processor.h" + +#include + +#include "input-event-codes.h" + +#include "define_multimodal.h" +#include "event_log_helper.h" +#include "i_pointer_drawing_manager.h" +#include "input_device_manager.h" +#include "input_event_handler.h" +#include "input_windows_manager.h" +#include "mouse_device_state.h" +#include "timer_manager.h" +#include "util_ex.h" +#include "util.h" + +namespace OHOS { +namespace MMI { +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "MouseTransformProcessor" }; +constexpr double DOUBLE_ZERO = 1e-6; +constexpr int32_t MIN_SPEED = 1; +constexpr int32_t MAX_SPEED = 11; +constexpr int32_t DEFAULT_SPEED = 5; +const std::vector ACCELERATE_CURVES { + { { 8, 32, 128 }, { 0.16, 0.30, 0.56 }, { 0.0, -1.12, -9.44 } }, + { { 8, 32, 128 }, { 0.32, 0.60, 1.12 }, { 0.0, -2.24, -18.88 } }, + { { 8, 32, 128 }, { 0.48, 0.90, 1.68 }, { 0.0, -3.36, -28.32 } }, + { { 8, 32, 128 }, { 0.64, 1.20, 2.24 }, { 0.0, -4.48, -37.76 } }, + { { 8, 32, 128 }, { 0.80, 1.50, 2.80 }, { 0.0, -5.60, -47.20 } }, + { { 8, 32, 128 }, { 0.86, 1.95, 3.64 }, { 0.0, -8.72, -62.80 } }, + { { 8, 32, 128 }, { 0.92, 2.40, 4.48 }, { 0.0, -11.84, -78.40 } }, + { { 8, 32, 128 }, { 0.98, 2.85, 5.32 }, { 0.0, -14.96, -94.00 } }, + { { 8, 32, 128 }, { 1.04, 3.30, 6.16 }, { 0.0, -18.08, -109.60 } }, + { { 8, 32, 128 }, { 1.10, 3.75, 7.00 }, { 0.0, -21.20, -125.20 } }, + { { 8, 32, 128 }, { 1.16, 4.20, 7.84 }, { 0.0, -24.32, -140.80 } } +}; +#ifdef OHOS_BUILD_ENABLE_COOPERATE +constexpr double PERCENT_CONST = 100.0; +#endif // OHOS_BUILD_ENABLE_COOPERATE +} // namespace + +double MouseTransformProcessor::absolutionX_ = -1.0; +double MouseTransformProcessor::absolutionY_ = -1.0; +int32_t MouseTransformProcessor::currentDisplayId_ = -1; +int32_t MouseTransformProcessor::globalPointerSpeed_ = DEFAULT_SPEED; +bool MouseTransformProcessor::isUserSetSpeedStatus_ = false; + +MouseTransformProcessor::MouseTransformProcessor(int32_t deviceId) + : pointerEvent_(PointerEvent::Create()), deviceId_(deviceId) +{} + +std::shared_ptr MouseTransformProcessor::GetPointerEvent() const +{ + return pointerEvent_; +} + +int32_t MouseTransformProcessor::HandleMotionInner(struct libinput_event_pointer* data) +{ + CALL_DEBUG_ENTER; + CHKPR(data, ERROR_NULL_POINTER); + CHKPR(pointerEvent_, ERROR_NULL_POINTER); + pointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE); + pointerEvent_->SetButtonId(buttonId_); + + InitAbsolution(); + if (currentDisplayId_ == -1) { + absolutionX_ = -1; + absolutionY_ = -1; + MMI_HILOGI("The currentDisplayId_ is -1"); + return RET_ERR; + } + + int32_t ret = HandleMotionAccelerate(data); + if (ret != RET_OK) { + MMI_HILOGE("Failed to handle motion correction"); + return ret; + } + WinMgr->UpdateAndAdjustMouseLocation(currentDisplayId_, absolutionX_, absolutionY_); + pointerEvent_->SetTargetDisplayId(currentDisplayId_); + MMI_HILOGD("Change coordinate: x:%{public}lf, y:%{public}lf, currentDisplayId_:%{public}d", + absolutionX_, absolutionY_, currentDisplayId_); + return RET_OK; +} + +int32_t MouseTransformProcessor::HandleMotionAccelerate(struct libinput_event_pointer* data) +{ + CHKPR(data, ERROR_NULL_POINTER); + double dx = libinput_event_pointer_get_dx(data); + double dy = libinput_event_pointer_get_dy(data); + double vin = (fmax(abs(dx), abs(dy)) + fmin(abs(dx), abs(dy))) / 2.0; + double gain { 0.0 }; + if (!GetSpeedGain(vin, gain)) { + MMI_HILOGE("Get speed gain failed"); + return RET_ERR; + } + double correctionX = dx * gain; + double correctionY = dy * gain; + MMI_HILOGD("Get and process the movement coordinates, dx:%{public}lf, dy:%{public}lf," + "correctionX:%{public}lf, correctionY:%{public}lf, gain:%{public}lf", + dx, dy, correctionX, correctionY, gain); + if (!WinMgr->GetMouseIsCaptureMode()) { + absolutionX_ += correctionX; + absolutionY_ += correctionY; + } + return RET_OK; +} + +void MouseTransformProcessor::InitAbsolution() +{ + CALL_DEBUG_ENTER; + if (absolutionX_ != -1 || absolutionY_ != -1 || currentDisplayId_ != -1) { + MMI_HILOGW("Unable to initialize coordinate information"); + return; + } + auto displayGroupInfo = WinMgr->GetDisplayGroupInfo(); + if (displayGroupInfo.displaysInfo.empty()) { + MMI_HILOGI("The displayInfo is empty"); + return; + } + currentDisplayId_ = displayGroupInfo.displaysInfo[0].id; + absolutionX_ = displayGroupInfo.displaysInfo[0].width * 1.0 / 2; + absolutionY_ = displayGroupInfo.displaysInfo[0].height * 1.0 / 2; +} + +int32_t MouseTransformProcessor::HandleButtonInner(struct libinput_event_pointer* data) +{ + CALL_DEBUG_ENTER; + CHKPR(data, ERROR_NULL_POINTER); + CHKPR(pointerEvent_, ERROR_NULL_POINTER); + MMI_HILOGD("Current action:%{public}d", pointerEvent_->GetPointerAction()); + + auto ret = HandleButtonValueInner(data); + if (ret != RET_OK) { + MMI_HILOGE("The button value does not exist"); + return RET_ERR; + } + uint32_t button = libinput_event_pointer_get_button(data); + auto state = libinput_event_pointer_get_button_state(data); + if (state == LIBINPUT_BUTTON_STATE_RELEASED) { + MouseState->MouseBtnStateCounts(button, BUTTON_STATE_RELEASED); + pointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_UP); + int32_t buttonId = MouseState->LibinputChangeToPointer(button); + pointerEvent_->DeleteReleaseButton(buttonId); + isPressed_ = false; + buttonId_ = PointerEvent::BUTTON_NONE; + } else if (state == LIBINPUT_BUTTON_STATE_PRESSED) { + MouseState->MouseBtnStateCounts(button, BUTTON_STATE_PRESSED); + pointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN); + int32_t buttonId = MouseState->LibinputChangeToPointer(button); + pointerEvent_->SetButtonPressed(buttonId); + isPressed_ = true; + buttonId_ = pointerEvent_->GetButtonId(); + } else { + MMI_HILOGE("Unknown state, state:%{public}u", state); + return RET_ERR; + } + return RET_OK; +} + +int32_t MouseTransformProcessor::HandleButtonValueInner(struct libinput_event_pointer* data) +{ + CALL_DEBUG_ENTER; + CHKPR(data, ERROR_NULL_POINTER); + CHKPR(pointerEvent_, ERROR_NULL_POINTER); + uint32_t button = libinput_event_pointer_get_button(data); + int32_t buttonId = MouseState->LibinputChangeToPointer(button); + if (buttonId == PointerEvent::BUTTON_NONE) { + MMI_HILOGE("Unknown btn, btn:%{public}u", button); + return RET_ERR; + } + pointerEvent_->SetButtonId(buttonId); + return RET_OK; +} + +int32_t MouseTransformProcessor::HandleAxisInner(struct libinput_event_pointer* data) +{ + CALL_DEBUG_ENTER; + CHKPR(data, ERROR_NULL_POINTER); + CHKPR(pointerEvent_, ERROR_NULL_POINTER); + if (buttonId_ == PointerEvent::BUTTON_NONE && pointerEvent_->GetButtonId() != PointerEvent::BUTTON_NONE) { + pointerEvent_->SetButtonId(PointerEvent::BUTTON_NONE); + } + if (TimerMgr->IsExist(timerId_)) { + pointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_AXIS_UPDATE); + TimerMgr->ResetTimer(timerId_); + MMI_HILOGD("Axis update"); + } else { + static constexpr int32_t timeout = 100; + std::weak_ptr weakPtr = shared_from_this(); + timerId_ = TimerMgr->AddTimer(timeout, 1, [weakPtr]() { + CALL_DEBUG_ENTER; + auto sharedPtr = weakPtr.lock(); + CHKPV(sharedPtr); + MMI_HILOGD("timer:%{public}d", sharedPtr->timerId_); + sharedPtr->timerId_ = -1; + auto pointerEvent = sharedPtr->GetPointerEvent(); + CHKPV(pointerEvent); + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_AXIS_END); + pointerEvent->UpdateId(); + auto inputEventNormalizeHandler = InputHandler->GetEventNormalizeHandler(); + CHKPV(inputEventNormalizeHandler); + inputEventNormalizeHandler->HandlePointerEvent(pointerEvent); + }); + + pointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_AXIS_BEGIN); + MMI_HILOGD("Axis begin"); + } + + if (libinput_event_pointer_has_axis(data, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) { + double axisValue = libinput_event_pointer_get_axis_value(data, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); + pointerEvent_->SetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_VERTICAL, axisValue); + } + if (libinput_event_pointer_has_axis(data, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)) { + double axisValue = libinput_event_pointer_get_axis_value(data, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL); + pointerEvent_->SetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_HORIZONTAL, axisValue); + } + return RET_OK; +} + +void MouseTransformProcessor::HandlePostInner(struct libinput_event_pointer* data, + PointerEvent::PointerItem &pointerItem) +{ + CALL_DEBUG_ENTER; + CHKPV(data); + CHKPV(pointerEvent_); + auto mouseInfo = WinMgr->GetMouseInfo(); + MouseState->SetMouseCoords(mouseInfo.physicalX, mouseInfo.physicalY); + pointerItem.SetDisplayX(mouseInfo.physicalX); + pointerItem.SetDisplayY(mouseInfo.physicalY); + pointerItem.SetWindowX(0); + pointerItem.SetWindowY(0); + pointerItem.SetPointerId(0); + pointerItem.SetPressed(isPressed_); + + int64_t time = GetSysClockTime(); + pointerItem.SetDownTime(time); + pointerItem.SetWidth(0); + pointerItem.SetHeight(0); + pointerItem.SetPressure(0); + pointerItem.SetToolType(PointerEvent::TOOL_TYPE_FINGER); + pointerItem.SetDeviceId(deviceId_); + SetDxDyForDInput(pointerItem, data); + pointerEvent_->UpdateId(); + pointerEvent_->UpdatePointerItem(pointerEvent_->GetPointerId(), pointerItem); + pointerEvent_->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); + pointerEvent_->SetActionTime(time); + pointerEvent_->SetActionStartTime(time); + pointerEvent_->SetDeviceId(deviceId_); + pointerEvent_->SetPointerId(0); + pointerEvent_->SetTargetDisplayId(currentDisplayId_); + pointerEvent_->SetTargetWindowId(-1); + pointerEvent_->SetAgentWindowId(-1); +} + +int32_t MouseTransformProcessor::Normalize(struct libinput_event *event) +{ + CALL_DEBUG_ENTER; + CHKPR(event, ERROR_NULL_POINTER); + CHKPR(pointerEvent_, ERROR_NULL_POINTER); + auto data = libinput_event_get_pointer_event(event); + CHKPR(data, ERROR_NULL_POINTER); + pointerEvent_->ClearAxisValue(); + int32_t result; + const int32_t type = libinput_event_get_type(event); + switch (type) { + case LIBINPUT_EVENT_POINTER_MOTION: + case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: { + result = HandleMotionInner(data); + break; + } + case LIBINPUT_EVENT_POINTER_BUTTON: { + result = HandleButtonInner(data); + break; + } + case LIBINPUT_EVENT_POINTER_AXIS: { + result = HandleAxisInner(data); + break; + } + default: { + MMI_HILOGE("Unknown type:%{public}d", type); + return RET_ERR; + } + } + PointerEvent::PointerItem pointerItem; + HandlePostInner(data, pointerItem); + WinMgr->UpdateTargetPointer(pointerEvent_); + DumpInner(); + return result; +} + +#ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING +void MouseTransformProcessor::HandleMotionMoveMouse(int32_t offsetX, int32_t offsetY) +{ + CALL_DEBUG_ENTER; + CHKPV(pointerEvent_); + pointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_MOVE); + InitAbsolution(); + absolutionX_ += offsetX; + absolutionY_ += offsetY; + WinMgr->UpdateAndAdjustMouseLocation(currentDisplayId_, absolutionX_, absolutionY_); +} + +void MouseTransformProcessor::OnDisplayLost(int32_t displayId) +{ + if (currentDisplayId_ != displayId) { + currentDisplayId_ = -1; + absolutionX_ = -1; + absolutionY_ = -1; + InitAbsolution(); + WinMgr->UpdateAndAdjustMouseLocation(currentDisplayId_, absolutionX_, absolutionY_); + } +} + +int32_t MouseTransformProcessor::GetDisplayId() +{ + return currentDisplayId_; +} + +void MouseTransformProcessor::HandlePostMoveMouse(PointerEvent::PointerItem& pointerItem) +{ + CALL_DEBUG_ENTER; + auto mouseInfo = WinMgr->GetMouseInfo(); + CHKPV(pointerEvent_); + MouseState->SetMouseCoords(mouseInfo.physicalX, mouseInfo.physicalY); + pointerItem.SetDisplayX(mouseInfo.physicalX); + pointerItem.SetDisplayY(mouseInfo.physicalY); + pointerItem.SetWindowX(0); + pointerItem.SetWindowY(0); + pointerItem.SetPointerId(0); + pointerItem.SetPressed(isPressed_); + + int64_t time = GetSysClockTime(); + pointerItem.SetDownTime(time); + pointerItem.SetWidth(0); + pointerItem.SetHeight(0); + pointerItem.SetPressure(0); + + pointerEvent_->UpdateId(); + pointerEvent_->UpdatePointerItem(pointerEvent_->GetPointerId(), pointerItem); + pointerEvent_->SetSourceType(PointerEvent::SOURCE_TYPE_MOUSE); + pointerEvent_->SetActionTime(time); + pointerEvent_->SetActionStartTime(time); + + pointerEvent_->SetPointerId(0); + pointerEvent_->SetTargetDisplayId(-1); + pointerEvent_->SetTargetWindowId(-1); + pointerEvent_->SetAgentWindowId(-1); +} + +bool MouseTransformProcessor::NormalizeMoveMouse(int32_t offsetX, int32_t offsetY) +{ + CALL_DEBUG_ENTER; + CHKPF(pointerEvent_); + bool bHasPointerDevice = InputDevMgr->HasPointerDevice(); + if (!bHasPointerDevice) { + MMI_HILOGE("There hasn't any pointer device"); + return false; + } + + PointerEvent::PointerItem pointerItem; + HandleMotionMoveMouse(offsetX, offsetY); + HandlePostMoveMouse(pointerItem); + DumpInner(); + return bHasPointerDevice; +} +#endif // OHOS_BUILD_ENABLE_POINTER_DRAWING + +void MouseTransformProcessor::DumpInner() +{ + EventLogHelper::PrintEventData(pointerEvent_); +} + +void MouseTransformProcessor::Dump(int32_t fd, const std::vector &args) +{ + CALL_DEBUG_ENTER; + PointerEvent::PointerItem item; + CHKPV(pointerEvent_); + pointerEvent_->GetPointerItem(pointerEvent_->GetPointerId(), item); + mprintf(fd, "Mouse device state information:\t"); + mprintf(fd, + "PointerId:%d | SourceType:%s | PointerAction:%s | WindowX:%d | WindowY:%d | ButtonId:%d " + "| AgentWindowId:%d | TargetWindowId:%d | DownTime:%" PRId64 " | IsPressed:%s \t", + pointerEvent_->GetPointerId(), pointerEvent_->DumpSourceType(), pointerEvent_->DumpPointerAction(), + item.GetWindowX(), item.GetWindowY(), pointerEvent_->GetButtonId(), pointerEvent_->GetAgentWindowId(), + pointerEvent_->GetTargetWindowId(), item.GetDownTime(), item.IsPressed() ? "true" : "false"); +} + +int32_t MouseTransformProcessor::SetPointerSpeed(int32_t speed) +{ + CALL_DEBUG_ENTER; + if (speed < MIN_SPEED) { + globalPointerSpeed_ = MIN_SPEED; + } else if (speed > MAX_SPEED) { + globalPointerSpeed_ = MAX_SPEED; + } else { + globalPointerSpeed_ = speed; + } + isUserSetSpeedStatus_ = true; + MMI_HILOGD("Set pointer speed:%{public}d", globalPointerSpeed_); + return RET_OK; +} + +int32_t MouseTransformProcessor::GetPointerSpeed() +{ + CALL_DEBUG_ENTER; + MMI_HILOGD("Get pointer speed:%{public}d", globalPointerSpeed_); + return globalPointerSpeed_; +} + +bool MouseTransformProcessor::GetSpeedGain(double vin, double &gain) +{ + if (fabs(vin) < DOUBLE_ZERO) { + MMI_HILOGE("The value of the parameter passed in is 0"); + return false; + } + if (GetSpeed() < 1) { + MMI_HILOGE("The speed value can't be less than 1"); + return false; + } + const AccelerateCurve& curve = ACCELERATE_CURVES[GetSpeed() - 1]; + int32_t num = static_cast(ceil(fabs(vin))); + for (size_t i = 0; i < curve.speeds.size(); ++i) { + if (num <= curve.speeds[i]) { + gain = (curve.slopes[i] * vin + curve.diffNums[i]) / vin; + return true; + } + } + gain = (curve.slopes.back() * vin + curve.diffNums.back()) / vin; + return true; +} + +void MouseTransformProcessor::SetDxDyForDInput(PointerEvent::PointerItem& pointerItem, + struct libinput_event_pointer* data) +{ + double dx = libinput_event_pointer_get_dx(data); + double dy = libinput_event_pointer_get_dy(data); + int32_t rawDx = static_cast(dx); + int32_t rawDy = static_cast(dy); + pointerItem.SetRawDx(rawDx); + pointerItem.SetRawDy(rawDy); + MMI_HILOGD("MouseTransformProcessor SetDxDyForDInput, dx:%{public}d, dy:%{public}d", rawDx, rawDy); +} + +int32_t MouseTransformProcessor::SetPointerLocation(int32_t x, int32_t y) +{ + MMI_HILOGI("Location, x:%{public}d, y:%{public}d", x, y); + auto displayGroupInfo = WinMgr->GetDisplayGroupInfo(); + if (currentDisplayId_ == -1) { + if (displayGroupInfo.displaysInfo.empty()) { + MMI_HILOGI("The displayInfo is empty"); + return RET_ERR; + } + currentDisplayId_ = displayGroupInfo.displaysInfo[0].id; + } + struct DisplayInfo display; + for (auto& it : displayGroupInfo.displaysInfo) { + if (it.id == currentDisplayId_) { + display = it; + break; + } + } + absolutionX_ = static_cast(x); + absolutionY_ = static_cast(y); + WinMgr->UpdateAndAdjustMouseLocation(currentDisplayId_, absolutionX_, absolutionY_); + int32_t physicalX = WinMgr->GetMouseInfo().physicalX; + int32_t physicalY = WinMgr->GetMouseInfo().physicalY; + IPointerDrawingManager::GetInstance()->SetPointerLocation(getpid(), physicalX, physicalY); + return RET_OK; +} + +#ifdef OHOS_BUILD_ENABLE_COOPERATE +void MouseTransformProcessor::SetAbsolutionLocation(double xPercent, double yPercent) +{ + MMI_HILOGI("Cross screen location, xPercent:%{public}lf, yPercent:%{public}lf", + xPercent, yPercent); + auto displayGroupInfo = WinMgr->GetDisplayGroupInfo(); + if (currentDisplayId_ == -1) { + if (displayGroupInfo.displaysInfo.empty()) { + MMI_HILOGI("The displayInfo is empty"); + return; + } + currentDisplayId_ = displayGroupInfo.displaysInfo[0].id; + } + struct DisplayInfo display; + for (auto &it : displayGroupInfo.displaysInfo) { + if (it.id == currentDisplayId_) { + display = it; + break; + } + } + absolutionX_ = display.width * xPercent / PERCENT_CONST; + absolutionY_ = display.height * yPercent / PERCENT_CONST; + WinMgr->UpdateAndAdjustMouseLocation(currentDisplayId_, absolutionX_, absolutionY_); + int32_t physicalX = WinMgr->GetMouseInfo().physicalX; + int32_t physicalY = WinMgr->GetMouseInfo().physicalY; + IPointerDrawingManager::GetInstance()->SetPointerLocation(getpid(), physicalX, physicalY); +} +#endif // OHOS_BUILD_ENABLE_COOPERATE + +int32_t MouseTransformProcessor::GetSpeed() const +{ + if ((vendorConfigPointerSpeed_ == -1) || isUserSetSpeedStatus_) { + return globalPointerSpeed_; + } + return vendorConfigPointerSpeed_; +} + +void MouseTransformProcessor::SetConfigPointerSpeed(int32_t speed) +{ + if (speed < MIN_SPEED) { + vendorConfigPointerSpeed_ = MIN_SPEED; + } else if (speed > MAX_SPEED) { + vendorConfigPointerSpeed_ = MAX_SPEED; + } else { + vendorConfigPointerSpeed_ = speed; + } +} +} // namespace MMI +} // namespace OHOS diff --git a/service/permission_helper/include/permission_helper.h b/service/permission_helper/include/permission_helper.h index edfc87bb05850daa3aa6e42b76daed640b661e3a..1f4771e4fdbd29c9959e208953558cdf436bf3ae 100644 --- a/service/permission_helper/include/permission_helper.h +++ b/service/permission_helper/include/permission_helper.h @@ -28,6 +28,7 @@ public: static const uint32_t APL_SYSTEM_BASIC = 1 << OHOS::Security::AccessToken::APL_SYSTEM_BASIC; static const uint32_t APL_SYSTEM_CORE = 1 << OHOS::Security::AccessToken::APL_SYSTEM_CORE; static const uint32_t APL_SYSTEM_BASIC_CORE = APL_SYSTEM_BASIC + APL_SYSTEM_CORE; + static const uint32_t ROOT_UID = 0; public: DISALLOW_COPY_AND_MOVE(PermissionHelper); @@ -35,9 +36,10 @@ public: bool CheckMonitor(); int32_t GetTokenType(); + bool VerifySystemApp(); + private: bool CheckHapPermission(uint32_t tokenId, uint32_t required); - bool CheckNativePermission(uint32_t tokenId, uint32_t required); bool CheckMonitorPermission(uint32_t tokenId); }; diff --git a/service/permission_helper/src/permission_helper.cpp b/service/permission_helper/src/permission_helper.cpp index f7ed4675409668d92735fcca9f7fb769a896c6bb..be8d54ce9fc1408c23c705951605363f2b0d26a7 100644 --- a/service/permission_helper/src/permission_helper.cpp +++ b/service/permission_helper/src/permission_helper.cpp @@ -13,20 +13,44 @@ * limitations under the License. */ +#include "ipc_skeleton.h" #include "permission_helper.h" #include "proto.h" -#include "ipc_skeleton.h" + #include "mmi_log.h" +#include "tokenid_kit.h" + namespace OHOS { namespace MMI { namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "PermissionHelper"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "PermissionHelper" }; } // namespace PermissionHelper::PermissionHelper() {} PermissionHelper::~PermissionHelper() {} +bool PermissionHelper::VerifySystemApp() +{ + MMI_HILOGD("verify system App"); + auto callerToken = IPCSkeleton::GetCallingTokenID(); + auto tokenType = OHOS::Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(callerToken); + MMI_HILOGD("token type is %{public}d", static_cast(tokenType)); + int32_t callingUid = IPCSkeleton::GetCallingUid(); + if (tokenType == OHOS::Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE + || tokenType == OHOS::Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL + || callingUid == ROOT_UID) { + MMI_HILOGD("called tokenType is native, verify success"); + return true; + } + uint64_t accessTokenIdEx = IPCSkeleton::GetCallingFullTokenID(); + if (!OHOS::Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(accessTokenIdEx)) { + MMI_HILOGE("system api is called by non-system app"); + return false; + } + return true; +} + bool PermissionHelper::CheckPermission(uint32_t required) { CALL_DEBUG_ENTER; @@ -35,7 +59,8 @@ bool PermissionHelper::CheckPermission(uint32_t required) if (tokenType == OHOS::Security::AccessToken::TOKEN_HAP) { return CheckHapPermission(tokenId, required); } else if (tokenType == OHOS::Security::AccessToken::TOKEN_NATIVE) { - return CheckNativePermission(tokenId, required); + MMI_HILOGI("Token type is native"); + return true; } else if (tokenType == OHOS::Security::AccessToken::TOKEN_SHELL) { MMI_HILOGI("Token type is shell"); return true; @@ -78,22 +103,6 @@ bool PermissionHelper::CheckHapPermission(uint32_t tokenId, uint32_t required) return true; } -bool PermissionHelper::CheckNativePermission(uint32_t tokenId, uint32_t required) -{ - OHOS::Security::AccessToken::NativeTokenInfo findInfo; - if (OHOS::Security::AccessToken::AccessTokenKit::GetNativeTokenInfo(tokenId, findInfo) != 0) { - MMI_HILOGE("GetNativeTokenInfo failed, name:%{public}s, apl:%{public}d, required:%{public}d", - findInfo.processName.c_str(), findInfo.apl, required); - return false; - } - if (!((1 << findInfo.apl) & required)) { - MMI_HILOGE("Check native permission failed"); - return false; - } - MMI_HILOGI("Check native permission success"); - return true; -} - bool PermissionHelper::CheckMonitorPermission(uint32_t tokenId) { static const std::string inputMonitor = "ohos.permission.INPUT_MONITORING"; diff --git a/service/subscriber/include/key_subscriber_handler.h b/service/subscriber/include/key_subscriber_handler.h index 080cde695e52ecd998f64f6d38631a49ed13481b..68dd4b83c5e4aeb5d3b881d46938b6dd152708ac 100644 --- a/service/subscriber/include/key_subscriber_handler.h +++ b/service/subscriber/include/key_subscriber_handler.h @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef KEY_SUBSCRIBER_HANDLER_H #define KEY_SUBSCRIBER_HANDLER_H @@ -30,7 +31,7 @@ namespace OHOS { namespace MMI { -class KeySubscriberHandler : public IInputEventHandler { +class KeySubscriberHandler final : public IInputEventHandler { public: KeySubscriberHandler() = default; DISALLOW_COPY_AND_MOVE(KeySubscriberHandler); @@ -47,6 +48,7 @@ public: int32_t SubscribeKeyEvent(SessionPtr sess, int32_t subscribeId, const std::shared_ptr keyOption); int32_t UnsubscribeKeyEvent(SessionPtr sess, int32_t subscribeId); + void RemoveSubscriberKeyUpTimer(int32_t keyCode); void Dump(int32_t fd, const std::vector &args); private: struct Subscriber { @@ -61,16 +63,13 @@ private: void InsertSubScriber(std::shared_ptr subs); private: - bool SubscribeKeyEvent(std::shared_ptr keyEvent); + bool OnSubscribeKeyEvent(std::shared_ptr keyEvent); bool HandleKeyDown(const std::shared_ptr &keyEvent); bool HandleKeyUp(const std::shared_ptr &keyEvent); bool HandleKeyCancel(const std::shared_ptr &keyEvent); - bool IsPreKeysMatch(const std::set &preKeys, const std::vector &pressedKeys) const; - void NotifySubscriber(std::shared_ptr keyEvent, - const std::shared_ptr &subscriber); - + const std::shared_ptr &subscriber); bool AddTimer(const std::shared_ptr &subscriber, const std::shared_ptr &keyEvent); void ClearTimer(const std::shared_ptr &subscriber); void OnTimer(const std::shared_ptr subscriber); @@ -79,11 +78,14 @@ private: bool CloneKeyEvent(std::shared_ptr keyEvent); void RemoveKeyCode(int32_t keyCode, std::vector &keyCodes); bool IsRepeatedKeyEvent(std::shared_ptr keyEvent); + bool IsNotifyPowerKeySubsciber(int32_t keyCode, const std::vector &keyCodes); + void HandleKeyUpWithDelay(std::shared_ptr keyEvent, const std::shared_ptr &subscriber); + void PrintKeyUpLog(const std::shared_ptr &subscriber); private: std::list> subscribers_ {}; bool callbackInitialized_ { false }; - bool hasEventExecuting { false }; + bool hasEventExecuting_ { false }; std::shared_ptr keyEvent_ { nullptr }; }; } // namespace MMI diff --git a/service/subscriber/src/key_subscriber_handler.cpp b/service/subscriber/src/key_subscriber_handler.cpp index 32d8483e91d6d7ae5cdb5ddb08490f7de84fee9b..fd9cfe987b877a4d43fd2dbb4e32a02e6500192a 100644 --- a/service/subscriber/src/key_subscriber_handler.cpp +++ b/service/subscriber/src/key_subscriber_handler.cpp @@ -17,6 +17,7 @@ #include "bytrace_adapter.h" #include "define_multimodal.h" +#include "dfx_hisysevent.h" #include "error_multimodal.h" #include "input_event_data_transformation.h" #include "input_event_handler.h" @@ -28,7 +29,7 @@ namespace OHOS { namespace MMI { namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "KeySubscriberHandler"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "KeySubscriberHandler" }; constexpr uint32_t MAX_PRE_KEY_COUNT = 4; } // namespace @@ -36,7 +37,7 @@ constexpr uint32_t MAX_PRE_KEY_COUNT = 4; void KeySubscriberHandler::HandleKeyEvent(const std::shared_ptr keyEvent) { CHKPV(keyEvent); - if (SubscribeKeyEvent(keyEvent)) { + if (OnSubscribeKeyEvent(keyEvent)) { MMI_HILOGD("Subscribe keyEvent filter success. keyCode:%{public}d", keyEvent->GetKeyCode()); BytraceAdapter::StartBytrace(keyEvent, BytraceAdapter::KEY_SUBSCRIBE_EVENT); return; @@ -83,8 +84,8 @@ int32_t KeySubscriberHandler::SubscribeKeyEvent( for (const auto &keyCode : keyOption->GetPreKeys()) { MMI_HILOGD("keyOption->prekey:%{public}d", keyCode); } - MMI_HILOGD("subscribeId:%{public}d,keyOption->finalKey:%{public}d," - "keyOption->isFinalKeyDown:%{public}s,keyOption->finalKeyDownDuration:%{public}d", + MMI_HILOGD("subscribeId:%{public}d, keyOption->finalKey:%{public}d," + "keyOption->isFinalKeyDown:%{public}s, keyOption->finalKeyDownDuration:%{public}d", subscribeId, keyOption->GetFinalKey(), keyOption->IsFinalKeyDown() ? "true" : "false", keyOption->GetFinalKeyDownDuration()); auto subscriber = std::make_shared(subscribeId, sess, keyOption); @@ -107,7 +108,7 @@ int32_t KeySubscriberHandler::UnsubscribeKeyEvent(SessionPtr sess, int32_t subsc return RET_ERR; } -bool KeySubscriberHandler::SubscribeKeyEvent(std::shared_ptr keyEvent) +bool KeySubscriberHandler::OnSubscribeKeyEvent(std::shared_ptr keyEvent) { CHKPF(keyEvent); if (IsRepeatedKeyEvent(keyEvent)) { @@ -116,7 +117,7 @@ bool KeySubscriberHandler::SubscribeKeyEvent(std::shared_ptr keyEvent) } keyEvent_ = KeyEvent::Clone(keyEvent); int32_t keyAction = keyEvent->GetKeyAction(); - MMI_HILOGD("keyCode:%{public}d,keyAction:%{public}s", keyEvent->GetKeyCode(), + MMI_HILOGD("keyCode:%{public}d, keyAction:%{public}s", keyEvent->GetKeyCode(), KeyEvent::ActionToString(keyAction)); for (const auto &keyCode : keyEvent->GetPressedKeys()) { MMI_HILOGD("Pressed KeyCode:%{public}d", keyCode); @@ -125,10 +126,10 @@ bool KeySubscriberHandler::SubscribeKeyEvent(std::shared_ptr keyEvent) if (keyAction == KeyEvent::KEY_ACTION_DOWN) { handled = HandleKeyDown(keyEvent); } else if (keyAction == KeyEvent::KEY_ACTION_UP) { - hasEventExecuting = false; + hasEventExecuting_ = false; handled = HandleKeyUp(keyEvent); } else if (keyAction == KeyEvent::KEY_ACTION_CANCEL) { - hasEventExecuting = false; + hasEventExecuting_ = false; handled = HandleKeyCancel(keyEvent); } else { MMI_HILOGW("keyAction exception"); @@ -164,9 +165,13 @@ void KeySubscriberHandler::OnSessionDelete(SessionPtr sess) } } -bool KeySubscriberHandler::IsPreKeysMatch( - const std::set &preKeys, const std::vector &pressedKeys) const +bool KeySubscriberHandler::IsPreKeysMatch(const std::set &preKeys, + const std::vector &pressedKeys) const { + if (preKeys.size() == 0) { + return true; + } + if (preKeys.size() != pressedKeys.size()) { return false; } @@ -182,13 +187,16 @@ bool KeySubscriberHandler::IsPreKeysMatch( } void KeySubscriberHandler::NotifySubscriber(std::shared_ptr keyEvent, - const std::shared_ptr &subscriber) + const std::shared_ptr &subscriber) { CALL_DEBUG_ENTER; CHKPV(keyEvent); CHKPV(subscriber); auto udsServerPtr = InputHandler->GetUDSServer(); CHKPV(udsServerPtr); + if (keyEvent->GetKeyCode() == KeyEvent::KEYCODE_POWER) { + DfxHisysevent::ReportPowerInfo(keyEvent, OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC); + } NetPacket pkt(MmiMessageId::ON_SUBSCRIBE_KEY); InputEventDataTransformation::KeyEventToNetPacket(keyEvent, pkt); int32_t fd = subscriber->sess_->GetFd(); @@ -204,7 +212,7 @@ void KeySubscriberHandler::NotifySubscriber(std::shared_ptr keyEvent, } bool KeySubscriberHandler::AddTimer(const std::shared_ptr &subscriber, - const std::shared_ptr &keyEvent) + const std::shared_ptr &keyEvent) { CALL_DEBUG_ENTER; CHKPF(keyEvent); @@ -216,7 +224,9 @@ bool KeySubscriberHandler::AddTimer(const std::shared_ptr &subscribe } auto &keyOption = subscriber->keyOption_; - if (keyOption->GetFinalKeyDownDuration() <= 0) { + bool isKeyDown = keyOption->IsFinalKeyDown(); + int32_t duration = isKeyDown ? keyOption->GetFinalKeyDownDuration() : keyOption->GetFinalKeyUpDelay(); + if (duration <= 0) { MMI_HILOGE("Leave, duration <= 0"); return true; } @@ -227,7 +237,7 @@ bool KeySubscriberHandler::AddTimer(const std::shared_ptr &subscribe } std::weak_ptr weakSubscriber = subscriber; - subscriber->timerId_ = TimerMgr->AddTimer(keyOption->GetFinalKeyDownDuration(), 1, [this, weakSubscriber] () { + subscriber->timerId_ = TimerMgr->AddTimer(duration, 1, [this, weakSubscriber] () { MMI_HILOGD("Timer callback"); auto subscriber = weakSubscriber.lock(); CHKPV(subscriber); @@ -239,10 +249,10 @@ bool KeySubscriberHandler::AddTimer(const std::shared_ptr &subscribe return false; } subscriber->keyEvent_ = keyEvent_; - hasEventExecuting = true; + hasEventExecuting_ = true; MMI_HILOGD("Leave, add timer success, subscribeId:%{public}d," - "duration:%{public}d,timerId:%{public}d", - subscriber->id_, keyOption->GetFinalKeyDownDuration(), subscriber->timerId_); + "duration:%{public}d, timerId:%{public}d", + subscriber->id_, duration, subscriber->timerId_); return true; } @@ -252,16 +262,16 @@ void KeySubscriberHandler::ClearTimer(const std::shared_ptr &subscri CHKPV(subscriber); if (subscriber->timerId_ < 0) { - MMI_HILOGW("Leave, subscribeId:%{public}d,null timerId < 0", subscriber->id_); + MMI_HILOGW("Leave, subscribeId:%{public}d, null timerId < 0", subscriber->id_); return; } + TimerMgr->RemoveTimer(subscriber->timerId_); auto timerId = subscriber->timerId_; subscriber->keyEvent_.reset(); subscriber->timerId_ = -1; - TimerMgr->RemoveTimer(timerId); - hasEventExecuting = false; - MMI_HILOGD("subscribeId:%{public}d,timerId:%{public}d", subscriber->id_, timerId); + hasEventExecuting_ = false; + MMI_HILOGD("subscribeId:%{public}d, timerId:%{public}d", subscriber->id_, timerId); } void KeySubscriberHandler::OnTimer(const std::shared_ptr subscriber) @@ -305,8 +315,8 @@ bool KeySubscriberHandler::HandleKeyDown(const std::shared_ptr &keyEve RemoveKeyCode(keyCode, pressedKeys); for (const auto &subscriber : subscribers_) { auto &keyOption = subscriber->keyOption_; - MMI_HILOGD("subscribeId:%{public}d,keyOption->finalKey:%{public}d," - "keyOption->isFinalKeyDown:%{public}s,keyOption->finalKeyDownDuration:%{public}d", + MMI_HILOGD("subscribeId:%{public}d, keyOption->finalKey:%{public}d," + "keyOption->isFinalKeyDown:%{public}s, keyOption->finalKeyDownDuration:%{public}d", subscriber->id_, keyOption->GetFinalKey(), keyOption->IsFinalKeyDown() ? "true" : "false", keyOption->GetFinalKeyDownDuration()); for (const auto &keyCode : keyOption->GetPreKeys()) { @@ -354,15 +364,8 @@ bool KeySubscriberHandler::HandleKeyUp(const std::shared_ptr &keyEvent std::vector pressedKeys = keyEvent->GetPressedKeys(); RemoveKeyCode(keyCode, pressedKeys); for (const auto &subscriber : subscribers_) { + PrintKeyUpLog(subscriber); auto &keyOption = subscriber->keyOption_; - MMI_HILOGD("subscribeId:%{public}d,keyOption->finalKey:%{public}d," - "keyOption->isFinalKeyDown:%{public}s,keyOption->finalKeyDownDuration:%{public}d", - subscriber->id_, keyOption->GetFinalKey(), keyOption->IsFinalKeyDown() ? "true" : "false", - keyOption->GetFinalKeyDownDuration()); - for (const auto &keyCode : keyOption->GetPreKeys()) { - MMI_HILOGD("keyOption->prekey:%{public}d", keyCode); - } - if (keyOption->IsFinalKeyDown()) { ClearTimer(subscriber); MMI_HILOGD("keyOption->IsFinalKeyDown()"); @@ -379,16 +382,24 @@ bool KeySubscriberHandler::HandleKeyUp(const std::shared_ptr &keyEvent continue; } + if (!IsNotifyPowerKeySubsciber(keyOption->GetFinalKey(), pressedKeys)) { + MMI_HILOGD("In special case, subscriber are not notified"); + continue; + } + auto duration = keyOption->GetFinalKeyDownDuration(); if (duration <= 0) { MMI_HILOGD("duration <= 0"); - NotifySubscriber(keyEvent, subscriber); + HandleKeyUpWithDelay(keyEvent, subscriber); handled = true; continue; } - const KeyEvent::KeyItem* keyItem = keyEvent->GetKeyItem(); - CHKPF(keyItem); + std::optional keyItem = keyEvent->GetKeyItem(); + if (!keyItem) { + MMI_HILOGE("The keyItem is nullopt"); + return false; + } auto upTime = keyEvent->GetActionTime(); auto downTime = keyItem->GetDownTime(); if (upTime - downTime >= (static_cast(duration) * 1000)) { @@ -396,7 +407,7 @@ bool KeySubscriberHandler::HandleKeyUp(const std::shared_ptr &keyEvent continue; } MMI_HILOGD("upTime - downTime < duration"); - NotifySubscriber(keyEvent, subscriber); + HandleKeyUpWithDelay(keyEvent, subscriber); handled = true; } MMI_HILOGD("%{public}s", handled ? "true" : "false"); @@ -417,7 +428,7 @@ bool KeySubscriberHandler::CloneKeyEvent(std::shared_ptr keyEvent) { CHKPF(keyEvent); if (keyEvent_ == nullptr) { - MMI_HILOGW("The keyEvent_ is nullptr"); + MMI_HILOGW("keyEvent_ is nullptr"); keyEvent_ = KeyEvent::Clone(keyEvent); } CHKPF(keyEvent_); @@ -437,7 +448,7 @@ void KeySubscriberHandler::RemoveKeyCode(int32_t keyCode, std::vector & bool KeySubscriberHandler::IsRepeatedKeyEvent(std::shared_ptr keyEvent) { CHKPF(keyEvent); - if (!hasEventExecuting) { + if (!hasEventExecuting_) { return false; } @@ -469,6 +480,56 @@ bool KeySubscriberHandler::IsRepeatedKeyEvent(std::shared_ptr keyEvent return true; } +void KeySubscriberHandler::RemoveSubscriberKeyUpTimer(int32_t keyCode) +{ + for (const auto& item : subscribers_) { + if ((item->timerId_ >= 0) && (item->keyOption_->GetFinalKey() == keyCode)) { + ClearTimer(item); + } + } +} + +bool KeySubscriberHandler::IsNotifyPowerKeySubsciber(int32_t keyCode, const std::vector &keyCodes) +{ + if (keyCode != KeyEvent::KEYCODE_POWER) { + return true; + } + + for (const auto& pressedKey: keyCodes) { + if (pressedKey == KeyEvent::KEYCODE_VOLUME_DOWN || pressedKey == KeyEvent::KEYCODE_VOLUME_UP) { + return false; + } + } + return true; +} + +void KeySubscriberHandler::HandleKeyUpWithDelay(std::shared_ptr keyEvent, + const std::shared_ptr &subscriber) +{ + auto keyUpDelay = subscriber->keyOption_->GetFinalKeyUpDelay(); + if (keyUpDelay <= 0) { + NotifySubscriber(keyEvent, subscriber); + } else { + if (!AddTimer(subscriber, keyEvent)) { + MMI_HILOGE("Leave, add timer failed"); + } + } +} + +void KeySubscriberHandler::PrintKeyUpLog(const std::shared_ptr &subscriber) +{ + CHKPV(subscriber); + auto &keyOption = subscriber->keyOption_; + MMI_HILOGD("subscribeId:%{public}d, keyOption->finalKey:%{public}d," + "keyOption->isFinalKeyDown:%{public}s, keyOption->finalKeyDownDuration:%{public}d," + "keyOption->finalKeyUpDelay:%{public}d", + subscriber->id_, keyOption->GetFinalKey(), keyOption->IsFinalKeyDown() ? "true" : "false", + keyOption->GetFinalKeyDownDuration(), keyOption->GetFinalKeyUpDelay()); + for (const auto &keyCode : keyOption->GetPreKeys()) { + MMI_HILOGD("keyOption->prekey:%{public}d", keyCode); + } +} + void KeySubscriberHandler::Dump(int32_t fd, const std::vector &args) { CALL_DEBUG_ENTER; diff --git a/service/timer_manager/src/timer_manager.cpp b/service/timer_manager/src/timer_manager.cpp index ca4db87ed941b61f88142c6bb87f33a5483aa8ff..f9130d51b11fe3902262e34bf23bc21eb0015a50 100644 --- a/service/timer_manager/src/timer_manager.cpp +++ b/service/timer_manager/src/timer_manager.cpp @@ -20,7 +20,7 @@ namespace MMI { namespace { constexpr int32_t MIN_DELAY = -1; constexpr int32_t MIN_INTERVAL = 50; -constexpr int32_t MAX_INTERVAL = 4096; +constexpr int32_t MAX_INTERVAL_MS = 10000; constexpr int32_t MAX_TIMER_COUNT = 64; constexpr int32_t NONEXISTENT_ID = -1; constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "TimerManager" }; @@ -80,8 +80,8 @@ int32_t TimerManager::AddTimerInternal(int32_t intervalMs, int32_t repeatCount, { if (intervalMs < MIN_INTERVAL) { intervalMs = MIN_INTERVAL; - } else if (intervalMs > MAX_INTERVAL) { - intervalMs = MAX_INTERVAL; + } else if (intervalMs > MAX_INTERVAL_MS) { + intervalMs = MAX_INTERVAL_MS; } if (!callback) { return NONEXISTENT_ID; @@ -192,7 +192,7 @@ void TimerManager::ProcessTimersInternal() curTimer->callback(); continue; } - if (!AddInt64(nowTime, curTimer->intervalMs, curTimer->nextCallTime)) { + if (!AddInt64(curTimer->nextCallTime, curTimer->intervalMs, curTimer->nextCallTime)) { MMI_HILOGE("The addition of nextCallTime in TimerItem overflows"); return; } diff --git a/service/touch_event_normalize/include/gesture_transform_processor.h b/service/touch_event_normalize/include/gesture_transform_processor.h index 6d72ffc3b61cbf0559038316d2f0438e7e30b4ad..f81b35b332af773adfa7bf0f33c55ca7e4efd070 100644 --- a/service/touch_event_normalize/include/gesture_transform_processor.h +++ b/service/touch_event_normalize/include/gesture_transform_processor.h @@ -15,16 +15,17 @@ #ifndef GESTURE_TRANSFORM_PROCESSOR_H #define GESTURE_TRANSFORM_PROCESSOR_H + #include "nocopyable.h" #include "transform_processor.h" namespace OHOS { namespace MMI { -class GestureTransformProcessor : public TransformProcessor { +class GestureTransformProcessor final : public TransformProcessor { public: explicit GestureTransformProcessor(int32_t deviceId); DISALLOW_COPY_AND_MOVE(GestureTransformProcessor); - virtual ~GestureTransformProcessor() = default; + ~GestureTransformProcessor() = default; std::shared_ptr OnEvent(struct libinput_event *event) override; private: diff --git a/service/touch_event_normalize/include/joystick_transform_processor.h b/service/touch_event_normalize/include/joystick_transform_processor.h new file mode 100644 index 0000000000000000000000000000000000000000..4d86cacb791f041c6c97e62eed42533e49dd4e03 --- /dev/null +++ b/service/touch_event_normalize/include/joystick_transform_processor.h @@ -0,0 +1,103 @@ +/* + * 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 JOYSTICK_TRANSFORM_PROCESSOR_H +#define JOYSTICK_TRANSFORM_PROCESSOR_H + +#include "input_windows_manager.h" +#include "transform_processor.h" + +namespace OHOS { +namespace MMI { +class JoystickTransformProcessor final : public TransformProcessor { + enum LIBINPUT_BUTTON_CODE : uint32_t { + LIBINPUT_HOMEPAGE_BUTTON_CODE = 172, + LIBINPUT_TRIGGER_BUTTON_CODE = 288, + LIBINPUT_THUMB_BUTTON_CODE = 289, + LIBINPUT_THUMB2_BUTTON_CODE = 290, + LIBINPUT_TOP_BUTTON_CODE = 291, + LIBINPUT_TOP2_BUTTON_CODE = 292, + LIBINPUT_PINKIE_BUTTON_CODE = 293, + LIBINPUT_BASE_BUTTON_CODE = 294, + LIBINPUT_BASE2_BUTTON_CODE = 295, + LIBINPUT_BASE3_BUTTON_CODE = 296, + LIBINPUT_BASE4_BUTTON_CODE = 297, + LIBINPUT_BASE5_BUTTON_CODE = 298, + LIBINPUT_BASE6_BUTTON_CODE = 299, + LIBINPUT_DEAD_BUTTON_CODE = 303, + LIBINPUT_SOUTH_BUTTON_CODE = 304, + LIBINPUT_EAST_BUTTON_CODE = 305, + LIBINPUT_C_BUTTON_CODE = 306, + LIBINPUT_NORTH_BUTTON_CODE = 307, + LIBINPUT_WEST_BUTTON_CODE = 308, + LIBINPUT_Z_BUTTON_CODE = 309, + LIBINPUT_TL_BUTTON_CODE = 310, + LIBINPUT_TR_BUTTON_CODE = 311, + LIBINPUT_TL2_BUTTON_CODE = 312, + LIBINPUT_TR2_BUTTON_CODE = 313, + LIBINPUT_SELECT_BUTTON_CODE = 314, + LIBINPUT_START_BUTTON_CODE = 315, + LIBINPUT_MODE_BUTTON_CODE = 316, + LIBINPUT_THUMBL_BUTTON_CODE = 317, + LIBINPUT_THUMBR_BUTTON_CODE = 318 + }; + const std::map LibinputChangeToPointer = { + { LIBINPUT_TL2_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_TL2 }, + { LIBINPUT_TR2_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_TR2 }, + { LIBINPUT_TL_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_TL }, + { LIBINPUT_TR_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_TR }, + { LIBINPUT_SOUTH_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_SOUTH }, + { LIBINPUT_NORTH_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_NORTH }, + { LIBINPUT_WEST_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_WEST }, + { LIBINPUT_EAST_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_EAST }, + { LIBINPUT_SELECT_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_SELECT }, + { LIBINPUT_HOMEPAGE_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_HOMEPAGE }, + { LIBINPUT_THUMBL_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_THUMBL }, + { LIBINPUT_THUMBR_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_THUMBR }, + { LIBINPUT_THUMB2_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_THUMB2 }, + { LIBINPUT_THUMB_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_THUMB }, + { LIBINPUT_TOP_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_TOP }, + { LIBINPUT_TOP2_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_TOP2 }, + { LIBINPUT_PINKIE_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_PINKIE }, + { LIBINPUT_BASE_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_BASE }, + { LIBINPUT_BASE2_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_BASE2 }, + { LIBINPUT_BASE3_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_BASE3 }, + { LIBINPUT_BASE4_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_BASE4 }, + { LIBINPUT_BASE5_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_BASE5 }, + { LIBINPUT_BASE6_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_BASE6 }, + { LIBINPUT_DEAD_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_DEAD }, + { LIBINPUT_C_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_C }, + { LIBINPUT_Z_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_Z }, + { LIBINPUT_MODE_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_MODE } + }; + +public: + explicit JoystickTransformProcessor(int32_t deviceId); + DISALLOW_COPY_AND_MOVE(JoystickTransformProcessor); + ~JoystickTransformProcessor() = default; + std::shared_ptr OnEvent(struct libinput_event *event) override; + +private: + bool OnEventJoystickButton(struct libinput_event* event); + bool OnEventJoystickAxis(struct libinput_event *event); + int32_t LibinputButtonToPointer(const uint32_t button); +private: + int32_t deviceId_ { 0 }; + std::shared_ptr pointerEvent_ { nullptr }; + std::vector> joystickType; +}; +} // namespace MMI +} // namespace OHOS +#endif // JOYSTICK_TRANSFORM_POINT_PROCESSOR_H \ No newline at end of file diff --git a/service/touch_event_normalize/include/tablet_tool_tranform_processor.h b/service/touch_event_normalize/include/tablet_tool_tranform_processor.h index 85612c98c9638005de9f13325af20fcfa56ba872..e5e1d6e94e66d8c47746317d8e54bde58748b5d9 100644 --- a/service/touch_event_normalize/include/tablet_tool_tranform_processor.h +++ b/service/touch_event_normalize/include/tablet_tool_tranform_processor.h @@ -20,11 +20,11 @@ namespace OHOS { namespace MMI { -class TabletToolTransformProcessor : public TransformProcessor { +class TabletToolTransformProcessor final : public TransformProcessor { public: explicit TabletToolTransformProcessor(int32_t deviceId); DISALLOW_COPY_AND_MOVE(TabletToolTransformProcessor); - virtual ~TabletToolTransformProcessor() = default; + ~TabletToolTransformProcessor() = default; std::shared_ptr OnEvent(struct libinput_event *event) override; private: diff --git a/service/touch_event_normalize/include/touch_event_normalize.h b/service/touch_event_normalize/include/touch_event_normalize.h index fec7cdad960773eea41a02e3952b99cda2f5f919..d02f504f41e9d50a9fa30c3653ec9893cd96fa9e 100644 --- a/service/touch_event_normalize/include/touch_event_normalize.h +++ b/service/touch_event_normalize/include/touch_event_normalize.h @@ -27,13 +27,33 @@ namespace OHOS { namespace MMI { class TouchEventNormalize final { DECLARE_DELAYED_SINGLETON(TouchEventNormalize); + +public: + enum class DeviceType : int32_t { + KEYBOARD, + POINTER, + TOUCH, + TABLET_TOOL, + TABLET_PAD, + GESTURE, + SWITCH, + JOYSTICK, + AISENSOR, + TOUCH_PAD, + REMOTE_CONTROL, + TRACK_BALL, + KNUCKLE, + TRACKPAD5, + GAMEPAD, + }; + public: DISALLOW_COPY_AND_MOVE(TouchEventNormalize); - std::shared_ptr OnLibInput(struct libinput_event *event, INPUT_DEVICE_TYPE deviceType); + std::shared_ptr OnLibInput(struct libinput_event *event, DeviceType deviceType); private: std::shared_ptr MakeTransformProcessor( - int32_t deviceId, INPUT_DEVICE_TYPE deviceType) const; + int32_t deviceId, DeviceType deviceType) const; private: std::map> processors_; diff --git a/service/touch_event_normalize/include/touch_transform_processor.h b/service/touch_event_normalize/include/touch_transform_processor.h index b1df3eed2590610d655d9612da624f335bf6933e..22ec3efea00461b30c21639ef6e7e3ea32b7ee07 100644 --- a/service/touch_event_normalize/include/touch_transform_processor.h +++ b/service/touch_event_normalize/include/touch_transform_processor.h @@ -20,11 +20,11 @@ namespace OHOS { namespace MMI { -class TouchTransformProcessor : public TransformProcessor { +class TouchTransformProcessor final : public TransformProcessor { public: explicit TouchTransformProcessor(int32_t deviceId); DISALLOW_COPY_AND_MOVE(TouchTransformProcessor); - virtual ~TouchTransformProcessor() = default; + ~TouchTransformProcessor() = default; std::shared_ptr OnEvent(struct libinput_event *event) override; private: diff --git a/service/touch_event_normalize/include/touchpad_transform_processor.h b/service/touch_event_normalize/include/touchpad_transform_processor.h index 71c883fe6f274edb647a8bf7e247d3e141f645e0..ed5e0002eb1a1409b45b5394674733f6c1aafb0c 100644 --- a/service/touch_event_normalize/include/touchpad_transform_processor.h +++ b/service/touch_event_normalize/include/touchpad_transform_processor.h @@ -12,18 +12,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef TOUCHPAD_TRANSFORM_PROCESSOR_H #define TOUCHPAD_TRANSFORM_PROCESSOR_H + #include "nocopyable.h" #include "transform_processor.h" namespace OHOS { namespace MMI { -class TouchPadTransformProcessor : public TransformProcessor { +class TouchPadTransformProcessor final : public TransformProcessor { public: explicit TouchPadTransformProcessor(int32_t deviceId); DISALLOW_COPY_AND_MOVE(TouchPadTransformProcessor); - virtual ~TouchPadTransformProcessor() = default; + ~TouchPadTransformProcessor() = default; std::shared_ptr OnEvent(struct libinput_event *event) override; private: diff --git a/service/touch_event_normalize/include/transform_processor.h b/service/touch_event_normalize/include/transform_processor.h index e1f3e4f86bc86de9373db3310e3f353a1d049647..f278564e292e12a1a44210c35e2020fe2467841a 100644 --- a/service/touch_event_normalize/include/transform_processor.h +++ b/service/touch_event_normalize/include/transform_processor.h @@ -12,10 +12,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef TRANSFORM_PROCESSOR_H #define TRANSFORM_PROCESSOR_H + #include #include + #include "pointer_event.h" namespace OHOS { diff --git a/service/touch_event_normalize/src/joystick_transform_processor.cpp b/service/touch_event_normalize/src/joystick_transform_processor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..53036fe2174fc4aaaa425aa9bf518df69edc2c76 --- /dev/null +++ b/service/touch_event_normalize/src/joystick_transform_processor.cpp @@ -0,0 +1,145 @@ +/* + * 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. + */ + +#include "joystick_transform_processor.h" + +#include "mmi_log.h" + +namespace OHOS { +namespace MMI { +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "JoystickTransformProcessor" }; +} // namespace + +JoystickTransformProcessor::JoystickTransformProcessor(int32_t deviceId) : deviceId_(deviceId) +{ + joystickType.emplace_back( + std::make_pair(LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_X, PointerEvent::AXIS_TYPE_ABS_X)); + joystickType.emplace_back( + std::make_pair(LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_Y, PointerEvent::AXIS_TYPE_ABS_Y)); + joystickType.emplace_back( + std::make_pair(LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_Z, PointerEvent::AXIS_TYPE_ABS_Z)); + joystickType.emplace_back( + std::make_pair(LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_RZ, PointerEvent::AXIS_TYPE_ABS_RZ)); + joystickType.emplace_back( + std::make_pair(LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_GAS, PointerEvent::AXIS_TYPE_ABS_GAS)); + joystickType.emplace_back( + std::make_pair(LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_BRAKE, PointerEvent::AXIS_TYPE_ABS_BRAKE)); + joystickType.emplace_back( + std::make_pair(LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_HAT0X, PointerEvent::AXIS_TYPE_ABS_HAT0X)); + joystickType.emplace_back( + std::make_pair(LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_HAT0Y, PointerEvent::AXIS_TYPE_ABS_HAT0Y)); + joystickType.emplace_back( + std::make_pair(LIBINPUT_JOYSTICK_AXIS_SOURCE_ABS_THROTTLE, PointerEvent::AXIS_TYPE_ABS_THROTTLE)); +} + +bool JoystickTransformProcessor::OnEventJoystickButton(struct libinput_event* event) +{ + CALL_DEBUG_ENTER; + CHKPF(event); + auto data = libinput_event_get_joystick_button_event(event); + CHKPF(data); + int64_t time = GetSysClockTime(); + pointerEvent_->SetActionTime(time); + pointerEvent_->SetActionStartTime(time); + pointerEvent_->SetDeviceId(deviceId_); + uint32_t button = libinput_event_joystick_button_get_key(data); + int32_t buttonId = LibinputButtonToPointer(button); + if (buttonId == PointerEvent::BUTTON_NONE) { + MMI_HILOGE("Unknown btn, btn:%{public}u", button); + return false; + } + pointerEvent_->SetButtonId(buttonId); + auto state = libinput_event_joystick_button_get_key_state(data); + if (state == LIBINPUT_BUTTON_STATE_RELEASED) { + pointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_UP); + pointerEvent_->DeleteReleaseButton(buttonId); + } else if (state == LIBINPUT_BUTTON_STATE_PRESSED) { + pointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_DOWN); + pointerEvent_->SetButtonPressed(buttonId); + } else { + MMI_HILOGE("Unknown state, state:%{public}u", state); + return false; + } + MMI_HILOGD("button:%{public}u, buttonId:%{public}d, state:%{public}d", button, buttonId, state); + return true; +} + +int32_t JoystickTransformProcessor::LibinputButtonToPointer(const uint32_t button) +{ + auto iter = LibinputChangeToPointer.find(button); + return (iter == LibinputChangeToPointer.end() ? PointerEvent::BUTTON_NONE : iter->second); +} + +bool JoystickTransformProcessor::OnEventJoystickAxis(struct libinput_event *event) +{ + CALL_DEBUG_ENTER; + CHKPF(event); + auto data = libinput_event_get_joystick_axis_event(event); + CHKPF(data); + int64_t time = GetSysClockTime(); + pointerEvent_->SetActionTime(time); + pointerEvent_->SetActionStartTime(time); + pointerEvent_->SetDeviceId(deviceId_); + pointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_AXIS_UPDATE); + pointerEvent_->SetSourceType(PointerEvent::SOURCE_TYPE_JOYSTICK); + + for (const auto &item : joystickType) { + if (libinput_event_get_joystick_axis_value_is_changed(data, item.first) != 0) { + struct libinput_event_joystick_axis_abs_info* axisInfo = + libinput_event_get_joystick_axis_abs_info(data, item.first); + CHKPF(axisInfo); + pointerEvent_->SetAxisValue(item.second, axisInfo->value); + } + } + return true; +} + +std::shared_ptr JoystickTransformProcessor::OnEvent(struct libinput_event *event) +{ + CALL_DEBUG_ENTER; + CHKPP(event); + if (pointerEvent_ == nullptr) { + pointerEvent_ = PointerEvent::Create(); + CHKPP(pointerEvent_); + } + pointerEvent_->ClearAxisValue(); + auto type = libinput_event_get_type(event); + switch (type) { + case LIBINPUT_EVENT_JOYSTICK_BUTTON: { + if (!OnEventJoystickButton(event)) { + MMI_HILOGE("Get OnEventJoystickButton failed"); + return nullptr; + } + break; + } + case LIBINPUT_EVENT_JOYSTICK_AXIS: { + if (!OnEventJoystickAxis(event)) { + MMI_HILOGE("Get OnEventJoystickAxis failed"); + return nullptr; + } + break; + } + default: { + MMI_HILOGE("Unknown event type, joystickType:%{public}d", type); + return nullptr; + } + } + WinMgr->UpdateTargetPointer(pointerEvent_); + + return pointerEvent_; +} +} // namespace MMI +} // namespace OHOS diff --git a/service/touch_event_normalize/src/tablet_tool_tranform_processor.cpp b/service/touch_event_normalize/src/tablet_tool_tranform_processor.cpp index 3b6919b5176f9a1e3b3ff10f80940e14fe52351a..8455a4077d208e210152f09387d9438f29efa14e 100644 --- a/service/touch_event_normalize/src/tablet_tool_tranform_processor.cpp +++ b/service/touch_event_normalize/src/tablet_tool_tranform_processor.cpp @@ -168,6 +168,7 @@ bool TabletToolTransformProcessor::OnTipDown(struct libinput_event_tablet_tool* item.SetTiltY(tiltY); item.SetPressure(pressure); item.SetToolType(toolType); + item.SetTargetWindowId(-1); pointerEvent_->SetDeviceId(deviceId_); pointerEvent_->AddPointerItem(item); diff --git a/service/touch_event_normalize/src/touch_event_normalize.cpp b/service/touch_event_normalize/src/touch_event_normalize.cpp index f2cbb447a84be2e5a211b2da315a045c86ded7c7..35ea06f3c76ea93ac6a6791190bcd782aae955cf 100644 --- a/service/touch_event_normalize/src/touch_event_normalize.cpp +++ b/service/touch_event_normalize/src/touch_event_normalize.cpp @@ -16,6 +16,7 @@ #include "touch_event_normalize.h" #include "gesture_transform_processor.h" #include "input_device_manager.h" +#include "joystick_transform_processor.h" #include "tablet_tool_tranform_processor.h" #include "touch_transform_processor.h" #include "touchpad_transform_processor.h" @@ -30,7 +31,7 @@ TouchEventNormalize::TouchEventNormalize() {} TouchEventNormalize::~TouchEventNormalize() {} std::shared_ptr TouchEventNormalize::OnLibInput( - struct libinput_event *event, INPUT_DEVICE_TYPE deviceType) + struct libinput_event *event, DeviceType deviceType) { CHKPP(event); auto device = libinput_event_get_device(event); @@ -51,30 +52,36 @@ std::shared_ptr TouchEventNormalize::OnLibInput( } std::shared_ptr TouchEventNormalize::MakeTransformProcessor( - int32_t deviceId, INPUT_DEVICE_TYPE deviceType) const + int32_t deviceId, DeviceType deviceType) const { std::shared_ptr processor { nullptr }; switch (deviceType) { #ifdef OHOS_BUILD_ENABLE_TOUCH - case INPUT_DEVICE_CAP_TOUCH: { + case DeviceType::TOUCH: { processor = std::make_shared(deviceId); break; } - case INPUT_DEVICE_CAP_TABLET_TOOL: { + case DeviceType::TABLET_TOOL: { processor = std::make_shared(deviceId); break; } #endif // OHOS_BUILD_ENABLE_TOUCH #ifdef OHOS_BUILD_ENABLE_POINTER - case INPUT_DEVICE_CAP_TOUCH_PAD: { + case DeviceType::TOUCH_PAD: { processor = std::make_shared(deviceId); break; } - case INPUT_DEVICE_CAP_GESTURE: { + case DeviceType::GESTURE: { processor = std::make_shared(deviceId); break; } #endif // OHOS_BUILD_ENABLE_POINTER +#ifdef OHOS_BUILD_ENABLE_JOYSTICK + case DeviceType::JOYSTICK: { + processor = std::make_shared(deviceId); + break; + } +#endif // OHOS_BUILD_ENABLE_JOYSTICK default: { MMI_HILOGE("Unsupported device type: %{public}d", deviceType); break; diff --git a/service/touch_event_normalize/test/transform_point_test.cpp b/service/touch_event_normalize/test/transform_point_test.cpp index ee23a2bc8ef8f750da44912a2b5952de55fc00d4..aec51108ff1c3ea08f037951c5b9cd2d43db8b36 100644 --- a/service/touch_event_normalize/test/transform_point_test.cpp +++ b/service/touch_event_normalize/test/transform_point_test.cpp @@ -12,9 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include #include #include + #include "mmi_log.h" #include "virtual_pen.h" @@ -22,7 +24,6 @@ namespace OHOS { namespace MMI { namespace { using namespace testing::ext; -using namespace OHOS::MMI; constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MMI_LOG_DOMAIN, "TransformPointTest" }; constexpr int32_t WAIT_TIME_FOR_INPUT { 1000 }; constexpr int32_t WAIT_TIME_FOR_EVENTS { 10 }; diff --git a/service/window_manager/include/i_pointer_drawing_manager.h b/service/window_manager/include/i_pointer_drawing_manager.h index 448bcb2f31b539bdfc69e25940848579747cba1d..ec152ffd96ee036ca157b4ca5d80d6452d76f738 100644 --- a/service/window_manager/include/i_pointer_drawing_manager.h +++ b/service/window_manager/include/i_pointer_drawing_manager.h @@ -18,7 +18,8 @@ #include -#include "display_info.h" +#include "pointer_style.h" +#include "window_info.h" #include "struct_multimodal.h" namespace OHOS { @@ -43,11 +44,11 @@ public: { return 0; } - virtual int32_t SetPointerStyle(int32_t pid, int32_t windowId, int32_t pointerStyle) + virtual int32_t SetPointerStyle(int32_t pid, int32_t windowId, PointerStyle pointerStyle) { return 0; } - virtual int32_t GetPointerStyle(int32_t pid, int32_t windowId, int32_t &pointerStyle) + virtual int32_t GetPointerStyle(int32_t pid, int32_t windowId, PointerStyle &pointerStyle) { return 0; } @@ -57,6 +58,11 @@ public: return false; } virtual void SetPointerLocation(int32_t pid, int32_t x, int32_t y) {} + virtual void SetMouseDisplayState(bool state) {} + virtual bool GetMouseDisplayState() const + { + return true; + } public: static inline std::shared_ptr iPointDrawMgr_ { nullptr }; }; diff --git a/service/dinput/include/i_call_dinput.h b/service/window_manager/include/input_display_bind_helper.h similarity index 40% rename from service/dinput/include/i_call_dinput.h rename to service/window_manager/include/input_display_bind_helper.h index 613f53f48b53c78fbe487215a45647587f32cfc3..c63fc107045138e5f645a932356c0cd264af57cc 100644 --- a/service/dinput/include/i_call_dinput.h +++ b/service/window_manager/include/input_display_bind_helper.h @@ -13,34 +13,40 @@ * limitations under the License. */ -#ifndef I_CALL_DINPUT_H -#define I_CALL_DINPUT_H -#ifdef OHOS_DISTRIBUTED_INPUT_MODEL +#ifndef INPUT_DISPLAY_BIND_HELPER_H +#define INPUT_DISPLAY_BIND_HELPER_H +#include +#include #include +#include -#include "iremote_broker.h" +#include "window_info.h" namespace OHOS { namespace MMI { -class ICallDinput : public IRemoteBroker { +class BindInfos; +class InputDisplayBindHelper +{ public: - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.multimodalinput.ICallDinput"); - virtual int32_t HandlePrepareDinput(const std::string &deviceId, int32_t status) = 0; - virtual int32_t HandleUnprepareDinput(const std::string &deviceId, int32_t status) = 0; - virtual int32_t HandleStartDinput(const std::string &deviceId, uint32_t inputTypes, int32_t status) = 0; - virtual int32_t HandleStopDinput(const std::string &deviceId, uint32_t inputTypes, int32_t status) = 0; - virtual int32_t HandleRemoteInputAbility(const std::set &remoteInputAbility) = 0; -protected: - enum { - HANDLE_PREPARE_DINPUT = 0, - HANDLE_UNPREPARE_DINPUT = 1, - HANDLE_START_DINPUT = 2, - HANDLE_STOP_DINPUT = 3, - HANDLE_REMOTE_INPUT_ABILITY = 4, - }; + InputDisplayBindHelper(const std::string bindCfgFile); + std::string GetBindDisplayNameByInputDevice(int32_t inputDeviceId) const; + void AddInputDevice(int32_t id, const std::string &name); + void RemoveInputDevice(int32_t id); + bool IsDisplayAdd(int32_t id, const std::string &name); + std::set> GetDisplayIdNames() const; + void AddDisplay(int32_t id, const std::string &name); + void RemoveDisplay(int32_t id); + void Load(); + std::string Dumps() const; + void Store(); + int32_t GetDisplayBindInfo(DisplayBindInfos &infos); + int32_t SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg); +private: + const std::string fileName_; + std::shared_ptr infos_; + std::shared_ptr configFileInfos_; }; -} // namespace MMI +} //namespace MMI } // namespace OHOS -#endif // OHOS_DISTRIBUTED_INPUT_MODEL -#endif // I_CALL_DINPUT_H +#endif // INPUT_DISPLAY_BIND_HELPER_H \ No newline at end of file diff --git a/service/window_manager/include/input_windows_manager.h b/service/window_manager/include/input_windows_manager.h index 3deb8af47db90186a3364f269342b933d32c4273..277001af02c91ca6a8563574da40adacdd311ec7 100644 --- a/service/window_manager/include/input_windows_manager.h +++ b/service/window_manager/include/input_windows_manager.h @@ -17,14 +17,18 @@ #include +#include "extra_data.h" #include "libinput.h" #include "nocopyable.h" #include "singleton.h" -#include "display_info.h" +#include "window_info.h" #include "input_event.h" +#include "input_display_bind_helper.h" #include "input_event_data_transformation.h" +#include "input_event.h" #include "pointer_event.h" +#include "pointer_style.h" #include "uds_server.h" namespace OHOS { @@ -39,7 +43,7 @@ class InputWindowsManager final { public: DISALLOW_COPY_AND_MOVE(InputWindowsManager); void Init(UDSServer& udsServer); - int32_t GetClientFd(std::shared_ptr pointerEvent) const; + int32_t GetClientFd(std::shared_ptr pointerEvent); #ifdef OHOS_BUILD_ENABLE_KEYBOARD int32_t GetPidAndUpdateTarget(std::shared_ptr inputEvent); #endif // OHOS_BUILD_ENABLE_KEYBOARD @@ -70,8 +74,8 @@ public: #endif // OHOS_BUILD_ENABLE_TOUCH #ifdef OHOS_BUILD_ENABLE_POINTER const DisplayGroupInfo& GetDisplayGroupInfo(); - int32_t SetPointerStyle(int32_t pid, int32_t windowId, int32_t pointerStyle); - int32_t GetPointerStyle(int32_t pid, int32_t windowId, int32_t &pointerStyle) const; + int32_t SetPointerStyle(int32_t pid, int32_t windowId, PointerStyle pointerStyle); + int32_t GetPointerStyle(int32_t pid, int32_t windowId, PointerStyle &pointerStyle) const; #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING bool IsNeedRefreshLayer(int32_t windowId); #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING @@ -83,7 +87,12 @@ public: void DispatchPointer(int32_t pointerAction); void SendPointerEvent(int32_t pointerAction); #endif // OHOS_BUILD_ENABLE_POINTER - + int32_t SetMouseCaptureMode(int32_t windowId, bool isCaptureMode); + bool GetMouseIsCaptureMode() const; + void DeviceStatusChanged(int32_t deviceId, const std::string &sysUid, const std::string devStatus); + int32_t GetDisplayBindInfo(DisplayBindInfos &infos); + int32_t SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg); + int32_t AppendExtraData(const ExtraData& extraData); private: #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) bool IsInHotArea(int32_t x, int32_t y, const std::vector &rects) const; @@ -102,6 +111,9 @@ private: #endif // OHOS_BUILD_ENABLE_JOYSTICK #ifdef OHOS_BUILD_ENABLE_TOUCH int32_t UpdateTouchScreenTarget(std::shared_ptr pointerEvent); + void PullEnterLeaveEvent(int32_t logicalX, int32_t logicalY, + const std::shared_ptr pointerEvent, const WindowInfo* touchWindow); + void DispatchTouch(int32_t pointerAction); #endif // OHOS_BUILD_ENABLE_TOUCH #ifdef OHOS_BUILD_ENABLE_POINTER int32_t UpdateTouchPadTarget(std::shared_ptr pointerEvent); @@ -126,9 +138,13 @@ private: bool IsInsideDisplay(const DisplayInfo& displayInfo, int32_t physicalX, int32_t physicalY); void FindPhysicalDisplay(const DisplayInfo& displayInfo, int32_t& physicalX, int32_t& physicalY, int32_t& displayId); + void InitMouseDownInfo(); #endif // OHOS_BUILD_ENABLE_POINTER void CheckFocusWindowChange(const DisplayGroupInfo &displayGroupInfo); void CheckZorderWindowChange(const DisplayGroupInfo &displayGroupInfo); + void UpdateDisplayIdAndName(); + void UpdatePointerAction(std::shared_ptr pointerEvent); + void ClearExtraData(); private: UDSServer* udsServer_ { nullptr }; #ifdef OHOS_BUILD_ENABLE_POINTER @@ -137,10 +153,25 @@ private: int32_t lastLogicY_ { -1 }; WindowInfo lastWindowInfo_; std::shared_ptr lastPointerEvent_ { nullptr }; - std::map> pointerStyle_; + std::map> pointerStyle_; + WindowInfo mouseDownInfo_; + PointerStyle globalStyle_; +#endif // OHOS_BUILD_ENABLE_POINTER +#ifdef OHOS_BUILD_ENABLE_TOUCH + int32_t lastTouchLogicX_ { -1 }; + int32_t lastTouchLogicY_ { -1 }; + WindowInfo lastTouchWindowInfo_; + std::shared_ptr lastTouchEvent_ { nullptr }; #endif // OHOS_BUILD_ENABLE_POINTER DisplayGroupInfo displayGroupInfo_; - MouseLocation mouseLocation_ = { -1, -1 }; // physical coord + MouseLocation mouseLocation_ = { -1, -1 }; + std::map touchItemDownInfos_; + InputDisplayBindHelper bindInfo_; + struct CaptureModeInfo { + int32_t windowId { -1 }; + bool isCaptureMode { false }; + } captureModeInfo_; + ExtraData extraData_; }; #define WinMgr ::OHOS::DelayedSingleton::GetInstance() diff --git a/service/window_manager/include/pointer_drawing_manager.h b/service/window_manager/include/pointer_drawing_manager.h index c6cba8d513cccbf4313e16fa4f25379f117cb534..2a271980db43fecb7198cd2c0e1dd43f93cf2715 100644 --- a/service/window_manager/include/pointer_drawing_manager.h +++ b/service/window_manager/include/pointer_drawing_manager.h @@ -33,9 +33,9 @@ namespace OHOS { namespace MMI { -class PointerDrawingManager : public IPointerDrawingManager, - public IDeviceObserver, - public std::enable_shared_from_this { +class PointerDrawingManager final : public IPointerDrawingManager, + public IDeviceObserver, + public std::enable_shared_from_this { public: static const int32_t IMAGE_WIDTH = 64; static const int32_t IMAGE_HEIGHT = 64; @@ -43,23 +43,24 @@ public: public: PointerDrawingManager(); DISALLOW_COPY_AND_MOVE(PointerDrawingManager); - ~PointerDrawingManager() = default; + ~PointerDrawingManager() override = default; void DrawPointer(int32_t displayId, int32_t physicalX, int32_t physicalY, - const MOUSE_ICON mouseStyle = MOUSE_ICON::DEFAULT); - void UpdateDisplayInfo(const DisplayInfo& displayInfo); - void OnDisplayInfo(const DisplayGroupInfo& displayGroupInfo); - void OnWindowInfo(const WinInfo &info); - void UpdatePointerDevice(bool hasPointerDevicee, bool isPointerVisible); - bool Init(); - void DeletePointerVisible(int32_t pid); - int32_t SetPointerVisible(int32_t pid, bool visible); - int32_t SetPointerStyle(int32_t pid, int32_t windowId, int32_t pointerStyle); - int32_t GetPointerStyle(int32_t pid, int32_t windowId, int32_t &pointerStyle); - void DrawPointerStyle(); - bool IsPointerVisible(); - void SetPointerLocation(int32_t pid, int32_t x, int32_t y); + const MOUSE_ICON mouseStyle = MOUSE_ICON::DEFAULT) override; + void UpdateDisplayInfo(const DisplayInfo& displayInfo) override; + void OnDisplayInfo(const DisplayGroupInfo& displayGroupInfo) override; + void OnWindowInfo(const WinInfo &info) override; + void UpdatePointerDevice(bool hasPointerDevice, bool isPointerVisible) override; + bool Init() override; + void DeletePointerVisible(int32_t pid) override; + int32_t SetPointerVisible(int32_t pid, bool visible) override; + int32_t SetPointerStyle(int32_t pid, int32_t windowId, PointerStyle pointerStyle) override; + int32_t GetPointerStyle(int32_t pid, int32_t windowId, PointerStyle &pointerStyle) override; + void DrawPointerStyle() override; + bool IsPointerVisible() override; + void SetPointerLocation(int32_t pid, int32_t x, int32_t y) override; void AdjustMouseFocus(ICON_TYPE iconType, int32_t &physicalX, int32_t &physicalY); - + void SetMouseDisplayState(bool state) override; + bool GetMouseDisplayState() const override; private: void CreatePointerWindow(int32_t displayId, int32_t physicalX, int32_t physicalY); sptr GetLayer(); @@ -69,9 +70,7 @@ private: void DrawManager(); void FixCursorPosition(int32_t &physicalX, int32_t &physicalY); std::unique_ptr DecodeImageToPixelMap(const std::string &imagePath); - void DeletePidInfo(int32_t pid); void UpdatePointerVisible(); - void UpdatePidInfo(int32_t pid, bool visible); void InitStyle(); int32_t InitLayer(const MOUSE_ICON mouseStyle); @@ -86,13 +85,14 @@ private: bool hasPointerDevice_ { false }; int32_t lastPhysicalX_ { -1 }; int32_t lastPhysicalY_ { -1 }; - int32_t lastMouseStyle_ { -1 }; + PointerStyle lastMouseStyle_ {}; int32_t pid_ { 0 }; int32_t windowId_ { 0 }; int32_t imageWidth_ { 0 }; int32_t imageHeight_ { 0 }; std::map mouseIcons_; std::list pidInfos_; + bool mouseDisplayState_ { false }; }; } // namespace MMI } // namespace OHOS diff --git a/service/window_manager/src/input_display_bind_helper.cpp b/service/window_manager/src/input_display_bind_helper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4d3aac723385beeaa921f3910a3b1b9920e567f0 --- /dev/null +++ b/service/window_manager/src/input_display_bind_helper.cpp @@ -0,0 +1,511 @@ +/* + * 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. + */ +#include "input_display_bind_helper.h" + +#include +#include +#include +#include + +#include "mmi_log.h" + +namespace OHOS { +namespace MMI { +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "InputDisplayBindHelper" }; +} +class BindInfo +{ +public: + int32_t GetInputDeviceId() const { return inputDeviceId_; } + std::string GetInputDeviceName() const { return inputDeviceName_; } + int32_t GetDisplayId() const { return displayId_; } + std::string GetDisplayName() const { return displayName_; } + bool IsUnbind() const { return ((inputDeviceId_ == -1) || (displayId_ == -1)); } + bool InputDeviceNotBind() const { return (inputDeviceId_ == -1); } + bool DisplayNotBind() const { return (displayId_ == -1); } + bool AddInputDevice(int32_t deviceId, const std::string &deviceName); + void RemoveInputDevice(); + bool AddDisplay(int32_t id, const std::string &name); + void RemoveDisplay(); + std::string GetDesc() const; + friend bool operator<(const BindInfo &l, const BindInfo &r); + friend std::ostream& operator<<(std::ostream &os, const BindInfo &r); + friend std::istream& operator>>(std::istream &is, BindInfo &r); +private: + int32_t inputDeviceId_ { -1 }; + std::string inputDeviceName_; + int32_t displayId_ { -1 }; + std::string displayName_; +}; + +class BindInfos { +public: + bool Add(const BindInfo &info); + void UnbindInputDevice(int32_t deviceId); + void UnbindDisplay(int32_t displayId); + BindInfo GetUnbindInputDevice(const std::string &displayName); + BindInfo GetUnbindDisplay(const std::string &inputDeviceName); + std::string GetDisplayNameByInputDevice(const std::string &name); + int32_t GetBindDisplayIdByInputDevice(int32_t inputDeviceId) const; + std::string GetBindDisplayNameByInputDevice(int32_t inputDeviceId) const; + std::string GetInputDeviceByDisplayName(const std::string &name); + std::string GetDesc() const; + const std::list &GetInfos() const { return infos_; } + friend std::ostream& operator<<(std::ostream &os, const BindInfos &r); + friend std::istream& operator>>(std::istream &is, BindInfos &r); +private: + BindInfo GetUnbindInputDevice(); + BindInfo GetUnbindInfo(); + BindInfo GetUnbindDisplay(); + std::list infos_; +}; + +bool BindInfo::AddInputDevice(int32_t deviceId, const std::string &deviceName) +{ + if ((inputDeviceId_ != -1) || !inputDeviceName_.empty()) { + return false; + } + inputDeviceId_ = deviceId; + inputDeviceName_ = deviceName; + return true; +} + +void BindInfo::RemoveInputDevice() { + inputDeviceId_ = -1; + inputDeviceName_.clear(); +} +bool BindInfo::AddDisplay(int32_t id, const std::string &name) { + if ((displayId_ != -1) || !displayName_.empty()) { + return false; + } + displayId_ = id; + displayName_ = name; + return true; +} +void BindInfo::RemoveDisplay() { + displayId_ = -1; + displayName_.clear(); +} +std::string BindInfo::GetDesc() const { + std::ostringstream oss; + oss << "InputDevice(id:" << inputDeviceId_ << ",name:" << inputDeviceName_ << "),Display(id:" << displayId_ << ",name:" << displayName_ << ")"; + return oss.str(); +} + +bool operator<(const BindInfo &l, const BindInfo &r) { + if (l.inputDeviceId_ != r.inputDeviceId_) { + return (l.inputDeviceId_ < r.inputDeviceId_); + } + return (l.displayId_ < r.displayId_); +} + +std::ostream& operator<<(std::ostream &os, const BindInfo &r) { + os << r.inputDeviceName_ << "<=>" << r.displayName_ << std::endl; + return os; +} + +std::istream& operator>>(std::istream &is, BindInfo &r) { + std::string line; + std::getline(is, line); + const std::string delim = "<=>"; + std::string::size_type pos = line.find(delim); + if (pos == std::string::npos) { + return is; + } + r.inputDeviceName_ = line.substr(0, pos); + r.displayName_ = line.substr(pos + delim.length()); + r.inputDeviceId_ = 0; + r.displayId_ = 0; + return is; +} + +std::string BindInfos::GetDesc() const { + int32_t index = 0; + std::ostringstream oss; + for (auto &info : infos_) { + oss << "index:" << index << "," << info.GetDesc() << std::endl; + } + return oss.str(); +} + +int32_t BindInfos::GetBindDisplayIdByInputDevice(int32_t inputDeviceId) const { + for (const auto &item : infos_) { + if (item.GetInputDeviceId() == inputDeviceId) { + if (!item.IsUnbind()) { + return item.GetDisplayId(); + } + } + } + return -1; +} + +std::string BindInfos::GetBindDisplayNameByInputDevice(int32_t inputDeviceId) const { + for (const auto &item : infos_) { + if (item.GetInputDeviceId() == inputDeviceId) { + if (!item.IsUnbind()) { + return item.GetDisplayName(); + } + } + } + return ""; +} + +std::string BindInfos::GetDisplayNameByInputDevice(const std::string &name) { + for (const auto &item : infos_) { + if (item.GetInputDeviceName() == name) { + return item.GetDisplayName(); + } + } + return ""; +} + +std::string BindInfos::GetInputDeviceByDisplayName(const std::string &name) { + for (const auto &item : infos_) { + if (item.GetDisplayName() == name) { + return item.GetInputDeviceName(); + } + } + return ""; +} + +bool BindInfos::Add(const BindInfo &info) { + auto it = infos_.begin(); + for (; it != infos_.end(); ++it) { + if (info < *it) { + break; + } + } + auto it2 = infos_.emplace(it, std::move(info)); + if (it2 == infos_.end()) { + MMI_HILOGE("Duplicate %{public}s", info.GetDesc().c_str()); + } + return true; +} + +void BindInfos::UnbindInputDevice(int32_t deviceId) { + auto it = infos_.begin(); + for (; it != infos_.end(); ++it) { + if (it->GetInputDeviceId() == deviceId) { + it->RemoveInputDevice(); + if (it->IsUnbind()) { + infos_.erase(it); + } + return; + } + } +} + +void BindInfos::UnbindDisplay(int32_t displayId) { + auto it = infos_.begin(); + for (; it != infos_.end(); ++it) { + if (it->GetDisplayId() == displayId) { + it->RemoveDisplay(); + if (it->IsUnbind()) { + infos_.erase(it); + } + return; + } + } +} + +BindInfo BindInfos::GetUnbindInfo() { + auto it = infos_.begin(); + while (it != infos_.end()) { + if (it->IsUnbind()) { + auto info = std::move(*it); + infos_.erase(it); + return info; + } + ++it; + } + return BindInfo(); +} + +BindInfo BindInfos::GetUnbindInputDevice(const std::string &displayName) { + auto it = infos_.begin(); + while (it != infos_.end()) { + if (it->InputDeviceNotBind()) { + if (it->GetDisplayName() == displayName) { + auto info = std::move(*it); + infos_.erase(it); + return info; + } + } + ++it; + } + return BindInfo(); +} + +BindInfo BindInfos::GetUnbindDisplay() { + auto it = infos_.begin(); + while (it != infos_.end()) { + if (it->DisplayNotBind()) { + auto info = std::move(*it); + infos_.erase(it); + return info; + } + ++it; + } + return BindInfo(); +} + +BindInfo BindInfos::GetUnbindDisplay(const std::string &inputDeviceName) { + auto it = infos_.begin(); + while (it != infos_.end()) { + if (it->DisplayNotBind()) { + if (it->GetInputDeviceName() == inputDeviceName) { + auto info = std::move(*it); + infos_.erase(it); + return info; + } + } + ++it; + } + return GetUnbindDisplay(); +} + +std::ostream& operator<<(std::ostream &os, const BindInfos &r) { + const auto &infos = r.GetInfos(); + for (const auto &info : infos) { + if (!info.IsUnbind()) { + os << info; + } + } + return os; +} + +std::istream& operator>>(std::istream &is, BindInfos &r) { + while (!is.eof()) { + BindInfo info; + is >> info; + if (info.IsUnbind()) { + break; + } + r.Add(info); + } + return is; +} + +InputDisplayBindHelper::InputDisplayBindHelper(const std::string bindCfgFile) + : fileName_(bindCfgFile), + infos_(std::make_shared()), + configFileInfos_(std::make_shared()) +{} + +std::string InputDisplayBindHelper::GetBindDisplayNameByInputDevice(int32_t inputDeviceId) const +{ + CALL_DEBUG_ENTER; + if (infos_ == nullptr) { + return {}; + } + return infos_->GetBindDisplayNameByInputDevice(inputDeviceId); +} + +void InputDisplayBindHelper::AddInputDevice(int32_t id, const std::string &name) +{ + CALL_DEBUG_ENTER; + MMI_HILOGD("Param: id:%{public}d, name:%{public}s", id, name.c_str()); + auto displayName = configFileInfos_->GetDisplayNameByInputDevice(name); + BindInfo info = infos_->GetUnbindInputDevice(displayName); + info.AddInputDevice(id, name); + infos_->Add(info); + Store(); +} + +void InputDisplayBindHelper::RemoveInputDevice(int32_t id) +{ + CALL_DEBUG_ENTER; + MMI_HILOGD("Param: id:%{public}d", id); + infos_->UnbindInputDevice(id); +} + +bool InputDisplayBindHelper::IsDisplayAdd(int32_t id, const std::string &name) +{ + const auto &infos = infos_->GetInfos(); + for (const auto &info : infos) { + if ((info.GetDisplayName() == name) && (info.GetDisplayId() == id)) { + return true; + } + } + return false; +} + +std::set> InputDisplayBindHelper::GetDisplayIdNames() const +{ + CALL_DEBUG_ENTER; + std::set> idNames; + const auto &infos = infos_->GetInfos(); + for (const auto &info : infos) { + if (info.GetDisplayId() != -1) { + idNames.insert(std::make_pair(info.GetDisplayId(), info.GetDisplayName())); + } + } + return idNames; +} + +void InputDisplayBindHelper::AddDisplay(int32_t id, const std::string &name) +{ + CALL_DEBUG_ENTER; + MMI_HILOGD("Param: id:%{public}d, name:%{public}s", id, name.c_str()); + auto inputDeviceName = configFileInfos_->GetInputDeviceByDisplayName(name); + BindInfo info = infos_->GetUnbindDisplay(inputDeviceName); + info.AddDisplay(id, name); + infos_->Add(info); + Store(); +} + +void InputDisplayBindHelper::RemoveDisplay(int32_t id) +{ + CALL_DEBUG_ENTER; + MMI_HILOGD("Param: id:%{public}d", id); + infos_->UnbindDisplay(id); +} + +void InputDisplayBindHelper::Store() +{ + CALL_DEBUG_ENTER; + if (infos_ == nullptr) { + return; + } + std::ofstream ofs(fileName_.c_str(), std::ios::trunc | std::ios::out | std::ios_base::binary); + if (!ofs) { + MMI_HILOGE("Open file fail.%{public}s, errno:%{public}d", fileName_.c_str(), errno); + return; + } + ofs << *infos_; + ofs.close(); +} + +int32_t InputDisplayBindHelper::GetDisplayBindInfo(DisplayBindInfos &infos) +{ + CALL_DEBUG_ENTER; + if (infos_ == nullptr) { + MMI_HILOGE("Infos_ is nullptr"); + return RET_ERR; + } + for (const auto &item : infos_->GetInfos()) { + infos.push_back({ + .inputDeviceId = item.GetInputDeviceId(), + .inputDeviceName = item.GetInputDeviceName(), + .displayId = item.GetDisplayId(), + .displayName = item.GetDisplayName(), + }); + } + return RET_OK; +} + +int32_t InputDisplayBindHelper::SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg) +{ + CALL_DEBUG_ENTER; + MMI_HILOGD("Param: deviceId:%{public}d, displayId:%{public}d", deviceId, displayId); + if ((deviceId == -1) || (displayId == -1)) { + msg = "The deviceId or displayId is invalid"; + MMI_HILOGE("%s", msg.c_str()); + return RET_ERR; + } + if (infos_ == nullptr) { + msg = "Infos_ is nullptr"; + MMI_HILOGE("%s", msg.c_str()); + return RET_ERR; + } + + BindInfo bindByDevice; + BindInfo bindByDisplay; + for (const auto &item : infos_->GetInfos()) { + if (item.GetInputDeviceId() == deviceId) { + bindByDevice = item; + } + if (item.GetDisplayId() == displayId) { + bindByDisplay = item; + } + } + if (bindByDevice.GetInputDeviceId() == -1) { + msg = "The deviceId is invalid"; + MMI_HILOGE("%s", msg.c_str()); + return RET_ERR; + } + if (bindByDisplay.GetDisplayId() == -1) { + msg = "The displayId is invalid"; + MMI_HILOGE("%s", msg.c_str()); + return RET_ERR; + } + + if (infos_->GetBindDisplayIdByInputDevice(deviceId) == displayId) { + msg = "The input device and display has alread bind"; + MMI_HILOGE("%s", msg.c_str()); + return RET_ERR; + } + + infos_->UnbindInputDevice(bindByDevice.GetInputDeviceId()); + infos_->UnbindInputDevice(bindByDisplay.GetInputDeviceId()); + infos_->UnbindDisplay(bindByDevice.GetDisplayId()); + infos_->UnbindDisplay(bindByDisplay.GetDisplayId()); + + BindInfo info1; + info1.AddInputDevice(bindByDevice.GetInputDeviceId(), bindByDevice.GetInputDeviceName()) ; + info1.AddDisplay(bindByDisplay.GetDisplayId(), bindByDisplay.GetDisplayName()); + infos_->Add(info1); + + if ((bindByDevice.GetDisplayId() != -1) && (bindByDisplay.GetInputDeviceId() != -1)) { + MMI_HILOGD("Both display id and input device id are invalid"); + BindInfo info2; + info2.AddInputDevice(bindByDisplay.GetInputDeviceId(), bindByDisplay.GetInputDeviceName()); + info2.AddDisplay(bindByDevice.GetDisplayId(), bindByDevice.GetDisplayName()); + infos_->Add(info2); + return RET_OK; + } + + if (bindByDevice.GetDisplayId() != -1) { + MMI_HILOGD("The display id is invalid"); + AddDisplay(bindByDevice.GetDisplayId(), bindByDevice.GetDisplayName()); + return RET_OK; + } + + if (bindByDisplay.GetInputDeviceId() != -1) { + MMI_HILOGD("The input device id is invalid"); + AddInputDevice(bindByDisplay.GetInputDeviceId(), bindByDisplay.GetInputDeviceName()); + return RET_OK; + } + + msg = "Can not reach here"; + return RET_ERR; +} + +void InputDisplayBindHelper::Load() +{ + CALL_DEBUG_ENTER; + std::ifstream ifs(fileName_.c_str()); + MMI_HILOGEK("Open file end:%{public}s", fileName_.c_str()); + if (!ifs) { + MMI_HILOGE("Open file fail.%{public}s, errno:%{public}d", fileName_.c_str(), errno); + return; + } + ifs >> *configFileInfos_; + ifs.close(); +} + +std::string InputDisplayBindHelper::Dumps() const +{ + CALL_DEBUG_ENTER; + if (infos_ == nullptr) { + return {}; + } + std::ostringstream oss; + oss << *infos_; + return oss.str(); +} +} //namespace MMI +} // namespace OHOS \ No newline at end of file diff --git a/service/window_manager/src/input_windows_manager.cpp b/service/window_manager/src/input_windows_manager.cpp index 782decd89d83d82b83a528aea097d0ec9a7d6c6c..f704b0cb546715396b27b261093ee9b5cabc7311 100644 --- a/service/window_manager/src/input_windows_manager.cpp +++ b/service/window_manager/src/input_windows_manager.cpp @@ -19,37 +19,65 @@ #include #include "dfx_hisysevent.h" -#include "i_pointer_drawing_manager.h" #include "input_device_manager.h" +#include "i_pointer_drawing_manager.h" #include "mouse_event_normalize.h" #include "pointer_drawing_manager.h" +#include "util.h" #include "util_ex.h" #include "util_napi_error.h" -#include "util.h" namespace OHOS { namespace MMI { namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "InputWindowsManager"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "InputWindowsManager" }; #ifdef OHOS_BUILD_ENABLE_POINTER constexpr int32_t DEFAULT_POINTER_STYLE = 0; -constexpr size_t MAX_WINDOW_COUNT = 20; #endif // OHOS_BUILD_ENABLE_POINTER +const std::string bindCfgFileName = "/data/service/el1/public/multimodalinput/display_bind.cfg"; } // namespace -InputWindowsManager::InputWindowsManager() {} +InputWindowsManager::InputWindowsManager() : bindInfo_(bindCfgFileName) +{ + MMI_HILOGI("Bind cfg file name:%{public}s", bindCfgFileName.c_str()); +} + InputWindowsManager::~InputWindowsManager() {} +void InputWindowsManager::DeviceStatusChanged(int32_t deviceId, const std::string &sysUid, const std::string devStatus) +{ + CALL_INFO_TRACE; + if (devStatus == "add") { + bindInfo_.AddInputDevice(deviceId, sysUid); + } else { + bindInfo_.RemoveInputDevice(deviceId); + } +} + void InputWindowsManager::Init(UDSServer& udsServer) { udsServer_ = &udsServer; CHKPV(udsServer_); + bindInfo_.Load(); #ifdef OHOS_BUILD_ENABLE_POINTER udsServer_->AddSessionDeletedCallback(std::bind(&InputWindowsManager::OnSessionLost, this, std::placeholders::_1)); + InitMouseDownInfo(); #endif // OHOS_BUILD_ENABLE_POINTER + InputDevMgr->SetInputStatusChangeCallback(std::bind(&InputWindowsManager::DeviceStatusChanged, this, + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); } -int32_t InputWindowsManager::GetClientFd(std::shared_ptr pointerEvent) const +#ifdef OHOS_BUILD_ENABLE_POINTER +void InputWindowsManager::InitMouseDownInfo() +{ + mouseDownInfo_.id = -1; + mouseDownInfo_.pid = -1; + mouseDownInfo_.defaultHotAreas.clear(); + mouseDownInfo_.pointerHotAreas.clear(); +} +#endif // OHOS_BUILD_ENABLE_POINTER + +int32_t InputWindowsManager::GetClientFd(std::shared_ptr pointerEvent) { CALL_DEBUG_ENTER; CHKPR(pointerEvent, INVALID_FD); @@ -60,9 +88,31 @@ int32_t InputWindowsManager::GetClientFd(std::shared_ptr pointerEv break; } } - CHKPR(windowInfo, INVALID_FD); + CHKPR(udsServer_, INVALID_FD); - return udsServer_->GetClientFd(windowInfo->pid); + if (windowInfo != nullptr) { + return udsServer_->GetClientFd(windowInfo->pid); + } + if (pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_CANCEL) { + return udsServer_->GetClientFd(-1); + } + int32_t pid = -1; + if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHSCREEN) { + auto iter = touchItemDownInfos_.find(pointerEvent->GetPointerId()); + if (iter != touchItemDownInfos_.end()) { + pid = iter->second.pid; + touchItemDownInfos_.erase(iter); + } + } +#ifdef OHOS_BUILD_ENABLE_POINTER + if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_MOUSE) { + if (mouseDownInfo_.pid != -1) { + pid = mouseDownInfo_.pid; + InitMouseDownInfo(); + } + } +#endif // OHOS_BUILD_ENABLE_POINTER + return udsServer_->GetClientFd(pid); } #ifdef OHOS_BUILD_ENABLE_KEYBOARD @@ -174,12 +224,56 @@ void InputWindowsManager::CheckZorderWindowChange(const DisplayGroupInfo &displa oldZorderFirstWindowPid, newZorderFirstWindowPid); } +void InputWindowsManager::UpdateDisplayIdAndName() { + using IdNames = std::set>; + IdNames newInfo; + for (const auto &item : displayGroupInfo_.displaysInfo) { + newInfo.insert(std::make_pair(item.id, item.uniq)); + } + auto oldInfo = bindInfo_.GetDisplayIdNames(); + if (newInfo == oldInfo) { + return; + } + for (auto it = oldInfo.begin(); it != oldInfo.end();) { + if (newInfo.find(*it) == newInfo.end()) { + bindInfo_.RemoveDisplay(it->first); + oldInfo.erase(it++); + } else { + ++it; + } + } + for (const auto &item : newInfo) { + if (!bindInfo_.IsDisplayAdd(item.first, item.second)) { + bindInfo_.AddDisplay(item.first, item.second); + } + } +} + +int32_t InputWindowsManager::GetDisplayBindInfo(DisplayBindInfos &infos) +{ + CALL_DEBUG_ENTER; + return bindInfo_.GetDisplayBindInfo(infos); +} + +int32_t InputWindowsManager::SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg) +{ + CALL_DEBUG_ENTER; + return bindInfo_.SetDisplayBind(deviceId, displayId, msg); +} + void InputWindowsManager::UpdateDisplayInfo(const DisplayGroupInfo &displayGroupInfo) { CALL_DEBUG_ENTER; CheckFocusWindowChange(displayGroupInfo); CheckZorderWindowChange(displayGroupInfo); + if (captureModeInfo_.isCaptureMode && + ((displayGroupInfo_.focusWindowId != displayGroupInfo.focusWindowId) || + (displayGroupInfo_.windowsInfo[0].id != displayGroupInfo.windowsInfo[0].id))) { + captureModeInfo_.isCaptureMode = false; + } displayGroupInfo_ = displayGroupInfo; + PrintDisplayInfo(); + UpdateDisplayIdAndName(); #ifdef OHOS_BUILD_ENABLE_POINTER UpdatePointerStyle(); #endif // OHOS_BUILD_ENABLE_POINTER @@ -197,7 +291,14 @@ void InputWindowsManager::UpdateDisplayInfo(const DisplayGroupInfo &displayGroup CHKPV(displayInfo); int32_t logicX = mouseLocation.physicalX + displayInfo->x; int32_t logicY = mouseLocation.physicalY + displayInfo->y; - std::optional windowInfo = GetWindowInfo(logicX, logicY); + std::optional windowInfo; + CHKPV(lastPointerEvent_); + if (lastPointerEvent_->GetPointerAction() == PointerEvent::POINTER_ACTION_MOVE && + lastPointerEvent_->GetPressedButtons().empty()) { + windowInfo = GetWindowInfo(logicX, logicY); + } else { + windowInfo = SelectWindowInfo(logicX, logicY, lastPointerEvent_); + } if (!windowInfo) { MMI_HILOGE("The windowInfo is nullptr"); return; @@ -216,7 +317,6 @@ void InputWindowsManager::UpdateDisplayInfo(const DisplayGroupInfo &displayGroup #endif // OHOS_BUILD_ENABLE_POINTER } #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING - PrintDisplayInfo(); } #ifdef OHOS_BUILD_ENABLE_POINTER @@ -262,11 +362,19 @@ void InputWindowsManager::SendPointerEvent(int32_t pointerAction) pointerEvent->SetActionTime(time); pointerEvent->SetActionStartTime(time); pointerEvent->UpdateId(); + if (extraData_.appended && extraData_.sourceType == PointerEvent::SOURCE_TYPE_MOUSE) { + pointerEvent->SetBuffer(extraData_.buffer); + UpdatePointerAction(pointerEvent); + } else { + pointerEvent->ClearBuffer(); + } auto fd = udsServer_->GetClientFd(lastWindowInfo_.pid); auto sess = udsServer_->GetSession(fd); - CHKPV(sess); - + if (sess == nullptr) { + MMI_HILOGI("The last window has disappeared"); + return; + } NetPacket pkt(MmiMessageId::ON_POINTER_EVENT); InputEventDataTransformation::Marshalling(pointerEvent, pkt); if (!sess->SendMsg(pkt)) { @@ -279,6 +387,10 @@ void InputWindowsManager::DispatchPointer(int32_t pointerAction) { CALL_INFO_TRACE; CHKPV(udsServer_); + if (!IPointerDrawingManager::GetInstance()->GetMouseDisplayState()) { + MMI_HILOGI("the mouse is hide"); + return; + } if (lastPointerEvent_ == nullptr) { SendPointerEvent(pointerAction); return; @@ -294,7 +406,13 @@ void InputWindowsManager::DispatchPointer(int32_t pointerAction) return; } if (pointerAction == PointerEvent::POINTER_ACTION_ENTER_WINDOW) { - auto windowInfo = GetWindowInfo(lastLogicX_, lastLogicY_); + std::optional windowInfo; + if (lastPointerEvent_->GetPointerAction() == PointerEvent::POINTER_ACTION_MOVE && + lastPointerEvent_->GetPressedButtons().empty()) { + windowInfo = GetWindowInfo(lastLogicX_, lastLogicY_); + } else { + windowInfo = SelectWindowInfo(lastLogicX_, lastLogicY_, lastPointerEvent_); + } if (!windowInfo) { MMI_HILOGE("windowInfo is nullptr"); return; @@ -321,7 +439,12 @@ void InputWindowsManager::DispatchPointer(int32_t pointerAction) pointerEvent->SetActionTime(time); pointerEvent->SetActionStartTime(time); pointerEvent->SetDeviceId(lastPointerEvent_->GetDeviceId()); - + if (extraData_.appended && extraData_.sourceType == PointerEvent::SOURCE_TYPE_MOUSE) { + pointerEvent->SetBuffer(extraData_.buffer); + UpdatePointerAction(pointerEvent); + } else { + pointerEvent->ClearBuffer(); + } auto fd = udsServer_->GetClientFd(lastWindowInfo_.pid); if (fd == RET_ERR) { auto windowInfo = GetWindowInfo(lastLogicX_, lastLogicY_); @@ -332,7 +455,10 @@ void InputWindowsManager::DispatchPointer(int32_t pointerAction) fd = udsServer_->GetClientFd(windowInfo->pid); } auto sess = udsServer_->GetSession(fd); - CHKPV(sess); + if (sess == nullptr) { + MMI_HILOGI("The last window has disappeared"); + return; + } NetPacket pkt(MmiMessageId::ON_POINTER_EVENT); InputEventDataTransformation::Marshalling(pointerEvent, pkt); @@ -345,22 +471,36 @@ void InputWindowsManager::DispatchPointer(int32_t pointerAction) void InputWindowsManager::NotifyPointerToWindow() { CALL_INFO_TRACE; - auto windowInfo = GetWindowInfo(lastLogicX_, lastLogicY_); + std::optional windowInfo; + CHKPV(lastPointerEvent_); + if (lastPointerEvent_->GetPointerAction() == PointerEvent::POINTER_ACTION_MOVE && + lastPointerEvent_->GetPressedButtons().empty()) { + windowInfo = GetWindowInfo(lastLogicX_, lastLogicY_); + } else { + windowInfo = SelectWindowInfo(lastLogicX_, lastLogicY_, lastPointerEvent_); + } if (!windowInfo) { - MMI_HILOGE("windowInfo is nullptr"); + MMI_HILOGE("The windowInfo is nullptr"); return; } if (windowInfo->id == lastWindowInfo_.id) { - MMI_HILOGI("The mouse pointer does not leave the window"); + MMI_HILOGI("The mouse pointer does not leave the window:%{public}d", lastWindowInfo_.id); lastWindowInfo_ = *windowInfo; return; } + bool isFindLastWindow = false; for (const auto &item : displayGroupInfo_.windowsInfo) { if (item.id == lastWindowInfo_.id) { DispatchPointer(PointerEvent::POINTER_ACTION_LEAVE_WINDOW); + isFindLastWindow = true; break; } } + if (!isFindLastWindow) { + if (udsServer_ != nullptr && udsServer_->GetClientFd(lastWindowInfo_.pid) != INVALID_FD) { + DispatchPointer(PointerEvent::POINTER_ACTION_LEAVE_WINDOW); + } + } lastWindowInfo_ = *windowInfo; DispatchPointer(PointerEvent::POINTER_ACTION_ENTER_WINDOW); } @@ -368,11 +508,11 @@ void InputWindowsManager::NotifyPointerToWindow() void InputWindowsManager::PrintDisplayInfo() { - MMI_HILOGI("logicalInfo,width:%{public}d,height:%{public}d,focusWindowId:%{public}d", + MMI_HILOGD("logicalInfo,width:%{public}d,height:%{public}d,focusWindowId:%{public}d", displayGroupInfo_.width, displayGroupInfo_.height, displayGroupInfo_.focusWindowId); - MMI_HILOGI("windowsInfos,num:%{public}zu", displayGroupInfo_.windowsInfo.size()); + MMI_HILOGD("windowsInfos,num:%{public}zu", displayGroupInfo_.windowsInfo.size()); for (const auto &item : displayGroupInfo_.windowsInfo) { - MMI_HILOGI("windowsInfos,id:%{public}d,pid:%{public}d,uid:%{public}d," + MMI_HILOGD("windowsInfos,id:%{public}d,pid:%{public}d,uid:%{public}d," "area.x:%{public}d,area.y:%{public}d,area.width:%{public}d,area.height:%{public}d," "defaultHotAreas.size:%{public}zu,pointerHotAreas.size:%{public}zu," "agentWindowId:%{public}d,flags:%{public}d", @@ -380,18 +520,18 @@ void InputWindowsManager::PrintDisplayInfo() item.area.height, item.defaultHotAreas.size(), item.pointerHotAreas.size(), item.agentWindowId, item.flags); for (const auto &win : item.defaultHotAreas) { - MMI_HILOGI("defaultHotAreas:x:%{public}d,y:%{public}d,width:%{public}d,height:%{public}d", + MMI_HILOGD("defaultHotAreas:x:%{public}d,y:%{public}d,width:%{public}d,height:%{public}d", win.x, win.y, win.width, win.height); } for (const auto &pointer : item.pointerHotAreas) { - MMI_HILOGI("pointerHotAreas:x:%{public}d,y:%{public}d,width:%{public}d,height:%{public}d", + MMI_HILOGD("pointerHotAreas:x:%{public}d,y:%{public}d,width:%{public}d,height:%{public}d", pointer.x, pointer.y, pointer.width, pointer.height); } } - MMI_HILOGI("displayInfos,num:%{public}zu", displayGroupInfo_.displaysInfo.size()); + MMI_HILOGD("displayInfos,num:%{public}zu", displayGroupInfo_.displaysInfo.size()); for (const auto &item : displayGroupInfo_.displaysInfo) { - MMI_HILOGI("displayInfos,id:%{public}d,x:%{public}d,y:%{public}d," + MMI_HILOGD("displayInfos,id:%{public}d,x:%{public}d,y:%{public}d," "width:%{public}d,height:%{public}d,name:%{public}s," "uniq:%{public}s,direction:%{public}d", item.id, item.x, item.y, item.width, item.height, item.name.c_str(), @@ -428,27 +568,27 @@ void InputWindowsManager::RotateTouchScreen(DisplayInfo info, LogicalCoordinate& { const Direction direction = info.direction; - if (direction == Direction0) { - MMI_HILOGD("direction is Direction0"); + if (direction == DIRECTION0) { + MMI_HILOGD("direction is DIRECTION0"); return; } - if (direction == Direction90) { - MMI_HILOGD("direction is Direction90"); + if (direction == DIRECTION90) { + MMI_HILOGD("direction is DIRECTION90"); int32_t temp = coord.x; coord.x = info.height - coord.y; coord.y = temp; MMI_HILOGD("physicalX:%{public}d, physicalY:%{public}d", coord.x, coord.y); return; } - if (direction == Direction180) { - MMI_HILOGD("direction is Direction180"); + if (direction == DIRECTION180) { + MMI_HILOGD("direction is DIRECTION180"); coord.x = info.width - coord.x; coord.y = info.height - coord.y; MMI_HILOGD("physicalX:%{public}d, physicalY:%{public}d", coord.x, coord.y); return; } - if (direction == Direction270) { - MMI_HILOGD("direction is Direction270"); + if (direction == DIRECTION270) { + MMI_HILOGD("direction is DIRECTION270"); int32_t temp = coord.y; coord.y = info.width - coord.x; coord.x = temp; @@ -478,7 +618,7 @@ bool InputWindowsManager::TouchPointToDisplayPoint(int32_t deviceId, struct libi EventTouch& touchInfo, int32_t& physicalDisplayId) { CHKPF(touch); - std::string screenId = InputDevMgr->GetScreenId(deviceId); + std::string screenId = bindInfo_.GetBindDisplayNameByInputDevice(deviceId); if (screenId.empty()) { screenId = "default0"; } @@ -541,7 +681,7 @@ bool InputWindowsManager::IsNeedRefreshLayer(int32_t windowId) displayId = displayGroupInfo_.displaysInfo[0].id; } auto displayInfo = GetPhysicalDisplay(displayId); - CHKPR(displayInfo, false); + CHKPF(displayInfo); int32_t logicX = mouseLocation.physicalX + displayInfo->x; int32_t logicY = mouseLocation.physicalY + displayInfo->y; std::optional touchWindow = GetWindowInfo(logicX, logicY); @@ -574,42 +714,57 @@ void InputWindowsManager::OnSessionLost(SessionPtr session) } } -int32_t InputWindowsManager::SetPointerStyle(int32_t pid, int32_t windowId, int32_t pointerStyle) +int32_t InputWindowsManager::SetPointerStyle(int32_t pid, int32_t windowId, PointerStyle pointerStyle) { CALL_DEBUG_ENTER; + if (windowId == GLOBAL_WINDOW_ID) { + globalStyle_.id = pointerStyle.id; + MMI_HILOGD("Setting global pointer style"); + return RET_OK; + } auto it = pointerStyle_.find(pid); if (it == pointerStyle_.end()) { MMI_HILOGE("The pointer style map is not include param pd:%{public}d", pid); - return COMMON_PARAMETER_ERROR ; + return COMMON_PARAMETER_ERROR; } - auto iter = it->second.find(windowId); - if (iter == it->second.end()) { - MMI_HILOGE("The window id is invalid"); - return COMMON_PARAMETER_ERROR ; + if (iter != it->second.end()) { + iter->second = pointerStyle; + return RET_OK; } - - iter->second = pointerStyle; - MMI_HILOGD("Window id:%{public}d set pointer style:%{public}d success", windowId, pointerStyle); - return RET_OK; + for (const auto& windowInfo : displayGroupInfo_.windowsInfo) { + if (windowId == windowInfo.id && pid == windowInfo.pid) { + auto iter = it->second.insert(std::make_pair(windowId, pointerStyle)); + if (!iter.second) { + MMI_HILOGW("The window type is duplicated"); + } + return RET_OK; + } + } + MMI_HILOGE("The window id is invalid"); + return COMMON_PARAMETER_ERROR; } -int32_t InputWindowsManager::GetPointerStyle(int32_t pid, int32_t windowId, int32_t &pointerStyle) const +int32_t InputWindowsManager::GetPointerStyle(int32_t pid, int32_t windowId, PointerStyle &pointerStyle) const { CALL_DEBUG_ENTER; + if (windowId == GLOBAL_WINDOW_ID) { + MMI_HILOGD("Getting global pointer style"); + pointerStyle.id = globalStyle_.id; + return RET_OK; + } auto it = pointerStyle_.find(pid); if (it == pointerStyle_.end()) { MMI_HILOGE("The pointer style map is not include param pd, %{public}d", pid); return RET_ERR; } - auto iter = it->second.find(windowId); if (iter == it->second.end()) { - MMI_HILOGE("The window id is Invalid"); - return COMMON_PARAMETER_ERROR ; + pointerStyle.id = globalStyle_.id; + return RET_OK; } - MMI_HILOGD("Window type:%{public}d get pointer style:%{public}d success", windowId, iter->second); + MMI_HILOGD("Window type:%{public}d get pointer style:%{public}d success", windowId, iter->second.id); pointerStyle = iter->second; return RET_OK; } @@ -617,31 +772,20 @@ int32_t InputWindowsManager::GetPointerStyle(int32_t pid, int32_t windowId, int3 void InputWindowsManager::UpdatePointerStyle() { CALL_DEBUG_ENTER; + PointerStyle pointerStyle; + pointerStyle.id = DEFAULT_POINTER_STYLE; for (const auto& windowItem : displayGroupInfo_.windowsInfo) { int32_t pid = windowItem.pid; auto it = pointerStyle_.find(pid); if (it == pointerStyle_.end()) { - std::map tmpPointerStyle = {{windowItem.id, DEFAULT_POINTER_STYLE}}; + std::map tmpPointerStyle = {}; auto iter = pointerStyle_.insert(std::make_pair(pid, tmpPointerStyle)); if (!iter.second) { MMI_HILOGW("The pd is duplicated"); } continue; } - - auto subIter = it->second.find(windowItem.id); - if (subIter == it->second.end()) { - if (it->second.size() == MAX_WINDOW_COUNT) { - MMI_HILOGD("The window count:%{public}zu exceeds limit in same pd", it->second.size()); - it->second.erase(it->second.begin()); - } - auto iter = it->second.insert(std::make_pair(windowItem.id, DEFAULT_POINTER_STYLE)); - if (!iter.second) { - MMI_HILOGW("The window type is duplicated"); - } - } } - MMI_HILOGD("Number of pointer style:%{public}zu", pointerStyle_.size()); } @@ -676,7 +820,7 @@ void InputWindowsManager::AdjustDisplayCoordinate( { int32_t width = 0; int32_t height = 0; - if (displayInfo.direction == Direction0 || displayInfo.direction == Direction180) { + if (displayInfo.direction == DIRECTION0 || displayInfo.direction == DIRECTION180) { width = displayInfo.width; height = displayInfo.height; } else { @@ -722,26 +866,38 @@ bool InputWindowsManager::UpdateDisplayId(int32_t& displayId) std::optional InputWindowsManager::SelectWindowInfo(int32_t logicalX, int32_t logicalY, const std::shared_ptr& pointerEvent) { - CALL_DEBUG_ENTER; + CALL_INFO_TRACE; int32_t action = pointerEvent->GetPointerAction(); if ((firstBtnDownWindowId_ == -1) || ((action == PointerEvent::POINTER_ACTION_BUTTON_DOWN) && (pointerEvent->GetPressedButtons().size() == 1)) || - ((action == PointerEvent::POINTER_ACTION_MOVE) && (pointerEvent->GetPressedButtons().empty()))) { + ((action == PointerEvent::POINTER_ACTION_MOVE) && (pointerEvent->GetPressedButtons().empty())) || + (extraData_.appended && extraData_.sourceType == PointerEvent::SOURCE_TYPE_MOUSE)) { int32_t targetWindowId = pointerEvent->GetTargetWindowId(); for (const auto &item : displayGroupInfo_.windowsInfo) { if ((item.flags & WindowInfo::FLAG_BIT_UNTOUCHABLE) == WindowInfo::FLAG_BIT_UNTOUCHABLE) { - MMI_HILOGD("Skip the untouchable window to continue searching, " - "window:%{public}d, flags:%{public}d", item.id, item.flags); + MMI_HILOGI("Skip the untouchable window to continue searching, " + "window:%{public}d, flags:%{public}d, pid:%{public}d", item.id, item.flags, item.pid); continue; + } else if (extraData_.appended && extraData_.sourceType == PointerEvent::SOURCE_TYPE_MOUSE) { + if (IsInHotArea(logicalX, logicalY, item.pointerHotAreas)) { + firstBtnDownWindowId_ = item.id; + MMI_HILOGI("Mouse event select pull window, window:%{public}d, pid:%{public}d", + firstBtnDownWindowId_, item.pid); + break; + } else { + continue; + } } else if ((targetWindowId < 0) && (IsInHotArea(logicalX, logicalY, item.pointerHotAreas))) { firstBtnDownWindowId_ = item.id; - MMI_HILOGW("Find out the dispatch window of this pointer event when the targetWindowId " - "hasn't been setted up yet, window:%{public}d", firstBtnDownWindowId_); + MMI_HILOGI("Find out the dispatch window of this pointer event when the targetWindowId " + "hasn't been set up yet, window:%{public}d, pid:%{public}d", + firstBtnDownWindowId_, item.pid); break; } else if ((targetWindowId >= 0) && (targetWindowId == item.id)) { firstBtnDownWindowId_ = targetWindowId; - MMI_HILOGW("Find out the dispatch window of this pointer event when the targetWindowId " - "has been setted up already, window:%{public}d", firstBtnDownWindowId_); + MMI_HILOGI("Find out the dispatch window of this pointer event when the targetWindowId " + "has been set up already, window:%{public}d, pid:%{public}d", + firstBtnDownWindowId_, item.pid); break; } else { MMI_HILOGW("Continue searching for the dispatch window of this pointer event"); @@ -778,6 +934,7 @@ void InputWindowsManager::UpdatePointerEvent(int32_t logicalX, int32_t logicalY, const std::shared_ptr& pointerEvent, const WindowInfo& touchWindow) { CHKPV(pointerEvent); + MMI_HILOGD("LastWindowInfo:%{public}d, touchWindow:%{public}d", lastWindowInfo_.id, touchWindow.id); if (lastWindowInfo_.id != touchWindow.id) { DispatchPointer(PointerEvent::POINTER_ACTION_LEAVE_WINDOW); lastLogicX_ = logicalX; @@ -824,21 +981,32 @@ int32_t InputWindowsManager::UpdateMouseTarget(std::shared_ptr poi } auto touchWindow = SelectWindowInfo(logicalX, logicalY, pointerEvent); if (!touchWindow) { - MMI_HILOGE("touchWindow is nullptr, targetWindow:%{public}d", pointerEvent->GetTargetWindowId()); - return RET_ERR; + if (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_BUTTON_DOWN || mouseDownInfo_.id == -1) { + MMI_HILOGE("touchWindow is nullptr, targetWindow:%{public}d", pointerEvent->GetTargetWindowId()); + return RET_ERR; + } + touchWindow = std::make_optional(mouseDownInfo_); + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_CANCEL); + MMI_HILOGI("mouse event send cancel, window:%{public}d, pid:%{public}d", touchWindow->id, touchWindow->pid); } - int32_t mouseStyle = -1; - int32_t ret = GetPointerStyle(touchWindow->pid, touchWindow->id, mouseStyle); + PointerStyle pointerStyle; + int32_t ret = GetPointerStyle(touchWindow->pid, touchWindow->id, pointerStyle); if (ret != RET_OK) { MMI_HILOGE("Get pointer style failed, pointerStyleInfo is nullptr"); return ret; } + if (!IPointerDrawingManager::GetInstance()->GetMouseDisplayState()) { + IPointerDrawingManager::GetInstance()->SetMouseDisplayState(true); + DispatchPointer(PointerEvent::POINTER_ACTION_ENTER_WINDOW); + } IPointerDrawingManager::GetInstance()->UpdateDisplayInfo(*physicalDisplayInfo); WinInfo info = { .windowPid = touchWindow->pid, .windowId = touchWindow->id }; IPointerDrawingManager::GetInstance()->OnWindowInfo(info); IPointerDrawingManager::GetInstance()->DrawPointer(displayId, pointerItem.GetDisplayX(), - pointerItem.GetDisplayY(), MOUSE_ICON(mouseStyle)); - + pointerItem.GetDisplayY(), MOUSE_ICON(pointerStyle.id)); + if (captureModeInfo_.isCaptureMode && (touchWindow->id != captureModeInfo_.windowId)) { + captureModeInfo_.isCaptureMode = false; + } pointerEvent->SetTargetWindowId(touchWindow->id); pointerEvent->SetAgentWindowId(touchWindow->agentWindowId); int32_t windowX = logicalX - touchWindow->area.x; @@ -846,11 +1014,27 @@ int32_t InputWindowsManager::UpdateMouseTarget(std::shared_ptr poi pointerItem.SetWindowX(windowX); pointerItem.SetWindowY(windowY); pointerEvent->UpdatePointerItem(pointerId, pointerItem); + if (extraData_.appended && extraData_.sourceType == PointerEvent::SOURCE_TYPE_MOUSE) { + pointerEvent->SetBuffer(extraData_.buffer); + UpdatePointerAction(pointerEvent); + } else { + pointerEvent->ClearBuffer(); + } CHKPR(udsServer_, ERROR_NULL_POINTER); #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING UpdatePointerEvent(logicalX, logicalY, pointerEvent, *touchWindow); #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING - + int32_t action = pointerEvent->GetPointerAction(); + if (action == PointerEvent::POINTER_ACTION_BUTTON_DOWN) { + mouseDownInfo_ = *touchWindow; + } + if (action == PointerEvent::POINTER_ACTION_BUTTON_UP) { + InitMouseDownInfo(); + MMI_HILOGD("Mouse up, clear mouse down info"); + } + if (action == PointerEvent::POINTER_ACTION_PULL_UP) { + ClearExtraData(); + } MMI_HILOGD("pid:%{public}d,id:%{public}d,agentWindowId:%{public}d," "logicalX:%{public}d,logicalY:%{public}d," "displayX:%{public}d,displayY:%{public}d,windowX:%{public}d,windowY:%{public}d", @@ -860,6 +1044,27 @@ int32_t InputWindowsManager::UpdateMouseTarget(std::shared_ptr poi } #endif // OHOS_BUILD_ENABLE_POINTER +int32_t InputWindowsManager::SetMouseCaptureMode(int32_t windowId, bool isCaptureMode) +{ + if (windowId < 0) { + MMI_HILOGE("Windowid(%{public}d) is invalid", windowId); + return RET_ERR; + } + if ((captureModeInfo_.isCaptureMode == isCaptureMode) && !isCaptureMode) { + MMI_HILOGE("Windowid:(%{public}d) is not capture mode", windowId); + return RET_OK; + } + captureModeInfo_.windowId = windowId; + captureModeInfo_.isCaptureMode = isCaptureMode; + MMI_HILOGI("Windowid:(%{public}d) is (%{public}d)", windowId, isCaptureMode); + return RET_OK; +} + +bool InputWindowsManager::GetMouseIsCaptureMode() const +{ + return captureModeInfo_.isCaptureMode; +} + #ifdef OHOS_BUILD_ENABLE_TOUCH int32_t InputWindowsManager::UpdateTouchScreenTarget(std::shared_ptr pointerEvent) { @@ -902,6 +1107,15 @@ int32_t InputWindowsManager::UpdateTouchScreenTarget(std::shared_ptr= 0) { if (item.id == targetWindowId) { touchWindow = &item; @@ -913,9 +1127,16 @@ int32_t InputWindowsManager::UpdateTouchScreenTarget(std::shared_ptrGetPointerAction() == PointerEvent::POINTER_ACTION_DOWN) { + MMI_HILOGE("The touchWindow is nullptr, logicalX:%{public}d, logicalY:%{public}d", + logicalX, logicalY); + return RET_ERR; + } + touchWindow = &it->second; + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_CANCEL); + MMI_HILOGD("touch event send cancel, window:%{public}d", touchWindow->id); } auto windowX = logicalX - touchWindow->area.x; auto windowY = logicalY - touchWindow->area.y; @@ -929,13 +1150,132 @@ int32_t InputWindowsManager::UpdateTouchScreenTarget(std::shared_ptry - touchWindow->area.y); pointerItem.SetTargetWindowId(touchWindow->id); pointerEvent->UpdatePointerItem(pointerId, pointerItem); - MMI_HILOGD("pid:%{public}d,logicalX:%{public}d,logicalY:%{public}d," + if (extraData_.appended && extraData_.sourceType == PointerEvent::SOURCE_TYPE_TOUCHSCREEN && + extraData_.pointerId == pointerId) { + pointerEvent->SetBuffer(extraData_.buffer); + UpdatePointerAction(pointerEvent); + PullEnterLeaveEvent(logicalX, logicalY, pointerEvent, touchWindow); + } else { + pointerEvent->ClearBuffer(); + lastTouchEvent_ = nullptr; + lastTouchWindowInfo_.id = -1; + } + MMI_HILOGI("pid:%{public}d,logicalX:%{public}d,logicalY:%{public}d," "physicalX:%{public}d,physicalY:%{public}d,windowX:%{public}d,windowY:%{public}d," "displayId:%{public}d,TargetWindowId:%{public}d,AgentWindowId:%{public}d", touchWindow->pid, logicalX, logicalY, physicalX, physicalY, windowX, windowY, displayId, pointerEvent->GetTargetWindowId(), pointerEvent->GetAgentWindowId()); + if (IPointerDrawingManager::GetInstance()->GetMouseDisplayState()) { + DispatchPointer(PointerEvent::POINTER_ACTION_LEAVE_WINDOW); + IPointerDrawingManager::GetInstance()->SetMouseDisplayState(false); + } + + int32_t pointerAction = pointerEvent->GetPointerAction(); + if (pointerAction == PointerEvent::POINTER_ACTION_DOWN) { + touchItemDownInfos_.insert(std::make_pair(pointerId, *touchWindow)); + } + if (pointerAction == PointerEvent::POINTER_ACTION_UP) { + auto iter = touchItemDownInfos_.find(pointerId); + if (iter != touchItemDownInfos_.end()) { + touchItemDownInfos_.erase(iter); + MMI_HILOGD("Clear the touch info, action is up, pointerid:%{public}d", pointerId); + } + } + if (pointerAction == PointerEvent::POINTER_ACTION_PULL_UP) { + ClearExtraData(); + } return ERR_OK; } + +void InputWindowsManager::PullEnterLeaveEvent(int32_t logicalX, int32_t logicalY, + const std::shared_ptr pointerEvent, const WindowInfo* touchWindow) +{ + CHKPV(pointerEvent); + CHKPV(touchWindow); + MMI_HILOGD("LastTouchWindowInfo:%{public}d, touchWindow:%{public}d", lastTouchWindowInfo_.id, touchWindow->id); + if (lastTouchWindowInfo_.id != -1 && lastTouchWindowInfo_.id != touchWindow->id) { + DispatchTouch(PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW); + lastTouchLogicX_ = logicalX; + lastTouchLogicY_ = logicalY; + lastTouchEvent_ = pointerEvent; + lastTouchWindowInfo_ = *touchWindow; + DispatchTouch(PointerEvent::POINTER_ACTION_PULL_IN_WINDOW); + return; + } + lastTouchLogicX_ = logicalX; + lastTouchLogicY_ = logicalY; + lastTouchEvent_ = pointerEvent; + lastTouchWindowInfo_ = *touchWindow; +} + +void InputWindowsManager::DispatchTouch(int32_t pointerAction) +{ + CALL_INFO_TRACE; + CHKPV(udsServer_); + CHKPV(lastTouchEvent_); + if (pointerAction == PointerEvent::POINTER_ACTION_PULL_IN_WINDOW) { + WindowInfo *touchWindow = nullptr; + for (auto item : displayGroupInfo_.windowsInfo) { + if ((item.flags & WindowInfo::FLAG_BIT_UNTOUCHABLE) == WindowInfo::FLAG_BIT_UNTOUCHABLE) { + MMI_HILOGD("Skip the untouchable window to continue searching, " + "window:%{public}d, flags:%{public}d", item.id, item.flags); + continue; + } + if (IsInHotArea(lastTouchLogicX_, lastTouchLogicY_, item.defaultHotAreas)) { + touchWindow = &item; + break; + } + } + if (touchWindow == nullptr) { + MMI_HILOGE("touchWindow is nullptr"); + return; + } + if (touchWindow->id != lastTouchWindowInfo_.id) { + lastTouchWindowInfo_ = *touchWindow; + } + } + auto pointerEvent = PointerEvent::Create(); + CHKPV(pointerEvent); + PointerEvent::PointerItem lastPointerItem; + int32_t lastPointerId = lastTouchEvent_->GetPointerId(); + if (!lastTouchEvent_->GetPointerItem(lastPointerId, lastPointerItem)) { + MMI_HILOGE("GetPointerItem:%{public}d fail", lastPointerId); + return; + } + PointerEvent::PointerItem currentPointerItem; + currentPointerItem.SetWindowX(lastTouchLogicX_ - lastTouchWindowInfo_.area.x); + currentPointerItem.SetWindowY(lastTouchLogicY_ - lastTouchWindowInfo_.area.y); + currentPointerItem.SetDisplayX(lastPointerItem.GetDisplayX()); + currentPointerItem.SetDisplayY(lastPointerItem.GetDisplayY()); + currentPointerItem.SetPointerId(lastPointerId); + + pointerEvent->UpdateId(); + pointerEvent->SetTargetDisplayId(lastTouchEvent_->GetTargetDisplayId()); + pointerEvent->SetTargetWindowId(lastTouchWindowInfo_.id); + pointerEvent->SetAgentWindowId(lastTouchWindowInfo_.agentWindowId); + pointerEvent->SetPointerId(lastPointerId); + pointerEvent->AddPointerItem(currentPointerItem); + pointerEvent->SetPointerAction(pointerAction); + pointerEvent->SetBuffer(extraData_.buffer); + pointerEvent->SetSourceType(lastTouchEvent_->GetSourceType()); + int64_t time = GetSysClockTime(); + pointerEvent->SetActionTime(time); + pointerEvent->SetActionStartTime(time); + pointerEvent->SetDeviceId(lastTouchEvent_->GetDeviceId()); + auto fd = udsServer_->GetClientFd(lastTouchWindowInfo_.pid); + auto sess = udsServer_->GetSession(fd); + if (sess == nullptr) { + MMI_HILOGI("The last window has disappeared"); + return; + } + + NetPacket pkt(MmiMessageId::ON_POINTER_EVENT); + InputEventDataTransformation::Marshalling(pointerEvent, pkt); + if (!sess->SendMsg(pkt)) { + MMI_HILOGE("Send message failed, errCode:%{public}d", MSG_SEND_FAIL); + return; + } +} #endif // OHOS_BUILD_ENABLE_TOUCH #ifdef OHOS_BUILD_ENABLE_POINTER @@ -1058,7 +1398,7 @@ void InputWindowsManager::UpdateAndAdjustMouseLocation(int32_t& displayId, doubl } int32_t width = 0; int32_t height = 0; - if (displayInfo->direction == Direction0 || displayInfo->direction == Direction180) { + if (displayInfo->direction == DIRECTION0 || displayInfo->direction == DIRECTION180) { width = displayInfo->width; height = displayInfo->height; } else { @@ -1097,6 +1437,54 @@ MouseLocation InputWindowsManager::GetMouseInfo() } #endif // OHOS_BUILD_ENABLE_POINTER +int32_t InputWindowsManager::AppendExtraData(const ExtraData& extraData) +{ + CALL_DEBUG_ENTER; + extraData_.appended = extraData.appended; + extraData_.buffer = extraData.buffer; + extraData_.sourceType = extraData.sourceType; + extraData_.pointerId = extraData.pointerId; + return RET_OK; +} + +void InputWindowsManager::ClearExtraData() +{ + CALL_DEBUG_ENTER; + extraData_.appended = false; + extraData_.buffer.clear(); + extraData_.sourceType = -1; + extraData_.pointerId = -1; +} + +void InputWindowsManager::UpdatePointerAction(std::shared_ptr pointerEvent) +{ + CALL_DEBUG_ENTER; + int32_t action = pointerEvent->GetPointerAction(); + switch (action) { + case PointerEvent::POINTER_ACTION_MOVE: { + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_PULL_MOVE); + break; + } + case PointerEvent::POINTER_ACTION_BUTTON_UP: + case PointerEvent::POINTER_ACTION_UP: { + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_PULL_UP); + break; + } + case PointerEvent::POINTER_ACTION_ENTER_WINDOW: { + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_PULL_IN_WINDOW); + break; + } + case PointerEvent::POINTER_ACTION_LEAVE_WINDOW: { + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW); + break; + } + default: { + MMI_HILOGI("Action is:%{public}d, no need change", action); + break; + } + } +} + void InputWindowsManager::Dump(int32_t fd, const std::vector &args) { CALL_DEBUG_ENTER; @@ -1130,6 +1518,7 @@ void InputWindowsManager::Dump(int32_t fd, const std::vector &args) item.id, item.x, item.y, item.width, item.height, item.name.c_str(), item.uniq.c_str(), item.direction); } + mprintf(fd, "Input device and display bind info:\n%s\n", bindInfo_.Dumps().c_str()); } } // namespace MMI -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/service/window_manager/src/pointer_drawing_manager.cpp b/service/window_manager/src/pointer_drawing_manager.cpp index 9800cdbca8ab604a32fc15798bce667c1914148f..403999119943ff135196768e6318461a981a69b4 100644 --- a/service/window_manager/src/pointer_drawing_manager.cpp +++ b/service/window_manager/src/pointer_drawing_manager.cpp @@ -23,6 +23,7 @@ #include "define_multimodal.h" #include "input_device_manager.h" +#include "input_windows_manager.h" #include "mmi_log.h" #include "util.h" @@ -31,14 +32,8 @@ namespace MMI { namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "PointerDrawingManager" }; const std::string IMAGE_POINTER_DEFAULT_PATH = "/system/etc/multimodalinput/mouse_icon/"; -constexpr int32_t PAD_SCREEN_WIDTH = 2560; -constexpr int32_t PHONE_SCREEN_WIDTH = 2160; -constexpr int32_t SMALL_ICON_WIDTH = 40; -constexpr int32_t SMALL_ICON_HEIGHT = 40; -constexpr int32_t MIDDLE_ICON_WIDTH = 60; -constexpr int32_t MIDDLE_ICON_HEIGHT = 60; -constexpr int32_t LARGE_ICON_WIDTH = 80; -constexpr int32_t LARGE_ICON_HEIGHT = 80; +constexpr int32_t BASELINE_DENSITY = 160; +constexpr int32_t DEVICE_INDEPENDENT_PIXELS = 40; } // namespace } // namespace MMI } // namespace OHOS @@ -63,16 +58,18 @@ void PointerDrawingManager::DrawPointer(int32_t displayId, int32_t physicalX, in AdjustMouseFocus(ICON_TYPE(mouseIcons_[mouseStyle].alignmentWay), physicalX, physicalY); if (pointerWindow_ != nullptr) { pointerWindow_->MoveTo(physicalX + displayInfo_.x, physicalY + displayInfo_.y); - if (lastMouseStyle_ == mouseStyle) { + MMI_HILOGD("Pointer window move success"); + if (lastMouseStyle_.id == mouseStyle) { MMI_HILOGD("The lastMouseStyle is equal with mouseStyle"); return; } - lastMouseStyle_ = mouseStyle; + lastMouseStyle_.id = mouseStyle; int32_t ret = InitLayer(mouseStyle); if (ret != RET_OK) { MMI_HILOGE("Init layer failed"); return; } + UpdatePointerVisible(); MMI_HILOGD("Leave, display:%{public}d,physicalX:%{public}d,physicalY:%{public}d", displayId, physicalX, physicalY); return; @@ -85,7 +82,7 @@ void PointerDrawingManager::DrawPointer(int32_t displayId, int32_t physicalX, in MMI_HILOGE("Init layer failed"); return; } - + UpdatePointerVisible(); MMI_HILOGD("Leave, display:%{public}d,physicalX:%{public}d,physicalY:%{public}d", displayId, physicalX, physicalY); } @@ -93,20 +90,25 @@ void PointerDrawingManager::DrawPointer(int32_t displayId, int32_t physicalX, in int32_t PointerDrawingManager::InitLayer(const MOUSE_ICON mouseStyle) { CALL_DEBUG_ENTER; - CHKPR(pointerWindow_, RET_ERR); + if (pointerWindow_ == nullptr) { + MMI_HILOGD("pointerWindow_ is nullptr"); + return RET_ERR; + } sptr layer = GetLayer(); if (layer == nullptr) { + MMI_HILOGE("Init layer is failed, Layer is nullptr"); pointerWindow_->Destroy(); pointerWindow_ = nullptr; - MMI_HILOGE("Init layer is failed, Layer is nullptr"); + MMI_HILOGD("Pointer window destroy success"); return RET_ERR; } sptr buffer = GetSurfaceBuffer(layer); if (buffer == nullptr || buffer->GetVirAddr() == nullptr) { + MMI_HILOGE("Init layer is failed, buffer or virAddr is nullptr"); pointerWindow_->Destroy(); pointerWindow_ = nullptr; - MMI_HILOGE("Init layer is failed, buffer or virAddr is nullptr"); + MMI_HILOGD("Pointer window destroy success"); return RET_ERR; } @@ -124,7 +126,6 @@ int32_t PointerDrawingManager::InitLayer(const MOUSE_ICON mouseStyle) return RET_ERR; } MMI_HILOGD("Init layer success"); - UpdatePointerVisible(); return RET_OK; } @@ -149,6 +150,24 @@ void PointerDrawingManager::AdjustMouseFocus(ICON_TYPE iconType, int32_t &physic } } + +void PointerDrawingManager::SetMouseDisplayState(bool state) +{ + CALL_DEBUG_ENTER; + if (mouseDisplayState_ != state) { + mouseDisplayState_ = state; + if (mouseDisplayState_) { + InitLayer(MOUSE_ICON(lastMouseStyle_.id)); + } + UpdatePointerVisible(); + } +} + +bool PointerDrawingManager::GetMouseDisplayState() const +{ + return mouseDisplayState_; +} + void PointerDrawingManager::FixCursorPosition(int32_t &physicalX, int32_t &physicalY) { if (physicalX < 0) { @@ -159,7 +178,7 @@ void PointerDrawingManager::FixCursorPosition(int32_t &physicalX, int32_t &physi physicalY = 0; } const int32_t cursorUnit = 16; - if (displayInfo_.direction == Direction0 || displayInfo_.direction == Direction180) { + if (displayInfo_.direction == DIRECTION0 || displayInfo_.direction == DIRECTION180) { if (physicalX > (displayInfo_.width - imageWidth_ / cursorUnit)) { physicalX = displayInfo_.width - imageWidth_ / cursorUnit; } @@ -178,6 +197,7 @@ void PointerDrawingManager::FixCursorPosition(int32_t &physicalX, int32_t &physi void PointerDrawingManager::CreatePointerWindow(int32_t displayId, int32_t physicalX, int32_t physicalY) { + CALL_INFO_TRACE; sptr option = new (std::nothrow) OHOS::Rosen::WindowOption(); CHKPV(option); option->SetWindowType(OHOS::Rosen::WindowType::WINDOW_TYPE_POINTER); @@ -198,11 +218,13 @@ void PointerDrawingManager::CreatePointerWindow(int32_t displayId, int32_t physi sptr PointerDrawingManager::GetLayer() { + CALL_DEBUG_ENTER; std::shared_ptr surfaceNode = pointerWindow_->GetSurfaceNode(); if (surfaceNode == nullptr) { MMI_HILOGE("Draw pointer is failed, get node is nullptr"); pointerWindow_->Destroy(); pointerWindow_ = nullptr; + MMI_HILOGD("Pointer window destroy success"); return nullptr; } return surfaceNode->GetSurface(); @@ -210,6 +232,7 @@ sptr PointerDrawingManager::GetLayer() sptr PointerDrawingManager::GetSurfaceBuffer(sptr layer) const { + CALL_DEBUG_ENTER; sptr buffer; int32_t releaseFence = 0; OHOS::BufferRequestConfig config = { @@ -264,6 +287,7 @@ void PointerDrawingManager::DrawPixelmap(OHOS::Rosen::Drawing::Canvas &canvas, c std::unique_ptr PointerDrawingManager::DecodeImageToPixelMap(const std::string &imagePath) { + CALL_DEBUG_ENTER; OHOS::Media::SourceOptions opts; opts.formatHint = "image/png"; uint32_t ret = 0; @@ -291,19 +315,8 @@ void PointerDrawingManager::UpdateDisplayInfo(const DisplayInfo& displayInfo) CALL_DEBUG_ENTER; hasDisplay_ = true; displayInfo_ = displayInfo; - - if ((displayInfo_.width >= PHONE_SCREEN_WIDTH) || (displayInfo_.height >= PHONE_SCREEN_WIDTH)) { - if ((displayInfo_.width == PAD_SCREEN_WIDTH) || (displayInfo_.height == PAD_SCREEN_WIDTH)) { - imageWidth_ = MIDDLE_ICON_WIDTH; - imageHeight_ = MIDDLE_ICON_HEIGHT; - } else { - imageWidth_ = LARGE_ICON_WIDTH; - imageHeight_ = LARGE_ICON_HEIGHT; - } - } else { - imageWidth_ = SMALL_ICON_WIDTH; - imageHeight_ = SMALL_ICON_HEIGHT; - } + imageWidth_ = displayInfo.dpi * DEVICE_INDEPENDENT_PIXELS / BASELINE_DENSITY; + imageHeight_ = displayInfo.dpi * DEVICE_INDEPENDENT_PIXELS / BASELINE_DENSITY; } void PointerDrawingManager::OnDisplayInfo(const DisplayGroupInfo& displayGroupInfo) @@ -323,6 +336,7 @@ void PointerDrawingManager::OnDisplayInfo(const DisplayGroupInfo& displayGroupIn if (pointerWindow_ != nullptr) { pointerWindow_->Destroy(); pointerWindow_ = nullptr; + MMI_HILOGD("Pointer window destroy success"); } MMI_HILOGD("displayId_:%{public}d, displayWidth_:%{public}d, displayHeight_:%{public}d", displayInfo_.id, displayInfo_.width, displayInfo_.height); @@ -339,7 +353,11 @@ void PointerDrawingManager::UpdatePointerDevice(bool hasPointerDevice, bool isPo { CALL_DEBUG_ENTER; hasPointerDevice_ = hasPointerDevice; - SetPointerVisible(getpid(), isPointerVisible); + if (hasPointerDevice_) { + SetPointerVisible(getpid(), isPointerVisible); + } else { + DeletePointerVisible(getpid()); + } DrawManager(); } @@ -347,25 +365,26 @@ void PointerDrawingManager::DrawManager() { if (hasDisplay_ && hasPointerDevice_ && pointerWindow_ == nullptr) { MMI_HILOGD("Draw pointer begin"); - int32_t mouseStyle = -1; - int32_t ret = WinMgr->GetPointerStyle(pid_, windowId_, mouseStyle); + PointerStyle pointerStyle; + int32_t ret = WinMgr->GetPointerStyle(pid_, windowId_, pointerStyle); if (ret != RET_OK) { MMI_HILOGE("Get pointer style failed, pointerStyleInfo is nullptr"); return; } if (lastPhysicalX_ == -1 || lastPhysicalY_ == -1) { - DrawPointer(displayInfo_.id, displayInfo_.width / 2, displayInfo_.height / 2, MOUSE_ICON(mouseStyle)); - MMI_HILOGD("Draw manager, mouseStyle:%{public}d, last physical is initial value", mouseStyle); + DrawPointer(displayInfo_.id, displayInfo_.width / 2, displayInfo_.height / 2, MOUSE_ICON(pointerStyle.id)); + MMI_HILOGD("Draw manager, mouseStyle:%{public}d, last physical is initial value", pointerStyle.id); return; } - DrawPointer(displayInfo_.id, lastPhysicalX_, lastPhysicalY_, MOUSE_ICON(mouseStyle)); - MMI_HILOGD("Draw manager, mouseStyle:%{public}d", mouseStyle); + DrawPointer(displayInfo_.id, lastPhysicalX_, lastPhysicalY_, MOUSE_ICON(pointerStyle.id)); + MMI_HILOGD("Draw manager, mouseStyle:%{public}d", pointerStyle.id); return; } if (!hasPointerDevice_ && pointerWindow_ != nullptr) { - MMI_HILOGD("Destroy draw pointer"); + MMI_HILOGD("Pointer window destroy start"); pointerWindow_->Destroy(); pointerWindow_ = nullptr; + MMI_HILOGD("Pointer window destroy success"); } } @@ -385,38 +404,16 @@ std::shared_ptr IPointerDrawingManager::GetInstance() return iPointDrawMgr_; } -void PointerDrawingManager::DeletePidInfo(int32_t pid) -{ - CALL_DEBUG_ENTER; - for (auto it = pidInfos_.begin(); it != pidInfos_.end(); ++it) { - if (it->pid == pid) { - pidInfos_.erase(it); - return; - } - } -} - -void PointerDrawingManager::UpdatePidInfo(int32_t pid, bool visible) -{ - CALL_DEBUG_ENTER; - for (auto it = pidInfos_.begin(); it != pidInfos_.end(); ++it) { - if (it->pid == pid) { - pidInfos_.erase(it); - break; - } - } - PidInfo info = { .pid = pid, .visible = visible }; - pidInfos_.push_back(info); -} - void PointerDrawingManager::UpdatePointerVisible() { CALL_DEBUG_ENTER; CHKPV(pointerWindow_); - if (IsPointerVisible()) { + if (IsPointerVisible() && mouseDisplayState_) { pointerWindow_->Show(); + MMI_HILOGD("Pointer window show success"); } else { pointerWindow_->Hide(); + MMI_HILOGD("Pointer window hide success"); } } @@ -435,15 +432,36 @@ bool PointerDrawingManager::IsPointerVisible() void PointerDrawingManager::DeletePointerVisible(int32_t pid) { CALL_DEBUG_ENTER; - DeletePidInfo(pid); - UpdatePointerVisible(); + auto it = pidInfos_.begin(); + for (; it != pidInfos_.end(); ++it) { + if (it->pid == pid) { + pidInfos_.erase(it); + break; + } + } + if (it != pidInfos_.end()) { + if (IsPointerVisible()) { + InitLayer(MOUSE_ICON(lastMouseStyle_.id)); + } + UpdatePointerVisible(); + } } int32_t PointerDrawingManager::SetPointerVisible(int32_t pid, bool visible) { CALL_DEBUG_ENTER; - UpdatePidInfo(pid, visible); - InitLayer(MOUSE_ICON(lastMouseStyle_)); + for (auto it = pidInfos_.begin(); it != pidInfos_.end(); ++it) { + if (it->pid == pid) { + pidInfos_.erase(it); + break; + } + } + PidInfo info = { .pid = pid, .visible = visible }; + pidInfos_.push_back(info); + if (visible) { + InitLayer(MOUSE_ICON(lastMouseStyle_.id)); + } + UpdatePointerVisible(); return RET_OK; } @@ -455,14 +473,15 @@ void PointerDrawingManager::SetPointerLocation(int32_t pid, int32_t x, int32_t y lastPhysicalY_ = y; if (pointerWindow_ != nullptr) { pointerWindow_->MoveTo(x, y); + MMI_HILOGD("Pointer window move success"); SetPointerVisible(pid, true); } } -int32_t PointerDrawingManager::SetPointerStyle(int32_t pid, int32_t windowId, int32_t pointerStyle) +int32_t PointerDrawingManager::SetPointerStyle(int32_t pid, int32_t windowId, PointerStyle pointerStyle) { CALL_DEBUG_ENTER; - auto it = mouseIcons_.find(MOUSE_ICON(pointerStyle)); + auto it = mouseIcons_.find(MOUSE_ICON(pointerStyle.id)); if (it == mouseIcons_.end()) { MMI_HILOGE("The param pointerStyle is invalid"); return RET_ERR; @@ -480,28 +499,32 @@ int32_t PointerDrawingManager::SetPointerStyle(int32_t pid, int32_t windowId, in } if (!WinMgr->IsNeedRefreshLayer(windowId)) { - MMI_HILOGD("Not need refresh layer, window type:%{public}d, pointer style:%{public}d", windowId, pointerStyle); + MMI_HILOGD("Not need refresh layer, window type:%{public}d, pointer style:%{public}d", + windowId, pointerStyle.id); return RET_OK; } if (pointerWindow_ != nullptr) { int32_t physicalX = lastPhysicalX_; int32_t physicalY = lastPhysicalY_; - AdjustMouseFocus(ICON_TYPE(mouseIcons_[MOUSE_ICON(pointerStyle)].alignmentWay), physicalX, physicalY); + AdjustMouseFocus(ICON_TYPE(mouseIcons_[MOUSE_ICON(pointerStyle.id)].alignmentWay), physicalX, physicalY); + MMI_HILOGD("Pointer window move start"); pointerWindow_->MoveTo(physicalX + displayInfo_.x, physicalY + displayInfo_.y); + MMI_HILOGD("Pointer window move success"); lastMouseStyle_ = pointerStyle; - int32_t ret = InitLayer(MOUSE_ICON(pointerStyle)); + int32_t ret = InitLayer(MOUSE_ICON(pointerStyle.id)); if (ret != RET_OK) { MMI_HILOGE("Init layer failed"); return RET_ERR; } + UpdatePointerVisible(); } - MMI_HILOGD("Window id:%{public}d set pointer style:%{public}d success", windowId, pointerStyle); + MMI_HILOGD("Window id:%{public}d set pointer style:%{public}d success", windowId, pointerStyle.id); return RET_OK; } -int32_t PointerDrawingManager::GetPointerStyle(int32_t pid, int32_t windowId, int32_t &pointerStyle) +int32_t PointerDrawingManager::GetPointerStyle(int32_t pid, int32_t windowId, PointerStyle &pointerStyle) { CALL_DEBUG_ENTER; int32_t ret = WinMgr->GetPointerStyle(pid, windowId, pointerStyle); @@ -509,7 +532,7 @@ int32_t PointerDrawingManager::GetPointerStyle(int32_t pid, int32_t windowId, in MMI_HILOGE("Get pointer style failed, pointerStyleInfo is nullptr"); return ret; } - MMI_HILOGD("Window id:%{public}d get pointer style:%{public}d success", windowId, pointerStyle); + MMI_HILOGD("Window id:%{public}d get pointer style:%{public}d success", windowId, pointerStyle.id); return RET_OK; } @@ -517,20 +540,20 @@ void PointerDrawingManager::DrawPointerStyle() { CALL_DEBUG_ENTER; if (hasDisplay_ && hasPointerDevice_) { - int32_t mouseStyle = -1; - int32_t ret = WinMgr->GetPointerStyle(pid_, windowId_, mouseStyle); + PointerStyle pointerStyle; + int32_t ret = WinMgr->GetPointerStyle(pid_, windowId_, pointerStyle); if (ret != RET_OK) { MMI_HILOGE("Draw pointer style failed, pointerStyleInfo is nullptr"); return; } if (lastPhysicalX_ == -1 || lastPhysicalY_ == -1) { - DrawPointer(displayInfo_.id, displayInfo_.width / 2, displayInfo_.height / 2, MOUSE_ICON(mouseStyle)); - MMI_HILOGD("Draw pointer style, mouseStyle:%{public}d", mouseStyle); + DrawPointer(displayInfo_.id, displayInfo_.width / 2, displayInfo_.height / 2, MOUSE_ICON(pointerStyle.id)); + MMI_HILOGD("Draw pointer style, mouseStyle:%{public}d", pointerStyle.id); return; } - DrawPointer(displayInfo_.id, lastPhysicalX_, lastPhysicalY_, MOUSE_ICON(mouseStyle)); - MMI_HILOGD("Draw pointer style, mouseStyle:%{public}d", mouseStyle); + DrawPointer(displayInfo_.id, lastPhysicalX_, lastPhysicalY_, MOUSE_ICON(pointerStyle.id)); + MMI_HILOGD("Draw pointer style, mouseStyle:%{public}d", pointerStyle.id); } } diff --git a/service/window_manager/test/input_display_bind_helper_test.cpp b/service/window_manager/test/input_display_bind_helper_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f076d6f237ae6b5110965ea73e375332fa7630dc --- /dev/null +++ b/service/window_manager/test/input_display_bind_helper_test.cpp @@ -0,0 +1,250 @@ +/* + * 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. + */ + +#include "gtest/gtest.h" + +#include + +#include "input_display_bind_helper.h" +#include "mmi_log.h" + +namespace OHOS { +namespace MMI { +namespace { +using namespace testing::ext; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "InputDisplayBindHelperTest" }; +} // namespace +class InputDisplayBindHelperTest : public testing::Test { +public: + static void SetUpTestCase(void) {} + static void TearDownTestCase(void) {} + static bool WriteConfigFile(const std::string &content); + static inline const std::string bindCfgFile_ = "input_display_bind_helper.cfg"; + static std::string GetCfgFileName() { return bindCfgFile_; } +}; + +bool InputDisplayBindHelperTest::WriteConfigFile(const std::string &content) +{ + const std::string &fileName = InputDisplayBindHelperTest::bindCfgFile_; + std::ofstream ofs(fileName.c_str()); + if (!ofs) { + MMI_HILOGE("Open file fail.%s\n", fileName.c_str()); + return false; + } + ofs << content; + ofs.close(); + return true; +} + +/** + * @tc.name: InputDisplayBindHelperTest_001 + * @tc.desc: No bind info in disk + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_001, TestSize.Level1) +{ + InputDisplayBindHelperTest::WriteConfigFile(""); + InputDisplayBindHelper bindInfo(InputDisplayBindHelperTest::GetCfgFileName()); + // 多模初始化 + bindInfo.Load(); + // 检测到触摸板设备 + bindInfo.AddInputDevice(1, "mouse"); + bindInfo.AddInputDevice(2, "keyboard"); + // 窗口同步信息 + bindInfo.AddDisplay(0, "hp 223"); + bindInfo.AddDisplay(2, "think 123"); + ASSERT_EQ(bindInfo.Dumps(), std::string("mouse<=>hp 223\nkeyboard<=>think 123\n")); +} + +/** + * @tc.name: InputDisplayBindHelperTest_002 + * @tc.desc: Has info with adding order in disk + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_002, TestSize.Level1) +{ + InputDisplayBindHelperTest::WriteConfigFile("mouse<=>hp 223\nkeyboard<=>think 123\n"); + InputDisplayBindHelper bindInfo(InputDisplayBindHelperTest::GetCfgFileName()); + // 多模初始化 + bindInfo.Load(); + // 检测到触摸板设备 + bindInfo.AddInputDevice(1, "mouse"); + bindInfo.AddInputDevice(2, "keyboard"); + // 窗口同步信息 + bindInfo.AddDisplay(0, "hp 223"); + bindInfo.AddDisplay(2, "think 123"); + ASSERT_EQ(bindInfo.Dumps(), std::string("mouse<=>hp 223\nkeyboard<=>think 123\n")); +} + +/** + * @tc.name: InputDisplayBindHelperTest_003 + * @tc.desc: Has info without adding order in disk + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_003, TestSize.Level1) +{ + InputDisplayBindHelperTest::WriteConfigFile("mouse<=>think 123\nkeyboard<=>hp 223\n"); + InputDisplayBindHelper bindInfo(InputDisplayBindHelperTest::GetCfgFileName()); + // 多模初始化 + bindInfo.Load(); + // 检测到触摸板设备 + bindInfo.AddInputDevice(1, "mouse"); + bindInfo.AddInputDevice(2, "keyboard"); + // 窗口同步信息 + bindInfo.AddDisplay(0, "hp 223"); + bindInfo.AddDisplay(2, "think 123"); + ASSERT_EQ(bindInfo.Dumps(), std::string("mouse<=>think 123\nkeyboard<=>hp 223\n")); +} + +/** + * @tc.name: InputDisplayBindHelperTest_004 + * @tc.desc: Bind and remove test + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_004, TestSize.Level1) +{ + InputDisplayBindHelperTest::WriteConfigFile(""); + InputDisplayBindHelper bindInfo(InputDisplayBindHelperTest::GetCfgFileName()); + // 多模初始化 + bindInfo.Load(); + // 检测到触摸板设备 + bindInfo.AddInputDevice(1, "mouse"); + bindInfo.AddInputDevice(2, "keyboard"); + // 窗口同步信息 + bindInfo.AddDisplay(0, "hp 223"); + bindInfo.AddDisplay(2, "think 123"); + // 显示屏移除 + bindInfo.RemoveDisplay(2); + bindInfo.RemoveDisplay(0); + // 输入设备移除 + bindInfo.RemoveInputDevice(1); + bindInfo.RemoveInputDevice(2); + bindInfo.RemoveInputDevice(3); + // 窗口同步信息 + bindInfo.AddDisplay(0, "hp 223"); + bindInfo.AddDisplay(2, "think 123"); + // 检测到触摸板设备 + bindInfo.AddInputDevice(1, "mouse"); + bindInfo.AddInputDevice(2, "keyboard"); + bindInfo.AddInputDevice(3, "keyboard88"); + + bindInfo.Store(); + bindInfo.Load(); + bindInfo.Dumps(); + // 输入设备移除 + bindInfo.RemoveInputDevice(1); + bindInfo.RemoveInputDevice(2); + // 触摸板设备移除 + bindInfo.RemoveDisplay(2); + bindInfo.RemoveDisplay(0); + ASSERT_EQ(bindInfo.Dumps(), std::string("")); +} + +/** + * @tc.name: InputDisplayBindHelperTest_005 + * @tc.desc: Test GetBindDisplayNameByInputDevice + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetBindDisplayNameByInputDevice_005, TestSize.Level1) +{ + InputDisplayBindHelperTest::WriteConfigFile("mouse<=>think 123\nkeyboard<=>hp 223\n"); + InputDisplayBindHelper bindInfo(InputDisplayBindHelperTest::GetCfgFileName()); + // 多模初始化 + bindInfo.Load(); + // 检测到触摸板设备 + bindInfo.AddInputDevice(1, "mouse"); + bindInfo.AddInputDevice(2, "keyboard"); + // 窗口同步信息 + bindInfo.AddDisplay(0, "hp 223"); + bindInfo.AddDisplay(2, "think 123"); + ASSERT_EQ(bindInfo.Dumps(), std::string("mouse<=>think 123\nkeyboard<=>hp 223\n")); + // 获取 + ASSERT_EQ(bindInfo.GetBindDisplayNameByInputDevice(1), std::string("think 123")); + ASSERT_EQ(bindInfo.GetBindDisplayNameByInputDevice(2), std::string("hp 223")); + ASSERT_EQ(bindInfo.GetBindDisplayNameByInputDevice(3), std::string()); + // 删除display + bindInfo.RemoveDisplay(0); + ASSERT_EQ(bindInfo.GetBindDisplayNameByInputDevice(1), std::string("think 123")); + ASSERT_EQ(bindInfo.GetBindDisplayNameByInputDevice(2), std::string()); + bindInfo.RemoveDisplay(2); + ASSERT_EQ(bindInfo.GetBindDisplayNameByInputDevice(1), std::string()); + ASSERT_EQ(bindInfo.GetBindDisplayNameByInputDevice(2), std::string()); +} + +/** + * @tc.name: InputDisplayBindHelperTest_IsDisplayAdd_006 + * @tc.desc: Test GetBindDisplayNameByInputDevice + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_IsDisplayAdd_006, TestSize.Level1) +{ + InputDisplayBindHelperTest::WriteConfigFile("mouse<=>think 123\nkeyboard<=>hp 223\n"); + InputDisplayBindHelper bindInfo(InputDisplayBindHelperTest::GetCfgFileName()); + // 多模初始化 + bindInfo.Load(); + ASSERT_FALSE(bindInfo.IsDisplayAdd(0, "hp 223")); + ASSERT_FALSE(bindInfo.IsDisplayAdd(2, "think 123")); + ASSERT_FALSE(bindInfo.IsDisplayAdd(1, "think 123")); + // 窗口同步信息 + bindInfo.AddDisplay(0, "hp 223"); + bindInfo.AddDisplay(2, "think 123"); + ASSERT_EQ(bindInfo.Dumps(), std::string()); + ASSERT_TRUE(bindInfo.IsDisplayAdd(0, "hp 223")); + ASSERT_TRUE(bindInfo.IsDisplayAdd(2, "think 123")); + ASSERT_FALSE(bindInfo.IsDisplayAdd(1, "think 123")); + // 检测到触摸板设备 + bindInfo.AddInputDevice(1, "mouse"); + bindInfo.AddInputDevice(2, "keyboard"); + ASSERT_EQ(bindInfo.Dumps(), std::string("mouse<=>think 123\nkeyboard<=>hp 223\n")); +} + +/** + * @tc.name: InputDisplayBindHelperTest_GetDisplayIdNames_007 + * @tc.desc: Test GetBindDisplayNameByInputDevice + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputDisplayBindHelperTest, InputDisplayBindHelperTest_GetDisplayIdNames_007, TestSize.Level1) +{ + using IdNames = std::set>; + InputDisplayBindHelperTest::WriteConfigFile("mouse<=>think 123\nkeyboard<=>hp 223\n"); + InputDisplayBindHelper bindInfo(InputDisplayBindHelperTest::GetCfgFileName()); + // 多模初始化 + bindInfo.Load(); + IdNames idNames; + ASSERT_EQ(bindInfo.GetDisplayIdNames(), idNames); + // 窗口同步信息 + bindInfo.AddDisplay(0, "hp 223"); + idNames.insert(std::make_pair(0, "hp 223")); + ASSERT_EQ(bindInfo.GetDisplayIdNames(), idNames); + bindInfo.AddDisplay(2, "think 123"); + idNames.insert(std::make_pair(2, "think 123")); + ASSERT_EQ(bindInfo.GetDisplayIdNames(), idNames); + ASSERT_EQ(bindInfo.Dumps(), std::string()); + // 检测到触摸板设备 + bindInfo.AddInputDevice(1, "mouse"); + bindInfo.AddInputDevice(2, "keyboard"); + idNames.insert(std::make_pair(2, "think 123")); + ASSERT_EQ(bindInfo.GetDisplayIdNames(), idNames); + ASSERT_EQ(bindInfo.Dumps(), std::string("mouse<=>think 123\nkeyboard<=>hp 223\n")); +} +} //namespace MMI +} // namespace OHOS \ No newline at end of file diff --git a/service/window_manager/test/input_windows_manager_test.cpp b/service/window_manager/test/input_windows_manager_test.cpp index 766ff93e2f6b889ed7243d4c31a61ede307446cf..2ebb5e54c42b8081947c3872b978d57ff1a80d09 100644 --- a/service/window_manager/test/input_windows_manager_test.cpp +++ b/service/window_manager/test/input_windows_manager_test.cpp @@ -21,7 +21,6 @@ namespace OHOS { namespace MMI { namespace { using namespace testing::ext; -using namespace OHOS::MMI; } // namespace class InputWindowsManagerTest : public testing::Test { diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 5f004007b0a97f11bd2a4197feaa85e4f4a8da75..5f71cdccc3628ac8913999052fa2ab5d412a7158 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -20,9 +20,12 @@ group("test") { "addinputeventfilter_fuzzer:fuzztest", "addinterceptor_fuzzer:fuzztest", "addmonitor_fuzzer:fuzztest", + "functionkeystate_fuzzer:fuzztest", "getkeyboardtype_fuzzer:fuzztest", "markconsumed_fuzzer:fuzztest", "movemouse_fuzzer:fuzztest", + "pointerspeed_fuzzer:fuzztest", + "pointerstyle_fuzzer:fuzztest", "pointervisible_fuzzer:fuzztest", "simulateinputevent_fuzzer:fuzztest", "subscribekeyevent_fuzzer:fuzztest", diff --git a/test/fuzztest/addinputeventfilter_fuzzer/addinputeventfilter_fuzzer.cpp b/test/fuzztest/addinputeventfilter_fuzzer/addinputeventfilter_fuzzer.cpp index 18ed15b5777a1a51d7b2edba54e0a627bf2389d1..1ea5934933a66829e3c8447030b09c83760c55ca 100644 --- a/test/fuzztest/addinputeventfilter_fuzzer/addinputeventfilter_fuzzer.cpp +++ b/test/fuzztest/addinputeventfilter_fuzzer/addinputeventfilter_fuzzer.cpp @@ -25,13 +25,38 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "AddInputEventFilterFuzzTest" }; } // namespace -void AddInputEventFilterFuzzTest(const uint8_t* data, size_t /* size */) +void AddInputEventFilterFuzzTest(const uint8_t* data, size_t size) { - auto fun = [](std::shared_ptr event) ->bool { - MMI_HILOGD("Add inputevent filter success"); - return false; + struct TestFilter : public IInputEventFilter { + virtual bool OnInputEvent(std::shared_ptr keyEvent) const override { + CHKPR(keyEvent, false); + MMI_HILOGI("Fuzz test in TestFilter::OnInputEvent,key code:%{public}d", keyEvent->GetKeyCode()); + return false; + } + bool OnInputEvent(std::shared_ptr pointerEvent) const override + { + CHKPR(pointerEvent, false); + MMI_HILOGI("Fuzz test in TestFilter::OnInputEvent,pointer id:%{public}d", pointerEvent->GetPointerId()); + return false; + } }; - InputManager::GetInstance()->AddInputEventFilter(fun); + auto filter = std::make_shared(); + const auto priority = 200 + (size % 100); + uint32_t touchTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX); + const auto filterId = InputManager::GetInstance()->AddInputEventFilter(filter, priority, touchTags); + if (filterId == -1) { + MMI_HILOGE("Add filter,ret:%{public}d", filterId); + return; + } else { + MMI_HILOGE("Add filter success,filterId:%{public}d", filterId); + } + auto ret = InputManager::GetInstance()->RemoveInputEventFilter(filterId); + if (ret != RET_OK) { + MMI_HILOGE("Remove filter,ret:%{public}d", ret); + return; + } else { + MMI_HILOGE("Remove filter,success,filterId:%{public}d", filterId); + } } } // MMI } // OHOS diff --git a/test/fuzztest/enableinputdevicecooperate_fuzzer/BUILD.gn b/test/fuzztest/enableinputdevicecooperate_fuzzer/BUILD.gn index 8496d9d18384356377c446c406730213ae8288f6..e535e3e4eb3142d55ea23296d9b1b678713be566 100644 --- a/test/fuzztest/enableinputdevicecooperate_fuzzer/BUILD.gn +++ b/test/fuzztest/enableinputdevicecooperate_fuzzer/BUILD.gn @@ -21,8 +21,11 @@ module_output_path = "multimodalinput/fuzz" ohos_fuzztest("EnableInputDeviceCooperateFuzzTest") { module_out_path = module_output_path fuzz_config_file = "//foundation/multimodalinput/input/test/fuzztest/enableinputdevicecooperate_fuzzer" - include_dirs = - [ "//foundation/multimodalinput/input/interfaces/util/common/include" ] + include_dirs = [ + "//foundation/multimodalinput/input/interfaces/util/common/include", + "//foundation/multimodalinput/input/frameworks/proxy/event_handler/include", + "//foundation/multimodalinput/input/frameworks/proxy/module_loader/include", + ] cflags = [ "-g", "-O0", @@ -30,6 +33,10 @@ ohos_fuzztest("EnableInputDeviceCooperateFuzzTest") { "-fno-omit-frame-pointer", ] sources = [ "enableinputdevicecooperate_fuzzer.cpp" ] + configs = [ + "//foundation/multimodalinput/input/util:libmmi_util_public_config", + "//foundation/multimodalinput/input/service/filter:mmi_event_filter_config", + ] deps = [ "${mmi_path}/frameworks/proxy:libmmi-client" ] external_deps = [ "c_utils:utils", diff --git a/test/fuzztest/enableinputdevicecooperate_fuzzer/enableinputdevicecooperate_fuzzer.cpp b/test/fuzztest/enableinputdevicecooperate_fuzzer/enableinputdevicecooperate_fuzzer.cpp index c102d5a70326fe0a984cf12bab0da5a428e88499..fb42e0da0a5b1fe22ab44f0cfbe0e7d0331e5196 100644 --- a/test/fuzztest/enableinputdevicecooperate_fuzzer/enableinputdevicecooperate_fuzzer.cpp +++ b/test/fuzztest/enableinputdevicecooperate_fuzzer/enableinputdevicecooperate_fuzzer.cpp @@ -15,7 +15,7 @@ #include "enableinputdevicecooperate_fuzzer.h" #include "securec.h" -#include "input_manager.h" +#include "input_manager_impl.h" #include "mmi_log.h" namespace OHOS { @@ -31,7 +31,7 @@ void EnableInputDeviceCooperateFuzzTest(const uint8_t* data, size_t size) auto fun = [](std::string listener, CooperationMessage cooperateMessages) { MMI_HILOGD("EnableInputDeviceCooperateFuzzTest"); }; - InputManager::GetInstance()->EnableInputDeviceCooperate(enabled, fun); + InputMgrImpl.EnableInputDeviceCooperate(enabled, fun); } } // namespace MMI } // namespace OHOS diff --git a/frameworks/napi/distributed_input/BUILD.gn b/test/fuzztest/functionkeystate_fuzzer/BUILD.gn similarity index 32% rename from frameworks/napi/distributed_input/BUILD.gn rename to test/fuzztest/functionkeystate_fuzzer/BUILD.gn index 49261c2cadd09124ee9ab97a81b4e7a90323aebd..8d0be336fa1344fc64512f06ccc84bbd42564296 100644 --- a/frameworks/napi/distributed_input/BUILD.gn +++ b/test/fuzztest/functionkeystate_fuzzer/BUILD.gn @@ -11,56 +11,40 @@ # See the License for the specific language governing permissions and # limitations under the License. +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") import("//foundation/multimodalinput/input/multimodalinput_mini.gni") +module_output_path = "multimodalinput/fuzz" + +##############################fuzztest########################################## +ohos_fuzztest("FunctionkeyStateFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//foundation/multimodalinput/input/test/fuzztest/functionkeystate_fuzzer" + include_dirs = + [ "//foundation/multimodalinput/input/interfaces/util/common/include" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "functionkeystate_fuzzer.cpp" ] + deps = [ "${mmi_path}/frameworks/proxy:libmmi-client" ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] +} -if (input_feature_distributed) { - distributed_input_path = "${mmi_path}/frameworks/napi/distributed_input" - config("distributedinput_config") { - visibility = [ ":*" ] - - include_dirs = [ - "//foundation/multimodalinput/input/util/common/include", - "//foundation/multimodalinput/input/interfaces/native/innerkits/proxy/include", - "${distributed_input_path}/include", - ] - - defines = [] - if (input_feature_libinput) { - defines += [ "OHOS_BUILD_LIBINPUT" ] - } - - if (input_feature_hdf) { - defines += [ "OHOS_BUILD_HDF" ] - } - } - - ohos_shared_library("distributedinput") { - sources = [ - "src/js_input_dinput_context.cpp", - "src/js_input_dinput_manager.cpp", - "src/js_register_module.cpp", - ] - - configs = [ ":distributedinput_config" ] - - deps = [ - "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", - "//foundation/multimodalinput/input/frameworks/proxy:libmmi-common", - "//foundation/multimodalinput/input/util:libmmi-util", - "//third_party/libuv:uv", - ] - - external_deps = [ - "c_utils:utils", - "drivers_interface_input:hdi_input", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "napi:ace_napi", - ] - - relative_install_dir = "module/multimodalinput" - - part_name = "input" - subsystem_name = "multimodalinput" - } +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":FunctionkeyStateFuzzTest", + ] } +############################################################################### diff --git a/test/fuzztest/functionkeystate_fuzzer/corpus/init b/test/fuzztest/functionkeystate_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/functionkeystate_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# 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. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/functionkeystate_fuzzer/functionkeystate_fuzzer.cpp b/test/fuzztest/functionkeystate_fuzzer/functionkeystate_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2e7b6a357eea4ce11a3ad1daad16a3d70fc23e91 --- /dev/null +++ b/test/fuzztest/functionkeystate_fuzzer/functionkeystate_fuzzer.cpp @@ -0,0 +1,60 @@ +/* + * 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. + */ + +#include "functionkeystate_fuzzer.h" + +#include "securec.h" + +#include "input_manager.h" +#include "mmi_log.h" + +namespace OHOS { +namespace MMI { +template +size_t GetObject(T &object, const uint8_t *data, size_t size) +{ + size_t objectSize = sizeof(object); + if (objectSize > size) { + return 0; + } + errno_t ret = memcpy_s(&object, objectSize, data, objectSize); + if (ret != EOK) { + return 0; + } + return objectSize; +} + +void FunctionkeyStateFuzzTest(const uint8_t* data, size_t size) +{ + int32_t funcKey; + size_t startPos = 0; + startPos += GetObject(funcKey, data + startPos, size - startPos); + int32_t random; + GetObject(random, data + startPos, size - startPos); + bool enable = (random % 2) ? false : true; + InputManager::GetInstance()->SetFunctionKeyState(funcKey, enable); + + InputManager::GetInstance()->GetFunctionKeyState(funcKey); +} +} // MMI +} // OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::MMI::FunctionkeyStateFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/service/hdf_adapter/include/hdf_inject_init.h b/test/fuzztest/functionkeystate_fuzzer/functionkeystate_fuzzer.h similarity index 64% rename from service/hdf_adapter/include/hdf_inject_init.h rename to test/fuzztest/functionkeystate_fuzzer/functionkeystate_fuzzer.h index 2c03ce1da5f48e333927a9894d51464f48ab699f..37fe497145c5404d59e12757e6caf95ee8c76585 100644 --- a/service/hdf_adapter/include/hdf_inject_init.h +++ b/test/fuzztest/functionkeystate_fuzzer/functionkeystate_fuzzer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * 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 @@ -12,20 +12,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef HDF_INJECT_INIT_H -#define HDF_INJECT_INIT_H -enum DrvType { - TOUCH = 0, - MOUSE, - KEYBOARD, - PEN, - PAD, - FINGER, - JOYSTICK, - SWITCH5, - TRACKPAD5, - GAMEPAD, - TRACKBALL, - INVALD = 100, -}; -#endif // HDF_INJECT_INIT_H \ No newline at end of file + +#ifndef FUNCTIONKEYSTATE_FUZZER_H +#define FUNCTIONKEYSTATE_FUZZER_H + +#define FUZZ_PROJECT_NAME "functionkeystate_fuzzer" + +#endif // FUNCTIONKEYSTATE_FUZZER_H diff --git a/test/fuzztest/functionkeystate_fuzzer/project.xml b/test/fuzztest/functionkeystate_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/functionkeystate_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/getdevice_fuzzer/getdevice_fuzzer.cpp b/test/fuzztest/getdevice_fuzzer/getdevice_fuzzer.cpp index dba55f714bbe55fe0c80ae3a6ae9f5dc6c6fb738..fcc31d9692f251f56c1c6e52612001af6384fb7e 100755 --- a/test/fuzztest/getdevice_fuzzer/getdevice_fuzzer.cpp +++ b/test/fuzztest/getdevice_fuzzer/getdevice_fuzzer.cpp @@ -38,7 +38,12 @@ void GetDeviceFuzzTest(const uint8_t* data, size_t /* size */) /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ + if (data == nullptr) { + return 0; + } + if (size < sizeof(int32_t)) { + return 0; + } OHOS::MMI::GetDeviceFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/getinputdevicecooperatestate_fuzzer/BUILD.gn b/test/fuzztest/getinputdevicecooperatestate_fuzzer/BUILD.gn index 32a18c9864e1171571d3db658ab0ee3bee5c44cd..adcc3ce21829c14512a26b7ae94e7d13a4d7db69 100644 --- a/test/fuzztest/getinputdevicecooperatestate_fuzzer/BUILD.gn +++ b/test/fuzztest/getinputdevicecooperatestate_fuzzer/BUILD.gn @@ -22,9 +22,9 @@ ohos_fuzztest("GetInputDeviceCooperateStateFuzzTest") { module_out_path = module_output_path fuzz_config_file = "//foundation/multimodalinput/input/test/fuzztest/getinputdevicecooperatestate_fuzzer" include_dirs = [ - "//foundation/multimodalinput/input/interfaces/native/innerkits/proxy/include", - "//foundation/window/window_manager/previewer/mock", - "//foundation/bundlemanager/bundle_framework/services/bundlemgr/test/mock/include", + "//foundation/multimodalinput/input/interfaces/util/common/include", + "//foundation/multimodalinput/input/frameworks/proxy/event_handler/include", + "//foundation/multimodalinput/input/frameworks/proxy/module_loader/include", ] cflags = [ "-g", @@ -33,6 +33,10 @@ ohos_fuzztest("GetInputDeviceCooperateStateFuzzTest") { "-fno-omit-frame-pointer", ] sources = [ "getinputdevicecooperatestate_fuzzer.cpp" ] + configs = [ + "//foundation/multimodalinput/input/util:libmmi_util_public_config", + "//foundation/multimodalinput/input/service/filter:mmi_event_filter_config", + ] deps = [ "${mmi_path}/frameworks/proxy:libmmi-client" ] external_deps = [ "c_utils:utils", diff --git a/test/fuzztest/getinputdevicecooperatestate_fuzzer/getinputdevicecooperatestate_fuzzer.cpp b/test/fuzztest/getinputdevicecooperatestate_fuzzer/getinputdevicecooperatestate_fuzzer.cpp index fcc34a028271adc07a103efc2b4263ce1853547e..73e1a2fa38740f5c557bd4a8381ce3cc6d872903 100644 --- a/test/fuzztest/getinputdevicecooperatestate_fuzzer/getinputdevicecooperatestate_fuzzer.cpp +++ b/test/fuzztest/getinputdevicecooperatestate_fuzzer/getinputdevicecooperatestate_fuzzer.cpp @@ -17,7 +17,7 @@ #include "securec.h" -#include "input_manager.h" +#include "input_manager_impl.h" #include "mmi_log.h" namespace OHOS { @@ -35,7 +35,7 @@ void GetInputDeviceCooperateStateFuzzTest(const uint8_t* data, size_t size) auto fun = [](bool inputdevice) { MMI_HILOGD("Get inputdevice state success"); }; - InputManager::GetInstance()->GetInputDeviceCooperateState(deviceId, fun); + InputMgrImpl.GetInputDeviceCooperateState(deviceId, fun); } } // namespace MMI } // namespace OHOS diff --git a/test/fuzztest/markconsumed_fuzzer/markconsumed_fuzzer.cpp b/test/fuzztest/markconsumed_fuzzer/markconsumed_fuzzer.cpp index 339befef0081041ecc19ba3da59858aa8f070253..7f0bd1300781cc0713c51e8b30ef02f6ce0d6f01 100644 --- a/test/fuzztest/markconsumed_fuzzer/markconsumed_fuzzer.cpp +++ b/test/fuzztest/markconsumed_fuzzer/markconsumed_fuzzer.cpp @@ -26,10 +26,20 @@ namespace MMI { namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "MarkConsumedFuzzTest" }; } // namespace + +class InputEventConsumerTest : public IInputEventConsumer { +public: + virtual void OnInputEvent(std::shared_ptr keyEvent) const override {}; + virtual void OnInputEvent(std::shared_ptr pointerEvent) const override + { + MMI_HILOGD("Report pointer event success"); + }; + virtual void OnInputEvent(std::shared_ptr axisEvent) const override {}; +}; + template -T GetObject(const uint8_t *data, size_t size) +size_t GetObject(const uint8_t *data, size_t size, T &object) { - T object; size_t objectSize = sizeof(object); if (objectSize > size) { return 0; @@ -38,15 +48,18 @@ T GetObject(const uint8_t *data, size_t size) if (ret != EOK) { return 0; } - return object; + return objectSize; } void MarkConsumedFuzzTest(const uint8_t* data, size_t size) { CALL_DEBUG_ENTER; - int32_t monitorId = GetObject(data, size); - int32_t eventId = GetObject(data, size); + int32_t eventId; + GetObject(data, size, eventId); + auto consumer = std::make_shared(); + int32_t monitorId = InputManager::GetInstance()->AddMonitor(consumer); InputManager::GetInstance()->MarkConsumed(monitorId, eventId); + InputManager::GetInstance()->RemoveMonitor(monitorId); } } // namespace MMI } // namespace OHOS diff --git a/test/fuzztest/pointerspeed_fuzzer/BUILD.gn b/test/fuzztest/pointerspeed_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..c59ff74033a2e23375dc330025da30aa1d839f22 --- /dev/null +++ b/test/fuzztest/pointerspeed_fuzzer/BUILD.gn @@ -0,0 +1,50 @@ +# 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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/multimodalinput/input/multimodalinput_mini.gni") +module_output_path = "multimodalinput/fuzz" + +##############################fuzztest########################################## +ohos_fuzztest("PointerSpeedFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//foundation/multimodalinput/input/test/fuzztest/pointerspeed_fuzzer" + include_dirs = + [ "//foundation/multimodalinput/input/interfaces/util/common/include" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "pointerspeed_fuzzer.cpp" ] + deps = [ "${mmi_path}/frameworks/proxy:libmmi-client" ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":PointerSpeedFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/pointerspeed_fuzzer/corpus/init b/test/fuzztest/pointerspeed_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/pointerspeed_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# 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. + +FUZZ \ No newline at end of file diff --git a/service/filter/src/event_filter_parcel.cpp b/test/fuzztest/pointerspeed_fuzzer/pointerspeed_fuzzer.cpp similarity index 38% rename from service/filter/src/event_filter_parcel.cpp rename to test/fuzztest/pointerspeed_fuzzer/pointerspeed_fuzzer.cpp index 7f7adbb9c536b4c209667295275ef7493f6b0ca2..a89645f1e7ebb78f2fe29536b32a0573ed2abfb1 100644 --- a/service/filter/src/event_filter_parcel.cpp +++ b/test/fuzztest/pointerspeed_fuzzer/pointerspeed_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * 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 @@ -13,51 +13,55 @@ * limitations under the License. */ -#include "event_filter_parcel.h" +#include "pointerspeed_fuzzer.h" -#include "define_multimodal.h" +#include "securec.h" + +#include "input_manager.h" +#include "mmi_log.h" namespace OHOS { namespace MMI { namespace { -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "PointerEventParcel" }; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "PointerSpeedFuzzTest" }; } // namespace -bool PointerEventParcel::Marshalling(Parcel& out) const +template +size_t GetObject(const uint8_t *data, size_t size, T &object) { - if (data_ == nullptr) { - data_ = PointerEvent::Create(); + size_t objectSize = sizeof(object); + if (objectSize > size) { + return 0; } - CHKPF(data_); - if (!data_->WriteToParcel(out)) { - data_ = nullptr; - return false; + errno_t ret = memcpy_s(&object, objectSize, data, objectSize); + if (ret != EOK) { + return 0; } - return true; + return objectSize; } -PointerEventParcel *PointerEventParcel::Unmarshalling(Parcel& in) +void PointerSpeedFuzzTest(const uint8_t* data, size_t size) { - auto* request = new (std::nothrow) PointerEventParcel(); - if (request == nullptr) { - return nullptr; - } - - if (request->data_ == nullptr) { - request->data_ = PointerEvent::Create(); + int32_t speed; + size_t startPos = 0; + startPos += GetObject(data + startPos, size - startPos, speed); + InputManager::GetInstance()->SetPointerSpeed(speed); + if (InputManager::GetInstance()->SetPointerSpeed(speed) == RET_OK) { + MMI_HILOGD("Set pointer speed success"); } - if (request->data_ == nullptr) { - delete request; - return nullptr; + GetObject(data + startPos, size - startPos, speed); + if (InputManager::GetInstance()->GetPointerSpeed(speed) == RET_OK) { + MMI_HILOGD("Get pointer speed success"); } - - if (!request->data_->ReadFromParcel(in)) { - request->data_ = nullptr; - delete request; - return nullptr; - } - return request; } } // namespace MMI } // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::MMI::PointerSpeedFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/pointerspeed_fuzzer/pointerspeed_fuzzer.h b/test/fuzztest/pointerspeed_fuzzer/pointerspeed_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..206b6eb1ddb21f3c9b93df15a324d20a175c26dc --- /dev/null +++ b/test/fuzztest/pointerspeed_fuzzer/pointerspeed_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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 POINTERSPEED_FUZZER_H +#define POINTERSPEED_FUZZER_H + +#define FUZZ_PROJECT_NAME "pointerspeed_fuzzer" + +#endif // POINTERSPEED_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/pointerspeed_fuzzer/project.xml b/test/fuzztest/pointerspeed_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..27c26d11b7d89f7aef7835fb5f95f9e5ecaf6f9d --- /dev/null +++ b/test/fuzztest/pointerspeed_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/pointerstyle_fuzzer/BUILD.gn b/test/fuzztest/pointerstyle_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..73c259758c7f260c946a1d31bd12fdb2d19349c5 --- /dev/null +++ b/test/fuzztest/pointerstyle_fuzzer/BUILD.gn @@ -0,0 +1,51 @@ +# 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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/multimodalinput/input/multimodalinput_mini.gni") +module_output_path = "multimodalinput/fuzz" + +##############################fuzztest########################################## +ohos_fuzztest("PointerStyleFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//foundation/multimodalinput/input/test/fuzztest/pointerstyle_fuzzer" + include_dirs = + [ "//foundation/multimodalinput/input/interfaces/util/common/include" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "pointerstyle_fuzzer.cpp" ] + deps = [ "${mmi_path}/frameworks/proxy:libmmi-client" ] + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_single", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":PointerStyleFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/pointerstyle_fuzzer/corpus/init b/test/fuzztest/pointerstyle_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/pointerstyle_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# 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. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/pointerstyle_fuzzer/pointerstyle_fuzzer.cpp b/test/fuzztest/pointerstyle_fuzzer/pointerstyle_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..41deaf51992b6ea63d2142ccd0a8c923d3d21269 --- /dev/null +++ b/test/fuzztest/pointerstyle_fuzzer/pointerstyle_fuzzer.cpp @@ -0,0 +1,134 @@ +/* + * 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. + */ + +#include "pointerstyle_fuzzer.h" + +#include "ipc_skeleton.h" +#include "securec.h" + +#include "input_manager.h" + +namespace OHOS { +namespace MMI { +template +size_t GetObject(const uint8_t *data, size_t size, T &object) +{ + size_t objectSize = sizeof(object); + if (objectSize > size) { + return 0; + } + errno_t ret = memcpy_s(&object, objectSize, data, objectSize); + if (ret != EOK) { + return 0; + } + return objectSize; +} + +size_t GetString(const uint8_t *data, size_t size, char *object, size_t objectSize) +{ + if (objectSize > size) { + return 0; + } + errno_t ret = memcpy_s(&object, objectSize, data, objectSize); + if (ret != EOK) { + return 0; + } + return objectSize; +} + +void UpdateHotAreas(const uint8_t* data, size_t size, WindowInfo &windowInfo) +{ + size_t startPos = 0; + std::vector defaultHotAreasInfo; + std::vector pointerHotAreasInfo; + for (size_t j = 0; j < WindowInfo::MAX_HOTAREA_COUNT; ++j) { + Rect defaultRect; + startPos += GetObject(data + startPos, size - startPos, defaultRect.height); + startPos += GetObject(data + startPos, size - startPos, defaultRect.width); + startPos += GetObject(data + startPos, size - startPos, defaultRect.x); + startPos += GetObject(data + startPos, size - startPos, defaultRect.y); + defaultHotAreasInfo.push_back(defaultRect); + Rect pointerRect; + startPos += GetObject(data + startPos, size - startPos, pointerRect.height); + startPos += GetObject(data + startPos, size - startPos, pointerRect.width); + startPos += GetObject(data + startPos, size - startPos, pointerRect.x); + startPos += GetObject(data + startPos, size - startPos, pointerRect.y); + pointerHotAreasInfo.push_back(pointerRect); + } + windowInfo.defaultHotAreas = defaultHotAreasInfo; + windowInfo.pointerHotAreas = pointerHotAreasInfo; +} + +void UpdateDisplayInfo(const uint8_t* data, size_t size, int32_t windowId) +{ + DisplayGroupInfo displayGroupInfo; + size_t startPos = 0; + size_t stringSize = 4; + startPos += GetObject(data + startPos, size - startPos, displayGroupInfo.width); + startPos += GetObject(data + startPos, size - startPos, displayGroupInfo.height); + startPos += GetObject(data + startPos, size - startPos, displayGroupInfo.focusWindowId); + std::vector windowsInfo; + std::vector displaysInfo; + WindowInfo windowInfo; + windowInfo.id = windowId; + windowInfo.pid = IPCSkeleton::GetCallingPid(); + startPos += GetObject(data + startPos, size - startPos, windowInfo.uid); + startPos += GetObject(data + startPos, size - startPos, windowInfo.area.x); + startPos += GetObject(data + startPos, size - startPos, windowInfo.area.y); + startPos += GetObject(data + startPos, size - startPos, windowInfo.area.width); + startPos += GetObject(data + startPos, size - startPos, windowInfo.area.height); + UpdateHotAreas(data, size, windowInfo); + windowsInfo.push_back(windowInfo); + + DisplayInfo displayInfo; + startPos += GetObject(data + startPos, size - startPos, displayInfo.id); + startPos += GetObject(data + startPos, size - startPos, displayInfo.x); + startPos += GetObject(data + startPos, size - startPos, displayInfo.y); + startPos += GetObject(data + startPos, size - startPos, displayInfo.width); + startPos += GetObject(data + startPos, size - startPos, displayInfo.height); + startPos += GetObject(data + startPos, size - startPos, displayInfo.dpi); + char name[] = "name"; + startPos += GetString(data + startPos, size - startPos, name, stringSize); + displayInfo.name = name; + char uniq[] = "uniq"; + GetString(data + startPos, size - startPos, uniq, stringSize); + displayInfo.uniq = uniq; + displaysInfo.push_back(displayInfo); + displayGroupInfo.windowsInfo = windowsInfo; + displayGroupInfo.displaysInfo = displaysInfo; + InputManager::GetInstance()->UpdateDisplayInfo(displayGroupInfo); +} + +void PointerStyleFuzzTest(const uint8_t* data, size_t size) +{ + int32_t windowId; + size_t startPos = 0; + startPos += GetObject(data + startPos, size - startPos, windowId); + UpdateDisplayInfo(data, size, windowId); + PointerStyle pointerStyle; + GetObject(data + startPos, size - startPos, pointerStyle.id); + InputManager::GetInstance()->SetPointerStyle(windowId, pointerStyle); + InputManager::GetInstance()->GetPointerStyle(windowId, pointerStyle); +} +} // MMI +} // OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::MMI::PointerStyleFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/pointerstyle_fuzzer/pointerstyle_fuzzer.h b/test/fuzztest/pointerstyle_fuzzer/pointerstyle_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..457dd0d4f8e3ff4ae1c0d66cc4a6ecc59ab117c8 --- /dev/null +++ b/test/fuzztest/pointerstyle_fuzzer/pointerstyle_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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 POINTERSTYLE_FUZZER_H +#define POINTERSTYLE_FUZZER_H + +#define FUZZ_PROJECT_NAME "pointerstyle_fuzzer" + +#endif // POINTERSTYLE_FUZZER_H diff --git a/test/fuzztest/pointerstyle_fuzzer/project.xml b/test/fuzztest/pointerstyle_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/pointerstyle_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/registercooperatelistener_fuzzer/BUILD.gn b/test/fuzztest/registercooperatelistener_fuzzer/BUILD.gn index 494847ce247f27d6e660e48eba2dc7714bdf8852..1e4c738759dc4f35129ed5067f11e5acb6c5d435 100644 --- a/test/fuzztest/registercooperatelistener_fuzzer/BUILD.gn +++ b/test/fuzztest/registercooperatelistener_fuzzer/BUILD.gn @@ -21,8 +21,11 @@ module_output_path = "multimodalinput/fuzz" ohos_fuzztest("RegisterCooperateListenerFuzzTest") { module_out_path = module_output_path fuzz_config_file = "//foundation/multimodalinput/input/test/fuzztest/registercooperatelistener_fuzzer" - include_dirs = - [ "//foundation/multimodalinput/input/interfaces/util/common/include" ] + include_dirs = [ + "//foundation/multimodalinput/input/interfaces/util/common/include", + "//foundation/multimodalinput/input/frameworks/proxy/event_handler/include", + "//foundation/multimodalinput/input/frameworks/proxy/module_loader/include", + ] cflags = [ "-g", "-O0", @@ -30,6 +33,10 @@ ohos_fuzztest("RegisterCooperateListenerFuzzTest") { "-fno-omit-frame-pointer", ] sources = [ "registercooperatelistener_fuzzer.cpp" ] + configs = [ + "//foundation/multimodalinput/input/util:libmmi_util_public_config", + "//foundation/multimodalinput/input/service/filter:mmi_event_filter_config", + ] deps = [ "${mmi_path}/frameworks/proxy:libmmi-client" ] external_deps = [ "c_utils:utils", diff --git a/test/fuzztest/registercooperatelistener_fuzzer/registercooperatelistener_fuzzer.cpp b/test/fuzztest/registercooperatelistener_fuzzer/registercooperatelistener_fuzzer.cpp index b5fa9aeebcb60e44c982b5f25b055b4131dd6492..cac0cf58cccc2609c2b34b6496fb755ed43bf9e3 100644 --- a/test/fuzztest/registercooperatelistener_fuzzer/registercooperatelistener_fuzzer.cpp +++ b/test/fuzztest/registercooperatelistener_fuzzer/registercooperatelistener_fuzzer.cpp @@ -17,7 +17,7 @@ #include "securec.h" -#include "input_manager.h" +#include "input_manager_impl.h" #include "mmi_log.h" #include "i_input_device_cooperate_listener.h" @@ -39,8 +39,8 @@ public: void RegisterCooperateListenerFuzzTest(const uint8_t* data, size_t size) { std::shared_ptr consumer = std::make_shared(); - InputManager::GetInstance()->RegisterCooperateListener(consumer); - InputManager::GetInstance()->UnregisterCooperateListener(consumer); + InputMgrImpl.RegisterCooperateListener(consumer); + InputMgrImpl.UnregisterCooperateListener(consumer); } } // namespace MMI } // namespace OHOS diff --git a/test/fuzztest/removeinterceptor_fuzzer/removeinterceptor_fuzzer.cpp b/test/fuzztest/removeinterceptor_fuzzer/removeinterceptor_fuzzer.cpp index 0f8304d502a5e9eae439b64da81bb8e662e49504..6079d1a2af8321d93b101dc674599e47723cfa04 100755 --- a/test/fuzztest/removeinterceptor_fuzzer/removeinterceptor_fuzzer.cpp +++ b/test/fuzztest/removeinterceptor_fuzzer/removeinterceptor_fuzzer.cpp @@ -40,7 +40,12 @@ void RemoveInterceptorFuzzTest(const uint8_t* data, size_t /* size */) /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ + if (data == nullptr) { + return 0; + } + if (size < sizeof(int32_t)) { + return 0; + } OHOS::MMI::RemoveInterceptorFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/setanrobserver_fuzzer/setanrobserver_fuzzer.cpp b/test/fuzztest/setanrobserver_fuzzer/setanrobserver_fuzzer.cpp old mode 100755 new mode 100644 index 1d0cf81dc5d6ddf55aae38690426649bd677c72c..d68c38bd41c31cba4e5e3b92d5936e6b73ab09cd --- a/test/fuzztest/setanrobserver_fuzzer/setanrobserver_fuzzer.cpp +++ b/test/fuzztest/setanrobserver_fuzzer/setanrobserver_fuzzer.cpp @@ -16,8 +16,8 @@ #include "setanrobserver_fuzzer.h" #include "input_manager.h" -#include "mmi_log.h" #include "i_anr_observer.h" +#include "mmi_log.h" namespace OHOS { namespace MMI { diff --git a/test/fuzztest/simulateinputevent_fuzzer/simulateinputevent_fuzzer.cpp b/test/fuzztest/simulateinputevent_fuzzer/simulateinputevent_fuzzer.cpp index 7a30321e146b349889ca0d6f634b6eacec19919e..e2367cb98ce514128ea862b5a6894de39616b994 100644 --- a/test/fuzztest/simulateinputevent_fuzzer/simulateinputevent_fuzzer.cpp +++ b/test/fuzztest/simulateinputevent_fuzzer/simulateinputevent_fuzzer.cpp @@ -76,21 +76,21 @@ bool SimulateInputEventFuzzTest(const uint8_t* data, size_t size) auto pointerDownEvent = PointerEvent::Create(); CHKPF(pointerDownEvent); PointerEvent::PointerItem downitem; - downitem.SetPointerId(0); // test code,set the PointerId = 0 + downitem.SetPointerId(0); int32_t physicalX; startPos += GetObject(physicalX, data + startPos, size - startPos); - downitem.SetDisplayX(physicalX); // test code,set the DisplayX = 823 + downitem.SetDisplayX(physicalX); int32_t physicalY; startPos += GetObject(physicalY, data + startPos, size - startPos); - downitem.SetDisplayY(physicalY); // test code,set the DisplayY = 723 + downitem.SetDisplayY(physicalY); int32_t pressure; startPos += GetObject(pressure, data + startPos, size - startPos); - downitem.SetPressure(pressure); // test code,set the Pressure = 5 - downitem.SetDeviceId(1); // test code,set the DeviceId = 1 + downitem.SetPressure(pressure); + downitem.SetDeviceId(1); pointerDownEvent->AddPointerItem(downitem); pointerDownEvent->SetId(std::numeric_limits::max()); pointerDownEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); - pointerDownEvent->SetPointerId(0); // test code,set the PointerId = 1 + pointerDownEvent->SetPointerId(0); pointerDownEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); MMI_HILOGD("Call InputManager::SimulatePointerEvent"); InputManager::GetInstance()->SimulateInputEvent(pointerDownEvent); @@ -98,15 +98,15 @@ bool SimulateInputEventFuzzTest(const uint8_t* data, size_t size) auto pointerUpEvent = PointerEvent::Create(); CHKPF(pointerUpEvent); PointerEvent::PointerItem upitem; - upitem.SetPointerId(0); // test code,set the PointerId = 0 - upitem.SetDisplayX(physicalX); // test code,set the DisplayX = 823 - upitem.SetDisplayY(physicalY); // test code,set the DisplayY = 723 - upitem.SetPressure(pressure); // test code,set the Pressure = 5 - upitem.SetDeviceId(1); // test code,set the DeviceId = 1 + upitem.SetPointerId(0); + upitem.SetDisplayX(physicalX); + upitem.SetDisplayY(physicalY); + upitem.SetPressure(pressure); + upitem.SetDeviceId(1); pointerUpEvent->AddPointerItem(upitem); pointerUpEvent->SetId(std::numeric_limits::max()); pointerUpEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UP); - pointerUpEvent->SetPointerId(0); // test code,set the PointerId = 1 + pointerUpEvent->SetPointerId(0); pointerUpEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); MMI_HILOGD("Call InputManager::SimulatePointerEvent"); InputManager::GetInstance()->SimulateInputEvent(pointerUpEvent); diff --git a/test/fuzztest/startinputdevicecooperate_fuzzer/BUILD.gn b/test/fuzztest/startinputdevicecooperate_fuzzer/BUILD.gn index 1dba1f443d3d68a4a0a40ef56f20afd086419cad..3c1418823f24d42a277400e4fad5bbee447a6bad 100644 --- a/test/fuzztest/startinputdevicecooperate_fuzzer/BUILD.gn +++ b/test/fuzztest/startinputdevicecooperate_fuzzer/BUILD.gn @@ -21,8 +21,11 @@ module_output_path = "multimodalinput/fuzz" ohos_fuzztest("StartInputDeviceCooperateFuzzTest") { module_out_path = module_output_path fuzz_config_file = "//foundation/multimodalinput/input/test/fuzztest/startinputdevicecooperate_fuzzer" - include_dirs = - [ "//foundation/multimodalinput/input/interfaces/util/common/include" ] + include_dirs = [ + "//foundation/multimodalinput/input/interfaces/util/common/include", + "//foundation/multimodalinput/input/frameworks/proxy/event_handler/include", + "//foundation/multimodalinput/input/frameworks/proxy/module_loader/include", + ] cflags = [ "-g", "-O0", @@ -30,6 +33,10 @@ ohos_fuzztest("StartInputDeviceCooperateFuzzTest") { "-fno-omit-frame-pointer", ] sources = [ "startinputdevicecooperate_fuzzer.cpp" ] + configs = [ + "//foundation/multimodalinput/input/util:libmmi_util_public_config", + "//foundation/multimodalinput/input/service/filter:mmi_event_filter_config", + ] deps = [ "${mmi_path}/frameworks/proxy:libmmi-client" ] external_deps = [ "c_utils:utils", diff --git a/test/fuzztest/startinputdevicecooperate_fuzzer/startinputdevicecooperate_fuzzer.cpp b/test/fuzztest/startinputdevicecooperate_fuzzer/startinputdevicecooperate_fuzzer.cpp index 409d8a5cee673b95ed4d152b9d7b0ae71459b423..27a28685092cc638efca78fa072ef297155e6558 100644 --- a/test/fuzztest/startinputdevicecooperate_fuzzer/startinputdevicecooperate_fuzzer.cpp +++ b/test/fuzztest/startinputdevicecooperate_fuzzer/startinputdevicecooperate_fuzzer.cpp @@ -15,7 +15,7 @@ #include "startinputdevicecooperate_fuzzer.h" -#include "input_manager.h" +#include "input_manager_impl.h" #include "mmi_log.h" namespace OHOS { @@ -34,7 +34,7 @@ void StartInputDeviceCooperateFuzzTest(const uint8_t* data, size_t size) auto fun = [](std::string listener, CooperationMessage cooperateMessages) { MMI_HILOGD("StartInputDeviceCooperateFuzzTest"); }; - InputManager::GetInstance()->StartInputDeviceCooperate(sinkDeviceId, srcInputDeviceId, fun); + InputMgrImpl.StartInputDeviceCooperate(sinkDeviceId, srcInputDeviceId, fun); } } // MMI } // OHOS @@ -42,7 +42,12 @@ void StartInputDeviceCooperateFuzzTest(const uint8_t* data, size_t size) /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - /* Run your code on data */ + if (data == nullptr) { + return 0; + } + if (size < sizeof(int32_t)) { + return 0; + } OHOS::MMI::StartInputDeviceCooperateFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/stopdevicecooperate_fuzzer/BUILD.gn b/test/fuzztest/stopdevicecooperate_fuzzer/BUILD.gn index 945145b25e9ae04ed3ffbb17d40d9778221aefb0..31eeff0d5a242604b61973891174ac3f542676be 100644 --- a/test/fuzztest/stopdevicecooperate_fuzzer/BUILD.gn +++ b/test/fuzztest/stopdevicecooperate_fuzzer/BUILD.gn @@ -21,8 +21,11 @@ module_output_path = "multimodalinput/fuzz" ohos_fuzztest("StopDeviceCooperateFuzzTest") { module_out_path = module_output_path fuzz_config_file = "//foundation/multimodalinput/input/test/fuzztest/stopdevicecooperate_fuzzer" - include_dirs = - [ "//foundation/multimodalinput/input/interfaces/util/common/include" ] + include_dirs = [ + "//foundation/multimodalinput/input/interfaces/util/common/include", + "//foundation/multimodalinput/input/frameworks/proxy/event_handler/include", + "//foundation/multimodalinput/input/frameworks/proxy/module_loader/include", + ] cflags = [ "-g", "-O0", @@ -30,6 +33,10 @@ ohos_fuzztest("StopDeviceCooperateFuzzTest") { "-fno-omit-frame-pointer", ] sources = [ "stopdevicecooperate_fuzzer.cpp" ] + configs = [ + "//foundation/multimodalinput/input/util:libmmi_util_public_config", + "//foundation/multimodalinput/input/service/filter:mmi_event_filter_config", + ] deps = [ "${mmi_path}/frameworks/proxy:libmmi-client" ] external_deps = [ "c_utils:utils", diff --git a/test/fuzztest/stopdevicecooperate_fuzzer/stopdevicecooperate_fuzzer.cpp b/test/fuzztest/stopdevicecooperate_fuzzer/stopdevicecooperate_fuzzer.cpp index 62dbeeaa695a070dee17d3f67aebc13f19398d0d..561829e890dc5f916eefc08a0e64156207896f3d 100644 --- a/test/fuzztest/stopdevicecooperate_fuzzer/stopdevicecooperate_fuzzer.cpp +++ b/test/fuzztest/stopdevicecooperate_fuzzer/stopdevicecooperate_fuzzer.cpp @@ -15,7 +15,7 @@ #include "stopdevicecooperate_fuzzer.h" -#include "input_manager.h" +#include "input_manager_impl.h" #include "mmi_log.h" namespace OHOS { @@ -30,7 +30,7 @@ void StopDeviceCooperateFuzzTest(size_t size) MMI_HILOGD("StopDeviceCooperateFuzzTest"); }; - InputManager::GetInstance()->StopDeviceCooperate(fun); + InputMgrImpl.StopDeviceCooperate(fun); } } // MMI } // OHOS diff --git a/test/fuzztest/subscribekeyevent_fuzzer/subscribekeyevent_fuzzer.cpp b/test/fuzztest/subscribekeyevent_fuzzer/subscribekeyevent_fuzzer.cpp index 948d4b684d07550f624be01beab5aaa48504bea0..701ba0403ba22f4b321d5460b13beca1cb1554fa 100644 --- a/test/fuzztest/subscribekeyevent_fuzzer/subscribekeyevent_fuzzer.cpp +++ b/test/fuzztest/subscribekeyevent_fuzzer/subscribekeyevent_fuzzer.cpp @@ -24,7 +24,7 @@ namespace OHOS { namespace MMI { namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "SubscribeKeyEventFuzzTest" }; -constexpr int32_t DEFAULT_PREKEY_COUNT = 4; +constexpr int32_t DEFAULT_PREKEY_COUNT = 3; } // namespace class InputEventConsumerTest : public IInputEventConsumer { diff --git a/test/fuzztest/updatedisplayinfo_fuzzer/updatedisplayinfo_fuzzer.cpp b/test/fuzztest/updatedisplayinfo_fuzzer/updatedisplayinfo_fuzzer.cpp index c5e5f681606e9a031408b07e3477803dab58e9e8..21679fec404114575d750c7a22e9e8d67bdcf9d6 100644 --- a/test/fuzztest/updatedisplayinfo_fuzzer/updatedisplayinfo_fuzzer.cpp +++ b/test/fuzztest/updatedisplayinfo_fuzzer/updatedisplayinfo_fuzzer.cpp @@ -42,7 +42,7 @@ size_t GetObject(const uint8_t *data, size_t size, T &object) return objectSize; } -size_t GetString(size_t objectSize, const uint8_t *data, size_t size, std::string &object) +size_t GetString(const uint8_t *data, size_t size, char *object, size_t objectSize) { if (objectSize > size) { return 0; @@ -54,15 +54,39 @@ size_t GetString(size_t objectSize, const uint8_t *data, size_t size, std::strin return objectSize; } +void UpdateHotAreas(const uint8_t* data, size_t size, WindowInfo &windowInfo) +{ + size_t startPos = 0; + std::vector defaultHotAreasInfo; + std::vector pointerHotAreasInfo; + for (size_t j = 0; j < WindowInfo::MAX_HOTAREA_COUNT; ++j) { + Rect defaultRect; + startPos += GetObject(data + startPos, size - startPos, defaultRect.height); + startPos += GetObject(data + startPos, size - startPos, defaultRect.width); + startPos += GetObject(data + startPos, size - startPos, defaultRect.x); + startPos += GetObject(data + startPos, size - startPos, defaultRect.y); + defaultHotAreasInfo.push_back(defaultRect); + Rect pointerRect; + startPos += GetObject(data + startPos, size - startPos, pointerRect.height); + startPos += GetObject(data + startPos, size - startPos, pointerRect.width); + startPos += GetObject(data + startPos, size - startPos, pointerRect.x); + startPos += GetObject(data + startPos, size - startPos, pointerRect.y); + pointerHotAreasInfo.push_back(pointerRect); + } + windowInfo.defaultHotAreas = defaultHotAreasInfo; + windowInfo.pointerHotAreas = pointerHotAreasInfo; +} + void UpdateDisplayInfoFuzzTest(const uint8_t* data, size_t size) { DisplayGroupInfo displayGroupInfo; size_t startPos = 0; + size_t stringSize = 4; startPos += GetObject(data + startPos, size - startPos, displayGroupInfo.width); startPos += GetObject(data + startPos, size - startPos, displayGroupInfo.height); startPos += GetObject(data + startPos, size - startPos, displayGroupInfo.focusWindowId); - std::vector windowsInfos; - std::vector displaysInfos; + std::vector windowsInfo; + std::vector displaysInfo; for (size_t i = 0; i < WindowInfo::MAX_HOTAREA_COUNT + 1; ++i) { WindowInfo windowInfo; startPos += GetObject(data + startPos, size - startPos, windowInfo.id); @@ -72,7 +96,8 @@ void UpdateDisplayInfoFuzzTest(const uint8_t* data, size_t size) startPos += GetObject(data + startPos, size - startPos, windowInfo.area.y); startPos += GetObject(data + startPos, size - startPos, windowInfo.area.width); startPos += GetObject(data + startPos, size - startPos, windowInfo.area.height); - windowsInfos.push_back(windowInfo); + UpdateHotAreas(data, size, windowInfo); + windowsInfo.push_back(windowInfo); DisplayInfo displayInfo; startPos += GetObject(data + startPos, size - startPos, displayInfo.id); @@ -80,27 +105,17 @@ void UpdateDisplayInfoFuzzTest(const uint8_t* data, size_t size) startPos += GetObject(data + startPos, size - startPos, displayInfo.y); startPos += GetObject(data + startPos, size - startPos, displayInfo.width); startPos += GetObject(data + startPos, size - startPos, displayInfo.height); - - size_t objectSize = 0; - std::string name = ""; - size_t ret = 0; - ret = GetString(objectSize, data, size, name); - if (ret == 0) { - MMI_HILOGD("%{public}s:%{public}d The return value is 0", __func__, __LINE__); - return; - } + startPos += GetObject(data + startPos, size - startPos, displayInfo.dpi); + char name[] = "name"; + startPos += GetString(data + startPos, size - startPos, name, stringSize); displayInfo.name = name; - std::string uniq = ""; - ret = GetString(objectSize, data, size, uniq); - if (ret == 0) { - MMI_HILOGD("%{public}s:%{public}d The return value is 0", __func__, __LINE__); - return; - } + char uniq[] = "uniq"; + startPos += GetString(data + startPos, size - startPos, uniq, stringSize); displayInfo.uniq = uniq; - displaysInfos.push_back(displayInfo); + displaysInfo.push_back(displayInfo); } - displayGroupInfo.windowsInfo = windowsInfos; - displayGroupInfo.displaysInfo = displaysInfos; + displayGroupInfo.windowsInfo = windowsInfo; + displayGroupInfo.displaysInfo = displaysInfo; InputManager::GetInstance()->UpdateDisplayInfo(displayGroupInfo); MMI_HILOGD("Update display info success"); } diff --git a/test/unittest/common/include/event_util_test.h b/test/unittest/common/include/event_util_test.h index 5e411a85d576cb12951e427c51e064cf87f43c73..86aa32e9ef8a11e1d8a827725add807c520f2ef4 100644 --- a/test/unittest/common/include/event_util_test.h +++ b/test/unittest/common/include/event_util_test.h @@ -51,18 +51,18 @@ PermissionDef infoManagerTestPermDef_ = { }; PermissionStateFull infoManagerTestState_ = { - .grantFlags = {1}, - .grantStatus = {PermissionState::PERMISSION_GRANTED}, + .grantFlags = { 1 }, + .grantStatus = { PermissionState::PERMISSION_GRANTED }, .isGeneral = true, .permissionName = "ohos.permission.INPUT_MONITORING", - .resDeviceID = {"local"} + .resDeviceID = { "local" } }; HapPolicyParams infoManagerTestPolicyPrams_ = { .apl = APL_NORMAL, .domain = "test.domain", - .permList = {infoManagerTestPermDef_}, - .permStateList = {infoManagerTestState_} + .permList = { infoManagerTestPermDef_ }, + .permStateList = { infoManagerTestState_ } }; HapInfoParams infoManagerTestInfoParms_ = { @@ -120,6 +120,20 @@ public: virtual void OnInputEvent(std::shared_ptr axisEvent) const override {}; }; +class PriorityMiddleCallback : public IInputEventConsumer { +public: + virtual void OnInputEvent(std::shared_ptr keyEvent) const override; + virtual void OnInputEvent(std::shared_ptr pointerEvent) const override; + virtual void OnInputEvent(std::shared_ptr axisEvent) const override {}; +}; + +class PriorityHighCallback : public IInputEventConsumer { +public: + virtual void OnInputEvent(std::shared_ptr keyEvent) const override; + virtual void OnInputEvent(std::shared_ptr pointerEvent) const override; + virtual void OnInputEvent(std::shared_ptr axisEvent) const override {}; +}; + class InputEventCallback : public IInputEventConsumer { public: virtual void OnInputEvent(std::shared_ptr keyEvent) const override; diff --git a/test/unittest/common/include/system_info.h b/test/unittest/common/include/system_info.h index 038e962302927114fc5e172467bcc1b45c486ca2..552f0b08128d88aa53eee76830b97a6b40c39f64 100644 --- a/test/unittest/common/include/system_info.h +++ b/test/unittest/common/include/system_info.h @@ -21,7 +21,7 @@ namespace OHOS { namespace MMI { namespace SYSTEM_INFO { -static constexpr double CPU_USAGE_UNKONW = -1.0; +static constexpr double CPU_USAGE_UNKNOWN = -1.0; static constexpr double CPU_USAGE_LOAD = 20.0; static constexpr double CPU_USAGE_MAX = 100.0; class SystemInfo { diff --git a/test/unittest/common/src/event_util_test.cpp b/test/unittest/common/src/event_util_test.cpp index 269da0b13538af3762938132343049c51e6c83c9..76c05e63cfa73ec5a9ae145f7d9caafd11e75c26 100644 --- a/test/unittest/common/src/event_util_test.cpp +++ b/test/unittest/common/src/event_util_test.cpp @@ -47,7 +47,9 @@ void InputEventConsumer::OnInputEvent(std::shared_ptr pointerEvent ASSERT_TRUE(pointerEvent != nullptr); auto pointerAction = pointerEvent->GetPointerAction(); if (pointerAction != PointerEvent::POINTER_ACTION_ENTER_WINDOW && - pointerAction != PointerEvent::POINTER_ACTION_LEAVE_WINDOW) { + pointerAction != PointerEvent::POINTER_ACTION_LEAVE_WINDOW && + pointerAction != PointerEvent::POINTER_ACTION_PULL_IN_WINDOW && + pointerAction != PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW) { TestUtil->AddEventDump(TestUtil->DumpInputEvent(pointerEvent)); } } @@ -74,6 +76,46 @@ void InputEventCallback::OnInputEvent(std::shared_ptr keyEvent) const } } +void PriorityMiddleCallback::OnInputEvent(std::shared_ptr pointerEvent) const +{ + CALL_DEBUG_ENTER; + if (TestUtil->GetRecvFlag() != RECV_FLAG::RECV_MARK_CONSUMED) { + TestUtil->SetRecvFlag(RECV_FLAG::RECV_INTERCEPT); + ASSERT_TRUE(pointerEvent != nullptr); + TestUtil->AddEventDump("Call middle interceptor"); + } +} + +void PriorityMiddleCallback::OnInputEvent(std::shared_ptr keyEvent) const +{ + CALL_DEBUG_ENTER; + if (TestUtil->GetRecvFlag() != RECV_FLAG::RECV_MARK_CONSUMED) { + TestUtil->SetRecvFlag(RECV_FLAG::RECV_INTERCEPT); + ASSERT_TRUE(keyEvent != nullptr); + TestUtil->AddEventDump("Call middle interceptor"); + } +} + +void PriorityHighCallback::OnInputEvent(std::shared_ptr pointerEvent) const +{ + CALL_DEBUG_ENTER; + if (TestUtil->GetRecvFlag() != RECV_FLAG::RECV_MARK_CONSUMED) { + TestUtil->SetRecvFlag(RECV_FLAG::RECV_INTERCEPT); + ASSERT_TRUE(pointerEvent != nullptr); + TestUtil->AddEventDump("Call high interceptor"); + } +} + +void PriorityHighCallback::OnInputEvent(std::shared_ptr keyEvent) const +{ + CALL_DEBUG_ENTER; + if (TestUtil->GetRecvFlag() != RECV_FLAG::RECV_MARK_CONSUMED) { + TestUtil->SetRecvFlag(RECV_FLAG::RECV_INTERCEPT); + ASSERT_TRUE(keyEvent != nullptr); + TestUtil->AddEventDump("Call high interceptor"); + } +} + void WindowEventConsumer::OnInputEvent(std::shared_ptr keyEvent) const { threadId_ = GetThisThreadId(); @@ -139,7 +181,6 @@ bool EventUtilTest::Init() auto runner = AppExecFwk::EventRunner::Create(threadTest); CHKPF(runner); auto eventHandler = std::make_shared(runner); - CHKPF(eventHandler); MMI::InputManager::GetInstance()->SetWindowInputEventConsumer(listener_, eventHandler); return true; } @@ -149,6 +190,11 @@ std::string EventUtilTest::DumpInputEvent(const std::shared_ptr& p const int precision = 2; std::ostringstream ostream; std::vector pointerIds { pointerEvent->GetPointerIds() }; + std::string str; + std::vector buffer = pointerEvent->GetBuffer(); + for (const auto& buff : buffer) { + str += std::to_string(buff); + } ostream << "ClientMsgHandler: in OnPointerEvent" << ",EventType:" << pointerEvent->GetEventType() << ",ActionTime:" << pointerEvent->GetActionTime() @@ -158,10 +204,13 @@ std::string EventUtilTest::DumpInputEvent(const std::shared_ptr& p << ",PointerAction:" << pointerEvent->DumpPointerAction() << ",SourceType:" << pointerEvent->DumpSourceType() << ",ButtonId:" << pointerEvent->GetButtonId() + << ",DeviceId:" << pointerEvent->GetDeviceId() << ",VerticalAxisValue:" << std::fixed << std::setprecision(precision) << pointerEvent->GetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_VERTICAL) << ",HorizontalAxisValue:" << std::fixed << std::setprecision(precision) - << pointerEvent->GetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_HORIZONTAL); + << pointerEvent->GetAxisValue(PointerEvent::AXIS_TYPE_SCROLL_HORIZONTAL) + <<",BufferCount:" << buffer.size() + <<",Buffer:" << str.c_str(); for (const auto &pointerId : pointerIds) { PointerEvent::PointerItem item; if (!pointerEvent->GetPointerItem(pointerId, item)) { @@ -179,8 +228,10 @@ std::string EventUtilTest::DumpInputEvent(const std::shared_ptr& p << ",ToolWidth:" << item.GetToolWidth() << ",ToolHeight:" << item.GetToolHeight() << ",Pressure:" << item.GetPressure() << ",ToolType:" << item.GetToolType() << ",LongAxis:" << item.GetLongAxis() << ",ShortAxis:" << item.GetShortAxis() - << ",DeviceId:" << item.GetDeviceId(); + << ",DeviceId:" << item.GetDeviceId() << ",RawDx:" << item.GetRawDx() + << ",RawDy:" << item.GetRawDy(); } + return ostream.str(); } @@ -196,9 +247,14 @@ std::string EventUtilTest::DumpInputEvent(const std::shared_ptr& keyEv << ", KeyAction:" << keyEvent->GetKeyAction(); std::vector pressedKeys = keyEvent->GetPressedKeys(); for (const int32_t &key : pressedKeys) { - auto keyItem = keyEvent->GetKeyItem(key); - CHKPS(keyItem); - keyItem->GetDeviceId(); + std::optional keyItem = keyEvent->GetKeyItem(key); + if (!keyItem) { + MMI_HILOGE("keyItem is nullopt"); + return ""; + } + strm << ", KeyCode:" << keyItem->GetKeyCode() + << ", DeviceId:" << keyItem->GetDeviceId() + << ", Unicode:" << keyItem->GetUnicode(); } return strm.str(); } @@ -207,6 +263,7 @@ bool EventUtilTest::CompareDump(const std::shared_ptr& pointerEven { CALL_DEBUG_ENTER; std::string before = DumpInputEvent(pointerEvent); + MMI_HILOGD("before:%{public}s", before.c_str()); InputManager::GetInstance()->SimulateInputEvent(pointerEvent); std::string after = GetEventDump(); MMI_HILOGD("after:%{public}s", after.c_str()); @@ -218,6 +275,7 @@ bool EventUtilTest::CompareDump(const std::shared_ptr& keyEvent) { CALL_DEBUG_ENTER; std::string before = DumpInputEvent(keyEvent); + MMI_HILOGD("before:%{public}s", before.c_str()); InputManager::GetInstance()->SimulateInputEvent(keyEvent); std::string after = GetEventDump(); MMI_HILOGD("after:%{public}s", after.c_str()); diff --git a/test/unittest/common/src/system_info.cpp b/test/unittest/common/src/system_info.cpp index 18b35dc8a2484c3f9d2f1fb32c78161bd1acd0bb..ab7589dbabac4358c40bd3a65e4bd31e6fa4e859 100644 --- a/test/unittest/common/src/system_info.cpp +++ b/test/unittest/common/src/system_info.cpp @@ -60,21 +60,25 @@ int32_t CpuInfo::GetTaskPidFile(const std::string &process_name) continue; } const std::string path = procPath + "/" + pidFile->d_name + "/status"; - std::ifstream filePath(path); - if (!filePath.is_open()) { + std::ifstream file(path); + if (!file.is_open()) { continue; } std::string strLine; - std::getline(filePath, strLine); + if (!std::getline(file, strLine)) { + MMI_HILOGE("getline failed"); + file.close(); + return DEFAULT_PID; + } if (strLine.empty()) { - filePath.close(); + file.close(); continue; } if ((strLine.find(process_name)) == std::string::npos) { - filePath.close(); + file.close(); continue; } - while (std::getline(filePath, strLine)) { + while (std::getline(file, strLine)) { if ((strLine.find("Pid")) != std::string::npos) { if (::sscanf_s(strLine.c_str(), "%*s%d", &pid, sizeof(pid)) != 1) { MMI_HILOGE("Failed to cut out the pid"); @@ -82,10 +86,12 @@ int32_t CpuInfo::GetTaskPidFile(const std::string &process_name) break; } } - filePath.close(); + file.close(); break; } - ::closedir(dir); + if (::closedir(dir) != 0) { + MMI_HILOGE("Failed to closedir"); + } return pid; } @@ -115,7 +121,7 @@ int32_t CpuInfo::GetTaskPidCmd(const std::string &process_name, int32_t flag, st return DEFAULT_PID; } ::pclose(fp); - return ::atoi(buf); + return std::stoi(buf); } int32_t CpuInfo::GetProcOccupy(int32_t pid) @@ -195,14 +201,14 @@ double CpuInfo::GetSystemCpuUsage() int32_t ret = GetSystemCpuStatInfo(first); if (ret != RET_OK) { MMI_HILOGE("Failed to obtain CPU information, errcode:%{public}d", ret); - return CPU_USAGE_UNKONW; + return CPU_USAGE_UNKNOWN; } std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); Total_Cpu_Occupy second {}; ret = GetSystemCpuStatInfo(second); if (ret != RET_OK) { MMI_HILOGE("Failed to obtain CPU information, errcode:%{public}d", ret); - return CPU_USAGE_UNKONW; + return CPU_USAGE_UNKNOWN; } return GetCpuUsage(first, second); @@ -229,22 +235,22 @@ double CpuInfo::GetProcCpuUsage(const std::string &process_name) if ((totalTime1 = GetSystemTotalOccupy()) == RET_ERR) { MMI_HILOGE("Failed to obtain CPU occupy"); - return CPU_USAGE_UNKONW; + return CPU_USAGE_UNKNOWN; } if ((procTime1 = GetProcOccupy(pid)) == RET_ERR) { MMI_HILOGE("Failed to obtain process CPU information"); - return CPU_USAGE_UNKONW; + return CPU_USAGE_UNKNOWN; } std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); if ((totalTime2 = GetSystemTotalOccupy()) == RET_ERR) { MMI_HILOGE("Failed to obtain CPU occupy"); - return CPU_USAGE_UNKONW; + return CPU_USAGE_UNKNOWN; } if ((procTime2 = GetProcOccupy(pid)) == RET_ERR) { MMI_HILOGE("Failed to obtain process CPU information"); - return CPU_USAGE_UNKONW; + return CPU_USAGE_UNKNOWN; } return CHK_RATE(CPU_USAGE_MAX * (procTime2 - procTime1) / (totalTime2 - totalTime1)); diff --git a/tools/event_inject/BUILD.gn b/tools/event_inject/BUILD.gn index 03f2da866cd488f71a761eef4bce2a3bd9e30a83..7d44cd28d1c7f1cb9637532024c4fea6d991c09a 100644 --- a/tools/event_inject/BUILD.gn +++ b/tools/event_inject/BUILD.gn @@ -25,16 +25,6 @@ config("event_injection_config") { "//foundation/multimodalinput/input/util/common/include", "//foundation/multimodalinput/input/interfaces/native/innerkits/common/include", ] - - defines = [] - - if (input_feature_debug) { - defines += [ "OHOS_BUILD_MMI_DEBUG" ] - } - - if (input_feature_libinput) { - defines += [ "OHOS_BUILD_LIBINPUT" ] - } } config("event_injection_public_config") { @@ -48,24 +38,7 @@ config("event_injection_public_config") { } ohos_source_set("event-injection") { - sources = [ - "src/device_base.cpp", - "src/get_device_node.cpp", - "src/get_device_object.cpp", - "src/injection_event_dispatch.cpp", - "src/injection_tools_help_func.cpp", - "src/input_parse.cpp", - "src/manage_inject_device.cpp", - "src/processing_finger_device.cpp", - "src/processing_game_pad_device.cpp", - "src/processing_joystick_device.cpp", - "src/processing_keyboard_device.cpp", - "src/processing_mouse_device.cpp", - "src/processing_pad_device.cpp", - "src/processing_pen_device.cpp", - "src/processing_touch_screen_device.cpp", - "src/send_message.cpp", - ] + sources = event_injection_sources configs = [ ":event_injection_config", @@ -73,17 +46,14 @@ ohos_source_set("event-injection") { ] deps = [ + "//foundation/multimodalinput/input/patch/diff_libinput_mmi:libinput-third-mmi", "//foundation/multimodalinput/input/service/connect_manager:mmi_connect_manager_proxy", "//foundation/multimodalinput/input/service/filter:mmi_event_filter_service", "//foundation/multimodalinput/input/util:libmmi-util", - "//third_party/cJSON:cjson_static", + "//third_party/cJSON:cjson", ] - if (input_feature_libinput) { - deps += [ "//foundation/multimodalinput/input/patch/diff_libinput_mmi:libinput-third-mmi" ] - } - - external_deps = [ "ipc:ipc_core" ] + external_deps = [ "ipc:ipc_single" ] part_name = "input" subsystem_name = "multimodalinput" @@ -124,12 +94,9 @@ ohos_unittest("ut-event-injection-out") { "${mmi_path}/service/window_manager/include", "${mmi_path}/tools/event_inject/include", "${mmi_path}/uinput", + "$root_out_dir/diff_libinput_mmi/export_include", ] - if (input_feature_libinput) { - include_dirs += [ "$root_out_dir/diff_libinput_mmi/export_include" ] - } - sources = [ "test/device_base_test.cpp", "test/get_device_node_test.cpp", @@ -143,37 +110,23 @@ ohos_unittest("ut-event-injection-out") { "test/processing_pad_device_test.cpp", "test/processing_pen_device_test.cpp", "test/processing_touch_screen_device_test.cpp", - "test/send_message_test.cpp", ] - defines = [] - - if (input_feature_debug) { - defines += [ "OHOS_BUILD_MMI_DEBUG" ] - } - - if (input_feature_libinput) { - defines += [ "OHOS_BUILD_LIBINPUT" ] - } - deps = [ "${mmi_path}/frameworks/proxy:libmmi-client", "${mmi_path}/service:libmmi-server", "${mmi_path}/tools/event_inject:event-injection", "${mmi_path}/util:libmmi-util", - "//third_party/cJSON:cjson_static", + "//foundation/multimodalinput/input/patch/diff_libinput_mmi:libinput-third-mmi", + "//third_party/cJSON:cjson", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] - if (input_feature_libinput) { - deps += [ "//foundation/multimodalinput/input/patch/diff_libinput_mmi:libinput-third-mmi" ] - } - external_deps = [ "c_utils:utils", "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", + "ipc:ipc_single", ] } @@ -183,23 +136,11 @@ ohos_executable("mmi-event-injection") { configs = [ ":event_injection_public_config" ] deps = [ + "//foundation/multimodalinput/input/patch/diff_libinput_mmi:libinput-third-mmi", "//foundation/multimodalinput/input/tools/event_inject:event-injection", "//foundation/multimodalinput/input/util:libmmi-util", ] - if (input_feature_libinput) { - deps += [ "//foundation/multimodalinput/input/patch/diff_libinput_mmi:libinput-third-mmi" ] - } - defines = [] - - if (input_feature_debug) { - defines += [ "OHOS_BUILD_MMI_DEBUG" ] - } - - if (input_feature_libinput) { - defines += [ "OHOS_BUILD_LIBINPUT" ] - } - install_enable = true part_name = "input" subsystem_name = "multimodalinput" diff --git a/tools/event_inject/include/injection_event_dispatch.h b/tools/event_inject/include/injection_event_dispatch.h index 6fb1eda6e718e4a595843f3e4b0383c1984b66f7..9513dd70c8ac80dad238efd63e0d5b3dc2d913e4 100644 --- a/tools/event_inject/include/injection_event_dispatch.h +++ b/tools/event_inject/include/injection_event_dispatch.h @@ -44,8 +44,9 @@ public: int32_t GetDevTypeIndex(int32_t devIndex) const; int32_t GetDevIndexType(int32_t devType) const; int32_t GetDeviceIndex(const std::string &deviceNameText) const; + void SetArgvs(const std::vector &injectArgvs); std::string GetFunId() const; - bool VerifyArgvs(const int32_t &argc, const std::vector &argv); + bool VerifyArgvs(); bool RegisterInjectEvent(InjectFunctionMap &msg) { auto it = injectFuns_.find(msg.id); @@ -66,7 +67,6 @@ public: } private: std::string funId_ { "" }; - int32_t argvNum_ { 0 }; ManageInjectDevice manageInjectDevice_; std::vector injectArgvs_; std::map injectFuns_; diff --git a/tools/event_inject/include/injection_tools_help_func.h b/tools/event_inject/include/injection_tools_help_func.h index 51544b93a0f30a17b0bbf5474f1cd7199350baca..a2087e32176217aa09472d85a8bf4ad4e87a9fe5 100644 --- a/tools/event_inject/include/injection_tools_help_func.h +++ b/tools/event_inject/include/injection_tools_help_func.h @@ -27,8 +27,19 @@ namespace MMI { class InjectionToolsHelpFunc { public: InjectionToolsHelpFunc() = default; + ~InjectionToolsHelpFunc() = default; DISALLOW_COPY_AND_MOVE(InjectionToolsHelpFunc); - std::string GetHelpText(); + bool CheckInjectionCommand(int32_t argc, char **argv); + bool SelectOptions(int32_t argc, char **argv, int32_t &opt); + bool SendEventOption(int32_t argc, char **argv); + bool JsonOption(int32_t argc, char **argv); + bool HelpOption(int32_t argc, char **argv); + bool IsNumberic(const std::string &str); + void SetArgvs(int argc, char **argv, const std::string &str); + std::vector GetArgvs() const; + void ShowUsage(); +private: + std::vector injectArgvs_; }; } // namespace MMI } // namespace OHOS diff --git a/tools/event_inject/include/manage_inject_device.h b/tools/event_inject/include/manage_inject_device.h index f8ce4b851820d68c372070e880319ac6186c88af..e98605545a3dd55bbfddbfe1c197cef863e444fd 100644 --- a/tools/event_inject/include/manage_inject_device.h +++ b/tools/event_inject/include/manage_inject_device.h @@ -18,7 +18,6 @@ #include "get_device_object.h" #include "get_device_node.h" -#include "send_message.h" namespace OHOS { namespace MMI { @@ -30,7 +29,6 @@ public: int32_t TransformJsonData(const DeviceItems &configData); private: int32_t SendEvent(const InputEventArray &inputEventArray); - int32_t SendEventToHdi(const InputEventArray &inputEventArray); int32_t SendEventToDeviceNode(const InputEventArray &inputEventArray); private: GetDeviceNode getDeviceNodeObject_; diff --git a/tools/event_inject/jsonFiles/Test_TransformGamePadJsonDataToInputData.json b/tools/event_inject/jsonFiles/Test_TransformGamePadJsonDataToInputData.json index 00746ea4bcb3e4c436b75e4714a13a46536a1ef8..2ad707931bd3effc883fddac87bf62d7ed14d6b9 100644 --- a/tools/event_inject/jsonFiles/Test_TransformGamePadJsonDataToInputData.json +++ b/tools/event_inject/jsonFiles/Test_TransformGamePadJsonDataToInputData.json @@ -12,7 +12,7 @@ {"eventType": "KEY_EVENT_CLICK", "keyValue": 304}, {"eventType": "KEY_EVENT_CLICK", "keyValue": 305}, {"eventType": "KEY_EVENT_PRESS", "keyValue": 317}, - {"eventType": "KEY_EVENT_RELESE", "keyValue": 317}, + {"eventType": "KEY_EVENT_RELEASE", "keyValue": 317}, {"eventType": "KEY_EVENT_PRESS", "keyValue": 318}, {"eventType": "KEY_EVENT_RELEASE", "keyValue": 318}, {"eventType": "DIRECTION_KEY", "direction":"up"}, diff --git a/tools/event_inject/jsonFiles/Test_TransformJsonDataCheckFileNotEmpty.json b/tools/event_inject/jsonFiles/Test_TransformJsonDataCheckFileNotEmpty.json index 5b9af6b7e5adcead5fd89a6a0ebdc6bd0441e794..bd0cb059b2ec035a3e4fc3c5607ea3d0b45574f2 100644 --- a/tools/event_inject/jsonFiles/Test_TransformJsonDataCheckFileNotEmpty.json +++ b/tools/event_inject/jsonFiles/Test_TransformJsonDataCheckFileNotEmpty.json @@ -3,10 +3,10 @@ "deviceName": "mouse", "events":[ {"eventType": "KEY_EVENT_PRESS", "keyValue": 272}, - {"eventType": "KEY_EVENT_RELESE", "keyValue": 272}, + {"eventType": "KEY_EVENT_RELEASE", "keyValue": 272}, {"eventType": "KEY_EVENT_CLICK", "keyValue": 273}, {"eventType": "KEY_EVENT_PRESS", "keyValue": 274, "blockTime":1000 }, - {"eventType": "KEY_EVENT_RELESE", "keyValue": 274}, + {"eventType": "KEY_EVENT_RELEASE", "keyValue": 274}, {"eventType": "MOUSE_EVENT_MOVE", "xPos": 10, "yPos": -20}, {"eventType": "MOUSE_EVENT_MOVE", "xPos": -10, "yPos": 20}, {"eventType": "MOUSE_EVENT_WHEEL", "direction": "down", "distance": 20}, diff --git a/tools/event_inject/jsonFiles/Test_TransformJsonDataGetDeviceNodeError.json b/tools/event_inject/jsonFiles/Test_TransformJsonDataGetDeviceNodeError.json index 6272ec42a3447650f864517f9ec979c9795ecf30..54295606333dc773187a200edfbecd699cb1f315 100644 --- a/tools/event_inject/jsonFiles/Test_TransformJsonDataGetDeviceNodeError.json +++ b/tools/event_inject/jsonFiles/Test_TransformJsonDataGetDeviceNodeError.json @@ -3,10 +3,10 @@ "deviceName": "Mouse", "events":[ {"eventType": "KEY_EVENT_PRESS", "keyValue": 272}, - {"eventType": "KEY_EVENT_RELESE", "keyValue": 272}, + {"eventType": "KEY_EVENT_RELEASE", "keyValue": 272}, {"eventType": "KEY_EVENT_CLICK", "keyValue": 273}, {"eventType": "KEY_EVENT_PRESS", "keyValue": 274, "blockTime":1000 }, - {"eventType": "KEY_EVENT_RELESE", "keyValue": 274}, + {"eventType": "KEY_EVENT_RELEASE", "keyValue": 274}, {"eventType": "MOUSE_EVENT_MOVE", "xPos": 10, "yPos": -20}, {"eventType": "MOUSE_EVENT_MOVE", "xPos": -10, "yPos": 20}, {"eventType": "MOUSE_EVENT_WHEEL", "direction": "down", "distance": 20}, diff --git a/tools/event_inject/src/device_base.cpp b/tools/event_inject/src/device_base.cpp index e5de668ea181a18296eda39258b7e4780d21c16f..40ac6f9e497c2b16896f76c17f324e6c681e0540 100644 --- a/tools/event_inject/src/device_base.cpp +++ b/tools/event_inject/src/device_base.cpp @@ -15,8 +15,8 @@ #include "device_base.h" -using namespace OHOS::MMI; - +namespace OHOS { +namespace MMI { namespace { constexpr int32_t FIRST_FINGER = 1; constexpr int32_t SECOND_FINGER = 2; @@ -480,4 +480,6 @@ void DeviceBase::SetThrottle(InputEventArray& inputEventArray, int64_t blockTime injectEvent.event.value = value; SetTimeToLibinputEvent(injectEvent); inputEventArray.events.push_back(injectEvent); -} \ No newline at end of file +} +} // namespace MMI +} // namespace OHOS \ No newline at end of file diff --git a/tools/event_inject/src/get_device_node.cpp b/tools/event_inject/src/get_device_node.cpp index 663bd4b1df1fab37a6dab55e3e90056c1d8d13b1..057068d9d1d90ba191eaba6e0af06adc75863ac0 100644 --- a/tools/event_inject/src/get_device_node.cpp +++ b/tools/event_inject/src/get_device_node.cpp @@ -15,8 +15,8 @@ #include "get_device_node.h" -using namespace OHOS::MMI; - +namespace OHOS { +namespace MMI { namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "GetDeviceNode" }; const std::string DEVICES_INFO_PATH = "/proc/bus/input/devices"; @@ -131,4 +131,6 @@ void GetDeviceNode::AnalyseDevices(const std::vector &deviceStrs, D } } } -} \ No newline at end of file +} +} // namespace MMI +} // namespace OHOS \ No newline at end of file diff --git a/tools/event_inject/src/get_device_object.cpp b/tools/event_inject/src/get_device_object.cpp index 0d52fe6852b68af7c5b5e2b09288ad9fc74e0eec..43eadd8995e95826a4fe20daf331425bd1cd1bea 100644 --- a/tools/event_inject/src/get_device_object.cpp +++ b/tools/event_inject/src/get_device_object.cpp @@ -16,11 +16,11 @@ #include "get_device_object.h" #include +#include #include -#include - -using namespace OHOS::MMI; +namespace OHOS { +namespace MMI { namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "GetDeviceObject" }; bool IsKeyboardDevice(const std::string& deviceName) @@ -75,3 +75,5 @@ DeviceBase* GetDeviceObject::CreateDeviceObject(const std::string deviceName) return deviceBasePtr; } +} // namespace MMI +} // namespace OHOS diff --git a/tools/event_inject/src/injection_event_dispatch.cpp b/tools/event_inject/src/injection_event_dispatch.cpp index a552961a592610abfea7ed5839addaaaf8030a05..c912b7043e15e2ba733bcac5eefb762d1306c35e 100644 --- a/tools/event_inject/src/injection_event_dispatch.cpp +++ b/tools/event_inject/src/injection_event_dispatch.cpp @@ -23,9 +23,9 @@ #include #include "error_multimodal.h" +#include "input_parse.h" #include "proto.h" #include "util.h" -#include "input_parse.h" namespace OHOS { namespace MMI { @@ -36,7 +36,7 @@ constexpr uint32_t SEND_EVENT_DEV_NODE_INDEX = 1; constexpr uint32_t SEND_EVENT_TYPE_INDEX = 2; constexpr uint32_t SEND_EVENT_CODE_INDEX = 3; constexpr uint32_t SEND_EVENT_VALUE_INDEX = 4; -constexpr int32_t ARGVS_TARGET_INDEX = 1; +constexpr int32_t ARGVS_TARGET_INDEX = 0; constexpr int32_t ARGVS_CODE_INDEX = 2; constexpr int32_t JSON_FILE_PATH_INDEX = 1; constexpr uint32_t INPUT_TYPE_LENGTH = 3; @@ -52,6 +52,7 @@ void InjectionEventDispatch::Init() void InjectionEventDispatch::InitManageFunction() { + CALL_DEBUG_ENTER; InjectFunctionMap funs[] = { {"help", std::bind(&InjectionEventDispatch::OnHelp, this)}, {"sendevent", std::bind(&InjectionEventDispatch::OnSendEvent, this)}, @@ -87,37 +88,31 @@ int32_t InjectionEventDispatch::OnJson() return manageInjectDevice_.TransformJsonData(DataInit(jsonBuf, logStatus)); } +void InjectionEventDispatch::SetArgvs(const std::vector &injectArgvs) +{ + injectArgvs_ = injectArgvs; +} + std::string InjectionEventDispatch::GetFunId() const { return funId_; } -bool InjectionEventDispatch::VerifyArgvs(const int32_t &argc, const std::vector &argv) +bool InjectionEventDispatch::VerifyArgvs() { CALL_DEBUG_ENTER; - if (argc < ARGV_VALID || argv.at(ARGVS_TARGET_INDEX).empty()) { - MMI_HILOGE("Invalid Input Para, Please Check the validity of the para. errCode:%{public}d", PARAM_INPUT_FAIL); + std::string temp = injectArgvs_.at(ARGVS_TARGET_INDEX); + if (temp.empty()) { + MMI_HILOGE("Invalid Input parameter"); return false; } - - bool result = false; - for (const auto &item : injectFuns_) { - std::string temp(argv.at(ARGVS_TARGET_INDEX)); - if (temp == item.first) { - funId_ = temp; - result = true; - break; - } - } - if (result) { - injectArgvs_.clear(); - for (uint64_t i = 1; i < static_cast(argc); i++) { - injectArgvs_.push_back(argv[i]); - } - argvNum_ = argc - 1; + auto it = injectFuns_.find(temp); + if (it == injectFuns_.end()) { + MMI_HILOGE("Parameter bound function not found"); + return false; } - - return result; + funId_ = temp; + return true; } void InjectionEventDispatch::Run() @@ -159,8 +154,7 @@ int32_t InjectionEventDispatch::ExecuteFunction(std::string funId) int32_t InjectionEventDispatch::OnHelp() { InjectionToolsHelpFunc helpFunc; - std::string ret = helpFunc.GetHelpText(); - MMI_HILOGI("%{public}s", ret.c_str()); + helpFunc.ShowUsage(); return RET_OK; } diff --git a/tools/event_inject/src/injection_tools_help_func.cpp b/tools/event_inject/src/injection_tools_help_func.cpp index c4e8ac85e1bbdec35fc6ba00770449cc85b0d002..dcdb9ed84e5bb3c857b55c296800f2e71df38381 100644 --- a/tools/event_inject/src/injection_tools_help_func.cpp +++ b/tools/event_inject/src/injection_tools_help_func.cpp @@ -15,12 +15,185 @@ #include "injection_tools_help_func.h" +#include + +#include +#include #include -using namespace OHOS::MMI; +#include + +namespace OHOS { +namespace MMI { +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "InjectionToolsHelpFunc" }; +constexpr int32_t SEND_EVENT_ARGV_COUNTS = 6; +constexpr int32_t JSON_ARGV_COUNTS = 3; +constexpr int32_t HELP_ARGV_COUNTS = 2; +constexpr int32_t SHORT_OPTION_LENGTH = 2; +} // namespace + +bool InjectionToolsHelpFunc::CheckInjectionCommand(int32_t argc, char **argv) +{ + CALL_DEBUG_ENTER; + int32_t c = -1; + if (!SelectOptions(argc, argv, c)) { + MMI_HILOGE("Select option failed"); + return false; + } + switch (c) { + case 'S': { + if (!SendEventOption(argc, argv)) { + MMI_HILOGE("SendEvent option failed"); + return false; + } + break; + } + case 'J': { + if (!JsonOption(argc, argv)) { + MMI_HILOGE("Json option failed"); + return false; + } + break; + } + case '?': { + if (!HelpOption(argc, argv)) { + MMI_HILOGE("Help option failed"); + return false; + } + break; + } + default: { + std::cout << "invalid command" << std::endl; + return false; + } + } + return true; +} + +bool InjectionToolsHelpFunc::SelectOptions(int32_t argc, char **argv, int32_t &opt) +{ + CALL_DEBUG_ENTER; + if (argc < SHORT_OPTION_LENGTH) { + std::cout << "Please enter options or parameters" << std::endl; + return false; + } + struct option longOptions[] = { + {"sendevent", no_argument, NULL, 'S'}, + {"json", no_argument, NULL, 'J'}, + {"help", no_argument, NULL, '?'}, + {NULL, 0, NULL, 0} + }; + std::string inputOptions = argv[optind]; + if (inputOptions.find('-') == inputOptions.npos) { + for (uint32_t i = 0; i < sizeof(longOptions) / sizeof(struct option) - 1; ++i) { + if (longOptions[i].name == inputOptions) { + opt = longOptions[i].val; + optind++; + break; + } + } + } else if ((inputOptions.length() != SHORT_OPTION_LENGTH) && (inputOptions[inputOptions.find('-') + 1] != '-')) { + std::cout << "More than one short option is not supported" << std::endl; + return false; + } else { + int32_t optionIndex = 0; + opt = getopt_long(argc, argv, "SJ?", longOptions, &optionIndex); + } + if (opt == -1) { + std::cout << "Nonstandard input parameters" << std::endl; + return false; + } + return true; +} + +bool InjectionToolsHelpFunc::SendEventOption(int32_t argc, char **argv) +{ + CALL_DEBUG_ENTER; + if (argc != SEND_EVENT_ARGV_COUNTS) { + std::cout<< "Wrong number of input parameters" << std::endl; + return false; + } + std::string deviceNode = argv[optind]; + if (deviceNode.empty()) { + std::cout << "Device node does not exist: " << deviceNode.c_str() << std::endl; + return false; + } + char realPath[PATH_MAX] = {}; + if (realpath(deviceNode.c_str(), realPath) == nullptr) { + std::cout << "Device node path is error, path: " << deviceNode.c_str() << std::endl; + return false; + } + while (++optind < argc) { + std::string deviceInfo = argv[optind]; + if (!IsNumberic(deviceInfo)) { + std::cout << "Parameter is error, element: " << deviceInfo.c_str() << std::endl; + return false; + } + } + SetArgvs(argc, argv, "sendevent"); + return true; +} + +bool InjectionToolsHelpFunc::JsonOption(int32_t argc, char **argv) +{ + CALL_DEBUG_ENTER; + if (argc < JSON_ARGV_COUNTS) { + std::cout<< "Wrong number of input parameters" << std::endl; + return false; + } + const std::string jsonFile = argv[optind]; + std::string jsonBuf = ReadJsonFile(jsonFile); + if (jsonBuf.empty()) { + return false; + } + SetArgvs(argc, argv, "json"); + return true; +} + +bool InjectionToolsHelpFunc::HelpOption(int32_t argc, char **argv) +{ + CALL_DEBUG_ENTER; + if (argc != HELP_ARGV_COUNTS) { + std::cout<< "Wrong number of input parameters" << std::endl; + return false; + } + SetArgvs(argc, argv, "help"); + return true; +} + +bool InjectionToolsHelpFunc::IsNumberic(const std::string &str) +{ + return !str.empty() && std::all_of(str.begin(), str.end(), ::isdigit); +} + +void InjectionToolsHelpFunc::SetArgvs(int32_t argc, char **argv, const std::string &str) +{ + injectArgvs_.clear(); + injectArgvs_.push_back(str); + for (int32_t i = SHORT_OPTION_LENGTH; i < argc; ++i) { + injectArgvs_.push_back(argv[i]); + } +} + +std::vector InjectionToolsHelpFunc::GetArgvs() const +{ + return injectArgvs_; +} -std::string InjectionToolsHelpFunc::GetHelpText() +void InjectionToolsHelpFunc::ShowUsage() { - std::string ret = "\n Harmony device event injection ...\n\n"; - return ret; + std::cout << "Usage: mmi-event-injection