91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Monkey源碼分析番外篇之WindowManager注入事件如何跳出進程間安全限制

發布時間:2020-07-16 03:17:43 來源:網絡 閱讀:413 作者:zhukev 欄目:移動開發

在分析monkey源碼的時候有些背景知識沒有搞清楚,比如在看到monkey是使用windowmanager的injectKeyEvent方法注入事件的時候,心里就打了個疙瘩,這種方式不是只能在當前應用中注入事件嗎?Google了下發現了國外一個大牛有留下蛛絲馬跡描述這個問題,特意摘錄下來并做相應部分的翻譯,其他部分大家喜歡就看下,我就不翻譯了。

How it works

Behind the scenes, Monkey uses several private interfaces to communicate with three essential system services:

  1. Package Manager: Monkey uses the package manager to get a list of Activities for a given Intent. This enables Monkey to randomly switch between Activities while testing an application.
  2. Activity Manager: Monkey calls the very powerful setActivityController function on the Activity Manager. This effectively gives Monkey complete control over the activity life-cycle for the duration of the test.
  3. Window Manager: Monkey calls a series of functions on the Window Manager to inject events into the application. This enables Monkey to simulate touches and key-presses. Because Monkey communicates at this level, there is no obvious difference between events which have arrived from Monkey and events which have arrived from an actual user. In fact, the distinction is so seamless that it is sometimes necessary to manually check who is in control — hence the famous isUserAMonkey() method in the Android
Window Manager: Monkey通過調用WindowManager的一系列方法來注入事件到應用中。這樣monkey可以模擬觸摸和按鍵等用戶行為。正是因為monkey是在這個層面和應用交互的,所以你的應用接收到的事件哪個是來自真實用戶,哪個是來自monkey模擬的已經沒有很明顯的界限了。事實上正是因為這種近似無縫的區別,我們有時不得不去判斷究竟是誰在控制著我們的設備了--這就是為什么android系統提供的isUserAMonkey()方法變得這么流行的原因了。

Monkey sends random events to any application you choose. In order to ensure that this doesn’t cause a security hole, Android uses several techniques to ensure that only monkey can send events, and only when the phone’s user is asking it to.

Monkey隨機的往不同的的app發送隨機事件。為了防止這種行為導致android自家的安全漏洞出來,android使用了幾個技術來保證只有monkey可以,且在改手機設備用戶允許的情況下才可以,往不同的app發送事件。

Firstly, Monkey itself can only be run by root, or by someone in the “shell” Unix group. Normally, only “adb shell” runs as the “shell group”. This means that the only way to run monkey is to do so through “adb shell”.

首先,monkey本身只能一是被root運行,二是被屬于shell這個組的成員運行。而正常來說,只有”adb shell“是在shell這個組下運行的。這就意味著運行monkey的唯一方法就是通過‘adb shell’了。

Secondly, the Monkey application, which is mostly written in Java, asks for two special manifest permissions. The first, SET_ACTIVITY_WATCHER, allows Monkey to take control of the activity life-cycle. The second, INJECT_EVENTS, allows Monkey to simulate touches and key presses. Importantly, no normal Android application can request these permissions — they are only granted to applications supplied with the Android system. So there is little danger of a rogue APK taking control of an Android device using Monkey.

其次,monkey這個android自身提供的應用,大部分是用android的native語言java來編寫的,它會向系統請求兩個特背的manifest權限。第一個就是SET_ACTIVITY_WATCHER這個權限,它允許monkey對activity的生命周期進行全權控制。第二個就是INJECT_EVENTS這個權限它允許monkey去模擬觸摸和按鍵事件。重要的是,正常的安卓app是不能請求到這些權限的--只有android系統同意的應用才會得到允許獲得這些權限(譯者注:其實就是需要android系統的AOSP系統簽名。monkey是android自己維護編寫的工具,當然是允許了)

以下是本人摘錄的INJECT_EVENTS這個manifest選項的官方解析:

INJECT_EVENTS:Allows an application to inject user events (keys, touch, trackball) into the event stream and deliver them to ANY window.


Monkey events

What is an event? In Android, events are sent in  response to user input, or due to system events, such as power management. Monkey supports quite a few event types, but only three of them are of interest for automated testing:

  • KeyEvent: these events are sent by the window manager in response to hardware button presses, and also presses on the keyboard — whether hardware, or on-screen.
  • MotionEvent: sent by the window manager in response to presses on the touchscreen.
  • FlipEvent: sent when the user flips out the hardware keyboard on the HTC Dream. On that device, this would imply an orientation change. Unfortunately, Monkey does not simulate orientation changes on other devices.


 

作者

自主博客

微信

CSDN

天地會珠海分舵

http://techgogogo.com


服務號:TechGoGoGo

掃描碼:

Monkey源碼分析番外篇之WindowManager注入事件如何跳出進程間安全限制

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

北票市| 金塔县| 波密县| 贺州市| 手机| 民丰县| 靖州| 曲水县| 揭东县| 浦北县| 禹城市| 岳西县| 鄂伦春自治旗| 安阳市| 永和县| 大埔区| 万盛区| 尤溪县| 昆明市| 普陀区| 惠来县| 垫江县| 察隅县| 隆德县| 凉山| 长武县| 房产| 开鲁县| 元朗区| 波密县| 通许县| 呼玛县| 承德市| 琼结县| 彝良县| 宜州市| 法库县| 嘉义市| 灵璧县| 台北市| 固始县|