Removed setting the UDC for now as the service runs before the other init scripts selinux is a complete pain, but I need to figure out a way to make it so that you can use hidg devices without root; preferably with a way for an android app to request access.
62 lines
2.4 KiB
Bash
62 lines
2.4 KiB
Bash
#!/system/bin/sh
|
|
# $1 setup
|
|
controller=$(getprop sys.usb.controller)
|
|
moddir=[MODDIR]
|
|
selected=standard-keyboard
|
|
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
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
echo success ghid was run >>$moddir/ghid.log
|
|
|
|
if ! [[ "$1" == "setup" ]]; then
|
|
exit 1
|
|
fi
|
|
shift
|
|
|
|
case "$1" in
|
|
""|"none" )
|
|
remove_ghid
|
|
;;
|
|
* )
|
|
enable_ghid
|
|
;;
|
|
esac
|