How can I disable Android USB debugging programmatically

12,553

Solution 1

It seems to be impossible. I think I must use Settings.System with ADB_ENABLED, but ADB_ENABLED is a Secure-System-Setting which cannot be changed by a normal application. :-(

On the other hand, there is the permission android.permission.WRITE_SECURE_SETTINGS, so it looks like I can alter it. Can I get it on a rooted phone?

If someone has an idea on how to fix this security issue, it would be great.

Solution 2

I don't think it is a security issue.

First, it is the responsibility of a developer to only make debug messages available that do not compromise his application in the later.

Secondly, debug messages that are used for development should probably have another debug level than for production.

Third, if your application exposes data via adb that compromisses your application, maybe there's something wrong in the app design in the beginning?

Fourth: It is not recommended to toggle settings that the user should be able to configure. I would hate to see manything I configured go on and off by starting an app. Of course, you mentioned the Bug with Samsung. But I think they should be able to fix this.

Regards, Chris

Share:
12,553
niels
Author by

niels

#SOreadytohelp

Updated on June 26, 2022

Comments

  • niels
    niels almost 2 years

    There is a bug on some Samsung Android Phones causing USB-debugging to automatically be turned on if the USB is plugged in. This is obviously a security issue. I want to write a program which will disable USB debugging so that I can start it whenever usb-plug is inserted. Any ideas on how to do this?

  • niels
    niels about 13 years
    You are right that an app normally doesn't should toggle the settings, but about the security issue, I'm think you are totally wrong. With usb debugging you can not only read log files, you can a lot of other things: root the phone, install software without confirmation of the user, delete or read all data. Correct me if I'm wrong.
  • Rajkiran
    Rajkiran almost 12 years
    Yes, on a rooted phone you can. There's an app called Widgetsoid2.x in the play store which does it. But it needs the app to be put in the /system/app directory.
  • fklappan
    fklappan over 11 years
    It absolutely IS a security issue! See link at the end. I want to make sure that the user of my business enterprise app dont have USB debugging enabled so i can assume that the device admin policy is "secure" ( i know there is no 100% security ). With USB debugging enabled, an attacker is able to crack the password lock and therefore can get all device data from my phone ( including settings, memory and encrypted passwords - because the key has to be somewhere in the app ). Source: thomascannon.net/projects/android-reversing
  • Android Noob
    Android Noob almost 11 years
    I've done this by modifying the Nexus 10 factory image (mantaray) by mounting my system.img file on Ubuntu (need to run simg2img tool), going into the system/app folder, dragging my app in there, using make_ext4fs, and then flashing the system.img file back onto the device.
  • ChuongPham
    ChuongPham over 10 years
    @niels: Rajkiran's comment is incorrect. In order to programatically enable/disable usb debugging, you'll need to sign your app with an Android platform (Gingerbread, Jellybean, etc) certificate, AND your app has the appropriate configs in AndroidManifest.xml, AND your app is installed in the /system/app directory programmatically or manually. You cannot do this alone with a rooted device by simply moving it to the /system/app directory. It doesn't work like that.