Skip to content

Commit 352e040

Browse files
committed
stop com.android.bluetooth and bthal, unload btusb before sleep
stopping com.android.bluetooth to avoid hidl crashes as suggested by Jon West <electrikjesus@gmail.com>
1 parent 6f3f36e commit 352e040

File tree

2 files changed

+32
-40
lines changed

2 files changed

+32
-40
lines changed

post_sleep.sh

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,16 @@ function reprobe_module_if_loaded()
2626
MODULE_RELOAD_LIST=""
2727
# set RESTART_WIFI to true if a wifi module is going to be reloaded, note that users will have to manually turn on wifi again after a wificond restart
2828
RESTART_WIFI=false
29-
# set RESET_BT to true if a bluetooth module is going to be reloaded, note that user might have to manually turn on bluetooth again after bthal restart
30-
RESTART_BT=false
3129

3230
### EXAMPLE:
3331
### if [ "$BOARD" == "xxx" ]
3432
### then
35-
### MODULE_RELOAD_LIST="$MODULE_RELOAD_LIST iwlwifi btusb"
33+
### MODULE_RELOAD_LIST="$MODULE_RELOAD_LIST iwlwifi"
3634
### RESTART_WIFI=true
37-
### RESTART_BT=true
3835
### fi
3936

40-
# usually bluetooth breaks when waking from s3 resets the device, then bthal continues to communicate to it with existing sockets as if the reset had never happened
41-
# while disabling bthal before suspend then starting it after is enough on the steamdeck, reprobing the module should make it work better in a more general sense
42-
RESTART_BT=true
43-
MODULE_RELOAD_LIST="$MODULE_RELOAD_LIST btusb"
37+
# note that btusb is unloaded in pre_sleep.sh, since it takes more than 10+ seconds to unload btusb right after wake
38+
# ie. do not put btusb into the reload list
4439

4540
# users can use this to flag wificond restart
4641
USER_RESTART_WIFI_FLAG=/data/etc/wake_reload_wifi
@@ -49,31 +44,11 @@ then
4944
RESTART_WIFI=true
5045
fi
5146

52-
# users can use this to flag bluetooth restart
53-
USER_RESTART_BT_FLAG=/data/etc/wake_reload_bt
54-
if [ -e $USER_RESTART_BT_FLAG ]
55-
then
56-
RESTART_BT=true
57-
fi
58-
59-
# stop services if requested
60-
if $RESTART_BT
61-
then
62-
setprop ctl.stop btlinux-1.1
63-
setprop ctl.stop vendor.bluetooth-1-1
64-
fi
65-
6647
if $RESTART_WIFI
6748
then
6849
setprop ctl.stop wificond
6950
fi
7051

71-
# setprop ctl.stop should be instant, but just in case
72-
if $RESTART_WIFI || $RESTART_BT
73-
then
74-
sleep 0.2
75-
fi
76-
7752
# perform module reprobe
7853
MODULE_RELOAD_LOG=/data/wake_module_reload_log
7954
rm -f $MODULE_RELOAD_LOG
@@ -101,18 +76,20 @@ then
10176
setprop ctl.start wificond
10277
fi
10378

104-
if $RESTART_BT
105-
then
106-
bthal=$(getprop ro.bliss.bthal)
107-
case $bthal in
108-
"btlinux")
109-
setprop ctl.start btlinux-1.1
110-
;;
111-
"celadon")
112-
setprop ctl.start vendor.bluetooth-1-1
113-
;;
114-
esac
115-
fi
79+
# probe btusb since it was unloaded in pre_sleep.sh
80+
modprobe btusb
81+
82+
# bthal and com.android.bluetooth were disabled in pre_sleep.sh
83+
bthal=$(getprop ro.bliss.bthal)
84+
case $bthal in
85+
"btlinux")
86+
setprop ctl.start btlinux-1.1
87+
;;
88+
"celadon")
89+
setprop ctl.start vendor.bluetooth-1-1
90+
;;
91+
esac
92+
pm enable com.android.bluetooth
11693

11794
# allow user defined actions
11895
USER_SCRIPT=/data/etc/post_sleep.sh

pre_sleep.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ export UEVENT=$(cat $DMIPATH/uevent)
99

1010
# put prebaked actions here
1111

12+
# stop com.android.bluetooth
13+
pm disable com.android.bluetooth
14+
bt_pid=$(pidof com.android.bluetooth)
15+
if [ -n "$bt_pid" ]
16+
then
17+
kill -KILL $bt_pid
18+
fi
19+
20+
# stop bluetooth hal
21+
setprop ctl.stop vendor.bluetooth-1-1
22+
setprop ctl.stop btlinux-1.1
23+
24+
# unload btusb here, because unloading could take 10+ seconds right after wake
25+
modprobe -r btusb
26+
1227
# allow user defined actions
1328
USER_SCRIPT=/data/etc/pre_sleep.sh
1429
if [ -e $USER_SCRIPT ]

0 commit comments

Comments
 (0)