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.common_utils import CommonUtils 21from utilities.main_utils import common_main 22from utilities import constants 23from utilities.video_utils_service import VideoRecording 24 25 26class IsAbleToSwitchAppTest(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 Target device") 38 self.video_utils_service_target.enable_screen_recording() 39 self.common_utils.enable_wifi_on_phone_device() 40 self.bt_utils.pair_primary_to_secondary() 41 42 def test_media_is_able_to_switch_app(self): 43 """Tests validating song title on HU after switch media app""" 44 self.media_utils.open_media_app_on_hu() 45 self.media_utils.open_youtube_music_app() 46 current_phone_song_title = self.media_utils.get_song_title_from_phone() 47 current_hu_song_title = self.media_utils.get_song_title_from_hu() 48 asserts.assert_true(current_phone_song_title == current_hu_song_title, 49 'Invalid song titles. ' 50 'Song title on phone device and HU should be the same') 51 52 # Open Media apps menu 53 self.media_utils.open_media_apps_menu() 54 55 # Assert YouTube Music and Bluetooth Audio apps are present 56 asserts.assert_true( 57 self.common_utils.has_ui_element_with_text(constants.BLUETOOTH_AUDIO_APP), 58 '<' + constants.BLUETOOTH_AUDIO_APP + '> app should be present on Media app page') 59 asserts.assert_true( 60 self.common_utils.has_ui_element_with_text(constants.YOUTUBE_MUSIC_APP), 61 '<' + constants.YOUTUBE_MUSIC_APP + '> app should be present on Media app page') 62 63 # Open YouTube Music app on HU 64 self.media_utils.open_youtube_music_app_on_hu() 65 current_phone_next_song_title = self.media_utils.get_song_title_from_phone() 66 current_hu_next_song_title = self.media_utils.get_song_title_from_hu() 67 asserts.assert_true(current_phone_next_song_title == current_hu_next_song_title, 68 'Invalid song titles. ' 69 'Song title on phone device and HU should be the same') 70 71 # Open Media apps menu 72 self.media_utils.open_media_apps_menu() 73 self.media_utils.open_bluetooth_audio_app_on_hu() 74 current_phone_bt_audio_song_title = self.media_utils.get_song_title_from_phone() 75 current_hu_bt_audio_song_title = self.media_utils.get_song_title_from_hu() 76 asserts.assert_true(current_phone_bt_audio_song_title == current_hu_bt_audio_song_title, 77 'Invalid song titles. ' 78 'Song title on phone device and HU should be the same') 79 80 81 def teardown_test(self): 82 # Close YouTube Music app 83 self.media_utils.close_youtube_music_app() 84 self.call_utils.press_home() 85 logging.info("Stopping the screen recording on Target") 86 self.video_utils_service_target.stop_screen_recording() 87 logging.info("Pull the screen recording from Target") 88 self.video_utils_service_target.pull_recording_file(self.log_path) 89 logging.info("delete the screen recording from the Target") 90 self.video_utils_service_target.delete_screen_recording_from_device() 91 super().teardown_test() 92 93 94if __name__ == '__main__': 95 common_main() 96