summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlesl <lesl@google.com>2020-02-20 18:51:22 +0800
committerlesl <lesl@google.com>2020-02-20 19:24:19 +0800
commitef698cf9d70d64aa4f8a952f953f81baffccb6a2 (patch)
tree4ce7747c69348afcb43b30249adb32e4426fdeba
parent162424ec2c9f0cfcb05c3225c8d8b54bdb70446a (diff)
wifi: fix a bug in the ApConfigUtil.checkConfigurationChangeNeedToRestart()
The bssid was checking for object instance equality. And add unit test to covert the test. Bug: 147779354 Test: atest FrameworksWifiTests Change-Id: I354d2d7f53e4e0f3ba572dc229983e66ad598e08
-rw-r--r--service/java/com/android/server/wifi/util/ApConfigUtil.java2
-rw-r--r--tests/wifitests/src/com/android/server/wifi/util/ApConfigUtilTest.java84
2 files changed, 85 insertions, 1 deletions
diff --git a/service/java/com/android/server/wifi/util/ApConfigUtil.java b/service/java/com/android/server/wifi/util/ApConfigUtil.java
index e5b5037c8..bf319b4f2 100644
--- a/service/java/com/android/server/wifi/util/ApConfigUtil.java
+++ b/service/java/com/android/server/wifi/util/ApConfigUtil.java
@@ -534,7 +534,7 @@ public class ApConfigUtil {
public static boolean checkConfigurationChangeNeedToRestart(
SoftApConfiguration currentConfig, SoftApConfiguration newConfig) {
return !Objects.equals(currentConfig.getSsid(), newConfig.getSsid())
- || currentConfig.getBssid() != newConfig.getBssid()
+ || !Objects.equals(currentConfig.getBssid(), newConfig.getBssid())
|| currentConfig.getSecurityType() != newConfig.getSecurityType()
|| !Objects.equals(currentConfig.getPassphrase(), newConfig.getPassphrase())
|| currentConfig.isHiddenSsid() != newConfig.isHiddenSsid()
diff --git a/tests/wifitests/src/com/android/server/wifi/util/ApConfigUtilTest.java b/tests/wifitests/src/com/android/server/wifi/util/ApConfigUtilTest.java
index 01c5795ea..19952c48e 100644
--- a/tests/wifitests/src/com/android/server/wifi/util/ApConfigUtilTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/util/ApConfigUtilTest.java
@@ -24,6 +24,7 @@ import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.res.Resources;
+import android.net.MacAddress;
import android.net.wifi.SoftApCapability;
import android.net.wifi.SoftApConfiguration;
import android.net.wifi.SoftApConfiguration.Builder;
@@ -41,6 +42,7 @@ import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import java.util.ArrayList;
import java.util.Arrays;
/**
@@ -469,4 +471,86 @@ public class ApConfigUtilTest extends WifiBaseTest {
wifiConfig.preSharedKey = "1233443";
assertNull(ApConfigUtil.fromWifiConfiguration(wifiConfig));
}
+
+
+ @Test
+ public void testCheckConfigurationChangeNeedToRestart() throws Exception {
+ SoftApConfiguration currentConfig = new SoftApConfiguration.Builder()
+ .setSsid("TestSSid")
+ .setBssid(MacAddress.fromString("11:22:33:44:55:66"))
+ .setPassphrase("testpassphrase", SoftApConfiguration.SECURITY_TYPE_WPA2_PSK)
+ .setBand(SoftApConfiguration.BAND_2GHZ)
+ .setChannel(11, SoftApConfiguration.BAND_2GHZ)
+ .setHiddenSsid(true)
+ .build();
+
+ // Test no changed
+ // DO NOT use copy constructor to copy to test since it's instance is the same.
+ SoftApConfiguration newConfig_noChange = new SoftApConfiguration.Builder()
+ .setSsid("TestSSid")
+ .setBssid(MacAddress.fromString("11:22:33:44:55:66"))
+ .setPassphrase("testpassphrase", SoftApConfiguration.SECURITY_TYPE_WPA2_PSK)
+ .setBand(SoftApConfiguration.BAND_2GHZ)
+ .setChannel(11, SoftApConfiguration.BAND_2GHZ)
+ .setHiddenSsid(true)
+ .build();
+ assertFalse(ApConfigUtil.checkConfigurationChangeNeedToRestart(currentConfig,
+ newConfig_noChange));
+
+ // Test SSID changed
+ SoftApConfiguration newConfig_ssidChanged = new SoftApConfiguration
+ .Builder(newConfig_noChange)
+ .setSsid("NewTestSSid").build();
+ assertTrue(ApConfigUtil.checkConfigurationChangeNeedToRestart(currentConfig,
+ newConfig_ssidChanged));
+ // Test BSSID changed
+ SoftApConfiguration newConfig_bssidChanged = new SoftApConfiguration
+ .Builder(newConfig_noChange)
+ .setBssid(MacAddress.fromString("aa:bb:cc:dd:ee:ff")).build();
+ assertTrue(ApConfigUtil.checkConfigurationChangeNeedToRestart(currentConfig,
+ newConfig_bssidChanged));
+ // Test Passphrase Changed
+ SoftApConfiguration newConfig_passphraseChanged = new SoftApConfiguration
+ .Builder(newConfig_noChange)
+ .setPassphrase("newtestpassphrase",
+ SoftApConfiguration.SECURITY_TYPE_WPA2_PSK).build();
+ assertTrue(ApConfigUtil.checkConfigurationChangeNeedToRestart(currentConfig,
+ newConfig_passphraseChanged));
+ // Test Security Type Changed
+ SoftApConfiguration newConfig_securityeChanged = new SoftApConfiguration
+ .Builder(newConfig_noChange)
+ .setPassphrase("newtestpassphrase",
+ SoftApConfiguration.SECURITY_TYPE_WPA3_SAE).build();
+ assertTrue(ApConfigUtil.checkConfigurationChangeNeedToRestart(currentConfig,
+ newConfig_securityeChanged));
+ // Test Channel Changed
+ SoftApConfiguration newConfig_channelChanged = new SoftApConfiguration
+ .Builder(newConfig_noChange)
+ .setChannel(6, SoftApConfiguration.BAND_2GHZ).build();
+ assertTrue(ApConfigUtil.checkConfigurationChangeNeedToRestart(currentConfig,
+ newConfig_channelChanged));
+ // Test Band Changed
+ SoftApConfiguration newConfig_bandChanged = new SoftApConfiguration
+ .Builder(newConfig_noChange)
+ .setBand(SoftApConfiguration.BAND_5GHZ).build();
+ assertTrue(ApConfigUtil.checkConfigurationChangeNeedToRestart(currentConfig,
+ newConfig_bandChanged));
+ // Test isHidden Changed
+ SoftApConfiguration newConfig_hiddenChanged = new SoftApConfiguration
+ .Builder(newConfig_noChange)
+ .setHiddenSsid(false).build();
+ assertTrue(ApConfigUtil.checkConfigurationChangeNeedToRestart(currentConfig,
+ newConfig_hiddenChanged));
+ // Test Others Changed
+ SoftApConfiguration newConfig_nonRevalentChanged = new SoftApConfiguration
+ .Builder(newConfig_noChange)
+ .setMaxNumberOfClients(10)
+ .setAutoShutdownEnabled(false)
+ .setShutdownTimeoutMillis(500000)
+ .enableClientControlByUser(true)
+ .setClientList(new ArrayList<>(), new ArrayList<>())
+ .build();
+ assertFalse(ApConfigUtil.checkConfigurationChangeNeedToRestart(currentConfig,
+ newConfig_nonRevalentChanged));
+ }
}