Package Name from process id

3,269 views
Skip to first unread message

Ornat Oya

unread,
Jul 25, 2011, 11:08:49 AM7/25/11
to android-platform
Hi to everyone,

Is it possible to get the package name of an application if I know the
process id and user id. For example, I want to get the package name of
the application who called vibrator related functions in the
VibratorService.

Thanks

Oya

Carlos Silva

unread,
Jul 25, 2011, 11:48:03 AM7/25/11
to android-...@googlegroups.com
/proc/$PID/cmdline

^^^^ Has the package name.

 

Ornat Oya

unread,
Jul 25, 2011, 12:10:41 PM7/25/11
to android-platform
I actually need this in VibratorService.java in the framework. Any
other advice?

On Jul 25, 6:48 pm, Carlos Silva <r3...@r3pek.org> wrote:

Tez

unread,
Jul 25, 2011, 1:35:56 PM7/25/11
to android-platform
pid -> package name is not supported currently.
what was suggested earlier could work.

-Earlence

Christopher Tate

unread,
Jul 25, 2011, 2:28:22 PM7/25/11
to android-...@googlegroups.com

You cannot necessarily tell down to the individual application,
because multiple applications can share the same uid or execute within
the same process.

PackageManager.getPackagesForUid(uid) will give you the names of all
the packages that share the given uid. In most cases this will be
unambiguous, but if there is more than one entry in the list you may
have to use other means to disambiguate (such as looking at
/proc/$PID/whatever to get the name of your caller's process, as
suggested earlier). This will work if nothing is using shared-process
as well as shared-uid. If the callers *are* using shared-process, you
simply cannot tell: the two applications are essentially identical for
all outbound-call API purposes.

--
christopher tate
android framework engineer

Ornat Oya

unread,
Jul 25, 2011, 11:55:24 AM7/25/11
to android-platform
I am on the framework side. I am coding in VibratorService.java. Any
advice?

On Jul 25, 6:48 pm, Carlos Silva <r3...@r3pek.org> wrote:

Tez

unread,
Jul 26, 2011, 2:10:52 AM7/26/11
to android-platform
I'm not sure what you are asking for here. People have given you
really detailed replies. IF you are looking for exact code, please
look somewhere else.

-Earlence

Ornat Oya

unread,
Jul 26, 2011, 5:06:02 AM7/26/11
to android-platform
Sorry to bother you. My last two replies were sent consequently as I
thought the first one was not sent. Both replies have the same quoted
text. There is an approval process on the mails, I suppose.

Thanks for your replies
> > > ^^^^ Has the package name.- Hide quoted text -
>
> - Show quoted text -

Dianne Hackborn

unread,
Jul 26, 2011, 1:56:30 AM7/26/11
to android-...@googlegroups.com
The only correct way to do this is to have the caller of the IPC pass in their package name, and verify on the receiver side that the package name they are giving is actually associated with the uid of the incoming call.

As Chris says, multiple .apks can be associated with the same uid and thus run in the same process, so you need to have them provide the information about who they are.  This is generally easy, because all access to system services goes through Context, and Context knows the package it is for, so it can add this information as part of its implementation of the SDK API that does the IPC call underneath.

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To post to this group, send email to android-...@googlegroups.com.
To unsubscribe from this group, send email to android-platfo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.




--
Dianne Hackborn
Android framework engineer
hac...@android.com

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.

Reply all
Reply to author
Forward
0 new messages