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