You can only safely know its uid, by calling Binder.getCallingUid() while
processing the incoming IPC call.  You can use
http://developer.android.com/reference/android/content/pm/PackageManager.html#getPackagesForUid(int)
to
get all of the .apk package names associated with the uid.

Typically if code needs to have a specific package name for the caller, this
is done by having the caller pass their package name in to the IPC call and
then using 
http://developer.android.com/reference/android/content/pm/PackageManager.html#getApplicationInfo(java.lang.String,
int) to verify that the uid of that package matches the incoming
Binder.getCallingUid().

For the framework, the wrapper code for the aidl interface automatically
takes care of providing the package name since it always has the Context of
the caller.  Note that supplying the package name like this is *not* a
security mechanism, since any process can use the low-level aidl interface
to give you any package name you want; to be secure you always need to rely
on Binder.getCallingUid().


On Tue, Aug 30, 2011 at 12:07 PM, Chetan Dhillon
<[email protected]>wrote:

> I am writing a remote service using AIDL. The APIs on this service
> will be used by activities running in other applications after they
> bind to it. I want this service to be shared/used by among multiple
> applications that is why I want to run it in it own process and have
> other applications talk to it over RPC.
>
> My question are-
> - Is there a way to know which application is calling into the
> service? I would like to retrieve package name or ApplicationInfo of
> calling app.
> - Do Context.getPacakgeName and Context.getApplictionInfo inside my
> service return information about the process in which service is
> running or the process in which calling app is runing?
>
> thanks
> Chetan
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>



-- 
Dianne Hackborn
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to