Search code examples
androidandroid-serviceandroid-service-binding

Custom Android service not found despite proper permissions and queries with SDK 33


In this project, I provide two example apps:

  • a "service app" providing a service like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.softbankrobotics.pddlplanning.example.service">
...
  <permission
      android:name="com.softbankrobotics.planning.SEARCH_PLANS"
      android:protectionLevel="normal" />

  <application ...>
    ...
    <service
        android:name=".ExamplePDDLPlannerService"
        android:enabled="true"
        android:exported="true"
        android:permission="com.softbankrobotics.planning.SEARCH_PLANS">
      <intent-filter>
        <action android:name="com.softbankrobotics.planning.action.SEARCH_PLANS_FROM_PDDL" />
      </intent-filter>
    </service>
  </application>
</manifest>

The service interface is defined with this .aidl file. It shows one method accepting two strings, and returning a list of parcelable objects.

  • a "client app", configured to use the service like this:
<uses-permission android:name="com.softbankrobotics.planning.SEARCH_PLANS" />
<queries>
    <package android:name="com.softbankrobotics.pddlplanning.example.service" />
    <intent>
        <action android:name="com.softbankrobotics.planning.action.SEARCH_PLANS_FROM_PDDL" />
    </intent>
</queries>

... and it binds the service this way, after permissions were successfully checked:

val plannerServiceIntent = Intent(IPDDLPlannerService.ACTION_SEARCH_PLANS_FROM_PDDL)
plannerServiceIntent.`package` = "com.softbankrobotics.pddlplanning.example.service"
val foundService = context.bindService(plannerServiceIntent, serviceConnection, Context.BIND_AUTO_CREATE)
if (!foundService) {
    context.unbindService(serviceConnection)
    throw RemoteException("Planner service was not found")
}

(this piece of code was re-assembled, it is more spread around in the repository)

Despite exporting the service, declaring and checking permissions, ensuring package visibility for the client... My call to bindService returns false, and the logs confirm the service was not found. Whereas dumpsys shows the service is here.

What did I do wrong?

Note that I compile using the Android SDK version 33, and I used to know how to do this with older Android SDK versions.

To reproduce the issue:

  • build the APKs, install them
  • run the Planning Client app (ExampleClientActivity from the client-app-example module)

Solution

  • I figured it out! The applicationId in the build.gradle differed from the package name in the manifest.