Skip to content

Conversation

@alryaz
Copy link

@alryaz alryaz commented May 28, 2025

Based on the workaround mentioned by @szescxz.
The app (HID Gadget) does the following when disabling a gadget device:

echo "" > /config/usb_gadget/g1//UDC

This does appear to fix the issue (#50) on my Xiaomi 13 Ultra running AOSP.
I also tested this command using a regulard terminal interface; it also works.

The UDC value gets collected at the script's first line, and the UDC also gets overwritten at the very end.

While more testing is required on end devices, I hereby propose for this change to be included in the next release.

Copy link

@szescxz szescxz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference, the mentioned workaround is from this comment.

I should also mention that, at least on my device, Android OS (?) seems to automatically re-enable the gadget device when adb is the last (or only) item in sys.usb.config. Therefore I suggest adding getprop and setprop commands to temporarily remove adb from the system property before disabling the gadget device, since the majority users who rooted their device tends to keep USB debugging enabled.

@Arian04
Copy link
Owner

Arian04 commented May 29, 2025

thank you so much to both of you for finding the workaround and bringing it to my attention. unfortunately the next release will be after I merge in changes from the develop branch, in which I've heavily refactored this code, so the change you're suggesting won't be able to be merged into there (There's no shell script anymore, just a root service running Kotlin code). However, the fix itself can be implemented for sure.

I could do this myself, but if you'd like to be credited for the contribution, you can add this code:

try {
    resetGadget()
} catch (e: IOException) {
    Timber.e("Failed to reset usb gadget")
    Timber.e(e)
}

to this line:

@Arian04 Arian04 closed this May 29, 2025
@Arian04
Copy link
Owner

Arian04 commented Jun 6, 2025

just wanted to update, since a new PR wasn't submitted, I went ahead and did it myself, but I credited both of you in the code and the commit message: 8b4d1d2

thanks again!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants