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.main_utils import common_main 21from utilities.common_utils import CommonUtils 22from mobly.controllers import android_device 23from utilities.video_utils_service import VideoRecording 24 25 26class IsDeviceSyncedAfterHuStart(bluetooth_base_test.BluetoothBaseTest): 27 28 def setup_class(self): 29 super().setup_class() 30 self.media_utils = MediaUtils(self.target, self.discoverer) 31 self.common_utils = CommonUtils(self.target, self.discoverer) 32 33 def setup_test(self): 34 self.common_utils.grant_local_mac_address_permission() 35 self.common_utils.enable_wifi_on_phone_device() 36 self.bt_utils.pair_primary_to_secondary() 37 self.media_utils.enable_bt_media_debugging_logs() 38 39 def test_is_hu_synced_after_hu_start(self): 40 """Tests validating is media synced after HU start""" 41 # Reboot HU 42 self.discoverer.unload_snippet('mbs') 43 self.discoverer.reboot() 44 self.call_utils.wait_with_log(10) 45 self.video_utils_service.enable_screen_recording() 46 self.media_utils.enable_bt_media_debugging_logs() 47 self.media_utils.open_youtube_music_app() 48 self.call_utils.wait_with_log(30) 49 self.discoverer.load_snippet('mbs', android_device.MBS_PACKAGE) 50 current_phone_song_title = self.media_utils.get_song_title_from_phone() 51 self.media_utils.open_media_app_on_hu() 52 self.call_utils.handle_bluetooth_audio_pop_up() 53 current_hu_song_title = self.media_utils.get_song_title_from_hu() 54 asserts.assert_true(self.media_utils.is_song_playing_on_hu(), 55 'Song should be playing after HU reboot') 56 asserts.assert_true(current_phone_song_title == current_hu_song_title, 57 'Invalid song titles. ' 58 'Song title on phone device and HU should be the same') 59 60 def teardown_test(self): 61 62 63 # Close YouTube Music app 64 self.media_utils.close_youtube_music_app() 65 self.call_utils.press_home() 66 super().teardown_no_video_recording() 67 68 69if __name__ == '__main__': 70 common_main() 71