blob: cfa56451d515e6ec8ff48a320e684ad637ce6590 [file] [log] [blame]
Fabian Kozynskib176f422019-02-05 09:36:59 -05001/*
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
17package com.android.keyguard;
18
19
20import static android.telephony.SubscriptionManager.DATA_ROAMING_DISABLE;
21import static android.telephony.SubscriptionManager.DATA_ROAMING_ENABLE;
22import static android.telephony.SubscriptionManager.NAME_SOURCE_DEFAULT_SOURCE;
23
24import static junit.framework.Assert.assertTrue;
Fabian Kozynski4e63d9e2019-08-29 09:47:07 -040025import static junit.framework.TestCase.assertFalse;
Fabian Kozynskib176f422019-02-05 09:36:59 -050026
27import static org.junit.Assert.assertEquals;
Fabian Kozynski4e63d9e2019-08-29 09:47:07 -040028import static org.junit.Assert.assertNotEquals;
Fabian Kozynskib176f422019-02-05 09:36:59 -050029import static org.mockito.ArgumentMatchers.any;
30import static org.mockito.ArgumentMatchers.anyBoolean;
31import static org.mockito.ArgumentMatchers.anyInt;
Fabian Kozynski4e63d9e2019-08-29 09:47:07 -040032import static org.mockito.Mockito.mock;
Fabian Kozynskib176f422019-02-05 09:36:59 -050033import static org.mockito.Mockito.never;
34import static org.mockito.Mockito.reset;
35import static org.mockito.Mockito.verify;
36import static org.mockito.Mockito.when;
37
38import android.content.Context;
39import android.net.ConnectivityManager;
Fabian Kozynski4e63d9e2019-08-29 09:47:07 -040040import android.net.wifi.WifiInfo;
Fabian Kozynskib176f422019-02-05 09:36:59 -050041import android.net.wifi.WifiManager;
42import android.os.Handler;
Fabian Kozynskic3d06f32019-07-31 14:18:41 -040043import android.provider.Settings;
Fabian Kozynski4e63d9e2019-08-29 09:47:07 -040044import android.telephony.ServiceState;
Fabian Kozynskib176f422019-02-05 09:36:59 -050045import android.telephony.SubscriptionInfo;
Malcolm Chen06ec3572019-04-09 15:55:29 -070046import android.telephony.SubscriptionManager;
Fabian Kozynskib176f422019-02-05 09:36:59 -050047import android.telephony.TelephonyManager;
48import android.test.suitebuilder.annotation.SmallTest;
49import android.testing.AndroidTestingRunner;
50import android.testing.TestableLooper;
Fabian Kozynski4e63d9e2019-08-29 09:47:07 -040051import android.text.TextUtils;
Fabian Kozynskib176f422019-02-05 09:36:59 -050052
53import com.android.internal.telephony.IccCardConstants;
54import com.android.systemui.Dependency;
Sunny Goyal87fccf02019-08-13 17:39:10 -070055import com.android.systemui.R;
Fabian Kozynskib176f422019-02-05 09:36:59 -050056import com.android.systemui.SysuiTestCase;
57import com.android.systemui.keyguard.WakefulnessLifecycle;
58
59import org.junit.Before;
60import org.junit.Test;
61import org.junit.runner.RunWith;
62import org.mockito.ArgumentCaptor;
63import org.mockito.Mock;
64import org.mockito.MockitoAnnotations;
65
66import java.util.ArrayList;
Bonian Chena7e9e8c2019-06-02 23:59:31 +000067import java.util.HashMap;
Fabian Kozynskib176f422019-02-05 09:36:59 -050068import java.util.List;
69
70@SmallTest
71@RunWith(AndroidTestingRunner.class)
72@TestableLooper.RunWithLooper
73public class CarrierTextControllerTest extends SysuiTestCase {
74
75 private static final CharSequence SEPARATOR = " \u2014 ";
Fabian Kozynskic3d06f32019-07-31 14:18:41 -040076 private static final CharSequence INVALID_CARD_TEXT = "Invalid card";
77 private static final CharSequence AIRPLANE_MODE_TEXT = "Airplane mode";
Fabian Kozynskib176f422019-02-05 09:36:59 -050078 private static final String TEST_CARRIER = "TEST_CARRIER";
Sooraj Sasindran0d45da72019-04-25 15:12:21 -070079 private static final String TEST_CARRIER_2 = "TEST_CARRIER_2";
80 private static final String TEST_GROUP_UUID = "59b5c870-fc4c-47a4-a99e-9db826b48b24";
81 private static final int TEST_CARRIER_ID = 1;
Fabian Kozynskib176f422019-02-05 09:36:59 -050082 private static final SubscriptionInfo TEST_SUBSCRIPTION = new SubscriptionInfo(0, "", 0,
83 TEST_CARRIER, TEST_CARRIER, NAME_SOURCE_DEFAULT_SOURCE, 0xFFFFFF, "",
Sooraj Sasindran0d45da72019-04-25 15:12:21 -070084 DATA_ROAMING_DISABLE, null, null, null, null, false, null, "", false, TEST_GROUP_UUID,
85 TEST_CARRIER_ID, 0);
86 private static final SubscriptionInfo TEST_SUBSCRIPTION_2 = new SubscriptionInfo(0, "", 0,
87 TEST_CARRIER, TEST_CARRIER_2, NAME_SOURCE_DEFAULT_SOURCE, 0xFFFFFF, "",
88 DATA_ROAMING_DISABLE, null, null, null, null, false, null, "", true, TEST_GROUP_UUID,
89 TEST_CARRIER_ID, 0);
Fabian Kozynski4e63d9e2019-08-29 09:47:07 -040090 private static final SubscriptionInfo TEST_SUBSCRIPTION_NULL = new SubscriptionInfo(0, "", 0,
91 TEST_CARRIER, null, NAME_SOURCE_DEFAULT_SOURCE, 0xFFFFFF, "", DATA_ROAMING_DISABLE,
92 null, null, null, null, false, null, "");
Fabian Kozynskib176f422019-02-05 09:36:59 -050093 private static final SubscriptionInfo TEST_SUBSCRIPTION_ROAMING = new SubscriptionInfo(0, "", 0,
94 TEST_CARRIER, TEST_CARRIER, NAME_SOURCE_DEFAULT_SOURCE, 0xFFFFFF, "",
95 DATA_ROAMING_ENABLE, null, null, null, null, false, null, "");
96 @Mock
97 private WifiManager mWifiManager;
98 @Mock
99 private CarrierTextController.CarrierTextCallback mCarrierTextCallback;
100 @Mock
101 private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
102 @Mock
103 private ConnectivityManager mConnectivityManager;
104 @Mock
105 private TelephonyManager mTelephonyManager;
Malcolm Chen06ec3572019-04-09 15:55:29 -0700106 @Mock
107 private SubscriptionManager mSubscriptionManager;
Fabian Kozynskib176f422019-02-05 09:36:59 -0500108 private CarrierTextController.CarrierTextCallbackInfo mCarrierTextCallbackInfo;
109
110 private CarrierTextController mCarrierTextController;
111 private TestableLooper mTestableLooper;
112
113 @Before
114 public void setUp() {
115 MockitoAnnotations.initMocks(this);
116 mTestableLooper = TestableLooper.get(this);
117
118 mContext.addMockSystemService(WifiManager.class, mWifiManager);
119 mContext.addMockSystemService(ConnectivityManager.class, mConnectivityManager);
120 mContext.addMockSystemService(TelephonyManager.class, mTelephonyManager);
Malcolm Chen06ec3572019-04-09 15:55:29 -0700121 mContext.addMockSystemService(SubscriptionManager.class, mSubscriptionManager);
Fabian Kozynskic3d06f32019-07-31 14:18:41 -0400122 mContext.getOrCreateTestableResources().addOverride(
123 R.string.keyguard_sim_error_message_short, INVALID_CARD_TEXT);
124 mContext.getOrCreateTestableResources().addOverride(
125 R.string.airplane_mode, AIRPLANE_MODE_TEXT);
Fabian Kozynskib176f422019-02-05 09:36:59 -0500126 mDependency.injectMockDependency(WakefulnessLifecycle.class);
127 mDependency.injectTestDependency(Dependency.MAIN_HANDLER,
128 new Handler(mTestableLooper.getLooper()));
129
130 mCarrierTextCallbackInfo = new CarrierTextController.CarrierTextCallbackInfo("",
131 new CharSequence[]{}, false, new int[]{});
Malcolm Chen387dc0e2019-10-08 18:11:22 -0700132 when(mTelephonyManager.getSupportedModemCount()).thenReturn(3);
Malcolm Chend3844352019-11-04 16:26:28 -0800133 when(mTelephonyManager.getActiveModemCount()).thenReturn(3);
Fabian Kozynski00d02f12019-04-15 09:48:30 -0400134
Fabian Kozynskib176f422019-02-05 09:36:59 -0500135 mCarrierTextController = new TestCarrierTextController(mContext, SEPARATOR, true, true,
136 mKeyguardUpdateMonitor);
137 // This should not start listening on any of the real dependencies
138 mCarrierTextController.setListening(mCarrierTextCallback);
Sooraj Sasindranb7d633b2019-05-02 13:47:21 -0700139 mCarrierTextController.updateDisplayOpportunisticSubscriptionCarrierText(false);
Fabian Kozynskib176f422019-02-05 09:36:59 -0500140 }
141
142 @Test
Fabian Kozynskic3d06f32019-07-31 14:18:41 -0400143 public void testAirplaneMode() {
144 Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1);
145 reset(mCarrierTextCallback);
146 List<SubscriptionInfo> list = new ArrayList<>();
147 list.add(TEST_SUBSCRIPTION);
148 when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list);
149 when(mKeyguardUpdateMonitor.getSimState(0)).thenReturn(IccCardConstants.State.READY);
150 mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
151
152 mCarrierTextController.updateCarrierText();
153
154 ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
155 ArgumentCaptor.forClass(
156 CarrierTextController.CarrierTextCallbackInfo.class);
157
158 mTestableLooper.processAllMessages();
159 verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
160 assertEquals(AIRPLANE_MODE_TEXT, captor.getValue().carrierText);
161 }
162
163 @Test
164 public void testCardIOError() {
165 reset(mCarrierTextCallback);
166 List<SubscriptionInfo> list = new ArrayList<>();
167 list.add(TEST_SUBSCRIPTION);
168 when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list);
169 when(mKeyguardUpdateMonitor.getSimState(0)).thenReturn(IccCardConstants.State.READY);
170 when(mKeyguardUpdateMonitor.getSimState(1)).thenReturn(
171 IccCardConstants.State.CARD_IO_ERROR);
172 mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
173
174 mCarrierTextController.mCallback.onSimStateChanged(3, 1,
175 IccCardConstants.State.CARD_IO_ERROR);
176
177 ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
178 ArgumentCaptor.forClass(
179 CarrierTextController.CarrierTextCallbackInfo.class);
180
181 mTestableLooper.processAllMessages();
182 verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
183 assertEquals("TEST_CARRIER" + SEPARATOR + INVALID_CARD_TEXT, captor.getValue().carrierText);
184 // There's only one subscription in the list
185 assertEquals(1, captor.getValue().listOfCarriers.length);
186 assertEquals(TEST_CARRIER, captor.getValue().listOfCarriers[0]);
Malcolm Chend3844352019-11-04 16:26:28 -0800187
188 // Now it becomes single SIM active mode.
189 reset(mCarrierTextCallback);
190 when(mTelephonyManager.getActiveModemCount()).thenReturn(1);
191 // Update carrier text. It should ignore error state of subId 3 in inactive slotId.
192 mCarrierTextController.updateCarrierText();
193 mTestableLooper.processAllMessages();
194 verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
195 assertEquals("TEST_CARRIER", captor.getValue().carrierText);
Fabian Kozynskic3d06f32019-07-31 14:18:41 -0400196 }
197
198 @Test
Fabian Kozynskib176f422019-02-05 09:36:59 -0500199 public void testWrongSlots() {
200 reset(mCarrierTextCallback);
201 when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(
202 new ArrayList<>());
203 when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(
204 IccCardConstants.State.CARD_IO_ERROR);
205 // This should not produce an out of bounds error, even though there are no subscriptions
206 mCarrierTextController.mCallback.onSimStateChanged(0, -3,
207 IccCardConstants.State.CARD_IO_ERROR);
208 mCarrierTextController.mCallback.onSimStateChanged(0, 3, IccCardConstants.State.READY);
209 verify(mCarrierTextCallback, never()).updateCarrierInfo(any());
210 }
211
212 @Test
213 public void testMoreSlotsThanSubs() {
214 reset(mCarrierTextCallback);
215 when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(
216 new ArrayList<>());
Fabian Kozynski00d02f12019-04-15 09:48:30 -0400217
218 // STOPSHIP(b/130246708) This line makes sure that SubscriptionManager provides the
219 // same answer as KeyguardUpdateMonitor. Remove when this is addressed
220 when(mSubscriptionManager.getActiveSubscriptionInfoList(anyBoolean())).thenReturn(
221 new ArrayList<>());
222
Fabian Kozynskib176f422019-02-05 09:36:59 -0500223 when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(
224 IccCardConstants.State.CARD_IO_ERROR);
225 // This should not produce an out of bounds error, even though there are no subscriptions
226 mCarrierTextController.mCallback.onSimStateChanged(0, 1,
227 IccCardConstants.State.CARD_IO_ERROR);
228
229 mTestableLooper.processAllMessages();
230 verify(mCarrierTextCallback).updateCarrierInfo(
231 any(CarrierTextController.CarrierTextCallbackInfo.class));
232 }
233
234 @Test
235 public void testCallback() {
236 reset(mCarrierTextCallback);
237 mCarrierTextController.postToCallback(mCarrierTextCallbackInfo);
238 mTestableLooper.processAllMessages();
239
240 ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
241 ArgumentCaptor.forClass(
242 CarrierTextController.CarrierTextCallbackInfo.class);
243 verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
244 assertEquals(mCarrierTextCallbackInfo, captor.getValue());
245 }
246
247 @Test
248 public void testNullingCallback() {
249 reset(mCarrierTextCallback);
250
251 mCarrierTextController.postToCallback(mCarrierTextCallbackInfo);
252 mCarrierTextController.setListening(null);
253
254 // This shouldn't produce NPE
255 mTestableLooper.processAllMessages();
256 verify(mCarrierTextCallback).updateCarrierInfo(any());
257 }
258
259 @Test
260 public void testCreateInfo_OneValidSubscription() {
261 reset(mCarrierTextCallback);
262 List<SubscriptionInfo> list = new ArrayList<>();
263 list.add(TEST_SUBSCRIPTION);
264 when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(IccCardConstants.State.READY);
265 when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list);
Fabian Kozynski00d02f12019-04-15 09:48:30 -0400266
Bonian Chena7e9e8c2019-06-02 23:59:31 +0000267 mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
268
Fabian Kozynskib176f422019-02-05 09:36:59 -0500269 ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
270 ArgumentCaptor.forClass(
271 CarrierTextController.CarrierTextCallbackInfo.class);
272
273 mCarrierTextController.updateCarrierText();
274 mTestableLooper.processAllMessages();
275 verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
276
277 CarrierTextController.CarrierTextCallbackInfo info = captor.getValue();
278 assertEquals(1, info.listOfCarriers.length);
279 assertEquals(TEST_CARRIER, info.listOfCarriers[0]);
280 assertEquals(1, info.subscriptionIds.length);
281 }
282
283 @Test
284 public void testCreateInfo_OneValidSubscriptionWithRoaming() {
285 reset(mCarrierTextCallback);
286 List<SubscriptionInfo> list = new ArrayList<>();
287 list.add(TEST_SUBSCRIPTION_ROAMING);
288 when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(IccCardConstants.State.READY);
289 when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list);
Fabian Kozynski00d02f12019-04-15 09:48:30 -0400290
Bonian Chena7e9e8c2019-06-02 23:59:31 +0000291 mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
292
Fabian Kozynskib176f422019-02-05 09:36:59 -0500293 ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
294 ArgumentCaptor.forClass(
295 CarrierTextController.CarrierTextCallbackInfo.class);
296
297 mCarrierTextController.updateCarrierText();
298 mTestableLooper.processAllMessages();
299 verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
300
301 CarrierTextController.CarrierTextCallbackInfo info = captor.getValue();
302 assertEquals(1, info.listOfCarriers.length);
303 assertTrue(info.listOfCarriers[0].toString().contains(TEST_CARRIER));
304 assertEquals(1, info.subscriptionIds.length);
305 }
306
307 @Test
Fabian Kozynski4e63d9e2019-08-29 09:47:07 -0400308 public void testCarrierText_noTextOnReadySimWhenNull() {
309 reset(mCarrierTextCallback);
310 List<SubscriptionInfo> list = new ArrayList<>();
311 list.add(TEST_SUBSCRIPTION_NULL);
312 when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(IccCardConstants.State.READY);
313 when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list);
314
315 mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
316
317 ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
318 ArgumentCaptor.forClass(
319 CarrierTextController.CarrierTextCallbackInfo.class);
320
321 mCarrierTextController.updateCarrierText();
322 mTestableLooper.processAllMessages();
323 verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
324
325 assertTrue("Carrier text should be empty, instead it's " + captor.getValue().carrierText,
326 TextUtils.isEmpty(captor.getValue().carrierText));
327 assertFalse("No SIM should be available", captor.getValue().anySimReady);
328 }
329
330 @Test
331 public void testCarrierText_noTextOnReadySimWhenNull_airplaneMode_wifiOn() {
332 Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1);
333 reset(mCarrierTextCallback);
334 List<SubscriptionInfo> list = new ArrayList<>();
335 list.add(TEST_SUBSCRIPTION_NULL);
336 when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(IccCardConstants.State.READY);
337 when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list);
338 mockWifi();
339
340 mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
341 ServiceState ss = mock(ServiceState.class);
342 when(ss.getDataRegState()).thenReturn(ServiceState.STATE_IN_SERVICE);
343 mKeyguardUpdateMonitor.mServiceStates.put(TEST_SUBSCRIPTION_NULL.getSubscriptionId(), ss);
344
345 ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
346 ArgumentCaptor.forClass(
347 CarrierTextController.CarrierTextCallbackInfo.class);
348
349 mCarrierTextController.updateCarrierText();
350 mTestableLooper.processAllMessages();
351 verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
352
353 assertFalse("No SIM should be available", captor.getValue().anySimReady);
354 // There's no airplane mode if at least one SIM is State.READY and there's wifi
355 assertFalse("Device should not be in airplane mode", captor.getValue().airplaneMode);
356 assertNotEquals(AIRPLANE_MODE_TEXT, captor.getValue().carrierText);
357 }
358
359 private void mockWifi() {
360 when(mWifiManager.isWifiEnabled()).thenReturn(true);
361 WifiInfo wifiInfo = mock(WifiInfo.class);
362 when(wifiInfo.getBSSID()).thenReturn("");
363 when(mWifiManager.getConnectionInfo()).thenReturn(wifiInfo);
364 }
365
366 @Test
Fabian Kozynskib176f422019-02-05 09:36:59 -0500367 public void testCreateInfo_noSubscriptions() {
368 reset(mCarrierTextCallback);
369 when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(
370 new ArrayList<>());
Fabian Kozynski00d02f12019-04-15 09:48:30 -0400371
Fabian Kozynskib176f422019-02-05 09:36:59 -0500372 ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
373 ArgumentCaptor.forClass(
374 CarrierTextController.CarrierTextCallbackInfo.class);
375
376 mCarrierTextController.updateCarrierText();
377 mTestableLooper.processAllMessages();
378 verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
379
380 CarrierTextController.CarrierTextCallbackInfo info = captor.getValue();
381 assertEquals(0, info.listOfCarriers.length);
382 assertEquals(0, info.subscriptionIds.length);
383
384 }
385
Fabian Kozynski00d02f12019-04-15 09:48:30 -0400386 @Test
387 public void testCarrierText_twoValidSubscriptions() {
388 reset(mCarrierTextCallback);
389 List<SubscriptionInfo> list = new ArrayList<>();
390 list.add(TEST_SUBSCRIPTION);
391 list.add(TEST_SUBSCRIPTION);
392 when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(IccCardConstants.State.READY);
393 when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list);
394
Bonian Chena7e9e8c2019-06-02 23:59:31 +0000395 mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
396
Fabian Kozynski00d02f12019-04-15 09:48:30 -0400397 ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
398 ArgumentCaptor.forClass(
399 CarrierTextController.CarrierTextCallbackInfo.class);
400
401 mCarrierTextController.updateCarrierText();
402 mTestableLooper.processAllMessages();
403 verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
404
405 assertEquals(TEST_CARRIER + SEPARATOR + TEST_CARRIER,
406 captor.getValue().carrierText);
407 }
408
409 @Test
410 public void testCarrierText_oneDisabledSub() {
411 reset(mCarrierTextCallback);
412 List<SubscriptionInfo> list = new ArrayList<>();
413 list.add(TEST_SUBSCRIPTION);
414 list.add(TEST_SUBSCRIPTION);
415 when(mKeyguardUpdateMonitor.getSimState(anyInt()))
416 .thenReturn(IccCardConstants.State.READY)
417 .thenReturn(IccCardConstants.State.NOT_READY);
418 when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list);
419
Bonian Chena7e9e8c2019-06-02 23:59:31 +0000420 mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
421
Fabian Kozynski00d02f12019-04-15 09:48:30 -0400422 ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
423 ArgumentCaptor.forClass(
424 CarrierTextController.CarrierTextCallbackInfo.class);
425
426 mCarrierTextController.updateCarrierText();
427 mTestableLooper.processAllMessages();
428 verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
429
430 assertEquals(TEST_CARRIER,
431 captor.getValue().carrierText);
432 }
433
434 @Test
435 public void testCarrierText_firstDisabledSub() {
436 reset(mCarrierTextCallback);
437 List<SubscriptionInfo> list = new ArrayList<>();
438 list.add(TEST_SUBSCRIPTION);
439 list.add(TEST_SUBSCRIPTION);
440 when(mKeyguardUpdateMonitor.getSimState(anyInt()))
441 .thenReturn(IccCardConstants.State.NOT_READY)
442 .thenReturn(IccCardConstants.State.READY);
443 when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list);
444
Bonian Chena7e9e8c2019-06-02 23:59:31 +0000445 mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
446
Fabian Kozynski00d02f12019-04-15 09:48:30 -0400447 ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
448 ArgumentCaptor.forClass(
449 CarrierTextController.CarrierTextCallbackInfo.class);
450
451 mCarrierTextController.updateCarrierText();
452 mTestableLooper.processAllMessages();
453 verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
454
455 assertEquals(TEST_CARRIER,
456 captor.getValue().carrierText);
457 }
458
459 @Test
460 public void testCarrierText_threeSubsMiddleDisabled() {
461 reset(mCarrierTextCallback);
462 List<SubscriptionInfo> list = new ArrayList<>();
463 list.add(TEST_SUBSCRIPTION);
464 list.add(TEST_SUBSCRIPTION);
465 list.add(TEST_SUBSCRIPTION);
466 when(mKeyguardUpdateMonitor.getSimState(anyInt()))
467 .thenReturn(IccCardConstants.State.READY)
468 .thenReturn(IccCardConstants.State.NOT_READY)
469 .thenReturn(IccCardConstants.State.READY);
470 when(mKeyguardUpdateMonitor.getSubscriptionInfo(anyBoolean())).thenReturn(list);
Bonian Chena7e9e8c2019-06-02 23:59:31 +0000471 mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
Fabian Kozynski00d02f12019-04-15 09:48:30 -0400472
Fabian Kozynski00d02f12019-04-15 09:48:30 -0400473 ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
474 ArgumentCaptor.forClass(
475 CarrierTextController.CarrierTextCallbackInfo.class);
476
477 mCarrierTextController.updateCarrierText();
478 mTestableLooper.processAllMessages();
479 verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
480
481 assertEquals(TEST_CARRIER + SEPARATOR + TEST_CARRIER,
482 captor.getValue().carrierText);
483 }
484
Sooraj Sasindran0d45da72019-04-25 15:12:21 -0700485 @Test
486 public void testCarrierText_GroupedSubWithOpportunisticCarrierText() {
487 reset(mCarrierTextCallback);
488 List<SubscriptionInfo> list = new ArrayList<>();
489 list.add(TEST_SUBSCRIPTION);
490 list.add(TEST_SUBSCRIPTION_2);
491 when(mKeyguardUpdateMonitor.getSimState(anyInt()))
492 .thenReturn(IccCardConstants.State.READY);
Fabian Kozynski8d735cc2019-04-29 10:44:10 -0400493
Bonian Chena7e9e8c2019-06-02 23:59:31 +0000494 mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
Sooraj Sasindranb7d633b2019-05-02 13:47:21 -0700495 mCarrierTextController.updateDisplayOpportunisticSubscriptionCarrierText(true);
Sooraj Sasindran0d45da72019-04-25 15:12:21 -0700496 when(mSubscriptionManager.getActiveSubscriptionInfoList(anyBoolean())).thenReturn(list);
497
498 ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
499 ArgumentCaptor.forClass(
500 CarrierTextController.CarrierTextCallbackInfo.class);
501
502 mCarrierTextController.updateCarrierText();
503 mTestableLooper.processAllMessages();
504 verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
505
506 assertEquals(TEST_CARRIER_2, captor.getValue().carrierText);
507 }
508
Fabian Kozynskib176f422019-02-05 09:36:59 -0500509 public static class TestCarrierTextController extends CarrierTextController {
510 private KeyguardUpdateMonitor mKUM;
511
512 public TestCarrierTextController(Context context, CharSequence separator,
513 boolean showAirplaneMode, boolean showMissingSim, KeyguardUpdateMonitor kum) {
514 super(context, separator, showAirplaneMode, showMissingSim);
515 mKUM = kum;
516 }
517
518 @Override
519 public void setListening(CarrierTextCallback callback) {
520 super.setListening(callback);
521 mKeyguardUpdateMonitor = mKUM;
522 }
Fabian Kozynskib176f422019-02-05 09:36:59 -0500523 }
524}