from lib_python import execution, steps, variables
from libcrashtest.emulator import console


def open_android_console():
    android_console = console.open_android_console()

    if android_console is None:
        execution.error("Unable to open Android console")

    variables.console = android_console
    execution.passed()


steps.new_step("Emulator - Open Android console", open_android_console)


def close_android_console():
    # check whether console is open
    if variables.console is None:
        execution.error("Unable to close console, console is None")

    # close console
    variables.console.close()
    variables.console = None

    execution.passed()


steps.new_step("Emulator - Close Android console", close_android_console)


def set_connection_as_roaming():
    if not console.enable_roaming_on_emulator(variables.console):
        execution.error("Failed to set emulator connection as roaming")

    execution.passed()


steps.new_step("Emulator - Set emulator connection as roaming", set_connection_as_roaming)


def disable_data_connection():
    if not console.disable_data_connection_on_emulator(variables.console):
        execution.error("Failed to disable data connection")

    execution.passed()


steps.new_step("Emulator - Disable data connection", disable_data_connection)
