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 """ 17 This test script exercises different opportunistic scan scenarios. 18 It is expected that the second AndroidDevice is able to advertise. 19 20 This test script was designed with this setup in mind: 21 Shield box one: Android Device, Android Device 22 """ 23 24 from queue import Empty 25 26 from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest 27 from acts.test_utils.bt.BleEnum import ScanSettingsScanMode 28 from acts.test_utils.bt.BleEnum import ScanSettingsScanMode 29 from acts.test_utils.bt.bt_test_utils import batch_scan_result 30 from acts.test_utils.bt.bt_test_utils import cleanup_scanners_and_advertisers 31 from acts.test_utils.bt.bt_test_utils import generate_ble_advertise_objects 32 from acts.test_utils.bt.bt_test_utils import generate_ble_scan_objects 33 from acts.test_utils.bt.bt_test_utils import reset_bluetooth 34 from acts.test_utils.bt.bt_test_utils import scan_result 35 36 37 class BleOpportunisticScanTest(BluetoothBaseTest): 38 default_timeout = 10 39 max_scan_instances = 28 40 report_delay = 2000 41 scan_callbacks = [] 42 adv_callbacks = [] 43 active_scan_callback_list = [] 44 active_adv_callback_list = [] 45 46 def __init__(self, controllers): 47 BluetoothBaseTest.__init__(self, controllers) 48 self.scn_ad = self.android_devices[0] 49 self.adv_ad = self.android_devices[1] 50 self.tests = ( 51 "test_scan_result_no_advertisement", 52 "test_scan_result_no_advertisement", 53 "test_scan_result", 54 "test_batch_scan_result_not_expected", 55 "test_scan_result_not_expected", 56 "test_max_opportunistic_scan_instances", 57 "test_discover_opportunistic_scan_result_off_secondary_scan_filter", 58 "test_negative_opportunistic_scan_filter_result_off_secondary_scan_result", 59 "test_opportunistic_scan_filter_result_off_secondary_scan_result", 60 "test_batch_scan_result", 61 "test_max_opportunistic_batch_scan_instances", 62 ) 63 64 def teardown_test(self): 65 cleanup_scanners_and_advertisers( 66 self.scn_ad, self.active_adv_callback_list, self.adv_ad, 67 self.active_adv_callback_list) 68 self.active_adv_callback_list = [] 69 self.active_scan_callback_list = [] 70 71 def on_exception(self, test_name, begin_time): 72 reset_bluetooth(self.android_devices) 73 74 def _setup_generic_advertisement(self): 75 adv_callback, adv_data, adv_settings = generate_ble_advertise_objects( 76 self.adv_ad.droid) 77 self.adv_ad.droid.bleStartBleAdvertising(adv_callback, adv_data, 78 adv_settings) 79 self.active_adv_callback_list.append(adv_callback) 80 81 def _verify_no_events_found(self, event_name): 82 try: 83 event = self.scn_ad.ed.pop_event(event_name, self.default_timeout) 84 self.log.error("Found an event when none was expected: {}".format( 85 event)) 86 return False 87 except Empty: 88 self.log.info("No scan result found as expected.") 89 return True 90 91 @BluetoothBaseTest.bt_test_wrap 92 def test_scan_result_no_advertisement(self): 93 """Test opportunistic scan with no advertisement. 94 95 Tests opportunistic scan where there are no advertisements. This should 96 not find any onScanResults. 97 98 Steps: 99 1. Initialize scanner with scan mode set to opportunistic mode. 100 2. Start scanning on dut 0 101 3. Pop onScanResults event on the scanner 102 103 Expected Result: 104 Find no advertisements with the opportunistic scan instance. 105 106 Returns: 107 Pass if True 108 Fail if False 109 110 TAGS: LE, Advertising, Scanning, Opportunistic Scan 111 Priority: 1 112 """ 113 self.scn_ad.droid.bleSetScanSettingsScanMode( 114 ScanSettingsScanMode.SCAN_MODE_OPPORTUNISTIC.value) 115 filter_list, scan_settings, scan_callback = generate_ble_scan_objects( 116 self.scn_ad.droid) 117 self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings, 118 scan_callback) 119 self.active_scan_callback_list.append(scan_callback) 120 if not self._verify_no_events_found(scan_result.format(scan_callback)): 121 return False 122 self.scn_ad.droid.bleStopBleScan(scan_callback) 123 return True 124 125 @BluetoothBaseTest.bt_test_wrap 126 def test_batch_scan_result_no_advertisement(self): 127 """Test batch opportunistic scan without an advertisement. 128 129 Tests opportunistic scan where there are no advertisements. This should 130 not find any onBatchScanResult. 131 132 Steps: 133 1. Initialize scanner with scan mode set to opportunistic mode. 134 2. Set report delay seconds such that onBatchScanResult events are 135 expected 136 2. Start scanning on dut 0 137 3. Pop onBatchScanResult event on the scanner 138 139 Expected Result: 140 Find no advertisements with the opportunistic scan instance. 141 142 Returns: 143 Pass if True 144 Fail if False 145 146 TAGS: LE, Advertising, Scanning, Opportunistic Scan, Batch Scanning 147 Priority: 1 148 """ 149 self.scn_ad.droid.bleSetScanSettingsScanMode( 150 ScanSettingsScanMode.SCAN_MODE_OPPORTUNISTIC.value) 151 self.scn_ad.droid.bleSetScanSettingsReportDelayMillis( 152 self.report_delay) 153 filter_list, scan_settings, scan_callback = generate_ble_scan_objects( 154 self.scn_ad.droid) 155 self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings, 156 scan_callback) 157 self.active_scan_callback_list.append(scan_callback) 158 if not self._verify_no_events_found(batch_scan_result.format( 159 scan_callback)): 160 return False 161 self.scn_ad.droid.bleStopBleScan(scan_callback) 162 return True 163 164 @BluetoothBaseTest.bt_test_wrap 165 def test_scan_result(self): 166 """Test opportunistic scan with an advertisement. 167 168 Tests opportunistic scan where it will only report scan results when 169 other registered scanners find results. 170 171 Steps: 172 1. Initialize advertiser and start advertisement on dut1 173 2. Initialize scanner with scan mode set to opportunistic mode on dut0 174 and start scanning 175 3. Try to find an event, expect none. 176 4. Start a second scanner on dut0, with any other mode set 177 5. Pop onScanResults event on the second scanner 178 6. Pop onScanResults event on the first scanner 179 180 Expected Result: 181 Scan result is found on the opportunistic scan instance. 182 183 Returns: 184 Pass if True 185 Fail if False 186 187 TAGS: LE, Advertising, Scanning, Opportunistic Scan 188 Priority: 1 189 """ 190 self._setup_generic_advertisement() 191 self.scn_ad.droid.bleSetScanSettingsScanMode( 192 ScanSettingsScanMode.SCAN_MODE_OPPORTUNISTIC.value) 193 filter_list, scan_settings, scan_callback = generate_ble_scan_objects( 194 self.scn_ad.droid) 195 196 self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings, 197 scan_callback) 198 self.active_scan_callback_list.append(scan_callback) 199 if not self._verify_no_events_found(scan_result.format(scan_callback)): 200 return False 201 self.scn_ad.droid.bleSetScanSettingsScanMode( 202 ScanSettingsScanMode.SCAN_MODE_LOW_LATENCY.value) 203 filter_list2, scan_settings2, scan_callback2 = ( 204 generate_ble_scan_objects(self.scn_ad.droid)) 205 self.scn_ad.droid.bleStartBleScan(filter_list2, scan_settings2, 206 scan_callback2) 207 self.active_scan_callback_list.append(scan_callback2) 208 self.scn_ad.ed.pop_event( 209 scan_result.format(scan_callback2), self.default_timeout) 210 self.scn_ad.ed.pop_event( 211 scan_result.format(scan_callback), self.default_timeout) 212 return True 213 214 @BluetoothBaseTest.bt_test_wrap 215 def test_batch_scan_result(self): 216 """Test batch opportunistic scan with advertisement. 217 218 Tests opportunistic scan where it will only report scan results when 219 other registered scanners find results. Set the report delay millis such 220 that an onBatchScanResult is expected. 221 222 Steps: 223 1. Initialize advertiser and start advertisement on dut1 224 2. Initialize scanner with scan mode set to opportunistic mode and 225 set scan settings report delay seconds such that a batch scan is 226 expected 227 3. Start scanning on dut 0 228 4. Try to find an event, expect none. 229 5. Start a second scanner on dut0, with any other mode set and set scan 230 settings report delay millis such that an onBatchScanResult is expected 231 6. Pop onBatchScanResult event on the second scanner 232 7. Pop onBatchScanResult event on the first scanner 233 234 Expected Result: 235 Find a batch scan result on both opportunistic scan instances. 236 237 Returns: 238 Pass if True 239 Fail if False 240 241 TAGS: LE, Advertising, Scanning, Opportunistic Scan, Batch Scanning 242 Priority: 1 243 """ 244 self._setup_generic_advertisement() 245 self.scn_ad.droid.bleSetScanSettingsScanMode( 246 ScanSettingsScanMode.SCAN_MODE_OPPORTUNISTIC.value) 247 self.scn_ad.droid.bleSetScanSettingsReportDelayMillis( 248 self.report_delay) 249 filter_list, scan_settings, scan_callback = generate_ble_scan_objects( 250 self.scn_ad.droid) 251 self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings, 252 scan_callback) 253 self.active_scan_callback_list.append(scan_callback) 254 if not self._verify_no_events_found(batch_scan_result.format( 255 scan_callback)): 256 return False 257 self.scn_ad.droid.bleSetScanSettingsReportDelayMillis( 258 self.report_delay) 259 self.scn_ad.droid.bleSetScanSettingsScanMode( 260 ScanSettingsScanMode.SCAN_MODE_LOW_LATENCY.value) 261 filter_list2 = self.scn_ad.droid.bleGenFilterList() 262 scan_settings2 = self.scn_ad.droid.bleBuildScanSetting() 263 scan_callback2 = self.scn_ad.droid.bleGenScanCallback() 264 self.scn_ad.droid.bleStartBleScan(filter_list2, scan_settings2, 265 scan_callback2) 266 self.active_scan_callback_list.append(scan_callback2) 267 self.scn_ad.ed.pop_event( 268 batch_scan_result.format(scan_callback2), self.default_timeout) 269 self.scn_ad.ed.pop_event( 270 batch_scan_result.format(scan_callback), self.default_timeout) 271 return True 272 273 @BluetoothBaseTest.bt_test_wrap 274 def test_batch_scan_result_not_expected(self): 275 """Test opportunistic batch scan without expecting an event. 276 277 Tests opportunistic scan where it will only report scan results when 278 other registered scanners find results. Set the report delay millis such 279 that a batch scan is not expected. 280 281 Steps: 282 1. Initialize advertiser and start advertisement on dut1 283 2. Initialize scanner with scan mode set to opportunistic mode and 284 set scan settings report delay seconds such that a batch scan is 285 expected. 286 3. Start scanning on dut 0 287 4. Try to find an event, expect none. 288 5. Start a second scanner on dut0, with any other mode set and set scan 289 settings report delay millis to 0 such that an onBatchScanResult is not 290 expected. 291 6. Pop onScanResults event on the second scanner 292 7. Pop onBatchScanResult event on the first scanner 293 294 Expected Result: 295 Batch scan result is not expected on opportunistic scan instance. 296 297 Returns: 298 Pass if True 299 Fail if False 300 301 TAGS: LE, Advertising, Scanning, Opportunistic Scan, Batch Scanning 302 Priority: 1 303 """ 304 self._setup_generic_advertisement() 305 self.scn_ad.droid.bleSetScanSettingsScanMode( 306 ScanSettingsScanMode.SCAN_MODE_OPPORTUNISTIC.value) 307 self.scn_ad.droid.bleSetScanSettingsReportDelayMillis( 308 self.report_delay) 309 filter_list, scan_settings, scan_callback = generate_ble_scan_objects( 310 self.scn_ad.droid) 311 self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings, 312 scan_callback) 313 self.active_scan_callback_list.append(scan_callback) 314 if not self._verify_no_events_found(batch_scan_result.format( 315 scan_callback)): 316 317 return False 318 self.scn_ad.droid.bleSetScanSettingsScanMode( 319 ScanSettingsScanMode.SCAN_MODE_LOW_LATENCY.value) 320 filter_list2, scan_settings2, scan_callback2 = ( 321 generate_ble_scan_objects(self.scn_ad.droid)) 322 self.scn_ad.droid.bleStartBleScan(filter_list2, scan_settings2, 323 scan_callback2) 324 self.active_scan_callback_list.append(scan_callback2) 325 self.scn_ad.ed.pop_event( 326 scan_result.format(scan_callback2), self.default_timeout) 327 return self._verify_no_events_found(batch_scan_result.format( 328 scan_callback)) 329 330 @BluetoothBaseTest.bt_test_wrap 331 def test_scan_result_not_expected(self): 332 """Test opportunistic scan without expecting an event. 333 334 Tests opportunistic scan where it will only report batch scan results 335 when other registered scanners find results. 336 337 Steps: 338 1. Initialize advertiser and start advertisement on dut1 339 2. Initialize scanner with scan mode set to opportunistic mode. 340 3. Start scanning on dut 0 341 4. Try to find an event, expect none. 342 5. Start a second scanner on dut0, with any other mode set and set scan 343 settings 344 report delay millis such that an onBatchScanResult is expected 345 6. Pop onBatchScanResult event on the second scanner 346 7. Pop onScanResults event on the first scanner 347 348 Expected Result: 349 Scan result is not expected on opportunistic scan instance. 350 351 Returns: 352 Pass if True 353 Fail if False 354 355 TAGS: LE, Advertising, Scanning, Opportunistic Scan 356 Priority: 1 357 """ 358 self._setup_generic_advertisement() 359 self.scn_ad.droid.bleSetScanSettingsScanMode( 360 ScanSettingsScanMode.SCAN_MODE_OPPORTUNISTIC.value) 361 filter_list = self.scn_ad.droid.bleGenFilterList() 362 scan_settings = self.scn_ad.droid.bleBuildScanSetting() 363 scan_callback = self.scn_ad.droid.bleGenScanCallback() 364 self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings, 365 scan_callback) 366 self.active_scan_callback_list.append(scan_callback) 367 if not self._verify_no_events_found(scan_result.format(scan_callback)): 368 return False 369 self.scn_ad.droid.bleSetScanSettingsReportDelayMillis( 370 self.report_delay) 371 self.scn_ad.droid.bleSetScanSettingsScanMode( 372 ScanSettingsScanMode.SCAN_MODE_LOW_LATENCY.value) 373 filter_list2, scan_settings2, scan_callback2 = ( 374 generate_ble_scan_objects(self.scn_ad.droid)) 375 self.scn_ad.droid.bleStartBleScan(filter_list2, scan_settings2, 376 scan_callback2) 377 self.active_scan_callback_list.append(scan_callback2) 378 self.scn_ad.ed.pop_event( 379 batch_scan_result.format(scan_callback2), self.default_timeout) 380 return self._verify_no_events_found(scan_result.format(scan_callback)) 381 382 @BluetoothBaseTest.bt_test_wrap 383 def test_max_opportunistic_scan_instances(self): 384 """Test max number of opportunistic scan instances. 385 386 Tests max instances of opportunistic scans. Each instances should 387 find an onScanResults event. 388 389 Steps: 390 1. Initialize advertiser and start advertisement on dut1 391 2. Set scan settings to opportunistic scan on dut0 scan instance 392 3. Start scan scan from step 2 393 4. Repeat step two and three until there are max_scan_instances-1 scan 394 instances 395 5. Start a regular ble scan on dut0 with the last available scan 396 instance 397 6. Pop onScanResults event on all scan instances 398 399 Expected Result: 400 Each opportunistic scan instance finds a advertisement. 401 402 Returns: 403 Pass if True 404 Fail if False 405 406 TAGS: LE, Advertising, Scanning, Opportunistic Scan 407 Priority: 1 408 """ 409 self._setup_generic_advertisement() 410 for _ in range(self.max_scan_instances - 1): 411 self.scn_ad.droid.bleSetScanSettingsScanMode( 412 ScanSettingsScanMode.SCAN_MODE_OPPORTUNISTIC.value) 413 filter_list = self.scn_ad.droid.bleGenFilterList() 414 scan_settings = self.scn_ad.droid.bleBuildScanSetting() 415 scan_callback = self.scn_ad.droid.bleGenScanCallback() 416 self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings, 417 scan_callback) 418 self.active_scan_callback_list.append(scan_callback) 419 420 self.scn_ad.droid.bleSetScanSettingsScanMode( 421 ScanSettingsScanMode.SCAN_MODE_LOW_LATENCY.value) 422 filter_list2, scan_settings2, scan_callback2 = ( 423 generate_ble_scan_objects(self.scn_ad.droid)) 424 self.scn_ad.droid.bleStartBleScan(filter_list2, scan_settings2, 425 scan_callback2) 426 self.active_scan_callback_list.append(scan_callback2) 427 428 for callback in self.active_scan_callback_list: 429 self.scn_ad.ed.pop_event( 430 scan_result.format(callback), self.default_timeout) 431 432 return True 433 434 @BluetoothBaseTest.bt_test_wrap 435 def test_max_opportunistic_batch_scan_instances(self): 436 """Test max opportunistic batch scan instances. 437 438 Tests max instances of opportunistic batch scans. Each instances should 439 find an onBatchScanResult event. 440 441 Steps: 442 1. Initialize advertiser and start advertisement on dut1 443 2. Set scan settings to opportunistic scan on dut0 scan instance and 444 set report delay seconds such that an onBatchScanResult is expected 445 3. Start scan scan from step 2 446 4. Repeat step two and three until there are max_scan_instances-1 scan 447 instances 448 5. Start a regular ble scan on dut0 with the last available scan 449 instance 450 6. Pop onBatchScanResult event on all scan instances 451 452 Expected Result: 453 Each opportunistic scan instance finds an advertisement. 454 455 Returns: 456 Pass if True 457 Fail if False 458 459 TAGS: LE, Advertising, Scanning, Opportunistic Scan, Batch Scanning 460 Priority: 1 461 """ 462 self._setup_generic_advertisement() 463 for _ in range(self.max_scan_instances - 1): 464 self.scn_ad.droid.bleSetScanSettingsScanMode( 465 ScanSettingsScanMode.SCAN_MODE_OPPORTUNISTIC.value) 466 self.scn_ad.droid.bleSetScanSettingsReportDelayMillis( 467 self.report_delay) 468 filter_list = self.scn_ad.droid.bleGenFilterList() 469 scan_settings = self.scn_ad.droid.bleBuildScanSetting() 470 scan_callback = self.scn_ad.droid.bleGenScanCallback() 471 self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings, 472 scan_callback) 473 self.active_scan_callback_list.append(scan_callback) 474 475 self.scn_ad.droid.bleSetScanSettingsScanMode( 476 ScanSettingsScanMode.SCAN_MODE_LOW_LATENCY.value) 477 self.scn_ad.droid.bleSetScanSettingsReportDelayMillis( 478 self.report_delay) 479 filter_list2, scan_settings2, scan_callback2 = ( 480 generate_ble_scan_objects(self.scn_ad.droid)) 481 self.scn_ad.droid.bleStartBleScan(filter_list2, scan_settings2, 482 scan_callback2) 483 self.active_scan_callback_list.append(scan_callback2) 484 485 for callback in self.active_scan_callback_list: 486 self.scn_ad.ed.pop_event( 487 batch_scan_result.format(callback), self.default_timeout) 488 489 return True 490 491 @BluetoothBaseTest.bt_test_wrap 492 def test_discover_opportunistic_scan_result_off_secondary_scan_filter( 493 self): 494 """Test opportunistic scan result from secondary scan filter. 495 496 Tests opportunistic scan where the secondary scan instance does not find 497 an advertisement but the scan instance with scan mode set to 498 opportunistic scan will find an advertisement. 499 500 Steps: 501 1. Initialize advertiser and start advertisement on dut1 (make sure the 502 advertisement is not advertising the device name) 503 2. Set scan settings to opportunistic scan on dut0 scan instance 504 3. Start scan scan from step 2 505 4. Try to find an event, expect none 506 5. Start a second scanner on dut0, with any other mode set and set the 507 scan filter device name to "opp_test" 508 6. Pop onScanResults from the second scanner 509 7. Expect no events 510 8. Pop onScanResults from the first scanner 511 512 Expected Result: 513 Opportunistic scan instance finds an advertisement. 514 515 Returns: 516 Pass if True 517 Fail if False 518 519 TAGS: LE, Advertising, Scanning, Opportunistic Scan 520 Priority: 1 521 """ 522 self._setup_generic_advertisement() 523 self.scn_ad.droid.bleSetScanSettingsScanMode( 524 ScanSettingsScanMode.SCAN_MODE_OPPORTUNISTIC.value) 525 filter_list, scan_settings, scan_callback = generate_ble_scan_objects( 526 self.scn_ad.droid) 527 528 self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings, 529 scan_callback) 530 self.active_scan_callback_list.append(scan_callback) 531 if not self._verify_no_events_found(scan_result.format(scan_callback)): 532 return False 533 self.scn_ad.droid.bleSetScanSettingsScanMode( 534 ScanSettingsScanMode.SCAN_MODE_LOW_LATENCY.value) 535 filter_list2, scan_settings2, scan_callback2 = ( 536 generate_ble_scan_objects(self.scn_ad.droid)) 537 self.scn_ad.droid.bleSetScanFilterDeviceName("opp_test") 538 self.scn_ad.droid.bleBuildScanFilter(filter_list2) 539 self.scn_ad.droid.bleStartBleScan(filter_list2, scan_settings2, 540 scan_callback2) 541 self.active_scan_callback_list.append(scan_callback2) 542 if not self._verify_no_events_found(scan_result.format( 543 scan_callback2)): 544 return False 545 self.scn_ad.ed.pop_event( 546 scan_result.format(scan_callback), self.default_timeout) 547 return True 548 549 @BluetoothBaseTest.bt_test_wrap 550 def test_negative_opportunistic_scan_filter_result_off_secondary_scan_result( 551 self): 552 """Test opportunistic scan not found scenario. 553 554 Tests opportunistic scan where the secondary scan instance does find an 555 advertisement but the scan instance with scan mode set to opportunistic 556 scan does not find an advertisement due to mismatched scan filters. 557 558 Steps: 559 1. Initialize advertiser and start advertisement on dut1 (make sure the 560 advertisement is not advertising the device name) 561 2. Set scan settings to opportunistic scan on dut0 scan instance and set 562 the scan filter device name to "opp_test" 563 3. Start scan scan from step 2 564 4. Try to find an event, expect none 565 5. Start a second scanner on dut0, with any other mode set 566 6. Pop onScanResults from the second scanner 567 7. Pop onScanResults from the first scanner 568 8. Expect no events 569 570 Expected Result: 571 Opportunistic scan instance doesn't find any advertisements. 572 573 Returns: 574 Pass if True 575 Fail if False 576 577 TAGS: LE, Advertising, Scanning, Opportunistic Scan 578 Priority: 1 579 """ 580 self._setup_generic_advertisement() 581 self.scn_ad.droid.bleSetScanSettingsScanMode( 582 ScanSettingsScanMode.SCAN_MODE_OPPORTUNISTIC.value) 583 filter_list, scan_settings, scan_callback = generate_ble_scan_objects( 584 self.scn_ad.droid) 585 self.scn_ad.droid.bleSetScanFilterDeviceName("opp_test") 586 self.scn_ad.droid.bleBuildScanFilter(filter_list) 587 self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings, 588 scan_callback) 589 self.active_scan_callback_list.append(scan_callback) 590 if not self._verify_no_events_found(scan_result.format(scan_callback)): 591 return False 592 self.scn_ad.droid.bleSetScanSettingsScanMode( 593 ScanSettingsScanMode.SCAN_MODE_LOW_LATENCY.value) 594 filter_list2, scan_settings2, scan_callback2 = ( 595 generate_ble_scan_objects(self.scn_ad.droid)) 596 self.scn_ad.droid.bleStartBleScan(filter_list2, scan_settings2, 597 scan_callback2) 598 self.active_scan_callback_list.append(scan_callback2) 599 self.scn_ad.ed.pop_event( 600 scan_result.format(scan_callback2), self.default_timeout) 601 return self._verify_no_events_found(scan_result.format(scan_callback)) 602 603 @BluetoothBaseTest.bt_test_wrap 604 def test_opportunistic_scan_filter_result_off_secondary_scan_result(self): 605 """Test opportunistic scan from a secondary scan result. 606 607 Tests opportunistic scan where the scan filters are the same between the 608 first scan instance with opportunistic scan set and the second instance 609 with any other mode set. 610 611 Steps: 612 1. Initialize advertiser and start advertisement on dut1 (make sure the 613 advertisement is not advertising the device name) 614 2. Set scan settings to opportunistic scan on dut0 scan instance and set 615 the scan filter device name to the advertiser's device name 616 3. Start scan scan from step 2 617 4. Try to find an event, expect none 618 5. Start a second scanner on dut0, with any other mode set and set the 619 scan filter device name to the advertiser's device name 620 6. Pop onScanResults from the second scanner 621 7. Pop onScanResults from the first scanner 622 623 Expected Result: 624 Opportunistic scan instance finds a advertisement. 625 626 Returns: 627 Pass if True 628 Fail if False 629 630 TAGS: LE, Advertising, Scanning, Opportunistic Scan 631 Priority: 1 632 """ 633 self.adv_ad.droid.bleSetAdvertiseDataIncludeDeviceName(True) 634 self._setup_generic_advertisement() 635 adv_device_name = self.adv_ad.droid.bluetoothGetLocalName() 636 self.scn_ad.droid.bleSetScanSettingsScanMode( 637 ScanSettingsScanMode.SCAN_MODE_OPPORTUNISTIC.value) 638 filter_list, scan_settings, scan_callback = generate_ble_scan_objects( 639 self.scn_ad.droid) 640 self.scn_ad.droid.bleSetScanFilterDeviceName(adv_device_name) 641 self.scn_ad.droid.bleBuildScanFilter(filter_list) 642 self.scn_ad.droid.bleStartBleScan(filter_list, scan_settings, 643 scan_callback) 644 self.active_scan_callback_list.append(scan_callback) 645 if not self._verify_no_events_found(scan_result.format(scan_callback)): 646 return False 647 self.scn_ad.droid.bleSetScanSettingsScanMode( 648 ScanSettingsScanMode.SCAN_MODE_LOW_LATENCY.value) 649 filter_list2, scan_settings2, scan_callback2 = ( 650 generate_ble_scan_objects(self.scn_ad.droid)) 651 self.scn_ad.droid.bleSetScanFilterDeviceName(adv_device_name) 652 self.scn_ad.droid.bleBuildScanFilter(filter_list2) 653 self.scn_ad.droid.bleStartBleScan(filter_list2, scan_settings2, 654 scan_callback2) 655 self.active_scan_callback_list.append(scan_callback2) 656 self.scn_ad.ed.pop_event( 657 scan_result.format(scan_callback2), self.default_timeout) 658 self.scn_ad.ed.pop_event( 659 scan_result.format(scan_callback), self.default_timeout) 660 return True 661