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