blob: e99a914f45d9a5d9af449da56c69e6d9b502dbd6 [file] [log] [blame]
Etan Cohence1e8162017-10-25 12:49:13 -07001#!/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
Etan Cohen42ed3842017-12-18 13:07:00 -080018from acts import utils
Etan Cohenf1405832018-04-11 17:41:20 -070019from acts.test_decorators import test_tracker_info
Etan Cohence1e8162017-10-25 12:49:13 -070020from acts.test_utils.wifi.rtt import rtt_const as rconsts
21from acts.test_utils.wifi.rtt import rtt_test_utils as rutils
22from acts.test_utils.wifi.rtt.RttBaseTest import RttBaseTest
23
24
Etan Cohend0ae4d32017-10-26 16:29:19 -070025class RttDisableTest(RttBaseTest):
26 """Test class for RTT ranging enable/disable flows."""
Etan Cohence1e8162017-10-25 12:49:13 -070027
Etan Cohen42ed3842017-12-18 13:07:00 -080028 MODE_DISABLE_WIFI = 0
29 MODE_ENABLE_DOZE = 1
30 MODE_DISABLE_LOCATIONING = 2
31
Etan Cohence1e8162017-10-25 12:49:13 -070032 def __init__(self, controllers):
33 RttBaseTest.__init__(self, controllers)
34
Etan Cohen42ed3842017-12-18 13:07:00 -080035 def run_disable_rtt(self, disable_mode):
Etan Cohend0ae4d32017-10-26 16:29:19 -070036 """Validate the RTT disabled flows: whether by disabling Wi-Fi or entering
37 doze mode.
38
39 Args:
Etan Cohen42ed3842017-12-18 13:07:00 -080040 disable_mode: The particular mechanism in which RTT is disabled. One of
41 the MODE_* constants.
Etan Cohend0ae4d32017-10-26 16:29:19 -070042 """
Etan Cohence1e8162017-10-25 12:49:13 -070043 dut = self.android_devices[0]
44
45 # validate start-up conditions
46 asserts.assert_true(dut.droid.wifiIsRttAvailable(), "RTT is not available")
47
48 # scan to get some APs to be used later
Etan Cohenb6911252018-05-25 16:57:45 -070049 all_aps = rutils.select_best_scan_results(rutils.scan_networks(dut),
50 select_count=1)
Etan Cohence1e8162017-10-25 12:49:13 -070051 asserts.assert_true(len(all_aps) > 0, "Need at least one visible AP!")
52
Etan Cohend0ae4d32017-10-26 16:29:19 -070053 # disable RTT and validate broadcast & API
Etan Cohen42ed3842017-12-18 13:07:00 -080054 if disable_mode == self.MODE_DISABLE_WIFI:
Etan Cohenbb50a3c2018-02-15 15:39:22 -080055 # disabling Wi-Fi is not sufficient: since scan mode (and hence RTT) will
56 # remain enabled - we need to disable the Wi-Fi chip aka Airplane Mode
57 asserts.assert_true(utils.force_airplane_mode(dut, True),
58 "Can not turn on airplane mode on: %s" % dut.serial)
Etan Cohen42ed3842017-12-18 13:07:00 -080059 elif disable_mode == self.MODE_ENABLE_DOZE:
Etan Cohendbe2c172018-02-01 15:05:32 -080060 asserts.assert_true(utils.enable_doze(dut), "Can't enable doze")
Etan Cohen42ed3842017-12-18 13:07:00 -080061 elif disable_mode == self.MODE_DISABLE_LOCATIONING:
62 utils.set_location_service(dut, False)
63
Etan Cohence1e8162017-10-25 12:49:13 -070064 rutils.wait_for_event(dut, rconsts.BROADCAST_WIFI_RTT_NOT_AVAILABLE)
65 asserts.assert_false(dut.droid.wifiIsRttAvailable(), "RTT is available")
66
67 # request a range and validate error
68 id = dut.droid.wifiRttStartRangingToAccessPoints(all_aps[0:1])
69 event = rutils.wait_for_event(dut, rutils.decorate_event(
70 rconsts.EVENT_CB_RANGING_ON_FAIL, id))
71 asserts.assert_equal(event["data"][rconsts.EVENT_CB_RANGING_KEY_STATUS],
72 rconsts.RANGING_FAIL_CODE_RTT_NOT_AVAILABLE,
73 "Invalid error code")
74
Etan Cohend0ae4d32017-10-26 16:29:19 -070075 # enable RTT and validate broadcast & API
Etan Cohen42ed3842017-12-18 13:07:00 -080076 if disable_mode == self.MODE_DISABLE_WIFI:
Etan Cohenbb50a3c2018-02-15 15:39:22 -080077 asserts.assert_true(utils.force_airplane_mode(dut, False),
78 "Can not turn off airplane mode on: %s" % dut.serial)
Etan Cohen42ed3842017-12-18 13:07:00 -080079 elif disable_mode == self.MODE_ENABLE_DOZE:
Etan Cohendbe2c172018-02-01 15:05:32 -080080 asserts.assert_true(utils.disable_doze(dut), "Can't disable doze")
Etan Cohen42ed3842017-12-18 13:07:00 -080081 elif disable_mode == self.MODE_DISABLE_LOCATIONING:
82 utils.set_location_service(dut, True)
83
Etan Cohence1e8162017-10-25 12:49:13 -070084 rutils.wait_for_event(dut, rconsts.BROADCAST_WIFI_RTT_AVAILABLE)
85 asserts.assert_true(dut.droid.wifiIsRttAvailable(), "RTT is not available")
Etan Cohend0ae4d32017-10-26 16:29:19 -070086
87 ############################################################################
88
Etan Cohenf1405832018-04-11 17:41:20 -070089 @test_tracker_info(uuid="498c49ab-a188-4612-998d-c47b35ff285e")
Etan Cohend0ae4d32017-10-26 16:29:19 -070090 def test_disable_wifi(self):
91 """Validate that getting expected broadcast when Wi-Fi is disabled and that
92 any range requests are rejected."""
Etan Cohen42ed3842017-12-18 13:07:00 -080093 self.run_disable_rtt(self.MODE_DISABLE_WIFI)
Etan Cohend0ae4d32017-10-26 16:29:19 -070094
Etan Cohenf1405832018-04-11 17:41:20 -070095 @test_tracker_info(uuid="f71f731f-4aaf-402b-8595-db94b625b544")
Etan Cohend0ae4d32017-10-26 16:29:19 -070096 def test_enable_doze(self):
97 """Validate that getting expected broadcast when RTT is disabled due to doze
98 mode and that any range requests are rejected."""
Etan Cohen42ed3842017-12-18 13:07:00 -080099 self.run_disable_rtt(self.MODE_ENABLE_DOZE)
100
Etan Cohenf1405832018-04-11 17:41:20 -0700101 @test_tracker_info(uuid="6a1c83a8-9eaf-49db-b547-5131cba0eafe")
Etan Cohen42ed3842017-12-18 13:07:00 -0800102 def test_disable_location(self):
103 """Validate that getting expected broadcast when locationing is disabled and
104 that any range requests are rejected."""
105 self.run_disable_rtt(self.MODE_DISABLE_LOCATIONING)