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 mobly.controllers import android_device 22from utilities.common_utils import CommonUtils 23from utilities.video_utils_service import VideoRecording 24 25 26class IsSongPLayingAfterRebootTest(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 super().enable_recording() 39 40 def test_is_song_playing_after_reboot(self): 41 """Tests validating is song playing on HU after reboot HU""" 42 self.media_utils.open_media_app_on_hu() 43 self.call_utils.handle_bluetooth_audio_pop_up() 44 self.media_utils.open_youtube_music_app() 45 current_phone_song_title = self.media_utils.get_song_title_from_phone() 46 current_hu_song_title = self.media_utils.get_song_title_from_hu() 47 asserts.assert_true(current_phone_song_title == current_hu_song_title, 48 'Invalid song titles. ' 49 'Song title on phone device and HU should be the same') 50 51 # Reboot HU 52 self.discoverer.unload_snippet('mbs') 53 self.discoverer.reboot() 54 self.call_utils.wait_with_log(30) 55 self.discoverer.load_snippet('mbs', android_device.MBS_PACKAGE) 56 self.media_utils.enable_bt_media_debugging_logs() 57 self.media_utils.open_media_app_on_hu() 58 self.call_utils.handle_bluetooth_audio_pop_up() 59 # Assert song is playing after HU reboot 60 asserts.assert_true(self.media_utils.is_song_playing_on_hu(), 61 'Song should be playing after HU reboot') 62 # Assert song title same on both devices after HU reboot 63 current_next_phone_song_title = self.media_utils.get_song_title_from_phone() 64 current_next_hu_song_title = self.media_utils.get_song_title_from_hu() 65 asserts.assert_true(current_next_phone_song_title == current_next_hu_song_title, 66 'Invalid song titles. ' 67 'Song title on phone device and HU should be the same') 68 69 def teardown_test(self): 70 self.media_utils.get_bt_dumpsys_metadata() 71 # Close YouTube Music app 72 self.media_utils.close_youtube_music_app() 73 self.call_utils.press_home() 74 super().teardown_no_video_recording() 75 76 77if __name__ == '__main__': 78 common_main() 79