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
This commit is contained in:
lordwelch 2020-03-11 15:37:15 -07:00
parent 138fd917c6
commit dd1446f30e
4 changed files with 57 additions and 43 deletions

View File

@ -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

View File

@ -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

View File

@ -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}

View File

@ -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*;' &