Is there a way to disable all USB functionality except for charging? I don't really use MTP or PTP and would like to disable it if possible.
Go to Settings → Storage and tap on the overflow menu in the top right (on a device with a physical menu key, you may need to press that instead). This should bring up a menu item labeled "USB Computer Connection":
Tap on that, and it will give you a list with possible connection modes. Uncheck everything that you don't intend to use. On my N5/CM11 there are only two options on this page: MTP and PTP. Unchecking both causes the phone to simply charge when plugged into a PC. I have seen others that have an explicit "Charge Only" option, but I believe that is nonstandard.
The most device-compatible way to disable everything is to run this command at startup or set this in your build.prop:
setprop persist.sys.usb.config none
which is equivalent to charge-only on all Android devices.
That also disables adb. If you use adb regularly, then:
setprop persist.sys.usb.config adb
will allow adb when developer options are turned on/checked. If you don't use ADB often, I would not recommend it, because setting
adb causes my S5 to still recognize in device manager, even when it is locked.
To restore original functionality,
setprop persist.sys.usb.config mtp,ptp,adb
allows all USB protocols.
Hope this helps anyone Googling for an answer.
click 5 times on SETTINGS>ABOUT PHONE>MODEL NUBMER
then DEVELOPER OPTIONS will be added in main settings (in bottom). Enter there and choose USB SETTINGS> CHARGING|MTP.