0

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)
Victor Paléologue
  • 2,025
  • 1
  • 17
  • 27
  • 1
    Are you sure that `IPDDLPlannerService.ACTION_SEARCH_PLANS_FROM_PDDL` is `"com.softbankrobotics.planning.action.SEARCH_PLANS_FROM_PDDL"`? Does Logcat show anything useful at the point of your failed binding attempt? – CommonsWare Sep 13 '22 at 11:19
  • Yes, see https://github.com/victorpaleologue/pddl-planning-android/blob/9724206c6b3ce5007cafa1412836d7566b278447/pddl-planning/src/main/aidl/com/softbankrobotics/pddlplanning/IPDDLPlannerService.aidl#L12 I'm adding a link to the logs of a run. It behaves as if the service did not exist. – Victor Paléologue Sep 13 '22 at 11:26
  • 1
    @VictorPaléologue Are you getting the same error even when you declare the service in the manifest xml file using the whole package name like – MariosP Sep 22 '22 at 06:49
  • Thanks for the suggestion. I have just tried it out, and that did not change a thing. I clearly uninstalled the apps, re-installed them in the right order, and disabled the automatic cancellation of permission for these apps. – Victor Paléologue Sep 22 '22 at 09:08
  • 1
    When you create the `Intent` to bind to the `Service`, set the component (package and class name) and see if that helps. – David Wasser Sep 23 '22 at 12:55
  • That does not help. – Victor Paléologue Sep 26 '22 at 08:48

1 Answers1

0

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

Victor Paléologue
  • 2,025
  • 1
  • 17
  • 27