Ejemplo n.º 1
0
    def flash(self, flash_file_list, device_info, timeout):
        """
        Start the flash execution for the flash tool (flash procedure with device state change)

        :type flash_file_list: list
        :param flash_file_list: list containing flash file absolute paths
        :type device_info: FlashDeviceInfo
        :param device_info: contain all device information needed by the flash tool
        :type timeout: int
        :param timeout: max time in seconds to do flash procedure
        :rtype: int
        :return: result of the flash procedure (Global.SUCCESS, Global.FAILURE, Global.BLOCKED)
        """

        # Check flash files availability and format
        self._flash_file = self._check_flash_files(flash_file_list)

        self._retrieve_device_info(device_info)

        # Change the device state => Trig the flash mode
        if self._switch_device_state_fct("FLASH_SWITCH_OFF") == Global.SUCCESS \
                and self._switch_device_state_fct("POS_MODE_ON") == Global.SUCCESS:
            self._flash_tool_state = "FLASH_MODE"
            flash_return_code = FlashToolBase._flash(self, timeout)
            if flash_return_code == Global.SUCCESS:
                flash_return_code, _ = self._switch_device_state_fct("WAIT_BOOT")
        else:
            self._logger.error("%s: Can not switch in fastboot mode on the device" % self.__class__.__name__)
            flash_return_code = Global.FAILURE

        return flash_return_code
Ejemplo n.º 2
0
    def _run(self):
        """
        Flash the target.

        :rtype: int
        :return: return code for flash tool command execution or None
        :rtype: str
        :return: error message if any
        """
        cur_dir = os.getcwd()
        try:
            os.chdir(self._flash_file)
            return_code, error_message = FlashToolBase._run(self)
        finally:
            os.chdir(cur_dir)

        # Valid return_code from flashing command
        if return_code is not None:
            if return_code != 0:
                self.exec_result = False
                self.error_message = "AndroidGminOSFlashTool: Unexpected result: %d" % return_code
            else:
                self.exec_result = True
                self._logger.info("AndroidGminOSFlashTool: Flash succeeds")
                self._flash_tool_state = "FLASHED"

        else:
            self.exec_result = False
            self.error_message = error_message
Ejemplo n.º 3
0
    def _run(self):
        """
        Flash the target.

        :rtype: int
        :return: return code for flash tool command execution or None
        :rtype: str
        :return: error message if any
        """
        # Set environment variable ANDROID_PRODUCT_OUT to be able to support fastboot flashall command
        os.environ["ANDROID_PRODUCT_OUT"] = self._flash_file

        return_code, error_message = FlashToolBase._run(self)

        # Delete environment variable ANDROID_PRODUCT_OUT cause no more used
        del os.environ["ANDROID_PRODUCT_OUT"]

        # Valid return_code from flashing command
        if return_code is not None:
            if return_code != 0:
                self.exec_result = False
                self.error_message = "%s: Unexpected result: %d" % (self.__class__.__name__, return_code)
            else:
                self.exec_result = True
                self._logger.info("%s: Flash succeeds" % (self.__class__.__name__))
                self._flash_tool_state = "FLASHED"

        else:
            self.exec_result = False
            self.error_message = error_message
Ejemplo n.º 4
0
    def __init__(self, logger=None):
        """
        Constructor

        :type logger: object
        :param logger: logger name
        """
        FlashToolBase.__init__(self, "FastbootTool", logger)

        # Specific to Flash Tool
        self._logger = logger if logger else LOGGER_TEST_SCRIPT
        self._flash_tool_state = "UNUSED"
        self._serial = None
        self._pos_serial = None
        self._soc_serial = None
        self._switch_device_state_fct = None
        self._first_file_flashing = False
