RoLAN210 RoLAN210 - 11 months ago 47
Android Question

How to only allow my companion watch app to connect to my wearable listener service on handheld?

I want to ensure my WearableListenerService running on my handheld is only accessible by my companion app. I would think that creating a custom permission would be the route to take however I faced issues with this approach and could not get the wearable to successfully bind to the handheld, I would get the following exception on my handheld;

Permission Denial: Accessing service ComponentInfo{} from pid=4868, uid=10014 requires
WearableService: bind: Permission denied connecting to ServiceRecord[, events=1, bound=false, [Event[79380002: onMessageReceived, event=requestId=16741, action=/start-activity, dataSize=26, source=31c5457d]]]
java.lang.SecurityException: Not allowed to bind to service Intent { }
at android.content.ContextWrapper.bindService(
at android.content.ContextWrapper.bindService(
at android.content.ContextWrapper.bindService(
at aeim.a(
at aeim.a(
at aeim.handleMessage(
at android.os.Handler.dispatchMessage(
at android.os.Looper.loop(

I have tried defining a custom permission in a number of ways, initially in only the handheld manifest and then in both manifests, as well as trying different protection levels, normal, signature, signatureOrSystem. I even verified that the permission was successfully granted to my wearable by running the dumpsys command;

declared permissions: prot=normal, INSTALLED
requested permissions:
install permissions: granted=true
android.permission.WAKE_LOCK: granted=true

I have applied a data filter to my service however I would like to enforce that only MY app can launch my service and the filter approach doesn't seem sufficient.

Answer Source

Your watch app and handheld app never directly talk to one another. All of the Data Layer APIs go through Google Play services (the lines of your exception) - first on the Wear side, then on the handheld side.

Given that, it is not possible to add a custom permission that secure the communication over the Data Layer (as the Google Play services app will never add your custom permission).