From dd1446f30e2a0a5712ef1b69e172770fdae32ca7 Mon Sep 17 00:00:00 2001 From: lordwelch Date: Wed, 11 Mar 2020 15:37:15 -0700 Subject: [PATCH] Attempt to fix instability with hid and configfs I may just need a new cord Add test for rc file Add more logging Exec the script and stat the service to run the script Run the permission changes in a background subshell --- customize.sh | 51 ++++++++++++++++++++++++++-------------------- module.prop | 4 ++-- overlay.d/ghid.rc | 1 + system/bin/ghid.sh | 44 ++++++++++++++++++++++----------------- 4 files changed, 57 insertions(+), 43 deletions(-) diff --git a/customize.sh b/customize.sh index a0a4afb..0b2c867 100644 --- a/customize.sh +++ b/customize.sh @@ -85,37 +85,44 @@ rpwd="$PWD" ########################################################################################## ui_print "- Patching ramdisk" - ui_print "- Adding overlay.d/ghid.rc" + ./magiskboot cpio ramdisk.cpio extract /overlay.d/ghid.rc ghid.rc + if ! diff $MODPATH/overlay.d/ghid.rc ghid.rc; then + rm ghid.rc + ui_print "- Adding overlay.d/ghid.rc" - ./magiskboot cpio ramdisk.cpio \ - "mkdir 755 overlay.d" \ - "add 755 overlay.d/ghid.rc $MODPATH/overlay.d/ghid.rc" + ./magiskboot cpio ramdisk.cpio \ + "mkdir 755 overlay.d" \ + "add 755 overlay.d/ghid.rc $MODPATH/overlay.d/ghid.rc" - if [ $((STATUS & 4)) -ne 0 ]; then - ui_print "- Compressing ramdisk" - ./magiskboot cpio ramdisk.cpio compress - fi + if [ $((STATUS & 4)) -ne 0 ]; then + ui_print "- Compressing ramdisk" + ./magiskboot cpio ramdisk.cpio compress + fi - rm -f ramdisk.cpio.orig config + rm -f ramdisk.cpio.orig config - ui_print "- Repacking boot image" - ./magiskboot repack "$BOOTIMAGE" || abort "! Unable to repack boot image!" + ui_print "- Repacking boot image" + ./magiskboot repack "$BOOTIMAGE" || abort "! Unable to repack boot image!" - # Sign chromeos boot - $CHROMEOS && sign_chromeos + # Sign chromeos boot + $CHROMEOS && sign_chromeos - ########################################################################################## - # End bootpatch - ########################################################################################## + ########################################################################################## + # End bootpatch + ########################################################################################## - ui_print "- Flashing new boot image" + ui_print "- Flashing new boot image" - if ! flash_image new-boot.img "$BOOTIMAGE"; then - ui_print "- Compressing ramdisk to fit in partition" - ./magiskboot cpio ramdisk.cpio compress - ./magiskboot repack "$BOOTIMAGE" - flash_image new-boot.img "$BOOTIMAGE" || abort "! Insufficient partition size" + if ! flash_image new-boot.img "$BOOTIMAGE"; then + ui_print "- Compressing ramdisk to fit in partition" + ./magiskboot cpio ramdisk.cpio compress + ./magiskboot repack "$BOOTIMAGE" + flash_image new-boot.img "$BOOTIMAGE" || abort "! Insufficient partition size" + fi + else + rm ghid.rc + ui_print "- overlay.d/ghid.rc already added" fi ./magiskboot cleanup diff --git a/module.prop b/module.prop index 3bca9c9..fe79fbf 100644 --- a/module.prop +++ b/module.prop @@ -1,6 +1,6 @@ id=ghid name=ghid -version=0 -versionCode=26 +version=0.9 +versionCode=30 author=lordwelch description=creates ghid device files in /dev diff --git a/overlay.d/ghid.rc b/overlay.d/ghid.rc index 3a39f43..6033533 100644 --- a/overlay.d/ghid.rc +++ b/overlay.d/ghid.rc @@ -1,4 +1,5 @@ on property:sys.usb.ffs.ready=1 && property:sys.usb.config=* && property:sys.usb.configfs=1 + exec u:r:magisk:s0 root root -- /system/bin/ghid.sh setup ${sys.usb.config} start ghid service ghid /system/bin/ghid.sh setup ${sys.usb.config} diff --git a/system/bin/ghid.sh b/system/bin/ghid.sh index 62b8cf1..99eb4bf 100644 --- a/system/bin/ghid.sh +++ b/system/bin/ghid.sh @@ -3,15 +3,25 @@ controller=$(getprop sys.usb.controller) moddir=[MODDIR] 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 + remove_ghid() { - echo "disabling ghid" >>$moddir/ghid.log + 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" >>$moddir/ghid.log + echo "enabling ghid" running=true . "$moddir/definitions/$f" if [ ! -d /config/usb_gadget/g1/functions/hid.usb0 ]; then @@ -20,21 +30,21 @@ enable_ghid() { 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 + 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 >>$moddir/ghid.log + echo nothing to update return 0 fi - echo new ghid >>$moddir/ghid.log + echo new ghid - echo $protocol >>$moddir/ghid.log - echo $subclass >>$moddir/ghid.log - echo $report_length >>$moddir/ghid.log + 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 @@ -44,12 +54,12 @@ enable_ghid() { 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 none >/config/usb_gadget/g1/UDC + # echo "$controller" >/config/usb_gadget/g1/UDC } -echo success ghid was run >>$moddir/ghid.log +echo success ghid was run with: "$@" if ! [[ "$1" == "setup" ]]; then exit 1 @@ -64,8 +74,4 @@ case "$1" in 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* +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*;' &