summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPatrik Fimml <patrikf@google.com>2019-10-17 15:29:19 +0200
committerPatrik Fimml <patrikf@google.com>2019-10-30 11:56:10 +0100
commitb062c908670fb4180f6935d0cac0927d11fe7b6b (patch)
tree759f9a402c91d40613148a831f101cb7b0af699f /tests
parent7c40e73a914a8cd41dc7fcc3332f4ce6aeb5af3c (diff)
Configurable SoftAP: Service implementation.
Implements the new configurable LOHS API introduced for system apps. The regular LOHS flow is largely shared and almost unchanged. When custom configuration is applied to a LOHS it becomes "exclusive" and we prohibit sharing it with other apps. Bug: 132705022 Test: atest ActiveModeWardenTest LocalOnlyHotspotRequestInfoTest SoftApManagerTest WifiApConfigStoreTest WifiServiceImplTest Test: atest android.net.wifi.cts.WifiManagerTest Change-Id: I46afe716cf4fd7402f64e9fa1c7d81d1fd127afc
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java2
-rw-r--r--tests/wifitests/src/com/android/server/wifi/LocalOnlyHotspotRequestInfoTest.java30
-rw-r--r--tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java43
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java61
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java185
5 files changed, 279 insertions, 42 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java b/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java
index 4bfeac395..073ef4e3f 100644
--- a/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java
@@ -876,7 +876,7 @@ public class ActiveModeWardenTest extends WifiBaseTest {
SoftApModeConfiguration tetherConfig =
new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, null);
WifiConfiguration lohsConfigWC = WifiApConfigStore.generateLocalOnlyHotspotConfig(mContext,
- WifiConfiguration.AP_BAND_2GHZ);
+ WifiConfiguration.AP_BAND_2GHZ, null);
SoftApModeConfiguration lohsConfig =
new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_LOCAL_ONLY, lohsConfigWC);
diff --git a/tests/wifitests/src/com/android/server/wifi/LocalOnlyHotspotRequestInfoTest.java b/tests/wifitests/src/com/android/server/wifi/LocalOnlyHotspotRequestInfoTest.java
index b90332ad2..31ede2fd0 100644
--- a/tests/wifitests/src/com/android/server/wifi/LocalOnlyHotspotRequestInfoTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/LocalOnlyHotspotRequestInfoTest.java
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;
import android.net.wifi.ILocalOnlyHotspotCallback;
+import android.net.wifi.SoftApConfiguration;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.os.IBinder;
@@ -62,7 +63,7 @@ public class LocalOnlyHotspotRequestInfoTest extends WifiBaseTest {
*/
@Test
public void verifyBinderLinkToDeathIsCalled() throws Exception {
- mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(mCallback, mDeathCallback);
+ mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(mCallback, mDeathCallback, null);
verify(mAppBinder).linkToDeath(eq(mLOHSRequestInfo), eq(0));
}
@@ -71,7 +72,7 @@ public class LocalOnlyHotspotRequestInfoTest extends WifiBaseTest {
*/
@Test(expected = NullPointerException.class)
public void verifyNullCallbackChecked() throws Exception {
- mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(null, mDeathCallback);
+ mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(null, mDeathCallback, null);
}
/**
@@ -79,7 +80,7 @@ public class LocalOnlyHotspotRequestInfoTest extends WifiBaseTest {
*/
@Test(expected = NullPointerException.class)
public void verifyNullDeathCallbackChecked() throws Exception {
- mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(mCallback, null);
+ mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(mCallback, null, null);
}
/**
@@ -87,7 +88,7 @@ public class LocalOnlyHotspotRequestInfoTest extends WifiBaseTest {
*/
@Test
public void verifyUnlinkDeathRecipientUnlinksFromBinder() throws Exception {
- mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(mCallback, mDeathCallback);
+ mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(mCallback, mDeathCallback, null);
mLOHSRequestInfo.unlinkDeathRecipient();
verify(mAppBinder).unlinkToDeath(eq(mLOHSRequestInfo), eq(0));
}
@@ -97,7 +98,7 @@ public class LocalOnlyHotspotRequestInfoTest extends WifiBaseTest {
*/
@Test
public void verifyBinderDeathTriggersCallback() {
- mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(mCallback, mDeathCallback);
+ mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(mCallback, mDeathCallback, null);
mLOHSRequestInfo.binderDied();
verify(mDeathCallback).onLocalOnlyHotspotRequestorDeath(eq(mLOHSRequestInfo));
}
@@ -109,7 +110,7 @@ public class LocalOnlyHotspotRequestInfoTest extends WifiBaseTest {
public void verifyRemoteExceptionTriggersCallback() throws Exception {
doThrow(mRemoteException).when(mAppBinder)
.linkToDeath(any(IBinder.DeathRecipient.class), eq(0));
- mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(mCallback, mDeathCallback);
+ mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(mCallback, mDeathCallback, null);
verify(mDeathCallback).onLocalOnlyHotspotRequestorDeath(eq(mLOHSRequestInfo));
}
@@ -118,16 +119,25 @@ public class LocalOnlyHotspotRequestInfoTest extends WifiBaseTest {
*/
@Test
public void verifyPid() {
- mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(mCallback, mDeathCallback);
+ mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(mCallback, mDeathCallback, null);
assertEquals(Process.myPid(), mLOHSRequestInfo.getPid());
}
+ @Test
+ public void verifyCustomConfig() {
+ SoftApConfiguration config = new SoftApConfiguration.Builder()
+ .setSsid("customSsid")
+ .build();
+ mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(mCallback, mDeathCallback, config);
+ assertEquals(config, mLOHSRequestInfo.getCustomConfig());
+ }
+
/**
* Verify that sendHotspotFailedMessage does send a Message properly
*/
@Test
public void verifySendFailedMessage() throws Exception {
- mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(mCallback, mDeathCallback);
+ mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(mCallback, mDeathCallback, null);
mLOHSRequestInfo.sendHotspotFailedMessage(
WifiManager.LocalOnlyHotspotCallback.ERROR_GENERIC);
verify(mCallback).onHotspotFailed(WifiManager.LocalOnlyHotspotCallback.ERROR_GENERIC);
@@ -138,7 +148,7 @@ public class LocalOnlyHotspotRequestInfoTest extends WifiBaseTest {
*/
@Test
public void verifySendStartedMessage() throws Exception {
- mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(mCallback, mDeathCallback);
+ mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(mCallback, mDeathCallback, null);
WifiConfiguration config = mock(WifiConfiguration.class);
mLOHSRequestInfo.sendHotspotStartedMessage(config);
verify(mCallback).onHotspotStarted(config);
@@ -149,7 +159,7 @@ public class LocalOnlyHotspotRequestInfoTest extends WifiBaseTest {
*/
@Test
public void verifySendStoppedMessage() throws Exception {
- mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(mCallback, mDeathCallback);
+ mLOHSRequestInfo = new LocalOnlyHotspotRequestInfo(mCallback, mDeathCallback, null);
mLOHSRequestInfo.sendHotspotStoppedMessage();
verify(mCallback).onHotspotStopped();
}
diff --git a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java
index 1f5166abb..9fd36fbd9 100644
--- a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java
@@ -22,6 +22,7 @@ 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.IFACE_IP_MODE_LOCAL_ONLY;
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;
@@ -37,7 +38,6 @@ import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.anyLong;
import static org.mockito.Mockito.anyString;
-import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.never;
@@ -148,6 +148,8 @@ public class SoftApManagerTest extends WifiBaseTest {
TEST_INTERFACE_NAME, TEST_COUNTRY_CODE.toUpperCase(Locale.ROOT)))
.thenReturn(true);
when(mWifiNative.getFactoryMacAddress(any())).thenReturn(TEST_MAC_ADDRESS);
+ when(mWifiApConfigStore.randomizeBssidIfUnset(any(), any())).thenAnswer(
+ (invocation) -> invocation.getArgument(1));
}
private WifiConfiguration createDefaultApConfig() {
@@ -1134,41 +1136,36 @@ public class SoftApManagerTest extends WifiBaseTest {
}
@Test
- public void setsRandomMacWhenEnabled() throws Exception {
+ public void resetsFactoryMacWhenRandomizationOff() throws Exception {
+ WifiConfiguration config = new WifiConfiguration();
+ config.apBand = WifiConfiguration.AP_BAND_2GHZ;
+ config.SSID = TEST_SSID;
+ config.BSSID = null;
SoftApModeConfiguration apConfig =
- new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, null);
- when(mResources.getBoolean(R.bool.config_wifi_ap_mac_randomization_supported))
- .thenReturn(true);
+ new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config);
ArgumentCaptor<MacAddress> mac = ArgumentCaptor.forClass(MacAddress.class);
+ when(mWifiNative.getFactoryMacAddress(TEST_INTERFACE_NAME)).thenReturn(TEST_MAC_ADDRESS);
when(mWifiNative.setMacAddress(eq(TEST_INTERFACE_NAME), mac.capture())).thenReturn(true);
startSoftApAndVerifyEnabled(apConfig);
- mSoftApManager.stop();
- mLooper.dispatchAll();
-
- clearInvocations(mWifiNative, mCallback, mSarManager, mWifiDiagnostics, mWifiMetrics,
- mListener, mFrameworkFacade, mContext);
-
- startSoftApAndVerifyEnabled(apConfig);
- mSoftApManager.stop();
- assertThat(mac.getAllValues()).hasSize(2);
- assertThat(mac.getAllValues()).containsNoDuplicates();
+ assertThat(mac.getValue()).isEqualTo(TEST_MAC_ADDRESS);
}
@Test
- public void resetsFactoryMacWhenRandomizationOff() throws Exception {
- when(mResources.getBoolean(R.bool.config_wifi_ap_mac_randomization_supported))
- .thenReturn(false);
- SoftApModeConfiguration apConfig =
- new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, null);
+ public void setsCustomMac() throws Exception {
+ WifiConfiguration config = new WifiConfiguration();
+ config.apBand = WifiConfiguration.AP_BAND_2GHZ;
+ config.SSID = TEST_SSID;
+ config.BSSID = "23:34:45:56:67:78";
+ SoftApModeConfiguration apConfig = new SoftApModeConfiguration(
+ IFACE_IP_MODE_LOCAL_ONLY, config);
ArgumentCaptor<MacAddress> mac = ArgumentCaptor.forClass(MacAddress.class);
- when(mWifiNative.getFactoryMacAddress(TEST_INTERFACE_NAME)).thenReturn(TEST_MAC_ADDRESS);
when(mWifiNative.setMacAddress(eq(TEST_INTERFACE_NAME), mac.capture())).thenReturn(true);
startSoftApAndVerifyEnabled(apConfig);
- assertThat(mac.getValue()).isEqualTo(TEST_MAC_ADDRESS);
+ assertThat(mac.getValue()).isEqualTo(MacAddress.fromString("23:34:45:56:67:78"));
}
@Test
@@ -1238,7 +1235,7 @@ public class SoftApManagerTest extends WifiBaseTest {
WIFI_AP_STATE_ENABLING, HOTSPOT_NO_ERROR, TEST_INTERFACE_NAME,
softApConfig.getTargetMode());
verify(mListener).onStarted();
- verify(mWifiMetrics).addSoftApUpChangedEvent(true, softApConfig.mTargetMode);
+ verify(mWifiMetrics).addSoftApUpChangedEvent(true, softApConfig.getTargetMode());
verify(mFrameworkFacade).registerContentObserver(eq(mContext), any(Uri.class), eq(true),
observerCaptor.capture());
mContentObserver = observerCaptor.getValue();
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java b/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java
index 8799ba6e2..774af4de0 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java
@@ -16,6 +16,8 @@
package com.android.server.wifi;
+import static com.google.common.truth.Truth.assertThat;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -31,6 +33,8 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
+import android.net.MacAddress;
+import android.net.wifi.SoftApConfiguration;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiConfiguration.KeyMgmt;
import android.os.Build;
@@ -543,7 +547,7 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
@Test
public void generateLocalOnlyHotspotConfigIsValid() {
WifiConfiguration config = WifiApConfigStore
- .generateLocalOnlyHotspotConfig(mContext, WifiConfiguration.AP_BAND_2GHZ);
+ .generateLocalOnlyHotspotConfig(mContext, WifiConfiguration.AP_BAND_2GHZ, null);
verifyDefaultLocalOnlyApConfig(config, TEST_DEFAULT_HOTSPOT_SSID,
WifiConfiguration.AP_BAND_2GHZ);
// The LOHS config should also have a specific network id set - check that as well.
@@ -559,7 +563,7 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
@Test
public void generateLocalOnlyHotspotConfigIsValid5G() {
WifiConfiguration config = WifiApConfigStore
- .generateLocalOnlyHotspotConfig(mContext, WifiConfiguration.AP_BAND_5GHZ);
+ .generateLocalOnlyHotspotConfig(mContext, WifiConfiguration.AP_BAND_5GHZ, null);
verifyDefaultLocalOnlyApConfig(config, TEST_DEFAULT_HOTSPOT_SSID,
WifiConfiguration.AP_BAND_5GHZ);
// The LOHS config should also have a specific network id set - check that as well.
@@ -569,6 +573,59 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
assertTrue(WifiApConfigStore.validateApWifiConfiguration(config));
}
+ @Test
+ public void generateLohsConfig_forwardsCustomMac() {
+ SoftApConfiguration customConfig = new SoftApConfiguration.Builder()
+ .setBssid(MacAddress.fromString("11:22:33:44:55:66"))
+ .build();
+ WifiConfiguration wifiConfig = WifiApConfigStore.generateLocalOnlyHotspotConfig(
+ mContext, WifiConfiguration.AP_BAND_2GHZ, customConfig);
+ assertThat(wifiConfig.BSSID).isNotEmpty();
+ assertThat(MacAddress.fromString(wifiConfig.BSSID)).isEqualTo(
+ MacAddress.fromString("11:22:33:44:55:66"));
+ }
+
+ @Test
+ public void randomizeBssid_randomizesWhenEnabled() {
+ mResources.setBoolean(R.bool.config_wifi_ap_mac_randomization_supported, true);
+ WifiConfiguration baseConfig = new WifiConfiguration();
+
+ WifiApConfigStore store = createWifiApConfigStore();
+ WifiConfiguration config1 = store.randomizeBssidIfUnset(mContext, baseConfig);
+ WifiConfiguration config2 = store.randomizeBssidIfUnset(mContext, baseConfig);
+
+ assertThat(config1.BSSID).isNotNull();
+ assertThat(config2.BSSID).isNotNull();
+ MacAddress mac1 = MacAddress.fromString(config1.BSSID);
+ MacAddress mac2 = MacAddress.fromString(config2.BSSID);
+ assertThat(mac1).isNotEqualTo(mac2);
+ }
+
+ @Test
+ public void randomizeBssid_usesFactoryMacWhenRandomizationOff() {
+ mResources.setBoolean(R.bool.config_wifi_ap_mac_randomization_supported, false);
+ WifiConfiguration baseConfig = new WifiConfiguration();
+
+ WifiApConfigStore store = createWifiApConfigStore();
+ WifiConfiguration config = store.randomizeBssidIfUnset(mContext, baseConfig);
+
+ assertThat(config.BSSID).isNull();
+ }
+
+ @Test
+ public void randomizeBssid_forwardsCustomMac() {
+ mResources.setBoolean(R.bool.config_wifi_ap_mac_randomization_supported, true);
+ WifiConfiguration baseConfig = new WifiConfiguration();
+ baseConfig.BSSID = "11:22:33:44:55:66";
+
+ WifiApConfigStore store = createWifiApConfigStore();
+ WifiConfiguration config = store.randomizeBssidIfUnset(mContext, baseConfig);
+
+ assertThat(config.BSSID).isNotEmpty();
+ assertThat(MacAddress.fromString(config.BSSID)).isEqualTo(
+ MacAddress.fromString("11:22:33:44:55:66"));
+ }
+
/**
* Helper method to generate random SSIDs.
*
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
index a009943a2..fd0ad2582 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -24,6 +24,7 @@ import static android.net.wifi.WifiManager.LocalOnlyHotspotCallback.ERROR_GENERI
import static android.net.wifi.WifiManager.LocalOnlyHotspotCallback.ERROR_INCOMPATIBLE_MODE;
import static android.net.wifi.WifiManager.LocalOnlyHotspotCallback.ERROR_NO_CHANNEL;
import static android.net.wifi.WifiManager.LocalOnlyHotspotCallback.ERROR_TETHERING_DISALLOWED;
+import static android.net.wifi.WifiManager.LocalOnlyHotspotCallback.REQUEST_REGISTERED;
import static android.net.wifi.WifiManager.SAP_START_FAILURE_GENERAL;
import static android.net.wifi.WifiManager.SAP_START_FAILURE_NO_CHANNEL;
import static android.net.wifi.WifiManager.WIFI_AP_STATE_DISABLED;
@@ -35,6 +36,8 @@ import static android.net.wifi.WifiManager.WIFI_STATE_DISABLED;
import static com.android.server.wifi.LocalOnlyHotspotRequestInfo.HOTSPOT_NO_ERROR;
+import static com.google.common.truth.Truth.assertThat;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -95,6 +98,7 @@ import android.net.wifi.ISoftApCallback;
import android.net.wifi.ITrafficStateCallback;
import android.net.wifi.ITxPacketCountListener;
import android.net.wifi.ScanResult;
+import android.net.wifi.SoftApConfiguration;
import android.net.wifi.WifiClient;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiConfiguration.KeyMgmt;
@@ -145,7 +149,6 @@ import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
-import org.mockito.Spy;
import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -268,7 +271,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
@Mock ILocalOnlyHotspotCallback mLohsCallback;
@Mock IScanResultsListener mClientScanResultsListener;
- @Spy FakeWifiLog mLog;
+ WifiLog mLog = new LogcatLog(TAG);
@Before public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
@@ -376,6 +379,10 @@ public class WifiServiceImplTest extends WifiBaseTest {
return null;
}
};
+
+ // permission not granted by default
+ doThrow(SecurityException.class).when(mContext).enforceCallingOrSelfPermission(
+ eq(Manifest.permission.NETWORK_SETUP_WIZARD), any());
}
/**
@@ -1432,13 +1439,16 @@ public class WifiServiceImplTest extends WifiBaseTest {
assertTrue(retrievedScanResultList.isEmpty());
}
- private void registerLOHSRequestFull() {
- // allow test to proceed without a permission check failure
+ private void setupLohsPermissions() {
when(mWifiPermissionsUtil.isLocationModeEnabled()).thenReturn(true);
when(mFrameworkFacade.isAppForeground(any(), anyInt())).thenReturn(true);
when(mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING))
.thenReturn(false);
- int result = mWifiServiceImpl.startLocalOnlyHotspot(mLohsCallback, TEST_PACKAGE_NAME);
+ }
+
+ private void registerLOHSRequestFull() {
+ setupLohsPermissions();
+ int result = mWifiServiceImpl.startLocalOnlyHotspot(mLohsCallback, TEST_PACKAGE_NAME, null);
assertEquals(LocalOnlyHotspotCallback.REQUEST_REGISTERED, result);
verifyCheckChangePermission(TEST_PACKAGE_NAME);
}
@@ -1644,11 +1654,174 @@ public class WifiServiceImplTest extends WifiBaseTest {
private void verifyLohsBand(int expectedBand) {
verify(mActiveModeWarden).startSoftAp(mSoftApModeConfigCaptor.capture());
- final WifiConfiguration configuration = mSoftApModeConfigCaptor.getValue().mConfig;
+ final WifiConfiguration configuration =
+ mSoftApModeConfigCaptor.getValue().getWifiConfiguration();
assertNotNull(configuration);
assertEquals(expectedBand, configuration.apBand);
}
+ private static class FakeLohsCallback extends ILocalOnlyHotspotCallback.Stub {
+ boolean mIsStarted = false;
+ WifiConfiguration mWifiConfig = null;
+
+ @Override
+ public void onHotspotStarted(WifiConfiguration wifiConfig) {
+ mIsStarted = true;
+ this.mWifiConfig = wifiConfig;
+ }
+
+ @Override
+ public void onHotspotStopped() {
+ mIsStarted = false;
+ mWifiConfig = null;
+ }
+
+ @Override
+ public void onHotspotFailed(int i) {
+ mIsStarted = false;
+ mWifiConfig = null;
+ }
+ }
+
+ private void setupForCustomLohs() {
+ setupLohsPermissions();
+ when(mContext.checkPermission(eq(Manifest.permission.NETWORK_SETUP_WIZARD),
+ anyInt(), anyInt())).thenReturn(PackageManager.PERMISSION_GRANTED);
+ setupWardenForCustomLohs();
+ }
+
+ private void setupWardenForCustomLohs() {
+ doAnswer(invocation -> {
+ changeLohsState(WIFI_AP_STATE_ENABLED, WIFI_AP_STATE_DISABLED, HOTSPOT_NO_ERROR);
+ mWifiServiceImpl.updateInterfaceIpState(mLohsInterfaceName, IFACE_IP_MODE_LOCAL_ONLY);
+ return null;
+ }).when(mActiveModeWarden).startSoftAp(any());
+ }
+
+ @Test(expected = SecurityException.class)
+ public void testCustomLohs_FailsWithoutPermission() {
+ SoftApConfiguration customConfig = new SoftApConfiguration.Builder()
+ .setSsid("customConfig")
+ .build();
+ // set up basic permissions, but not NETWORK_SETUP_WIZARD
+ setupLohsPermissions();
+ setupWardenForCustomLohs();
+ mWifiServiceImpl.startLocalOnlyHotspot(mLohsCallback, TEST_PACKAGE_NAME, customConfig);
+ }
+
+ private static void nopDeathCallback(LocalOnlyHotspotRequestInfo requestor) {
+ }
+
+ @Test
+ public void testCustomLohs_ExclusiveAfterShared() {
+ FakeLohsCallback sharedCallback = new FakeLohsCallback();
+ FakeLohsCallback exclusiveCallback = new FakeLohsCallback();
+ SoftApConfiguration exclusiveConfig = new SoftApConfiguration.Builder()
+ .setSsid("customSsid")
+ .build();
+
+ setupForCustomLohs();
+ mWifiServiceImpl.registerLOHSForTest(mPid, new LocalOnlyHotspotRequestInfo(
+ sharedCallback, WifiServiceImplTest::nopDeathCallback, null));
+ assertThat(mWifiServiceImpl.startLocalOnlyHotspot(
+ exclusiveCallback, TEST_PACKAGE_NAME, exclusiveConfig))
+ .isEqualTo(ERROR_GENERIC);
+ mLooper.dispatchAll();
+
+ assertThat(sharedCallback.mIsStarted).isTrue();
+ assertThat(exclusiveCallback.mIsStarted).isFalse();
+ }
+
+ @Test
+ public void testCustomLohs_ExclusiveBeforeShared() {
+ FakeLohsCallback sharedCallback = new FakeLohsCallback();
+ FakeLohsCallback exclusiveCallback = new FakeLohsCallback();
+ SoftApConfiguration exclusiveConfig = new SoftApConfiguration.Builder()
+ .setSsid("customSsid")
+ .build();
+
+ setupForCustomLohs();
+ mWifiServiceImpl.registerLOHSForTest(mPid, new LocalOnlyHotspotRequestInfo(
+ exclusiveCallback, WifiServiceImplTest::nopDeathCallback, exclusiveConfig));
+ assertThat(mWifiServiceImpl.startLocalOnlyHotspot(
+ sharedCallback, TEST_PACKAGE_NAME, null))
+ .isEqualTo(ERROR_GENERIC);
+ mLooper.dispatchAll();
+
+ assertThat(exclusiveCallback.mIsStarted).isTrue();
+ assertThat(sharedCallback.mIsStarted).isFalse();
+ }
+
+ @Test
+ public void testCustomLohs_Wpa2() {
+ SoftApConfiguration config = new SoftApConfiguration.Builder()
+ .setSsid("customSsid")
+ .setWpa2Passphrase("passphrase")
+ .build();
+ FakeLohsCallback callback = new FakeLohsCallback();
+
+ setupForCustomLohs();
+ assertThat(mWifiServiceImpl.startLocalOnlyHotspot(callback, TEST_PACKAGE_NAME, config))
+ .isEqualTo(REQUEST_REGISTERED);
+ mLooper.dispatchAll();
+
+ assertThat(callback.mIsStarted).isTrue();
+ assertThat(callback.mWifiConfig.SSID).isEqualTo("customSsid");
+ assertThat(callback.mWifiConfig.getAuthType()).isEqualTo(KeyMgmt.WPA2_PSK);
+ assertThat(callback.mWifiConfig.preSharedKey).isEqualTo("passphrase");
+ }
+
+ @Test
+ public void testCustomLohs_Open() {
+ SoftApConfiguration config = new SoftApConfiguration.Builder()
+ .setSsid("customSsid")
+ .build();
+ FakeLohsCallback callback = new FakeLohsCallback();
+
+ setupForCustomLohs();
+ assertThat(mWifiServiceImpl.startLocalOnlyHotspot(callback, TEST_PACKAGE_NAME, config))
+ .isEqualTo(REQUEST_REGISTERED);
+ mLooper.dispatchAll();
+
+ assertThat(callback.mIsStarted).isTrue();
+ assertThat(callback.mWifiConfig.SSID).isEqualTo("customSsid");
+ assertThat(callback.mWifiConfig.getAuthType()).isEqualTo(KeyMgmt.NONE);
+ assertThat(callback.mWifiConfig.preSharedKey).isNull();
+ }
+
+ @Test
+ public void testCustomLohs_GeneratesSsidIfAbsent() {
+ SoftApConfiguration config = new SoftApConfiguration.Builder()
+ .setWpa2Passphrase("passphrase")
+ .build();
+ FakeLohsCallback callback = new FakeLohsCallback();
+
+ setupForCustomLohs();
+ assertThat(mWifiServiceImpl.startLocalOnlyHotspot(callback, TEST_PACKAGE_NAME, config))
+ .isEqualTo(REQUEST_REGISTERED);
+ mLooper.dispatchAll();
+
+ assertThat(callback.mIsStarted).isTrue();
+ assertThat(callback.mWifiConfig.SSID).isNotEmpty();
+ }
+
+ @Test
+ public void testCustomLohs_ForwardsBssid() {
+ SoftApConfiguration config = new SoftApConfiguration.Builder()
+ .setBssid(MacAddress.fromString("aa:bb:cc:dd:ee:ff"))
+ .build();
+ FakeLohsCallback callback = new FakeLohsCallback();
+
+ setupForCustomLohs();
+ assertThat(mWifiServiceImpl.startLocalOnlyHotspot(callback, TEST_PACKAGE_NAME, config))
+ .isEqualTo(REQUEST_REGISTERED);
+ mLooper.dispatchAll();
+
+ assertThat(callback.mIsStarted).isTrue();
+ assertThat(callback.mWifiConfig.BSSID)
+ .ignoringCase().isEqualTo("aa:bb:cc:dd:ee:ff");
+ }
+
/**
* Verify that WifiServiceImpl does not send the stop ap message if there were no
* pending LOHS requests upon a binder death callback.