-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathservice.sh
executable file
·112 lines (93 loc) · 2.75 KB
/
service.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
#!/system/bin/sh
# Do NOT assume where your module will be located.
# ALWAYS use $MODDIR if you need to know where this script
# and module is placed.
# This will make sure your module will still work
# if Magisk change its mount point in the future
MODDIR=${0%/*}
# these environment variables below can be customized
# --------------------------------------------------------
# default definitions
ENABLE_LOG=""
ADB_PORT=""
STATUS_CHK_FREQUENCY=""
# --------------------------------------------------------
# constant definitions
DEFAULT_ADB_PORT="5555"
DEFAULT_STATUS_CHK_FREQUENCY="1"
ADB_PORT_PATTERN='^([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$'
STATUS_CHK_FREQUENCY_PATTERN='^([1-9]|10)$'
# functions
print_log() {
[ "$ENABLE_LOG" != "1" ] && return
echo "$(date '+[%Y-%m-%d %I:%M:%S]') $1" >> /data/local/tmp/wifiadb.log
}
start_adb() {
setprop service.adb.tcp.port "$ADB_PORT"
stop adbd
start adbd
}
stop_adb() {
setprop service.adb.tcp.port ""
stop adbd
start adbd
}
check_adb_status() {
if [ "$(getprop init.svc.adbd)" != "running" ]; then
return 0
fi
if [ "$(getprop service.adb.tcp.port)" != "$ADB_PORT" ]; then
return 0
fi
return 1
}
maintain_adb_availability() {
while true; do
# print_log "Checking ADB status..."
if [ -e "${MODDIR}/disable" ]; then
check_adb_status
if [ $? -eq 1 ]; then
print_log "Module is disabled, stopping ADB..."
stop_adb
fi
else
check_adb_status
if [ $? -eq 0 ]; then
print_log "Module is enabled, starting ADB..."
start_adb
fi
fi
sleep $STATUS_CHK_FREQUENCY
done
}
load_config() {
CONFIG_PATH="${MODDIR}/config"
if [ -f "$CONFIG_PATH" ]; then
source "$CONFIG_PATH"
print_log "Config file loaded."
else
print_log "Config file not found."
fi
}
parse_config() {
if ! echo "$ADB_PORT" | grep -Eq "$ADB_PORT_PATTERN"; then
print_log "ADB_PORT parse failed, set to default value"
ADB_PORT=$DEFAULT_ADB_PORT
fi
print_log "ADB_PORT value: $ADB_PORT"
if ! echo "$STATUS_CHK_FREQUENCY" | grep -Eq "$STATUS_CHK_FREQUENCY_PATTERN"; then
print_log "STATUS_CHK_FREQUENCY parse failed, set to default value"
STATUS_CHK_FREQUENCY=$DEFAULT_STATUS_CHK_FREQUENCY
fi
print_log "STATUS_CHK_FREQUENCY value: $STATUS_CHK_FREQUENCY"
}
# This script will be executed in late_start service mode
(
until [ "$(getprop sys.boot_completed)" -eq 1 ]; do
sleep 1
done
load_config
parse_config
print_log "---- magisk-wifiadb started ----"
maintain_adb_availability
) &