Exemplo n.º 1
0
def prepare_for_next_run(suite):
    devices = [device for device in all_devices]
    print "Start preparing for the next {0} run".format(suite.upper())
    if len(devices) > 0:
        for device in devices:
            serial = device["serial"]
            print "Prepare device {0} for next build.".format(device)
            print "Will try to use adb connection to shutdown/put the device into sleep mode"
            if local_utils.has_adb_serial(serial = serial):
                if shutdown_to_charge:
                    print "[ {0} ]: Shutdown device to charge".format(serial)
                    local_steps.command(command = "adb -s {0} shell reboot -p".format(serial))()
                    time.sleep(5)
                    print "[ {0} ]: Shutdown - Done!".format(serial)
                else:
                    print "[ {0} ]: Put device into sleep mode".format(serial)
                    adb_steps.put_device_into_sleep_mode(serial = serial)()
                    print "[ {0} ]: Sleep - Done!".format(serial)
            else:
                print "[ {0} ]: does not have adb connection!!!".format(serial)
                print "[ {0} ]: Try to use relay to shutdown the devices".format(serial)
                try:
                    my_relay = Relayed_device(relay_port = device["relay"]["tty"],
                                            power_port = device["relay"]["power_port"],
                                            v_up_port = device["relay"]["v_up_port"],
                                            v_down_port = device["relay"]["v_down_port"])
                    my_relay.power_on()
                    my_relay.power_off()
                    my_relay.close()
                except Exception, e:
                    print "{0} devivice has no relay - {1}!!!".format(serial, e.message)
Exemplo n.º 2
0
class perform_startup_wizard(base_step):
    def __init__(self, device, platform, version=None, **kwargs):
        self.relay = Relayed_device(kb_relay_port=device['kb']['relay_tty'],
                                    kb_port=device['kb']['kb_tty'])
        self.kb_device_port = device['kb']['port']
        self.platform = platform
        self.version = version
        base_step.__init__(self, **kwargs)

    def do(self):
        print "Trying to activate kb, platform - ", str(self.platform)
        time.sleep(10)
        self.relay.try_activate_kb(self.kb_device_port)
        time.sleep(5)
        print "Should be activated"

        # welcome screen
        if self.platform == "ECS28A":
            keys = ['<enter>', '<tab>', '<enter>']
        else:
            keys = ['<enter>', '<tab>', '<enter>']
        # wifi
        keys += ['<tab>', '<tab>', '<enter>', '<tab>', '<enter>']
        # date&time
        keys += ['<tab>', '<tab>', '<enter>']
        # name
        keys += ['<tab>', '<tab>', '<tab>', '<tab>', '<enter>']
        # protect your phone
        keys += [
            '<tab>', '<tab>', '<tab>', '<tab>', '<enter>', '<tab>', '<enter>'
        ]
        # google services
        if self.platform == "ECS28A":
            keys += [
                '<tab>', '<tab>', '<tab>', '<tab>', '<tab>', '<enter>',
                '<tab>', '<tab>', '<enter>'
            ]
        else:
            keys += [
                '<tab>', '<tab>', '<tab>', '<tab>', '<tab>', '<tab>',
                '<enter>', '<tab>', '<tab>', '<enter>'
            ]
        # allow
        keys += ['<tab>', '<enter>']
        for key in keys:
            print key
            self.relay.send_to_kb(key)
            time.sleep(2)
        time.sleep(2)
        # got it
        self.relay.send_to_kb('<enter>')

        self.relay.try_deactivate_kb()
        self.relay.close()

    def check_condition(self):
        return True
Exemplo n.º 3
0
class first_boot_no_wizard(base_step):
    def __init__(self, device, **kwargs):
        self.relay = Relayed_device(kb_relay_port=device['kb']['relay_tty'],
                                    kb_port=device['kb']['kb_tty'])
        self.kb_device_port = device['kb']['port']
        base_step.__init__(self, **kwargs)

    def do(self):
        self.relay.try_activate_kb(self.kb_device_port)

        # allow
        keys += ['<tab>', '<enter>']
        # got it
        keys += ['<enter>', '<enter>']
        for key in keys:
            self.relay.send_to_kb(key)
            time.sleep(0.5)
        self.relay.try_deactivate_kb()
        self.relay.close()

    def check_condition(self):
        return True
