summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Rambo Wang <rambowang@google.com> 2023-08-01 15:51:55 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2023-08-01 15:51:55 +0000
commit769a63e38a1c02b543e9997e4898c5ea0adef02d (patch)
tree920e7db83ef14de7395eaa12d01bff4b607c391e
parentfcfc6c13f523807a9d7e7f5a18683ee7f8b9d233 (diff)
parentd065e0e533c08e97a8d3a54b6b6bd332289e9b5f (diff)
Merge "Introduce utility method in CarrierConfigManager to get config subset" into main
-rw-r--r--telephony/java/android/telephony/CarrierConfigManager.java34
1 files changed, 34 insertions, 0 deletions
diff --git a/telephony/java/android/telephony/CarrierConfigManager.java b/telephony/java/android/telephony/CarrierConfigManager.java
index 63dbeeba8e40..318b01aad076 100644
--- a/telephony/java/android/telephony/CarrierConfigManager.java
+++ b/telephony/java/android/telephony/CarrierConfigManager.java
@@ -9899,4 +9899,38 @@ public class CarrierConfigManager {
}
trm.removeCarrierConfigChangedListener(listener);
}
+
+ /**
+ * Get subset of specified carrier configuration if available or empty bundle, without throwing
+ * {@link RuntimeException} to caller.
+ *
+ * <p>This is a system internally used only utility to reduce the repetitive logic.
+ *
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}, or the calling app
+ * has carrier privileges on the specified subscription (see
+ * {@link TelephonyManager#hasCarrierPrivileges()}).
+ *
+ * @param context Context used to get the CarrierConfigManager service.
+ * @param subId The subscription ID to get the config from.
+ * @param keys The config keys the client is interested in.
+ * @return Config bundle with key/value for the specified keys or empty bundle when failed
+ * @hide
+ */
+ @RequiresPermission(anyOf = {
+ Manifest.permission.READ_PHONE_STATE,
+ "carrier privileges",
+ })
+ @NonNull
+ public static PersistableBundle getCarrierConfigSubset(
+ @NonNull Context context, int subId, @NonNull String... keys) {
+ PersistableBundle configs = null;
+ CarrierConfigManager ccm = context.getSystemService(CarrierConfigManager.class);
+ try {
+ configs = ccm.getConfigForSubId(subId, keys);
+ } catch (RuntimeException exception) {
+ Rlog.w(TAG, "CarrierConfigLoader is not available.");
+ }
+ return configs != null ? configs : new PersistableBundle();
+ }
}