def setup_class(self):
        self.droid_ad = self.android_devices[0]
        for ad in self.android_devices:
            bt_test_utils.clear_bonded_devices(ad)

        self.userid_1 = users.create_new_user(self.droid_ad, "testUser")
        self.userid_2 = users.create_new_user(self.droid_ad, "testUser2")
コード例 #2
0
    def test_le_pairing(self):
        """Test LE pairing transport stress

        This will test LE pairing between two android devices.

        Steps:
        1. Start an LE advertisement on secondary device.
        2. Find address from primary device.
        3. Discover and bond to LE address.
        4. Stop LE advertisement on secondary device.
        5. Repeat steps 1-4 100 times

        Expected Result:
        LE pairing should pass 100 times.

        Returns:
          Pass if True
          Fail if False

        TAGS: LE, Scanning, Stress, Pairing
        Priority: 1
        """
        iterations = 100
        for i in range(iterations):
            try:
                target_address, adv_callback, scan_callback = get_mac_address_of_generic_advertisement(
                    self.scn_ad, self.adv_ad)
            except BtTestUtilsError as err:
                self.log.error(err)
                return False
            self.log.info("Begin interation {}/{}".format(i + 1, iterations))
            self.scn_ad.droid.bluetoothStartPairingHelper()
            self.adv_ad.droid.bluetoothStartPairingHelper()
            start_time = self.start_timer()
            self.scn_ad.droid.bluetoothDiscoverAndBond(target_address)
            if not self._verify_successful_bond(target_address):
                self.log.error("Failed to bond devices.")
                return False
            self.log.info("Total time (ms): {}".format(self.end_timer()))
            if not clear_bonded_devices(self.scn_ad):
                self.log.error("Failed to unbond device from scanner.")
                return False
            if not clear_bonded_devices(self.adv_ad):
                self.log.error("Failed to unbond device from advertiser.")
                return False
            self.adv_ad.droid.bleStopBleAdvertising(adv_callback)
            self.scn_ad.droid.bleStopBleScan(scan_callback)
            # Magic sleep to let unbonding finish
            time.sleep(2)
        return True
コード例 #3
0
 def setup_test(self):
     for a in self.android_devices:
         if not clear_bonded_devices(a):
             return False
     for a in self.android_devices:
         a.ed.clear_all_events()
     return True
    def setup_class(self):
        self.ad.droid.bluetoothFactoryReset()
        # Factory reset requires a short delay to take effect
        time.sleep(3)

        self.ad.log.info("Making sure BT phone is enabled here during setup")
        if not bluetooth_enabled_check(self.ad):
            self.log.error("Failed to turn Bluetooth on DUT")
        # Give a breathing time of short delay to take effect
        time.sleep(3)

        reset_bluetooth([self.ad])

        # Determine if we have a relay-based device
        if hasattr(self, 'relay_devices'):
            for headphone in self.relay_devices:
                headphone.setup()
        '''
        # Turn of the Power Supply for the headphones.
        if hasattr(self, 'relay_devices'):
            power_supply = self.relay_devices[0]
            power_supply.power_off()
        '''
        super(HeadphoneTest, self).setup_class()
        return clear_bonded_devices(self.ad)
コード例 #5
0
 def setup_test(self):
     for a in self.android_devices:
         if not clear_bonded_devices(a):
             return False
     self.log.debug(log_energy_info(self.android_devices, "Start"))
     for a in self.android_devices:
         a.ed.clear_all_events()
     return True
 def setup_test(self):
     # Reset bluetooth
     reset_bluetooth(self.android_devices)
     for ad in self.android_devices:
         if not clear_bonded_devices(ad):
             logging.error("Failed to unbound device")
             return False
         # Sync device time for timestamp comparison
         sync_device_time(ad)
     return super(BtMetricsTest, self).setup_test()
    def teardown_class(self):
        if self.headphone_list is not None:
            for headphone in self.headphone_list:
                headphone.power_off()
                headphone.clean_up()
        '''
        power_supply = self.relay_devices[0]
        power_supply.power_off()
        '''

        return clear_bonded_devices(self.ad)
    def test_pair_unpair_stress(self):
        """ Stress Test for Pairing and Unpairing of Bluetooth Headphones.

             Steps:
              1. Pairing and Connect Bluetooth headset.
              2. Disconnect Bleutooth Headset.
              3. Repeat step 1-2 for 10 iterations.

              Expected Result: Bluetooth pairing and unpairing should succeed.

              Returns:
                 Pass if True
                 Fail if False

              TAGS: Classic, Stress
              Priority: 1
        """
        for n in range(self.iterations):
            self.log.info("Pair headphone iteration %s.", (n + 1))

            for headphone in self.headphone_list:
                if self._discover_and_pair(headphone) is False:
                    # The device is probably not in pairing mode, put in pairing mode.
                    headphone.turn_power_on_and_enter_pairing_mode()
                    time.sleep(6)
                    if self._discover_and_pair(headphone) is False:
                        # Device must be on, but not in pairing  mode.
                        headphone.power_off()
                        headphone.turn_power_on_and_enter_pairing_mode()
                        time.sleep(6)
                        msg = "Unable to pair to %s", headphone.name
                        assert_true(self._discover_and_pair(headphone), msg)

                if len(self.ad.droid.bluetoothGetConnectedDevices()) == 0:
                    self.log.error("Not connected to relay based device.")
                    return False
                clear_bonded_devices(self.ad)
