Copy IpSecConfig when IpSecTransforms are created

This change prevents IpSecTransforms from being inadvertently modified
by changes to the IpSecConfig. Specifically, once the transform is
created, it takes a copy of the config, rather than a reference.

Bug: 69385347
Test: New tests added, and all test passing
Change-Id: I89b8660c175ca20aa70352dcda893434ff7fd42b
This commit is contained in:
Benedict Wong
2018-02-06 20:43:21 -08:00
parent 025aae1fc9
commit e5623e2b61
2 changed files with 35 additions and 2 deletions

View File

@@ -218,6 +218,25 @@ public final class IpSecConfig implements Parcelable {
@VisibleForTesting
public IpSecConfig() {}
/** Copy constructor */
@VisibleForTesting
public IpSecConfig(IpSecConfig c) {
mMode = c.mMode;
mSourceAddress = c.mSourceAddress;
mDestinationAddress = c.mDestinationAddress;
mNetwork = c.mNetwork;
mSpiResourceId = c.mSpiResourceId;
mEncryption = c.mEncryption;
mAuthentication = c.mAuthentication;
mAuthenticatedEncryption = c.mAuthenticatedEncryption;
mEncapType = c.mEncapType;
mEncapSocketResourceId = c.mEncapSocketResourceId;
mEncapRemotePort = c.mEncapRemotePort;
mNattKeepaliveInterval = c.mNattKeepaliveInterval;
mMarkValue = c.mMarkValue;
mMarkMask = c.mMarkMask;
}
private IpSecConfig(Parcel in) {
mMode = in.readInt();
mSourceAddress = in.readString();

View File

@@ -84,9 +84,11 @@ public final class IpSecTransform implements AutoCloseable {
@Retention(RetentionPolicy.SOURCE)
public @interface EncapType {}
private IpSecTransform(Context context, IpSecConfig config) {
/** @hide */
@VisibleForTesting
public IpSecTransform(Context context, IpSecConfig config) {
mContext = context;
mConfig = config;
mConfig = new IpSecConfig(config);
mResourceId = INVALID_RESOURCE_ID;
}
@@ -142,6 +144,18 @@ public final class IpSecTransform implements AutoCloseable {
return this;
}
/**
* Equals method used for testing
*
* @hide
*/
@VisibleForTesting
public static boolean equals(IpSecTransform lhs, IpSecTransform rhs) {
if (lhs == null || rhs == null) return (lhs == rhs);
return IpSecConfig.equals(lhs.getConfig(), rhs.getConfig())
&& lhs.mResourceId == rhs.mResourceId;
}
/**
* Deactivate this {@code IpSecTransform} and free allocated resources.
*