Service 如何知道caller

重写Binder的onTransact方法

1  
you need to do that in Binder#onTransact method, this is a good place for any remote checks – pskink Feb 10 at 17:58
    
The description of Binder#onTransact mentions unmarshalling transactions. Is it safe to use it just for checking permissions and returning false when the permissions are not okay, and returning the default implementation when all is well? – Daniel Feb 11 at 15:36
    
i think so, but the docs do not say what is returned boolean for (try to return false and see what happens) or you would try to throw RemoteException saying "dear client, nonono, you have no permissions to call me" – pskink Feb 11 at 16:03
    
I did try it. When I return false from onTransact, the function call on the client returns null. – Daniel
拿到caller的包名
String pkg = getPackageManager().getNameForUid(getCallingUid());
posted @ 2016-04-11 16:11  枪侠  阅读(260)  评论(0编辑  收藏  举报