android adb与fastboot

sancaiodm Adb命令与工具 2021-09-25 2434 0

adb logcat -b 缓冲区类型  命令;

Android中的日志缓冲区 : system缓冲区 - 与系统相关的日志信息, radio缓冲区 - 广播电话相关的日志信息, events缓冲区 - 事件相关的日志信息, main缓冲区 - 默认的缓冲区;

关闭GPS定位:adb shell settings put secure location_mode 0

开启GPS定位:adb shell settings put secure location_mode 3

1.打开飞行模式: adb shell settings put global airplane_mode_on 1

2.关闭飞行模式    adb shell settings put global airplane_mode_on 0

设置系统灭屏时间:adb shell settings put settings screen_off_timeout 15000 //15秒

adb关闭wifi: adb shell svc wifi disable

adb开启wifi :adb shell svc wifi enbale

蓝牙同理:adb shell svc xxx enbale

开启数据流量 adb shell svc data disable

adb shell svc power stayon [true|false|usb|ac]

--设置屏幕的常亮,true保持常亮,false不保持,usb当插入usb时常亮,ac当插入电源时常亮  

adb shell dumpsys battery    查看电池信息

adb shell dumpsys battery unplug 模拟手机未充电状态

adb shell dumpsys battery reset   让手机充电恢复正常


adb shell dumpsys deviceidle enable 启动手机idle模式

adb shell dumpsys deviceidle force-idle 手机强制进入idle模式

adb shell dumpsys deviceidle 可查看idle模式信息

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

adb shell am start -W package/XXXActivity   //冷启动时间检测

TotalTime:应用的启动时间,包括创建进程+Application初始化+Activity初始化到界面显示。

WaitTime:一般比TotalTime大点,是AMS启动Activity的总耗时。

Android 5.0以下没有WaitTime,所以我们只需要关注TotalTime即可。




在Windows系统下使用adb搜索过滤使用关键字:findstr, Linux系统下使用关键字:grep 

如:adb logcat |findstr tag,          adb  shell |grep tag

adb logcat -s ActivityManager | findstr Displayed   (获取系统当前显示APP包名与Main类)

表示过滤tag为ActivityManager的信息,Displayed为过滤log内容中含此字符中的信息

(Windows bat)adb shell ps | findstr 进程名称

(Mac 终端)adb shell ps | grep 进程名称

netstat -ano|findstr "5037"查看一下什么进程占了5037端口

adb 的源码路径: aosp/system/core/adb下的源码,查看Android.mk你将会发现adb和adbd其实是一份代码,通过宏来编译

清除应用数据与缓存:adb shell pm clear <packagename>

通过adb shell setprop修改system/build.prop 文件时,需要在重启系统。重启之前需要保证build.prop文件的权限为644,否则重启程序之后会出现问题。设置build.prop文件权限如下:

adb shell chmod 644 system/build.prop

看手机是user版本还是userdebug或是eng版本:  adb shell getprop ro.build.type

查看app的内存情况  :     adb shell dumpsys meminfo packagename

查看APP的CPU使用情况   :  adb shell dumpsys cpuinfo | findstr packagename

模拟屏幕点击事件:adb shell input tap x坐标 y坐标

亮屏:  adb shell input keyevent 26     //keyevent 26表示点击power

解锁:  adb shell input swipe 500 50 500 700     //swipe 表示滑动,从500,50滑动到500,700

强制停止APP: adb shell am force-stop <PACKAGE>

强制停止APP:adb shell kill <PID>

等待手机:  adb wait-for-device

查看手机是user版本还是userdebug或是eng版本 adb shell getprop ro.build.type       //依次类推查看任何属性都是这命令

修改属性值: adb shell setprop config.override_forced_orient true

获取屏幕密度: adb shell wm density 

获取屏幕分辨率: adb shell wm size

模拟广播发送到指定应用接收:adb shell am broadcast -a broadcastaction -n "com.google.youtub/com.google.youtub.xxReceiver" -es 参数名 "参数"

启动摄像头 最后参数 0:主摄像头, 1:前摄像头 ,2或是3 副摄像头

adb shell am start -a android.media.action.STILL_IMAGE_CAMERA --ei android.intent.extras.CAMERA_FACING 0

adb shell input keyevent 27     拍照

adb shell input keyevent 4    退回back


//看查某APP的进程ID,如下是找到Settings应用,adb shell ps |grep "XXX" 

xxx@xx-optiplex:~/workcode/xxxx$ adb shell ps |grep "settings"   
grep: warning: GREP_OPTIONS is deprecated; please use an alias or script
system         2383    497 14073796 185416 0                  0 S com.android.settings     //包名完全匹配的   2383就是Settings应用的进程ID
system         2436    497 13806856 92724 0                   0 S com.android.settings:CryptKeeper
u0_a114        4240    497 13670276 70764 0                   0 S com.android.settings.intelligence

