aidl深度解析
2016-03-11 16:28
519 查看
本文是aidl自动生成的java类的解析,让你更加清晰的了解aidl
上一张自己画的UML图
:
上一张自己画的UML图
:
然后根据图看下面的一个aidl自动生成的java类: public interface ISizeAidlInterface extends android.os.IInterface { /** * Local-side IPC implementation stub class. */ public static abstract class Stub extends android.os.Binder implements com.easou.iris.aidltestnew.ISizeAidlInterface { private static final java.lang.String DESCRIPTOR = "com.easou.iris.aidltestnew.ISizeAidlInterface";//本aidl的标识 /** * Construct the stub at attach it to the interface. * 构造函数里给本Stub设置标识 */ public Stub() { this.attachInterface(this, DESCRIPTOR); } /** * Cast an IBinder object into an com.easou.iris.aidltestnew.ISizeAidlInterface interface, * generating a proxy if needed. * 把IBinder对象转换成ISizeAidlInterface接口,根绝情况使用代理类Proxy */ public static com.easou.iris.aidltestnew.ISizeAidlInterface asInterface(android.os.IBinder obj) { if ((obj == null)) { return null; } android.os.IInterface iin = obj.queryLocalInterface(DESCRIPTOR);//根据标识查询是否是本地进程,不是本地的话返回null if (((iin != null) && (iin instanceof com.easou.iris.aidltestnew.ISizeAidlInterface))) { return ((com.easou.iris.aidltestnew.ISizeAidlInterface) iin); } return new com.easou.iris.aidltestnew.ISizeAidlInterface.Stub.Proxy(obj);//!☆ 跨进程调用,使用代理,把实际的Binder对象传入 } @Override public android.os.IBinder asBinder() {//绑定Binder是返回的IBinder对象 return this; } /** *执行方法时参数顺序。 */ @Override public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException { switch (code) { case INTERFACE_TRANSACTION: { reply.writeString(DESCRIPTOR); return true; } case TRANSACTION_setSize: { data.enforceInterface(DESCRIPTOR); int _arg0; _arg0 = data.readInt(); this.setSize(_arg0); reply.writeNoException(); return true; } case TRANSACTION_getSize: { data.enforceInterface(DESCRIPTOR); int _result = this.getSize(); reply.writeNoException(); reply.writeInt(_result); return true; } } return super.onTransact(code, data, reply, flags); } /** *代理 */ private static class Proxy implements com.easou.iris.aidltestnew.ISizeAidlInterface { private android.os.IBinder mRemote;//保存对Stub的引用 Proxy(android.os.IBinder remote) { mRemote = remote; } @Override public android.os.IBinder asBinder() { return mRemote; } public java.lang.String getInterfaceDescriptor() { return DESCRIPTOR; } @Override public void setSize(int size) throws android.os.RemoteException { android.os.Parcel _data = android.os.Parcel.obtain(); android.os.Parcel _reply = android.os.Parcel.obtain(); try { _data.writeInterfaceToken(DESCRIPTOR); _data.writeInt(size); mRemote.transact(Stub.TRANSACTION_setSize, _data, _reply, 0); _reply.readException(); } finally { _reply.recycle(); _data.recycle(); } } @Override public int getSize() throws android.os.RemoteException { android.os.Parcel _data = android.os.Parcel.obtain(); android.os.Parcel _reply = android.os.Parcel.obtain(); int _result; try { _data.writeInterfaceToken(DESCRIPTOR); mRemote.transact(Stub.TRANSACTION_getSize, _data, _reply, 0); _reply.readException(); _result = _reply.readInt(); } finally { _reply.recycle(); _data.recycle(); } return _result; } } static final int TRANSACTION_setSize = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0); static final int TRANSACTION_getSize = (android.os.IBinder.FIRST_CALL_TRANSACTION + 1); } public void setSize(int size) throws android.os.RemoteException; public int getSize() throws android.os.RemoteException; }
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories