Remove mContext from IpSecBaseTest

This commit removes the mContext from IpSecBaseTest, and replaces it
with InstrumentationRegistry.getContext().

Bug: 72950854
Test: Ran on devices, passing.
Merged-In: If6fa359825aa9d1f7d4c8d49aba7a34925c073ed
Change-Id: If6fa359825aa9d1f7d4c8d49aba7a34925c073ed
(cherry picked from commit 69760fb5b62ae0e36c2a88bb20502dead3d7589b)
This commit is contained in:
Benedict Wong
2019-05-20 11:58:26 -07:00
parent 2cb7034baf
commit d8a36dd745
2 changed files with 6 additions and 6 deletions

View File

@@ -76,11 +76,9 @@ public class IpSecBaseTest {
protected ConnectivityManager mCM; protected ConnectivityManager mCM;
protected IpSecManager mISM; protected IpSecManager mISM;
protected Context mContext;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
mContext = InstrumentationRegistry.getContext();
mISM = mISM =
(IpSecManager) (IpSecManager)
InstrumentationRegistry.getContext() InstrumentationRegistry.getContext()
@@ -475,7 +473,7 @@ public class IpSecBaseTest {
private IpSecTransform buildDefaultTransform(InetAddress localAddr) throws Exception { private IpSecTransform buildDefaultTransform(InetAddress localAddr) throws Exception {
try (IpSecManager.SecurityParameterIndex spi = try (IpSecManager.SecurityParameterIndex spi =
mISM.allocateSecurityParameterIndex(localAddr)) { mISM.allocateSecurityParameterIndex(localAddr)) {
return buildIpSecTransform(mContext, spi, null, localAddr); return buildIpSecTransform(InstrumentationRegistry.getContext(), spi, null, localAddr);
} }
} }

View File

@@ -41,6 +41,7 @@ import android.system.ErrnoException;
import android.system.Os; import android.system.Os;
import android.system.OsConstants; import android.system.OsConstants;
import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4; import androidx.test.runner.AndroidJUnit4;
import java.io.FileDescriptor; import java.io.FileDescriptor;
@@ -238,7 +239,7 @@ public class IpSecManagerTest extends IpSecBaseTest {
mISM.allocateSecurityParameterIndex(localAddr); mISM.allocateSecurityParameterIndex(localAddr);
IpSecTransform transform = IpSecTransform transform =
new IpSecTransform.Builder(mContext) new IpSecTransform.Builder(InstrumentationRegistry.getContext())
.setEncryption(new IpSecAlgorithm(IpSecAlgorithm.CRYPT_AES_CBC, CRYPT_KEY)) .setEncryption(new IpSecAlgorithm(IpSecAlgorithm.CRYPT_AES_CBC, CRYPT_KEY))
.setAuthentication( .setAuthentication(
new IpSecAlgorithm( new IpSecAlgorithm(
@@ -456,7 +457,8 @@ public class IpSecManagerTest extends IpSecBaseTest {
IpSecManager.SecurityParameterIndex spi = IpSecManager.SecurityParameterIndex spi =
mISM.allocateSecurityParameterIndex(local)) { mISM.allocateSecurityParameterIndex(local)) {
IpSecTransform.Builder transformBuilder = new IpSecTransform.Builder(mContext); IpSecTransform.Builder transformBuilder =
new IpSecTransform.Builder(InstrumentationRegistry.getContext());
if (crypt != null) { if (crypt != null) {
transformBuilder.setEncryption(crypt); transformBuilder.setEncryption(crypt);
} }
@@ -617,7 +619,7 @@ public class IpSecManagerTest extends IpSecBaseTest {
try (IpSecManager.SecurityParameterIndex spi = try (IpSecManager.SecurityParameterIndex spi =
mISM.allocateSecurityParameterIndex(local); mISM.allocateSecurityParameterIndex(local);
IpSecTransform transform = IpSecTransform transform =
new IpSecTransform.Builder(mContext) new IpSecTransform.Builder(InstrumentationRegistry.getContext())
.setEncryption(crypt) .setEncryption(crypt)
.setAuthentication(auth) .setAuthentication(auth)
.setIpv4Encapsulation(encapSocket, encapSocket.getPort()) .setIpv4Encapsulation(encapSocket, encapSocket.getPort())