Inter-process Dialogue--aidl (iii)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.