14

in my app i need a way to detect if the android-device runs in usb-debugging mode.

Is it possible? If yes, how?

thanx in advance

2 Answers2

26

You can use the following to get whether or not the ADB is enabled.

int adb = Settings.Secure.getInt(context.getContentResolver(),  Settings.Global.ADB_ENABLED, 0);

If it is enabled, adb == 1, otherwise adb == 0.

Smart Manoj
  • 5,230
  • 4
  • 34
  • 59
Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
0

On my Android 2.3 device it is possible to detect the usb debugging mode by scanning the complete process list (ps -s) for the process /sbin/adbd.

If this process is present USB debugging is enabled.

Robert
  • 39,162
  • 17
  • 99
  • 152
  • does this work without special permissions like android.permission.GET_TASKS ? – Android Developer Oct 01 '12 at 17:21
  • 1
    This will not work on Android Nougat. https://code.google.com/p/android/issues/detail?id=205565 – Jared Rummler Aug 19 '16 at 00:56
  • I could see at least the process `shell` when following the instructions [here](https://stackoverflow.com/questions/44732749/how-to-make-adb-shell-ps-list-all-processes-in-android-o) in Pie. Not sure though if ***p***_rocess_ ***s***_tatus_ is also going to be available from inside apps, or if instead it is just adb-specific (and so being kind of redundant for the purpose). – mirh Jun 10 '22 at 18:33
  • @mirh since about Android 8 or 9 apps do not see any other processes than their own. – Robert Jun 10 '22 at 18:36
  • I see, I just tested instead with "terminal emulator" and there's basically nothing to see anymore. Though I still wonder if the extended permissions of [Shizuku](https://www.xda-developers.com/implementing-shizuku/) (which is the second best thing after rooting) couldn't still let you see something more. – mirh Jun 11 '22 at 14:16