Loading core/java/android/app/SystemServiceRegistry.java +34 −2 Original line number Diff line number Diff line Loading @@ -66,6 +66,8 @@ import android.companion.ICompanionDeviceManager; import android.companion.virtual.IVirtualDeviceManager; import android.companion.virtual.VirtualDeviceManager; import android.compat.Compatibility; import android.compat.annotation.ChangeId; import android.compat.annotation.EnabledSince; import android.content.ClipboardManager; import android.content.ContentCaptureOptions; import android.content.Context; Loading Loading @@ -196,6 +198,7 @@ import android.os.ServiceManager; import android.os.ServiceManager.ServiceNotFoundException; import android.os.StatsFrameworkInitializer; import android.os.SystemConfigManager; import android.os.SystemProperties; import android.os.SystemUpdateManager; import android.os.SystemVibrator; import android.os.SystemVibratorManager; Loading Loading @@ -285,6 +288,18 @@ public final class SystemServiceRegistry { /** @hide */ public static boolean sEnableServiceNotFoundWtf = false; /** * Starting with {@link VANILLA_ICE_CREAM}, Telephony feature flags * (e.g. {@link PackageManager#FEATURE_TELEPHONY_SUBSCRIPTION}) are being checked before * returning managers that depend on them. If the feature is missing, * {@link Context#getSystemService} will return null. * * This change is specific to VcnManager. */ @ChangeId @EnabledSince(targetSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM) static final long ENABLE_CHECKING_TELEPHONY_FEATURES_FOR_VCN = 330902016; // Service registry information. // This information is never changed once static initialization has completed. private static final Map<Class<?>, String> SYSTEM_SERVICE_NAMES = Loading Loading @@ -450,7 +465,8 @@ public final class SystemServiceRegistry { new CachedServiceFetcher<VcnManager>() { @Override public VcnManager createService(ContextImpl ctx) throws ServiceNotFoundException { if (!ctx.getPackageManager().hasSystemFeature( if (shouldCheckTelephonyFeatures() && !ctx.getPackageManager().hasSystemFeature( PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION)) { return null; } Loading Loading @@ -1748,6 +1764,22 @@ public final class SystemServiceRegistry { return manager.hasSystemFeature(featureName); } // Suppressing AndroidFrameworkCompatChange because we're querying vendor // partition SDK level, not application's target SDK version (which BTW we // also check through Compatibility framework a few lines below). @SuppressWarnings("AndroidFrameworkCompatChange") private static boolean shouldCheckTelephonyFeatures() { // Check SDK version of the vendor partition. Pre-V devices might have // incorrectly under-declared telephony features. final int vendorApiLevel = SystemProperties.getInt( "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT); if (vendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) return false; // Check SDK version of the client app. Apps targeting pre-V SDK might // have not checked for existence of these features. return Compatibility.isChangeEnabled(ENABLE_CHECKING_TELEPHONY_FEATURES_FOR_VCN); } /** * Gets a system service from a given context. * @hide Loading Loading
core/java/android/app/SystemServiceRegistry.java +34 −2 Original line number Diff line number Diff line Loading @@ -66,6 +66,8 @@ import android.companion.ICompanionDeviceManager; import android.companion.virtual.IVirtualDeviceManager; import android.companion.virtual.VirtualDeviceManager; import android.compat.Compatibility; import android.compat.annotation.ChangeId; import android.compat.annotation.EnabledSince; import android.content.ClipboardManager; import android.content.ContentCaptureOptions; import android.content.Context; Loading Loading @@ -196,6 +198,7 @@ import android.os.ServiceManager; import android.os.ServiceManager.ServiceNotFoundException; import android.os.StatsFrameworkInitializer; import android.os.SystemConfigManager; import android.os.SystemProperties; import android.os.SystemUpdateManager; import android.os.SystemVibrator; import android.os.SystemVibratorManager; Loading Loading @@ -285,6 +288,18 @@ public final class SystemServiceRegistry { /** @hide */ public static boolean sEnableServiceNotFoundWtf = false; /** * Starting with {@link VANILLA_ICE_CREAM}, Telephony feature flags * (e.g. {@link PackageManager#FEATURE_TELEPHONY_SUBSCRIPTION}) are being checked before * returning managers that depend on them. If the feature is missing, * {@link Context#getSystemService} will return null. * * This change is specific to VcnManager. */ @ChangeId @EnabledSince(targetSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM) static final long ENABLE_CHECKING_TELEPHONY_FEATURES_FOR_VCN = 330902016; // Service registry information. // This information is never changed once static initialization has completed. private static final Map<Class<?>, String> SYSTEM_SERVICE_NAMES = Loading Loading @@ -450,7 +465,8 @@ public final class SystemServiceRegistry { new CachedServiceFetcher<VcnManager>() { @Override public VcnManager createService(ContextImpl ctx) throws ServiceNotFoundException { if (!ctx.getPackageManager().hasSystemFeature( if (shouldCheckTelephonyFeatures() && !ctx.getPackageManager().hasSystemFeature( PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION)) { return null; } Loading Loading @@ -1748,6 +1764,22 @@ public final class SystemServiceRegistry { return manager.hasSystemFeature(featureName); } // Suppressing AndroidFrameworkCompatChange because we're querying vendor // partition SDK level, not application's target SDK version (which BTW we // also check through Compatibility framework a few lines below). @SuppressWarnings("AndroidFrameworkCompatChange") private static boolean shouldCheckTelephonyFeatures() { // Check SDK version of the vendor partition. Pre-V devices might have // incorrectly under-declared telephony features. final int vendorApiLevel = SystemProperties.getInt( "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT); if (vendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) return false; // Check SDK version of the client app. Apps targeting pre-V SDK might // have not checked for existence of these features. return Compatibility.isChangeEnabled(ENABLE_CHECKING_TELEPHONY_FEATURES_FOR_VCN); } /** * Gets a system service from a given context. * @hide Loading