def test_connect_while_media_playing(self): """ BT connect SRC and SNK when the SRC is already playing music and verify SNK strarts streaming after connection. Connect to another device (Audio Sink) via BT while it is playing audio. Check if the audio starts streaming on the Sink. Pre-Condition: 1. Devices previously bonded & Connected Steps: 1. Disconnect TG from CT (since they are connected as a precondition) 2. Play Music on TG (Audio SRC) 3. Get the metadata of the playing music 4. Connect TG and CT 5. Check if the music is streaming on CT (Audio SNK) by checking if its MediaSession became active. 6. Fail if CT is not streaming. 7. Get the metdata from the CT (Audio SNK) and compare it with the metadata from Step 3 8. Fail if the metadata did not match. Returns: True if the event was received False if the event was not received Priority: 0 """ self.log.info("Bluetooth Disconnect the car and phone") result = bt_test_utils.disconnect_pri_from_sec( self.SRC, self.SNK, [BtEnum.BluetoothProfile.A2DP.value]) if not result: # Temporary timeout time.sleep(3) if bt_test_utils.is_a2dp_src_device_connected( self.SRC, self.SNK.droid.bluetoothGetLocalAddress()): self.SRC.log.error("Failed to disconnect on A2dp") return False self._init_mbs() # Play Media on Phone self.TG.droid.bluetoothMediaHandleMediaCommandOnPhone( car_media_utils.CMD_MEDIA_PLAY) # At this point, media should be playing only on phone, not on Car, since they are disconnected if not car_media_utils.isMediaSessionActive( self.log, self.TG, PHONE_MEDIA_BROWSER_SERVICE_NAME) or car_media_utils.isMediaSessionActive( self.log, self.CT, CAR_MEDIA_BROWSER_SERVICE_NAME): self.log.error("Media playing in wrong end") return False # Get the metadata of the song that the phone is playing metadata_TG = self.TG.droid.bluetoothMediaGetCurrentMediaMetaData() if metadata_TG is None: self.TG.log.error("No Media Metadata available from Phone") return False # Now connect to Car on Bluetooth if (not bt_test_utils.connect_pri_to_sec(self.SRC, self.SNK, set( [BtEnum.BluetoothProfile.A2DP.value]))): return False # Wait for a bit for the information to show up in the car side time.sleep(2) # At this point, since we have connected while the Phone was playing media, the car # should automatically play. Both devices should have their respective MediaSessions active if not car_media_utils.isMediaSessionActive( self.log, self.TG, PHONE_MEDIA_BROWSER_SERVICE_NAME): self.TG.log.error("Media not playing in Phone") return False if not car_media_utils.isMediaSessionActive( self.log, self.CT, CAR_MEDIA_BROWSER_SERVICE_NAME): self.CT.log.error("Media not playing in Car") return False # Get the metadata from Car and compare it with the Phone's media metadata before the connection happened. metadata_CT = self.CT.droid.bluetoothMediaGetCurrentMediaMetaData() if metadata_CT is None: self.CT.log.info("No Media Metadata available from car") return car_media_utils.compare_metadata(self.log, metadata_TG, metadata_CT)
def test_disconnect_while_media_playing(self): """ Disconnect BT between CT and TG in the middle of a audio streaming session and check 1) If TG continues to still play music 2) If CT stops playing Pre-Condition: 1. Devices previously bonded & Connected Steps: 1. Invoke Play from CT 2. Check if both CT and TG are playing music by checking if the respective MediaSessions are active 3. Fail if either the CT or TG is not playing 4. Disconnect Bluetooth connection between CT and TG 5. Check if the CT MediaSession stopped being active. Fail if its mediasession is still active. 6. Check if the TG MediaSession is still active. 7. Fail if TG stopped playing music. Returns: True if the CT stopped playing audio and the TG continued after BT disconnect False if the CT still was playing audio or TG stopped after BT disconnect. Priority: 0 """ self._init_mbs() self.log.info("Sending Play command from Car") if not car_media_utils.send_media_passthrough_cmd( self.log, self.CT, self.TG, car_media_utils.CMD_MEDIA_PLAY, car_media_utils.EVENT_PLAY_RECEIVED, DEFAULT_EVENT_TIMEOUT): return False time.sleep(DEFAULT_WAIT_TIME) self.TG.log.info("Phone Media Sessions:") if not car_media_utils.isMediaSessionActive( self.log, self.TG, PHONE_MEDIA_BROWSER_SERVICE_NAME): self.TG.log.error("Media not playing in connected Phone") return False self.CT.log.info("Car Media Sessions:") if not car_media_utils.isMediaSessionActive( self.log, self.CT, CAR_MEDIA_BROWSER_SERVICE_NAME): self.CT.log.error("Media not playing in connected Car") return False self.log.info("Bluetooth Disconnect the car and phone") result = bt_test_utils.disconnect_pri_from_sec( self.SRC, self.SNK, [BtEnum.BluetoothProfile.A2DP.value]) if not result: if bt_test_utils.is_a2dp_src_device_connected( self.SRC, self.SNK.droid.bluetoothGetLocalAddress()): self.SRC.log.error("Failed to disconnect on A2dp") return False self.TG.log.info("Phone Media Sessions:") if not car_media_utils.isMediaSessionActive( self.log, self.TG, PHONE_MEDIA_BROWSER_SERVICE_NAME): self.TG.log.error( "Media stopped playing in phone after BT disconnect") return False self.CT.log.info("Car Media Sessions:") if car_media_utils.isMediaSessionActive( self.log, self.CT, CAR_MEDIA_BROWSER_SERVICE_NAME): self.CT.log.error( "Media still playing in a Car after BT disconnect") return False return True