Robot: A tool for recording and replaying Android input event (Touch)

Source: Internet
Author: User

The main purpose of this tool is to record the various actions on the screen, and then replay them multiple times for stability testing and for the recurrence of bugs that require multiple repetitions.

The code is in the following location:

Http://download.csdn.net/detail/dfysy/8479123

Before, others forwarded me a record/replay event program, before KK can be used, but because the Android L enable pie (Positionindependent execution), on L can't use. There is no source code, you can only write another.

The principle of the program:

is to read all the event inputs below the/dev/input, record them all, and then write them back in one at the time of playback. In addition to the contents of the input_event, it is necessary to record which input node the event was read from, since playback requires knowing which node the event should be written to.

Due to the difference between the event occurrence time and the actual read time in the input_event, it is possible to calculate the error (negative value) of the difference between the two events during playback. The best design should be to sort all the read events again according to the occurrence time. However, to simplify the design, the wall clock time to read the event is recorded directly here, although the time relationship between the different input nodes may be biased. But the direct order of the same input node is correct.

The main style of the program is the C and C + + mix, the reason for using C + +, mainly because the use of template processing map and vector, so do not use the C language laborious Baja to implement the relevant insertion search algorithm, the purpose is fast, not to contend.

The main data structures and functions:

Map<string,int> FILENAME2FD; /*input Filenameàinput fd*/

Map<string,int> FILENAME2FDR; /* fd*/in the Filenameà record file in the record file

Map<int,string> Fd2filename;/*input fdàinputfilename*/

Map<int,string> filename*/in a fdà record file in a fdr2filename;/* record file

Map<int,int> fdàinputfd*/in fdr2fd;/* record file

vector<event_info>eventlistfile;/* all lists in the record file so that you don't have to read the file every time */

vector<event_info>eventlistscan; /* Records all event*/read from the input file node

The program is mainly divided into the following parts

1) traverse the Dev/input directory and open All nodes (This section uses the Android getevent section code). Establish a map between FD and file names

Scanandopeninputs (Input_dir);

2) Parse the command input, if it is recording, enter Receiveevents (), read the event of the input file node and save it. Select is used here to monitor the individual input.

ret= Select (MAX_FD, &fds, NULL, NULL, &timeout);

3) Parse the command input, and if it is playback, read each event from the file and calculate the time difference between each event, then write it to the corresponding file node according to the FD and filename corresponding.


Android.mk need to be under the option, so that you can use the STL library, where the static compilation, so as not to download to some devices cannot find the library

Local_c_includes + = Bionic Bionic/libstdc++/include External/stlport/stlport
Local_static_libraries: = libc libstlport_static


Local_force_static_executable: = True
Include $ (build_executable)


TODO:1) Adds the ability to output to a specified file so that different files can be recorded for different test content

2) Add the ability to playback the specified file so that you can use the shell to organize the tests for each function.

Robot: A tool for recording and replaying Android input event (Touch)

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.