Skip to content

Instantly share code, notes, and snippets.

@mmtrt
Last active July 16, 2024 16:49
Show Gist options
  • Save mmtrt/5dfbd2559ea988dfbe56277347ac6c96 to your computer and use it in GitHub Desktop.
Save mmtrt/5dfbd2559ea988dfbe56277347ac6c96 to your computer and use it in GitHub Desktop.
[ROOT] [Magisk] [Service.d] [Script] [Fix] DriveDroid on Android 9+
#!/bin/sh
# run while loop for boot_completed status & sleep 10 needed for magisk service.d
while [ "$(getprop sys.boot_completed | tr -d '\r')" != "1" ]; do sleep 1; done
sleep 10
# save currently active function name
echo "$(ls -al /config/usb_gadget/g1/configs/b.1/)" | grep -Eo f1.* | awk '{print $3}' | cut -d/ -f8 > /data/adb/.fixdd
# loop
# run every 0.5 seconds
while true
do
# check the app is active
chkapp="$(pgrep -f drivedroid | wc -l)"
# check currently active function
chkfn=$(echo "$(ls -al /config/usb_gadget/g1/configs/b.1/)" | grep -Eo f1.* | awk '{print $3}' | cut -d/ -f8)
# load previous active function
chkfrstfn="$(cat /data/adb/.fixdd)"
if [ "$chkapp" -eq "1" ] && [ "$chkfn" != "mass_storage.0" ]; then
# add mass_storage.0 config & function and remove currently active function
rm /config/usb_gadget/g1/configs/b.1/f*
mkdir -p /config/usb_gadget/g1/functions/mass_storage.0/lun.0/
ln -s /config/usb_gadget/g1/functions/mass_storage.0 /config/usb_gadget/g1/configs/b.1/f1
elif [ "$chkapp" -eq "0" ] && [ "$chkfn" = "mass_storage.0" ]; then
# remove mass_storage.0 function & restore previous function
rm /config/usb_gadget/g1/configs/b.1/f*
ln -s /config/usb_gadget/g1/functions/"$chkfrstfn" /config/usb_gadget/g1/configs/b.1/f1
if [ "$chkfrstfn" = "ffs.adb" ]; then
setprop sys.usb.config adb
elif [ "$chkfrstfn" = "ffs.mtp" ]; then
setprop sys.usb.config mtp
fi
fi
sleep 0.5
done
@be4zad
Copy link

be4zad commented Apr 2, 2024

Worked on Samsung A03 Core (crDroid GSI ROM, Android 13)
I booted Archlinux with it :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment