USB Debugging Connection to Use "adb" Tool

This section provides a tutorial example on how to create a USB debugging connection to run debugging commands using the 'adb' tool.

The first option to connect an Android device to run "adb" debugging commands is to use a USB cable as shown in this tutorial.

1. Connect your Android phone with a USB cable to your desktop computer.

2. Turn on "Developer Options" on your Android phone by going to "Settings > About Phone > Software Information", and tapping "Build number" 7 times. Yes, 7 times!

3. Go back to "Settings". You will see "Developer Options" showing up at the end of the screen.

4. Turn on "USB Debugging" on your Android phone by going to "Settings > Developer Options", and turn on the "USB Debugging" option in the "DEBUGGING" section. You will see the following confirmation message:

Allow USB debugging?

USB debugging is intended for development purposes only. It can be
used to copy data between your computer and your device, install
applications on your device without notification, and read log data.
[OK] [Cancel]

5. Tap on "OK" to confirm. You will see an authorization request message.

Allow USB debugging?

The computer's RSA key fingerprint is "....".
[x] Always allow from this computer.

6. Check "Always allow..." and tap OK to authorize the connection.

7. Verify the USB debugging connection on your desktop computer by running the following "adb" command.

herong$ ~/Applications/platform-tools/adb devices

List of devices attached
988bdb3533534e4734	device

If you see a device listed in the output, you know that your Android phone is connected and ready to run "adb" commands.

If you see a device listed with an "unauthorized" status, you probably missed the authorization step. You can go back to Android phone, turn off and turn on "Settings > Developer Options > USB debugging". Then tap "OK" on the authorization message box.

8. Test the connection by running the following "adb" commands. The output confirms that the connected phone is running Android 8.0.0 based on Linux kernel 4.4.78.

herong$ ~/Applications/platform-tools/adb shell \

herong$ ~/Applications/platform-tools/adb shell uname -a
Linux localhost 4.4.78-13052619 #1 SMP PREEMPT ... 2018 aarch64

9. Verify the "adbd" daemon process running on the connected device:

herong$ ~/Applications/platform-tools/adb shell

dream2qltecan:/ $ ps -elf | grep shell
shell   6866     1  0 13:03:53 ?     00:00:05 adbd --root_seclabel=...
shell  29977  6866  0 21:41:28 pts/0 00:00:00 sh -
shell  30029 29977 12 21:43:36 pts/0 00:00:00 ps -elf
shell  30030 29977  5 21:43:36 pts/0 00:00:00 grep shell

dream2qltecan:/ $ exit

The output confirms that "adbd" is running on the connected device as PID 6866, which runs the "sh" process (PID 29977) I requested. The "sh" process runs the "ps" process (PID 30029).

By default the "adbd" process runs under user "shell" with limited permissions. If you try the "adb root" command will restart it under user "root", you will get an error message:

herong$ ~/Applications/platform-tools/adb shell cat /system/build.prop
cat: /system/build.prop: Permission denied

herong$ ~/Applications/platform-tools/adb root
adbd cannot run as root in production builds

So the "adb shell" only gives you access limited to the user "shell", not unlimited as "root".

11. Verify the debugging server process running on the desktop computer. The server process manages the communication between the client "adb" and the daemon "adbd", as described in the previous tutorial.

herong$ ps -ef | grep adb

502 17323 1 0 22:20 adb -L tcp:5037 fork-server server --reply-fd 4

Cool, I have successfully created a USB debugging connection from my desktop computer to my Android phone and ready to run debugging command through the "adb" tool.

Table of Contents

 About This Book

 Installing JDK 1.8 on Windows System

 Installation of Android SDK R24 and Emulator

 Installing Apache Ant 1.9 on Windows System

 Developing First Android Application - HelloAndroid

 Android Application Package (APK) Files

Android Debug Bridge (adb) Tool

 What Is Android Debug Bridge (adb)

 Install "adb" as Part of SDK Platform Tools

USB Debugging Connection to Use "adb" Tool

 Wireless Debugging Connection to Use "adb" Tool

 Debugging Connection to Android Device Emulators

 Commands and Options Supported by "adb"

 "adb install" and "adb uninstall" Commands

 "adb push" and "adb pull" Commands

 "adb shell" - Remote Shell Interface

 Android File Systems

 AboutAndroid - Application to Retrieve System Information Class and Activity Lifecycle

 View Objects and Layout Resource Files

 Using "adb logcat" Command for Debugging

 Build Process and Package File Content

 Building Your Own Web Browser

 Android Command Line Shell

 Samsung Galaxy Tab 3 Mini Tablet

 USB Debugging Applications on Samsung Tablet

 Android Tablet - LG-V905R

 USB Debugging Applications on LG-V905R Tablet

 Android Phone - LG-P925g

 USB Debugging Applications on LG-P925g Phone

 Archived Tutorials


 Full Version in PDF/EPUB