1# Copyright 2024 Google LLC 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14"""Modem grpc interface.""" 15 16from floss.pandora.server import bluetooth as bluetooth_module 17import grpc 18from pandora_experimental import modem_grpc_aio 19from pandora_experimental import modem_pb2 20 21 22class Modem(modem_grpc_aio.ModemServicer): 23 """Service to trigger modem procedures. 24 25 This class implements the Pandora bluetooth test interfaces, 26 where the meta class definition is automatically generated by the protobuf. 27 The interface definition can be found in: 28 https://cs.android.com/android/platform/superproject/main/+/main:packages/modules/Bluetooth/pandora/interfaces/pandora_experimental/modem.proto 29 """ 30 31 def __init__(self, bluetooth: bluetooth_module.Bluetooth): 32 self.bluetooth = bluetooth 33 34 async def Call(self, request: modem_pb2.CallRequest, context: grpc.ServicerContext) -> modem_pb2.CallResponse: 35 phone_number = request.phone_number 36 if phone_number is None or len(phone_number) == 0: 37 await context.abort(grpc.StatusCode.INVALID_ARGUMENT, 'Cannot call empty number.') 38 39 call_result = self.bluetooth.incoming_call(phone_number) 40 if not call_result: 41 await context.abort(grpc.StatusCode.INTERNAL, 'Failed to receive a call.') 42 43 return modem_pb2.CallResponse() 44 45 async def AnswerCall(self, request: modem_pb2.AnswerCallRequest, 46 context: grpc.ServicerContext) -> modem_pb2.AnswerCallResponse: 47 context.set_code(grpc.StatusCode.UNIMPLEMENTED) # type: ignore 48 context.set_details('Method not implemented!') # type: ignore 49 raise NotImplementedError('Method not implemented!') 50 51 async def Close(self, request: modem_pb2.CloseRequest, context: grpc.ServicerContext) -> modem_pb2.CloseResponse: 52 context.set_code(grpc.StatusCode.UNIMPLEMENTED) # type: ignore 53 context.set_details('Method not implemented!') # type: ignore 54 raise NotImplementedError('Method not implemented!') 55