查到应用的进程ID后,我们再此基本上还可以查看进程内的线程    adb shell  ps -T -p 123

xxx@xx-optiplex:~/workcode/xxxx$ adb shell  ps -T -p 2383   
USER            PID   TID   PPID     VSZ    RSS WCHAN            ADDR S CMD            
system         2383  2383    497 14073796 182100 0                  0 S ndroid.settings
system         2383  2393    497 14073796 182100 0                  0 S Signal Catcher
system         2383  2394    497 14073796 182100 0                  0 S perfetto_hprof_
system         2383  2395    497 14073796 182100 0                  0 S ADB-JDWP Connec
system         2383  2396    497 14073796 182100 0                  0 S Jit thread pool
system         2383  2397    497 14073796 182100 0                  0 S HeapTaskDaemon
system         2383  2398    497 14073796 182100 0                  0 S ReferenceQueueD
system         2383  2399    497 14073796 182100 0                  0 S FinalizerDaemon
system         2383  2400    497 14073796 182100 0                  0 S FinalizerWatchd
system         2383  2401    497 14073796 182100 0                  0 S Binder:2383_1
system         2383  2402    497 14073796 182100 0                  0 S Binder:2383_2
system         2383  2404    497 14073796 182100 0                  0 S Binder:2383_3
system         2383  2409    497 14073796 182100 0                  0 S HandlerThreadAl
system         2383  2472    497 14073796 182100 0                  0 S RenderThread
system         2383  2476    497 14073796 182100 0                  0 S AsyncTask #1
system         2383  2482    497 14073796 182100 0                  0 S Binder:2383_4
system         2383  2917    497 14073796 182100 0                  0 S queued-work-loo
system         2383  3232    497 14073796 182100 0                  0 S android.bg
system         2383  4234    497 14073796 182100 0                  0 S SettingsIntelli
system         2383  4235    497 14073796 182100 0                  0 S BluetoothUpdate
system         2383  4236    497 14073796 182100 0                  0 S WifiManagerThre
system         2383  4238    497 14073796 182100 0                  0 S pool-2-thread-1
system         2383  4260    497 14073796 182100 0                  0 S pool-2-thread-2
system         2383  4262    497 14073796 182100 0                  0 S pool-2-thread-3
system         2383  4268    497 14073796 182100 0                  0 S pool-2-thread-4
system         2383  4272    497 14073796 182100 0                  0 S Binder:2383_5
system         2383  4276    497 14073796 182100 0                  0 S pool-2-thread-5
system         2383  4719    497 14073796 182100 0                  0 S pool-2-thread-6
system         2383  4721    497 14073796 182100 0                  0 S pool-2-thread-7
system         2383  4723    497 14073796 182100 0                  0 S pool-2-thread-8
system         2383  5085    497 14073796 182100 0                  0 S Binder:2383_6

PID 是进程id, TID(thead id)可以理解为线程的Id。CMD线程名


也可  adb shell top -H -p 123 查看进程内的线程,此方式可以直接看到线程的数量,及运行与休眠线程的数量

Threads: 31 total,   0 running,  31 sleeping,   0 stopped,   0 zombie
  Mem:  2924336K total,  2900440K used,  24469504 free,   3338240 buffers
 Swap:  1813084K total,   109056K used,  1704028K free,  1958900K cached
800%cpu   2%user   0%nice   4%sys 793%idle   0%iow   0%irq   0%sirq   0%host
  TID USER         PR  NI VIRT  RES  SHR S[%CPU] %MEM     TIME+ THREAD          PROCESS                                                                                                                     
 5085 system       20   0  13G 178M 141M S  0.0   6.2   0:00.00 Binder:2383_6   com.android.settings
Threads: 31 total,   0 running,  31 sleeping,   0 stopped,   0 zombie
  Mem:  2924336K total,  2898692K used,  26259456 free,   3338240 buffers
 Swap:  1813084K total,   115712K used,  1697372K free,  1960296K cached
