Android4.3的新类UiAutomationConnection

来源:互联网 发布:植物大战僵尸2淘宝存档 编辑:程序博客网 时间:2024/04/27 17:02
Android4.3上,Google的开发者新增了一个类UiAutomationConnection,它目前用在Instrumentation test中,控制某些操作的权限。
 
 
代码解释是这样说的:
 
UiAutomationConnection是一个远程对象,它从shell中传递给Instrumentation,用于控制某些特权操作,使得这些操作shell可以做,但Instrumentation不能做。这些特权操作需要实现UiAutomation,用来通过模拟用户动作和执行屏幕检测来实现跨应用的测试。
 
 
这里的shell实际上就是运行am.jar的进程,当用户通过shell命令运行一个测试,例如:
 
adb shell am instrument -e class com.android.browserpowertest.PowerMeasurement#myTest1 -w com.android.browserpowertest/com.android.browserpowertest.PowerTestRunner
 
这样就会在手机上启动一个shell进程,它将调用runInstrument来触发测试过程。
 
 
下面是4个时序图(中间用绿色横条分隔),分别描述的是:
 
1. 启动测试,shell创建UiAutomationConnection对象,并通过AMS传递给TestApp.
 
2. 测试完成后退出的过程。
 
3. TestApp调用connect.
 
4. TestApp调用disconnect.
 
 
从图中发现:UiAutomationConnection的对象是在shell进程中创建,调用它的成员函数,如connect或disconnect都是跨进程的远程调用(通过binder)。
转载来源:http://www.2cto.com/kf/201311/256188.html
0 0