多态的背后
来源:互联网 发布:百度淘宝店面图片素材 编辑:程序博客网 时间:2024/05/21 07:25
1、Activity中:
private Window mWindow = null;
mWindow = getWindow();
Log.d(tag, "mWindow.getClass().getName() is: " + mWindow.getClass().getName());
D/MainActivity( 437): mWindow.getClass().getName() is: com.android.internal.policy.impl.PhoneWindow
2、Activity中:
private WindowManager mWindowManager = null;
mWindowManager = getWindowManager();
Log.d(tag, "mWindowManager.getClass().getName() is: " + mWindowManager.getClass().getName());
D/MainActivity( 437): mWindowManager.getClass().getName() is: android.view.Window$LocalWindowManager
3、ServiceManager(java)中:
private IServiceManager mISM = null;
mISM = ServiceManager.getIServiceManager();
Log.d(tag, "mISM.toString() is: " + mISM.toString());
Log.d(tag, "mISM.getClass().getName() is: " + mISM.getClass().getName());
D/ServiceManager002Activity( 712): mISM.toString() is: android.os.ServiceManagerProxy@40f169f0
D/ServiceManager002Activity( 712): mISM.getClass().getName() is: android.os.ServiceManagerProxy
4、Context.ACTIVITY_SERVICE
IBinder activity = ServiceManager.getService(Context.ACTIVITY_SERVICE);
Log.d(tag, "activity.toString() is: " + activity.toString());
Log.d(tag, "activity.getClass().getName() is: " + activity.getClass().getName());
D/ServiceManager002Activity( 712): activity.toString() is: android.os.BinderProxy@40f16a80
D/ServiceManager002Activity( 712): activity.getClass().getName() is: android.os.BinderProxy
5、Context.ALARM_SERVICE
IBinder alarm = ServiceManager.getService(Context.ALARM_SERVICE);
Log.d(tag, "alarm.toString() is: " + alarm.toString());
Log.d(tag, "alarm.getClass().getName() is: " + alarm.getClass().getName());
D/ServiceManager002Activity( 712): alarm.toString() is: android.os.BinderProxy@40f18228
D/ServiceManager002Activity( 712): alarm.getClass().getName() is: android.os.BinderProxy
6、Context.INPUT_METHOD_SERVICE
IBinder input_method = ServiceManager.getService(Context.INPUT_METHOD_SERVICE);
Log.d(tag, "input_method.toString() is: " + input_method.toString());
Log.d(tag, "input_method.getClass().getName() is: " + input_method.getClass().getName());
D/ServiceManager002Activity( 712): input_method.toString() is: android.os.BinderProxy@40f4a7b0
D/ServiceManager002Activity( 712): input_method.getClass().getName() is: android.os.BinderProxy
7、Context.POWER_SERVICE
IBinder power = ServiceManager.getService(Context.POWER_SERVICE);
Log.d(tag, "power.toString() is: " + power.toString());
Log.d(tag, "power.getClass().getName() is: " + power.getClass().getName());
D/ServiceManager002Activity( 712): power.toString() is: android.os.BinderProxy@40f34c38
D/ServiceManager002Activity( 712): power.getClass().getName() is: android.os.BinderProxy
8、Context.WINDOW_SERVICE
IBinder window = ServiceManager.getService(Context.WINDOW_SERVICE);
Log.d(tag, "window.toString() is: " + window.toString());
Log.d(tag, "window.getClass().getName() is: " + window.getClass().getName());
D/ServiceManager002Activity( 712): window.toString() is: android.os.BinderProxy@40f180a0
D/ServiceManager002Activity( 712): window.getClass().getName() is: android.os.BinderProxy
ServiceManager.getService()函数的源码为如下:
public static IBinder getService(String name)
{
try
{
IBinder service = sCache.get(name);
if (service != null)
{
return service;
}
else
{
return getIServiceManager().getService(name);
}
}
catch (RemoteException e)
{
Log.e(TAG, "error in getService", e);
}
return null;
}
该函数中又调用:getIServiceManager().getService(name);
private static IServiceManager getIServiceManager()
{
if (sServiceManager != null)
{
return sServiceManager;
}
// Find the service manager
sServiceManager = ServiceManagerNative.asInterface(BinderInternal.getContextObject());
return sServiceManager;
}
通过Point 3可以知道getIServiceManager的返回值是 android.os.ServiceManagerProxy类型的,
调用 android.os.ServiceManagerProxy的getService函数:
public IBinder getService(String name) throws RemoteException {
Parcel data = Parcel.obtain();
Parcel reply = Parcel.obtain();
data.writeInterfaceToken(IServiceManager.descriptor);
data.writeString(name);
mRemote.transact(GET_SERVICE_TRANSACTION, data, reply, 0);
IBinder binder = reply.readStrongBinder();
reply.recycle();
data.recycle();
return binder;
}
该代理会与ServiceManager的Server部分进行通信。
9、BinderInternal.getContextObject()
private IBinder mIBinder = null;
mIBinder = BinderInternal.getContextObject();
Log.d(tag, "mIBinder.toString() is: " + mIBinder.toString());
Log.d(tag, "mIBinder.getClass().getName() is: " + mIBinder.getClass().getName());
D/ActivityManagerNative002Activity( 743): mIBinder.toString() is: android.os.BinderProxy@40f17310
D/ActivityManagerNative002Activity( 743): mIBinder.getClass().getName() is: android.os.BinderProxy
10、ServiceManagerProxy的成员变量:mRemote
Log.d(tag, "remote.toString() is: " + remote.toString());
Log.d(tag, "remote.getClass().getName() is: " + remote.getClass().getName());
D/ServiceManager002Activity( 730): remote.toString() is: android.os.BinderProxy@40f14c80
D/ServiceManager002Activity( 730): remote.getClass().getName() is: android.os.BinderProxy
mRemote的值与ServiceManager中调用BinderInternal.getContextObject()的返回值是一致的:
ServiceManager中:ServiceManagerNative.asInterface(BinderInternal.getContextObject())
ServiceManagerNative中:new ServiceManagerProxy(obj) obj是BinderInternal.getContextObject()的返回值
ServiceManagerProxy中:mRemote = remote remote是ServiceManagerProxy构造函数的参数
因此,mRemote实际就是BinderInternal.getContextObject()的返回值
- 多态的背后
- 对多态变形引擎背后方法的概述
- 用户界面背后的理论
- 字符串黑箱的背后
- 强暴背后的故事
- 金卡的背后
- 跳槽背后的管理学
- 丁香花背后的故事
- 李世民背后的女人
- 李世民背后的女人
- 李彦宏背后的蜘蛛侠
- Linux背后的人
- 不公平的背后..
- Linux背后的人
- 问题背后的问题
- 火灾的背后是什么?
- 论四核“冲动”的背后
- 不公平的背后..
- 软件项目流程
- linux-2.6.32.2打yaffs2补丁时出错:bash: ./patch-ker.sh: Permission denied
- 祝贺热火
- 解决Tomcat Error listenerStart 问题
- [KMP模板题]HDU-1711 Number Sequence
- 多态的背后
- htc获取root权限和刷机
- 扫雷第一步,先戳哪里最高效?
- Reactive Extensions (Rx) 入门(4) —— Rx的事件编程②
- FTP的两种连接模式
- 平均需要扔多少次硬币才能够得到连续2个正面
- 【设计模式】为别人做嫁衣 --- 代理模式
- (7)EJB3.0 EJB开发消息驱动bean 【经典】 JMS
- perl学习(一)