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/SavedNetworkEvaluatorTest.java27
-rw-r--r--tests/wifitests/src/com/android/server/wifi/TestUtil.java8
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java2
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiBackupRestoreTest.java22
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java119
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java81
-rw-r--r--tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java62
7 files changed, 226 insertions, 95 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/SavedNetworkEvaluatorTest.java b/tests/wifitests/src/com/android/server/wifi/SavedNetworkEvaluatorTest.java
index 78a3a3d0f..7f6360408 100644
--- a/tests/wifitests/src/com/android/server/wifi/SavedNetworkEvaluatorTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/SavedNetworkEvaluatorTest.java
@@ -172,6 +172,33 @@ public class SavedNetworkEvaluatorTest {
}
/**
+ * Do not evaluate networks that {@link WifiConfiguration#isEphemeral}.
+ */
+ @Test
+ public void ignoreEphemeralNetworks() {
+ String[] ssids = {"\"test1\"", "\"test2\""};
+ String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4"};
+ int[] freqs = {2470, 2437};
+ String[] caps = {"[ESS]", "[ESS]"};
+ int[] levels = {mThresholdQualifiedRssi2G + 8, mThresholdQualifiedRssi2G + 10};
+ int[] securities = {SECURITY_NONE, SECURITY_NONE};
+
+ ScanDetailsAndWifiConfigs scanDetailsAndConfigs =
+ WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids,
+ freqs, caps, levels, securities, mWifiConfigManager, mClock);
+ List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails();
+ WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs();
+ for (WifiConfiguration wifiConfiguration : savedConfigs) {
+ wifiConfiguration.ephemeral = true;
+ }
+
+ WifiConfiguration candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails,
+ null, null, true, false, null);
+
+ assertNull(candidate);
+ }
+
+ /**
* Set the candidate {@link ScanResult} for all {@link WifiConfiguration}s regardless of
* whether they are secure saved, open saved, or {@link WifiConfiguration#useExternalScores}.
*/
diff --git a/tests/wifitests/src/com/android/server/wifi/TestUtil.java b/tests/wifitests/src/com/android/server/wifi/TestUtil.java
index 90df07a61..a0a103026 100644
--- a/tests/wifitests/src/com/android/server/wifi/TestUtil.java
+++ b/tests/wifitests/src/com/android/server/wifi/TestUtil.java
@@ -74,14 +74,18 @@ public class TestUtil {
* Send {@link WifiManager#WIFI_AP_STATE_CHANGED} broadcast.
*/
public static void sendWifiApStateChanged(BroadcastReceiver broadcastReceiver,
- Context context, int apState, int previousState, int error) {
+ Context context, int apState, int previousState, int error, String ifaceName,
+ int mode) {
Intent intent = new Intent(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
intent.putExtra(WifiManager.EXTRA_WIFI_AP_STATE, apState);
intent.putExtra(WifiManager.EXTRA_PREVIOUS_WIFI_AP_STATE, previousState);
if (apState == WifiManager.WIFI_AP_STATE_FAILED) {
- //only set reason number when softAP start failed
+ // only set reason number when softAP start failed
intent.putExtra(WifiManager.EXTRA_WIFI_AP_FAILURE_REASON, error);
}
+ intent.putExtra(WifiManager.EXTRA_WIFI_AP_INTERFACE_NAME, ifaceName);
+ intent.putExtra(WifiManager.EXTRA_WIFI_AP_MODE, mode);
+
broadcastReceiver.onReceive(context, intent);
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java b/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java
index d4a3ff549..2d3b06695 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java
@@ -202,5 +202,7 @@ public class WifiApConfigStoreTest {
public void generateLocalOnlyHotspotConfigIsValid() {
WifiConfiguration config = WifiApConfigStore.generateLocalOnlyHotspotConfig(mContext);
verifyDefaultApConfig(config, TEST_DEFAULT_HOTSPOT_SSID);
+ // The LOHS config should also have a specific network id set - check that as well.
+ assertEquals(WifiConfiguration.LOCAL_ONLY_NETWORK_ID, config.networkId);
}
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiBackupRestoreTest.java b/tests/wifitests/src/com/android/server/wifi/WifiBackupRestoreTest.java
index 362540517..58b8d394b 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiBackupRestoreTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiBackupRestoreTest.java
@@ -24,10 +24,13 @@ import android.os.Process;
import android.test.suitebuilder.annotation.SmallTest;
import com.android.server.net.IpConfigStore;
+import com.android.server.wifi.util.WifiPermissionsUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
@@ -48,11 +51,15 @@ import java.util.Random;
@SmallTest
public class WifiBackupRestoreTest {
- private final WifiBackupRestore mWifiBackupRestore = new WifiBackupRestore();
+ @Mock WifiPermissionsUtil mWifiPermissionsUtil;
+ private WifiBackupRestore mWifiBackupRestore;
private boolean mCheckDump = true;
@Before
public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ when(mWifiPermissionsUtil.checkConfigOverridePermission(anyInt())).thenReturn(true);
+ mWifiBackupRestore = new WifiBackupRestore(mWifiPermissionsUtil);
// Enable verbose logging before tests to check the backup data dumps.
mWifiBackupRestore.enableVerboseLogging(1);
}
@@ -361,25 +368,34 @@ public class WifiBackupRestoreTest {
*/
@Test
public void testMultipleNetworksSystemAppBackupRestore() {
+ int systemAppUid = Process.SYSTEM_UID;
+ int nonSystemAppUid = Process.FIRST_APPLICATION_UID + 556;
+ when(mWifiPermissionsUtil.checkConfigOverridePermission(eq(systemAppUid)))
+ .thenReturn(true);
+ when(mWifiPermissionsUtil.checkConfigOverridePermission(eq(nonSystemAppUid)))
+ .thenReturn(false);
+
List<WifiConfiguration> configurations = new ArrayList<>();
List<WifiConfiguration> expectedConfigurations = new ArrayList<>();
WifiConfiguration wepNetwork = WifiConfigurationTestUtil.createWepNetwork();
+ wepNetwork.creatorUid = systemAppUid;
configurations.add(wepNetwork);
expectedConfigurations.add(wepNetwork);
// These should not be in |expectedConfigurations|.
WifiConfiguration nonSystemAppWepNetwork = WifiConfigurationTestUtil.createWepNetwork();
- nonSystemAppWepNetwork.creatorUid = Process.FIRST_APPLICATION_UID;
+ nonSystemAppWepNetwork.creatorUid = nonSystemAppUid;
configurations.add(nonSystemAppWepNetwork);
WifiConfiguration pskNetwork = WifiConfigurationTestUtil.createPskNetwork();
+ pskNetwork.creatorUid = systemAppUid;
configurations.add(pskNetwork);
expectedConfigurations.add(pskNetwork);
// These should not be in |expectedConfigurations|.
WifiConfiguration nonSystemAppPskNetwork = WifiConfigurationTestUtil.createPskNetwork();
- nonSystemAppPskNetwork.creatorUid = Process.FIRST_APPLICATION_UID + 1;
+ nonSystemAppPskNetwork.creatorUid = nonSystemAppUid;
configurations.add(nonSystemAppPskNetwork);
WifiConfiguration openNetwork = WifiConfigurationTestUtil.createOpenNetwork();
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
index 7342cdb16..45ffa8c04 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -97,6 +97,7 @@ import org.mockito.Spy;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.io.StringWriter;
+import java.util.List;
/**
* Unit tests for {@link WifiServiceImpl}.
@@ -132,6 +133,8 @@ public class WifiServiceImplTest {
ArgumentCaptor.forClass(IntentFilter.class);
final ArgumentCaptor<Message> mMessageCaptor = ArgumentCaptor.forClass(Message.class);
+ final ArgumentCaptor<SoftApModeConfiguration> mSoftApModeConfigCaptor =
+ ArgumentCaptor.forClass(SoftApModeConfiguration.class);
@Mock Context mContext;
@Mock WifiInjector mWifiInjector;
@@ -534,7 +537,9 @@ public class WifiServiceImplTest {
when(mUserManager.hasUserRestriction(eq(UserManager.DISALLOW_CONFIG_TETHERING)))
.thenReturn(false);
mWifiServiceImpl.setWifiApEnabled(null, true);
- verify(mWifiController).sendMessage(eq(CMD_SET_AP), eq(1), eq(0), eq(null));
+ verify(mWifiController)
+ .sendMessage(eq(CMD_SET_AP), eq(1), eq(0), mSoftApModeConfigCaptor.capture());
+ assertNull(mSoftApModeConfigCaptor.getValue().getWifiConfiguration());
}
/**
@@ -549,7 +554,9 @@ public class WifiServiceImplTest {
.thenReturn(false);
WifiConfiguration apConfig = new WifiConfiguration();
mWifiServiceImpl.setWifiApEnabled(apConfig, true);
- verify(mWifiController).sendMessage(eq(CMD_SET_AP), eq(1), eq(0), eq(apConfig));
+ verify(mWifiController).sendMessage(
+ eq(CMD_SET_AP), eq(1), eq(0), mSoftApModeConfigCaptor.capture());
+ assertEquals(apConfig, mSoftApModeConfigCaptor.getValue().getWifiConfiguration());
}
/**
@@ -562,7 +569,9 @@ public class WifiServiceImplTest {
when(mUserManager.hasUserRestriction(eq(UserManager.DISALLOW_CONFIG_TETHERING)))
.thenReturn(false);
mWifiServiceImpl.setWifiApEnabled(null, false);
- verify(mWifiController).sendMessage(eq(CMD_SET_AP), eq(0), eq(0), eq(null));
+ verify(mWifiController)
+ .sendMessage(eq(CMD_SET_AP), eq(0), eq(0), mSoftApModeConfigCaptor.capture());
+ assertNull(mSoftApModeConfigCaptor.getValue().getWifiConfiguration());
}
/**
@@ -576,7 +585,8 @@ public class WifiServiceImplTest {
// mApConfig is a mock and the values are not set - triggering the invalid config. Testing
// will be improved when we actually do test softap configs in b/37280779
mWifiServiceImpl.setWifiApEnabled(mApConfig, true);
- verify(mWifiController, never()).sendMessage(eq(CMD_SET_AP), eq(1), eq(0), eq(mApConfig));
+ verify(mWifiController, never())
+ .sendMessage(eq(CMD_SET_AP), eq(1), eq(0), any(SoftApModeConfiguration.class));
}
/**
@@ -613,7 +623,9 @@ public class WifiServiceImplTest {
public void testStartSoftApWithPermissionsAndNullConfig() {
boolean result = mWifiServiceImpl.startSoftAp(null);
assertTrue(result);
- verify(mWifiController).sendMessage(eq(CMD_SET_AP), eq(1), eq(0), eq(null));
+ verify(mWifiController)
+ .sendMessage(eq(CMD_SET_AP), eq(1), eq(0), mSoftApModeConfigCaptor.capture());
+ assertNull(mSoftApModeConfigCaptor.getValue().getWifiConfiguration());
}
/**
@@ -634,7 +646,9 @@ public class WifiServiceImplTest {
WifiConfiguration config = new WifiConfiguration();
boolean result = mWifiServiceImpl.startSoftAp(config);
assertTrue(result);
- verify(mWifiController).sendMessage(eq(CMD_SET_AP), eq(1), eq(0), eq(config));
+ verify(mWifiController)
+ .sendMessage(eq(CMD_SET_AP), eq(1), eq(0), mSoftApModeConfigCaptor.capture());
+ assertEquals(config, mSoftApModeConfigCaptor.getValue().getWifiConfiguration());
}
/**
@@ -874,7 +888,7 @@ public class WifiServiceImplTest {
public void testStopLocalOnlyHotspotTriggersSoftApStopWithOneRegisteredRequest() {
registerLOHSRequestFull();
verify(mWifiController)
- .sendMessage(eq(CMD_SET_AP), eq(1), eq(0), any(WifiConfiguration.class));
+ .sendMessage(eq(CMD_SET_AP), eq(1), eq(0), any(SoftApModeConfiguration.class));
mWifiServiceImpl.stopLocalOnlyHotspot();
// there is was only one request registered, we should tear down softap
@@ -957,7 +971,8 @@ public class WifiServiceImplTest {
registerLOHSRequestFull();
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_FAILED, WIFI_AP_STATE_DISABLED, SAP_START_FAILURE_GENERAL);
+ WIFI_AP_STATE_FAILED, WIFI_AP_STATE_DISABLED, SAP_START_FAILURE_GENERAL,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
mLooper.dispatchAll();
verify(mHandler).handleMessage(mMessageCaptor.capture());
Message message = mMessageCaptor.getValue();
@@ -981,7 +996,8 @@ public class WifiServiceImplTest {
registerLOHSRequestFull();
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_FAILED, WIFI_AP_STATE_DISABLED, SAP_START_FAILURE_NO_CHANNEL);
+ WIFI_AP_STATE_FAILED, WIFI_AP_STATE_DISABLED, SAP_START_FAILURE_NO_CHANNEL,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
mLooper.dispatchAll();
verify(mHandler).handleMessage(mMessageCaptor.capture());
@@ -1013,7 +1029,8 @@ public class WifiServiceImplTest {
reset(mHandler);
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_DISABLING, WIFI_AP_STATE_ENABLED, HOTSPOT_NO_ERROR);
+ WIFI_AP_STATE_DISABLING, WIFI_AP_STATE_ENABLED, HOTSPOT_NO_ERROR,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
mLooper.dispatchAll();
verify(mHandler).handleMessage(mMessageCaptor.capture());
@@ -1045,7 +1062,8 @@ public class WifiServiceImplTest {
reset(mHandler);
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_DISABLED, WIFI_AP_STATE_DISABLING, HOTSPOT_NO_ERROR);
+ WIFI_AP_STATE_DISABLED, WIFI_AP_STATE_DISABLING, HOTSPOT_NO_ERROR,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
mLooper.dispatchAll();
verify(mHandler).handleMessage(mMessageCaptor.capture());
@@ -1069,7 +1087,8 @@ public class WifiServiceImplTest {
registerLOHSRequestFull();
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_ENABLED, WIFI_AP_STATE_DISABLED, HOTSPOT_NO_ERROR);
+ WIFI_AP_STATE_ENABLED, WIFI_AP_STATE_DISABLED, HOTSPOT_NO_ERROR, WIFI_IFACE_NAME,
+ IFACE_IP_MODE_LOCAL_ONLY);
mLooper.dispatchAll();
verifyNoMoreInteractions(mHandler);
@@ -1099,9 +1118,11 @@ public class WifiServiceImplTest {
reset(mHandler);
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_DISABLING, WIFI_AP_STATE_ENABLED, HOTSPOT_NO_ERROR);
+ WIFI_AP_STATE_DISABLING, WIFI_AP_STATE_ENABLED, HOTSPOT_NO_ERROR,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_DISABLED, WIFI_AP_STATE_DISABLING, HOTSPOT_NO_ERROR);
+ WIFI_AP_STATE_DISABLED, WIFI_AP_STATE_DISABLING, HOTSPOT_NO_ERROR,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
mLooper.dispatchAll();
verify(mHandler).handleMessage(mMessageCaptor.capture());
@@ -1125,9 +1146,11 @@ public class WifiServiceImplTest {
registerLOHSRequestFull();
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_FAILED, WIFI_AP_STATE_FAILED, ERROR_GENERIC);
+ WIFI_AP_STATE_FAILED, WIFI_AP_STATE_FAILED, ERROR_GENERIC,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_FAILED, WIFI_AP_STATE_FAILED, ERROR_GENERIC);
+ WIFI_AP_STATE_FAILED, WIFI_AP_STATE_FAILED, ERROR_GENERIC,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
mLooper.dispatchAll();
verify(mHandler).handleMessage(mMessageCaptor.capture());
@@ -1155,9 +1178,11 @@ public class WifiServiceImplTest {
registerLOHSRequestFull();
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_FAILED, WIFI_AP_STATE_FAILED, ERROR_GENERIC);
+ WIFI_AP_STATE_FAILED, WIFI_AP_STATE_FAILED, ERROR_GENERIC,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_FAILED, WIFI_AP_STATE_FAILED, ERROR_GENERIC);
+ WIFI_AP_STATE_FAILED, WIFI_AP_STATE_FAILED, ERROR_GENERIC,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
verify(mRequestInfo).sendHotspotFailedMessage(ERROR_GENERIC);
mLooper.dispatchAll();
@@ -1194,9 +1219,11 @@ public class WifiServiceImplTest {
reset(mHandler);
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_DISABLING, WIFI_AP_STATE_ENABLED, HOTSPOT_NO_ERROR);
+ WIFI_AP_STATE_DISABLING, WIFI_AP_STATE_ENABLED, HOTSPOT_NO_ERROR,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_DISABLED, WIFI_AP_STATE_DISABLING, HOTSPOT_NO_ERROR);
+ WIFI_AP_STATE_DISABLED, WIFI_AP_STATE_DISABLING, HOTSPOT_NO_ERROR,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
verify(mRequestInfo).sendHotspotStoppedMessage();
mLooper.dispatchAll();
@@ -1223,9 +1250,11 @@ public class WifiServiceImplTest {
mWifiServiceImpl.registerLOHSForTest(TEST_PID2, mRequestInfo2);
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_DISABLING, WIFI_AP_STATE_ENABLED, HOTSPOT_NO_ERROR);
+ WIFI_AP_STATE_DISABLING, WIFI_AP_STATE_ENABLED, HOTSPOT_NO_ERROR,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_DISABLED, WIFI_AP_STATE_DISABLING, HOTSPOT_NO_ERROR);
+ WIFI_AP_STATE_DISABLED, WIFI_AP_STATE_DISABLING, HOTSPOT_NO_ERROR,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
verify(mRequestInfo).sendHotspotFailedMessage(ERROR_GENERIC);
verify(mRequestInfo2).sendHotspotFailedMessage(ERROR_GENERIC);
@@ -1383,9 +1412,11 @@ public class WifiServiceImplTest {
// now stop the hotspot
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_DISABLING, WIFI_AP_STATE_ENABLED, HOTSPOT_NO_ERROR);
+ WIFI_AP_STATE_DISABLING, WIFI_AP_STATE_ENABLED, HOTSPOT_NO_ERROR,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
TestUtil.sendWifiApStateChanged(mBroadcastReceiverCaptor.getValue(), mContext,
- WIFI_AP_STATE_DISABLED, WIFI_AP_STATE_DISABLING, HOTSPOT_NO_ERROR);
+ WIFI_AP_STATE_DISABLED, WIFI_AP_STATE_DISABLING, HOTSPOT_NO_ERROR,
+ WIFI_IFACE_NAME, IFACE_IP_MODE_LOCAL_ONLY);
mLooper.dispatchAll();
verify(mHandler).handleMessage(mMessageCaptor.capture());
assertEquals(HOTSPOT_STOPPED, mMessageCaptor.getValue().what);
@@ -1473,4 +1504,44 @@ public class WifiServiceImplTest {
verify(mWifiStateMachine).syncAddOrUpdatePasspointConfig(any(),
any(PasspointConfiguration.class), anyInt());
}
+
+ /**
+ * Verify that a call to {@link WifiServiceImpl#restoreBackupData(byte[])} is only allowed from
+ * callers with the signature only NETWORK_SETTINGS permission.
+ */
+ @Test(expected = SecurityException.class)
+ public void testRestoreBackupDataNotApprovedCaller() {
+ doThrow(new SecurityException()).when(mContext)
+ .enforceCallingOrSelfPermission(eq(android.Manifest.permission.NETWORK_SETTINGS),
+ eq("WifiService"));
+ mWifiServiceImpl.restoreBackupData(null);
+ verify(mWifiBackupRestore, never()).retrieveConfigurationsFromBackupData(any(byte[].class));
+ }
+
+ /**
+ * Verify that a call to {@link WifiServiceImpl#restoreSupplicantBackupData(byte[], byte[])} is
+ * only allowed from callers with the signature only NETWORK_SETTINGS permission.
+ */
+ @Test(expected = SecurityException.class)
+ public void testRestoreSupplicantBackupDataNotApprovedCaller() {
+ doThrow(new SecurityException()).when(mContext)
+ .enforceCallingOrSelfPermission(eq(android.Manifest.permission.NETWORK_SETTINGS),
+ eq("WifiService"));
+ mWifiServiceImpl.restoreSupplicantBackupData(null, null);
+ verify(mWifiBackupRestore, never()).retrieveConfigurationsFromSupplicantBackupData(
+ any(byte[].class), any(byte[].class));
+ }
+
+ /**
+ * Verify that a call to {@link WifiServiceImpl#retrieveBackupData()} is only allowed from
+ * callers with the signature only NETWORK_SETTINGS permission.
+ */
+ @Test(expected = SecurityException.class)
+ public void testRetrieveBackupDataNotApprovedCaller() {
+ doThrow(new SecurityException()).when(mContext)
+ .enforceCallingOrSelfPermission(eq(android.Manifest.permission.NETWORK_SETTINGS),
+ eq("WifiService"));
+ mWifiServiceImpl.retrieveBackupData();
+ verify(mWifiBackupRestore, never()).retrieveBackupDataFromConfigurations(any(List.class));
+ }
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
index be9b0c544..2a30b671b 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
@@ -16,6 +16,18 @@
package com.android.server.wifi;
+import static android.net.wifi.WifiManager.EXTRA_PREVIOUS_WIFI_AP_STATE;
+import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_FAILURE_REASON;
+import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_INTERFACE_NAME;
+import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_MODE;
+import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_STATE;
+import static android.net.wifi.WifiManager.WIFI_AP_STATE_DISABLED;
+import static android.net.wifi.WifiManager.WIFI_AP_STATE_DISABLING;
+import static android.net.wifi.WifiManager.WIFI_AP_STATE_ENABLED;
+import static android.net.wifi.WifiManager.WIFI_AP_STATE_ENABLING;
+
+import static com.android.server.wifi.LocalOnlyHotspotRequestInfo.HOTSPOT_NO_ERROR;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
@@ -303,6 +315,7 @@ public class WifiStateMachineTest {
static final String sHexSSID = sWifiSsid.getHexString().replace("0x", "").replace("22", "");
static final String sBSSID = "01:02:03:04:05:06";
static final int sFreq = 2437;
+ static final String WIFI_IFACE_NAME = "mockWlan";
WifiStateMachine mWsm;
HandlerThread mWsmThread;
@@ -315,6 +328,9 @@ public class WifiStateMachineTest {
TestLooper mLooper;
Context mContext;
+ final ArgumentCaptor<SoftApManager.Listener> mSoftApManagerListenerCaptor =
+ ArgumentCaptor.forClass(SoftApManager.Listener.class);
+
@Mock WifiScanner mWifiScanner;
@Mock SupplicantStateTracker mSupplicantStateTracker;
@Mock WifiMetrics mWifiMetrics;
@@ -370,7 +386,7 @@ public class WifiStateMachineTest {
when(mWifiInjector.makeWifiConnectivityManager(any(WifiInfo.class), anyBoolean()))
.thenReturn(mWifiConnectivityManager);
when(mWifiInjector.makeSoftApManager(any(INetworkManagementService.class),
- any(SoftApManager.Listener.class), any(IApInterface.class),
+ mSoftApManagerListenerCaptor.capture(), any(IApInterface.class),
any(WifiConfiguration.class)))
.thenReturn(mSoftApManager);
when(mWifiInjector.getPasspointManager()).thenReturn(mPasspointManager);
@@ -381,7 +397,8 @@ public class WifiStateMachineTest {
when(mWifiNative.setupForClientMode()).thenReturn(mClientInterface);
when(mWifiNative.setupForSoftApMode()).thenReturn(mApInterface);
- when(mWifiNative.getInterfaceName()).thenReturn("mockWlan");
+ when(mApInterface.getInterfaceName()).thenReturn(WIFI_IFACE_NAME);
+ when(mWifiNative.getInterfaceName()).thenReturn(WIFI_IFACE_NAME);
when(mWifiNative.enableSupplicant()).thenReturn(true);
when(mWifiNative.disableSupplicant()).thenReturn(true);
when(mWifiNative.getFrameworkNetworkId(anyInt())).thenReturn(0);
@@ -478,14 +495,64 @@ public class WifiStateMachineTest {
assertEquals("DisconnectedState", getCurrentState().getName());
}
- @Test
- public void loadComponentsInApMode() throws Exception {
- mWsm.setHostApRunning(new WifiConfiguration(), true);
+ private void checkApStateChangedBroadcast(Intent intent, int expectedCurrentState,
+ int expectedPrevState, int expectedErrorCode, String expectedIfaceName,
+ int expectedMode) {
+ int currentState = intent.getIntExtra(EXTRA_WIFI_AP_STATE, WIFI_AP_STATE_DISABLED);
+ int prevState = intent.getIntExtra(EXTRA_PREVIOUS_WIFI_AP_STATE, WIFI_AP_STATE_DISABLED);
+ int errorCode = intent.getIntExtra(EXTRA_WIFI_AP_FAILURE_REASON, HOTSPOT_NO_ERROR);
+ String ifaceName = intent.getStringExtra(EXTRA_WIFI_AP_INTERFACE_NAME);
+ int mode = intent.getIntExtra(EXTRA_WIFI_AP_MODE, WifiManager.IFACE_IP_MODE_UNSPECIFIED);
+ assertEquals(expectedCurrentState, currentState);
+ assertEquals(expectedPrevState, prevState);
+ assertEquals(expectedErrorCode, errorCode);
+ assertEquals(expectedIfaceName, ifaceName);
+ assertEquals(expectedMode, mode);
+ }
+
+ private void loadComponentsInApMode(int mode) throws Exception {
+ SoftApModeConfiguration config = new SoftApModeConfiguration(mode, new WifiConfiguration());
+ mWsm.setHostApRunning(config, true);
mLooper.dispatchAll();
assertEquals("SoftApState", getCurrentState().getName());
verify(mSoftApManager).start();
+
+ // reset expectations for mContext due to previously sent AP broadcast
+ reset(mContext);
+
+ // get the SoftApManager.Listener and trigger some updates
+ SoftApManager.Listener listener = mSoftApManagerListenerCaptor.getValue();
+ listener.onStateChanged(WIFI_AP_STATE_ENABLING, 0);
+ listener.onStateChanged(WIFI_AP_STATE_ENABLED, 0);
+ listener.onStateChanged(WIFI_AP_STATE_DISABLING, 0);
+ // note, this will trigger a mode change when TestLooper is dispatched
+ listener.onStateChanged(WIFI_AP_STATE_DISABLED, 0);
+
+ ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
+ verify(mContext, times(4))
+ .sendStickyBroadcastAsUser(intentCaptor.capture(), eq(UserHandle.ALL));
+
+ List<Intent> capturedIntents = intentCaptor.getAllValues();
+ checkApStateChangedBroadcast(capturedIntents.get(0), WIFI_AP_STATE_ENABLING,
+ WIFI_AP_STATE_DISABLED, HOTSPOT_NO_ERROR, WIFI_IFACE_NAME, mode);
+ checkApStateChangedBroadcast(capturedIntents.get(1), WIFI_AP_STATE_ENABLED,
+ WIFI_AP_STATE_ENABLING, HOTSPOT_NO_ERROR, WIFI_IFACE_NAME, mode);
+ checkApStateChangedBroadcast(capturedIntents.get(2), WIFI_AP_STATE_DISABLING,
+ WIFI_AP_STATE_ENABLED, HOTSPOT_NO_ERROR, WIFI_IFACE_NAME, mode);
+ checkApStateChangedBroadcast(capturedIntents.get(3), WIFI_AP_STATE_DISABLED,
+ WIFI_AP_STATE_DISABLING, HOTSPOT_NO_ERROR, WIFI_IFACE_NAME, mode);
+ }
+
+ @Test
+ public void loadComponentsInApModeForTethering() throws Exception {
+ loadComponentsInApMode(WifiManager.IFACE_IP_MODE_TETHERED);
+ }
+
+ @Test
+ public void loadComponentsInApModeForLOHS() throws Exception {
+ loadComponentsInApMode(WifiManager.IFACE_IP_MODE_LOCAL_ONLY);
}
@Test
@@ -609,7 +676,9 @@ public class WifiStateMachineTest {
mWsm.setSupplicantRunning(false);
mWsm.sendMessage(WifiStateMachine.CMD_DISABLE_P2P_RSP);
mWsm.sendMessage(WifiMonitor.SUP_DISCONNECTION_EVENT);
- mWsm.setHostApRunning(new WifiConfiguration(), true);
+ SoftApModeConfiguration config = new SoftApModeConfiguration(
+ WifiManager.IFACE_IP_MODE_TETHERED, new WifiConfiguration());
+ mWsm.setHostApRunning(config, true);
mLooper.dispatchAll();
assertEquals("SoftApState", getCurrentState().getName());
assertEquals(WifiManager.WIFI_STATE_DISABLED, mWsm.syncGetWifiState());
diff --git a/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java b/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java
index d9fbb1d28..e7c5fa962 100644
--- a/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java
@@ -1257,10 +1257,10 @@ public class WifiScanningServiceTest {
}
/**
- * Verify that the newest full scan results are returned by WifiService.getSingleScanResults.
+ * Verify that the newest scan results are returned by WifiService.getSingleScanResults.
*/
@Test
- public void retrieveMostRecentFullSingleScanResults() throws Exception {
+ public void retrieveMostRecentSingleScanResults() throws Exception {
WifiScanner.ScanSettings requestSettings = createRequest(WifiScanner.WIFI_BAND_BOTH, 0,
0, 20, WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN);
ScanResults expectedResults = ScanResults.create(0, true, 2400, 5150, 5175);
@@ -1312,64 +1312,6 @@ public class WifiScanningServiceTest {
}
/**
- * Verify that the newest partial scan results are not returned by
- * WifiService.getSingleScanResults.
- */
- @Test
- public void doesNotRetrieveMostRecentPartialSingleScanResults() throws Exception {
- WifiScanner.ScanSettings fullRequestSettings = createRequest(WifiScanner.WIFI_BAND_BOTH, 0,
- 0, 20, WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN);
- ScanResults expectedFullResults = ScanResults.create(0, true, 2400, 5150, 5175);
- doSuccessfulSingleScan(fullRequestSettings,
- computeSingleScanNativeSettings(fullRequestSettings),
- expectedFullResults);
-
- Handler handler = mock(Handler.class);
- BidirectionalAsyncChannel controlChannel = connectChannel(handler);
- InOrder order = inOrder(handler, mWifiScannerImpl);
-
- controlChannel.sendMessage(
- Message.obtain(null, WifiScanner.CMD_GET_SINGLE_SCAN_RESULTS, 0));
- mLooper.dispatchAll();
- Message response = verifyHandleMessageAndGetMessage(order, handler);
-
- List<ScanResult> results = Arrays.asList(
- ((WifiScanner.ParcelableScanResults) response.obj).getResults());
- assertEquals(results.size(), expectedFullResults.getRawScanResults().length);
-
- // now update with a new scan that only has one result
- int secondScanRequestId = 35;
- WifiScanner.ScanSettings partialRequestSettings = createRequest(WifiScanner.WIFI_BAND_BOTH,
- 0, 0, 20, WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN);
- ScanResults expectedPartialResults = ScanResults.create(0, false, 5150);
- sendSingleScanRequest(controlChannel, secondScanRequestId, partialRequestSettings, null);
-
- mLooper.dispatchAll();
- WifiNative.ScanEventHandler eventHandler = verifyStartSingleScan(order,
- computeSingleScanNativeSettings(partialRequestSettings));
- verifySuccessfulResponse(order, handler, secondScanRequestId);
-
- // dispatch scan 2 results
- when(mWifiScannerImpl.getLatestSingleScanResults())
- .thenReturn(expectedPartialResults.getScanData());
- eventHandler.onScanStatus(WifiNative.WIFI_SCAN_RESULTS_AVAILABLE);
-
- mLooper.dispatchAll();
- verifyScanResultsReceived(order, handler, secondScanRequestId,
- expectedPartialResults.getScanData());
- verifySingleScanCompletedReceived(order, handler, secondScanRequestId);
-
- controlChannel.sendMessage(
- Message.obtain(null, WifiScanner.CMD_GET_SINGLE_SCAN_RESULTS, 0));
- mLooper.dispatchAll();
- Message response2 = verifyHandleMessageAndGetMessage(order, handler);
-
- List<ScanResult> results2 = Arrays.asList(
- ((WifiScanner.ParcelableScanResults) response2.obj).getResults());
- assertEquals(results2.size(), expectedFullResults.getRawScanResults().length);
- }
-
- /**
* Cached scan results should be cleared after the driver is unloaded.
*/
@Test