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

Commit 0861b534 authored by Jong Wook Kim's avatar Jong Wook Kim Committed by Android (Google) Code Review
Browse files

Merge "Display "Unavailable" when received default MAC"

parents ce287b9f d2ba8871
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -102,11 +102,12 @@ public class WifiInfoPreferenceController extends AbstractPreferenceController
                    Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED, 0);
            final String macAddress = wifiInfo == null ? null : wifiInfo.getMacAddress();

            if (TextUtils.isEmpty(macAddress)) {
                mWifiMacAddressPref.setSummary(R.string.status_unavailable);
            } else if (macRandomizationMode == 1
            if (macRandomizationMode == 1
                    && WifiInfo.DEFAULT_MAC_ADDRESS.equals(macAddress)) {
                mWifiMacAddressPref.setSummary(R.string.wifi_status_mac_randomized);
            } else if (TextUtils.isEmpty(macAddress)
                    || WifiInfo.DEFAULT_MAC_ADDRESS.equals(macAddress)) {
                mWifiMacAddressPref.setSummary(R.string.status_unavailable);
            } else {
                mWifiMacAddressPref.setSummary(macAddress);
            }
+79 −3
Original line number Diff line number Diff line
@@ -79,6 +79,7 @@ public class WifiInfoPreferenceControllerTest {
                .thenReturn(mMacPreference)
                .thenReturn(mIpPreference);
        when(mWifiManager.getConnectionInfo()).thenReturn(mWifiInfo);
        when(mWifiManager.getCurrentNetwork()).thenReturn(null);
        mController = new WifiInfoPreferenceController(mContext, mLifecycle, mWifiManager);
    }

@@ -103,7 +104,6 @@ public class WifiInfoPreferenceControllerTest {

    @Test
    public void onResume_shouldUpdateWifiInfo() {
        when(mWifiManager.getCurrentNetwork()).thenReturn(null);
        when(mWifiInfo.getMacAddress()).thenReturn(TEST_MAC_ADDRESS);

        mController.displayPreference(mScreen);
@@ -114,22 +114,98 @@ public class WifiInfoPreferenceControllerTest {
    }

    @Test
    public void testUpdateMacAddress() {
        when(mWifiManager.getCurrentNetwork()).thenReturn(null);
    public void updateWifiInfo_nullWifiInfoWithMacRandomizationOff_setMacUnavailable() {
        Settings.Global.putInt(mContext.getContentResolver(),
                Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED, 0);
        mController.displayPreference(mScreen);
        when(mWifiManager.getConnectionInfo()).thenReturn(null);

        mController.updateWifiInfo();

        verify(mMacPreference).setSummary(R.string.status_unavailable);
    }

    @Test
    public void updateWifiInfo_nullMacWithMacRandomizationOff_setMacUnavailable() {
        Settings.Global.putInt(mContext.getContentResolver(),
                Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED, 0);
        mController.displayPreference(mScreen);
        when(mWifiInfo.getMacAddress()).thenReturn(null);

        mController.updateWifiInfo();

        verify(mMacPreference).setSummary(R.string.status_unavailable);
    }

    @Test
    public void updateWifiInfo_defaultMacWithMacRandomizationOff_setMacUnavailable() {
        Settings.Global.putInt(mContext.getContentResolver(),
                Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED, 0);
        mController.displayPreference(mScreen);
        when(mWifiInfo.getMacAddress()).thenReturn(WifiInfo.DEFAULT_MAC_ADDRESS);

        mController.updateWifiInfo();

        verify(mMacPreference).setSummary(R.string.status_unavailable);
    }

    @Test
    public void updateWifiInfo_validMacWithMacRandomizationOff_setValidMac() {
        Settings.Global.putInt(mContext.getContentResolver(),
                Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED, 0);
        mController.displayPreference(mScreen);
        when(mWifiInfo.getMacAddress()).thenReturn(TEST_MAC_ADDRESS);

        mController.updateWifiInfo();

        verify(mMacPreference).setSummary(TEST_MAC_ADDRESS);
    }

    @Test
    public void updateWifiInfo_nullWifiInfoWithMacRandomizationOn_setMacUnavailable() {
        Settings.Global.putInt(mContext.getContentResolver(),
                Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED, 1);
        mController.displayPreference(mScreen);
        when(mWifiManager.getConnectionInfo()).thenReturn(null);

        mController.updateWifiInfo();

        verify(mMacPreference).setSummary(R.string.status_unavailable);
    }

    @Test
    public void updateWifiInfo_nullMacWithMacRandomizationOn_setMacUnavailable() {
        Settings.Global.putInt(mContext.getContentResolver(),
                Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED, 1);
        mController.displayPreference(mScreen);
        when(mWifiInfo.getMacAddress()).thenReturn(null);

        mController.updateWifiInfo();

        verify(mMacPreference).setSummary(R.string.status_unavailable);
    }

    @Test
    public void updateWifiInfo_defaultMacWithMacRandomizationOn_setMacRandomized() {
        Settings.Global.putInt(mContext.getContentResolver(),
                Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED, 1);
        mController.displayPreference(mScreen);
        when(mWifiInfo.getMacAddress()).thenReturn(WifiInfo.DEFAULT_MAC_ADDRESS);

        mController.updateWifiInfo();

        verify(mMacPreference).setSummary(R.string.wifi_status_mac_randomized);
    }

    @Test
    public void updateWifiInfo_validMacWithMacRandomizationOn_setValidMac() {
        Settings.Global.putInt(mContext.getContentResolver(),
                Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED, 1);
        mController.displayPreference(mScreen);
        when(mWifiInfo.getMacAddress()).thenReturn(TEST_MAC_ADDRESS);

        mController.updateWifiInfo();

        verify(mMacPreference).setSummary(TEST_MAC_ADDRESS);
    }
}