ActivityManager 类, 相信大家都不陌生。 从API Level 1开始就有了。
但是从Level 8开始, 惊喜的发现这里面多了一个方法, 叫做 isUserAMonkey() 。
初看该方法, 不明白到底什么意思? " 判断用户是否是只猴子" ? 不可能吧..
于是好奇的我开始查看SDK。
文档上只写了 " Returns "true" if the user interface is currently being messed with by a monkey. "
--> 如果当前UI正在被一只猴子瞎搞则返回 true .. ???
搞什么飞机? 什么意思?
于是好奇的我,又开始查看源码!
源码如下:
/** * 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 类中。
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; }
明天再看.. 哈哈.. 撤了