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

Commit dd4764b7 authored by clownshen's avatar clownshen Committed by Clown SHEN
Browse files

Fix NPE when connect timeout

If user click connect button and then receive timeout event after leave
detail page, the NPE happened. Ignore the timeout event if activity
already gone.

Bug: 131141866
Test: manual test
Test: make RunSettingsRoboTests -j32 ROBOTEST_FILTER=com.android.settings.wifi.details.WifiDetailPreferenceControllerTest
Change-Id: Ic22c22027386d4a6de5d693eafcd9cd463ed3415
parent b70f2b58
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -1109,6 +1109,10 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController
            }
            @Override
            public void onFinish() {
                if (mFragment == null || mFragment.getActivity() == null) {
                    Log.d(TAG, "Ignore timeout since activity not exist!");
                    return;
                }
                Log.e(TAG, "Timeout for state:" + mConnectingState);
                if (mConnectingState == STATE_ENABLE_WIFI) {
                    updateConnectingState(STATE_ENABLE_WIFI_FAILED);
+33 −0
Original line number Diff line number Diff line
@@ -1623,6 +1623,39 @@ public class WifiDetailPreferenceControllerTest {
                mContext.getString(R.string.wifi_failed_connect_message));
    }

    @Test
    public void testConnectButton_clickConnectAndBackKey_ignoreTimeoutEvent() {
        setUpForDisconnectedNetwork();
        when(mockWifiManager.isWifiEnabled()).thenReturn(true);
        InOrder inOrder = inOrder(mockButtonsPref);
        setUpForToast();

        displayAndResume();

        // check connect button exist
        verifyConnectBtnSetUpAsVisible(inOrder);

        // click connect button
        mController.connectNetwork();

        // check display button as connecting
        verify(mockWifiManager, times(1)).connect(anyInt(), any(WifiManager.ActionListener.class));
        verifyConnectBtnSetUpAsConnecting(inOrder);

        // leave detail page
        when(mockFragment.getActivity()).thenReturn(null);

        // timeout happened
        mController.mTimer.onFinish();

        // check connect button visible, be init as default and toast failed message
        inOrder.verify(mockButtonsPref, never()).setButton3Text(R.string.wifi_connect);
        inOrder.verify(mockButtonsPref, never()).setButton3Icon(R.drawable.ic_settings_wireless);
        inOrder.verify(mockButtonsPref, never()).setButton3Enabled(true);
        inOrder.verify(mockButtonsPref, never()).setButton3Visible(true);
        assertThat(ShadowToast.shownToastCount()).isEqualTo(0);
    }

    @Test
    public void updateAccessPoint_returnFalseForNothingChanged() {
        setUpForDisconnectedNetwork();