72 lines
2.8 KiB
Bash
72 lines
2.8 KiB
Bash
#!/system/bin/sh
|
|
# $1 setup
|
|
controller=$(getprop sys.usb.controller)
|
|
moddir=[MODDIR]
|
|
selected=keyboard-standard
|
|
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() {
|
|
for f in $selected; do
|
|
echo "enabling ghid" >>$moddir/ghid.log
|
|
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" >>$moddir/ghid.log
|
|
echo current_protocol $current_protocol >>$moddir/ghid.log
|
|
echo current_subclass $current_subclass >>$moddir/ghid.log
|
|
echo current_report_length $current_report_length >>$moddir/ghid.log
|
|
|
|
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 >>$moddir/ghid.log
|
|
return 0
|
|
fi
|
|
|
|
echo new ghid >>$moddir/ghid.log
|
|
|
|
echo $protocol >>$moddir/ghid.log
|
|
echo $subclass >>$moddir/ghid.log
|
|
echo $report_length >>$moddir/ghid.log
|
|
|
|
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
|
|
|
|
}
|
|
|
|
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
|
|
chcon u:object_r:null_device:s0 /dev/hidg*
|
|
chmod 666 /dev/hidg*
|
|
sleep 1
|
|
chcon u:object_r:null_device:s0 /dev/hidg*
|
|
chmod 666 /dev/hidg*
|