~mterry/jenkins-launchpad-plugin/skip-greeter

« back to all changes in this revision

Viewing changes to unlock_screen.py

Update screen unlock code to match lp:~ubuntu-test-case-dev/ubuntu-test-cases/touch. Remove internal use of bzr branch, push needed files instead. Move unlock step to right after power on.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
from autopilot import introspection
4
4
from autopilot.display import Display
5
5
from autopilot.input import Pointer, Touch
 
6
import dbus
6
7
import os
7
8
import sys
8
 
import subprocess
 
9
import time
9
10
 
10
11
 
11
12
def help():
17
18
 
18
19
 
19
20
def start_unity_in_testability():
20
 
    override_file = os.path.expanduser("~/.config/upstart/unity8.override")
 
21
    override_file = "~/.config/upstart/unity8.override"
 
22
 
21
23
    os.system('echo "exec unity8 -testability" > ~/.config/upstart/unity8.override')
22
 
    
23
 
    pid = int(subprocess.check_output(["pidof", "unity8"]))
24
 
    if pid:
25
 
        print "Stopping unity"
26
 
        os.system('stop -q unity8')
27
 
        if os.path.exists("/proc/%d" % pid) is False:
28
 
            print "Unity process stopped successfully"
29
 
    
30
 
    print "Now starting unity in testability mode"
31
 
    os.system('start -q unity8')
32
 
    pid = int(subprocess.check_output(["pidof", "unity8"]))
33
 
    if os.path.exists("/proc/%d" % pid) is True:
34
 
        print "Unity is now started "
35
 
    
36
 
    print "Cleaning up upstart override"
 
24
 
 
25
    print "----------------------------------------------------------------------"
 
26
    print "Stopping Unity"
 
27
    os.system('/sbin/stop unity8')
 
28
    print "Unity stopped"
 
29
    os.system('rm -f /tmp/mir_socket')
 
30
 
 
31
    print "----------------------------------------------------------------------"
 
32
    print "Taking screen lock (#1235000)"
 
33
    bus = dbus.SystemBus()
 
34
    powerd = bus.get_object('com.canonical.powerd', '/com/canonical/powerd')
 
35
    powerd_cookie = powerd.requestSysState("autopilot-lock", 1, dbus_interface='com.canonical.powerd')
 
36
    print "----------------------------------------------------------------------"
 
37
    print "Starting Unity with testability"
 
38
    os.system('/sbin/start unity8')
 
39
    print "Unity started"
 
40
    print "----------------------------------------------------------------------"
 
41
    print "Releasing screen lock (#1235000)"
 
42
    powerd.clearSysState(powerd_cookie, dbus_interface='com.canonical.powerd')
 
43
 
 
44
    print "----------------------------------------------------------------------"
37
45
    if os.path.exists(override_file):
38
46
        os.remove(override_file)
39
 
    
40
 
    print "Attempting to unlock the screen"
 
47
    print "Cleaned up upstart override"
 
48
    print "----------------------------------------------------------------------"
 
49
 
 
50
    print "Turning on the screen"
 
51
    print ""
 
52
    time.sleep(15)
41
53
 
42
54
 
43
55
def unlock_screen():
47
59
    unity8 = introspection.get_proxy_object_for_existing_process(connection_name=conn)
48
60
    greeter = unity8.select_single("Greeter")
49
61
    x, y, w, h = greeter.globalRect
50
 
    tx = int(x + w)
51
 
    ty = int(y + (h / 2))
 
62
    tx = x + w
 
63
    ty = y + (h / 2)
52
64
 
53
65
    pointing_device.drag(tx, ty, tx / 2, ty)
54
66
    try:
55
67
        greeter.shown.wait_for(False)
56
 
        print "THE SCREEN UNLOCKED SUCCESSFULLY"
57
 
    except:
58
 
        AssertionError
59
 
        print "The screen could not be unlocked, try restarting the device"
60
 
 
61
 
 
62
 
def unlock_screen_blind():
 
68
    except AssertionError:
 
69
        print "----------------------------------------------------------------------"
 
70
        print "THE SCREEN DIDN'T UNLOCK THE FIRST TRY, NOW ATTEMPTING A BLIND SWIPE"
 
71
        unlock_screen_blind(greeter)
 
72
 
 
73
 
 
74
def unlock_screen_blind(greeter=None):
63
75
    input_device = Touch.create()
64
76
    pointing_device = Pointer(input_device)
65
77
    x, y, w, h = Display.create(preferred_backend='UPA').get_screen_geometry(0)
66
 
    tx = int(x + w)
67
 
    ty = int(y + (h / 2))
 
78
    tx = x + w
 
79
    ty = y + (h / 2)
68
80
 
69
81
    pointing_device.drag(tx, ty, tx / 2, ty)
 
82
    if greeter is not None:
 
83
        try:
 
84
            greeter.shown.wait_for(False)
 
85
            if greeter.shown is False:
 
86
                print ""
 
87
                print "THE SCREEN IS NOW UNLOCKED"
 
88
        except AssertionError:
 
89
            print "----------------------------------------------------------------------"
 
90
            "THE SCREEN DIDN'T UNLOCK, RESTART THE DEVICE AND RUN THE SCRIPT AGAIN"
70
91
 
71
92
 
72
93
if len(sys.argv) >= 2 and sys.argv[1] == '-q':