I am trying to search if there is a way to disable android device usb port, software level mainly. So users can still charge android device but cannot communicate with PC anymore.
I got some clues in link1. But it looks there is not an easy way for this.
Android OS is a Linux based OS. So I am wondering if there is a config file in Android OS that allows root users to disable usb port, like files under path /etc in Linux OS.
EDIT: Use this command in android terminal emulator. Root priveleges required, but you can put a password on Superuser so that no one else can undo this or edit the script:
echo 0 > /sys/devices/virtual/android_usb/android0/enable
or...
su -c 'echo 0 > /sys/devices/virtual/android_usb/android0/enable'
To automate this, you need to make a script and put it in /system/etc/init.d, let's say /system/etc/init.d/usb_off:
#!/system/bin/sh
echo 0 > /sys/devices/virtual/android_usb/android0/enable
Then make sure it's executable with:
chmod +x /system/etc/init.d/usb_off
You can also try this, but it's reported not to work. Execute these in the command line via Android Terminal Emulator:
setprop persist.sys.usb.config ''
setprop sys.usb.config ''
You can tell the usb-storage module to ignore a VID/PID combination
Make a file such as /etc/modprobe.d/android.conf
having contents of the form
options usb-storage quirks=vid##:pid##:i
Where the vid/pid are given in hex without prefix
A serious limitation of this technique is that some installations will load the usb-storage driver during the initread stage before /etc
is present and honored, so it may get loaded without the ignore quirk. To work around that you can modify the inittread archive, or you can unload and reload the usb-storage module (if nothing else in your system is using it).
Another downside is that if you decide you want to mount it, you'd have to reload the driver without the quirk (for example using insmod).