Esempio n. 1
0
 def test_disconnect_failure_send_message(self):
     addr = self.MSE.droid.bluetoothGetLocalAddress()
     if bt_test_utils.is_map_mce_device_connected(self.MCE, addr):
         connected = True
     disconnected = bt_test_utils.disconnect_pri_from_sec(
         self.MCE, self.MSE, [BtEnum.BluetoothProfile.MAP_MCE.value])
     # Grace time for the disconnection to complete.
     time.sleep(3)
     if not bt_test_utils.is_map_mce_device_connected(self.MCE, addr):
         disconnected = True
     self.MCE.log.info("Connected = {}, Disconnected = {}".format(
         connected, disconnected))
     return connected and disconnected and not self.send_message(
         [self.REMOTE])
    def test_a2dp_connect_disconnect_from_snk(self):
        """
        Test Connect/Disconnect on A2DP Sink profile.

        Pre-Condition:
        1. Devices previously bonded and NOT connected on A2dp

        Steps:
        1. Initiate a connection on A2DP Sink profile from SNK
        2. Check if they connected.
        3. Initiate a disconnect on A2DP Sink profile from SNK
        4. Ensure they disconnected on A2dp alone

        Returns:
        True    if we connected/disconnected successfully
        False   if we did not connect/disconnect successfully

        Priority: 0
        """
        # Connect
        if is_a2dp_connected(self.SNK, self.SRC):
            self.log.info("Already Connected")
        else:
            if (not bt_test_utils.connect_pri_to_sec(
                    self.SNK, self.SRC,
                    set([BtEnum.BluetoothProfile.A2DP_SINK.value]))):
                return False
        # Delay to establish A2DP connection before disconnecting
        time.sleep(5)
        # Disconnect
        result = bt_test_utils.disconnect_pri_from_sec(
            self.SNK, self.SRC, [BtEnum.BluetoothProfile.A2DP_SINK.value])
        # Grace timeout to allow a2dp time to disconnect
        time.sleep(2)
        if not result:
            # Additional profile connection check for b/
            if bt_test_utils.is_a2dp_snk_device_connected(
                    self.SNK, self.SRC.droid.bluetoothGetLocalAddress()):
                self.SNK.log.error("Failed to disconnect on A2dp Sink")
                return False
        # Logging if we connected right back, since that happens sometimes
        # Not failing the test if it did though
        if is_a2dp_connected(self.SNK, self.SRC):
            self.SNK.log.error("Still connected after a disconnect")
        return True
Esempio n. 3
0
 def test_send_message_failure_no_map_connection(self):
     if not bt_test_utils.disconnect_pri_from_sec(
             self.MCE, self.MSE, [BtEnum.BluetoothProfile.MAP_MCE.value]):
         return False
     return not self.send_message([self.REMOTE])
    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
    def test_connect_disconnect_paired(self):
        """
        Tests if we can connect two devices over Headset, A2dp and then disconnect them with success

        Precondition:
        1. Devices are paired.

        Steps:
        1. Initiate connection over A2dp Sink and Headset client profiles.
        2. Check if the connection succeeded.

        Returns:
          Pass if True
          Fail if False

        Priority: 0
        """

        NUM_TEST_RUNS = 2
        failure = 0
        addr = self.ph.droid.bluetoothGetLocalAddress()
        for i in range(NUM_TEST_RUNS):
            self.log.info("Running test [" + str(i) + "/" + str(NUM_TEST_RUNS)
                          + "]")
            success = bt_test_utils.connect_pri_to_sec(self.car, self.ph, set(
                [BtEnum.BluetoothProfile.HEADSET_CLIENT.value,
                 BtEnum.BluetoothProfile.A2DP_SINK.value]))

            # Check if we got connected.
            if not success:
                self.car.log.info("Not all profiles connected.")
                if (bt_test_utils.is_hfp_client_device_connected(self.car,
                                                                 addr) and
                        bt_test_utils.is_a2dp_snk_device_connected(self.car,
                                                                   addr)):
                    self.car.log.info(
                        "HFP Client or A2DP SRC connected successfully.")
                else:
                    failure = failure + 1
                continue

            # Disconnect the devices.
            success = bt_test_utils.disconnect_pri_from_sec(
                self.car, self.ph,
                [BtEnum.BluetoothProfile.HEADSET_CLIENT.value,
                 BtEnum.BluetoothProfile.A2DP_SINK.value])

            if success is False:
                self.car.log.info("Disconnect failed.")
                if (bt_test_utils.is_hfp_client_device_connected(self.car,
                                                                 addr) or
                        bt_test_utils.is_a2dp_snk_device_connected(self.car,
                                                                   addr)):
                    self.car.log.info(
                        "HFP Client or A2DP SRC failed to disconnect.")
                    failure = failure + 1
                continue

        self.log.info("Failure {} total tests {}".format(failure,
                                                         NUM_TEST_RUNS))
        if failure > 0:
            return False
        return True