1#!/usr/bin/env python3 2# 3# Copyright 2021 - 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 FuchsiaHfpLib(BaseLib): 21 22 def __init__(self, addr: str) -> None: 23 super().__init__(addr, "hfp") 24 25 def init(self): 26 """Initializes the HFP service. 27 28 Returns: 29 Dictionary, None if success, error if error. 30 """ 31 test_cmd = "hfp_facade.HfpInit" 32 test_args = {} 33 34 return self.send_command(test_cmd, test_args) 35 36 def removeService(self): 37 """Removes the HFP service from the Fuchsia device 38 39 Returns: 40 Dictionary, None if success, error if error. 41 """ 42 test_cmd = "hfp_facade.HfpRemoveService" 43 test_args = {} 44 45 return self.send_command(test_cmd, test_args) 46 47 def listPeers(self): 48 """List all connected HFP peer devices. 49 50 Returns: 51 Dictionary, None if success, error if error. 52 """ 53 test_cmd = "hfp_facade.ListPeers" 54 test_args = {} 55 56 return self.send_command(test_cmd, test_args) 57 58 def setActivePeer(self, peer_id): 59 """Set the active HFP peer device. All peer specific commands will be 60 directed to this device. 61 62 Args: 63 peer_id: The id of the peer to set as active. Use "listPeers" to 64 find connected peer ids. 65 66 Returns: 67 Dictionary, None if success, error if error. 68 """ 69 test_cmd = "hfp_facade.SetActivePeer" 70 test_args = {"peer_id": peer_id} 71 72 return self.send_command(test_cmd, test_args) 73 74 def listCalls(self): 75 """List all calls known to the sl4f component. 76 77 Returns: 78 Dictionary, None if success, error if error. 79 """ 80 test_cmd = "hfp_facade.ListCalls" 81 test_args = {} 82 83 return self.send_command(test_cmd, test_args) 84 85 def newCall(self, remote, state, direction): 86 """Opens a new call channel and alerts the HFP peer. 87 88 Args: 89 remote: The number of the remote party. 90 state: The state of the call. 91 direction: The direction of the call. Can be "incoming" or "outgoing". 92 93 Returns: 94 Dictionary, call_id if success, error if error. 95 """ 96 test_cmd = "hfp_facade.NewCall" 97 test_args = {"remote": remote, "state": state, "direction": direction} 98 99 return self.send_command(test_cmd, test_args) 100 101 def initiateIncomingCall(self, remote): 102 """Opens an incoming call channel and alerts the HFP peer. 103 104 Args: 105 remote: The number of the remote party. 106 107 Returns: 108 Dictionary, call_id if success, error if error. 109 """ 110 test_cmd = "hfp_facade.IncomingCall" 111 test_args = {"remote": remote} 112 113 return self.send_command(test_cmd, test_args) 114 115 def initiateIncomingWaitingCall(self, remote): 116 """Opens an incoming call when there is an onging call and alerts 117 the HFP peer. 118 119 Args: 120 remote: The number of the remote party. 121 122 Returns: 123 Dictionary, call_id if success, error if error. 124 """ 125 test_cmd = "hfp_facade.IncomingWaitingCall" 126 test_args = {"remote": remote} 127 128 return self.send_command(test_cmd, test_args) 129 130 def initiateOutgoingCall(self, remote): 131 """Opens an outgoing call channel and alerts the HFP peer. 132 133 Args: 134 remote: The number of the remote party. 135 136 Returns: 137 Dictionary, call_id if success, error if error. 138 """ 139 test_cmd = "hfp_facade.OutgoingCall" 140 test_args = {"remote": remote} 141 142 return self.send_command(test_cmd, test_args) 143 144 def setCallActive(self, call_id): 145 """Sets the specified call to the "OngoingActive" state. 146 147 Args: 148 call_id: The unique id of the call. 149 150 Returns: 151 Dictionary, None if success, error if error. 152 """ 153 test_cmd = "hfp_facade.SetCallActive" 154 test_args = {"call_id": call_id} 155 156 return self.send_command(test_cmd, test_args) 157 158 def setCallHeld(self, call_id): 159 """Sets the specified call to the "OngoingHeld" state. 160 161 Args: 162 call_id: The unique id of the call. 163 164 Returns: 165 Dictionary, None if success, error if error. 166 """ 167 test_cmd = "hfp_facade.SetCallHeld" 168 test_args = {"call_id": call_id} 169 170 return self.send_command(test_cmd, test_args) 171 172 def setCallTerminated(self, call_id): 173 """Sets the specified call to the "Terminated" state. 174 175 Args: 176 call_id: The unique id of the call. 177 178 Returns: 179 Dictionary, None if success, error if error. 180 """ 181 test_cmd = "hfp_facade.SetCallTerminated" 182 test_args = {"call_id": call_id} 183 184 return self.send_command(test_cmd, test_args) 185 186 def setCallTransferredToAg(self, call_id): 187 """Sets the specified call to the "TransferredToAg" state. 188 189 Args: 190 call_id: The unique id of the call. 191 192 Returns: 193 Dictionary, None if success, error if error. 194 """ 195 test_cmd = "hfp_facade.SetCallTransferredToAg" 196 test_args = {"call_id": call_id} 197 198 return self.send_command(test_cmd, test_args) 199 200 def setSpeakerGain(self, value): 201 """Sets the active peer's speaker gain. 202 203 Args: 204 value: The gain value to set. Must be between 0-15 inclusive. 205 206 Returns: 207 Dictionary, None if success, error if error. 208 """ 209 test_cmd = "hfp_facade.SetSpeakerGain" 210 test_args = {"value": value} 211 212 return self.send_command(test_cmd, test_args) 213 214 def setMicrophoneGain(self, value): 215 """Sets the active peer's microphone gain. 216 217 Args: 218 value: The gain value to set. Must be between 0-15 inclusive. 219 220 Returns: 221 Dictionary, None if success, error if error. 222 """ 223 test_cmd = "hfp_facade.SetMicrophoneGain" 224 test_args = {"value": value} 225 226 return self.send_command(test_cmd, test_args) 227 228 def setServiceAvailable(self, value): 229 """Sets the simulated network service status reported by the call manager. 230 231 Args: 232 value: True to set the network service to available. 233 234 Returns: 235 Dictionary, None if success, error if error. 236 """ 237 test_cmd = "hfp_facade.SetServiceAvailable" 238 test_args = {"value": value} 239 240 return self.send_command(test_cmd, test_args) 241 242 def setRoaming(self, value): 243 """Sets the simulated roaming status reported by the call manager. 244 245 Args: 246 value: True to set the network connection to roaming. 247 248 Returns: 249 Dictionary, None if success, error if error. 250 """ 251 test_cmd = "hfp_facade.SetRoaming" 252 test_args = {"value": value} 253 254 return self.send_command(test_cmd, test_args) 255 256 def setSignalStrength(self, value): 257 """Sets the simulated signal strength reported by the call manager. 258 259 Args: 260 value: The signal strength value to set. Must be between 0-5 inclusive. 261 262 Returns: 263 Dictionary, None if success, error if error. 264 """ 265 test_cmd = "hfp_facade.SetSignalStrength" 266 test_args = {"value": value} 267 268 return self.send_command(test_cmd, test_args) 269 270 def setSubscriberNumber(self, value): 271 """Sets the subscriber number reported by the call manager. 272 273 Args: 274 value: The subscriber number to set. Maximum length 128 characters. 275 276 Returns: 277 Dictionary, None if success, error if error. 278 """ 279 test_cmd = "hfp_facade.SetSubscriberNumber" 280 test_args = {"value": value} 281 282 return self.send_command(test_cmd, test_args) 283 284 def setOperator(self, value): 285 """Sets the operator value reported by the call manager. 286 287 Args: 288 value: The operator value to set. Maximum length 16 characters. 289 290 Returns: 291 Dictionary, None if success, error if error. 292 """ 293 test_cmd = "hfp_facade.SetOperator" 294 test_args = {"value": value} 295 296 return self.send_command(test_cmd, test_args) 297 298 def setNrecSupport(self, value): 299 """Sets the noise reduction/echo cancelation support reported by the call manager. 300 301 Args: 302 value: The nrec support bool. 303 304 Returns: 305 Dictionary, None if success, error if error. 306 """ 307 test_cmd = "hfp_facade.SetNrecSupport" 308 test_args = {"value": value} 309 310 return self.send_command(test_cmd, test_args) 311 312 def setBatteryLevel(self, value): 313 """Sets the battery level reported by the call manager. 314 315 Args: 316 value: The integer battery level value. Must be 0-5 inclusive. 317 318 Returns: 319 Dictionary, None if success, error if error. 320 """ 321 test_cmd = "hfp_facade.SetBatteryLevel" 322 test_args = {"value": value} 323 324 return self.send_command(test_cmd, test_args) 325 326 def setLastDialed(self, number): 327 """Sets the last dialed number in the call manager. 328 329 Args: 330 number: The number of the remote party. 331 332 Returns: 333 Dictionary, None if success, error if error. 334 """ 335 test_cmd = "hfp_facade.SetLastDialed" 336 test_args = {"number": number} 337 338 return self.send_command(test_cmd, test_args) 339 340 def clearLastDialed(self): 341 """Clears the last dialed number in the call manager. 342 343 Returns: 344 Dictionary, None if success, error if error. 345 """ 346 test_cmd = "hfp_facade.ClearLastDialed" 347 test_args = {} 348 349 return self.send_command(test_cmd, test_args) 350 351 def setMemoryLocation(self, location, number): 352 """Sets a memory location to point to a remote number. 353 354 Args: 355 location: The memory location at which to store the number. 356 number: The number of the remote party to be stored. 357 358 Returns: 359 Dictionary, None if success, error if error. 360 """ 361 test_cmd = "hfp_facade.SetMemoryLocation" 362 test_args = {"location": location, "number": number} 363 364 return self.send_command(test_cmd, test_args) 365 366 def clearMemoryLocation(self, location): 367 """Clear a memory location so that it no longer points to a remote 368 number. 369 370 Args: 371 localtion: The memory location to clear. 372 373 Returns: 374 Dictionary, None if success, error if error. 375 """ 376 test_cmd = "hfp_facade.ClearMemoryLocation" 377 test_args = {"location": location} 378 379 return self.send_command(test_cmd, test_args) 380 381 def setDialResult(self, number, status): 382 """Sets the status result to be returned when the number is dialed. 383 384 Args: 385 number: The number of the remote party. 386 status: The status to be returned when an outgoing call is 387 initiated to the number. 388 389 Returns: 390 Dictionary, None if success, error if error. 391 """ 392 test_cmd = "hfp_facade.SetDialResult" 393 test_args = {"number": number, "status": status} 394 395 return self.send_command(test_cmd, test_args) 396 397 def getState(self): 398 """Get the call manager's state. 399 400 Returns: 401 Dictionary, State dictionary if success, error if error. 402 """ 403 test_cmd = "hfp_facade.GetState" 404 test_args = {} 405 406 return self.send_command(test_cmd, test_args) 407 408 def setConnectionBehavior(self, autoconnect): 409 """Set the Service Level Connection behavior when a new peer connects. 410 411 Args: 412 autoconnect: Enable/Disable autoconnection of SLC. 413 414 Returns: 415 Dictionary, None if success, error if error. 416 """ 417 test_cmd = "hfp_facade.SetConnectionBehavior" 418 test_args = {"autoconnect": autoconnect} 419 420 return self.send_command(test_cmd, test_args) 421