コード例 #9
0
    def test_pair_bluetooth_stress(self):
        """Stress test for pairing BT devices.

        Test the integrity of Bluetooth pairing.

        1. Primary device discover the secondary device
        2. Primary device tries to pair to secondary device
        3. Pair two devices after verifying pin number on both devices are equal
        4. Verify both devices are paired
        5. Unpair devices.
        6. Verify devices unpaired.
        7. Repeat steps 1-6 100 times.


        Expected Result:
        Each iteration of toggling Bluetooth pairing and unpairing
        should succeed.

        Returns:
          Pass if True
          Fail if False

        TAGS: Classic, Stress
        Priority: 1
        """
        for n in range(self.iterations):
            self.log.info("Pair bluetooth iteration {}.".format(n + 1))
            self.start_timer()
            if (not pair_pri_to_sec(self.android_devices[0],
                                    self.android_devices[1],
                                    attempts=1,
                                    auto_confirm=False)):
                self.log.error("Failed to bond devices.")
                return False
            self.log.info("Total time (ms): {}".format(self.end_timer()))
            # A device bond will trigger a number of system routines that need
            # to settle before unbond
            time.sleep(2)
            for ad in self.android_devices:
                if not clear_bonded_devices(ad):
                    return False
                # Necessary sleep time for entries to update unbonded state
                time.sleep(2)
                bonded_devices = ad.droid.bluetoothGetBondedDevices()
                if len(bonded_devices) > 0:
                    self.log.error(
                        "Failed to unbond devices: {}".format(bonded_devices))
                    return False
        return True
    def test_pair_and_unpair_bt_device(self):
        """ Test Pairing and Unpairing Bluetooth Headphones to the Android device.

             Steps:
              1. Pair and Connect Bluetooth headset.
              2. Disconnect Bleutooth Headset.

              Expected Result: Bluetooth pairing and unpairing should succeed.

              Returns:
                 Pass if True
                 Fail if False

              TAGS: Classic.
              Priority: 0
        """
        for headphone in self.headphone_list:
            self.log.info("Start testing on  " + headphone.name)

            if self._discover_and_pair(headphone) is False:
                # The device is probably not in pairing mode, put in pairing mode.

                headphone.turn_power_on_and_enter_pairing_mode()
                time.sleep(6)
                if self._discover_and_pair(headphone) is False:
                    # Device must be on, but not in pairing  mode.
                    headphone.power_off()
                    headphone.turn_power_on_and_enter_pairing_mode()
                    time.sleep(6)
                    msg = "Unable to pair to %s", headphone.name
                    assert_true(self._discover_and_pair(headphone), msg)

            if len(self.ad.droid.bluetoothGetConnectedDevices()) == 0:
                self.log.error("Not connected to relay based device.")
                return False
            clear_bonded_devices(self.ad)
