Merge "Add session ID to VpnTransportInfo"
This commit is contained in:
@@ -176,10 +176,12 @@ package android.net {
|
||||
}
|
||||
|
||||
public final class VpnTransportInfo implements android.os.Parcelable android.net.TransportInfo {
|
||||
ctor public VpnTransportInfo(int);
|
||||
ctor public VpnTransportInfo(int, @Nullable String);
|
||||
method public int describeContents();
|
||||
method @NonNull public android.net.VpnTransportInfo makeCopy(long);
|
||||
method public void writeToParcel(@NonNull android.os.Parcel, int);
|
||||
field @NonNull public static final android.os.Parcelable.Creator<android.net.VpnTransportInfo> CREATOR;
|
||||
field @Nullable public final String sessionId;
|
||||
field public final int type;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,11 +17,14 @@
|
||||
package android.net;
|
||||
|
||||
import static android.annotation.SystemApi.Client.MODULE_LIBRARIES;
|
||||
import static android.net.NetworkCapabilities.REDACT_FOR_NETWORK_SETTINGS;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.SystemApi;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -38,8 +41,26 @@ public final class VpnTransportInfo implements TransportInfo, Parcelable {
|
||||
/** Type of this VPN. */
|
||||
public final int type;
|
||||
|
||||
public VpnTransportInfo(int type) {
|
||||
@Nullable
|
||||
public final String sessionId;
|
||||
|
||||
@Override
|
||||
public long getApplicableRedactions() {
|
||||
return REDACT_FOR_NETWORK_SETTINGS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a copy of a {@link VpnTransportInfo} with the sessionId redacted if necessary.
|
||||
*/
|
||||
@NonNull
|
||||
public VpnTransportInfo makeCopy(long redactions) {
|
||||
return new VpnTransportInfo(type,
|
||||
((redactions & REDACT_FOR_NETWORK_SETTINGS) != 0) ? null : sessionId);
|
||||
}
|
||||
|
||||
public VpnTransportInfo(int type, @Nullable String sessionId) {
|
||||
this.type = type;
|
||||
this.sessionId = sessionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,17 +68,17 @@ public final class VpnTransportInfo implements TransportInfo, Parcelable {
|
||||
if (!(o instanceof VpnTransportInfo)) return false;
|
||||
|
||||
VpnTransportInfo that = (VpnTransportInfo) o;
|
||||
return this.type == that.type;
|
||||
return (this.type == that.type) && TextUtils.equals(this.sessionId, that.sessionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(type);
|
||||
return Objects.hash(type, sessionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("VpnTransportInfo{type=%d}", type);
|
||||
return String.format("VpnTransportInfo{type=%d, sessionId=%s}", type, sessionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -68,12 +89,13 @@ public final class VpnTransportInfo implements TransportInfo, Parcelable {
|
||||
@Override
|
||||
public void writeToParcel(@NonNull Parcel dest, int flags) {
|
||||
dest.writeInt(type);
|
||||
dest.writeString(sessionId);
|
||||
}
|
||||
|
||||
public static final @NonNull Creator<VpnTransportInfo> CREATOR =
|
||||
new Creator<VpnTransportInfo>() {
|
||||
public VpnTransportInfo createFromParcel(Parcel in) {
|
||||
return new VpnTransportInfo(in.readInt());
|
||||
return new VpnTransportInfo(in.readInt(), in.readString());
|
||||
}
|
||||
public VpnTransportInfo[] newArray(int size) {
|
||||
return new VpnTransportInfo[size];
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package android.net;
|
||||
|
||||
import static android.net.NetworkCapabilities.REDACT_FOR_NETWORK_SETTINGS;
|
||||
import static android.net.NetworkCapabilities.REDACT_NONE;
|
||||
|
||||
import static com.android.testutils.ParcelUtils.assertParcelSane;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -33,23 +36,33 @@ public class VpnTransportInfoTest {
|
||||
|
||||
@Test
|
||||
public void testParceling() {
|
||||
VpnTransportInfo v = new VpnTransportInfo(VpnManager.TYPE_VPN_PLATFORM);
|
||||
assertParcelSane(v, 1 /* fieldCount */);
|
||||
VpnTransportInfo v = new VpnTransportInfo(VpnManager.TYPE_VPN_PLATFORM, "12345");
|
||||
assertParcelSane(v, 2 /* fieldCount */);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsAndHashCode() {
|
||||
VpnTransportInfo v1 = new VpnTransportInfo(VpnManager.TYPE_VPN_PLATFORM);
|
||||
VpnTransportInfo v2 = new VpnTransportInfo(VpnManager.TYPE_VPN_SERVICE);
|
||||
VpnTransportInfo v3 = new VpnTransportInfo(VpnManager.TYPE_VPN_PLATFORM);
|
||||
VpnTransportInfo v4 = new VpnTransportInfo(VpnManager.TYPE_VPN_LEGACY);
|
||||
VpnTransportInfo v5 = new VpnTransportInfo(VpnManager.TYPE_VPN_OEM);
|
||||
String session1 = "12345";
|
||||
String session2 = "6789";
|
||||
VpnTransportInfo v11 = new VpnTransportInfo(VpnManager.TYPE_VPN_PLATFORM, session1);
|
||||
VpnTransportInfo v12 = new VpnTransportInfo(VpnManager.TYPE_VPN_SERVICE, session1);
|
||||
VpnTransportInfo v13 = new VpnTransportInfo(VpnManager.TYPE_VPN_PLATFORM, session1);
|
||||
VpnTransportInfo v14 = new VpnTransportInfo(VpnManager.TYPE_VPN_LEGACY, session1);
|
||||
VpnTransportInfo v15 = new VpnTransportInfo(VpnManager.TYPE_VPN_OEM, session1);
|
||||
VpnTransportInfo v21 = new VpnTransportInfo(VpnManager.TYPE_VPN_LEGACY, session2);
|
||||
|
||||
assertNotEquals(v1, v2);
|
||||
assertNotEquals(v3, v4);
|
||||
assertNotEquals(v4, v5);
|
||||
VpnTransportInfo v31 = v11.makeCopy(REDACT_FOR_NETWORK_SETTINGS);
|
||||
VpnTransportInfo v32 = v13.makeCopy(REDACT_FOR_NETWORK_SETTINGS);
|
||||
|
||||
assertEquals(v1, v3);
|
||||
assertEquals(v1.hashCode(), v3.hashCode());
|
||||
assertNotEquals(v11, v12);
|
||||
assertNotEquals(v13, v14);
|
||||
assertNotEquals(v14, v15);
|
||||
assertNotEquals(v14, v21);
|
||||
|
||||
assertEquals(v11, v13);
|
||||
assertEquals(v31, v32);
|
||||
assertEquals(v11.hashCode(), v13.hashCode());
|
||||
assertEquals(REDACT_FOR_NETWORK_SETTINGS, v32.getApplicableRedactions());
|
||||
assertEquals(session1, v15.makeCopy(REDACT_NONE).sessionId);
|
||||
}
|
||||
}
|
||||
@@ -1233,10 +1233,12 @@ public class ConnectivityServiceTest {
|
||||
if (mAgentRegistered) throw new IllegalStateException("already registered");
|
||||
updateState(NetworkInfo.DetailedState.CONNECTING, "registerAgent");
|
||||
mConfig = new VpnConfig();
|
||||
mConfig.session = "MySession12345";
|
||||
setUids(uids);
|
||||
if (!isAlwaysMetered) mNetworkCapabilities.addCapability(NET_CAPABILITY_NOT_METERED);
|
||||
mInterface = VPN_IFNAME;
|
||||
mNetworkCapabilities.setTransportInfo(new VpnTransportInfo(getActiveVpnType()));
|
||||
mNetworkCapabilities.setTransportInfo(new VpnTransportInfo(getActiveVpnType(),
|
||||
mConfig.session));
|
||||
mMockNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_VPN, lp,
|
||||
mNetworkCapabilities);
|
||||
mMockNetworkAgent.waitForIdle(TIMEOUT_MS);
|
||||
|
||||
Reference in New Issue
Block a user