diff options
author | Hui Wang <huiwang@google.com> | 2021-09-11 02:40:32 +0000 |
---|---|---|
committer | Hui Wang <huiwang@google.com> | 2021-09-14 01:57:37 +0000 |
commit | 172a70afd04af3304e95e9a48ff2925b1839c71b (patch) | |
tree | 0fa80aefdfedd4de72aa9905696ab2e23f16282d /src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java | |
parent | dc9677fabbfc79c9a13336cb6dbb8bb01c9869f2 (diff) | |
download | CellBroadcastReceiver-172a70afd04af3304e95e9a48ff2925b1839c71b.tar.gz |
Catch exception when calling TelephonyManager#getSimApplicationState
Bug: 196773672
Test: atest CellBroadcastReceiverUnitTests:CellBroadcastSettingsTest
Change-Id: I3b3f3cf55493d7d19caa2dbf76f967eab865388a
Diffstat (limited to 'src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java')
-rw-r--r-- | src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java b/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java index 355c5775d..a5c9caaca 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java @@ -836,12 +836,18 @@ public class CellBroadcastSettings extends CollapsingToolbarBaseActivity { * @return The resource */ public static @NonNull Resources getResources(@NonNull Context context, int subId) { - if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID - || !SubscriptionManager.isValidSubscriptionId(subId) - // based on 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) { + + 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); return context.getResources(); } |