Sending multi touch from a phone to android x86 on Virtualbox using uinput

633 views
Skip to first unread message

Rishi Ranjan

unread,
Oct 20, 2014, 1:00:33 PM10/20/14
to andro...@googlegroups.com
Hi,
    I am trying to send multi touch from a phone to android x86 on Virtualbox using uinput. I am using muti touch screen in android emulator to receive the multi touch data. Once I recei the data, I want to use uinput t inject it into androidx86. 

I have following code to create uinput device but device keeps on getting removed. Looks like there are no drivers to handle multi touch event. Can someone help me what I can change to get this working. 

Code to create Uinput: 

#define UI_SET_PROPBIT          _IOW(UINPUT_IOCTL_BASE, 110, int)
int main(int argc, char **argv)
{
    int uinp_fd = -1;
    struct uinput_user_dev uinp;
    struct input_event event;

                if (!(uinp_fd = open("/dev/uinput", O_WRONLY|O_NDELAY))) {
                    fprintf(stderr, "Unable to open /dev/uinput !\n");
                    exit(-1);
                }

                memset(&uinp, 0, sizeof(uinp));
                strncpy(uinp.name, "ABC", UINPUT_MAX_NAME_SIZE);
                uinp.id.vendor=0x1234;
                uinp.id.product=1;
                uinp.id.version=1;
                uinp.absmin[ABS_MT_POSITION_X]=0;
                uinp.absmax[ABS_MT_POSITION_X]=800;
                uinp.absmin[ABS_MT_POSITION_Y]=0;
                uinp.absmax[ABS_MT_POSITION_Y]=600;


                // Added for MT Touch
                uinp.absmax[ABS_MT_SLOT] = 9;
                uinp.absmax[ABS_MT_TRACKING_ID] = 10;
                uinp.absmax[ABS_MT_TOUCH_MAJOR] = 0x7fffffff; // TODO: Make it less random;
                uinp.absmax[ABS_MT_PRESSURE] = 0x100; // TODO: Make it less random;


                // Added for MT Touch
                ioctl(uinp_fd, UI_SET_PROPBIT, INPUT_PROP_DIRECT);
                ioctl(uinp_fd, UI_SET_EVBIT, EV_ABS);
                ioctl(uinp_fd, UI_SET_EVBIT, BTN_TOUCH);

                // Added for MT Touch
                ioctl(uinp_fd, UI_SET_ABSBIT, ABS_MT_SLOT);
                ioctl(uinp_fd, UI_SET_ABSBIT, ABS_MT_POSITION_X);
                ioctl(uinp_fd, UI_SET_ABSBIT, ABS_MT_POSITION_Y);
                ioctl(uinp_fd, UI_SET_ABSBIT, ABS_MT_TRACKING_ID);
                ioctl(uinp_fd, UI_SET_ABSBIT, ABS_MT_TOUCH_MAJOR);
                ioctl(uinp_fd, UI_SET_ABSBIT, ABS_MT_PRESSURE);
                write(uinp_fd, &uinp, sizeof(uinp));
                if (ioctl(uinp_fd, UI_DEV_CREATE)) {
                    ALOGW("Unable to create ABS uinput device...");
                    fprintf(stderr, "Unable to create ABS uinput device...\n");
                    exit(-1);
                }

    return 0;
}


I am getting following error: 

I/EventHub( 1119): New device: id=7, fd=167, path='/dev/input/event7', name='ABC', classes=0x14, configuration='/system/usr/idc/ABC.idc', keyLayout='', keyCharacterMap='', builtinKeyboard=false, usingSuspendBlockIoctl=true, usingClockIoctl=true
I/InputReader( 1119): Device reconfigured: id=7, name='ABC', size 800x600, orientation 0, mode 1, display id 0
I/InputReader( 1119): Device added: id=7, name='ABC', sources=0x00001002
I/EventHub( 1119): Removing device '/dev/input/event7' due to inotify event
I/EventHub( 1119): Removed device: path=/dev/input/event7 name=ABC id=7 fd=167 classes=0x14
I/InputReader( 1119): Device removed: id=7, name='ABC', sources=0x00001002
D/InputReader( 1119): Could not retrieve current multitouch slot index.  status=-1
E/EventHub( 1119): could not get driver version for /dev/input/js0, Invalid argument

Rishi Ranjan

unread,
Oct 21, 2014, 12:39:54 AM10/21/14
to andro...@googlegroups.com
I have tried using the device id of BUS_USB. BUS_USB is supported by hid-multitouch but still I am getting same error. 

Rishi Ranjan

unread,
Oct 21, 2014, 1:04:29 AM10/21/14
to andro...@googlegroups.com
http://lii-enac.fr/cgi-bin/gitweb.cgi?p=linux-input/libmt-uinput.git;a=tree code worked so my code change in hid-multitouch must be the issue. I will try multitouch with this code now. 

Chih-Wei Huang

unread,
Oct 27, 2014, 5:57:19 AM10/27/14
to Android-x86
If the program you posted is the complete code,
it won't work as expected, because:

1. It must be a daemon. Otherwise when it terminated,
kernel will remove the uinput device it created.
(exactly the symptom you seen)
2. The daemon must write events to the uinput device
it created from some input source.

I suggest read the code in kitkat-x86 to understand
how to write a uinput program:

hardware/libhardware_legacy/power/powerbtnd.c
> --
> You received this message because you are subscribed to the Google Groups
> "Android-x86" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to android-x86...@googlegroups.com.
> To post to this group, send email to andro...@googlegroups.com.
> Visit this group at http://groups.google.com/group/android-x86.
> For more options, visit https://groups.google.com/d/optout.



--
Chih-Wei
Android-x86 project
http://www.android-x86.org

Rishi Ranjan

unread,
Oct 27, 2014, 8:15:01 PM10/27/14
to andro...@googlegroups.com
Hi Chih-Wei,
                 Thank you for pointing me tot he sample code. I will look at it. 

I am creating my code as daemon and reading input evens from a socket. I am sending multi touch data from a Note II to this socket. 

I was following https://www.kernel.org/doc/Documentation/input/multi-touch-protocol.txt spec to create input in uinput device but looks like my understanding of multi touch spec is not correct. I have to send BTN_KEY events also before touch events starts working. 

I will discuss the multi touch protocol on android forum. 

Thanks,
Rishi
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
Message has been deleted
0 new messages