您好,登錄后才能下訂單哦!
在分析monkey源碼的時候有些背景知識沒有搞清楚,比如在看到monkey是使用windowmanager的injectKeyEvent方法注入事件的時候,心里就打了個疙瘩,這種方式不是只能在當前應用中注入事件嗎?Google了下發現了國外一個大牛有留下蛛絲馬跡描述這個問題,特意摘錄下來并做相應部分的翻譯,其他部分大家喜歡就看下,我就不翻譯了。
Behind the scenes, Monkey uses several private interfaces to communicate with three essential system services:
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:
作者 | 自主博客 | 微信 | CSDN |
天地會珠海分舵 | http://techgogogo.com | 服務號:TechGoGoGo 掃描碼:
| 向AI問一下細節 推薦閱讀:
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。 猜你喜歡最新資訊相關推薦相關標簽AI
助 手
上蔡县|
许昌县|
和静县|
莱阳市|
云浮市|
新建县|
四子王旗|
武川县|
广安市|
湛江市|
绥棱县|
科技|
延津县|
铜川市|
扶余县|
股票|
黑龙江省|
奎屯市|
盘山县|
高密市|
牟定县|
达日县|
乌苏市|
同德县|
安塞县|
文昌市|
老河口市|
西峡县|
资兴市|
驻马店市|
光山县|
铁力市|
花莲县|
宜君县|
长葛市|
连山|
太和县|
秦皇岛市|
灌阳县|
浑源县|
韶关市|
|