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