老李推荐:第14章5节《MonkeyRunner源码剖析》 HierarchyViewer实现原理-装备ViewServer-查询ViewServer运行状态...

老李推荐:第14章5节《MonkeyRunner源码剖析》 HierarchyViewer实现原理-装备ViewServer-查询ViewServer运行状态

 

    poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标。如果对课程感兴趣,请大家咨询qq:908821478,咨询电话010-84505200。

上一小节我们描述了HierarchyViewer是如何组建ADB协议命令来实现ViewServer的端口转发的,在端口转发设置好后,下一个要做的事情就是去检测目标设备端ViewServer线程是否已经启动起来了。我们进入setupViewServer调用的DeviceBridge的isViewServerRunning方法:

 165     public static boolean isViewServerRunning(IDevice device) {  

166         final boolean[] result = new boolean[1];  

167         try {  

168             if (device.isOnline()) {  

169                 device.executeShellCommand(buildIsServerRunningShellCommand(),  

170                         new BooleanResultReader(result));  

171                 if (!result[0]) {  

172                     ViewServerInfo serverInfo = loadViewServerInfo(device);  

173                     if (serverInfo != null && serverInfo.protocolVersion > 2) {  

174                         result[0] = true;  

175                     }  

176                 }  

177             }  

178         } catch (TimeoutException e) {  

               ...  

187         }  

188         return result[0];  

189     }  

代码14-5-1 DeviceBridge - isViewServerRunning

 

关键代码是上面的169行,通过Device类的实例来往ADB服务器发送相应的命令来检测ViewServer是否已经在运行。

device.executeShellCommand在前面章节已经分析过了,就是用来发送”adb shell”命令的。

我们看下buildIsServerRunningShellCommand方法,看这个命令是如何组织起来的:

 

235     private static String buildIsServerRunningShellCommand() {  236         return String.format("service call window %d", SERVICE_CODE_IS_SERVER_RUNNING);   

237     }  

代码14-5-2 DeviceBridge - buildIsServerRunningShellCommand

 

而全局变量 SERVICE_CODE_IS_SERVER_RUNNING 的定义是:

 48     private static final int DEFAULT_SERVER_PORT = 4939;  

49     // These codes must match the auto-generated codes in IWindowManager.java  

50     // See IWindowManager.aidl as well  

51     private static final int SERVICE_CODE_START_SERVER = 1;  

52     private static final int SERVICE_CODE_STOP_SERVER = 2;  

53     private static final int SERVICE_CODE_IS_SERVER_RUNNING = 3;  

 

代码14-5-3 DeviceBridge - 全局变量示例

 

236行整出来的这一串不就是”service call window 3”嘛。所以结合device.sendShellCommand,事实上就是往设备发送了命令”adb shell service call window 3”,上一章我们才用它来查询ViewServer的运行状态了!

转载于:https://www.cnblogs.com/poptest/p/5099792.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值