monkey源码分析之事件注入方法变化

发布时间:2020-08-13 08:46:50 作者:zhukev
来源:网络 阅读:223

在上一篇文章《Monkey源码分析之事件注入》中,我们看到了monkey在注入事件的时候用到了《Monkey源码分析番外篇之Android注入事件的三种方法比较》中的第一种方法,通过Internal API的WindowManager的injectKeyEvent之类的方法注入事件。这种方法在android api level 16也就是android4.1.2之后已经发生了变化:

这里我们看下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

扫描码:

monkey源码分析之事件注入方法变化

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》