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 16import re 17 18from bluetooth_test import bluetooth_base_test 19from mobly import asserts 20from utilities.media_utils import MediaUtils 21from utilities.common_utils import CommonUtils 22from utilities.main_utils import common_main 23 24TIMESTAMP_MATCHER = "^([0-5]?[0-9]):([0-5][0-9]):([0-5]?[0-9])$" 25 26 27class IsMediaMetadataOnHuValid(bluetooth_base_test.BluetoothBaseTest): 28 29 def setup_class(self): 30 super().setup_class() 31 self.media_utils = MediaUtils(self.target, self.discoverer) 32 self.common_utils = CommonUtils(self.target, self.discoverer) 33 34 def setup_test(self): 35 self.common_utils.grant_local_mac_address_permission() 36 self.common_utils.enable_wifi_on_phone_device() 37 self.bt_utils.pair_primary_to_secondary() 38 super().enable_recording() 39 self.media_utils.enable_bt_media_debugging_logs() 40 41 def test_is_media_metadata_valid_on_hu(self): 42 """Tests is media metadata on HU valid""" 43 self.media_utils.open_media_app_on_hu() 44 self.call_utils.handle_bluetooth_audio_pop_up() 45 self.media_utils.open_youtube_music_app() 46 current_phone_song_title = self.media_utils.get_song_title_from_phone() 47 self.media_utils.pause_media_on_hu() 48 self.media_utils.maximize_now_playing() 49 current_hu_song_title = self.media_utils.get_song_title_from_hu() 50 asserts.assert_true(current_phone_song_title == current_hu_song_title, 51 'Invalid song titles. ' 52 'Song title on phone device and HU should be the same') 53 phone_current_song_metadata = self.media_utils.get_song_metadata().split(',') 54 asserts.assert_true(len(phone_current_song_metadata) > 0, 55 'Phone Media metadata should not be empty') 56 actual_hu_artist_title = self.media_utils.get_artist_title_on_hu() 57 actual_phone_artist_title = phone_current_song_metadata[1].strip() 58 actual_hu_album_title = self.media_utils.get_album_title_on_hu() 59 actual_phone_album_title = phone_current_song_metadata[2].strip() 60 actual_current_song_playing_time = self.media_utils.get_current_song_playing_time_on_hu() 61 actual_current_song_max_playing_time = self.media_utils.get_current_song_max_playing_time_on_hu() 62 63 # Artist tile validation 64 asserts.assert_true( 65 actual_hu_artist_title == actual_phone_artist_title, 66 'Artist title should be the same on HU and phone device.\nHU Artist title: ' 67 '<' + actual_hu_artist_title + '>\nPhone Artist title: ' 68 '<' + actual_phone_artist_title + '>') 69 70 # Album title validation 71 asserts.assert_true( 72 actual_hu_album_title == actual_phone_album_title, 73 'Album title should be the same on HU and phone device.\nHU Album title: ' 74 '<' + actual_hu_album_title + '>\nPhone Album title: ' 75 '<' + actual_phone_album_title + '>') 76 77 # Timestamp pattern validation 78 asserts.assert_true( 79 re.match(TIMESTAMP_MATCHER, actual_current_song_playing_time), 80 'Invalid song playing time. Timestamp should match with RegEx: ' 81 '<' + TIMESTAMP_MATCHER + '>\nActual current playing timestamp on HU: ' 82 '<' + actual_current_song_playing_time + '>') 83 asserts.assert_true( 84 re.match(TIMESTAMP_MATCHER, actual_current_song_max_playing_time), 85 'Invalid song max playing time. Timestamp should match with RegEx: ' 86 '<' + TIMESTAMP_MATCHER + '>\nActual current max playing timestamp on HU: ' 87 '<' + actual_current_song_max_playing_time + '>') 88 89 def teardown_test(self): 90 self.media_utils.get_bt_dumpsys_metadata() 91 # Minimize now_playing 92 self.media_utils.minimize_now_playing() 93 # Close YouTube Music app 94 self.media_utils.close_youtube_music_app() 95 self.call_utils.press_home() 96 super().teardown_test() 97 98 99if __name__ == '__main__': 100 common_main() 101