• 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 thea
14# License for the specific language governing permissions and limitations under
15# the License.
16"""
17Test script to exercise Ble Advertisement 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 Advertisements will also fail.
21"""
22
23from acts.controllers.android import SL4AAPIError
24from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
25from acts.test_utils.bt.bt_test_utils import adv_fail
26from acts.test_utils.bt.bt_test_utils import generate_ble_advertise_objects
27from acts.test_utils.bt.BleEnum import AdvertiseSettingsAdvertiseMode
28from acts.test_utils.bt.BleEnum import AdvertiseSettingsAdvertiseTxPower
29from acts.test_utils.bt.BleEnum import JavaInteger
30
31
32class BleAdvertiseVerificationError(Exception):
33    """Error in fetsching BleScanner Advertise result."""
34
35
36class BleAdvertiseApiTest(BluetoothBaseTest):
37    def __init__(self, controllers):
38        BluetoothBaseTest.__init__(self, controllers)
39        self.ad_dut = self.android_devices[0]
40
41    @BluetoothBaseTest.bt_test_wrap
42    def test_adv_settings_defaults(self):
43        """Tests the default advertisement settings.
44
45        This builder object should have a proper "get" expectation for each
46        attribute of the builder object once it's built.
47
48        Steps:
49        1. Build a new advertise settings object.
50        2. Get the attributes of the advertise settings object.
51        3. Compare the attributes found against the attributes exp.
52
53        Expected Result:
54        Found attributes should match expected attributes.
55
56        Returns:
57          True is pass
58          False if fail
59
60        TAGS: LE, Advertising
61        Priority: 0
62        """
63        test_result = True
64        droid = self.ad_dut.droid
65        adv_settings = droid.bleBuildAdvertiseSettings()
66        adv_mode = droid.bleGetAdvertiseSettingsMode(adv_settings)
67        tx_power_level = droid.bleGetAdvertiseSettingsTxPowerLevel(
68            adv_settings)
69        is_connectable = droid.bleGetAdvertiseSettingsIsConnectable(
70            adv_settings)
71
72        exp_adv_mode = AdvertiseSettingsAdvertiseMode.ADVERTISE_MODE_LOW_POWER.value
73        exp_tx_power_level = AdvertiseSettingsAdvertiseTxPower.ADVERTISE_TX_POWER_MEDIUM.value
74        exp_is_connectable = True
75        if adv_mode != exp_adv_mode:
76            test_result = False
77            self.log.debug("exp filtering mode: {},"
78                           " found filtering mode: {}".format(exp_adv_mode,
79                                                              adv_mode))
80        if tx_power_level != exp_tx_power_level:
81            test_result = False
82            self.log.debug("exp tx power level: {},"
83                           " found filtering tx power level: {}".format(
84                               exp_tx_power_level, tx_power_level))
85        if exp_is_connectable != is_connectable:
86            test_result = False
87            self.log.debug("exp is connectable: {},"
88                           " found filtering is connectable: {}".format(
89                               exp_is_connectable, is_connectable))
90        return test_result
91
92    @BluetoothBaseTest.bt_test_wrap
93    def test_adv_data_defaults(self):
94        """Tests the default advertisement data.
95
96        This builder object should have a proper "get" expectation for each
97        attribute of the builder object once it's built.
98
99        Steps:
100        1. Build a new AdvertiseData object.
101        2. Get the attributes of the advertise settings object.
102        3. Compare the attributes found against the attributes exp.
103
104        Expected Result:
105        Found attributes should match expected attributes.
106
107        Returns:
108          True is pass
109          False if fail
110
111        TAGS: LE, Advertising
112        Priority: 0
113        """
114        test_result = True
115        droid = self.ad_dut.droid
116        adv_data = droid.bleBuildAdvertiseData()
117        service_uuids = droid.bleGetAdvertiseDataServiceUuids(adv_data)
118        include_tx_power_level = droid.bleGetAdvertiseDataIncludeTxPowerLevel(
119            adv_data)
120        include_device_name = droid.bleGetAdvertiseDataIncludeDeviceName(
121            adv_data)
122
123        exp_service_uuids = []
124        exp_include_tx_power_level = False
125        exp_include_device_name = False
126        self.log.debug("Step 4: Verify all defaults match exp values.")
127        if service_uuids != exp_service_uuids:
128            test_result = False
129            self.log.debug("exp filtering service uuids: {},"
130                           " found filtering service uuids: {}".format(
131                               exp_service_uuids, service_uuids))
132        if include_tx_power_level != exp_include_tx_power_level:
133            test_result = False
134            self.log.debug(
135                "exp filtering include tx power level:: {},"
136                " found filtering include tx power level: {}".format(
137                    exp_include_tx_power_level, include_tx_power_level))
138        if include_device_name != exp_include_device_name:
139            test_result = False
140            self.log.debug(
141                "exp filtering include tx power level: {},"
142                " found filtering include tx power level: {}".format(
143                    exp_include_device_name, include_device_name))
144        if not test_result:
145            self.log.debug("Some values didn't match the defaults.")
146        else:
147            self.log.debug("All default values passed.")
148        return test_result
149
150    @BluetoothBaseTest.bt_test_wrap
151    def test_adv_settings_set_adv_mode_balanced(self):
152        """Tests advertise settings balanced mode.
153
154        This advertisement settings from "set" advertisement mode should match
155        the corresponding "get" function.
156
157        Steps:
158        1. Build a new advertise settings object.
159        2. Set the advertise mode attribute to balanced.
160        3. Get the attributes of the advertise settings object.
161        4. Compare the attributes found against the attributes exp.
162
163        Expected Result:
164        Found attributes should match expected attributes.
165
166        Returns:
167          True is pass
168          False if fail
169
170        TAGS: LE, Advertising
171        Priority: 1
172        """
173        self.log.debug("Step 1: Setup environment.")
174        droid = self.ad_dut.droid
175        exp_adv_mode = AdvertiseSettingsAdvertiseMode.ADVERTISE_MODE_BALANCED.value
176        self.log.debug(
177            "Step 2: Set the filtering settings object's value to {}".format(
178                exp_adv_mode))
179        return self.verify_adv_settings_adv_mode(droid, exp_adv_mode)
180
181    @BluetoothBaseTest.bt_test_wrap
182    def test_adv_settings_set_adv_mode_low_power(self):
183        """Tests advertise settings low power mode.
184
185        This advertisement settings from "set" advertisement mode should match
186        the corresponding "get" function.
187
188        Steps:
189        1. Build a new advertise settings object.
190        2. Set the advertise mode attribute to low power mode.
191        3. Get the attributes of the advertise settings object.
192        4. Compare the attributes found against the attributes exp.
193
194        Expected Result:
195        Found attributes should match expected attributes.
196
197        Returns:
198          True is pass
199          False if fail
200
201        TAGS: LE, Advertising
202        Priority: 1
203        """
204        self.log.debug("Step 1: Setup environment.")
205        droid = self.ad_dut.droid
206        exp_adv_mode = AdvertiseSettingsAdvertiseMode.ADVERTISE_MODE_LOW_POWER.value
207        self.log.debug(
208            "Step 2: Set the filtering settings object's value to {}".format(
209                exp_adv_mode))
210        return self.verify_adv_settings_adv_mode(droid, exp_adv_mode)
211
212    @BluetoothBaseTest.bt_test_wrap
213    def test_adv_settings_set_adv_mode_low_latency(self):
214        """Tests advertise settings low latency mode.
215
216        This advertisement settings from "set" advertisement mode should match
217        the corresponding "get" function.
218
219        Steps:
220        1. Build a new advertise settings object.
221        2. Set the advertise mode attribute to low latency mode.
222        3. Get the attributes of the advertise settings object.
223        4. Compare the attributes found against the attributes exp.
224
225        Expected Result:
226        Found attributes should match expected attributes.
227
228        Returns:
229          True is pass
230          False if fail
231
232        TAGS: LE, Advertising
233        Priority: 1
234        """
235        self.log.debug("Step 1: Setup environment.")
236        droid = self.ad_dut.droid
237        exp_adv_mode = AdvertiseSettingsAdvertiseMode.ADVERTISE_MODE_LOW_LATENCY.value
238        self.log.debug(
239            "Step 2: Set the filtering settings object's value to {}".format(
240                exp_adv_mode))
241        return self.verify_adv_settings_adv_mode(droid, exp_adv_mode)
242
243    @BluetoothBaseTest.bt_test_wrap
244    def test_adv_settings_set_invalid_adv_mode(self):
245        """Tests advertise settings invalid advertising mode.
246
247        This advertisement settings from "set" advertisement mode should fail
248        when setting an invalid advertisement.
249
250        Steps:
251        1. Build a new advertise settings object.
252        2. Set the advertise mode attribute to -1.
253
254        Expected Result:
255        Building the advertise settings should fail.
256
257        Returns:
258          True is pass
259          False if fail
260
261        TAGS: LE, Advertising
262        Priority: 2
263        """
264        self.log.debug("Step 1: Setup environment.")
265        droid = self.ad_dut.droid
266        exp_adv_mode = -1
267        self.log.debug("Step 2: Set the filtering mode to -1")
268        return self.verify_invalid_adv_settings_adv_mode(droid, exp_adv_mode)
269
270    @BluetoothBaseTest.bt_test_wrap
271    def test_adv_settings_set_adv_tx_power_level_high(self):
272        """Tests advertise settings tx power level high.
273
274        This advertisement settings from "set" advertisement tx power level
275        should match the corresponding "get" function.
276
277        Steps:
278        1. Build a new advertise settings object.
279        2. Set the advertise mode attribute to tx power level high.
280        3. Get the attributes of the advertise settings object.
281        4. Compare the attributes found against the attributes exp.
282
283        Expected Result:
284        Found attributes should match expected attributes.
285
286        Returns:
287          True is pass
288          False if fail
289
290        TAGS: LE, Advertising
291        Priority: 1
292        """
293        self.log.debug("Step 1: Setup environment.")
294        droid = self.ad_dut.droid
295        exp_adv_tx_power = (
296            AdvertiseSettingsAdvertiseTxPower.ADVERTISE_TX_POWER_HIGH.value)
297        self.log.debug(
298            "Step 2: Set the filtering settings object's value to {}".format(
299                exp_adv_tx_power))
300        return self.verify_adv_settings_tx_power_level(droid, exp_adv_tx_power)
301
302    @BluetoothBaseTest.bt_test_wrap
303    def test_adv_settings_set_adv_tx_power_level_medium(self):
304        """Tests advertise settings tx power level medium.
305
306        This advertisement settings from "set" advertisement tx power level
307        should match the corresponding "get" function.
308
309        Steps:
310        1. Build a new advertise settings object.
311        2. Set the advertise mode attribute to tx power level medium.
312        3. Get the attributes of the advertise settings object.
313        4. Compare the attributes found against the attributes exp.
314
315        Expected Result:
316        Found attributes should match expected attributes.
317
318        Returns:
319          True is pass
320          False if fail
321
322        TAGS: LE, Advertising
323        Priority: 1
324        """
325        self.log.debug("Step 1: Setup environment.")
326        test_result = True
327        droid = self.ad_dut.droid
328        exp_adv_tx_power = (
329            AdvertiseSettingsAdvertiseTxPower.ADVERTISE_TX_POWER_MEDIUM.value)
330        self.log.debug(
331            "Step 2: Set the filtering settings object's value to {}".format(
332                exp_adv_tx_power))
333        return self.verify_adv_settings_tx_power_level(droid, exp_adv_tx_power)
334
335    @BluetoothBaseTest.bt_test_wrap
336    def test_adv_settings_set_adv_tx_power_level_low(self):
337        """Tests advertise settings tx power level low.
338
339        This advertisement settings from "set" advertisement tx power level
340        should match the corresponding "get" function.
341
342        Steps:
343        1. Build a new advertise settings object.
344        2. Set the advertise mode attribute to tx power level low.
345        3. Get the attributes of the advertise settings object.
346        4. Compare the attributes found against the attributes exp.
347
348        Expected Result:
349        Found attributes should match expected attributes.
350
351        Returns:
352          True is pass
353          False if fail
354
355        TAGS: LE, Advertising
356        Priority: 1
357        """
358        self.log.debug("Step 1: Setup environment.")
359        droid = self.ad_dut.droid
360        exp_adv_tx_power = (
361            AdvertiseSettingsAdvertiseTxPower.ADVERTISE_TX_POWER_LOW.value)
362        self.log.debug(
363            "Step 2: Set the filtering settings object's value to ".format(
364                exp_adv_tx_power))
365        return self.verify_adv_settings_tx_power_level(droid, exp_adv_tx_power)
366
367    @BluetoothBaseTest.bt_test_wrap
368    def test_adv_settings_set_adv_tx_power_level_ultra_low(self):
369        """Tests advertise settings tx power level ultra low.
370
371        This advertisement settings from "set" advertisement tx power level
372        should match the corresponding "get" function.
373
374        Steps:
375        1. Build a new advertise settings object.
376        2. Set the advertise mode attribute to tx power level ultra low.
377        3. Get the attributes of the advertise settings object.
378        4. Compare the attributes found against the attributes exp.
379
380        Expected Result:
381        Found attributes should match expected attributes.
382
383        Returns:
384          True is pass
385          False if fail
386
387        TAGS: LE, Advertising
388        Priority: 1
389        """
390        self.log.debug("Step 1: Setup environment.")
391        droid = self.ad_dut.droid
392        exp_adv_tx_power = (
393            AdvertiseSettingsAdvertiseTxPower.ADVERTISE_TX_POWER_ULTRA_LOW.
394            value)
395        self.log.debug(
396            "Step 2: Set the filtering settings object's value to ".format(
397                exp_adv_tx_power))
398        return self.verify_adv_settings_tx_power_level(droid, exp_adv_tx_power)
399
400    @BluetoothBaseTest.bt_test_wrap
401    def test_adv_settings_set_invalid_adv_tx_power_level(self):
402        """Tests advertise settings invalid advertising tx power level.
403
404        This advertisement settings from "set" advertisement mode should fail
405        when setting an invalid advertisement.
406
407        Steps:
408        1. Build a new advertise settings object.
409        2. Set the advertise tx power level attribute to -1.
410
411        Expected Result:
412        Building the advertise settings should fail.
413
414        Returns:
415          True is pass
416          False if fail
417
418        TAGS: LE, Advertising
419        Priority: 1
420        """
421        self.log.debug("Step 1: Setup environment.")
422        droid = self.ad_dut.droid
423        exp_adv_tx_power = -1
424        self.log.debug("Step 2: Set the filtering mode to -1")
425        return self.verify_invalid_adv_settings_tx_power_level(
426            droid, exp_adv_tx_power)
427
428    @BluetoothBaseTest.bt_test_wrap
429    def test_adv_settings_set_is_connectable_true(self):
430        """Tests advertise settings is connectable true.
431
432        This advertisement settings from "set" advertisement tx power level
433        should match the corresponding "get" function.
434
435        Steps:
436        1. Build a new advertise settings object.
437        2. Set the advertise is connectable to true.
438        3. Get the attributes of the advertise settings object.
439        4. Compare the attributes found against the attributes exp.
440
441        Expected Result:
442        Found attributes should match expected attributes.
443
444        Returns:
445          True is pass
446          False if fail
447
448        TAGS: LE, Advertising
449        Priority: 1
450        """
451        self.log.debug("Step 1: Setup environment.")
452        droid = self.ad_dut.droid
453        exp_is_connectable = True
454        self.log.debug(
455            "Step 2: Set the filtering settings object's value to {}".format(
456                exp_is_connectable))
457        return self.verify_adv_settings_is_connectable(droid,
458                                                       exp_is_connectable)
459
460    @BluetoothBaseTest.bt_test_wrap
461    def test_adv_settings_set_is_connectable_false(self):
462        """Tests advertise settings is connectable false.
463
464        This advertisement settings from "set" advertisement tx power level
465        should match the corresponding "get" function.
466
467        Steps:
468        1. Build a new advertise settings object.
469        2. Set the advertise is connectable to false.
470        3. Get the attributes of the advertise settings object.
471        4. Compare the attributes found against the attributes exp.
472
473        Expected Result:
474        Found attributes should match expected attributes.
475
476        Returns:
477          True is pass
478          False if fail
479
480        TAGS: LE, Advertising
481        Priority: 1
482        """
483        self.log.debug("Step 1: Setup environment.")
484        droid = self.ad_dut.droid
485        exp_is_connectable = False
486        self.log.debug("Step 2: Set the filtering settings object's value to "
487                       + str(exp_is_connectable))
488        return self.verify_adv_settings_is_connectable(droid,
489                                                       exp_is_connectable)
490
491    @BluetoothBaseTest.bt_test_wrap
492    def test_adv_data_set_service_uuids_empty(self):
493        """Tests advertisement data's service uuids to empty.
494
495        This advertisement data from "set" advertisement service uuid
496        should match the corresponding "get" function.
497
498        Steps:
499        1. Build a new AdvertiseData object.
500        2. Set the AdvertiseData's service uuid to empty.
501        3. Get the attributes of the AdvertiseData object.
502        4. Compare the attributes found against the attributes exp.
503
504        Expected Result:
505        Found attributes should match expected attributes.
506
507        Returns:
508          True is pass
509          False if fail
510
511        TAGS: LE, Advertising
512        Priority: 1
513        """
514        self.log.debug("Step 1: Setup environment.")
515        droid = self.ad_dut.droid
516        exp_service_uuids = []
517        self.log.debug("Step 2: Set the filtering data object's value to " +
518                       str(exp_service_uuids))
519        return self.verify_adv_data_service_uuids(droid, exp_service_uuids)
520
521    @BluetoothBaseTest.bt_test_wrap
522    def test_adv_data_set_service_uuids_single(self):
523        """Tests advertisement data's service uuids to empty.
524
525        This advertisement data from "set" advertisement service uuid
526        should match the corresponding "get" function.
527
528        Steps:
529        1. Build a new AdvertiseData object.
530        2. Set the AdvertiseData's service uuid to empty.
531        3. Get the attributes of the AdvertiseData object.
532        4. Compare the attributes found against the attributes exp.
533
534        Expected Result:
535        Found attributes should match expected attributes.
536
537        Returns:
538          True is pass
539          False if fail
540
541        TAGS: LE, Advertising
542        Priority: 1
543        """
544        self.log.debug("Step 1: Setup environment.")
545        droid = self.ad_dut.droid
546        exp_service_uuids = ["00000000-0000-1000-8000-00805f9b34fb"]
547        self.log.debug("Step 2: Set the filtering data object's value to " +
548                       str(exp_service_uuids))
549        return self.verify_adv_data_service_uuids(droid, exp_service_uuids)
550
551    @BluetoothBaseTest.bt_test_wrap
552    def test_adv_data_set_service_uuids_multiple(self):
553        """Tests advertisement data's service uuids to multiple uuids.
554
555        This advertisement data from "set" advertisement service uuid
556        should match the corresponding "get" function.
557
558        Steps:
559        1. Build a new AdvertiseData object.
560        2. Set the AdvertiseData's service uuid to multiple uuids.
561        3. Get the attributes of the AdvertiseData object.
562        4. Compare the attributes found against the attributes exp.
563
564        Expected Result:
565        Found attributes should match expected attributes.
566
567        Returns:
568          True is pass
569          False if fail
570
571        TAGS: LE, Advertising
572        Priority: 1
573        """
574        self.log.debug("Step 1: Setup environment.")
575        droid = self.ad_dut.droid
576        exp_service_uuids = ["00000000-0000-1000-8000-00805f9b34fb",
577                             "00000000-0000-1000-8000-00805f9b34fb"]
578        self.log.debug("Step 2: Set the filtering data object's value to " +
579                       str(exp_service_uuids))
580        return self.verify_adv_data_service_uuids(droid, exp_service_uuids)
581
582    @BluetoothBaseTest.bt_test_wrap
583    def test_adv_data_set_service_uuids_invalid_uuid(self):
584        """Tests advertisement data's service uuids to an invalid uuid.
585
586        This advertisement data from "set" advertisement service uuid
587        should fail when there is an invalid service uuid.
588
589        Steps:
590        1. Build a new AdvertiseData object.
591        2. Set the AdvertiseData's service uuid to an invalid uuid.
592
593        Expected Result:
594        Building the AdvertiseData should fail.
595
596        Returns:
597          True is pass
598          False if fail
599
600        TAGS: LE, Advertising
601        Priority: 1
602        """
603        self.log.debug("Step 1: Setup environment.")
604        droid = self.ad_dut.droid
605        exp_service_uuids = ["0"]
606        self.log.debug("Step 2: Set the filtering data service uuids to " +
607                       str(exp_service_uuids))
608        return self.verify_invalid_adv_data_service_uuids(droid,
609                                                          exp_service_uuids)
610
611    @BluetoothBaseTest.bt_test_wrap
612    def test_adv_data_set_service_data(self):
613        """Tests advertisement data's service data.
614
615        This advertisement data from "set" advertisement service data
616        should match the corresponding "get" function.
617
618        Steps:
619        1. Build a new AdvertiseData object.
620        2. Set the AdvertiseData's service data.
621        3. Get the attributes of the AdvertiseData object.
622        4. Compare the attributes found against the attributes exp.
623
624        Expected Result:
625        Found attributes should match expected attributes.
626
627        Returns:
628          True is pass
629          False if fail
630
631        TAGS: LE, Advertising
632        Priority: 1
633        """
634        self.log.debug("Step 1: Setup environment.")
635        droid = self.ad_dut.droid
636        exp_service_data_uuid = "00000000-0000-1000-8000-00805f9b34fb"
637        exp_service_data = [1,2,3]
638        self.log.debug(
639            "Step 2: Set the filtering data object's service data uuid to: {}, "
640            "service data: {}".format(exp_service_data_uuid, exp_service_data))
641        return self.verify_adv_data_service_data(droid, exp_service_data_uuid,
642                                                 exp_service_data)
643
644    @BluetoothBaseTest.bt_test_wrap
645    def test_adv_data_set_service_data_invalid_service_data(self):
646        """Tests advertisement data's invalid service data.
647
648        This advertisement data from "set" advertisement service data
649        should fail on an invalid value.
650
651        Steps:
652        1. Build a new AdvertiseData object.
653        2. Set the AdvertiseData's service data to an invalid value.
654        3. Get the attributes of the AdvertiseData object.
655        4. Compare the attributes found against the attributes exp.
656
657        Expected Result:
658        Found attributes should match expected attributes.
659
660        Returns:
661          True is pass
662          False if fail
663
664        TAGS: LE, Advertising
665        Priority: 1
666        """
667        self.log.debug("Step 1: Setup environment.")
668        droid = self.ad_dut.droid
669        exp_service_data_uuid = "00000000-0000-1000-8000-00805f9b34fb"
670        exp_service_data = "helloworld"
671        self.log.debug(
672            "Step 2: Set the filtering data object's service data uuid to: {}, "
673            "service data: {}".format(exp_service_data_uuid, exp_service_data))
674        return self.verify_invalid_adv_data_service_data(
675            droid, exp_service_data_uuid, exp_service_data)
676
677    @BluetoothBaseTest.bt_test_wrap
678    def test_adv_data_set_service_data_invalid_service_data_uuid(self):
679        """Tests advertisement data's invalid service data and uuid.
680
681        This advertisement data from "set" advertisement service data
682        should fail on an invalid value.
683
684        Steps:
685        1. Build a new AdvertiseData object.
686        2. Set the AdvertiseData's service data and uuid to an invalid value.
687        3. Get the attributes of the AdvertiseData object.
688        4. Compare the attributes found against the attributes exp.
689
690        Expected Result:
691        Found attributes should match expected attributes.
692
693        Returns:
694          True is pass
695          False if fail
696
697        TAGS: LE, Advertising
698        Priority: 1
699        """
700        self.log.debug("Step 1: Setup environment.")
701        droid = self.ad_dut.droid
702        exp_service_data_uuid = "0"
703        exp_service_data = "1,2,3"
704        self.log.debug(
705            "Step 2: Set the filtering data object's service data uuid to: {}, "
706            "service data: {}".format(exp_service_data_uuid, exp_service_data))
707        return self.verify_invalid_adv_data_service_data(
708            droid, exp_service_data_uuid, exp_service_data)
709
710    @BluetoothBaseTest.bt_test_wrap
711    def test_adv_data_set_manu_id(self):
712        """Tests advertisement data's manufacturers data and id.
713
714        This advertisement data from "set" advertisement manufacturers data
715        should match the corresponding "get" function.
716
717        Steps:
718        1. Build a new AdvertiseData object.
719        2. Set the AdvertiseData's manufacturers data and id.
720        3. Get the attributes of the AdvertiseData object.
721        4. Compare the attributes found against the attributes exp.
722
723        Expected Result:
724        Found attributes should match expected attributes.
725
726        Returns:
727          True is pass
728          False if fail
729
730        TAGS: LE, Advertising
731        Priority: 1
732        """
733        self.log.debug("Step 1: Setup environment.")
734        droid = self.ad_dut.droid
735        exp_manu_id = 0
736        exp_manu_specific_data = [1,2,3]
737        self.log.debug(
738            "Step 2: Set the filtering data object's service data manu id: {}"
739            ", manu specific data: {}".format(exp_manu_id,
740                                              exp_manu_specific_data))
741        return self.verify_adv_data_manu_id(droid, exp_manu_id,
742                                            exp_manu_specific_data)
743
744    @BluetoothBaseTest.bt_test_wrap
745    def test_adv_data_set_manu_id_invalid_manu_id(self):
746        """Tests advertisement data's manufacturers invalid id.
747
748        This advertisement data from "set" advertisement manufacturers data
749        should not be successful on an invalid id.
750
751        Steps:
752        1. Build a new AdvertiseData object.
753        2. Set the AdvertiseData's manufacturers id to -1.
754        3. Build the advertisement data.
755
756        Expected Result:
757        Building the advertisement data should fail.
758
759        Returns:
760          True is pass
761          False if fail
762
763        TAGS: LE, Advertising
764        Priority: 1
765        """
766        self.log.debug("Step 1: Setup environment.")
767        droid = self.ad_dut.droid
768        exp_manu_id = -1
769        exp_manu_specific_data = [1,2,3]
770        self.log.debug(
771            "Step 2: Set the filtering data object's service data manu id: {}"
772            ", manu specific data: {}".format(exp_manu_id,
773                                              exp_manu_specific_data))
774        return self.verify_invalid_adv_data_manu_id(droid, exp_manu_id,
775                                                    exp_manu_specific_data)
776
777    @BluetoothBaseTest.bt_test_wrap
778    def test_adv_data_set_manu_id_invalid_manu_specific_data(self):
779        """Tests advertisement data's manufacturers invalid specific data.
780
781        This advertisement data from "set" advertisement manufacturers data
782        should not be successful on an invalid specific data.
783
784        Steps:
785        1. Build a new AdvertiseData object.
786        2. Set the AdvertiseData's manufacturers specific data to helloworld.
787        3. Build the advertisement data.
788
789        Expected Result:
790        Building the advertisement data should fail.
791
792        Returns:
793          True is pass
794          False if fail
795
796        TAGS: LE, Advertising
797        Priority: 1
798        """
799        self.log.debug("Step 1: Setup environment.")
800        droid = self.ad_dut.droid
801        exp_manu_id = 0
802        exp_manu_specific_data = ['helloworld']
803        self.log.debug(
804            "Step 2: Set the filtering data object's service data manu id: {}"
805            ", manu specific data: {}".format(exp_manu_id,
806                                              exp_manu_specific_data))
807        return self.verify_invalid_adv_data_manu_id(droid, exp_manu_id,
808                                                    exp_manu_specific_data)
809
810    @BluetoothBaseTest.bt_test_wrap
811    def test_adv_data_set_manu_id_max(self):
812        """Tests advertisement data's manufacturers id to the max size.
813
814        This advertisement data from "set" advertisement manufacturers data
815        should match the corresponding "get" function.
816
817        Steps:
818        1. Build a new AdvertiseData object.
819        2. Set the AdvertiseData's manufacturers id to JavaInterger.MAX value.
820        3. Get the attributes of the AdvertiseData object.
821        4. Compare the attributes found against the attributes exp.
822
823        Expected Result:
824        Found attributes should match expected attributes.
825
826        Returns:
827          True is pass
828          False if fail
829
830        TAGS: LE, Advertising
831        Priority: 3
832        """
833        self.log.debug("Step 1: Setup environment.")
834        droid = self.ad_dut.droid
835        exp_manu_id = JavaInteger.MAX.value
836        exp_manu_specific_data = [1,2,3]
837        self.log.debug(
838            "Step 2: Set the filtering data object's service data manu id: {}"
839            ", manu specific data: {}".format(exp_manu_id,
840                                              exp_manu_specific_data))
841        return self.verify_adv_data_manu_id(droid, exp_manu_id,
842                                            exp_manu_specific_data)
843
844    @BluetoothBaseTest.bt_test_wrap
845    def test_adv_data_set_include_tx_power_level_true(self):
846        """Tests advertisement data's include tx power level to True.
847
848        This advertisement data from "set" advertisement manufacturers data
849        should match the corresponding "get" function.
850
851        Steps:
852        1. Build a new AdvertiseData object.
853        2. Set the AdvertiseData's include tx power level to True.
854        3. Get the attributes of the AdvertiseData object.
855        4. Compare the attributes found against the attributes exp.
856
857        Expected Result:
858        Found attributes should match expected attributes.
859
860        Returns:
861          True is pass
862          False if fail
863
864        TAGS: LE, Advertising
865        Priority: 1
866        """
867        self.log.debug("Step 1: Setup environment.")
868        droid = self.ad_dut.droid
869        exp_include_tx_power_level = True
870        self.log.debug(
871            "Step 2: Set the filtering data object's include tx power level: "
872            "{}".format(exp_include_tx_power_level))
873        return self.verify_adv_data_include_tx_power_level(
874            droid, exp_include_tx_power_level)
875
876    @BluetoothBaseTest.bt_test_wrap
877    def test_adv_data_set_include_tx_power_level_false(self):
878        """Tests advertisement data's include tx power level to False.
879
880        This advertisement data from "set" advertisement manufacturers data
881        should match the corresponding "get" function.
882
883        Steps:
884        1. Build a new AdvertiseData object.
885        2. Set the AdvertiseData's include tx power level to False.
886        3. Get the attributes of the AdvertiseData object.
887        4. Compare the attributes found against the attributes exp.
888
889        Expected Result:
890        Found attributes should match expected attributes.
891
892        Returns:
893          True is pass
894          False if fail
895
896        TAGS: LE, Advertising
897        Priority: 1
898        """
899        self.log.debug("Step 1: Setup environment.")
900        droid = self.ad_dut.droid
901        exp_include_tx_power_level = False
902        self.log.debug(
903            "Step 2: Set the filtering data object's include tx power level: {}"
904            .format(exp_include_tx_power_level))
905        return self.verify_adv_data_include_tx_power_level(
906            droid, exp_include_tx_power_level)
907
908    @BluetoothBaseTest.bt_test_wrap
909    def test_adv_data_set_include_device_name_true(self):
910        """Tests advertisement data's include device name to True.
911
912        This advertisement data from "set" advertisement manufacturers data
913        should match the corresponding "get" function.
914
915        Steps:
916        1. Build a new AdvertiseData object.
917        2. Set the AdvertiseData's include device name to True.
918        3. Get the attributes of the AdvertiseData object.
919        4. Compare the attributes found against the attributes exp.
920
921        Expected Result:
922        Found attributes should match expected attributes.
923
924        Returns:
925          True is pass
926          False if fail
927
928        TAGS: LE, Advertising
929        Priority: 1
930        """
931        self.log.debug("Step 1: Setup environment.")
932        droid = self.ad_dut.droid
933        exp_include_device_name = True
934        self.log.debug(
935            "Step 2: Set the filtering data object's include device name: {}"
936            .format(exp_include_device_name))
937        return self.verify_adv_data_include_device_name(
938            droid, exp_include_device_name)
939
940    @BluetoothBaseTest.bt_test_wrap
941    def test_adv_data_set_include_device_name_false(self):
942        """Tests advertisement data's include device name to False.
943
944        This advertisement data from "set" advertisement manufacturers data
945        should match the corresponding "get" function.
946
947        Steps:
948        1. Build a new AdvertiseData object.
949        2. Set the AdvertiseData's include device name to False.
950        3. Get the attributes of the AdvertiseData object.
951        4. Compare the attributes found against the attributes exp.
952
953        Expected Result:
954        Found attributes should match expected attributes.
955
956        Returns:
957          True is pass
958          False if fail
959
960        TAGS: LE, Advertising
961        Priority: 1
962        """
963        self.log.debug("Step 1: Setup environment.")
964        test_result = True
965        droid = self.ad_dut.droid
966        exp_include_device_name = False
967        self.log.debug(
968            "Step 2: Set the filtering data object's include device name: {}".format(
969                exp_include_device_name))
970        return self.verify_adv_data_include_device_name(
971            droid, exp_include_device_name)
972
973    @BluetoothBaseTest.bt_test_wrap
974    def test_advertisement_greater_than_31_bytes(self):
975        """Tests advertisement data's size to be greater than 31 bytes.
976
977        This advertisement data from "set" advertisement manufacturers data
978        should match the corresponding "get" function.
979
980        Steps:
981        1. Build a new AdvertiseData object.
982        2. Set the AdvertiseData's size to be greater than 31 bytes
983        3. Build the advertisement data.
984
985        Expected Result:
986        Api fails to build the AdvertiseData.
987
988        Returns:
989          True is pass
990          False if fail
991
992        TAGS: LE, Advertising
993        Priority: 1
994        """
995        test_result = True
996        droid = self.ad_dut.droid
997        ed = self.android_devices[0].ed
998        service_data = []
999        for i in range(25):
1000            service_data.append(i)
1001        droid.bleAddAdvertiseDataServiceData(
1002            "0000110D-0000-1000-8000-00805F9B34FB",
1003            service_data)
1004        advcallback, adv_data, adv_settings = generate_ble_advertise_objects(
1005            droid)
1006        droid.bleStartBleAdvertising(advcallback, adv_data, adv_settings)
1007        try:
1008            ed.pop_event(adv_fail.format(advcallback))
1009        except SL4AAPIError:
1010            self.log.info("{} event was not found.".format(adv_fail.format(
1011                advcallback)))
1012            return False
1013        return test_result
1014
1015    def verify_adv_settings_adv_mode(self, droid, exp_adv_mode):
1016        try:
1017            droid.bleSetAdvertiseSettingsAdvertiseMode(exp_adv_mode)
1018        except BleAdvertiseVerificationError as error:
1019            self.log.debug(str(error))
1020            return False
1021        self.log.debug("Step 3: Get a filtering settings object's index.")
1022        settings_index = droid.bleBuildAdvertiseSettings()
1023        self.log.debug("Step 4: Get the filtering setting's filtering mode.")
1024        adv_mode = droid.bleGetAdvertiseSettingsMode(settings_index)
1025        if exp_adv_mode is not adv_mode:
1026            self.log.debug("exp value: {}, Actual value: {}".format(
1027                exp_adv_mode, adv_mode))
1028            return False
1029        self.log.debug("Advertise Setting's filtering mode {} value "
1030                       "test Passed.".format(exp_adv_mode))
1031        return True
1032
1033    def verify_adv_settings_tx_power_level(self, droid, exp_adv_tx_power):
1034        try:
1035            droid.bleSetAdvertiseSettingsTxPowerLevel(exp_adv_tx_power)
1036        except BleAdvertiseVerificationError as error:
1037            self.log.debug(str(error))
1038            return False
1039        self.log.debug("Step 3: Get a filtering settings object's index.")
1040        settings_index = droid.bleBuildAdvertiseSettings()
1041        self.log.debug("Step 4: Get the filtering setting's tx power level.")
1042        adv_tx_power_level = droid.bleGetAdvertiseSettingsTxPowerLevel(
1043            settings_index)
1044        if exp_adv_tx_power is not adv_tx_power_level:
1045            self.log.debug("exp value: {}, Actual value: {}".format(
1046                exp_adv_tx_power, adv_tx_power_level))
1047            return False
1048        self.log.debug("Advertise Setting's tx power level {}"
1049                       "  value test Passed.".format(exp_adv_tx_power))
1050        return True
1051
1052    def verify_adv_settings_is_connectable(self, droid, exp_is_connectable):
1053        try:
1054            droid.bleSetAdvertiseSettingsIsConnectable(exp_is_connectable)
1055        except BleAdvertiseVerificationError as error:
1056            self.log.debug(str(error))
1057            return False
1058        self.log.debug("Step 3: Get a filtering settings object's index.")
1059        settings_index = droid.bleBuildAdvertiseSettings()
1060        self.log.debug(
1061            "Step 4: Get the filtering setting's is connectable value.")
1062        is_connectable = droid.bleGetAdvertiseSettingsIsConnectable(
1063            settings_index)
1064        if exp_is_connectable is not is_connectable:
1065            self.log.debug("exp value: {}, Actual value: {}".format(
1066                exp_is_connectable, is_connectable))
1067            return False
1068        self.log.debug("Advertise Setting's is connectable {}"
1069                       " value test Passed.".format(exp_is_connectable))
1070        return True
1071
1072    def verify_adv_data_service_uuids(self, droid, exp_service_uuids):
1073        try:
1074            droid.bleSetAdvertiseDataSetServiceUuids(exp_service_uuids)
1075        except BleAdvertiseVerificationError as error:
1076            self.log.debug(str(error))
1077            return False
1078        self.log.debug("Step 3: Get a filtering data object's index.")
1079        data_index = droid.bleBuildAdvertiseData()
1080        self.log.debug("Step 4: Get the filtering data's service uuids.")
1081        service_uuids = droid.bleGetAdvertiseDataServiceUuids(data_index)
1082        if exp_service_uuids != service_uuids:
1083            self.log.debug("exp value: {}, Actual value: {}".format(
1084                exp_service_uuids, service_uuids))
1085            return False
1086        self.log.debug(
1087            "Advertise Data's service uuids {}, value test Passed.".format(
1088                exp_service_uuids))
1089        return True
1090
1091    def verify_adv_data_service_data(self, droid, exp_service_data_uuid,
1092                                     exp_service_data):
1093        try:
1094            droid.bleAddAdvertiseDataServiceData(exp_service_data_uuid,
1095                                                 exp_service_data)
1096        except BleAdvertiseVerificationError as error:
1097            self.log.debug(str(error))
1098            return False
1099        self.log.debug("Step 3: Get a filtering data object's index.")
1100        data_index = droid.bleBuildAdvertiseData()
1101        self.log.debug("Step 4: Get the filtering data's service data.")
1102        service_data = droid.bleGetAdvertiseDataServiceData(
1103            data_index, exp_service_data_uuid)
1104        if exp_service_data != service_data:
1105            self.log.debug("exp value: {}, Actual value: {}".format(
1106                exp_service_data, service_data))
1107            return False
1108        self.log.debug("Advertise Data's service data uuid: {}, service data: "
1109                       "{}, value test Passed.".format(exp_service_data_uuid,
1110                                                       exp_service_data))
1111        return True
1112
1113    def verify_adv_data_manu_id(self, droid, exp_manu_id,
1114                                exp_manu_specific_data):
1115        try:
1116            droid.bleAddAdvertiseDataManufacturerId(exp_manu_id,
1117                                                    exp_manu_specific_data)
1118        except BleAdvertiseVerificationError as error:
1119            self.log.debug(str(error))
1120            return False
1121        self.log.debug("Step 3: Get a filtering data object's index.")
1122        data_index = droid.bleBuildAdvertiseData()
1123        self.log.debug("Step 5: Get the filtering data's manu specific data.")
1124        manu_specific_data = droid.bleGetAdvertiseDataManufacturerSpecificData(
1125            data_index, exp_manu_id)
1126        if exp_manu_specific_data != manu_specific_data:
1127            self.log.debug("exp value: " + str(exp_manu_specific_data) +
1128                           ", Actual value: " + str(manu_specific_data))
1129            return False
1130        self.log.debug("Advertise Data's manu id: " + str(exp_manu_id) +
1131                       ", manu's specific data: " + str(
1132                           exp_manu_specific_data) + "  value test Passed.")
1133        return True
1134
1135    def verify_adv_data_include_tx_power_level(self, droid,
1136                                               exp_include_tx_power_level):
1137        try:
1138            droid.bleSetAdvertiseDataIncludeTxPowerLevel(
1139                exp_include_tx_power_level)
1140        except BleAdvertiseVerificationError as error:
1141            self.log.debug(str(error))
1142            return False
1143        self.log.debug("Step 3: Get a filtering settings object's index.")
1144        data_index = droid.bleBuildAdvertiseData()
1145        self.log.debug(
1146            "Step 4: Get the filtering data's include tx power level.")
1147        include_tx_power_level = droid.bleGetAdvertiseDataIncludeTxPowerLevel(
1148            data_index)
1149        if exp_include_tx_power_level is not include_tx_power_level:
1150            self.log.debug("exp value: " + str(exp_include_tx_power_level) +
1151                           ", Actual value: " + str(include_tx_power_level))
1152            return False
1153        self.log.debug("Advertise Setting's include tx power level " + str(
1154            exp_include_tx_power_level) + "  value test Passed.")
1155        return True
1156
1157    def verify_adv_data_include_device_name(self, droid,
1158                                            exp_include_device_name):
1159        try:
1160            droid.bleSetAdvertiseDataIncludeDeviceName(exp_include_device_name)
1161        except BleAdvertiseVerificationError as error:
1162            self.log.debug(str(error))
1163            return False
1164        self.log.debug("Step 3: Get a filtering settings object's index.")
1165        data_index = droid.bleBuildAdvertiseData()
1166        self.log.debug("Step 4: Get the filtering data's include device name.")
1167        include_device_name = droid.bleGetAdvertiseDataIncludeDeviceName(
1168            data_index)
1169        if exp_include_device_name is not include_device_name:
1170            self.log.debug("exp value: {}, Actual value: {}".format(
1171                exp_include_device_name, include_device_name))
1172            return False
1173        self.log.debug("Advertise Setting's include device name {}"
1174                       " value test Passed.".format(exp_include_device_name))
1175        return True
1176
1177    def verify_invalid_adv_settings_adv_mode(self, droid, exp_adv_mode):
1178        try:
1179            droid.bleSetAdvertiseSettingsAdvertiseMode(exp_adv_mode)
1180            droid.bleBuildAdvertiseSettings()
1181            self.log.debug("Set Advertise settings invalid filtering mode "
1182                           "passed with input as {}".format(exp_adv_mode))
1183            return False
1184        except SL4AAPIError:
1185            self.log.debug("Set Advertise settings invalid filtering mode "
1186                           "failed successfully with input as {}".format(
1187                               exp_adv_mode))
1188            return True
1189
1190    def verify_invalid_adv_settings_tx_power_level(self, droid,
1191                                                   exp_adv_tx_power):
1192        try:
1193            droid.bleSetAdvertiseSettingsTxPowerLevel(exp_adv_tx_power)
1194            droid.bleBuildAdvertiseSettings()
1195            self.log.debug("Set Advertise settings invalid tx power level " +
1196                           " with input as {}".format(exp_adv_tx_power))
1197            return False
1198        except SL4AAPIError:
1199            self.log.debug("Set Advertise settings invalid tx power level "
1200                           "failed successfullywith input as {}".format(
1201                               exp_adv_tx_power))
1202            return True
1203
1204    def verify_invalid_adv_data_service_uuids(self, droid, exp_service_uuids):
1205        try:
1206            droid.bleSetAdvertiseDataSetServiceUuids(exp_service_uuids)
1207            droid.bleBuildAdvertiseData()
1208            self.log.debug("Set Advertise Data service uuids " +
1209                           " with input as {}".format(exp_service_uuids))
1210            return False
1211        except SL4AAPIError:
1212            self.log.debug("Set Advertise Data invalid service uuids failed "
1213                           "successfully with input as {}".format(
1214                               exp_service_uuids))
1215            return True
1216
1217    def verify_invalid_adv_data_service_data(
1218            self, droid, exp_service_data_uuid, exp_service_data):
1219        try:
1220            droid.bleAddAdvertiseDataServiceData(exp_service_data_uuid,
1221                                                 exp_service_data)
1222            droid.bleBuildAdvertiseData()
1223            self.log.debug("Set Advertise Data service data uuid: {},"
1224                           ", service data: {}".format(exp_service_data_uuid,
1225                                                       exp_service_data))
1226            return False
1227        except SL4AAPIError:
1228            self.log.debug("Set Advertise Data service data uuid: " + str(
1229                exp_service_data_uuid) + ", service data: " + str(
1230                    exp_service_data) + " failed successfully.")
1231            return True
1232
1233    def verify_invalid_adv_data_manu_id(self, droid, exp_manu_id,
1234                                        exp_manu_specific_data):
1235        try:
1236            droid.bleAddAdvertiseDataManufacturerId(exp_manu_id,
1237                                                    exp_manu_specific_data)
1238            droid.bleBuildAdvertiseData()
1239            self.log.debug("Set Advertise Data manu id: " + str(exp_manu_id) +
1240                           ", manu specific data: " + str(
1241                               exp_manu_specific_data))
1242            return False
1243        except SL4AAPIError:
1244            self.log.debug("Set Advertise Data manu id: {},"
1245                           " manu specific data: {},".format(
1246                               exp_manu_id, exp_manu_specific_data))
1247            return True
1248