上一篇文章《UiAutomator源码分析之UiAutomatorBridge框架》中我们把UiAutomatorBridge以及它相关的类进行的描述,往下我们会尝试根据两个实例将这些类给串联起来,我准备做的是用如下两个很有代表性的实例:
/* */ UiAutomatorBridge(UiAutomation uiAutomation) /* */ { /* 48 */ this.mUiAutomation = uiAutomation; /* 49 */ this.mInteractionController = new InteractionController(this); /* 50 */ this.mQueryController = new QueryController(this); /* */ }
public boolean pressHome() { 218 Tracer.trace(); 219 waitForIdle(); 220 return getAutomatorBridge().getInteractionController().sendKeyAndWaitForEvent( 221 KeyEvent.KEYCODE_HOME, 0, AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED, 222 KEY_PRESS_EVENT_TIMEOUT); 223 }
/* */ public boolean sendKeyAndWaitForEvent(final int keyCode, final int metaState, int eventType, long timeout) /* */ { /* 188 */ Runnable command = new Runnable() /* */ { /* */ public void run() { /* 191 */ long eventTime = SystemClock.uptimeMillis(); /* 192 */ KeyEvent downEvent = new KeyEvent(eventTime, eventTime, 0, keyCode, 0, metaState, -1, 0, 0, 257); /* */ /* */ /* 195 */ if (InteractionController.this.injectEventSync(downEvent)) { /* 196 */ KeyEvent upEvent = new KeyEvent(eventTime, eventTime, 1, keyCode, 0, metaState, -1, 0, 0, 257); /* */ /* */ /* 199 */ InteractionController.this.injectEventSync(upEvent); /* */ } /* */ /* */ } /* 203 */ }; /* 204 */ return runAndWaitForEvents(command, new WaitForAnyEventPredicate(eventType), timeout) != null; /* */ }
/* */ private boolean injectEventSync(InputEvent event) { /* 655 */ return this.mUiAutomatorBridge.injectInputEvent(event, true); /* */ }
/* */ public boolean injectInputEvent(InputEvent event, boolean sync) { /* 70 */ return this.mUiAutomation.injectInputEvent(event, sync); /* */ }
/* */ private AccessibilityEvent runAndWaitForEvents(Runnable command, UiAutomation.AccessibilityEventFilter filter, long timeout) /* */ { /* */ try /* */ { /* 161 */ return this.mUiAutomatorBridge.executeCommandAndWaitForAccessibilityEvent(command, filter, timeout); /* */ } /* */ catch (TimeoutException e) { /* 164 */ Log.w(LOG_TAG, "runAndwaitForEvent timedout waiting for events"); /* 165 */ return null; /* */ } catch (Exception e) { /* 167 */ Log.e(LOG_TAG, "exception from executeCommandAndWaitForAccessibilityEvent", e); } /* 168 */ return null; /* */ }
/* */ public AccessibilityEvent executeCommandAndWaitForAccessibilityEvent(Runnable command, UiAutomation.AccessibilityEventFilter filter, long timeoutMillis) throws TimeoutException /* */ { /* 104 */ return this.mUiAutomation.executeAndWaitForEvent(command, filter, timeoutMillis); /* */ }
作者 | 自主博客 | 微信 | CSDN |
天地会珠海分舵 | http://techgogogo.com | 服务号:TechGoGoGo 扫描码: | 向AI问一下细节 免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。 猜你喜欢最新资讯相关推荐开发者交流群:相关标签AI
助 手 |
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>