安卓系统应用调试脚本
这是一个对之前写的脚本的记录档案,自己也看不太懂当时的写法了,羞愧。用一个 repo 放这些脚本代码感觉有些浪费,干脆整个文章记录曾经的那段历史吧!
这代码的主要目的就是想少敲点命令,一步到位,做一个快男!
说明 - AndroidROMTools
Android run script tools for debugging system apps or frameworks. This was used by myself when debugging system apps or frameworks. In this project, module names was not given to avoid the project name, but the main structure was reminded.
此脚本主要分成一个入口与两个模块,详细的树状图如下:
1 | . |
入口
名字叫 btool
,为啥起这个怪名字,我也不知道。
1 | !/bin/bash |
Utils
初始化:
init.sh
1
2
3!/bin/bash
adb root
adb wait-for-device remount打印带颜色的字符:
printOperationTip.sh
1
2
3
4
5
6!/bin/bash
echo -e "\e[31;43m-----------------------------------------------------------\e[0m"
echo ""
echo -e "\e[31;47m\t"$1"\t\e[0m"
echo ""
echo -e "\e[31;43m-----------------------------------------------------------\e[0m"模块未完成的告警提示:
tipWhenNotImplement.sh
1
2/bin/bash
echo -e "\nModule < \e[41m$1\e[0m \e[31m>NOT IMPELEMNT!\e[0m\n"参数错误提示:
tipWhenParametersError.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21/bin/bash
clear
echo ""
echo -e "\e[31;42mOops! Please give me the \e[0m\e[1;5;40;31mcorrect\e[0m\e[31;42m parameters!!!\e[0m"
echo ""
params=""
cnt=1;
for i in $@;
do
if [ $cnt != 1 ]; then
params=$params",\e[1;5;31;40m "$i" \e[0m"
else
params="\e[1;5;31;40m "$i" \e[0m"
fi
cnt=$(($cnt+1))
done
if [ $cnt == 1 ]; then
params="\e[4;31mNONE\e[0m"
fi
echo -e "\e[33mavaliable parameters are :\e[0m" $params"\n"处理特定任务:
handleSpecificTask.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108!/bin/bash
UTILS_DIR=~/.PersonalTools/utils
OP_INDEX=$1
PROJECT_SRC_DIR=$2
APP_SRC_DIR=$3
APP_OUT_DIR=$4
APP_REMOTE_DIR=$5
APP_PKG_NAME=$6
PROJECT_LUNCH_IDX=$7
for i in $@; do
statements
echo $i
done
for compile SnapCamera APK in
if [ -f /tmp/btoollog ]; then
echo "exist"
else
echo "/tmp/btoollog not exists"
mkdir /tmp/btoollog
fi
function compileModifiedSourceCode(){
{UTILS_DIR}/printOperationTip.sh "<Prepare to Compile>"
cd ${PROJECT_SRC_DIR}
pwd
source build/envsetup.sh
lunch ${PROJECT_LUNCH_IDX}
cd ${APP_SRC_DIR}
pwd
mm
}
function makeSureCloseCompletelyAndReopen(){
{UTILS_DIR}/printOperationTip.sh "<Prepare to force-stop APK>"
echo -e "\n\e[32m\ttry to stop app\e[0m"
adb shell am force-stop ${APP_PKG_NAME}
echo -e ""
echo -e "\n\e[32m\ttry to start app\e[0m"
adb shell am start -n ${APP_PKG_NAME}
echo -e ""
}
function pushCompiledAPK2Phone(){
{UTILS_DIR}/printOperationTip.sh "<Prepare to Push APK>"
cd ${APP_OUT_DIR}
pwd
echo "${APP_OUT_DIR}"
adb push . ${APP_REMOTE_DIR}
adb push oat/arm64/$appname.odex /system/priv-app/$appname/oat/arm64/$appname.odex
if [ $? -eq 0 ]; then
echo -e "\n\e[32m\tpush app to phone successfully\e[0m"
fi
echo -e ""
}
function checkPushedFilesStatus(){
{UTILS_DIR}/printOperationTip.sh "<Prepare to Check Push Result>"
adb shell ls -l ${APP_REMOTE_DIR} ${APP_REMOTE_DIR}/oat/arm64/
if [ $? -eq 0 ]; then
echo -e "\n\e[32m\tconnect to phone successfully\e[0m"
fi
echo -e ""
}
case $1 in
"0" )
compileModifiedSourceCode
pushCompiledAPK2Phone
makeSureCloseCompletelyAndReopen
checkPushedFilesStatus
;;
"1" )
compileModifiedSourceCode
;;
"2" )
pushCompiledAPK2Phone
;;
"3" )
makeSureCloseCompletelyAndReopen
;;
"4" )
checkPushedFilesStatus
;;
"subl" )
subl ${APP_SRC_DIR}
;;
"src" )
echo ${APP_SRC_DIR}
;;
* )
{UTILS_DIR}/tipWhenParametersError.sh 0 1 2 3 4 subl src
echo -e "\t\e[1;4;5;31;40m 0 \e[0m\t : \e[33m1 -> 2 -> 3 -> 4\e[0m"
echo -e "\t\e[1;4;5;31;40m 1 \e[0m\t : \e[33mCompile Modified Source Code\e[0m"
echo -e "\t\e[1;4;5;31;40m 2 \e[0m\t : \e[33mPush Compiled APK 2 Phone\e[0m"
echo -e "\t\e[1;4;5;31;40m 3 \e[0m\t : \e[33mClose App\e[0m"
echo -e "\t\e[1;4;5;31;40m 4 \e[0m\t : \e[33mShow App Info\e[0m"
echo -e "\t\e[1;4;5;31;40m subl \e[0m\t : \e[33mOpen App Src With Sublime Text\e[0m\n"
echo -e "\t\e[1;4;5;31;40m src \e[0m\t : \e[33mPrint SRC path\e[0m\n"
;;
esac
模块
Android Framework 处理:
handleFramework.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18!/bin/bash
SRC_HOME=/home/ckt/work/xxxxxx/msm8909_go/LINUX/android/frameworks/base
OUT_HOME=/home/ckt/work/xxxxxx/msm8909_go/LINUX/android/out/target/product/msm8909go/system/framework
cd /home/ckt/work/xxxxxx/msm8909_go/LINUX/android/
source build/envsetup.sh
lunch 29
make framework
make snod
adb push ${OUT_HOME}/arm/boot.oat /system/framework/arm/
adb push ${OUT_HOME}/arm/boot.art /system/framework/arm/
adb push ${OUT_HOME}/framework.jar /system/framework/
adb push ${OUT_HOME}/framework-res.apk /system/framework/
adb reboot bootloader桌面时钟:
handleXxxx.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23/bin/bash
UTILS_DIR=~/.PersonalTools/utils
PROJECT_DIR="/home/ckt/work/android8"
PROJECT_SRC_DIR=${PROJECT_DIR}
PROJECT_OUT_DIR=${PROJECT_DIR}/out/target/product/msm8953_64
PROJECT_LUNCH_IDX=39
DESKCLOCK_SRC_DIR=${PROJECT_SRC_DIR}/packages/apps/DeskClock/
DESKCLOCK_OUT_DIR=${PROJECT_OUT_DIR}/system/app/DeskClock/
DESKCLOCK_PKG_NAME=com.android.deskclock
DESKCLOCK_REMOTE_DIR=/system/app/DeskClock
case $1 in
"deskclock" )
{UTILS_DIR}/handleSpecificTask.sh $2 ${PROJECT_SRC_DIR} ${DESKCLOCK_SRC_DIR} ${DESKCLOCK_OUT_DIR} ${DESKCLOCK_REMOTE_DIR} ${DESKCLOCK_PKG_NAME} ${PROJECT_LUNCH_IDX}
;;
* )
{UTILS_DIR}/tipWhenParametersError.sh deskclock
;;
esac多媒体应用:
handleXxxxxx.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46!/bin/bash
UTILS_DIR=~/.PersonalTools/utils
PROJECT_DIR="/home/ckt/work/xxxxxxx/LINUX/android"
PROJECT_SRC_DIR="${PROJECT_DIR}"
PROJECT_OUT_DIR="${PROJECT_DIR}/out/target/product/msm8909go"
PROJECT_LUNCH_IDX=29
SOUNDRECORDER_SRC_DIR="${PROJECT_SRC_DIR}/packages/apps/SoundRecorder/"
SOUNDRECORDER_OUT_DIR="${PROJECT_OUT_DIR}/system/priv-app/SoundRecorder/"
SOUNDRECORDER_PKG_NAME=com.android.soundrecorder
SOUNDRECORDER_REMOTE_DIR=/system/priv-app/SoundRecorder
GALLERY_SRC_DIR="${PROJECT_SRC_DIR}/packages/apps/Gallery2/"
GALLERY_OUT_DIR="${PROJECT_OUT_DIR}/system/app/Gallery2/"
GALLERY_PKG_NAME=com.android.gallery3d
GALLERY_REMOTE_DIR=/system/app/Gallery2
SNAPDRAGONMUSIC_SRC_DIR="${PROJECT_SRC_DIR}/packages/apps/Music/"
SNAPDRAGONMUSIC_OUT_DIR="${PROJECT_OUT_DIR}/system/app/Music/"
SNAPDRAGONMUSIC_PKG_NAME=com.android.music
SNAPDRAGONMUSIC_REMOTE_DIR=/system/app/Music
CLOCK_SRC_DIR="${PROJECT_SRC_DIR}/packages/apps/DeskClock"
CLOCK_OUT_DIR="${PROJECT_OUT_DIR}/system/app/DeskClock"
CLOCK_PKG_NAME=com.android.deskclock
CLOCK_REMOTE_DIR=/system/app/DeskClock
case $1 in
"soundrecorder" )
{UTILS_DIR}/handleSpecificTask.sh $2 ${PROJECT_SRC_DIR} ${SOUNDRECORDER_SRC_DIR} ${SOUNDRECORDER_OUT_DIR} ${SOUNDRECORDER_REMOTE_DIR} ${SOUNDRECORDER_PKG_NAME} ${PROJECT_LUNCH_IDX}
;;
"gallery" )
{UTILS_DIR}/handleSpecificTask.sh $2 ${PROJECT_SRC_DIR} ${GALLERY_SRC_DIR} ${GALLERY_OUT_DIR} ${GALLERY_REMOTE_DIR} ${GALLERY_PKG_NAME} ${PROJECT_LUNCH_IDX}
;;
"music" )
{UTILS_DIR}/handleSpecificTask.sh $2 ${PROJECT_SRC_DIR} ${SNAPDRAGONMUSIC_SRC_DIR} ${SNAPDRAGONMUSIC_OUT_DIR} ${SNAPDRAGONMUSIC_REMOTE_DIR} ${SNAPDRAGONMUSIC_PKG_NAME} ${PROJECT_LUNCH_IDX}
;;
"clock" )
{UTILS_DIR}/handleSpecificTask.sh $2 ${PROJECT_SRC_DIR} ${CLOCK_SRC_DIR} ${CLOCK_OUT_DIR} ${CLOCK_REMOTE_DIR} ${CLOCK_PKG_NAME} ${PROJECT_LUNCH_IDX}
;;
* )
{UTILS_DIR}/tipWhenParametersError.sh soundrecorder gallery music clock
;;
esac
目前这些脚本对我来说,已无实际用途,不能保证准确性,只是做一个纪念,纪念那段无知却在挣扎的时光。