Android directs TAG in, out, inout

All non-basic parameters need a directional tag to indicate how data flows, whether in, out, or inout. The directional tag of the basic parameter is by default and can only be in. There are some questions in my mind about this directional tag. First of all, what is the way of data flow? Secondly, what do in, out and inout represent and what are the differences between them? Obviously, official documents do not account for these things clearly. So we still have a clear analysis from the source code.

TAG in

Set the method parameter of aidl class to in

 void addStudent(in Student student);

In the. java class I generated, some code snippets are as follows:

case TRANSACTION_addStudent:
{
data.enforceInterface(descriptor);
com.yang.test.data.Student _arg0;
//TAG in, reading student objects from data
if ((0!=data.readInt())) {
_arg0 = com.yang.test.data.Student.CREATOR.createFromParcel(data);
}
else {
_arg0 = null;
}
//Then call the aidl interface, which ends later, without returning the passed parameters to the reply stream
this.addStudent(_arg0);
reply.writeNoException();
return true;
}

TAG out

Set the aidl class method parameter to out

 void addStudent(out Student student);

In the. java class I generated, some code snippets are as follows:

case TRANSACTION_addStudent:
{
data.enforceInterface(descriptor);
com.yang.test.data.Student _arg0;
//TAG out, which does not read the object passed by the client, creates a student object directly, and then calls the aidl interface to pass the created object to the interface.
_arg0 = new com.yang.test.data.Student();
this.addStudent(_arg0);
reply.writeNoException();
//Any modification to the student object on the server side will be returned to the reply stream. If the client reads the student object, it will get the new object on the server side.
if ((_arg0!=null)) {
reply.writeInt(1);
_arg0.writeToParcel(reply, android.os.Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
}
else {
reply.writeInt(0);
}
return true;
}

TAG  inout

Set the aidl class method parameter to inout

case TRANSACTION_addStudent:
{
data.enforceInterface(descriptor);
com.yang.test.data.Student _arg0;
//TAG inout, first read the student object from data
if ((0!=data.readInt())) {
_arg0 = com.yang.test.data.Student.CREATOR.createFromParcel(data);
}
else {
_arg0 = null;
}
//Pass the read student object into the implementation class interface
this.addStudent(_arg0);
reply.writeNoException();

//After the class interface is processed, the student object is written into the reply stream. If the client wants to read the student, it is the student object that has been modified by the service.
if ((_arg0!=null)) {
reply.writeInt(1);
_arg0.writeToParcel(reply, android.os.Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
}
else {
reply.writeInt(0);
}
return true;
}

summary

Through the analysis of the source code above, we know the specific meaning of in, out and inout tag s.

In: The object passed in by the client will not be returned to the client object after calling the transact method, passing it to the server and calling the local method of the server.

out: An object passed in by the client calls the transact method and passes to the server. The server will create a new object and return the new object after calling the local method of the server.

inout: Input object of client, call transact method, transfer to server, call local method of server, if the content of the object is modified by server, the modified object will be returned to client, if not, the original object will be returned to client.

 

Keywords: Java Android

Added by busybee on Thu, 26 Sep 2019 12:26:03 +0300