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

Commit 69a5a966 authored by Xia Wang's avatar Xia Wang
Browse files

Wait for broadcast even if the network state has been changed.

bug: 2863356

Change-Id: If279e891cf66fcef465e85b704b0b857f6ac3742
parent 6b164fe0
Loading
Loading
Loading
Loading
+38 −38
Original line number Diff line number Diff line
@@ -91,13 +91,14 @@ public class ConnectivityManagerMobileTest
    //                                      DISCONNECTING, DISCONNECTED, UNKNOWN
    private void waitForNetworkState(int networkType, State expectedState, long timeout) {
        long startTime = System.currentTimeMillis();
        // In case the broadcast is already sent out, no need to wait
        if (cmActivity.mCM.getNetworkInfo(networkType).getState() == expectedState) {
            return;
        } else {
        while (true) {
            if ((System.currentTimeMillis() - startTime) > timeout) {
                if (cmActivity.mCM.getNetworkInfo(networkType).getState() != expectedState) {
                    assertFalse("Wait for network state timeout", true);
                } else {
                    // the broadcast has been sent out. the state has been changed.
                    return;
                }
            }
            Log.v(LOG_TAG, "Wait for the connectivity state for network: " + networkType +
                    " to be " + expectedState.toString());
@@ -117,18 +118,18 @@ public class ConnectivityManagerMobileTest
            }
        }
    }
    }

    // Wait for Wifi state: WIFI_STATE_DISABLED, WIFI_STATE_DISABLING, WIFI_STATE_ENABLED,
    //                      WIFI_STATE_ENALBING, WIFI_STATE_UNKNOWN
    private void waitForWifiState(int expectedState, long timeout) {
        long startTime = System.currentTimeMillis();
        if (cmActivity.mWifiState == expectedState) {
            return;
        } else {
        while (true) {
            if ((System.currentTimeMillis() - startTime) > timeout) {
                if (cmActivity.mWifiState != expectedState) {
                    assertFalse("Wait for Wifi state timeout", true);
                } else {
                    return;
                }
            }
            Log.v(LOG_TAG, "Wait for wifi state to be: " + expectedState);
            synchronized (cmActivity.wifiObject) {
@@ -145,7 +146,6 @@ public class ConnectivityManagerMobileTest
            }
        }
    }
    }

    // Test case 1: Test enabling Wifi without associating with any AP
    @LargeTest