Analysis of simulated differences between Android [real machine] and [simulator] Touch Screen events

Source: Internet
Author: User

AndroidThe question of the difference between a real machine and a simulator is an eternal topic. Why can't you finish. The existence of a simulator plays a role in it, but do not trust it in everything. Unless you are an android pure upper-layer application developer or enthusiast, I suggest you discard the simulator. Its idealized guidance makes us a lot of trouble. Of course, this is also a good thing. At the very least, I was more interested in finding answers.

The reason for the problem is that there is a need for automated testing. I need to write a script to simulate a series of operations on the touch screen instead of manual testing ~ What do you do when you start camera for 1000 consecutive times and exit this abnormal test after taking a photo ?). This proves that the bug has been solved!

On Linux, you can use sendevent to simulate keyboard or mouse click events. Android is based on linux2.6, so you can also simulate click events. Many web articles provide such a piece of data to show you how to perform simulated clicks:

ADB shell sendevent/dev/input/event0 3 0 110 // X coordinate
ADB shell sendevent/dev/input/event0 3 1 70 // y coordinate
ADB shell sendevent/dev/input/event0 1 330 1 // press the status, which is accurate to the pressure value.
ADB shell sendevent/dev/input/event0 0 0 0 // a required row of data
ADB shell sendevent/dev/input/event0 1 330 0 // lift status, no pressure value
ADB shell sendevent/dev/input/event0 0 0 0 // a required row, equivalent to terminating a complete data segment of Peugeot

 

 

You can click () on the simulator in the above method. However, it is not possible on the real machine because of two reasons.


Lifecycle 1./dev/input/event0 ×

There is only one/dev/input/event0 on the simulator, but it is not on the real machine (if it is true, you still need to leave the factory-_-| ).

 

The device event information obtained using CAT:

# Cat/proc/bus/input/devices

I: Bus = 0000 vendor = 0000 Product = 0000 version = 0000
N: Name = "qtouch-touchscreen"
P: phys =
S: sysfs =/devices/virtual/input/input5
U: uniq =
H: handlers = event5
B: EV = B
B: Key = 400 0 4 0 0 0 0 0 0 0 0
B: ABS = 2750000 11030003

"Qtouch-touchscreen" is not the number of events to be killed. It is possible to say 1234567. It depends on your device.

 

Limit 2. Data Type X

When exploring the cause, pass:

# ADB shell getevent/dev/input/event5> getvalue

 

You can get:

0003 0035 000007c8
0003 0036 00000771
0003 0038 00000001
0000 0002 00000000
0003 0037 00000010
0000 0000 00000000

 

This is different from what I previously imagined. When I saw C, I knew it was a hexadecimal number. The first reaction was to make a 10-hexadecimal conversion. How to convert it?

Int main (INT argc, char * argv []) point by point... (this. c won't be written yet? Can't I write or search ?)

You can get:

3 53 1992
3 54 1905
3 56 1
0 2 0
3 55 16

0 0 0

 

Regardless of the reason, do a test to verify the result:

ADB shell sendevent/dev/input/event5 3 53 1992
ADB shell sendevent/dev/input/event5 3 54 1905.
ADB shell sendevent/dev/input/event5 3 56 1
ADB shell sendevent/dev/input/event5 0 2 0
ADB shell sendevent/dev/input/event5 3 55 16
ADB shell sendevent/dev/input/event5 0 0 0

 

If the operation data is very large, we can use the powerful VI to convert the batch data in the script, for example:

Vim '+ % normal Gg ''+., $ g/^/S // ADB shell sendevent/dev // input // event5/g'' + wq' Value

 

Click

 

Since the test results prove that the messy number is correct, the reason must be investigated! In fact, the root cause of the problem is that the real device in the hand already supports multi-point touch.

In Android, the multi-touch function depends on the following major software bits defined in rawinputevent. Java:

Public class rawinputevent {</P> <p>... <br/> Public static final int abs_mt_touch_major = 0x30; </P> <p> Public static final int abs_mt_touch_minor = 0x31; </P> <p> Public static final int abs_mt_width_major = 0x32; </P> <p> Public static final int abs_mt_width_minor = 0x33; </P> <p> Public static final int abs_mt_orientation = 0x34; </P> <p> Public static final int abs_mt_position_x = 0x35; </P> <p> Public static final int abs_mt_position_y = 0x36; </P> <p> Public static final int abs_mt_tool_type = 0x37; </P> <p> Public static final int abs_mt_blob_id = 0x38; </P> <p>... <br/>}

In keyinputqueue. in Java, the system creates a thread to put all input events into a queue, in keyinputqueue. at the end of Java, convert the multi-point event type to the single point event type and return a new inputdevice.

 

More than 1: Go to bed first ......

Author: yiyaaixuexi published on 1:21:00 Original article link Read: 3887 comment: 20 view comment

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.