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