-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathdroid
executable file
·359 lines (330 loc) · 7.21 KB
/
droid
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
#!/bin/bash
DOC=""
DOC+="
devices
- list devices and their model
"
devices() {
lines=$(adb devices | tail --lines=+2)
echo List of devices attached
IFS=$'\n'
output="Serial;Brand;Model;Product;SDK\n"
output+="------;-----;-----;-------;---\n"
for line in $lines ; do
split=($(echo $line | grep -Po "[^\s]+"))
if [[ "$line" == *"no permissions"* ]]; then
output+="$split;no permissions\n"
permissions=${split[@]:1}
continue
fi
if [[ "$line" == *"offline"* ]]; then
output+="$split;offline\n"
offline=${split[@]:1}
continue
fi
export ANDROID_SERIAL=$split
output+="$split;$(getBrand);$(getModel);$(getprop ro.build.product);$(getSdk)\n"
done
echo -e $output | column -t -s ';'
echo ""
if [ ! -z "$permissions" ]; then
echo "* $permissions"
fi
if [ ! -z "$offline" ];then
echo "* $offline - looks like device is offline or adb over network is not enabled on device"
fi
}
DOC+="
start <uri>
- start default app that may resolve the requested uri
"
start() {
shell am start -a android.intent.action.VIEW $@
}
DOC+="
setDate <date format>
- change device date using format yyyyMMdd.HHmmss
"
setDate() {
su date -s $1
}
DOC+="
getIp
- Print all IPs for device. Result may vary depend on device.
"
getIp() {
ip=$(shell netcfg)
if [[ "$ip" == *"not found"* ]]; then
shell ip a
else
echo $ip
fi
}
DOC+="
getSdk
- Print device sdk version number
"
getSdk() {
getprop ro.build.version.sdk
}
DOC+="
getModel
- Print device model
"
getModel() {
getprop ro.product.model
}
DOC+="
getBrand
- Print device brand
"
getBrand() {
getprop ro.product.brand
}
DOC+="
wifiConnect
- Connectos to a wifi network
"
wifiConnect() {
# echo "Use one of following:"
# echo " wifiConnect_service"
# echo " wifiConnect_file"
# #wifiConnect_service
wifiConnect_file
}
DOC+="
wifiConnect_service <ssid> <password>
- Connect to wifi network using an android service
- EXPERIMENTAL
"
wifiConnect_service() {
shell am startservice \
-n com.google.wifisetup/.WifiSetupService \
-a WifiSetupService.Connect \
-e ssid $1 \
-e passphrase $2
}
DOC+="
wifiConnect_file
- Connect to wifi network using configuration file inside device
- EXPERIMENTAL - this one works but need futher improvements.
"
wifiConnect_file() {
echo "Wanted ssid"
read -e ssid
echo "Password:"
read -es pass
echo "Password manager <WPA-PSK>"
read -e mgmt
if [ -z "$mgmt" ]; then
mgmt="WPA-PSK"
fi
{ # try
pull /data/misc/wifi/wpa_supplicant.conf .wifi
} || {
cat >.wifi<<TEXT
ctrl_interface=tiwlan0
update_config=1
device_type=0-00000000-0
TEXT
}
cat >>.wifi<<TEXT
network={
ssid="$ssid"
psk="$pass"
key_mgmt=$mgmt
priority=1
}
TEXT
push .wifi /data/misc/wifi/wpa_supplicant.conf
adb shell chown system.wifi /data/misc/wifi/wpa_supplicant.conf
adb shell chmod 660 /data/misc/wifi/wpa_supplicant.conf
adb shell am start -a android.intent.action.MAIN -n com.android.settings/.Settings
}
DOC+="
screenshot [file name]
- Take a screenshot from device.
"
screenshot() {
file=screenshot.png
if [ ! -z "$1" ]; then
file=$1
fi
shell screencap -p /tmp/screencap.png
pull /tmp/screencap.png $file
orientation=$(orientation)
echo "Orientation '$orientation'"
rotation=$(( $orientation * -90 ))
echo "Rotation '$rotation'"
convert $file -rotate $rotation $file
xdg-open $file &
}
DOC+="
orientation [direction]
- Check or Change device orientation device to direction
none - without parameter, print current orientation
0 - portrait - top
1 - landscape - left
2 - portrait - bottom
3 - landscape - righ
"
orientation() {
orientation=$1
if [ -z "$orientation" ];then
orientation=$(adb shell dumpsys input | grep 'SurfaceOrientation' | grep -oP "\d+" | head -n 1)
if [ -z "$orientation" ]; then
# old devices does not have input service, so we need to dump whole sys
orientation=$(adb shell dumpsys | grep 'SurfaceOrientation' | grep -oP "\d+" | head -n 1)
fi
echo $orientation
exit 0
fi
if [[ $orientation -lt 0 || $orientation -gt 4 ]];then
orientation=0
echo "Orientation value is invalid"
return 1
fi
echo "Orientation $orientation"
shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:$orientation
}
DOC+="
open <home|settings|date>
- Open a predefined activity
"
open() {
home() {
shell am start -a android.intent.action.MAIN -c android.intent.category.HOME
}
settings() {
shell am start -a android.intent.action.MAIN -n com.android.settings/.Settings
}
date() {
shell am start -a android.provider.Settings.ACTION_DATE_SETTINGS
shell am start -n com.android.settings/.DateTimeSettings
}
$1
}
DOC+="
dev <touch>
- Manage some dev options
touch <show|hide>
- manage touch visibility
e.g: $0 dev touch show
"
dev() {
touch() {
show() {
shell content insert --uri content://settings/system --bind name:s:show_touches --bind value:i:1
}
hide() {
shell content insert --uri content://settings/system --bind name:s:show_touches --bind value:i:0
}
$1
}
$@
}
DOC+="
resolution
- Print device resolution
"
resolution() {
shell dumpsys window | grep -A1 Display: | grep -Po "(\d+x\d+)" | head -1
}
DOC+="
density
- Print device density
"
density() {
# grep on the and to remove carriage return (\r)
getprop ro.sf.lcd_density | grep -Po "(\d+)"
}
DOC+="
inches
- Calculate screen inches using resolution and density
"
inches() {
res=$(resolution)
res=(${res/x/ })
density=$(density)
width=${res[0]}
height=${res[1]}
inches=$(bc <<< "scale=3; sqrt( $width^2 + $height^2) / $density ")
echo $inches
}
# Thanks to MaxChinni https://stackoverflow.com/a/24038245/1622925
DOC+="
input <record|playback>
- record and playback inputs on device.
"
input() {
record() {
adb shell getevent | grep --line-buffered ^/ | tee /tmp/android-touch-events.log
}
playback() {
awk '{printf "%s %d %d %d\n", substr($1, 1, length($1) -1), strtonum("0x"$2), strtonum("0x"$3), strtonum("0x"$4)}' /tmp/android-touch-events.log | xargs -l echo adb shell sendevent
}
$@
}
DOC+="
install <url>
- download apk and install on device
"
install() {
file="/tmp/apk.apk"
curl -o $file $1
adb install $file
}
# Thanks to geffchang https://android.stackexchange.com/a/47994
# and Izzy https://android.stackexchange.com/questions/47989/how-can-i-shutdown-my-android-phone-using-an-adb-command#comment64570_47994
DOC+="
shutdown
- shutdown device
"
shutdown() {
# -p stands for --power-off
shell reboot -p
}
DOC+="
su <command>
- send command as super user
"
su() {
shell su -c \"$@\" 0
}
# Just a wrapper for adb shell
shell() {
adb shell $@
}
# Just a wrapper for adb pull
pull() {
adb pull $@
}
# Just a wrapper for adb push
push() {
adb push $@
}
DOC+="
getprop [property name]
- read a property from device
If not property were inform print whole property file
"
getprop() {
if [ -z "$@" ]; then
shell getprop
else
shell getprop $@ | grep -Po "[^\r]+"
fi
}
# Helper command
help() {
cat <<TEXT
Droid Commands
General command
$DOC
TEXT
}
if [ "$(type -t $1)" == "function" ]; then
$@
else
help
fi