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