-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwakelock-source-hunter.sh
63 lines (38 loc) · 1.58 KB
/
wakelock-source-hunter.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
#!/bin/bash
SLEEP=30
WAKELOCK=IPA_WS
PARENT=$(dumpsys window windows | grep mCurrentFocus | cut -d'{' -f2 |cut -d' ' -f3 |cut -d'/' -f1)
echo -e "Parent app is ${PARENT}, will skip it during the tests.\n"
if [ ! -e /sys/kernel/debug/wakeup_sources ]; then
echo "Error: can't find the wakeup_sources file."
exit 1
fi
if ! grep ${WAKELOCK} /sys/kernel/debug/wakeup_sources >/dev/null; then
echo "Error: you have selected the ${WAKELOCK} to hunt down, but your phone doesn't have this wakelock. Please edit this script and select another wakelock."
exit 1
fi
echo -e "I will count ${WAKELOCK} wakelocks during disabling apps one-by-one. But before I'll make some baseline with all apps enabled. Please wait...\n"
for i in $( seq 3 ); do
printf "Baseline ..."
BEFORE=$(grep ${WAKELOCK} /sys/kernel/debug/wakeup_sources |awk '{ print $2; }')
sleep ${SLEEP}
AFTER=$(grep ${WAKELOCK} /sys/kernel/debug/wakeup_sources | awk '{ print $2; }')
COUNT=$(( AFTER - BEFORE ))
printf "\r%10d baseline\n" ${COUNT}
done
pm list packages -3 -e | while read -r LINE; do
PACKAGE=${LINE#*:}
if [ "$PACKAGE" == "$PARENT" ]; then
continue
fi
printf "%s ..." ${PACKAGE}
BEFORE=$(grep ${WAKELOCK} /sys/kernel/debug/wakeup_sources | awk '{ print $2; }')
pm disable ${PACKAGE} >/dev/null
sleep ${SLEEP}
AFTER=$(grep ${WAKELOCK} /sys/kernel/debug/wakeup_sources | awk '{ print $2; }')
pm enable ${PACKAGE} >/dev/null
COUNT=$(( AFTER - BEFORE ))
printf "\r%10d %s\n" ${COUNT} ${PACKAGE}
# This sleep is for braking the script without stucking an app disabled
sleep 5
done