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线程启动过程源码分析的更多相关文章

  1. 10.11 android输入系统_补充知识_activity_window_decor_view关系

    android里:1个application, 有1个或多个activity(比如支付宝有:首页.财富.口碑.朋友.我的,这些就是activity)1个activity, 有1个window(每个ac ...

  2. 10.8 android输入系统_实战_使用GlobalKey一键启动程序

    11. 实战_使用GlobalKey一键启动程序参考文章:Android 两种注册(动态注册和静态注册).发送广播的区别http://www.jianshu.com/p/ea5e233d9f43 [A ...

  3. 10.13 android输入系统_多点触摸驱动理论与框架

    1.多点触摸驱动理论 驱动程序仅上报多个触点的位置就可以,是放大还是缩小由应用程序控制 对于多点触摸驱动在linux系统中有个输入子系统,其已经实现了open/read/write等接口 我们只需要实 ...

  4. 10.14 android输入系统_多点触摸驱动测试及Reader线程、InputStage分析

    21. 多点触摸_电容屏驱动程序_实践_tiny4412 tiny4412触摸屏: 分辨率为800 x 480http://wiki.friendlyarm.com/wiki/index.php/LC ...

  5. Android系统默认Home应用程序(Launcher)的启动过程源码分析

    在前面一篇文章中,我们分析了Android系统在启动时安装应用程序的过程,这些应用程序安装好之后,还须要有一个Home应用程序来负责把它们在桌面上展示出来,在Android系统中,这个默认的Home应 ...

  6. Android Content Provider的启动过程源码分析

    本文參考Android应用程序组件Content Provider的启动过程源码分析http://blog.csdn.net/luoshengyang/article/details/6963418和 ...

  7. Activity启动过程源码分析(Android 8.0)

    Activity启动过程源码分析 本文来Activity的启动流程,一般我们都是通过startActivity或startActivityForResult来启动目标activity,那么我们就由此出 ...

  8. 10.5 android输入系统_Reader线程_使用EventHub读取事件和核心类及配置文件_实验_分析

    4. Reader线程_使用EventHub读取事件 使用inotify监测/dev/input下文件的创建和删除 使用epoll监测有无数据上报 细节: a.fd1 = inotify_init(& ...

  9. 10.1、android输入系统_必备Linux编程知识_inotify和epoll

    1. inotify和epoll 怎么监测键盘接入与拔出? (1)hotplug机制:内核发现键盘接入/拔出==>启动hotplug进程==>发消息给输入系统 (2)inotify机制:输 ...

随机推荐

  1. [欧拉回路] poj 1386 Play on Words

    题目链接: http://poj.org/problem?id=1386 Play on Words Time Limit: 1000MS   Memory Limit: 10000K Total S ...

  2. android-从官网下拉源码(ubuntu)

    今天终于成功的从谷歌官网上下载了android 源码.中间折腾了好久,最终总算有所收获 1.下载repo curl https://storage.googleapis.com/git-repo-do ...

  3. zoj 1119 / poj 1523 SPF (典型例题 求割点 Tarjan 算法)

    poj : http://poj.org/problem?id=1523 如果无向图中一个点 u 为割点 则u 或者是具有两个及以上子女的深度优先生成树的根,或者虽然不是一个根,但是它有一个子女 w, ...

  4. vue 打包成 apk 文件(修改路径)

    第一个坑:文件引用路径 现在项目我们什么都没动,是初始化之后直接打包的状态,打开dist/index.htmnl文件整个网页都是一片空白的. 爬坑: 打开 config文件夹/index.js文件 a ...

  5. ajax ---- json 和 xml 区别

    2.XML和JSON优缺点 (1).XML的优缺点<1>.XML的优点 A.格式统一,符合标准: B.容易与其他系统进行远程交互,数据共享比较方便.<2>.XML的缺点 A.X ...

  6. Gym 100952 F. Contestants Ranking

    http://codeforces.com/gym/100952/problem/F F. Contestants Ranking time limit per test 1 second memor ...

  7. Intellij IDEA 部署Web项目,解决 404 错误

    https://blog.csdn.net/eaphyy/article/details/72513914

  8. 使用spring-boot 国际化配置所碰到的乱码问题

    写好html静态页面 ,  也加上了编码格式 , 获取国际化展示在浏览器中还是存在乱码 , 开始以为是浏览器编码格式问题 , 做过处理后任没有得到解决 , 具体的处理方案如下: <meta ht ...

  9. 用for和while循环求e的值[e=1+1/1!+1/2!+1/3!+1/4!+1/5!+...+1/n!]

    /*编敲代码,依据下面公式求e的值. 要求用两种方法计算: 1)for循环.计算前50项 2)while循环,直至最后一项的值小于10-4 e=1+1/1!+1/2!+1/3!+1/4!+1/5!+. ...

  10. Impala是什么?

    Impala是Cloudera公司主导开发的新型查询系统,它提供SQL语义,能查询存储在Hadoop的HDFS和HBase中的PB级大数据.已有的Hive系统虽然也提供了SQL语义,但由于Hive底层 ...