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
16from utilities import constants
17from mobly import asserts
18from utilities.main_utils import common_main
19from utilities.common_utils import CommonUtils
20from bluetooth_sms_test import bluetooth_sms_base_test
21from mobly.controllers import android_device
22
23
24class UxRestrictionPlayUnreadMessageWhileDrivingTest(bluetooth_sms_base_test.BluetoothSMSBaseTest):
25
26  def setup_class(self):
27    super().setup_class()
28    self.common_utils = CommonUtils(self.target, self.discoverer)
29
30    # pair the devices
31    self.bt_utils.pair_primary_to_secondary()
32
33  def setup_test(self):
34
35    # wait for user permissions popup & give contacts and sms permissions
36    self.call_utils.wait_with_log(20)
37    self.common_utils.click_on_ui_element_with_text('Allow')
38
39    # Clearing the sms from the phone
40    self.call_utils.clear_sms_app(self.target)
41
42    # Reboot Phone
43    self.target.unload_snippet('mbs')
44    self.call_utils.reboot_device(self.target)
45    self.call_utils.wait_with_log(30)
46    self.target.load_snippet('mbs', android_device.MBS_PACKAGE)
47
48    #set driving mode
49    self.call_utils.enable_driving_mode()
50
51  def test_play_new_unread_sms(self):
52    # To test that new unread sms plays on HU
53
54    # Open the sms app
55    self.call_utils.open_sms_app()
56
57    # Verify that there is no new sms currently
58    self.call_utils.verify_sms_app_unread_message(False)
59
60    # Send a new sms
61    target_phone_number = self.target.mbs.getPhoneNumber()
62    self.phone_notpaired.mbs.sendSms(target_phone_number,constants.SMS_TEXT)
63    self.call_utils.wait_with_log(constants.BT_DEFAULT_TIMEOUT)
64
65    # Perform the verifications
66    self.call_utils.verify_sms_app_unread_message(True)
67    self.call_utils.verify_sms_preview_timestamp(True)
68
69    # Tap on Received Text message to read it aloud
70    self.call_utils.tap_to_read_aloud()
71
72    # Check whether the Assistant transcription plate displayed upon tapping
73    asserts.assert_true(self.call_utils.is_assistant_sms_transcription_plate_displayed(True),
74                        'Assistant SMS Transcription plate has not opened upon tapping the SMS')
75    self.call_utils.is_assistant_sms_transcription_plate_displayed(True)
76  def teardown_test(self):
77    # Go to home screen
78    self.call_utils.press_home()
79    #Disable driving mode
80    self.call_utils.disable_driving_mode()
81
82  def teardown_class(self):
83    super().teardown_test()
84
85if __name__ == '__main__':
86  common_main()