diff options
author | 2020-02-03 20:52:01 +0000 | |
---|---|---|
committer | 2020-02-03 20:52:01 +0000 | |
commit | 0dcce3b875ced0b86dc9322e84f47a8c0375e41d (patch) | |
tree | 40e6c5b1b6c0429adef6fcadc4c65317ed4ce19f | |
parent | 19fd3c80f5aa0acdf1396780113063defee624c4 (diff) | |
parent | 14747aa9fd8d91252c000bc671630820052b421d (diff) |
Merge "Create new context with new resources"
-rw-r--r-- | telephony/java/android/telephony/SubscriptionManager.java | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index 7406c8d5a33c..97f50fd314b8 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -55,7 +55,6 @@ import android.os.RemoteException; import android.provider.Telephony.SimInfo; import android.telephony.euicc.EuiccManager; import android.telephony.ims.ImsMmTelManager; -import android.util.DisplayMetrics; import android.util.Log; import android.util.Pair; @@ -2500,23 +2499,24 @@ public class SubscriptionManager { final SubscriptionInfo subInfo = SubscriptionManager.from(context).getActiveSubscriptionInfo(subId); - Configuration config = context.getResources().getConfiguration(); - Configuration newConfig = new Configuration(); - newConfig.setTo(config); + Configuration overrideConfig = new Configuration(); if (subInfo != null) { - newConfig.mcc = subInfo.getMcc(); - newConfig.mnc = subInfo.getMnc(); - if (newConfig.mnc == 0) newConfig.mnc = Configuration.MNC_ZERO; + overrideConfig.mcc = subInfo.getMcc(); + overrideConfig.mnc = subInfo.getMnc(); + if (overrideConfig.mnc == 0) overrideConfig.mnc = Configuration.MNC_ZERO; } if (useRootLocale) { - newConfig.setLocale(Locale.ROOT); + overrideConfig.setLocale(Locale.ROOT); } - DisplayMetrics metrics = context.getResources().getDisplayMetrics(); - DisplayMetrics newMetrics = new DisplayMetrics(); - newMetrics.setTo(metrics); - Resources res = new Resources(context.getResources().getAssets(), newMetrics, newConfig); + // Create new context with new configuration so that we can avoid modifying the passed in + // context. + // Note that if the original context configuration changes, the resources here will also + // change for all values except those overridden by newConfig (e.g. if the device has an + // orientation change). + Context newContext = context.createConfigurationContext(overrideConfig); + Resources res = newContext.getResources(); if (cacheKey != null) { // Save the newly created Resources in the resource cache. |