Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 37a22b6c authored by Oscar Shu's avatar Oscar Shu Committed by Android (Google) Code Review
Browse files

Merge "MAC randomization: getFactoryMacAddresses API"

parents f509c389 9806aa50
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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();
}
+15 −0
Original line number Diff line number Diff line
@@ -4434,4 +4434,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();
        }
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -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();
    }
}
+13 −0
Original line number Diff line number Diff line
@@ -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();
    }
}