Suggestion API to set macRandomization setting

Allows suggestions to either use enhanced randomization or persistent
randomization. If not set, enhanced randomization will be used by
default.

Bug: 162801581
Test: atest android.net.wifi

Change-Id: Ia41511677221e4aa1d79830c898d90f808c4e7c8
This commit is contained in:
xshu
2020-08-24 02:14:51 -07:00
parent ae905ec585
commit fc5cee94fe
4 changed files with 64 additions and 0 deletions

View File

@@ -31644,6 +31644,7 @@ package android.net.wifi {
method @NonNull public android.net.wifi.WifiNetworkSuggestion.Builder setBssid(@NonNull android.net.MacAddress);
method @NonNull public android.net.wifi.WifiNetworkSuggestion.Builder setCredentialSharedWithUser(boolean);
method @NonNull public android.net.wifi.WifiNetworkSuggestion.Builder setIsAppInteractionRequired(boolean);
method @NonNull public android.net.wifi.WifiNetworkSuggestion.Builder setIsEnhancedMacRandomizationEnabled(boolean);
method @NonNull public android.net.wifi.WifiNetworkSuggestion.Builder setIsEnhancedOpen(boolean);
method @NonNull public android.net.wifi.WifiNetworkSuggestion.Builder setIsHiddenSsid(boolean);
method @NonNull public android.net.wifi.WifiNetworkSuggestion.Builder setIsInitialAutojoinEnabled(boolean);

View File

@@ -507,6 +507,7 @@ package android.net.wifi {
method @NonNull public android.net.wifi.WifiNetworkSuggestion.Builder setBssid(@NonNull android.net.MacAddress);
method @NonNull public android.net.wifi.WifiNetworkSuggestion.Builder setCredentialSharedWithUser(boolean);
method @NonNull public android.net.wifi.WifiNetworkSuggestion.Builder setIsAppInteractionRequired(boolean);
method @NonNull public android.net.wifi.WifiNetworkSuggestion.Builder setIsEnhancedMacRandomizationEnabled(boolean);
method @NonNull public android.net.wifi.WifiNetworkSuggestion.Builder setIsEnhancedOpen(boolean);
method @NonNull public android.net.wifi.WifiNetworkSuggestion.Builder setIsHiddenSsid(boolean);
method @NonNull public android.net.wifi.WifiNetworkSuggestion.Builder setIsInitialAutojoinEnabled(boolean);

View File

@@ -149,6 +149,11 @@ public final class WifiNetworkSuggestion implements Parcelable {
*/
private boolean mIsNetworkUntrusted;
/**
* Whether this network will use enhanced MAC randomization.
*/
private boolean mIsEnhancedMacRandomizationEnabled;
public Builder() {
mSsid = null;
mBssid = null;
@@ -171,6 +176,7 @@ public final class WifiNetworkSuggestion implements Parcelable {
mWapiEnterpriseConfig = null;
mIsNetworkUntrusted = false;
mPriorityGroup = 0;
mIsEnhancedMacRandomizationEnabled = true;
}
/**
@@ -393,6 +399,29 @@ public final class WifiNetworkSuggestion implements Parcelable {
return this;
}
/**
* Specifies the MAC randomization method.
* <p>
* Suggested networks will never use the device (factory) MAC address to associate to the
* network - instead they use a locally generated random MAC address. This method controls
* the strategy for generating the random MAC address:
* <li> Persisted MAC randomization (false): generates the MAC address from a secret seed
* and information from the Wi-Fi configuration (SSID or Passpoint profile). That means that
* the same generated MAC address will be used for each subsequent association. </li>
* <li> Enhanced MAC randomization (true - the default): periodically generates a new MAC
* address new connections. Under this option, the randomized MAC address should change
* if the suggestion is removed and then added back. </li>
*
* @param enabled {@code true} to periodically change the randomized MAC address.
* {@code false} to use the same randomized MAC for all connections to this
* network.
* @return Instance of {@link Builder} to enable chaining of the builder method.
*/
public @NonNull Builder setIsEnhancedMacRandomizationEnabled(boolean enabled) {
mIsEnhancedMacRandomizationEnabled = enabled;
return this;
}
/**
* Specifies whether the app needs to log in to a captive portal to obtain Internet access.
* <p>
@@ -577,6 +606,9 @@ public final class WifiNetworkSuggestion implements Parcelable {
wifiConfiguration.meteredOverride = mMeteredOverride;
wifiConfiguration.carrierId = mCarrierId;
wifiConfiguration.trusted = !mIsNetworkUntrusted;
wifiConfiguration.macRandomizationSetting = mIsEnhancedMacRandomizationEnabled
? WifiConfiguration.RANDOMIZATION_ENHANCED
: WifiConfiguration.RANDOMIZATION_PERSISTENT;
return wifiConfiguration;
}
@@ -607,6 +639,9 @@ public final class WifiNetworkSuggestion implements Parcelable {
wifiConfiguration.trusted = !mIsNetworkUntrusted;
mPasspointConfiguration.setCarrierId(mCarrierId);
mPasspointConfiguration.setMeteredOverride(wifiConfiguration.meteredOverride);
wifiConfiguration.macRandomizationSetting = mIsEnhancedMacRandomizationEnabled
? WifiConfiguration.RANDOMIZATION_ENHANCED
: WifiConfiguration.RANDOMIZATION_PERSISTENT;
return wifiConfiguration;
}

View File

@@ -609,6 +609,33 @@ public class WifiNetworkSuggestionTest {
.build();
}
/**
* Verify that the macRandomizationSetting defaults to RANDOMIZATION_ENHANCED and could be set
* to RANDOMIZATION_PERSISTENT.
*/
@Test
public void testWifiNetworkSuggestionBuilderSetMacRandomization() {
WifiNetworkSuggestion suggestion = new WifiNetworkSuggestion.Builder()
.setSsid(TEST_SSID)
.build();
assertEquals(WifiConfiguration.RANDOMIZATION_ENHANCED,
suggestion.wifiConfiguration.macRandomizationSetting);
suggestion = new WifiNetworkSuggestion.Builder()
.setSsid(TEST_SSID)
.setIsEnhancedMacRandomizationEnabled(false)
.build();
assertEquals(WifiConfiguration.RANDOMIZATION_PERSISTENT,
suggestion.wifiConfiguration.macRandomizationSetting);
suggestion = new WifiNetworkSuggestion.Builder()
.setSsid(TEST_SSID)
.setIsEnhancedMacRandomizationEnabled(true)
.build();
assertEquals(WifiConfiguration.RANDOMIZATION_ENHANCED,
suggestion.wifiConfiguration.macRandomizationSetting);
}
/**
* Check that parcel marshalling/unmarshalling works
*/