没有AIDL方式启动目标Activity的方式
ActivityManagerProxy.startActivity
public int startActivity(IApplicationThread caller, String callingPackage, Intent intent,
String resolvedType, IBinder resultTo, String resultWho, int requestCode,
int startFlags, ProfilerInfo profilerInfo, Bundle options) throws RemoteException {
Parcel data = Parcel.obtain();
Parcel reply = Parcel.obtain();
data.writeInterfaceToken(IActivityManager.descriptor);
data.writeStrongBinder(caller != null ? caller.asBinder() : null);
data.writeString(callingPackage);
intent.writeToParcel(data, 0);
data.writeString(resolvedType);
data.writeStrongBinder(resultTo);
data.writeString(resultWho);
data.writeInt(requestCode);
data.writeInt(startFlags);
if (profilerInfo != null) {
data.writeInt(1);
profilerInfo.writeToParcel(data, Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
} else {
data.writeInt(0);
}
if (options != null) {
data.writeInt(1);
options.writeToParcel(data, 0);
} else {
data.writeInt(0);
}
mRemote.transact(START_ACTIVITY_TRANSACTION, data, reply, 0);
reply.readException();
int result = reply.readInt();
reply.recycle();
data.recycle();
return result;
}
正如上面代码所示, 如果没有AIDL, 要实现进程间通信, App进行与system_server进程之间进行通信, 需要先将通讯请求转换成序列化的数据, 然后调用transact()函数发送给服务端, 而且还得制定对应的协议, 参数的先后顺序, 而且服务端与客户端都必须一致, 否则就会出错.
参考文章
https://www.zhihu.com/question/39440766
https://blog.csdn.net/xude1985/article/details/9232049
https://blog.csdn.net/tiefeng0606/article/details/51142518
网友评论