xref: /aosp_15_r20/platform_testing/tests/automotive/mobly_tests/utilities/phone_device_utils.py (revision dd0948b35e70be4c0246aabd6c72554a5eb8b22a)
1#  Copyright (C) 2023 The Android Open Source Project
2#
3#  Licensed under the Apache License, Version 2.0 (the "License");
4#  you may not use this file except in compliance with the License.
5#  You may obtain a copy of the License at
6#
7#       http://www.apache.org/licenses/LICENSE-2.0
8#
9#  Unless required by applicable law or agreed to in writing, software
10#  distributed under the License is distributed on an "AS IS" BASIS,
11#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12#  See the License for the specific language governing permissions and
13#  limitations under the License.
14
15import logging
16import re
17import time
18
19from mobly.controllers import android_device
20from utilities import constants
21
22class PhoneDeviceUtils:
23    """Utility for controlling individual mobile device
24
25    This class provides functions that execute generic call sequences.
26
27    """
28    def __init__(self, phone_device):
29        self.phone_device = phone_device
30
31    def call_number_from_home_screen(self, number):
32        """Assumes the phone is on its home screen.
33        Opens the phone app, then dial pad, enters the given number, and starts a call"""
34        self.phone_device.mbs.pressPhoneIcon()
35        logging.info("Close the video call popup on Phone")
36        self.phone_device.mbs.clickUIElementWithText(constants.NOT_NOW_TEXT)
37        isDialPadOpen = self.phone_device.mbs.isDialPadOpen()
38        logging.info("Check if the dial pad is already open: %s", isDialPadOpen)
39        if not isDialPadOpen :
40            logging.info("Opening the dial pad now")
41            self.phone_device.mbs.pressDialpadIcon()
42        logging.info("Dial pad should be open now %s :", self.phone_device.mbs.isDialPadOpen())
43        logging.info("Calling %s from phone device" % number)
44        self.phone_device.mbs.enterNumberOnDialpad(number)
45        self.phone_device.mbs.pressCallButton()