3

I'm running Android Pie on a rooted OnePlus 6, and I wanted to know how I can enable OTG with a shell command. I need this in order to automate some tasks.

There is a setting that can toggle OTG, found in settings > system > OTG storage, so I figured something like this would work:

settings put global otg_enabled 1

However I'm unsure what the setting for OTG is actually called; I tried a bunch of possibilities but none seemed to work. Also tried googling it, but found nothing.

Anyone able to help me out here?

0

3 Answers 3

4

Note: the solution is tested on a rooted OnePlus 6 running OxygenOS (Android 8, 9, 10).


The command I use is:

adb shell su -c 'setprop persist.sys.oem.otg_support true'

Some folks on some forums suggested to toggle the value for the global settings key oneplus_otg_auto_disable, but it never worked out for me. My solution survives reboot and OTG would work even when decryption password is not supplied.

I automate the solution for fail-safe scenario (in case something disable the OTG) using Tasker app. My task is:

Code → Run Shell:

  • setprop persist.sys.oem.otg_support true
  • enable Use Root

I then assign the task to a boot event profile so that the task runs during startup.

3
  • 1
    I think both - property and settings key - are OEM specific, not part of AOSP. Commented Aug 28, 2019 at 11:34
  • 1
    Yes, I agree. I didn't see such keys in my Nexus 6 running Android 7, back when I had it.
    – Firelord
    Commented Aug 28, 2019 at 11:35
  • 1
    on my rooted OnePlus 10 Pro 5G (NE2213): my problem was that the OTG toggle was greyed out and could not be changed from "off". Attaching a usb flash stick got "recognizing" and nothing more. I used the "setprop" ..true command, and the disk was mounted read/write (both ntfs and ext4 usb disks worked). i then used set property... false, and now i could toggle the otg setting! upon reboot i can now toggle the otg setting. perhaps "all" i needed was a reboot, but I'll never know. In any case, problem solved for me, thx Commented Mar 26, 2023 at 20:53
2

This worked for me:

  1. Find 'otg' on global settings

    adb shell setting list global | grep 'otg'
    

    Result:

    otg_time_out_close 0
    

    0 is for off, 1 is for on.

  2. Switching OTG on/off

    adb shell settings put [whatever the result of the first command] [0 or 1] `
    

Please take note that this method is not tested on other devices. This is tested on a realme RMX3263.

1

This works for me :

turn ON:

echo 1 > /sys/class/power_supply/usb/otg_switch

turn OFF:

echo 0 > /sys/class/power_supply/usb/otg_switch

This doesn't change the toggle button's state on OTG setting page though.

1
  • Hi. It would be good if your answer mentions a couple of details, such as: 1) the solution needs root access to work; 2) the solution won't survive a reboot; 3) the Android device and Android version on which this solution was tested.
    – Firelord
    Commented Feb 20, 2023 at 11:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .