Exemplo n.º 1
0
 def openApp(self, pebbleConnection, uuid):
     AppStartService = AppMessageService(
         pebbleConnection, message_type=LegacyAppLaunchMessage)
     AppStartService.send_message(
         uuid, {
             LegacyAppLaunchMessage.Keys.RunState:
             Uint8(LegacyAppLaunchMessage.States.Running)
         })
     AppStartService.shutdown()
Exemplo n.º 2
0
class PebbleManager(object):
    def __init__(self, qemu):
        self.qemu = qemu.split(":")
        print self.qemu
        self.pebble = PebbleConnection(QemuTransport(*self.qemu), log_packet_level=logging.DEBUG)
        self.handle_start = None
        self.handle_stop = None
        self.blobdb = None
        self.launcher = None

    def connect(self):
        self.pebble.connect()
        greenlet = gevent.spawn(self.pebble.run_sync)
        self.pebble.fetch_watch_info()
        self.register_endpoints()
        self.pebble.transport.send_packet(QemuBluetoothConnection(connected=True), target=MessageTargetQemu())
        self.blobdb = BlobDBClient(self.pebble)
        self.request_running_app()
        logger.info("connected to %s", self.qemu)
        return greenlet

    def disconnect(self):
        if self.launcher is not None:
            self.launcher.shutdown()

    def register_endpoints(self):
        self.pebble.register_endpoint(AppRunState, self.handle_lifecycle)
        self.launcher = AppMessageService(self.pebble, message_type=LegacyAppLaunchMessage)
        self.launcher.register_handler("appmessage", self.handle_launcher)

    def request_running_app(self):
        if self.pebble.firmware_version.major >= 3:
            self.pebble.send_packet(AppRunState(data=AppRunStateRequest()))
        else:
            self.launcher.send_message(uuid.UUID(int=0), {LegacyAppLaunchMessage.Keys.StateFetch: Uint8(1)})

    def handle_lifecycle(self, packet):
        if isinstance(packet.data, AppRunStateStart):
            if callable(self.handle_start):
                self.handle_start(packet.data.uuid)
        elif isinstance(packet.data, AppRunStateStop):
            if callable(self.handle_stop):
                self.handle_stop(packet.data.uuid)

    def handle_launcher(self, txid, uuid, message):
        state = message[LegacyAppLaunchMessage.Keys.RunState]
        if state == LegacyAppLaunchMessage.States.Running:
            if callable(self.handle_start):
                self.handle_start(uuid)
        elif state == LegacyAppLaunchMessage.States.NotRunning:
            if callable(self.handle_stop):
                self.handle_stop(uuid)

    @property
    def timeline_is_supported(self):
        return self.pebble.firmware_version.major >= 3
Exemplo n.º 3
0
    def _install_legacy2(self):
        metadata = self._bundle.get_app_metadata()
        app_uuid = metadata['uuid']

        # We don't really care if this worked; we're just waiting for it.
        self._pebble.send_and_read(
            LegacyAppInstallRequest(data=LegacyUpgradeAppUUID(uuid=app_uuid)),
            LegacyAppInstallResponse)

        # Find somewhere to install to.
        result = self._pebble.send_and_read(
            LegacyAppInstallRequest(data=LegacyBankInfoRequest()),
            LegacyAppInstallResponse).data
        assert isinstance(result, LegacyBankInfoResponse)
        first_free = 0
        for app in result.apps:
            assert isinstance(app, LegacyBankEntry)
            if app.bank_number == first_free:
                first_free += 1
        if first_free == result.bank_count:
            raise AppInstallError("No app banks free.")

        # Send the app over
        binary = self._bundle.zip.read(self._bundle.get_app_path())
        self._send_part_legacy2(PutBytesType.Binary, binary, first_free)

        if self._bundle.has_resources:
            resources = self._bundle.zip.read(self._bundle.get_resource_path())
            self._send_part_legacy2(PutBytesType.Resources, resources,
                                    first_free)

        if self._bundle.has_worker:
            worker = self._bundle.zip.read(self._bundle.get_worker_path())
            self._send_part_legacy2(PutBytesType.Worker, worker, first_free)

        # Mark it as available
        self._pebble.send_and_read(
            LegacyAppInstallRequest(
                data=LegacyAppAvailable(bank=first_free, vibrate=True)),
            LegacyAppInstallResponse)

        # Launch it (which is painful on 2.x).
        appmessage = AppMessageService(self._pebble,
                                       message_type=LegacyAppLaunchMessage)
        appmessage.send_message(
            app_uuid, {
                LegacyAppLaunchMessage.Keys.RunState:
                AMUint8(LegacyAppLaunchMessage.States.Running)
            })
        appmessage.shutdown()
