Can we programmatically enable / disable USB debugging on Android devices?

Is there a way to enable or disable USB debugging programmatically on Android devices?

+8
android
source share
5 answers

On a regular device with a normal application, you cannot.

You need an embedded device with the application in / system / app, then you can.

In any case, you should not configure such a thing yourself, so the user should have full control in this case.

+2
source share

Hi, this is my first post here, and usually I will not worry, but I see no one wanted to give you an answer, despite the fact that there are several ways to do this. This is all from my application, I am "idone" on xda-dev btw. Also some of this code, perhaps Samsung MSMxxxx

If you have root, you really can. And here are 3 ways to do this, despite the fact that other people say differently Method 1 (secret secret code) Method 2 (set sys.usb.config) Method 3 (setting global settings adb_enabled 1)

public String[] SET_DM_PORT_STATUS_LIST = new String[9];{ SET_DM_PORT_STATUS_LIST[0] = "setMTP"; SET_DM_PORT_STATUS_LIST[1] = "setMTPADB"; SET_DM_PORT_STATUS_LIST[2] = "setPTP"; SET_DM_PORT_STATUS_LIST[3] = "setPTPADB"; SET_DM_PORT_STATUS_LIST[4] = "setRNDISDMMODEM"; SET_DM_PORT_STATUS_LIST[5] = "setRMNETDMMODEM"; SET_DM_PORT_STATUS_LIST[6] = "setDMMODEMADB"; SET_DM_PORT_STATUS_LIST[7] = "setMASSSTORAGE"; SET_DM_PORT_STATUS_LIST[8] = "setMASSSTORAGEADB";} public String[] SET_DM_PORT_CONFIG_LIST = new String[9];{ SET_DM_PORT_CONFIG_LIST[0] = "mtp"; SET_DM_PORT_CONFIG_LIST[1] = "mtp,adb"; SET_DM_PORT_CONFIG_LIST[2] = "ptp"; SET_DM_PORT_CONFIG_LIST[3] = "ptp,adb"; SET_DM_PORT_CONFIG_LIST[4] = "rndis,acm,diag"; SET_DM_PORT_CONFIG_LIST[5] = "rmnet,acm,diag"; SET_DM_PORT_CONFIG_LIST[6] = "diag,acm,adb"; SET_DM_PORT_CONFIG_LIST[7] = "mass_storage"; SET_DM_PORT_CONFIG_LIST[8] = "mass_storage,adb";} Process su = Runtime.getRuntime().exec("su"); DataOutputStream outputStream = new DataOutputStream(su.getOutputStream()); outputStream.writeBytes("am broadcast -a android.provider.Telephony.SECRET_CODE -d android_secret_code://" + SET_DM_PORT_STATUS_LIST[paramInt]+"\n"); outputStream.writeBytes("setprop sys.usb.config " + SET_DM_PORT_CONFIG_LIST[paramInt]+"\n"); if(SET_DM_PORT_STATUS_LIST[paramInt].contains("adb")){ outputStream.writeBytes("settings put global adb_enabled 1\n"); } 

I am trying to modify IOTHIDDENMENU.apk and recreate its methods, but without the internal and hidden api that it uses.

+2
source share

This is not possible in android, because for this you need to access Setting.System . For more information see here: How to disable Android USB debugging programmatically

+1
source share

This is not possible without using your own firmware, which provides access to security settings. See here: http://groups.google.com/group/android-developers/browse_frm/thread/953c6f0eb0fa9bed#

usb debugging is another name for Android Debug Bridge (ADB). The item you are looking for is here

http://developer.android.com/reference/android/provider/Settings.Secure.html#ADB_ENABLED

+1
source share

excellent answer: stack overflow

basically him:

 android.os.Debug.waitForDebugger(); also you can use the following to determine if the debugger is connected: android.os.Debug.isDebuggerConnected(); //Determine if a debugger is currently att 
-2
source share

All Articles