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?
- /**
- * Returns "true" if the user interface is currently being messed with
- * by a monkey.
- */
- public static boolean isUserAMonkey() {
- try {
- return ActivityManagerNative.getDefault().isUserAMonkey();
- } catch (RemoteException e) {
- }
- return false;
- }
繼續,我又來到了 ActivityManagerNative 類中。
[java] view
plaincopyprint?
- public boolean isUserAMonkey() throws RemoteException {
- Parcel data = Parcel.obtain();
- Parcel reply = Parcel.obtain();
- data.writeInterfaceToken(IActivityManager.descriptor);
- mRemote.transact(IS_USER_A_MONKEY_TRANSACTION, data, reply, 0);
- reply.readException();
- boolean res = reply.readInt() != 0;
- data.recycle();
- reply.recycle();
- return res;
- }
明天再看.. 哈哈.. 撤了