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

Commit b15dc370 authored by Tomasz Wasilczyk's avatar Tomasz Wasilczyk
Browse files

Add sdk version check before skipping telephony managers initialization

Bug: 330583731
Test: ABTD
Change-Id: I0360114a5105823457f28788eaf7d910e40631ed
parent 5f9c22a9
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -18,8 +18,13 @@ package android.telephony;

import android.annotation.NonNull;
import android.app.SystemServiceRegistry;
import android.compat.Compatibility;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledSince;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.SystemProperties;
import android.os.TelephonyServiceManager;
import android.telephony.euicc.EuiccCardManager;
import android.telephony.euicc.EuiccManager;
@@ -40,6 +45,16 @@ public class TelephonyFrameworkInitializer {
    private TelephonyFrameworkInitializer() {
    }

    /**
     * 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.
     */
    @ChangeId
    @EnabledSince(targetSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM)
    static final long ENABLE_CHECKING_TELEPHONY_FEATURES = 330583731;

    private static volatile TelephonyServiceManager sTelephonyServiceManager;

    /**
@@ -57,8 +72,23 @@ public class TelephonyFrameworkInitializer {
        sTelephonyServiceManager = Preconditions.checkNotNull(telephonyServiceManager);
    }

    // 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 hasSystemFeature(Context context, String feature) {
        // Check release status of this change in behavior.
        if (!Flags.minimalTelephonyManagersConditionalOnFeatures()) return true;

        // Check SDK version of the vendor partition.
        final int vendorApiLevel = SystemProperties.getInt(
                "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT);
        if (vendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) return true;

        // Check SDK version of the client app.
        if (!Compatibility.isChangeEnabled(ENABLE_CHECKING_TELEPHONY_FEATURES)) return true;

        // Finally, check if the system feature is actually present.
        return context.getPackageManager().hasSystemFeature(feature);
    }