diff options
author | Ningyuan Wang <nywang@google.com> | 2016-03-02 12:54:29 -0800 |
---|---|---|
committer | Ningyuan Wang <nywang@google.com> | 2016-03-16 10:08:04 -0700 |
commit | d02611ce4158fda6c2d14ee13ad7f9553f416d21 (patch) | |
tree | 479baaa55395b91c5f3b024fd45c5f36fe378aad /tests | |
parent | 25211a6fab0c8c623a0b9d39ac1bebac3d496176 (diff) |
Wifi country code refactoring
This CL pulls coutry code logic into one class.
This also refactors all the existing country code logic.
We do not set country code for P2p interface now because
this is redundant. wpa_supplicant will route all the request
to the real interface.
Some initial unittests are added.
Bug: 27477896
TEST: compile, runtest frameworks-wifi,
manually tested with an angler phone
Change-Id: I870c3ad615a1f9bfb3fb40b149b9ca71dc850cdd
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiCountryCodeTest.java | 168 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java | 3 |
2 files changed, 170 insertions, 1 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiCountryCodeTest.java b/tests/wifitests/src/com/android/server/wifi/WifiCountryCodeTest.java new file mode 100644 index 000000000..33cf2170b --- /dev/null +++ b/tests/wifitests/src/com/android/server/wifi/WifiCountryCodeTest.java @@ -0,0 +1,168 @@ +/* + * Copyright (C) 2016 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.assertEquals; +import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import android.test.suitebuilder.annotation.SmallTest; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +/** + * Unit tests for {@link com.android.server.wifi.WifiCountryCode}. + */ +@SmallTest +public class WifiCountryCodeTest { + + private static final String TAG = "WifiCountryCodeTest"; + private String mDefaultCountryCode = "US"; + private String mTelephonyCountryCode = "JP"; + private boolean mRevertCountryCodeOnCellularLoss = true; + @Mock WifiNative mWifiNative; + private WifiCountryCode mWifiCountryCode; + + /** + * Setup test. + */ + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + + when(mWifiNative.setCountryCode(anyString())).thenReturn(true); + + mWifiCountryCode = new WifiCountryCode(mWifiNative, mDefaultCountryCode, + mRevertCountryCodeOnCellularLoss); + } + + /** + * Test if we do not receive country code from Telephony. + * @throws Exception + */ + @Test + public void useDefaultCountryCode() throws Exception { + // Supplicant started. + mWifiCountryCode.setReadyForChange(true); + // Wifi get L2 connected. + mWifiCountryCode.setReadyForChange(false); + verify(mWifiNative).setCountryCode(anyString()); + assertEquals(mDefaultCountryCode, mWifiCountryCode.getCurrentCountryCode()); + } + + /** + * Test if we receive country code from Telephony before supplicant starts. + * @throws Exception + */ + @Test + public void useTelephonyCountryCode() throws Exception { + mWifiCountryCode.setCountryCode(mTelephonyCountryCode); + assertEquals(null, mWifiCountryCode.getCurrentCountryCode()); + // Supplicant started. + mWifiCountryCode.setReadyForChange(true); + // Wifi get L2 connected. + mWifiCountryCode.setReadyForChange(false); + verify(mWifiNative).setCountryCode(anyString()); + assertEquals(mTelephonyCountryCode, mWifiCountryCode.getCurrentCountryCode()); + } + + /** + * Test if we receive country code from Telephony after supplicant starts. + * @throws Exception + */ + @Test + public void setTelephonyCountryCodeAfterSupplicantStarts() throws Exception { + // Supplicant starts. + mWifiCountryCode.setReadyForChange(true); + assertEquals(mDefaultCountryCode, mWifiCountryCode.getCurrentCountryCode()); + // Telephony country code arrives. + mWifiCountryCode.setCountryCode(mTelephonyCountryCode); + // Wifi get L2 connected. + mWifiCountryCode.setReadyForChange(false); + verify(mWifiNative, times(2)).setCountryCode(anyString()); + assertEquals(mTelephonyCountryCode, mWifiCountryCode.getCurrentCountryCode()); + } + + /** + * Test if we receive country code from Telephony after we get L2 connected. + * @throws Exception + */ + @Test + public void setTelephonyCountryCodeAfterL2Connected() throws Exception { + // Supplicant starts. + mWifiCountryCode.setReadyForChange(true); + // Wifi get L2 connected. + mWifiCountryCode.setReadyForChange(false); + // Telephony country code arrives. + mWifiCountryCode.setCountryCode(mTelephonyCountryCode); + // Telephony coutry code won't be applied at this time. + assertEquals(mDefaultCountryCode, mWifiCountryCode.getCurrentCountryCode()); + mWifiCountryCode.setReadyForChange(true); + // Telephony coutry is applied after supplicant is ready. + verify(mWifiNative, times(2)).setCountryCode(anyString()); + assertEquals(mTelephonyCountryCode, mWifiCountryCode.getCurrentCountryCode()); + } + + /** + * Test if we can reset the country code upon sim card is removed. + * @throws Exception + */ + @Test + public void resetCountryCodeWhenSIMCardRemoved() throws Exception { + mWifiCountryCode.setCountryCode(mTelephonyCountryCode); + // Supplicant started. + mWifiCountryCode.setReadyForChange(true); + // Wifi get L2 connected. + mWifiCountryCode.setReadyForChange(false); + assertEquals(mTelephonyCountryCode, mWifiCountryCode.getCurrentCountryCode()); + // SIM card is removed. + mWifiCountryCode.simCardRemoved(); + // Country code restting is not applied yet. + assertEquals(mTelephonyCountryCode, mWifiCountryCode.getCurrentCountryCode()); + mWifiCountryCode.setReadyForChange(true); + // Country code restting is applied when supplicant is ready. + verify(mWifiNative, times(2)).setCountryCode(anyString()); + assertEquals(mDefaultCountryCode, mWifiCountryCode.getCurrentCountryCode()); + } + + /** + * Test if we can reset the country code upon airplane mode is enabled. + * @throws Exception + */ + @Test + public void resetCountryCodeWhenAirplaneModeEnabled() throws Exception { + mWifiCountryCode.setCountryCode(mTelephonyCountryCode); + // Supplicant started. + mWifiCountryCode.setReadyForChange(true); + // Wifi get L2 connected. + mWifiCountryCode.setReadyForChange(false); + assertEquals(mTelephonyCountryCode, mWifiCountryCode.getCurrentCountryCode()); + // Airplane mode is enabled. + mWifiCountryCode.simCardRemoved(); + // Country code restting is not applied yet. + assertEquals(mTelephonyCountryCode, mWifiCountryCode.getCurrentCountryCode()); + mWifiCountryCode.setReadyForChange(true); + // Country code restting is applied when supplicant is ready. + verify(mWifiNative, times(2)).setCountryCode(anyString()); + assertEquals(mDefaultCountryCode, mWifiCountryCode.getCurrentCountryCode()); + } +} diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java index cee79cd60..1cc424553 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java @@ -324,6 +324,7 @@ public class WifiStateMachineTest { @Mock UserManager mUserManager; @Mock WifiApConfigStore mApConfigStore; @Mock BackupManagerProxy mBackupManagerProxy; + @Mock WifiCountryCode mCountryCode; public WifiStateMachineTest() throws Exception { } @@ -370,7 +371,7 @@ public class WifiStateMachineTest { new UserInfo(11, "managed profile", 0))); mWsm = new WifiStateMachine(context, factory, mLooper.getLooper(), - mUserManager, wifiInjector, mBackupManagerProxy); + mUserManager, wifiInjector, mBackupManagerProxy, mCountryCode); mWsmThread = getWsmHandlerThread(mWsm); final AsyncChannel channel = new AsyncChannel(); |