Pass TestInformation directly to DeviceContext and fix setenforce
problem.

TestInformation can be retrieved with getTestInformation in individual
tests.

Also remove a leftover setenforce call that was missed in
https://r.android.com/2239933. This uncovered a problem where
remountSystemWritable() could reboot the device back to enforcing state
after DisableSELinuxTargetPreparer, so move the remount too to a
preparer.

Test: atest libnativeloader_e2e_tests
Bug: 137356719
Change-Id: I2ac05e162230717fb1d2f75efaf9e22f2c23f863
diff --git a/libnativeloader/test/libnativeloader_e2e_tests.xml b/libnativeloader/test/libnativeloader_e2e_tests.xml
index f121dca..5d0d380 100644
--- a/libnativeloader/test/libnativeloader_e2e_tests.xml
+++ b/libnativeloader/test/libnativeloader_e2e_tests.xml
@@ -19,6 +19,15 @@
 
     <target_preparer class="com.android.tradefed.targetprep.RootTargetPreparer" />
 
+    <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
+        <!-- We push all files in LibnativeloaderTest.java, but use this
+             preparer to make partitions writable. That since remounting may
+             require a device reboot, and then it's important that the
+             `setenforce 0` from DisableSELinuxTargetPreparer occurs after that. -->
+        <option name="remount-system" value="true" />
+        <option name="remount-vendor" value="true" />
+    </target_preparer>
+
     <!-- Vendor native libraries aren't accessible by any apps by sepolicy
          rules. For that they need to be labelled same_process_hal_file in a
          vendor specific file_contexts file (see
diff --git a/libnativeloader/test/src/android/test/hostside/LibnativeloaderTest.java b/libnativeloader/test/src/android/test/hostside/LibnativeloaderTest.java
index 3e96df2..5ba96cc 100644
--- a/libnativeloader/test/src/android/test/hostside/LibnativeloaderTest.java
+++ b/libnativeloader/test/src/android/test/hostside/LibnativeloaderTest.java
@@ -56,13 +56,10 @@
 
     @BeforeClassWithInfo
     public static void beforeClassWithDevice(TestInformation testInfo) throws Exception {
-        DeviceContext ctx = new DeviceContext(
-                testInfo.getContext(), testInfo.getDevice(), testInfo.getBuildInfo());
+        DeviceContext ctx = new DeviceContext(testInfo);
 
         // A soft reboot is slow, so do setup for all tests and reboot once.
 
-        ctx.mDevice.remountSystemWritable();
-
         File libContainerApk = ctx.mBuildHelper.getTestFile("library_container_app.apk");
         try (ZipFile libApk = new ZipFile(libContainerApk)) {
             ctx.pushExtendedPublicSystemOemLibs(libApk);
@@ -102,15 +99,13 @@
 
         // For testDataApp. Install this the normal way after the system server restart.
         ctx.installPackage("loadlibrarytest_data_app");
-        ctx.assertCommandSucceeds("setenforce 0");
 
         testInfo.properties().put(CLEANUP_PATHS_KEY, ctx.mCleanup.getPathList());
     }
 
     @AfterClassWithInfo
     public static void afterClassWithDevice(TestInformation testInfo) throws Exception {
-        DeviceContext ctx = new DeviceContext(
-                testInfo.getContext(), testInfo.getDevice(), testInfo.getBuildInfo());
+        DeviceContext ctx = new DeviceContext(testInfo);
 
         // Uninstall loadlibrarytest_data_app.
         ctx.mDevice.uninstallPackage("android.test.app.data");
@@ -205,10 +200,10 @@
         CleanupPaths mCleanup;
         private String mTestArch;
 
-        DeviceContext(IInvocationContext context, ITestDevice device, IBuildInfo buildInfo) {
-            mContext = context;
-            mDevice = device;
-            mBuildHelper = new CompatibilityBuildHelper(buildInfo);
+        DeviceContext(TestInformation testInfo) {
+            mContext = testInfo.getContext();
+            mDevice = testInfo.getDevice();
+            mBuildHelper = new CompatibilityBuildHelper(testInfo.getBuildInfo());
             mCleanup = new CleanupPaths(mDevice);
         }