def _initialize_target(self): try: boot_state = local_utils.get_device_boot_state( serial=self.kwargs["serial"]) if boot_state == "android": adb_connection = connection_adb(serial=self.kwargs["serial"]) platform = adb_connection.get_prop(prop="ro.product.device") elif boot_state == "fastboot": if fastboot_utils.var_exists(var="product-string", serial=self.kwargs["serial"]): product_string = fastboot_utils.get_var( var="product-string", serial=self.kwargs["serial"]) platform = str(product_string).split("/")[-1] elif fastboot_utils.var_exists(var="product", serial=self.kwargs["serial"]): product_string = fastboot_utils.get_var( var="product", serial=self.kwargs["serial"]) platform = self.__SW_PLATFORMS[product_string] else: raise Exception("Invalid boot state - {0}".format(boot_state)) target = self.__PLATFORMS[platform] self._platform = platform self._target = globals()[target](**self.kwargs) except: raise StaticsError( "{0}: Error while trying to get target from the device - {1}". format(self.kwargs["serial"], traceback.format_exc()))
def check_condition(self): # If the OEM unlocking is disabled, pass if the state is unchanged if self.oem_unlock_enabled != "yes": return self.unlock_bootloader != fastboot_utils.get_var( serial=self.serial, var="unlocked") # If the OEM unlocking is enabled, pass if tha state return self.unlock_bootloader == fastboot_utils.get_var( serial=self.serial, var="unlocked")
def do(self): #use_control_process=False psteps = ParallelSteps(use_control_process=False) # Accept lock/ unlock action using volume and power keys def accept_lock_unlock(): time.sleep(1) self.relay.press_volume_down() time.sleep(1) self.relay.press_power() current_state = fastboot_utils.get_var(serial=self.serial, var="unlocked") if self.unlock_bootloader not in str(current_state): # Run the lock/ unlock command in a parallel step step_id_lock = psteps.add_step(fastboot_steps.command, serial=self.serial, command=self.unlock_cmd + " " + self.state_cmd, stderr_grep=self.string_to_check, timeout=120000) time.sleep(2) # Run accept lock unlock if the operations is allowed if self.oem_unlock_enabled == "yes": accept_lock_unlock() # Interpret the parallel step result psteps.interpret_step(step_id_lock)