dtmilano / AndroidViewClient

Android ViewServer and ADB client
Apache License 2.0
1.62k stars 347 forks source link

device.unclock() method doesn't do the "magic" when swipe needed? #157

Closed husaria closed 8 years ago

husaria commented 8 years ago

I've got following simple script to unlock device (no passcode or anything set):

from com.dtmilano.android.viewclient import ViewClient

device, serial = ViewClient.connectToDeviceOrExit()
if device.checkConnected():
    print("Device connected - serial: {}".format(serial))
    print("Device is going to be unlocked...")
    device.wake()
    device.unlock()
else:
    print("Device is not connected!"){code}

Device is just woken up but no unlocking is done. Is this method should do unlocking when swipe is needed? Should I do the "swiping" in some other way? What would be the best solution? I cannot find any swipe method.

dtmilano commented 8 years ago

After you wake up the device you should swipe to unlock it. The easiest way to generate the code would be using culebra -G, opening the Drag Dialog, specify the coordinates for your specific device and you'll have the code you can put in a swipeToUnlock() method.

See the details at http://dtmilano.blogspot.ca/2014/11/culebra-magical-drag.html

dtmilano commented 8 years ago

screen shot 2015-12-04 at 01 07 46 pm

This shows an example of culebra unlocking a phone by swiping (using Drag Dialog).

The generated code would look like this:

device.wake()
device.dragDip((168.67, 606.0), (168.67, 378.67), 1000, 20, 0)
vc.sleep(1)
husaria commented 8 years ago

Hi Diego, thanks for your replay, I just was not sure if I don't miss any additional option for device.unlock(), I was able to figure out something like that (it works perfectly for my Samsung S5, Samsung Galaxy Tab S and Sony Xperia T2 Ultra - which is good enough for me):

from com.dtmilano.android.adb.adbclient import AdbClient

def swipe_to_unlock(serial_no):
        dev = AdbClient(serial_no)
        disp_inf = dev.getDisplayInfo()
        w = disp_inf["width"]
        h = disp_inf["height"]
        dev.drag((0.5*w, 0.9*h), (0.5*w, 0.4*h), 300)
dtmilano commented 8 years ago

Great. I'm glad to hear you found the solution to your problem.