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  Test Steps:
18        1) Precall state check on Seahawk and phone devices.
19        2) Upload contacts.vcf to device.
20        3) Add the contact as favorite
21        4) Assert the contact is added to favorites
22        5) Remove the contact form favorites
23        6) Verify contact is removed from the favorites
24"""
25
26from bluetooth_test import bluetooth_base_test
27
28from utilities import constants
29from utilities.main_utils import common_main
30from mobly import asserts
31
32class AddRemoveFavoriteContact(bluetooth_base_test.BluetoothBaseTest):
33  """Enable and Disable Bluetooth from Bluetooth Palette."""
34
35  def setup_test(self):
36    """Setup steps before any test is executed."""
37
38    # Upload contacts to phone device
39    file_path = constants.PATH_TO_CONTACTS_VCF_FILE
40    self.call_utils.upload_vcf_contacts_to_device(self.target, file_path)
41
42    self.call_utils.wait_with_log(5)
43    # Pair caller phone with automotive device
44    self.bt_utils.pair_primary_to_secondary()
45    super().enable_recording()
46
47  def test_add_remove_favorite_contact(self):
48    """Tests add remove favorite contact."""
49    contact_name = "Adam Allen"
50    self.call_utils.open_phone_app()
51
52    # Adding the contacts to favorites from the favorites tab and verifying it
53    self.call_utils.add_favorites_from_favorites_tab(
54        contact_name)
55    asserts.assert_true(self.discoverer.mbs.hasUIElementWithText(contact_name),
56                        'Favorite contact should be displayed on Favorites Tab')
57    self.discoverer.mbs.clickUIElementWithText(contact_name)
58
59    self.call_utils.wait_with_log(2)
60    self.call_utils.is_ongoing_call_displayed_on_home(True)
61    self.call_utils.open_phone_app_from_home()
62    asserts.assert_true(self.discoverer.mbs.hasUIElementWithText(contact_name),
63                        'Favorite contact should be displayed on homescreen during call')
64
65    self.call_utils.end_call()
66    self.call_utils.is_contact_in_favorites(
67        contact_name, True)
68    self.call_utils.wait_with_log(10)
69
70    # Removing the contacts from favorites and verifying it
71    self.call_utils.open_details_page(contact_name)
72    self.call_utils.add_remove_favorite_contact()
73    self.call_utils.close_details_page()
74    self.call_utils.is_contact_in_favorites(
75        contact_name, False)
76
77  def teardown_test(self):
78      # End call if test failed
79    self.call_utils.end_call_using_adb_command(self.target)
80    self.call_utils.wait_with_log(5)
81    self.call_utils.press_home()
82    super().teardown_test()
83
84if __name__ == '__main__':
85    common_main()