1"""
2  Copyright (C) 2023 The Android Open Source Project
3
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7
8       http://www.apache.org/licenses/LICENSE-2.0
9
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15
16
17
18  Test Steps:
191. Call to Paired Mobile Device from remote phone call
202. Verify that HUN appears to 'Accept' or 'Decline' the call
213. Tap on 'Answer' to receive  the call
224. Call to Paired Mobile Device from remote phone call
235. Verify that HUN appears to 'Accept' or 'Decline' the call
246. Tap on 'Decline' to end  the call
25
26"""
27
28from bluetooth_sms_test import bluetooth_sms_base_test
29from utilities import constants
30from utilities import phone_device_utils
31from utilities.main_utils import common_main
32from utilities.common_utils import CommonUtils
33
34
35from mobly import asserts
36
37class UxRestrictionReceiveAnswerDeclineCallTest(bluetooth_sms_base_test.BluetoothSMSBaseTest):
38
39  def setup_class(self):
40    super().setup_class()
41    self.phone_utils = (phone_device_utils.PhoneDeviceUtils(self.phone_notpaired))
42    self.common_utils = CommonUtils(self.target, self.discoverer)
43
44    # pair the devices
45    self.bt_utils.pair_primary_to_secondary()
46
47    # wait for user permissions popup & give contacts and sms permissions
48    self.call_utils.wait_with_log(20)
49    self.common_utils.click_on_ui_element_with_text('Allow')
50
51  def setup_test(self):
52    # set driving mode
53    self.call_utils.enable_driving_mode()
54
55  def test_answer_incoming_call(self):
56
57    # call from the unpaired phone to the paired phone
58    callee_number = self.target.mbs.getPhoneNumber()
59    self.phone_utils.call_number_from_home_screen(callee_number)
60    self.call_utils.wait_with_log(constants.DEFAULT_WAIT_TIME_FIFTEEN_SECS)
61
62    # Confirm the 'Answer' call button is onscreen
63    asserts.assert_true(
64        self.discoverer.mbs.hasUIElementWithText(constants.ANSWER_CALL_TEXT),
65        "Expected \'Answer\' button to be in HU while call was incoming, but found none.")
66
67    # Answer the call
68    self.discoverer.mbs.clickUIElementWithText(constants.ANSWER_CALL_TEXT)
69    self.call_utils.wait_with_log(constants.WAIT_FOR_LOAD)
70
71    # Confirm that call is ongoing
72    asserts.assert_true(
73        self.discoverer.mbs.isOngoingCallDisplayedOnHome(),
74        "Expected an ongoing call to be displayed on home, but found none."
75    )
76    # End call
77    self.call_utils.end_call_using_adb_command(self.phone_notpaired)
78  def test_reject_incoming_call(self):
79
80    self.call_utils.press_phone_home_icon_using_adb_command(self.phone_notpaired)
81    # call from the unpaired phone to the paired phone
82    callee_number = self.target.mbs.getPhoneNumber()
83    self.phone_utils.call_number_from_home_screen(callee_number)
84    self.call_utils.wait_with_log(constants.DEFAULT_WAIT_TIME_FIFTEEN_SECS)
85
86    # Confirm the 'Decline' call button is onscreen
87    asserts.assert_true(
88        self.discoverer.mbs.hasUIElementWithText(constants.DECLINE_CALL_TEXT),
89        "Expected \'Decline\' button to be in HU while call was incoming, but found none.")
90
91    # reject the call
92    self.discoverer.mbs.clickUIElementWithText(constants.DECLINE_CALL_TEXT)
93    self.call_utils.wait_with_log(constants.WAIT_FOR_LOAD)
94
95    # Confirm that no call is ongoing
96    asserts.assert_false(
97        self.discoverer.mbs.isOngoingCallDisplayedOnHome(),
98        "Expected no ongoing call to be displayed on home after Declining call, but found one."
99    )
100
101  def teardown_test(self):
102    # End call if test failed
103    self.call_utils.end_call_using_adb_command(self.phone_notpaired)
104    #Disable driving mode
105    self.call_utils.disable_driving_mode()
106  def teardown_class(self):
107    super().teardown_test()
108
109if __name__ == '__main__':
110  common_main()