2020-03-03 02:52:42 -08:00
#!/system/bin/sh
# $1 setup
controller = $( getprop sys.usb.controller)
2020-03-04 12:35:05 -08:00
moddir = [ MODDIR]
2025-02-14 21:07:41 -08:00
2020-03-11 15:37:15 -07:00
exec >>$moddir /ghid.log
exec 2>>$moddir /ghid.log
2021-04-18 14:27:01 -07:00
date
2020-03-11 15:37:15 -07:00
set -o xtrace
set -o nohup
set +o errexit
set +o sh
set +o posix
2025-02-14 21:07:41 -08:00
exec >>$moddir /oghid.log
exec 2>>$moddir /oghid.log
2020-03-11 15:37:15 -07:00
2020-03-03 02:52:42 -08:00
remove_ghid( ) {
2025-02-14 21:07:41 -08:00
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( ) {
2025-02-14 21:07:41 -08:00
. " $moddir /definitions/keyboard-standard "
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) "
2020-03-06 00:01:42 -08:00
2025-02-14 21:07:41 -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
cd /config/usb_gadget/g1/configs/b.1/
/data/adb/magisk/busybox ln -nsf ../../../../usb_gadget/g1/functions/hid.usb0 ./fhid
return 0
fi
2020-03-06 00:01:42 -08:00
2025-02-14 21:07:41 -08:00
echo new ghid
2020-03-06 00:01:42 -08:00
2025-02-14 21:07:41 -08:00
echo protocol: $protocol
echo subclass: $subclass
echo report_length: $report_length
2020-03-06 00:01:42 -08:00
2025-02-14 21:07:41 -08:00
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
cat " $moddir /reports/ $report_name " >/config/usb_gadget/g1/functions/hid.usb0/report_desc
2020-03-03 15:31:32 -08:00
2025-02-14 21:07:41 -08:00
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
}
2020-03-11 15:37:15 -07:00
echo success ghid was run with: " $@ "
2020-03-03 02:52:42 -08:00
case " $1 " in
2025-02-14 21:07:41 -08:00
"init" )
enable_ghid
; ;
"remove" )
remove_ghid
; ;
*)
shift
exit 0
; ;
2020-03-03 02:52:42 -08:00
esac
2025-02-14 21:07:41 -08:00
restorecon /dev/hidg*