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 time 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 23 24 25class IsMediaSynchronizedForReconnectedDevice(bluetooth_base_test.BluetoothBaseTest): 26 27 def setup_class(self): 28 super().setup_class() 29 self.media_utils = MediaUtils(self.target, self.discoverer) 30 self.common_utils = CommonUtils(self.target, self.discoverer) 31 32 def setup_test(self): 33 self.common_utils.grant_local_mac_address_permission() 34 self.common_utils.enable_wifi_on_phone_device() 35 self.bt_utils.pair_primary_to_secondary() 36 super().enable_recording() 37 self.media_utils.enable_bt_media_debugging_logs() 38 39 def test_is_media_synchronized_after_reconnect_device(self): 40 """Tests validating is Media data synchronized after reconnect device""" 41 # Validate current song is playing on both devices 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 # Disable BT on HU 52 self.call_utils.open_bluetooth_palette() 53 self.bt_utils.click_on_use_bluetooth_toggle() 54 self.call_utils.open_bluetooth_palette() 55 # Assert <Bluetooth Audio disconnected> label is present 56 asserts.assert_true(self.call_utils.is_bluetooth_audio_disconnected_label_visible(), 57 '<Bluetooth Audio disconnected> label should be present') 58 # Enable BT on HU 59 self.discoverer.mbs.btEnable() 60 self.call_utils.wait_with_log(5) 61 # Assert <Bluetooth Audio disconnected> label is NOT present 62 asserts.assert_false(self.call_utils.is_bluetooth_audio_disconnected_label_visible(), 63 '<Bluetooth Audio disconnected> label should be present') 64 # Assert song title same on both devices after reconnect 65 current_next_phone_song_title = self.media_utils.get_song_title_from_phone() 66 current_next_hu_song_title = self.media_utils.get_song_title_from_hu() 67 asserts.assert_true(current_next_phone_song_title == current_next_hu_song_title, 68 'Invalid song titles. ' 69 'Song title on phone device and HU should be the same') 70 71 def teardown_test(self): 72 self.media_utils.get_bt_dumpsys_metadata() 73 # Close YouTube Music app 74 self.media_utils.close_youtube_music_app() 75 self.call_utils.press_home() 76 super().teardown_test() 77 78 79if __name__ == '__main__': 80 common_main() 81