78 lines
2.8 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]
2020-03-06 00:01:42 -08:00
selected=keyboard-standard
exec >>$moddir/ghid.log
exec 2>>$moddir/ghid.log
set -o xtrace
set -o nohup
set +o errexit
set +o sh
set +o posix
exec >>$moddir/ghid.log
exec 2>>$moddir/ghid.log
2020-03-03 02:52:42 -08:00
remove_ghid() {
echo "disabling ghid"
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() {
2020-03-06 00:01:42 -08:00
for f in $selected; do
echo "enabling ghid"
2020-03-06 00:01:42 -08:00
running=true
. "$moddir/definitions/$f"
if [ ! -d /config/usb_gadget/g1/functions/hid.usb0 ]; then
mkdir /config/usb_gadget/g1/functions/hid.usb0
fi
current_protocol="$(cat /config/usb_gadget/g1/functions/hid.usb0/protocol)"
current_subclass="$(cat /config/usb_gadget/g1/functions/hid.usb0/subclass)"
current_report_length="$(cat /config/usb_gadget/g1/functions/hid.usb0/report_length)"
echo "current ghid"
echo current_protocol $current_protocol
echo current_subclass $current_subclass
echo current_report_length $current_report_length
2020-03-06 00:01:42 -08:00
if [ -e /config/usb_gadget/g1/functions/hid.usb0 -a "$current_protocol" == "$protocol" -a "$current_subclass" == "$subclass" -a "$current_report_length" == "$report_length" ] && diff "$moddir/reports/$report_name" /config/usb_gadget/g1/functions/hid.usb0/report_desc ; then
echo nothing to update
2020-03-06 00:01:42 -08:00
return 0
fi
echo new ghid
2020-03-06 00:01:42 -08:00
echo $protocol
echo $subclass
echo $report_length
2020-03-06 00:01:42 -08:00
rm /config/usb_gadget/g1/configs/b.1/fhid
echo $protocol >/config/usb_gadget/g1/functions/hid.usb0/protocol
echo $subclass >/config/usb_gadget/g1/functions/hid.usb0/subclass
echo $report_length >/config/usb_gadget/g1/functions/hid.usb0/report_length
cp "$moddir/reports/$report_name" /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
done
# echo none >/config/usb_gadget/g1/UDC
# echo "$controller" >/config/usb_gadget/g1/UDC
2020-03-03 02:52:42 -08:00
}
echo success ghid was run with: "$@"
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
sh <<<'chcon u:object_r:null_device:s0 /dev/hidg*;chmod 666 /dev/hidg*;sleep 5;chcon u:object_r:null_device:s0 /dev/hidg*;chmod 666 /dev/hidg*;ls -alZ /dev/hidg*;' &