• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3# Copyright (C) 2018 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 the
14# License for the specific language governing permissions and limitations under
15# the License.
16
17import time
18from acts import signals
19from acts.controllers.buds_lib import apollo_lib
20
21AVRCP_WAIT_TIME = 3
22
23
24def get_serial_object(pri_ad, serial_device):
25    """This function will creates object for serial device connected.
26
27    Args:
28        pri_ad: Android device.
29        serial_device: serial device connected.
30
31    Returns:
32        object of serial device, otherwise Abort the class.
33    """
34    devices = apollo_lib.get_devices()
35    for device in devices:
36        if device['serial_number'] in serial_device:
37            return apollo_lib.BudsDevice(device['serial_number'])
38    pri_ad.log.error('Apollo device not found')
39    raise signals.TestAbortAll('Apollo device not found')
40
41
42def avrcp_actions(pri_ad, buds_device):
43    """Performs avrcp controls like volume up, volume down
44
45    Args:
46        pri_ad: Android device.
47        buds_device: serial device object to perform avrcp actions.
48
49    Returns:
50        True if successful, otherwise otherwise raises Exception.
51    """
52    pri_ad.log.debug("Setting voume to 0")
53    pri_ad.droid.setMediaVolume(0)
54    current_volume = pri_ad.droid.getMediaVolume()
55    pri_ad.log.info('Current volume to {}'.format(current_volume))
56    for _ in range(5):
57        buds_device.volume('Up')
58        time.sleep(AVRCP_WAIT_TIME)
59    pri_ad.log.info('Volume increased to {}'.format(
60        pri_ad.droid.getMediaVolume()))
61    if current_volume == pri_ad.droid.getMediaVolume():
62        pri_ad.log.error('Increase volume failed')
63        raise signals.TestFailure("Increase volume failed")
64    current_volume = pri_ad.droid.getMediaVolume()
65    for _ in range(5):
66        buds_device.volume('Down')
67        time.sleep(AVRCP_WAIT_TIME)
68    pri_ad.log.info('Volume decreased to {}'.format(
69        pri_ad.droid.getMediaVolume()))
70    if current_volume == pri_ad.droid.getMediaVolume():
71        pri_ad.log.error('Decrease volume failed')
72        raise signals.TestFailure("Decrease volume failed")
73    return True
74