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#
15#  Licensed under the Apache License, Version 2.0 (the "License");
16#  you may not use this file except in compliance with the License.
17#  You may obtain a copy of the License at
18#
19#       http://www.apache.org/licenses/LICENSE-2.0
20#
21#  Unless required by applicable law or agreed to in writing, software
22#  distributed under the License is distributed on an "AS IS" BASIS,
23#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24#  See the License for the specific language governing permissions and
25#  limitations under the License.
26
27from utilities import constants
28from utilities.main_utils import common_main
29from utilities.common_utils import CommonUtils
30from bluetooth_sms_test import bluetooth_sms_base_test
31from mobly.controllers import android_device
32
33class SMSReadMessageDBSync(bluetooth_sms_base_test.BluetoothSMSBaseTest):
34
35    def setup_class(self):
36        super().setup_class()
37        self.common_utils = CommonUtils(self.target, self.discoverer)
38
39    def setup_test(self):
40
41        # pair the devices
42        self.bt_utils.pair_primary_to_secondary()
43
44        # wait for user permissions popup & give contacts and sms permissions
45        self.call_utils.wait_with_log(20)
46        self.common_utils.click_on_ui_element_with_text('Allow')
47
48        # Clearing the sms from the phone
49        self.call_utils.clear_sms_app(self.target)
50        # Reboot Phone
51        self.target.unload_snippet('mbs')
52        self.call_utils.reboot_device(self.target)
53        self.call_utils.wait_with_log(30)
54        self.target.load_snippet('mbs', android_device.MBS_PACKAGE)
55
56    def test_read_sms_messagedb_sync(self):
57        # Open the sms app
58        self.call_utils.open_sms_app()
59
60        # Verify that there is no new sms currently
61        #self.call_utils.verify_sms_app_unread_message(False)
62
63        # send a new sms
64        target_phone_number = self.target.mbs.getPhoneNumber()
65        self.phone_notpaired.mbs.sendSms(target_phone_number,constants.SMS_TEXT)
66        self.call_utils.wait_with_log(10)
67
68        # Verify the new UNREAD sms in IVI device
69        self.call_utils.open_sms_app()
70        self.call_utils.verify_sms_app_unread_message(True)
71
72        # READ the message on paired phone
73        self.call_utils.open_notification_on_phone(self.target)
74        self.call_utils.wait_with_log(5)
75        self.target.mbs.clickUIElementWithText(constants.SMS_TEXT)
76
77        # Verify the SYNC READ sms in IVI device
78        self.call_utils.press_home()
79        self.call_utils.open_sms_app()
80        self.call_utils.verify_sms_app_unread_message(False)
81        self.call_utils.verify_sms_preview_timestamp(True)
82
83    def teardown_test(self):
84         # Go to home screen
85         self.call_utils.press_home()
86         super().teardown_test()
87
88if __name__ == '__main__':
89  common_main()