Android--brush machine and adb

Table of contents

1. Android device startup process

2. Introduction of flashing mode

3. Windows command line

Fourth, adb introduction and configuration

5. Commonly used adb commands


1. Android device startup process

Android is the Linux kernel (Kernel) + Java virtual machine (JVM)

Android device startup is divided into two stages:

  • Linux start

1. Turn on the power and start the system:

When the power button is pressed, the boot chip code starts to execute from a predefined place (solidified in ROM), loads the boot program BootLoader into RAM, and then starts to execute.

2. Bootloader:

The bootloader (Bootloader) is a small program before the Android operating system is started, and its main function is to load the system operating system into the memory and start its operation.

3. Linux kernel startup

When the kernel starts, it sets the cache, protected memory, plan list, and loads the driver. When the kernel completes the system settings, it first looks for the init.rc file in the system file and starts the init process.

  •  android start

4. The init process starts:

The init process is the first process in the user space in the Android system, and the process number is 1. Initialize and start the attribute service, and start the Zygote process.

5. Zygote process:

Create a Java virtual machine and register the JNI method for the Java virtual machine, create a server-side Socket, and start the SystemServer process.

6. The SystemServer process starts:

Start the Binder thread pool and SystemServiceManager, and start various system services.

7. Launcher start:

The AMS started by the SystemServer process will start the Launcher. After the Launcher is started, the shortcut icons of the installed applications will be displayed on the interface.


2. Introduction of flashing mode

  • wire brush

During the BootLoader stage, if you find a special combination of keys, such as the volume + key and the power key, you will enter the fastboot mode: it is a special stage entered during the bootloader period, you can connect to the computer through a data cable, and then execute some commands on the computer , such as flashing the system image to the mobile phone, fastboot can be understood as implementing a simple communication protocol, receiving commands and updating the image file, and nothing else can be done. This brushing method is called "wire brushing".

  •  card swiping

If there is no key to enter fastboot, the bootloader will continue to execute, and if a special key combination is found, it will enter recovery mode: in a sense, this is a small operating system, which is the same as the kernel of the system that is normally booted into , but the things done after init and after are different.

In the recovery mode, part of the file system will be loaded, so you can read the update.zip in the sdcard for flashing, of course, you can also clear the cache and user data. This way of flashing is called "card swiping".

  • Enter fastboot (bootloader) mode

1. Most Android phones can enter the fastboot mode when they are turned off, and then press and hold the [Power button] + [Volume +] buttons at the same time for about 2-3 seconds;

2. As a developer, we can generally use the adb command to enter in the boot state: adb reboot bootloader, generally there will be "fastboot mode" related words after entering. 

As shown below:

 

  • Commands to be executed for flashing in fastboot mode 
# 命令格式:
fastboot flash xxx xxx.img
# 如下:
fastboot flash system system.img
fastboot flash boot boot.img
fastboot flash apdp apdp.img
fastboot reboot
  • recovery mode 

1. Enter recovery through key combination;

2. Perform operations such as installation/reset/clear cache in the upper application settings to enter recovery and OTA upgrade;

3. The key components of the Android system are running abnormally, and the device will automatically enter the recovery mode under special circumstances such as repeated restarts.


3. Windows command line

There are two ways to enter:

  1. Shortcut key (win+R), enter cmd and press Enter;
  2. Find the "Command Prompt" program.

Common commands:

#1.目录跳转
cd //(同Linux命令cd)
cd .. //进入上级目录
cd /d d: //进入上次d盘所在的目录(或者直接输入:d:)
cd /d d:\ //进入d盘根目录
#2.列出文件
dir //(同Linux命令ls)
#3.查找字符串
findstr //(同Linux命令grep)
#4.其它
md //创建目录(同Linux命令mkdir)
copy //拷贝文件(同Linux命令cp)
del //删除文件(同Linux命令rm)
rd //删除目录(同Linux命令rm -r)
move //移动文件(同Linux命令mv)