コード例 #11
0
    def test_pair_bluetooth_stress(self):
        """Stress test for pairing BT devices.

        Test the integrity of Bluetooth pairing.

        Steps:
        1. Pair two Android devices
        2. Verify both devices are paired
        3. Unpair devices.
        4. Verify devices unpaired.
        5. Repeat steps 1-4 100 times.

        Expected Result:
        Each iteration of toggling Bluetooth pairing and unpairing
        should succeed.

        Returns:
          Pass if True
          Fail if False

        TAGS: Classic, Stress
        Priority: 1
        """
        for n in range(self.iterations):
            self.log.info("Pair bluetooth iteration {}.".format(n + 1))
            self.start_timer()
            if (not pair_pri_to_sec(self.android_devices[0].droid,
                                self.android_devices[1].droid)):
                self.log.error("Failed to bond devices.")
                return False
            self.log.info("Total time (ms): {}".format(self.end_timer()))
            for ad in self.android_devices:
                if not clear_bonded_devices(ad):
                    return False
                # Necessary sleep time for entries to update unbonded state
                time.sleep(1)
                bonded_devices = ad.droid.bluetoothGetBondedDevices()
                if len(bonded_devices) > 0:
                    self.log.error("Failed to unbond devices: {}".format(
                        bonded_devices))
                    return False
        return True
    def setup_test(self):
        for a in self.android_devices:
            if not clear_bonded_devices(a):
                return False
        for a in self.android_devices:
            a.ed.clear_all_events()

        i = 0
        while not self.device_ad.droid.bluetoothHidDeviceIsReady():
            time.sleep(1)
            i += 1
            self.log.info("BluetoothHidDevice NOT Ready")
            if i == 10:
                return False

        if not self.device_ad.droid.bluetoothHidDeviceRegisterApp():
            self.log.error("Device: registration failed")
            return False

        self.log.info("Device: registration done")
        return True
 def teardown_test(self):
     super(BluetoothBaseTest, self).teardown_test()
     self.dongle.clean_up()
     clear_bonded_devices(self.dut)
     return True
コード例 #14
0
 def teardown_test(self):
     clear_bonded_devices(self.pri_ad)
     CoexBaseTest.teardown_test(self)
     self.audio_receiver.clean_up()
    def test_pairing_metric(self):
        """Test if a pairing event generates the correct metric entry

        This test tries to pair two Bluetooth devices and dumps metrics after
        pairing. A correctly implemented stack should record 8 pairing events.

        Steps:
        1. Start pairing between two Bluetooth devices
        2. After pairing is done, dump and parse the metrics
        3. Compare the number of pairing events and the time stamp of the
        pairing event

        Expected Result:
        No errors, 8 pairing events should be generated
        Returns:
          Pass if True
          Fail if False

        TAGS: Classic
        Priority: 1
        """
        time_bonds = []
        for n in range(self.iterations):
            start_time = get_current_epoch_time()
            self.log.info("Pair bluetooth iteration {}.".format(n + 1))
            if (not pair_pri_to_sec(self.android_devices[0],
                                    self.android_devices[1],
                                    attempts=1,
                                    auto_confirm=False)):
                self.log.error("Failed to bond devices.")
                return False
            end_time = get_current_epoch_time()
            time_bonds.append((start_time, end_time))
            # A device bond will trigger a number of system routines that need
            # to settle before unbond
            time.sleep(2)
            for ad in self.android_devices:
                if not clear_bonded_devices(ad):
                    return False
                # Necessary sleep time for entries to update unbonded state
                time.sleep(2)
                bonded_devices = ad.droid.bluetoothGetBondedDevices()
                if len(bonded_devices) > 0:
                    self.log.error(
                        "Failed to unbond devices: {}".format(bonded_devices))
                    return False
        end_time = get_current_epoch_time()
        bluetooth_logs, bluetooth_logs_ascii = \
            self.collect_bluetooth_manager_metrics_logs(
                [self.android_devices[0]])
        bluetooth_log = bluetooth_logs[0]
        bluetooth_log_ascii = bluetooth_logs_ascii[0]
        asserts.assert_equal(len(bluetooth_log.pair_event),
                             8,
                             extras=bluetooth_log_ascii)
        for pair_event in bluetooth_log.pair_event:
            t = pair_event.event_time_millis
            asserts.assert_true(
                start_time <= t <= end_time,
                "Event time %d not within limit [%d, %d]" %
                (t, start_time, end_time))
            device_info = pair_event.device_paired_with
            asserts.assert_true(device_info, "Device info is none")
            asserts.assert_equal(
                device_info.device_type, self.android_devices[0].
                bluetooth_proto_module.DeviceInfo.DEVICE_TYPE_BREDR,
                "Device type does not match")
 def teardown_test(self):
     clear_bonded_devices(self.pri_ad)
     super().teardown_test()
     self.audio_receiver.clean_up()
