Question

I have an aidl service which works correctly till the client is installed when the host is installed before, but as I mentioned in the title when the host isn't installed and I install the client and after that I install the host I get a SecurityException on bindService()

Intent serviceIntent = new Intent(AidlService.class.getName());
if (!mContext.getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty()) {
    mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
}

Caused by: java.lang.SecurityException: Not allowed to bind to service Intent { act=com.mypackage.AidlService}

i have also tested a few application that use aidl and they had the same problem !

UPDATE

I figured out that the problem is with permission, as my service uses a custom permission when the client is installed before the host it can't understand the permission, so when I install the host and try to bind to it, android can't use the permission, so it throws a security exception !

android:permission="com.mypackage.AidlService.BIND"

<permission android:name="com.mypackage.AidlService.BIND"
            android:label="@string/perName"
            android:description="@string/perDesc"
            android:protectionLevel="normal" />

any idea to fix the problem ?

Was it helpful?

Solution

According to Android Custom Permission Fails Based on App Install Order

you should use android:protectionLevel="signature" instead of normal in permission tag

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top