1#/usr/bin/env python3.4 2# 3# Copyright (C) 2016 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); you may not 6# use this file except in compliance with the License. You may obtain a copy of 7# the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14# License for the specific language governing permissions and limitations under 15# the License. 16""" 17Test script to exercise Ble Scan Api's. This exercises all getters and 18setters. This is important since there is a builder object that is immutable 19after you set all attributes of each object. If this test suite doesn't pass, 20then other test suites utilising Ble Scanner will also fail. 21""" 22 23from acts.controllers.android import SL4AAPIError 24from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest 25from acts.test_utils.bt.BleEnum import ScanSettingsCallbackType 26from acts.test_utils.bt.BleEnum import ScanSettingsScanMode 27from acts.test_utils.bt.BleEnum import ScanSettingsScanResultType 28from acts.test_utils.bt.BleEnum import ScanSettingsReportDelaySeconds 29from acts.test_utils.bt.BleEnum import Uuids 30 31 32class BleScanResultsError(Exception): 33 """Error in getting scan results""" 34 35 36class BleScanVerificationError(Exception): 37 """Error in comparing BleScan results""" 38 39 40class BleSetScanSettingsError(Exception): 41 """Error in setting Ble Scan Settings""" 42 43 44class BleSetScanFilterError(Exception): 45 """Error in setting Ble Scan Settings""" 46 47 48class BleScanApiTest(BluetoothBaseTest): 49 def __init__(self, controllers): 50 BluetoothBaseTest.__init__(self, controllers) 51 self.ad_dut = self.android_devices[0] 52 53 def _format_defaults(self, input): 54 """ 55 Creates a dictionary of default ScanSetting and ScanFilter Values. 56 :return: input: dict 57 """ 58 if 'ScanSettings' not in input.keys(): 59 input['ScanSettings'] = ( 60 ScanSettingsCallbackType.CALLBACK_TYPE_ALL_MATCHES.value, 0, 61 ScanSettingsScanMode.SCAN_MODE_LOW_POWER.value, 62 ScanSettingsScanResultType.SCAN_RESULT_TYPE_FULL.value) 63 if 'ScanFilterManufacturerDataId' not in input.keys(): 64 input['ScanFilterManufacturerDataId'] = -1 65 if 'ScanFilterDeviceName' not in input.keys(): 66 input['ScanFilterDeviceName'] = None 67 if 'ScanFilterDeviceAddress' not in input.keys(): 68 input['ScanFilterDeviceAddress'] = None 69 if 'ScanFilterManufacturerData' not in input.keys(): 70 input['ScanFilterManufacturerData'] = None 71 return input 72 73 def validate_scan_settings_helper(self, input, droid): 74 """ 75 Validates each input of the scan settings object that is matches what 76 was set or not set such that it matches the defaults. 77 :return: False at any point something doesn't match. True if everything 78 matches. 79 """ 80 filter_list = droid.bleGenFilterList() 81 if 'ScanSettings' in input.keys(): 82 try: 83 droid.bleSetScanSettingsCallbackType(input['ScanSettings'][0]) 84 droid.bleSetScanSettingsReportDelayMillis(input['ScanSettings'] 85 [1]) 86 droid.bleSetScanSettingsScanMode(input['ScanSettings'][2]) 87 droid.bleSetScanSettingsResultType(input['ScanSettings'][3]) 88 except SL4AAPIError as error: 89 self.log.debug("Set Scan Settings failed with: ".format(error)) 90 return False 91 if 'ScanFilterDeviceName' in input.keys(): 92 try: 93 droid.bleSetScanFilterDeviceName(input['ScanFilterDeviceName']) 94 except SL4AAPIError as error: 95 self.log.debug("Set Scan Filter Device Name failed with: {}" 96 .format(error)) 97 return False 98 if 'ScanFilterDeviceAddress' in input.keys(): 99 try: 100 droid.bleSetScanFilterDeviceAddress(input[ 101 'ScanFilterDeviceAddress']) 102 except SL4AAPIError as error: 103 self.log.debug("Set Scan Filter Device Address failed with: {}" 104 .format(error)) 105 return False 106 if ('ScanFilterManufacturerDataId' in input.keys() and 107 'ScanFilterManufacturerDataMask' in input.keys()): 108 try: 109 droid.bleSetScanFilterManufacturerData( 110 input['ScanFilterManufacturerDataId'], 111 input['ScanFilterManufacturerData'], 112 input['ScanFilterManufacturerDataMask']) 113 except SL4AAPIError as error: 114 self.log.debug("Set Scan Filter Manufacturer info with data " 115 "mask failed with: {}".format(error)) 116 return False 117 if ('ScanFilterManufacturerDataId' in input.keys() and 118 'ScanFilterManufacturerData' in input.keys() and 119 'ScanFilterManufacturerDataMask' not in input.keys()): 120 try: 121 droid.bleSetScanFilterManufacturerData( 122 input['ScanFilterManufacturerDataId'], 123 input['ScanFilterManufacturerData']) 124 except SL4AAPIError as error: 125 self.log.debug( 126 "Set Scan Filter Manufacturer info failed with: " 127 "{}".format(error)) 128 return False 129 if ('ScanFilterServiceUuid' in input.keys() and 130 'ScanFilterServiceMask' in input.keys()): 131 132 droid.bleSetScanFilterServiceUuid(input['ScanFilterServiceUuid'], 133 input['ScanFilterServiceMask']) 134 135 input = self._format_defaults(input) 136 scan_settings_index = droid.bleBuildScanSetting() 137 scan_settings = ( 138 droid.bleGetScanSettingsCallbackType(scan_settings_index), 139 droid.bleGetScanSettingsReportDelayMillis(scan_settings_index), 140 droid.bleGetScanSettingsScanMode(scan_settings_index), 141 droid.bleGetScanSettingsScanResultType(scan_settings_index)) 142 143 scan_filter_index = droid.bleBuildScanFilter(filter_list) 144 device_name_filter = droid.bleGetScanFilterDeviceName( 145 filter_list, scan_filter_index) 146 device_address_filter = droid.bleGetScanFilterDeviceAddress( 147 filter_list, scan_filter_index) 148 manufacturer_id = droid.bleGetScanFilterManufacturerId( 149 filter_list, scan_filter_index) 150 manufacturer_data = droid.bleGetScanFilterManufacturerData( 151 filter_list, scan_filter_index) 152 153 if scan_settings != input['ScanSettings']: 154 self.log.debug("Scan Settings did not match. expected: {}, found: " 155 "{}".format(input['ScanSettings'], scan_settings)) 156 return False 157 if device_name_filter != input['ScanFilterDeviceName']: 158 self.log.debug("Scan Filter device name did not match. expected: " 159 "{}, found {}".format(input['ScanFilterDeviceName'], 160 device_name_filter)) 161 return False 162 if device_address_filter != input['ScanFilterDeviceAddress']: 163 self.log.debug("Scan Filter address name did not match. expected: " 164 "{}, found: {}".format(input[ 165 'ScanFilterDeviceAddress'], 166 device_address_filter)) 167 return False 168 if manufacturer_id != input['ScanFilterManufacturerDataId']: 169 self.log.debug("Scan Filter manufacturer data id did not match. " 170 "expected: {}, found: {}".format(input[ 171 'ScanFilterManufacturerDataId'], 172 manufacturer_id)) 173 return False 174 if manufacturer_data != input['ScanFilterManufacturerData']: 175 self.log.debug("Scan Filter manufacturer data did not match. " 176 "expected: {}, found: {}".format(input[ 177 'ScanFilterManufacturerData'], 178 manufacturer_data)) 179 return False 180 if 'ScanFilterManufacturerDataMask' in input.keys(): 181 manufacturer_data_mask = droid.bleGetScanFilterManufacturerDataMask( 182 filter_list, scan_filter_index) 183 if manufacturer_data_mask != input[ 184 'ScanFilterManufacturerDataMask']: 185 self.log.debug( 186 "Manufacturer data mask did not match. expected:" 187 " {}, found: {}".format(input[ 188 'ScanFilterManufacturerDataMask'], 189 manufacturer_data_mask)) 190 191 return False 192 if ('ScanFilterServiceUuid' in input.keys() and 193 'ScanFilterServiceMask' in input.keys()): 194 195 expected_service_uuid = input['ScanFilterServiceUuid'] 196 expected_service_mask = input['ScanFilterServiceMask'] 197 service_uuid = droid.bleGetScanFilterServiceUuid(filter_list, 198 scan_filter_index) 199 service_mask = droid.bleGetScanFilterServiceUuidMask( 200 filter_list, scan_filter_index) 201 if service_uuid != expected_service_uuid.lower(): 202 self.log.debug("Service uuid did not match. expected: {}, " 203 "found {}".format(expected_service_uuid, 204 service_uuid)) 205 return False 206 if service_mask != expected_service_mask.lower(): 207 self.log.debug("Service mask did not match. expected: {}, " 208 "found {}".format(expected_service_mask, 209 service_mask)) 210 return False 211 self.scan_settings_index = scan_settings_index 212 self.filter_list = filter_list 213 self.scan_callback = droid.bleGenScanCallback() 214 return True 215 216 @BluetoothBaseTest.bt_test_wrap 217 def test_start_ble_scan_with_default_settings(self): 218 """Test LE scan with default settings. 219 220 Test to validate all default scan settings values. 221 222 Steps: 223 1. Create LE scan objects. 224 2. Start LE scan. 225 226 Expected Result: 227 Scan starts successfully and matches expected settings. 228 229 Returns: 230 Pass if True 231 Fail if False 232 233 TAGS: LE, Scanning 234 Priority: 1 235 """ 236 input = {} 237 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 238 239 @BluetoothBaseTest.bt_test_wrap 240 def test_stop_ble_scan_default_settings(self): 241 """Test stopping an LE scan. 242 243 Test default scan settings on an actual scan. Verify it can also stop 244 the scan. 245 246 Steps: 247 1. Validate default scan settings. 248 2. Start ble scan. 249 3. Stop ble scan. 250 251 Expected Result: 252 LE scan is stopped successfully. 253 254 Returns: 255 Pass if True 256 Fail if False 257 258 TAGS: LE, Scanning 259 Priority: 0 260 """ 261 input = {} 262 test_result = self.validate_scan_settings_helper(input, 263 self.ad_dut.droid) 264 if not test_result: 265 self.log.error("Could not setup ble scanner.") 266 return test_result 267 self.ad_dut.droid.bleStartBleScan( 268 self.filter_list, self.scan_settings_index, self.scan_callback) 269 try: 270 self.ad_dut.droid.bleStopBleScan(self.scan_callback) 271 except BleScanResultsError as error: 272 self.log.error(str(error)) 273 test_result = False 274 return test_result 275 276 @BluetoothBaseTest.bt_test_wrap 277 def test_scan_settings_callback_type_all_matches(self): 278 """Test LE scan settings callback type all matches. 279 280 Test scan settings callback type all matches. 281 282 Steps: 283 1. Validate the scan settings callback type with all other settings set 284 to their respective defaults. 285 286 Expected Result: 287 Expected Scan settings should match found scan settings. 288 289 Returns: 290 Pass if True 291 Fail if False 292 293 TAGS: LE, Scanning 294 Priority: 1 295 """ 296 input = {} 297 input["ScanSettings"] = ( 298 ScanSettingsCallbackType.CALLBACK_TYPE_ALL_MATCHES.value, 0, 299 ScanSettingsScanMode.SCAN_MODE_LOW_POWER.value, 300 ScanSettingsScanResultType.SCAN_RESULT_TYPE_FULL.value) 301 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 302 303 @BluetoothBaseTest.bt_test_wrap 304 def test_scan_settings_set_callback_type_first_match(self): 305 """Test LE scan settings callback type first match 306 307 Test scan settings callback type first match. 308 309 Steps: 310 1. Validate the scan settings callback type with all other settings set 311 to their respective defaults. 312 313 Expected Result: 314 Expected Scan settings should match found scan settings. 315 316 Returns: 317 Pass if True 318 Fail if False 319 320 TAGS: LE, Scanning 321 Priority: 1 322 """ 323 input = {} 324 input["ScanSettings"] = ( 325 ScanSettingsCallbackType.CALLBACK_TYPE_FIRST_MATCH.value, 0, 326 ScanSettingsScanMode.SCAN_MODE_LOW_POWER.value, 327 ScanSettingsScanResultType.SCAN_RESULT_TYPE_FULL.value) 328 test_result = self.validate_scan_settings_helper(input, 329 self.ad_dut.droid) 330 return test_result 331 332 @BluetoothBaseTest.bt_test_wrap 333 def test_scan_settings_set_callback_type_match_lost(self): 334 """Test LE scan settings callback type match lost. 335 336 Test scan settings callback type match lost. 337 338 Steps: 339 1. Validate the scan settings callback type with all other settings set 340 to their respective defaults. 341 342 Expected Result: 343 Expected Scan settings should match found scan settings. 344 345 Returns: 346 Pass if True 347 Fail if False 348 349 TAGS: LE, Scanning 350 Priority: 1 351 """ 352 input = {} 353 input["ScanSettings"] = ( 354 ScanSettingsCallbackType.CALLBACK_TYPE_MATCH_LOST.value, 0, 355 ScanSettingsScanMode.SCAN_MODE_LOW_POWER.value, 356 ScanSettingsScanResultType.SCAN_RESULT_TYPE_FULL.value) 357 test_result = self.validate_scan_settings_helper(input, 358 self.ad_dut.droid) 359 return test_result 360 361 @BluetoothBaseTest.bt_test_wrap 362 def test_scan_settings_set_invalid_callback_type(self): 363 """Test LE scan settings invalid callback type. 364 365 Test scan settings invalid callback type -1. 366 367 Steps: 368 1. Build a LE ScanSettings object with an invalid callback type. 369 370 Expected Result: 371 Api should fail to build object. 372 373 Returns: 374 Pass if True 375 Fail if False 376 377 TAGS: LE, Scanning 378 Priority: 2 379 """ 380 input = {} 381 input["ScanSettings"] = ( 382 -1, 0, ScanSettingsScanMode.SCAN_MODE_LOW_POWER.value, 383 ScanSettingsScanResultType.SCAN_RESULT_TYPE_FULL.value) 384 test_result = self.validate_scan_settings_helper(input, 385 self.ad_dut.droid) 386 return not test_result 387 388 @BluetoothBaseTest.bt_test_wrap 389 def test_scan_settings_set_scan_mode_low_power(self): 390 """Test LE scan settings scan mode low power mode. 391 392 Test scan settings scan mode low power. 393 394 Steps: 395 1. Validate the scan settings scan mode with all other settings set to 396 their respective defaults. 397 398 Expected Result: 399 Expected Scan settings should match found scan settings. 400 401 Returns: 402 Pass if True 403 Fail if False 404 405 TAGS: LE, Scanning 406 Priority: 1 407 """ 408 input = {} 409 input["ScanSettings"] = ( 410 ScanSettingsCallbackType.CALLBACK_TYPE_ALL_MATCHES.value, 0, 411 ScanSettingsScanMode.SCAN_MODE_LOW_POWER.value, 412 ScanSettingsScanResultType.SCAN_RESULT_TYPE_FULL.value) 413 test_result = self.validate_scan_settings_helper(input, 414 self.ad_dut.droid) 415 return test_result 416 417 @BluetoothBaseTest.bt_test_wrap 418 def test_scan_settings_set_scan_mode_balanced(self): 419 """Test LE scan settings scan mode balanced. 420 421 Test scan settings scan mode balanced. 422 423 Steps: 424 1. Validate the scan settings scan mode with all other settings set to 425 their respective defaults. 426 427 Expected Result: 428 Expected Scan settings should match found scan settings. 429 430 Returns: 431 Pass if True 432 Fail if False 433 434 TAGS: LE, Scanning 435 Priority: 1 436 """ 437 input = {} 438 input["ScanSettings"] = ( 439 ScanSettingsCallbackType.CALLBACK_TYPE_ALL_MATCHES.value, 0, 440 ScanSettingsScanMode.SCAN_MODE_BALANCED.value, 441 ScanSettingsScanResultType.SCAN_RESULT_TYPE_FULL.value) 442 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 443 444 @BluetoothBaseTest.bt_test_wrap 445 def test_scan_settings_set_scan_mode_low_latency(self): 446 """Test LE scan settings scan mode low latency. 447 448 Test scan settings scan mode low latency. 449 450 Steps: 451 1. Validate the scan settings scan mode with all other settings set to 452 their respective defaults. 453 454 Expected Result: 455 Expected Scan settings should match found scan settings. 456 457 Returns: 458 Pass if True 459 Fail if False 460 461 TAGS: LE, Scanning 462 Priority: 1 463 """ 464 input = {} 465 input["ScanSettings"] = ( 466 ScanSettingsCallbackType.CALLBACK_TYPE_ALL_MATCHES.value, 0, 467 ScanSettingsScanMode.SCAN_MODE_LOW_LATENCY.value, 468 ScanSettingsScanResultType.SCAN_RESULT_TYPE_FULL.value) 469 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 470 471 @BluetoothBaseTest.bt_test_wrap 472 def test_scan_settings_set_invalid_scan_mode(self): 473 """Test LE scan settings scan mode as an invalid value. 474 Test scan settings invalid scan mode -2. 475 Steps: 476 1. Set the scan settings scan mode to -2. 477 478 Expected Result: 479 Building the ScanSettings object should fail. 480 481 Returns: 482 Pass if True 483 Fail if False 484 485 TAGS: LE, Scanning 486 Priority: 1 487 """ 488 input = {} 489 input["ScanSettings"] = ( 490 ScanSettingsCallbackType.CALLBACK_TYPE_ALL_MATCHES.value, 0, -2, 491 ScanSettingsScanResultType.SCAN_RESULT_TYPE_FULL.value) 492 return not self.validate_scan_settings_helper(input, self.ad_dut.droid) 493 494 @BluetoothBaseTest.bt_test_wrap 495 def test_scan_settings_set_report_delay_millis_min(self): 496 """Test scan settings report delay millis as min value 497 498 Test scan settings report delay millis min acceptable value. 499 500 Steps: 501 1. Validate the scan settings report delay millis with all other 502 settings set to their respective defaults. 503 504 Expected Result: 505 Expected Scan settings should match found scan settings. 506 507 Returns: 508 Pass if True 509 Fail if False 510 511 TAGS: LE, Scanning 512 Priority: 2 513 """ 514 input = {} 515 input["ScanSettings"] = ( 516 ScanSettingsCallbackType.CALLBACK_TYPE_ALL_MATCHES.value, 517 ScanSettingsReportDelaySeconds.MIN.value, 518 ScanSettingsScanMode.SCAN_MODE_LOW_POWER.value, 519 ScanSettingsScanResultType.SCAN_RESULT_TYPE_FULL.value) 520 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 521 522 @BluetoothBaseTest.bt_test_wrap 523 def test_scan_settings_set_report_delay_millis_min_plus_one(self): 524 """Test scan settings report delay millis as min value plus one. 525 526 Test scan settings report delay millis as min value plus one. 527 528 Steps: 529 1. Validate the scan settings report delay millis with all other 530 settings set to their respective defaults. 531 532 Expected Result: 533 Expected Scan settings should match found scan settings. 534 535 Returns: 536 Pass if True 537 Fail if False 538 539 TAGS: LE, Scanning 540 Priority: 4 541 """ 542 input = {} 543 input["ScanSettings"] = ( 544 ScanSettingsCallbackType.CALLBACK_TYPE_ALL_MATCHES.value, 545 ScanSettingsReportDelaySeconds.MIN.value + 1, 546 ScanSettingsScanMode.SCAN_MODE_LOW_POWER.value, 547 ScanSettingsScanResultType.SCAN_RESULT_TYPE_FULL.value) 548 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 549 550 @BluetoothBaseTest.bt_test_wrap 551 def test_scan_settings_set_report_delay_millis_max(self): 552 """Test scan settings report delay millis as max value. 553 554 Test scan settings report delay millis max value. 555 556 Steps: 557 1. Validate the scan settings report delay millis with all other 558 settings set to their respective defaults. 559 560 Expected Result: 561 Expected Scan settings should match found scan settings. 562 563 Returns: 564 Pass if True 565 Fail if False 566 567 TAGS: LE, Scanning 568 Priority: 3 569 """ 570 input = {} 571 input["ScanSettings"] = ( 572 ScanSettingsCallbackType.CALLBACK_TYPE_ALL_MATCHES.value, 573 ScanSettingsReportDelaySeconds.MAX.value, 574 ScanSettingsScanMode.SCAN_MODE_LOW_POWER.value, 575 ScanSettingsScanResultType.SCAN_RESULT_TYPE_FULL.value) 576 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 577 578 @BluetoothBaseTest.bt_test_wrap 579 def test_scan_settings_set_report_delay_millis_max_minus_one(self): 580 """Test scan settings report delay millis as max value minus one. 581 582 Test scan settings report delay millis max value - 1. 583 584 Steps: 585 1. Validate the scan settings report delay millis with all other 586 settings set to their respective defaults. 587 588 Expected Result: 589 Expected Scan settings should match found scan settings. 590 591 Returns: 592 Pass if True 593 Fail if False 594 595 TAGS: LE, Scanning 596 Priority: 3 597 """ 598 input = {} 599 input["ScanSettings"] = ( 600 ScanSettingsCallbackType.CALLBACK_TYPE_ALL_MATCHES.value, 601 ScanSettingsReportDelaySeconds.MAX.value - 1, 602 ScanSettingsScanMode.SCAN_MODE_LOW_POWER.value, 603 ScanSettingsScanResultType.SCAN_RESULT_TYPE_FULL.value) 604 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 605 606 @BluetoothBaseTest.bt_test_wrap 607 def test_scan_settings_set_invalid_report_delay_millis_min_minus_one(self): 608 """Test scan settings report delay millis as an invalid value. 609 610 Test scan settings invalid report delay millis min value - 1. 611 612 Steps: 613 1. Set scan settings report delay millis to min value -1. 614 2. Build scan settings object. 615 616 Expected Result: 617 Building scan settings object should fail. 618 619 Returns: 620 Pass if True 621 Fail if False 622 623 TAGS: LE, Scanning 624 Priority: 2 625 """ 626 droid = self.ad_dut.droid 627 input = {} 628 input["ScanSettings"] = ( 629 ScanSettingsCallbackType.CALLBACK_TYPE_ALL_MATCHES.value, 630 ScanSettingsReportDelaySeconds.MIN.value - 1, 631 ScanSettingsScanMode.SCAN_MODE_LOW_POWER.value, 632 ScanSettingsScanResultType.SCAN_RESULT_TYPE_FULL.value) 633 return not self.validate_scan_settings_helper(input, droid) 634 635 @BluetoothBaseTest.bt_test_wrap 636 def test_scan_settings_set_scan_result_type_full(self): 637 """Test scan settings result type full. 638 639 Test scan settings result type full. 640 641 Steps: 642 1. Validate the scan settings result type with all other settings 643 set to their respective defaults. 644 645 Expected Result: 646 Expected Scan settings should match found scan settings. 647 648 Returns: 649 Pass if True 650 Fail if False 651 652 TAGS: LE, Scanning 653 Priority: 1 654 """ 655 input = {} 656 input["ScanSettings"] = ( 657 ScanSettingsCallbackType.CALLBACK_TYPE_ALL_MATCHES.value, 0, 658 ScanSettingsScanMode.SCAN_MODE_LOW_POWER.value, 659 ScanSettingsScanResultType.SCAN_RESULT_TYPE_FULL.value) 660 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 661 662 @BluetoothBaseTest.bt_test_wrap 663 def test_scan_settings_set_scan_result_type_abbreviated(self): 664 """Test scan settings result type abbreviated. 665 666 Test scan settings result type abbreviated. 667 668 Steps: 669 1. Validate the scan settings result type with all other settings 670 set to their respective defaults. 671 672 Expected Result: 673 Expected Scan settings should match found scan settings. 674 675 Returns: 676 Pass if True 677 Fail if False 678 679 TAGS: LE, Scanning 680 Priority: 1 681 """ 682 input = {} 683 input["ScanSettings"] = ( 684 ScanSettingsCallbackType.CALLBACK_TYPE_ALL_MATCHES.value, 0, 685 ScanSettingsScanMode.SCAN_MODE_LOW_POWER.value, 686 ScanSettingsScanResultType.SCAN_RESULT_TYPE_ABBREVIATED.value) 687 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 688 689 @BluetoothBaseTest.bt_test_wrap 690 def test_scan_settings_set_invalid_scan_result_type(self): 691 """Test scan settings result type as an invalid value. 692 693 Test scan settings invalid result type -1. 694 695 Steps: 696 1. Set scan settings result type as an invalid value. 697 2. Build scan settings object. 698 699 Expected Result: 700 Expected Scan settings should match found scan settings. 701 702 Returns: 703 Pass if True 704 Fail if False 705 706 TAGS: LE, Scanning 707 Priority: 2 708 """ 709 input = {} 710 input["ScanSettings"] = ( 711 ScanSettingsCallbackType.CALLBACK_TYPE_ALL_MATCHES.value, 0, 712 ScanSettingsScanMode.SCAN_MODE_LOW_POWER.value, -1) 713 return not self.validate_scan_settings_helper(input, self.ad_dut.droid) 714 715 @BluetoothBaseTest.bt_test_wrap 716 def test_scan_filter_set_device_name(self): 717 """Test scan filter set valid device name. 718 719 Test scan filter device name sl4atest. 720 721 Steps: 722 1. Validate the scan filter device name with all other settings 723 set to their respective defaults. 724 725 Expected Result: 726 Expected Scan filter should match found scan settings. 727 728 Returns: 729 Pass if True 730 Fail if False 731 732 TAGS: LE, Scanning 733 Priority: 1 734 """ 735 input = {} 736 input['ScanFilterDeviceName'] = "sl4atest" 737 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 738 739 @BluetoothBaseTest.bt_test_wrap 740 def test_scan_filter_set_device_name_blank(self): 741 """Test scan filter set blank device name. 742 743 Test scan filter device name blank. 744 745 Steps: 746 1. Validate the scan filter device name with all other settings 747 set to their respective defaults. 748 749 Expected Result: 750 Expected Scan filter should match found scan filter. 751 752 Returns: 753 Pass if True 754 Fail if False 755 756 TAGS: LE, Scanning 757 Priority: 1 758 """ 759 droid = self.ad_dut.droid 760 input = {} 761 input['ScanFilterDeviceName'] = "" 762 return self.validate_scan_settings_helper(input, droid) 763 764 @BluetoothBaseTest.bt_test_wrap 765 def test_scan_filter_set_device_name_special_chars(self): 766 """Test scan filter set device name as special chars. 767 768 Test scan filter device name special characters. 769 770 Steps: 771 1. Validate the scan filter device name with all other settings 772 set to their respective defaults. 773 774 Expected Result: 775 Expected Scan filter should match found scan filter. 776 777 Returns: 778 Pass if True 779 Fail if False 780 781 TAGS: LE, Scanning 782 Priority: 1 783 """ 784 input = {} 785 input['ScanFilterDeviceName'] = "!@#$%^&*()\":<>/" 786 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 787 788 @BluetoothBaseTest.bt_test_wrap 789 def test_scan_filter_set_device_address(self): 790 """Test scan filter set valid device address. 791 792 Test scan filter device address valid. 793 794 Steps: 795 1. Validate the scan filter device address with all other settings 796 set to their respective defaults. 797 798 Expected Result: 799 Expected Scan filter should match found scan filter. 800 801 Returns: 802 Pass if True 803 Fail if False 804 805 TAGS: LE, Scanning 806 Priority: 1 807 """ 808 input = {} 809 input['ScanFilterDeviceAddress'] = "01:02:03:AB:CD:EF" 810 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 811 812 @BluetoothBaseTest.bt_test_wrap 813 def test_scan_filter_set_invalid_device_address_lower_case(self): 814 """Test scan filter set invalid device address. 815 816 Test scan filter device address lower case. 817 818 Steps: 819 1. Set the scan filter address to an invalid, lowercase mac address 820 821 Expected Result: 822 Api to build scan filter should fail. 823 824 Returns: 825 Pass if True 826 Fail if False 827 828 TAGS: LE, Scanning 829 Priority: 2 830 """ 831 input = {} 832 input['ScanFilterDeviceAddress'] = "01:02:03:ab:cd:ef" 833 return not self.validate_scan_settings_helper(input, self.ad_dut.droid) 834 835 @BluetoothBaseTest.bt_test_wrap 836 def test_scan_filter_set_invalid_device_address_blank(self): 837 """Test scan filter set invalid device address. 838 839 Test scan filter invalid device address blank. 840 841 Steps: 842 1. Set the scan filter address to an invalid, blank mac address 843 844 Expected Result: 845 Api to build scan filter should fail. 846 847 Returns: 848 Pass if True 849 Fail if False 850 851 TAGS: LE, Scanning 852 Priority: 2 853 """ 854 input = {} 855 input['ScanFilterDeviceAddress'] = "" 856 test_result = self.validate_scan_settings_helper(input, 857 self.ad_dut.droid) 858 return not test_result 859 860 @BluetoothBaseTest.bt_test_wrap 861 def test_scan_filter_set_invalid_device_address_bad_format(self): 862 """Test scan filter set badly formatted device address. 863 864 Test scan filter badly formatted device address. 865 866 Steps: 867 1. Set the scan filter address to an invalid, blank mac address 868 869 Expected Result: 870 Api to build scan filter should fail. 871 872 Returns: 873 Pass if True 874 Fail if False 875 876 TAGS: LE, Scanning 877 Priority: 2 878 """ 879 input = {} 880 input['ScanFilterDeviceAddress'] = "10.10.10.10.10" 881 return not self.validate_scan_settings_helper(input, self.ad_dut.droid) 882 883 @BluetoothBaseTest.bt_test_wrap 884 def test_scan_filter_set_invalid_device_address_bad_address(self): 885 """Test scan filter device address as an invalid value. 886 887 Test scan filter invalid device address invalid characters. 888 889 Steps: 890 1. Set a scan filter's device address as ZZ:ZZ:ZZ:ZZ:ZZ:ZZ 891 892 Expected Result: 893 Api to build the scan filter should fail. 894 895 Returns: 896 Pass if True 897 Fail if False 898 899 TAGS: LE, Scanning 900 Priority: 1 901 """ 902 input = {} 903 input['ScanFilterDeviceAddress'] = "ZZ:ZZ:ZZ:ZZ:ZZ:ZZ" 904 return not self.validate_scan_settings_helper(input, self.ad_dut.droid) 905 906 @BluetoothBaseTest.bt_test_wrap 907 def test_scan_filter_set_manufacturer_id_data(self): 908 """Test scan filter manufacturer data. 909 910 Test scan filter manufacturer data with a valid input. 911 912 Steps: 913 1. Validate the scan filter manufacturer id with all other settings 914 set to their respective defaults. 915 916 Expected Result: 917 Expected Scan filter should match found scan filter. 918 919 Returns: 920 Pass if True 921 Fail if False 922 923 TAGS: LE, Scanning 924 Priority: 1 925 """ 926 expected_manufacturer_id = 0 927 expected_manufacturer_data = [1, 2, 1, 3, 4, 5, 6] 928 input = {} 929 input['ScanFilterManufacturerDataId'] = expected_manufacturer_id 930 input['ScanFilterManufacturerData'] = expected_manufacturer_data 931 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 932 933 @BluetoothBaseTest.bt_test_wrap 934 def test_scan_filter_set_manufacturer_id_data_mask(self): 935 """Test scan filter manufacturer data mask. 936 937 Test scan filter manufacturer data with a valid data mask. 938 939 Steps: 940 1. Validate the scan filter manufacturer id with all other settings 941 set to their respective defaults. 942 943 Expected Result: 944 Expected Scan filter should match found scan filter. 945 946 Returns: 947 Pass if True 948 Fail if False 949 950 TAGS: LE, Scanning 951 Priority: 1 952 """ 953 expected_manufacturer_id = 1 954 expected_manufacturer_data = [1] 955 expected_manufacturer_data_mask = [1, 2, 1, 3, 4, 5, 6] 956 input = {} 957 input['ScanFilterManufacturerDataId'] = expected_manufacturer_id 958 input['ScanFilterManufacturerData'] = expected_manufacturer_data 959 input[ 960 'ScanFilterManufacturerDataMask'] = expected_manufacturer_data_mask 961 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 962 963 @BluetoothBaseTest.bt_test_wrap 964 def test_scan_filter_set_manufacturer_max_id(self): 965 """Test scan filter manufacturer data id. 966 967 Test scan filter manufacturer data max id. 968 969 Steps: 970 1. Validate the scan filter manufacturer id with all other settings 971 set to their respective defaults. 972 973 Expected Result: 974 Expected Scan filter should match found scan filter. 975 976 Returns: 977 Pass if True 978 Fail if False 979 980 TAGS: LE, Scanning 981 Priority: 2 982 """ 983 expected_manufacturer_id = 2147483647 984 expected_manufacturer_data = [1, 2, 1, 3, 4, 5, 6] 985 input = {} 986 input['ScanFilterManufacturerDataId'] = expected_manufacturer_id 987 input['ScanFilterManufacturerData'] = expected_manufacturer_data 988 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 989 990 @BluetoothBaseTest.bt_test_wrap 991 def test_scan_filter_set_manufacturer_data_empty(self): 992 """Test scan filter empty manufacturer data. 993 994 Test scan filter manufacturer data as empty but valid manufacturer data. 995 996 Steps: 997 1. Validate the scan filter manufacturer id with all other settings 998 set to their respective defaults. 999 1000 Expected Result: 1001 Expected Scan filter should match found scan filter. 1002 1003 Returns: 1004 Pass if True 1005 Fail if False 1006 1007 TAGS: LE, Scanning 1008 Priority: 2 1009 """ 1010 expected_manufacturer_id = 1 1011 expected_manufacturer_data = [] 1012 input = {} 1013 input['ScanFilterManufacturerDataId'] = expected_manufacturer_id 1014 input['ScanFilterManufacturerData'] = expected_manufacturer_data 1015 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 1016 1017 @BluetoothBaseTest.bt_test_wrap 1018 def test_scan_filter_set_manufacturer_data_mask_empty(self): 1019 """Test scan filter empty manufacturer data mask. 1020 1021 Test scan filter manufacturer mask empty. 1022 1023 Steps: 1024 1. Validate the scan filter manufacturer id with all other settings 1025 set to their respective defaults. 1026 1027 Expected Result: 1028 Expected Scan filter should match found scan filter. 1029 1030 Returns: 1031 Pass if True 1032 Fail if False 1033 1034 TAGS: LE, Scanning 1035 Priority: 1 1036 """ 1037 expected_manufacturer_id = 1 1038 expected_manufacturer_data = [1, 2, 1, 3, 4, 5, 6] 1039 expected_manufacturer_data_mask = [] 1040 input = {} 1041 input['ScanFilterManufacturerDataId'] = expected_manufacturer_id 1042 input['ScanFilterManufacturerData'] = expected_manufacturer_data 1043 input[ 1044 'ScanFilterManufacturerDataMask'] = expected_manufacturer_data_mask 1045 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 1046 1047 @BluetoothBaseTest.bt_test_wrap 1048 def test_scan_filter_set_invalid_manufacturer_min_id_minus_one(self): 1049 """Test scan filter invalid manufacturer data. 1050 1051 Test scan filter invalid manufacturer id min value - 1. 1052 1053 Steps: 1054 1. Set the scan filters manufacturer id to -1. 1055 2. Build the scan filter. 1056 1057 Expected Result: 1058 Api to build the scan filter should fail. 1059 1060 Returns: 1061 Pass if True 1062 Fail if False 1063 1064 TAGS: LE, Scanning 1065 Priority: 2 1066 """ 1067 expected_manufacturer_id = -1 1068 expected_manufacturer_data = [1, 2, 1, 3, 4, 5, 6] 1069 input = {} 1070 input['ScanFilterManufacturerDataId'] = expected_manufacturer_id 1071 input['ScanFilterManufacturerData'] = expected_manufacturer_data 1072 return not self.validate_scan_settings_helper(input, self.ad_dut.droid) 1073 1074 @BluetoothBaseTest.bt_test_wrap 1075 def test_scan_filter_set_service_uuid(self): 1076 """Test scan filter set valid service uuid. 1077 1078 Test scan filter service uuid. 1079 1080 Steps: 1081 1. Validate the scan filter service uuid with all other settings 1082 set to their respective defaults. 1083 1084 Expected Result: 1085 Expected Scan filter should match found scan filter. 1086 1087 Returns: 1088 Pass if True 1089 Fail if False 1090 1091 TAGS: LE, Scanning 1092 Priority: 1 1093 """ 1094 expected_service_uuid = "00000000-0000-1000-8000-00805F9B34FB" 1095 expected_service_mask = "00000000-0000-1000-8000-00805F9B34FB" 1096 input = {} 1097 input['ScanFilterServiceUuid'] = expected_service_uuid 1098 input['ScanFilterServiceMask'] = expected_service_mask 1099 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 1100 1101 @BluetoothBaseTest.bt_test_wrap 1102 def test_scan_filter_service_uuid_p_service(self): 1103 """Test scan filter service uuid. 1104 1105 Test scan filter service uuid p service 1106 1107 Steps: 1108 1. Validate the scan filter service uuid with all other settings 1109 set to their respective defaults. 1110 1111 Expected Result: 1112 Expected Scan filter should match found scan filter. 1113 1114 Returns: 1115 Pass if True 1116 Fail if False 1117 1118 TAGS: LE, Scanning 1119 Priority: 2 1120 """ 1121 expected_service_uuid = Uuids.P_Service.value 1122 expected_service_mask = "00000000-0000-1000-8000-00805F9B34FB" 1123 self.log.debug("Step 1: Setup environment.") 1124 1125 input = {} 1126 input['ScanFilterServiceUuid'] = expected_service_uuid 1127 input['ScanFilterServiceMask'] = expected_service_mask 1128 return self.validate_scan_settings_helper(input, self.ad_dut.droid) 1129 1130 @BluetoothBaseTest.bt_test_wrap 1131 def test_classic_ble_scan_with_service_uuids_p(self): 1132 """Test classic LE scan with valid service uuid. 1133 1134 Test classic ble scan with scan filter service uuid p service uuids. 1135 1136 Steps: 1137 1. Validate the scan filter service uuid with all other settings 1138 set to their respective defaults. 1139 2. Start classic ble scan. 1140 3. Stop classic ble scan 1141 1142 Expected Result: 1143 Expected Scan filter should match found scan filter. 1144 1145 Returns: 1146 Pass if True 1147 Fail if False 1148 1149 TAGS: LE, Scanning 1150 Priority: 1 1151 """ 1152 1153 droid = self.ad_dut.droid 1154 service_uuid_list = [Uuids.P_Service.value] 1155 scan_callback = droid.bleGenLeScanCallback() 1156 return self.verify_classic_ble_scan_with_service_uuids( 1157 droid, scan_callback, service_uuid_list) 1158 1159 @BluetoothBaseTest.bt_test_wrap 1160 def test_classic_ble_scan_with_service_uuids_hr(self): 1161 """Test classic LE scan with valid service uuid. 1162 1163 Test classic ble scan with scan filter service uuid hr service 1164 1165 Steps: 1166 1. Validate the scan filter service uuid with all other settings 1167 set to their respective defaults. 1168 2. Start classic ble scan. 1169 3. Stop classic ble scan 1170 1171 Expected Result: 1172 Expected Scan filter should match found scan filter. 1173 1174 Returns: 1175 Pass if True 1176 Fail if False 1177 1178 TAGS: LE, Scanning 1179 Priority: 1 1180 """ 1181 droid = self.ad_dut.droid 1182 service_uuid_list = [Uuids.HR_SERVICE.value] 1183 scan_callback = droid.bleGenLeScanCallback() 1184 return self.verify_classic_ble_scan_with_service_uuids( 1185 droid, scan_callback, service_uuid_list) 1186 1187 @BluetoothBaseTest.bt_test_wrap 1188 def test_classic_ble_scan_with_service_uuids_empty_uuid_list(self): 1189 """Test classic LE scan with empty but valid uuid list. 1190 1191 Test classic ble scan with service uuids as empty list. 1192 1193 Steps: 1194 1. Validate the scan filter service uuid with all other settings 1195 set to their respective defaults. 1196 2. Start classic ble scan. 1197 3. Stop classic ble scan 1198 1199 Expected Result: 1200 Expected Scan filter should match found scan filter. 1201 1202 Returns: 1203 Pass if True 1204 Fail if False 1205 1206 TAGS: LE, Scanning 1207 Priority: 1 1208 """ 1209 droid = self.ad_dut.droid 1210 service_uuid_list = [] 1211 scan_callback = droid.bleGenLeScanCallback() 1212 return self.verify_classic_ble_scan_with_service_uuids( 1213 droid, scan_callback, service_uuid_list) 1214 1215 @BluetoothBaseTest.bt_test_wrap 1216 def test_classic_ble_scan_with_service_uuids_hr_and_p(self): 1217 """Test classic LE scan with multiple service uuids. 1218 1219 Test classic ble scan with service uuids a list of hr and p service. 1220 1221 Steps: 1222 1. Validate the scan filter service uuid with all other settings 1223 set to their respective defaults. 1224 2. Start classic ble scan. 1225 3. Stop classic ble scan 1226 1227 Expected Result: 1228 Expected Scan filter should match found scan filter. 1229 1230 Returns: 1231 Pass if True 1232 Fail if False 1233 1234 TAGS: LE, Scanning 1235 Priority: 1 1236 """ 1237 droid = self.ad_dut.droid 1238 service_uuid_list = [Uuids.HR_SERVICE.value, Uuids.P_Service.value] 1239 scan_callback = droid.bleGenLeScanCallback() 1240 return self.verify_classic_ble_scan_with_service_uuids( 1241 droid, scan_callback, service_uuid_list) 1242 1243 def verify_classic_ble_scan_with_service_uuids(self, droid, scan_callback, 1244 service_uuid_list): 1245 1246 test_result = True 1247 try: 1248 test_result = droid.bleStartClassicBleScanWithServiceUuids( 1249 scan_callback, service_uuid_list) 1250 except BleScanResultsError as error: 1251 self.log.error(str(error)) 1252 return False 1253 droid.bleStopClassicBleScan(scan_callback) 1254 if not test_result: 1255 self.log.error( 1256 "Start classic ble scan with service uuids return false " 1257 "boolean value.") 1258 return False 1259 return True 1260