-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell.sh
343 lines (329 loc) · 7.97 KB
/
shell.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
#!/bin/sh
function cmdAndGitbash(){
#cmd commands
adb pull /data/data/com.android.providers.settings/databases/settings.db
adb push /d/Software/Temp/PowerManager.apk /system/priv-app/PowerManager
ren D:\Software\Temp\PowerSettingActivity_signed.apk PowerManager.apk
adb push D:\Software\Temp\PowerManager.apk /system/priv-app/PowerManager
adb logcat -c;
adb logcat > D:\WorkMaterial\localrepo\LenovoPower\log.txt
#git-bash commands
mv /d/Software/Temp/PowerSettingActivity_signed.apk /d/Software/Temp/PowerManager.apk
adb pull //data/data/com.android.providers.settings/databases/settings.db
adb push /d/Software/Temp/PowerManager.apk //system/priv-app/PowerManager
adb logcat -c;adb logcat > $outPutFile
adb shell dumpsys notification > D:\WorkMaterial\localrepo\LenovoPower\log.txt
adb shell dumpsys > $outPutFile
adb shell dumpsys activity activities > $outPutFile
}
declare -i index_reboot=0
declare -i index_remount=0
function adbPush()
{
filename=$1
suffix=$2
mountPath=$3
APKDelete=$4
if [ -f $filename*.$suffix ]; then
let index_remount++
if [ $index_remount = 1 ]; then
echo "remount..."
adb root
adb remount
fi
index_reboot=1
case "$suffix" in
apk)
#-f判断filename这个文件是否存在
if [ ! -f $filename.$suffix ]; then
mv $filename*.$suffix $filename.$suffix
fi
if [ "$filename" = "framework-res" ]; then
adb push $filename.$suffix $mountPath
else
adb push $filename.$suffix $mountPath/$filename
fi
;;
jar)
adb push $filename.$suffix $mountPath
;;
esac
strPar="n";
strContains "$APKDelete" "$strPar";
deleteFile=$?;
if [ $deleteFile -eq 0 ]; then
rm $filename.$suffix
fi
fi
}
function confirmDirExist(){
dirname=$1;
#-f判断dirname这个目录是否存在
if [ -d "$dirname" ]; then
rm -rf "$dirname"
fi
mkdir -p "$dirname"
}
function strContains(){
strA=$1;
strB=$2;
result=$(echo $strA | grep "${strB}")
if [ "$result" != "" ]
then
return 1
else
return 0
fi
}
#adbDeviceExists:Test if the adb device exists
function adbDeviceExists(){
while (true)
do
desDevices="List of devices attached";
len_desDevices=$(echo `expr length "$desDevices"`);
adbDevices=$(echo `adb devices`);
len_adbDevices=$(echo `expr length "$adbDevices"`);
if [ $len_desDevices -ne $len_adbDevices ]; then
break 1;
fi
done
}
#demo:describe the command of shell.sh
function demo(){
./shell s r n;r:reboot the device;n:delete the file installed to device
}
#Here comes the operating...
adbDeviceExists;#firstly, judge if the adb devices exists
rootDir=/e/Bat_shell/shell;
outPutFile=$rootDir/log.txt
echo "Parameter1:$1"
#Uppercase to Lowercase
LOWERCASE=$(echo $1 | tr '[A-Z]' '[a-z]')
DeviceReboot=$(echo $2 | tr '[A-Z]' '[a-z]')
APKDelete=$(echo $3 | tr '[A-Z]' '[a-z]')
case $LOWERCASE in
p)
filename=PowerManager;
mv Power*.apk $filename.apk
adbPush $filename "apk" "//system/priv-app"
adb reboot
;;
s)
for filename in \
DownloadProviderUi\
PhotoTable\
ColorProfiles
do
adbPush $filename "apk" "//system/app" $APKDelete
done
for filename in \
DownloadProvider\
SettingsProvider\
Settings\
VpnDialogs\
LenovoSettings\
LenovoSecurity\
NotificationCenterPlus\
NotificationCenter\
Android_battery\
AndroidProcessService\
AndroidPreference\
AndroidStorage\
AndroidTest2\
AndroidTest\
WideTouch\
AndroidCustomedControler\
LenovoBreathingLight\
DocumentsUI
do
adbPush $filename "apk" "//system/priv-app" $APKDelete
done
;;
f)
for filename in \
telephony-common\
framework\
ext\
services\
lenovocomponents
do
adbPush $filename "jar" "//system/framework" $APKDelete
done
for filename in \
lenovo-res\
framework-res
do
adbPush $filename "apk" "//system/framework" $APKDelete
done
;;
odex)
for filename in \
boot-framework\
boot
do
adbPush $filename "oat" "//system/framework/arm" $APKDelete
adbPush $filename "art" "//system/framework/arm" $APKDelete
done
;;
r)
adb kill-server
adb start-server
;;
l)
if [ "$2" = "mtk" ];then
dirname=$rootDir/DeviceInfo/Logcat/mtkLog;
confirmDirExist $dirname;
adb pull //sdcard/mtklog/mobilelog $dirname;
elif [ "$2" = "qcom" ];then
dirname=$rootDir/DeviceInfo/Logcat/qcomLog;
confirmDirExist $dirname;
adb pull //sdcard/log $dirname;
elif [ "$2" = "" ];then
adb logcat -c
echo Tip:Logcat is running......
echo "" > $outPutFile
adb logcat > $outPutFile
elif [ "$2" = "wm" ];then
adb logcat -c
adb logcat -v time -s WindowManager > $outPutFile
else
adb logcat -c
adb logcat |grep "$2"
fi
;;
gp)
adb shell getprop > $outPutFile
;;
dpa)
adb shell dumpsys activity > $outPutFile
;;
dpat)
adb shell dumpsys activity top > $outPutFile
;;
dpaa)
adb shell dumpsys activity activities > $outPutFile;
;;
dpaar)
#显示当前设备的所有任务栈内信息
adb shell dumpsys activity activities | sed -n '/Running activities/,/Run #0/p';
;;
dpi)
adb shell dumpsys input > $outPutFile
;;
dpm)
#查看packageName对应的应用占用的内存情况
packageName="$2";
adb shell dumpsys meminfo $packageName
;;
dpn)
adb shell dumpsys notification > $outPutFile
;;
dpw)
adb shell dumpsys window > $outPutFile
;;
dpww)
adb shell dumpsys window | sed -n '/WINDOW MANAGER WINDOWS/,/mLastDisplayFreezeDuration/p'> $outPutFile
;;
df)
adb shell df > $outPutFile
;;
dbl)
dirname=$rootDir/DeviceInfo/AndroidL_data;
confirmDirExist $dirname;
adb pull //data/data/com.android.providers.settings/databases/settings.db $dirname;
;;
dbm)
userid="$2";
if [ "all" = $userid ];then
dirname=$rootDir/DeviceInfo/Users;
confirmDirExist $dirname;
adb pull //data/system/users $dirname;
else
dirname=$rootDir/DeviceInfo/Users/$userid;
confirmDirExist $dirname;
adb pull //data/system/users/$userid/settings_global.xml $dirname;
adb pull //data/system/users/$userid/settings_secure.xml $dirname;
adb pull //data/system/users/$userid/settings_system.xml $dirname;
adb pull //data/system/users/$userid/restricted-packages.xml $dirname;
adb pull //data/system/users/$userid/package-restrictions.xml $dirname;
adb pull //data/system/users/$userid/registered_services $dirname;
adb pull //data/system/users/$userid/runtime-permissions.xml $dirname;
adb pull //data/system/users/$userid/appwidgets.xml $dirname;
#adb pull //data/data/com.android.providers.settings/databases/settings.db-backup;
#adb pull //data/data/com.android.providers.settings/databases/settings.db-journal;
fi
;;
dbi)
dirname=$rootDir/DeviceInfo/InputInfo;
confirmDirExist $dirname;
adb pull //data/system/input-manager-state.xml $dirname;
;;
dbps)
dirname=$rootDir/DeviceInfo/AndroidProcessService;
confirmDirExist $dirname;
xmlDir=//data/data/com.android.settings/files;
adb pull $xmlDir/mServiceProcessesByName.xml $dirname;
adb pull $xmlDir/mServiceProcessesByPid.xml $dirname;
adb pull $xmlDir/mRunningProcesses.xml $dirname;
adb pull $xmlDir/mInterestingProcesses.xml $dirname;
adb pull $xmlDir/mMergedItems.xml $dirname;
;;
dbcd)
adb pull //data/data/com.bignerdranch.android.criminalintent/databases/dbHelper.db
;;
dbatd)
adb pull //data/data/com.mt.androidtest_as/databases/crimesRecord.db
;;
at2ip)
adb pull //data/data/com.mt.androidtest2/databases/androidtest_at.db
;;
crashlog)
adb pull //sdcard/Download/com.mt.androidtest_as/Crash/mycrash.log
;;
crashlog2)
adb pull //sdcard/Download/com.mt.androidtest/Crash/mycrash.log
;;
ops)
dirname=$rootDir/DeviceInfo/AppOps;
confirmDirExist $dirname;
adb pull //data/system/appops.xml $dirname;
adb pull //system/etc/appops_policy.xml $dirname;
;;
kill)
adb shell kill -9 $2;
;;
pml)
adb shell pm list packages -f > $outPutFile
;;
pinfo)#aapt方式查看$2对应的*.apk的包信息
aapt dump badging $2 > $outPutFile
;;
ps)
if [ "$2" = "" ]
then
adb shell ps
else
adb shell ps | grep $2;
fi
;;
sp)
dirname=$rootDir/DeviceInfo/SharedPreferences;
confirmDirExist $dirname;
adb pull //data/data/com.lenovo.widetouch/shared_prefs $dirname;
;;
root)
adb root
adb disable-verity
adb reboot
;;
esac
#Following judge if reboot the device
strAll=$DeviceReboot;
strPar="r";
strContains "$strAll" "$strPar";
reboot=$?;#if strAll contains strPar,reboot the device
#echo $reboot
if [ $index_reboot = 1 -a "$reboot" -eq 1 ]; then
adb reboot
echo "rebooting..."
fi