Publish IBinder interface of native service with system manager

815 views
Skip to first unread message

Paturi

unread,
Dec 8, 2009, 7:33:12 AM12/8/09
to android-porting

HI

I would like to register native service with system manager and
publish its IBinder interface with service manager.
I want my client to retrieve the service interface through Java code
and invoke the methods in the service. Please help me how I can
accomplish this without changing the android framework. Please provide
me with an example if possible since I am unclear with IBinder concept
in Android.

Thanks

Dianne Hackborn

unread,
Dec 8, 2009, 6:11:39 PM12/8/09
to android...@googlegroups.com
The way to do this without modifying the framework is to put your implementation in an .apk that:

1. Declares a shared user ID with the system process, and that its components will run in the system process.
2. Has a Service component that implements your "system" service.
3. Has an intent receiver for BOOT_COMPLETED that, when run, starts the service.
4. In the Service implementation publishes its IBinder interface with the private ServiceManager API.

You can look at frameworks/base/packages/SettingsProvider for an example of an .apk that runs in the system process.




--
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.

Paturi

unread,
Dec 9, 2009, 12:54:09 AM12/9/09
to android-porting

I have a doubt regarding the fourth step.
How can I publish the IBinder interface with the private ServiceManger
API?
Please provide me with some example.


On Dec 9, 4:11 am, Dianne Hackborn <hack...@android.com> wrote:
> The way to do this without modifying the framework is to put your
> implementation in an .apk that:
>
> 1. Declares a shared user ID with the system process, and that its
> components will run in the system process.
> 2. Has a Service component that implements your "system" service.
> 3. Has an intent receiver for BOOT_COMPLETED that, when run, starts the
> service.
> 4. In the Service implementation publishes its IBinder interface with the
> private ServiceManager API.
>
> You can look at frameworks/base/packages/SettingsProvider for an example of
> an .apk that runs in the system process.
>
>
>
> On Tue, Dec 8, 2009 at 4:33 AM, Paturi <bharath.pat...@gmail.com> wrote:
>
> > HI
>
> > I would like to register native service with system manager and
> > publish its IBinder interface with service manager.
> > I want my client to retrieve the service interface through Java code
> > and invoke the methods in the service. Please help me how I can
> > accomplish this without changing the android framework. Please provide
> > me with an example if possible since I am unclear with IBinder concept
> > in Android.
>
> > Thanks
>
> > --
> > unsubscribe: android-porti...@googlegroups.com<android-porting%2Bunsu...@googlegroups.com>
> > website:http://groups.google.com/group/android-porting
>
> --
> Dianne Hackborn
> Android framework engineer
> hack...@android.com

Dianne Hackborn

unread,
Dec 9, 2009, 3:50:19 AM12/9/09
to android...@googlegroups.com
You can look in SystemService.java and the related classes it uses for lots and lots of examples.




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

Paturi

unread,
Dec 9, 2009, 6:24:00 AM12/9/09
to android-porting, Dianne Hackborn

Thanks once gain for your reply

I saw the code SystemService.java in packages/apps/IM/src/com/android/
im/engine but I still couldnt
understand it properly. Please explain with a small example how I can
publish the IBinder interface with
ServiceManger API. I may be asking you a simple question but I am
still unclear with publishing the IBinder interface and also how
Android services are different from regular Services.
> > <android-porting%2Bunsu...@googlegroups.com<android-porting%252Buns...@googlegroups.com>
>
> > > > website:http://groups.google.com/group/android-porting
>
> > > --
> > > Dianne Hackborn
> > > Android framework engineer
> > > hack...@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.
>
> > --
> > unsubscribe: android-porti...@googlegroups.com<android-porting%2Bunsu...@googlegroups.com>
> > website:http://groups.google.com/group/android-porting
>
> --
> Dianne Hackborn
> Android framework engineer

Dianne Hackborn

unread,
Dec 9, 2009, 9:45:19 AM12/9/09
to Paturi, android-porting
Sorry I don't have time right now to put together sample code.  I don't know why you are looking in the IM application, but you are not going to find anything useful there.  You want to look at SystemService.java in frameworks/base/services/...

Paturi

unread,
Dec 9, 2009, 11:23:33 AM12/9/09
to android-porting

Ok Thanks for your reply.
I am looking at SystemService.java in wrong directory.
I will look at framework/base/services and will let you know if I have
any queries.


On Dec 9, 7:45 pm, Dianne Hackborn <hack...@android.com> wrote:
> Sorry I don't have time right now to put together sample code.  I don't know
> why you are looking in the IM application, but you are not going to find
> anything useful there.  You want to look at SystemService.java in
> frameworks/base/services/...
>
>
>
>
>
> On Wed, Dec 9, 2009 at 3:24 AM, Paturi <bharath.pat...@gmail.com> wrote:
>
> > Thanks once gain for your reply
>
> > I saw the code SystemService.java in packages/apps/IM/src/com/android/
> > im/engine but I still couldnt
> > understand it properly. Please explain with a small example how I can
> > publish the IBinder interface with
> > ServiceManger API. I may be asking you a simple question but I am
> > still unclear with publishing the IBinder interface and also how
> > Android services are different from regular Services.
>
> > On Dec 9, 1:50 pm, Dianne Hackborn <hack...@android.com> wrote:
> > > You can look in SystemService.java and the related classes it uses for
> > lots
> > > and lots of examples.
>
> > > > > > unsubscribe: android-porti...@googlegroups.com<android-porting%2Bunsubscribe@ googlegroups.com>
> > <android-porting%2Bunsu...@googlegroups.com<android-porting%252Bunsubsc ri...@googlegroups.com>
>
> > > > <android-porting%2Bunsu...@googlegroups.com<android-porting%252Bunsubsc ri...@googlegroups.com>
> > <android-porting%252Buns...@googlegroups.com<android-porting%25252Buns ubsc...@googlegroups.com>
>
> > > > > > website:http://groups.google.com/group/android-porting
>
> > > > > --
> > > > > Dianne Hackborn
> > > > > Android framework engineer
> > > > > hack...@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.
>
> > > > --
> > > > unsubscribe: android-porti...@googlegroups.com<android-porting%2Bunsubscribe@ googlegroups.com>
> > <android-porting%2Bunsu...@googlegroups.com<android-porting%252Bunsubsc ri...@googlegroups.com>

Digambar Rasal

unread,
Jan 13, 2010, 10:36:45 AM1/13/10
to android-porting
Hi,

I am trying similar scenario and I have created package with
- broadcastreceiver with which I am planning to start service
- actual System service implementation.

On Boot completed intent,
onReceive(context)
{
....
if ( BOOT_COMPLETED) ServiceManager.addService("test",new TestService
(context));
...

But this doesn't happen but getting PERMISSION DENIED error.

This link mentions to run my app as System APP, i can add
"android:sharedUserId="android.uid.system" in manifest.
http://groups.google.com/group/android-platform/msg/7b56c90c109842b6

but on this I can't install my package with error UPDATE_INCOMPATIBLE.

Am I missing something ?

Regards
Digambar

Reply all
Reply to author
Forward
0 new messages