Search code examples
androidusbmdm

pragmatically way to disable all USB ports on android, so that it does not recognize any removable storage or any other device


I need a pragmatically way to disable all USB ports on android for a MDM application, so that it does not recognize any removable storage or any other device (USB mouse, USB keyboard etc).

my application is already set as a system application so it will have the required permissions.


Solution

  • If you provision your device with your app as the device owner (using Android Enterprise, aka Android for Work) you can set these restrictions:
    DISALLOW_MOUNT_PHYSICAL_MEDIA
    DISALLOW_USB_FILE_TRANSFER

    More details on building an app like this can be found here: https://developers.google.com/android/work/build-dpc

    I'm not sure how to prevent other devices like a mouse or keyboard, but I hope this helps some.

    Also, if you want to easily test those two disallows out, look into the TestDPC app. Be sure to install it as a device owner so you have permission for those APIs. Google provides source code to it.
    https://github.com/googlesamples/android-testdpc