| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.net.vcn; |
| 18 |
|
| 19 |
import static android.net.NetworkCapabilities.REDACT_FOR_NETWORK_SETTINGS; |
| 20 |
import static android.net.vcn.VcnGatewayConnectionConfig.MIN_UDP_PORT_4500_NAT_TIMEOUT_UNSET; |
| 21 |
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
| 22 |
|
| 23 |
import android.annotation.NonNull; |
| 24 |
import android.annotation.Nullable; |
| 25 |
import android.net.NetworkCapabilities; |
| 26 |
import android.net.TransportInfo; |
| 27 |
import android.net.wifi.WifiInfo; |
| 28 |
import android.os.Parcel; |
| 29 |
import android.os.Parcelable; |
| 30 |
import android.telephony.SubscriptionManager; |
| 31 |
|
| 32 |
import java.util.Objects; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public class VcnTransportInfo implements TransportInfo, Parcelable { |
| 51 |
@Nullable private final WifiInfo mWifiInfo; |
| 52 |
private final int mSubId; |
| 53 |
private final int mMinUdpPort4500NatTimeoutSeconds; |
| 54 |
|
| 55 |
public VcnTransportInfo(@NonNull WifiInfo wifiInfo) { |
| 56 |
this(wifiInfo, INVALID_SUBSCRIPTION_ID, MIN_UDP_PORT_4500_NAT_TIMEOUT_UNSET); |
| 57 |
} |
| 58 |
|
| 59 |
public VcnTransportInfo(@NonNull WifiInfo wifiInfo, int minUdpPort4500NatTimeoutSeconds) { |
| 60 |
this(wifiInfo, INVALID_SUBSCRIPTION_ID, minUdpPort4500NatTimeoutSeconds); |
| 61 |
} |
| 62 |
|
| 63 |
public VcnTransportInfo(int subId) { |
| 64 |
this(null , subId, MIN_UDP_PORT_4500_NAT_TIMEOUT_UNSET); |
| 65 |
} |
| 66 |
|
| 67 |
public VcnTransportInfo(int subId, int minUdpPort4500NatTimeoutSeconds) { |
| 68 |
this(null , subId, minUdpPort4500NatTimeoutSeconds); |
| 69 |
} |
| 70 |
|
| 71 |
private VcnTransportInfo( |
| 72 |
@Nullable WifiInfo wifiInfo, int subId, int minUdpPort4500NatTimeoutSeconds) { |
| 73 |
mWifiInfo = wifiInfo; |
| 74 |
mSubId = subId; |
| 75 |
mMinUdpPort4500NatTimeoutSeconds = minUdpPort4500NatTimeoutSeconds; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
@Nullable |
| 86 |
public WifiInfo getWifiInfo() { |
| 87 |
return mWifiInfo; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
public int getSubId() { |
| 100 |
return mSubId; |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
public int getMinUdpPort4500NatTimeoutSeconds() { |
| 110 |
return mMinUdpPort4500NatTimeoutSeconds; |
| 111 |
} |
| 112 |
|
| 113 |
@Override |
| 114 |
public int hashCode() { |
| 115 |
return Objects.hash(mWifiInfo, mSubId, mMinUdpPort4500NatTimeoutSeconds); |
| 116 |
} |
| 117 |
|
| 118 |
@Override |
| 119 |
public boolean equals(Object o) { |
| 120 |
if (!(o instanceof VcnTransportInfo)) return false; |
| 121 |
final VcnTransportInfo that = (VcnTransportInfo) o; |
| 122 |
return Objects.equals(mWifiInfo, that.mWifiInfo) |
| 123 |
&& mSubId == that.mSubId |
| 124 |
&& mMinUdpPort4500NatTimeoutSeconds == that.mMinUdpPort4500NatTimeoutSeconds; |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
@Override |
| 129 |
public int describeContents() { |
| 130 |
return 0; |
| 131 |
} |
| 132 |
|
| 133 |
@Override |
| 134 |
@NonNull |
| 135 |
public TransportInfo makeCopy(long redactions) { |
| 136 |
if ((redactions & NetworkCapabilities.REDACT_FOR_NETWORK_SETTINGS) != 0) { |
| 137 |
return new VcnTransportInfo( |
| 138 |
null, INVALID_SUBSCRIPTION_ID, MIN_UDP_PORT_4500_NAT_TIMEOUT_UNSET); |
| 139 |
} |
| 140 |
|
| 141 |
return new VcnTransportInfo( |
| 142 |
(mWifiInfo == null) ? null : mWifiInfo.makeCopy(redactions), |
| 143 |
mSubId, |
| 144 |
mMinUdpPort4500NatTimeoutSeconds); |
| 145 |
} |
| 146 |
|
| 147 |
@Override |
| 148 |
public long getApplicableRedactions() { |
| 149 |
long redactions = REDACT_FOR_NETWORK_SETTINGS; |
| 150 |
|
| 151 |
|
| 152 |
if (mWifiInfo != null) { |
| 153 |
redactions |= mWifiInfo.getApplicableRedactions(); |
| 154 |
} |
| 155 |
|
| 156 |
return redactions; |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
@Override |
| 161 |
public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 162 |
dest.writeInt(mSubId); |
| 163 |
dest.writeParcelable(mWifiInfo, flags); |
| 164 |
dest.writeInt(mMinUdpPort4500NatTimeoutSeconds); |
| 165 |
} |
| 166 |
|
| 167 |
@Override |
| 168 |
public String toString() { |
| 169 |
return "VcnTransportInfo { mWifiInfo = " + mWifiInfo + ", mSubId = " + mSubId + " }"; |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
public static final @NonNull Creator<VcnTransportInfo> CREATOR = |
| 174 |
new Creator<VcnTransportInfo>() { |
| 175 |
public VcnTransportInfo createFromParcel(Parcel in) { |
| 176 |
final int subId = in.readInt(); |
| 177 |
final WifiInfo wifiInfo = |
| 178 |
in.readParcelable(null, android.net.wifi.WifiInfo.class); |
| 179 |
final int minUdpPort4500NatTimeoutSeconds = in.readInt(); |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
if (wifiInfo == null |
| 185 |
&& subId == INVALID_SUBSCRIPTION_ID |
| 186 |
&& minUdpPort4500NatTimeoutSeconds |
| 187 |
== MIN_UDP_PORT_4500_NAT_TIMEOUT_UNSET) { |
| 188 |
return null; |
| 189 |
} |
| 190 |
|
| 191 |
return new VcnTransportInfo(wifiInfo, subId, minUdpPort4500NatTimeoutSeconds); |
| 192 |
} |
| 193 |
|
| 194 |
public VcnTransportInfo[] newArray(int size) { |
| 195 |
return new VcnTransportInfo[size]; |
| 196 |
} |
| 197 |
}; |
| 198 |
} |