zoukankan      html  css  js  c++  java
  • monkey源代码分析之事件注入方法变化

    在上一篇文章《Monkey源代码分析之事件注入》中。我们看到了monkey在注入事件的时候用到了《Monkey源代码分析番外篇之Android注入事件的三种方法比較》中的第一种方法,通过Internal API的WindowManager的injectKeyEvent之类的方法注入事件。

    这样的方法在android api level 16也就是android4.1.2之后已经发生了变化:

    • 在此之后注入事件的方式变成了使用InputManager的injectInputEvent方法了
    • 而InputManager的getInstance和injectInputEvent等方法后来又变成了隐藏方法,详细哪个版本号我没有去查,但起码我如今在看的Android 4.4.2是这种
    • 相同,uiautomator使用的注入事件方法用的也是InputManager的injectInputEvent的方法,这我想就是为什么UIAutomator仅仅支持api level 16以后的android版本号了
    这里我们看下monkey在最新的版本号API Level 19(android 4.4.2)的注入事件代码。
    /*     */   public int injectEvent(IWindowManager iwm, IActivityManager iam, int verbose)
    /*     */   {
    /* 101 */     if (verbose > 1) { String note;
    /*     */       String note;
    /* 103 */       if (this.mAction == 1) {
    /* 104 */         note = "ACTION_UP";
    /*     */       } else {
    /* 106 */         note = "ACTION_DOWN";
    /*     */       }
    /*     */       try
    /*     */       {
    /* 110 */         System.out.println(":Sending Key (" + note + "): " + this.mKeyCode + "    // " + MonkeySourceRandom.getKeyName(this.mKeyCode));
    /*     */       }
    /*     */       catch (ArrayIndexOutOfBoundsException e)
    /*     */       {
    /* 114 */         System.out.println(":Sending Key (" + note + "): " + this.mKeyCode + "    // Unknown key event");
    /*     */       }
    /*     */     }
    /*     */     
    /*     */ 
    /* 119 */     KeyEvent keyEvent = this.mKeyEvent;
    /* 120 */     if (keyEvent == null) {
    /* 121 */       long eventTime = this.mEventTime;
    /* 122 */       if (eventTime <= 0L) {
    /* 123 */         eventTime = SystemClock.uptimeMillis();
    /*     */       }
    /* 125 */       long downTime = this.mDownTime;
    /* 126 */       if (downTime <= 0L) {
    /* 127 */         downTime = eventTime;
    /*     */       }
    /* 129 */       keyEvent = new KeyEvent(downTime, eventTime, this.mAction, this.mKeyCode, this.mRepeatCount, this.mMetaState, this.mDeviceId, this.mScanCode, 8, 257);
    /*     */     }
    /*     */     
    /*     */ 
    /* 133 */     if (!InputManager.getInstance().injectInputEvent(keyEvent, 1))
    /*     */     {
    /* 135 */       return 0;
    /*     */     }
    /* 137 */     return 1;
    /*     */   }
    /*     */ }
    能够看到最后的注入事件方法从原来的iwm.injectKeyEvent变成了如今的Inputmanager.getInstance().injectInputEvent方法了。


     

    作者

    自主博客

    微信

    CSDN

    天地会珠海分舵

    http://techgogogo.com


    服务号:TechGoGoGo

    扫描码:

    http://blog.csdn.net/zhubaitian





  • 相关阅读:
    php array_sum()函数 语法
    php array_splice()函数 语法
    php array_search()函数 语法
    php array_intersect()函数 语法
    php array_diff()函数 语法
    php array_slice()函数 语法
    php array_merge()函数 语法
    php array_chunk()函数 语法
    php array_fill()函数 语法
    php compact()函数 语法
  • 原文地址:https://www.cnblogs.com/blfshiye/p/5388737.html
Copyright © 2011-2022 走看看