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

Commit de47626a authored by Cyril Lee's avatar Cyril Lee
Browse files

Added isOpenNetwork determine connect to an open network or not

Combine SECURITY_NONE, SECURITY_OWE, and SECURITY_OWE_TRANSITION
condition to public API

Test: atest AccessPointTest
Change-Id: I098d0b541997cd3f186d10fc8bbbc515f6237b32
parent ba3fc162
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -1185,8 +1185,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)
@@ -1672,6 +1671,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();
            }
        }
    }
}