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

Commit 8e6a4445 authored by RajaaAbdallah's avatar RajaaAbdallah Committed by JohnLai
Browse files

Floss: Implement Pandora modem profile

Bug: 331124618
Test: mma packages/modules/Bluetooth && pts-bot HFP
Tag: #floss
Flag: EXEMPT floss only changes
Change-Id: I5ddfe446ca764cb04dc7fbea0cfb4217f98e007e
parent 56fbe0f7
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ from floss.pandora.floss import media_client
from floss.pandora.floss import qa_client
from floss.pandora.floss import scanner_client
from floss.pandora.floss import socket_manager
from floss.pandora.floss import telephony_client
from floss.pandora.floss import utils
from gi.repository import GLib
import pydbus
@@ -71,6 +72,7 @@ class Bluetooth(object):
        self.gatt_client = gatt_client.FlossGattClient(self.bus, self.DEFAULT_ADAPTER)
        self.gatt_server = gatt_server.FlossGattServer(self.bus, self.DEFAULT_ADAPTER)
        self.socket_manager = socket_manager.FlossSocketManagerClient(self.bus, self.DEFAULT_ADAPTER)
        self.telephony_client = telephony_client.FlossTelephonyClient(self.bus, self.DEFAULT_ADAPTER)

    def __del__(self):
        if not self.is_clean:
@@ -147,6 +149,9 @@ class Bluetooth(object):
        if not self.socket_manager.register_callbacks():
            logging.error('scanner_client: Failed to register callbacks')
            return False
        if not self.telephony_client.register_telephony_callback():
            logging.error('telephony_client: Failed to register callbacks')
            return False
        return True

    def is_bluetoothd_proxy_valid(self):
@@ -161,7 +166,8 @@ class Bluetooth(object):
            self.media_client.has_proxy(),
            self.gatt_client.has_proxy(),
            self.gatt_server.has_proxy(),
            self.socket_manager.has_proxy()
            self.socket_manager.has_proxy(),
            self.telephony_client.has_proxy()
        ])

        if not proxy_ready:
@@ -199,6 +205,7 @@ class Bluetooth(object):
            self.gatt_client = gatt_client.FlossGattClient(self.bus, default_adapter)
            self.gatt_server = gatt_server.FlossGattServer(self.bus, default_adapter)
            self.socket_manager = socket_manager.FlossSocketManagerClient(self.bus, default_adapter)
            self.telephony_client = telephony_client.FlossTelephonyClient(self.bus, default_adapter)

            try:
                utils.poll_for_condition(
@@ -410,3 +417,6 @@ class Bluetooth(object):

    def disconnect_media(self, address):
        return self.media_client.disconnect(address)

    def incoming_call(self, number):
        return self.telephony_client.incoming_call(number)
+54 −0
Original line number Diff line number Diff line
# Copyright 2024 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.
"""Modem grpc interface."""

from floss.pandora.server import bluetooth as bluetooth_module
import grpc
from pandora_experimental import modem_grpc_aio
from pandora_experimental import modem_pb2


class Modem(modem_grpc_aio.ModemServicer):
    """Service to trigger modem procedures.

    This class implements the Pandora bluetooth test interfaces,
    where the meta class definition is automatically generated by the protobuf.
    The interface definition can be found in:
    https://cs.android.com/android/platform/superproject/main/+/main:packages/modules/Bluetooth/pandora/interfaces/pandora_experimental/modem.proto
    """

    def __init__(self, bluetooth: bluetooth_module.Bluetooth):
        self.bluetooth = bluetooth

    async def Call(self, request: modem_pb2.CallRequest, context: grpc.ServicerContext) -> modem_pb2.CallResponse:
        phone_number = request.phone_number
        if phone_number is None or len(phone_number) == 0:
            await context.abort(grpc.StatusCode.INVALID_ARGUMENT, 'Cannot call empty number.')

        call_result = self.bluetooth.incoming_call(phone_number)
        if not call_result:
            await context.abort(grpc.StatusCode.INTERNAL, 'Failed to receive a call.')

        return modem_pb2.CallResponse()

    async def AnswerCall(self, request: modem_pb2.AnswerCallRequest,
                         context: grpc.ServicerContext) -> modem_pb2.AnswerCallResponse:
        context.set_code(grpc.StatusCode.UNIMPLEMENTED)  # type: ignore
        context.set_details('Method not implemented!')  # type: ignore
        raise NotImplementedError('Method not implemented!')

    async def Close(self, request: modem_pb2.CloseRequest, context: grpc.ServicerContext) -> modem_pb2.CloseResponse:
        context.set_code(grpc.StatusCode.UNIMPLEMENTED)  # type: ignore
        context.set_details('Method not implemented!')  # type: ignore
        raise NotImplementedError('Method not implemented!')
+5 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ from floss.pandora.server import gatt
from floss.pandora.server import hid
from floss.pandora.server import host
from floss.pandora.server import l2cap
from floss.pandora.server import modem
from floss.pandora.server import rfcomm
from floss.pandora.server import security
import grpc
@@ -31,6 +32,7 @@ from pandora import security_grpc_aio
from pandora_experimental import gatt_grpc_aio
from pandora_experimental import hid_grpc_aio
from pandora_experimental import l2cap_grpc_aio
from pandora_experimental import modem_grpc_aio
from pandora_experimental import rfcomm_grpc_aio


@@ -58,6 +60,9 @@ async def serve(port):
            gatt_service = gatt.GATTService(bluetooth)
            gatt_grpc_aio.add_GATTServicer_to_server(gatt_service, server)

            modem_service = modem.Modem(bluetooth)
            modem_grpc_aio.add_ModemServicer_to_server(modem_service, server)

            hid_service = hid.HIDService(bluetooth)
            hid_grpc_aio.add_HIDServicer_to_server(hid_service, server)