private static final Singleton<IActivityManager> gDefault = new Singleton<IActivityManager>() {
        protected IActivityManager create() {
        // 返回ActivityManagerService
            IBinder b = ServiceManager.getService("activity");
            if (false) {
                Log.v("ActivityManager", "default service binder = " + b);
            }
            IActivityManager am = asInterface(b);
            if (false) {
                Log.v("ActivityManager", "default service = " + am);
            }
            return am;
        }
};

static public IActivityManager getDefault() {
        return gDefault.get();
}

static public IActivityManager asInterface(IBinder obj) {
        if (obj == null) {
            return null;
        }
        // String descriptor = "android.app.IActivityManager";
        IActivityManager in = (IActivityManager)obj.queryLocalInterface(descriptor);
        if (in != null) {
            return in;
        }
        return new ActivityManagerProxy(obj);
}

ServiceManager.getService方法的返回值可以结合SystemServer.java进行对比查阅。在这里只关心asInterface方法的返回值,通过源代码可以发现,obj.queryLocalInterface将返回null,因此流程转向ActivityManagerProxy。

ActivityManagerProxy定义在 ActivityManagerNative.java文件中。

results matching ""

    No results matching ""