Merge "Use app context when getting virtual machine manager." into main am: 49bddf23db
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Virtualization/+/3216218
Change-Id: I876bdcd6a40cb73750389cfb370eaa48be2bbf0d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
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");