import common
import subprocess
import time

from lib_python import steps, execution, variables
from libcrashtest.InputParameterConvertor import InputParameterConvertor

__KEYCODE_UNLOCK = 82
_skip_waiting = InputParameterConvertor.convert_to_bool(common.runtime_config["skip_waiting"]) if "skip_waiting" in common.runtime_config else False

def uninstall_appium_unlock():
    subprocess.call("adb uninstall io.appium.unlock")
    execution.passed()

steps.new_step("Uninstall Appium unlock helper", uninstall_appium_unlock)


def unlock_screen():
    if not _skip_waiting:
        time.sleep(15)

    variables.driver.press_keycode(__KEYCODE_UNLOCK)
    execution.passed()

steps.new_step("Unlock screen", unlock_screen)
