How to disable MTP and PTP file sharing via USB on Android 5? 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.
Thanks to @Firelord, this is the procedure to follow:


Root your phone
Install Terminal Emulator
In Terminal Emulator, run su sh -c 'echo -n none &gt; /data/property/persist.sys.usb.config'
Restart the phone


Bonus: Now you can get rid of all those horrible vendor apps. Bye Samsung and Three!

Caveat 1: USB debugging no longer works after doing this, regardless of whether you left it enabled while following the instructions or disabled and re-enabled it. All you need to do (I just verified it) is to set the value back to adb to make it work again, but then of course you have the original problem. If there’s a magic string to make USB debugging work and simultaneously disable both MTP and PTP, I don’t know what it is (I tried with none,adb).

Caveat 2: You can’t update Android anymore without completely resetting your device. Not even de-rooting and a factory reset work - bloody Android still says I’ve made an “unauthorized modification.” Let’s recap: “Freedom 0: The freedom to run the program as you wish, for any purpose.” I had to boot into Windows and use Samsung Smart Switch for PC to upgrade.