一、Android 机器root命令
1)adb reboot bootloader
::在设备管理中确认有fasboot端口后,再按任意键执行下一步命令
2)pause
3)fastboot oem root
4)fastboot reboot
二、Android机器与pc互传文件
1)将手机指定文件传到pc指定路径下
adb pull /sdcard/Android/xxx D:\xxx\xxx
2)将pc上指定文件传到手机指定路径文件
adb push D:\xxx\xxx /sdcard/Android/xxx
3)将手机上指定文件拷贝到手机新指定路径下
adb shell "cp /sdcard/Android/xxx.mp4 /sdcard/xx/"
4)查询指定关键字的应用进程
adb shell
ps -A | grep keyword
5)查询指定应用的内存
adb shell dumpsys meminfo 应用包名
6)查询Android APP路径
adb shell pm path 应用包名
三、shell脚本常用命令
1)使用 "echo" 命令可以将文本输出到终端或者文件中,而 "date "+%Y-%m-%d %H:%M:%S"
" 这部分会通过执行 "date" 命令获取当前日期和时间,并使用指定的格式进行格式化。 "| tee -a" 则是将输出写入到指定文件中
echo `date "+%Y-%m-%d %H:%M:%S"` 脚本主题描述 | tee -a /sdcard/Android/log/log.txt
2)将包含脚本名称和启动时间信息的文本追加到 "/sdcard/loge.txt" 文件中
strName="storage4"
echo "-----脚本名称:$strName\c"" ""start time"`date "+%H:%M:%S"`"\n" | tee -a/sdcard/loge.tx
3)点击back键和home键
input keyevent KEYCODE_BACK
input keyevent KEYCODE_HOME
4)清除缓存
logcat -c
5)杀APP进程
am force-stop 应用包名
6)启动APP
am start 应用包名/应用活动名
7)点击APP UI坐标
input tap x y
8)Android机器灭屏亮屏
input keyevent 26
9)滑动操作
input swipe start_x start_y end_x end_y 持续时间
10)获取特定进程的PID
adb shell "ps -e | grep 进程关键字 | awk '{print $截取第几个字符}'"
11)获取当前系统中活动(activity)相关的信息
adb shell "dumpsys activity -f top|grep ACTIVITY | awk '{print $2}'"
12)根据关键字查询屏幕开关
adb shell "dumpsys display |grep 'Display State' | tail -1 | cut -b 3-19"
13)
- 用户输入一个文件夹路径。
- 脚本遍历该文件夹及其子文件夹中所有非目录文件。
- 对每个文件,脚本将文件路径追加到当前日期和时间命名的文本文件中。
- 在文本文件中添加分隔线“------------------------------------------------------------------”。
- 使用
findstr
命令搜索文件内容中包含"EXCEPTION"的内容,并将匹配结果追加到相同的文本文件中。
set /p file_dir=
for /f %%i in ('dir /s /b /a-d "%file_dir%"') do (
echo %%i >> "%cd%\%date:~,10%.%time:~,2%.%time:~3,2%.%time:~6,2%.txt"
echo ------------------------------------------------------------------ >> "%cd%\%date:~,10%.%time:~,2%.%time:~3,2%.%time:~6,2%.txt"
findstr /C:"EXCEPTION" "%%i" >> "%cd%\%date:~,10%.%time:~,2%.%time:~3,2%.%time:~6,2%.txt"
四、批处理常用命令
1)setlocal enabledelayedexpansion
是一个Windows批处理脚本中的命令,它开启了延迟变量扩展(delayed variable expansion)模式。在延迟变量扩展模式下,批处理脚本可以在运行时动态地解析变量值,而不是在解析阶段确定变量值。
2)变量赋值
set "Folder1=C:\Users"
3)批处理实现新旧KO文件的升级压测
@echo off
setlocal enabledelayedexpansion
set "Folder1=C:\Users\Desktop\cameraios\201"
set "Folder2=C:\Users\Desktop\cameraios\501"
REM Initialize counters
set /a count_201d=0
set /a count_501=0
set /a total_runs=0
set "reg_data="
set "last_choice=2" REM Default to Folder2 for the first iteration
:main_loop
set /a total_runs+=1
echo ==========================
echo Total runs: %total_runs%
echo Count of data:0x201d: %count_201d%
echo Count of data:0x501: %count_501%
echo ==========================
echo.
echo %date% %time% 执行总次数:!total_runs! >> C:\Users\Desktop\cameraios\log.txt
echo %date% %time% 0x201d执行次数:!count_201d! >> C:\Users\Desktop\cameraios\log.txt
echo %date% %time% 0x501执行次数:!count_501! >> C:\Users\Desktop\cameraios\log.txt
REM Alternate between choices
if !last_choice! == 1 (
set "choice=2"
) else (
set "choice=1"
)
:install
if "%choice%"=="1" (
echo Pushing camera.ko to device from Folder1...
adb push "%Folder1%\camera.ko" /vendor_dlkm/lib/modules
if %errorlevel% neq 0 (
echo Failed to push camera.ko to device from Folder1.
) else (
echo %date% %time% Pushed camera.ko to device from Folder1 successfully. >> C:\Users\Desktop\cameraios\log.txt
set "last_choice=1"
goto post_install
)
) else if "%choice%"=="2" (
echo Pushing camera.ko to device from Folder2...
adb push "%Folder2%\camera.ko" /vendor_dlkm/lib/modules
if %errorlevel% neq 0 (
echo Failed to push camera.ko to device from Folder2.
) else (
echo %date% %time% Pushed camera.ko to device from Folder2 successfully. >> C:\Users\Desktop\cameraios\log.txt
set "last_choice=2"
goto post_install
)
) else (
echo Invalid choice. Please enter 1 or 2.
goto install
)
:post_install
echo.
timeout /t 10 >nul
echo Restarting USB...
adb disconnect
adb connect
echo.
echo Waiting for USB to restart...
timeout /t 10 >nul
if "%choice%"=="1" (
echo.
echo Rebooting device...
adb reboot
timeout /t 60 >nul
echo.
echo Waiting for device to start...
timeout /t 10 >nul
echo.
echo Executing command:adb shell "dumpsys display |grep 'Display State' | tail -1 | cut -b 3-19"
for /f %%a in ('adb shell "dumpsys display |grep 'Display State' | tail -1 | cut -b 3-19"') do set screen_status=%%a
timeout /t 4 >nul
if "%screen_stauts%"=="Display State=ON" (
echo Phone screen is already on.
) else (
echo Phone screen is off. Turning it on and unlocking...
adb shell input keyevent 26
timeout /t 2 >nul
adb shell input keyevent 82
timeout /t 2 >nul
)
echo.
timeout /t 2 >nul
echo Executing command: adb shell am start 应用包名/应用包名.CameraLauncher
adb shell am start 应用包名/应用包名.CameraLauncher
timeout /t 4 >nul
echo.
echo Executing command: adb shell input tap 934 2070
adb shell input tap 934 2070
timeout /t 4 >nul
echo.
timeout /t 4 >nul
echo Executing command: adb shell cat /sys/class//ois2/reg_data
for /f "delims=" %%a in ('adb shell cat /sys/class//ois2/reg_data') do (
echo %%a
set "line=%%a"
echo %date% %time% !line! >> C:\Users\Desktop\cameraios\log.txt
if "!line:data:0x201=!" neq "!line!" (
set /a count_201d+=1
)
)
timeout /t 3 >nul
echo %date% %time% Executing command: logcat201 >> C:\Users\Desktop\cameraios\cameraios.txt
adb logcat -db kernel | findstr "CAM" >> C:\Users\Desktop\cameraios\cameraios.txt
) else if "%choice%"=="2" (
echo.
echo Rebooting device...
adb reboot
timeout /t 60 >nul
echo.
echo Waiting for device to start...
timeout /t 10 >nul
echo.
echo Executing command:adb shell "dumpsys display |grep 'Display State' | tail -1 | cut -b 3-19"
for /f %%a in ('adb shell "dumpsys display |grep 'Display State' | tail -1 | cut -b 3-19"') do set screen_status=%%a
timeout /t 4 >nul
if "%screen_stauts%"=="Display State=ON" (
echo Phone screen is already on.
) else (
echo Phone screen is off. Turning it on and unlocking...
adb shell input keyevent 26
timeout /t 2 >nul
adb shell input keyevent 82
timeout /t 2 >nul
)
echo.
timeout /t 2 >nul
echo Executing command: adb shell am start 应用包名/应用包名.CameraLauncher
adb shell am start 应用包名/应用包名.CameraLauncher
timeout /t 4 >nul
echo.
echo Executing command: adb shell input tap 934 2070
adb shell input tap 934 2070
timeout /t 4 >nul
echo.
timeout /t 4 >nul
echo Executing command: adb shell cat /sys/class//ois2/reg_data
for /f "delims=" %%a in ('adb shell cat /sys/class//ois2/reg_data') do (
echo %%a
set "line=%%a"
echo %date% %time% !line! >> C:\Users\Desktop\cameraios\log.txt
if "!line:data:0x501=!" neq "!line!" (
set /a count_501+=1
)
)
timeout /t 3 >nul
echo %date% %time% Executing command: logcat501 >> C:\Users\Desktop\cameraios\cameraios.txt
adb logcat -db kernel | findstr "CAM" >> C:\Users\Desktop\cameraios\cameraios.txt
)
REM Repeat the loop
goto main_loop
4)读取文件内容并替换字段值或添加新行
@echo off
REM 获取设备 IP 地址
for /f "tokens=*" %%a in ("adb shell ip -f inet addr show wlan0 ^| grep inet ^| awk "{print $2}" ^| cut -d/ -f1") do set "ip_address=%%a"
REM 从设备中复制文件到本地
adb pull /vendor/etc/camera/camxoverridesettings.txt %~dp0\camxoverridesettings.txt
REM 更改当前工作目录到文件所在目录
cd /d %~dp0
REM 读取文件内容并替换字段值或添加新行
setlocal enabledelayedexpansion
set "found1=false"
set "found2=false"
(for /f "tokens=1,* delims==" %%a in (camxoverridesettings.txt) do (
if "%%a"=="logWarningMask" (
echo logWarningMask=0x900c8
set "found1=true"
)else if "%%a"=="logDRQEnable" (
echo logDRQEnable=0
set "found2=true"
) else (
echo %%a=%%b
)
)
if not !found1! == true ( echo logWarningMask=0x900c8)
if not !found14! == true ( echo logDRQEnable=0)
) > temp.txt
REM 将修改后的内容写回到原始文件中
copy /y temp.txt camxoverridesettings.txt
REM 删除临时文件
del temp.txt
adb shell "echo disable > /sys/class/stability/stability_test"
adb reboot bootloader
fastboot devices
fastboot oem root
fastboot reboot
timeout /t 18 /nobreak > nul
:loop
ping -n 1 -w 1000 %ip_address% > nul
if %errorlevel% == 0 (
goto continue
) else (
echo waiting devices reboot...
timeout /t 10 /nobreak > nul
goto loop
)
:continue
REM adb root 机器避免push失败
echo adb root get right...
adb root
adb remount
adb logcat -G 256M
adb disable-verity
REM 重启设备并等待设备重启完成
echo adb root reboot devices...
adb reboot
timeout /t 18 /nobreak > nul
:loop
ping -n 1 -w 1000 %ip_address% > nul
if %errorlevel% == 0 (
goto continue
) else (
echo waiting devices reboot...
timeout /t 10 /nobreak > nul
goto loop
)
:continue
echo reboot done continue.......
adb shell input keyevent 82
echo push camxoverridesettings file to vendor/etc/camera/.......
adb push %~dp0camxoverridesettings.txt vendor/etc/camera/
echo push done reboot devices.......
adb reboot
5)在Android设备的指定目录下,列出所有文件,并每次删除10000个文件
adb shell "cd 目录 && ls | xargs -n 10000 rm -rf"
6)循环安装同包名不同功能的APK
title INSTALL和UNINSTALL APK
@echo off
color 0A
@SET Path=%Path%;%CD%ADB1.0.40
set var2=APK包名
SET COUNTER=0
ECHO 初始化......
ECHO 等待您插入手机......
adb wait- for -device
echo --- begin root
adb reboot bootloader
fastboot oem root
fastboot reboot
for /F %%i in ('adb shell pm list package -3 ') do (
set var=%%i
)
set var1=%var:~8%
:LOOP
SET /a COUNTER+=1
echo LOOP counter=%COUNTER%
set /a num=counter%%2
ECHO counter1=%num%
if "var1" == "var2"(echo uninstall &GOTO uninstall )else(echo insatll &GOTO install)
:uninstall
::adb uninstall "D:\ADB\ADB 1.0.40\ADB 1.0.40\XXX.apk"
adb uninstall --user 0 APK包名
echo 卸载成功......
:install
if "counter1" == "0"(echo counter1==0 &GOTO install2)else(echo counter1!=0 &GOTO install3)
:install2
adb install "apk1路径"
echo 安装成功2......
pause
:install3
adb install -d "apk2路径"
echo 安装成功3......
::adb shell
PAUSE
GOTO LOOP
ECHO on