示例#1
0
    def waitForConnection(timeout, deviceId=".*"):
        """
        Waits for the workstation to connect to the device.

          Args:
            timeout - The timeout in seconds to wait. The default is to wait 
                      indefinitely.
            deviceId - A regular expression that specifies the device name. See the 
                       documentation for 'adb' in the Developer Guide to learn more 
                       about device names.
        """
        if timeout:
            tstart = time.time()
            tend = tstart + timeout

        adb = ADB()
        print("adb version = %s" % adb.version())
        while not timeout or time.time() < tend:
            for devid, state in adb.devices():
                if state == 'device' and re.match(deviceId, devid):
                    adb.serialnr = devid
                    mlib = Monkey.launchmonkey(adb)

                    if mlib:
                        return MonkeyDevice(adb, mlib)
            time.sleep(0.2)
示例#2
0
class DeviceInteraction:
    def __init__(self):
        self.adb = None
        self.mon = None

    def connect(self, pin):
        self.adb = ADB()
        self.adb.connect()
        self.mon = Monkey.launchmonkey(self.adb)
        return self.unlockphone(pin)


    def unlockphone(self, pin):
        screenstate = self.adb.devicestate()
        print("screen='%s'" % screenstate)

        if not screenstate:
            print("error getting devstate")
            return

        if screenstate == 'ON_UNLOCKED':
            print("already unlocked : '%s'" % screenstate)
            return True

        if screenstate == 'OFF':
            print("turning on screen")
            self.mon.keyevent(26)   # screen on
            time.sleep(1.0)   # NOTE: need much longer here on android6 than on android9
        self.mon.keyevent(82)   # unlock
        time.sleep(0.5)
        if pin:
            print("entering pin")
            self.mon.sendtext(pin)
            time.sleep(0.1)
            self.mon.keyevent(66)   # enter pin

        time.sleep(1.0)   # NOTE: need much longer here on android6 than on android9
        screenstate = self.adb.devicestate()
        print("pin -> screen='%s'" % screenstate)

        return screenstate == 'ON_UNLOCKED'
示例#3
0
def start():
    import sys
    fn = sys.argv[1]

    adb = ADB()
    print("adb version = %s" % adb.version())
    for serial, state in adb.devices():
        adb.serialnr = serial

    cap = adb.makecapture()
    img = cap.capture()
    img.save(fn)
示例#4
0
 def connect(self, pin):
     self.adb = ADB()
     self.adb.connect()
     self.mon = Monkey.launchmonkey(self.adb)
     return self.unlockphone(pin)