为什么通过AIDL方式使用binder机制的时候如果Bn端函数比较耗时Bp端会ANR

来源:互联网 发布:编写网站的软件 编辑:程序博客网 时间:2024/05/20 13:36

分析:

看源码红色部分,第三个参数是0,而FLAG_ONEWAY             = 0x00000001;(可以添加oneway来设置它)

private static class Proxy implements com.example.abc.ITest {
private android.os.IBinder mRemote;

.....................


@Override
public int add(int a, int b) 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);
_data.writeInt(a);
_data.writeInt(b);
mRemote.transact(Stub.TRANSACTION_add, _data, _reply, 0);
_reply.readException();
_result = _reply.readInt();
} finally {
_reply.recycle();
_data.recycle();
}
return _result;
}
}


static final int TRANSACTION_add = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0);
}

0 0
原创粉丝点击