In-depth understanding of Android: Wi-Fi, NFC and GPS [excerpt]-Chapter 1 preparations

Source: Internet
Author: User

Thank you for your patience. This book is expected to be available in middle March. From today on, I will include some of the content of this book in my blog. Note that the original article is serialized without being edited by the publisher, so it may look a little non-professional.

[Key point: we recommend that you use source insight or eclipse to read the code from vim.

The skill required for Framework developers is to use Eclipse to debug the System_server code.

Finally, there is no code. For the airpcap tool, please download this book]

Chapter 1 preparations

Main content of this chapter:

  • Describes the composition of this book;
  • Tool usage;
  • Download resources in this book.
1.1 Android system architecture

Android is a mobile development platform launched by Google. The platform is based on the Linux kernel. Figure 1-1 shows the architecture of the system.

Figure 1-1 Android system architecture

As shown in Figure 1-1, the Android system can be divided into four layers:

  • Linux kernel layer. Currently, Android 4.4 (codenamed KitKat) is based on Linux kernel 3.4.
  • Libraries layer, which provides dynamic Libraries (also called shared Libraries), Android runtime Libraries, and Dalvik virtual machines [1. In programming languages, most of these layers are written in C or C ++, so we can simply regard them as Native layers.
  • Above the Libraries layer is the Framework layer, which is mostly written in Java. It is the cornerstone of the Java World on the Android platform.
  • The Applications layer is above the Framework layer. The Applications that directly interact with users are developed in Java.
1.2 use of tools

This section describes three powerful tools used in Android development and source code research.

1.2.1 use of Source Insight

Source Insight is an essential tool for reading Source Code. It is a software in Windows and can be installed through wine on the Linux platform. The following describes how to import Source code in Source Insight.

When using Source Insight, you need to create a Source code Project. You can specify the Source code directory through the menu item Project → New Project.

Note that many readers often add all the Android Source code to the project, which causes the Source Insight to run very slowly.

In fact, you only need to add the source code directory of the current analysis to the project. For example, after creating a Source Insight Project, add only the Source code/framework/base directory. In addition, after the source code under a directory is analyzed, you can use the Project → Add and Remove Project Files option to Remove directories that do not need to be analyzed from the Project. The preceding steps are as follows.

Figure 1-2 add or delete directories in the project

The box on the Right of Figure 1-2 shows that Source Insight supports dynamic addition or deletion of directories. This method can greatly reduce the workload of Source Insight.

Tip: Generally, add the directory under the framework/base to the project. If necessary, add other directories. In addition, for other usage tips of Source Insight, refer to Chapter 1st of "deep understanding of Android: Volume 1.

1.2.2 use of Eclipse

I generally use Source Insight to view Native code, while Eclipse, an integrated development tool recommended by Android, can view both Java code and Native code and debug the core processes of the system.

1. Import the Android Framework Java source code

Note: This step can be implemented only by compiling the complete Android source code. The steps are as follows:

1) copy the Android source code directory/development/ide/eclipse/. classpath to the Android source code root directory.

2) Open the. classpath file in the root directory of the Android source code. This file is for Eclipse, and the path of each module in the source code directory is saved.

Because we only care about the modules related to the Framework, we can comment out directories that are not the Framework from this file. In addition, removing unnecessary modules can speed up the Android source code import. Figure 1-3 shows part of the file.

Figure 1-3. Content diagram of the classpath File

Then, click New> Java Project in the Eclipse menu bar to bring up the dialog box 1-4. Set Location to the path where the Android 4.2 source code is located.

Figure 1-4 import the Android source code

Because there are many Android 4.2 source code files, the import process will last for a long time.

Tip:

1) before importing the source code, you must cancel the Eclipse automatic compilation option (set through Project> Build Project Automatically in the menu bar ). In addition, do not clean up the project after the source code is imported. The cleanup operation will delete the files generated by the source code compilation, resulting in the re-Compilation of the Android system.

2) The author provides a configured. classpath file in the shared resources of this book. Please download and use it.

2. Import Android Native code

This section describes how to import the Android Native code in Eclipse. The steps are as follows:

  • After importing the Java file in the Android Framework, switch to the C/C ++ view (by clicking Window> Open Perspective> select C/C ++ ).
  • Click New → C/C ++ in the menu bar, and then select Convert to a C/C ++ project. 1-5:

Figure 1-5 converting to C ++ engineering Diagram

As shown in figure 1-5, the previous Java project is converted into a C ++ project. However, you still need to complete the following steps.

1) open the path and symbol Setting Dialog of the project through Properties → C/C ++ General → Paths and symbols. 1-6.

Figure 1-6 path and symbol settings

2) In the box above figure 1-6 select the endpoints page, then click Import Settings in the box below, and then select 4.2 source code/development/ide/eclipse/android-include-paths.xml to Import the path configuration.

