From 167b913ad48e23453c1bb20817c6b6dc63fca25c Mon Sep 17 00:00:00 2001 From: Nikita Ioffe Date: Wed, 16 Nov 2022 15:56:02 +0000 Subject: [PATCH] Register managers provided by the com.android.virt APEX This allows apps to retrieve an instance of VirtualMachineManager via Context.getSystemService() API. Bug: 249093790 Test: builds Test: atest --test-mapping packages/modules/Virtualization:avf-presubmit Change-Id: I488c275343753f2a3af6270cbad2ab02f33f203f --- core/api/system-current.txt | 1 + core/java/android/app/SystemServiceRegistry.java | 2 ++ core/java/android/content/Context.java | 15 +++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/core/api/system-current.txt b/core/api/system-current.txt index fe66952ab3f95..ec2689960a0f7 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -3146,6 +3146,7 @@ package android.content { field public static final String TRANSLATION_MANAGER_SERVICE = "translation"; field public static final String UI_TRANSLATION_SERVICE = "ui_translation"; field public static final String UWB_SERVICE = "uwb"; + field public static final String VIRTUALIZATION_SERVICE = "virtualization"; field public static final String VR_SERVICE = "vrmanager"; field public static final String WALLPAPER_EFFECTS_GENERATION_SERVICE = "wallpaper_effects_generation"; field public static final String WEARABLE_SENSING_SERVICE = "wearable_sensing"; diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java index 68579840d3394..e54a0841dd26f 100644 --- a/core/java/android/app/SystemServiceRegistry.java +++ b/core/java/android/app/SystemServiceRegistry.java @@ -210,6 +210,7 @@ import android.service.oemlock.OemLockManager; import android.service.persistentdata.IPersistentDataBlockService; import android.service.persistentdata.PersistentDataBlockManager; import android.service.vr.IVrManager; +import android.system.virtualmachine.VirtualizationFrameworkInitializer; import android.telecom.TelecomManager; import android.telephony.MmsManager; import android.telephony.TelephonyFrameworkInitializer; @@ -1566,6 +1567,7 @@ public final class SystemServiceRegistry { NearbyFrameworkInitializer.registerServiceWrappers(); OnDevicePersonalizationFrameworkInitializer.registerServiceWrappers(); DeviceLockFrameworkInitializer.registerServiceWrappers(); + VirtualizationFrameworkInitializer.registerServiceWrappers(); } finally { // If any of the above code throws, we're in a pretty bad shape and the process // will likely crash, but we'll reset it just in case there's an exception handler... diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index 0b20078bdb5f3..fcdf4403902d7 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -3939,6 +3939,7 @@ public abstract class Context { DISPLAY_HASH_SERVICE, CREDENTIAL_SERVICE, DEVICE_LOCK_SERVICE, + VIRTUALIZATION_SERVICE, }) @Retention(RetentionPolicy.SOURCE) public @interface ServiceName {} @@ -6113,6 +6114,20 @@ public abstract class Context { */ public static final String DEVICE_LOCK_SERVICE = "device_lock"; + /** + * Use with {@link #getSystemService(String)} to retrieve a + * {@link android.system.virtualmachine.VirtualMachineManager}. + * + *

On devices without {@link PackageManager#FEATURE_VIRTUALIZATION_FRAMEWORK} system feature + * the {@link #getSystemService(String)} will return {@code null}. + * + * @see #getSystemService(String) + * @see android.system.virtualmachine.VirtualMachineManager + * @hide + */ + @SystemApi + public static final String VIRTUALIZATION_SERVICE = "virtualization"; + /** * Determine whether the given permission is allowed for a particular * process and user ID running in the system.