MAC randomization: getFactoryMacAddresses API
API to get the factory MAC addresses. Not for use by third party apps. Bug: 111634904 Test: unit tests Change-Id: I9258889b963886b79191b9ea1e7aa70ffb4eb6ad
This commit is contained in:
@@ -193,5 +193,7 @@ interface IWifiManager
|
||||
int addNetworkSuggestions(in List<WifiNetworkSuggestion> networkSuggestions, in String packageName);
|
||||
|
||||
int removeNetworkSuggestions(in List<WifiNetworkSuggestion> networkSuggestions, in String packageName);
|
||||
|
||||
String[] getFactoryMacAddresses();
|
||||
}
|
||||
|
||||
|
||||
@@ -4427,4 +4427,19 @@ public class WifiManager {
|
||||
public boolean isOweSupported() {
|
||||
return isFeatureSupported(WIFI_FEATURE_OWE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the factory Wi-Fi MAC addresses.
|
||||
* @return Array of String representing Wi-Fi MAC addresses sorted lexically or an empty Array
|
||||
* if failed.
|
||||
* @hide
|
||||
*/
|
||||
@RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS)
|
||||
public String[] getFactoryMacAddresses() {
|
||||
try {
|
||||
return mService.getFactoryMacAddresses();
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -452,4 +452,9 @@ public abstract class AbstractWifiService extends IWifiManager.Stub {
|
||||
List<WifiNetworkSuggestion> networkSuggestions, String callingPackageName) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getFactoryMacAddresses() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import static android.net.wifi.WifiManager.WIFI_AP_STATE_ENABLED;
|
||||
import static android.net.wifi.WifiManager.WIFI_AP_STATE_ENABLING;
|
||||
import static android.net.wifi.WifiManager.WIFI_AP_STATE_FAILED;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -88,6 +89,7 @@ public class WifiManagerTest {
|
||||
private static final int TEST_UID = 14553;
|
||||
private static final String TEST_PACKAGE_NAME = "TestPackage";
|
||||
private static final String TEST_COUNTRY_CODE = "US";
|
||||
private static final String[] TEST_MAC_ADDRESSES = {"da:a1:19:0:0:0"};
|
||||
|
||||
@Mock Context mContext;
|
||||
@Mock
|
||||
@@ -1320,4 +1322,15 @@ i * Verify that a call to cancel WPS immediately returns a failure.
|
||||
assertEquals(WifiManager.NETWORK_SUGGESTIONS_MAX_PER_APP,
|
||||
mWifiManager.getMaxNumberOfNetworkSuggestionsPerApp());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify getting the factory MAC address.
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testGetFactoryMacAddress() throws Exception {
|
||||
when(mWifiService.getFactoryMacAddresses()).thenReturn(TEST_MAC_ADDRESSES);
|
||||
assertArrayEquals(TEST_MAC_ADDRESSES, mWifiManager.getFactoryMacAddresses());
|
||||
verify(mWifiService).getFactoryMacAddresses();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user