1# Copyright (C) 2024 The Android Open Source Project 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# http://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"""Profile proxy base module.""" 15 16from mmi2grpc._helpers import format_function 17from mmi2grpc._helpers import assert_description 18 19from pandora_experimental.os_grpc import Os 20 21 22class ProfileProxy: 23 """Profile proxy base class.""" 24 25 def __init__(self, channel) -> None: 26 self.os = Os(channel) 27 28 def interact(self, test: str, mmi_name: str, mmi_description: str, pts_addr: bytes): 29 """Translate a MMI call to its corresponding implementation. 30 31 Args: 32 test: PTS test id. 33 mmi_name: MMI name. 34 mmi_description: MMI description. 35 pts_addr: Bluetooth MAC address of the PTS in bytes. 36 37 Raises: 38 AttributeError: the MMI is not implemented. 39 """ 40 try: 41 if not mmi_name.isidentifier(): 42 mmi_name = "_mmi_" + mmi_name 43 self.log(f"starting MMI {mmi_name}") 44 out = getattr(self, mmi_name)(test=test, description=mmi_description, pts_addr=pts_addr) 45 self.log(f"finishing MMI {mmi_name}") 46 return out 47 except AttributeError: 48 code = format_function(mmi_name, mmi_description) 49 assert False, f'Unhandled mmi {mmi_name}\n{code}' 50 51 def log(self, text=""): 52 self.os.Log(text=text) 53 54 def test_started(self, test: str, description: str, pts_addr: bytes): 55 return "OK" 56