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

Commit b77cc658 authored by Ben Lin's avatar Ben Lin
Browse files

Don't try to update Mac address if the preference pane is hidden.

If the preference controller is marking Mac Address as hidden by the
device, don't bother updating the connectivity.

Bug: 127358664
Test: atest WifiMacAddressPreferenceControllerTest
Change-Id: Ibc3c60b358cd1573a16b020f4b1fcea492b642f5
parent ee577653
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -69,9 +69,11 @@ public abstract class AbstractWifiMacAddressPreferenceController
    @Override
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);
        if (isAvailable()) {
            mWifiMacAddress = screen.findPreference(KEY_WIFI_MAC_ADDRESS);
            updateConnectivity();
        }
    }

    @Override
    protected String[] getConnectivityIntents() {
+15 −4
Original line number Diff line number Diff line
@@ -20,7 +20,9 @@ import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;

import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

import android.annotation.SuppressLint;
import android.content.Context;
@@ -91,6 +93,19 @@ public class WifiMacAddressPreferenceControllerTest {
                .asList().containsAllIn(expectedIntents);
    }

    @Test
    public void updateConnectivity_notAvailable_notCalled() {
        boolean mCalled = false;
        mController = spy(new ConcreteWifiMacAddressPreferenceController(mContext, mLifecycle) {
            @Override
            public boolean isAvailable() {
                return false;
            }
        });
        mController.displayPreference(mScreen);
        verify(mController, never()).updateConnectivity();
    }

    @Test
    public void updateConnectivity_null_setMacUnavailable() {
        doReturn(null).when(mWifiManager).getFactoryMacAddresses();
@@ -105,10 +120,6 @@ public class WifiMacAddressPreferenceControllerTest {
        doReturn(macAddresses).when(mWifiManager).getFactoryMacAddresses();
        mController.displayPreference(mScreen);
        assertThat(mPreference.getSummary()).isEqualTo(TEST_MAC_ADDRESS);




    }

    private static class ConcreteWifiMacAddressPreferenceController