1#!/usr/bin/env python3 2# 3# Copyright 2022 - The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17from blueberry.tests.gd.cert.truth import assertThat 18from blueberry.tests.topshim.lib.topshim_base_test import TopshimBaseTest 19from blueberry.tests.topshim.lib.adapter_client import AdapterClient 20 21from mobly import test_runner 22 23 24class SuspendTest(TopshimBaseTest): 25 26 def __verify_no_wake_suspend(self): 27 # Start suspend work 28 self.dut().clear_event_mask() 29 self.dut().clear_event_filter() 30 self.dut().clear_filter_accept_list() 31 self.dut().stop_advertising() 32 self.dut().stop_scanning() 33 self.dut().disconnect_all_acls() 34 self.dut().le_rand() 35 36 def __verify_no_wake_resume(self): 37 # Start resume work 38 self.dut().set_default_event_mask_except(0, 0) 39 self.dut().set_event_filter_inquiry_result_all_devices() 40 self.dut().set_event_filter_connection_setup_all_devices() 41 self.dut().le_rand() 42 43 def __verify_wakeful_suspend(self, is_a2dp_connected): 44 self.dut().clear_event_mask() 45 self.dut().clear_event_filter() 46 self.dut().clear_filter_accept_list() 47 self.dut().stop_advertising() 48 self.dut().stop_scanning() 49 if is_a2dp_connected: 50 # self.media_server.disconnect_a2dp() 51 pass 52 self.dut().disconnect_all_acls() 53 self.dut().allow_wake_by_hid() 54 self.dut().le_rand() 55 56 def __verify_wakeful_resume(self, was_a2dp_connected): 57 # Start resume work 58 self.dut().set_default_event_mask_except(0, 0) 59 self.dut().set_event_filter_inquiry_result_all_devices() 60 self.dut().set_event_filter_connection_setup_all_devices() 61 if was_a2dp_connected: 62 # restore filter accept list? 63 self.dut().restore_filter_accept_list() 64 # reconnect a2dp 65 # self.media_server.reconnect_last_a2dp() 66 # self.gatt.restart_all_previous_advertising() 67 self.dut().start_advertising() 68 self.dut().le_rand() 69 70 def test_no_wake_suspend(self): 71 self.__verify_no_wake_suspend() 72 73 def test_no_wake_resume(self): 74 self.__verify_no_wake_resume() 75 76 def test_no_wake_suspend_then_resume(self): 77 self.__verify_no_wake_suspend() 78 self.__verify_no_wake_resume() 79 80 def test_no_wake_suspend_then_resume_then_suspend(self): 81 self.__verify_no_wake_suspend() 82 self.__verify_no_wake_resume() 83 self.__verify_no_wake_suspend() 84 85 def test_wakeful_suspend_no_a2dp(self): 86 self.__verify_wakeful_suspend(False) 87 88 def test_wakeful_resume_no_a2dp(self): 89 self.__verify_wakeful_resume(False) 90 91 def test_wakeful_suspend_then_resume_no_a2dp(self): 92 self.__verify_wakeful_suspend(False) 93 self.__verify_wakeful_resume(False) 94 95 def test_wakeful_suspend_then_resume_then_suspend_no_a2dp(self): 96 self.__verify_wakeful_suspend(False) 97 self.__verify_wakeful_resume(False) 98 self.__verify_wakeful_suspend(False) 99 100 101if __name__ == "__main__": 102 test_runner.main() 103