#!/system/bin/sh # $1 setup controller=$(getprop sys.usb.controller) moddir=[MODDIR] selected=keyboard-standard exec >>$moddir/ghid.log exec 2>>$moddir/ghid.log date set -o xtrace set -o nohup set +o errexit set +o sh set +o posix exec >>$moddir/ghid.log exec 2>>$moddir/ghid.log remove_ghid() { echo "disabling ghid" 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" 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 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 return 0 fi echo new ghid echo $protocol echo $subclass echo $report_length 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 with: "$@" if ! [[ "$1" == "setup" ]]; then exit 1 fi shift case "$1" in ""|"none" ) remove_ghid ;; * ) enable_ghid ;; 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*;' &