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_CARRIER_ID;
23 
24 import static junit.framework.Assert.assertTrue;
25 import static junit.framework.TestCase.assertFalse;
26 
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertNotEquals;
29 import static org.junit.Assert.fail;
30 import static org.mockito.ArgumentMatchers.any;
31 import static org.mockito.ArgumentMatchers.anyBoolean;
32 import static org.mockito.ArgumentMatchers.anyInt;
33 import static org.mockito.Mockito.doAnswer;
34 import static org.mockito.Mockito.mock;
35 import static org.mockito.Mockito.never;
36 import static org.mockito.Mockito.reset;
37 import static org.mockito.Mockito.verify;
38 import static org.mockito.Mockito.when;
39 
40 import android.net.ConnectivityManager;
41 import android.net.wifi.WifiInfo;
42 import android.net.wifi.WifiManager;
43 import android.os.Handler;
44 import android.os.HandlerThread;
45 import android.os.Looper;
46 import android.os.Process;
47 import android.provider.Settings;
48 import android.telephony.ServiceState;
49 import android.telephony.SubscriptionInfo;
50 import android.telephony.SubscriptionManager;
51 import android.telephony.TelephonyManager;
52 import android.test.suitebuilder.annotation.SmallTest;
53 import android.testing.AndroidTestingRunner;
54 import android.testing.TestableLooper;
55 import android.text.TextUtils;
56 
57 import com.android.systemui.Dependency;
58 import com.android.systemui.R;
59 import com.android.systemui.SysuiTestCase;
60 import com.android.systemui.keyguard.WakefulnessLifecycle;
61 
62 import org.junit.Before;
63 import org.junit.Test;
64 import org.junit.runner.RunWith;
65 import org.mockito.ArgumentCaptor;
66 import org.mockito.Mock;
67 import org.mockito.MockitoAnnotations;
68 import org.mockito.invocation.InvocationOnMock;
69 
70 import java.util.ArrayList;
71 import java.util.HashMap;
72 import java.util.List;
73 
74 @SmallTest
75 @RunWith(AndroidTestingRunner.class)
76 @TestableLooper.RunWithLooper
77 public class CarrierTextControllerTest extends SysuiTestCase {
78 
79     private static final CharSequence SEPARATOR = " \u2014 ";
80     private static final CharSequence INVALID_CARD_TEXT = "Invalid card";
81     private static final CharSequence AIRPLANE_MODE_TEXT = "Airplane mode";
82     private static final String TEST_CARRIER = "TEST_CARRIER";
83     private static final String TEST_CARRIER_2 = "TEST_CARRIER_2";
84     private static final int TEST_CARRIER_ID = 1;
85     private static final SubscriptionInfo TEST_SUBSCRIPTION = new SubscriptionInfo(0, "", 0,
86             TEST_CARRIER, TEST_CARRIER, NAME_SOURCE_CARRIER_ID, 0xFFFFFF, "",
87             DATA_ROAMING_DISABLE, null, null, null, null, false, null, "", false, null,
88             TEST_CARRIER_ID, 0);
89     private static final SubscriptionInfo TEST_SUBSCRIPTION_NULL = new SubscriptionInfo(0, "", 0,
90             TEST_CARRIER, null, NAME_SOURCE_CARRIER_ID, 0xFFFFFF, "", DATA_ROAMING_DISABLE,
91             null, null, null, null, false, null, "");
92     private static final SubscriptionInfo TEST_SUBSCRIPTION_ROAMING = new SubscriptionInfo(0, "", 0,
93             TEST_CARRIER, TEST_CARRIER, NAME_SOURCE_CARRIER_ID, 0xFFFFFF, "",
94             DATA_ROAMING_ENABLE, null, null, null, null, false, null, "");
95     @Mock
96     private WifiManager mWifiManager;
97     @Mock
98     private CarrierTextController.CarrierTextCallback mCarrierTextCallback;
99     @Mock
100     private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
101     @Mock
102     private ConnectivityManager mConnectivityManager;
103     @Mock
104     private TelephonyManager mTelephonyManager;
105     @Mock
106     private SubscriptionManager mSubscriptionManager;
107     private CarrierTextController.CarrierTextCallbackInfo mCarrierTextCallbackInfo;
108 
109     private CarrierTextController mCarrierTextController;
110     private TestableLooper mTestableLooper;
111 
checkMainThread(InvocationOnMock inv)112     private Void checkMainThread(InvocationOnMock inv) {
113         Looper mainLooper = Dependency.get(Dependency.MAIN_HANDLER).getLooper();
114         if (!mainLooper.isCurrentThread()) {
115             fail("This call should be done from the main thread");
116         }
117         return null;
118     }
119 
120     @Before
setUp()121     public void setUp() {
122         MockitoAnnotations.initMocks(this);
123         mTestableLooper = TestableLooper.get(this);
124 
125         mContext.addMockSystemService(WifiManager.class, mWifiManager);
126         mContext.addMockSystemService(ConnectivityManager.class, mConnectivityManager);
127         when(mConnectivityManager.isNetworkSupported(anyInt())).thenReturn(true);
128         mContext.addMockSystemService(TelephonyManager.class, mTelephonyManager);
129         mContext.addMockSystemService(SubscriptionManager.class, mSubscriptionManager);
130         mContext.getOrCreateTestableResources().addOverride(
131                 R.string.keyguard_sim_error_message_short, INVALID_CARD_TEXT);
132         mContext.getOrCreateTestableResources().addOverride(
133                 R.string.airplane_mode, AIRPLANE_MODE_TEXT);
134         mDependency.injectMockDependency(WakefulnessLifecycle.class);
135         mDependency.injectTestDependency(Dependency.MAIN_HANDLER,
136                 new Handler(mTestableLooper.getLooper()));
137         mDependency.injectTestDependency(Dependency.BG_LOOPER, mTestableLooper.getLooper());
138         mDependency.injectTestDependency(KeyguardUpdateMonitor.class, mKeyguardUpdateMonitor);
139 
140         doAnswer(this::checkMainThread).when(mKeyguardUpdateMonitor)
141                 .registerCallback(any(KeyguardUpdateMonitorCallback.class));
142         doAnswer(this::checkMainThread).when(mKeyguardUpdateMonitor)
143                 .removeCallback(any(KeyguardUpdateMonitorCallback.class));
144 
145         mCarrierTextCallbackInfo = new CarrierTextController.CarrierTextCallbackInfo("",
146                 new CharSequence[]{}, false, new int[]{});
147         when(mTelephonyManager.getSupportedModemCount()).thenReturn(3);
148         when(mTelephonyManager.getActiveModemCount()).thenReturn(3);
149 
150         mCarrierTextController = new CarrierTextController(mContext, SEPARATOR, true, true);
151         // This should not start listening on any of the real dependencies but will test that
152         // callbacks in mKeyguardUpdateMonitor are done in the mTestableLooper thread
153         mCarrierTextController.setListening(mCarrierTextCallback);
154         mTestableLooper.processAllMessages();
155     }
156 
157     @Test
testKeyguardUpdateMonitorCalledInMainThread()158     public void testKeyguardUpdateMonitorCalledInMainThread() throws Exception {
159         // This test will run on the main looper (which is not the same as the looper set as MAIN
160         // for CarrierTextCallback. This will fail if calls to mKeyguardUpdateMonitor are not done
161         // through the looper set in the set up
162         HandlerThread thread = new HandlerThread("testThread",
163                 Process.THREAD_PRIORITY_BACKGROUND);
164         thread.start();
165         TestableLooper testableLooper = new TestableLooper(thread.getLooper());
166         Handler h = new Handler(testableLooper.getLooper());
167         h.post(() -> {
168             mCarrierTextController.setListening(null);
169             mCarrierTextController.setListening(mCarrierTextCallback);
170         });
171         testableLooper.processAllMessages();
172         mTestableLooper.processAllMessages();
173         thread.quitSafely();
174     }
175 
176     @Test
testAirplaneMode()177     public void testAirplaneMode() {
178         Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1);
179         reset(mCarrierTextCallback);
180         List<SubscriptionInfo> list = new ArrayList<>();
181         list.add(TEST_SUBSCRIPTION);
182         when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list);
183         when(mKeyguardUpdateMonitor.getSimState(0)).thenReturn(TelephonyManager.SIM_STATE_READY);
184         mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
185 
186         mCarrierTextController.updateCarrierText();
187 
188         ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
189                 ArgumentCaptor.forClass(
190                         CarrierTextController.CarrierTextCallbackInfo.class);
191 
192         mTestableLooper.processAllMessages();
193         verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
194         assertEquals(AIRPLANE_MODE_TEXT, captor.getValue().carrierText);
195     }
196 
197     @Test
testCardIOError()198     public void testCardIOError() {
199         reset(mCarrierTextCallback);
200         List<SubscriptionInfo> list = new ArrayList<>();
201         list.add(TEST_SUBSCRIPTION);
202         when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list);
203         when(mKeyguardUpdateMonitor.getSimState(0)).thenReturn(TelephonyManager.SIM_STATE_READY);
204         when(mKeyguardUpdateMonitor.getSimState(1)).thenReturn(
205                 TelephonyManager.SIM_STATE_CARD_IO_ERROR);
206         mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
207 
208         mCarrierTextController.mCallback.onSimStateChanged(3, 1,
209                 TelephonyManager.SIM_STATE_CARD_IO_ERROR);
210 
211         ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
212                 ArgumentCaptor.forClass(
213                         CarrierTextController.CarrierTextCallbackInfo.class);
214 
215         mTestableLooper.processAllMessages();
216         verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
217         assertEquals("TEST_CARRIER" + SEPARATOR + INVALID_CARD_TEXT, captor.getValue().carrierText);
218         // There's only one subscription in the list
219         assertEquals(1, captor.getValue().listOfCarriers.length);
220         assertEquals(TEST_CARRIER, captor.getValue().listOfCarriers[0]);
221 
222         // Now it becomes single SIM active mode.
223         reset(mCarrierTextCallback);
224         when(mTelephonyManager.getActiveModemCount()).thenReturn(1);
225         // Update carrier text. It should ignore error state of subId 3 in inactive slotId.
226         mCarrierTextController.updateCarrierText();
227         mTestableLooper.processAllMessages();
228         verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
229         assertEquals("TEST_CARRIER", captor.getValue().carrierText);
230     }
231 
232     @Test
testWrongSlots()233     public void testWrongSlots() {
234         reset(mCarrierTextCallback);
235         when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(
236                 new ArrayList<>());
237         when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(
238                 TelephonyManager.SIM_STATE_CARD_IO_ERROR);
239         // This should not produce an out of bounds error, even though there are no subscriptions
240         mCarrierTextController.mCallback.onSimStateChanged(0, -3,
241                 TelephonyManager.SIM_STATE_CARD_IO_ERROR);
242         mCarrierTextController.mCallback.onSimStateChanged(0, 3, TelephonyManager.SIM_STATE_READY);
243         verify(mCarrierTextCallback, never()).updateCarrierInfo(any());
244     }
245 
246     @Test
testMoreSlotsThanSubs()247     public void testMoreSlotsThanSubs() {
248         reset(mCarrierTextCallback);
249         when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(
250                 new ArrayList<>());
251 
252         // STOPSHIP(b/130246708) This line makes sure that SubscriptionManager provides the
253         // same answer as KeyguardUpdateMonitor. Remove when this is addressed
254         when(mSubscriptionManager.getCompleteActiveSubscriptionInfoList()).thenReturn(
255                 new ArrayList<>());
256 
257         when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(
258                 TelephonyManager.SIM_STATE_CARD_IO_ERROR);
259         // This should not produce an out of bounds error, even though there are no subscriptions
260         mCarrierTextController.mCallback.onSimStateChanged(0, 1,
261                 TelephonyManager.SIM_STATE_CARD_IO_ERROR);
262 
263         mTestableLooper.processAllMessages();
264         verify(mCarrierTextCallback).updateCarrierInfo(
265                 any(CarrierTextController.CarrierTextCallbackInfo.class));
266     }
267 
268     @Test
testCallback()269     public void testCallback() {
270         reset(mCarrierTextCallback);
271         mCarrierTextController.postToCallback(mCarrierTextCallbackInfo);
272         mTestableLooper.processAllMessages();
273 
274         ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
275                 ArgumentCaptor.forClass(
276                         CarrierTextController.CarrierTextCallbackInfo.class);
277         verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
278         assertEquals(mCarrierTextCallbackInfo, captor.getValue());
279     }
280 
281     @Test
testNullingCallback()282     public void testNullingCallback() {
283         reset(mCarrierTextCallback);
284 
285         mCarrierTextController.postToCallback(mCarrierTextCallbackInfo);
286         mCarrierTextController.setListening(null);
287 
288         // This shouldn't produce NPE
289         mTestableLooper.processAllMessages();
290         verify(mCarrierTextCallback).updateCarrierInfo(any());
291     }
292 
293     @Test
testCreateInfo_OneValidSubscription()294     public void testCreateInfo_OneValidSubscription() {
295         reset(mCarrierTextCallback);
296         List<SubscriptionInfo> list = new ArrayList<>();
297         list.add(TEST_SUBSCRIPTION);
298         when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(
299                 TelephonyManager.SIM_STATE_READY);
300         when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list);
301 
302         mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
303 
304         ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
305                 ArgumentCaptor.forClass(
306                         CarrierTextController.CarrierTextCallbackInfo.class);
307 
308         mCarrierTextController.updateCarrierText();
309         mTestableLooper.processAllMessages();
310         verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
311 
312         CarrierTextController.CarrierTextCallbackInfo info = captor.getValue();
313         assertEquals(1, info.listOfCarriers.length);
314         assertEquals(TEST_CARRIER, info.listOfCarriers[0]);
315         assertEquals(1, info.subscriptionIds.length);
316     }
317 
318     @Test
testCreateInfo_OneValidSubscriptionWithRoaming()319     public void testCreateInfo_OneValidSubscriptionWithRoaming() {
320         reset(mCarrierTextCallback);
321         List<SubscriptionInfo> list = new ArrayList<>();
322         list.add(TEST_SUBSCRIPTION_ROAMING);
323         when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(
324                 TelephonyManager.SIM_STATE_READY);
325         when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list);
326 
327         mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
328 
329         ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
330                 ArgumentCaptor.forClass(
331                         CarrierTextController.CarrierTextCallbackInfo.class);
332 
333         mCarrierTextController.updateCarrierText();
334         mTestableLooper.processAllMessages();
335         verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
336 
337         CarrierTextController.CarrierTextCallbackInfo info = captor.getValue();
338         assertEquals(1, info.listOfCarriers.length);
339         assertTrue(info.listOfCarriers[0].toString().contains(TEST_CARRIER));
340         assertEquals(1, info.subscriptionIds.length);
341     }
342 
343     @Test
testCarrierText_noTextOnReadySimWhenNull()344     public void testCarrierText_noTextOnReadySimWhenNull() {
345         reset(mCarrierTextCallback);
346         List<SubscriptionInfo> list = new ArrayList<>();
347         list.add(TEST_SUBSCRIPTION_NULL);
348         when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(
349             TelephonyManager.SIM_STATE_READY);
350         when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list);
351 
352         mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
353 
354         ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
355                 ArgumentCaptor.forClass(
356                         CarrierTextController.CarrierTextCallbackInfo.class);
357 
358         mCarrierTextController.updateCarrierText();
359         mTestableLooper.processAllMessages();
360         verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
361 
362         assertTrue("Carrier text should be empty, instead it's " + captor.getValue().carrierText,
363                 TextUtils.isEmpty(captor.getValue().carrierText));
364         assertFalse("No SIM should be available", captor.getValue().anySimReady);
365     }
366 
367     @Test
testCarrierText_noTextOnReadySimWhenNull_airplaneMode_wifiOn()368     public void testCarrierText_noTextOnReadySimWhenNull_airplaneMode_wifiOn() {
369         Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1);
370         reset(mCarrierTextCallback);
371         List<SubscriptionInfo> list = new ArrayList<>();
372         list.add(TEST_SUBSCRIPTION_NULL);
373         when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(
374                 TelephonyManager.SIM_STATE_READY);
375         when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list);
376         mockWifi();
377 
378         mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
379         ServiceState ss = mock(ServiceState.class);
380         when(ss.getDataRegistrationState()).thenReturn(ServiceState.STATE_IN_SERVICE);
381         mKeyguardUpdateMonitor.mServiceStates.put(TEST_SUBSCRIPTION_NULL.getSubscriptionId(), ss);
382 
383         ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
384                 ArgumentCaptor.forClass(
385                         CarrierTextController.CarrierTextCallbackInfo.class);
386 
387         mCarrierTextController.updateCarrierText();
388         mTestableLooper.processAllMessages();
389         verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
390 
391         assertFalse("No SIM should be available", captor.getValue().anySimReady);
392         // There's no airplane mode if at least one SIM is State.READY and there's wifi
393         assertFalse("Device should not be in airplane mode", captor.getValue().airplaneMode);
394         assertNotEquals(AIRPLANE_MODE_TEXT, captor.getValue().carrierText);
395     }
396 
mockWifi()397     private void mockWifi() {
398         when(mWifiManager.isWifiEnabled()).thenReturn(true);
399         WifiInfo wifiInfo = mock(WifiInfo.class);
400         when(wifiInfo.getBSSID()).thenReturn("");
401         when(mWifiManager.getConnectionInfo()).thenReturn(wifiInfo);
402     }
403 
404     @Test
testCreateInfo_noSubscriptions()405     public void testCreateInfo_noSubscriptions() {
406         reset(mCarrierTextCallback);
407         when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(
408                 new ArrayList<>());
409 
410         ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
411                 ArgumentCaptor.forClass(
412                         CarrierTextController.CarrierTextCallbackInfo.class);
413 
414         mCarrierTextController.updateCarrierText();
415         mTestableLooper.processAllMessages();
416         verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
417 
418         CarrierTextController.CarrierTextCallbackInfo info = captor.getValue();
419         assertEquals(0, info.listOfCarriers.length);
420         assertEquals(0, info.subscriptionIds.length);
421 
422     }
423 
424     @Test
testCarrierText_twoValidSubscriptions()425     public void testCarrierText_twoValidSubscriptions() {
426         reset(mCarrierTextCallback);
427         List<SubscriptionInfo> list = new ArrayList<>();
428         list.add(TEST_SUBSCRIPTION);
429         list.add(TEST_SUBSCRIPTION);
430         when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(
431             TelephonyManager.SIM_STATE_READY);
432         when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list);
433 
434         mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
435 
436         ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
437                 ArgumentCaptor.forClass(
438                         CarrierTextController.CarrierTextCallbackInfo.class);
439 
440         mCarrierTextController.updateCarrierText();
441         mTestableLooper.processAllMessages();
442         verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
443 
444         assertEquals(TEST_CARRIER + SEPARATOR + TEST_CARRIER,
445                 captor.getValue().carrierText);
446     }
447 
448     @Test
testCarrierText_oneDisabledSub()449     public void testCarrierText_oneDisabledSub() {
450         reset(mCarrierTextCallback);
451         List<SubscriptionInfo> list = new ArrayList<>();
452         list.add(TEST_SUBSCRIPTION);
453         list.add(TEST_SUBSCRIPTION);
454         when(mKeyguardUpdateMonitor.getSimState(anyInt()))
455                 .thenReturn(TelephonyManager.SIM_STATE_READY)
456                 .thenReturn(TelephonyManager.SIM_STATE_NOT_READY);
457         when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list);
458 
459         mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
460 
461         ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
462                 ArgumentCaptor.forClass(
463                         CarrierTextController.CarrierTextCallbackInfo.class);
464 
465         mCarrierTextController.updateCarrierText();
466         mTestableLooper.processAllMessages();
467         verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
468 
469         assertEquals(TEST_CARRIER,
470                 captor.getValue().carrierText);
471     }
472 
473     @Test
testCarrierText_firstDisabledSub()474     public void testCarrierText_firstDisabledSub() {
475         reset(mCarrierTextCallback);
476         List<SubscriptionInfo> list = new ArrayList<>();
477         list.add(TEST_SUBSCRIPTION);
478         list.add(TEST_SUBSCRIPTION);
479         when(mKeyguardUpdateMonitor.getSimState(anyInt()))
480                 .thenReturn(TelephonyManager.SIM_STATE_NOT_READY)
481                 .thenReturn(TelephonyManager.SIM_STATE_READY);
482         when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list);
483 
484         mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
485 
486         ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
487                 ArgumentCaptor.forClass(
488                         CarrierTextController.CarrierTextCallbackInfo.class);
489 
490         mCarrierTextController.updateCarrierText();
491         mTestableLooper.processAllMessages();
492         verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
493 
494         assertEquals(TEST_CARRIER,
495                 captor.getValue().carrierText);
496     }
497 
498     @Test
testCarrierText_threeSubsMiddleDisabled()499     public void testCarrierText_threeSubsMiddleDisabled() {
500         reset(mCarrierTextCallback);
501         List<SubscriptionInfo> list = new ArrayList<>();
502         list.add(TEST_SUBSCRIPTION);
503         list.add(TEST_SUBSCRIPTION);
504         list.add(TEST_SUBSCRIPTION);
505         when(mKeyguardUpdateMonitor.getSimState(anyInt()))
506                 .thenReturn(TelephonyManager.SIM_STATE_READY)
507                 .thenReturn(TelephonyManager.SIM_STATE_NOT_READY)
508                 .thenReturn(TelephonyManager.SIM_STATE_READY);
509         when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list);
510         mKeyguardUpdateMonitor.mServiceStates = new HashMap<>();
511 
512         ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor =
513                 ArgumentCaptor.forClass(
514                         CarrierTextController.CarrierTextCallbackInfo.class);
515 
516         mCarrierTextController.updateCarrierText();
517         mTestableLooper.processAllMessages();
518         verify(mCarrierTextCallback).updateCarrierInfo(captor.capture());
519 
520         assertEquals(TEST_CARRIER + SEPARATOR + TEST_CARRIER,
521                 captor.getValue().carrierText);
522     }
523 }
524