AUTOLIST
线程阻塞,命令发送后,会等待viewserver反馈结果。viewserver在检测到界面跳转以后才会回馈结果。
private class WindowChangeMonitor implements Runnable { private IDevice device; public WindowChangeMonitor(IDevice device) { this.device = device; } public void run() { while (!Thread.currentThread().isInterrupted()) { DeviceConnection connection = null; try { connection = new DeviceConnection(this.device); connection.sendCommand("AUTOLIST"); String line; while ((!Thread.currentThread().isInterrupted()) && ((line = connection.getInputStream().readLine()) != null)) { if (line.equalsIgnoreCase("LIST UPDATE")) { } if (line.equalsIgnoreCase("FOCUS UPDATE")) { } show(line); } } catch (IOException e) { } finally { if (connection != null) connection.close(); } } } }
以上程序运行后,会一直等待,知道界面有跳转。反馈的结果有2种:LIST UPDATE和FOCUS UPATE。输出结果如下:
Appiot----------------LIST UPDATE Appiot----------------FOCUS UPDATE Appiot----------------LIST UPDATE Appiot----------------LIST UPDATE Appiot----------------LIST UPDATE
一个界面的跳转有一个FOCUS UPDATE事件触发,但是会触发若干LIST UPDATE事件。
GET_FOCUS
得到当前设备上显示的界面的activity。
在刚才代码的基础上,当检测到界面跳转时,获得跳转后的activity.
private class WindowChangeMonitor implements Runnable { private IDevice device; public WindowChangeMonitor(IDevice device) { this.device = device; } public void run() { while (!Thread.currentThread().isInterrupted()) { DeviceConnection connection = null; try { connection = new DeviceConnection(this.device); connection.sendCommand("AUTOLIST"); String line; while ((!Thread.currentThread().isInterrupted()) && ((line = connection.getInputStream().readLine()) != null)) { if (line.equalsIgnoreCase("LIST UPDATE")) { } if (line.equalsIgnoreCase("FOCUS UPDATE")) { getWindowId(); } show(line); } } catch (IOException e) { } finally { if (connection != null) connection.close(); } } } public void getWindowId(){ DeviceConnection connection = null; try { connection = new DeviceConnection(this.device); connection.sendCommand("GET_FOCUS"); String line; while ((!Thread.currentThread().isInterrupted()) && ((line = connection.getInputStream().readLine()) != null)) { show(line); } } catch (IOException e) { } finally { if (connection != null) connection.close(); } } }
输出结果:
Appiot----------------LIST UPDATE Appiot----------------42180858 com.sina.weibopro/com.sina.weibopro.DetailWeiboActivity Appiot----------------FOCUS UPDATE Appiot----------------LIST UPDATE Appiot----------------LIST UPDATE Appiot----------------LIST UPDATE
ViewServer接受hierarchyviewer的命令
时间: 2024-10-28 18:55:41