"Self portrait tutorial 57" Python "FastBoot one click brush

Keywords: Python Android Mobile Programming

Most Android mobile phones / car phones / TVs and other mobile terminal devices,
You can refresh the Android system version through fastboot, which is actually the swipe of multiple img files (image files).


Preparation stage
  1. First, press the combination button (the combination button of each Android terminal is different, for example, some of them press and hold the Home key + volume down key continuously and then turn on, lasting for more than 3s),
    Enter fastboot mode. You can also use the ADB reboot bootloader command to enter the fastboot mode.
  2. Connect USB to Android device to ensure fastboot devices can find Android device
  3. The fastboot flash *.img command can be used to write various specified packages,
  4. You can exit the fastboot mode and restart the system through fastboot reboot
  5. Note 1: the following script's img file brush order cannot be changed at will.
  6. Note 2: the img files written by each Android terminal are different. Please consult the corresponding R & D personnel or spm.
  7. Note 3: there is a risk in brushing the machine. If it's not a professional R & D or testing personnel, please don't brush your Android device at will to avoid turning it into a brick!

Python batch script

Remember the essence of batch scripts: execute statements in batch order

#python3
#coding=utf-8

import os

print("Being fastboot Brush machine, Please wait a moment...")
os.system("fastboot oem format")
os.system("fastboot flash systemA system.img")
os.system("fastboot flash recoveryA recovery.img")
os.system("fastboot flash systemB system.img")
os.system("fastboot flash recoveryB recovery.img")
os.system("fastboot flash cache cache.img")
os.system("fastboot flash data data.img")
os.system("fastboot flash map map.img")
os.system("fastboot flash private private.img")
os.system("fastboot flash speech speech.img")
print("Brush machine finished, Restart...")
os.system("fastboot reboot")
os.system("pause")

Python procedure oriented functions

Process function oriented programming thinking should be as follows:
How many functions do you need to do this.
It's better to encapsulate all functions as well as possible. If you need to expose only some parameter interfaces, you can.
Package the previous script statement block, no need to pass parameters, and then call this FastBoot? Flash().

import os

def fastboot_flash():
    print("Being fastboot Brush machine, Please wait a moment...")
    os.system("fastboot oem format")
    os.system("fastboot flash systemA system.img")
    os.system("fastboot flash recoveryA recovery.img")
    os.system("fastboot flash systemB system.img")
    os.system("fastboot flash recoveryB recovery.img")
    os.system("fastboot flash cache cache.img")
    os.system("fastboot flash data data.img")
    os.system("fastboot flash map map.img")
    os.system("fastboot flash private private.img")
    os.system("fastboot flash speech speech.img")
    print("Brush machine finished, Restart...")
    os.system("fastboot reboot")

fastboot_flash()
os.system("pause")

Python object oriented classes

The programming thinking of object-oriented class should be as follows:
If you are given a blank world, what kinds of things do you need in this world,
What are the common attributes and methods of these kinds of things,
What is the relationship between these kinds of things (objects) and other kinds of things (objects).
Try to encapsulate these classes and only expose the external attributes (variables) and methods (functions).

import os

class FastbootFlasher():
    def __init__(self):
        pass

    def fastboot_flash(self):
        print("Being fastboot Brush machine, Please wait a moment...")
        os.system("fastboot oem format")
        os.system("fastboot flash systemA system.img")
        os.system("fastboot flash recoveryA recovery.img")
        os.system("fastboot flash systemB system.img")
        os.system("fastboot flash recoveryB recovery.img")
        os.system("fastboot flash cache cache.img")
        os.system("fastboot flash data data.img")
        os.system("fastboot flash map map.img")
        os.system("fastboot flash private private.img")
        os.system("fastboot flash speech speech.img")
        print("Brush machine finished, Restart...")
        
    def fastboot_reboot(self):
        os.system("fastboot reboot")

f_obj = FastbootFlasher()
f_obj.fastboot_flash()
f_obj.fastboot_reboot()
os.system("pause")

Operation mode

Make sure the Android device is connected to the computer through the USB cable, and successfully enters the fastboot mode,
fastboot device device is effectively connected,
Unzip the system version package, and then drop FastBoot? Flash.py to the unzipped folder,

Double click to run FastBoot? Flash.py.

Remind again that the above brush machine has risks. If it is not a professional R & D personnel or testing personnel, please do not brush your Android device at will, to avoid brushing into bricks!


For more and better original articles, please visit the official website: www.zipython.com
Selfie tutorial (automatic testing Python tutorial, the first Python tutorial for software testers)
Original link: https://www.zipython.com/#/detail?id=692d5fe794e44f309459d3774eec8ab6
You can also follow the wechat subscription number of "wusanren" and accept the article push at any time.

Posted by Stevis2002 on Fri, 10 Apr 2020 01:13:19 -0700