Lock/Unlock Android Smartphone mit Monkeyrunner

Kurz zur Einleitung, weil das mein erster Post zu diesem Thema ist:
Monkeyrunner ist ein Tool des Android SDK, welches als Schnittstelle zu dem angeschlossenen Android Smartphone fungiert. Es bietet eine, mit Python Scripten angesprochene, Fernsteuerung des Geräts mit einigen Features. So lassen sich lange Interaktionsfolgen automatisiert verscripten und „unbemannt“ ausführen.

Also, Screen Lock & Unlock mit Monkeyrunner:

# simulierter Druck auf den Power Knopf -> Screen aus
device.press("POWER", MonkeyDevice.DOWN_AND_UP)

# eigene Methode zum Aufwecken des Bildschirms
# nochmal ein Druck auf POWER funktioniert nicht
device.wake()

# 1 Sekunde warten
MonkeyRunner.sleep(1)

# Ziehen des Entsperr-Rings (vom unteren Rand in die Mitte (HTC One X))
device.drag((354, 1191), (324, 525), 1, 10)

# entsperrt!

Der Sperrbildschirm ist in diesem Beispiel nur mit dem üblichen Entsperr-Ring von HTC versehen, kein Muster oder PIN.
Die einzige Hürde ist also das Festlegen der Koordinaten beim Entsperren. Dazu später noch ein weiteres Tutorial.

English Version

A short introduction first because this is the first post on this topic:

Monkeyrunner is a tool which provides an interface between your computer and the connected Android smartphone. It is controlled by Python scripts and is capable of serving as a Android device remote control with functions like sending various inputs, running apps, taking and saving screenshots from the device. This way you can automatize complex interactions and inputs and run them unattended.

How to lock & unlock the Android device with Monkeyrunner:

# simulate a POWER button press -> turn off the screen
device.press("POWER", MonkeyDevice.DOWN_AND_UP)

# monkeyrunner method to unlock the screen
# POWER button press doesn't work to turn on
device.wake()

# wait a second
MonkeyRunner.sleep(1)

# drag the unlock-ring (from bottom to center (HTC One X))
device.drag((354, 1191), (324, 525), 1, 10)

# unlocked!

This example shows that the lock screen is just secured by the HTC unlock-ring, which must simply be dragged from the bottom to the center. No lock pattern or PIN here (which is much easier to solve with monkeyrunner).
So there’s just one small thing to consider: defining the coordinates of your unlock … thingy’s start end end position. Doing so depends on the device and Android version your using. There will be a tutorial here about that very soon.

via