Ejemplo n.º 5
0
    def __init__(self, logger=None):
        """
        Constructor

        :type logger: object
        :param logger: logger name
        """
        FlashToolBase.__init__(self, "PFT", logger)

        # Specific to Flash Tool
        self._logger = logger if logger else LOGGER_TEST_SCRIPT
        self._flash_tool_state = "INIT"
        self._serial = None
        self._soc_serial = None
        self._switch_device_state_fct = None
        self._first_file_flashing = False
        self._pos_mode_on_exec_thread = None
        self._flash_file = None
Ejemplo n.º 6
0
    def __init__(self, logger=None):
        """
        Constructor

        :type logger: object
        :param logger: logger name
        """
        FlashToolBase.__init__(self, self.__class__.__name__, logger)

        # Specific to Flash Tool
        self._logger = logger if logger else LOGGER_TEST_SCRIPT
        self._flash_tool_state = "UNUSED"
        self._serial = None
        self._pos_serial = None
        self._soc_serial = None
        self._switch_device_state_fct = None
        self._adb_over_ethernet = False
        self._flash_file = None
Ejemplo n.º 7
0
    def flash(self, flash_file_list, device_info, timeout):
        self._flash_file = self._check_flash_files(flash_file_list)

        #Force creating a new emulator configuration named x86
        proc = subprocess.Popen([
            self.path_to_android, 'create', 'avd', '-n', "x86", '-t', '1', '-f'
        ],
                                stdin=subprocess.PIPE)
        proc.communicate(input="no")
        flash_return_code = FlashToolBase._flash(self, timeout)

        return flash_return_code
Ejemplo n.º 8
0
    def _analyze_output(self, data):
        """
        Analyze in real time the output log from flash tool command execution
        and switch the device state when needed

        :type data: str
        :param data: string to analyze
        """
        for d in data:
            self._logger.debug(d)
            # Search in logging trigger for flashing event
            if d != "":
                if any(word in d for word in ["Ready to flash", "Waiting for devices"]):
                    # Switch the device in FLASH MODE state if not already in
                    if self._flash_tool_state == "FLASH_INIT_STATE":
                        # Activate provisionning line to allow PFT to connect device as soon as it
                        # is ready (device in DNX or POS mode)
                        if self._switch_device_state_fct("POS_MODE_ON") == Global.SUCCESS:
                            self._flash_tool_state = "FLASH_MODE_START"
                        else:
                            self.exec_result = False
                            self.error_message = "PFT: Issue can not enable provisionning line on the device"
                            self._flash_tool_state = "UNUSED"
                            FlashToolBase._stop(self)

                if any(word in d for word in ["New Android device", "New SOC device", "Android device detected"]):
                    # Change the device state => Stop the flash mode as now started
                    if self._flash_tool_state == "FLASH_MODE_START":
                        # Deactivate provisionning line as PFT start the flashing.
                        if self._switch_device_state_fct("POS_MODE_OFF") == Global.SUCCESS:
                            self._flash_tool_state = "FLASH_MODE"
                        else:
                            self.exec_result = False
                            self.error_message = "PFT: Issue can not disable provisionning line on the device"
                            self._flash_tool_state = "UNUSED"
                            FlashToolBase._stop(self)
Ejemplo n.º 9
0
    def _run(self):
        """
        Flash the target.

        :rtype: int
        :return: return code for flash tool command execution or None
        :rtype: str
        :return: error message if any
        """
        return_code, error_message = FlashToolBase._run(self)

        # Valid return_code from flashing command
        if return_code is not None:
            if return_code == 0:

                # if we flash a blankphone, PFT does not restart the board
                # we stay in the current state (should be "FLASH_MODE")
                # else PFT tool reboot the board
                # We suppose that first file flashed is a blankphone
                # In the future we shall ask the device what is its state?
                if self._first_file_flashing is False:
                    # Wait for the boot (after flash, the device is booting)
                    return_code, error_message = self._switch_device_state_fct("WAIT_BOOT")
                    if return_code == Global.SUCCESS:
                        self.exec_result = True
                        self._logger.info("PFT: Flash succeeds - device succeeds to boot : %s" % error_message)
                        self._flash_tool_state = "FLASHED"
                    else:
                        self.exec_result = False
                        self.error_message = "PFT: Flash failure - device fails to boot : %s" % error_message
                        self._flash_tool_state = "UNUSED"
                else:
                    self.exec_result = True
            elif chr(return_code) == "\x11":
                self.exec_result = False
                self.error_message = "Some PFT arguments are not supported. " + \
                                     "Please check if your PhoneFlashTool version is up-to-date"
                self._flash_tool_state = "UNUSED"
            else:
                self.exec_result = False
                self.error_message = "Unexpected result: %d" % return_code
                self._flash_tool_state = "UNUSED"
        else:
            self.exec_result = False
            self.error_message = error_message
            self._flash_tool_state = "UNUSED"
