alert notification from kernel

543 views
Skip to first unread message

andria

unread,
Oct 28, 2011, 9:05:19 AM10/28/11
to Android Linux Kernel Development
Hi,

I work on a kernel module that sometimes raises an alert thanks to
printk. I want to improve it by raising the alert in the user space
like a notification in the status bar. Does anyone know how this can
be done? One way to do it is to do like the sms notification because
as far as I know there is something related to sms an call at kernel
level but I don't know here exactly. So any idea?

Thanks,

Andria

Tiago Maluta

unread,
Nov 1, 2011, 10:41:45 AM11/1/11
to android...@googlegroups.com
you can create a file [1] as a sysfs entry on your system, create a
android service pooling that information and display to user.

[1] example: you can create a "notifications" file and put printk content.

$ cat /sys/kernel/notifications
YOUR MESSAGE

--tm

preetam m.n

unread,
Nov 3, 2011, 12:34:35 PM11/3/11
to android...@googlegroups.com
as said below create a sysfs entries for the aleart.

1. for checking for the alert (it could be something like toggling the switch- saying true or 1 when you have a message and false or 0 when no message).
2. for message

create a handler in the android stack to watch 1st sysfs entry to check for the aleart.
create a intent observer which pops alert on the lcd. make sure the system by default registers for this intent.
when a alert from kernel is given, you handler should be able to recognize it by realizing that the switch is toggled from false to true using cat the 2nd sysfs entry you can get the message content.
immediately broadcast an intent to the registered observers and from there your observer should be able to pop and alert message on lcd.

if you not keen of knowing the message from the kernel you can go ahead and create only one sysfs entry and use the same logic.

- Preetam





--
"The great pleasure in life is doing what people say you cannot do"

Durgadoss Ramanathan

unread,
Nov 4, 2011, 1:27:46 PM11/4/11
to android...@googlegroups.com
Hi Andria,

You can Poll from the User Space using "Handlers" as Preetam mentioned.
But "Polling" is bad. Instead you can use UEvents.

The ideal (Android) way would be:

1. Let your kernel module send an UEvent, whenever the alert raises.
    This can be done by KOBJ_UEVENT(,,.,,)
2. Create a Simple Service in UserSpace that has an UEventObserver. Register this Observer with your
    KOBJ device path name.
You can have a look at android/frameworks/base/services/java/com/android/server/BatteryService.java
to figure out how to use UEventObservers.

3. Whenever you send the UEvent, this Observer will be called by the Android Framework. Inside the observer
code, you can broadCast an Intent to notify other Services/Apps, that can raise a 'notification' or 'Toasts' or
'Alerts'.

Thanks,
Durga
Regards
Durgadoss

andria

unread,
Nov 5, 2011, 7:19:55 PM11/5/11
to Android Linux Kernel Development
Hi guys,

Thanks for answering. I'll give it a try and report back if anything
goes wrong.

Regards
Andrirad

On 4 nov, 18:27, Durgadoss Ramanathan <r.durgad...@gmail.com> wrote:
> Hi Andria,
>
> You can Poll from the User Space using "Handlers" as Preetam mentioned.
> But "Polling" is bad. Instead you can use UEvents.
>
> The ideal (Android) way would be:
>
> 1. Let your kernel module send an UEvent, whenever the alert raises.
>     This can be done by KOBJ_UEVENT(,,.,,)
> 2. Create a Simple Service in UserSpace that has an UEventObserver.
> Register this Observer with your
>     KOBJ device path name.
> You can have a look at android<http://www.google.com/codesearch#cZwlSNS7aEw/>
> /frameworks <http://www.google.com/codesearch#cZwlSNS7aEw/frameworks/>/base<http://www.google.com/codesearch#cZwlSNS7aEw/frameworks/base/&exact_p...>
> /services<http://www.google.com/codesearch#cZwlSNS7aEw/frameworks/base/services...>
> /java<http://www.google.com/codesearch#cZwlSNS7aEw/frameworks/base/services...>
> /com<http://www.google.com/codesearch#cZwlSNS7aEw/frameworks/base/services...>
> /android<http://www.google.com/codesearch#cZwlSNS7aEw/frameworks/base/services...>
> /server<http://www.google.com/codesearch#cZwlSNS7aEw/frameworks/base/services...>/BatteryService.java
> > On Tue, Nov 1, 2011 at 8:11 PM, Tiago Maluta <tiago.mal...@gmail.com>wrote:
>
> >> you can create a file [1] as a sysfs entry on your system, create a
> >> android service pooling that information and display to user.
>
> >> [1] example: you can create a "notifications" file and put printk content.
>
> >>     $ cat /sys/kernel/notifications
> >>     YOUR MESSAGE
>
> >> --tm
>

andria

unread,
Nov 7, 2011, 4:53:04 AM11/7/11
to Android Linux Kernel Development
Hi,

Is UEventObserver only available for the framework? Because when I try
to import this class in my application source code an error is raised.

I've found that there is a kernel API that enables user-space program
execution from kernel thanks to call_userhelpmode but when I tried
that one it returns an error.

Thanks,

Andria



On 4 nov, 18:27, Durgadoss Ramanathan <r.durgad...@gmail.com> wrote:
> Hi Andria,
>
> You can Poll from the User Space using "Handlers" as Preetam mentioned.
> But "Polling" is bad. Instead you can use UEvents.
>
> The ideal (Android) way would be:
>
> 1. Let your kernel module send an UEvent, whenever the alert raises.
>     This can be done by KOBJ_UEVENT(,,.,,)
> 2. Create a Simple Service in UserSpace that has an UEventObserver.
> Register this Observer with your
>     KOBJ device path name.
> > On Tue, Nov 1, 2011 at 8:11 PM, Tiago Maluta <tiago.mal...@gmail.com>wrote:
>
> >> you can create a file [1] as a sysfs entry on your system, create a
> >> android service pooling that information and display to user.
>
> >> [1] example: you can create a "notifications" file and put printk content.
>
> >>     $ cat /sys/kernel/notifications
> >>     YOUR MESSAGE
>
> >> --tm
>

andria

unread,
Nov 8, 2011, 4:41:18 AM11/8/11
to Android Linux Kernel Development
Hi

I just want to update what I said before.

On 7 nov, 10:53, andria <andri...@gmail.com> wrote:
> Hi,
>
> Is UEventObserver only available for the framework? Because when I try
> to import this class in my application source code an error is raised.
>
> I've found that there is a kernel API that enables user-space program
> execution from kernel thanks to call_userhelpmode but when I tried
> that one it returns an error.

The error disappeared I don't know exactly why. The only thing I did
is to wrap the am command with a shell script.
My problem now is that the am command part of the script seems like
never executed unlike other commands as echo which just works fine.

Mohamed El-Houssainy

unread,
Feb 9, 2014, 11:24:31 AM2/9/14
to android...@googlegroups.com
Hi Andria,

Can you tell me how did you use the UEvenetObserver ?
I can't import it and the an error appear to me and i can't solve this problem !
Reply all
Reply to author
Forward
0 new messages