How 3rd party app obtains my custom defined service permission to start my service?

怎甘沉沦 提交于 2019-12-13 05:42:17

问题


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.



来源:https://stackoverflow.com/questions/14062108/how-3rd-party-app-obtains-my-custom-defined-service-permission-to-start-my-servi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!