import subprocess

from lib_python import execution, logger, steps

__RESPONSE_OK = "0\r\r\n"


def enable_roaming_data_connection():
    response = subprocess.check_output("adb shell settings put global data_roaming 1; echo $?")

    if not response.endswith(__RESPONSE_OK):
        logger.error("ADB shell command {0} did not respond with {1}".format(response, __RESPONSE_OK))
        execution.error("ADB shell command has failed")

    execution.passed()


steps.new_step("Emulator - Enable roaming data connection", enable_roaming_data_connection)