Fourth, adb introduction and configuration

        Android Debug Bridge, Android Debug Bridge, referred to as ADB.

        ADB is a versatile command-line tool that allows you to communicate with your device. adb commands can be used to perform various device operations such as installing and debugging applications. It is a debugging tool that we often use for Android development. Of course, its use must be mastered by our Android developers;

  • How does the adb command work? 

        It is a client-server program that includes the following three components:

        1. Client: used to send commands. The client runs on the development machine and can be invoked from the command line terminal by issuing the adb command.

        2. Daemon (adbd): Used to run commands on the device, the daemon runs as a background process on each device.

        3. Server: Used to manage the communication between the client and the daemon, the server runs as a background process on the development machine.

  • The adb environment variable configuration is divided into three steps:

        1. Right-click This Computer, select Properties, and then select Advanced System Settings;

        2. Set the environment variable, double-click Path in the system variable, and then click New to fill in the path of adb;

        3. After clicking OK, enter adb version in the cmd window to verify, as shown in the figure below.

  • Turn on adb debugging for the device

        To use adb on a device connected via usb, you must enable USB debugging (located under the developer option) in the device's system settings. For non-userdebug versions of the phone, the "developer option" is hidden by default. To display it, please go to the phone's Settings --> About Phone -->, click "Version Number" several times, and a prompt will pop up:

"Developer options have been turned on", return to the previous screen, and you can find the developer options at the bottom. (Note: The position and name of "Developer Options" on the screen will vary depending on the device)


5. Commonly used adb commands

//1.查看当前连接电脑的设备(如有多台设备连接,需要加-s参数进行选择)
$ adb devices
List of devices attached
emulator-6666 device
emulator-6667 device
$ adb -s emulator-6666 install camera.apk
//2.重启连接成功的设备
adb reboot
//3.将apk安装到已连接的设备上,-r:强制安装,-d:运行版本代码降级,-t:允许安装测试apk
adb install (-r -d -t) <apk-path> 
//4.推送、拉取文件
adb pull <remote-path> <local-path>
adb push <local-path> <remote-path>
//5.root当前的手机并挂载
adb root & adb remount
//6.进行设备或者模拟器的shell,如同进入Linux系统
adb shell
//7.在设备上执行command,command可为任意可执行程序,.exe文件
adb shell [command]
//8.查看手机内属性
adb shell getprop 
//9.查看一个文件,cpu信息
adb shell cat /proc/cpuinfo
adb shell cat /proc/memoinfo
//10.Android系统服务相关的命令(am  pm  input)
//10.1 启动拨号盘
adb shell am start -a android.intent.action.CALL -d tel:10086
//10.2 杀掉一个应用
adb shell am force-stop com.some.package
//10.3 查看com.some.package在手机上的路径
adb shell pm path com.some.package
//10.4 模拟按键,keycode对应设备某些功能
adb shell input keyevent <keycode>
//11.dumpsys:获取在连接的设备上运行的所有系统服务的诊断输出
adb shell dumpsys -l
adb shell dumpsys activity
adb shell dumpsys window
adb shell dumpsys batterystats
adb shell dumpsys meminfo package_name|pid [-d]
//12.logcat,抓取日志
adb shell logcat
// -b <buffer>	指定log类型,如 events、radio。默认是main、system 和 crash 缓冲区集。
adb shell logcat -b radio
// -c, --clear	清除(清空)所选的缓冲区。
adb shell logcat -c
// 只显示包含“tag”字符后的log
adb shell logcat | findstr “tag”	
// 将log保存到文件d:/xxx/log.txt
adb shell logcat > d:/xxx/log.txt	

This article is only a brief introduction to Android flashing and adb commands, there are still many details and in-depth content that have not been covered. Please feel free to point out any inaccuracies or incompleteness, I would be very grateful.

Guess you like

Origin blog.csdn.net/weixin_44715733/article/details/130748453