Use app context when getting virtual machine manager.
Bug: 359439878
Test: run ferrochrome
Change-Id: I88860f556692bc2c213e2bf2fc03a6d18ed211e4
diff --git a/android/VmLauncherApp/java/com/android/virtualization/vmlauncher/Runner.java b/android/VmLauncherApp/java/com/android/virtualization/vmlauncher/Runner.java
index f50ec86..a5f58fe 100644
--- a/android/VmLauncherApp/java/com/android/virtualization/vmlauncher/Runner.java
+++ b/android/VmLauncherApp/java/com/android/virtualization/vmlauncher/Runner.java
@@ -42,7 +42,10 @@
/** Create a virtual machine of the given config, under the given context. */
static Runner create(Context context, VirtualMachineConfig config)
throws VirtualMachineException {
- VirtualMachineManager vmm = context.getSystemService(VirtualMachineManager.class);
+ // context may already be the app context, but calling this again is not harmful.
+ // See b/359439878 on why vmm should be obtained from the app context.
+ Context appContext = context.getApplicationContext();
+ VirtualMachineManager vmm = appContext.getSystemService(VirtualMachineManager.class);
VirtualMachineCustomImageConfig customConfig = config.getCustomImageConfig();
if (customConfig == null) {
throw new RuntimeException("CustomImageConfig is missing");