def connect_disconnect_a2dp_headset(self): """Connects and disconnect a2dp profile on headset for multiple iterations. Steps: 1.Connect a2dp profile on headset. 2.Disconnect a2dp profile on headset. 3.Repeat step 1 and 2 for N iterations. Returns: True if successful, False otherwise. """ for i in range(0, self.iterations): self.log.info("A2DP connect/disconnect Iteration {}".format(i)) if not connect_dev_to_headset( self.pri_ad, self.audio_receiver.mac_address, set([BtEnum.BluetoothProfile.A2DP.value])): self.log.error("Failed to connect headset.") return False if not disconnect_headset_from_dev( self.pri_ad, self.audio_receiver.mac_address, [BtEnum.BluetoothProfile.A2DP.value]): self.log.error("Failed to disconnect headset.") return False return True
def initiate_call_when_a2dp_streaming_on(self): """Initiates HFP call when a2dp is streaming, then check for call is present or not. Disconnect a2dp profile and then connect HFP profile and answer the call from reference device. Returns: True if successful, False otherwise. """ if not self.play_music_and_connect_wifi(): return False if not initiate_call(self.log, self.pri_ad, self.re_phone_number): self.log.error("Failed to initiate call") return False if wait_for_dialing(self.log, self.pri_ad): self.pri_ad.droid.bluetoothDisconnectConnectedProfile( self.audio_receiver.mac_address, [BtEnum.BluetoothProfile.A2DP.value]) if not connect_dev_to_headset( self.pri_ad, self.audio_receiver.mac_address, [BtEnum.BluetoothProfile.HEADSET.value]): return False if not wait_and_answer_call(self.log, self.sec_ad): self.log.error("Failed to answer call in second device") return False time.sleep(self.iperf["duration"]) if not hangup_call(self.log, self.pri_ad): self.log.error("Failed to hangup call") return False return True
def connect_disconnect_hfp_headset(self): """Connect and disconnect hfp profile on headset for multiple iterations. Steps: 1.Connect hfp profile on headset. 2.Disconnect hfp profile on headset. 3.Repeat step 1 and 2 for N iterations. Returns: True if successful, False otherwise. """ for i in range(self.iterations): if not connect_dev_to_headset( self.pri_ad, self.audio_receiver.mac_address, {BtEnum.BluetoothProfile.HEADSET.value}): self.log.error("Failure to connect HFP headset.") return False if not disconnect_headset_from_dev( self.pri_ad, self.audio_receiver.mac_address, {BtEnum.BluetoothProfile.HEADSET.value}): self.log.error("Could not disconnect {}".format( self.audio_receiver.mac_address)) return False return True
def connect_to_headset_when_turned_off_with_iperf(self): """Wrapper function to start iperf and test connection to headset when it is turned off. Returns: True if successful, False otherwise. """ self.run_iperf_and_get_result() self.audio_receiver.clean_up() if not connect_dev_to_headset( self.pri_ad, self.audio_receiver.mac_address, set([BtEnum.BluetoothProfile.HEADSET.value])): self.log.error("Failed to connect to headset.") return True return False