Etan Cohen | ce1e816 | 2017-10-25 12:49:13 -0700 | [diff] [blame] | 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 | |
| 17 | from acts import asserts |
Etan Cohen | 42ed384 | 2017-12-18 13:07:00 -0800 | [diff] [blame] | 18 | from acts import utils |
Etan Cohen | f140583 | 2018-04-11 17:41:20 -0700 | [diff] [blame] | 19 | from acts.test_decorators import test_tracker_info |
Etan Cohen | ce1e816 | 2017-10-25 12:49:13 -0700 | [diff] [blame] | 20 | from acts.test_utils.wifi.rtt import rtt_const as rconsts |
| 21 | from acts.test_utils.wifi.rtt import rtt_test_utils as rutils |
| 22 | from acts.test_utils.wifi.rtt.RttBaseTest import RttBaseTest |
| 23 | |
| 24 | |
Etan Cohen | d0ae4d3 | 2017-10-26 16:29:19 -0700 | [diff] [blame] | 25 | class RttDisableTest(RttBaseTest): |
| 26 | """Test class for RTT ranging enable/disable flows.""" |
Etan Cohen | ce1e816 | 2017-10-25 12:49:13 -0700 | [diff] [blame] | 27 | |
Etan Cohen | 42ed384 | 2017-12-18 13:07:00 -0800 | [diff] [blame] | 28 | MODE_DISABLE_WIFI = 0 |
| 29 | MODE_ENABLE_DOZE = 1 |
| 30 | MODE_DISABLE_LOCATIONING = 2 |
| 31 | |
Etan Cohen | ce1e816 | 2017-10-25 12:49:13 -0700 | [diff] [blame] | 32 | def __init__(self, controllers): |
| 33 | RttBaseTest.__init__(self, controllers) |
| 34 | |
Etan Cohen | 42ed384 | 2017-12-18 13:07:00 -0800 | [diff] [blame] | 35 | def run_disable_rtt(self, disable_mode): |
Etan Cohen | d0ae4d3 | 2017-10-26 16:29:19 -0700 | [diff] [blame] | 36 | """Validate the RTT disabled flows: whether by disabling Wi-Fi or entering |
| 37 | doze mode. |
| 38 | |
| 39 | Args: |
Etan Cohen | 42ed384 | 2017-12-18 13:07:00 -0800 | [diff] [blame] | 40 | disable_mode: The particular mechanism in which RTT is disabled. One of |
| 41 | the MODE_* constants. |
Etan Cohen | d0ae4d3 | 2017-10-26 16:29:19 -0700 | [diff] [blame] | 42 | """ |
Etan Cohen | ce1e816 | 2017-10-25 12:49:13 -0700 | [diff] [blame] | 43 | 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 Cohen | b691125 | 2018-05-25 16:57:45 -0700 | [diff] [blame^] | 49 | all_aps = rutils.select_best_scan_results(rutils.scan_networks(dut), |
| 50 | select_count=1) |
Etan Cohen | ce1e816 | 2017-10-25 12:49:13 -0700 | [diff] [blame] | 51 | asserts.assert_true(len(all_aps) > 0, "Need at least one visible AP!") |
| 52 | |
Etan Cohen | d0ae4d3 | 2017-10-26 16:29:19 -0700 | [diff] [blame] | 53 | # disable RTT and validate broadcast & API |
Etan Cohen | 42ed384 | 2017-12-18 13:07:00 -0800 | [diff] [blame] | 54 | if disable_mode == self.MODE_DISABLE_WIFI: |
Etan Cohen | bb50a3c | 2018-02-15 15:39:22 -0800 | [diff] [blame] | 55 | # 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 Cohen | 42ed384 | 2017-12-18 13:07:00 -0800 | [diff] [blame] | 59 | elif disable_mode == self.MODE_ENABLE_DOZE: |
Etan Cohen | dbe2c17 | 2018-02-01 15:05:32 -0800 | [diff] [blame] | 60 | asserts.assert_true(utils.enable_doze(dut), "Can't enable doze") |
Etan Cohen | 42ed384 | 2017-12-18 13:07:00 -0800 | [diff] [blame] | 61 | elif disable_mode == self.MODE_DISABLE_LOCATIONING: |
| 62 | utils.set_location_service(dut, False) |
| 63 | |
Etan Cohen | ce1e816 | 2017-10-25 12:49:13 -0700 | [diff] [blame] | 64 | 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 Cohen | d0ae4d3 | 2017-10-26 16:29:19 -0700 | [diff] [blame] | 75 | # enable RTT and validate broadcast & API |
Etan Cohen | 42ed384 | 2017-12-18 13:07:00 -0800 | [diff] [blame] | 76 | if disable_mode == self.MODE_DISABLE_WIFI: |
Etan Cohen | bb50a3c | 2018-02-15 15:39:22 -0800 | [diff] [blame] | 77 | asserts.assert_true(utils.force_airplane_mode(dut, False), |
| 78 | "Can not turn off airplane mode on: %s" % dut.serial) |
Etan Cohen | 42ed384 | 2017-12-18 13:07:00 -0800 | [diff] [blame] | 79 | elif disable_mode == self.MODE_ENABLE_DOZE: |
Etan Cohen | dbe2c17 | 2018-02-01 15:05:32 -0800 | [diff] [blame] | 80 | asserts.assert_true(utils.disable_doze(dut), "Can't disable doze") |
Etan Cohen | 42ed384 | 2017-12-18 13:07:00 -0800 | [diff] [blame] | 81 | elif disable_mode == self.MODE_DISABLE_LOCATIONING: |
| 82 | utils.set_location_service(dut, True) |
| 83 | |
Etan Cohen | ce1e816 | 2017-10-25 12:49:13 -0700 | [diff] [blame] | 84 | rutils.wait_for_event(dut, rconsts.BROADCAST_WIFI_RTT_AVAILABLE) |
| 85 | asserts.assert_true(dut.droid.wifiIsRttAvailable(), "RTT is not available") |
Etan Cohen | d0ae4d3 | 2017-10-26 16:29:19 -0700 | [diff] [blame] | 86 | |
| 87 | ############################################################################ |
| 88 | |
Etan Cohen | f140583 | 2018-04-11 17:41:20 -0700 | [diff] [blame] | 89 | @test_tracker_info(uuid="498c49ab-a188-4612-998d-c47b35ff285e") |
Etan Cohen | d0ae4d3 | 2017-10-26 16:29:19 -0700 | [diff] [blame] | 90 | 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 Cohen | 42ed384 | 2017-12-18 13:07:00 -0800 | [diff] [blame] | 93 | self.run_disable_rtt(self.MODE_DISABLE_WIFI) |
Etan Cohen | d0ae4d3 | 2017-10-26 16:29:19 -0700 | [diff] [blame] | 94 | |
Etan Cohen | f140583 | 2018-04-11 17:41:20 -0700 | [diff] [blame] | 95 | @test_tracker_info(uuid="f71f731f-4aaf-402b-8595-db94b625b544") |
Etan Cohen | d0ae4d3 | 2017-10-26 16:29:19 -0700 | [diff] [blame] | 96 | 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 Cohen | 42ed384 | 2017-12-18 13:07:00 -0800 | [diff] [blame] | 99 | self.run_disable_rtt(self.MODE_ENABLE_DOZE) |
| 100 | |
Etan Cohen | f140583 | 2018-04-11 17:41:20 -0700 | [diff] [blame] | 101 | @test_tracker_info(uuid="6a1c83a8-9eaf-49db-b547-5131cba0eafe") |
Etan Cohen | 42ed384 | 2017-12-18 13:07:00 -0800 | [diff] [blame] | 102 | 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) |