800%cpu   1%user   0%nice   2%sys 797%idle   0%iow   0%irq   0%sirq   0%host
  TID USER         PR  NI VIRT  RES  SHR S[%CPU] %MEM     TIME+ THREAD          
 5085 system       20   0  13G 178M 141M S  0.0   6.2   0:00.00 Binder:2383_6  
 4723 system       20   0  13G 178M 141M S  0.0   6.2   0:00.01 pool-2-thread-8
 4721 system       20   0  13G 178M 141M S  0.0   6.2   0:00.00 pool-2-thread-7
 4719 system       20   0  13G 178M 141M S  0.0   6.2   0:00.01 pool-2-thread-6
 4276 system       20   0  13G 178M 141M S  0.0   6.2   0:00.03 pool-2-thread-5
 4272 system       20   0  13G 178M 141M S  0.0   6.2   0:00.00 Binder:2383_5  
 4268 system       20   0  13G 178M 141M S  0.0   6.2   0:00.00 pool-2-thread-4
 4262 system       20   0  13G 178M 141M S  0.0   6.2   0:00.03 pool-2-thread-3
 4260 system       20   0  13G 178M 141M S  0.0   6.2   0:00.01 pool-2-thread-2
 4238 system       20   0  13G 178M 141M S  0.0   6.2   0:00.03 pool-2-thread-1
 4236 system       20   0  13G 178M 141M S  0.0   6.2   0:00.00 WifiManagerThre
 4235 system       30  10  13G 178M 141M S  0.0   6.2   0:00.00 BluetoothUpdate
 4234 system       30  10  13G 178M 141M S  0.0   6.2   0:00.00 SettingsIntelli
 3232 system       30  10  13G 178M 141M S  0.0   6.2   0:00.01 android.bg     
 2917 system       18  -2  13G 178M 141M S  0.0   6.2   0:00.00 queued-work-loo
 2482 system       20   0  13G 178M 141M S  0.0   6.2   0:00.02 Binder:2383_4  
 2476 system       30  10  13G 178M 141M S  0.0   6.2   0:00.07 AsyncTask #1   
 2472 system       16  -4  13G 178M 141M S  0.0   6.2   0:00.42 RenderThread   
 2409 system       20   0  13G 178M 141M S  0.0   6.2   0:00.05 HandlerThreadAl
^C404 system       20   0  13G 178M 141M S  0.0   6.2   0:00.01 Binder:2383_3

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


Fastboot 部分命令:

boot 引导分区,存放内核kernel和ramdisk的分区(类似windows的bios),如果没有这个分区,那么设备将无法开机。

recovery 类似windows系统的PE重装系统

system 系统C盘

data  //也叫userdata分区 数据分区 好比windows D盘,数据盘

cache 缓存分区 

sdcard  内部存储空间

misc 这个分区中包含了各种以开关量形式保存的系统配置,包括 CID(Carrier or Region ID)、USB配置和某些硬件配置等。这是个很重要的分区,如果它遭到了破坏或有数据丢失,那么设备的一些功能可能无法正常使用


boot分区----------负责启动。

radio分区----------负责驱动。//这个分区是手机的一些底层设备相关的驱动或功能程序吧,如打电话和发短信等

recovery分区-------负责恢复。

boot分区-----------系统内核。

system分区---------系统文件。

cache分区----------系统缓存。

data分区-------用户数据。

verdor分区--edm厂家定制分区

恢复出厂设置会清空data,cache分区的所有数据


列出fastboot设备

fastboot devices

设备上锁,解锁

fastboot  flashing  unlock    # 设备解锁,开始刷机

fastboot  flashing lock    # 设备上锁,刷机完毕

fastboot oem lock 和  fastboot oem unlock  解锁bootloader和上锁

重启相关

fastboot reboot            #重启⼿机

fastboot reboot-bootloader    #重启到bootloader模式,其实就是再次进入fastboot

擦除相关(erase)

fastboot erase boot    #擦除boot分区(擦了引导就没了,会卡在第一屏,)

fastboot erase recovery   #擦除recovery分区

fastboot erase system    #擦除system分区(擦了系统就没了,会卡在第二屏)

fastboot erase userdata    #擦除userdata分区(可擦,清空数据用)

fastboot erase cache    #擦除cache分区(可擦,清空数据用)

fastboot format system    #格式化system分区

fastboot format userdata    #格式化userdata分区

fastboot format  cache    #格式化cache分区


写⼊分区(flash)

fastboot flash boot boot.img    #写⼊boot分区

fastboot flash recovery recovery.img    写⼊recovery分

fastboot flash system system.img    #写⼊system分区

fastboot -S 300M flash system system.img     //解决fastboot 刷 system.img 尺寸限制问题  

获取⼿机的全部信息

fastboot getvar all

fastboot flash splash1 开机画面

sudo fastboot getver:version  查看fastboot版本

Android 擦除nv数据:

adb reboot bootloader

fastboot erase fsg

fastboot erase fsc

fastboot erase modemst1   ///擦除mdem文件

fastboot erase modemst2   ///擦除mdem文件


fastboot -w reboot #清除手机中所有数据然后重启,等同于系统中的“恢复出厂设置”,或Recovery模式的“清空所有数据”操作

等同于:

fastboot format cache

fastboot format userdata

评论