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

Commit 28d32cd1 authored by Xia Wang's avatar Xia Wang Committed by Android (Google) Code Review
Browse files

Merge "Wait for broadcast even if the network state has been changed. bug: 2863356"

parents 48a16ce3 69a5a966
Loading
Loading
Loading
Loading
+38 −38
Original line number Original line Diff line number Diff line
@@ -91,13 +91,14 @@ public class ConnectivityManagerMobileTest
    //                                      DISCONNECTING, DISCONNECTED, UNKNOWN
    //                                      DISCONNECTING, DISCONNECTED, UNKNOWN
    private void waitForNetworkState(int networkType, State expectedState, long timeout) {
    private void waitForNetworkState(int networkType, State expectedState, long timeout) {
        long startTime = System.currentTimeMillis();
        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) {
        while (true) {
            if ((System.currentTimeMillis() - startTime) > timeout) {
            if ((System.currentTimeMillis() - startTime) > timeout) {
                if (cmActivity.mCM.getNetworkInfo(networkType).getState() != expectedState) {
                    assertFalse("Wait for network state timeout", true);
                    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 +
            Log.v(LOG_TAG, "Wait for the connectivity state for network: " + networkType +
                    " to be " + expectedState.toString());
                    " to be " + expectedState.toString());
@@ -117,18 +118,18 @@ public class ConnectivityManagerMobileTest
            }
            }
        }
        }
    }
    }
    }


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


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