Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0356befc authored by Nathan Harold's avatar Nathan Harold Committed by Yan Yan
Browse files

Return a null VCN when the dependencies aren't met

Update the check to return a null for the VcnManager
when the dependencies aren't met.
1) For compat reasons, always return a nonnull VcnManager
   to apps targeting a pre-V SDK.
2) For devices that have pre-V feature flags, return null only
   if FEATURE_TELEPHONY is null.
3) For V+ feature flagged devices, instead check
   FEATURE_TELEPHONY_SUBSCRIPTION.

Bug: 334750038
Test: atest CtsVcnTestCases
Change-Id: I116095bcb2203f8e684e7b735bfe414d6dd459e2
parent 71e98529
Loading
Loading
Loading
Loading
+27 −8
Original line number Diff line number Diff line
@@ -300,6 +300,16 @@ public final class SystemServiceRegistry {
    @EnabledSince(targetSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM)
    static final long ENABLE_CHECKING_TELEPHONY_FEATURES_FOR_VCN = 330902016;

    /**
     * The corresponding vendor API for Android V
     *
     * <p>Starting with Android V, the vendor API format has switched to YYYYMM.
     *
     * @see <a href="https://preview.source.android.com/docs/core/architecture/api-flags">Vendor API
     *     level</a>
     */
    private static final int VENDOR_API_FOR_ANDROID_V = 202404;

    // Service registry information.
    // This information is never changed once static initialization has completed.
    private static final Map<Class<?>, String> SYSTEM_SERVICE_NAMES =
@@ -465,9 +475,10 @@ public final class SystemServiceRegistry {
                new CachedServiceFetcher<VcnManager>() {
            @Override
            public VcnManager createService(ContextImpl ctx) throws ServiceNotFoundException {
                if (shouldCheckTelephonyFeatures()
                    && !ctx.getPackageManager().hasSystemFeature(
                            PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION)) {
                final String telephonyFeatureToCheck = getVcnFeatureDependency();

                if (telephonyFeatureToCheck != null
                    && !ctx.getPackageManager().hasSystemFeature(telephonyFeatureToCheck)) {
                    return null;
                }

@@ -1768,16 +1779,24 @@ public final class SystemServiceRegistry {
    // 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() {
    @Nullable
    private static String getVcnFeatureDependency() {
        // Check SDK version of the client app. Apps targeting pre-V SDK might
        // have not checked for existence of these features.
        if (!Compatibility.isChangeEnabled(ENABLE_CHECKING_TELEPHONY_FEATURES_FOR_VCN)) {
            return null;
        }

        // 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;
        if (vendorApiLevel < VENDOR_API_FOR_ANDROID_V) {
            return PackageManager.FEATURE_TELEPHONY;
        } else {
            return PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION;
        }

        // 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);
    }

    /**