Sending events in C/C++

1,065 views
Skip to first unread message

jwills

unread,
Jul 21, 2010, 4:21:11 PM7/21/10
to android-platform
Is there any framework in place currently to allow a system level
service written in C or C++ to broadcast an intent? I came across
http://groups.google.com/group/android-platform/browse_thread/thread/de88861f8ff99a3e/ca0f07557aa6af84?lnk=gst&q=event+c#ca0f07557aa6af84
stating it was not possible, but noticed the datestamp of a year and a
half ago. Have there been any updates to this, or does that response
still hold true? If that is still the case, are there any plans to
change this in the future? I would hate to have to write up a service
in Java whose sole purpose is to listen to my C based daemon and pass
off intents for it when necessary, but that's the only workaround I
can think of at the moment.

Thanks,
Jordan Wills

Dianne Hackborn

unread,
Jul 21, 2010, 7:25:55 PM7/21/10
to android-...@googlegroups.com
You just need to write some JNI code to call the desired Java APIs.


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

jwills

unread,
Jul 22, 2010, 9:35:01 AM7/22/10
to android-platform
I'm not certain that JNI code would work too well in this situation,
but please let me know if you disagree. My background is very heavy
in C and very light in Java, so I'll be the first to admit that my
understanding of the capabilities of the NDK and JNI code is somewhat
limited.

I have a daemon written in C that, among other things, makes
occasional changes to the system clock via settimeofday(). The
frequency with which this change is made is based on a few functions
that are called through the mainline loop of the C code. I could
write JNI code to let a Java program kick off the mainline loop, or
recreate the loop in Java using JNI code to call the individual
functions, but I don't know that this would solve my problem. I
thought that the JNI code was basically a way of having Java tell C
that it needs to run a piece of code. In my case, I would think I'd
need the reverse- a way for the C code to make a call to a function
written in Java to broadcast an intent whenever the C code determines
it needs to change the time of day.

Again, I'm rather new to coding in Java (and definitely new to coding
for Android), so please let me know if my understanding and solution
are flawed.

Thanks,
Jordan Wills


On Jul 21, 6:25 pm, Dianne Hackborn <hack...@android.com> wrote:
> You just need to write some JNI code to call the desired Java APIs.
>
>
>
>
>
> On Wed, Jul 21, 2010 at 1:21 PM, jwills <wills.jor...@gmail.com> wrote:
> > Is there any framework in place currently to allow a system level
> > service written in C or C++ to broadcast an intent?  I came across
>
> >http://groups.google.com/group/android-platform/browse_thread/thread/...
> > stating it was not possible, but noticed the datestamp of a year and a
> > half ago.  Have there been any updates to this, or does that response
> > still hold true?  If that is still the case, are there any plans to
> > change this in the future?  I would hate to have to write up a service
> > in Java whose sole purpose is to listen to my C based daemon and pass
> > off intents for it when necessary, but that's the only workaround I
> > can think of at the moment.
>
> > Thanks,
> > Jordan Wills
>
> > --
> > 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<android-platform%2Bunsubscrib e...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/android-platform?hl=en.
>
> --
> Dianne Hackborn
> Android framework engineer
> hack...@android.com

Dianne Hackborn

unread,
Jul 22, 2010, 12:30:39 PM7/22/10
to android-...@googlegroups.com
JNI lets native code and Java interact, in both ways.

Given that a significant chunk of Android is written in Java (including in particular everything about Intent, broadcasting them, starting activities with them, etc), then at some point you are going to need a JNI call to get from the native code into the Java platform.

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

sanjeev sharma

unread,
Jul 26, 2010, 12:31:39 AM7/26/10
to android-...@googlegroups.com
Thanks For Reply,

As I understood both JNI and NDK Serve same purpose or they have totally different.


Regards
Sanjeev Sharma

FrankG

unread,
Jul 26, 2010, 4:19:45 AM7/26/10
to android-platform
Hello Jordan,

you can study how the android system does this :

I.e. vold .. he listesn to uevent from the kernel
and send them to the java world via sockets.

The listener for the vold messages is
com.android.server.MountListener.
He send then intents and Notifications to the rest of the system.

Good luck !

Frank





Anand Android

unread,
Aug 1, 2010, 1:12:54 PM8/1/10
to android-...@googlegroups.com
Hi Frank,
I have few questions about vold which is being used in froyo.

- why in froyo vold is re-written in cpp ? where as the vold in eclair is in C
- when i plug in usb cable ,from the kernel log i can figure out the occurrence of charger interrupt. how does froyo vold handles uevents when we plug in the usb cable?? and which part of the code does this ?
- On boot,if i disable vold service and enable mountd ,my android boot breaks. why is this happening in froyo?
- and finally what makes froyo vold so special from mountd and eclair vold?

-
Ananda






--

FrankG

unread,
Aug 3, 2010, 3:13:29 AM8/3/10
to android-platform
Hello Ananada,

On 1 Aug., 19:12, Anand Android <android.an...@gmail.com> wrote:
> Hi Frank,
> I have few questions about vold which is being used in froyo.
>
> - why in froyo vold is re-written in cpp ? where as the vold in eclair is in
> C

This is new for me too. I have no more details as you.

Interessting. Seems that he is redesigned .. and works in a different
way ?!

Some more details would be interessting, especially when you read such
comments

/*
* Switch uevents are broken.
* For now we manually bootstrap
* the ums switch
*/


