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 IsAbleToPlayMediaFromWidgetTest(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        super().enable_recording()
36        self.media_utils.enable_bt_media_debugging_logs()
37
38    def test_media_is_song_playing(self):
39        """Tests validating play/pause media 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        logging.info("Getting song title from phone device: %s", self.media_utils.get_song_title_from_phone())
44        self.media_utils.press_pause_song_button()
45        self.call_utils.wait_with_log(3)
46        asserts.assert_false(self.media_utils.is_song_playing_on_hu(),
47                             'Media player should be on PAUSE mode')
48        self.media_utils.play_media_on_hu()
49        self.call_utils.wait_with_log(3)
50        asserts.assert_true(self.media_utils.is_song_playing_on_hu(),
51                            'Media player should be on PLAY mode')
52
53    def teardown_test(self):
54        self.media_utils.get_bt_dumpsys_metadata()
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