Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable android device usb port

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.

like image 648
peacepassion Avatar asked Jan 09 '23 10:01

peacepassion


1 Answers

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 ''
like image 179
jan Avatar answered Jan 18 '23 11:01

jan