RK Android7.1 禁用 USB触摸
一.
二.禁用触摸
2.1.\frameworks\native\services\inputflinger\EventHub.h
EventHub->getEvents(),获取输入事件和设备增删事件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | /* * Input device classes. */ enum { /* The input device is a keyboard or has buttons. */ INPUT_DEVICE_CLASS_KEYBOARD = 0x00000001 , /* The input device is an alpha-numeric keyboard (not just a dial pad). */ INPUT_DEVICE_CLASS_ALPHAKEY = 0x00000002 , /* The input device is a touchscreen or a touchpad (either single-touch or multi-touch). */ INPUT_DEVICE_CLASS_TOUCH = 0x00000004 , /* The input device is a cursor device such as a trackball or mouse. */ INPUT_DEVICE_CLASS_CURSOR = 0x00000008 , /* The input device is a multi-touch touchscreen. */ INPUT_DEVICE_CLASS_TOUCH_MT = 0x00000010 , /* The input device is a directional pad (implies keyboard, has DPAD keys). */ INPUT_DEVICE_CLASS_DPAD = 0x00000020 , /* The input device is a gamepad (implies keyboard, has BUTTON keys). */ INPUT_DEVICE_CLASS_GAMEPAD = 0x00000040 , /* The input device has switches. */ INPUT_DEVICE_CLASS_SWITCH = 0x00000080 , /* The input device is a joystick (implies gamepad, has joystick absolute axes). */ INPUT_DEVICE_CLASS_JOYSTICK = 0x00000100 , /* The input device has a vibrator (supports FF_RUMBLE). */ INPUT_DEVICE_CLASS_VIBRATOR = 0x00000200 , /* The input device has a mouse. */ INPUT_DEVICE_CLASS_KEYMOUSE = 0x00000400 , /* The input device has a microphone. */ INPUT_DEVICE_CLASS_MIC = 0x00000400 , /* The input device is an external stylus (has data we want to fuse with touch data). */ INPUT_DEVICE_CLASS_EXTERNAL_STYLUS = 0x00000800 , /* The input device has a rotary encoder */ INPUT_DEVICE_CLASS_ROTARY_ENCODER = 0x00001000 , /* The input device is virtual (not a real device, not part of UI configuration). */ INPUT_DEVICE_CLASS_VIRTUAL = 0x40000000 , /* The input device is external (not built-in). */ INPUT_DEVICE_CLASS_EXTERNAL = 0x80000000 , }; |
2.2.frameworks\native\services\inputflinger\EventHub.cpp Mapper只处理一次 不能根据属性同步
触摸
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | --- a/frameworks/ native /services/inputflinger/EventHub.cpp +++ b/frameworks/ native /services/inputflinger/EventHub.cpp @@ - 1199 , 7 + 1199 , 10 @@ status_t EventHub::openDeviceLocked( const char *devicePath) { device->classes |= INPUT_DEVICE_CLASS_ROTARY_ENCODER; } } - + char usb_touch [PROPERTY_VALUE_MAX]; + int usb_touch_flag = 0 ; + property_get( "persist.sys.UsbTouch" , usb_touch, "0" ); + usb_touch_flag = strtol(usb_touch, 0 , 0 ); // See if this is a touch pad. // Is this a new modern multi-touch driver? if (test_bit(ABS_MT_POSITION_X, device->absBitmask) @@ - 1208 , 13 + 1211 , 21 @@ status_t EventHub::openDeviceLocked( const char *devicePath) { // with the ABS_MT range. Try to confirm that the device really is // a touch screen. if (test_bit(BTN_TOUCH, device->keyBitmask) || !haveGamepadButtons) { - device->classes |= INPUT_DEVICE_CLASS_TOUCH | INPUT_DEVICE_CLASS_TOUCH_MT; + device->classes |= INPUT_DEVICE_CLASS_TOUCH | INPUT_DEVICE_CLASS_TOUCH_MT; + if (usb_touch_flag){ + ALOGD( "gatsby INPUT_DEVICE_CLASS_TOUCH INPUT_DEVICE_CLASS_TOUCH_MT" ); + return - 1 ; + } } // Is this an old style single-touch driver? } else if (test_bit(BTN_TOUCH, device->keyBitmask) && test_bit(ABS_X, device->absBitmask) && test_bit(ABS_Y, device->absBitmask)) { - device->classes |= INPUT_DEVICE_CLASS_TOUCH; + device->classes |= INPUT_DEVICE_CLASS_TOUCH; + if (usb_touch_flag){ + ALOGD( "gatsby INPUT_DEVICE_CLASS_TOUCH" ); + return - 1 ; + } // Is this a BT stylus? } else if ((test_bit(ABS_PRESSURE, device->absBitmask) || test_bit(BTN_TOUCH, device->keyBitmask)) |
键盘
device->classes |= INPUT_DEVICE_CLASS_KEYBOARD | INPUT_DEVICE_CLASS_KEYMOUSE;
鼠标
device->classes |= INPUT_DEVICE_CLASS_CURSOR;
2.3.frameworks\native\services\inputflinger\InputReader.cpp 多点触摸屏处理函数 处理数据上报
输入系统 InputReader
- 键盘类设备:KeyboardInputMapper
- 触摸屏设备:MultiTouchInputMapper或SingleTouchInputMapper
- 鼠标类设备:CursorInputMapper
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | --- a/frameworks/ native /services/inputflinger/InputReader.cpp +++ b/frameworks/ native /services/inputflinger/InputReader.cpp @@ - 85 , 6 + 85 , 9 @@ static const nsecs_t STYLUS_DATA_LATENCY = ms2ns( 10 ); static const int KEYCODE_ENTER = 28 ; static const int KEYCODE_DPAD_CENTER = 232 ; + static char usb_touch [PROPERTY_VALUE_MAX]; + static int usb_touch_flag = 0 ; + // --- Static Functions --- template<typename T> @@ - 1739 , 6 + 1742 , 10 @@ void MultiTouchMotionAccumulator::clearSlots(int32_t initialSlot) { } void MultiTouchMotionAccumulator::process( const RawEvent* rawEvent) { + //ALOGD("gatsby MultiTouchMotionAccumulator"); + property_get( "persist.sys.UsbTouch" , usb_touch, "0" ); + usb_touch_flag = strtol(usb_touch, 0 , 0 ); + if (usb_touch_flag){ if (rawEvent->type == EV_ABS) { bool newSlot = false ; if (mUsingSlotsProtocol) { @@ - 1821 , 6 + 1828 , 7 @@ void MultiTouchMotionAccumulator::process( const RawEvent* rawEvent) { // MultiTouch Sync: The driver has returned all data for *one* of the pointers. mCurrentSlot += 1 ; } +} } |
三.禁用鼠标
3.1.鼠标、触摸休眠唤醒
mCursorButtonAccumulator.process(rawEvent);//按键
mCursorMotionAccumulator.process(rawEvent);//移动
mCursorScrollAccumulator.process(rawEvent);//滚动
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | --- a/frameworks/ native /services/inputflinger/InputReader.cpp +++ b/frameworks/ native /services/inputflinger/InputReader.cpp @@ - 85 , 6 + 85 , 9 @@ static const nsecs_t STYLUS_DATA_LATENCY = ms2ns( 10 ); static const int KEYCODE_ENTER = 28 ; static const int KEYCODE_DPAD_CENTER = 232 ; + static char usb_mouse [PROPERTY_VALUE_MAX]; + static int usb_mouse_flag = 0 ; + // --- Static Functions --- template<typename T> @@ - 2622 , 6 + 2625 , 11 @@ void CursorInputMapper::reset(nsecs_t when) { } void CursorInputMapper::process( const RawEvent* rawEvent) { + property_get( "persist.sys.UsbMouse" , usb_mouse, "0" ); + usb_mouse_flag = strtol(usb_mouse, 0 , 0 ); + //ALOGD("gatsby CursorInputMapper %d",usb_mouse_flag); + if (!usb_mouse_flag){ + //ALOGD("gatsby CursorInputMapperxxxxx %d",usb_mouse_flag); mCursorButtonAccumulator.process(rawEvent); mCursorMotionAccumulator.process(rawEvent); mCursorScrollAccumulator.process(rawEvent); @@ - 2629 , 6 + 2637 , 7 @@ void CursorInputMapper::process( const RawEvent* rawEvent) { if (rawEvent->type == EV_SYN && rawEvent->code == SYN_REPORT) { sync(rawEvent->when); } + } } void CursorInputMapper::sync(nsecs_t when) { @@ - 3372 , 7 + 3381 , 8 @@ void TouchInputMapper::configureParameters() { // Initial downs on external touch devices should wake the device. // Normally we don't do this for internal touch screens to prevent them from waking // up in your pocket but you can enable it using the input device configuration. - mParameters.wake = getDevice()->isExternal(); + //mParameters.wake = getDevice()->isExternal(); + mParameters.wake = 0 ; getDevice()->getConfiguration().tryGetProperty(String8( "touch.wake" ), mParameters.wake); } |
3.2.异常 init.rc里面的服务老是重启
[ 3.434014] init: Service 'inputflinger' (pid 226) killed by signal 6
[ 3.434052] init: Service 'inputflinger' (pid 226) killing any children in process group
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | [ 2.837536 ] init: Starting service 'inputflinger' ... [ 2.838752 ] init: Starting service 'installd' ... [ 2.839252 ] init: Starting service 'keystore' ... [ 2.845439 ] init: Starting service 'mediacodec' ... [ 2.845861 ] init: Starting service 'mediadrm' ... [ 2.848736 ] init: Starting service 'mediaextractor' ... [ 2.851013 ] init: Starting service 'media' ... [ 2.855864 ] init: Starting service 'netd' ... [ 2.856386 ] init: Service 'rootservice' (pid 217 ) exited with status 0 [ 2.856576 ] init: Starting service 'gatekeeperd' ... [ 2.864264 ] logd.daemon: reinit [ 2.871770 ] rk_gmac-dwmac ff290000.ethernet: rk_get_eth_addr: mac address: 3e:6e: 85 : 07 :a7:0e [ 2.871786 ] eth0: device MAC address 3e:6e: 85 : 07 :a7:0e [ 2.872398 ] init: Starting service 'perfprofd' ... [ 2.872895 ] init: Service 'logd-reinit' (pid 202 ) exited with status 0 [ 2.873057 ] init: Service 'akmd' (pid 221 ) exited with status 254 [ 2.910133 ] ret = ffffffff [ 2.910574 ] init: Service 'up_eth0' (pid 220 ) exited with status 0 [ 2.914185 ] init: Service 'drmservice' (pid 219 ) exited with status 0 [ 2.945194 ] capability: warning: `daemonsu' uses 32 -bit capabilities (legacy support in use) [ 2.946996 ] init: Untracked pid 233 exited with status 0 [ 3.034081 ] read descriptors [ 3.034182 ] read strings [ 3.034962 ] pcd_pullup, is_on 1 [ 3.226907 ] EXT4-fs (mmcblk2p10): re-mounted. Opts: ( null ) [ 3.231591 ] random: nonblocking pool is initialized [ 3.434014 ] init: Service 'inputflinger' (pid 226 ) killed by signal 6 [ 3.434052 ] init: Service 'inputflinger' (pid 226 ) killing any children in process group |
3.3.优化
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | --- a/frameworks/ native /services/inputflinger/InputReader.cpp +++ b/frameworks/ native /services/inputflinger/InputReader.cpp @@ - 85 , 6 + 85 , 9 @@ static const nsecs_t STYLUS_DATA_LATENCY = ms2ns( 10 ); static const int KEYCODE_ENTER = 28 ; static const int KEYCODE_DPAD_CENTER = 232 ; + static char usb_mouse [PROPERTY_VALUE_MAX]; + static int usb_mouse_flag = 0 ; + // --- Static Functions --- template<typename T> @@ - 1260 , 6 + 1263 , 7 @@ void CursorButtonAccumulator::clearButtons() { } void CursorButtonAccumulator::process( const RawEvent* rawEvent) { + if (!usb_mouse_flag){ if (rawEvent->type == EV_KEY) { switch (rawEvent->code) { case BTN_LEFT: @@ - 1292 , 6 + 1296 , 7 @@ void CursorButtonAccumulator::process( const RawEvent* rawEvent) { break ; } } + } } uint32_t CursorButtonAccumulator::getButtonState() const { @@ - 1334 , 6 + 1339 , 7 @@ void CursorMotionAccumulator::clearRelativeAxes() { } void CursorMotionAccumulator::process( const RawEvent* rawEvent) { + if (!usb_mouse_flag){ if (rawEvent->type == EV_REL) { switch (rawEvent->code) { case REL_X: @@ - 1344 , 6 + 1350 , 7 @@ void CursorMotionAccumulator::process( const RawEvent* rawEvent) { break ; } } + } } void CursorMotionAccumulator::finishSync() { @@ - 1373 , 6 + 1380 , 7 @@ void CursorScrollAccumulator::clearRelativeAxes() { } void CursorScrollAccumulator::process( const RawEvent* rawEvent) { + if (!usb_mouse_flag){ if (rawEvent->type == EV_REL) { switch (rawEvent->code) { case REL_WHEEL: @@ - 1383 , 6 + 1391 , 7 @@ void CursorScrollAccumulator::process( const RawEvent* rawEvent) { break ; } } + } } void CursorScrollAccumulator::finishSync() { @@ - 2622 , 6 + 2631 , 9 @@ void CursorInputMapper::reset(nsecs_t when) { } void CursorInputMapper::process( const RawEvent* rawEvent) { + property_get( "persist.sys.UsbMouse" , usb_mouse, "0" ); + usb_mouse_flag = strtol(usb_mouse, 0 , 0 ); + //ALOGD("gatsby CursorInputMapper %d",usb_mouse_flag); mCursorButtonAccumulator.process(rawEvent); mCursorMotionAccumulator.process(rawEvent); mCursorScrollAccumulator.process(rawEvent); @@ - 3372 , 7 + 3384 , 8 @@ void TouchInputMapper::configureParameters() { // Initial downs on external touch devices should wake the device. // Normally we don't do this for internal touch screens to prevent them from waking // up in your pocket but you can enable it using the input device configuration. - mParameters.wake = getDevice()->isExternal(); + //mParameters.wake = getDevice()->isExternal(); + mParameters.wake = 0 ; getDevice()->getConfiguration().tryGetProperty(String8( "touch.wake" ), mParameters.wake); } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】