From c5029c9007f7f3501c9d11924e1c48f49fd8161d Mon Sep 17 00:00:00 2001 From: Malcolm Chen Date: Tue, 13 Aug 2019 13:24:07 -0700 Subject: [PATCH] Move filterMobileSubscriptionInSameGroup into KeyguardUpdateMonitor. This avoids race condition that, KeyguardUpdateMonitor refreshes active sub list however CarrierTextController filtered it based on stale active data subId. By move filterMobileSubscriptionInSameGroup into KeyguardUpdateMonitor, it becomes the single source of truth about which carrier name should be shown. Bug: 138456731 Bug: 151600673 Test: manual and unittest Change-Id: Ida3a90c5408b056cad7a79fbba84fe880ce1e5be Merged-In: Ida3a90c5408b056cad7a79fbba84fe880ce1e5be (cherry picked from commit 5c63b51d9e9e6c2b90575b71e62e66f39c9ff719) --- .../keyguard/CarrierTextController.java | 72 +------------------ .../keyguard/KeyguardUpdateMonitor.java | 49 ++++++++++++- .../systemui/statusbar/OperatorNameView.java | 2 +- .../policy/EmergencyCryptkeeperText.java | 2 +- .../keyguard/CarrierTextControllerTest.java | 54 ++++---------- .../keyguard/KeyguardUpdateMonitorTest.java | 40 ++++++++++- 6 files changed, 101 insertions(+), 118 deletions(-) diff --git a/packages/SystemUI/src/com/android/keyguard/CarrierTextController.java b/packages/SystemUI/src/com/android/keyguard/CarrierTextController.java index 2b8e3ee0dfc0f..a246484c18eb4 100644 --- a/packages/SystemUI/src/com/android/keyguard/CarrierTextController.java +++ b/packages/SystemUI/src/com/android/keyguard/CarrierTextController.java @@ -19,16 +19,12 @@ package com.android.keyguard; import static android.telephony.PhoneStateListener.LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE; import static android.telephony.PhoneStateListener.LISTEN_NONE; -import static com.android.internal.telephony.PhoneConstants.MAX_PHONE_COUNT_DUAL_SIM; - import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.net.ConnectivityManager; import android.net.wifi.WifiManager; import android.os.Handler; -import android.os.SystemProperties; -import android.telephony.CarrierConfigManager; import android.telephony.PhoneStateListener; import android.telephony.ServiceState; import android.telephony.SubscriptionInfo; @@ -37,20 +33,18 @@ import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.Log; -import androidx.annotation.VisibleForTesting; - import com.android.internal.telephony.IccCardConstants; import com.android.internal.telephony.TelephonyIntents; -import com.android.internal.telephony.TelephonyProperties; import com.android.settingslib.WirelessUtils; import com.android.systemui.Dependency; import com.android.systemui.R; import com.android.systemui.keyguard.WakefulnessLifecycle; -import java.util.ArrayList; import java.util.List; import java.util.Objects; +import androidx.annotation.VisibleForTesting; + /** * Controller that generates text including the carrier names and/or the status of all the SIM * interfaces in the device. Through a callback, the updates can be retrieved either as a list or @@ -73,8 +67,6 @@ public class CarrierTextController { private Context mContext; private CharSequence mSeparator; private WakefulnessLifecycle mWakefulnessLifecycle; - @VisibleForTesting - protected boolean mDisplayOpportunisticSubscriptionCarrierText; private final WakefulnessLifecycle.Observer mWakefulnessObserver = new WakefulnessLifecycle.Observer() { @Override @@ -175,9 +167,6 @@ public class CarrierTextController { mSimSlotsNumber = ((TelephonyManager) context.getSystemService( Context.TELEPHONY_SERVICE)).getPhoneCount(); mSimErrorState = new boolean[mSimSlotsNumber]; - updateDisplayOpportunisticSubscriptionCarrierText(SystemProperties.getBoolean( - TelephonyProperties.DISPLAY_OPPORTUNISTIC_SUBSCRIPTION_CARRIER_TEXT_PROPERTY_NAME, - false)); } /** @@ -254,63 +243,8 @@ public class CarrierTextController { } } - /** - * @param subscriptions - */ - private void filterMobileSubscriptionInSameGroup(List subscriptions) { - if (subscriptions.size() == MAX_PHONE_COUNT_DUAL_SIM) { - SubscriptionInfo info1 = subscriptions.get(0); - SubscriptionInfo info2 = subscriptions.get(1); - if (info1.getGroupUuid() != null && info1.getGroupUuid().equals(info2.getGroupUuid())) { - // If both subscriptions are primary, show both. - if (!info1.isOpportunistic() && !info2.isOpportunistic()) return; - - // If carrier required, always show signal bar of primary subscription. - // Otherwise, show whichever subscription is currently active for Internet. - boolean alwaysShowPrimary = CarrierConfigManager.getDefaultConfig() - .getBoolean(CarrierConfigManager - .KEY_ALWAYS_SHOW_PRIMARY_SIGNAL_BAR_IN_OPPORTUNISTIC_NETWORK_BOOLEAN); - if (alwaysShowPrimary) { - subscriptions.remove(info1.isOpportunistic() ? info1 : info2); - } else { - subscriptions.remove(info1.getSubscriptionId() == mActiveMobileDataSubscription - ? info2 : info1); - } - - } - } - } - - /** - * updates if opportunistic sub carrier text should be displayed or not - * - */ - @VisibleForTesting - public void updateDisplayOpportunisticSubscriptionCarrierText(boolean isEnable) { - mDisplayOpportunisticSubscriptionCarrierText = isEnable; - } - protected List getSubscriptionInfo() { - List subs; - if (mDisplayOpportunisticSubscriptionCarrierText) { - SubscriptionManager subscriptionManager = ((SubscriptionManager) mContext - .getSystemService( - Context.TELEPHONY_SUBSCRIPTION_SERVICE)); - subs = subscriptionManager.getActiveSubscriptionInfoList(false); - if (subs == null) { - subs = new ArrayList<>(); - } else { - filterMobileSubscriptionInSameGroup(subs); - } - } else { - subs = mKeyguardUpdateMonitor.getSubscriptionInfo(false); - if (subs == null) { - subs = new ArrayList<>(); - } else { - filterMobileSubscriptionInSameGroup(subs); - } - } - return subs; + return mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(false); } protected void updateCarrierText() { diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java index 8d858dcb25df3..4d82923e86a41 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java @@ -30,6 +30,7 @@ import static android.os.BatteryManager.EXTRA_PLUGGED; import static android.os.BatteryManager.EXTRA_STATUS; import static android.telephony.PhoneStateListener.LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE; +import static com.android.internal.telephony.PhoneConstants.MAX_PHONE_COUNT_DUAL_SIM; import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT; import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW; import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT; @@ -77,6 +78,7 @@ import android.os.UserManager; import android.provider.Settings; import android.service.dreams.DreamService; import android.service.dreams.IDreamManager; +import android.telephony.CarrierConfigManager; import android.telephony.PhoneStateListener; import android.telephony.ServiceState; import android.telephony.SubscriptionInfo; @@ -257,6 +259,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { private boolean mLogoutEnabled; // If the user long pressed the lock icon, disabling face auth for the current session. private boolean mLockIconPressed; + private int mActiveMobileDataSubscription = SubscriptionManager.INVALID_SUBSCRIPTION_ID; /** * Short delay before restarting biometric authentication after a successful try @@ -392,9 +395,11 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { } }; - private PhoneStateListener mPhoneStateListener = new PhoneStateListener() { + @VisibleForTesting + public PhoneStateListener mPhoneStateListener = new PhoneStateListener() { @Override public void onActiveDataSubscriptionIdChanged(int subId) { + mActiveMobileDataSubscription = subId; mHandler.sendEmptyMessage(MSG_SIM_SUBSCRIPTION_INFO_CHANGED); } }; @@ -496,7 +501,9 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { } } - /** @return List of SubscriptionInfo records, maybe empty but never null */ + /** + * @return List of SubscriptionInfo records, maybe empty but never null. + */ public List getSubscriptionInfo(boolean forceReload) { List sil = mSubscriptionInfo; if (sil == null || forceReload) { @@ -508,7 +515,42 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { } else { mSubscriptionInfo = sil; } - return mSubscriptionInfo; + return new ArrayList<>(mSubscriptionInfo); + } + + /** + * This method returns filtered list of SubscriptionInfo from {@link #getSubscriptionInfo}. + * above. Maybe empty but never null. + * + * In DSDS mode if both subscriptions are grouped and one is opportunistic, we filter out one + * of them based on carrier config. e.g. In this case we should only show one carrier name + * on the status bar and quick settings. + */ + public List getFilteredSubscriptionInfo(boolean forceReload) { + List subscriptions = getSubscriptionInfo(false); + if (subscriptions.size() == MAX_PHONE_COUNT_DUAL_SIM) { + SubscriptionInfo info1 = subscriptions.get(0); + SubscriptionInfo info2 = subscriptions.get(1); + if (info1.getGroupUuid() != null && info1.getGroupUuid().equals(info2.getGroupUuid())) { + // If both subscriptions are primary, show both. + if (!info1.isOpportunistic() && !info2.isOpportunistic()) return subscriptions; + + // If carrier required, always show signal bar of primary subscription. + // Otherwise, show whichever subscription is currently active for Internet. + boolean alwaysShowPrimary = CarrierConfigManager.getDefaultConfig() + .getBoolean(CarrierConfigManager + .KEY_ALWAYS_SHOW_PRIMARY_SIGNAL_BAR_IN_OPPORTUNISTIC_NETWORK_BOOLEAN); + if (alwaysShowPrimary) { + subscriptions.remove(info1.isOpportunistic() ? info1 : info2); + } else { + subscriptions.remove(info1.getSubscriptionId() == mActiveMobileDataSubscription + ? info2 : info1); + } + + } + } + + return subscriptions; } @Override @@ -2637,6 +2679,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { pw.println(" " + mSubscriptionInfo.get(i)); } } + pw.println(" Current active data subId=" + mActiveMobileDataSubscription); pw.println(" Service states:"); for (int subId : mServiceStates.keySet()) { pw.println(" " + subId + "=" + mServiceStates.get(subId)); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/OperatorNameView.java b/packages/SystemUI/src/com/android/systemui/statusbar/OperatorNameView.java index d1b3c3cb12d8c..2a5ccdb0c0a7a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/OperatorNameView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/OperatorNameView.java @@ -134,7 +134,7 @@ public class OperatorNameView extends TextView implements DemoMode, DarkReceiver private void updateText() { CharSequence displayText = null; - List subs = mKeyguardUpdateMonitor.getSubscriptionInfo(false); + List subs = mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(false); final int N = subs.size(); for (int i = 0; i < N; i++) { int subId = subs.get(i).getSubscriptionId(); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/EmergencyCryptkeeperText.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/EmergencyCryptkeeperText.java index 0d6178b1176b0..f2c0434a1a957 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/EmergencyCryptkeeperText.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/EmergencyCryptkeeperText.java @@ -97,7 +97,7 @@ public class EmergencyCryptkeeperText extends TextView { boolean allSimsMissing = true; CharSequence displayText = null; - List subs = mKeyguardUpdateMonitor.getSubscriptionInfo(false); + List subs = mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(false); final int N = subs.size(); for (int i = 0; i < N; i++) { int subId = subs.get(i).getSubscriptionId(); diff --git a/packages/SystemUI/tests/src/com/android/keyguard/CarrierTextControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/CarrierTextControllerTest.java index 1421b06be6211..1ae37e8200e43 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/CarrierTextControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/CarrierTextControllerTest.java @@ -71,15 +71,10 @@ public class CarrierTextControllerTest extends SysuiTestCase { private static final CharSequence AIRPLANE_MODE_TEXT = "Airplane mode"; private static final String TEST_CARRIER = "TEST_CARRIER"; private static final String TEST_CARRIER_2 = "TEST_CARRIER_2"; - private static final String TEST_GROUP_UUID = "59b5c870-fc4c-47a4-a99e-9db826b48b24"; private static final int TEST_CARRIER_ID = 1; private static final SubscriptionInfo TEST_SUBSCRIPTION = new SubscriptionInfo(0, "", 0, TEST_CARRIER, TEST_CARRIER, NAME_SOURCE_DEFAULT_SOURCE, 0xFFFFFF, "", - DATA_ROAMING_DISABLE, null, null, null, null, false, null, "", false, TEST_GROUP_UUID, - TEST_CARRIER_ID, 0); - private static final SubscriptionInfo TEST_SUBSCRIPTION_2 = new SubscriptionInfo(0, "", 0, - TEST_CARRIER, TEST_CARRIER_2, NAME_SOURCE_DEFAULT_SOURCE, 0xFFFFFF, "", - DATA_ROAMING_DISABLE, null, null, null, null, false, null, "", true, TEST_GROUP_UUID, + DATA_ROAMING_DISABLE, null, null, null, null, false, null, "", false, null, TEST_CARRIER_ID, 0); private static final SubscriptionInfo TEST_SUBSCRIPTION_ROAMING = new SubscriptionInfo(0, "", 0, TEST_CARRIER, TEST_CARRIER, NAME_SOURCE_DEFAULT_SOURCE, 0xFFFFFF, "", @@ -126,7 +121,6 @@ public class CarrierTextControllerTest extends SysuiTestCase { mKeyguardUpdateMonitor); // This should not start listening on any of the real dependencies mCarrierTextController.setListening(mCarrierTextCallback); - mCarrierTextController.updateDisplayOpportunisticSubscriptionCarrierText(false); } @Test @@ -135,7 +129,7 @@ public class CarrierTextControllerTest extends SysuiTestCase { reset(mCarrierTextCallback); List list = new ArrayList<>(); list.add(TEST_SUBSCRIPTION); - when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list); + when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list); when(mKeyguardUpdateMonitor.getSimState(0)).thenReturn(IccCardConstants.State.READY); mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); @@ -155,7 +149,7 @@ public class CarrierTextControllerTest extends SysuiTestCase { reset(mCarrierTextCallback); List list = new ArrayList<>(); list.add(TEST_SUBSCRIPTION); - when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list); + when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list); when(mKeyguardUpdateMonitor.getSimState(0)).thenReturn(IccCardConstants.State.READY); when(mKeyguardUpdateMonitor.getSimState(1)).thenReturn( IccCardConstants.State.CARD_IO_ERROR); @@ -179,7 +173,7 @@ public class CarrierTextControllerTest extends SysuiTestCase { @Test public void testWrongSlots() { reset(mCarrierTextCallback); - when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn( + when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn( new ArrayList<>()); when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn( IccCardConstants.State.CARD_IO_ERROR); @@ -193,7 +187,7 @@ public class CarrierTextControllerTest extends SysuiTestCase { @Test public void testMoreSlotsThanSubs() { reset(mCarrierTextCallback); - when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn( + when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn( new ArrayList<>()); // STOPSHIP(b/130246708) This line makes sure that SubscriptionManager provides the @@ -243,7 +237,7 @@ public class CarrierTextControllerTest extends SysuiTestCase { List list = new ArrayList<>(); list.add(TEST_SUBSCRIPTION); when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(IccCardConstants.State.READY); - when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list); + when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list); mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); @@ -267,7 +261,7 @@ public class CarrierTextControllerTest extends SysuiTestCase { List list = new ArrayList<>(); list.add(TEST_SUBSCRIPTION_ROAMING); when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(IccCardConstants.State.READY); - when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list); + when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list); mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); @@ -288,7 +282,7 @@ public class CarrierTextControllerTest extends SysuiTestCase { @Test public void testCreateInfo_noSubscriptions() { reset(mCarrierTextCallback); - when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn( + when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn( new ArrayList<>()); ArgumentCaptor captor = @@ -312,7 +306,7 @@ public class CarrierTextControllerTest extends SysuiTestCase { list.add(TEST_SUBSCRIPTION); list.add(TEST_SUBSCRIPTION); when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(IccCardConstants.State.READY); - when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list); + when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list); mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); @@ -337,7 +331,7 @@ public class CarrierTextControllerTest extends SysuiTestCase { when(mKeyguardUpdateMonitor.getSimState(anyInt())) .thenReturn(IccCardConstants.State.READY) .thenReturn(IccCardConstants.State.NOT_READY); - when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list); + when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list); mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); @@ -362,7 +356,7 @@ public class CarrierTextControllerTest extends SysuiTestCase { when(mKeyguardUpdateMonitor.getSimState(anyInt())) .thenReturn(IccCardConstants.State.NOT_READY) .thenReturn(IccCardConstants.State.READY); - when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list); + when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list); mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); @@ -389,7 +383,7 @@ public class CarrierTextControllerTest extends SysuiTestCase { .thenReturn(IccCardConstants.State.READY) .thenReturn(IccCardConstants.State.NOT_READY) .thenReturn(IccCardConstants.State.READY); - when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list); + when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list); mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); ArgumentCaptor captor = @@ -404,30 +398,6 @@ public class CarrierTextControllerTest extends SysuiTestCase { captor.getValue().carrierText); } - @Test - public void testCarrierText_GroupedSubWithOpportunisticCarrierText() { - reset(mCarrierTextCallback); - List list = new ArrayList<>(); - list.add(TEST_SUBSCRIPTION); - list.add(TEST_SUBSCRIPTION_2); - when(mKeyguardUpdateMonitor.getSimState(anyInt())) - .thenReturn(IccCardConstants.State.READY); - - mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); - mCarrierTextController.updateDisplayOpportunisticSubscriptionCarrierText(true); - when(mSubscriptionManager.getActiveSubscriptionInfoList(anyBoolean())).thenReturn(list); - - ArgumentCaptor captor = - ArgumentCaptor.forClass( - CarrierTextController.CarrierTextCallbackInfo.class); - - mCarrierTextController.updateCarrierText(); - mTestableLooper.processAllMessages(); - verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); - - assertEquals(TEST_CARRIER_2, captor.getValue().carrierText); - } - public static class TestCarrierTextController extends CarrierTextController { private KeyguardUpdateMonitor mKUM; diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java index db6177a63f968..a3cb6c05ca7a1 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java @@ -16,15 +16,18 @@ package com.android.keyguard; +import static android.telephony.SubscriptionManager.DATA_ROAMING_DISABLE; +import static android.telephony.SubscriptionManager.NAME_SOURCE_DEFAULT_SOURCE; + import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.reset; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -42,6 +45,7 @@ import android.hardware.fingerprint.FingerprintManager; import android.os.Bundle; import android.os.UserManager; import android.telephony.ServiceState; +import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.test.suitebuilder.annotation.SmallTest; import android.testing.AndroidTestingRunner; @@ -62,6 +66,8 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; @SmallTest @@ -73,7 +79,18 @@ import java.util.concurrent.atomic.AtomicBoolean; // new tests. @RunWithLooper(setAsMainLooper = true) public class KeyguardUpdateMonitorTest extends SysuiTestCase { - + private static final String TEST_CARRIER = "TEST_CARRIER"; + private static final String TEST_CARRIER_2 = "TEST_CARRIER_2"; + private static final int TEST_CARRIER_ID = 1; + private static final String TEST_GROUP_UUID = "59b5c870-fc4c-47a4-a99e-9db826b48b24"; + private static final SubscriptionInfo TEST_SUBSCRIPTION = new SubscriptionInfo(1, "", 0, + TEST_CARRIER, TEST_CARRIER, NAME_SOURCE_DEFAULT_SOURCE, 0xFFFFFF, "", + DATA_ROAMING_DISABLE, null, null, null, null, false, null, "", false, TEST_GROUP_UUID, + TEST_CARRIER_ID, 0); + private static final SubscriptionInfo TEST_SUBSCRIPTION_2 = new SubscriptionInfo(2, "", 0, + TEST_CARRIER, TEST_CARRIER_2, NAME_SOURCE_DEFAULT_SOURCE, 0xFFFFFF, "", + DATA_ROAMING_DISABLE, null, null, null, null, false, null, "", true, TEST_GROUP_UUID, + TEST_CARRIER_ID, 0); @Mock private KeyguardUpdateMonitor.StrongAuthTracker mStrongAuthTracker; @Mock @@ -92,6 +109,8 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { private DevicePolicyManager mDevicePolicyManager; @Mock private KeyguardBypassController mKeyguardBypassController; + @Mock + private SubscriptionManager mSubscriptionManager; private TestableLooper mTestableLooper; private TestableKeyguardUpdateMonitor mKeyguardUpdateMonitor; @@ -119,6 +138,7 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { context.addMockSystemService(FaceManager.class, mFaceManager); context.addMockSystemService(UserManager.class, mUserManager); context.addMockSystemService(DevicePolicyManager.class, mDevicePolicyManager); + context.addMockSystemService(SubscriptionManager.class, mSubscriptionManager); mTestableLooper = TestableLooper.get(this); mKeyguardUpdateMonitor = new TestableKeyguardUpdateMonitor(context); @@ -441,6 +461,22 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { assertThat(mKeyguardUpdateMonitor.getUserCanSkipBouncer(user)).isTrue(); } + @Test + public void testGetSubscriptionInfo_whenInGroupedSubWithOpportunistic() { + List list = new ArrayList<>(); + list.add(TEST_SUBSCRIPTION); + list.add(TEST_SUBSCRIPTION_2); + when(mSubscriptionManager.getActiveSubscriptionInfoList(anyBoolean())).thenReturn(list); + mKeyguardUpdateMonitor.mPhoneStateListener.onActiveDataSubscriptionIdChanged( + TEST_SUBSCRIPTION_2.getSubscriptionId()); + mTestableLooper.processAllMessages(); + + List listToVerify = mKeyguardUpdateMonitor + .getFilteredSubscriptionInfo(false); + assertThat(listToVerify.size()).isEqualTo(1); + assertThat(listToVerify.get(0)).isEqualTo(TEST_SUBSCRIPTION_2); + } + private Intent putPhoneInfo(Intent intent, Bundle data, Boolean simInited) { int subscription = simInited ? 1/* mock subid=1 */ : SubscriptionManager.DUMMY_SUBSCRIPTION_ID_BASE;