Richard
Richard

Reputation: 968

Detect if ADB server is running on Android?

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?

Upvotes: 7

Views: 13655

Answers (1)

Alex P.
Alex P.

Reputation: 31676

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.

Upvotes: 8

Related Questions