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:
Using battery info I can detect if USB is plugged in. Well, that is also a legit use.
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!
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?
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.
Related
Logcat works fine when device is connected to Android Studio. But how to log data when device is disconnected from Android Studio, but I still need to capture some information for later analysis?
This does NOT require rooting your device, NOT changing the code of your app, NOT subscribing to a third party service, NOT having your app in Google Play. If you can or are willing to do some of these things, there are other solutions.
However this solution DOES require to have the computer nearby, turned on and connected to the same network where the device is connected (not necessarily on the internet).
Start off by plugging the device into your computer via USB, then run
adb devices to make sure the device is there. If it finds more than one device (e.g. emulator and actual phone), disconnect/close everything but the one you want to debug to keep things simpler and not mistaken one device for another. Then, run adb tcpip 5555 to change the android to tcp mode, which will allow debugging over the network (instead of USB).
At that point you need to find the IP address of your phone, and you can do that in various ways. The easiest is running adb shell ip -f inet addr show wlan0 which will respond with something like:
11: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
inet 192.168.x.x/yy brd 192.168.0.255 scope global wlan0
valid_lft forever preferred_lft forever
Disconnect the device from the computer's USB in the usual way. Connect it again "over the air" by typing adb connect 192.168.x.x, replacing the x with the IP address found above (right after inet). If the device and your computer are on the same network (e.g. same wifi, or mix of wifi and ethernet from the same router) it should connect. Otherwise, you might need to debug the networking, a whole different problem (but usually not necessary).
Sometimes you can connect to the device but it is shown as "offline". Most of the time just waiting one minute will automatically fix the issue. If in a minute or two the issue does not fix itself, you have to debug it, e.g. as described in this question
At this point the device should appear in the drop list of available devices in Android Studio and you should be able to debug it as if it were attached over the USB. However in some cases I have found that the logcat in Android Studio is not updated in this setup. If that happens, run adb logcat and you will see the logcat on the computer. That will have too much information, because includes everything is running on your device, not just your app -- so you will need to filter it, for example with adb shell logcat --pid NNNN where NNNN is the PID of your app. To find such a PID, run adb shell "ps -A | head -1; ps -A | grep -i com.example" (use the java package of your main Activity instead of com.example) which will respond with something like
USER PID PPID VSZ RSS WCHAN ADDR S NAME
u0_a105 NNNN 1511 4970004 182688 0 0 S com.example
When done, run adb usb to restore the phone to regular USB debugging.
Question is straight forward and simple. Is it possible to get the dumpsys information after certain point or certain user action. Not from the scratch.
There is no such thing.
Logs belong to the logcat facility. dumpsys is mostly for reporting the current state and some more advanced things. It is true that few of the Android service developers included some limited logging excerpts into their dumpsys output but virtually none of them implemented a way to clear those logs.
I realise this is a bit late but...
As per the documentation:
Connect your mobile device to your computer.
Open a terminal and type the following commands to reset the adb server:
adb kill-server
adb devices
This will list any connected devices (If you don't see any devices listed, make sure your phone is connected, and USB Debugging is turned on, and then kill and restart adb again).
Next you will need to reset battery data gathering. The device is always collecting batterystats and other debugging information in the background. Resetting erases old battery collection data. If you do not reset, the output will be huge.
In terminal use command:
adb shell dumpsys batterystats --reset
Disconnect your device from your computer so that you are only drawing current from the device's battery.
Play with your app and perform actions for which you would like data; for example, disconnect from WiFi and send data to the cloud.
Reconnect your phone and make sure it is recognized:
adb devices
Dump all battery data (This can take a while):
adb shell dumpsys batterystats > [path/]batterystats.txt
The batterystats.txt file is created in the directory you specify using the optional path argument. If you leave out [path/], the file is created in your home directory.
You can find the home directory in Android Studio by going to:
Tools > SDK Manager > Android SDK Location.
Navigate to that filepath then open the subdirectory 'platform-tools' and look for batterystats.txt.
I have a third party application in my android phone.
The application offers a service at 127.0.0.1:30002.
I don't know the name of service.
Is there a way to find out whether that tcp service is up or not using adb or some other means.
Also what is the use of adb reverse.
Can i run a server in host pc and forward that server on android using adb reverse.
I am completely new to android, so please be brief.
Thanks in advance.
To find which app using specific port:
1. $ cat /proc/net/tcp - This will give you a list of open ports and the UId (unique application ID) of the port's owner.
2. & cat /data/system/packages.list | grep '<The UID you just found>' - This will give you the app name connected to this UID.
3. ps |grep '<the app name>' Will tell you if the app service is running.
What is adb reverse?
adb reverse tells your phone use a port of your local machine (e.g laptop).
Assume you use the command:
adb reverse tcp:80 tcp:3000
Now when your phone tries to access http://localhost:3000/ your request will be routed to localhost:80 of your laptop.
I was testing out the Glass quickstart and chose COMPASS to "re-upload" as a test (tutorial: https://developers.google.com/glass/develop/gdk/quick-start#for_android_beginners)
Now that it worked, I'm stuck with 2x "Compass - sample" and can't call either one by voice commands.
Compass isn't important to me but I am in the process of making an apps for the medical field and I would like to be able to remove it.
Is it possible to remove an .apk from Glass without rooting the device? I have Glass in debug mode and I'm capable of uploading apk's.
Thanks for the help!
You can remove it via the standard way over ADB:
adb shell pm uninstall com.example.MyApp
(where com.example.MyApp is the package name defined in the manifest).
If you have more than one device connected the command will fail - you can direct it to the only attached emulator via the -e flag, the only attached USB device via the -d flag, or a specific device via its serial number and the -s flag (serial numbers as listed in adb devices).
Is it possible to communicate with the Android Debug Bridge (ADB) from inside an app if the service has been loaded through USB?
Here is the use case: I can take a screenshot of the framebuffer through ADB on an unrooted phone with no problem, but it is a little slow to transmit the entire raw buffer over USB, especially if I want to take more than a frame every 2 seconds. What I would like to do is access the framebuffer from inside an app on the phone which can then either transmit it over Wifi or do some compression first. ASL doesn't work on Jellybean (they shut down the loophole to install native services on /data/local), so I would just like to connect to the ADB service via some socket or whatever and issue the framebuffer request that way.
I am ok with having to connect via USB to load the ADB service, but once connected, I would like to do processing on the phone itself before transmission. And it must work on unrooted phones.
Is this possible?
Oneliner:
$ adb shell screencap -p \| gzip -c \> /mnt/sdcard/s.png.gz; adb pull /mnt/sdcard/s.png.gz;