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