Remove getOrCreateRandomizedMacAddress API

Bug: 137799272
Test: unit tests
Change-Id: I078d28ed81a84e32aaece839a51590364a974481
This commit is contained in:
xshu 2019-09-25 16:25:06 -07:00
parent c9c0b9f270
commit 44e80de8be
2 changed files with 3 additions and 66 deletions

View File

@ -1055,26 +1055,6 @@ public class WifiConfiguration implements Parcelable {
&& !MacAddress.fromString(WifiInfo.DEFAULT_MAC_ADDRESS).equals(mac);
}
/**
* @hide
* Returns Randomized MAC address to use with the network.
* If it is not set/valid, creates a new randomized address.
* If it can't generate a valid mac, returns the default MAC.
*/
public @NonNull MacAddress getOrCreateRandomizedMacAddress() {
int randomMacGenerationCount = 0;
while (!isValidMacAddressForRandomization(mRandomizedMacAddress)
&& randomMacGenerationCount < MAXIMUM_RANDOM_MAC_GENERATION_RETRY) {
mRandomizedMacAddress = MacAddress.createRandomUnicastAddress();
randomMacGenerationCount++;
}
if (!isValidMacAddressForRandomization(mRandomizedMacAddress)) {
mRandomizedMacAddress = MacAddress.fromString(WifiInfo.DEFAULT_MAC_ADDRESS);
}
return mRandomizedMacAddress;
}
/**
* Returns MAC address set to be the local randomized MAC address.
* Depending on user preference, the device may or may not use the returned MAC address for

View File

@ -19,7 +19,6 @@ package android.net.wifi;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import android.net.MacAddress;
@ -62,7 +61,8 @@ public class WifiConfigurationTest {
config.updateIdentifier = "1234";
config.fromWifiNetworkSpecifier = true;
config.fromWifiNetworkSuggestion = true;
MacAddress macBeforeParcel = config.getOrCreateRandomizedMacAddress();
config.setRandomizedMacAddress(MacAddress.createRandomUnicastAddress());
MacAddress macBeforeParcel = config.getRandomizedMacAddress();
Parcel parcelW = Parcel.obtain();
config.writeToParcel(parcelW, 0);
byte[] bytes = parcelW.marshall();
@ -75,7 +75,7 @@ public class WifiConfigurationTest {
// lacking a useful config.equals, check two fields near the end.
assertEquals(cookie, reconfig.getMoTree());
assertEquals(macBeforeParcel, reconfig.getOrCreateRandomizedMacAddress());
assertEquals(macBeforeParcel, reconfig.getRandomizedMacAddress());
assertEquals(config.updateIdentifier, reconfig.updateIdentifier);
assertFalse(reconfig.trusted);
assertTrue(config.fromWifiNetworkSpecifier);
@ -192,19 +192,6 @@ public class WifiConfigurationTest {
assertFalse(config.isOpenNetwork());
}
@Test
public void testGetOrCreateRandomizedMacAddress_SavesAndReturnsSameAddress() {
WifiConfiguration config = new WifiConfiguration();
MacAddress defaultMac = MacAddress.fromString(WifiInfo.DEFAULT_MAC_ADDRESS);
assertEquals(defaultMac, config.getRandomizedMacAddress());
MacAddress firstMacAddress = config.getOrCreateRandomizedMacAddress();
MacAddress secondMacAddress = config.getOrCreateRandomizedMacAddress();
assertNotEquals(defaultMac, firstMacAddress);
assertEquals(firstMacAddress, secondMacAddress);
}
@Test
public void testSetRandomizedMacAddress_ChangesSavedAddress() {
WifiConfiguration config = new WifiConfiguration();
@ -218,36 +205,6 @@ public class WifiConfigurationTest {
assertEquals(macToChangeInto, macAfterChange);
}
@Test
public void testGetOrCreateRandomizedMacAddress_ReRandomizesInvalidAddress() {
WifiConfiguration config = new WifiConfiguration();
MacAddress defaultMac = MacAddress.fromString(WifiInfo.DEFAULT_MAC_ADDRESS);
MacAddress macAddressZeroes = MacAddress.ALL_ZEROS_ADDRESS;
MacAddress macAddressMulticast = MacAddress.fromString("03:ff:ff:ff:ff:ff");
MacAddress macAddressGlobal = MacAddress.fromString("fc:ff:ff:ff:ff:ff");
config.setRandomizedMacAddress(null);
MacAddress macAfterChange = config.getOrCreateRandomizedMacAddress();
assertNotEquals(macAfterChange, null);
config.setRandomizedMacAddress(defaultMac);
macAfterChange = config.getOrCreateRandomizedMacAddress();
assertNotEquals(macAfterChange, defaultMac);
config.setRandomizedMacAddress(macAddressZeroes);
macAfterChange = config.getOrCreateRandomizedMacAddress();
assertNotEquals(macAfterChange, macAddressZeroes);
config.setRandomizedMacAddress(macAddressMulticast);
macAfterChange = config.getOrCreateRandomizedMacAddress();
assertNotEquals(macAfterChange, macAddressMulticast);
config.setRandomizedMacAddress(macAddressGlobal);
macAfterChange = config.getOrCreateRandomizedMacAddress();
assertNotEquals(macAfterChange, macAddressGlobal);
}
@Test
public void testSetRandomizedMacAddress_DoesNothingWhenNull() {
WifiConfiguration config = new WifiConfiguration();