summaryrefslogtreecommitdiffstats
path: root/tests/wifitests/src
diff options
context:
space:
mode:
Diffstat (limited to 'tests/wifitests/src')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java4
-rw-r--r--tests/wifitests/src/com/android/server/wifi/MockResources.java15
-rw-r--r--tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java15
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java40
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiControllerTest.java57
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java26
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiLockManagerTest.java2
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java101
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiScoreCardTest.java21
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java24
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/UtilsTest.java176
-rw-r--r--tests/wifitests/src/com/android/server/wifi/util/NativeUtilTest.java31
12 files changed, 450 insertions, 62 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
index b96fc3a90..69dff1edd 100644
--- a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
@@ -496,6 +496,7 @@ public class ClientModeImplTest {
mOsuProvider = PasspointProvisioningTestUtil.generateOsuProvider(true);
mConnectedNetwork = spy(WifiConfigurationTestUtil.createOpenNetwork());
when(mNullAsyncChannel.sendMessageSynchronously(any())).thenReturn(null);
+ when(mWifiScoreCard.getL2KeyAndGroupHint(any())).thenReturn(new Pair<>(null, null));
}
private void registerAsyncChannel(Consumer<AsyncChannel> consumer, Messenger messenger) {
@@ -2817,9 +2818,12 @@ public class ClientModeImplTest {
*/
@Test
public void testScoreCardNoteConnectionComplete() throws Exception {
+ Pair<String, String> l2KeyAndGroupHint = Pair.create("Wad", "Gab");
+ when(mWifiScoreCard.getL2KeyAndGroupHint(any())).thenReturn(l2KeyAndGroupHint);
connect();
mLooper.dispatchAll();
verify(mWifiScoreCard).noteIpConfiguration(any());
+ verify(mIpClient).setL2KeyAndGroupHint(eq("Wad"), eq("Gab"));
}
/**
diff --git a/tests/wifitests/src/com/android/server/wifi/MockResources.java b/tests/wifitests/src/com/android/server/wifi/MockResources.java
index 1a061e22a..dd4413228 100644
--- a/tests/wifitests/src/com/android/server/wifi/MockResources.java
+++ b/tests/wifitests/src/com/android/server/wifi/MockResources.java
@@ -24,12 +24,14 @@ public class MockResources extends android.test.mock.MockResources {
private HashMap<Integer, Integer> mIntegerValues;
private HashMap<Integer, String> mStringValues;
private HashMap<Integer, CharSequence> mTextValues;
+ private HashMap<Integer, int[]> mIntArrayValues;
public MockResources() {
mBooleanValues = new HashMap<Integer, Boolean>();
mIntegerValues = new HashMap<Integer, Integer>();
mStringValues = new HashMap<Integer, String>();
mTextValues = new HashMap<Integer, CharSequence>();
+ mIntArrayValues = new HashMap<Integer, int[]>();
}
@Override
@@ -68,6 +70,15 @@ public class MockResources extends android.test.mock.MockResources {
}
}
+ @Override
+ public int[] getIntArray(int id) {
+ if (mIntArrayValues.containsKey(id)) {
+ return mIntArrayValues.get(id);
+ } else {
+ return null;
+ }
+ }
+
public void setBoolean(int id, boolean value) {
mBooleanValues.put(id, value);
}
@@ -83,4 +94,8 @@ public class MockResources extends android.test.mock.MockResources {
public void setText(int id, CharSequence value) {
mTextValues.put(id, value);
}
+
+ public void setIntArray(int id, int[] value) {
+ mIntArrayValues.put(id, value);
+ }
}
diff --git a/tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java b/tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java
index a19640ff6..985789858 100644
--- a/tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java
@@ -173,7 +173,8 @@ public class ScanRequestProxyTest {
mInOrder.verify(mWifiScanner).registerScanListener(any());
mInOrder.verify(mWifiScanner).startScan(any(), any(), any());
- assertTrue(mWorkSourceArgumentCaptor.getValue().equals(new WorkSource(TEST_UID)));
+ assertTrue(mWorkSourceArgumentCaptor.getValue().equals(
+ new WorkSource(TEST_UID, TEST_PACKAGE_NAME_1)));
validateScanSettings(mScanSettingsArgumentCaptor.getValue(), false);
verify(mWifiMetrics).incrementExternalAppOneshotScanRequestsCount();
@@ -189,7 +190,8 @@ public class ScanRequestProxyTest {
mInOrder.verify(mWifiScanner).registerScanListener(any());
mInOrder.verify(mWifiScanner).startScan(any(), any(), any());
- assertTrue(mWorkSourceArgumentCaptor.getValue().equals(new WorkSource(TEST_UID)));
+ assertTrue(mWorkSourceArgumentCaptor.getValue().equals(
+ new WorkSource(TEST_UID, TEST_PACKAGE_NAME_1)));
validateScanSettings(mScanSettingsArgumentCaptor.getValue(), false, true);
}
@@ -203,7 +205,8 @@ public class ScanRequestProxyTest {
mInOrder.verify(mWifiScanner).registerScanListener(any());
mInOrder.verify(mWifiScanner).startScan(any(), any(), any());
- assertTrue(mWorkSourceArgumentCaptor.getValue().equals(new WorkSource(TEST_UID)));
+ assertTrue(mWorkSourceArgumentCaptor.getValue().equals(
+ new WorkSource(TEST_UID, TEST_PACKAGE_NAME_1)));
validateScanSettings(mScanSettingsArgumentCaptor.getValue(), false, true);
}
@@ -221,7 +224,8 @@ public class ScanRequestProxyTest {
mInOrder.verify(mWifiConfigManager, never()).retrieveHiddenNetworkList();
mInOrder.verify(mWifiScanner).startScan(any(), any(), any());
- assertTrue(mWorkSourceArgumentCaptor.getValue().equals(new WorkSource(TEST_UID)));
+ assertTrue(mWorkSourceArgumentCaptor.getValue().equals(
+ new WorkSource(TEST_UID, TEST_PACKAGE_NAME_1)));
validateScanSettings(mScanSettingsArgumentCaptor.getValue(), false);
verify(mWifiMetrics).incrementExternalAppOneshotScanRequestsCount();
@@ -241,7 +245,8 @@ public class ScanRequestProxyTest {
mInOrder.verify(mWifiConfigManager).retrieveHiddenNetworkList();
mInOrder.verify(mWifiScanner).startScan(any(), any(), any());
- assertTrue(mWorkSourceArgumentCaptor.getValue().equals(new WorkSource(TEST_UID)));
+ assertTrue(mWorkSourceArgumentCaptor.getValue().equals(
+ new WorkSource(TEST_UID, TEST_PACKAGE_NAME_1)));
validateScanSettings(mScanSettingsArgumentCaptor.getValue(), true);
verify(mWifiMetrics).incrementExternalAppOneshotScanRequestsCount();
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
index 2f73ca7f0..a2d0e46b8 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
@@ -49,6 +49,7 @@ import android.util.Pair;
import androidx.test.filters.SmallTest;
+import com.android.dx.mockito.inline.extended.ExtendedMockito;
import com.android.internal.R;
import com.android.server.wifi.util.WifiPermissionsUtil;
import com.android.server.wifi.util.WifiPermissionsWrapper;
@@ -60,6 +61,7 @@ import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoSession;
import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -137,6 +139,7 @@ public class WifiConfigManagerTest {
private TestLooper mLooper = new TestLooper();
private ContentObserver mContentObserverPnoChannelCulling;
private ContentObserver mContentObserverPnoRecencySorting;
+ private MockitoSession mSession;
/**
* Setup the mocks and an instance of WifiConfigManager before each test.
@@ -219,6 +222,11 @@ public class WifiConfigManagerTest {
Settings.Global.WIFI_PNO_RECENCY_SORTING_ENABLED)), eq(false),
observerCaptor.capture());
mContentObserverPnoRecencySorting = observerCaptor.getValue();
+ // static mocking
+ mSession = ExtendedMockito.mockitoSession()
+ .mockStatic(WifiConfigStore.class, withSettings().lenient())
+ .startMocking();
+ when(WifiConfigStore.createUserFiles(anyInt())).thenReturn(mock(List.class));
}
/**
@@ -227,6 +235,7 @@ public class WifiConfigManagerTest {
@After
public void cleanup() {
validateMockitoUsage();
+ mSession.finishMocking();
}
/**
@@ -4450,6 +4459,37 @@ public class WifiConfigManagerTest {
verifyExpiryOfTimeout(passpointNetwork);
}
+ /**
+ * Verifies the disconnection of Passpoint network using
+ * {@link WifiConfigManager#disableEphemeralNetwork(String)} and ensures that any user choice
+ * set over other networks is removed.
+ */
+ @Test
+ public void testDisablePasspointNetworkRemovesUserChoice() throws Exception {
+ WifiConfiguration passpointNetwork = WifiConfigurationTestUtil.createPasspointNetwork();
+ WifiConfiguration savedNetwork = WifiConfigurationTestUtil.createOpenNetwork();
+
+ verifyAddNetworkToWifiConfigManager(savedNetwork);
+ verifyAddPasspointNetworkToWifiConfigManager(passpointNetwork);
+
+ // Set connect choice of passpoint network over saved network.
+ assertTrue(
+ mWifiConfigManager.setNetworkConnectChoice(
+ savedNetwork.networkId, passpointNetwork.configKey(), 78L));
+
+ WifiConfiguration retrievedSavedNetwork =
+ mWifiConfigManager.getConfiguredNetwork(savedNetwork.networkId);
+ assertEquals(
+ passpointNetwork.configKey(),
+ retrievedSavedNetwork.getNetworkSelectionStatus().getConnectChoice());
+
+ // Disable the passpoint network & ensure the user choice is now removed from saved network.
+ mWifiConfigManager.disableEphemeralNetwork(passpointNetwork.SSID);
+
+ retrievedSavedNetwork = mWifiConfigManager.getConfiguredNetwork(savedNetwork.networkId);
+ assertNull(retrievedSavedNetwork.getNetworkSelectionStatus().getConnectChoice());
+ }
+
private void verifyExpiryOfTimeout(WifiConfiguration config) {
// Disable the ephemeral network.
long disableTimeMs = 546643L;
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiControllerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiControllerTest.java
index 455393ea3..18f7ea5df 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiControllerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiControllerTest.java
@@ -37,9 +37,7 @@ import android.content.IntentFilter;
import android.content.res.Resources;
import android.location.LocationManager;
import android.net.wifi.WifiManager;
-import android.os.Handler;
import android.os.test.TestLooper;
-import android.provider.Settings;
import android.util.Log;
import androidx.test.filters.SmallTest;
@@ -47,6 +45,7 @@ import androidx.test.filters.SmallTest;
import com.android.internal.R;
import com.android.internal.util.IState;
import com.android.internal.util.StateMachine;
+import com.android.server.wifi.util.WifiPermissionsUtil;
import org.junit.After;
import org.junit.Before;
@@ -88,8 +87,6 @@ public class WifiControllerTest {
when(mSettingsStore.isAirplaneModeOn()).thenReturn(false);
when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false);
when(mSettingsStore.isScanAlwaysAvailable()).thenReturn(false);
- when(mSettingsStore.getLocationModeSetting(eq(mContext)))
- .thenReturn(Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);
}
TestLooper mLooper;
@@ -99,9 +96,9 @@ public class WifiControllerTest {
@Mock WifiSettingsStore mSettingsStore;
@Mock ClientModeImpl mClientModeImpl;
@Mock ActiveModeWarden mActiveModeWarden;
+ @Mock WifiPermissionsUtil mWifiPermissionsUtil;
WifiController mWifiController;
- Handler mClientModeImplHandler;
private BroadcastReceiver mBroadcastReceiver;
@@ -120,15 +117,17 @@ public class WifiControllerTest {
when(mResources.getInteger(R.integer.config_wifi_framework_recovery_timeout_delay))
.thenReturn(TEST_WIFI_RECOVERY_DELAY_MS);
+ when(mWifiPermissionsUtil.isLocationModeEnabled()).thenReturn(true);
mWifiController = new WifiController(mContext, mClientModeImpl, mLooper.getLooper(),
- mSettingsStore, mLooper.getLooper(), mFacade, mActiveModeWarden);
+ mSettingsStore, mLooper.getLooper(), mFacade, mActiveModeWarden,
+ mWifiPermissionsUtil);
mWifiController.start();
mLooper.dispatchAll();
+
ArgumentCaptor<BroadcastReceiver> bcastRxCaptor = ArgumentCaptor.forClass(
BroadcastReceiver.class);
verify(mContext).registerReceiver(bcastRxCaptor.capture(), any(IntentFilter.class));
-
mBroadcastReceiver = bcastRxCaptor.getValue();
ArgumentCaptor<ClientModeManager.Listener> clientModeCallbackCaptor =
@@ -185,7 +184,7 @@ public class WifiControllerTest {
WifiController wifiController =
new WifiController(mContext, mClientModeImpl, mLooper.getLooper(),
mSettingsStore, mLooper.getLooper(), mFacade,
- mActiveModeWarden);
+ mActiveModeWarden, mWifiPermissionsUtil);
wifiController.start();
mLooper.dispatchAll();
@@ -203,11 +202,11 @@ public class WifiControllerTest {
when(mSettingsStore.isAirplaneModeOn()).thenReturn(false);
when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false);
when(mSettingsStore.isScanAlwaysAvailable()).thenReturn(false);
- when(mSettingsStore.getLocationModeSetting(eq(mContext)))
- .thenReturn(Settings.Secure.LOCATION_MODE_OFF);
+ when(mWifiPermissionsUtil.isLocationModeEnabled()).thenReturn(false);
mWifiController = new WifiController(mContext, mClientModeImpl, mLooper.getLooper(),
- mSettingsStore, mLooper.getLooper(), mFacade, mActiveModeWarden);
+ mSettingsStore, mLooper.getLooper(), mFacade, mActiveModeWarden,
+ mWifiPermissionsUtil);
reset(mActiveModeWarden);
mWifiController.start();
@@ -230,26 +229,25 @@ public class WifiControllerTest {
@Test
public void testEnterScanModeWhenLocationModeEnabled() throws Exception {
when(mSettingsStore.isScanAlwaysAvailable()).thenReturn(true);
- when(mSettingsStore.getLocationModeSetting(eq(mContext)))
- .thenReturn(Settings.Secure.LOCATION_MODE_OFF);
+ when(mWifiPermissionsUtil.isLocationModeEnabled()).thenReturn(false);
reset(mContext, mActiveModeWarden);
when(mContext.getResources()).thenReturn(mResources);
mWifiController = new WifiController(mContext, mClientModeImpl, mLooper.getLooper(),
- mSettingsStore, mLooper.getLooper(), mFacade, mActiveModeWarden);
+ mSettingsStore, mLooper.getLooper(), mFacade, mActiveModeWarden,
+ mWifiPermissionsUtil);
+
+ mWifiController.start();
+ mLooper.dispatchAll();
+
ArgumentCaptor<BroadcastReceiver> bcastRxCaptor = ArgumentCaptor.forClass(
BroadcastReceiver.class);
verify(mContext).registerReceiver(bcastRxCaptor.capture(), any(IntentFilter.class));
-
mBroadcastReceiver = bcastRxCaptor.getValue();
- mWifiController.start();
- mLooper.dispatchAll();
-
verify(mActiveModeWarden).disableWifi();
- when(mSettingsStore.getLocationModeSetting(eq(mContext)))
- .thenReturn(Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);
+ when(mWifiPermissionsUtil.isLocationModeEnabled()).thenReturn(true);
Intent intent = new Intent(LocationManager.MODE_CHANGED_ACTION);
mBroadcastReceiver.onReceive(mContext, intent);
@@ -265,26 +263,24 @@ public class WifiControllerTest {
@Test
public void testExitScanModeWhenLocationModeDisabled() throws Exception {
when(mSettingsStore.isScanAlwaysAvailable()).thenReturn(true);
- when(mSettingsStore.getLocationModeSetting(eq(mContext)))
- .thenReturn(Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);
+ when(mWifiPermissionsUtil.isLocationModeEnabled()).thenReturn(true);
reset(mContext, mActiveModeWarden);
when(mContext.getResources()).thenReturn(mResources);
mWifiController = new WifiController(mContext, mClientModeImpl, mLooper.getLooper(),
- mSettingsStore, mLooper.getLooper(), mFacade, mActiveModeWarden);
+ mSettingsStore, mLooper.getLooper(), mFacade, mActiveModeWarden,
+ mWifiPermissionsUtil);
+ mWifiController.start();
+ mLooper.dispatchAll();
+
ArgumentCaptor<BroadcastReceiver> bcastRxCaptor = ArgumentCaptor.forClass(
BroadcastReceiver.class);
verify(mContext).registerReceiver(bcastRxCaptor.capture(), any(IntentFilter.class));
-
mBroadcastReceiver = bcastRxCaptor.getValue();
- mWifiController.start();
- mLooper.dispatchAll();
-
verify(mActiveModeWarden).enterScanOnlyMode();
- when(mSettingsStore.getLocationModeSetting(eq(mContext)))
- .thenReturn(Settings.Secure.LOCATION_MODE_OFF);
+ when(mWifiPermissionsUtil.isLocationModeEnabled()).thenReturn(false);
Intent intent = new Intent(LocationManager.MODE_CHANGED_ACTION);
mBroadcastReceiver.onReceive(mContext, intent);
@@ -1016,7 +1012,8 @@ public class WifiControllerTest {
when(mSettingsStore.isScanAlwaysAvailable()).thenReturn(false);
mWifiController = new WifiController(mContext, mClientModeImpl, mLooper.getLooper(),
- mSettingsStore, mLooper.getLooper(), mFacade, mActiveModeWarden);
+ mSettingsStore, mLooper.getLooper(), mFacade, mActiveModeWarden,
+ mWifiPermissionsUtil);
mWifiController.start();
mLooper.dispatchAll();
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java
index 1c33d3920..6b63137a2 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiDiagnosticsTest.java
@@ -79,6 +79,10 @@ public class WifiDiagnosticsTest {
private static final int BYTES_PER_KBYTE = 1024;
private static final int ALERT_REASON_CODE = 1;
private static final byte[] ALERT_DATA = {0 , 4, 5};
+ /** Mock resource for fatal firmware alert list */
+ private static final int[] FATAL_FW_ALART_LIST = {256, 257, 258};
+ /** Mock a non fatal firmware alert */
+ private static final int NON_FATAL_FW_ALART = 0;
private WifiNative.RingBufferStatus mFakeRbs;
/**
@@ -117,6 +121,8 @@ public class WifiDiagnosticsTest {
SMALL_RING_BUFFER_SIZE_KB);
resources.setInteger(R.integer.config_wifi_logger_ring_buffer_verbose_size_limit_kb,
LARGE_RING_BUFFER_SIZE_KB);
+ resources.setIntArray(R.array.config_wifi_fatal_firmware_alert_error_code_list,
+ FATAL_FW_ALART_LIST);
when(mContext.getResources()).thenReturn(resources);
when(mWifiInjector.makeLog(anyString())).thenReturn(mLog);
when(mWifiInjector.getJavaRuntime()).thenReturn(mJavaRuntime);
@@ -864,4 +870,24 @@ public class WifiDiagnosticsTest {
mWifiDiagnostics.captureBugReportData(WifiDiagnostics.REPORT_REASON_NONE);
verify(mWifiNative).flushRingBufferData();
}
+
+ /** Verifies that we flush HAL ringbuffer when detecting fatal firmware alert. */
+ @Test
+ public void captureAlertFlushRingBufferData() {
+ when(mBuildProperties.isUserBuild()).thenReturn(false);
+ when(mWifiNative.flushRingBufferData()).thenReturn(true);
+ /** captureAlertData with mock fatal firmware alert*/
+ mWifiDiagnostics.captureAlertData(FATAL_FW_ALART_LIST[0], ALERT_DATA);
+ verify(mWifiNative).flushRingBufferData();
+ }
+
+ /** Verifies that we don't flush HAL ringbuffer when detecting non fatal firmware alert. */
+ @Test
+ public void captureNonAlertFlushRingBufferData() {
+ when(mBuildProperties.isUserBuild()).thenReturn(false);
+ when(mWifiNative.flushRingBufferData()).thenReturn(true);
+ /** captureAlertData with mock non fatal firmware alert*/
+ mWifiDiagnostics.captureAlertData(NON_FATAL_FW_ALART, ALERT_DATA);
+ verify(mWifiNative, never()).flushRingBufferData();
+ }
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiLockManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiLockManagerTest.java
index 7cedfe36d..a40de55e9 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiLockManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiLockManagerTest.java
@@ -360,7 +360,7 @@ public class WifiLockManagerTest {
acquireWifiLockSuccessful(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "", mBinder, mWorkSource);
- mWifiLockManager.updateWifiLockWorkSource(mBinder, null);
+ mWifiLockManager.updateWifiLockWorkSource(mBinder, newWorkSource);
InOrder inOrder = inOrder(mBatteryStats);
inOrder.verify(mBatteryStats).noteFullWifiLockAcquiredFromSource(eq(newWorkSource));
inOrder.verify(mBatteryStats).noteFullWifiLockReleasedFromSource(mWorkSource);
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java
index a55f1d29c..88ff48838 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java
@@ -533,12 +533,11 @@ public class WifiMetricsTest {
return testSavedNetworks;
}
- private PasspointProvider createMockProvider(int eapType) {
+ private PasspointProvider createMockProvider(int eapType, boolean validateForR2) {
PasspointProvider provider = mock(PasspointProvider.class);
- PasspointConfiguration config = new PasspointConfiguration();
+ PasspointConfiguration config = mock(PasspointConfiguration.class);
Credential credential = new Credential();
- config.setCredential(credential);
switch (eapType) {
case EAPConstants.EAP_TLS:
credential.setCertCredential(new Credential.CertificateCredential());
@@ -555,6 +554,8 @@ public class WifiMetricsTest {
break;
}
when(provider.getConfig()).thenReturn(config);
+ when(config.getCredential()).thenReturn(credential);
+ when(config.validateForR2()).thenReturn(validateForR2);
return provider;
}
@@ -570,7 +571,10 @@ public class WifiMetricsTest {
int eapType = SAVED_PASSPOINT_PROVIDERS_TYPE.keyAt(i);
int count = SAVED_PASSPOINT_PROVIDERS_TYPE.valueAt(i);
for (int j = 0; j < count; j++) {
- providers.put(Integer.toString(eapType) + j, createMockProvider(eapType));
+ providers.put(Integer.toString(eapType) + j, createMockProvider(eapType, false));
+ }
+ for (int j = count; j < count * 2; j++) {
+ providers.put(Integer.toString(eapType) + j, createMockProvider(eapType, true));
}
}
mWifiMetrics.updateSavedPasspointProfilesInfo(providers);
@@ -1127,28 +1131,8 @@ public class WifiMetricsTest {
assertEquals(NUM_CLIENT_INTERFACE_DOWN, mDecodedProto.numClientInterfaceDown);
assertEquals(NUM_SOFTAP_INTERFACE_DOWN, mDecodedProto.numSoftApInterfaceDown);
assertEquals(NUM_PASSPOINT_PROVIDERS, mDecodedProto.numPasspointProviders);
- for (PasspointProfileTypeCount passpointProfileType : mDecodedProto
- .installedPasspointProfileType) {
- switch(passpointProfileType.eapMethodType) {
- case PasspointProfileTypeCount.TYPE_EAP_AKA:
- assertEquals(NUM_EAP_AKA_TYPE, passpointProfileType.count);
- break;
- case PasspointProfileTypeCount.TYPE_EAP_AKA_PRIME:
- assertEquals(NUM_EAP_AKA_PRIME_TYPE, passpointProfileType.count);
- break;
- case PasspointProfileTypeCount.TYPE_EAP_SIM:
- assertEquals(NUM_EAP_SIM_TYPE, passpointProfileType.count);
- break;
- case PasspointProfileTypeCount.TYPE_EAP_TLS:
- assertEquals(NUM_EAP_TLS_TYPE, passpointProfileType.count);
- break;
- case PasspointProfileTypeCount.TYPE_EAP_TTLS:
- assertEquals(NUM_EAP_TTLS_TYPE, passpointProfileType.count);
- break;
- default:
- fail("unknown type counted");
- }
- }
+ assertPasspointProfileTypeCount(mDecodedProto.installedPasspointProfileTypeForR1);
+ assertPasspointProfileTypeCount(mDecodedProto.installedPasspointProfileTypeForR2);
assertEquals(NUM_PASSPOINT_PROVIDER_INSTALLATION,
mDecodedProto.numPasspointProviderInstallation);
assertEquals(NUM_PASSPOINT_PROVIDER_INSTALL_SUCCESS,
@@ -3262,6 +3246,8 @@ public class WifiMetricsTest {
WifiInfo info = mock(WifiInfo.class);
when(info.getRssi()).thenReturn(nextRandInt());
when(info.getLinkSpeed()).thenReturn(nextRandInt());
+ long eventTimeMs = nextRandInt();
+ when(mClock.getElapsedSinceBootMillis()).thenReturn(eventTimeMs);
WifiLinkLayerStats stats1 = nextRandomStats(new WifiLinkLayerStats());
mWifiMetrics.updateWifiUsabilityStatsEntries(info, stats1);
@@ -3277,6 +3263,7 @@ public class WifiMetricsTest {
assertEquals(WifiUsabilityStats.LABEL_GOOD, statsList[0].label);
assertEquals(WifiUsabilityStats.LABEL_BAD, statsList[1].label);
assertEquals(WifiIsUnusableEvent.TYPE_FIRMWARE_ALERT, statsList[1].triggerType);
+ assertEquals(eventTimeMs, statsList[1].timeStampMs);
assertEquals(2, statsList[1].firmwareAlertCode);
}
@@ -3290,6 +3277,8 @@ public class WifiMetricsTest {
WifiInfo info = mock(WifiInfo.class);
when(info.getRssi()).thenReturn(nextRandInt());
when(info.getLinkSpeed()).thenReturn(nextRandInt());
+ long eventTimeMs = nextRandInt();
+ when(mClock.getElapsedSinceBootMillis()).thenReturn(eventTimeMs);
WifiLinkLayerStats stats1 = nextRandomStats(new WifiLinkLayerStats());
mWifiMetrics.updateWifiUsabilityStatsEntries(info, stats1);
@@ -3305,6 +3294,7 @@ public class WifiMetricsTest {
assertEquals(WifiUsabilityStats.LABEL_BAD, statsList[1].label);
assertEquals(WifiIsUnusableEvent.TYPE_DATA_STALL_BAD_TX, statsList[1].triggerType);
assertEquals(-1, statsList[1].firmwareAlertCode);
+ assertEquals(eventTimeMs, statsList[1].timeStampMs);
}
/**
@@ -3653,6 +3643,8 @@ public class WifiMetricsTest {
WifiInfo info = mock(WifiInfo.class);
when(info.getRssi()).thenReturn(nextRandInt());
when(info.getLinkSpeed()).thenReturn(nextRandInt());
+ long eventTimeMs = nextRandInt();
+ when(mClock.getElapsedSinceBootMillis()).thenReturn(eventTimeMs);
WifiLinkLayerStats stats1 = nextRandomStats(new WifiLinkLayerStats());
mWifiMetrics.updateWifiUsabilityStatsEntries(info, stats1);
@@ -3667,6 +3659,7 @@ public class WifiMetricsTest {
WifiUsabilityStats[] statsList = mDecodedProto.wifiUsabilityStatsList;
assertEquals(WifiUsabilityStats.LABEL_BAD, statsList[1].label);
assertEquals(WifiUsabilityStats.TYPE_IP_REACHABILITY_LOST, statsList[1].triggerType);
+ assertEquals(eventTimeMs, statsList[1].timeStampMs);
}
/**
@@ -3958,4 +3951,60 @@ public class WifiMetricsTest {
stats2 = nextRandomStats(stats2);
return stats2;
}
+
+ /**
+ * Verify the counts of passpoint profile type are correct.
+ * @param profileTypes type and count of installed passpoint profiles
+ */
+ private void assertPasspointProfileTypeCount(PasspointProfileTypeCount[] profileTypes) {
+ for (PasspointProfileTypeCount passpointProfileType : profileTypes) {
+ switch(passpointProfileType.eapMethodType) {
+ case PasspointProfileTypeCount.TYPE_EAP_AKA:
+ assertEquals(NUM_EAP_AKA_TYPE, passpointProfileType.count);
+ break;
+ case PasspointProfileTypeCount.TYPE_EAP_AKA_PRIME:
+ assertEquals(NUM_EAP_AKA_PRIME_TYPE, passpointProfileType.count);
+ break;
+ case PasspointProfileTypeCount.TYPE_EAP_SIM:
+ assertEquals(NUM_EAP_SIM_TYPE, passpointProfileType.count);
+ break;
+ case PasspointProfileTypeCount.TYPE_EAP_TLS:
+ assertEquals(NUM_EAP_TLS_TYPE, passpointProfileType.count);
+ break;
+ case PasspointProfileTypeCount.TYPE_EAP_TTLS:
+ assertEquals(NUM_EAP_TTLS_TYPE, passpointProfileType.count);
+ break;
+ default:
+ fail("unknown type counted");
+ }
+ }
+ }
+
+ /**
+ * Verify that the LABEL_BAD Wifi usability stats are not saved if screen state is off.
+ * @throws Exception
+ */
+ @Test
+ public void verifyLabelBadStatsAreNotSavedIfScreenIsOff() throws Exception {
+ mWifiMetrics.setScreenState(false);
+ WifiInfo info = mock(WifiInfo.class);
+ when(info.getRssi()).thenReturn(nextRandInt());
+ when(info.getLinkSpeed()).thenReturn(nextRandInt());
+ WifiLinkLayerStats stats1 = nextRandomStats(new WifiLinkLayerStats());
+ mWifiMetrics.updateWifiUsabilityStatsEntries(info, stats1);
+
+ // Add 1 LABEL_GOOD
+ WifiLinkLayerStats statsGood = addGoodWifiUsabilityStats(nextRandomStats(stats1));
+ // IP reachability lost occurs
+ mWifiMetrics.addToWifiUsabilityStatsList(WifiUsabilityStats.LABEL_BAD,
+ WifiUsabilityStats.TYPE_IP_REACHABILITY_LOST, -1);
+ // Wifi data stall occurs
+ mWifiMetrics.addToWifiUsabilityStatsList(WifiUsabilityStats.LABEL_BAD,
+ WifiIsUnusableEvent.TYPE_DATA_STALL_BAD_TX, -1);
+ // Firmware alert occurs
+ mWifiMetrics.logFirmwareAlert(2);
+
+ dumpProtoAndDeserialize();
+ assertEquals(0, mDecodedProto.wifiUsabilityStatsList.length);
+ }
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiScoreCardTest.java b/tests/wifitests/src/com/android/server/wifi/WifiScoreCardTest.java
index 28aa180e9..577f5bc65 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiScoreCardTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiScoreCardTest.java
@@ -25,6 +25,7 @@ import android.net.MacAddress;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiSsid;
import android.util.Base64;
+import android.util.Pair;
import androidx.test.filters.SmallTest;
@@ -124,6 +125,26 @@ public class WifiScoreCardTest {
}
/**
+ * Test identifiers.
+ */
+ @Test
+ public void testIdentifiers() throws Exception {
+ mWifiInfo.setSSID(TEST_SSID_1);
+ mWifiInfo.setBSSID(TEST_BSSID_1.toString());
+ Pair<String, String> p1 = mWifiScoreCard.getL2KeyAndGroupHint(mWifiInfo);
+ assertNotNull(p1.first);
+ assertNotNull(p1.second);
+ mWifiInfo.setBSSID(TEST_BSSID_2.toString());
+ Pair<String, String> p2 = mWifiScoreCard.getL2KeyAndGroupHint(mWifiInfo);
+ assertNotEquals(p1.first, p2.first);
+ assertEquals(p1.second, p2.second);
+ mWifiInfo.setBSSID(null);
+ Pair<String, String> p3 = mWifiScoreCard.getL2KeyAndGroupHint(mWifiInfo);
+ assertNull(p3.first);
+ assertNull(p3.second);
+ }
+
+ /**
* Test rssi poll updates
*/
@Test
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java
index 6cbd84864..38a222f4d 100644
--- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkEvaluatorTest.java
@@ -487,6 +487,30 @@ public class PasspointNetworkEvaluatorTest {
}
/**
+ * Verify that it never creates an ephemeral Passpoint Configuration when the scan result is the
+ * one disconnected by user.
+ */
+ @Test
+ public void skipCreateEphemeralPasspointConfigurationForApDisconnectedByUser() {
+ // Setup ScanDetail and match providers.
+ List<ScanDetail> scanDetails = Arrays.asList(new ScanDetail[]{
+ generateScanDetail(TEST_SSID1, TEST_BSSID1)});
+ when(mTelephonyManager.getSimState()).thenReturn(TelephonyManager.SIM_STATE_READY);
+ when(mTelephonyManager.getSimCarrierId()).thenReturn(20);
+ when(mCarrierNetworkConfig.isCarrierEncryptionInfoAvailable()).thenReturn(true);
+ when(mPasspointManager.hasCarrierProvider(anyString())).thenReturn(false);
+ when(mPasspointManager.findEapMethodFromNAIRealmMatchedWithCarrier(
+ any(List.class))).thenReturn(
+ EAPConstants.EAP_AKA);
+ when(mWifiConfigManager.wasEphemeralNetworkDeleted("\"" + TEST_SSID1 + "\""))
+ .thenReturn(true);
+
+ assertEquals(null, mEvaluator.evaluateNetworks(
+ scanDetails, null, null, false, false, mOnConnectableListener));
+ verify(mPasspointManager, never()).createEphemeralPasspointConfigForCarrier(anyInt());
+ }
+
+ /**
* Verify that it never creates an ephemeral Passpoint Configuration when the profile for the
* carrier already exists.
*/
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/UtilsTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/UtilsTest.java
new file mode 100644
index 000000000..6ddeb263e
--- /dev/null
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/UtilsTest.java
@@ -0,0 +1,176 @@
+/*
+ * Copyright (C) 2019 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.hotspot2;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+
+/**
+ * Unit tests for {@link com.android.server.wifi.hotspot2.Utils}.
+ */
+public class UtilsTest {
+ @Test
+ public void testRoamingConsortiumsToStringLong() {
+ assertEquals("null", Utils.roamingConsortiumsToString((long[]) null));
+
+ long[] ois = new long[]{1L, 2L, 1L << (63 - 40)};
+ String expected = "000001, 000002, 0000800000";
+ String result = Utils.roamingConsortiumsToString(ois);
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void testRoamingConsortiumsToStringCollection() {
+ ArrayList<Long> ois = new ArrayList<>();
+ assertEquals("", Utils.roamingConsortiumsToString(ois));
+
+ ois.add(1L);
+ ois.add(2L);
+ ois.add((1L << (63 - 40)));
+ String expected = "000001, 000002, 0000800000";
+ String result = Utils.roamingConsortiumsToString(ois);
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void testToUnicodeEscapedString() {
+ assertEquals("", Utils.toUnicodeEscapedString(""));
+
+ StringBuilder unescapedStringBuilder = new StringBuilder();
+ StringBuilder escapedStringBuilder = new StringBuilder();
+ for (int c = 0; c < 128; c++) {
+ unescapedStringBuilder.append((char) c);
+ if (c >= ' ' && c < 127) {
+ escapedStringBuilder.append((char) c);
+ } else {
+ escapedStringBuilder.append("\\u").append(String.format("%04x", c));
+ }
+ }
+ assertEquals(escapedStringBuilder.toString(),
+ Utils.toUnicodeEscapedString(unescapedStringBuilder.toString()));
+ }
+
+ @Test
+ public void testToHexString() {
+ assertEquals("null", Utils.toHexString(null));
+
+ byte[] bytes = {(byte) 0xab, (byte) 0xcd, (byte) 0xef};
+ String expected = "ab cd ef";
+ String result = Utils.toHexString(bytes);
+ assertEquals(expected, result.toLowerCase());
+ }
+
+ @Test
+ public void testToHex() {
+ assertEquals("", Utils.toHex(new byte[0]));
+
+ byte[] bytes = {(byte) 0xab, (byte) 0xcd, (byte) 0xef};
+ String expected = "abcdef";
+ String result = Utils.toHex(bytes);
+ assertEquals(expected, result.toLowerCase());
+
+ }
+
+ @Test
+ public void testHexToBytes() {
+ assertArrayEquals(new byte[0], Utils.hexToBytes(""));
+
+ String hexString = "abcd";
+ byte[] expected = {(byte) 0xab, (byte) 0xcd};
+ byte[] result = Utils.hexToBytes(hexString);
+ assertArrayEquals(expected, result);
+ }
+
+ @Test
+ public void testFromHex() {
+ int i = 0;
+ for (char c : "0123456789abcdef".toCharArray()) {
+ assertEquals(i, Utils.fromHex(c, true));
+ assertEquals(i, Utils.fromHex(c, false));
+ assertEquals(i, Utils.fromHex(Character.toUpperCase(c), true));
+ assertEquals(i, Utils.fromHex(Character.toUpperCase(c), false));
+ i++;
+ }
+
+ assertEquals(-1, Utils.fromHex('q', true));
+
+ try {
+ Utils.fromHex('q', false);
+ fail("Exception should be thrown!");
+ } catch (NumberFormatException e) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testCompare() {
+ assertEquals(-1, Utils.compare(-1, 1));
+ assertEquals(0, Utils.compare(0, 0));
+ assertEquals(1, Utils.compare(1, -1));
+
+ assertEquals(-1, Utils.compare(null, 0));
+ assertEquals(0, Utils.compare(null, null));
+ assertEquals(1, Utils.compare(0, null));
+ }
+
+ @Test
+ public void testToHMS() {
+ long hours = 12;
+ long minutes = 34;
+ long millis = 56789;
+
+ long time = (((hours * 60) + minutes) * 60) * 1000 + millis;
+
+ String expected = "12:34:56.789";
+ String result = Utils.toHMS(time);
+ assertEquals(expected, result);
+
+ expected = "-12:34:56.789";
+ result = Utils.toHMS(-time);
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void testToUTCString() {
+ long millis = 832077296000L;
+
+ String expected = "1996/05/14 12:34:56Z";
+ String result = Utils.toUTCString(millis);
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void testUnquote() {
+ assertEquals(null, Utils.unquote(null));
+
+ String unquoted = "This is a wug.";
+ String quoted = "\"This is a wug.\"";
+ String twiceQuoted = "\"\"This is a wug.\"\"";
+ String unclosedQuoted = "\"This is a wug.";
+ String quotedUnclosedQuoted = "\"\"This is a wug.\"";
+
+ assertEquals(unquoted, Utils.unquote(quoted));
+ assertEquals(quoted, Utils.unquote(twiceQuoted));
+ assertEquals(unclosedQuoted, Utils.unquote(unclosedQuoted));
+ assertEquals(unclosedQuoted, Utils.unquote(quotedUnclosedQuoted));
+ }
+}
+
+
diff --git a/tests/wifitests/src/com/android/server/wifi/util/NativeUtilTest.java b/tests/wifitests/src/com/android/server/wifi/util/NativeUtilTest.java
index 79dcccfcc..d4bcb479e 100644
--- a/tests/wifitests/src/com/android/server/wifi/util/NativeUtilTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/util/NativeUtilTest.java
@@ -128,6 +128,18 @@ public class NativeUtilTest {
}
/**
+ * Test that conversion of SSID string with len > 32 to bytes fail.
+ */
+ @Test
+ public void testLargeSsidDecodeFails() throws Exception {
+ try {
+ NativeUtil.decodeSsid("\"asdrewqdfgyuiopldsqwertyuiolhdergcv\"");
+ fail("Expected ssid decode to fail");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ /**
* Test that conversion of ssid bytes to hex string ssid works.
*/
@Test
@@ -178,6 +190,25 @@ public class NativeUtilTest {
}
/**
+ * Test that conversion of SSID bytes with len > 32 to string fail.
+ */
+ @Test
+ public void testLargeSsidEncodeFails() throws Exception {
+ try {
+ NativeUtil.encodeSsid(new ArrayList<>(
+ Arrays.asList((byte) 0xf5, (byte) 0xe4, (byte) 0xab, (byte) 0x78, (byte) 0x78,
+ (byte) 0xab, (byte) 0x34, (byte) 0x32, (byte) 0x43, (byte) 0x9a,
+ (byte) 0xab, (byte) 0x34, (byte) 0x32, (byte) 0x43, (byte) 0x9a,
+ (byte) 0xab, (byte) 0x34, (byte) 0x32, (byte) 0x43, (byte) 0x9a,
+ (byte) 0xab, (byte) 0x34, (byte) 0x32, (byte) 0x43, (byte) 0x9a,
+ (byte) 0xab, (byte) 0x34, (byte) 0x32, (byte) 0x43, (byte) 0x9a,
+ (byte) 0xab, (byte) 0x34, (byte) 0x32, (byte) 0x43, (byte) 0x9a)));
+ fail("Expected ssid encode to fail");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ /**
* Test that parsing of quoted SSID to byte array and vice versa works.
*/
@Test