Skip to content

Instantly share code, notes, and snippets.

@barsikus007
Forked from mmtrt/fixdd
Last active May 17, 2024 18:30
Show Gist options
  • Save barsikus007/2e44999712cdb074a1c9a9803cad7b8f to your computer and use it in GitHub Desktop.
Save barsikus007/2e44999712cdb074a1c9a9803cad7b8f to your computer and use it in GitHub Desktop.
[ROOT] [Magisk] [Service.d] [Script] [Fix] DriveDroid on Pixel 7 Pro
#!/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
get_fn_type() {
# get currently active function name
if ls /config/usb_gadget/g1/configs/b.1/function* > /dev/null 2>&1
then
echo "function"
else
echo "f"
fi
}
fn_type=$(get_fn_type)
get_chkfn() {
# get currently active function name
ls -al /config/usb_gadget/g1/configs/b.1/ | grep -Eo "$fn_type[0-9]+[[:space:]].*" | awk '{print $3}' | cut -d/ -f8
}
get_last_fn() {
# get currently free function number
num=$(ls -al /config/usb_gadget/g1/configs/b.1/ | grep -Eo "$fn_type[0-9]+[[:space:]]" | tail -1 | cut -dn -f 3)
echo "$fn_type"$((num+1))
}
is_mass_storage_present() {
# returns 1 if mass_storage.0 is present
ls -al /config/usb_gadget/g1/configs/b.1/ | grep -Eo "mass_storage.0" | wc -l
}
get_mass_storage_path() {
# get path to mass_storage.0
ls -al /config/usb_gadget/g1/configs/b.1/ | grep -Eo "$fn_type[0-9]+[[:space:]].*mass_storage.0" | cut -d' ' -f1
}
# save currently active function name
if [ "$fn_type" = "f" ]; then
get_chkfn > /data/adb/.fixdd
fi
# loop
# run every 0.5 seconds
while true
do
# check the app is active
chkapp="$(pgrep -f drivedroid | wc -l)"
# check if mass storage is active function
mass_storage_active=$(is_mass_storage_present)
if [ "$chkapp" -eq "1" ] && [ "$mass_storage_active" -eq "0" ]; then
# add mass_storage.0 to currently active functions
if [ "$fn_type" = "f" ]; then
setprop sys.usb.config cdrom
setprop sys.usb.configfs 1
rm /config/usb_gadget/g1/configs/b.1/f*
fi
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/$(get_last_fn)"
if [ "$fn_type" = "f" ]; then
getprop sys.usb.controller > /config/usb_gadget/g1/UDC
setprop sys.usb.state cdrom
fi
elif [ "$chkapp" -eq "0" ] && [ "$mass_storage_active" -eq "1" ]; then
# remove mass_storage.0 function
rm "/config/usb_gadget/g1/configs/b.1/$(get_mass_storage_path)"
# it seems, than pixel 7 doesn't use sys.usb.config at all
if [ "$fn_type" = "f" ]; then
# reload of configfs to fix samsung android auto
setprop sys.usb.configfs 0
setprop sys.usb.configfs 1
# load previous active function
chkfrstfn="$(cat /data/adb/.fixdd)"
ln -s /config/usb_gadget/g1/functions/"$chkfrstfn" /config/usb_gadget/g1/configs/b.1/f1
ls /sys/class/udc/ | grep -Eo ".*\.dwc3" > /config/usb_gadget/g1/UDC
if [ "$chkfrstfn" = "ffs.adb" ]; then
setprop sys.usb.config adb
elif [ "$chkfrstfn" = "ffs.mtp" ]; then
setprop sys.usb.config mtp
elif [ "$chkfrstfn" = "mtp.gs0" ]; then
setprop sys.usb.config mtp
fi
fi
fi
sleep 0.5
done
@barsikus007
Copy link
Author

barsikus007 commented Feb 13, 2023

OLD VERSION WHICH SUPPORT ONLY PIXEL 7 DEVICES
The installation is the same as the original, but the command is different:

curl -sL https://gist.github.com/barsikus007/2e44999712cdb074a1c9a9803cad7b8f/raw/ce0bd0e58403d4cbf44a0297fa994a6e1c3fdd7e/fixdd > ~/fixdd && sudo cp fixdd /data/adb/service.d/fixdd && sudo chmod +x /data/adb/service.d/fixdd

@barsikus007
Copy link
Author

barsikus007 commented Feb 22, 2023

New universal version of script with append function instead of swap

curl -sL https://gist.github.com/barsikus007/2e44999712cdb074a1c9a9803cad7b8f/raw/0110768792891a9f397e405b65bcab53356d75e0/fixdd > ~/fixdd && sudo cp fixdd /data/adb/service.d/fixdd && sudo chmod +x /data/adb/service.d/fixdd

@barsikus007
Copy link
Author

barsikus007 commented Feb 22, 2023

Version for devices which doesn't support function appending

curl -sL https://gist.github.com/barsikus007/2e44999712cdb074a1c9a9803cad7b8f/raw/f991af23ac973644b744c549f372403e7132e7fb/fixdd > ~/fixdd && sudo cp fixdd /data/adb/service.d/fixdd && sudo chmod +x /data/adb/service.d/fixdd

@liwa-dev
Copy link

Can u help me with it I'm using kernel su with poco x3 pro custom rom a13 and doesn't work for me

@barsikus007
Copy link
Author

Can u help me with it I'm using kernel su with poco x3 pro custom rom a13 and doesn't work for me

sorry, I can't help with that..

@Ashwinlapmobtech
Copy link

20240127_181120

Hi i am having poco f3 gt

And that also have folder required for drivedroid

But its name is mass_storage.usb0

But for drivedroid it should be mass_storage.0 should be the folder name

So only it recognises

But as its usb.0 its not recognised by drivedroid

And even if i use your code.. i think both maas storage.0 and

Mass storage usb.0 gets activated while plugging in cable so as a result showing usb descriptor failed in windows...

Thatt caise me so much trouble bro...

If possible please guide me to change that folder name or what to do to solve this issue accordingly bro...

Tq bro..

@barsikus007
Copy link
Author

@Ashwinlapmobtech, you can try to remove this folder (if mass_storage.0 exists)
add this to 64th line

rm /config/usb_gadget/g1/functions/mass_storage.usb0

@Ashwinlapmobtech
Copy link

Ashwinlapmobtech commented Jan 28, 2024

While using ykue

@Ashwinlapmobtech, you can try to remove this folder (if mass_storage.0 exists) add this to 64th line

rm /config/usb_gadget/g1/functions/mass_storage.usb0

@barsikus007

While executing your code the mass. storage.0 folder will be automatically created right bro?

So there is no use of folder mass. storage.usb.0

And it will not cause any impact by deleting that folder. .

Am i right bro...?

@barsikus007
Copy link
Author

AFAIR, this folders created dynamicaly on every boot, but I am not sure

@linuxlonestar
Copy link

@barsikus007, Hey, could you give me a quick rundown of how to install this? you have multiple commands for this. I assume the most recent one is accurate?

@barsikus007
Copy link
Author

@barsikus007, Hey, could you give me a quick rundown of how to install this? you have multiple commands for this. I assume the most recent one is accurate?

I prefer to use this magisk module
https://github.com/overzero-git/DriveDroid-fix-Magisk-module

@linuxlonestar
Copy link

Thanks man, I'll try it tonight

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