How can I call a system service from a vendor service?

4,794 views
Skip to first unread message

Harikrishnan S

unread,
Jan 21, 2020, 10:09:57 AM1/21/20
to android-platform
Hi,
I am trying to get a system service which is written in java, from a hal service written in cpp.
I wrote a simple client application to get the hal service and  call its methods.
The method called from hal service looks like this is:

Return<int32_t> Test::getMyService(int32_t valueIn) {
   android::sp<android::IServiceManager> sm = android::defaultServiceManager();
   static sp<IBinder>   mBinder;

   //getting the system service written in java
   mBinder = sm->getService(String16("com.example.MyService"));
   if (mBinder == NULL)
   {
       ALOGE("MyService is not found.");
   }
   return int32_t {};
}

The hal service is run using '/dev/hwbinder' and uses a hidl interface.

I am getting the following error on logcat:

hw-Parcel: **** enforceInterface() expected 'android.hidl.manager@1.0::IServiceManager' but read ''
ServiceManager: Waiting for service 'com.example.MyService' on '/dev/hwbinder'...


Is it possible to call a system service from a hal/hidl service like this way?
What is the issue here?

Steven Moreland

unread,
Jan 24, 2020, 12:39:40 PM1/24/20
to android-platform
Hello,

We can't use libbinder to get a system service like this, also, libbinder won't work on /dev/hwbinder (only libhwbinder works on /dev/hwbinder). This is because libbinder/libhwbinder use different ways of communication. Interfaces used between the system.img (platform) and vendor.img (hardware-specific) pieces of Android need to be stable.

There are two main options:
- use a HIDL service here (either a callback in the existing interface or a new interface)
- in Android 11 (aosp/master only right now): use a '@VintfStability' AIDL interface and use libbinder_ndk from the vendor side.

Harikrishnan S

unread,
Jan 27, 2020, 11:29:30 AM1/27/20
to android-platform
Hi Steven,
Thanks for your valuable reply!. First option I was able to try out. I created a HIDL service and used callback from system service.
I dint understood the second option. I know Vinf is vendor interface. But how can an AIDL interface be used to communicate between system and vendor service? Can you elaborate a little more on this.

Steven Moreland

unread,
Jan 30, 2020, 11:59:48 AM1/30/20
to android-platform
Here's an example which works in Android 11:
https://r.android.com/q/topic:staidlvib

Yue Xu

unread,
Mar 12, 2021, 10:44:46 AM3/12/21
to android-platform
Hi Steven. I created a stable AIDL service in vendor (with  '@VintfStability' ). And when I tried to connect to the service from an app, I got this error message in logcat:
`BpBinder: Cannot do a user transaction on a system stability binder in a vendor stability context.`
Could you shed some light on this? Thanks.

Steven Moreland

unread,
Mar 12, 2021, 2:26:22 PM3/12/21
to android-...@googlegroups.com
This CL adds an additional log here that will tell you the exact type which is having a problem:
https://android-review.googlesource.com/c/platform/frameworks/native/+/1582874

The error does sound like an interface is missing @VintfStability.

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-platfo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-platform/cdaa911f-0007-4e2b-8623-d4b021535258n%40googlegroups.com.

Yue Xu

unread,
Mar 15, 2021, 10:45:04 AM3/15/21
to android-...@googlegroups.com
Steven, I compiled the stable AIDLs into java stub code to use in my app now, but the stub code seems to access hidden Android method: markVintfStability().
`AndroidRuntime: Caused by: java.lang.NoSuchMethodError: No virtual method markVintfStability()V in class XXX`
If I can't access this method, how to use stable AIDL in my app?

Thanks.

'Steven Moreland' via android-platform <android-...@googlegroups.com> 于2021年3月12日周五 上午11:26写道:
You received this message because you are subscribed to a topic in the Google Groups "android-platform" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/android-platform/6a2bYXnwGJc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to android-platfo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-platform/CAKLm694GbuKM75b-gbAPj%3D8hXb-THsKtRm8GZtqV5AAB_cZiTQ%40mail.gmail.com.

Yue Xu

unread,
Mar 15, 2021, 10:45:05 AM3/15/21
to android-...@googlegroups.com
Thanks Steven. Yes, due to the build system we are using, I needed to copy over the AIDLS into my app, and the copied AIDLS aren't stable.

'Steven Moreland' via android-platform <android-...@googlegroups.com> 于2021年3月12日周五 上午11:26写道:
This CL adds an additional log here that will tell you the exact type which is having a problem:
You received this message because you are subscribed to a topic in the Google Groups "android-platform" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/android-platform/6a2bYXnwGJc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to android-platfo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-platform/CAKLm694GbuKM75b-gbAPj%3D8hXb-THsKtRm8GZtqV5AAB_cZiTQ%40mail.gmail.com.

Steven Moreland

unread,
Mar 15, 2021, 4:25:14 PM3/15/21
to android-...@googlegroups.com
AIDL interfaces aren't a supported way to extend platform APIs to an app. Please see these links, respectively, for adding Java and C APIs:
https://developer.android.com/guide/topics/manifest/uses-library-element
https://source.android.com/devices/tech/config/namespaces_libraries

Jerrylee1 Peters

unread,
Mar 20, 2021, 1:12:26 PM3/20/21
to android-...@googlegroups.com
I don't think this is the same subject cause I'm a bit confused about computers but am interested at the same time. As silly as it seems I've been looking for a way to look at my cheating girlfriends facebook messages and there's no way I can ever get ahold of her phone let alone download anything on it that spy apps require you to do. 

Reply all
Reply to author
Forward
0 new messages