Previously documented how a client communicates with a server across processes. If only one client needs it, the meaning of the cross-process is less significant. So I set up a client here to use this service side together.
The client's code is almost identical to the previous code. The code is not posted here. The only difference is that the file structure is different. Since the service is written in the previous project, we need a common set of aidl interfaces, and Book.java. Not only the same code, but also the same package name. Therefore, it is recommended to copy files directly from the server.
This allows us to ensure that the client communicates properly with the server.
Speaking of which, I have doubts. My server is too public. Any client, whether it is my client or not, just create this interface and package structure, and then know that my service's action can communicate with me. This is unscientific!
By reference, there are two ways to manage this communication in a more general way.
We focus on documenting one of these, namely Onbind validation.
First, we configure the androidmanifest inside the server.
< Permission Android:name = "Com.dream.fishbonelsy.aidldemo.permission.ACCESS" android:protectionlevel= "normal"/>
This configuration is to set a password, the password can be customized.
It is worth noting that the server process must be set to remote and cannot be set to any process name. Once set to any process name, this is not controlled by permissions.
<ServiceAndroid:name= ". Service. Bookmanagerservice "android:process= ": Remote" > <Intent-filter> <ActionAndroid:name= "Com.dream.fishbonelsy.aidldemo.service"/> </Intent-filter> </Service>
After the configuration is complete, we'll modify the small amount of code on the server side.
@Override public ibinder onbind (Intent Intent) { int check = Checkcallingorselfpermission ("Com.dream.fishbonelsy.aidldemo.permission.ACCESS"); if (check = = packagemanager.permission_denied) {returnnull; } return mbinder; }
Modify the Onbind method in the service so that you make a judgment before returning to IBinder. Returns NULL if no permission is available.
Regardless of which client you want to communicate with this server, just add the androidmanifest in your own
<android:name= "Com.dream.fishbonelsy.aidldemo.permission.ACCESS"/>
Can.
Thus, a basic cross-process, the C/S model is completed. But there are a lot of pits in it, and the next one is explored.
Done ~
Inter-process Dialogue--aidl (iii)