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 SMSUnreadMessageDBSyncTest(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        # send a new sms
56        target_phone_number = self.target.mbs.getPhoneNumber()
57        self.phone_notpaired.mbs.sendSms(target_phone_number,constants.SMS_TEXT)
58        self.call_utils.wait_with_log(10)
59
60    def test_unread_sms_message_db_sync(self):
61        # to test that the unread sms appears on phone after pairing
62
63        # Open the sms app
64        self.call_utils.open_sms_app()
65        # Perform the verifications
66        self.call_utils.verify_sms_app_unread_message(True)
67        self.call_utils.verify_sms_preview_text(True, constants.SMS_TEXT)
68        self.call_utils.verify_sms_preview_timestamp(True)
69
70    def teardown_test(self):
71        # Go to home screen
72        self.call_utils.press_home()
73        super().teardown_test()
74
75if __name__ == '__main__':
76    common_main()