From 9beb2691d9507aff2e6eab2f1fcb9fafe12be070 Mon Sep 17 00:00:00 2001 From: Hui Wang Date: Wed, 12 Jan 2022 20:11:46 +0000 Subject: Cache the resources when the mnc of the configuration is not zero Checking the sim loaded is not used properly for the resources caching. The resources per the mcc and mnc can also be ready before sim loaded. In this case, the mnc of the configuration from the resource is not 0. Bug: 214250834 Test: atest CellBroadcastReceiverUnitTests Change-Id: I15d6fe9d2e50c06d17fd8602b67bc9ddc5affb9c --- .../cellbroadcastreceiver/CellBroadcastSettings.java | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java') diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java b/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java index dd6291f03..f4fe98d17 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java @@ -33,7 +33,6 @@ import android.os.Bundle; import android.os.UserManager; import android.os.Vibrator; import android.telephony.SubscriptionManager; -import android.telephony.TelephonyManager; import android.util.Log; import android.view.MenuItem; import android.widget.Switch; @@ -881,17 +880,8 @@ public class CellBroadcastSettings extends CollapsingToolbarBaseActivity { */ public static @NonNull Resources getResources(@NonNull Context context, int subId) { - try { - if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID - || !SubscriptionManager.isValidSubscriptionId(subId) - // per the latest design, subId can be valid earlier than mcc mnc is known to - // telephony. check if sim is loaded to avoid caching the wrong resources. - || context.getSystemService(TelephonyManager.class).getSimApplicationState( - SubscriptionManager.getSlotIndex(subId)) != TelephonyManager.SIM_STATE_LOADED) { - return context.getResources(); - } - } catch (Exception e) { - Log.d(TAG, "Fail to getSimApplicationState due to " + e); + if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID + || !SubscriptionManager.isValidSubscriptionId(subId)) { return context.getResources(); } @@ -902,7 +892,11 @@ public class CellBroadcastSettings extends CollapsingToolbarBaseActivity { Resources res = SubscriptionManager.getResourcesForSubId(context, subId); - sResourcesCache.put(subId, res); + if (res.getConfiguration().mnc != 0) { + Log.d(TAG, "Cache resource for sub: " + subId + ", mcc: " + + res.getConfiguration().mcc + ", mnc:" + res.getConfiguration().mnc); + sResourcesCache.put(subId, res); + } return res; } -- cgit v1.2.3