monkey源代码分析之事件注入方法变化
2016-04-13 20:50
309 查看
在上一篇文章《Monkey源代码分析之事件注入》中。我们看到了monkey在注入事件的时候用到了《Monkey源代码分析番外篇之Android注入事件的三种方法比較》中的第一种方法,通过Internal
API的WindowManager的injectKeyEvent之类的方法注入事件。
这样的方法在android api level 16也就是android4.1.2之后已经发生了变化:
在此之后注入事件的方式变成了使用InputManager的injectInputEvent方法了
而InputManager的getInstance和injectInputEvent等方法后来又变成了隐藏方法,详细哪个版本号我没有去查,但起码我如今在看的Android 4.4.2是这种
相同,uiautomator使用的注入事件方法用的也是InputManager的injectInputEvent的方法,这我想就是为什么UIAutomator仅仅支持api level 16以后的android版本号了
这里我们看下monkey在最新的版本号API Level 19(android 4.4.2)的注入事件代码。
API的WindowManager的injectKeyEvent之类的方法注入事件。
这样的方法在android api level 16也就是android4.1.2之后已经发生了变化:
在此之后注入事件的方式变成了使用InputManager的injectInputEvent方法了
而InputManager的getInstance和injectInputEvent等方法后来又变成了隐藏方法,详细哪个版本号我没有去查,但起码我如今在看的Android 4.4.2是这种
相同,uiautomator使用的注入事件方法用的也是InputManager的injectInputEvent的方法,这我想就是为什么UIAutomator仅仅支持api level 16以后的android版本号了
这里我们看下monkey在最新的版本号API Level 19(android 4.4.2)的注入事件代码。
/* */ public int injectEvent(IWindowManager iwm, IActivityManager iam, int verbose) /* */ { /* 101 */ if (verbose > 1) { String note; /* */ String note; /* 103 */ if (this.mAction == 1) { /* 104 */ note = "ACTION_UP"; /* */ } else { /* 106 */ note = "ACTION_DOWN"; /* */ } /* */ try /* */ { /* 110 */ System.out.println(":Sending Key (" + note + "): " + this.mKeyCode + " // " + MonkeySourceRandom.getKeyName(this.mKeyCode)); /* */ } /* */ catch (ArrayIndexOutOfBoundsException e) /* */ { /* 114 */ System.out.println(":Sending Key (" + note + "): " + this.mKeyCode + " // Unknown key event"); /* */ } /* */ } /* */ /* */ /* 119 */ KeyEvent keyEvent = this.mKeyEvent; /* 120 */ if (keyEvent == null) { /* 121 */ long eventTime = this.mEventTime; /* 122 */ if (eventTime <= 0L) { /* 123 */ eventTime = SystemClock.uptimeMillis(); /* */ } /* 125 */ long downTime = this.mDownTime; /* 126 */ if (downTime <= 0L) { /* 127 */ downTime = eventTime; /* */ } /* 129 */ keyEvent = new KeyEvent(downTime, eventTime, this.mAction, this.mKeyCode, this.mRepeatCount, this.mMetaState, this.mDeviceId, this.mScanCode, 8, 257); /* */ } /* */ /* */ /* 133 */ if (!InputManager.getInstance().injectInputEvent(keyEvent, 1)) /* */ { /* 135 */ return 0; /* */ } /* 137 */ return 1; /* */ } /* */ }能够看到最后的注入事件方法从原来的iwm.injectKeyEvent变成了如今的Inputmanager.getInstance().injectInputEvent方法了。
作者 | 自主博客 | 微信 | CSDN |
天地会珠海分舵 | http://techgogogo.com | 服务号:TechGoGoGo 扫描码: | http://blog.csdn.net/zhubaitian |
相关文章推荐
- JAVA内部类总结
- python解决SNIMissingWarning和InsecurePlatformWarning警告
- 【dp】【codeforces】 451D Count Good Substrings
- 安卓使用代码得到当前程序的版本号和版本名
- 安卓使用代码安装Apk
- JavaWeb——基于过滤器的用户权限控制
- eclipse 上使用recycleview,cardview的办法
- ubuntu 14.04 java开发环境搭建 jdk 以及 inteliJ IDEA安装
- 【C++】输入输出运算符的重载
- Windows下Python,setuptools,pip,virtualenv的安装
- C++笔记
- python循环语句
- java中用中国网建提供的SMS短信平台发送短信
- 0基础学C#教程2--------C#如何调用excel,试用最新版的excel
- FindBugs插件的安装与使用
- javanio 实现socket通信
- ASP.Net 验证正则表达式
- java集合框架05——ArrayList和LinkedList的区别
- 如何在浏览器中debug-谷歌浏览器(Google Chrome )
- Windows下C语言单线程socket通信