10.4 android输入系统_框架、编写一个万能模拟输入驱动程序、reader/dispatcher线程启动过程源码分析
1. 输入系统框架
android输入系统官方文档 // 需FQ
http://source.android.com/devices/input/index.html
《深入理解Android 卷III》第五章 深入理解Android输入系统 // 主要讲EventHub
http://blog.csdn.net/innost/article/details/47660387
图解Android - Android GUI 系统 (5) - Android的Event Input System - 漫天尘沙 - 博客园.htm // 关注里面的Dispatcher处理流程
http://www.cnblogs.com/samchen2009/p/3368158.html
输入系统可分为三部分:
(1)读取(linux驱动(生成设备节点)、APP处理(open/read设备节点、监测有无数据及热拔插、处理(比如映射)))
a、支持多设备:GPIO键盘(/dev/input/event0)、红外遥控器(/dev/input/event1)、USB键盘鼠标、触摸屏
b、即插即用
c、多语言:同一键盘同一按键在不同语言下得到不同字符,因此存在映射
(2)分发
a、分辨:对于按键分为systemkey(音量、电源)、Globalkey(特殊键:启动一个应用程序)、UserKey(发给应用程序);对于触摸屏分为VirtualKey、手势(两个手指放大缩小)
b、发送:找到当前APP,发给他
(3)处理
APP收到后,处理
点击动作:执行某系函数
输入框:启动输入法或者直接生成文字
android系统代码框架:

2. 编写一个万能模拟输入驱动程序
测试方法:
android系统中范问evdev驱动获得输入系统的原始数据
/dev/input/event1,2这个设备节点是通过evdev驱动创建的
对于鼠标设备,可以通过访问/dev/input/event获得鼠标的原始数据,也可以通过访问/dev/mouse1,2....得到加工后的鼠标数据
怎么写输入驱动:
(1)分配/构造input_device结构体
(2)注册input_register_device后和evdev、keyboard、mouse上层框架建立联系
(3)有输入事件产生时,中断程序通过input_event上报数据
总结输入流程
APP:
d、open("/dev/input/event5")
f、read
驱动
(1)evdev.c
c、注册input的时候如果支持调用evdev的connect函数来创建设备节点
e、evdev_open被调用,并与input_dev建立联系
g、evdev_read被调用,无数据会休眠
j、input_event会调用evdev中的某个函数把数据放入buf,并唤醒休眠的进程
(2)硬件相关
a、构造input_dev
b、注册input_register_device
i、中断服务创新被调用,input_event被调用
(3)硬件
h、用户按下按键,产生中断
inputemulator.c
static struct input_dev *input_emulator_dev;
static int input_emulator_init(void)
{
int i;
input_emulator_dev = input_allocate_device();
//设置能产生哪类事情
set_bit(EV_KEY,input_emulator_dev->evbit);
set_bit(EV_REP,input_emulator_dev->evbit);
//设置能产生所有的按键事件
for(i=0;i<BITS_TO_LONGS(KEY_CNT);i++)
input_emulator_dev->keybit[i] = ~0UL;
//为android构造一些设备信息
input_emulator_dev ->name = "InputEmulatorFrom100ask.net";
input_emulator_dev ->id.bustype =1;
input_emulator_dev ->id.vendor = 0x1234;
input_emulator_dev ->id.product = 0x5678;
input_emulator_dev ->id.version = 1;
//注册
input_register_device(input_emulator_dev);
return 0;
}
static void input_emulator_exit(void)
{
input_unregister_device(input_emulator_dev);
input_free_device(input_emulator_dev);
}
module_init(input_emulator_init);
module_exit(input_emulator_exit);
MODULE_LICENSE("GPL");
Makefile:
LERN_DIR = /work/linux-3.0.86
all:
make -C $(KERN_DIR) M=‘pwd’ modules
clean:
make -C $(KERN_DIR) M=‘pwd’ modules clean
rm -rf modules.order
obj-m += InputEmulator .o
安装驱动后:使用sendevent指令开上报数据给指定的input设备
sendevent /dev/input/event5 1 2 1 // 1 2 1 : EV_KEY, KEY_1, down
sendevent /dev/input/event5 1 2 0 // 1 2 0 : EV_KEY, KEY_1, up
sendevent /dev/input/event5 0 0 0 // sync
sendevent /dev/input/event5 1 3 1
sendevent /dev/input/event5 1 3 0
sendevent /dev/input/event5 0 0 0
3. reader/dispatcher线程启动过程源码分析
涉及使用bouml制作时序图,先看 第0课第3节:使用bouml制作时序图
uml_tmp_file.rar
reader线程监控输入系统的设备节点,dispatcher线程负责分发,这两个线程由InputManagerService创建
InputReaderThread实例化对象mReaderTHread,其里面调用threadLoop循环;mReaderTHread只是创建线程,实现循环,在循环操作中用到mReader对象的函数
InputDispatcherThread实例化对象mDispatcherTHread,其里面调用threadLoop循环;mDispatcherTHread只是创建线程,实现循环,在循环操作中用到mDispatcher对象的函数
因此主进程还要创建两个实例化对象InputReader类对象mReader、InputDispatcher对象mDispatcher
还有个重要的EventHub类,其实例化对象时mEventHub,用这个对象监控输入设备
上述所有类使用InputManager类的mInputManager对象来管理,并且都是用C++实现的
Java层次通过JNI NativeInputManager来访问C++ InputManager
InputManager = new InputManagerService(context)//SystemServer.java
nativeInit();//在构造函数中通过JNI调用C++中的方法
nativeInit(JNIEnv*env,jclass clazz)//com_android_server_input_InputManagerService.cpp
NativeInputManager* im = new NativeInputManager(contextObj)
eventHub = new EventHub()//在NativeInputManager的构造函数中
eEpollFd = epoll_create(EPOLL_SIZE_HINT);
mInotify = inotify_init();
mInputManager = new InputManager(eventHub,this,this)
mDispatcher = new InputDispatcher(dispatcherPolicy)//dispatcherPolicy=im
mReader = new InputReader(eventHub,readerPolicy,mDispatcher)readerPolicy=im
mEventHub = .....
mPolicy = im
mQueuedListener = new QueuedInputListener(listener)
initialize()
mReaderThread = new InputReaderThread(mReader)
mDispatcherThread = new InputDispatcherTHread(mDispatcher)
inputManager.start()
nativeStart()
im->getInputManager()->start()
mDispatcherThread->run()
mReaderThread->run()

