1 /* 2 * Copyright (C) 2017 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.internal.telephony; 18 19 import static android.telephony.TelephonyManager.HAL_SERVICE_DATA; 20 import static android.telephony.TelephonyManager.HAL_SERVICE_MODEM; 21 import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK; 22 import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO; 23 import static android.telephony.TelephonyManager.HAL_SERVICE_SIM; 24 25 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU; 26 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ALLOW_DATA; 27 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE; 28 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CDMA_SEND_SMS; 29 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CDMA_SEND_SMS_EXPECT_MORE; 30 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CHANGE_SIM_PIN; 31 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CHANGE_SIM_PIN2; 32 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CONFERENCE; 33 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_DATA_REGISTRATION_STATE; 34 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_DELETE_SMS_ON_SIM; 35 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_DEVICE_IMEI; 36 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_DTMF; 37 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ENABLE_UICC_APPLICATIONS; 38 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION; 39 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ENTER_SIM_DEPERSONALIZATION; 40 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ENTER_SIM_PIN; 41 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ENTER_SIM_PIN2; 42 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ENTER_SIM_PUK; 43 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ENTER_SIM_PUK2; 44 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE; 45 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_ACTIVITY_INFO; 46 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_BARRING_INFO; 47 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_CELL_INFO_LIST; 48 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_CURRENT_CALLS; 49 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_HARDWARE_CONFIG; 50 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_IMSI; 51 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_RADIO_CAPABILITY; 52 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_SIM_STATUS; 53 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_SLICING_CONFIG; 54 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_SMSC_ADDRESS; 55 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_UICC_APPLICATIONS_ENABLEMENT; 56 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_HANGUP; 57 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND; 58 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND; 59 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_IMS_SEND_SMS; 60 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_LAST_CALL_FAIL_CAUSE; 61 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_NV_READ_ITEM; 62 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_NV_RESET_CONFIG; 63 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_NV_WRITE_ITEM; 64 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_OPERATOR; 65 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_RADIO_POWER; 66 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_REPORT_SMS_MEMORY_STATUS; 67 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING; 68 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SEND_DEVICE_STATE; 69 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SEND_SMS; 70 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SEND_SMS_EXPECT_MORE; 71 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SETUP_DATA_CALL; 72 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_INITIAL_ATTACH_APN; 73 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_SIM_CARD_POWER; 74 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_SMSC_ADDRESS; 75 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER; 76 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE; 77 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SHUTDOWN; 78 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SIGNAL_STRENGTH; 79 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SIM_AUTHENTICATION; 80 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SIM_CLOSE_CHANNEL; 81 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SIM_OPEN_CHANNEL; 82 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_START_NETWORK_SCAN; 83 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM; 84 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE; 85 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_UDUB; 86 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_VOICE_RADIO_TECH; 87 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_VOICE_REGISTRATION_STATE; 88 import static com.android.internal.telephony.RILConstants.RIL_REQUEST_WRITE_SMS_TO_SIM; 89 90 import static junit.framework.Assert.assertEquals; 91 import static junit.framework.Assert.assertFalse; 92 import static junit.framework.Assert.assertNotNull; 93 import static junit.framework.Assert.assertNull; 94 import static junit.framework.Assert.assertTrue; 95 import static junit.framework.Assert.fail; 96 97 import static org.mockito.ArgumentMatchers.anyBoolean; 98 import static org.mockito.ArgumentMatchers.anyInt; 99 import static org.mockito.ArgumentMatchers.any; 100 import static org.mockito.ArgumentMatchers.eq; 101 import static org.mockito.Mockito.atLeast; 102 import static org.mockito.Mockito.doReturn; 103 import static org.mockito.Mockito.doThrow; 104 import static org.mockito.Mockito.mock; 105 import static org.mockito.Mockito.never; 106 import static org.mockito.Mockito.spy; 107 import static org.mockito.Mockito.times; 108 import static org.mockito.Mockito.verify; 109 import static org.mockito.Mockito.when; 110 111 import android.content.Context; 112 import android.content.pm.ApplicationInfo; 113 import android.hardware.radio.V1_0.Carrier; 114 import android.hardware.radio.V1_0.CdmaSmsMessage; 115 import android.hardware.radio.V1_0.GsmSmsMessage; 116 import android.hardware.radio.V1_0.ImsSmsMessage; 117 import android.hardware.radio.V1_0.NvWriteItem; 118 import android.hardware.radio.V1_0.RadioError; 119 import android.hardware.radio.V1_0.RadioResponseInfo; 120 import android.hardware.radio.V1_0.RadioResponseType; 121 import android.hardware.radio.V1_0.RadioTechnologyFamily; 122 import android.hardware.radio.V1_0.SmsWriteArgs; 123 import android.hardware.radio.V1_6.IRadio; 124 import android.net.ConnectivityManager; 125 import android.net.InetAddresses; 126 import android.net.LinkAddress; 127 import android.os.AsyncResult; 128 import android.os.Handler; 129 import android.os.HandlerThread; 130 import android.os.IPowerManager; 131 import android.os.IThermalService; 132 import android.os.Looper; 133 import android.os.Message; 134 import android.os.PowerManager; 135 import android.os.RemoteException; 136 import android.os.WorkSource; 137 import android.service.carrier.CarrierIdentifier; 138 import android.telephony.AccessNetworkConstants; 139 import android.telephony.CellConfigLte; 140 import android.telephony.CellIdentityCdma; 141 import android.telephony.CellIdentityGsm; 142 import android.telephony.CellIdentityLte; 143 import android.telephony.CellIdentityNr; 144 import android.telephony.CellIdentityTdscdma; 145 import android.telephony.CellIdentityWcdma; 146 import android.telephony.CellInfo; 147 import android.telephony.CellInfoCdma; 148 import android.telephony.CellInfoGsm; 149 import android.telephony.CellInfoLte; 150 import android.telephony.CellInfoNr; 151 import android.telephony.CellInfoTdscdma; 152 import android.telephony.CellInfoWcdma; 153 import android.telephony.CellSignalStrengthCdma; 154 import android.telephony.CellSignalStrengthGsm; 155 import android.telephony.CellSignalStrengthLte; 156 import android.telephony.CellSignalStrengthNr; 157 import android.telephony.CellSignalStrengthTdscdma; 158 import android.telephony.CellSignalStrengthWcdma; 159 import android.telephony.ClosedSubscriberGroupInfo; 160 import android.telephony.NetworkScanRequest; 161 import android.telephony.RadioAccessFamily; 162 import android.telephony.RadioAccessSpecifier; 163 import android.telephony.SmsManager; 164 import android.telephony.TelephonyManager; 165 import android.telephony.data.ApnSetting; 166 import android.telephony.data.DataCallResponse; 167 import android.telephony.data.DataProfile; 168 import android.telephony.data.EpsQos; 169 import android.telephony.data.Qos; 170 import android.telephony.data.QosBearerFilter; 171 import android.telephony.data.QosBearerSession; 172 import android.telephony.data.TrafficDescriptor; 173 import android.testing.AndroidTestingRunner; 174 import android.testing.TestableLooper; 175 import android.util.SparseArray; 176 import android.view.Display; 177 178 import androidx.test.filters.FlakyTest; 179 180 import com.android.internal.telephony.uicc.IccCardApplicationStatus.PersoSubState; 181 182 import org.junit.After; 183 import org.junit.Assert; 184 import org.junit.Before; 185 import org.junit.Test; 186 import org.junit.runner.RunWith; 187 import org.mockito.ArgumentCaptor; 188 189 import java.io.ByteArrayInputStream; 190 import java.io.DataInputStream; 191 import java.io.IOException; 192 import java.util.ArrayList; 193 import java.util.Arrays; 194 import java.util.Collections; 195 import java.util.HashMap; 196 import java.util.HashSet; 197 import java.util.List; 198 import java.util.Map; 199 import java.util.Set; 200 import java.util.concurrent.CountDownLatch; 201 import java.util.concurrent.TimeUnit; 202 import java.util.function.Consumer; 203 204 @RunWith(AndroidTestingRunner.class) 205 @TestableLooper.RunWithLooper 206 public class RILTest extends TelephonyTest { 207 208 // refer to RIL#DEFAULT_BLOCKING_MESSAGE_RESPONSE_TIMEOUT_MS 209 private static final int DEFAULT_BLOCKING_MESSAGE_RESPONSE_TIMEOUT_MS = 2000; 210 211 // refer to RIL#DEFAULT_WAKE_LOCK_TIMEOUT_MS 212 private static final int DEFAULT_WAKE_LOCK_TIMEOUT_MS = 60000; 213 214 // Mocked classes 215 private ConnectivityManager mConnectionManager; 216 private TelephonyManager mTelephonyManager; 217 private IRadio mRadioProxy; 218 private RadioDataProxy mDataProxy; 219 private RadioNetworkProxy mNetworkProxy; 220 private RadioSimProxy mSimProxy; 221 private RadioModemProxy mRadioModemProxy; 222 223 private Map<Integer, HalVersion> mHalVersionV14 = new HashMap<>(); 224 private Map<Integer, HalVersion> mHalVersionV15 = new HashMap<>(); 225 private Map<Integer, HalVersion> mHalVersionV16 = new HashMap<>(); 226 private Map<Integer, HalVersion> mHalVersionV20 = new HashMap<>(); 227 private Map<Integer, HalVersion> mHalVersionV21 = new HashMap<>(); 228 229 private RIL mRILInstance; 230 private RIL mRILUnderTest; 231 ArgumentCaptor<Integer> mSerialNumberCaptor = ArgumentCaptor.forClass(Integer.class); 232 233 // Constants 234 private static final String ALPHA_LONG = "long"; 235 private static final String ALPHA_SHORT = "short"; 236 private static final int ARFCN = 690; 237 private static final int BASESTATION_ID = 65531; 238 private static final int BIT_ERROR_RATE = 99; 239 private static final int BSIC = 8; 240 private static final int CI = 268435456; 241 private static final int CID = 65535; 242 private static final int CQI = 2147483647; 243 private static final int CQI_TABLE_INDEX = 1; 244 private static final int DBM = -74; 245 private static final int EARFCN = 262140; 246 private static final ArrayList<Integer> BANDS = new ArrayList<>(Arrays.asList(1, 2)); 247 private static final int BANDWIDTH = 5000; 248 private static final int ECIO = -124; 249 private static final int LAC = 65535; 250 private static final int LATITUDE = 1292000; 251 private static final int LONGITUDE = 1295000; 252 private static final String MCC_STR = "120"; 253 private static final String MNC_STR = "260"; 254 private static final int NETWORK_ID = 65534; 255 private static final int NRARFCN = 3279165; 256 private static final int PCI = 503; 257 private static final int PSC = 500; 258 private static final int RSSNR = CellInfo.UNAVAILABLE; 259 private static final int RSRP = -96; 260 private static final int RSRQ = -10; 261 private static final int RSCP = -94; 262 private static final int RSCP_ASU = 26; 263 private static final int ECNO = -21; 264 private static final int ECNO_ASU = 6; 265 private static final int SIGNAL_NOISE_RATIO = 6; 266 private static final int RSSI = -65; 267 private static final int RSSI_ASU = 24; 268 private static final int SYSTEM_ID = 65533; 269 private static final int TAC = 65535; 270 private static final int TIMING_ADVANCE = 4; 271 private static final long TIMESTAMP = 215924934; 272 private static final int UARFCN = 690; 273 private static final int CONNECTION_STATUS = CellInfo.CONNECTION_NONE; 274 private static final boolean ENDC_AVAILABLE = true; 275 private static final boolean REGISTERED = true; 276 277 private static final int PROFILE_ID = 0; 278 private static final String APN = "apn"; 279 private static final int PROTOCOL = ApnSetting.PROTOCOL_IPV6; 280 private static final int AUTH_TYPE = 0; 281 private static final String USER_NAME = "username"; 282 private static final String PASSWORD = "password"; 283 private static final int TYPE = DataProfile.TYPE_3GPP; 284 private static final boolean APN_ENABLED = true; 285 private static final int SUPPORTED_APN_TYPES_BITMASK = ApnSetting.TYPE_CBS 286 | ApnSetting.TYPE_IMS; 287 private static final int SUPPORTED_NETWORK_TYPES_BITMASK = 288 (int) (TelephonyManager.NETWORK_TYPE_BITMASK_UMTS 289 | TelephonyManager.NETWORK_TYPE_BITMASK_LTE); 290 private static final int ROAMING_PROTOCOL = ApnSetting.PROTOCOL_IPV6; 291 private static final int MTU = 1234; 292 293 private static final String[] ADDITIONAL_PLMNS = new String[] {"00101", "001001", "12345"}; 294 295 private static final boolean CSG_INDICATION = true; 296 private static final String HOME_NODEB_NAME = "Android Network"; 297 private static final int CSG_IDENTITY = 0xC0FFEE; 298 299 @Before setUp()300 public void setUp() throws Exception { 301 super.setUp(getClass().getSimpleName()); 302 mConnectionManager = mock(ConnectivityManager.class); 303 mTelephonyManager = mock(TelephonyManager.class); 304 mRadioProxy = mock(IRadio.class); 305 mDataProxy = mock(RadioDataProxy.class); 306 mNetworkProxy = mock(RadioNetworkProxy.class); 307 mSimProxy = mock(RadioSimProxy.class); 308 mRadioModemProxy = mock(RadioModemProxy.class); 309 try { 310 TelephonyDevController.create(); 311 } catch (RuntimeException e) { 312 } 313 Context context = new ContextFixture().getTestDouble(); 314 doReturn(Display.DEFAULT_DISPLAY).when(context).getDisplayId(); 315 doReturn(true).when(mConnectionManager).isNetworkSupported(ConnectivityManager.TYPE_MOBILE); 316 doReturn(mConnectionManager).when(context) 317 .getSystemService(Context.CONNECTIVITY_SERVICE); 318 doReturn(mTelephonyManager).when(context) 319 .getSystemService(Context.TELEPHONY_SERVICE); 320 doReturn(true).when(mTelephonyManager).isDataCapable(); 321 PowerManager powerManager = new PowerManager(context, mock(IPowerManager.class), 322 mock(IThermalService.class), new Handler(Looper.myLooper())); 323 doReturn(powerManager).when(context).getSystemService(Context.POWER_SERVICE); 324 doReturn(new ApplicationInfo()).when(context).getApplicationInfo(); 325 SparseArray<RadioServiceProxy> proxies = new SparseArray<>(); 326 proxies.put(HAL_SERVICE_RADIO, null); 327 proxies.put(HAL_SERVICE_DATA, mDataProxy); 328 proxies.put(HAL_SERVICE_NETWORK, mNetworkProxy); 329 proxies.put(HAL_SERVICE_SIM, mSimProxy); 330 proxies.put(HAL_SERVICE_MODEM, mRadioModemProxy); 331 mRILInstance = new RIL(context, 332 RadioAccessFamily.getRafFromNetworkType(RILConstants.PREFERRED_NETWORK_MODE), 333 Phone.PREFERRED_CDMA_SUBSCRIPTION, 0, proxies, mFeatureFlags); 334 mRILUnderTest = spy(mRILInstance); 335 doReturn(mRadioProxy).when(mRILUnderTest).getRadioProxy(); 336 doReturn(mDataProxy).when(mRILUnderTest).getRadioServiceProxy(eq(RadioDataProxy.class)); 337 doReturn(mNetworkProxy).when(mRILUnderTest).getRadioServiceProxy( 338 eq(RadioNetworkProxy.class)); 339 doReturn(mSimProxy).when(mRILUnderTest).getRadioServiceProxy(eq(RadioSimProxy.class)); 340 doReturn(mRadioModemProxy).when(mRILUnderTest).getRadioServiceProxy( 341 eq(RadioModemProxy.class)); 342 doReturn(false).when(mDataProxy).isEmpty(); 343 doReturn(false).when(mNetworkProxy).isEmpty(); 344 doReturn(false).when(mSimProxy).isEmpty(); 345 doReturn(false).when(mRadioModemProxy).isEmpty(); 346 try { 347 for (int service = RIL.MIN_SERVICE_IDX; service <= RIL.MAX_SERVICE_IDX; service++) { 348 mHalVersionV14.put(service, new HalVersion(1, 4)); 349 mHalVersionV15.put(service, new HalVersion(1, 5)); 350 mHalVersionV16.put(service, new HalVersion(1, 6)); 351 mHalVersionV20.put(service, new HalVersion(2, 0)); 352 mHalVersionV21.put(service, new HalVersion(2, 1)); 353 } 354 replaceInstance(RIL.class, "mHalVersion", mRILUnderTest, mHalVersionV14); 355 } catch (Exception e) { 356 } 357 } 358 359 @After tearDown()360 public void tearDown() throws Exception { 361 if (mRILUnderTest != null) { 362 mRILUnderTest.mWakeLock.release(); 363 mRILUnderTest.mAckWakeLock.release(); 364 mRILUnderTest = null; 365 } 366 mRILInstance = null; 367 super.tearDown(); 368 } 369 370 @Test testRadioErrorWithWakelockTimeout()371 public void testRadioErrorWithWakelockTimeout() { 372 RadioBugDetector detector = mRILUnderTest.getRadioBugDetector(); 373 int wakelockTimeoutThreshold = detector.getWakelockTimeoutThreshold(); 374 for (int i = 0; i < wakelockTimeoutThreshold; i++) { 375 invokeMethod( 376 mRILInstance, 377 "obtainRequest", 378 new Class<?>[]{Integer.TYPE, Message.class, WorkSource.class}, 379 new Object[]{RIL_REQUEST_GET_SIM_STATUS, obtainMessage(), new WorkSource()}); 380 } 381 moveTimeForward(DEFAULT_WAKE_LOCK_TIMEOUT_MS); 382 processAllMessages(); 383 assertTrue(1 == detector.getWakelockTimoutCount()); 384 } 385 386 @FlakyTest 387 @Test testRadioErrorWithContinuousSystemErr()388 public void testRadioErrorWithContinuousSystemErr() throws Exception { 389 RadioBugDetector detector = mRILUnderTest.getRadioBugDetector(); 390 int systemErrorThreshold = detector.getSystemErrorThreshold(); 391 for (int i = 0; i < systemErrorThreshold; i++) { 392 mRILUnderTest.getIccCardStatus(obtainMessage()); 393 verify(mRadioProxy, atLeast(1)).getIccCardStatus(mSerialNumberCaptor.capture()); 394 verifyRILErrorResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), 395 RIL_REQUEST_GET_SIM_STATUS, RadioError.SYSTEM_ERR); 396 } 397 398 int status = detector.getRadioBugStatus(); 399 assertTrue(status == RadioBugDetector.RADIO_BUG_REPETITIVE_SYSTEM_ERROR); 400 } 401 402 @FlakyTest 403 @Test testGetIccCardStatus()404 public void testGetIccCardStatus() throws Exception { 405 mRILUnderTest.getIccCardStatus(obtainMessage()); 406 verify(mRadioProxy).getIccCardStatus(mSerialNumberCaptor.capture()); 407 verifyRILResponse( 408 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_GET_SIM_STATUS); 409 } 410 411 @FlakyTest 412 @Test testSupplyIccPinForApp()413 public void testSupplyIccPinForApp() throws Exception { 414 String pin = "1234"; 415 String aid = "2345"; 416 mRILUnderTest.supplyIccPinForApp(pin, aid, obtainMessage()); 417 verify(mRadioProxy).supplyIccPinForApp(mSerialNumberCaptor.capture(), eq(pin), eq(aid)); 418 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_ENTER_SIM_PIN); 419 } 420 421 @FlakyTest 422 @Test testSupplyIccPukForApp()423 public void testSupplyIccPukForApp() throws Exception { 424 String puk = "pukcode"; 425 String newPin = "1314"; 426 String aid = "2345"; 427 mRILUnderTest.supplyIccPukForApp(puk, newPin, aid, obtainMessage()); 428 verify(mRadioProxy) 429 .supplyIccPukForApp(mSerialNumberCaptor.capture(), eq(puk), eq(newPin), eq(aid)); 430 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_ENTER_SIM_PUK); 431 } 432 433 @FlakyTest 434 @Test testSupplyIccPin2ForApp()435 public void testSupplyIccPin2ForApp() throws Exception { 436 String pin = "1234"; 437 String aid = "2345"; 438 mRILUnderTest.supplyIccPin2ForApp(pin, aid, obtainMessage()); 439 verify(mRadioProxy).supplyIccPin2ForApp( 440 mSerialNumberCaptor.capture(), eq(pin), eq(aid)); 441 verifyRILResponse( 442 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_ENTER_SIM_PIN2); 443 } 444 445 @FlakyTest 446 @Test testSupplyIccPuk2ForApp()447 public void testSupplyIccPuk2ForApp() throws Exception { 448 String puk = "pukcode"; 449 String newPin = "1314"; 450 String aid = "2345"; 451 mRILUnderTest.supplyIccPuk2ForApp(puk, newPin, aid, obtainMessage()); 452 verify(mRadioProxy) 453 .supplyIccPuk2ForApp(mSerialNumberCaptor.capture(), eq(puk), eq(newPin), eq(aid)); 454 verifyRILResponse( 455 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_ENTER_SIM_PUK2); 456 } 457 458 @FlakyTest 459 @Test testChangeIccPinForApp()460 public void testChangeIccPinForApp() throws Exception { 461 String oldPin = "1234"; 462 String newPin = "1314"; 463 String aid = "2345"; 464 mRILUnderTest.changeIccPinForApp(oldPin, newPin, aid, obtainMessage()); 465 verify(mRadioProxy).changeIccPinForApp( 466 mSerialNumberCaptor.capture(), eq(oldPin), eq(newPin), eq(aid)); 467 verifyRILResponse( 468 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_CHANGE_SIM_PIN); 469 } 470 471 @FlakyTest 472 @Test testChangeIccPin2ForApp()473 public void testChangeIccPin2ForApp() throws Exception { 474 String oldPin2 = "1234"; 475 String newPin2 = "1314"; 476 String aid = "2345"; 477 mRILUnderTest.changeIccPin2ForApp(oldPin2, newPin2, aid, obtainMessage()); 478 verify(mRadioProxy).changeIccPin2ForApp( 479 mSerialNumberCaptor.capture(), eq(oldPin2), eq(newPin2), eq(aid)); 480 verifyRILResponse( 481 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_CHANGE_SIM_PIN2); 482 } 483 484 @FlakyTest 485 @Test testSupplyNetworkDepersonalization()486 public void testSupplyNetworkDepersonalization() throws Exception { 487 String netpin = "1234"; 488 mRILUnderTest.supplyNetworkDepersonalization(netpin, obtainMessage()); 489 verify(mRadioProxy).supplyNetworkDepersonalization( 490 mSerialNumberCaptor.capture(), eq(netpin)); 491 verifyRILResponse( 492 mRILUnderTest, 493 mSerialNumberCaptor.getValue(), 494 RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION); 495 } 496 497 @FlakyTest 498 @Test testSupplySimDepersonalization()499 public void testSupplySimDepersonalization() throws Exception { 500 String controlKey = "1234"; 501 PersoSubState persoType = PersoSubState.PERSOSUBSTATE_SIM_NETWORK_PUK; 502 503 // Not supported on Radio 1.0. 504 mRILUnderTest.supplySimDepersonalization(persoType, controlKey, obtainMessage()); 505 verify(mRadioProxy, never()).supplySimDepersonalization(anyInt(), anyInt(), eq(controlKey)); 506 verify(mRadioProxy, never()).supplyNetworkDepersonalization( 507 anyInt(), eq(controlKey)); 508 509 // Make radio version 1.5 to support the operation. 510 try { 511 replaceInstance(RIL.class, "mHalVersion", mRILUnderTest, mHalVersionV15); 512 } catch (Exception e) { 513 } 514 515 mRILUnderTest.supplySimDepersonalization(persoType, controlKey, obtainMessage()); 516 verify(mRadioProxy).supplySimDepersonalization( 517 mSerialNumberCaptor.capture(), 518 RILUtils.convertToHalPersoType(persoType), 519 eq(controlKey)); 520 verifyRILResponse( 521 mRILUnderTest, 522 mSerialNumberCaptor.getValue(), 523 RIL_REQUEST_ENTER_SIM_DEPERSONALIZATION); 524 } 525 526 @FlakyTest 527 @Test testSupplySimDepersonalizationWithNetworkLock()528 public void testSupplySimDepersonalizationWithNetworkLock() throws Exception { 529 530 String controlKey = "1234"; 531 PersoSubState persoType = PersoSubState.PERSOSUBSTATE_SIM_NETWORK; 532 533 // use supplyNetworkDepersonalization on Radio 1.0. 534 mRILUnderTest.supplySimDepersonalization(persoType, controlKey, obtainMessage()); 535 verify(mRadioProxy, never()).supplySimDepersonalization(anyInt(), anyInt(), eq(controlKey)); 536 verify(mRadioProxy).supplyNetworkDepersonalization( 537 mSerialNumberCaptor.capture(), eq(controlKey)); 538 verifyRILResponse( 539 mRILUnderTest, 540 mSerialNumberCaptor.getValue(), 541 RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION); 542 543 // Make radio version 1.5 to support the operation. 544 try { 545 replaceInstance(RIL.class, "mHalVersion", mRILUnderTest, mHalVersionV15); 546 } catch (Exception e) { 547 } 548 549 mRILUnderTest.supplySimDepersonalization(persoType, controlKey, obtainMessage()); 550 verify(mRadioProxy).supplySimDepersonalization( 551 mSerialNumberCaptor.capture(), 552 RILUtils.convertToHalPersoType(persoType), 553 eq(controlKey)); 554 verifyRILResponse( 555 mRILUnderTest, 556 mSerialNumberCaptor.getValue(), 557 RIL_REQUEST_ENTER_SIM_DEPERSONALIZATION); 558 } 559 560 @FlakyTest 561 @Test testGetCurrentCalls()562 public void testGetCurrentCalls() throws Exception { 563 mRILUnderTest.getCurrentCalls(obtainMessage()); 564 verify(mRadioProxy).getCurrentCalls(mSerialNumberCaptor.capture()); 565 verifyRILResponse( 566 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_GET_CURRENT_CALLS); 567 } 568 569 @FlakyTest 570 @Test testGetIMSIForApp()571 public void testGetIMSIForApp() throws Exception { 572 String aid = "1234"; 573 mRILUnderTest.getIMSIForApp(aid, obtainMessage()); 574 verify(mRadioProxy).getImsiForApp(mSerialNumberCaptor.capture(), eq(aid)); 575 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_GET_IMSI); 576 } 577 578 @FlakyTest 579 @Test testHangupWaitingOrBackground()580 public void testHangupWaitingOrBackground() throws Exception { 581 mRILUnderTest.hangupWaitingOrBackground(obtainMessage()); 582 verify(mRadioProxy).hangupWaitingOrBackground(mSerialNumberCaptor.capture()); 583 verifyRILResponse( 584 mRILUnderTest, 585 mSerialNumberCaptor.getValue(), 586 RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND); 587 } 588 589 @FlakyTest 590 @Test testHangupForegroundResumeBackground()591 public void testHangupForegroundResumeBackground() throws Exception { 592 mRILUnderTest.hangupForegroundResumeBackground(obtainMessage()); 593 verify(mRadioProxy).hangupForegroundResumeBackground(mSerialNumberCaptor.capture()); 594 verifyRILResponse( 595 mRILUnderTest, 596 mSerialNumberCaptor.getValue(), 597 RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND); 598 } 599 600 @FlakyTest 601 @Test testHangupConnection()602 public void testHangupConnection() throws Exception { 603 int gsmIndex = 0; 604 mRILUnderTest.hangupConnection(gsmIndex, obtainMessage()); 605 verify(mRadioProxy).hangup(mSerialNumberCaptor.capture(), eq(gsmIndex)); 606 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_HANGUP); 607 } 608 609 @FlakyTest 610 @Test testSwitchWaitingOrHoldingAndActive()611 public void testSwitchWaitingOrHoldingAndActive() throws Exception { 612 mRILUnderTest.switchWaitingOrHoldingAndActive(obtainMessage()); 613 verify(mRadioProxy).switchWaitingOrHoldingAndActive(mSerialNumberCaptor.capture()); 614 verifyRILResponse( 615 mRILUnderTest, 616 mSerialNumberCaptor.getValue(), 617 RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE); 618 } 619 620 @FlakyTest 621 @Test testConference()622 public void testConference() throws Exception { 623 mRILUnderTest.conference(obtainMessage()); 624 verify(mRadioProxy).conference(mSerialNumberCaptor.capture()); 625 verifyRILResponse( 626 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_CONFERENCE); 627 } 628 629 @FlakyTest 630 @Test testRejectCall()631 public void testRejectCall() throws Exception { 632 mRILUnderTest.rejectCall(obtainMessage()); 633 verify(mRadioProxy).rejectCall(mSerialNumberCaptor.capture()); 634 verifyRILResponse( 635 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_UDUB); 636 } 637 638 @FlakyTest 639 @Test testGetLastCallFailCause()640 public void testGetLastCallFailCause() throws Exception { 641 mRILUnderTest.getLastCallFailCause(obtainMessage()); 642 verify(mRadioProxy).getLastCallFailCause(mSerialNumberCaptor.capture()); 643 verifyRILResponse( 644 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_LAST_CALL_FAIL_CAUSE); 645 } 646 647 @FlakyTest 648 @Test testGetSignalStrength()649 public void testGetSignalStrength() throws Exception { 650 mRILUnderTest.getSignalStrength(obtainMessage()); 651 verify(mRadioProxy).getSignalStrength(mSerialNumberCaptor.capture()); 652 verifyRILResponse( 653 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SIGNAL_STRENGTH); 654 } 655 656 @FlakyTest 657 @Test testGetVoiceRegistrationState()658 public void testGetVoiceRegistrationState() throws Exception { 659 mRILUnderTest.getVoiceRegistrationState(obtainMessage()); 660 verify(mRadioProxy).getVoiceRegistrationState(mSerialNumberCaptor.capture()); 661 verifyRILResponse( 662 mRILUnderTest, 663 mSerialNumberCaptor.getValue(), 664 RIL_REQUEST_VOICE_REGISTRATION_STATE); 665 } 666 getRadioAccessSpecifier(CellInfo cellInfo)667 private RadioAccessSpecifier getRadioAccessSpecifier(CellInfo cellInfo) { 668 RadioAccessSpecifier ras; 669 if (cellInfo instanceof CellInfoLte) { 670 int ranLte = AccessNetworkConstants.AccessNetworkType.EUTRAN; 671 int[] lteChannels = {((CellInfoLte) cellInfo).getCellIdentity().getEarfcn()}; 672 ras = new RadioAccessSpecifier(ranLte, null /* bands */, lteChannels); 673 } else if (cellInfo instanceof CellInfoWcdma) { 674 int ranLte = AccessNetworkConstants.AccessNetworkType.UTRAN; 675 int[] wcdmaChannels = {((CellInfoWcdma) cellInfo).getCellIdentity().getUarfcn()}; 676 ras = new RadioAccessSpecifier(ranLte, null /* bands */, wcdmaChannels); 677 } else if (cellInfo instanceof CellInfoGsm) { 678 int ranGsm = AccessNetworkConstants.AccessNetworkType.GERAN; 679 int[] gsmChannels = {((CellInfoGsm) cellInfo).getCellIdentity().getArfcn()}; 680 ras = new RadioAccessSpecifier(ranGsm, null /* bands */, gsmChannels); 681 } else { 682 ras = null; 683 } 684 return ras; 685 } 686 getNetworkScanRequestForTesting()687 private NetworkScanRequest getNetworkScanRequestForTesting() { 688 // Construct a NetworkScanRequest for testing 689 List<CellInfo> allCellInfo = mTelephonyManager.getAllCellInfo(); 690 List<RadioAccessSpecifier> radioAccessSpecifier = new ArrayList<>(); 691 for (int i = 0; i < allCellInfo.size(); i++) { 692 RadioAccessSpecifier ras = getRadioAccessSpecifier(allCellInfo.get(i)); 693 if (ras != null) { 694 radioAccessSpecifier.add(ras); 695 } 696 } 697 if (radioAccessSpecifier.size() == 0) { 698 RadioAccessSpecifier gsm = new RadioAccessSpecifier( 699 AccessNetworkConstants.AccessNetworkType.GERAN, 700 null /* bands */, 701 null /* channels */); 702 radioAccessSpecifier.add(gsm); 703 } 704 RadioAccessSpecifier[] radioAccessSpecifierArray = 705 new RadioAccessSpecifier[radioAccessSpecifier.size()]; 706 return new NetworkScanRequest( 707 NetworkScanRequest.SCAN_TYPE_ONE_SHOT /* scan type */, 708 radioAccessSpecifier.toArray(radioAccessSpecifierArray), 709 5 /* search periodicity */, 710 60 /* max search time */, 711 true /*enable incremental results*/, 712 5 /* incremental results periodicity */, 713 null /* List of PLMN ids (MCC-MNC) */); 714 } 715 716 @FlakyTest 717 @Test testStartNetworkScanWithUnsupportedResponse()718 public void testStartNetworkScanWithUnsupportedResponse() throws Exception { 719 // Use Radio HAL v1.5 720 try { 721 replaceInstance(RIL.class, "mHalVersion", mRILUnderTest, mHalVersionV15); 722 } catch (Exception e) { 723 } 724 NetworkScanRequest nsr = getNetworkScanRequestForTesting(); 725 mRILUnderTest.startNetworkScan(nsr, obtainMessage()); 726 727 // Verify the v1.5 HAL methed is called firstly 728 verify(mRadioProxy).startNetworkScan_1_5(mSerialNumberCaptor.capture(), any()); 729 730 // Before we find a way to trigger real RadioResponse method, emulate the behaivor. 731 Consumer<RILRequest> unsupportedResponseEmulator = rr -> { 732 mRILUnderTest.setCompatVersion(rr.getRequest(), RIL.RADIO_HAL_VERSION_1_4); 733 mRILUnderTest.startNetworkScan(nsr, Message.obtain(rr.getResult())); 734 }; 735 736 verifyRILUnsupportedResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), 737 RIL_REQUEST_START_NETWORK_SCAN, unsupportedResponseEmulator); 738 739 // Verify the fallback method is invoked 740 verify(mRadioProxy).startNetworkScan_1_4(eq(mSerialNumberCaptor.getValue() + 1), any()); 741 } 742 743 @FlakyTest 744 @Test testGetVoiceRegistrationStateWithUnsupportedResponse()745 public void testGetVoiceRegistrationStateWithUnsupportedResponse() throws Exception { 746 // Use Radio HAL v1.5 747 try { 748 replaceInstance(RIL.class, "mHalVersion", mRILUnderTest, mHalVersionV15); 749 } catch (Exception e) { 750 } 751 mRILUnderTest.getVoiceRegistrationState(obtainMessage()); 752 753 // Verify the v1.5 HAL method is called 754 verify(mRadioProxy).getVoiceRegistrationState_1_5(mSerialNumberCaptor.capture()); 755 756 // Before we find a way to trigger real RadioResponse method, emulate the behaivor. 757 Consumer<RILRequest> unsupportedResponseEmulator = rr -> { 758 mRILUnderTest.setCompatVersion(rr.getRequest(), RIL.RADIO_HAL_VERSION_1_4); 759 mRILUnderTest.getVoiceRegistrationState(Message.obtain(rr.getResult())); 760 }; 761 762 verifyRILUnsupportedResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), 763 RIL_REQUEST_VOICE_REGISTRATION_STATE, unsupportedResponseEmulator); 764 765 // Verify the fallback method is invoked 766 verify(mRadioProxy).getVoiceRegistrationState(mSerialNumberCaptor.getValue() + 1); 767 } 768 769 @FlakyTest 770 @Test testGetDataRegistrationState()771 public void testGetDataRegistrationState() throws Exception { 772 mRILUnderTest.getDataRegistrationState(obtainMessage()); 773 verify(mRadioProxy).getDataRegistrationState(mSerialNumberCaptor.capture()); 774 verifyRILResponse( 775 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_DATA_REGISTRATION_STATE); 776 } 777 778 @FlakyTest 779 @Test testGetDataRegistrationStateWithUnsupportedResponse()780 public void testGetDataRegistrationStateWithUnsupportedResponse() throws Exception { 781 // Use Radio HAL v1.5 782 try { 783 replaceInstance(RIL.class, "mHalVersion", mRILUnderTest, mHalVersionV15); 784 } catch (Exception e) { 785 } 786 787 // Verify the v1.5 HAL method is called 788 mRILUnderTest.getDataRegistrationState(obtainMessage()); 789 verify(mRadioProxy).getDataRegistrationState_1_5(mSerialNumberCaptor.capture()); 790 791 // Before we find a way to trigger real RadioResponse method, emulate the behaivor. 792 Consumer<RILRequest> unsupportedResponseEmulator = rr -> { 793 mRILUnderTest.setCompatVersion(rr.getRequest(), RIL.RADIO_HAL_VERSION_1_4); 794 mRILUnderTest.getDataRegistrationState(Message.obtain(rr.getResult())); 795 }; 796 797 verifyRILUnsupportedResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), 798 RIL_REQUEST_DATA_REGISTRATION_STATE, unsupportedResponseEmulator); 799 800 // Verify the fallback method is invoked 801 verify(mRadioProxy).getDataRegistrationState(mSerialNumberCaptor.getValue() + 1); 802 } 803 804 @FlakyTest 805 @Test testGetOperator()806 public void testGetOperator() throws Exception { 807 mRILUnderTest.getOperator(obtainMessage()); 808 verify(mRadioProxy).getOperator(mSerialNumberCaptor.capture()); 809 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_OPERATOR); 810 } 811 812 @FlakyTest 813 @Test testSetRadioPower()814 public void testSetRadioPower() throws Exception { 815 boolean on = true; 816 mRILUnderTest.setRadioPower(on, obtainMessage()); 817 verify(mRadioProxy).setRadioPower(mSerialNumberCaptor.capture(), eq(on)); 818 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_RADIO_POWER); 819 } 820 821 @FlakyTest 822 @Test testSetRadioPower_1_6()823 public void testSetRadioPower_1_6() throws Exception { 824 boolean on = true, forEmergencyCall = false, preferredForEmergencyCall = false; 825 826 // Use Radio HAL v1.6 827 try { 828 replaceInstance(RIL.class, "mHalVersion", mRILUnderTest, mHalVersionV16); 829 } catch (Exception e) { 830 } 831 832 mRILUnderTest.setRadioPower( 833 on, forEmergencyCall, preferredForEmergencyCall, obtainMessage()); 834 verify(mRadioProxy) 835 .setRadioPower_1_6( 836 mSerialNumberCaptor.capture(), 837 eq(on), 838 eq(forEmergencyCall), 839 eq(preferredForEmergencyCall)); 840 verifyRILResponse_1_6( 841 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_RADIO_POWER); 842 } 843 844 @FlakyTest 845 @Test testSendDtmf()846 public void testSendDtmf() throws Exception { 847 char c = 'c'; 848 mRILUnderTest.sendDtmf(c, obtainMessage()); 849 verify(mRadioProxy).sendDtmf(mSerialNumberCaptor.capture(), eq(c + "")); 850 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_DTMF); 851 } 852 853 @FlakyTest 854 @Test testSendSMS()855 public void testSendSMS() throws Exception { 856 String smscPdu = "smscPdu"; 857 String pdu = "pdu"; 858 GsmSmsMessage msg = new GsmSmsMessage(); 859 msg.smscPdu = smscPdu; 860 msg.pdu = pdu; 861 mRILUnderTest.sendSMS(smscPdu, pdu, obtainMessage()); 862 verify(mRadioProxy).sendSms(mSerialNumberCaptor.capture(), eq(msg)); 863 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SEND_SMS); 864 } 865 866 @FlakyTest 867 @Test testSendSMS_1_6()868 public void testSendSMS_1_6() throws Exception { 869 // Use Radio HAL v1.6 870 try { 871 replaceInstance(RIL.class, "mHalVersion", mRILUnderTest, mHalVersionV16); 872 } catch (Exception e) { 873 } 874 String smscPdu = "smscPdu"; 875 String pdu = "pdu"; 876 GsmSmsMessage msg = new GsmSmsMessage(); 877 msg.smscPdu = smscPdu; 878 msg.pdu = pdu; 879 mRILUnderTest.sendSMS(smscPdu, pdu, obtainMessage()); 880 verify(mRadioProxy).sendSms_1_6(mSerialNumberCaptor.capture(), eq(msg)); 881 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SEND_SMS); 882 } 883 884 @FlakyTest 885 @Test testSendSMSExpectMore()886 public void testSendSMSExpectMore() throws Exception { 887 String smscPdu = "smscPdu"; 888 String pdu = "pdu"; 889 GsmSmsMessage msg = new GsmSmsMessage(); 890 msg.smscPdu = smscPdu; 891 msg.pdu = pdu; 892 mRILUnderTest.sendSMSExpectMore(smscPdu, pdu, obtainMessage()); 893 verify(mRadioProxy).sendSMSExpectMore(mSerialNumberCaptor.capture(), eq(msg)); 894 verifyRILResponse( 895 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SEND_SMS_EXPECT_MORE); 896 } 897 898 @FlakyTest 899 @Test testSendSMSExpectMore_1_6()900 public void testSendSMSExpectMore_1_6() throws Exception { 901 // Use Radio HAL v1.6 902 try { 903 replaceInstance(RIL.class, "mHalVersion", mRILUnderTest, mHalVersionV16); 904 } catch (Exception e) { 905 } 906 String smscPdu = "smscPdu"; 907 String pdu = "pdu"; 908 GsmSmsMessage msg = new GsmSmsMessage(); 909 msg.smscPdu = smscPdu; 910 msg.pdu = pdu; 911 mRILUnderTest.sendSMSExpectMore(smscPdu, pdu, obtainMessage()); 912 verify(mRadioProxy).sendSmsExpectMore_1_6(mSerialNumberCaptor.capture(), eq(msg)); 913 verifyRILResponse( 914 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SEND_SMS_EXPECT_MORE); 915 } 916 917 @FlakyTest 918 @Test testSendCdmaSMS_1_6()919 public void testSendCdmaSMS_1_6() throws Exception { 920 // Use Radio HAL v1.6 921 try { 922 replaceInstance(RIL.class, "mHalVersion", mRILUnderTest, mHalVersionV16); 923 } catch (Exception e) { 924 } 925 byte[] pdu = "000010020000000000000000000000000000000000".getBytes(); 926 CdmaSmsMessage msg = new CdmaSmsMessage(); 927 constructCdmaSendSmsRilRequest(msg, pdu); 928 mRILUnderTest.sendCdmaSms(pdu, obtainMessage()); 929 verify(mRadioProxy).sendCdmaSms_1_6(mSerialNumberCaptor.capture(), eq(msg)); 930 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_CDMA_SEND_SMS); 931 } 932 933 @FlakyTest 934 @Test testSendCdmaSMSExpectMore_1_6()935 public void testSendCdmaSMSExpectMore_1_6() throws Exception { 936 // Use Radio HAL v1.6 937 try { 938 replaceInstance(RIL.class, "mHalVersion", mRILUnderTest, mHalVersionV16); 939 } catch (Exception e) { 940 } 941 byte[] pdu = "000010020000000000000000000000000000000000".getBytes(); 942 CdmaSmsMessage msg = new CdmaSmsMessage(); 943 constructCdmaSendSmsRilRequest(msg, pdu); 944 mRILUnderTest.sendCdmaSMSExpectMore(pdu, obtainMessage()); 945 verify(mRadioProxy).sendCdmaSmsExpectMore_1_6(mSerialNumberCaptor.capture(), eq(msg)); 946 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), 947 RIL_REQUEST_CDMA_SEND_SMS_EXPECT_MORE); 948 } 949 constructCdmaSendSmsRilRequest(CdmaSmsMessage msg, byte[] pdu)950 private void constructCdmaSendSmsRilRequest(CdmaSmsMessage msg, byte[] pdu) { 951 int addrNbrOfDigits; 952 int subaddrNbrOfDigits; 953 int bearerDataLength; 954 ByteArrayInputStream bais = new ByteArrayInputStream(pdu); 955 DataInputStream dis = new DataInputStream(bais); 956 957 try { 958 msg.teleserviceId = dis.readInt(); // teleServiceId 959 msg.isServicePresent = (byte) dis.readInt() == 1 ? true : false; // servicePresent 960 msg.serviceCategory = dis.readInt(); // serviceCategory 961 msg.address.digitMode = dis.read(); // address digit mode 962 msg.address.numberMode = dis.read(); // address number mode 963 msg.address.numberType = dis.read(); // address number type 964 msg.address.numberPlan = dis.read(); // address number plan 965 addrNbrOfDigits = (byte) dis.read(); 966 for (int i = 0; i < addrNbrOfDigits; i++) { 967 msg.address.digits.add(dis.readByte()); // address_orig_bytes[i] 968 } 969 msg.subAddress.subaddressType = dis.read(); //subaddressType 970 msg.subAddress.odd = (byte) dis.read() == 1 ? true : false; //subaddr odd 971 subaddrNbrOfDigits = (byte) dis.read(); 972 for (int i = 0; i < subaddrNbrOfDigits; i++) { 973 msg.subAddress.digits.add(dis.readByte()); //subaddr_orig_bytes[i] 974 } 975 976 bearerDataLength = dis.read(); 977 for (int i = 0; i < bearerDataLength; i++) { 978 msg.bearerData.add(dis.readByte()); //bearerData[i] 979 } 980 } catch (IOException ex) { 981 ex.printStackTrace(); 982 } 983 } 984 985 @FlakyTest 986 @Test testWriteSmsToSim()987 public void testWriteSmsToSim() throws Exception { 988 String smscPdu = "smscPdu"; 989 String pdu = "pdu"; 990 int status = SmsManager.STATUS_ON_ICC_READ; 991 SmsWriteArgs args = new SmsWriteArgs(); 992 args.status = 1; 993 args.smsc = smscPdu; 994 args.pdu = pdu; 995 mRILUnderTest.writeSmsToSim(status, smscPdu, pdu, obtainMessage()); 996 verify(mRadioProxy).writeSmsToSim(mSerialNumberCaptor.capture(), eq(args)); 997 verifyRILResponse( 998 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_WRITE_SMS_TO_SIM); 999 } 1000 1001 @FlakyTest 1002 @Test testDeleteSmsOnSim()1003 public void testDeleteSmsOnSim() throws Exception { 1004 int index = 0; 1005 mRILUnderTest.deleteSmsOnSim(index, obtainMessage()); 1006 verify(mRadioProxy).deleteSmsOnSim(mSerialNumberCaptor.capture(), eq(index)); 1007 verifyRILResponse( 1008 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_DELETE_SMS_ON_SIM); 1009 } 1010 1011 @FlakyTest 1012 @Test testExitEmergencyCallbackMode()1013 public void testExitEmergencyCallbackMode() throws Exception { 1014 mRILUnderTest.exitEmergencyCallbackMode(obtainMessage()); 1015 verify(mRadioProxy).exitEmergencyCallbackMode(mSerialNumberCaptor.capture()); 1016 verifyRILResponse( 1017 mRILUnderTest, 1018 mSerialNumberCaptor.getValue(), 1019 RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE); 1020 } 1021 1022 @FlakyTest 1023 @Test testGetSmscAddress()1024 public void testGetSmscAddress() throws Exception { 1025 mRILUnderTest.getSmscAddress(obtainMessage()); 1026 verify(mRadioProxy).getSmscAddress(mSerialNumberCaptor.capture()); 1027 verifyRILResponse( 1028 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_GET_SMSC_ADDRESS); 1029 } 1030 1031 @FlakyTest 1032 @Test testSetSmscAddress()1033 public void testSetSmscAddress() throws Exception { 1034 String address = "address"; 1035 mRILUnderTest.setSmscAddress(address, obtainMessage()); 1036 verify(mRadioProxy).setSmscAddress(mSerialNumberCaptor.capture(), eq(address)); 1037 verifyRILResponse( 1038 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SET_SMSC_ADDRESS); 1039 } 1040 1041 @FlakyTest 1042 @Test testReportSmsMemoryStatus()1043 public void testReportSmsMemoryStatus() throws Exception { 1044 boolean available = true; 1045 mRILUnderTest.reportSmsMemoryStatus(available, obtainMessage()); 1046 verify(mRadioProxy).reportSmsMemoryStatus(mSerialNumberCaptor.capture(), eq(available)); 1047 verifyRILResponse( 1048 mRILUnderTest, 1049 mSerialNumberCaptor.getValue(), 1050 RIL_REQUEST_REPORT_SMS_MEMORY_STATUS); 1051 } 1052 1053 @FlakyTest 1054 @Test testReportStkServiceIsRunning()1055 public void testReportStkServiceIsRunning() throws Exception { 1056 mRILUnderTest.reportStkServiceIsRunning(obtainMessage()); 1057 verify(mRadioProxy).reportStkServiceIsRunning(mSerialNumberCaptor.capture()); 1058 verifyRILResponse( 1059 mRILUnderTest, 1060 mSerialNumberCaptor.getValue(), 1061 RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING); 1062 } 1063 1064 @FlakyTest 1065 @Test testGetCdmaSubscriptionSource()1066 public void testGetCdmaSubscriptionSource() throws Exception { 1067 mRILUnderTest.getCdmaSubscriptionSource(obtainMessage()); 1068 verify(mRadioProxy).getCdmaSubscriptionSource(mSerialNumberCaptor.capture()); 1069 verifyRILResponse( 1070 mRILUnderTest, 1071 mSerialNumberCaptor.getValue(), 1072 RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE); 1073 } 1074 1075 @FlakyTest 1076 @Test testAcknowledgeIncomingGsmSmsWithPdu()1077 public void testAcknowledgeIncomingGsmSmsWithPdu() throws Exception { 1078 boolean success = true; 1079 String ackPdu = "ackPdu"; 1080 mRILUnderTest.acknowledgeIncomingGsmSmsWithPdu(success, ackPdu, obtainMessage()); 1081 verify(mRadioProxy).acknowledgeIncomingGsmSmsWithPdu( 1082 mSerialNumberCaptor.capture(), eq(success), eq(ackPdu)); 1083 verifyRILResponse( 1084 mRILUnderTest, 1085 mSerialNumberCaptor.getValue(), 1086 RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU); 1087 } 1088 1089 @FlakyTest 1090 @Test testGetVoiceRadioTechnology()1091 public void testGetVoiceRadioTechnology() throws Exception { 1092 mRILUnderTest.getVoiceRadioTechnology(obtainMessage()); 1093 verify(mRadioProxy).getVoiceRadioTechnology(mSerialNumberCaptor.capture()); 1094 verifyRILResponse( 1095 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_VOICE_RADIO_TECH); 1096 } 1097 1098 @FlakyTest 1099 @Test testGetCellInfoList()1100 public void testGetCellInfoList() throws Exception { 1101 mRILUnderTest.getCellInfoList(obtainMessage(), null); 1102 verify(mRadioProxy).getCellInfoList(mSerialNumberCaptor.capture()); 1103 verifyRILResponse( 1104 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_GET_CELL_INFO_LIST); 1105 } 1106 1107 @FlakyTest 1108 @Test testSetCellInfoListRate()1109 public void testSetCellInfoListRate() throws Exception { 1110 int rateInMillis = 1000; 1111 mRILUnderTest.setCellInfoListRate(rateInMillis, obtainMessage(), null); 1112 verify(mRadioProxy).setCellInfoListRate(mSerialNumberCaptor.capture(), eq(rateInMillis)); 1113 verifyRILResponse( 1114 mRILUnderTest, 1115 mSerialNumberCaptor.getValue(), 1116 RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE); 1117 } 1118 1119 @FlakyTest 1120 @Test testSetInitialAttachApn()1121 public void testSetInitialAttachApn() throws Exception { 1122 ApnSetting apnSetting = new ApnSetting.Builder() 1123 .setId(-1) 1124 .setOperatorNumeric("22210") 1125 .setEntryName("Vodafone IT") 1126 .setApnName("web.omnitel.it") 1127 .setApnTypeBitmask(ApnSetting.TYPE_DUN) 1128 .setProtocol(ApnSetting.PROTOCOL_IP) 1129 .setRoamingProtocol(ApnSetting.PROTOCOL_IP) 1130 .setCarrierEnabled(true) 1131 .build(); 1132 1133 DataProfile dataProfile = new DataProfile.Builder() 1134 .setApnSetting(apnSetting) 1135 .setPreferred(false) 1136 .build(); 1137 1138 mRILUnderTest.setInitialAttachApn(dataProfile, obtainMessage()); 1139 verify(mRadioProxy).setInitialAttachApn_1_4( 1140 mSerialNumberCaptor.capture(), 1141 eq(RILUtils.convertToHalDataProfile14(dataProfile))); 1142 verifyRILResponse( 1143 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SET_INITIAL_ATTACH_APN); 1144 } 1145 1146 @FlakyTest 1147 @Test testSendRetryImsGsmSms()1148 public void testSendRetryImsGsmSms() throws Exception { 1149 String smscPdu = "smscPdu"; 1150 String pdu = "pdu"; 1151 GsmSmsMessage gsmMsg = new GsmSmsMessage(); 1152 gsmMsg.smscPdu = smscPdu; 1153 gsmMsg.pdu = pdu; 1154 1155 ImsSmsMessage firstMsg = new ImsSmsMessage(); 1156 firstMsg.tech = RadioTechnologyFamily.THREE_GPP; 1157 firstMsg.retry = false; 1158 firstMsg.messageRef = 0; 1159 firstMsg.gsmMessage.add(gsmMsg); 1160 1161 ImsSmsMessage retryMsg = new ImsSmsMessage(); 1162 retryMsg.tech = RadioTechnologyFamily.THREE_GPP; 1163 retryMsg.retry = true; 1164 retryMsg.messageRef = 0; 1165 retryMsg.gsmMessage.add(gsmMsg); 1166 1167 int maxRetryCount = 3; 1168 int firstTransmission = 0; 1169 for (int i = 0; i <= maxRetryCount; i++) { 1170 mRILUnderTest.sendImsGsmSms(smscPdu, pdu, i, 0, obtainMessage()); 1171 if (i == firstTransmission) { 1172 verify(mRadioProxy, times(1)).sendImsSms(mSerialNumberCaptor.capture(), 1173 eq(firstMsg)); 1174 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), 1175 RIL_REQUEST_IMS_SEND_SMS); 1176 } else { 1177 verify(mRadioProxy, times(i)).sendImsSms(mSerialNumberCaptor.capture(), 1178 eq(retryMsg)); 1179 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), 1180 RIL_REQUEST_IMS_SEND_SMS); 1181 } 1182 } 1183 } 1184 1185 @FlakyTest 1186 @Test testSendRetryImsCdmaSms()1187 public void testSendRetryImsCdmaSms() throws Exception { 1188 CdmaSmsMessage cdmaMsg = new CdmaSmsMessage(); 1189 1190 ImsSmsMessage firstMsg = new ImsSmsMessage(); 1191 firstMsg.tech = RadioTechnologyFamily.THREE_GPP2; 1192 firstMsg.retry = false; 1193 firstMsg.messageRef = 0; 1194 firstMsg.cdmaMessage.add(cdmaMsg); 1195 1196 ImsSmsMessage retryMsg = new ImsSmsMessage(); 1197 retryMsg.tech = RadioTechnologyFamily.THREE_GPP2; 1198 retryMsg.retry = true; 1199 retryMsg.messageRef = 0; 1200 retryMsg.cdmaMessage.add(cdmaMsg); 1201 1202 int maxRetryCount = 3; 1203 int firstTransmission = 0; 1204 byte pdu[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 1205 for (int i = 0; i <= maxRetryCount; i++) { 1206 mRILUnderTest.sendImsCdmaSms(pdu, i, 0, obtainMessage()); 1207 if (i == firstTransmission) { 1208 verify(mRadioProxy, times(1)).sendImsSms(mSerialNumberCaptor.capture(), 1209 eq(firstMsg)); 1210 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), 1211 RIL_REQUEST_IMS_SEND_SMS); 1212 } else { 1213 verify(mRadioProxy, times(i)).sendImsSms(mSerialNumberCaptor.capture(), 1214 eq(retryMsg)); 1215 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), 1216 RIL_REQUEST_IMS_SEND_SMS); 1217 } 1218 } 1219 } 1220 1221 @FlakyTest 1222 @Test testIccOpenLogicalChannel()1223 public void testIccOpenLogicalChannel() throws Exception { 1224 String aid = "aid"; 1225 int p2 = 0; 1226 mRILUnderTest.iccOpenLogicalChannel(aid, p2, obtainMessage()); 1227 verify(mRadioProxy).iccOpenLogicalChannel(mSerialNumberCaptor.capture(), eq(aid), eq(p2)); 1228 verifyRILResponse( 1229 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SIM_OPEN_CHANNEL); 1230 } 1231 1232 @FlakyTest 1233 @Test testIccCloseLogicalChannel()1234 public void testIccCloseLogicalChannel() throws Exception { 1235 int channel = 1; 1236 mRILUnderTest.iccCloseLogicalChannel(channel, false, obtainMessage()); 1237 verify(mRadioProxy).iccCloseLogicalChannel(mSerialNumberCaptor.capture(), eq(channel)); 1238 verifyRILResponse( 1239 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SIM_CLOSE_CHANNEL); 1240 } 1241 1242 @FlakyTest 1243 @Test testNvWriteItem()1244 public void testNvWriteItem() throws Exception { 1245 int itemId = 1; 1246 String itemValue = "value"; 1247 mRILUnderTest.nvWriteItem(itemId, itemValue, obtainMessage(), new WorkSource()); 1248 NvWriteItem item = new NvWriteItem(); 1249 item.itemId = itemId; 1250 item.value = itemValue; 1251 verify(mRadioProxy).nvWriteItem(mSerialNumberCaptor.capture(), eq(item)); 1252 verifyRILResponse( 1253 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_NV_WRITE_ITEM); 1254 } 1255 1256 @FlakyTest 1257 @Test testNvReadItem()1258 public void testNvReadItem() throws Exception { 1259 int itemId = 1; 1260 mRILUnderTest.nvReadItem(itemId, obtainMessage(), new WorkSource()); 1261 verify(mRadioProxy).nvReadItem(mSerialNumberCaptor.capture(), eq(itemId)); 1262 verifyRILResponse( 1263 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_NV_READ_ITEM); 1264 } 1265 1266 @FlakyTest 1267 @Test testNvResetConfig()1268 public void testNvResetConfig() throws Exception { 1269 int resetType = 1; 1270 mRILUnderTest.nvResetConfig(resetType, obtainMessage()); 1271 verify(mRadioProxy).nvResetConfig( 1272 mSerialNumberCaptor.capture(), 1273 RILUtils.convertToHalResetNvType(resetType)); 1274 verifyRILResponse( 1275 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_NV_RESET_CONFIG); 1276 } 1277 1278 @FlakyTest 1279 @Test testSetDataAllowed()1280 public void testSetDataAllowed() throws Exception { 1281 boolean allowed = true; 1282 mRILUnderTest.setDataAllowed(allowed, obtainMessage()); 1283 verify(mRadioProxy).setDataAllowed(mSerialNumberCaptor.capture(), eq(allowed)); 1284 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_ALLOW_DATA); 1285 } 1286 1287 @FlakyTest 1288 @Test testGetHardwareConfig()1289 public void testGetHardwareConfig() throws Exception { 1290 mRILUnderTest.getHardwareConfig(obtainMessage()); 1291 verify(mRadioProxy).getHardwareConfig(mSerialNumberCaptor.capture()); 1292 verifyRILResponse( 1293 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_GET_HARDWARE_CONFIG); 1294 } 1295 1296 @FlakyTest 1297 @Test testRequestIccSimAuthentication()1298 public void testRequestIccSimAuthentication() throws Exception { 1299 int authContext = 1; 1300 String data = "data"; 1301 String aid = "aid"; 1302 mRILUnderTest.requestIccSimAuthentication(authContext, data, aid, obtainMessage()); 1303 verify(mRadioProxy).requestIccSimAuthentication( 1304 mSerialNumberCaptor.capture(), eq(authContext), eq(data), eq(aid)); 1305 verifyRILResponse( 1306 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SIM_AUTHENTICATION); 1307 } 1308 1309 @FlakyTest 1310 @Test testRequestShutdown()1311 public void testRequestShutdown() throws Exception { 1312 mRILUnderTest.requestShutdown(obtainMessage()); 1313 verify(mRadioProxy).requestShutdown(mSerialNumberCaptor.capture()); 1314 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SHUTDOWN); 1315 } 1316 1317 @FlakyTest 1318 @Test testGetRadioCapability()1319 public void testGetRadioCapability() throws Exception { 1320 mRILUnderTest.getRadioCapability(obtainMessage()); 1321 verify(mRadioProxy).getRadioCapability(mSerialNumberCaptor.capture()); 1322 verifyRILResponse( 1323 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_GET_RADIO_CAPABILITY); 1324 } 1325 1326 @FlakyTest 1327 @Test testGetModemActivityInfo()1328 public void testGetModemActivityInfo() throws Exception { 1329 mRILUnderTest.getModemActivityInfo(obtainMessage(), new WorkSource()); 1330 verify(mRadioProxy).getModemActivityInfo(mSerialNumberCaptor.capture()); 1331 verifyRILResponse( 1332 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_GET_ACTIVITY_INFO); 1333 } 1334 1335 @FlakyTest 1336 @Test testGetModemActivityInfoTimeout()1337 public void testGetModemActivityInfoTimeout() { 1338 mRILUnderTest.getModemActivityInfo(obtainMessage(), new WorkSource()); 1339 assertEquals(1, mRILUnderTest.getRilRequestList().size()); 1340 moveTimeForward(DEFAULT_BLOCKING_MESSAGE_RESPONSE_TIMEOUT_MS); 1341 processAllMessages(); 1342 assertEquals(0, mRILUnderTest.getRilRequestList().size()); 1343 } 1344 1345 @FlakyTest 1346 @Test testSendDeviceState()1347 public void testSendDeviceState() throws Exception { 1348 int stateType = 1; 1349 boolean state = false; 1350 mRILUnderTest.sendDeviceState(stateType, state, obtainMessage()); 1351 verify(mRadioProxy).sendDeviceState( 1352 mSerialNumberCaptor.capture(), eq(stateType), eq(state)); 1353 verifyRILResponse( 1354 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SEND_DEVICE_STATE); 1355 } 1356 1357 @FlakyTest 1358 @Test testSetUnsolResponseFilter()1359 public void testSetUnsolResponseFilter() throws Exception { 1360 int filter = 1; 1361 mRILUnderTest.setUnsolResponseFilter(filter, obtainMessage()); 1362 verify(mRadioProxy).setIndicationFilter(mSerialNumberCaptor.capture(), eq(filter)); 1363 verifyRILResponse( 1364 mRILUnderTest, 1365 mSerialNumberCaptor.getValue(), 1366 RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER); 1367 } 1368 1369 @FlakyTest 1370 @Test testSetSimCardPowerForPowerDownState()1371 public void testSetSimCardPowerForPowerDownState() throws Exception { 1372 mRILUnderTest.setSimCardPower(TelephonyManager.CARD_POWER_DOWN, obtainMessage(), 1373 new WorkSource()); 1374 verify(mRadioProxy).setSimCardPower(mSerialNumberCaptor.capture(), eq(false)); 1375 verifyRILResponse( 1376 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SET_SIM_CARD_POWER); 1377 } 1378 1379 @FlakyTest 1380 @Test testSetSimCardPowerForPowerUpState()1381 public void testSetSimCardPowerForPowerUpState() throws Exception { 1382 mRILUnderTest.setSimCardPower(TelephonyManager.CARD_POWER_UP, obtainMessage(), 1383 new WorkSource()); 1384 verify(mRadioProxy).setSimCardPower(mSerialNumberCaptor.capture(), eq(true)); 1385 verifyRILResponse( 1386 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SET_SIM_CARD_POWER); 1387 } 1388 1389 @FlakyTest 1390 @Test testHandleCallSetupRequestFromSim()1391 public void testHandleCallSetupRequestFromSim() throws Exception { 1392 boolean accept = true; 1393 mRILUnderTest.handleCallSetupRequestFromSim(accept, obtainMessage()); 1394 verify(mRadioProxy).handleStkCallSetupRequestFromSim( 1395 mSerialNumberCaptor.capture(), eq(accept)); 1396 verifyRILResponse( 1397 mRILUnderTest, 1398 mSerialNumberCaptor.getValue(), 1399 RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM); 1400 } 1401 1402 @FlakyTest 1403 @Test testWakeLockTimeout()1404 public void testWakeLockTimeout() { 1405 invokeMethod( 1406 mRILInstance, 1407 "obtainRequest", 1408 new Class<?>[] {Integer.TYPE, Message.class, WorkSource.class}, 1409 new Object[] {RIL_REQUEST_GET_SIM_STATUS, obtainMessage(), new WorkSource()}); 1410 1411 // The wake lock should be held when obtain a RIL request. 1412 assertTrue(mRILInstance.getWakeLock(RIL.FOR_WAKELOCK).isHeld()); 1413 1414 moveTimeForward(DEFAULT_WAKE_LOCK_TIMEOUT_MS); 1415 processAllMessages(); 1416 1417 // The wake lock should be released after processed the time out event. 1418 assertFalse(mRILInstance.getWakeLock(RIL.FOR_WAKELOCK).isHeld()); 1419 } 1420 1421 @Test testGetBarringInfo()1422 public void testGetBarringInfo() throws Exception { 1423 // Not supported on Radio 1.0. 1424 mRILUnderTest.getBarringInfo(obtainMessage()); 1425 verify(mNetworkProxy, never()).getBarringInfo(anyInt()); 1426 1427 // Make radio version 1.5 to support the operation. 1428 try { 1429 replaceInstance(RIL.class, "mHalVersion", mRILUnderTest, mHalVersionV15); 1430 } catch (Exception e) { 1431 } 1432 mRILUnderTest.getBarringInfo(obtainMessage()); 1433 verify(mNetworkProxy).getBarringInfo(mSerialNumberCaptor.capture()); 1434 verifyRILResponse( 1435 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_GET_BARRING_INFO); 1436 } 1437 obtainMessage()1438 private Message obtainMessage() { 1439 return mRILUnderTest.getRilHandler().obtainMessage(); 1440 } 1441 verifyRILResponse(RIL ril, int serial, int requestType)1442 private static void verifyRILResponse(RIL ril, int serial, int requestType) { 1443 RadioResponseInfo responseInfo = 1444 createFakeRadioResponseInfo(serial, RadioError.NONE, RadioResponseType.SOLICITED); 1445 1446 RILRequest rr = ril.processResponse(responseInfo); 1447 assertNotNull(rr); 1448 1449 assertEquals(serial, rr.getSerial()); 1450 assertEquals(requestType, rr.getRequest()); 1451 assertTrue(ril.getWakeLock(RIL.FOR_WAKELOCK).isHeld()); 1452 1453 ril.processResponseDone(rr, responseInfo, null); 1454 assertEquals(0, ril.getRilRequestList().size()); 1455 assertFalse(ril.getWakeLock(RIL.FOR_WAKELOCK).isHeld()); 1456 } 1457 verifyRILResponse_1_6(RIL ril, int serial, int requestType)1458 private static void verifyRILResponse_1_6(RIL ril, int serial, int requestType) { 1459 android.hardware.radio.V1_6.RadioResponseInfo responseInfo = 1460 createFakeRadioResponseInfo_1_6( 1461 serial, RadioError.NONE, RadioResponseType.SOLICITED); 1462 1463 RILRequest rr = ril.processResponse_1_6(responseInfo); 1464 assertNotNull(rr); 1465 1466 assertEquals(serial, rr.getSerial()); 1467 assertEquals(requestType, rr.getRequest()); 1468 assertTrue(ril.getWakeLock(RIL.FOR_WAKELOCK).isHeld()); 1469 1470 ril.processResponseDone_1_6(rr, responseInfo, null); 1471 assertEquals(0, ril.getRilRequestList().size()); 1472 assertFalse(ril.getWakeLock(RIL.FOR_WAKELOCK).isHeld()); 1473 } 1474 verifyRILErrorResponse(RIL ril, int serial, int requestType, int error)1475 private static void verifyRILErrorResponse(RIL ril, int serial, int requestType, int error) { 1476 RadioResponseInfo responseInfo = 1477 createFakeRadioResponseInfo(serial, error, RadioResponseType.SOLICITED); 1478 1479 RILRequest rr = ril.processResponse(responseInfo); 1480 assertNotNull(rr); 1481 1482 assertEquals(serial, rr.getSerial()); 1483 assertEquals(requestType, rr.getRequest()); 1484 assertTrue(ril.getWakeLock(RIL.FOR_WAKELOCK).isHeld()); 1485 1486 ril.processResponseDone(rr, responseInfo, null); 1487 assertEquals(0, ril.getRilRequestList().size()); 1488 assertFalse(ril.getWakeLock(RIL.FOR_WAKELOCK).isHeld()); 1489 } 1490 verifyRILUnsupportedResponse(RIL ril, int serial, int requestType, Consumer<RILRequest> unsupportedResponseEmulator)1491 private static void verifyRILUnsupportedResponse(RIL ril, int serial, int requestType, 1492 Consumer<RILRequest> unsupportedResponseEmulator) { 1493 RadioResponseInfo responseInfo = 1494 createFakeRadioResponseInfo(serial, RadioError.REQUEST_NOT_SUPPORTED, 1495 RadioResponseType.SOLICITED); 1496 1497 RILRequest rr = ril.processResponse(responseInfo); 1498 assertNotNull(rr); 1499 1500 assertEquals(serial, rr.getSerial()); 1501 assertEquals(requestType, rr.getRequest()); 1502 assertTrue(ril.getWakeLock(RIL.FOR_WAKELOCK).isHeld()); 1503 1504 unsupportedResponseEmulator.accept(rr); 1505 1506 ril.processResponseDone(rr, responseInfo, null); 1507 1508 assertEquals(1, ril.getRilRequestList().size()); 1509 assertTrue(ril.getWakeLock(RIL.FOR_WAKELOCK).isHeld()); 1510 } 1511 createFakeRadioResponseInfo(int serial, int error, int type)1512 private static RadioResponseInfo createFakeRadioResponseInfo(int serial, int error, int type) { 1513 RadioResponseInfo respInfo = new RadioResponseInfo(); 1514 respInfo.serial = serial; 1515 respInfo.error = error; 1516 respInfo.type = type; 1517 return respInfo; 1518 } 1519 createFakeRadioResponseInfo_1_6( int serial, int error, int type)1520 private static android.hardware.radio.V1_6.RadioResponseInfo createFakeRadioResponseInfo_1_6( 1521 int serial, int error, int type) { 1522 android.hardware.radio.V1_6.RadioResponseInfo respInfo = 1523 new android.hardware.radio.V1_6.RadioResponseInfo(); 1524 respInfo.serial = serial; 1525 respInfo.error = error; 1526 respInfo.type = type; 1527 return respInfo; 1528 } 1529 getCellIdentityOperatorNames()1530 private android.hardware.radio.V1_2.CellIdentityOperatorNames getCellIdentityOperatorNames() { 1531 android.hardware.radio.V1_2.CellIdentityOperatorNames operatorNames = 1532 new android.hardware.radio.V1_2.CellIdentityOperatorNames(); 1533 operatorNames.alphaLong = ALPHA_LONG; 1534 operatorNames.alphaShort = ALPHA_SHORT; 1535 1536 return operatorNames; 1537 } 1538 getCellIdentityLte_1_2()1539 private android.hardware.radio.V1_2.CellIdentityLte getCellIdentityLte_1_2() { 1540 android.hardware.radio.V1_0.CellIdentityLte cellIdentity0 = 1541 new android.hardware.radio.V1_0.CellIdentityLte(); 1542 cellIdentity0.mcc = MCC_STR; 1543 cellIdentity0.mnc = MNC_STR; 1544 cellIdentity0.ci = CI; 1545 cellIdentity0.pci = PCI; 1546 cellIdentity0.tac = TAC; 1547 cellIdentity0.earfcn = EARFCN; 1548 1549 android.hardware.radio.V1_2.CellIdentityLte cellIdentity = 1550 new android.hardware.radio.V1_2.CellIdentityLte(); 1551 cellIdentity.base = cellIdentity0; 1552 cellIdentity.operatorNames = getCellIdentityOperatorNames(); 1553 cellIdentity.bandwidth = BANDWIDTH; 1554 1555 return cellIdentity; 1556 } 1557 getLteSignalStrength_1_0()1558 private android.hardware.radio.V1_0.LteSignalStrength getLteSignalStrength_1_0() { 1559 android.hardware.radio.V1_0.LteSignalStrength signalStrength = 1560 new android.hardware.radio.V1_0.LteSignalStrength(); 1561 signalStrength.signalStrength = RSSI_ASU; 1562 signalStrength.rsrp = -RSRP; 1563 signalStrength.rsrq = -RSRQ; 1564 signalStrength.rssnr = RSSNR; 1565 signalStrength.cqi = CQI; 1566 signalStrength.timingAdvance = TIMING_ADVANCE; 1567 1568 return signalStrength; 1569 } 1570 getCellInfo_1_4ForLte()1571 private android.hardware.radio.V1_4.CellInfo getCellInfo_1_4ForLte() { 1572 android.hardware.radio.V1_2.CellInfoLte cellInfo2 = 1573 new android.hardware.radio.V1_2.CellInfoLte(); 1574 cellInfo2.cellIdentityLte = getCellIdentityLte_1_2(); 1575 cellInfo2.signalStrengthLte = getLteSignalStrength_1_0(); 1576 1577 android.hardware.radio.V1_4.CellConfigLte cellConfig = 1578 new android.hardware.radio.V1_4.CellConfigLte(); 1579 cellConfig.isEndcAvailable = ENDC_AVAILABLE; 1580 1581 android.hardware.radio.V1_4.CellInfoLte cellInfoLte = 1582 new android.hardware.radio.V1_4.CellInfoLte(); 1583 cellInfoLte.base = cellInfo2; 1584 cellInfoLte.cellConfig = cellConfig; 1585 1586 android.hardware.radio.V1_4.CellInfo cellInfo = new android.hardware.radio.V1_4.CellInfo(); 1587 cellInfo.isRegistered = REGISTERED; 1588 cellInfo.connectionStatus = CONNECTION_STATUS; 1589 cellInfo.info.lte(cellInfoLte); 1590 1591 return cellInfo; 1592 } 1593 1594 @Test testConvertHalCellInfoList_1_4ForLte()1595 public void testConvertHalCellInfoList_1_4ForLte() { 1596 ArrayList<Object> records = new ArrayList<>(); 1597 records.add(getCellInfo_1_4ForLte()); 1598 1599 ArrayList<CellInfo> ret = RILUtils.convertHalCellInfoList(records); 1600 1601 assertEquals(1, ret.size()); 1602 CellInfoLte cellInfoLte = (CellInfoLte) ret.get(0); 1603 cellInfoLte.setTimeStamp(TIMESTAMP); // override the timestamp 1604 1605 CellIdentityLte cellIdentityLte = new CellIdentityLte(CI, PCI, TAC, EARFCN, new int[] {}, 1606 BANDWIDTH, MCC_STR, MNC_STR, ALPHA_LONG, ALPHA_SHORT, Collections.emptyList(), 1607 null); 1608 CellSignalStrengthLte cellSignalStrengthLte = new CellSignalStrengthLte( 1609 RSSI, RSRP, RSRQ, RSSNR, CQI, TIMING_ADVANCE); 1610 CellConfigLte cellConfigLte = new CellConfigLte(ENDC_AVAILABLE); 1611 CellInfoLte expected = new CellInfoLte(CONNECTION_STATUS, REGISTERED, TIMESTAMP, 1612 cellIdentityLte, cellSignalStrengthLte, cellConfigLte); 1613 assertEquals(expected, cellInfoLte); 1614 } 1615 getOptionalCsgInfo()1616 private android.hardware.radio.V1_5.OptionalCsgInfo getOptionalCsgInfo() { 1617 android.hardware.radio.V1_5.ClosedSubscriberGroupInfo closedSubscriberGroupInfo = 1618 new android.hardware.radio.V1_5.ClosedSubscriberGroupInfo(); 1619 closedSubscriberGroupInfo.csgIndication = CSG_INDICATION; 1620 closedSubscriberGroupInfo.homeNodebName = HOME_NODEB_NAME; 1621 closedSubscriberGroupInfo.csgIdentity = CSG_IDENTITY; 1622 1623 android.hardware.radio.V1_5.OptionalCsgInfo optionalCsgInfo = 1624 new android.hardware.radio.V1_5.OptionalCsgInfo(); 1625 optionalCsgInfo.csgInfo(closedSubscriberGroupInfo); 1626 1627 return optionalCsgInfo; 1628 } 1629 getCellIdentityLte_1_5()1630 private android.hardware.radio.V1_5.CellIdentityLte getCellIdentityLte_1_5() { 1631 android.hardware.radio.V1_5.CellIdentityLte cellIdentity = 1632 new android.hardware.radio.V1_5.CellIdentityLte(); 1633 cellIdentity.base = getCellIdentityLte_1_2(); 1634 cellIdentity.additionalPlmns = new ArrayList<>(Arrays.asList(ADDITIONAL_PLMNS)); 1635 cellIdentity.optionalCsgInfo = getOptionalCsgInfo(); 1636 cellIdentity.bands = BANDS; 1637 1638 return cellIdentity; 1639 } 1640 1641 @Test testConvertHalCellInfoList_1_5ForLte()1642 public void testConvertHalCellInfoList_1_5ForLte() { 1643 android.hardware.radio.V1_5.CellInfoLte cellInfoLte = 1644 new android.hardware.radio.V1_5.CellInfoLte(); 1645 cellInfoLte.cellIdentityLte = getCellIdentityLte_1_5(); 1646 cellInfoLte.signalStrengthLte = getLteSignalStrength_1_0(); 1647 1648 android.hardware.radio.V1_5.CellInfo cellInfo = new android.hardware.radio.V1_5.CellInfo(); 1649 cellInfo.registered = REGISTERED; 1650 cellInfo.connectionStatus = CONNECTION_STATUS; 1651 cellInfo.ratSpecificInfo.lte(cellInfoLte); 1652 1653 ArrayList<Object> records = new ArrayList<>(); 1654 records.add(cellInfo); 1655 1656 ArrayList<CellInfo> ret = RILUtils.convertHalCellInfoList(records); 1657 1658 assertEquals(1, ret.size()); 1659 CellInfoLte cil = (CellInfoLte) ret.get(0); 1660 cil.setTimeStamp(TIMESTAMP); // override the timestamp 1661 1662 Set<String> additionalPlmns = new HashSet<>(); 1663 Collections.addAll(additionalPlmns, ADDITIONAL_PLMNS); 1664 ClosedSubscriberGroupInfo closedSubscriberGroupInfo = 1665 new ClosedSubscriberGroupInfo(CSG_INDICATION, HOME_NODEB_NAME, CSG_IDENTITY); 1666 CellIdentityLte cellIdentityLte = new CellIdentityLte(CI, PCI, TAC, EARFCN, 1667 BANDS.stream().mapToInt(i -> i).toArray(), BANDWIDTH, MCC_STR, MNC_STR, ALPHA_LONG, 1668 ALPHA_SHORT, additionalPlmns, closedSubscriberGroupInfo); 1669 CellSignalStrengthLte cellSignalStrengthLte = new CellSignalStrengthLte( 1670 RSSI, RSRP, RSRQ, RSSNR, CQI, TIMING_ADVANCE); 1671 CellInfoLte expected = new CellInfoLte(CONNECTION_STATUS, REGISTERED, TIMESTAMP, 1672 cellIdentityLte, cellSignalStrengthLte, new CellConfigLte()); 1673 assertEquals(expected, cil); 1674 } 1675 1676 @Test testConvertHalCellInfoList_1_6ForLte()1677 public void testConvertHalCellInfoList_1_6ForLte() { 1678 android.hardware.radio.V1_6.LteSignalStrength signalStrength = 1679 new android.hardware.radio.V1_6.LteSignalStrength(); 1680 signalStrength.base = getLteSignalStrength_1_0(); 1681 signalStrength.cqiTableIndex = CQI_TABLE_INDEX; 1682 1683 android.hardware.radio.V1_6.CellInfoLte cellInfoLte = 1684 new android.hardware.radio.V1_6.CellInfoLte(); 1685 cellInfoLte.cellIdentityLte = getCellIdentityLte_1_5(); 1686 cellInfoLte.signalStrengthLte = signalStrength; 1687 1688 android.hardware.radio.V1_6.CellInfo cellInfo = new android.hardware.radio.V1_6.CellInfo(); 1689 cellInfo.registered = REGISTERED; 1690 cellInfo.connectionStatus = CONNECTION_STATUS; 1691 cellInfo.ratSpecificInfo.lte(cellInfoLte); 1692 1693 ArrayList<Object> records = new ArrayList<>(); 1694 records.add(cellInfo); 1695 1696 ArrayList<CellInfo> ret = RILUtils.convertHalCellInfoList(records); 1697 1698 assertEquals(1, ret.size()); 1699 CellInfoLte cil = (CellInfoLte) ret.get(0); 1700 cil.setTimeStamp(TIMESTAMP); // override the timestamp 1701 1702 Set<String> additionalPlmns = new HashSet<>(); 1703 Collections.addAll(additionalPlmns, ADDITIONAL_PLMNS); 1704 ClosedSubscriberGroupInfo closedSubscriberGroupInfo = 1705 new ClosedSubscriberGroupInfo(CSG_INDICATION, HOME_NODEB_NAME, CSG_IDENTITY); 1706 CellIdentityLte cellIdentityLte = new CellIdentityLte(CI, PCI, TAC, EARFCN, 1707 BANDS.stream().mapToInt(i -> i).toArray(), BANDWIDTH, MCC_STR, MNC_STR, ALPHA_LONG, 1708 ALPHA_SHORT, additionalPlmns, closedSubscriberGroupInfo); 1709 CellSignalStrengthLte cellSignalStrengthLte = new CellSignalStrengthLte( 1710 RSSI, RSRP, RSRQ, RSSNR, CQI_TABLE_INDEX, CQI, TIMING_ADVANCE); 1711 CellInfoLte expected = new CellInfoLte(CONNECTION_STATUS, REGISTERED, TIMESTAMP, 1712 cellIdentityLte, cellSignalStrengthLte, new CellConfigLte()); 1713 assertEquals(expected, cil); 1714 } 1715 getCellIdentityGsm_1_2()1716 private android.hardware.radio.V1_2.CellIdentityGsm getCellIdentityGsm_1_2() { 1717 android.hardware.radio.V1_0.CellIdentityGsm cellIdentity0 = 1718 new android.hardware.radio.V1_0.CellIdentityGsm(); 1719 cellIdentity0.mcc = MCC_STR; 1720 cellIdentity0.mnc = MNC_STR; 1721 cellIdentity0.lac = LAC; 1722 cellIdentity0.cid = CID; 1723 cellIdentity0.arfcn = ARFCN; 1724 cellIdentity0.bsic = BSIC; 1725 1726 android.hardware.radio.V1_2.CellIdentityGsm cellIdentity = 1727 new android.hardware.radio.V1_2.CellIdentityGsm(); 1728 cellIdentity.base = cellIdentity0; 1729 cellIdentity.operatorNames = getCellIdentityOperatorNames(); 1730 1731 return cellIdentity; 1732 } 1733 getGsmSignalStrength_1_0()1734 private android.hardware.radio.V1_0.GsmSignalStrength getGsmSignalStrength_1_0() { 1735 android.hardware.radio.V1_0.GsmSignalStrength signalStrength = 1736 new android.hardware.radio.V1_0.GsmSignalStrength(); 1737 signalStrength.signalStrength = RSSI_ASU; 1738 signalStrength.bitErrorRate = BIT_ERROR_RATE; 1739 signalStrength.timingAdvance = TIMING_ADVANCE; 1740 1741 return signalStrength; 1742 } 1743 1744 @Test testConvertHalCellInfoList_1_4ForGsm()1745 public void testConvertHalCellInfoList_1_4ForGsm() { 1746 android.hardware.radio.V1_2.CellInfoGsm cellInfoGsm = 1747 new android.hardware.radio.V1_2.CellInfoGsm(); 1748 cellInfoGsm.cellIdentityGsm = getCellIdentityGsm_1_2(); 1749 cellInfoGsm.signalStrengthGsm = getGsmSignalStrength_1_0(); 1750 1751 android.hardware.radio.V1_4.CellInfo cellInfo = new android.hardware.radio.V1_4.CellInfo(); 1752 cellInfo.isRegistered = REGISTERED; 1753 cellInfo.connectionStatus = CONNECTION_STATUS; 1754 cellInfo.info.gsm(cellInfoGsm); 1755 1756 ArrayList<Object> records = new ArrayList<>(); 1757 records.add(cellInfo); 1758 1759 ArrayList<CellInfo> ret = RILUtils.convertHalCellInfoList(records); 1760 1761 assertEquals(1, ret.size()); 1762 CellInfoGsm cig = (CellInfoGsm) ret.get(0); 1763 cig.setTimeStamp(TIMESTAMP); // override the timestamp 1764 1765 CellIdentityGsm cellIdentityGsm = new CellIdentityGsm(LAC, CID, ARFCN, BSIC, MCC_STR, 1766 MNC_STR, ALPHA_LONG, ALPHA_SHORT, Collections.emptyList()); 1767 CellSignalStrengthGsm cellSignalStrengthGsm = new CellSignalStrengthGsm( 1768 RSSI, BIT_ERROR_RATE, TIMING_ADVANCE); 1769 CellInfoGsm expected = new CellInfoGsm(CONNECTION_STATUS, REGISTERED, TIMESTAMP, 1770 cellIdentityGsm, cellSignalStrengthGsm); 1771 assertEquals(expected, cig); 1772 } 1773 getCellInfoGsm_1_5()1774 private android.hardware.radio.V1_5.CellInfoGsm getCellInfoGsm_1_5() { 1775 android.hardware.radio.V1_5.CellIdentityGsm cellIdentity = 1776 new android.hardware.radio.V1_5.CellIdentityGsm(); 1777 cellIdentity.base = getCellIdentityGsm_1_2(); 1778 cellIdentity.additionalPlmns = new ArrayList<>(Arrays.asList(ADDITIONAL_PLMNS)); 1779 1780 android.hardware.radio.V1_5.CellInfoGsm cellInfo = 1781 new android.hardware.radio.V1_5.CellInfoGsm(); 1782 cellInfo.cellIdentityGsm = cellIdentity; 1783 cellInfo.signalStrengthGsm = getGsmSignalStrength_1_0(); 1784 1785 return cellInfo; 1786 } 1787 1788 @Test testConvertHalCellInfoList_1_5ForGsm()1789 public void testConvertHalCellInfoList_1_5ForGsm() { 1790 android.hardware.radio.V1_5.CellInfo cellInfo = new android.hardware.radio.V1_5.CellInfo(); 1791 cellInfo.registered = REGISTERED; 1792 cellInfo.connectionStatus = CONNECTION_STATUS; 1793 cellInfo.ratSpecificInfo.gsm(getCellInfoGsm_1_5()); 1794 1795 ArrayList<Object> records = new ArrayList<>(); 1796 records.add(cellInfo); 1797 1798 ArrayList<CellInfo> ret = RILUtils.convertHalCellInfoList(records); 1799 1800 assertEquals(1, ret.size()); 1801 CellInfoGsm cellInfoGsm = (CellInfoGsm) ret.get(0); 1802 cellInfoGsm.setTimeStamp(TIMESTAMP); // override the timestamp 1803 1804 Set<String> additionalPlmns = new HashSet<>(); 1805 Collections.addAll(additionalPlmns, ADDITIONAL_PLMNS); 1806 CellIdentityGsm cellIdentityGsm = new CellIdentityGsm(LAC, CID, ARFCN, BSIC, MCC_STR, 1807 MNC_STR, ALPHA_LONG, ALPHA_SHORT, additionalPlmns); 1808 CellSignalStrengthGsm cellSignalStrengthGsm = new CellSignalStrengthGsm( 1809 RSSI, BIT_ERROR_RATE, TIMING_ADVANCE); 1810 CellInfoGsm expected = new CellInfoGsm(CONNECTION_STATUS, REGISTERED, TIMESTAMP, 1811 cellIdentityGsm, cellSignalStrengthGsm); 1812 assertEquals(expected, cellInfoGsm); 1813 } 1814 1815 @Test testConvertHalCellInfoList_1_6ForGsm()1816 public void testConvertHalCellInfoList_1_6ForGsm() { 1817 android.hardware.radio.V1_6.CellInfo cellInfo = new android.hardware.radio.V1_6.CellInfo(); 1818 cellInfo.registered = REGISTERED; 1819 cellInfo.connectionStatus = CONNECTION_STATUS; 1820 cellInfo.ratSpecificInfo.gsm(getCellInfoGsm_1_5()); 1821 1822 ArrayList<Object> records = new ArrayList<>(); 1823 records.add(cellInfo); 1824 1825 ArrayList<CellInfo> ret = RILUtils.convertHalCellInfoList(records); 1826 1827 assertEquals(1, ret.size()); 1828 CellInfoGsm cellInfoGsm = (CellInfoGsm) ret.get(0); 1829 cellInfoGsm.setTimeStamp(TIMESTAMP); // override the timestamp 1830 1831 Set<String> additionalPlmns = new HashSet<>(); 1832 Collections.addAll(additionalPlmns, ADDITIONAL_PLMNS); 1833 CellIdentityGsm cellIdentityGsm = new CellIdentityGsm(LAC, CID, ARFCN, BSIC, MCC_STR, 1834 MNC_STR, ALPHA_LONG, ALPHA_SHORT, additionalPlmns); 1835 CellSignalStrengthGsm cellSignalStrengthGsm = new CellSignalStrengthGsm( 1836 RSSI, BIT_ERROR_RATE, TIMING_ADVANCE); 1837 CellInfoGsm expected = new CellInfoGsm(CONNECTION_STATUS, REGISTERED, TIMESTAMP, 1838 cellIdentityGsm, cellSignalStrengthGsm); 1839 assertEquals(expected, cellInfoGsm); 1840 } 1841 getCellIdentityWcdma_1_2()1842 private android.hardware.radio.V1_2.CellIdentityWcdma getCellIdentityWcdma_1_2() { 1843 android.hardware.radio.V1_0.CellIdentityWcdma cellIdentity0 = 1844 new android.hardware.radio.V1_0.CellIdentityWcdma(); 1845 cellIdentity0.mcc = MCC_STR; 1846 cellIdentity0.mnc = MNC_STR; 1847 cellIdentity0.lac = LAC; 1848 cellIdentity0.cid = CID; 1849 cellIdentity0.psc = PSC; 1850 cellIdentity0.uarfcn = UARFCN; 1851 1852 android.hardware.radio.V1_2.CellIdentityWcdma cellIdentity = 1853 new android.hardware.radio.V1_2.CellIdentityWcdma(); 1854 cellIdentity.base = cellIdentity0; 1855 cellIdentity.operatorNames = getCellIdentityOperatorNames(); 1856 1857 return cellIdentity; 1858 } 1859 getWcdmaSignalStrength_1_2()1860 private android.hardware.radio.V1_2.WcdmaSignalStrength getWcdmaSignalStrength_1_2() { 1861 android.hardware.radio.V1_0.WcdmaSignalStrength signalStrength0 = 1862 new android.hardware.radio.V1_0.WcdmaSignalStrength(); 1863 signalStrength0.signalStrength = RSSI_ASU; 1864 signalStrength0.bitErrorRate = BIT_ERROR_RATE; 1865 1866 android.hardware.radio.V1_2.WcdmaSignalStrength signalStrength = 1867 new android.hardware.radio.V1_2.WcdmaSignalStrength(); 1868 signalStrength.base = signalStrength0; 1869 signalStrength.rscp = RSCP_ASU; 1870 signalStrength.ecno = ECNO_ASU; 1871 1872 return signalStrength; 1873 } 1874 1875 @Test testConvertHalCellInfoList_1_4ForWcdma()1876 public void testConvertHalCellInfoList_1_4ForWcdma() { 1877 android.hardware.radio.V1_2.CellInfoWcdma cellInfoWcdma = 1878 new android.hardware.radio.V1_2.CellInfoWcdma(); 1879 cellInfoWcdma.cellIdentityWcdma = getCellIdentityWcdma_1_2(); 1880 cellInfoWcdma.signalStrengthWcdma = getWcdmaSignalStrength_1_2(); 1881 1882 android.hardware.radio.V1_4.CellInfo cellInfo = new android.hardware.radio.V1_4.CellInfo(); 1883 cellInfo.isRegistered = REGISTERED; 1884 cellInfo.connectionStatus = CONNECTION_STATUS; 1885 cellInfo.info.wcdma(cellInfoWcdma); 1886 1887 ArrayList<Object> records = new ArrayList<>(); 1888 records.add(cellInfo); 1889 1890 ArrayList<CellInfo> ret = RILUtils.convertHalCellInfoList(records); 1891 1892 assertEquals(1, ret.size()); 1893 CellInfoWcdma ciw = (CellInfoWcdma) ret.get(0); 1894 ciw.setTimeStamp(TIMESTAMP); // override the timestamp 1895 1896 CellIdentityWcdma cellIdentityWcdma = new CellIdentityWcdma(LAC, CID, PSC, UARFCN, MCC_STR, 1897 MNC_STR, ALPHA_LONG, ALPHA_SHORT, Collections.emptyList(), null); 1898 CellSignalStrengthWcdma cellSignalStrengthWcdma = new CellSignalStrengthWcdma( 1899 RSSI, BIT_ERROR_RATE, RSCP, ECNO); 1900 CellInfoWcdma expected = new CellInfoWcdma(CONNECTION_STATUS, REGISTERED, TIMESTAMP, 1901 cellIdentityWcdma, cellSignalStrengthWcdma); 1902 assertEquals(expected, ciw); 1903 } 1904 getCellInfoWcdma_1_5()1905 private android.hardware.radio.V1_5.CellInfoWcdma getCellInfoWcdma_1_5() { 1906 android.hardware.radio.V1_5.CellIdentityWcdma cellIdentity = 1907 new android.hardware.radio.V1_5.CellIdentityWcdma(); 1908 cellIdentity.base = getCellIdentityWcdma_1_2(); 1909 cellIdentity.additionalPlmns = new ArrayList<>(Arrays.asList(ADDITIONAL_PLMNS)); 1910 cellIdentity.optionalCsgInfo = getOptionalCsgInfo(); 1911 1912 android.hardware.radio.V1_5.CellInfoWcdma cellInfo = 1913 new android.hardware.radio.V1_5.CellInfoWcdma(); 1914 cellInfo.cellIdentityWcdma = cellIdentity; 1915 cellInfo.signalStrengthWcdma = getWcdmaSignalStrength_1_2(); 1916 1917 return cellInfo; 1918 } 1919 1920 @Test testConvertHalCellInfoList_1_5ForWcdma()1921 public void testConvertHalCellInfoList_1_5ForWcdma() { 1922 android.hardware.radio.V1_5.CellInfo cellInfo = new android.hardware.radio.V1_5.CellInfo(); 1923 cellInfo.registered = REGISTERED; 1924 cellInfo.connectionStatus = CONNECTION_STATUS; 1925 cellInfo.ratSpecificInfo.wcdma(getCellInfoWcdma_1_5()); 1926 1927 ArrayList<Object> records = new ArrayList<>(); 1928 records.add(cellInfo); 1929 1930 ArrayList<CellInfo> ret = RILUtils.convertHalCellInfoList(records); 1931 1932 assertEquals(1, ret.size()); 1933 CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) ret.get(0); 1934 cellInfoWcdma.setTimeStamp(TIMESTAMP); // override the timestamp 1935 1936 Set<String> additionalPlmns = new HashSet<>(); 1937 Collections.addAll(additionalPlmns, ADDITIONAL_PLMNS); 1938 ClosedSubscriberGroupInfo closedSubscriberGroupInfo = 1939 new ClosedSubscriberGroupInfo(CSG_INDICATION, HOME_NODEB_NAME, CSG_IDENTITY); 1940 CellIdentityWcdma cellIdentityWcdma = new CellIdentityWcdma(LAC, CID, PSC, UARFCN, MCC_STR, 1941 MNC_STR, ALPHA_LONG, ALPHA_SHORT, additionalPlmns, closedSubscriberGroupInfo); 1942 CellSignalStrengthWcdma cellSignalStrengthWcdma = new CellSignalStrengthWcdma( 1943 RSSI, BIT_ERROR_RATE, RSCP, ECNO); 1944 CellInfoWcdma expected = new CellInfoWcdma(CONNECTION_STATUS, REGISTERED, TIMESTAMP, 1945 cellIdentityWcdma, cellSignalStrengthWcdma); 1946 assertEquals(expected, cellInfoWcdma); 1947 } 1948 1949 @Test testConvertHalCellInfoList_1_6ForWcdma()1950 public void testConvertHalCellInfoList_1_6ForWcdma() { 1951 android.hardware.radio.V1_6.CellInfo cellInfo = new android.hardware.radio.V1_6.CellInfo(); 1952 cellInfo.registered = REGISTERED; 1953 cellInfo.connectionStatus = CONNECTION_STATUS; 1954 cellInfo.ratSpecificInfo.wcdma(getCellInfoWcdma_1_5()); 1955 1956 ArrayList<Object> records = new ArrayList<>(); 1957 records.add(cellInfo); 1958 1959 ArrayList<CellInfo> ret = RILUtils.convertHalCellInfoList(records); 1960 1961 assertEquals(1, ret.size()); 1962 CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) ret.get(0); 1963 cellInfoWcdma.setTimeStamp(TIMESTAMP); // override the timestamp 1964 1965 Set<String> additionalPlmns = new HashSet<>(); 1966 Collections.addAll(additionalPlmns, ADDITIONAL_PLMNS); 1967 ClosedSubscriberGroupInfo closedSubscriberGroupInfo = 1968 new ClosedSubscriberGroupInfo(CSG_INDICATION, HOME_NODEB_NAME, CSG_IDENTITY); 1969 CellIdentityWcdma cellIdentityWcdma = new CellIdentityWcdma(LAC, CID, PSC, UARFCN, MCC_STR, 1970 MNC_STR, ALPHA_LONG, ALPHA_SHORT, additionalPlmns, closedSubscriberGroupInfo); 1971 CellSignalStrengthWcdma cellSignalStrengthWcdma = new CellSignalStrengthWcdma( 1972 RSSI, BIT_ERROR_RATE, RSCP, ECNO); 1973 CellInfoWcdma expected = new CellInfoWcdma(CONNECTION_STATUS, REGISTERED, TIMESTAMP, 1974 cellIdentityWcdma, cellSignalStrengthWcdma); 1975 assertEquals(expected, cellInfoWcdma); 1976 } 1977 getCellIdentityTdscdma_1_2()1978 private android.hardware.radio.V1_2.CellIdentityTdscdma getCellIdentityTdscdma_1_2() { 1979 android.hardware.radio.V1_0.CellIdentityTdscdma cellIdentity0 = 1980 new android.hardware.radio.V1_0.CellIdentityTdscdma(); 1981 cellIdentity0.mcc = MCC_STR; 1982 cellIdentity0.mnc = MNC_STR; 1983 cellIdentity0.lac = LAC; 1984 cellIdentity0.cid = CID; 1985 cellIdentity0.cpid = PSC; 1986 1987 android.hardware.radio.V1_2.CellIdentityTdscdma cellIdentity = 1988 new android.hardware.radio.V1_2.CellIdentityTdscdma(); 1989 cellIdentity.base = cellIdentity0; 1990 cellIdentity.uarfcn = UARFCN; 1991 cellIdentity.operatorNames = getCellIdentityOperatorNames(); 1992 1993 return cellIdentity; 1994 } 1995 getTdscdmaSignalStrength_1_2()1996 private android.hardware.radio.V1_2.TdscdmaSignalStrength getTdscdmaSignalStrength_1_2() { 1997 android.hardware.radio.V1_2.TdscdmaSignalStrength signalStrength = 1998 new android.hardware.radio.V1_2.TdscdmaSignalStrength(); 1999 signalStrength.signalStrength = RSSI_ASU; 2000 signalStrength.bitErrorRate = BIT_ERROR_RATE; 2001 signalStrength.rscp = RSCP_ASU; 2002 2003 return signalStrength; 2004 } 2005 2006 @Test testConvertHalCellInfoList_1_4ForTdscdma()2007 public void testConvertHalCellInfoList_1_4ForTdscdma() { 2008 android.hardware.radio.V1_2.CellInfoTdscdma cellInfoTdscdma = 2009 new android.hardware.radio.V1_2.CellInfoTdscdma(); 2010 cellInfoTdscdma.cellIdentityTdscdma = getCellIdentityTdscdma_1_2(); 2011 cellInfoTdscdma.signalStrengthTdscdma = getTdscdmaSignalStrength_1_2(); 2012 2013 android.hardware.radio.V1_4.CellInfo cellInfo = new android.hardware.radio.V1_4.CellInfo(); 2014 cellInfo.isRegistered = REGISTERED; 2015 cellInfo.connectionStatus = CONNECTION_STATUS; 2016 cellInfo.info.tdscdma(cellInfoTdscdma); 2017 2018 ArrayList<Object> records = new ArrayList<>(); 2019 records.add(cellInfo); 2020 2021 ArrayList<CellInfo> ret = RILUtils.convertHalCellInfoList(records); 2022 2023 assertEquals(1, ret.size()); 2024 CellInfoTdscdma cit = (CellInfoTdscdma) ret.get(0); 2025 cit.setTimeStamp(TIMESTAMP); // override the timestamp 2026 2027 CellIdentityTdscdma cellIdentityTdscdma = new CellIdentityTdscdma( 2028 MCC_STR, MNC_STR, LAC, CID, PSC, UARFCN, ALPHA_LONG, ALPHA_SHORT, 2029 Collections.emptyList(), null); 2030 CellSignalStrengthTdscdma cellSignalStrengthTdscdma = new CellSignalStrengthTdscdma( 2031 RSSI, BIT_ERROR_RATE, RSCP); 2032 CellInfoTdscdma expected = new CellInfoTdscdma(CONNECTION_STATUS, REGISTERED, TIMESTAMP, 2033 cellIdentityTdscdma, cellSignalStrengthTdscdma); 2034 assertEquals(expected, cit); 2035 } 2036 getCellInfoTdscdma_1_5()2037 private android.hardware.radio.V1_5.CellInfoTdscdma getCellInfoTdscdma_1_5() { 2038 android.hardware.radio.V1_5.CellIdentityTdscdma cellIdentity = 2039 new android.hardware.radio.V1_5.CellIdentityTdscdma(); 2040 cellIdentity.base = getCellIdentityTdscdma_1_2(); 2041 cellIdentity.additionalPlmns = new ArrayList<>(Arrays.asList(ADDITIONAL_PLMNS)); 2042 cellIdentity.optionalCsgInfo = getOptionalCsgInfo(); 2043 2044 android.hardware.radio.V1_5.CellInfoTdscdma cellInfo = 2045 new android.hardware.radio.V1_5.CellInfoTdscdma(); 2046 cellInfo.cellIdentityTdscdma = cellIdentity; 2047 cellInfo.signalStrengthTdscdma = getTdscdmaSignalStrength_1_2(); 2048 2049 return cellInfo; 2050 } 2051 2052 @Test testConvertHalCellInfoList_1_5ForTdscdma()2053 public void testConvertHalCellInfoList_1_5ForTdscdma() { 2054 android.hardware.radio.V1_5.CellInfo cellInfo = new android.hardware.radio.V1_5.CellInfo(); 2055 cellInfo.registered = REGISTERED; 2056 cellInfo.connectionStatus = CONNECTION_STATUS; 2057 cellInfo.ratSpecificInfo.tdscdma(getCellInfoTdscdma_1_5()); 2058 2059 ArrayList<Object> records = new ArrayList<>(); 2060 records.add(cellInfo); 2061 2062 ArrayList<CellInfo> ret = RILUtils.convertHalCellInfoList(records); 2063 2064 assertEquals(1, ret.size()); 2065 CellInfoTdscdma cellInfoTdscdma = (CellInfoTdscdma) ret.get(0); 2066 cellInfoTdscdma.setTimeStamp(TIMESTAMP); // override the timestamp 2067 2068 Set<String> additionalPlmns = new HashSet<>(); 2069 Collections.addAll(additionalPlmns, ADDITIONAL_PLMNS); 2070 ClosedSubscriberGroupInfo closedSubscriberGroupInfo = 2071 new ClosedSubscriberGroupInfo(CSG_INDICATION, HOME_NODEB_NAME, CSG_IDENTITY); 2072 CellIdentityTdscdma cellIdentityTdscdma = new CellIdentityTdscdma( 2073 MCC_STR, MNC_STR, LAC, CID, PSC, UARFCN, ALPHA_LONG, ALPHA_SHORT, 2074 additionalPlmns, closedSubscriberGroupInfo); 2075 CellSignalStrengthTdscdma cellSignalStrengthTdscdma = new CellSignalStrengthTdscdma( 2076 RSSI, BIT_ERROR_RATE, RSCP); 2077 CellInfoTdscdma expected = new CellInfoTdscdma(CONNECTION_STATUS, REGISTERED, TIMESTAMP, 2078 cellIdentityTdscdma, cellSignalStrengthTdscdma); 2079 assertEquals(expected, cellInfoTdscdma); 2080 } 2081 2082 @Test testConvertHalCellInfoList_1_6ForTdscdma()2083 public void testConvertHalCellInfoList_1_6ForTdscdma() { 2084 android.hardware.radio.V1_6.CellInfo cellInfo = new android.hardware.radio.V1_6.CellInfo(); 2085 cellInfo.registered = REGISTERED; 2086 cellInfo.connectionStatus = CONNECTION_STATUS; 2087 cellInfo.ratSpecificInfo.tdscdma(getCellInfoTdscdma_1_5()); 2088 2089 ArrayList<Object> records = new ArrayList<>(); 2090 records.add(cellInfo); 2091 2092 ArrayList<CellInfo> ret = RILUtils.convertHalCellInfoList(records); 2093 2094 assertEquals(1, ret.size()); 2095 CellInfoTdscdma cellInfoTdscdma = (CellInfoTdscdma) ret.get(0); 2096 cellInfoTdscdma.setTimeStamp(TIMESTAMP); // override the timestamp 2097 2098 Set<String> additionalPlmns = new HashSet<>(); 2099 Collections.addAll(additionalPlmns, ADDITIONAL_PLMNS); 2100 ClosedSubscriberGroupInfo closedSubscriberGroupInfo = 2101 new ClosedSubscriberGroupInfo(CSG_INDICATION, HOME_NODEB_NAME, CSG_IDENTITY); 2102 CellIdentityTdscdma cellIdentityTdscdma = new CellIdentityTdscdma( 2103 MCC_STR, MNC_STR, LAC, CID, PSC, UARFCN, ALPHA_LONG, ALPHA_SHORT, 2104 additionalPlmns, closedSubscriberGroupInfo); 2105 CellSignalStrengthTdscdma cellSignalStrengthTdscdma = new CellSignalStrengthTdscdma( 2106 RSSI, BIT_ERROR_RATE, RSCP); 2107 CellInfoTdscdma expected = new CellInfoTdscdma(CONNECTION_STATUS, REGISTERED, TIMESTAMP, 2108 cellIdentityTdscdma, cellSignalStrengthTdscdma); 2109 assertEquals(expected, cellInfoTdscdma); 2110 } 2111 getCellInfoCdma_1_2()2112 private android.hardware.radio.V1_2.CellInfoCdma getCellInfoCdma_1_2() { 2113 android.hardware.radio.V1_0.CellIdentityCdma cellIdentity0 = 2114 new android.hardware.radio.V1_0.CellIdentityCdma(); 2115 cellIdentity0.networkId = NETWORK_ID; 2116 cellIdentity0.systemId = SYSTEM_ID; 2117 cellIdentity0.baseStationId = BASESTATION_ID; 2118 cellIdentity0.longitude = LONGITUDE; 2119 cellIdentity0.latitude = LATITUDE; 2120 2121 android.hardware.radio.V1_2.CellIdentityCdma cellIdentity = 2122 new android.hardware.radio.V1_2.CellIdentityCdma(); 2123 cellIdentity.base = cellIdentity0; 2124 cellIdentity.operatorNames = getCellIdentityOperatorNames(); 2125 2126 android.hardware.radio.V1_0.CdmaSignalStrength cdmaSignalStrength = 2127 new android.hardware.radio.V1_0.CdmaSignalStrength(); 2128 cdmaSignalStrength.dbm = -DBM; 2129 cdmaSignalStrength.ecio = -ECIO; 2130 2131 android.hardware.radio.V1_0.EvdoSignalStrength evdoSignalStrength = 2132 new android.hardware.radio.V1_0.EvdoSignalStrength(); 2133 evdoSignalStrength.dbm = -DBM; 2134 evdoSignalStrength.ecio = -ECIO; 2135 evdoSignalStrength.signalNoiseRatio = SIGNAL_NOISE_RATIO; 2136 2137 android.hardware.radio.V1_2.CellInfoCdma cellInfo = 2138 new android.hardware.radio.V1_2.CellInfoCdma(); 2139 cellInfo.cellIdentityCdma = cellIdentity; 2140 cellInfo.signalStrengthCdma = cdmaSignalStrength; 2141 cellInfo.signalStrengthEvdo = evdoSignalStrength; 2142 2143 return cellInfo; 2144 } 2145 2146 @Test testConvertHalCellInfoList_1_4ForCdma()2147 public void testConvertHalCellInfoList_1_4ForCdma() { 2148 android.hardware.radio.V1_4.CellInfo cellInfo = new android.hardware.radio.V1_4.CellInfo(); 2149 cellInfo.isRegistered = REGISTERED; 2150 cellInfo.connectionStatus = CONNECTION_STATUS; 2151 cellInfo.info.cdma(getCellInfoCdma_1_2()); 2152 2153 ArrayList<Object> records = new ArrayList<>(); 2154 records.add(cellInfo); 2155 2156 ArrayList<CellInfo> ret = RILUtils.convertHalCellInfoList(records); 2157 2158 assertEquals(1, ret.size()); 2159 CellInfoCdma cellInfoCdma = (CellInfoCdma) ret.get(0); 2160 cellInfoCdma.setTimeStamp(TIMESTAMP); // override the timestamp 2161 2162 CellIdentityCdma cellIdentityCdma = new CellIdentityCdma(NETWORK_ID, SYSTEM_ID, 2163 BASESTATION_ID, LONGITUDE, LATITUDE, ALPHA_LONG, ALPHA_SHORT); 2164 CellSignalStrengthCdma cellSignalStrengthCdma = new CellSignalStrengthCdma( 2165 DBM, ECIO, DBM, ECIO, SIGNAL_NOISE_RATIO); 2166 CellInfoCdma expected = new CellInfoCdma(CONNECTION_STATUS, REGISTERED, TIMESTAMP, 2167 cellIdentityCdma, cellSignalStrengthCdma); 2168 assertEquals(expected, cellInfoCdma); 2169 } 2170 2171 @Test testConvertHalCellInfoList_1_5ForCdma()2172 public void testConvertHalCellInfoList_1_5ForCdma() { 2173 android.hardware.radio.V1_5.CellInfo cellInfo = new android.hardware.radio.V1_5.CellInfo(); 2174 cellInfo.registered = REGISTERED; 2175 cellInfo.connectionStatus = CONNECTION_STATUS; 2176 cellInfo.ratSpecificInfo.cdma(getCellInfoCdma_1_2()); 2177 2178 ArrayList<Object> records = new ArrayList<>(); 2179 records.add(cellInfo); 2180 2181 ArrayList<CellInfo> ret = RILUtils.convertHalCellInfoList(records); 2182 2183 assertEquals(1, ret.size()); 2184 CellInfoCdma cellInfoCdma = (CellInfoCdma) ret.get(0); 2185 cellInfoCdma.setTimeStamp(TIMESTAMP); // override the timestamp 2186 2187 CellIdentityCdma cellIdentityCdma = new CellIdentityCdma(NETWORK_ID, SYSTEM_ID, 2188 BASESTATION_ID, LONGITUDE, LATITUDE, ALPHA_LONG, ALPHA_SHORT); 2189 CellSignalStrengthCdma cellSignalStrengthCdma = new CellSignalStrengthCdma( 2190 DBM, ECIO, DBM, ECIO, SIGNAL_NOISE_RATIO); 2191 CellInfoCdma expected = new CellInfoCdma(CONNECTION_STATUS, REGISTERED, TIMESTAMP, 2192 cellIdentityCdma, cellSignalStrengthCdma); 2193 assertEquals(expected, cellInfoCdma); 2194 } 2195 2196 @Test testConvertHalCellInfoList_1_6ForCdma()2197 public void testConvertHalCellInfoList_1_6ForCdma() { 2198 android.hardware.radio.V1_6.CellInfo cellInfo = new android.hardware.radio.V1_6.CellInfo(); 2199 cellInfo.registered = REGISTERED; 2200 cellInfo.connectionStatus = CONNECTION_STATUS; 2201 cellInfo.ratSpecificInfo.cdma(getCellInfoCdma_1_2()); 2202 2203 ArrayList<Object> records = new ArrayList<>(); 2204 records.add(cellInfo); 2205 2206 ArrayList<CellInfo> ret = RILUtils.convertHalCellInfoList(records); 2207 2208 assertEquals(1, ret.size()); 2209 CellInfoCdma cellInfoCdma = (CellInfoCdma) ret.get(0); 2210 cellInfoCdma.setTimeStamp(TIMESTAMP); // override the timestamp 2211 2212 CellIdentityCdma cellIdentityCdma = new CellIdentityCdma(NETWORK_ID, SYSTEM_ID, 2213 BASESTATION_ID, LONGITUDE, LATITUDE, ALPHA_LONG, ALPHA_SHORT); 2214 CellSignalStrengthCdma cellSignalStrengthCdma = new CellSignalStrengthCdma( 2215 DBM, ECIO, DBM, ECIO, SIGNAL_NOISE_RATIO); 2216 CellInfoCdma expected = new CellInfoCdma(CONNECTION_STATUS, REGISTERED, TIMESTAMP, 2217 cellIdentityCdma, cellSignalStrengthCdma); 2218 assertEquals(expected, cellInfoCdma); 2219 } 2220 2221 @Test testConvertHalCellInfoList_1_4ForNr()2222 public void testConvertHalCellInfoList_1_4ForNr() { 2223 android.hardware.radio.V1_4.CellInfoNr cellinfo = 2224 new android.hardware.radio.V1_4.CellInfoNr(); 2225 cellinfo.cellidentity.nci = CI; 2226 cellinfo.cellidentity.pci = PCI; 2227 cellinfo.cellidentity.tac = TAC; 2228 cellinfo.cellidentity.nrarfcn = NRARFCN; 2229 cellinfo.cellidentity.mcc = MCC_STR; 2230 cellinfo.cellidentity.mnc = MNC_STR; 2231 cellinfo.cellidentity.operatorNames.alphaLong = ALPHA_LONG; 2232 cellinfo.cellidentity.operatorNames.alphaShort = ALPHA_SHORT; 2233 cellinfo.signalStrength.ssRsrp = RSRP; 2234 cellinfo.signalStrength.ssRsrq = RSRQ; 2235 cellinfo.signalStrength.ssSinr = SIGNAL_NOISE_RATIO; 2236 cellinfo.signalStrength.csiRsrp = RSRP; 2237 cellinfo.signalStrength.csiRsrq = RSRQ; 2238 cellinfo.signalStrength.csiSinr = SIGNAL_NOISE_RATIO; 2239 2240 android.hardware.radio.V1_4.CellInfo record = new android.hardware.radio.V1_4.CellInfo(); 2241 record.info.nr(cellinfo); 2242 2243 ArrayList<Object> records = new ArrayList<>(); 2244 records.add(record); 2245 2246 ArrayList<CellInfo> ret = RILUtils.convertHalCellInfoList(records); 2247 2248 CellInfoNr cellInfoNr = (CellInfoNr) ret.get(0); 2249 CellIdentityNr cellIdentityNr = (CellIdentityNr) cellInfoNr.getCellIdentity(); 2250 CellSignalStrengthNr signalStrengthNr = 2251 (CellSignalStrengthNr) cellInfoNr.getCellSignalStrength(); 2252 2253 CellIdentityNr expectedCellIdentity = new CellIdentityNr(PCI, TAC, NRARFCN, 2254 new int[] {}, MCC_STR, MNC_STR, CI, ALPHA_LONG, ALPHA_SHORT, 2255 Collections.emptyList()); 2256 CellSignalStrengthNr expectedSignalStrength = new CellSignalStrengthNr(-RSRP, -RSRQ, 2257 SIGNAL_NOISE_RATIO, -RSRP, -RSRQ, SIGNAL_NOISE_RATIO); 2258 2259 assertEquals(expectedCellIdentity, cellIdentityNr); 2260 assertEquals(expectedSignalStrength, signalStrengthNr); 2261 } 2262 2263 @Test testConvertDataCallResult()2264 public void testConvertDataCallResult() { 2265 DataCallResponse response = new DataCallResponse.Builder() 2266 .setCause(0) 2267 .setRetryDurationMillis(-1L) 2268 .setId(0) 2269 .setLinkStatus(2) 2270 .setProtocolType(ApnSetting.PROTOCOL_IPV4V6) 2271 .setInterfaceName("ifname") 2272 .setAddresses(Arrays.asList( 2273 new LinkAddress(InetAddresses.parseNumericAddress("10.0.2.15"), 32), 2274 new LinkAddress("2607:fb90:a620:651d:eabe:f8da:c107:44be/64"))) 2275 .setDnsAddresses(Arrays.asList(InetAddresses.parseNumericAddress("10.0.2.3"), 2276 InetAddresses.parseNumericAddress("fd00:976a::9"))) 2277 .setGatewayAddresses(Arrays.asList(InetAddresses.parseNumericAddress("10.0.2.15"), 2278 InetAddresses.parseNumericAddress("fe80::2"))) 2279 .setPcscfAddresses(Arrays.asList( 2280 InetAddresses.parseNumericAddress("fd00:976a:c206:20::6"), 2281 InetAddresses.parseNumericAddress("fd00:976a:c206:20::9"), 2282 InetAddresses.parseNumericAddress("fd00:976a:c202:1d::9"))) 2283 .setMtu(1500) 2284 .setMtuV4(1500) 2285 .setMtuV6(1500) 2286 .setQosBearerSessions(new ArrayList<>()) 2287 .setTrafficDescriptors(new ArrayList<>()) 2288 .build(); 2289 2290 // Test V1.4 SetupDataCallResult 2291 android.hardware.radio.V1_4.SetupDataCallResult result14 = 2292 new android.hardware.radio.V1_4.SetupDataCallResult(); 2293 result14.cause = android.hardware.radio.V1_4.DataCallFailCause.NONE; 2294 result14.suggestedRetryTime = -1; 2295 result14.cid = 0; 2296 result14.active = android.hardware.radio.V1_4.DataConnActiveStatus.ACTIVE; 2297 result14.type = android.hardware.radio.V1_4.PdpProtocolType.IPV4V6; 2298 result14.ifname = "ifname"; 2299 result14.addresses = new ArrayList<>( 2300 Arrays.asList("10.0.2.15", "2607:fb90:a620:651d:eabe:f8da:c107:44be/64")); 2301 result14.dnses = new ArrayList<>(Arrays.asList("10.0.2.3", "fd00:976a::9")); 2302 result14.gateways = new ArrayList<>(Arrays.asList("10.0.2.15", "fe80::2")); 2303 result14.pcscf = new ArrayList<>(Arrays.asList( 2304 "fd00:976a:c206:20::6", "fd00:976a:c206:20::9", "fd00:976a:c202:1d::9")); 2305 result14.mtu = 1500; 2306 2307 assertEquals(response, RILUtils.convertHalDataCallResult(result14)); 2308 2309 // Test V1.5 SetupDataCallResult 2310 android.hardware.radio.V1_5.SetupDataCallResult result15 = 2311 new android.hardware.radio.V1_5.SetupDataCallResult(); 2312 result15.cause = android.hardware.radio.V1_4.DataCallFailCause.NONE; 2313 result15.suggestedRetryTime = -1; 2314 result15.cid = 0; 2315 result15.active = android.hardware.radio.V1_4.DataConnActiveStatus.ACTIVE; 2316 result15.type = android.hardware.radio.V1_4.PdpProtocolType.IPV4V6; 2317 result15.ifname = "ifname"; 2318 2319 android.hardware.radio.V1_5.LinkAddress la1 = new android.hardware.radio.V1_5.LinkAddress(); 2320 la1.address = "10.0.2.15"; 2321 la1.properties = 0; 2322 la1.deprecationTime = -1; 2323 la1.expirationTime = -1; 2324 2325 android.hardware.radio.V1_5.LinkAddress la2 = new android.hardware.radio.V1_5.LinkAddress(); 2326 la2.address = "2607:fb90:a620:651d:eabe:f8da:c107:44be/64"; 2327 la2.properties = 0; 2328 la2.deprecationTime = -1; 2329 la2.expirationTime = -1; 2330 result15.addresses = new ArrayList<>(Arrays.asList(la1, la2)); 2331 result15.dnses = new ArrayList<>(Arrays.asList("10.0.2.3", "fd00:976a::9")); 2332 result15.gateways = new ArrayList<>(Arrays.asList("10.0.2.15", "fe80::2")); 2333 result15.pcscf = new ArrayList<>(Arrays.asList( 2334 "fd00:976a:c206:20::6", "fd00:976a:c206:20::9", "fd00:976a:c202:1d::9")); 2335 result15.mtuV4 = 1500; 2336 result15.mtuV6 = 3000; 2337 2338 response = new DataCallResponse.Builder() 2339 .setCause(0) 2340 .setRetryDurationMillis(-1L) 2341 .setId(0) 2342 .setLinkStatus(2) 2343 .setProtocolType(ApnSetting.PROTOCOL_IPV4V6) 2344 .setInterfaceName("ifname") 2345 .setAddresses(Arrays.asList( 2346 new LinkAddress(InetAddresses.parseNumericAddress("10.0.2.15"), 32), 2347 new LinkAddress("2607:fb90:a620:651d:eabe:f8da:c107:44be/64"))) 2348 .setDnsAddresses(Arrays.asList(InetAddresses.parseNumericAddress("10.0.2.3"), 2349 InetAddresses.parseNumericAddress("fd00:976a::9"))) 2350 .setGatewayAddresses(Arrays.asList(InetAddresses.parseNumericAddress("10.0.2.15"), 2351 InetAddresses.parseNumericAddress("fe80::2"))) 2352 .setPcscfAddresses(Arrays.asList( 2353 InetAddresses.parseNumericAddress("fd00:976a:c206:20::6"), 2354 InetAddresses.parseNumericAddress("fd00:976a:c206:20::9"), 2355 InetAddresses.parseNumericAddress("fd00:976a:c202:1d::9"))) 2356 .setMtu(3000) 2357 .setMtuV4(1500) 2358 .setMtuV6(3000) 2359 .setQosBearerSessions(new ArrayList<>()) 2360 .setTrafficDescriptors(new ArrayList<>()) 2361 .build(); 2362 2363 assertEquals(response, RILUtils.convertHalDataCallResult(result15)); 2364 2365 // Test V1.6 SetupDataCallResult 2366 android.hardware.radio.V1_6.SetupDataCallResult result16 = 2367 new android.hardware.radio.V1_6.SetupDataCallResult(); 2368 result16.cause = android.hardware.radio.V1_4.DataCallFailCause.NONE; 2369 result16.suggestedRetryTime = -1; 2370 result16.cid = 0; 2371 result16.active = android.hardware.radio.V1_4.DataConnActiveStatus.ACTIVE; 2372 result16.type = android.hardware.radio.V1_4.PdpProtocolType.IPV4V6; 2373 result16.ifname = "ifname"; 2374 2375 result16.addresses = new ArrayList<>(Arrays.asList(la1, la2)); 2376 result16.dnses = new ArrayList<>(Arrays.asList("10.0.2.3", "fd00:976a::9")); 2377 result16.gateways = new ArrayList<>(Arrays.asList("10.0.2.15", "fe80::2")); 2378 result16.pcscf = new ArrayList<>(Arrays.asList( 2379 "fd00:976a:c206:20::6", "fd00:976a:c206:20::9", "fd00:976a:c202:1d::9")); 2380 result16.mtuV4 = 1500; 2381 result16.mtuV6 = 3000; 2382 result16.handoverFailureMode = android.hardware.radio.V1_6.HandoverFailureMode.LEGACY; 2383 2384 // Build android.hardware.radio.V1_6.EpsQos 2385 android.hardware.radio.V1_6.EpsQos halEpsQos = new android.hardware.radio.V1_6.EpsQos(); 2386 halEpsQos.qci = 4; 2387 halEpsQos.downlink.maxBitrateKbps = 4; 2388 halEpsQos.downlink.guaranteedBitrateKbps = 7; 2389 halEpsQos.uplink.maxBitrateKbps = 5; 2390 halEpsQos.uplink.guaranteedBitrateKbps = 8; 2391 2392 result16.defaultQos.eps(halEpsQos); 2393 2394 // android.hardware.radio.V1_6.PortRange 2395 android.hardware.radio.V1_6.PortRange localPort = 2396 new android.hardware.radio.V1_6.PortRange(); 2397 android.hardware.radio.V1_6.PortRange remotePort = 2398 new android.hardware.radio.V1_6.PortRange(); 2399 localPort.start = 123; 2400 localPort.end = 123; 2401 remotePort.start = 223; 2402 remotePort.end = 223; 2403 2404 // android.hardware.radio.V1_6.QosFilter 2405 android.hardware.radio.V1_6.QosFilter halQosFilter = 2406 new android.hardware.radio.V1_6.QosFilter(); 2407 halQosFilter.localAddresses = new ArrayList<>(Arrays.asList("122.22.22.22")); 2408 halQosFilter.remoteAddresses = new ArrayList<>(Arrays.asList("144.44.44.44")); 2409 halQosFilter.localPort.range(localPort); 2410 halQosFilter.remotePort.range(remotePort); 2411 halQosFilter.protocol = android.hardware.radio.V1_6.QosProtocol.UDP; 2412 halQosFilter.tos.value((byte)7); 2413 halQosFilter.flowLabel.value(987); 2414 halQosFilter.spi.value(678); 2415 halQosFilter.direction = android.hardware.radio.V1_6.QosFilterDirection.BIDIRECTIONAL; 2416 halQosFilter.precedence = 45; 2417 2418 // android.hardware.radio.V1_6.QosSession 2419 android.hardware.radio.V1_6.QosSession halQosSession = 2420 new android.hardware.radio.V1_6.QosSession(); 2421 halQosSession.qosSessionId = 1234; 2422 halQosSession.qos.eps(halEpsQos); 2423 halQosSession.qosFilters = new ArrayList<>(Arrays.asList(halQosFilter)); 2424 2425 result16.qosSessions = new ArrayList<>(Arrays.asList(halQosSession)); 2426 2427 EpsQos epsQos = new EpsQos(new Qos.QosBandwidth(4, 7), new Qos.QosBandwidth(5, 8), 4); 2428 QosBearerFilter qosFilter = new QosBearerFilter( 2429 Arrays.asList( 2430 new LinkAddress(InetAddresses.parseNumericAddress("122.22.22.22"), 32)), 2431 Arrays.asList( 2432 new LinkAddress(InetAddresses.parseNumericAddress("144.44.44.44"), 32)), 2433 new QosBearerFilter.PortRange(123, 123), new QosBearerFilter.PortRange(223, 223), 2434 QosBearerFilter.QOS_PROTOCOL_UDP, 7, 987, 678, 2435 QosBearerFilter.QOS_FILTER_DIRECTION_BIDIRECTIONAL, 45); 2436 ArrayList<QosBearerFilter> qosFilters = new ArrayList<>(); 2437 ArrayList<QosBearerSession> qosSessions = new ArrayList<>(); 2438 qosFilters.add(qosFilter); 2439 QosBearerSession qosSession = new QosBearerSession(1234, epsQos, qosFilters); 2440 qosSessions.add(qosSession); 2441 2442 // android.hardware.radio.V1_6.TrafficDescriptor 2443 android.hardware.radio.V1_6.TrafficDescriptor halTrafficDescriptor = 2444 new android.hardware.radio.V1_6.TrafficDescriptor(); 2445 android.hardware.radio.V1_6.OptionalDnn halDnn = 2446 new android.hardware.radio.V1_6.OptionalDnn(); 2447 halDnn.value("DNN"); 2448 2449 android.hardware.radio.V1_6.OptionalOsAppId halOsAppId = 2450 new android.hardware.radio.V1_6.OptionalOsAppId(); 2451 android.hardware.radio.V1_6.OsAppId osAppId = new android.hardware.radio.V1_6.OsAppId(); 2452 // 97a498e3fc925c9489860333d06e4e470a454e5445525052495345. 2453 // [OsAppId.ANDROID_OS_ID, "ENTERPRISE", 1] 2454 byte[] osAppIdArray = {-105, -92, -104, -29, -4, -110, 92, 2455 -108, -119, -122, 3, 51, -48, 110, 78, 71, 10, 69, 78, 84, 69, 2456 82, 80, 82, 73, 83, 69}; 2457 osAppId.osAppId = RILUtils.primitiveArrayToArrayList(osAppIdArray); 2458 halOsAppId.value(osAppId); 2459 2460 halTrafficDescriptor.dnn = halDnn; 2461 halTrafficDescriptor.osAppId = halOsAppId; 2462 result16.trafficDescriptors = new ArrayList<>(Arrays.asList(halTrafficDescriptor)); 2463 2464 List<TrafficDescriptor> trafficDescriptors = Arrays.asList( 2465 new TrafficDescriptor("DNN", osAppIdArray)); 2466 2467 response = new DataCallResponse.Builder() 2468 .setCause(0) 2469 .setRetryDurationMillis(-1L) 2470 .setId(0) 2471 .setLinkStatus(2) 2472 .setProtocolType(ApnSetting.PROTOCOL_IPV4V6) 2473 .setInterfaceName("ifname") 2474 .setAddresses(Arrays.asList( 2475 new LinkAddress(InetAddresses.parseNumericAddress("10.0.2.15"), 32), 2476 new LinkAddress("2607:fb90:a620:651d:eabe:f8da:c107:44be/64"))) 2477 .setDnsAddresses(Arrays.asList(InetAddresses.parseNumericAddress("10.0.2.3"), 2478 InetAddresses.parseNumericAddress("fd00:976a::9"))) 2479 .setGatewayAddresses(Arrays.asList(InetAddresses.parseNumericAddress("10.0.2.15"), 2480 InetAddresses.parseNumericAddress("fe80::2"))) 2481 .setPcscfAddresses(Arrays.asList( 2482 InetAddresses.parseNumericAddress("fd00:976a:c206:20::6"), 2483 InetAddresses.parseNumericAddress("fd00:976a:c206:20::9"), 2484 InetAddresses.parseNumericAddress("fd00:976a:c202:1d::9"))) 2485 .setMtu(3000) 2486 .setMtuV4(1500) 2487 .setMtuV6(3000) 2488 .setHandoverFailureMode(DataCallResponse.HANDOVER_FAILURE_MODE_LEGACY) 2489 .setDefaultQos(epsQos) 2490 .setQosBearerSessions(qosSessions) 2491 .setTrafficDescriptors(trafficDescriptors) 2492 .build(); 2493 2494 assertEquals(response, RILUtils.convertHalDataCallResult(result16)); 2495 } 2496 2497 @Test testGetWorksourceClientId()2498 public void testGetWorksourceClientId() { 2499 RILRequest request = RILRequest.obtain(0, null, null); 2500 assertEquals(null, request.getWorkSourceClientId()); 2501 2502 request = RILRequest.obtain(0, null, new WorkSource()); 2503 assertEquals(null, request.getWorkSourceClientId()); 2504 2505 WorkSource ws = new WorkSource(); 2506 ws.add(100); 2507 request = RILRequest.obtain(0, null, ws); 2508 assertEquals("100:null", request.getWorkSourceClientId()); 2509 2510 ws = new WorkSource(); 2511 ws.add(100, "foo"); 2512 request = RILRequest.obtain(0, null, ws); 2513 assertEquals("100:foo", request.getWorkSourceClientId()); 2514 2515 ws = new WorkSource(); 2516 ws.createWorkChain().addNode(100, "foo").addNode(200, "bar"); 2517 request = RILRequest.obtain(0, null, ws); 2518 assertEquals("WorkChain{(100, foo), (200, bar)}", request.getWorkSourceClientId()); 2519 } 2520 2521 @Test testCellInfoTimestamp_1_4()2522 public void testCellInfoTimestamp_1_4() { 2523 ArrayList<Object> records = new ArrayList<>(); 2524 2525 for (int i = 0; i < 5 /* arbitrary */; i++) { 2526 android.hardware.radio.V1_4.CellInfo record = getCellInfo_1_4ForLte(); 2527 record.info.lte().base.cellIdentityLte.base.ci += i; // make them marginally unique 2528 2529 records.add(record); 2530 } 2531 List<CellInfo> cil = RILUtils.convertHalCellInfoList(records); 2532 2533 // Check that all timestamps are set to a valid number and are equal 2534 final long ts = cil.get(0).getTimeStamp(); 2535 for (CellInfo ci : cil) { 2536 assertTrue(ci.getTimeStamp() > 0 && ci.getTimeStamp() != Long.MAX_VALUE); 2537 assertEquals(ci.getTimeStamp(), ts); 2538 } 2539 } 2540 2541 @Test testSetupDataCall()2542 public void testSetupDataCall() throws Exception { 2543 ApnSetting apn = new ApnSetting.Builder() 2544 .setId(1234) 2545 .setEntryName(APN) 2546 .setApnName(APN) 2547 .setApnTypeBitmask(SUPPORTED_APN_TYPES_BITMASK) 2548 .setProtocol(ApnSetting.PROTOCOL_IPV6) 2549 .setRoamingProtocol(ApnSetting.PROTOCOL_IPV6) 2550 .setCarrierEnabled(true) 2551 .setProfileId(PROFILE_ID) 2552 .setAuthType(AUTH_TYPE) 2553 .setUser(USER_NAME) 2554 .setPassword(PASSWORD) 2555 .setNetworkTypeBitmask(SUPPORTED_NETWORK_TYPES_BITMASK) 2556 .setMtuV4(MTU) 2557 .setModemCognitive(true) 2558 .build(); 2559 2560 DataProfile dp = new DataProfile.Builder() 2561 .setApnSetting(apn) 2562 .setPreferred(false) 2563 .build(); 2564 2565 mRILUnderTest.setupDataCall(AccessNetworkConstants.AccessNetworkType.EUTRAN, dp, false, 0, 2566 null, DataCallResponse.PDU_SESSION_ID_NOT_SET, null, null, true, obtainMessage()); 2567 ArgumentCaptor<DataProfile> dpiCaptor = ArgumentCaptor.forClass(DataProfile.class); 2568 verify(mDataProxy).setupDataCall(mSerialNumberCaptor.capture(), 2569 eq(AccessNetworkConstants.AccessNetworkType.EUTRAN), dpiCaptor.capture(), 2570 eq(false), anyInt(), any(), anyInt(), any(), any(), eq(true)); 2571 verifyRILResponse( 2572 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SETUP_DATA_CALL); 2573 DataProfile dpi = dpiCaptor.getValue(); 2574 assertEquals(PROFILE_ID, dpi.getProfileId()); 2575 assertEquals(APN, dpi.getApn()); 2576 assertEquals(PROTOCOL, dpi.getProtocolType()); 2577 assertEquals(AUTH_TYPE, dpi.getAuthType()); 2578 assertEquals(USER_NAME, dpi.getUserName()); 2579 assertEquals(PASSWORD, dpi.getPassword()); 2580 assertEquals(TYPE, dpi.getType()); 2581 assertEquals(APN_ENABLED, dpi.isEnabled()); 2582 assertEquals(SUPPORTED_APN_TYPES_BITMASK, dpi.getSupportedApnTypesBitmask()); 2583 assertEquals(ROAMING_PROTOCOL, dpi.getRoamingProtocolType()); 2584 assertEquals(SUPPORTED_NETWORK_TYPES_BITMASK, dpi.getBearerBitmask()); 2585 assertEquals(MTU, dpi.getMtu()); 2586 } 2587 2588 @Test testCreateCarrierRestrictionList()2589 public void testCreateCarrierRestrictionList() { 2590 ArrayList<CarrierIdentifier> carriers = new ArrayList<>(); 2591 carriers.add(new CarrierIdentifier("110", "120", null, null, null, null)); 2592 carriers.add(new CarrierIdentifier("210", "220", "SPN", null, null, null)); 2593 carriers.add(new CarrierIdentifier("310", "320", null, "012345", null, null)); 2594 carriers.add(new CarrierIdentifier("410", "420", null, null, "GID1", null)); 2595 carriers.add(new CarrierIdentifier("510", "520", null, null, null, "GID2")); 2596 2597 Carrier c1 = new Carrier(); 2598 c1.mcc = "110"; 2599 c1.mnc = "120"; 2600 c1.matchType = CarrierIdentifier.MatchType.ALL; 2601 Carrier c2 = new Carrier(); 2602 c2.mcc = "210"; 2603 c2.mnc = "220"; 2604 c2.matchType = CarrierIdentifier.MatchType.SPN; 2605 c2.matchData = "SPN"; 2606 Carrier c3 = new Carrier(); 2607 c3.mcc = "310"; 2608 c3.mnc = "320"; 2609 c3.matchType = CarrierIdentifier.MatchType.IMSI_PREFIX; 2610 c3.matchData = "012345"; 2611 Carrier c4 = new Carrier(); 2612 c4.mcc = "410"; 2613 c4.mnc = "420"; 2614 c4.matchType = CarrierIdentifier.MatchType.GID1; 2615 c4.matchData = "GID1"; 2616 Carrier c5 = new Carrier(); 2617 c5.mcc = "510"; 2618 c5.mnc = "520"; 2619 c5.matchType = CarrierIdentifier.MatchType.GID2; 2620 c5.matchData = "GID2"; 2621 2622 ArrayList<Carrier> expected = new ArrayList<>(); 2623 expected.add(c1); 2624 expected.add(c2); 2625 expected.add(c3); 2626 expected.add(c4); 2627 expected.add(c5); 2628 2629 ArrayList<Carrier> result = RILUtils.convertToHalCarrierRestrictionList(carriers); 2630 2631 assertEquals(result, expected); 2632 } 2633 2634 @Test testEnableUiccApplications()2635 public void testEnableUiccApplications() throws Exception { 2636 // Not supported on Radio 1.0. 2637 mRILUnderTest.enableUiccApplications(false, obtainMessage()); 2638 verify(mSimProxy, never()).enableUiccApplications(anyInt(), anyBoolean()); 2639 2640 // Make radio version 1.5 to support the operation. 2641 try { 2642 replaceInstance(RIL.class, "mHalVersion", mRILUnderTest, mHalVersionV15); 2643 } catch (Exception e) { 2644 } 2645 mRILUnderTest.enableUiccApplications(false, obtainMessage()); 2646 verify(mSimProxy).enableUiccApplications(mSerialNumberCaptor.capture(), anyBoolean()); 2647 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), 2648 RIL_REQUEST_ENABLE_UICC_APPLICATIONS); 2649 } 2650 2651 @Test testAreUiccApplicationsEnabled()2652 public void testAreUiccApplicationsEnabled() throws Exception { 2653 // Not supported on Radio 1.0. 2654 mRILUnderTest.areUiccApplicationsEnabled(obtainMessage()); 2655 verify(mSimProxy, never()).areUiccApplicationsEnabled(mSerialNumberCaptor.capture()); 2656 2657 // Make radio version 1.5 to support the operation. 2658 try { 2659 replaceInstance(RIL.class, "mHalVersion", mRILUnderTest, mHalVersionV15); 2660 } catch (Exception e) { 2661 } 2662 mRILUnderTest.areUiccApplicationsEnabled(obtainMessage()); 2663 verify(mSimProxy).areUiccApplicationsEnabled(mSerialNumberCaptor.capture()); 2664 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), 2665 RIL_REQUEST_GET_UICC_APPLICATIONS_ENABLEMENT); 2666 } 2667 2668 @Test testAreUiccApplicationsEnabled_nullRadioProxy()2669 public void testAreUiccApplicationsEnabled_nullRadioProxy() throws Exception { 2670 // Not supported on Radio 1.0. 2671 doReturn(null).when(mRILUnderTest).getRadioProxy(); 2672 Message message = obtainMessage(); 2673 mRILUnderTest.areUiccApplicationsEnabled(message); 2674 processAllMessages(); 2675 verify(mSimProxy, never()).areUiccApplicationsEnabled(mSerialNumberCaptor.capture()); 2676 // Sending message is handled by getRadioProxy when proxy is null. 2677 // areUiccApplicationsEnabled shouldn't explicitly send another callback. 2678 assertNull(message.obj); 2679 } 2680 2681 @Test testSetGetCompatVersion()2682 public void testSetGetCompatVersion() { 2683 final int testRequest = RIL_REQUEST_GET_UICC_APPLICATIONS_ENABLEMENT; 2684 2685 // getCompactVersion should return null before first setting 2686 assertNull(mRILUnderTest.getCompatVersion(testRequest)); 2687 2688 // first time setting any valid HalVersion will success 2689 mRILUnderTest.setCompatVersion(testRequest, RIL.RADIO_HAL_VERSION_1_5); 2690 assertEquals(RIL.RADIO_HAL_VERSION_1_5, mRILUnderTest.getCompatVersion(testRequest)); 2691 2692 // try to set a lower HalVersion will success 2693 mRILUnderTest.setCompatVersion(testRequest, RIL.RADIO_HAL_VERSION_1_4); 2694 assertEquals(RIL.RADIO_HAL_VERSION_1_4, mRILUnderTest.getCompatVersion(testRequest)); 2695 2696 // try to set a greater HalVersion will not success 2697 mRILUnderTest.setCompatVersion(testRequest, RIL.RADIO_HAL_VERSION_1_6); 2698 assertEquals(RIL.RADIO_HAL_VERSION_1_4, mRILUnderTest.getCompatVersion(testRequest)); 2699 } 2700 2701 @FlakyTest 2702 @Test testGetSlicingConfig()2703 public void testGetSlicingConfig() throws Exception { 2704 // Use Radio HAL v1.6 2705 try { 2706 replaceInstance(RIL.class, "mHalVersion", mRILUnderTest, mHalVersionV16); 2707 } catch (Exception e) { 2708 } 2709 mRILUnderTest.getSlicingConfig(obtainMessage()); 2710 verify(mRadioProxy).getSlicingConfig(mSerialNumberCaptor.capture()); 2711 verifyRILResponse_1_6( 2712 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_GET_SLICING_CONFIG); 2713 } 2714 2715 @Test getImei()2716 public void getImei() throws RemoteException { 2717 try { 2718 replaceInstance(RIL.class, "mHalVersion", mRILUnderTest, mHalVersionV21); 2719 } catch (Exception e) { 2720 fail(); 2721 } 2722 mRILUnderTest.getImei(obtainMessage()); 2723 verify(mRadioModemProxy, atLeast(1)).getImei(mSerialNumberCaptor.capture()); 2724 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_DEVICE_IMEI); 2725 } 2726 2727 @Test getImeiNotSupported()2728 public void getImeiNotSupported() { 2729 try { 2730 replaceInstance(RIL.class, "mHalVersion", mRILUnderTest, mHalVersionV16); 2731 } catch (Exception e) { 2732 fail(); 2733 } 2734 Message message = obtainMessage(); 2735 mRILUnderTest.getImei(message); 2736 AsyncResult ar = (AsyncResult) message.obj; 2737 Assert.assertNull(ar.result); 2738 Assert.assertNotNull(ar.exception.getMessage()); 2739 Assert.assertEquals("REQUEST_NOT_SUPPORTED", ar.exception.getMessage()); 2740 } 2741 2742 @Test testRadioServiceInvokeHelper()2743 public void testRadioServiceInvokeHelper() throws Exception { 2744 CountDownLatch latch = new CountDownLatch(1); 2745 HandlerThread handlerThread = new HandlerThread("testRilServiceInvokeHelper"); 2746 handlerThread.start(); 2747 Handler handler = new Handler(handlerThread.getLooper()) { 2748 public void handleMessage(Message msg) { 2749 AsyncResult ar = (AsyncResult) msg.obj; 2750 if (ar != null && ar.exception instanceof CommandException) { 2751 CommandException.Error err = 2752 ((CommandException) (ar.exception)).getCommandError(); 2753 if (err == CommandException.Error.SYSTEM_ERR) { 2754 latch.countDown(); 2755 } 2756 } 2757 } 2758 }; 2759 2760 // RuntimeException 2761 doThrow(new RuntimeException()).when(mDataProxy).getDataCallList(anyInt()); 2762 mRILUnderTest.getDataCallList(handler.obtainMessage()); 2763 assertTrue(latch.await(3, TimeUnit.SECONDS)); 2764 2765 // RemoteException 2766 doThrow(new RemoteException()).when(mDataProxy).getDataCallList(anyInt()); 2767 mRILUnderTest.getDataCallList(handler.obtainMessage()); 2768 assertEquals(mRILUnderTest.getRadioState(), TelephonyManager.RADIO_POWER_UNAVAILABLE); 2769 } 2770 2771 2772 @Test testRadioServiceNotAvailable()2773 public void testRadioServiceNotAvailable() throws Exception { 2774 CountDownLatch latch = new CountDownLatch(1); 2775 HandlerThread handlerThread = new HandlerThread("testRadioServiceNotAvailable"); 2776 handlerThread.start(); 2777 Handler handler = new Handler(handlerThread.getLooper()) { 2778 public void handleMessage(Message msg) { 2779 AsyncResult ar = (AsyncResult) msg.obj; 2780 if (ar != null && ar.exception instanceof CommandException) { 2781 CommandException.Error err = 2782 ((CommandException) (ar.exception)).getCommandError(); 2783 if (err == CommandException.Error.RADIO_NOT_AVAILABLE) { 2784 latch.countDown(); 2785 } 2786 } 2787 } 2788 }; 2789 2790 when(mDataProxy.isEmpty()).thenReturn(true); 2791 mRILUnderTest.getDataCallList(handler.obtainMessage()); 2792 assertTrue(latch.await(3, TimeUnit.SECONDS)); 2793 } 2794 } 2795