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 logging.info("\tInitializing video services on Target") 36 self.video_utils_service_target = VideoRecording(self.target,self.__class__.__name__) 37 logging.info("Enabling video recording for phone Target") 38 self.video_utils_service_target.enable_screen_recording() 39 40 self.common_utils.enable_wifi_on_phone_device() 41 self.bt_utils.pair_primary_to_secondary() 42 43 def test_is_song_playing_after_reboot(self): 44 """Tests validating is song playing on HU after reboot HU""" 45 self.media_utils.open_media_app_on_hu() 46 self.media_utils.open_youtube_music_app() 47 current_phone_song_title = self.media_utils.get_song_title_from_phone() 48 current_hu_song_title = self.media_utils.get_song_title_from_hu() 49 asserts.assert_true(current_phone_song_title == current_hu_song_title, 50 'Invalid song titles. ' 51 'Song title on phone device and HU should be the same') 52 53 # Reboot HU 54 self.discoverer.unload_snippet('mbs') 55 super().hu_recording_handler() 56 self.discoverer.reboot() 57 self.call_utils.wait_with_log(30) 58 self.discoverer.load_snippet('mbs', android_device.MBS_PACKAGE) 59 60 logging.info("\tInitializing video services on HU post reboot") 61 self.video_utils_service = VideoRecording(self.discoverer, self.__class__.__name__) 62 logging.info("Enabling video recording for HU post reboot") 63 self.video_utils_service.enable_screen_recording() 64 65 self.media_utils.open_media_app_on_hu() 66 # Assert song is playing after HU reboot 67 asserts.assert_true(self.media_utils.is_song_playing_on_hu(), 68 'Song should be playing after HU reboot') 69 # Assert song title same on both devices after HU reboot 70 current_next_phone_song_title = self.media_utils.get_song_title_from_phone() 71 current_next_hu_song_title = self.media_utils.get_song_title_from_hu() 72 asserts.assert_true(current_next_phone_song_title == current_next_hu_song_title, 73 'Invalid song titles. ' 74 'Song title on phone device and HU should be the same') 75 76 def teardown_test(self): 77 # Close YouTube Music app 78 self.media_utils.close_youtube_music_app() 79 self.call_utils.press_home() 80 logging.info("Stopping the screen recording on Target") 81 self.video_utils_service_target.stop_screen_recording() 82 logging.info("Pull the screen recording from Target") 83 self.video_utils_service_target.pull_recording_file(self.log_path) 84 logging.info("delete the screen recording from the Target") 85 self.video_utils_service_target.delete_screen_recording_from_device() 86 super().teardown_test() 87 88 89if __name__ == '__main__': 90 common_main() 91