summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Tomasz Wasilczyk <twasilczyk@google.com> 2024-03-20 14:21:44 -0700
committer Tomasz Wasilczyk <twasilczyk@google.com> 2024-03-21 14:36:20 -0700
commitb15dc3704e1c8823dc516db41f7a9974b4a9214a (patch)
tree6a617d87e1e3e4b2210079cc034860b43065e824
parent5f9c22a9dd11b8d5ac6edf51b4f909f5fa2158c0 (diff)
Add sdk version check before skipping telephony managers initialization
Bug: 330583731 Test: ABTD Change-Id: I0360114a5105823457f28788eaf7d910e40631ed
-rw-r--r--telephony/java/android/telephony/TelephonyFrameworkInitializer.java30
1 files changed, 30 insertions, 0 deletions
diff --git a/telephony/java/android/telephony/TelephonyFrameworkInitializer.java b/telephony/java/android/telephony/TelephonyFrameworkInitializer.java
index 901daf813e86..f5688bfffa02 100644
--- a/telephony/java/android/telephony/TelephonyFrameworkInitializer.java
+++ b/telephony/java/android/telephony/TelephonyFrameworkInitializer.java
@@ -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);
}