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

Commit 514391ca authored by Antony Sargent's avatar Antony Sargent Committed by android-build-merger
Browse files

Merge "Prevent brief flash of "Error" in hotspot status text" into oc-mr1-dev am: bc6dc5c2

am: 151d5600

Change-Id: I60106dd55184e0ad48a216a71ab066849636ddb2
parents f7eae26a 151d5600
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -138,6 +138,7 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController

    private void handleWifiApStateChanged(int state, int reason) {
        switch (state) {
            case WifiManager.WIFI_AP_STATE_ENABLING:
            case WifiManager.WIFI_AP_STATE_ENABLED:
                /**
                 * Summary on enable is handled by tether
+30 −11
Original line number Diff line number Diff line
@@ -161,12 +161,7 @@ public class WifiTetherPreferenceControllerTest {
    @Test
    public void testReceiver_apStateChangedToDisabled_shouldUpdatePreferenceSummary() {
        mController.displayPreference(mScreen);
        final BroadcastReceiver receiver = ReflectionHelpers.getField(mController, "mReceiver");
        final Intent broadcast = new Intent(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
        broadcast.putExtra(WifiManager.EXTRA_WIFI_AP_STATE, WifiManager.WIFI_AP_STATE_DISABLED);

        receiver.onReceive(RuntimeEnvironment.application, broadcast);

        receiveApStateChangedBroadcast(WifiManager.WIFI_AP_STATE_DISABLED);
        assertThat(mPreference.getSummary().toString()).isEqualTo(
                RuntimeEnvironment.application.getString(R.string.wifi_hotspot_off_subtext));
    }
@@ -174,14 +169,26 @@ public class WifiTetherPreferenceControllerTest {
    @Test
    public void testReceiver_apStateChangedToDisabling_shouldUpdatePreferenceSummary() {
        mController.displayPreference(mScreen);
        final BroadcastReceiver receiver = ReflectionHelpers.getField(mController, "mReceiver");
        final Intent broadcast = new Intent(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
        broadcast.putExtra(WifiManager.EXTRA_WIFI_AP_STATE, WifiManager.WIFI_AP_STATE_DISABLING);
        receiveApStateChangedBroadcast(WifiManager.WIFI_AP_STATE_DISABLING);
        assertThat(mPreference.getSummary().toString()).isEqualTo(
                RuntimeEnvironment.application.getString(R.string.wifi_tether_stopping));
    }

        receiver.onReceive(RuntimeEnvironment.application, broadcast);
    @Test
    public void testReceiver_apStateChangedToEnablingOrEnabled_shouldNotUpdatePreferenceSummary() {
        mController.displayPreference(mScreen);
        receiveApStateChangedBroadcast(WifiManager.WIFI_AP_STATE_DISABLED);
        assertThat(mPreference.getSummary().toString()).isEqualTo(
                RuntimeEnvironment.application.getString(R.string.wifi_hotspot_off_subtext));

        // When turning on the hotspot, we receive STATE_ENABLING followed by STATE_ENABLED. Neither
        // of these should change the summary.
        receiveApStateChangedBroadcast(WifiManager.WIFI_AP_STATE_ENABLING);
        assertThat(mPreference.getSummary().toString()).isEqualTo(
                RuntimeEnvironment.application.getString(R.string.wifi_tether_stopping));
                RuntimeEnvironment.application.getString(R.string.wifi_hotspot_off_subtext));
        receiveApStateChangedBroadcast(WifiManager.WIFI_AP_STATE_ENABLED);
        assertThat(mPreference.getSummary().toString()).isEqualTo(
                RuntimeEnvironment.application.getString(R.string.wifi_hotspot_off_subtext));
    }

    @Test
@@ -248,4 +255,16 @@ public class WifiTetherPreferenceControllerTest {
            onStopCalled = true;
        }
    }

    /**
     * Helper to cause the controller to receive a WIFI_AP_STATE_CHANGED_ACTION with a specific
     * state.
     * @param state - the state, as specified by one of the WifiManager.WIFI_AP_STATE_* values
     */
    private void receiveApStateChangedBroadcast(int state) {
        final BroadcastReceiver receiver = ReflectionHelpers.getField(mController, "mReceiver");
        final Intent broadcast = new Intent(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
        broadcast.putExtra(WifiManager.EXTRA_WIFI_AP_STATE, state);
        receiver.onReceive(RuntimeEnvironment.application, broadcast);
    }
}