Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3e6cd433 authored by Charlie Boutier's avatar Charlie Boutier
Browse files

Pandora: Add dck.proto and dck implement bumble server

Test: atest BumbleBluetoothTests:android.bluetooth.DckTest
Bug: 294274195
Change-Id: Ie22ac6ec90c4b91412aa7aed08d765b2301c112b
parent 3033d709
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

option java_outer_classname = "DckProto";

package pandora;

import "google/protobuf/empty.proto";

service Dck {
  // Register DCK Service.
  rpc Register(google.protobuf.Empty) returns (google.protobuf.Empty);
}
 No newline at end of file
+5 −0
Original line number Diff line number Diff line
@@ -34,6 +34,10 @@ genrule {
        "pandora_experimental/avrcp_grpc_aio.py",
        "pandora_experimental/avrcp_pb2.py",
        "pandora_experimental/avrcp_pb2.pyi",
        "pandora_experimental/dck_grpc.py",
        "pandora_experimental/dck_grpc_aio.py",
        "pandora_experimental/dck_pb2.py",
        "pandora_experimental/dck_pb2.pyi",
        "pandora_experimental/gatt_grpc.py",
        "pandora_experimental/gatt_grpc_aio.py",
        "pandora_experimental/gatt_pb2.py",
@@ -97,6 +101,7 @@ filegroup {
    srcs: [
        ":pandora_experimental-python-gen-src{pandora_experimental/asha_pb2.pyi}",
        ":pandora_experimental-python-gen-src{pandora_experimental/avrcp_pb2.pyi}",
        ":pandora_experimental-python-gen-src{pandora_experimental/dck_pb2.pyi}",
        ":pandora_experimental-python-gen-src{pandora_experimental/gatt_pb2.pyi}",
        ":pandora_experimental-python-gen-src{pandora_experimental/hfp_pb2.pyi}",
        ":pandora_experimental-python-gen-src{pandora_experimental/hid_pb2.pyi}",
+26 −0
Original line number Diff line number Diff line
@@ -12,13 +12,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import grpc
import logging

from bumble.core import UUID as BumbleUUID, AdvertisingData
from bumble.device import Device
from bumble.gatt import TemplateService, Characteristic, CharacteristicValue
from bumble.pandora import utils
from bumble.l2cap import Channel

from google.protobuf.empty_pb2 import Empty
from pandora_experimental.dck_grpc_aio import DckServicer
from typing import Optional


class DckGattService(TemplateService):
    CCC_DK_UUID: BumbleUUID = BumbleUUID.from_16_bits(0xFFF5, 'Car Connectivity Consortium, LLC')
@@ -75,3 +81,23 @@ class DckGattService(TemplateService):
        # 19.2 LE Procedures AdvData field of ADV_IND

        return bytes(AdvertisingData([(AdvertisingData.SERVICE_DATA_16_BIT_UUID, bytes(DckGattService.CCC_DK_UUID))]))


class DckService(DckServicer):

    device: Device
    dck_gatt_service: Optional[DckGattService]

    def __init__(self, device: Device) -> None:
        self.log = utils.BumbleServerLoggerAdapter(logging.getLogger(), {"service_name": "Dck", "device": device})
        self.device = device
        self.dck_gatt_service = None

    @utils.rpc
    def Register(self, request: Empty, context: grpc.ServicerContext) -> Empty:
        logging.info("Register")
        if not self.dck_gatt_service:
            self.dck_gatt_service = DckGattService(self.device)
            self.device.add_service(self.dck_gatt_service)  # type: ignore[no-untyped-call]

        return Empty()