ADB 基本命令整理

What Is ADB

Android debug bridge is a command line tool that lets you communicate with connected Android device.

ADB COMMANDS

ADB Debugging

1.  adb devices

Prints a list of all attached devices.

Package Manager

2.  adb install

Pushes an Android application (specified as a full path to an .apk file) to device.

·         adb install test.apk

·         adb install -r test.apk   //replace existing application

3.  adb uninstall

Removes a package from the emulator/device.

·         adb uninstall com.test.app
·         adb uninstall -k com.test.app     //Keep the data and cache directories around after package removal.

4.  adb shell pm list packages

Prints all packages, optionally only those whose package name contains the text in <FILTER>.

·         adb shell pm list packages -s    //Filter to only show system packages.
·         adb shell pm list packages -3    //Filter to only show third party packages.
·         adb shell pm list packages -i    //See the installer for the packages.
 

File Manager

5.  adb pull

Download a specified file from the device to your computer.

·         adb pull /sdcard/demo.mp4   // download /sdcard/demo.mp4  to <android-sdk-path>/platform-tools directory.
·         adb pull /sdcard/demo.mp4 e:    // download /sdcard/demo.mp4 to drive E.
 
 

6.  adb push

Upload a specified file from your computer to the device.

·         adb push test.apk /sdcard     // Copies <android-sdk-path>/platform-tools/test.apk to /sdcard directory.
·         adb push d:	est.apk /sdcard    // Copies d:	est.apk to /sdcard directory.
 

7.  adb shell ls

list directory contents

8.  adb shell cd

change directory

9.  adb shell rm

remove files or directories

rm -f /sdcard/test.txt    //force remove without prompt
rm -r /sdcard/tmp     //remove the contents of directories recursively
rm -d /sdcard/tmp     //remove directory, even if it is a non-empty directory

 

10.adb shell mkdir

make directories

mkdir /sdcard/tmp

 

11.adb shell cp

copy fils and directories to dest

adb shell
cp /sdcard/test.txt  /sdcard/demo.txt    //cp [options] <source><dest>

 

12.adb shell  mv

move or rename files

adb shell

mv /sdcard/tmp   /system/tmp           //move

mv /sdcard/tmp   /sdacrd/test          //rename

 

Logcat

Print log data to the screen.

l  V-----show all info , verbose level

l  D-----show debug level

l  I-----show info level

l  W-----show warning level

l  E-----show error level

l  F-----show fatal level

 

n  Radio-----about network  

n  Event-----activity manager/service manager

n  Main-----default

n  Kernel-----CPU ,memory

n  Bugreport-----ANR ,version ,serial

 

 

13.adb logcat

adb logcat -v time >log.txt

 

14.adb shell dumpsys

dumps system data

adb shell dumpsys battery      //查看电量信息

adb shell dumpsys meminfo    //查看内存信息

adb shell dumpsys cpuinfo     //查看cpu信息

 

Screenshot

15.adb shell screencap

taking a screenshot of a device display

adb shell screencap  /sdcard/screen.png    

adb pull /adcard/screen.png          //download the file from the device

16.adb shell screenrecord

recording the display of devices running Android 4.4 and higher

adb shell screenrecord /sdcard/demo.mp4

adb pull /sdcard/demo.mp4      //download the file from the device

 

System

17.adb shell ps

list the process

adb shell ps aux

adb shell pstree

18.adb shell getprop

adb shell cat /system/build.prop   //获取系统版本信息

ro.build.id=KOT49H

ro.build.display.id=KOT49H.20140814 test-keys

ro.build.version.incremental=20140814

ro.build.version.sdk=19

ro.build.version.codename=REL

该文件存放的数据是以这种等号形式存放的,而且它们是键值对成对出现的。

现在我们再看看getprop取得的结果:

[ro.build.characteristics]: [mbx]

[ro.build.date.utc]: [1407987033]

[ro.build.date]: [2014-08-14 16:50:37]

[ro.build.description]: [k200-user 4.4.2 KOT49H 20140814 test-keys]

[ro.build.display.id]: [KOT49H.20140814 test-keys]

因此,getprop就是将配置文件里的信息读取出来并经过整理后,并以字典的形式展示给用户的。

adb shell getprop ro.serialno                        //获取版本序列号

adb shell getprop ro.build.version.number                          //获取版本号

 

Work Time

日常设置

1.电量设置

adb shell dumpsys battery set level 50

 

2.To capture screenshot

adb shell screencap /sdcard/screen.png

adb pull /sdcard/screen.png

 

3.To fetch System Version

adb shell getprop ro.build.version.number

 

4.To Disable USB Charging during adb connection

adb shell dumpsys battery set usb 0

 

[usb powered : False -> can be verified from "adb shell dumpsys battery"]

 

5.To Enable USB Charging during adb connection

adb shell dumpsys battery set usb 1

 

[usb powered : True -> can be verified from "adb shell dumpsys battery"]

 

6.To verify Battery Percentage

adb shell dumpsys battery

 

7.关键字搜索

adb shell

logcat -v time | grep "OTA"

 

8.抓取实时log

adb logcat - v time >power.txt

 

---------------------------------------------------------------------------

OTA

 

1.device full

cd /data/

mkdir space

dd if=/dev/zero of=/data/space/space.dat bs=1048576 count=3000

 

2.cache full

cd cache

mkdir space

dd if=/dev/zero of=/cache/space/space.dat bs=1048576 count=350

 

3.Reader APP

adb shell

dumpsys package "com.amazon.kindle" | grep 'version'

 

4.MIGU APP

adb shell

dumpsys package 'com.ophone.reader.ui' | grep version

 

--------------------------------------------------------------------------------

 

启动程序

Run adb command to start ContentSupportTestApp -

- adb devices

- adb shell

- am start -n com.amazon.android.app.contentsupport.testapp/.PackageListActivity

 

--------------------------------------------------------------------------------

KPI

 

1.刷机

 

[查看版本信息]adb shell dumpsys package com.amazon.kindle | grep versionName

 

2.传书

adb push (750books) /sdcard/Documents

 

3.adb shell setenforce Permissive

 

4.连接到debug board

 

Install screen to ubuntu:

>apt-get install screen

 

Connect your testing device to with serial cable, serial cable connect to normal usb cable, and normal usb cable to desktop

       

Enter screen mode by cmd:

>sudo screen /dev/ttyUSB0 115200

 

Run cmd in screen mode:

echo 0 > /proc/sys/kernel/printk

(press enter button)

 

echo 1 > /sys/module/printk/parameters/time

(press enter button)

 

echo 1 > /sys/devices/soc0/soc.2/2000000.aips-bus/20f4000.epdc/mxc_epdc_debug

(press enter button)

 

echo 24 >/sys/devices/soc0/soc.2/2000000.aips-bus/20f4000.epdc/temperature_override

(press enter button)

 

svc wifi disable

(press enter button)

 

getevent -tl &

(press enter button)

 

cat /proc/kmsg | grep -i 'update end marker'

 

 

memory test

1.  Collect the same after execution of each case and refer the PSS TOTAL value for memory details

adb shell dumpsys meminfo com.amazon.kindle

2.  Look out for LMK of “com.ophone.reader.ui” after execution of entire suite

adb logcat –v threadtime |grep lowmemorykiller

3.  Get available memory

adb shell cat /proc/meminfo

 

原文地址:https://www.cnblogs.com/Doris9301/p/7357288.html