MicrodroidTests: Fix presubmit

Flag guarded member should only be tested when flag is on.

Bug: 383901066
Change-Id: I3878f8ace73459f1ccd37e8d5eb7174c9f980b99
Test: T/H, atest MicrodroidTests
diff --git a/tests/testapk/Android.bp b/tests/testapk/Android.bp
index 01af51c..cb374a5 100644
--- a/tests/testapk/Android.bp
+++ b/tests/testapk/Android.bp
@@ -16,9 +16,11 @@
 java_defaults {
     name: "MicrodroidTestAppsDefaults",
     static_libs: [
+        "avf_aconfig_flags_java",
         "com.android.microdroid.testservice-java",
         "com.android.microdroid.test.vmshare_service-java",
         "com.android.virt.vm_attestation.testservice-java",
+        "platform-test-annotations",
     ],
     certificate: ":MicrodroidTestAppCert",
     sdk_version: "test_current",
diff --git a/tests/testapk/src/java/com/android/microdroid/test/MicrodroidTests.java b/tests/testapk/src/java/com/android/microdroid/test/MicrodroidTests.java
index b2e65bc..e69b8f6 100644
--- a/tests/testapk/src/java/com/android/microdroid/test/MicrodroidTests.java
+++ b/tests/testapk/src/java/com/android/microdroid/test/MicrodroidTests.java
@@ -25,6 +25,8 @@
 import static android.system.virtualmachine.VirtualMachineManager.CAPABILITY_NON_PROTECTED_VM;
 import static android.system.virtualmachine.VirtualMachineManager.CAPABILITY_PROTECTED_VM;
 
+import static com.android.system.virtualmachine.flags.Flags.promoteSetShouldUseHugepagesToSystemApi;
+
 import static com.google.common.truth.Truth.assertThat;
 import static com.google.common.truth.Truth.assertWithMessage;
 import static com.google.common.truth.TruthJUnit.assume;
@@ -52,6 +54,7 @@
 import android.os.ParcelFileDescriptor.AutoCloseInputStream;
 import android.os.ParcelFileDescriptor.AutoCloseOutputStream;
 import android.os.SystemProperties;
+import android.platform.test.annotations.RequiresFlagsEnabled;
 import android.system.OsConstants;
 import android.system.virtualmachine.VirtualMachine;
 import android.system.virtualmachine.VirtualMachineCallback;
@@ -69,6 +72,7 @@
 import com.android.microdroid.testservice.IAppCallback;
 import com.android.microdroid.testservice.ITestService;
 import com.android.microdroid.testservice.IVmCallback;
+import com.android.system.virtualmachine.flags.Flags;
 import com.android.virt.vm_attestation.testservice.IAttestationService.AttestationStatus;
 import com.android.virt.vm_attestation.testservice.IAttestationService.SigningResult;
 import com.android.virt.vm_attestation.util.X509Utils;
@@ -179,13 +183,15 @@
             throws Exception {
         assumeSupportedDevice();
 
-        VirtualMachineConfig config =
+        VirtualMachineConfig.Builder builder =
                 newVmConfigBuilderWithPayloadBinary("MicrodroidTestNativeLib.so")
                         .setMemoryBytes(minMemoryRequired())
                         .setDebugLevel(DEBUG_LEVEL_FULL)
-                        .setCpuTopology(cpuTopology)
-                        .setShouldUseHugepages(shouldUseHugepages)
-                        .build();
+                        .setCpuTopology(cpuTopology);
+        if (promoteSetShouldUseHugepagesToSystemApi()) {
+            builder.setShouldUseHugepages(shouldUseHugepages);
+        }
+        VirtualMachineConfig config = builder.build();
         VirtualMachine vm = forceCreateNewVirtualMachine("test_vm", config);
 
         TestResults testResults =
@@ -222,6 +228,7 @@
     }
 
     @Test
+    @RequiresFlagsEnabled(Flags.FLAG_PROMOTE_SET_SHOULD_USE_HUGEPAGES_TO_SYSTEM_API)
     public void createAndConnectToVm_WithHugepages() throws Exception {
         // Note: setting shouldUseHugepages to true only hints that VM wants to use transparent huge
         // pages. Whether it will actually be used depends on the value in the
@@ -231,6 +238,7 @@
     }
 
     @Test
+    @RequiresFlagsEnabled(Flags.FLAG_PROMOTE_SET_SHOULD_USE_HUGEPAGES_TO_SYSTEM_API)
     public void createAndConnectToVm_HostCpuTopology_WithHugepages() throws Exception {
         // Note: setting shouldUseHugepages to true only hints that VM wants to use transparent huge
         // pages. Whether it will actually be used depends on the value in the
@@ -599,7 +607,9 @@
         assertThat(minimal.getEncryptedStorageBytes()).isEqualTo(0);
         assertThat(minimal.isVmOutputCaptured()).isFalse();
         assertThat(minimal.getOs()).isEqualTo("microdroid");
-        assertThat(minimal.shouldUseHugepages()).isFalse();
+        if (promoteSetShouldUseHugepagesToSystemApi()) {
+            assertThat(minimal.shouldUseHugepages()).isFalse();
+        }
 
         // Maximal has everything that can be set to some non-default value. (And has different
         // values than minimal for the required fields.)
@@ -615,8 +625,10 @@
                         .setCpuTopology(CPU_TOPOLOGY_MATCH_HOST)
                         .setEncryptedStorageBytes(1_000_000)
                         .setVmOutputCaptured(true)
-                        .setOs("microdroid_gki-android14-6.1")
-                        .setShouldUseHugepages(true);
+                        .setOs("microdroid_gki-android14-6.1");
+        if (promoteSetShouldUseHugepagesToSystemApi()) {
+            maximalBuilder.setShouldUseHugepages(true);
+        }
         VirtualMachineConfig maximal = maximalBuilder.build();
 
         assertThat(maximal.getApkPath()).isEqualTo("/apk/path");
@@ -633,7 +645,9 @@
         assertThat(maximal.getEncryptedStorageBytes()).isEqualTo(1_000_000);
         assertThat(maximal.isVmOutputCaptured()).isTrue();
         assertThat(maximal.getOs()).isEqualTo("microdroid_gki-android14-6.1");
-        assertThat(maximal.shouldUseHugepages()).isTrue();
+        if (promoteSetShouldUseHugepagesToSystemApi()) {
+            assertThat(maximal.shouldUseHugepages()).isTrue();
+        }
 
         assertThat(minimal.isCompatibleWith(maximal)).isFalse();
         assertThat(minimal.isCompatibleWith(minimal)).isTrue();
@@ -703,7 +717,10 @@
         assertConfigCompatible(
                         baseline, newBaselineBuilder().setCpuTopology(CPU_TOPOLOGY_MATCH_HOST))
                 .isTrue();
-        assertConfigCompatible(baseline, newBaselineBuilder().setShouldUseHugepages(true)).isTrue();
+        if (promoteSetShouldUseHugepagesToSystemApi()) {
+            assertConfigCompatible(baseline, newBaselineBuilder().setShouldUseHugepages(true))
+                    .isTrue();
+        }
 
         // Changes that must be incompatible, since they must change the VM identity.
         assertConfigCompatible(baseline, newBaselineBuilder().addExtraApk("foo")).isFalse();