Hi,
I am trying to create a Java service that listens to kernel netlink uevent in order for it to detect when a Usb device is plugged-in/out.(is there a more simple way to do this in 2.2. ?)
Basically I want a kernel uevent -> broadcast intent service
I found a few classes in the Android source that listen to netlink events. A few are daemons like vold and netd and these run as root(and it is not possible for a apk installed content to run as root ).
I also found android.os.UEventObserver used by the system_server(I think) to do things like dock detection those are found in
frameworks//base/services/java/com/android/server/ and are called DockObserver , HeadsetObserver, BatteryService and HDMIObserver.
UEventObserver spawns a thread that will call native code found in hardware/libhardware_legacy/uevent. This code basically opens the socket
and binds to receive broadcast messages.I believe this happens in the system_server who runs as user "system"
When I try to mimic this behavior I get (as expected?) the following exception:
/ActivityManager( 62): Start proc com.sample.android.platform.core for broadcast com.sample.android.platform.core/com.sample.android.platform.service.PlatformServer: pid=244 uid=1000 gids={3002, 3001, 3003}
D/PlatformServer( 244): Starting
I/UsbDeviceObserver( 244): new Device Observer
W/dalvikvm( 244): threadid=7: thread exiting with uncaught exception (group=0x4001d800)
E/AndroidRuntime( 244): FATAL EXCEPTION: UEventObserver
E/AndroidRuntime( 244): java.lang.RuntimeException: Unable to open socket for UEventObserver
E/AndroidRuntime( 244): at android.os.UEventObserver.native_setup(Native Method)
E/AndroidRuntime( 244): at android.os.UEventObserver.access$000(UEventObserver.java:39)
E/AndroidRuntime( 244): at android.os.UEventObserver$UEventThread.run(UEventObserver.java:97)
(you can see I run a system user by the 1000 system userid) and I have the following permission declared
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Hence my question(s):
system_server who runs as user "system" how can is bind to a port < 1024 ? did I miss something?
How can I get notifications of events (like usb plugging) into my application? I plan to talk to the plugged usb device using libusb.
Greetings
P.S. I also found this thread on a similar subject
http://groups.google.com/group/android-ndk/browse_thread/thread/1f8447c39ddf8606