diff options
3 files changed, 14 insertions, 22 deletions
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 @@ -845,16 +842,6 @@ public class CellBroadcastSettings extends CollapsingToolbarBaseActivity { } /** - * 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 * * @param context Context @@ -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(); } diff --git a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertDialogTest.java b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertDialogTest.java index a30c9c41d..9168d5bf7 100644 --- a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertDialogTest.java +++ b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastAlertDialogTest.java @@ -35,6 +35,7 @@ import android.os.Looper; import android.os.Message; import android.os.PowerManager; import android.telephony.SmsCbMessage; +import android.telephony.TelephonyManager; import android.view.KeyEvent; import android.view.View; import android.view.ViewGroup; @@ -68,6 +69,9 @@ public class CellBroadcastAlertDialogTest extends @Mock private IThermalService.Stub mMockedThermalService; + @Mock + TelephonyManager mTelephonyManager; + @Captor private ArgumentCaptor<Integer> mInt; @@ -111,7 +115,9 @@ public class CellBroadcastAlertDialogTest extends mPowerManager = new PowerManager(mContext, mMockedPowerManagerService, mMockedThermalService, null); injectSystemService(PowerManager.class, mPowerManager); - CellBroadcastSettings.setUseResourcesForSubId(false); + doReturn(TelephonyManager.SIM_STATE_UNKNOWN).when(mTelephonyManager) + .getSimApplicationState(anyInt()); + injectSystemService(TelephonyManager.class, mTelephonyManager); } @After diff --git a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastServiceTestCase.java b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastServiceTestCase.java index 7609829c0..66ae7b10f 100644 --- a/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastServiceTestCase.java +++ b/tests/unit/src/com/android/cellbroadcastreceiver/unit/CellBroadcastServiceTestCase.java @@ -165,13 +165,14 @@ public abstract class CellBroadcastServiceTestCase<T extends Service> extends Se doReturn(mMockedTelephonyManager).when(mMockedTelephonyManager) .createForSubscriptionId(anyInt()); + doReturn(TelephonyManager.SIM_STATE_UNKNOWN).when(mMockedTelephonyManager) + .getSimApplicationState(anyInt()); mMockedServiceManager = new MockedServiceManager(); mMockedServiceManager.replaceService("isub", mSubService); mContext = new TestContextWrapper(getContext()); setContext(mContext); - CellBroadcastSettings.setUseResourcesForSubId(false); } @After |