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

Commit 7de19a56 authored by Cyril Lee's avatar Cyril Lee Committed by Android (Google) Code Review
Browse files

Merge "Added isOpenNetwork determine connect to an open network or not"

parents c6a2b1e6 de47626a
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -1206,8 +1206,7 @@ public class AccessPoint implements Comparable<AccessPoint> {
     * Can only be called for unsecured networks.
     */
    public void generateOpenNetworkConfig() {
        if ((security != SECURITY_NONE) && (security != SECURITY_OWE)
                && (security != SECURITY_OWE_TRANSITION)) {
        if (!isOpenNetwork()) {
            throw new IllegalStateException();
        }
        if (mConfig != null)
@@ -1699,6 +1698,14 @@ public class AccessPoint implements Comparable<AccessPoint> {
        return mWifiManager;
    }

    /**
     * Return true if this is an open network AccessPoint.
     */
    public boolean isOpenNetwork() {
        return security == SECURITY_NONE || security == SECURITY_OWE
                || security == SECURITY_OWE_TRANSITION;
    }

    /**
     * Callbacks relaying changes to the AccessPoint representation.
     *
+23 −1
Original line number Diff line number Diff line
@@ -94,7 +94,7 @@ public class AccessPointTest {
            new RssiCurve(-150, 10, new byte[]{Speed.FAST});
    public static final String TEST_BSSID = "00:00:00:00:00:00";
    private static final long MAX_SCORE_CACHE_AGE_MILLIS =
            20 * DateUtils.MINUTE_IN_MILLIS;;
            20 * DateUtils.MINUTE_IN_MILLIS;

    private Context mContext;
    private WifiInfo mWifiInfo;
@@ -1522,4 +1522,26 @@ public class AccessPointTest {

        verify(mMockConnectListener).onFailure(anyInt());
    }

    /**
     * Verifies that isOpenNetwork returns true for SECURITY_NONE, SECURITY_OWE, and
     * SECURITY_OWE_TRANSITION.
     */
    @Test
    public void testIsOpenNetwork_returnValidResult() {
        final Bundle bundle = new Bundle();
        AccessPoint ap;

        for (int i = 0; i < AccessPoint.SECURITY_MAX_VAL; i++) {
            bundle.putInt("key_security", i);
            ap = new AccessPoint(InstrumentationRegistry.getTargetContext(), bundle);

            if (i == AccessPoint.SECURITY_NONE || i == AccessPoint.SECURITY_OWE
                    || i == AccessPoint.SECURITY_OWE_TRANSITION) {
                assertThat(ap.isOpenNetwork()).isTrue();
            } else {
                assertThat(ap.isOpenNetwork()).isFalse();
            }
        }
    }
}