Ejemplo n.º 10
0
    def flash(self, flash_file_list, device_info, timeout):
        """
        Start the flash execution for the flash tool (flash procedure with device state change)

        :type flash_file_list: list
        :param flash_file_list: list containing flash file absolute paths
        :type device_info: FlashDeviceInfo
        :param device_info: contain all device information needed by the flash tool
        :type timeout: int
        :param timeout: max time in seconds to do flash procedure

        :rtype: int
        :return: result of the flash procedure (Global.SUCCESS, Global.FAILURE, Global.BLOCKED)

        """
        # Check flash file availability and format
        flash_files = self._check_flash_files(flash_file_list)

        self._retrieve_device_info(device_info)

        flash_return_code = Global.FAILURE
        # Change the device state => Trig the flash mode
        if self._switch_device_state_fct("FLASH_SWITCH_OFF") == Global.SUCCESS:
            # Device can be flashed
            self._flash_tool_state = "FLASH_INIT_STATE"
            self._first_file_flashing = True

            # Flash all flash files passed
            for flash_file in flash_files:

                self._flash_file = flash_file
                flash_return_code = FlashToolBase._flash(self, timeout)

                self._first_file_flashing = False

                if flash_return_code == Global.FAILURE:
                    # Flash has failed on a flash file => stop the flash procedure (do not flash other flash files)
                    break
        else:
            self._logger.error("PFT: Issue can not switch off the device state")

        if flash_return_code == Global.SUCCESS:
            flash_return_code, _ = self._switch_device_state_fct("WAIT_BOOT")

        return flash_return_code
Ejemplo n.º 11
0
    def flash(self, flash_file_list, device_info, timeout):
        """
        Start the flash execution for the flash tool (flash procedure with device state change)

        :type flash_file_list: list
        :param flash_file_list: list containing flash file absolute paths
        :type device_info: FlashDeviceInfo
        :param device_info: contain all device information needed by the flash tool
        :type timeout: int
        :param timeout: max time in seconds to do flash procedure
        :rtype: int
        :return: result of the flash procedure (Global.SUCCESS, Global.FAILURE, Global.BLOCKED)
        """

        # Check flash file availability and format
        flash_files = self._check_flash_files(flash_file_list)

        self._retrieve_device_info(device_info)

        # Flash all flash files passed
        for flash_file in flash_files:

            # Device state will depend of the flash file type and the current flash tool state
            if self._flash_tool_state == "UNUSED":
                # Change the device state => Trig the flash mode
                if self._switch_device_state_fct("FLASH_SWITCH_OFF") == Global.SUCCESS and \
                    self._switch_device_state_fct("POS_MODE_ON") == Global.SUCCESS:
                    self._flash_tool_state = "FLASH_MODE_START"
                else:
                    self._logger.error(
                        "FastbootTool: Issue can not switch off + enable provisionning mode on the device"
                    )
                    flash_return_code = Global.FAILURE

            if self._flash_tool_state == "FLASH_MODE_START" or self._flash_tool_state == "FLASH_MODE":
                self._flash_file = flash_file
                flash_return_code = FlashToolBase._flash(self, timeout)

            if flash_return_code == Global.FAILURE:
                # Flash has failed on a flash file => stop the flash procedure (do not flash other flash files)
                break

        return flash_return_code