How can I disable Android USB debugging programmatically
Asked Answered
C

3

4

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?

Cottle answered 6/4, 2011 at 10:27 Comment(1)
how can i prevent app from running on usb debugging mode or developer option on?Mandibular
C
6

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.

Cottle answered 6/4, 2011 at 14:16 Comment(3)
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.Interrelated
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.Announcer
@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.Stork
T
1

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

Titfer answered 6/4, 2011 at 14:31 Comment(2)
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.Cottle
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-reversingUnbearable
C
0

To achieve this , you require android.permission.WRITE_SECURE_SETTINGS permission.

Without root : From ABD execute adb shell pm grant <package-name> android.permission.WRITE_SECURE_SETTINGS

With root : Root access means we can execute shell commands without adb, so workaround for that :

        try {
            Runtime.getRuntime().exec(new String[]{"su","-c",String.format("pm grant %s android.permission.WRITE_SECURE_SETTINGS",BuildConfig.APPLICATION_ID)});
        } catch (IOException e) {
           // handle IOException
        }
Clerestory answered 17/3, 2021 at 15:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.