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

Commit e59ba746 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix NPE on network forget from details page." into oc-dr1-dev

parents 161d6564 d911da3a
Loading
Loading
Loading
Loading
+4 −3
Original line number Original line Diff line number Diff line
@@ -1053,7 +1053,8 @@ public class AccessPoint implements Comparable<AccessPoint> {
    }
    }


    /** Attempt to update the AccessPoint and return true if an update occurred. */
    /** Attempt to update the AccessPoint and return true if an update occurred. */
    public boolean update(WifiConfiguration config, WifiInfo info, NetworkInfo networkInfo) {
    public boolean update(
            @Nullable WifiConfiguration config, WifiInfo info, NetworkInfo networkInfo) {
        boolean updated = false;
        boolean updated = false;
        final int oldLevel = getLevel();
        final int oldLevel = getLevel();
        if (info != null && isInfoForThisAccessPoint(config, info)) {
        if (info != null && isInfoForThisAccessPoint(config, info)) {
@@ -1088,9 +1089,9 @@ public class AccessPoint implements Comparable<AccessPoint> {
        return updated;
        return updated;
    }
    }


    void update(WifiConfiguration config) {
    void update(@Nullable WifiConfiguration config) {
        mConfig = config;
        mConfig = config;
        networkId = config.networkId;
        networkId = config != null ? config.networkId : WifiConfiguration.INVALID_NETWORK_ID;
        if (mAccessPointListener != null) {
        if (mAccessPointListener != null) {
            mAccessPointListener.onAccessPointChanged(this);
            mAccessPointListener.onAccessPointChanged(this);
        }
        }
+24 −0
Original line number Original line Diff line number Diff line
@@ -656,4 +656,28 @@ public class AccessPointTest {
        assertThat(ap.update(newConfig, wifiInfo, networkInfo)).isFalse();
        assertThat(ap.update(newConfig, wifiInfo, networkInfo)).isFalse();
        verify(mockListener).onAccessPointChanged(ap);
        verify(mockListener).onAccessPointChanged(ap);
    }
    }

    @Test
    public void testUpdateWithNullWifiConfiguration_doesNotThrowNPE() {
        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();

        ap.update(null, wifiInfo, networkInfo);
    }
}
}