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
53    #set driving mode
54    self.call_utils.enable_driving_mode()
55
56  def test_answer_incoming_call(self):
57
58    # call from the unpaired phone to the paired phone
59    callee_number = self.target.mbs.getPhoneNumber()
60    self.phone_utils.call_number_from_home_screen(callee_number)
61    self.call_utils.wait_with_log(constants.DEFAULT_WAIT_TIME_FIFTEEN_SECS)
62
63    # Confirm the 'Answer' call button is onscreen
64    asserts.assert_true(
65        self.discoverer.mbs.hasUIElementWithText(constants.ANSWER_CALL_TEXT),
66        "Expected \'Answer\' button to be in HU while call was incoming, but found none.")
67
68    # Answer the call
69    self.discoverer.mbs.clickUIElementWithText(constants.ANSWER_CALL_TEXT)
70    self.call_utils.wait_with_log(constants.WAIT_FOR_LOAD)
71
72    # Confirm that call is ongoing
73    asserts.assert_true(
74        self.discoverer.mbs.isOngoingCallDisplayedOnHome(),
75        "Expected an ongoing call to be displayed on home, but found none."
76    )
77    # End call
78    self.call_utils.end_call_using_adb_command(self.phone_notpaired)
79  def test_reject_incoming_call(self):
80
81    self.call_utils.press_phone_home_icon_using_adb_command(self.phone_notpaired)
82    # call from the unpaired phone to the paired phone
83    callee_number = self.target.mbs.getPhoneNumber()
84    self.phone_utils.call_number_from_home_screen(callee_number)
85    self.call_utils.wait_with_log(constants.DEFAULT_WAIT_TIME_FIFTEEN_SECS)
86
87    # Confirm the 'Decline' call button is onscreen
88    asserts.assert_true(
89        self.discoverer.mbs.hasUIElementWithText(constants.DECLINE_CALL_TEXT),
90        "Expected \'Decline\' button to be in HU while call was incoming, but found none.")
91
92    # reject the call
93    self.discoverer.mbs.clickUIElementWithText(constants.DECLINE_CALL_TEXT)
94    self.call_utils.wait_with_log(constants.WAIT_FOR_LOAD)
95
96    # Confirm that no call is ongoing
97    asserts.assert_false(
98        self.discoverer.mbs.isOngoingCallDisplayedOnHome(),
99        "Expected no ongoing call to be displayed on home after Declining call, but found one."
100    )
101
102  def teardown_test(self):
103    # End call if test failed
104    self.call_utils.end_call_using_adb_command(self.phone_notpaired)
105    #Disable driving mode
106    self.call_utils.disable_driving_mode()
107  def teardown_class(self):
108    super().teardown_test()
109
110if __name__ == '__main__':
111  common_main()