AIDL 源码窥探
2015-10-23 16:04
411 查看
AIDL 源码窥探
ITelephony.adil:
是一个接口,定义了方法,操作的数据是基本数据类型
interface ITelephony { void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, double aDouble, String aString); void method(); }
ITelephony.java :
会由IDE自动生成的java文件.
ITelephony接口:继承了系统的IInterface接口
public interface ITelephony extends android.os.IInterface {....}
IInterface 接口:
public interface IInterface { public IBinder asBinder(); }
Stub抽象内部类(在ITelephony接口中):继承了Binder和ITelephony接口
public static abstract class Stub extends android.os.Binder implements com.android.internal.telephony.ITelephony{ asBinder() //return this; !!! asInterface(android.os.IBinder obj) //创建了一个new Proxy (obj)并返回 !!!! }
Proxy代理类(在Stub中):持有Stub,并实现了ITelephony接口,通过它(代理类)调用Stub对象的方法。
private static class Proxy implements com.android.internal.telephony.ITelephony { private android.os.IBinder mRemote; Proxy(android.os.IBinder remote) { mRemote = remote; // } asBinder() //return mRemote; }
服务端:
在实现的Service子类中 : 返回一个继承Binder,实现AIDL接口的Stub对象
@Override public IBinder onBind(Intent intent) { return new ITelephony.Stub() {...实现方法...}; }
客户端: 将mBinder(由服务端创建返回)转换成一个AIDL的接口对象(代理类对象)。
ITelephony telephonyService = ITelephony.Stub.asInterface(mBinder);
所有的Manager,都是通过ServiceManager获取到IBinder,然后让所有的Manager包装这个IBinder而成的。而ServiceManager里有两个成员:IServiceManager sServiceManager 和 HashMap sCache ,由此可以对IBinder进行添加,获取等操作
I开头的都是AIDL文件。服务端:返回实现的 IBinder 对象,new IAIDL.Stub( ){....}
客户端:对返回的IBinder对象转成代理使用,IAIDL.Stub.asInterface(mIBinder)
ActivityManager:
IUsageStats usageStatsService = IUsageStats.Stub.asInterface( ServiceManager.getService("usagestats")
TelephonyManager:
ITelephonyRegistry.Stub.asInterface (ServiceManager.getService( "telephony.registry")
DevicePolicyManager:
IDevicePolicyManager.Stub.asInterface( ServiceManager.getService(device_policy)
相关文章推荐
- explain分析查询
- IIS runs out of work items and causes RPC failures when connecting to a remote UNC path
- int main(int argc,char* argv[])详解
- Mac下通过proxychains-ng配置thunderbird来访问gmail
- FIFA 16 comes in with FIFA trainer that will try
- liunx 下scp出现 Permission denied, please try again 的解决办法
- hive环境搭建 Terminal initialization failed; falling back to unsupported 解决
- lucene Lock obtain timed out: Lock@
- Afaira服务器上报错NDEF invalid "Operation" tag
- A Detailed Introduction to K-Nearest Neighbor (KNN) Algorithm
- 运行报错“Could not find a storyboard named 'Main' in bundle”
- 当人工智能机器人具有七情六欲
- Fast-Fail、ConcurrentModificationException 、CopyOnWriteArrayList
- @property中,retain,assign,copy的差别
- MRC 循环retain的问题
- Delete Duplicate Emails
- <BEA-000386> <Server subsystem failed. Reason: weblogic.security.SecurityInitializationException: Au
- fast incremental backup failed on standby database
- Daily Scrum (2015/10/22)
- HDU 4460 Friend Chains -多源最短路裸题