Throw exception if VM type is not supported.
Check system properties in the Java client library to determine if
protected or unprotected VMs are supported, and throw an exception if a
client tries to build a VirtualMachineConfig for an unsupported VM type.
Test: mm
Change-Id: Iaef294118ba6af656b5ef58f85ca133335f21834
diff --git a/javalib/src/android/system/virtualmachine/VirtualMachineConfig.java b/javalib/src/android/system/virtualmachine/VirtualMachineConfig.java
index 35d600a..3a2d581 100644
--- a/javalib/src/android/system/virtualmachine/VirtualMachineConfig.java
+++ b/javalib/src/android/system/virtualmachine/VirtualMachineConfig.java
@@ -24,6 +24,7 @@
import android.content.pm.Signature; // This actually is certificate!
import android.os.ParcelFileDescriptor;
import android.os.PersistableBundle;
+import android.sysprop.HypervisorProperties;
import android.system.virtualizationservice.VirtualMachineAppConfig;
import java.io.File;
@@ -330,6 +331,16 @@
+ " is invalid");
}
+ if (mProtectedVm
+ && !HypervisorProperties.hypervisor_protected_vm_supported().orElse(false)) {
+ throw new UnsupportedOperationException(
+ "Protected VMs are not supported on this device.");
+ }
+ if (!mProtectedVm && !HypervisorProperties.hypervisor_vm_supported().orElse(false)) {
+ throw new UnsupportedOperationException(
+ "Unprotected VMs are not supported on this device.");
+ }
+
return new VirtualMachineConfig(
apkPath, certs, mPayloadConfigPath, mDebugLevel, mProtectedVm, mMemoryMib,
mNumCpus, mCpuAffinity);