5th Chapter 3 "Monkeyrunner Source code Analysis" Monkey principle-Start Run: Startup script (original)

Source: Internet
Author: User

Heaven Zhuhai Branch Rudder note : Originally this series is to prepare a book, details please see the earlier blog "to seek partners to write the deep understanding of Monkeyrunner" books. But for many reasons, there is no wish. So the draft is shared here, so mistakes are unavoidable. If necessary, please refer to the following, the forwarding of the word also keep the end of each article source and other information.

In this section, let's take a look at how monkey starts up. When we analyze the principle of monkeyrunner in the future, we will see that the client sends a "Monkey-port 12345" command to the Android target test machine via ADB to start the monkey service. So what does this order do? It is actually by calling monkey this shell script to start up the monkey service and then listen to port 12345 on the target device, Finally, Monkeyrunner and other host-side applications can be connected to the port to and from the monkey Send commands to simulate the operation of the user.

This shell script defaults to the Android system, which is located in the "/system/bin/" directory of the system when it is stored:

Code 5-3-1 Monkey Startup script

1# Script to start "monkey" on the device, which has a very rudimentary2# shell.3#4 base=/system5export CLASSPATH=$base/framework/monkey.jar6"" HUP7exec$base/bin com.android.commands.monkey.Monkey $*

The whole script is simply a few lines, the thing is very simple, in general is to set the environment variables for Monkey run, and then start Monkey. Here we will parse the key code:

    • 4-5 rows: Set up the Java Runtime Environment Classpath running Monkey. The purpose of setting up classpath is to tell the Java execution Environment which directories can find the classes or packages that you need to execute the Java program. This is where you specify where the Monkey.jar jar is located, and then export the classpath to the environment variable.

    • Line 6th: Set the shell that starts monkey to ignore the hub signal. Where the trap command represents to not capture a/series signal and processing, the second parameter in the code represents the system's hub signal is captured, the first parameter represents how to handle the captured signal, which is set to NULL, the representative does not do any processing, that is, ignore the captured hub signal. So what does the hub signal mean? This requires the reader to have some basic knowledge of the Linux operating system. Hub signal is also called sighup signal, in fact, is signal hangup abbreviation, translation is the signal of the end process. The system's default processing of the SIGHUP signal is to terminate the process of receiving the signal. So if the signal is not captured in the program, the process exits when the signal is received. So here we are capturing the signal, but not doing any processing after capture (because the second parameter of the trap is empty for the capture signal), the advantage of doing this is to try to end the monkey service with the Sighub signal elsewhere, such as in the event of an exception, Ensure that the monkey will continue to run on the target Android machine

    • Line 7th: This is a normal Android command to start the Java app. There are several ways to launch Java apps in Android, which is one of the app_process command launches. The argument "Com.android.commands.monkey.Monkey" in the command specifies the monkey's entry function, "[email protected]", which is the parameter that the user passed in, such as "-port 12345", Will eventually be passed to the class above for parsing.

——— to Be Continued ———

Heaven Zhuhai Branch Rudder
Public Number: Techgogogo
Weibo: Http://weibo.com/techgogogo
Csdn:http://blog.csdn.net/zhubaitian

5th Chapter 3, "Monkeyrunner Source Analysis" Monkey theory-start Run: Startup script (original)

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.