I am trying to switch from mtp,adb
mode to mass_storage
easily, preferably with a script. I can go to two different places in settings and toggle both things there. Or I can use setprop
or echo
to set it from the command line but that requires rebooting. As I was writing this question I thought to my self that I might be able to use settings put
but I could not find a key for USB computer connection. There was a key named usb_mass_storage_enabled
but that key does not appear to control the USB connection.
After reading on meta that this is apparently the proper way to do this instead of answering a comment with an unreadable comment, I have deleted my comment and moved it here.
@Irfan Latif - cat /sys/class/android_usb/android0/functions
does in fact reflect the changes when I use settings to change modes but when I try the simple script of:
echo -n 0 > /sys/class/android_usb/android0/enable
echo -n 'mass_storage' > /sys/class/android_usb/android0/functions
echo -n 1 > /sys/class/android_usb/android0/enable
Even though cat /sys/class/android_usb/android0/functions
returns mass_storage
the mode does not actually change.
I'm sorry I was mistaken, after further experimentation changing the /sys/class/android_usb/android0/functions
file will in fact change the functionality of the usb connection. However, this change will not be reflected in the settings menu, nor will it be reflected in the usb id reported by lsusb
. I did find though that should one turn off the usb with the enable file, issue command setprop persist.sys.usb.config
, then turn usb back on the same way, that although it still won't be registered in the settings menu it will cause lsusb
to return the correct mode id. Thanks.