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"; |
Sooraj Sasindran | 0d45da7 | 2019-04-25 15:12:21 -0700 | [diff] [blame] | 73 | private static final int TEST_CARRIER_ID = 1; |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 74 | private static final SubscriptionInfo TEST_SUBSCRIPTION = new SubscriptionInfo(0, "", 0, |
| 75 | TEST_CARRIER, TEST_CARRIER, NAME_SOURCE_DEFAULT_SOURCE, 0xFFFFFF, "", |
Malcolm Chen | 5c63b51 | 2019-08-13 13:24:07 -0700 | [diff] [blame^] | 76 | DATA_ROAMING_DISABLE, null, null, null, null, false, null, "", false, null, |
Sooraj Sasindran | 0d45da7 | 2019-04-25 15:12:21 -0700 | [diff] [blame] | 77 | TEST_CARRIER_ID, 0); |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 78 | private static final SubscriptionInfo TEST_SUBSCRIPTION_ROAMING = new SubscriptionInfo(0, "", 0, |
| 79 | TEST_CARRIER, TEST_CARRIER, NAME_SOURCE_DEFAULT_SOURCE, 0xFFFFFF, "", |
| 80 | DATA_ROAMING_ENABLE, null, null, null, null, false, null, ""); |
| 81 | @Mock |
| 82 | private WifiManager mWifiManager; |
| 83 | @Mock |
| 84 | private CarrierTextController.CarrierTextCallback mCarrierTextCallback; |
| 85 | @Mock |
| 86 | private KeyguardUpdateMonitor mKeyguardUpdateMonitor; |
| 87 | @Mock |
| 88 | private ConnectivityManager mConnectivityManager; |
| 89 | @Mock |
| 90 | private TelephonyManager mTelephonyManager; |
Malcolm Chen | 06ec357 | 2019-04-09 15:55:29 -0700 | [diff] [blame] | 91 | @Mock |
| 92 | private SubscriptionManager mSubscriptionManager; |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 93 | private CarrierTextController.CarrierTextCallbackInfo mCarrierTextCallbackInfo; |
| 94 | |
| 95 | private CarrierTextController mCarrierTextController; |
| 96 | private TestableLooper mTestableLooper; |
| 97 | |
| 98 | @Before |
| 99 | public void setUp() { |
| 100 | MockitoAnnotations.initMocks(this); |
| 101 | mTestableLooper = TestableLooper.get(this); |
| 102 | |
| 103 | mContext.addMockSystemService(WifiManager.class, mWifiManager); |
| 104 | mContext.addMockSystemService(ConnectivityManager.class, mConnectivityManager); |
| 105 | mContext.addMockSystemService(TelephonyManager.class, mTelephonyManager); |
Malcolm Chen | 06ec357 | 2019-04-09 15:55:29 -0700 | [diff] [blame] | 106 | mContext.addMockSystemService(SubscriptionManager.class, mSubscriptionManager); |
Fabian Kozynski | c3d06f3 | 2019-07-31 14:18:41 -0400 | [diff] [blame] | 107 | mContext.getOrCreateTestableResources().addOverride( |
| 108 | R.string.keyguard_sim_error_message_short, INVALID_CARD_TEXT); |
| 109 | mContext.getOrCreateTestableResources().addOverride( |
| 110 | R.string.airplane_mode, AIRPLANE_MODE_TEXT); |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 111 | mDependency.injectMockDependency(WakefulnessLifecycle.class); |
| 112 | mDependency.injectTestDependency(Dependency.MAIN_HANDLER, |
| 113 | new Handler(mTestableLooper.getLooper())); |
| 114 | |
| 115 | mCarrierTextCallbackInfo = new CarrierTextController.CarrierTextCallbackInfo("", |
| 116 | new CharSequence[]{}, false, new int[]{}); |
Fabian Kozynski | 00d02f1 | 2019-04-15 09:48:30 -0400 | [diff] [blame] | 117 | when(mTelephonyManager.getPhoneCount()).thenReturn(3); |
| 118 | |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 119 | mCarrierTextController = new TestCarrierTextController(mContext, SEPARATOR, true, true, |
| 120 | mKeyguardUpdateMonitor); |
| 121 | // This should not start listening on any of the real dependencies |
| 122 | mCarrierTextController.setListening(mCarrierTextCallback); |
| 123 | } |
| 124 | |
| 125 | @Test |
Fabian Kozynski | c3d06f3 | 2019-07-31 14:18:41 -0400 | [diff] [blame] | 126 | public void testAirplaneMode() { |
| 127 | Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 1); |
| 128 | reset(mCarrierTextCallback); |
| 129 | List<SubscriptionInfo> list = new ArrayList<>(); |
| 130 | list.add(TEST_SUBSCRIPTION); |
Malcolm Chen | 5c63b51 | 2019-08-13 13:24:07 -0700 | [diff] [blame^] | 131 | when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list); |
Fabian Kozynski | c3d06f3 | 2019-07-31 14:18:41 -0400 | [diff] [blame] | 132 | when(mKeyguardUpdateMonitor.getSimState(0)).thenReturn(IccCardConstants.State.READY); |
| 133 | mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); |
| 134 | |
| 135 | mCarrierTextController.updateCarrierText(); |
| 136 | |
| 137 | ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor = |
| 138 | ArgumentCaptor.forClass( |
| 139 | CarrierTextController.CarrierTextCallbackInfo.class); |
| 140 | |
| 141 | mTestableLooper.processAllMessages(); |
| 142 | verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); |
| 143 | assertEquals(AIRPLANE_MODE_TEXT, captor.getValue().carrierText); |
| 144 | } |
| 145 | |
| 146 | @Test |
| 147 | public void testCardIOError() { |
| 148 | reset(mCarrierTextCallback); |
| 149 | List<SubscriptionInfo> list = new ArrayList<>(); |
| 150 | list.add(TEST_SUBSCRIPTION); |
Malcolm Chen | 5c63b51 | 2019-08-13 13:24:07 -0700 | [diff] [blame^] | 151 | when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list); |
Fabian Kozynski | c3d06f3 | 2019-07-31 14:18:41 -0400 | [diff] [blame] | 152 | when(mKeyguardUpdateMonitor.getSimState(0)).thenReturn(IccCardConstants.State.READY); |
| 153 | when(mKeyguardUpdateMonitor.getSimState(1)).thenReturn( |
| 154 | IccCardConstants.State.CARD_IO_ERROR); |
| 155 | mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); |
| 156 | |
| 157 | mCarrierTextController.mCallback.onSimStateChanged(3, 1, |
| 158 | IccCardConstants.State.CARD_IO_ERROR); |
| 159 | |
| 160 | ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor = |
| 161 | ArgumentCaptor.forClass( |
| 162 | CarrierTextController.CarrierTextCallbackInfo.class); |
| 163 | |
| 164 | mTestableLooper.processAllMessages(); |
| 165 | verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); |
| 166 | assertEquals("TEST_CARRIER" + SEPARATOR + INVALID_CARD_TEXT, captor.getValue().carrierText); |
| 167 | // There's only one subscription in the list |
| 168 | assertEquals(1, captor.getValue().listOfCarriers.length); |
| 169 | assertEquals(TEST_CARRIER, captor.getValue().listOfCarriers[0]); |
| 170 | } |
| 171 | |
| 172 | @Test |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 173 | public void testWrongSlots() { |
| 174 | reset(mCarrierTextCallback); |
Malcolm Chen | 5c63b51 | 2019-08-13 13:24:07 -0700 | [diff] [blame^] | 175 | when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn( |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 176 | new ArrayList<>()); |
| 177 | when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn( |
| 178 | IccCardConstants.State.CARD_IO_ERROR); |
| 179 | // This should not produce an out of bounds error, even though there are no subscriptions |
| 180 | mCarrierTextController.mCallback.onSimStateChanged(0, -3, |
| 181 | IccCardConstants.State.CARD_IO_ERROR); |
| 182 | mCarrierTextController.mCallback.onSimStateChanged(0, 3, IccCardConstants.State.READY); |
| 183 | verify(mCarrierTextCallback, never()).updateCarrierInfo(any()); |
| 184 | } |
| 185 | |
| 186 | @Test |
| 187 | public void testMoreSlotsThanSubs() { |
| 188 | reset(mCarrierTextCallback); |
Malcolm Chen | 5c63b51 | 2019-08-13 13:24:07 -0700 | [diff] [blame^] | 189 | when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn( |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 190 | new ArrayList<>()); |
Fabian Kozynski | 00d02f1 | 2019-04-15 09:48:30 -0400 | [diff] [blame] | 191 | |
| 192 | // STOPSHIP(b/130246708) This line makes sure that SubscriptionManager provides the |
| 193 | // same answer as KeyguardUpdateMonitor. Remove when this is addressed |
| 194 | when(mSubscriptionManager.getActiveSubscriptionInfoList(anyBoolean())).thenReturn( |
| 195 | new ArrayList<>()); |
| 196 | |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 197 | when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn( |
| 198 | IccCardConstants.State.CARD_IO_ERROR); |
| 199 | // This should not produce an out of bounds error, even though there are no subscriptions |
| 200 | mCarrierTextController.mCallback.onSimStateChanged(0, 1, |
| 201 | IccCardConstants.State.CARD_IO_ERROR); |
| 202 | |
| 203 | mTestableLooper.processAllMessages(); |
| 204 | verify(mCarrierTextCallback).updateCarrierInfo( |
| 205 | any(CarrierTextController.CarrierTextCallbackInfo.class)); |
| 206 | } |
| 207 | |
| 208 | @Test |
| 209 | public void testCallback() { |
| 210 | reset(mCarrierTextCallback); |
| 211 | mCarrierTextController.postToCallback(mCarrierTextCallbackInfo); |
| 212 | mTestableLooper.processAllMessages(); |
| 213 | |
| 214 | ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor = |
| 215 | ArgumentCaptor.forClass( |
| 216 | CarrierTextController.CarrierTextCallbackInfo.class); |
| 217 | verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); |
| 218 | assertEquals(mCarrierTextCallbackInfo, captor.getValue()); |
| 219 | } |
| 220 | |
| 221 | @Test |
| 222 | public void testNullingCallback() { |
| 223 | reset(mCarrierTextCallback); |
| 224 | |
| 225 | mCarrierTextController.postToCallback(mCarrierTextCallbackInfo); |
| 226 | mCarrierTextController.setListening(null); |
| 227 | |
| 228 | // This shouldn't produce NPE |
| 229 | mTestableLooper.processAllMessages(); |
| 230 | verify(mCarrierTextCallback).updateCarrierInfo(any()); |
| 231 | } |
| 232 | |
| 233 | @Test |
| 234 | public void testCreateInfo_OneValidSubscription() { |
| 235 | reset(mCarrierTextCallback); |
| 236 | List<SubscriptionInfo> list = new ArrayList<>(); |
| 237 | list.add(TEST_SUBSCRIPTION); |
| 238 | when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(IccCardConstants.State.READY); |
Malcolm Chen | 5c63b51 | 2019-08-13 13:24:07 -0700 | [diff] [blame^] | 239 | when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list); |
Fabian Kozynski | 00d02f1 | 2019-04-15 09:48:30 -0400 | [diff] [blame] | 240 | |
Bonian Chen | a7e9e8c | 2019-06-02 23:59:31 +0000 | [diff] [blame] | 241 | mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); |
| 242 | |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 243 | ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor = |
| 244 | ArgumentCaptor.forClass( |
| 245 | CarrierTextController.CarrierTextCallbackInfo.class); |
| 246 | |
| 247 | mCarrierTextController.updateCarrierText(); |
| 248 | mTestableLooper.processAllMessages(); |
| 249 | verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); |
| 250 | |
| 251 | CarrierTextController.CarrierTextCallbackInfo info = captor.getValue(); |
| 252 | assertEquals(1, info.listOfCarriers.length); |
| 253 | assertEquals(TEST_CARRIER, info.listOfCarriers[0]); |
| 254 | assertEquals(1, info.subscriptionIds.length); |
| 255 | } |
| 256 | |
| 257 | @Test |
| 258 | public void testCreateInfo_OneValidSubscriptionWithRoaming() { |
| 259 | reset(mCarrierTextCallback); |
| 260 | List<SubscriptionInfo> list = new ArrayList<>(); |
| 261 | list.add(TEST_SUBSCRIPTION_ROAMING); |
| 262 | when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(IccCardConstants.State.READY); |
Malcolm Chen | 5c63b51 | 2019-08-13 13:24:07 -0700 | [diff] [blame^] | 263 | when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list); |
Fabian Kozynski | 00d02f1 | 2019-04-15 09:48:30 -0400 | [diff] [blame] | 264 | |
Bonian Chen | a7e9e8c | 2019-06-02 23:59:31 +0000 | [diff] [blame] | 265 | mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); |
| 266 | |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 267 | ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor = |
| 268 | ArgumentCaptor.forClass( |
| 269 | CarrierTextController.CarrierTextCallbackInfo.class); |
| 270 | |
| 271 | mCarrierTextController.updateCarrierText(); |
| 272 | mTestableLooper.processAllMessages(); |
| 273 | verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); |
| 274 | |
| 275 | CarrierTextController.CarrierTextCallbackInfo info = captor.getValue(); |
| 276 | assertEquals(1, info.listOfCarriers.length); |
| 277 | assertTrue(info.listOfCarriers[0].toString().contains(TEST_CARRIER)); |
| 278 | assertEquals(1, info.subscriptionIds.length); |
| 279 | } |
| 280 | |
| 281 | @Test |
| 282 | public void testCreateInfo_noSubscriptions() { |
| 283 | reset(mCarrierTextCallback); |
Malcolm Chen | 5c63b51 | 2019-08-13 13:24:07 -0700 | [diff] [blame^] | 284 | when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn( |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 285 | new ArrayList<>()); |
Fabian Kozynski | 00d02f1 | 2019-04-15 09:48:30 -0400 | [diff] [blame] | 286 | |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 287 | ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor = |
| 288 | ArgumentCaptor.forClass( |
| 289 | CarrierTextController.CarrierTextCallbackInfo.class); |
| 290 | |
| 291 | mCarrierTextController.updateCarrierText(); |
| 292 | mTestableLooper.processAllMessages(); |
| 293 | verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); |
| 294 | |
| 295 | CarrierTextController.CarrierTextCallbackInfo info = captor.getValue(); |
| 296 | assertEquals(0, info.listOfCarriers.length); |
| 297 | assertEquals(0, info.subscriptionIds.length); |
| 298 | |
| 299 | } |
| 300 | |
Fabian Kozynski | 00d02f1 | 2019-04-15 09:48:30 -0400 | [diff] [blame] | 301 | @Test |
| 302 | public void testCarrierText_twoValidSubscriptions() { |
| 303 | reset(mCarrierTextCallback); |
| 304 | List<SubscriptionInfo> list = new ArrayList<>(); |
| 305 | list.add(TEST_SUBSCRIPTION); |
| 306 | list.add(TEST_SUBSCRIPTION); |
| 307 | when(mKeyguardUpdateMonitor.getSimState(anyInt())).thenReturn(IccCardConstants.State.READY); |
Malcolm Chen | 5c63b51 | 2019-08-13 13:24:07 -0700 | [diff] [blame^] | 308 | when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list); |
Fabian Kozynski | 00d02f1 | 2019-04-15 09:48:30 -0400 | [diff] [blame] | 309 | |
Bonian Chen | a7e9e8c | 2019-06-02 23:59:31 +0000 | [diff] [blame] | 310 | mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); |
| 311 | |
Fabian Kozynski | 00d02f1 | 2019-04-15 09:48:30 -0400 | [diff] [blame] | 312 | ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor = |
| 313 | ArgumentCaptor.forClass( |
| 314 | CarrierTextController.CarrierTextCallbackInfo.class); |
| 315 | |
| 316 | mCarrierTextController.updateCarrierText(); |
| 317 | mTestableLooper.processAllMessages(); |
| 318 | verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); |
| 319 | |
| 320 | assertEquals(TEST_CARRIER + SEPARATOR + TEST_CARRIER, |
| 321 | captor.getValue().carrierText); |
| 322 | } |
| 323 | |
| 324 | @Test |
| 325 | public void testCarrierText_oneDisabledSub() { |
| 326 | reset(mCarrierTextCallback); |
| 327 | List<SubscriptionInfo> list = new ArrayList<>(); |
| 328 | list.add(TEST_SUBSCRIPTION); |
| 329 | list.add(TEST_SUBSCRIPTION); |
| 330 | when(mKeyguardUpdateMonitor.getSimState(anyInt())) |
| 331 | .thenReturn(IccCardConstants.State.READY) |
| 332 | .thenReturn(IccCardConstants.State.NOT_READY); |
Malcolm Chen | 5c63b51 | 2019-08-13 13:24:07 -0700 | [diff] [blame^] | 333 | when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list); |
Fabian Kozynski | 00d02f1 | 2019-04-15 09:48:30 -0400 | [diff] [blame] | 334 | |
Bonian Chen | a7e9e8c | 2019-06-02 23:59:31 +0000 | [diff] [blame] | 335 | mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); |
| 336 | |
Fabian Kozynski | 00d02f1 | 2019-04-15 09:48:30 -0400 | [diff] [blame] | 337 | ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor = |
| 338 | ArgumentCaptor.forClass( |
| 339 | CarrierTextController.CarrierTextCallbackInfo.class); |
| 340 | |
| 341 | mCarrierTextController.updateCarrierText(); |
| 342 | mTestableLooper.processAllMessages(); |
| 343 | verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); |
| 344 | |
| 345 | assertEquals(TEST_CARRIER, |
| 346 | captor.getValue().carrierText); |
| 347 | } |
| 348 | |
| 349 | @Test |
| 350 | public void testCarrierText_firstDisabledSub() { |
| 351 | reset(mCarrierTextCallback); |
| 352 | List<SubscriptionInfo> list = new ArrayList<>(); |
| 353 | list.add(TEST_SUBSCRIPTION); |
| 354 | list.add(TEST_SUBSCRIPTION); |
| 355 | when(mKeyguardUpdateMonitor.getSimState(anyInt())) |
| 356 | .thenReturn(IccCardConstants.State.NOT_READY) |
| 357 | .thenReturn(IccCardConstants.State.READY); |
Malcolm Chen | 5c63b51 | 2019-08-13 13:24:07 -0700 | [diff] [blame^] | 358 | when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list); |
Fabian Kozynski | 00d02f1 | 2019-04-15 09:48:30 -0400 | [diff] [blame] | 359 | |
Bonian Chen | a7e9e8c | 2019-06-02 23:59:31 +0000 | [diff] [blame] | 360 | mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); |
| 361 | |
Fabian Kozynski | 00d02f1 | 2019-04-15 09:48:30 -0400 | [diff] [blame] | 362 | ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor = |
| 363 | ArgumentCaptor.forClass( |
| 364 | CarrierTextController.CarrierTextCallbackInfo.class); |
| 365 | |
| 366 | mCarrierTextController.updateCarrierText(); |
| 367 | mTestableLooper.processAllMessages(); |
| 368 | verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); |
| 369 | |
| 370 | assertEquals(TEST_CARRIER, |
| 371 | captor.getValue().carrierText); |
| 372 | } |
| 373 | |
| 374 | @Test |
| 375 | public void testCarrierText_threeSubsMiddleDisabled() { |
| 376 | reset(mCarrierTextCallback); |
| 377 | List<SubscriptionInfo> list = new ArrayList<>(); |
| 378 | list.add(TEST_SUBSCRIPTION); |
| 379 | list.add(TEST_SUBSCRIPTION); |
| 380 | list.add(TEST_SUBSCRIPTION); |
| 381 | when(mKeyguardUpdateMonitor.getSimState(anyInt())) |
| 382 | .thenReturn(IccCardConstants.State.READY) |
| 383 | .thenReturn(IccCardConstants.State.NOT_READY) |
| 384 | .thenReturn(IccCardConstants.State.READY); |
Malcolm Chen | 5c63b51 | 2019-08-13 13:24:07 -0700 | [diff] [blame^] | 385 | when(mKeyguardUpdateMonitor.getFilteredSubscriptionInfo(anyBoolean())).thenReturn(list); |
Bonian Chen | a7e9e8c | 2019-06-02 23:59:31 +0000 | [diff] [blame] | 386 | mKeyguardUpdateMonitor.mServiceStates = new HashMap<>(); |
Fabian Kozynski | 00d02f1 | 2019-04-15 09:48:30 -0400 | [diff] [blame] | 387 | |
Fabian Kozynski | 00d02f1 | 2019-04-15 09:48:30 -0400 | [diff] [blame] | 388 | ArgumentCaptor<CarrierTextController.CarrierTextCallbackInfo> captor = |
| 389 | ArgumentCaptor.forClass( |
| 390 | CarrierTextController.CarrierTextCallbackInfo.class); |
| 391 | |
| 392 | mCarrierTextController.updateCarrierText(); |
| 393 | mTestableLooper.processAllMessages(); |
| 394 | verify(mCarrierTextCallback).updateCarrierInfo(captor.capture()); |
| 395 | |
| 396 | assertEquals(TEST_CARRIER + SEPARATOR + TEST_CARRIER, |
| 397 | captor.getValue().carrierText); |
| 398 | } |
| 399 | |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 400 | public static class TestCarrierTextController extends CarrierTextController { |
| 401 | private KeyguardUpdateMonitor mKUM; |
| 402 | |
| 403 | public TestCarrierTextController(Context context, CharSequence separator, |
| 404 | boolean showAirplaneMode, boolean showMissingSim, KeyguardUpdateMonitor kum) { |
| 405 | super(context, separator, showAirplaneMode, showMissingSim); |
| 406 | mKUM = kum; |
| 407 | } |
| 408 | |
| 409 | @Override |
| 410 | public void setListening(CarrierTextCallback callback) { |
| 411 | super.setListening(callback); |
| 412 | mKeyguardUpdateMonitor = mKUM; |
| 413 | } |
Fabian Kozynski | b176f42 | 2019-02-05 09:36:59 -0500 | [diff] [blame] | 414 | } |
| 415 | } |