diff options
author | Ahmed ElArabawy <arabawy@google.com> | 2018-05-22 18:22:03 -0700 |
---|---|---|
committer | Ahmed ElArabawy <arabawy@google.com> | 2018-06-08 07:43:37 -0700 |
commit | dc3d066444208c13ed4caf69bebee6b68e7488f3 (patch) | |
tree | 98c3ee57ab8587e55f85d0aaee825a6686cb7ef7 /tests | |
parent | 4c23cef241b5d93d2bf49d620a924911ae1ce916 (diff) |
WiFi: SAR Support: Add SarInfo
Current implementation has limited support for SAR in Wifi.
It just includes the support of power backoff when an ongoing
voice call is happening while Wifi is transmitting.
This commit is the first stage to provide more support for SAR
for WiFi TX power backoff when the device is in close proximity
to head or body of user with or without the presence of a voice call.
This stage adds the SarInfo which is a data structure that is used
by SarManager to communicate SAR triggers towards the WifiVendorHal
Bug: 65174506
Test: Run Wifi unit test suite
Test: ./frameworks/opt/net/wifi/tests/wifitests/runtests.sh
Change-Id: Ic5f002430db1e92f656ae861e65934241a8590ef
Signed-off-by: Ahmed ElArabawy <arabawy@google.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/SarInfoTest.java | 287 |
1 files changed, 287 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/SarInfoTest.java b/tests/wifitests/src/com/android/server/wifi/SarInfoTest.java new file mode 100644 index 000000000..1f0e44c8a --- /dev/null +++ b/tests/wifitests/src/com/android/server/wifi/SarInfoTest.java @@ -0,0 +1,287 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.wifi; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import android.support.test.filters.SmallTest; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * unit tests for {@link com.android.server.wifi.SarInfo}. + */ +@SmallTest +public class SarInfoTest { + private static final String TAG = "WifiSarInfoTest"; + + private SarInfo mSarInfo; + + private static final int SAR_SCENARIO_1 = 1; + private static final int SAR_SCENARIO_2 = 2; + + @Before + public void setUp() throws Exception { + mSarInfo = new SarInfo(true); + } + + @After + public void cleanUp() throws Exception { + } + + /** + * Test that at start, resetSarScenarioNeeded returns true, + * to allow for initial setting of normal scenario. + */ + @Test + public void testSarInfo_resetSarScenarioNeed_atStart() throws Exception { + assertTrue(mSarInfo.resetSarScenarioNeeded()); + } + + /** + * Test that at start, setSarScenarioNeeded returns true. + */ + @Test + public void testSarInfo_setSarScenarioNeeded_atStart() throws Exception { + assertTrue(mSarInfo.setSarScenarioNeeded(SAR_SCENARIO_1)); + } + + /** + * Test performing two successive reset of SAR scenario. + * The first should succeed, while the second should fail, since it is redundant. + */ + @Test + public void testSarInfo_repeat_reset_scenario() throws Exception { + /* Initial reset is allowed */ + assertTrue(mSarInfo.resetSarScenarioNeeded()); + mSarInfo.reportingSuccessful(); + + /* Now resetting again should not be allowed */ + assertFalse(mSarInfo.resetSarScenarioNeeded()); + } + + /** + * Test performing set SAR scenario after reset. + * The two attempts should succeed. + */ + @Test + public void testSarInfo_set_after_reset_scenario() throws Exception { + assertTrue(mSarInfo.resetSarScenarioNeeded()); + mSarInfo.reportingSuccessful(); + + /* Setting scenario should be allowed, since last call was for a reset */ + assertTrue(mSarInfo.setSarScenarioNeeded(SAR_SCENARIO_1)); + } + + /** + * Test performing setting SAR scenario twice with same value. + * The second attempt should fail. + */ + @Test + public void testSarInfo_set_twice_same_value_scenario() throws Exception { + assertTrue(mSarInfo.setSarScenarioNeeded(SAR_SCENARIO_1)); + mSarInfo.reportingSuccessful(); + + /* Second attempt should fail */ + assertFalse(mSarInfo.setSarScenarioNeeded(SAR_SCENARIO_1)); + } + + /** + * Test performing setting SAR scenario twice with different values. + * Both attempts should succeed. + */ + @Test + public void testSarInfo_set_twice_different_values_scenario() throws Exception { + assertTrue(mSarInfo.setSarScenarioNeeded(SAR_SCENARIO_1)); + mSarInfo.reportingSuccessful(); + + /* Setting scenario should be allowed */ + assertTrue(mSarInfo.setSarScenarioNeeded(SAR_SCENARIO_2)); + } + + /** + * Test performing reset of SAR scenario after setting it. + * Both attempts should succeed. + */ + @Test + public void testSarInfo_reset_after_set_scenario() throws Exception { + assertTrue(mSarInfo.setSarScenarioNeeded(SAR_SCENARIO_1)); + mSarInfo.reportingSuccessful(); + + /* Resetting scenario should be allowed */ + assertTrue(mSarInfo.resetSarScenarioNeeded()); + } + + /** + * Test that at start, shouldReport returns false (wifi modes still disabled). + */ + @Test + public void testSarInfo_shouldReport_all_wifi_disabled() throws Exception { + assertFalse(mSarInfo.shouldReport()); + } + + /** + * Test that once Wifi (any mode) is enabled, shouldReport returns true. + */ + @Test + public void testSarInfo_shouldReport_wifi_enabled() throws Exception { + mSarInfo.mIsWifiClientEnabled = true; + assertTrue(mSarInfo.shouldReport()); + } + + /** + * Test that setting sensor (with wifi disabled), shouldReport returns false. + */ + @Test + public void testSarInfo_check_sensor_wifi_disabled() throws Exception { + mSarInfo.mSensorState = SarInfo.SAR_SENSOR_NEAR_HEAD; + assertFalse(mSarInfo.shouldReport()); + } + + /** + * Test that setting sensor (with some wifi mode enabled), shouldReport returns true. + */ + @Test + public void testSarInfo_check_sensor_wifi_enabled() throws Exception { + mSarInfo.mIsWifiSapEnabled = true; + assertTrue(mSarInfo.shouldReport()); + mSarInfo.reportingSuccessful(); + + mSarInfo.mSensorState = SarInfo.SAR_SENSOR_NEAR_HEAD; + assertTrue(mSarInfo.shouldReport()); + } + + /** + * Test that setting sensor (with some wifi mode enabled), shouldReport returns true + * only the first time, following attempts should return false (since sensor state + * did not change) + */ + @Test + public void testSarInfo_check_sensor_multiple_wifi_enabled() throws Exception { + mSarInfo.mIsWifiScanOnlyEnabled = true; + mSarInfo.mSensorState = SarInfo.SAR_SENSOR_NEAR_HEAD; + assertTrue(mSarInfo.shouldReport()); + mSarInfo.reportingSuccessful(); + + assertFalse(mSarInfo.shouldReport()); + } + + /** + * Test that setting sensor with different values (with wifi enabled), + * shouldReport returns true every time. + */ + @Test + public void testSarInfo_check_sensor_multiple_values_wifi_enabled() throws Exception { + mSarInfo.mIsWifiClientEnabled = true; + mSarInfo.mSensorState = SarInfo.SAR_SENSOR_NEAR_HEAD; + assertTrue(mSarInfo.shouldReport()); + mSarInfo.reportingSuccessful(); + + mSarInfo.mSensorState = SarInfo.SAR_SENSOR_NEAR_BODY; + assertTrue(mSarInfo.shouldReport()); + mSarInfo.reportingSuccessful(); + + mSarInfo.mSensorState = SarInfo.SAR_SENSOR_NEAR_HEAD; + assertTrue(mSarInfo.shouldReport()); + } + + /** + * Test setting sensor while wifi is disabled, then enable wifi. + */ + @Test + public void testSarInfo_change_sensors_while_wifi_disabled() throws Exception { + mSarInfo.mSensorState = SarInfo.SAR_SENSOR_NEAR_HEAD; + assertFalse(mSarInfo.shouldReport()); + + mSarInfo.mIsWifiClientEnabled = true; + assertTrue(mSarInfo.shouldReport()); + mSarInfo.reportingSuccessful(); + } + + /** + * Test having a voice call, shouldReport should return true + * Note: will need to report once before starting the call to remove + * the effect of sensor state change. + */ + @Test + public void testSarInfo_voice_call_wifi_enabled() throws Exception { + mSarInfo.mIsWifiClientEnabled = true; + assertTrue(mSarInfo.shouldReport()); + mSarInfo.reportingSuccessful(); + + mSarInfo.mIsVoiceCall = true; + assertTrue(mSarInfo.shouldReport()); + } + + /** + * Test starting SAP, shouldReport should return true + * Note: will need to report once before starting SAP to remove + * the effect of sensor state change. + */ + @Test + public void testSarInfo_sap_wifi_enabled() throws Exception { + mSarInfo.mIsWifiClientEnabled = true; + assertTrue(mSarInfo.shouldReport()); + mSarInfo.reportingSuccessful(); + + mSarInfo.mIsWifiSapEnabled = true; + assertTrue(mSarInfo.shouldReport()); + } + + /** + * Test that setting sensor (with wifi enabled), reporting not successful + * Then, we should expect that shouldReport returns true evne if we have + * no further changes until reporting is successful. + */ + @Test + public void testSarInfo_check_sensor_reporting_no_success_reporting() throws Exception { + mSarInfo.mIsWifiClientEnabled = true; + mSarInfo.mSensorState = SarInfo.SAR_SENSOR_NEAR_HEAD; + assertTrue(mSarInfo.shouldReport()); + + /* No call to reportingSuccessful() will be done */ + assertTrue(mSarInfo.shouldReport()); + + /* Now call reportingSuccessful() */ + mSarInfo.reportingSuccessful(); + assertFalse(mSarInfo.shouldReport()); + } + + /** + * Test that setting sensor (with wifi enabled), reporting successful + * Then, changing the sensor state with no successful reporting. + * Followed by reverting to the previous state. + */ + @Test + public void testSarInfo_check_sensor_reporting_no_success_reporting_revert() throws Exception { + mSarInfo.mIsWifiClientEnabled = true; + mSarInfo.mSensorState = SarInfo.SAR_SENSOR_NEAR_HEAD; + assertTrue(mSarInfo.shouldReport()); + mSarInfo.reportingSuccessful(); + + /* Changing the sensor state and fail to report */ + mSarInfo.mSensorState = SarInfo.SAR_SENSOR_NEAR_BODY; + assertTrue(mSarInfo.shouldReport()); + + /* Changing the sensor back to the same value as last reported */ + mSarInfo.mSensorState = SarInfo.SAR_SENSOR_NEAR_HEAD; + assertFalse(mSarInfo.shouldReport()); + } +} |