As Android developers, one of the tools we use most often is ADB. However, during the normal development, we are trying ADB indirectly through AS. In fact, ADB has many powerful capabilities beyond serving as an intermediate bridge for debugging. In this article, I’ll show you how ADB can be used outside of development through the application of ADB in a live mobile game.

This implementation compares billing. Because there is a game mode called Ladder game in live mobile games, in fact, as a coach to participate in the game. All you have to do is click next at the end of each match. The next button in a live mobile game is in a fixed position. This makes it easy for us to automatically click and continue the game through automation.

The result is as follows,

ADB provides the input command. The complete help information for the input command is as follows:

Usage: input [<source>] <command> [<arg>...]  The sources are: mouse keyboard joystick touchnavigation touchpad trackball stylus dpad gesture touchscreen gamepad The commands and default sources are: text <string> (Default: touchscreen) keyevent [--longpress] <key code number or name> ... (Default: keyboard) tap <x> <y> (Default: touchscreen) swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen) press (Default: trackball) roll <dx> <dy> (Default: trackball)Copy the code

Tap is the automatic tap on the screen. For example, clicking on (400, 300) at the top of the screen would simply use the following command,

adb shell input tap 400 300
Copy the code

So, where exactly is that point on the screen? Here’s a way to get the exact position of a point: Go to the Developer options, open Pointer Position in Input, and display the position of the touch when you touch a point on the screen.

Tap doesn’t work well, though, because games, for example, do their own processing of touch events and may require a certain amount of time before they are considered clicks. So what do we do here?

We can do this via Swipe. To swipe means to slip. This action allows you to pass in a sliding time, and if you slide on a position for 2 seconds, it may be judged by the game as a 2 second down. So, in the end, all you need to do is use the following script,

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

import os, time

if __name__ == "__main__":
	while True:
		print(str(int(time.time())), end='\r')
		os.system("adb -s 61e22ff2 shell input swipe 2000 1000 2000 1000 100")
Copy the code

This is just a simple use of ADB. Now that we know this, we can use ADB to implement more interesting features, namely various automation operations, and so on.

The above automation is just one of ADB’s many features. In addition, ADB supports ADB shell Dumpsys Activity Top to get information about the currently displayed activity, including various information about layout controls. I have simplified and encapsulated some ADB operations in my open source library, and I have finished some of them. I can consider adding some GUI later. The address of this library is:…

In addition, I came across a fairly comprehensive open source library summarizing ADB while browsing Github. The address of this library is as follows, if you are interested, you can see for yourself:…