コード例 #17
0
 def teardown_test(self):
     clear_bonded_devices(self.pri_ad)
     super().teardown_test()
コード例 #18
0
    def test_repairing(self):
        """
        Tests that even if we modify the priorities, on unpair and pair
        we will reset the priorities.

        Steps:
        1. Pair the devices (do not connect)
        2. Unset the priorities for HFP and A2DP
        3. Pair again
        4. Check the priorities, they should be set to default.

        Returns:
          Pass if True
          Fail if False

        Priority: 0
        """
        # Pair the devices.
        self.log.info("Pairing the devices ...")
        if not bt_test_utils.pair_pri_to_sec(
                self.car, self.ph, attempts=1, auto_confirm=False):
            self.log.error("Failed to pair devices.")
            return False

        # Timed wait for the profile priorities to propagate.
        time.sleep(BOND_TO_SDP_WAIT)

        # Set the priority to OFF for ALL car profiles.
        self.car.log.info("Set priorities off ...")
        car_bt_utils.set_car_profile_priorities_off(self.car, self.ph)

        # Now unpair the devices.
        self.log.info("Resetting the devices ...")
        for ad in self.android_devices:
            bt_test_utils.clear_bonded_devices(ad)
        # Give the stack time to unbond.
        time.sleep(UNBOND_TIMEOUT)

        # Pair them again!
        self.log.info("Pairing them again ...")
        if not bt_test_utils.pair_pri_to_sec(
                self.car, self.ph, attempts=1, auto_confirm=False):
            self.log.error("Faild to pair devices.")
            return False

        # Timed wait for the profile priorities to propagate.
        time.sleep(BOND_TO_SDP_WAIT)

        # Check the default priorities.
        ph_hfp_p = self.car.droid.bluetoothHfpClientGetPriority(
            self.ph.droid.bluetoothGetLocalAddress())
        if ph_hfp_p != BtEnum.BluetoothPriorityLevel.PRIORITY_ON.value:
            self.hf.log.error("HFP priority found: {}, expected: {}.".format(
                ph_hfp_p, BtEnum.BluetoothPriorityLevel.PRIORITY_ON.value))
            return False

        ph_a2dp_p = self.car.droid.bluetoothA2dpSinkGetPriority(
            self.ph.droid.bluetoothGetLocalAddress())
        if ph_a2dp_p != BtEnum.BluetoothPriorityLevel.PRIORITY_ON.value:
            self.ph.log.error("A2DP priority found: {}, expected {}.".format(
                ph_a2dp_p, BtEnum.BluetoothPriorityLevel.PRIORITY_ON.value))
            return False

        return True
コード例 #19
0
 def teardown_test(self):
     for ad in self.android_devices:
         bt_test_utils.clear_bonded_devices(ad)
     # Give the stack time to unbond.
     time.sleep(UNBOND_TIMEOUT)
コード例 #20
0
 def setup_class(self):
     self.droid_ad = self.android_devices[0]
     for ad in self.android_devices:
         bt_test_utils.clear_bonded_devices(ad)
