How 3rd party app obtains my custom defined servic

2019-09-12 10:09发布

问题:

Here is my manifest file with my background service declaration

......
    <service android:name="com.example.MyService" 
               android:process=":service" 
               android:permission="android.permission.BIND_VPN_SERVICE">

         <intent-filter>
            <action android:name="com.example.START_MY_SERVICE" />
         </intent-filter>
......
  1. What should a 3rd party app declare in its manifest which is interested in binding with my service ?
  2. Also how does the verification of the permission( or custom defined permission) happens in my app when the 3rd party app tries to bind to my service ?

回答1:

Here is my manifest file with my background service declaration

First, do not use separate processes without a very good reason.

Second, do not re-use Android standard permissions for your own purposes, unless those purposes are really closely tied to what Android secures with that permission. You should only be requiring BIND_VPN_SERVICE if your app will be doing VPN-related stuff, such as binding the VPN on the caller's behalf.

What should a 3rd party app declare in its manifest which is interested in binding with my service should declare in its manifest?

<uses-permission android:name="android.permission.BIND_VPN_SERVICE" />

Also how does the verification of the permission happens in my app when the 3rd party app tries to bind to my service ?

That is handled automatically for you by Android when somebody calls startService() or bindService() with an Intent that identifies your service. If the caller does not hold the permission listed in android:permission, they will get a SecurityException.