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

Commit 703a233b authored by Sundeep Ghuman's avatar Sundeep Ghuman Committed by Android (Google) Code Review
Browse files

Merge "Updating network info state should return true." into oc-dev

parents 24f4743f 96a53579
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -998,9 +998,10 @@ public class AccessPoint implements Comparable<AccessPoint> {
            if (mRssi != info.getRssi()) {
                mRssi = info.getRssi();
                updated = true;
            } else if (mNetworkInfo.getDetailedState() != networkInfo.getDetailedState()) {
                updated = true;
            }
            mInfo = info;
            // TODO(b/37289220): compare NetworkInfo states and set updated = true if necessary
            mNetworkInfo = networkInfo;
        } else if (mInfo != null) {
            updated = true;
+51 −0
Original line number Diff line number Diff line
@@ -404,4 +404,55 @@ public class AccessPointTest {
        assertThat(ap.getPasspointFqdn()).isEqualTo(fqdn);
        assertThat(ap.getConfigName()).isEqualTo(providerFriendlyName);
    }

    @Test
    public void testUpdateNetworkInfo_returnsTrue() {
        int networkId = 123;
        int rssi = -55;
        WifiConfiguration config = new WifiConfiguration();
        config.networkId = networkId;
        WifiInfo wifiInfo = new WifiInfo();
        wifiInfo.setNetworkId(networkId);
        wifiInfo.setRssi(rssi);

        NetworkInfo networkInfo =
                new NetworkInfo(ConnectivityManager.TYPE_WIFI, 0 /* subtype */, "WIFI", "");
        networkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTING, "", "");

        AccessPoint ap = new TestAccessPointBuilder(mContext)
                .setNetworkInfo(networkInfo)
                .setNetworkId(networkId)
                .setRssi(rssi)
                .setWifiInfo(wifiInfo)
                .build();

        NetworkInfo newInfo = new NetworkInfo(networkInfo);
        newInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED, "", "");
        assertThat(ap.update(config, wifiInfo, newInfo)).isTrue();
    }

    @Test
    public void testUpdateNetworkInfoWithSameInfo_returnsFalse() {
        int networkId = 123;
        int rssi = -55;
        WifiConfiguration config = new WifiConfiguration();
        config.networkId = networkId;
        WifiInfo wifiInfo = new WifiInfo();
        wifiInfo.setNetworkId(networkId);
        wifiInfo.setRssi(rssi);

        NetworkInfo networkInfo =
                new NetworkInfo(ConnectivityManager.TYPE_WIFI, 0 /* subtype */, "WIFI", "");
        networkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTING, "", "");

        AccessPoint ap = new TestAccessPointBuilder(mContext)
                .setNetworkInfo(networkInfo)
                .setNetworkId(networkId)
                .setRssi(rssi)
                .setWifiInfo(wifiInfo)
                .build();

        NetworkInfo newInfo = new NetworkInfo(networkInfo); // same values
        assertThat(ap.update(config, wifiInfo, newInfo)).isFalse();
    }
}
+40 −15
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.os.Bundle;

/**
@@ -36,11 +37,13 @@ public class TestAccessPointBuilder {

    // set some sensible defaults
    private int mRssi = AccessPoint.UNREACHABLE_RSSI;
    private int networkId = WifiConfiguration.INVALID_NETWORK_ID;
    private int mNetworkId = WifiConfiguration.INVALID_NETWORK_ID;
    private String ssid = "TestSsid";
    private NetworkInfo mNetworkInfo = null;
    private String mFqdn = null;
    private String mProviderFriendlyName = null;
    private WifiConfiguration mWifiConfig;
    private WifiInfo mWifiInfo;

    Context mContext;

@@ -51,12 +54,13 @@ public class TestAccessPointBuilder {
    public AccessPoint build() {
        Bundle bundle = new Bundle();

        WifiConfiguration wifiConig = new WifiConfiguration();
        wifiConig.networkId = networkId;
        WifiConfiguration wifiConfig = new WifiConfiguration();
        wifiConfig.networkId = mNetworkId;

        bundle.putString(AccessPoint.KEY_SSID, ssid);
        bundle.putParcelable(AccessPoint.KEY_CONFIG, wifiConig);
        bundle.putParcelable(AccessPoint.KEY_CONFIG, wifiConfig);
        bundle.putParcelable(AccessPoint.KEY_NETWORKINFO, mNetworkInfo);
        bundle.putParcelable(AccessPoint.KEY_WIFIINFO, mWifiInfo);
        if (mFqdn != null) {
            bundle.putString(AccessPoint.KEY_FQDN, mFqdn);
        }
@@ -81,11 +85,6 @@ public class TestAccessPointBuilder {
        return this;
    }

    public TestAccessPointBuilder setRssi(int rssi) {
        mRssi = rssi;
        return this;
    }

    /**
     * Set the rssi based upon the desired signal level.
     *
@@ -106,6 +105,16 @@ public class TestAccessPointBuilder {
        return this;
    }

    public TestAccessPointBuilder setNetworkInfo(NetworkInfo info) {
        mNetworkInfo = info;
        return this;
    }

    public TestAccessPointBuilder setRssi(int rssi) {
        mRssi = rssi;
        return this;
    }

    /**
    * Set whether the AccessPoint is reachable.
    * Side effect: if the signal level was not previously set,
@@ -125,9 +134,9 @@ public class TestAccessPointBuilder {

    public TestAccessPointBuilder setSaved(boolean saved){
        if (saved) {
             networkId = 1;
             mNetworkId = 1;
        } else {
             networkId = WifiConfiguration.INVALID_NETWORK_ID;
             mNetworkId = WifiConfiguration.INVALID_NETWORK_ID;
        }
        return this;
    }
@@ -146,4 +155,20 @@ public class TestAccessPointBuilder {
        mProviderFriendlyName = friendlyName;
        return this;
    }

    public TestAccessPointBuilder setWifiInfo(WifiInfo info) {
        mWifiInfo = info;
        return this;
    }

    /**
     * Set the networkId in the WifiConfig.
     *
     * <p>Setting this to a value other than {@link WifiConfiguration#INVALID_NETWORK_ID} makes this
     * AccessPoint a saved network.
     */
    public TestAccessPointBuilder setNetworkId(int networkId) {
        mNetworkId = networkId;
        return this;
    }
}