1"""Wifi Direct tests.""" 2 3 4from mobly import asserts 5from mobly import test_runner 6from utils import android_base_test 7from utils import assert_utils 8 9SSID = 'SSID' 10# The time period that SSID needs to be found. 11SCAN_TIMEOUT = 30 12# The listen channel and operation channel for wifi direct. 13CHANNEL = 1 14# The frequency of wifi direct to be expected. 15FREQUENCY = 2412 16 17 18class WifiDirectTest(android_base_test.AndroidBaseTest): 19 """Wifi Direct tests.""" 20 21 def setup_class(self): 22 super(WifiDirectTest, self).setup_class() 23 self.station = self.dut_a 24 self.group_owner = self.dut_b 25 # Sets the tag that represents this device in logs. 26 self.station.debug_tag = 'station' 27 self.group_owner.debug_tag = 'group_owner' 28 29 def setup_test(self): 30 # Make sure wifi of group owner is off to disable wifi direct. 31 self.group_owner.android.wifiDisable() 32 # Make sure wifi is on. 33 self.station.android.wifiEnable() 34 self.group_owner.android.wifiEnable() 35 36 def test_wifi_direct_legacy_connection(self): 37 """Test for basic Wifi Direct process flow. 38 39 Steps: 40 1. Group owner sets up a wifi p2p group. 41 2. Station connects to the group as a regular hotspot. 42 43 Verifies: 44 Station can connect to the wifi p2p group created by group owner. 45 """ 46 callback = self.group_owner.android.wifiP2pSetChannel(CHANNEL, CHANNEL) 47 assert_utils.AssertAsyncSuccess(callback) 48 self.group_owner.log.info('Wifi direct channel set.') 49 callback = self.group_owner.android.wifiP2pStartGroup() 50 group_info = assert_utils.AssertAsyncSuccess(callback) 51 self.group_owner.log.info('Wifi direct group started as a temporary group.') 52 network_found = self.station.android.wifiScanAndFindSsid( 53 group_info.data[SSID], SCAN_TIMEOUT) 54 asserts.assert_true(network_found, 'Network is not found within 30 seconds') 55 asserts.assert_equal(network_found['frequency'], FREQUENCY) 56 self.station.log.info('Network is found, connecting...') 57 connect_result = self.station.android.wifiConnectByUpdate( 58 group_info.data[SSID], group_info.data['Password']) 59 asserts.assert_true(connect_result, 'Failed to connect to the network') 60 self.station.log.info('Connected to the network') 61 callback = self.group_owner.android.wifiP2pRemoveGroup() 62 assert_utils.AssertAsyncSuccess(callback) 63 self.group_owner.log.info('Wifi direct group removed') 64 65 def teardown_test(self): 66 # Turn wifi off on both devices after test finishes. 67 self.station.android.wifiDisable() 68 self.group_owner.android.wifiDisable() 69 70 71if __name__ == '__main__': 72 test_runner.main() 73