From 14f7c8ada3af5eb1a43b4ce4c6b9d464db154d55 Mon Sep 17 00:00:00 2001 From: Hui Wang Date: Fri, 20 Aug 2021 22:50:53 +0000 Subject: Mock telephony api instead of static flag in CellBroadcastSettings Bug: 196349924 Test: atest CellBroadcastReceiverOemUnitTests Test: atest CellBroadcastReceiverUnitTests Merged-In: I1630d09fca01033a47fb94f07d0b6d8d9c7430c0 Change-Id: I1630d09fca01033a47fb94f07d0b6d8d9c7430c0 (cherry picked from commit 4529cee025dcc67c4dbdaa5411a3106716303772) --- .../CellBroadcastSettings.java | 25 +++++----------------- 1 file changed, 5 insertions(+), 20 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 c8eb50057..8b84bd185 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java @@ -177,9 +177,6 @@ public class CellBroadcastSettings extends CollapsingToolbarBaseActivity { // Key for shared preference which represents whether user has changed any preference private static final String ANY_PREFERENCE_CHANGED_BY_USER = "any_preference_changed_by_user"; - // Test override for disabling the subId specific resources - private static boolean sUseResourcesForSubId = true; - @Override public void onCreate(Bundle savedInstanceState) { // for backward compatibility on R devices @@ -844,16 +841,6 @@ public class CellBroadcastSettings extends CollapsingToolbarBaseActivity { return defaultValue; } - /** - * Override used by tests so that we don't call - * SubscriptionManager.getResourcesForSubId, which is a static unmockable - * method. - */ - @VisibleForTesting - public static void setUseResourcesForSubId(boolean useResourcesForSubId) { - sUseResourcesForSubId = useResourcesForSubId; - } - /** * Get the device resource based on SIM * @@ -863,14 +850,12 @@ public class CellBroadcastSettings extends CollapsingToolbarBaseActivity { * @return The resource */ public static @NonNull Resources getResources(@NonNull Context context, int 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. - TelephonyManager tm = context.getSystemService(TelephonyManager.class); - boolean isSimLoaded = tm.getSimApplicationState(SubscriptionManager.getSlotIndex(subId)) - == TelephonyManager.SIM_STATE_LOADED; if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID - || !SubscriptionManager.isValidSubscriptionId(subId) || !sUseResourcesForSubId - || !isSimLoaded) { + || !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) { return context.getResources(); } -- cgit v1.2.3