For privacy and security reasons I'd like to disable MTP and PTP on my phone. I recently plugged my phone into an inflight entertainment system to charge it, and was surprised to see that the status bar showed that the phone was connected as a camera (via PTP). This could happen with basically any USB hub, and you won't know until you connect to it.
Running Android 5.0.2 on a Samsung Galaxy A3 (SM-A300FU).
I have tried the following:
- Enabled USB debugging
- Plugged in the USB cable
- Rooted my phone (and verified that it's actually rooted)
adb shell su -c 'setprop persist.sys.usb.config adb'
(thanks @Firelord)Verified in Terminal Emulator:
$ su sh -c 'cat /data/property/persist.sys.usb.config' adb
- Unplugged the USB cable
- Rebooted
- Disabled USB debugging
- Plugged in the USB cable
At this point the device is automatically "Connected as a media device", and the setting is back to the default:
$ su sh -c 'cat /data/property/persist.sys.usb.config'
mtp
If I leave the USB debugging enabled the value is mtp,adb
after rebooting.
After reporting this as a bug, it turns out it's actually been fixed, and charge-only mode has been reintroduced in Android 6.
This is different from Disabling MTP/PTP/all USB stuff except charging because that question is about CyanogenMod, not stock Android, and the accepted answer is not applicable to Android 5.
adb shell su -c 'setprop persist.sys.usb.config adb'
. This command runs with root privileges and makes the changes persistent. Yours doesn't make it persistent. The file/data/property/persist.sys.usb.config
store the changes.mtp
withnone
.