Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if ADB server is running on Android?

Tags:

android

adb

I am trying to detect if the adb server is running on the Android device for part of an anti-cheating implementation for my free game.

Specifically, I want to stop use of adb shell input tap x,y, since the game is a competitive multiplayer puzzle game.

Things I have tried:

  1. Using battery info I can detect if USB is plugged in. Well, that is also a legit use.

  2. Using Settings.Secure or Settings.Global, I can query ADB_ENABLED, but that always returns 1 if adb is enabled. It DOES NOT take into account adb connected or not!

  3. Querying all system services, but I cannot see anything that looks like an adb service.

At this point, I am out of ideas. Hopefully someone else knows how to do this?

like image 415
Richard Avatar asked Jan 11 '15 05:01

Richard


People also ask

How do I know if adb is running?

If you're already on Ice Cream Sandwich, go to Settings > Developer options and tick “Android debugging” or “USB debugging.” A result like that (where the X's represent your device's actual serial number) confirms that your ADB is set up and working.

How do I know if adb is running in Android Studio?

You can verify that your device is connected by executing adb devices from the android_sdk /platform-tools/ directory. If connected, you'll see the device name listed as a "device." Note: When you connect a device running Android 4.2.

How do I see what services are running in adb?

To know if the service is currently started or stopped, look for app=ProcessRecord(...) or app=null respectively. while inside of your shell. If my application is a system application, will be it be displayed with "adb shell service list" command? "adb shell dumpsys activity services myservice" worked like a charm.

How do you check if I have adb installed?

Next type cd platform-tools : Then type ls (or dir on Windows). You should see adb or adb.exe depending on your operating system. From here you can type ./adb and see some program output.


1 Answers

You can check for running adbd process or query init.svc.adbd system property:

$ ps adbd
USER     PID   PPID  VSIZE  RSS     WCHAN    PC         NAME
root      14947 1     4596   208   ffffffff 00019358 S /sbin/adbd

$ getprop init.svc.adbd
running

In Android the adb driver is implemented as a function of universal usb driver. You can check the (comma separated) list of currently enabled usb functions to see if it includes "adb":

$ cat /sys/devices/virtual/android_usb/android0/functions
mtp,adb

But you would not be able stop cheating while your app is running completely on the user controlled device.

like image 147
Alex P. Avatar answered Oct 07 '22 08:10

Alex P.