Access and use the values of the accelerometer in the Android kernel level

杀马特。学长 韩版系。学妹 提交于 2021-01-29 06:24:05

问题


How can I access the accelerometer in the android kernel space and use it's data? I'm working on a project where I need to control some of the phone's functionality while the phone is moving (in a car) and I want to use the accelerometer to help determine if the phone had accelerated. It has to all be done in the kernel space. I found on the android developer pages how to use the accelerometer and the SensorEvent to detect changes in a user level application. But how to do something like that on the kernel level? Should I make a system call?

From looking around a bit and searching, I think the files are in /goldfish/drivers/hwmon/ but I'm not quite sure.


回答1:


The accelerometer input, at the antive level, is taken from /dev/input/event devices. You can verify that using the toolbox's getevent(), which will show you the input events in real time as you tilt the phone (if memory serves, you need /dev/input/event3 but you can check this for yourself easily).

The drivers for the accelerometer export this character device, which in turn the Android runtime (with the assistance of libhardware) later converts to the familiar SensorEvent. There is no kernel API for this. Your simplest solution would be to interface with the /dev/event directly. This could be done in two ways:

  1. User mode daemon listens on /dev/event, and also communicates with your kernel thread (e.g. by blocking on another character device which your kernel module exports, reverse system call, etc)

  2. not recommended but would work - opening the /dev/input/event from kernel mode (using a direct call to sys_open and then calls to sys_read). This would require "working around" kernel protections (most notably KERNEL_DS being set).



来源:https://stackoverflow.com/questions/16222919/access-and-use-the-values-of-the-accelerometer-in-the-android-kernel-level

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!