Example #1
0
 def getDevice(self):
     #todo
     #provides more device type, only android target currently
     self.logger.debug('get device instance!')
     self._device = AndroidDevice()
     self._device.getConnect()
     self._devices.append(self._device)
     return self._device
Example #2
0
async def device_watch(allow_remote: bool = False):
    serial2udid = {}
    udid2serial = {}

    def callback(udid: str, status: str):
        if status == STATUS_OKAY:
            print("Good")

    async for event in adb.track_devices():
        logger.debug("%s", event)
        # udid = event.serial  # FIXME(ssx): fix later
        if not allow_remote:
            if re.match(r"(\d+)\.(\d+)\.(\d+)\.(\d+):(\d+)", event.serial):
                logger.debug("Skip remote device: %s", event)
                continue
        if event.present:
            try:
                udid = serial2udid[event.serial] = event.serial
                udid2serial[udid] = event.serial

                device = AndroidDevice(event.serial, partial(callback, udid))

                await device.init()
                await device.open_identify()

                udid2device[udid] = device

                await hbconn.device_update({
                    # "private": False, # TODO
                    "udid":
                    udid,
                    "platform":
                    "android",
                    "colding":
                    False,
                    "provider":
                    device.addrs(),
                    "properties":
                    await device.properties(),
                })
                logger.info("Device:%s is ready", event.serial)
            except RuntimeError:
                logger.warning("Device:%s initialize failed", event.serial)
            except Exception as e:
                logger.error("Unknown error: %s", e)
                import traceback
                traceback.print_exc()
        else:
            udid = serial2udid[event.serial]
            if udid in udid2device:
                udid2device[udid].close()
                udid2device.pop(udid, None)

            await hbconn.device_update({
                "udid": udid,
                "provider": None,  # not present
            })
Example #3
0
 def getDevice(self):
     #todo
     #provides more device type, only android target currently
     self.logger.debug('get device instance!')
     self._device = AndroidDevice()
     self._device.getConnect()
     self._devices.append(self._device)
     return self._device
Example #4
0
class DeviceManager(object):
    '''DeviceManager maintains collecion of availiable devices'''
    _instance = None
    _mutex = threading.Lock()

    def __init__(self):
        self._devices = list()
        self.logger = Logger.getLogger()
        self.logger.debug('init DeviceManager instance!')

    @staticmethod
    def getInstance(context=None):
        if(DeviceManager._instance == None):
            DeviceManager._mutex.acquire()
            if(DeviceManager._instance == None):
                DeviceManager._instance = DeviceManager()
            else:
                pass
            DeviceManager._mutex.release()
        else:
            pass

        if not context is None:
            DeviceManager._instance.setContext(context)
        return DeviceManager._instance

    def setContext(self, context=None):
        self._context = context

    def getDevice(self):
        #todo
        #provides more device type, only android target currently
        self.logger.debug('get device instance!')
        self._device = AndroidDevice()
        self._device.getConnect()
        self._devices.append(self._device)
        return self._device

    def getDeviceState(self,serial=None):
        return self._device.getState()

    def getDevices(self):
        return self._devices
Example #5
0
class DeviceManager(object):
    '''DeviceManager maintains collecion of availiable devices'''
    _instance = None
    _mutex = threading.Lock()

    def __init__(self):
        self._devices = list()
        self.logger = Logger.getLogger()
        self.logger.debug('init DeviceManager instance!')

    @staticmethod
    def getInstance(context=None):
        if (DeviceManager._instance == None):
            DeviceManager._mutex.acquire()
            if (DeviceManager._instance == None):
                DeviceManager._instance = DeviceManager()
            else:
                pass
            DeviceManager._mutex.release()
        else:
            pass

        if not context is None:
            DeviceManager._instance.setContext(context)
        return DeviceManager._instance

    def setContext(self, context=None):
        self._context = context

    def getDevice(self):
        #todo
        #provides more device type, only android target currently
        self.logger.debug('get device instance!')
        self._device = AndroidDevice()
        self._device.getConnect()
        self._devices.append(self._device)
        return self._device

    def getDeviceState(self, serial=None):
        return self._device.getState()

    def getDevices(self):
        return self._devices