Exemplo n.º 4
0
    def _install_legacy2(self):
        metadata = self._bundle.get_app_metadata()
        app_uuid = metadata['uuid']

        self._pebble.send_packet(LegacyAppInstallRequest(data=LegacyUpgradeAppUUID(uuid=app_uuid)))
        # We don't really care if this worked; we're just waiting for it.
        self._pebble.read_from_endpoint(LegacyAppInstallResponse)

        # Find somewhere to install to.
        self._pebble.send_packet(LegacyAppInstallRequest(data=LegacyBankInfoRequest()))
        result = self._pebble.read_from_endpoint(LegacyAppInstallResponse).data
        assert isinstance(result, LegacyBankInfoResponse)
        first_free = 0
        for app in result.apps:
            assert isinstance(app, LegacyBankEntry)
            if app.bank_number == first_free:
                first_free += 1
        if first_free == result.bank_count:
            raise AppInstallError("No app banks free.")

        # Send the app over
        binary = self._bundle.zip.read(self._bundle.get_app_path())
        self._send_part_legacy2(PutBytesType.Binary, binary, first_free)

        if self._bundle.has_resources:
            resources = self._bundle.zip.read(self._bundle.get_resource_path())
            self._send_part_legacy2(PutBytesType.Resources, resources, first_free)

        if self._bundle.has_worker:
            worker = self._bundle.zip.read(self._bundle.get_worker_path())
            self._send_part_legacy2(PutBytesType.Worker, worker, first_free)

        # Mark it as available
        self._pebble.send_packet(LegacyAppInstallRequest(data=LegacyAppAvailable(bank=first_free, vibrate=True)))
        self._pebble.read_from_endpoint(LegacyAppInstallResponse)

        # Launch it (which is painful on 2.x).
        appmessage = AppMessageService(self._pebble, message_type=LegacyAppLaunchMessage)
        appmessage.send_message(app_uuid, {
            LegacyAppLaunchMessage.Keys.RunState: AMUint8(LegacyAppLaunchMessage.States.Running)
        })
        appmessage.shutdown()
Exemplo n.º 5
0
class PebbleManager(object):
    def __init__(self, qemu):
        self.qemu = qemu.split(':')
        print self.qemu
        self.pebble = PebbleConnection(QemuTransport(*self.qemu),
                                       log_packet_level=logging.DEBUG)
        self.handle_start = None
        self.handle_stop = None
        self.blobdb = None
        self.launcher = None

    def connect(self):
        self.pebble.connect()
        greenlet = gevent.spawn(self.pebble.run_sync)
        self.pebble.fetch_watch_info()
        self.register_endpoints()
        self.pebble.transport.send_packet(
            QemuBluetoothConnection(connected=True),
            target=MessageTargetQemu())
        self.blobdb = BlobDBClient(self.pebble)
        self.request_running_app()
        logger.info('connected to %s', self.qemu)
        return greenlet

    def disconnect(self):
        if self.launcher is not None:
            self.launcher.shutdown()

    def register_endpoints(self):
        self.pebble.register_endpoint(AppRunState, self.handle_lifecycle)
        self.launcher = AppMessageService(self.pebble,
                                          message_type=LegacyAppLaunchMessage)
        self.launcher.register_handler("appmessage", self.handle_launcher)

    def request_running_app(self):
        if self.pebble.firmware_version.major >= 3:
            self.pebble.send_packet(AppRunState(data=AppRunStateRequest()))
        else:
            self.launcher.send_message(
                uuid.UUID(int=0),
                {LegacyAppLaunchMessage.Keys.StateFetch: Uint8(1)})

    def handle_lifecycle(self, packet):
        if isinstance(packet.data, AppRunStateStart):
            if callable(self.handle_start):
                self.handle_start(packet.data.uuid)
        elif isinstance(packet.data, AppRunStateStop):
            if callable(self.handle_stop):
                self.handle_stop(packet.data.uuid)

    def handle_launcher(self, txid, uuid, message):
        state = message[LegacyAppLaunchMessage.Keys.RunState]
        if state == LegacyAppLaunchMessage.States.Running:
            if callable(self.handle_start):
                self.handle_start(uuid)
        elif state == LegacyAppLaunchMessage.States.NotRunning:
            if callable(self.handle_stop):
                self.handle_stop(uuid)

    @property
    def timeline_is_supported(self):
        return self.pebble.firmware_version.major >= 3