开发者

How can I disable Android USB debugging programmatically

There is a bug on some Samsung Android Phones causing USB-debugging to automatically be turned on if the USB开发者_如何学Go 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?


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.


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


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
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