1#!/usr/bin/python3.4 2# 3# Copyright 2017 - 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 acts import asserts 18from acts import utils 19from acts.test_decorators import test_tracker_info 20from acts_contrib.test_utils.wifi.rtt import rtt_const as rconsts 21from acts_contrib.test_utils.wifi.rtt import rtt_test_utils as rutils 22from acts_contrib.test_utils.wifi.rtt.RttBaseTest import RttBaseTest 23from acts_contrib.test_utils.wifi.WifiBaseTest import WifiBaseTest 24 25 26class RttDisableTest(WifiBaseTest, RttBaseTest): 27 """Test class for RTT ranging enable/disable flows.""" 28 29 MODE_DISABLE_WIFI = 0 30 MODE_ENABLE_DOZE = 1 31 MODE_DISABLE_LOCATIONING = 2 32 33 def setup_test(self): 34 RttBaseTest.setup_test(self) 35 36 def setup_class(self): 37 super().setup_class() 38 if "AccessPoint" in self.user_params: 39 self.legacy_configure_ap_and_start() 40 elif "OpenWrtAP" in self.user_params: 41 self.configure_openwrt_ap_and_start(open_network=True) 42 43 def run_disable_rtt(self, disable_mode): 44 """Validate the RTT disabled flows: whether by disabling Wi-Fi or entering 45 doze mode. 46 47 Args: 48 disable_mode: The particular mechanism in which RTT is disabled. One of 49 the MODE_* constants. 50 """ 51 dut = self.android_devices[0] 52 53 # validate start-up conditions 54 asserts.assert_true(dut.droid.wifiIsRttAvailable(), 55 "RTT is not available") 56 57 # scan to get some APs to be used later 58 all_aps = rutils.select_best_scan_results( 59 rutils.scan_networks(dut), select_count=1) 60 asserts.assert_true(len(all_aps) > 0, "Need at least one visible AP!") 61 62 # disable RTT and validate broadcast & API 63 if disable_mode == self.MODE_DISABLE_WIFI: 64 # disabling Wi-Fi is not sufficient: since scan mode (and hence RTT) will 65 # remain enabled - we need to disable the Wi-Fi chip aka Airplane Mode 66 asserts.assert_true( 67 utils.force_airplane_mode(dut, True), 68 "Can not turn on airplane mode on: %s" % dut.serial) 69 elif disable_mode == self.MODE_ENABLE_DOZE: 70 asserts.assert_true(utils.enable_doze(dut), "Can't enable doze") 71 elif disable_mode == self.MODE_DISABLE_LOCATIONING: 72 utils.set_location_service(dut, False) 73 74 rutils.wait_for_event(dut, rconsts.BROADCAST_WIFI_RTT_NOT_AVAILABLE) 75 asserts.assert_false(dut.droid.wifiIsRttAvailable(), 76 "RTT is available") 77 78 # request a range and validate error 79 id = dut.droid.wifiRttStartRangingToAccessPoints(all_aps[0:1]) 80 event = rutils.wait_for_event( 81 dut, rutils.decorate_event(rconsts.EVENT_CB_RANGING_ON_FAIL, id)) 82 asserts.assert_equal( 83 event["data"][rconsts.EVENT_CB_RANGING_KEY_STATUS], 84 rconsts.RANGING_FAIL_CODE_RTT_NOT_AVAILABLE, "Invalid error code") 85 86 # enable RTT and validate broadcast & API 87 if disable_mode == self.MODE_DISABLE_WIFI: 88 asserts.assert_true( 89 utils.force_airplane_mode(dut, False), 90 "Can not turn off airplane mode on: %s" % dut.serial) 91 elif disable_mode == self.MODE_ENABLE_DOZE: 92 asserts.assert_true(utils.disable_doze(dut), "Can't disable doze") 93 elif disable_mode == self.MODE_DISABLE_LOCATIONING: 94 utils.set_location_service(dut, True) 95 96 rutils.wait_for_event(dut, rconsts.BROADCAST_WIFI_RTT_AVAILABLE) 97 asserts.assert_true(dut.droid.wifiIsRttAvailable(), 98 "RTT is not available") 99 100 ############################################################################ 101 102 @test_tracker_info(uuid="498c49ab-a188-4612-998d-c47b35ff285e") 103 def test_disable_wifi(self): 104 """Validate that getting expected broadcast when Wi-Fi is disabled and that 105 any range requests are rejected.""" 106 self.run_disable_rtt(self.MODE_DISABLE_WIFI) 107 108 @test_tracker_info(uuid="f71f731f-4aaf-402b-8595-db94b625b544") 109 def test_enable_doze(self): 110 """Validate that getting expected broadcast when RTT is disabled due to doze 111 mode and that any range requests are rejected.""" 112 self.run_disable_rtt(self.MODE_ENABLE_DOZE) 113 114 @test_tracker_info(uuid="6a1c83a8-9eaf-49db-b547-5131cba0eafe") 115 def test_disable_location(self): 116 """Validate that getting expected broadcast when locationing is disabled and 117 that any range requests are rejected.""" 118 self.run_disable_rtt(self.MODE_DISABLE_LOCATIONING) 119