老李推荐:第14章6节《MonkeyRunner源码剖析》 HierarchyViewer实现原理-装备ViewServer-启动ViewServer...

老李推荐:第14章6节《MonkeyRunner源码剖析》 HierarchyViewer实现原理-装备ViewServer-启动ViewServer

 

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

在获得ViewServer的运行状态后,如果ViewServer还没有启动的话,HierarchyViewer的setupViewServer的下一步就会去启动ViewServer。调用的方法是DeviceBridge.startViewServer,我们进去看看:

 

190     public static boolean startViewServer(IDevice device) {  

191         return startViewServer(device, DEFAULT_SERVER_PORT);  

192     }  

代码14-6-1 DeviceBridge-startViewServer

 

传入的参数是ddmlib的Device类的一个实例,方法很简单,直接转发给startViewServer的另一个重载函数,并且增加多一个4939(DEFAULT_SERVER_PORT)的端口号作为参数:

 

193     public static boolean startViewServer(IDevice device, int port) {  

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

195         try {  

196             if (device.isOnline()) {  

197                 device.executeShellCommand(buildStartServerShellCommand(port),  

198                         new BooleanResultReader(result));  

199             }  

200         } catch (TimeoutException e) {  

...  

208         }  

209         return result[0];  

210     }  

代码14-6-2 DeviceBridge-startViewServer重载

 

流程跟上一小节发送”adb shell service call window 3”来查询ViewServer一样,都是先去组建命令字串,然后通过Device实例把这个命令给发出去,只是命令不一样而已。这里我们看下发送的是什么命令:

 

229     private static String buildStartServerShellCommand(int port) {  

230         return String.format("service call window %d i32 %d", SERVICE_CODE_START_SERVER, port); //$NON-NLS-1$  

231     }  

代码14-6-3 DeviceBridge - BuildStartServerShellCommand

 

其中 SERVICE_CODE_START_SERVER 全局变量是定义为1,所以可以看到最终组合的命令就是”service call window 1 i32 4939”最终结合Device的executeShellCommand命令就等于是发送”adb shell service call window 1 i32 4939”命令来启动ViewServer来监听4939端口了。这个命令我们在第13章也已经见识过了。

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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值