Android4.3的新类UiAutomationConnection

(转载请注明原文地址:http://blog.csdn.net/while0/article/details/14450765

在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.


Android4.3的新类UiAutomationConnection_第1张图片


 从图中发现:UiAutomationConnection的对象是在shell进程中创建,调用它的成员函数,如connect或disconnect都是跨进程的远程调用(通过binder)。



你可能感兴趣的:(Instrumentation)