Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restart bthal on wake, allow user defined module reprobe #5

Open
wants to merge 2 commits into
base: typhoon-x86
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions device.mk
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ endif
PRODUCT_COPY_FILES := \
$(if $(wildcard $(PRODUCT_DIR)init.rc),$(PRODUCT_DIR)init.rc:root/init.rc) \
$(if $(wildcard $(PRODUCT_DIR)init.sh),$(PRODUCT_DIR),$(LOCAL_PATH)/)init.sh:system/etc/init.sh \
$(if $(wildcard $(PRODUCT_DIR)pre_sleep.sh),$(PRODUCT_DIR),$(LOCAL_PATH)/)pre_sleep.sh:system/etc/pre_sleep.sh \
$(if $(wildcard $(PRODUCT_DIR)post_sleep.sh),$(PRODUCT_DIR),$(LOCAL_PATH)/)post_sleep.sh:system/etc/post_sleep.sh \
$(if $(wildcard $(PRODUCT_DIR)modules.blocklist),$(PRODUCT_DIR),$(LOCAL_PATH)/)modules.blocklist:system/etc/modules.blocklist \
$(if $(wildcard $(PRODUCT_DIR)modules.options),$(PRODUCT_DIR),$(LOCAL_PATH)/)modules.options:system/etc/modules.options \
$(if $(wildcard $(PRODUCT_DIR)fstab.$(TARGET_PRODUCT)),$(PRODUCT_DIR)fstab.$(TARGET_PRODUCT),$(LOCAL_PATH)/fstab.x86):root/fstab.$(TARGET_PRODUCT) \
Expand Down
2 changes: 2 additions & 0 deletions init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,10 @@ function init_hal_bluetooth()

if [ "$BTLINUX_HAL" = "1" ]; then
start btlinux-1.1
set_property "ro.bliss.bthal" "btlinux"
else
start vendor.bluetooth-1-1
set_property "ro.bliss.bthal" "celadon"
fi
}

Expand Down
99 changes: 99 additions & 0 deletions post_sleep.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# called from modified suspend hal

# prepare env
DMIPATH=/sys/class/dmi/id
export BOARD=$(cat $DMIPATH/board_name)
export PRODUCT=$(cat $DMIPATH/product_name)
export VENDOR=$(cat $DMIPATH/sys_vendor)
export UEVENT=$(cat $DMIPATH/uevent)

function reprobe_module_if_loaded()
{
module=$1
for modname in $(lsmod | awk '{print $1}')
do
if [ "$module" == "$modname" ]
then
modprobe -rv $module
modprobe -v $module
return
fi
done
echo module $module not loaded, not reprobing
}

# prep the prebaked list here, if there are known devices that definitely needs this work-around
MODULE_RELOAD_LIST=""
# 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
RESTART_WIFI=false

### EXAMPLE:
### if [ "$BOARD" == "xxx" ]
### then
### MODULE_RELOAD_LIST="$MODULE_RELOAD_LIST iwlwifi"
### RESTART_WIFI=true
### fi

# note that btusb is unloaded in pre_sleep.sh, since it takes more than 10+ seconds to unload btusb right after wake
# ie. do not put btusb into the reload list

# users can use this to flag wificond restart
USER_RESTART_WIFI_FLAG=/data/etc/wake_reload_wifi
if [ -e $USER_RESTART_WIFI_FLAG ]
then
RESTART_WIFI=true
fi

if $RESTART_WIFI
then
setprop ctl.stop wificond
fi

# perform module reprobe
MODULE_RELOAD_LOG=/data/wake_module_reload_log
rm -f $MODULE_RELOAD_LOG
if [ -n "$MODULE_RELOAD_LIST" ]
then
for m in $MODULE_RELOAD_LIST
do
reprobe_module_if_loaded $m 2>&1 | cat >> $MODULE_RELOAD_LOG
done
fi

# let users define a list of modules to reload on wake
USER_MODULE_RELOAD_LIST=/data/etc/wake_module_reload_list
if [ -e $USER_MODULE_RELOAD_LIST ]
then
for m in $(cat $USER_MODULE_RELOAD_LIST)
do
reprobe_module_if_loaded $m 2>&1 | cat >> $MODULE_RELOAD_LOG
done
fi

# start services again
if $RESTART_WIFI
then
setprop ctl.start wificond
fi

# probe btusb since it was unloaded in pre_sleep.sh
modprobe btusb

# bthal and com.android.bluetooth were disabled in pre_sleep.sh
bthal=$(getprop ro.bliss.bthal)
case $bthal in
"btlinux")
setprop ctl.start btlinux-1.1
;;
"celadon")
setprop ctl.start vendor.bluetooth-1-1
;;
esac
pm enable com.android.bluetooth

# allow user defined actions
USER_SCRIPT=/data/etc/post_sleep.sh
if [ -e $USER_SCRIPT ]
then
/system/bin/sh $USER_SCRIPT
fi
32 changes: 32 additions & 0 deletions pre_sleep.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# called from modified suspend hal

# prepare env
DMIPATH=/sys/class/dmi/id
export BOARD=$(cat $DMIPATH/board_name)
export PRODUCT=$(cat $DMIPATH/product_name)
export VENDOR=$(cat $DMIPATH/sys_vendor)
export UEVENT=$(cat $DMIPATH/uevent)

# put prebaked actions here

# stop com.android.bluetooth
pm disable com.android.bluetooth
bt_pid=$(pidof com.android.bluetooth)
if [ -n "$bt_pid" ]
then
kill -KILL $bt_pid
fi

# stop bluetooth hal
setprop ctl.stop vendor.bluetooth-1-1
setprop ctl.stop btlinux-1.1

# unload btusb here, because unloading could take 10+ seconds right after wake
modprobe -r btusb

# allow user defined actions
USER_SCRIPT=/data/etc/pre_sleep.sh
if [ -e $USER_SCRIPT ]
then
/system/bin/sh $USER_SCRIPT
fi