Exemplo n.º 4
0
    s = d["serial"]
    print "Prepare device " + str(s) + " for next build."
    print "Will try to use adb connection to shutdown/put to sleep the device"
    if local_utils.has_adb_serial(serial=s):
        adb_steps.enable_uiautomator_service(serial=s, timeout=120)()
        if shutdown_to_charge:
            print str(s) + ": Shutdown device to charge"
            local_steps.command(command="adb -s " + str(s) +
                                " shell reboot -p")()
            time.sleep(5)
            print str(s) + ": Shutdown - Done!"
        else:
            print str(s) + ": Put device to sleep"
            adb_steps.put_device_into_sleep_mode(serial=s)()
            print str(s) + ": Sleep - Done!"
    else:
        print str(s) + ": does not have adb connection!!!"
        print str(s) + ": Try to use relay to shutdown the devices"
        try:
            my_relay = Relayed_device(relay_port=d["relay"]["tty"],
                                      power_port=d["relay"]["power_port"],
                                      v_up_port=d["relay"]["v_up_port"],
                                      v_down_port=d["relay"]["v_down_port"])
            my_relay.power_on()
            my_relay.power_off()
            my_relay.close()
        except Exception, e:
            print "NO relay!!!"
            print e.message
########################################################################
Exemplo n.º 5
0
class enable_usb_debugging(base_step):
    def __init__(self, device, platform="ECS27B", **kwargs):
        self.relay = Relayed_device(kb_relay_port=device['kb']['relay_tty'],
                                    kb_port=device['kb']['kb_tty'])
        self.touch_relay = Relayed_device(
            relay_port=device["relay"]["tty"],
            power_port=device["relay"]["power_port"],
            v_up_port=device["relay"]["v_up_port"],
            v_down_port=device["relay"]["v_down_port"],
            always_allow_port=device["relay"]["always_allow_port"],
            allow_ok_port=device["relay"]["allow_ok_port"],
        )
        self.kb_device_port = device['kb']['port']
        self.device = device
        self.allowed = False
        self.platform = platform
        base_step.__init__(self, **kwargs)

    def do(self):
        print self.platform
        time.sleep(5)
        self.relay.try_activate_kb(self.kb_device_port)
        time.sleep(5)
        if self.platform == "ECS28A":
            # about app button
            keys = [
                '<tab>', '<tab>', '<tab>', '<tab>', '<tab>', '<tab>', '<tab>',
                '<tab>', '<enter>'
            ]
            # setting
            keys += [
                '<downarrow>', '<downarrow>', '<downarrow>', '<downarrow>',
                '<rarrow>', '<rarrow>'
            ]
            keys += [
                '<rarrow>', '<rarrow>', '<rarrow>', '<rarrow>', '<rarrow>',
                '<enter>'
            ]
            # about phone
            keys += [
                '<downarrow>', '<downarrow>', '<downarrow>', '<downarrow>',
                '<downarrow>'
            ]
            keys += [
                '<downarrow>', '<downarrow>', '<downarrow>', '<downarrow>',
                '<downarrow>', '<enter>'
            ]
            # enable dev_options
            keys += [
                '<downarrow>', '<downarrow>', '<downarrow>', '<downarrow>',
                '<downarrow>', '<downarrow>'
            ]
            keys += [
                '<enter>', '<enter>', '<enter>', '<enter>', '<enter>',
                '<enter>', '<enter>', '<esc>'
            ]
            # dev options
            keys += ['<uparrow>', '<larrow>', '<enter>']
            # enable_usb_debugging
            keys += [
                '<downarrow>', '<downarrow>', '<downarrow>', '<downarrow>',
                '<downarrow>'
            ]
            keys += ['<downarrow>', '<downarrow>', 'downarrow']
            keys += ['<enter>', '<tab>', '<enter>']
            # home
            keys += ['<esc>', '<esc>', '<esc>']
        else:
            # all app button
            keys = [
                '<uparrow>', '<uparrow>', '<downarrow>', '<downarrow>',
                '<enter>'
            ]
            # setting
            keys += [
                '<downarrow>', '<downarrow>', '<downarrow>', '<downarrow>',
                '<downarrow>', '<enter>'
            ]
            # about phone
            keys += [
                '<downarrow>', '<downarrow>', '<downarrow>', '<downarrow>',
                '<downarrow>'
            ]
            keys += [
                '<downarrow>', '<downarrow>', '<downarrow>', '<downarrow>',
                '<downarrow>', '<enter>'
            ]
            # enable dev_options
            keys += [
                '<downarrow>', '<downarrow>', '<downarrow>', '<downarrow>',
                '<downarrow>', '<downarrow>'
            ]
            keys += [
                '<enter>', '<enter>', '<enter>', '<enter>', '<enter>',
                '<enter>', '<enter>', '<esc>'
            ]
            # dev options
            keys += [
                '<downarrow>', '<downarrow>', '<downarrow>', '<downarrow>',
                '<downarrow>'
            ]
            keys += [
                '<downarrow>', '<downarrow>', '<downarrow>', '<downarrow>',
                '<downarrow>', '<enter>'
            ]
            # enable_usb_debugging
            keys += [
                '<downarrow>', '<downarrow>', '<downarrow>', '<downarrow>',
                '<downarrow>'
            ]
            keys += ['<downarrow>', '<downarrow>']
            keys += ['<enter>', '<tab>', '<enter>']
            # home
            keys += ['<esc>', '<esc>', '<esc>']

        for key in keys:
            print key
            self.relay.send_to_kb(key)
            time.sleep(1)
        self.relay.try_deactivate_kb()
        time.sleep(5)

        # Allow USB debugging -- checkbox + OK
        # Trying 5 times and then exit with error
        for t in range(5):
            try:
                print "Try to check always allow and touch OK - ", str(t + 1)
                self.touch_relay.allow_usb_debugging()
                time.sleep(5)
                self.relay.try_activate_kb(self.kb_device_port)
                time.sleep(5)
                self.relay.try_deactivate_kb()
                time.sleep(5)
                local_steps.wait_for_adb(serial=self.device["serial"],
                                         timeout=10)()
                print "Success"
                self.allowed = True
                break
            except FailedError:
                print "Failed"
                pass

        self.relay.close()
        self.touch_relay.close()

    def check_condition(self):
        return self.allowed
