What is ADB?
ADB, the Android Debug Bridge, is how a computer gives instructions to an Android phone over a cable or a network. By the end of this lesson you will know its three parts, how a phone decides to trust a computer, and how to read the list adb devices prints.
One tool, three programs
When you type an adb command, three programs take part:
YOUR COMPUTER THE PHONE
┌──────────────────────────────────────┐ ┌──────────────────┐
│ │ USB │ │
│ adb devices ──► adb server ─────────┼──────────┼──► adbd │
│ (the client) (background, │ or │ (the daemon) │
│ port 5037) │ Wi-Fi │ │
│ DroidDeck ────► ▲ │ │ runs the │
│ (another client) │ │ │ command, sends │
│ │ │ │ the answer back │
└──────────────────────┼───────────────┘ └──────────────────┘
│
one server, many clients| Program | Where it runs | What it does |
|---|---|---|
| Client | Your computer | The adb command you type. It sends your request to the server and prints the answer. |
| Server | Your computer, in the background | Keeps track of every connected device and passes requests to the right one. It listens on port 5037 of your own computer. |
Daemon (adbd) | The phone | Receives requests and carries them out: installs, copies, runs commands. A daemon is a program that runs in the background waiting for work. |
The server starts by itself the first time you run an adb command, and keeps running after you close the terminal. You see this the first time:
$ adb devices
* daemon not running; starting now at tcp:5037
* daemon started successfully
List of devices attachedHere "daemon" means the adb server on your computer, which is a little confusing: the phone's program is also a daemon. To stop the server, run adb kill-server. It starts again the next time any client needs it.
DroidDeck is another client. It runs the same adb commands you would type, through the same server, and shows the results in a window. Anything DroidDeck does, adb can do from a terminal.
Get adb on your computer
adb is part of Google's Android SDK Platform-Tools, a small download that also contains fastboot. Three common ways to get it:
- Download Platform-Tools for your system from the Android developers site, unpack it, and run
adbfrom that folder or add the folder to yourPATH. - Install your Linux distribution's package:
sudo apt install adbon Debian and Ubuntu,sudo dnf install android-toolson Fedora. - Install Android Studio, which keeps a copy in
~/Android/Sdk/platform-tools.
The DroidDeck snap carries its own adb. See Install DroidDeck for every package.
Check it works:
adb versionIt prints Android Debug Bridge version, the version numbers, and where the program is installed.
Developer options and USB debugging
A phone ignores ADB until you switch it on. The switch is in a menu that Android hides from everyday users, Developer options.
Open Settings, then About phone, and tap Build number seven times. The phone may ask for your PIN, then says you are now a developer.
The place varies by maker. On some phones Build number is under Software information.
Open Developer options. It is usually under Settings › System.
Turn on USB debugging and confirm.
An Android emulator, such as the one in Android Studio, has debugging on already and needs none of this.
The authorisation prompt
Turning on USB debugging is not enough. The phone also has to trust this computer.
The first time you run adb on a computer, it creates a key pair in your home folder: a private key, ~/.android/adbkey, and a public key, ~/.android/adbkey.pub. When you plug in a phone, the server shows the phone its public key, and the phone asks you:
┌────────────────────────────────────────────┐
│ Allow USB debugging? │
│ │
│ The computer's RSA key fingerprint is: │
│ 4F:2A:…:9C │
│ │
│ ☐ Always allow from this computer │
│ │
│ Cancel Allow │
└────────────────────────────────────────────┘The fingerprint is a short summary of the computer's public key, a different one for every computer. Tick Always allow from this computer and the phone remembers the key, so it does not ask again. Leave it unticked and it asks every time you connect.
Until you select Allow, the computer can see that a phone is there, but can do nothing with it. That is the point: a stranger who plugs your locked phone into their laptop gets no access, because the prompt only shows on an unlocked screen.
WARNING
Treat the prompt like a door key. Only allow a computer you own or fully trust. Never accept it on a shared computer, a public charging kiosk or a stranger's laptop. And keep ~/.android/adbkey private: anyone with a copy can act as your computer to every phone that has allowed it.
Device states
adb devices lists every device the server can see, with a serial number that identifies it and its state:
$ adb devices
List of devices attached
emulator-5554 device
R58N12ABCDE unauthorizedAdd -l for more detail, including the model:
$ adb devices -l
List of devices attached
emulator-5554 device product:sdk_gphone64_x86_64 model:sdk_gphone64_x86_64 device:emu64x transport_id:1
R58N12ABCDE unauthorized usb:1-2 transport_id:2The states you will meet:
| State | What it means | What to do |
|---|---|---|
device | Connected, authorised and ready. | Nothing. |
unauthorized | The phone has not allowed this computer yet. | Unlock the phone and select Allow. |
offline | The server can see the device, but it is not answering. | Unplug and replug. If that fails, adb kill-server and try again. |
no permissions | On Linux, your user may not open this USB device. | Install your distribution's adb package, which brings the udev rules, and replug. |
DroidDeck shows the same states on its Devices tab, with one difference in wording: the ready state device is shown as online. See Connect a device.
Talk to one device among several
With more than one device connected, adb refuses to guess:
$ adb shell
adb: more than one device/emulatorName the one you mean with -s and its serial:
adb -s emulator-5554 shell-d picks the only USB device and -e the only emulator. DroidDeck does the same thing with its device picker: every tab acts on the device shown there, and it adds -s with that serial to each command.
Stay safe
- Only debug devices you own or have permission to test. ADB can read files, install apps and run commands; using it on someone else's phone without asking is an intrusion.
- Only allow computers you trust. If you ever accepted the prompt somewhere you should not have, open Developer options and select Revoke USB debugging authorizations. Every computer then has to ask again.
- Watch for the prompt appearing when you did not expect it. It means some computer is trying to connect. Select Cancel.
- Turn USB debugging off when you are done for the day, or turn Developer options off altogether with the switch at the top of that menu.
Check yourself
Question 1 of 6
Which part of ADB runs on the phone and carries out the requests?
What you learned
- ADB has a client (the
adbcommand or an app like DroidDeck), a server on your computer, and a daemon,adbd, on the device. - USB debugging in Developer options lets the daemon listen; the authorisation prompt decides which computers it obeys.
adb devicesshows each device's serial and state. Onlydevice(DroidDeck: online) is ready to use.- With several devices, pick one with
-sand its serial.
Next steps
- Lesson 2: ADB essentials: install apps, copy files, use the shell
- DroidDeck beginner guide: connect your phone in a window
- DroidDeck troubleshooting: when the phone does not appear