1#!/usr/bin/env python3 2# 3# Copyright 2019 - 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 FuchsiaProfileServerLib(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 addService(self, record): 27 """Publishes an SDP service record specified by input args 28 29 Args: 30 record: A database that represents an SDP record to 31 be published. 32 33 Returns: 34 Dictionary, service id if success, error if error. 35 """ 36 test_cmd = "profile_server_facade.ProfileServerAddService" 37 test_args = { 38 "record": record, 39 } 40 test_id = self.build_id(self.test_counter) 41 self.test_counter += 1 42 43 return self.send_command(test_id, test_cmd, test_args) 44 45 def addSearch(self, attribute_list, profile_id): 46 """Publishes services specified by input args 47 48 Args: 49 attribute_list: The list of attributes to set 50 profile_id: The profile ID to set. 51 Returns: 52 Dictionary, None if success, error if error. 53 """ 54 test_cmd = "profile_server_facade.ProfileServerAddSearch" 55 test_args = { 56 "attribute_list": attribute_list, 57 "profile_id": profile_id 58 } 59 test_id = self.build_id(self.test_counter) 60 self.test_counter += 1 61 62 return self.send_command(test_id, test_cmd, test_args) 63 64 def removeService(self, service_id): 65 """Removes a service. 66 67 Args: 68 record: A database that represents an SDP record to 69 be published. 70 71 Returns: 72 Dictionary, None if success, error if error. 73 """ 74 test_cmd = "profile_server_facade.ProfileServerRemoveService" 75 test_args = { 76 "service_id": service_id, 77 } 78 test_id = self.build_id(self.test_counter) 79 self.test_counter += 1 80 81 return self.send_command(test_id, test_cmd, test_args) 82 83 def init(self): 84 """Initializes the ProfileServerFacade's proxy object. 85 86 No operations for SDP can be performed until this is initialized. 87 88 Returns: 89 Dictionary, None if success, error if error. 90 """ 91 test_cmd = "profile_server_facade.ProfileServerInit" 92 test_args = {} 93 test_id = self.build_id(self.test_counter) 94 self.test_counter += 1 95 96 return self.send_command(test_id, test_cmd, test_args) 97 98 def cleanUp(self): 99 """Cleans up all objects related to SDP. 100 101 Returns: 102 Dictionary, None if success, error if error. 103 """ 104 test_cmd = "profile_server_facade.ProfileServerCleanup" 105 test_args = {} 106 test_id = self.build_id(self.test_counter) 107 self.test_counter += 1 108 109 return self.send_command(test_id, test_cmd, test_args) 110 111 def connectL2cap(self, identifier, psm): 112 """ Sends an outgoing l2cap connection to a connected peer device. 113 114 Args: 115 psm: The psm value to connect over. Available PSMs: 116 SDP 0x0001 See Bluetooth Service Discovery Protocol (SDP) 117 RFCOMM 0x0003 See RFCOMM with TS 07.10 118 TCS-BIN 0x0005 See Bluetooth Telephony Control Specification / 119 TCS Binary 120 TCS-BIN-CORDLESS 0x0007 See Bluetooth Telephony Control 121 Specification / TCS Binary 122 BNEP 0x000F See Bluetooth Network Encapsulation Protocol 123 HID_Control 0x0011 See Human Interface Device 124 HID_Interrupt 0x0013 See Human Interface Device 125 UPnP 0x0015 See [ESDP] 126 AVCTP 0x0017 See Audio/Video Control Transport Protocol 127 AVDTP 0x0019 See Audio/Video Distribution Transport Protocol 128 AVCTP_Browsing 0x001B See Audio/Video Remote Control Profile 129 UDI_C-Plane 0x001D See the Unrestricted Digital Information 130 Profile [UDI] 131 ATT 0x001F See Bluetooth Core Specification 132 3DSP 0x0021 See 3D Synchronization Profile. 133 LE_PSM_IPSP 0x0023 See Internet Protocol Support Profile 134 (IPSP) 135 OTS 0x0025 See Object Transfer Service (OTS) 136 EATT 0x0027 See Bluetooth Core Specification 137 138 Returns: 139 Dictionary, None if success, error if error. 140 """ 141 test_cmd = "profile_server_facade.ProfileServerConnectL2cap" 142 test_args = {"identifier": identifier, "psm": psm} 143 test_id = self.build_id(self.test_counter) 144 self.test_counter += 1 145 146 return self.send_command(test_id, test_cmd, test_args) 147