1#!/usr/bin/env python3.4 2# 3# Copyright 2018 - 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 17import time 18from acts.test_decorators import test_tracker_info 19from acts.test_utils.power import PowerWiFiBaseTest as PWBT 20from acts.test_utils.wifi import wifi_test_utils as wutils 21 22UNLOCK_SCREEN = 'input keyevent 82' 23 24 25class PowerWiFiscanTest(PWBT.PowerWiFiBaseTest): 26 def setup_class(self): 27 super().setup_class() 28 # Setup scan command 29 SINGLE_SHOT_SCAN = ( 30 'am instrument -w -r -e min_scan_count \"700\"' 31 ' -e WifiScanTest-testWifiSingleShotScan %d' 32 ' -e class com.google.android.platform.powertests.' 33 'WifiScanTest#testWifiSingleShotScan' 34 ' com.google.android.platform.powertests/' 35 'android.test.InstrumentationTestRunner > /dev/null &' % 36 (self.mon_duration + self.mon_offset + 10)) 37 BACKGROUND_SCAN = ('am instrument -w -r -e min_scan_count \"1\" -e ' 38 'WifiScanTest-testWifiBackgroundScan %d -e class ' 39 'com.google.android.platform.powertests.WifiScan' 40 'Test#testWifiBackgroundScan com.google.android.' 41 'platform.powertests/android.test.Instrumentation' 42 'TestRunner > /dev/null &' % 43 (self.mon_duration + self.mon_offset + 10)) 44 WIFI_SCAN = ('am instrument -w -r -e min_scan_count \"1\" -e ' 45 'WifiScanTest-testWifiScan %d -e class ' 46 'com.google.android.platform.powertests.WifiScanTest#' 47 'testWifiScan com.google.android.platform.powertests/' 48 'android.test.InstrumentationTestRunner > /dev/null &' % 49 (self.mon_duration + self.mon_offset + 10)) 50 self.APK_SCAN_CMDS = { 51 'singleshot': SINGLE_SHOT_SCAN, 52 'background': BACKGROUND_SCAN, 53 'wifi': WIFI_SCAN 54 } 55 56 def scan_setup(self): 57 """Setup for scan based on the type of scan. 58 59 Trigger the desired scan. 60 """ 61 self.log.info('Trigger {} scans'.format(self.test_configs.scan_mode)) 62 if self.test_configs.scan_type == 'apk': 63 atten_setting = self.test_configs.wifi_band + '_' + self.test_configs.rssi 64 self.set_attenuation(self.atten_level[atten_setting]) 65 self.dut.adb.shell_nb( 66 self.APK_SCAN_CMDS[self.test_configs.scan_mode]) 67 else: 68 self.mon_info.offset = 0 69 if self.test_configs.scan_mode == 'pno': 70 self.log.info('Set attenuation to trigger PNO scan') 71 self.set_attenuation(self.atten_level['max_atten']) 72 elif self.test_configs.scan_mode == 'connectivity': 73 self.dut.droid.wakeUpNow() 74 self.log.info( 75 'Now turn on screen to trigger connectivity scans') 76 self.dut.adb.shell(UNLOCK_SCREEN) 77 elif self.test_configs.scan_mode == 'roaming': 78 atten_setting = self.test_configs.wifi_band + '_roaming' 79 self.set_attenuation(self.atten_level[atten_setting]) 80 81 def wifi_scan_test_func(self): 82 83 attrs = [ 84 'screen_status', 'wifi_status', 'wifi_band', 'rssi', 'scan_type', 85 'scan_mode' 86 ] 87 indices = [2, 4, 6, 8, 10, 11] 88 self.decode_test_configs(attrs, indices) 89 if self.test_configs.wifi_status == 'Disconnected': 90 self.setup_ap_connection( 91 self.main_network[self.test_configs.wifi_band], connect=False) 92 elif self.test_configs.wifi_status == 'Connected': 93 self.setup_ap_connection( 94 self.main_network[self.test_configs.wifi_band]) 95 else: 96 wutils.wifi_toggle_state(self.dut, True) 97 if self.test_configs.screen_status == 'OFF': 98 self.dut.droid.goToSleepNow() 99 self.dut.log.info('Screen is OFF') 100 time.sleep(2) 101 self.scan_setup() 102 self.measure_power_and_validate() 103 104 # Test cases 105 # Power.apk triggered scans 106 @test_tracker_info(uuid='e5539b01-e208-43c6-bebf-6f1e73d8d8cb') 107 def test_screen_OFF_WiFi_Disconnected_band_2g_RSSI_high_scan_apk_singleshot( 108 self): 109 self.wifi_scan_test_func() 110 111 @test_tracker_info(uuid='14c5a762-95bc-40ea-9fd4-27126df7d86c') 112 def test_screen_OFF_WiFi_Disconnected_band_2g_RSSI_low_scan_apk_singleshot( 113 self): 114 self.wifi_scan_test_func() 115 116 @test_tracker_info(uuid='a6506600-c567-43b5-9c25-86b505099b97') 117 def test_screen_OFF_WiFi_Disconnected_band_2g_RSSI_none_scan_apk_singleshot( 118 self): 119 self.wifi_scan_test_func() 120 121 @test_tracker_info(uuid='1a458248-1159-4c8e-a39f-92fc9e69c4dd') 122 def test_screen_OFF_WiFi_Disconnected_band_5g_RSSI_high_scan_apk_singleshot( 123 self): 124 self.wifi_scan_test_func() 125 126 @test_tracker_info(uuid='bd4da426-a621-4131-9f89-6e5a77f321d2') 127 def test_screen_OFF_WiFi_Disconnected_band_5g_RSSI_low_scan_apk_singleshot( 128 self): 129 self.wifi_scan_test_func() 130 131 @test_tracker_info(uuid='288b3add-8925-4803-81c0-53debf157ffc') 132 def test_screen_OFF_WiFi_Disconnected_band_5g_RSSI_none_scan_apk_singleshot( 133 self): 134 self.wifi_scan_test_func() 135 136 @test_tracker_info(uuid='f401c66c-e515-4f51-8ef2-2a03470d8ff2') 137 def test_screen_OFF_WiFi_Disconnected_band_5g_RSSI_high_scan_apk_background( 138 self): 139 self.wifi_scan_test_func() 140 141 @test_tracker_info(uuid='fe38c1c7-937c-42c0-9381-98356639df8f') 142 def test_screen_OFF_WiFi_Disconnected_band_2g_RSSI_high_scan_apk_wifi( 143 self): 144 self.wifi_scan_test_func() 145 146 @test_tracker_info(uuid='8eedefd1-3a08-4ac2-ba55-5eb438def3d4') 147 def test_screen_OFF_WiFi_Disconnected_band_5g_RSSI_high_scan_apk_wifi( 148 self): 149 self.wifi_scan_test_func() 150 151 # Firmware/framework scans 152 @test_tracker_info(uuid='ff5ea952-ee31-4968-a190-82935ce7a8cb') 153 def test_screen_OFF_WiFi_ON_band_5g_RSSI_high_scan_system_connectivity( 154 self): 155 """WiFi disconected, turn on Screen to trigger connectivity scans. 156 157 """ 158 self.wifi_scan_test_func() 159 160 @test_tracker_info(uuid='9a836e5b-8128-4dd2-8e96-e79177810bdd') 161 def test_screen_OFF_WiFi_Connected_band_2g_RSSI_high_scan_system_connectivity( 162 self): 163 """WiFi connected to 2g, turn on screen to trigger connectivity scans. 164 165 """ 166 self.wifi_scan_test_func() 167 168 @test_tracker_info(uuid='51e3c4f1-742b-45af-afd5-ae3552a03272') 169 def test_screen_OFF_WiFi_Connected_band_2g_RSSI_high_scan_system_roaming( 170 self): 171 """WiFi connected to 2g, low RSSI to be below roaming threshold. 172 173 """ 174 self.wifi_scan_test_func() 175 176 @test_tracker_info(uuid='a16ae337-326f-4d09-990f-42232c3c0dc4') 177 def test_screen_OFF_WiFi_Connected_band_2g_RSSI_high_scan_system_pno(self): 178 """WiFi connected to 2g, trigger pno scan. 179 180 """ 181 self.wifi_scan_test_func() 182