Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.keyguard; |
| 18 | |
| 19 | |
| 20 | import static android.telephony.SubscriptionManager.DATA_ROAMING_DISABLE; |
| 21 | import static android.telephony.SubscriptionManager.DATA_ROAMING_ENABLE; |
| 22 | import static android.telephony.SubscriptionManager.NAME_SOURCE_DEFAULT_SOURCE; |
| 23 | |
| 24 | import static junit.framework.Assert.assertTrue; |
| 25 | |
| 26 | import static org.junit.Assert.assertEquals; |
| 27 | import static org.mockito.ArgumentMatchers.any; |
| 28 | import static org.mockito.ArgumentMatchers.anyBoolean; |
| 29 | import static org.mockito.ArgumentMatchers.anyInt; |
| 30 | import static org.mockito.Mockito.never; |
| 31 | import static org.mockito.Mockito.reset; |
| 32 | import static org.mockito.Mockito.verify; |
| 33 | import static org.mockito.Mockito.when; |
| 34 | |
| 35 | import android.content.Context; |
| 36 | import android.net.ConnectivityManager; |
| 37 | import android.net.wifi.WifiManager; |
| 38 | import android.os.Handler; |
Fabian Kozynski | c3d06f3 | 2019-07-31 14:18:41 -0400 | [diff] [blame] | 39 | import android.provider.Settings; |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 40 | import android.telephony.SubscriptionInfo; |
Malcolm Chen | 06ec357 | 2019-04-09 15:55:29 -0700 | [diff] [blame] | 41 | import android.telephony.SubscriptionManager; |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 42 | import android.telephony.TelephonyManager; |
| 43 | import android.test.suitebuilder.annotation.SmallTest; |
| 44 | import android.testing.AndroidTestingRunner; |
| 45 | import android.testing.TestableLooper; |
| 46 | |
| 47 | import com.android.internal.telephony.IccCardConstants; |
| 48 | import com.android.systemui.Dependency; |
| 49 | import com.android.systemui.SysuiTestCase; |
| 50 | import com.android.systemui.keyguard.WakefulnessLifecycle; |
| 51 | |
| 52 | import org.junit.Before; |
| 53 | import org.junit.Test; |
| 54 | import org.junit.runner.RunWith; |
| 55 | import org.mockito.ArgumentCaptor; |
| 56 | import org.mockito.Mock; |
| 57 | import org.mockito.MockitoAnnotations; |
| 58 | |
| 59 | import java.util.ArrayList; |
Bonian Chen | a7e9e8c | 2019-06-02 23:59:31 +0000 | [diff] [blame] | 60 | import java.util.HashMap; |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 61 | import java.util.List; |
| 62 | |
| 63 | @SmallTest |
| 64 | @RunWith(AndroidTestingRunner.class) |
| 65 | @TestableLooper.RunWithLooper |
| 66 | public class CarrierTextControllerTest extends SysuiTestCase { |
| 67 | |
| 68 | private static final CharSequence SEPARATOR = " \u2014 "; |
Fabian Kozynski | c3d06f3 | 2019-07-31 14:18:41 -0400 | [diff] [blame] | 69 | private static final CharSequence INVALID_CARD_TEXT = "Invalid card"; |
| 70 | private static final CharSequence AIRPLANE_MODE_TEXT = "Airplane mode"; |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 71 | private static final String TEST_CARRIER = "TEST_CARRIER"; |
Sooraj Sasindran | 0d45da7 | 2019-04-25 15:12:21 -0700 | [diff] [blame] | 72 | private static final String TEST_CARRIER_2 = "TEST_CARRIER_2"; |
| 73 | private static final String TEST_GROUP_UUID = "59b5c870-fc4c-47a4-a99e-9db826b48b24"; |
| 74 | private static final int TEST_CARRIER_ID = 1; |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 75 | private static final SubscriptionInfo TEST_SUBSCRIPTION = new SubscriptionInfo(0, "", 0, |
| 76 | TEST_CARRIER, TEST_CARRIER, NAME_SOURCE_DEFAULT_SOURCE, 0xFFFFFF, "", |
Sooraj Sasindran | 0d45da7 | 2019-04-25 15:12:21 -0700 | [diff] [blame] | 77 | DATA_ROAMING_DISABLE, null, null, null, null, false, null, "", false, TEST_GROUP_UUID, |
| 78 | TEST_CARRIER_ID, 0); |
| 79 | private static final SubscriptionInfo TEST_SUBSCRIPTION_2 = new SubscriptionInfo(0, "", 0, |
| 80 | TEST_CARRIER, TEST_CARRIER_2, NAME_SOURCE_DEFAULT_SOURCE, 0xFFFFFF, "", |
| 81 | DATA_ROAMING_DISABLE, null, null, null, null, false, null, "", true, TEST_GROUP_UUID, |
| 82 | TEST_CARRIER_ID, 0); |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 83 | private static final SubscriptionInfo TEST_SUBSCRIPTION_ROAMING = new SubscriptionInfo(0, "", 0, |
| 84 | TEST_CARRIER, TEST_CARRIER, NAME_SOURCE_DEFAULT_SOURCE, 0xFFFFFF, "", |
| 85 | DATA_ROAMING_ENABLE, null, null, null, null, false, null, ""); |
| 86 | @Mock |
| 87 | private WifiManager mWifiManager; |
| 88 | @Mock |
| 89 | private CarrierTextController.CarrierTextCallback mCarrierTextCallback; |
| 90 | @Mock |
| 91 | private KeyguardUpdateMonitor mKeyguardUpdateMonitor; |
| 92 | @Mock |
| 93 | private ConnectivityManager mConnectivityManager; |
| 94 | @Mock |
| 95 | private TelephonyManager mTelephonyManager; |
Malcolm Chen | 06ec357 | 2019-04-09 15:55:29 -0700 | [diff] [blame] | 96 | @Mock |
| 97 | private SubscriptionManager mSubscriptionManager; |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 98 | private CarrierTextController.CarrierTextCallbackInfo mCarrierTextCallbackInfo; |
| 99 | |
| 100 | private CarrierTextController mCarrierTextController; |
| 101 | private TestableLooper mTestableLooper; |
| 102 | |
| 103 | @Before |
| 104 | public void setUp() { |
| 105 | MockitoAnnotations.initMocks(this); |
| 106 | mTestableLooper = TestableLooper.get(this); |
| 107 | |
| 108 | mContext.addMockSystemService(WifiManager.class, mWifiManager); |
| 109 | mContext.addMockSystemService(ConnectivityManager.class, mConnectivityManager); |
| 110 | mContext.addMockSystemService(TelephonyManager.class, mTelephonyManager); |
Malcolm Chen | 06ec357 | 2019-04-09 15:55:29 -0700 | [diff] [blame] | 111 | mContext.addMockSystemService(SubscriptionManager.class, mSubscriptionManager); |
Fabian Kozynski | c3d06f3 | 2019-07-31 14:18:41 -0400 | [diff] [blame] | 112 | mContext.getOrCreateTestableResources().addOverride( |
| 113 | R.string.keyguard_sim_error_message_short, INVALID_CARD_TEXT); |
| 114 | mContext.getOrCreateTestableResources().addOverride( |
| 115 | R.string.airplane_mode, AIRPLANE_MODE_TEXT); |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 116 | mDependency.injectMockDependency(WakefulnessLifecycle.class); |
| 117 | mDependency.injectTestDependency(Dependency.MAIN_HANDLER, |
| 118 | new Handler(mTestableLooper.getLooper())); |
| 119 | |
| 120 | mCarrierTextCallbackInfo = new CarrierTextController.CarrierTextCallbackInfo("", |
| 121 | new CharSequence[]{}, false, new int[]{}); |
Malcolm Chen | 387dc0e | 2019-10-08 18:11:22 -0700 | [diff] [blame] | 122 | when(mTelephonyManager.getSupportedModemCount()).thenReturn(3); |
Malcolm Chen | d384435 | 2019-11-04 16:26:28 -0800 | [diff] [blame] | 123 | when(mTelephonyManager.getActiveModemCount()).thenReturn(3); |
Fabian Kozynski | 00d02f1 | 2019-04-15 09:48:30 -0400 | [diff] [blame] | 124 | |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 125 | mCarrierTextController = new TestCarrierTextController(mContext, SEPARATOR, true, true, |
| 126 | mKeyguardUpdateMonitor); |
| 127 | // This should not start listening on any of the real dependencies |
| 128 | mCarrierTextController.setListening(mCarrierTextCallback); |
Sooraj Sasindran | b7d633b | 2019-05-02 13:47:21 -0700 | [diff] [blame] | 129 | mCarrierTextController.updateDisplayOpportunisticSubscriptionCarrierText(false); |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | @Test |
Fabian Kozynski | c3d06f3 | 2019-07-31 14:18:41 -0400 | [diff] [blame] | 133 | public void testAirplaneMode() { |
| 134 | Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1); |
| 135 | reset(mCarrierTextCallback); |
| 136 | List<SubscriptionInfo> list = new ArrayList<>(); |
| 137 | list.add(TEST_SUBSCRIPTION); |
| 138 | when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list); |
| 139 | when(mKeyguardUpdateMonitor.getSimState(0)).thenReturn(IccCardConstants.State.READY); |
| 140 | mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); |
| 141 | |
| 142 | mCarrierTextController.updateCarrierText(); |
| 143 | |
| 144 | ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor = |
| 145 | ArgumentCaptor.forClass( |
| 146 | CarrierTextController.CarrierTextCallbackInfo.class); |
| 147 | |
| 148 | mTestableLooper.processAllMessages(); |
| 149 | verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); |
| 150 | assertEquals(AIRPLANE_MODE_TEXT, captor.getValue().carrierText); |
| 151 | } |
| 152 | |
| 153 | @Test |
| 154 | public void testCardIOError() { |
| 155 | reset(mCarrierTextCallback); |
| 156 | List<SubscriptionInfo> list = new ArrayList<>(); |
| 157 | list.add(TEST_SUBSCRIPTION); |
| 158 | when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list); |
| 159 | when(mKeyguardUpdateMonitor.getSimState(0)).thenReturn(IccCardConstants.State.READY); |
| 160 | when(mKeyguardUpdateMonitor.getSimState(1)).thenReturn( |
| 161 | IccCardConstants.State.CARD_IO_ERROR); |
| 162 | mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); |
| 163 | |
| 164 | mCarrierTextController.mCallback.onSimStateChanged(3, 1, |
| 165 | IccCardConstants.State.CARD_IO_ERROR); |
| 166 | |
| 167 | ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor = |
| 168 | ArgumentCaptor.forClass( |
| 169 | CarrierTextController.CarrierTextCallbackInfo.class); |
| 170 | |
| 171 | mTestableLooper.processAllMessages(); |
| 172 | verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); |
| 173 | assertEquals("TEST_CARRIER" + SEPARATOR + INVALID_CARD_TEXT, captor.getValue().carrierText); |
| 174 | // There's only one subscription in the list |
| 175 | assertEquals(1, captor.getValue().listOfCarriers.length); |
| 176 | assertEquals(TEST_CARRIER, captor.getValue().listOfCarriers[0]); |
Malcolm Chen | d384435 | 2019-11-04 16:26:28 -0800 | [diff] [blame] | 177 | |
| 178 | // Now it becomes single SIM active mode. |
| 179 | reset(mCarrierTextCallback); |
| 180 | when(mTelephonyManager.getActiveModemCount()).thenReturn(1); |
| 181 | // Update carrier text. It should ignore error state of subId 3 in inactive slotId. |
| 182 | mCarrierTextController.updateCarrierText(); |
| 183 | mTestableLooper.processAllMessages(); |
| 184 | verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); |
| 185 | assertEquals("TEST_CARRIER", captor.getValue().carrierText); |
Fabian Kozynski | c3d06f3 | 2019-07-31 14:18:41 -0400 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | @Test |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 189 | public void testWrongSlots() { |
| 190 | reset(mCarrierTextCallback); |
| 191 | when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn( |
| 192 | new ArrayList<>()); |
| 193 | when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn( |
| 194 | IccCardConstants.State.CARD_IO_ERROR); |
| 195 | // This should not produce an out of bounds error, even though there are no subscriptions |
| 196 | mCarrierTextController.mCallback.onSimStateChanged(0, -3, |
| 197 | IccCardConstants.State.CARD_IO_ERROR); |
| 198 | mCarrierTextController.mCallback.onSimStateChanged(0, 3, IccCardConstants.State.READY); |
| 199 | verify(mCarrierTextCallback, never()).updateCarrierInfo(any()); |
| 200 | } |
| 201 | |
| 202 | @Test |
| 203 | public void testMoreSlotsThanSubs() { |
| 204 | reset(mCarrierTextCallback); |
| 205 | when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn( |
| 206 | new ArrayList<>()); |
Fabian Kozynski | 00d02f1 | 2019-04-15 09:48:30 -0400 | [diff] [blame] | 207 | |
| 208 | // STOPSHIP(b/130246708) This line makes sure that SubscriptionManager provides the |
| 209 | // same answer as KeyguardUpdateMonitor. Remove when this is addressed |
| 210 | when(mSubscriptionManager.getActiveSubscriptionInfoList(anyBoolean())).thenReturn( |
| 211 | new ArrayList<>()); |
| 212 | |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 213 | when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn( |
| 214 | IccCardConstants.State.CARD_IO_ERROR); |
| 215 | // This should not produce an out of bounds error, even though there are no subscriptions |
| 216 | mCarrierTextController.mCallback.onSimStateChanged(0, 1, |
| 217 | IccCardConstants.State.CARD_IO_ERROR); |
| 218 | |
| 219 | mTestableLooper.processAllMessages(); |
| 220 | verify(mCarrierTextCallback).updateCarrierInfo( |
| 221 | any(CarrierTextController.CarrierTextCallbackInfo.class)); |
| 222 | } |
| 223 | |
| 224 | @Test |
| 225 | public void testCallback() { |
| 226 | reset(mCarrierTextCallback); |
| 227 | mCarrierTextController.postToCallback(mCarrierTextCallbackInfo); |
| 228 | mTestableLooper.processAllMessages(); |
| 229 | |
| 230 | ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor = |
| 231 | ArgumentCaptor.forClass( |
| 232 | CarrierTextController.CarrierTextCallbackInfo.class); |
| 233 | verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); |
| 234 | assertEquals(mCarrierTextCallbackInfo, captor.getValue()); |
| 235 | } |
| 236 | |
| 237 | @Test |
| 238 | public void testNullingCallback() { |
| 239 | reset(mCarrierTextCallback); |
| 240 | |
| 241 | mCarrierTextController.postToCallback(mCarrierTextCallbackInfo); |
| 242 | mCarrierTextController.setListening(null); |
| 243 | |
| 244 | // This shouldn't produce NPE |
| 245 | mTestableLooper.processAllMessages(); |
| 246 | verify(mCarrierTextCallback).updateCarrierInfo(any()); |
| 247 | } |
| 248 | |
| 249 | @Test |
| 250 | public void testCreateInfo_OneValidSubscription() { |
| 251 | reset(mCarrierTextCallback); |
| 252 | List<SubscriptionInfo> list = new ArrayList<>(); |
| 253 | list.add(TEST_SUBSCRIPTION); |
| 254 | when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(IccCardConstants.State.READY); |
| 255 | when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list); |
Fabian Kozynski | 00d02f1 | 2019-04-15 09:48:30 -0400 | [diff] [blame] | 256 | |
Bonian Chen | a7e9e8c | 2019-06-02 23:59:31 +0000 | [diff] [blame] | 257 | mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); |
| 258 | |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 259 | ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor = |
| 260 | ArgumentCaptor.forClass( |
| 261 | CarrierTextController.CarrierTextCallbackInfo.class); |
| 262 | |
| 263 | mCarrierTextController.updateCarrierText(); |
| 264 | mTestableLooper.processAllMessages(); |
| 265 | verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); |
| 266 | |
| 267 | CarrierTextController.CarrierTextCallbackInfo info = captor.getValue(); |
| 268 | assertEquals(1, info.listOfCarriers.length); |
| 269 | assertEquals(TEST_CARRIER, info.listOfCarriers[0]); |
| 270 | assertEquals(1, info.subscriptionIds.length); |
| 271 | } |
| 272 | |
| 273 | @Test |
| 274 | public void testCreateInfo_OneValidSubscriptionWithRoaming() { |
| 275 | reset(mCarrierTextCallback); |
| 276 | List<SubscriptionInfo> list = new ArrayList<>(); |
| 277 | list.add(TEST_SUBSCRIPTION_ROAMING); |
| 278 | when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(IccCardConstants.State.READY); |
| 279 | when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list); |
Fabian Kozynski | 00d02f1 | 2019-04-15 09:48:30 -0400 | [diff] [blame] | 280 | |
Bonian Chen | a7e9e8c | 2019-06-02 23:59:31 +0000 | [diff] [blame] | 281 | mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); |
| 282 | |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 283 | ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor = |
| 284 | ArgumentCaptor.forClass( |
| 285 | CarrierTextController.CarrierTextCallbackInfo.class); |
| 286 | |
| 287 | mCarrierTextController.updateCarrierText(); |
| 288 | mTestableLooper.processAllMessages(); |
| 289 | verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); |
| 290 | |
| 291 | CarrierTextController.CarrierTextCallbackInfo info = captor.getValue(); |
| 292 | assertEquals(1, info.listOfCarriers.length); |
| 293 | assertTrue(info.listOfCarriers[0].toString().contains(TEST_CARRIER)); |
| 294 | assertEquals(1, info.subscriptionIds.length); |
| 295 | } |
| 296 | |
| 297 | @Test |
| 298 | public void testCreateInfo_noSubscriptions() { |
| 299 | reset(mCarrierTextCallback); |
| 300 | when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn( |
| 301 | new ArrayList<>()); |
Fabian Kozynski | 00d02f1 | 2019-04-15 09:48:30 -0400 | [diff] [blame] | 302 | |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 303 | ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor = |
| 304 | ArgumentCaptor.forClass( |
| 305 | CarrierTextController.CarrierTextCallbackInfo.class); |
| 306 | |
| 307 | mCarrierTextController.updateCarrierText(); |
| 308 | mTestableLooper.processAllMessages(); |
| 309 | verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); |
| 310 | |
| 311 | CarrierTextController.CarrierTextCallbackInfo info = captor.getValue(); |
| 312 | assertEquals(0, info.listOfCarriers.length); |
| 313 | assertEquals(0, info.subscriptionIds.length); |
| 314 | |
| 315 | } |
| 316 | |
Fabian Kozynski | 00d02f1 | 2019-04-15 09:48:30 -0400 | [diff] [blame] | 317 | @Test |
| 318 | public void testCarrierText_twoValidSubscriptions() { |
| 319 | reset(mCarrierTextCallback); |
| 320 | List<SubscriptionInfo> list = new ArrayList<>(); |
| 321 | list.add(TEST_SUBSCRIPTION); |
| 322 | list.add(TEST_SUBSCRIPTION); |
| 323 | when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(IccCardConstants.State.READY); |
| 324 | when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list); |
| 325 | |
Bonian Chen | a7e9e8c | 2019-06-02 23:59:31 +0000 | [diff] [blame] | 326 | mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); |
| 327 | |
Fabian Kozynski | 00d02f1 | 2019-04-15 09:48:30 -0400 | [diff] [blame] | 328 | ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor = |
| 329 | ArgumentCaptor.forClass( |
| 330 | CarrierTextController.CarrierTextCallbackInfo.class); |
| 331 | |
| 332 | mCarrierTextController.updateCarrierText(); |
| 333 | mTestableLooper.processAllMessages(); |
| 334 | verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); |
| 335 | |
| 336 | assertEquals(TEST_CARRIER + SEPARATOR + TEST_CARRIER, |
| 337 | captor.getValue().carrierText); |
| 338 | } |
| 339 | |
| 340 | @Test |
| 341 | public void testCarrierText_oneDisabledSub() { |
| 342 | reset(mCarrierTextCallback); |
| 343 | List<SubscriptionInfo> list = new ArrayList<>(); |
| 344 | list.add(TEST_SUBSCRIPTION); |
| 345 | list.add(TEST_SUBSCRIPTION); |
| 346 | when(mKeyguardUpdateMonitor.getSimState(anyInt())) |
| 347 | .thenReturn(IccCardConstants.State.READY) |
| 348 | .thenReturn(IccCardConstants.State.NOT_READY); |
| 349 | when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list); |
| 350 | |
Bonian Chen | a7e9e8c | 2019-06-02 23:59:31 +0000 | [diff] [blame] | 351 | mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); |
| 352 | |
Fabian Kozynski | 00d02f1 | 2019-04-15 09:48:30 -0400 | [diff] [blame] | 353 | ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor = |
| 354 | ArgumentCaptor.forClass( |
| 355 | CarrierTextController.CarrierTextCallbackInfo.class); |
| 356 | |
| 357 | mCarrierTextController.updateCarrierText(); |
| 358 | mTestableLooper.processAllMessages(); |
| 359 | verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); |
| 360 | |
| 361 | assertEquals(TEST_CARRIER, |
| 362 | captor.getValue().carrierText); |
| 363 | } |
| 364 | |
| 365 | @Test |
| 366 | public void testCarrierText_firstDisabledSub() { |
| 367 | reset(mCarrierTextCallback); |
| 368 | List<SubscriptionInfo> list = new ArrayList<>(); |
| 369 | list.add(TEST_SUBSCRIPTION); |
| 370 | list.add(TEST_SUBSCRIPTION); |
| 371 | when(mKeyguardUpdateMonitor.getSimState(anyInt())) |
| 372 | .thenReturn(IccCardConstants.State.NOT_READY) |
| 373 | .thenReturn(IccCardConstants.State.READY); |
| 374 | when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list); |
| 375 | |
Bonian Chen | a7e9e8c | 2019-06-02 23:59:31 +0000 | [diff] [blame] | 376 | mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); |
| 377 | |
Fabian Kozynski | 00d02f1 | 2019-04-15 09:48:30 -0400 | [diff] [blame] | 378 | ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor = |
| 379 | ArgumentCaptor.forClass( |
| 380 | CarrierTextController.CarrierTextCallbackInfo.class); |
| 381 | |
| 382 | mCarrierTextController.updateCarrierText(); |
| 383 | mTestableLooper.processAllMessages(); |
| 384 | verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); |
| 385 | |
| 386 | assertEquals(TEST_CARRIER, |
| 387 | captor.getValue().carrierText); |
| 388 | } |
| 389 | |
| 390 | @Test |
| 391 | public void testCarrierText_threeSubsMiddleDisabled() { |
| 392 | reset(mCarrierTextCallback); |
| 393 | List<SubscriptionInfo> list = new ArrayList<>(); |
| 394 | list.add(TEST_SUBSCRIPTION); |
| 395 | list.add(TEST_SUBSCRIPTION); |
| 396 | list.add(TEST_SUBSCRIPTION); |
| 397 | when(mKeyguardUpdateMonitor.getSimState(anyInt())) |
| 398 | .thenReturn(IccCardConstants.State.READY) |
| 399 | .thenReturn(IccCardConstants.State.NOT_READY) |
| 400 | .thenReturn(IccCardConstants.State.READY); |
| 401 | when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list); |
Bonian Chen | a7e9e8c | 2019-06-02 23:59:31 +0000 | [diff] [blame] | 402 | mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); |
Fabian Kozynski | 00d02f1 | 2019-04-15 09:48:30 -0400 | [diff] [blame] | 403 | |
Fabian Kozynski | 00d02f1 | 2019-04-15 09:48:30 -0400 | [diff] [blame] | 404 | ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor = |
| 405 | ArgumentCaptor.forClass( |
| 406 | CarrierTextController.CarrierTextCallbackInfo.class); |
| 407 | |
| 408 | mCarrierTextController.updateCarrierText(); |
| 409 | mTestableLooper.processAllMessages(); |
| 410 | verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); |
| 411 | |
| 412 | assertEquals(TEST_CARRIER + SEPARATOR + TEST_CARRIER, |
| 413 | captor.getValue().carrierText); |
| 414 | } |
| 415 | |
Sooraj Sasindran | 0d45da7 | 2019-04-25 15:12:21 -0700 | [diff] [blame] | 416 | @Test |
| 417 | public void testCarrierText_GroupedSubWithOpportunisticCarrierText() { |
| 418 | reset(mCarrierTextCallback); |
| 419 | List<SubscriptionInfo> list = new ArrayList<>(); |
| 420 | list.add(TEST_SUBSCRIPTION); |
| 421 | list.add(TEST_SUBSCRIPTION_2); |
| 422 | when(mKeyguardUpdateMonitor.getSimState(anyInt())) |
| 423 | .thenReturn(IccCardConstants.State.READY); |
Fabian Kozynski | 8d735cc | 2019-04-29 10:44:10 -0400 | [diff] [blame] | 424 | |
Bonian Chen | a7e9e8c | 2019-06-02 23:59:31 +0000 | [diff] [blame] | 425 | mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); |
Sooraj Sasindran | b7d633b | 2019-05-02 13:47:21 -0700 | [diff] [blame] | 426 | mCarrierTextController.updateDisplayOpportunisticSubscriptionCarrierText(true); |
Sooraj Sasindran | 0d45da7 | 2019-04-25 15:12:21 -0700 | [diff] [blame] | 427 | when(mSubscriptionManager.getActiveSubscriptionInfoList(anyBoolean())).thenReturn(list); |
| 428 | |
| 429 | ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor = |
| 430 | ArgumentCaptor.forClass( |
| 431 | CarrierTextController.CarrierTextCallbackInfo.class); |
| 432 | |
| 433 | mCarrierTextController.updateCarrierText(); |
| 434 | mTestableLooper.processAllMessages(); |
| 435 | verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); |
| 436 | |
| 437 | assertEquals(TEST_CARRIER_2, captor.getValue().carrierText); |
| 438 | } |
| 439 | |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 440 | public static class TestCarrierTextController extends CarrierTextController { |
| 441 | private KeyguardUpdateMonitor mKUM; |
| 442 | |
| 443 | public TestCarrierTextController(Context context, CharSequence separator, |
| 444 | boolean showAirplaneMode, boolean showMissingSim, KeyguardUpdateMonitor kum) { |
| 445 | super(context, separator, showAirplaneMode, showMissingSim); |
| 446 | mKUM = kum; |
| 447 | } |
| 448 | |
| 449 | @Override |
| 450 | public void setListening(CarrierTextCallback callback) { |
| 451 | super.setListening(callback); |
| 452 | mKeyguardUpdateMonitor = mKUM; |
| 453 | } |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 454 | } |
| 455 | } |