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
15import logging
16
17from bluetooth_test import bluetooth_base_test
18from mobly import asserts
19from utilities.media_utils import MediaUtils
20from utilities.common_utils import CommonUtils
21from utilities.main_utils import common_main
22
23
24class IsNowPlayingLabelDisplayed(bluetooth_base_test.BluetoothBaseTest):
25
26    def setup_class(self):
27        super().setup_class()
28        self.media_utils = MediaUtils(self.target, self.discoverer)
29        self.common_utils = CommonUtils(self.target, self.discoverer)
30
31    def setup_test(self):
32        self.common_utils.grant_local_mac_address_permission()
33        self.common_utils.enable_wifi_on_phone_device()
34        self.bt_utils.pair_primary_to_secondary()
35        self.media_utils.enable_bt_media_debugging_logs()
36        super().enable_recording()
37
38    def test_is_now_paying_label_displayed(self):
39        """Tests is Now Playing label displayed on HU"""
40        self.media_utils.open_media_app_on_hu()
41        self.call_utils.handle_bluetooth_audio_pop_up()
42        self.media_utils.open_youtube_music_app()
43        self.call_utils.wait_with_log(5)
44        logging.info("Getting song title from phone device: %s", self.media_utils.get_song_title_from_phone())
45        self.media_utils.pause_media_on_hu()
46        self.media_utils.maximize_now_playing()
47        self.call_utils.wait_with_log(5)
48        asserts.assert_true(self.media_utils.is_now_playing_label_displayed(),
49                            '<Now Playing> label should be displayed')
50
51    def teardown_test(self):
52        self.media_utils.get_bt_dumpsys_metadata()
53        # Minimize now_playing
54        self.media_utils.minimize_now_playing()
55        # Close YouTube Music app
56        self.media_utils.close_youtube_music_app()
57        self.call_utils.press_home()
58        super().teardown_test()
59
60
61if __name__ == '__main__':
62    common_main()
63