-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlocal_connect.sh
executable file
·100 lines (84 loc) · 2.56 KB
/
local_connect.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
#!/bin/bash
# convert to lower case using Linux/Mac compatible syntax (bash v3.2)
PLATFORM_NAME=`echo "$PLATFORM_NAME" | tr '[:upper:]' '[:lower:]'`
if [[ "$PLATFORM_NAME" == "ios" ]]; then
# start containerized usbmuxd service/process
usbmuxd -f &
sleep 2
declare -i index=0
available=0
# as default REMOTE_ADB_POLLING_SEC is 5s then we wait for authorizing ~50 sec only
while [[ $available -eq 0 ]] && [[ $index -lt 10 ]]
do
#87 ios: define exit strategy from container on exit
available=`ios list | grep -c $DEVICE_UDID`
if [[ $available -eq 1 ]]; then
break
fi
available=`ios list | grep -c ${DEVICE_UDID/-/}`
if [[ $available -eq 1 ]]; then
break
fi
sleep ${REMOTE_ADB_POLLING_SEC}
index+=1
done
if [[ $available -eq 1 ]]; then
echo "Device is available"
else
echo "Device is not available!"
exit 1
fi
# exit 0 means all good
exit 0
fi
# start adb allowing remote access by "-a" arg
# https://github.com/sorccu/docker-adb
# 2016-07-02 Due to internal ADB changes our previous start command no longer works in the latest version.
# The command has been updated, but if you were specifying it yourself, make sure you're using adb -a -P 5037 server nodaemon.
# Do NOT use the fork-server argument anymore.
adb -a -P 5037 server nodaemon &
sleep 1
# wait until device is connected and authorized
available=0
# to detect negative state
unauthorized=0
offline=0
declare -i index=0
# as default REMOTE_ADB_POLLING_SEC is 5s then we wait for authorizing ~50 sec only
while [[ $available -eq 0 ]] && [[ $index -lt 10 ]]
do
available=`adb devices | grep -c -w device`
echo "available: $available"
if [[ $available -eq 1 ]]; then
# do not wait default 5 sec pause if everything is good
break
fi
unauthorized=`adb devices | grep -c unauthorized`
echo "unauthorized: $unauthorized"
offline=`adb devices | grep -c offline`
echo "offline: $offline"
sleep ${REMOTE_ADB_POLLING_SEC}
index+=1
done
if [[ $unauthorized -eq 1 ]]; then
echo "Device is not authorized!"
exit 3
fi
if [[ $offline -eq 1 ]]; then
echo "Device is offline!"
exit 2
fi
if [[ $available -eq 1 ]]; then
echo "Device is available"
else
echo "Device is not available!"
exit 1
fi
info=""
# to support device reboot as device is available by adb but not functionaning correctly.
# this extra dumpsys display call guarantees that android is fully booted
while [[ "$info" == "" ]]
do
info=`adb shell dumpsys display | grep -A 20 DisplayDeviceInfo`
echo "info: ${info}"
done