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 15import logging 16 17from mobly.asserts import assert_equal 18 19from pairing.br_edr.ssp.test_base import BREDRSSPPairTestBase 20 21from pandora.security_pb2 import PairingEventAnswer 22 23class BREDRKeyboardOnlyTestClass(BREDRSSPPairTestBase): 24 25 def _setup_devices(self) -> None: 26 self.ref.config.setdefault('classic_enabled', True) 27 self.ref.config.setdefault('le_enabled', False) 28 self.ref.config.setdefault('classic_ssp_enabled', True) 29 self.ref.config.setdefault('classic_sc_enabled', False) 30 31 self.ref.config.setdefault( 32 'server', 33 { 34 'pairing_sc_enable': False, 35 'pairing_mitm_enable': False, 36 'pairing_bonding_enable': True, 37 # Android IO CAP: Display_YESNO 38 # Ref IO CAP: 39 'io_capability': 'keyboard_input_only', 40 }, 41 ) 42 43 async def accept_pairing(self): 44 # this io cap is not supported on bumble side: 45 # see https://source.corp.google.com/h/googleplex-android/platform/superproject/main/+/main:external/python/bumble/bumble/device.py;l=2976?q=%22exception%20while%20confirming%22&sq=repo:googleplex-android%2Fplatform%2Fsuperproject%2Fmain%20b:main 46 # thus, this testcase does not run at all at this moment 47 # Android side triggers a pairing event 'justworks' 48 # TODO: decide what to do with this testcase 49 # - ignore this case, or 50 # - fix bumble to allow this case to run 51 52 init_ev = await anext(self.initiator_pairing_event_stream) 53 logging.debug(f'[{self.initiator_pairing_event_stream.device.name}] init_ev.method_variant():{init_ev.method_variant()}') 54 55 init_ev_ans = PairingEventAnswer(event=init_ev, confirm=True) 56 self.initiator_pairing_event_stream.send_nowait(init_ev_ans) 57 58 # responder receives just works 59 responder_ev = await anext(self.responder_pairing_event_stream) 60 logging.debug(f'[{self.responder_pairing_event_stream.device.name}] responder_ev.method_variant():{responder_ev.method_variant()}') 61 62 responder_ev_ans = PairingEventAnswer(event=responder_ev, confirm=True) 63 self.responder_pairing_event_stream.send_nowait(responder_ev_ans) 64