> - when i plug in usb cable ,from the kernel log i can figure out the
> occurrence of charger interrupt. how does froyo vold handles uevents when we
> plug in the usb cable?? and which part of the code does this ?

I heared from my colleagues that the VBUS detection changed with the
new kernel.

In main.cpp it seems for me that vold now reads a sysfs enty ( /sys/
devices/virtual/switch/usb_mass_storage/state)
instead of listening directly for uevents.

But it seems that concerning power managment he plays a different
rule ?!


> - On boot,if i disable vold service and enable mountd ,my android boot
> breaks. why is this happening in froyo?

I think because then central services are not informed .. this
android, not linux IMHO.

> - and finally what makes froyo vold so special from mountd and eclair vold?

No idea .. but it would be very good to know, what and why in the
principiel design changed.


> Ananda
>

Good luck !

Frank


> On Mon, Jul 26, 2010 at 1:49 PM, FrankG <frankgru...@googlemail.com> wrote:
> > Hello Jordan,
>
> > you can study how the android system does this :
>
> > I.e. vold .. he listesn to uevent from the kernel
> > and send them to the java world via sockets.
>
> > The listener for the vold messages is
> > com.android.server.MountListener.
> > He send then intents and Notifications to the rest of the system.
>
> > Good luck !
>
> >  Frank
>
> > --
> > 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<android-platform%2Bunsubscrib­e...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/android-platform?hl=en.- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -

FrankG

unread,
Aug 3, 2010, 3:53:02 AM8/3/10
to android-platform


> > - On boot,if i disable vold service and enable mountd ,my android boot
> > breaks. why is this happening in froyo?
>

Their are new classes : VolumeManager and Volume ..

BTW .. MountService also changed.

Good luck !
Frank


Anand Android

unread,
Aug 5, 2010, 9:03:38 AM8/5/10
to android-...@googlegroups.com
Hi Frank,
Thanks for the information.
In vold.fstab file i can see the following format to mount the sdcard

Format: dev_mount <label> <mount_point> <part> <sysfs_path1...>

the last parameter ,<sysfs_path1 ...> , i didnt get what he's refering to .
can u put some light on it.

-Anand





Good luck !
   Frank


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

Anand Android

unread,
Aug 5, 2010, 9:29:19 AM8/5/10
to android-...@googlegroups.com
HI Frank,
I do see 'doMount' definition system/core/Fat.cpp ,inside which he actually calls 'mount' system call for mounting purpose.
But i couldn't able to understand how does he mounting sdcards during the boot time.


-Anand

FrankG

unread,
Aug 9, 2010, 4:35:28 AM8/9/10
to android-platform
Hi Anand,
Hi Anand,


I think the sys-fs path list depends from your particular
device and your driver configuration. Look in your
vold.conf and their for media_path.

Good luck !

Frank



On 5 Aug., 15:03, Anand Android <android.an...@gmail.com> wrote:
> Hi Frank,
> Thanks for the information.
> In vold.fstab file i can see the following format to mount the sdcard
>
> Format: dev_mount <label> <mount_point> <part> <sysfs_path1...>
>
> the last parameter ,<sysfs_path1 ...> , i didnt get what he's refering to .
> can u put some light on it.
>
> -Anand
>
>
>
> On Tue, Aug 3, 2010 at 1:23 PM, FrankG <frankgru...@googlemail.com> wrote:
>
> > > > - On boot,if i disable vold service and enable mountd ,my android boot
> > > > breaks. why is this happening in froyo?
>
> > Their are new classes : VolumeManager and Volume ..
>
> > BTW .. MountService also changed.
>
> > Good luck !
> >    Frank
>
> > --
> > 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<android-platform%2Bunsubscrib­e...@googlegroups.com>
> > .
> > For more options, visit this group at

FrankG

unread,
Aug 9, 2010, 5:24:05 AM8/9/10
to android-platform
Hmm .. Fap.cpp is for me under system/vold/. and is part of the new
vold. The vold service is started via init.rc. Hís main.cpp reads
"/etc/vold.fstab"

Good luck !

Frank



On 5 Aug., 15:29, Anand Android <android.an...@gmail.com> wrote:
> HI Frank,
> I do see 'doMount' definition system/core/Fat.cpp ,inside which he actually
> calls 'mount' system call for mounting purpose.
> But i couldn't able to understand how does he mounting sdcards during the
> boot time.
>
> -Anand
>
> On Thu, Aug 5, 2010 at 6:33 PM, Anand Android <android.an...@gmail.com>wrote:
>
>
>
> > Hi Frank,
> > Thanks for the information.
> > In vold.fstab file i can see the following format to mount the sdcard
>
> > Format: dev_mount <label> <mount_point> <part> <sysfs_path1...>
>
> > the last parameter ,<sysfs_path1 ...> , i didnt get what he's refering to .
> > can u put some light on it.
>
> > -Anand
>
> > On Tue, Aug 3, 2010 at 1:23 PM, FrankG <frankgru...@googlemail.com> wrote:
>
> >> > > - On boot,if i disable vold service and enable mountd ,my android boot
> >> > > breaks. why is this happening in froyo?
>
> >> Their are new classes : VolumeManager and Volume ..
>
> >> BTW .. MountService also changed.
>
> >> Good luck !
> >>    Frank
>
> >> --
> >> 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<android-platform%2Bunsubscrib­e...@googlegroups.com>
> >> .
> >> For more options, visit this group at
Reply all
Reply to author
Forward
0 new messages