Default Randomized MAC Address to 0:0:0:0:0:0 in WifiConfig

Set the default value of Randomized MAC address as 0:0:0:0:0:0 instead
of null.

Making this change to simplify storing randomized address to XML for
permanent storage. Without this change, will need to manually check if
the value is null during MacAddress<->XML conversion.

Bug: 72753415
Test: Unittest.
Change-Id: I6edf486360e267acec9f8a343386444be2ea99fa
This commit is contained in:
Jong Wook Kim
2018-02-05 14:26:48 -08:00
parent 0ab4ea3ef2
commit 4f10fb95de
2 changed files with 8 additions and 0 deletions

View File

@@ -917,6 +917,9 @@ public class WifiConfiguration implements Parcelable {
* Does not guarantee that the returned address is valid for use.
*/
public MacAddress getRandomizedMacAddress() {
if (mRandomizedMacAddress == null) {
mRandomizedMacAddress = MacAddress.ALL_ZEROS_ADDRESS;
}
return mRandomizedMacAddress;
}
@@ -1617,6 +1620,7 @@ public class WifiConfiguration implements Parcelable {
creatorUid = -1;
shared = true;
dtimInterval = 0;
mRandomizedMacAddress = MacAddress.ALL_ZEROS_ADDRESS;
}
/**

View File

@@ -176,6 +176,8 @@ public class WifiConfigurationTest {
@Test
public void testGetOrCreateRandomizedMacAddress_SavesAndReturnsSameAddress() {
WifiConfiguration config = new WifiConfiguration();
assertEquals(MacAddress.ALL_ZEROS_ADDRESS, config.getRandomizedMacAddress());
MacAddress firstMacAddress = config.getOrCreateRandomizedMacAddress();
MacAddress secondMacAddress = config.getOrCreateRandomizedMacAddress();
@@ -185,6 +187,8 @@ public class WifiConfigurationTest {
@Test
public void testSetRandomizedMacAddress_ChangesSavedAddress() {
WifiConfiguration config = new WifiConfiguration();
assertEquals(MacAddress.ALL_ZEROS_ADDRESS, config.getRandomizedMacAddress());
MacAddress macToChangeInto = MacAddress.createRandomUnicastAddress();
config.setRandomizedMacAddress(macToChangeInto);
MacAddress macAfterChange = config.getOrCreateRandomizedMacAddress();