您的位置:首页 > 大数据 > 人工智能

aidl深度解析

2016-03-11 16:28 519 查看
本文是aidl自动生成的java类的解析,让你更加清晰的了解aidl

上一张自己画的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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  aidl android 内核 源码