Right way to do this
Disable the broken VOLUME DOWN key by editing /system/usr/keylayout/gpio-keys.kl
and /system/usr/keylayout/Generic.kl
as root
and commenting that key out. Longer instructions on this answer.
Dumb and hacky approach that sort of worked for me
This is an ugly solution but it works for me. It is a "tethered" solution requiring adb
to do repeated "soft reboots" (restarting the Android Zygote process).
This bash
script repeatedly restarts the Android Zygote process until it detects that the device isn't in safe mode. Takes about 20-50 reboots until my device randomly gets lucky and doesn't restart in safe mode…
#!/bin/sh
n=0
g=0
while true; do
safe_mode=$(adb shell dumpsys display | egrep -o 'mSafeMode=\w+' | cut -d= -f2)
case "$safe_mode" in
true)
n=$(( $n + 1 ))
g=0
echo "In safe mode, rebooting (try #${
n
}
) ..."
adb shell "su root -- killall zygote"
;;
false)
g=$(( $g + 1 ))
[[ $g -gt 2 ]] && break;
echo "Appears not to be in safe mode, will check again ..."
;;
*)
echo "adb shell dumpsys display failed" ;;
esac
sleep 15
done
adb shell dumpsys power | grep -q 'mScreenOn=false' && \
adb shell input keyevent = POWER
echo "Escaped from safe mode after ${
n
}
reboots. Whew."
This related question and this answer gave me what I needed to figure it out.