3) Same as above, select the Symbols page in Figure 1-6, and then Import the 4.2 source code/development/ide/eclipse/android-symbols.xml file through the Import Settings in the box below.

After you have configured the path and symbol file, you can further select the C ++ file to be imported from the Source Location page in Figure 1-6. This step is shown in step 1-7.

Figure 1-7 Filter C ++ files

By using the Add Folder option in Figure 1-7, the reader can select which directories The C ++ files are filtered out. Currently, the author only imports the Native code under the frameworks directory.

After all the files are imported, you can right-click the C ++ project and select Index> Rebuild to regenerate the Native code Index.

Now, the Native code in Android can be imported through the above method.

3. debug SystemServer

To debug SystemServer, follow these steps:

1) Compile the Android source code project first. There are many warnings during compilation. If there is an error, most of the reason is that the. classpath file contains unnecessary modules. You can follow the prompts in Eclipse to handle the issue. Several machines configured by the author are successfully configured once.

2) Right-click the Android source code project and choose Debug As> Debug Configurations from the shortcut menu. the dialog box from 1 to 8 is displayed, and the Remote Java Application column is displayed on the left.

Figure 1-8 Debug Configuration box

3) Click the create button in the black box in Figure 1-8, and then set the dialog box according to the content in the black box in Figure 1-9.

Figure 1-9 Remote Java Application configuration

As shown in figure 1-9, you need to select the Remote debugging port number as 8600 and the Host type as localhost. 8600 is the debug port number of the SystemServer process. Once Eclipse connects to this port, it can debug SystemServer through the JDWP protocol.

Tip: You can also read chapter 1st of "deep understanding Android: Volume 2" to learn more about how to use Eclipse.

1.2.3 use of BusyBox

BusyBox, known as the Swiss army knife on the Linux platform, provides many common tools, such as grep and find. These tools are available in standard Linux, but most of them are removed from the Android system. This makes it difficult for us to debug the program and study the Android system, so we need to install BusyBox on our mobile phone.

1. Download BusyBox

Available from the website.

Figure 1-10 download BusyBox

Note that the website has compiled the corresponding BusyBox based on different platforms. We can download the corresponding file based on our mobile phone. I downloaded a busybox-armv7l that supports Galaxy Note 2.

Upgraded: arm v7 indicates that the ARM instruction set is v7, which is currently supported by the CPU Of the ARM Cortex-A8/A9 series.

2. install and use BusyBox

After downloading BusyBox, you need to push it to your mobile phone. For example:

Adb push busybox/system/xbin # To avoid conflicts, I pushed it to the/system/xbin directory.

Cd/system/xbin # enter the corresponding directory

Chmod 755 busybox # change the busybox permission to Executable

Busybox -- install. # install busybox

Grep # execute the grep Command provided by busybox, or execute the xxx command in busybox xxx.

BusyBox installation is complete. If you execute the busybox command, the output from 1 to 11 is printed.

Figure 1-11 tools provided by BusyBox

We can see that BusyBox provides a lot of tools, so that we will become more powerful when studying Android systems.

Tip: busybox-armv7l downloads are provided in book sharing resources.

1.3 resource download instructions

To alleviate the trouble that Chinese readers cannot download the source code from the Android official website, I shared the Android source code and other resources used in this book on the 115 network drive, as shown in 1-12.

Figure 1-12 Resources

Figure 1-12:

  • 4.2.2.tar.gz is the source code package 4.2.2. Please note that the wpa_supplicant analysis in this book uses wpa_supplicant In the Android 4.1 source code. Therefore, the author copies the wpa_supplicant code in version 4.1 to wpa_supplicant_8_4.1 in the external directory.
  • Classpath is the Android Java configuration file. Change it to. classpath when using it.
  • The busybox-armv7l is BusyBox.
  • Com. cb. eclipse. folding_1.0.6.jar is an Eclipse plug-in named Coffee Byte Java. It can collapse the code segment for ease of reading [2].
  • The last four files are the protocol data packets stored by AirPcap, a Wi-Fi data interception tool. p2p_cap is the data packets stored during P2P testing, wps_pbc and wps_pin are the data packets saved when wsc pbc and PIN are tested, and wpa_supplicant_analysis is the data packets saved when the STA is added to the AP. Readers without the AirPcap tool can use the Wireshark tool to directly import the data to analyze Wi-Fi in a more intuitive way.

Finally, the resource isHttp://115.com/lb/5lbdugrdt4r. In addition, you must pay attention to the author's blog blog.csdn.net/innostto obtain new information.


[1] 4.4 When a virtual machine named ART is added for running, it is believed that its appearance can improve the running speed of the application.

[2] For more information about how to use Android, see Chapter 2. Its electronic version is http://download.csdn.net/detail/innost/4408140.

 

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.