62 lines
2.4 KiB
Bash
Raw Normal View History

2020-03-03 02:52:42 -08:00
#!/system/bin/sh
# $1 setup
controller=$(getprop sys.usb.controller)
moddir=[MODDIR]
selected=standard-keyboard
2020-03-03 02:52:42 -08:00
remove_ghid() {
echo "disabling ghid" >>$moddir/ghid.log
rm /config/usb_gadget/g1/configs/b.1/fhid
rmdir /config/usb_gadget/g1/functions/hid.usb0
2020-03-03 02:52:42 -08:00
}
enable_ghid() {
echo "enabling ghid" >>$moddir/ghid.log
running=true
. "$moddir/definitions/$selected"
if [ ! -d /config/usb_gadget/g1/functions/hid.usb0 ]; then
mkdir /config/usb_gadget/g1/functions/hid.usb0
fi
current_protocols="$(cat /config/usb_gadget/g1/functions/hid.usb0/protocol)"
current_subclasses="$(cat /config/usb_gadget/g1/functions/hid.usb0/subclass)"
current_report_lengths="$(cat /config/usb_gadget/g1/functions/hid.usb0/report_length)"
echo "current ghid" >>$moddir/ghid.log
echo current_protocols $current_protocols >>$moddir/ghid.log
echo current_subclasses $current_subclasses >>$moddir/ghid.log
echo current_report_lengths $current_report_lengths >>$moddir/ghid.log
if [ -e /config/usb_gadget/g1/functions/hid.usb0 -a "$current_protocols" == "$protocols" -a "$current_subclasses" == "$subclasses" -a "$current_report_lengths" == "$report_lengths" ] && diff "$moddir/reports/$report_names" /config/usb_gadget/g1/functions/hid.usb0/report_desc ; then
echo nothing to update >>$moddir/ghid.log
return 0
fi
echo new ghid >>$moddir/ghid.log
echo $protocols >>$moddir/ghid.log
echo $subclasses >>$moddir/ghid.log
echo $report_lengths >>$moddir/ghid.log
rm /config/usb_gadget/g1/configs/b.1/fhid
echo $protocols >/config/usb_gadget/g1/functions/hid.usb0/protocol
echo $subclasses >/config/usb_gadget/g1/functions/hid.usb0/subclass
echo $report_lengths >/config/usb_gadget/g1/functions/hid.usb0/report_length
cp "$moddir/reports/$report_names" /config/usb_gadget/g1/functions/hid.usb0/report_desc
cd /config/usb_gadget/g1/configs/b.1/
/data/adb/magisk/busybox ln -nsf ../../../../usb_gadget/g1/functions/hid.usb0 ./fhid
2020-03-03 02:52:42 -08:00
}
echo success ghid was run >>$moddir/ghid.log
2020-03-03 02:52:42 -08:00
if ! [[ "$1" == "setup" ]]; then
exit 1
2020-03-03 02:52:42 -08:00
fi
shift
case "$1" in
""|"none" )
remove_ghid
;;
* )
enable_ghid
;;
2020-03-03 02:52:42 -08:00
esac