【Android】Google真能搞之 isUserAMonkey()

來源:互聯網
上載者:User

ActivityManager  類, 相信大家都不陌生。 從API Level 1開始就有了。

 

但是從Level 8開始, 驚喜的發現這裡面多了一個方法, 叫做 isUserAMonkey() 。 

 

初看該方法, 不明白到底什麼意思?  " 判斷使用者是否是只猴子" ? 不可能吧..

 

於是好奇的我開始查看SDK。

 

文檔上唯寫了 " Returns "true" if the user interface is currently being messed with by a monkey. "

 

-->  如果當前UI正在被一隻猴子瞎搞則返回 true .. ???

 

搞什麼飛機? 什麼意思?

 

於是好奇的我,又開始查看源碼!

 

源碼如下: 

[java] view
plaincopyprint?

  1. /** 
  2.  * Returns "true" if the user interface is currently being messed with 
  3.  * by a monkey. 
  4.  */  
  5. public static boolean isUserAMonkey() {  
  6.     try {  
  7.         return ActivityManagerNative.getDefault().isUserAMonkey();  
  8.     } catch (RemoteException e) {  
  9.     }  
  10.     return false;  
  11. }  

 

 

繼續,我又來到了 ActivityManagerNative 類中。

 

[java] view
plaincopyprint?

  1. public boolean isUserAMonkey() throws RemoteException {  
  2.     Parcel data = Parcel.obtain();  
  3.     Parcel reply = Parcel.obtain();  
  4.     data.writeInterfaceToken(IActivityManager.descriptor);  
  5.     mRemote.transact(IS_USER_A_MONKEY_TRANSACTION, data, reply, 0);  
  6.     reply.readException();  
  7.     boolean res = reply.readInt() != 0;  
  8.     data.recycle();  
  9.     reply.recycle();  
  10.     return res;  
  11. }  

 

 

明天再看.. 哈哈.. 撤了

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.