1#!/usr/bin/env python3 2# 3# Copyright 2018 - The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of 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, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17from acts.controllers.fuchsia_lib.base_lib import BaseLib 18 19 20class FuchsiaBleLib(BaseLib): 21 def __init__(self, addr, tc, client_id): 22 self.address = addr 23 self.test_counter = tc 24 self.client_id = client_id 25 26 def bleStopBleAdvertising(self): 27 """BleStopAdvertising command 28 29 Returns: 30 Dictionary, None if success, error string if error. 31 """ 32 test_cmd = "ble_advertise_facade.BleStopAdvertise" 33 test_args = {} 34 test_id = self.build_id(self.test_counter) 35 self.test_counter += 1 36 37 return self.send_command(test_id, test_cmd, test_args) 38 39 def bleStartBleAdvertising(self, 40 advertising_data, 41 interval, 42 connectable=True): 43 """BleStartAdvertising command 44 45 Args: 46 advertising_data: dictionary, advertising data required for ble advertise. 47 interval: int, Advertising interval (in ms). 48 49 Returns: 50 Dictionary, None if success, error string if error. 51 """ 52 test_cmd = "ble_advertise_facade.BleAdvertise" 53 test_args = { 54 "advertising_data": advertising_data, 55 "interval_ms": interval, 56 "connectable": connectable 57 } 58 test_id = self.build_id(self.test_counter) 59 self.test_counter += 1 60 return self.send_command(test_id, test_cmd, test_args) 61 62 def blePublishService(self, id_, primary, type_, service_id): 63 """Publishes services specified by input args 64 65 Args: 66 id: string, Identifier of service. 67 primary: bool, Flag of service. 68 type: string, Canonical 8-4-4-4-12 uuid of service. 69 service_proxy_key: string, Unique identifier to specify where to publish service 70 71 Returns: 72 Dictionary, None if success, error if error. 73 """ 74 test_cmd = "bluetooth.BlePublishService" 75 test_args = { 76 "id": id_, 77 "primary": primary, 78 "type": type_, 79 "local_service_id": service_id 80 } 81 test_id = self.build_id(self.test_counter) 82 self.test_counter += 1 83 84 return self.send_command(test_id, test_cmd, test_args) 85