コード例 #21
0
    def test_gatt_connect_mitm_attack(self):
        """Test GATT connection with permission write encrypted mitm.

        Test establishing a gatt connection between a GATT server and GATT
        client while the GATT server's characteristic includes the property
        write value and the permission write encrypted mitm value. This will
        prompt LE pairing and then the devices will create a bond.

        Steps:
        1. Create a GATT server and server callback on the peripheral device.
        2. Create a unique service and characteristic uuid on the peripheral.
        3. Create a characteristic on the peripheral with these properties:
            gatt_characteristic['property_write'],
            gatt_characteristic['permission_write_encrypted_mitm']
        4. Create a GATT service on the peripheral.
        5. Add the characteristic to the GATT service.
        6. Create a GATT connection between your central and peripheral device.
        7. From the central device, discover the peripheral's services.
        8. Iterate the services found until you find the unique characteristic
            created in step 3.
        9. Once found, write a random but valid value to the characteristic.
        10. Start pairing helpers on both devices immediately after attempting
            to write to the characteristic.
        11. Within 10 seconds of writing the characteristic, there should be
            a prompt to bond the device from the peripheral. The helpers will
            handle the UI interaction automatically. (see
            BluetoothConnectionFacade.java bluetoothStartPairingHelper).
        12. Verify that the two devices are bonded.

        Expected Result:
        Verify that a connection was established and the devices are bonded.

        Returns:
          Pass if True
          Fail if False

        TAGS: LE, Advertising, Filtering, Scanning, GATT, Characteristic, MITM
        Priority: 1
        """
        gatt_server_cb = self.per_ad.droid.gattServerCreateGattServerCallback()
        gatt_server = self.per_ad.droid.gattServerOpenGattServer(
            gatt_server_cb)
        self.gatt_server_list.append(gatt_server)
        service_uuid = "3846D7A0-69C8-11E4-BA00-0002A5D5C51B"
        test_uuid = "aa7edd5a-4d1d-4f0e-883a-d145616a1630"
        bonded = False
        characteristic = self.per_ad.droid.gattServerCreateBluetoothGattCharacteristic(
            test_uuid, gatt_characteristic['property_write'],
            gatt_characteristic['permission_write_encrypted_mitm'])
        gatt_service = self.per_ad.droid.gattServerCreateService(
            service_uuid, gatt_service_types['primary'])
        self.per_ad.droid.gattServerAddCharacteristicToService(gatt_service,
                                                               characteristic)
        self.per_ad.droid.gattServerAddService(gatt_server, gatt_service)
        result = self._find_service_added_event(gatt_server_cb, service_uuid)
        if not result:
            return False
        bluetooth_gatt, gatt_callback, adv_callback = (
            orchestrate_gatt_connection(self.cen_ad, self.per_ad))
        self.bluetooth_gatt_list.append(bluetooth_gatt)
        self.adv_instances.append(adv_callback)
        if self.cen_ad.droid.gattClientDiscoverServices(bluetooth_gatt):
            expected_event = gatt_cb_strings['gatt_serv_disc'].format(
                gatt_callback)
            try:
                event = self.cen_ad.ed.pop_event(expected_event,
                                                 self.default_timeout)
            except Empty:
                self.log.error(gatt_cb_err['gatt_serv_disc'].format(
                    expected_event))
                return False
            discovered_services_index = event['data']['ServicesIndex']
        else:
            self.log.info("Failed to discover services.")
            return False
        test_value = [1, 2, 3, 4, 5, 6, 7]
        services_count = self.cen_ad.droid.gattClientGetDiscoveredServicesCount(
            discovered_services_index)
        for i in range(services_count):
            characteristic_uuids = (
                self.cen_ad.droid.gattClientGetDiscoveredCharacteristicUuids(
                    discovered_services_index, i))
            for characteristic_uuid in characteristic_uuids:
                if characteristic_uuid == test_uuid:
                    self.cen_ad.droid.bluetoothStartPairingHelper()
                    self.per_ad.droid.bluetoothStartPairingHelper()
                    self.cen_ad.droid.gattClientCharacteristicSetValue(
                        bluetooth_gatt, discovered_services_index, i,
                        characteristic_uuid, test_value)
                    self.cen_ad.droid.gattClientWriteCharacteristic(
                        bluetooth_gatt, discovered_services_index, i,
                        characteristic_uuid)
                    start_time = time.time() + self.default_timeout
                    target_name = self.per_ad.droid.bluetoothGetLocalName()
                    while time.time() < start_time and bonded == False:
                        bonded_devices = \
                            self.cen_ad.droid.bluetoothGetBondedDevices()
                        for device in bonded_devices:
                            if ('name' in device.keys() and
                                    device['name'] == target_name):
                                bonded = True
                                break
                    bonded = False
                    target_name = self.cen_ad.droid.bluetoothGetLocalName()
                    while time.time() < start_time and bonded == False:
                        bonded_devices = \
                            self.per_ad.droid.bluetoothGetBondedDevices()
                        for device in bonded_devices:
                            if ('name' in device.keys() and
                                    device['name'] == target_name):
                                bonded = True
                                break
        for ad in [self.cen_ad, self.per_ad]:
            if not clear_bonded_devices(ad):
                return False
            # Necessary sleep time for entries to update unbonded state
            time.sleep(2)
            bonded_devices = ad.droid.bluetoothGetBondedDevices()
            if len(bonded_devices) > 0:
                self.log.error("Failed to unbond devices: {}".format(
                    bonded_devices))
                return False
        return self._orchestrate_gatt_disconnection(bluetooth_gatt,
                                                    gatt_callback)