10.4 android输入系统_框架、编写一个万能模拟输入驱动程序、reader/dispatcher线程启动过程源码分析的更多相关文章
- 10.11 android输入系统_补充知识_activity_window_decor_view关系
android里:1个application, 有1个或多个activity(比如支付宝有:首页.财富.口碑.朋友.我的,这些就是activity)1个activity, 有1个window(每个ac ...
- 10.8 android输入系统_实战_使用GlobalKey一键启动程序
11. 实战_使用GlobalKey一键启动程序参考文章:Android 两种注册(动态注册和静态注册).发送广播的区别http://www.jianshu.com/p/ea5e233d9f43 [A ...
- 10.13 android输入系统_多点触摸驱动理论与框架
1.多点触摸驱动理论 驱动程序仅上报多个触点的位置就可以,是放大还是缩小由应用程序控制 对于多点触摸驱动在linux系统中有个输入子系统,其已经实现了open/read/write等接口 我们只需要实 ...
- 10.14 android输入系统_多点触摸驱动测试及Reader线程、InputStage分析
21. 多点触摸_电容屏驱动程序_实践_tiny4412 tiny4412触摸屏: 分辨率为800 x 480http://wiki.friendlyarm.com/wiki/index.php/LC ...
- Android系统默认Home应用程序(Launcher)的启动过程源码分析
在前面一篇文章中,我们分析了Android系统在启动时安装应用程序的过程,这些应用程序安装好之后,还须要有一个Home应用程序来负责把它们在桌面上展示出来,在Android系统中,这个默认的Home应 ...
- Android Content Provider的启动过程源码分析
本文參考Android应用程序组件Content Provider的启动过程源码分析http://blog.csdn.net/luoshengyang/article/details/6963418和 ...
- Activity启动过程源码分析(Android 8.0)
Activity启动过程源码分析 本文来Activity的启动流程,一般我们都是通过startActivity或startActivityForResult来启动目标activity,那么我们就由此出 ...
- 10.5 android输入系统_Reader线程_使用EventHub读取事件和核心类及配置文件_实验_分析
4. Reader线程_使用EventHub读取事件 使用inotify监测/dev/input下文件的创建和删除 使用epoll监测有无数据上报 细节: a.fd1 = inotify_init(& ...
- 10.1、android输入系统_必备Linux编程知识_inotify和epoll
1. inotify和epoll 怎么监测键盘接入与拔出? (1)hotplug机制:内核发现键盘接入/拔出==>启动hotplug进程==>发消息给输入系统 (2)inotify机制:输 ...
随机推荐
- Python: PS 滤镜-- Fish lens
本文实现 PS 滤镜中的一种几何变换– Fish lens, 对图像做扭曲,感觉就像通过一个凸镜或者凹镜在观察图像一样. import numpy as np from skimage import ...
- 3.常用Bracket插件
转自:https://blog.csdn.net/iso_wsy/article/details/52608205 1.Emmet 如果你从事Web前端开发的话,对该插件一定不会陌生.它可以加快你的 ...
- | 插件下载陈磊SQL MD5 加密
简介:SQL MD5 加密 下述是 SQL Server 中 MD5加密 16位和32位的 ,)) ,ModifiedOn=null ; ,)) ,ModifiedOn=null ;
- IBM磁盘阵列及文件系统的管理
一.几个基本概念 物理卷(PV):一个物理卷指一块硬盘 卷组(VG):卷组是可用物理硬盘的集合,可以逻辑地看成一块大硬盘 物理分区(PP):卷组中物理卷划分成固定大小的块(缺省为4MB) 逻辑卷(LV ...
- 相似group by的分组计数功能
之前同事发过一个语句,实现的功能比較简单,相似group by的分组计数功能,由于where条件有like,又无法用group by来实现. SELECT a.N0,b.N1,c.N2,d.N3,e. ...
- IK分词器插件elasticsearch-analysis-ik 6.1.1
http://88250.b3log.org/full-text-search-elasticsearch#b3_solo_h3_0 IK分词器插件 (1)源码 https://github.com/ ...
- java产生随机数的三种方式
转自:https://blog.csdn.net/YTTmiao/article/details/78187448 随机数在实际中使用很广泛,比如要随即生成一个固定长度的字符串.数字.或者随即生成一个 ...
- error: function declaration isn’t a prototype [-Werror=strict-prototypes]
"warning: function declaration isn't a prototype" was caused by the function like that: ...
- Codeforces Round #194 (Div. 2) 部分题解
http://codeforces.com/contest/334 A题意:1-n^2 平均分成 n 份,每份n个数,且和相同 解法 : 构造矩阵1-n^2的矩阵即可 ][]; int main() ...
- php学习笔记5
PHP 常量 常量值被定义后,在脚本的其他任何地方都不能被改变. 一个常量由英文字母.下划线.和数字组成,但数字不能作为首字母出现. (常量名不需要加 $ 修饰符). 注意: 常量在整个脚本中都可以使 ...