adb 與 fastboot

最後更新: 2019-07-10

介紹

adb: A versatile command-line tool that lets you communicate with a device.

Samsung devices use their own firmware-flashing software(Odin),

so Fastboot isn't the way to go if you own a Galaxy.

 


adb (Android Debug Bridge)

 

Microsoft Windows ADB Setup

Download the ADB ZIP file for Windows (4Mb)

Extract the contents of this ZIP file into an easily accessible folder (such as C:\adb)

How adb works

When you start an adb client, the client first checks whether there is an adb server process already running.

If there isn't, it starts the server process. When the server starts,

it binds to local TCP port 5037 and listens for commands sent from adb clients—all adb clients use port 5037 to communicate with the adb server.

The server then sets up connections to all running devices.

It locates emulators by scanning odd-numbered ports in the range 5555 to 5585,

the range used by the first 16 emulators. Where the server finds an adb daemon (adbd), it sets up a connection to that port.

Note that each emulator uses a pair of sequential ports — an even-numbered port for console connections and an odd-numbered port for adb connections.

Install Driver

 

Connect & Setting

C:\adb\platform-tools>adb devices

List of devices attached
* daemon not running; starting now at tcp:5037
* daemon started successfully

C:\adb\platform-tools>adb devices

List of devices attached

Connect the device to your PC via USB.

Enable OEM unlock in the Developer options under device Settings, if present.

# Copy files from your phone to your computer.

adb pull

# Remotely install APKs on your phone.

adb install [source.apk]

# Open or run commands in a terminal on the host Android device.

adb shell [command]

Useful command

adb shell pm list packages

...
package:com.google.android.apps.authenticator2
...

# push file

 

# boot into bootloader mode

adb reboot bootloader

Remark: 一般 reboot

adb reboot


Minimal ADB and Fastboot

 

https://forum.xda-developers.com/showthread.php?t=2317790
 


root access

 

C:\adb>adb root

C:\adb>adb shell

 


Backup &Restore ROM

 

# Create a full backup of your phone and save to the computer.

adb backup

# Restore a backup to your phone.

adb restore

i.e.

adb backup -apk -shared -all -system -f C:\backup.ab

adb restore C:\backup.ab

# flash a .zip that's on your computer to your phone

adb sideload xxx.zip

 



fastboot

 

Windows Program: fastboot.exe

 

# boot into fastboot mode

adb reboot bootloader

OR

"Volume Down" + "Power"

# unlock bootloader

# In order to do anything useful in fastboot, the bootloader must be unlocked

fastboot oem unlock

# To check the bootloader status

fastboot oem device-info

(bootloader)    Device tampered: false
(bootloader)    Device unlocked: true
(bootloader)    Device critical unlocked: true
(bootloader)    Charger screen enabled: false
(bootloader)    Display panel:
OKAY [  0.055s]
Finished. Total time: 0.057s

# To boot into recovery image

# image name: recovery-3.2.1-1.img

fastboot boot recovery-3.2.1-1.img

Downloading 'boot.img'                             OKAY [  0.996s]
booting                                            OKAY [  0.577s]
Finished. Total time: 1.619s
# 之後 reboot 了

# flash image

# update recovery mode image

fastboot flash recovery recovery.img

# update kernels

fastboot flash boot <boot image file name>.img

# update bootloader

fastboot flash bootloader <bootloader image file name>.img

# flash radio image. This one controls connectivity on your device, so if you're having problems with Wi-Fi or mobile data,

# or if you just want to update your radio, type:

fastboot flash radio <radio image file name>.img

 

A/B Partition

TWRP Not Booting? Here’s The Solution

fastboot set_active a            # b partition: fastboot set_active b

Setting current slot to 'a'                        OKAY [  0.024s]
Finished. Total time: 0.034s

fastboot reboot

 

 


Check Property

 

 

# returns encrypted or unencrypted

adb shell getprop ro.crypto.state

 


Encryption

 

Android has two methods for device encryption:

- file-based encryption(Android 7.0 and later)

    allows different files to be encrypted with different keys

    support Direct Boot

- full-disk encryption.

https://source.android.com/security/encryption/

 


 

Creative Commons license icon Creative Commons license icon