Exemplo n.º 6
0
 def do(self):
     cmd_header = "screen -x {0} -p0 -X stuff '".format(self.screen_name)
     enter = "\r'"
     local_steps.command(command="{0}{1}{2}".format(
         cmd_header, self.screen_command, enter))()
     if not self.user_build or self.user_signed or self.update:
         return
     waiting = 0
     unlock_grep = "\"oem\" \"unlock\"` command"
     print "{0}: Waiting unlock command".format(self.serial)
     while waiting < self.timeout / 8:
         cat_grep_cmd = "tail -n 10 {0} | grep '{1}'".format(
             self.screen_log, unlock_grep)
         stdout, stderr = self.local_connection.run_cmd(
             command=cat_grep_cmd)
         if unlock_grep in stdout:
             time.sleep(30)
             my_relay = Relayed_device(
                 relay_port=self.device["relay"]["tty"],
                 power_port=self.device["relay"]["power_port"],
                 v_up_port=self.device["relay"]["v_up_port"],
                 v_down_port=self.device["relay"]["v_down_port"])
             my_relay.press_volume_up()
             my_relay.press_power()
             my_relay.close()
             break
         waiting += 2
         time.sleep(2)
     unlock_grep = "\"oem\" \"unlock\"` failed"
     while waiting < 30:
         cat_grep_cmd = "tail -n 10 {0} | grep '{1}'".format(
             self.screen_log, unlock_grep)
         stdout, stderr = self.local_connection.run_cmd(
             command=cat_grep_cmd)
         if unlock_grep in stdout:
             print "{0}: Unlock command failed".format(self.serial)
             print "{0}: The device is not OEM enabled!!!!!".format(
                 self.serial)
             sys.exit(0)
         waiting += 2
         time.sleep(2)
     waiting = 0
     lock_grep = "\"oem\" \"lock\"` command"
     print "{0}: Waiting lock command".format(self.serial)
     while waiting < self.timeout * 6 / 8:
         cat_grep_cmd = "tail -n 10 {0} | grep '{1}'".format(
             self.screen_log, lock_grep)
         stdout, stderr = self.local_connection.run_cmd(
             command=cat_grep_cmd)
         if lock_grep in stdout:
             time.sleep(30)
             my_relay = Relayed_device(
                 relay_port=self.device["relay"]["tty"],
                 power_port=self.device["relay"]["power_port"],
                 v_up_port=self.device["relay"]["v_up_port"],
                 v_down_port=self.device["relay"]["v_down_port"])
             my_relay.press_volume_up()
             my_relay.press_power()
             my_relay.close()
             break
         waiting += 2
         time.sleep(2)