zoukankan      html  css  js  c++  java
  • uiautomator 获取控件,点击的原理

    首先,找控件然后点击:

    new UiObject(By.selector(“test”)).click();

    第一步:调用getQueryController

    this.getQueryController().findAccessibilityNodeInfo(this.mUiSelector);

    第二步:获取getRootInActiveWindow,三层调用,最后通过mUiAutomation获取

    AccessibilityNodeInfo rootNode = this.getRootNode();
    this.mUiAutomatorBridge.getRootInActiveWindow();
    this.mUiAutomation.getRootInActiveWindow();

    第三步:selector和rootNode算法对比找到所需要的object

    this.translateCompoundSelector(uiSelector, rootNode, isCounting);

    第四步:object click

    public boolean click() throws UiObjectNotFoundException {
        Tracer.trace(new Object[0]);
        AccessibilityNodeInfo node = this.findAccessibilityNodeInfo(this.mConfig.getWaitForSelectorTimeout());
        if(node == null) {
            throw new UiObjectNotFoundException(this.mUiSelector.toString());
        } else {
            Rect rect = this.getVisibleBounds(node);
            return this.getInteractionController().clickAndSync(rect.centerX(), rect.centerY(), this.mConfig.getActionAcknowledgmentTimeout());
        }
    }

    第五步:调用InteractionController

    private Runnable clickRunnable(final int x, final int y) {
        return new Runnable() {
            public void run() {
                if(InteractionController.this.touchDown(x, y)) {
                    SystemClock.sleep(100L);
                    InteractionController.this.touchUp(x, y);
                }
    
            }
        };
    }

    第六步:转换成event,最后还是uiautomation 注入事件

    private boolean touchUp(int x, int y) {
        if(DEBUG) {
            Log.d(LOG_TAG, "touchUp (" + x + ", " + y + ")");
        }
    
        long eventTime = SystemClock.uptimeMillis();
        MotionEvent event = MotionEvent.obtain(this.mDownTime, eventTime, 1, (float)x, (float)y, 0);
        event.setSource(4098);
        this.mDownTime = 0L;
        return this.injectEventSync(event);
    }
    private boolean injectEventSync(InputEvent event) {
        return this.mUiAutomatorBridge.injectInputEvent(event, true);
    }
    public boolean injectInputEvent(InputEvent event, boolean sync) {
        return this.mUiAutomation.injectInputEvent(event, sync);
    }
  • 相关阅读:
    宋宝华:slab在内核内存管理和用户态Memcached的双重存在
    能感知功耗的Linux调度器(EAS)
    内存检测王者之剑—valgrind
    随心所动,厂商的CPU核管理策略介绍
    一文读懂 进程怎么绑定 CPU
    Fastbootd实现原理分析
    cachestat、cachetop、pcstat-linux系统缓存命中率分析工具
    WIFI的WPS和pin码(测试失败)
    视频下载(钉钉、B站等) 解决方案
    DevExpress 报表设计文件(.vsrepx)不显示或显示空白
  • 原文地址:https://www.cnblogs.com/season-xie/p/6341362.html
Copyright © 2011-2022 走看看