Merge "Remove requireNonNull check from matchesWifiNetworkKey"

This commit is contained in:
Junyu Lai
2023-03-09 09:13:40 +00:00
committed by Gerrit Code Review
4 changed files with 52 additions and 3 deletions

View File

@@ -32,6 +32,7 @@ import android.content.Context;
import android.net.wifi.WifiInfo;
import android.service.NetworkIdentityProto;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.util.proto.ProtoOutputStream;
import com.android.net.module.util.BitUtils;
@@ -406,10 +407,18 @@ public class NetworkIdentity {
setOemManaged(getOemBitfield(snapshot.getNetworkCapabilities()));
if (mType == TYPE_WIFI) {
final TransportInfo transportInfo = snapshot.getNetworkCapabilities()
.getTransportInfo();
final NetworkCapabilities nc = snapshot.getNetworkCapabilities();
final TransportInfo transportInfo = nc.getTransportInfo();
if (transportInfo instanceof WifiInfo) {
final WifiInfo info = (WifiInfo) transportInfo;
// Log.wtf to catch trying to set a null wifiNetworkKey into NetworkIdentity.
// See b/266598304. The problematic data that has null wifi network key is
// thrown out when storing data, which is handled by the service.
if (info.getNetworkKey() == null) {
Log.wtf(TAG, "WifiInfo contains a null wifiNetworkKey and it will"
+ " be set into NetworkIdentity, netId=" + snapshot.getNetwork()
+ "NetworkCapabilities=" + nc);
}
setWifiNetworkKey(info.getNetworkKey());
}
} else if (mType == TYPE_TEST) {

View File

@@ -700,7 +700,15 @@ public final class NetworkTemplate implements Parcelable {
* to know details about the key.
*/
private boolean matchesWifiNetworkKey(@NonNull String wifiNetworkKey) {
Objects.requireNonNull(wifiNetworkKey);
// Note that this code accepts null wifi network keys because of a past bug where wifi
// code was sending a null network key for some connected networks, which isn't expected
// and ended up stored in the data on many devices.
// A null network key in the data matches a wildcard template (one where
// {@code mMatchWifiNetworkKeys} is empty), but not one where {@code MatchWifiNetworkKeys}
// contains null. See b/266598304.
if (wifiNetworkKey == null) {
return CollectionUtils.isEmpty(mMatchWifiNetworkKeys);
}
return CollectionUtils.isEmpty(mMatchWifiNetworkKeys)
|| CollectionUtils.contains(mMatchWifiNetworkKeys, wifiNetworkKey);
}