diff options
| -rw-r--r-- | api/current.txt | 1 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/WifiNetworkSuggestion.java | 132 | ||||
| -rw-r--r-- | wifi/tests/src/android/net/wifi/WifiNetworkSuggestionTest.java | 222 | ||||
| -rw-r--r-- | wifi/tests/src/android/net/wifi/hotspot2/PasspointConfigurationTest.java | 174 | ||||
| -rw-r--r-- | wifi/tests/src/android/net/wifi/hotspot2/PasspointTestUtils.java | 163 |
5 files changed, 491 insertions, 201 deletions
diff --git a/api/current.txt b/api/current.txt index 47f10f00c4d6..cae2068cd479 100644 --- a/api/current.txt +++ b/api/current.txt @@ -30137,6 +30137,7 @@ package android.net.wifi { method @NonNull public android.net.wifi.WifiNetworkSuggestion.Builder setIsHiddenSsid(boolean); method @NonNull public android.net.wifi.WifiNetworkSuggestion.Builder setIsMetered(boolean); method @NonNull public android.net.wifi.WifiNetworkSuggestion.Builder setIsUserInteractionRequired(boolean); + method @NonNull public android.net.wifi.WifiNetworkSuggestion.Builder setPasspointConfig(@NonNull android.net.wifi.hotspot2.PasspointConfiguration); method @NonNull public android.net.wifi.WifiNetworkSuggestion.Builder setPriority(@IntRange(from=0) int); method @NonNull public android.net.wifi.WifiNetworkSuggestion.Builder setSsid(@NonNull String); method @NonNull public android.net.wifi.WifiNetworkSuggestion.Builder setWpa2EnterpriseConfig(@NonNull android.net.wifi.WifiEnterpriseConfig); diff --git a/wifi/java/android/net/wifi/WifiNetworkSuggestion.java b/wifi/java/android/net/wifi/WifiNetworkSuggestion.java index 426201732359..9b529cee58b3 100644 --- a/wifi/java/android/net/wifi/WifiNetworkSuggestion.java +++ b/wifi/java/android/net/wifi/WifiNetworkSuggestion.java @@ -23,6 +23,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.app.ActivityThread; import android.net.MacAddress; +import android.net.wifi.hotspot2.PasspointConfiguration; import android.os.Parcel; import android.os.Parcelable; import android.os.Process; @@ -80,6 +81,10 @@ public final class WifiNetworkSuggestion implements Parcelable { */ private @Nullable WifiEnterpriseConfig mWpa3EnterpriseConfig; /** + * The passpoint config for use with Hotspot 2.0 network + */ + private @Nullable PasspointConfiguration mPasspointConfiguration; + /** * This is a network that does not broadcast its SSID, so an * SSID-specific probe request must be used for scans. */ @@ -110,6 +115,7 @@ public final class WifiNetworkSuggestion implements Parcelable { mWpa3SaePassphrase = null; mWpa2EnterpriseConfig = null; mWpa3EnterpriseConfig = null; + mPasspointConfiguration = null; mIsHiddenSSID = false; mIsAppInteractionRequired = false; mIsUserInteractionRequired = false; @@ -234,6 +240,24 @@ public final class WifiNetworkSuggestion implements Parcelable { } /** + * Set the associated Passpoint configuration for this network. Needed for authenticating + * to Hotspot 2.0 networks. See {@link PasspointConfiguration} for description. + * + * @param passpointConfig Instance of {@link PasspointConfiguration}. + * @return Instance of {@link Builder} to enable chaining of the builder method. + * @throws IllegalArgumentException if passpoint configuration is invalid. + */ + public @NonNull Builder setPasspointConfig( + @NonNull PasspointConfiguration passpointConfig) { + checkNotNull(passpointConfig); + if (!passpointConfig.validate()) { + throw new IllegalArgumentException("Passpoint configuration is invalid"); + } + mPasspointConfiguration = passpointConfig; + return this; + } + + /** * Specifies whether this represents a hidden network. * <p> * <li>If not set, defaults to false (i.e not a hidden network).</li> @@ -366,13 +390,24 @@ public final class WifiNetworkSuggestion implements Parcelable { numSecurityTypes += !TextUtils.isEmpty(mWpa3SaePassphrase) ? 1 : 0; numSecurityTypes += mWpa2EnterpriseConfig != null ? 1 : 0; numSecurityTypes += mWpa3EnterpriseConfig != null ? 1 : 0; + numSecurityTypes += mPasspointConfiguration != null ? 1 : 0; if (numSecurityTypes > 1) { throw new IllegalStateException("only one of setIsEnhancedOpen, setWpa2Passphrase," - + "setWpa3Passphrase, setWpa2EnterpriseConfig or setWpa3EnterpriseConfig" - + " can be invoked for network specifier"); + + "setWpa3Passphrase, setWpa2EnterpriseConfig, setWpa3EnterpriseConfig" + + "or setPasspointConfig can be invoked for network suggestion"); } } + private WifiConfiguration buildWifiConfigurationForPasspoint() { + WifiConfiguration wifiConfiguration = new WifiConfiguration(); + wifiConfiguration.FQDN = mPasspointConfiguration.getHomeSp().getFqdn(); + wifiConfiguration.priority = mPriority; + wifiConfiguration.meteredOverride = + mIsMetered ? WifiConfiguration.METERED_OVERRIDE_METERED + : WifiConfiguration.METERED_OVERRIDE_NONE; + return wifiConfiguration; + } + /** * Create a network suggestion object for use in * {@link WifiManager#addNetworkSuggestions(List)}. @@ -384,29 +419,36 @@ public final class WifiNetworkSuggestion implements Parcelable { * </p> * * For example: - * To provide credentials for one open, one WPA2 and one WPA3 network with their - * corresponding SSID's: + * To provide credentials for one open, one WPA2, one WPA3 network with their + * corresponding SSID's and one with Passpoint config: * * <pre>{@code * final WifiNetworkSuggestion suggestion1 = * new Builder() * .setSsid("test111111") - * .build() + * .build(); * final WifiNetworkSuggestion suggestion2 = * new Builder() * .setSsid("test222222") * .setWpa2Passphrase("test123456") - * .build() + * .build(); * final WifiNetworkSuggestion suggestion3 = * new Builder() * .setSsid("test333333") * .setWpa3Passphrase("test6789") - * .build() + * .build(); + * final PasspointConfiguration passpointConfig= new PasspointConfiguration(); + * // configure passpointConfig to include a valid Passpoint configuration + * final WifiNetworkSuggestion suggestion4 = + * new Builder() + * .setPasspointConfig(passpointConfig) + * .build(); * final List<WifiNetworkSuggestion> suggestionsList = * new ArrayList<WifiNetworkSuggestion> { { * add(suggestion1); * add(suggestion2); * add(suggestion3); + * add(suggestion4); * } }; * final WifiManager wifiManager = * context.getSystemService(Context.WIFI_SERVICE); @@ -419,21 +461,37 @@ public final class WifiNetworkSuggestion implements Parcelable { * @see WifiNetworkSuggestion */ public @NonNull WifiNetworkSuggestion build() { - if (mSsid == null) { - throw new IllegalStateException("setSsid should be invoked for suggestion"); - } - if (TextUtils.isEmpty(mSsid)) { - throw new IllegalStateException("invalid ssid for suggestion"); - } - if (mBssid != null - && (mBssid.equals(MacAddress.BROADCAST_ADDRESS) - || mBssid.equals(MacAddress.ALL_ZEROS_ADDRESS))) { - throw new IllegalStateException("invalid bssid for suggestion"); - } validateSecurityParams(); + WifiConfiguration wifiConfiguration; + if (mPasspointConfiguration != null) { + if (mSsid != null) { + throw new IllegalStateException("setSsid should not be invoked for suggestion " + + "with Passpoint configuration"); + } + if (mIsHiddenSSID) { + throw new IllegalStateException("setIsHiddenSsid should not be invoked for " + + "suggestion with Passpoint configuration"); + } + wifiConfiguration = buildWifiConfigurationForPasspoint(); + + } else { + if (mSsid == null) { + throw new IllegalStateException("setSsid should be invoked for suggestion"); + } + if (TextUtils.isEmpty(mSsid)) { + throw new IllegalStateException("invalid ssid for suggestion"); + } + if (mBssid != null + && (mBssid.equals(MacAddress.BROADCAST_ADDRESS) + || mBssid.equals(MacAddress.ALL_ZEROS_ADDRESS))) { + throw new IllegalStateException("invalid bssid for suggestion"); + } + wifiConfiguration = buildWifiConfiguration(); + } return new WifiNetworkSuggestion( - buildWifiConfiguration(), + wifiConfiguration, + mPasspointConfiguration, mIsAppInteractionRequired, mIsUserInteractionRequired, Process.myUid(), @@ -448,6 +506,12 @@ public final class WifiNetworkSuggestion implements Parcelable { public final WifiConfiguration wifiConfiguration; /** + * Passpoint configuration for the provided network. + * @hide + */ + public final PasspointConfiguration passpointConfiguration; + + /** * Whether app needs to log in to captive portal to obtain Internet access. * @hide */ @@ -474,6 +538,7 @@ public final class WifiNetworkSuggestion implements Parcelable { /** @hide */ public WifiNetworkSuggestion() { this.wifiConfiguration = null; + this.passpointConfiguration = null; this.isAppInteractionRequired = false; this.isUserInteractionRequired = false; this.suggestorUid = -1; @@ -481,14 +546,16 @@ public final class WifiNetworkSuggestion implements Parcelable { } /** @hide */ - public WifiNetworkSuggestion(@NonNull WifiConfiguration wifiConfiguration, + public WifiNetworkSuggestion(@NonNull WifiConfiguration networkConfiguration, + @Nullable PasspointConfiguration passpointConfiguration, boolean isAppInteractionRequired, boolean isUserInteractionRequired, int suggestorUid, @NonNull String suggestorPackageName) { - checkNotNull(wifiConfiguration); + checkNotNull(networkConfiguration); checkNotNull(suggestorPackageName); + this.wifiConfiguration = networkConfiguration; + this.passpointConfiguration = passpointConfiguration; - this.wifiConfiguration = wifiConfiguration; this.isAppInteractionRequired = isAppInteractionRequired; this.isUserInteractionRequired = isUserInteractionRequired; this.suggestorUid = suggestorUid; @@ -501,6 +568,7 @@ public final class WifiNetworkSuggestion implements Parcelable { public WifiNetworkSuggestion createFromParcel(Parcel in) { return new WifiNetworkSuggestion( in.readParcelable(null), // wifiConfiguration + in.readParcelable(null), // PasspointConfiguration in.readBoolean(), // isAppInteractionRequired in.readBoolean(), // isUserInteractionRequired in.readInt(), // suggestorUid @@ -522,6 +590,7 @@ public final class WifiNetworkSuggestion implements Parcelable { @Override public void writeToParcel(Parcel dest, int flags) { dest.writeParcelable(wifiConfiguration, flags); + dest.writeParcelable(passpointConfiguration, flags); dest.writeBoolean(isAppInteractionRequired); dest.writeBoolean(isUserInteractionRequired); dest.writeInt(suggestorUid); @@ -531,7 +600,8 @@ public final class WifiNetworkSuggestion implements Parcelable { @Override public int hashCode() { return Objects.hash(wifiConfiguration.SSID, wifiConfiguration.BSSID, - wifiConfiguration.allowedKeyManagement, suggestorUid, suggestorPackageName); + wifiConfiguration.allowedKeyManagement, wifiConfiguration.FQDN, + suggestorUid, suggestorPackageName); } /** @@ -546,12 +616,17 @@ public final class WifiNetworkSuggestion implements Parcelable { return false; } WifiNetworkSuggestion lhs = (WifiNetworkSuggestion) obj; - return Objects.equals(this.wifiConfiguration.SSID, lhs.wifiConfiguration.SSID) - && Objects.equals(this.wifiConfiguration.BSSID, lhs.wifiConfiguration.BSSID) + if (this.passpointConfiguration == null ^ lhs.passpointConfiguration == null) { + return false; + } + + return TextUtils.equals(this.wifiConfiguration.SSID, lhs.wifiConfiguration.SSID) + && TextUtils.equals(this.wifiConfiguration.BSSID, lhs.wifiConfiguration.BSSID) && Objects.equals(this.wifiConfiguration.allowedKeyManagement, - lhs.wifiConfiguration.allowedKeyManagement) - && suggestorUid == lhs.suggestorUid - && TextUtils.equals(suggestorPackageName, lhs.suggestorPackageName); + lhs.wifiConfiguration.allowedKeyManagement) + && TextUtils.equals(this.wifiConfiguration.FQDN, lhs.wifiConfiguration.FQDN) + && this.suggestorUid == lhs.suggestorUid + && TextUtils.equals(this.suggestorPackageName, lhs.suggestorPackageName); } @Override @@ -559,6 +634,7 @@ public final class WifiNetworkSuggestion implements Parcelable { StringBuilder sb = new StringBuilder("WifiNetworkSuggestion [") .append(", SSID=").append(wifiConfiguration.SSID) .append(", BSSID=").append(wifiConfiguration.BSSID) + .append(", FQDN=").append(wifiConfiguration.FQDN) .append(", isAppInteractionRequired=").append(isAppInteractionRequired) .append(", isUserInteractionRequired=").append(isUserInteractionRequired) .append(", suggestorUid=").append(suggestorUid) diff --git a/wifi/tests/src/android/net/wifi/WifiNetworkSuggestionTest.java b/wifi/tests/src/android/net/wifi/WifiNetworkSuggestionTest.java index 4dfa96b8c606..699008905f0a 100644 --- a/wifi/tests/src/android/net/wifi/WifiNetworkSuggestionTest.java +++ b/wifi/tests/src/android/net/wifi/WifiNetworkSuggestionTest.java @@ -19,6 +19,8 @@ package android.net.wifi; import static org.junit.Assert.*; import android.net.MacAddress; +import android.net.wifi.hotspot2.PasspointConfiguration; +import android.net.wifi.hotspot2.PasspointTestUtils; import android.os.Parcel; import android.os.Process; @@ -39,6 +41,7 @@ public class WifiNetworkSuggestionTest { private static final String TEST_BSSID = "12:12:12:12:12:12"; private static final String TEST_SSID_1 = "\"Test1234\""; private static final String TEST_PRESHARED_KEY = "Test123"; + private static final String TEST_FQDN = "fqdn"; /** * Validate correctness of WifiNetworkSuggestion object created by @@ -186,6 +189,25 @@ public class WifiNetworkSuggestionTest { } /** + * Validate correctness of WifiNetworkSuggestion object created by + * {@link WifiNetworkSuggestion.Builder#build()} for Passpoint network which requires + * app interaction and metered. + */ + @Test + public void testWifiNetworkSuggestionBuilderForPasspointNetworkWithReqAppInteractionMetered() { + PasspointConfiguration passpointConfiguration = PasspointTestUtils.createConfig(); + WifiNetworkSuggestion suggestion = new WifiNetworkSuggestion.Builder() + .setPasspointConfig(passpointConfiguration) + .setIsAppInteractionRequired(true) + .setIsMetered(true) + .build(); + assertEquals(TEST_FQDN, suggestion.wifiConfiguration.FQDN); + assertTrue(suggestion.isAppInteractionRequired); + assertEquals(suggestion.wifiConfiguration.meteredOverride, + WifiConfiguration.METERED_OVERRIDE_METERED); + } + + /** * Ensure {@link WifiNetworkSuggestion.Builder#setSsid(String)} throws an exception * when the string is not Unicode. */ @@ -209,6 +231,18 @@ public class WifiNetworkSuggestionTest { } /** + * Ensure {@link WifiNetworkSuggestion.Builder#setPasspointConfig(PasspointConfiguration)}} + * throws an exception when the PasspointConfiguration is not valid. + */ + @Test(expected = IllegalArgumentException.class) + public void testWifiNetworkSuggestionBuilderSetPasspointConfigWithNonValid() { + PasspointConfiguration passpointConfiguration = new PasspointConfiguration(); + new WifiNetworkSuggestion.Builder() + .setPasspointConfig(passpointConfiguration) + .build(); + } + + /** * Ensure {@link WifiNetworkSuggestion.Builder#build()} throws an exception * when {@link WifiNetworkSuggestion.Builder#setSsid(String)} is not set. */ @@ -311,6 +345,91 @@ public class WifiNetworkSuggestionTest { } /** + * Ensure {@link WifiNetworkSuggestion.Builder#build()} throws an exception + * when both {@link WifiNetworkSuggestion.Builder#setSsid(String)} and + * {@link WifiNetworkSuggestion.Builder#setPasspointConfig(PasspointConfiguration)} are invoked. + */ + @Test(expected = IllegalStateException.class) + public void testWifiNetworkSuggestionBuilderWithBothSsidAndPasspointConfig() { + PasspointConfiguration passpointConfiguration = PasspointTestUtils.createConfig(); + new WifiNetworkSuggestion.Builder() + .setSsid(TEST_SSID) + .setPasspointConfig(passpointConfiguration) + .build(); + } + + /** + * Ensure {@link WifiNetworkSuggestion.Builder#build()} throws an exception + * when both {@link WifiNetworkSuggestion.Builder#setWpa2Passphrase(String)} and + * {@link WifiNetworkSuggestion.Builder#setPasspointConfig(PasspointConfiguration)} are invoked. + */ + @Test(expected = IllegalStateException.class) + public void testWifiNetworkSuggestionBuilderWithBothWpa2PassphraseAndPasspointConfig() { + PasspointConfiguration passpointConfiguration = PasspointTestUtils.createConfig(); + new WifiNetworkSuggestion.Builder() + .setWpa2Passphrase(TEST_PRESHARED_KEY) + .setPasspointConfig(passpointConfiguration) + .build(); + } + + /** + * Ensure {@link WifiNetworkSuggestion.Builder#build()} throws an exception + * when both {@link WifiNetworkSuggestion.Builder#setWpa3Passphrase(String)} and + * {@link WifiNetworkSuggestion.Builder#setPasspointConfig(PasspointConfiguration)} are invoked. + */ + @Test(expected = IllegalStateException.class) + public void testWifiNetworkSuggestionBuilderWithBothWpa3PassphraseAndPasspointConfig() { + PasspointConfiguration passpointConfiguration = PasspointTestUtils.createConfig(); + new WifiNetworkSuggestion.Builder() + .setWpa3Passphrase(TEST_PRESHARED_KEY) + .setPasspointConfig(passpointConfiguration) + .build(); + } + + /** + * Ensure {@link WifiNetworkSuggestion.Builder#build()} throws an exception + * when both {@link WifiNetworkSuggestion.Builder#setWpa3EnterpriseConfig(WifiEnterpriseConfig)} + * and {@link WifiNetworkSuggestion.Builder#setPasspointConfig(PasspointConfiguration)} are + * invoked. + */ + @Test(expected = IllegalStateException.class) + public void testWifiNetworkSuggestionBuilderWithBothEnterpriseAndPasspointConfig() { + PasspointConfiguration passpointConfiguration = PasspointTestUtils.createConfig(); + new WifiNetworkSuggestion.Builder() + .setWpa3EnterpriseConfig(new WifiEnterpriseConfig()) + .setPasspointConfig(passpointConfiguration) + .build(); + } + + /** + * Ensure {@link WifiNetworkSuggestion.Builder#build()} throws an exception + * when both {@link WifiNetworkSuggestion.Builder#setIsEnhancedOpen(boolean)} and + * {@link WifiNetworkSuggestion.Builder#setPasspointConfig(PasspointConfiguration)} are invoked. + */ + @Test(expected = IllegalStateException.class) + public void testWifiNetworkSuggestionBuilderWithBothEnhancedOpenAndPasspointConfig() { + PasspointConfiguration passpointConfiguration = PasspointTestUtils.createConfig(); + new WifiNetworkSuggestion.Builder() + .setIsEnhancedOpen(true) + .setPasspointConfig(passpointConfiguration) + .build(); + } + + /** + * Ensure {@link WifiNetworkSuggestion.Builder#build()} throws an exception + * when both {@link WifiNetworkSuggestion.Builder#setIsHiddenSsid(boolean)} and + * {@link WifiNetworkSuggestion.Builder#setPasspointConfig(PasspointConfiguration)} are invoked. + */ + @Test(expected = IllegalStateException.class) + public void testWifiNetworkSuggestionBuilderWithBothHiddenSsidAndPasspointConfig() { + PasspointConfiguration passpointConfiguration = PasspointTestUtils.createConfig(); + new WifiNetworkSuggestion.Builder() + .setIsHiddenSsid(true) + .setPasspointConfig(passpointConfiguration) + .build(); + } + + /** * Check that parcel marshalling/unmarshalling works */ @Test @@ -319,8 +438,8 @@ public class WifiNetworkSuggestionTest { configuration.SSID = TEST_SSID; configuration.BSSID = TEST_BSSID; configuration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); - WifiNetworkSuggestion suggestion = - new WifiNetworkSuggestion(configuration, false, true, TEST_UID, TEST_PACKAGE_NAME); + WifiNetworkSuggestion suggestion = new WifiNetworkSuggestion( + configuration, null, false, true, TEST_UID, TEST_PACKAGE_NAME); Parcel parcelW = Parcel.obtain(); suggestion.writeToParcel(parcelW, 0); @@ -337,6 +456,39 @@ public class WifiNetworkSuggestionTest { // SSID + keyMgmt + same UID). |isAppInteractionRequired| & |isUserInteractionRequired| are // not considered for equality and hence needs to be checked for explicitly below. assertEquals(suggestion, parcelSuggestion); + assertEquals(suggestion.hashCode(), parcelSuggestion.hashCode()); + assertEquals(suggestion.isAppInteractionRequired, + parcelSuggestion.isAppInteractionRequired); + assertEquals(suggestion.isUserInteractionRequired, + parcelSuggestion.isUserInteractionRequired); + } + + /** + * Check that parcel marshalling/unmarshalling works + */ + @Test + public void testPasspointNetworkSuggestionParcel() { + PasspointConfiguration passpointConfiguration = PasspointTestUtils.createConfig(); + WifiNetworkSuggestion suggestion = new WifiNetworkSuggestion.Builder() + .setPasspointConfig(passpointConfiguration) + .build(); + + Parcel parcelW = Parcel.obtain(); + suggestion.writeToParcel(parcelW, 0); + byte[] bytes = parcelW.marshall(); + parcelW.recycle(); + + Parcel parcelR = Parcel.obtain(); + parcelR.unmarshall(bytes, 0, bytes.length); + parcelR.setDataPosition(0); + WifiNetworkSuggestion parcelSuggestion = + WifiNetworkSuggestion.CREATOR.createFromParcel(parcelR); + + // Two suggestion objects are considered equal if they point to the same network (i.e same + // SSID + keyMgmt + same UID). |isAppInteractionRequired| & |isUserInteractionRequired| are + // not considered for equality and hence needs to be checked for explicitly below. + assertEquals(suggestion, parcelSuggestion); + assertEquals(suggestion.hashCode(), parcelSuggestion.hashCode()); assertEquals(suggestion.isAppInteractionRequired, parcelSuggestion.isAppInteractionRequired); assertEquals(suggestion.isUserInteractionRequired, @@ -354,7 +506,7 @@ public class WifiNetworkSuggestionTest { configuration.BSSID = TEST_BSSID; configuration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); WifiNetworkSuggestion suggestion = - new WifiNetworkSuggestion(configuration, true, false, TEST_UID, + new WifiNetworkSuggestion(configuration, null, true, false, TEST_UID, TEST_PACKAGE_NAME); WifiConfiguration configuration1 = new WifiConfiguration(); @@ -362,10 +514,11 @@ public class WifiNetworkSuggestionTest { configuration1.BSSID = TEST_BSSID; configuration1.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); WifiNetworkSuggestion suggestion1 = - new WifiNetworkSuggestion(configuration1, false, true, TEST_UID, + new WifiNetworkSuggestion(configuration1, null, false, true, TEST_UID, TEST_PACKAGE_NAME); assertEquals(suggestion, suggestion1); + assertEquals(suggestion.hashCode(), suggestion1.hashCode()); } /** @@ -378,14 +531,14 @@ public class WifiNetworkSuggestionTest { configuration.SSID = TEST_SSID; configuration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); WifiNetworkSuggestion suggestion = - new WifiNetworkSuggestion(configuration, false, false, TEST_UID, + new WifiNetworkSuggestion(configuration, null, false, false, TEST_UID, TEST_PACKAGE_NAME); WifiConfiguration configuration1 = new WifiConfiguration(); configuration1.SSID = TEST_SSID_1; configuration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); WifiNetworkSuggestion suggestion1 = - new WifiNetworkSuggestion(configuration1, false, false, TEST_UID, + new WifiNetworkSuggestion(configuration1, null, false, false, TEST_UID, TEST_PACKAGE_NAME); assertNotEquals(suggestion, suggestion1); @@ -402,14 +555,14 @@ public class WifiNetworkSuggestionTest { configuration.BSSID = TEST_BSSID; configuration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); WifiNetworkSuggestion suggestion = - new WifiNetworkSuggestion(configuration, false, false, TEST_UID, + new WifiNetworkSuggestion(configuration, null, false, false, TEST_UID, TEST_PACKAGE_NAME); WifiConfiguration configuration1 = new WifiConfiguration(); configuration1.SSID = TEST_SSID; configuration1.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); WifiNetworkSuggestion suggestion1 = - new WifiNetworkSuggestion(configuration1, false, false, TEST_UID, + new WifiNetworkSuggestion(configuration1, null, false, false, TEST_UID, TEST_PACKAGE_NAME); assertNotEquals(suggestion, suggestion1); @@ -425,14 +578,14 @@ public class WifiNetworkSuggestionTest { configuration.SSID = TEST_SSID; configuration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); WifiNetworkSuggestion suggestion = - new WifiNetworkSuggestion(configuration, false, false, TEST_UID, + new WifiNetworkSuggestion(configuration, null, false, false, TEST_UID, TEST_PACKAGE_NAME); WifiConfiguration configuration1 = new WifiConfiguration(); configuration1.SSID = TEST_SSID; configuration1.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); WifiNetworkSuggestion suggestion1 = - new WifiNetworkSuggestion(configuration1, false, false, TEST_UID, + new WifiNetworkSuggestion(configuration1, null, false, false, TEST_UID, TEST_PACKAGE_NAME); assertNotEquals(suggestion, suggestion1); @@ -448,11 +601,11 @@ public class WifiNetworkSuggestionTest { configuration.SSID = TEST_SSID; configuration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); WifiNetworkSuggestion suggestion = - new WifiNetworkSuggestion(configuration, false, false, TEST_UID, + new WifiNetworkSuggestion(configuration, null, false, false, TEST_UID, TEST_PACKAGE_NAME); WifiNetworkSuggestion suggestion1 = - new WifiNetworkSuggestion(configuration, false, false, TEST_UID_OTHER, + new WifiNetworkSuggestion(configuration, null, false, false, TEST_UID_OTHER, TEST_PACKAGE_NAME); assertNotEquals(suggestion, suggestion1); @@ -467,13 +620,48 @@ public class WifiNetworkSuggestionTest { WifiConfiguration configuration = new WifiConfiguration(); configuration.SSID = TEST_SSID; configuration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); - WifiNetworkSuggestion suggestion = - new WifiNetworkSuggestion(configuration, false, false, TEST_UID, TEST_PACKAGE_NAME); + WifiNetworkSuggestion suggestion = new WifiNetworkSuggestion( + configuration, null, false, false, TEST_UID, TEST_PACKAGE_NAME); - WifiNetworkSuggestion suggestion1 = - new WifiNetworkSuggestion(configuration, false, false, TEST_UID, - TEST_PACKAGE_NAME_OTHER); + WifiNetworkSuggestion suggestion1 = new WifiNetworkSuggestion( + configuration, null, false, false, TEST_UID, TEST_PACKAGE_NAME_OTHER); + + assertNotEquals(suggestion, suggestion1); + } + /** + * Check NetworkSuggestion equals returns {@code true} for 2 Passpoint network suggestions with + * same FQDN. + */ + @Test + public void testPasspointNetworkSuggestionEqualsSameWithSameFQDN() { + PasspointConfiguration passpointConfiguration = PasspointTestUtils.createConfig(); + PasspointConfiguration passpointConfiguration1 = PasspointTestUtils.createConfig(); + WifiNetworkSuggestion suggestion = new WifiNetworkSuggestion.Builder() + .setPasspointConfig(passpointConfiguration) + .build(); + WifiNetworkSuggestion suggestion1 = new WifiNetworkSuggestion.Builder() + .setPasspointConfig(passpointConfiguration1) + .build(); + assertEquals(suggestion, suggestion1); + assertEquals(suggestion.hashCode(), suggestion1.hashCode()); + } + /** + * Check NetworkSuggestion equals returns {@code false} for 2 Passpoint network suggestions with + * different FQDN. + */ + @Test + public void testPasspointNetworkSuggestionNotEqualsSameWithDifferentFQDN() { + PasspointConfiguration passpointConfiguration = PasspointTestUtils.createConfig(); + PasspointConfiguration passpointConfiguration1 = PasspointTestUtils.createConfig(); + passpointConfiguration1.getHomeSp().setFqdn(TEST_FQDN + 1); + + WifiNetworkSuggestion suggestion = new WifiNetworkSuggestion.Builder() + .setPasspointConfig(passpointConfiguration) + .build(); + WifiNetworkSuggestion suggestion1 = new WifiNetworkSuggestion.Builder() + .setPasspointConfig(passpointConfiguration1) + .build(); assertNotEquals(suggestion, suggestion1); } } diff --git a/wifi/tests/src/android/net/wifi/hotspot2/PasspointConfigurationTest.java b/wifi/tests/src/android/net/wifi/hotspot2/PasspointConfigurationTest.java index 88740d850643..c3b074eaee5a 100644 --- a/wifi/tests/src/android/net/wifi/hotspot2/PasspointConfigurationTest.java +++ b/wifi/tests/src/android/net/wifi/hotspot2/PasspointConfigurationTest.java @@ -19,23 +19,15 @@ package android.net.wifi.hotspot2; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import android.net.wifi.EAPConstants; -import android.net.wifi.hotspot2.pps.Credential; -import android.net.wifi.hotspot2.pps.HomeSp; -import android.net.wifi.hotspot2.pps.Policy; -import android.net.wifi.hotspot2.pps.UpdateParameter; import android.os.Parcel; -import android.util.Base64; import androidx.test.filters.SmallTest; import org.junit.Test; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; -import java.util.List; import java.util.Map; /** @@ -47,136 +39,6 @@ public class PasspointConfigurationTest { private static final int CERTIFICATE_FINGERPRINT_BYTES = 32; /** - * Utility function for creating a {@link android.net.wifi.hotspot2.pps.HomeSP}. - * - * @return {@link android.net.wifi.hotspot2.pps.HomeSP} - */ - private static HomeSp createHomeSp() { - HomeSp homeSp = new HomeSp(); - homeSp.setFqdn("fqdn"); - homeSp.setFriendlyName("friendly name"); - homeSp.setRoamingConsortiumOis(new long[] {0x55, 0x66}); - return homeSp; - } - - /** - * Utility function for creating a {@link android.net.wifi.hotspot2.pps.Credential}. - * - * @return {@link android.net.wifi.hotspot2.pps.Credential} - */ - private static Credential createCredential() { - Credential cred = new Credential(); - cred.setRealm("realm"); - cred.setUserCredential(null); - cred.setCertCredential(null); - cred.setSimCredential(new Credential.SimCredential()); - cred.getSimCredential().setImsi("1234*"); - cred.getSimCredential().setEapType(EAPConstants.EAP_SIM); - cred.setCaCertificate(null); - cred.setClientCertificateChain(null); - cred.setClientPrivateKey(null); - return cred; - } - - /** - * Helper function for creating a {@link Policy} for testing. - * - * @return {@link Policy} - */ - private static Policy createPolicy() { - Policy policy = new Policy(); - policy.setMinHomeDownlinkBandwidth(123); - policy.setMinHomeUplinkBandwidth(345); - policy.setMinRoamingDownlinkBandwidth(567); - policy.setMinRoamingUplinkBandwidth(789); - policy.setMaximumBssLoadValue(12); - policy.setExcludedSsidList(new String[] {"ssid1", "ssid2"}); - HashMap<Integer, String> requiredProtoPortMap = new HashMap<>(); - requiredProtoPortMap.put(12, "23,342,123"); - requiredProtoPortMap.put(23, "789,372,1235"); - policy.setRequiredProtoPortMap(requiredProtoPortMap); - - List<Policy.RoamingPartner> preferredRoamingPartnerList = new ArrayList<>(); - Policy.RoamingPartner partner1 = new Policy.RoamingPartner(); - partner1.setFqdn("partner1.com"); - partner1.setFqdnExactMatch(true); - partner1.setPriority(12); - partner1.setCountries("us,jp"); - Policy.RoamingPartner partner2 = new Policy.RoamingPartner(); - partner2.setFqdn("partner2.com"); - partner2.setFqdnExactMatch(false); - partner2.setPriority(42); - partner2.setCountries("ca,fr"); - preferredRoamingPartnerList.add(partner1); - preferredRoamingPartnerList.add(partner2); - policy.setPreferredRoamingPartnerList(preferredRoamingPartnerList); - - UpdateParameter policyUpdate = new UpdateParameter(); - policyUpdate.setUpdateIntervalInMinutes(1712); - policyUpdate.setUpdateMethod(UpdateParameter.UPDATE_METHOD_OMADM); - policyUpdate.setRestriction(UpdateParameter.UPDATE_RESTRICTION_HOMESP); - policyUpdate.setServerUri("policy.update.com"); - policyUpdate.setUsername("username"); - policyUpdate.setBase64EncodedPassword( - Base64.encodeToString("password".getBytes(), Base64.DEFAULT)); - policyUpdate.setTrustRootCertUrl("trust.cert.com"); - policyUpdate.setTrustRootCertSha256Fingerprint( - new byte[CERTIFICATE_FINGERPRINT_BYTES]); - policy.setPolicyUpdate(policyUpdate); - - return policy; - } - - private static UpdateParameter createSubscriptionUpdate() { - UpdateParameter subUpdate = new UpdateParameter(); - subUpdate.setUpdateIntervalInMinutes(9021); - subUpdate.setUpdateMethod(UpdateParameter.UPDATE_METHOD_SSP); - subUpdate.setRestriction(UpdateParameter.UPDATE_RESTRICTION_ROAMING_PARTNER); - subUpdate.setServerUri("subscription.update.com"); - subUpdate.setUsername("subUsername"); - subUpdate.setBase64EncodedPassword( - Base64.encodeToString("subPassword".getBytes(), Base64.DEFAULT)); - subUpdate.setTrustRootCertUrl("subscription.trust.cert.com"); - subUpdate.setTrustRootCertSha256Fingerprint(new byte[CERTIFICATE_FINGERPRINT_BYTES]); - return subUpdate; - } - /** - * Helper function for creating a {@link PasspointConfiguration} for testing. - * - * @return {@link PasspointConfiguration} - */ - private static PasspointConfiguration createConfig() { - PasspointConfiguration config = new PasspointConfiguration(); - config.setUpdateIdentifier(1234); - config.setHomeSp(createHomeSp()); - config.setAaaServerTrustedNames( - new String[] {"trusted.fqdn.com", "another-trusted.fqdn.com"}); - config.setCredential(createCredential()); - config.setPolicy(createPolicy()); - config.setSubscriptionUpdate(createSubscriptionUpdate()); - Map<String, byte[]> trustRootCertList = new HashMap<>(); - trustRootCertList.put("trustRoot.cert1.com", - new byte[CERTIFICATE_FINGERPRINT_BYTES]); - trustRootCertList.put("trustRoot.cert2.com", - new byte[CERTIFICATE_FINGERPRINT_BYTES]); - config.setTrustRootCertList(trustRootCertList); - config.setUpdateIdentifier(1); - config.setCredentialPriority(120); - config.setSubscriptionCreationTimeInMillis(231200); - config.setSubscriptionExpirationTimeInMillis(2134232); - config.setSubscriptionType("Gold"); - config.setUsageLimitUsageTimePeriodInMinutes(3600); - config.setUsageLimitStartTimeInMillis(124214213); - config.setUsageLimitDataLimit(14121); - config.setUsageLimitTimeLimitInMinutes(78912); - Map<String, String> friendlyNames = new HashMap<>(); - friendlyNames.put("en", "ServiceName1"); - friendlyNames.put("kr", "ServiceName2"); - config.setServiceFriendlyNames(friendlyNames); - return config; - } - - /** * Verify parcel write and read consistency for the given configuration. * * @param writeConfig The configuration to verify @@ -209,7 +71,7 @@ public class PasspointConfigurationTest { */ @Test public void verifyParcelWithFullConfiguration() throws Exception { - verifyParcel(createConfig()); + verifyParcel(PasspointTestUtils.createConfig()); } /** @@ -219,7 +81,7 @@ public class PasspointConfigurationTest { */ @Test public void verifyParcelWithoutServiceNames() throws Exception { - PasspointConfiguration config = createConfig(); + PasspointConfiguration config = PasspointTestUtils.createConfig(); config.setServiceFriendlyNames(null); verifyParcel(config); } @@ -231,7 +93,7 @@ public class PasspointConfigurationTest { */ @Test public void verifyParcelWithoutHomeSP() throws Exception { - PasspointConfiguration config = createConfig(); + PasspointConfiguration config = PasspointTestUtils.createConfig(); config.setHomeSp(null); verifyParcel(config); } @@ -243,7 +105,7 @@ public class PasspointConfigurationTest { */ @Test public void verifyParcelWithoutCredential() throws Exception { - PasspointConfiguration config = createConfig(); + PasspointConfiguration config = PasspointTestUtils.createConfig(); config.setCredential(null); verifyParcel(config); } @@ -255,7 +117,7 @@ public class PasspointConfigurationTest { */ @Test public void verifyParcelWithoutPolicy() throws Exception { - PasspointConfiguration config = createConfig(); + PasspointConfiguration config = PasspointTestUtils.createConfig(); config.setPolicy(null); verifyParcel(config); } @@ -267,7 +129,7 @@ public class PasspointConfigurationTest { */ @Test public void verifyParcelWithoutSubscriptionUpdate() throws Exception { - PasspointConfiguration config = createConfig(); + PasspointConfiguration config = PasspointTestUtils.createConfig(); config.setSubscriptionUpdate(null); verifyParcel(config); } @@ -280,7 +142,7 @@ public class PasspointConfigurationTest { */ @Test public void verifyParcelWithoutTrustRootCertList() throws Exception { - PasspointConfiguration config = createConfig(); + PasspointConfiguration config = PasspointTestUtils.createConfig(); config.setTrustRootCertList(null); verifyParcel(config); } @@ -293,7 +155,7 @@ public class PasspointConfigurationTest { */ @Test public void verifyParcelWithoutAaaServerTrustedNames() throws Exception { - PasspointConfiguration config = createConfig(); + PasspointConfiguration config = PasspointTestUtils.createConfig(); config.setAaaServerTrustedNames(null); verifyParcel(config); } @@ -318,7 +180,7 @@ public class PasspointConfigurationTest { */ @Test public void validateFullConfig() throws Exception { - PasspointConfiguration config = createConfig(); + PasspointConfiguration config = PasspointTestUtils.createConfig(); assertTrue(config.validate()); assertTrue(config.validateForR2()); @@ -332,7 +194,7 @@ public class PasspointConfigurationTest { */ @Test public void validateFullConfigWithoutUpdateIdentifier() throws Exception { - PasspointConfiguration config = createConfig(); + PasspointConfiguration config = PasspointTestUtils.createConfig(); config.setUpdateIdentifier(Integer.MIN_VALUE); assertTrue(config.validate()); @@ -346,7 +208,7 @@ public class PasspointConfigurationTest { */ @Test public void validateConfigWithoutCredential() throws Exception { - PasspointConfiguration config = createConfig(); + PasspointConfiguration config = PasspointTestUtils.createConfig(); config.setCredential(null); assertFalse(config.validate()); @@ -360,7 +222,7 @@ public class PasspointConfigurationTest { */ @Test public void validateConfigWithoutHomeSp() throws Exception { - PasspointConfiguration config = createConfig(); + PasspointConfiguration config = PasspointTestUtils.createConfig(); config.setHomeSp(null); assertFalse(config.validate()); @@ -375,7 +237,7 @@ public class PasspointConfigurationTest { */ @Test public void validateConfigWithoutPolicy() throws Exception { - PasspointConfiguration config = createConfig(); + PasspointConfiguration config = PasspointTestUtils.createConfig(); config.setPolicy(null); assertTrue(config.validate()); @@ -390,7 +252,7 @@ public class PasspointConfigurationTest { */ @Test public void validateConfigWithoutSubscriptionUpdate() throws Exception { - PasspointConfiguration config = createConfig(); + PasspointConfiguration config = PasspointTestUtils.createConfig(); config.setSubscriptionUpdate(null); assertTrue(config.validate()); @@ -405,7 +267,7 @@ public class PasspointConfigurationTest { */ @Test public void validateConfigWithoutAaaServerTrustedNames() throws Exception { - PasspointConfiguration config = createConfig(); + PasspointConfiguration config = PasspointTestUtils.createConfig(); config.setAaaServerTrustedNames(null); assertTrue(config.validate()); @@ -420,7 +282,7 @@ public class PasspointConfigurationTest { */ @Test public void validateConfigWithInvalidTrustRootCertUrl() throws Exception { - PasspointConfiguration config = createConfig(); + PasspointConfiguration config = PasspointTestUtils.createConfig(); byte[] rawUrlBytes = new byte[MAX_URL_BYTES + 1]; Map<String, byte[]> trustRootCertList = new HashMap<>(); Arrays.fill(rawUrlBytes, (byte) 'a'); @@ -445,7 +307,7 @@ public class PasspointConfigurationTest { */ @Test public void validateConfigWithInvalidTrustRootCertFingerprint() throws Exception { - PasspointConfiguration config = createConfig(); + PasspointConfiguration config = PasspointTestUtils.createConfig(); Map<String, byte[]> trustRootCertList = new HashMap<>(); trustRootCertList.put("test.cert.com", new byte[CERTIFICATE_FINGERPRINT_BYTES + 1]); config.setTrustRootCertList(trustRootCertList); @@ -482,7 +344,7 @@ public class PasspointConfigurationTest { */ @Test public void validateCopyConstructorWithValidSource() throws Exception { - PasspointConfiguration sourceConfig = createConfig(); + PasspointConfiguration sourceConfig = PasspointTestUtils.createConfig(); PasspointConfiguration copyConfig = new PasspointConfiguration(sourceConfig); assertTrue(copyConfig.equals(sourceConfig)); } diff --git a/wifi/tests/src/android/net/wifi/hotspot2/PasspointTestUtils.java b/wifi/tests/src/android/net/wifi/hotspot2/PasspointTestUtils.java new file mode 100644 index 000000000000..adf74ebe36e5 --- /dev/null +++ b/wifi/tests/src/android/net/wifi/hotspot2/PasspointTestUtils.java @@ -0,0 +1,163 @@ +/* + * 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 android.net.wifi.hotspot2; + +import android.net.wifi.EAPConstants; +import android.net.wifi.hotspot2.pps.Credential; +import android.net.wifi.hotspot2.pps.HomeSp; +import android.net.wifi.hotspot2.pps.Policy; +import android.net.wifi.hotspot2.pps.UpdateParameter; +import android.util.Base64; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class PasspointTestUtils { + private static final int CERTIFICATE_FINGERPRINT_BYTES = 32; + + /** + * Utility function for creating a {@link android.net.wifi.hotspot2.pps.HomeSP}. + * + * @return {@link android.net.wifi.hotspot2.pps.HomeSP} + */ + private static HomeSp createHomeSp() { + HomeSp homeSp = new HomeSp(); + homeSp.setFqdn("fqdn"); + homeSp.setFriendlyName("friendly name"); + homeSp.setRoamingConsortiumOis(new long[] {0x55, 0x66}); + return homeSp; + } + + /** + * Utility function for creating a {@link android.net.wifi.hotspot2.pps.Credential}. + * + * @return {@link android.net.wifi.hotspot2.pps.Credential} + */ + private static Credential createCredential() { + Credential cred = new Credential(); + cred.setRealm("realm"); + cred.setUserCredential(null); + cred.setCertCredential(null); + cred.setSimCredential(new Credential.SimCredential()); + cred.getSimCredential().setImsi("1234*"); + cred.getSimCredential().setEapType(EAPConstants.EAP_SIM); + cred.setCaCertificate(null); + cred.setClientCertificateChain(null); + cred.setClientPrivateKey(null); + return cred; + } + + /** + * Helper function for creating a {@link Policy} for testing. + * + * @return {@link Policy} + */ + private static Policy createPolicy() { + Policy policy = new Policy(); + policy.setMinHomeDownlinkBandwidth(123); + policy.setMinHomeUplinkBandwidth(345); + policy.setMinRoamingDownlinkBandwidth(567); + policy.setMinRoamingUplinkBandwidth(789); + policy.setMaximumBssLoadValue(12); + policy.setExcludedSsidList(new String[] {"ssid1", "ssid2"}); + HashMap<Integer, String> requiredProtoPortMap = new HashMap<>(); + requiredProtoPortMap.put(12, "23,342,123"); + requiredProtoPortMap.put(23, "789,372,1235"); + policy.setRequiredProtoPortMap(requiredProtoPortMap); + + List<Policy.RoamingPartner> preferredRoamingPartnerList = new ArrayList<>(); + Policy.RoamingPartner partner1 = new Policy.RoamingPartner(); + partner1.setFqdn("partner1.com"); + partner1.setFqdnExactMatch(true); + partner1.setPriority(12); + partner1.setCountries("us,jp"); + Policy.RoamingPartner partner2 = new Policy.RoamingPartner(); + partner2.setFqdn("partner2.com"); + partner2.setFqdnExactMatch(false); + partner2.setPriority(42); + partner2.setCountries("ca,fr"); + preferredRoamingPartnerList.add(partner1); + preferredRoamingPartnerList.add(partner2); + policy.setPreferredRoamingPartnerList(preferredRoamingPartnerList); + + UpdateParameter policyUpdate = new UpdateParameter(); + policyUpdate.setUpdateIntervalInMinutes(1712); + policyUpdate.setUpdateMethod(UpdateParameter.UPDATE_METHOD_OMADM); + policyUpdate.setRestriction(UpdateParameter.UPDATE_RESTRICTION_HOMESP); + policyUpdate.setServerUri("policy.update.com"); + policyUpdate.setUsername("username"); + policyUpdate.setBase64EncodedPassword( + Base64.encodeToString("password".getBytes(), Base64.DEFAULT)); + policyUpdate.setTrustRootCertUrl("trust.cert.com"); + policyUpdate.setTrustRootCertSha256Fingerprint( + new byte[CERTIFICATE_FINGERPRINT_BYTES]); + policy.setPolicyUpdate(policyUpdate); + + return policy; + } + + private static UpdateParameter createSubscriptionUpdate() { + UpdateParameter subUpdate = new UpdateParameter(); + subUpdate.setUpdateIntervalInMinutes(9021); + subUpdate.setUpdateMethod(UpdateParameter.UPDATE_METHOD_SSP); + subUpdate.setRestriction(UpdateParameter.UPDATE_RESTRICTION_ROAMING_PARTNER); + subUpdate.setServerUri("subscription.update.com"); + subUpdate.setUsername("subUsername"); + subUpdate.setBase64EncodedPassword( + Base64.encodeToString("subPassword".getBytes(), Base64.DEFAULT)); + subUpdate.setTrustRootCertUrl("subscription.trust.cert.com"); + subUpdate.setTrustRootCertSha256Fingerprint(new byte[CERTIFICATE_FINGERPRINT_BYTES]); + return subUpdate; + } + /** + * Helper function for creating a {@link PasspointConfiguration} for testing. + * + * @return {@link PasspointConfiguration} + */ + public static PasspointConfiguration createConfig() { + PasspointConfiguration config = new PasspointConfiguration(); + config.setUpdateIdentifier(1234); + config.setHomeSp(createHomeSp()); + config.setAaaServerTrustedNames( + new String[] {"trusted.fqdn.com", "another-trusted.fqdn.com"}); + config.setCredential(createCredential()); + config.setPolicy(createPolicy()); + config.setSubscriptionUpdate(createSubscriptionUpdate()); + Map<String, byte[]> trustRootCertList = new HashMap<>(); + trustRootCertList.put("trustRoot.cert1.com", + new byte[CERTIFICATE_FINGERPRINT_BYTES]); + trustRootCertList.put("trustRoot.cert2.com", + new byte[CERTIFICATE_FINGERPRINT_BYTES]); + config.setTrustRootCertList(trustRootCertList); + config.setUpdateIdentifier(1); + config.setCredentialPriority(120); + config.setSubscriptionCreationTimeInMillis(231200); + config.setSubscriptionExpirationTimeInMillis(2134232); + config.setSubscriptionType("Gold"); + config.setUsageLimitUsageTimePeriodInMinutes(3600); + config.setUsageLimitStartTimeInMillis(124214213); + config.setUsageLimitDataLimit(14121); + config.setUsageLimitTimeLimitInMinutes(78912); + Map<String, String> friendlyNames = new HashMap<>(); + friendlyNames.put("en", "ServiceName1"); + friendlyNames.put("kr", "ServiceName2"); + config.setServiceFriendlyNames(friendlyNames); + return config; + } +} |