From d065e0e533c08e97a8d3a54b6b6bd332289e9b5f Mon Sep 17 00:00:00 2001 From: Rambo Wang Date: Thu, 9 Mar 2023 22:22:05 +0000 Subject: [PATCH] Introduce utility method in CarrierConfigManager to get config subset This CL introduces a hidden utility method for system components to get the subset of carrier config. Many system components has been update to use the new CarrierConfigManager API to get subset of config. But the callers side have repetitive private methods to do the same thing. The utility method in CarrierConfigManager will remove the duplication. Bug: b/263267340 Test: FrameworksTelephonyTests (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:96727486197e8c0602ffb8f27787aae1b256fa44) Merged-In: Ifbd84c67525fd9ea2925e5b735788e6c3c22dd34 Change-Id: Iac88c03f2c9b4ac80dd2ed0b72a200cfc1631d21 --- .../telephony/CarrierConfigManager.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/telephony/java/android/telephony/CarrierConfigManager.java b/telephony/java/android/telephony/CarrierConfigManager.java index 63dbeeba8e40e..318b01aad076a 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. + * + *

This is a system internally used only utility to reduce the repetitive logic. + * + *

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(); + } }