Search code examples
androidandroid-sensors

what is android /dev/input/eventX file used for?


Do these file represent all the sensors in a device ? I have a rot access on my android device but when I try to open these files I see that they are empty, my filer browser tells that these files have been modified a few seconds before I browse this directory


Solution

  • These are special character files. Opening them with text editor makes no sense; try accessing them with 'cat': cat /dev/input/event0

    If you create some input on the associated device, like typing on the keyboard, moving the most, activating a sensor, you should see data. This data in 32 byte 'evdev' (Event Device) structures. Its better to look at it with something like: od -h /dev/input/event1

    They represents Linux user input devices like keyboards, mouse or touchpads. On Android they represent sensors too. On my HTC Wildfire, you can find proximity, light, compass sensors.

    You can check your device like that:

    # cat /sys/class/input/event*/device/name
    h2w headset
    atmel-touchscreen
    proximity
    buzz-keypad
    buzz-nav
    lightsensor-level
    curcial-oj
    compass
    

    Browse /sys/class/input directory to find out what they are.

    When Android boots up EventHub (frameworks/base/services/input/EventHub.cpp in the Android source) scans all files in /dev/input and queries each (using IOCTLS to query the device name, version, etc) and creates the appropriate device (like mouse, keyboard, multitouch screen, etc) (by a mechanism as yet still unknown to ribo)

    These 'evdev' 32 byte structures:

    struct input_event {
        struct timeval time;
        unsigned short type;
        unsigned short code;
        unsigned int value;
    };
    

    contain the timestamp of the event, the type of the event, the keycode (or mouse relative motion direction/axis) and a value (such as how much a mouse moved).