RILTest.java revision 370c13358a56461ec12c711303c7cb986c85e3b6
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 17package com.android.internal.telephony; 18 19import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU; 20import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ALLOW_DATA; 21import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE; 22import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CHANGE_SIM_PIN; 23import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CHANGE_SIM_PIN2; 24import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CONFERENCE; 25import static com.android.internal.telephony.RILConstants.RIL_REQUEST_DATA_REGISTRATION_STATE; 26import static com.android.internal.telephony.RILConstants.RIL_REQUEST_DELETE_SMS_ON_SIM; 27import static com.android.internal.telephony.RILConstants.RIL_REQUEST_DEVICE_IDENTITY; 28import static com.android.internal.telephony.RILConstants.RIL_REQUEST_DTMF; 29import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION; 30import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ENTER_SIM_PIN; 31import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ENTER_SIM_PIN2; 32import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ENTER_SIM_PUK; 33import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ENTER_SIM_PUK2; 34import static com.android.internal.telephony.RILConstants.RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE; 35import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_ACTIVITY_INFO; 36import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_CELL_INFO_LIST; 37import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_CURRENT_CALLS; 38import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_HARDWARE_CONFIG; 39import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_IMSI; 40import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_RADIO_CAPABILITY; 41import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_SIM_STATUS; 42import static com.android.internal.telephony.RILConstants.RIL_REQUEST_GET_SMSC_ADDRESS; 43import static com.android.internal.telephony.RILConstants.RIL_REQUEST_HANGUP; 44import static com.android.internal.telephony.RILConstants.RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND; 45import static com.android.internal.telephony.RILConstants.RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND; 46import static com.android.internal.telephony.RILConstants.RIL_REQUEST_IMS_REGISTRATION_STATE; 47import static com.android.internal.telephony.RILConstants.RIL_REQUEST_IMS_SEND_SMS; 48import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ISIM_AUTHENTICATION; 49import static com.android.internal.telephony.RILConstants.RIL_REQUEST_LAST_CALL_FAIL_CAUSE; 50import static com.android.internal.telephony.RILConstants.RIL_REQUEST_NV_READ_ITEM; 51import static com.android.internal.telephony.RILConstants.RIL_REQUEST_NV_RESET_CONFIG; 52import static com.android.internal.telephony.RILConstants.RIL_REQUEST_NV_WRITE_ITEM; 53import static com.android.internal.telephony.RILConstants.RIL_REQUEST_OPERATOR; 54import static com.android.internal.telephony.RILConstants.RIL_REQUEST_PULL_LCEDATA; 55import static com.android.internal.telephony.RILConstants.RIL_REQUEST_RADIO_POWER; 56import static com.android.internal.telephony.RILConstants.RIL_REQUEST_REPORT_SMS_MEMORY_STATUS; 57import static com.android.internal.telephony.RILConstants.RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING; 58import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SEND_DEVICE_STATE; 59import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SEND_SMS; 60import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SEND_SMS_EXPECT_MORE; 61import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_INITIAL_ATTACH_APN; 62import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_SIM_CARD_POWER; 63import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_SMSC_ADDRESS; 64import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER; 65import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE; 66import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SHUTDOWN; 67import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SIGNAL_STRENGTH; 68import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SIM_AUTHENTICATION; 69import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SIM_CLOSE_CHANNEL; 70import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SIM_OPEN_CHANNEL; 71import static com.android.internal.telephony.RILConstants.RIL_REQUEST_START_LCE; 72import static com.android.internal.telephony.RILConstants.RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM; 73import static com.android.internal.telephony.RILConstants.RIL_REQUEST_STOP_LCE; 74import static com.android.internal.telephony.RILConstants.RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE; 75import static com.android.internal.telephony.RILConstants.RIL_REQUEST_UDUB; 76import static com.android.internal.telephony.RILConstants.RIL_REQUEST_VOICE_RADIO_TECH; 77import static com.android.internal.telephony.RILConstants.RIL_REQUEST_VOICE_REGISTRATION_STATE; 78import static com.android.internal.telephony.RILConstants.RIL_REQUEST_WRITE_SMS_TO_SIM; 79 80import static junit.framework.Assert.assertEquals; 81import static junit.framework.Assert.assertFalse; 82import static junit.framework.Assert.assertNotNull; 83import static junit.framework.Assert.assertTrue; 84 85import static org.junit.Assert.fail; 86import static org.mockito.Matchers.any; 87import static org.mockito.Matchers.eq; 88import static org.mockito.Mockito.doReturn; 89import static org.mockito.Mockito.mock; 90import static org.mockito.Mockito.spy; 91import static org.mockito.Mockito.times; 92import static org.mockito.Mockito.verify; 93 94import android.content.Context; 95import android.content.pm.ApplicationInfo; 96import android.hardware.radio.V1_0.CdmaSmsMessage; 97import android.hardware.radio.V1_0.DataProfileInfo; 98import android.hardware.radio.V1_0.GsmSmsMessage; 99import android.hardware.radio.V1_0.IRadio; 100import android.hardware.radio.V1_0.ImsSmsMessage; 101import android.hardware.radio.V1_0.NvWriteItem; 102import android.hardware.radio.V1_0.RadioError; 103import android.hardware.radio.V1_0.RadioResponseInfo; 104import android.hardware.radio.V1_0.RadioResponseType; 105import android.hardware.radio.V1_0.SetupDataCallResult; 106import android.hardware.radio.V1_0.SmsWriteArgs; 107import android.net.ConnectivityManager; 108import android.net.LinkAddress; 109import android.net.NetworkUtils; 110import android.os.Handler; 111import android.os.HandlerThread; 112import android.os.IPowerManager; 113import android.os.Message; 114import android.os.PowerManager; 115import android.os.WorkSource; 116import android.support.test.filters.FlakyTest; 117import android.telephony.CellIdentityCdma; 118import android.telephony.CellIdentityGsm; 119import android.telephony.CellIdentityLte; 120import android.telephony.CellIdentityWcdma; 121import android.telephony.CellInfo; 122import android.telephony.CellInfoCdma; 123import android.telephony.CellInfoGsm; 124import android.telephony.CellInfoLte; 125import android.telephony.CellInfoWcdma; 126import android.telephony.CellSignalStrengthCdma; 127import android.telephony.CellSignalStrengthGsm; 128import android.telephony.CellSignalStrengthLte; 129import android.telephony.CellSignalStrengthWcdma; 130import android.telephony.SmsManager; 131import android.telephony.TelephonyManager; 132import android.telephony.data.DataCallResponse; 133import android.telephony.data.DataProfile; 134 135import com.android.internal.telephony.RIL.RilHandler; 136import com.android.internal.telephony.dataconnection.ApnSetting; 137import com.android.internal.telephony.dataconnection.DcTracker; 138 139import org.junit.After; 140import org.junit.Before; 141import org.junit.Test; 142import org.mockito.ArgumentCaptor; 143import org.mockito.Mock; 144import org.mockito.MockitoAnnotations; 145 146import java.lang.reflect.InvocationTargetException; 147import java.lang.reflect.Method; 148import java.util.ArrayList; 149import java.util.Arrays; 150 151public class RILTest extends TelephonyTest { 152 153 // refer to RIL#DEFAULT_BLOCKING_MESSAGE_RESPONSE_TIMEOUT_MS 154 private static final int DEFAULT_BLOCKING_MESSAGE_RESPONSE_TIMEOUT_MS = 2000; 155 156 // refer to RIL#DEFAULT_WAKE_LOCK_TIMEOUT_MS 157 private static final int DEFAULT_WAKE_LOCK_TIMEOUT_MS = 60000; 158 159 @Mock 160 private ConnectivityManager mConnectionManager; 161 @Mock 162 private IRadio mRadioProxy; 163 164 private RilHandler mRilHandler; 165 private RIL mRILInstance; 166 private RIL mRILUnderTest; 167 private RILTestHandler mTestHandler; 168 ArgumentCaptor<Integer> mSerialNumberCaptor = ArgumentCaptor.forClass(Integer.class); 169 170 // Constants 171 private static final String ALPHA_LONG = "long"; 172 private static final String ALPHA_SHORT = "short"; 173 private static final int ARFCN = 690; 174 private static final int BASESTATION_ID = 65531; 175 private static final int BIT_ERROR_RATE = 99; 176 private static final int BSIC = 8; 177 private static final int CI = 268435456; 178 private static final int CID = 65535; 179 private static final int CQI = 2147483647; 180 private static final int DBM = 74; 181 private static final int EARFCN = 262140; 182 private static final int ECIO = 124; 183 private static final String EMPTY_ALPHA_LONG = ""; 184 private static final String EMPTY_ALPHA_SHORT = ""; 185 private static final int LAC = 65535; 186 private static final int LATITUDE = 1292000; 187 private static final int LONGITUDE = 1295000; 188 private static final int MCC = 120; 189 private static final String MCC_STR = "120"; 190 private static final int MNC = 260; 191 private static final String MNC_STR = "260"; 192 private static final int NETWORK_ID = 65534; 193 private static final int PCI = 503; 194 private static final int PSC = 500; 195 private static final int RIL_TIMESTAMP_TYPE_OEM_RIL = 3; 196 private static final int RSSNR = 2147483647; 197 private static final int RSRP = 96; 198 private static final int RSRQ = 10; 199 private static final int SIGNAL_NOICE_RATIO = 6; 200 private static final int SIGNAL_STRENGTH = 24; 201 private static final int SYSTEM_ID = 65533; 202 private static final int TAC = 65535; 203 private static final int TIME_ADVANCE = 4; 204 private static final long TIMESTAMP = 215924934; 205 private static final int UARFCN = 690; 206 private static final int TYPE_CDMA = 2; 207 private static final int TYPE_GSM = 1; 208 private static final int TYPE_LTE = 3; 209 private static final int TYPE_WCDMA = 4; 210 211 private class RILTestHandler extends HandlerThread { 212 213 RILTestHandler(String name) { 214 super(name); 215 } 216 217 @Override 218 protected void onLooperPrepared() { 219 super.onLooperPrepared(); 220 createTelephonyDevController(); 221 Context context = new ContextFixture().getTestDouble(); 222 doReturn(true).when(mConnectionManager) 223 .isNetworkSupported(ConnectivityManager.TYPE_MOBILE); 224 doReturn(mConnectionManager).when(context) 225 .getSystemService(Context.CONNECTIVITY_SERVICE); 226 PowerManager powerManager = createPowerManager(context); 227 doReturn(powerManager).when(context).getSystemService(Context.POWER_SERVICE); 228 doReturn(new ApplicationInfo()).when(context).getApplicationInfo(); 229 230 mRILInstance = new RIL(context, RILConstants.PREFERRED_NETWORK_MODE, 231 Phone.PREFERRED_CDMA_SUBSCRIPTION, 0); 232 mRILUnderTest = spy(mRILInstance); 233 doReturn(mRadioProxy).when(mRILUnderTest).getRadioProxy(any()); 234 235 mRilHandler = mRILUnderTest.getRilHandler(); 236 237 setReady(true); 238 } 239 240 private PowerManager createPowerManager(Context context) { 241 return new PowerManager(context, mock(IPowerManager.class), new Handler(getLooper())); 242 } 243 244 private void createTelephonyDevController() { 245 try { 246 TelephonyDevController.create(); 247 } catch (RuntimeException e) { 248 } 249 } 250 } 251 252 @Before 253 public void setUp() { 254 MockitoAnnotations.initMocks(this); 255 mTestHandler = new RILTestHandler(getClass().getSimpleName()); 256 mTestHandler.start(); 257 waitUntilReady(); 258 } 259 260 @After 261 public void tearDown() throws Exception { 262 mTestHandler.quit(); 263 } 264 265 @FlakyTest 266 @Test 267 public void testGetIccCardStatus() throws Exception { 268 mRILUnderTest.getIccCardStatus(obtainMessage()); 269 verify(mRadioProxy).getIccCardStatus(mSerialNumberCaptor.capture()); 270 verifyRILResponse( 271 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_GET_SIM_STATUS); 272 } 273 274 @FlakyTest 275 @Test 276 public void testSupplyIccPinForApp() throws Exception { 277 String pin = "1234"; 278 String aid = "2345"; 279 mRILUnderTest.supplyIccPinForApp(pin, aid, obtainMessage()); 280 verify(mRadioProxy).supplyIccPinForApp(mSerialNumberCaptor.capture(), eq(pin), eq(aid)); 281 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_ENTER_SIM_PIN); 282 } 283 284 @FlakyTest 285 @Test 286 public void testSupplyIccPukForApp() throws Exception { 287 String puk = "pukcode"; 288 String newPin = "1314"; 289 String aid = "2345"; 290 mRILUnderTest.supplyIccPukForApp(puk, newPin, aid, obtainMessage()); 291 verify(mRadioProxy) 292 .supplyIccPukForApp(mSerialNumberCaptor.capture(), eq(puk), eq(newPin), eq(aid)); 293 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_ENTER_SIM_PUK); 294 } 295 296 @FlakyTest 297 @Test 298 public void testSupplyIccPin2ForApp() throws Exception { 299 String pin = "1234"; 300 String aid = "2345"; 301 mRILUnderTest.supplyIccPin2ForApp(pin, aid, obtainMessage()); 302 verify(mRadioProxy).supplyIccPin2ForApp( 303 mSerialNumberCaptor.capture(), eq(pin), eq(aid)); 304 verifyRILResponse( 305 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_ENTER_SIM_PIN2); 306 } 307 308 @FlakyTest 309 @Test 310 public void testSupplyIccPuk2ForApp() throws Exception { 311 String puk = "pukcode"; 312 String newPin = "1314"; 313 String aid = "2345"; 314 mRILUnderTest.supplyIccPuk2ForApp(puk, newPin, aid, obtainMessage()); 315 verify(mRadioProxy) 316 .supplyIccPuk2ForApp(mSerialNumberCaptor.capture(), eq(puk), eq(newPin), eq(aid)); 317 verifyRILResponse( 318 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_ENTER_SIM_PUK2); 319 } 320 321 @FlakyTest 322 @Test 323 public void testChangeIccPinForApp() throws Exception { 324 String oldPin = "1234"; 325 String newPin = "1314"; 326 String aid = "2345"; 327 mRILUnderTest.changeIccPinForApp(oldPin, newPin, aid, obtainMessage()); 328 verify(mRadioProxy).changeIccPinForApp( 329 mSerialNumberCaptor.capture(), eq(oldPin), eq(newPin), eq(aid)); 330 verifyRILResponse( 331 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_CHANGE_SIM_PIN); 332 } 333 334 @FlakyTest 335 @Test 336 public void testChangeIccPin2ForApp() throws Exception { 337 String oldPin2 = "1234"; 338 String newPin2 = "1314"; 339 String aid = "2345"; 340 mRILUnderTest.changeIccPin2ForApp(oldPin2, newPin2, aid, obtainMessage()); 341 verify(mRadioProxy).changeIccPin2ForApp( 342 mSerialNumberCaptor.capture(), eq(oldPin2), eq(newPin2), eq(aid)); 343 verifyRILResponse( 344 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_CHANGE_SIM_PIN2); 345 } 346 347 @FlakyTest 348 @Test 349 public void testSupplyNetworkDepersonalization() throws Exception { 350 String netpin = "1234"; 351 mRILUnderTest.supplyNetworkDepersonalization(netpin, obtainMessage()); 352 verify(mRadioProxy).supplyNetworkDepersonalization( 353 mSerialNumberCaptor.capture(), eq(netpin)); 354 verifyRILResponse( 355 mRILUnderTest, 356 mSerialNumberCaptor.getValue(), 357 RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION); 358 } 359 360 @FlakyTest 361 @Test 362 public void testGetCurrentCalls() throws Exception { 363 mRILUnderTest.getCurrentCalls(obtainMessage()); 364 verify(mRadioProxy).getCurrentCalls(mSerialNumberCaptor.capture()); 365 verifyRILResponse( 366 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_GET_CURRENT_CALLS); 367 } 368 369 @FlakyTest 370 @Test 371 public void testGetIMSIForApp() throws Exception { 372 String aid = "1234"; 373 mRILUnderTest.getIMSIForApp(aid, obtainMessage()); 374 verify(mRadioProxy).getImsiForApp(mSerialNumberCaptor.capture(), eq(aid)); 375 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_GET_IMSI); 376 } 377 378 @FlakyTest 379 @Test 380 public void testHangupWaitingOrBackground() throws Exception { 381 mRILUnderTest.hangupWaitingOrBackground(obtainMessage()); 382 verify(mRadioProxy).hangupWaitingOrBackground(mSerialNumberCaptor.capture()); 383 verifyRILResponse( 384 mRILUnderTest, 385 mSerialNumberCaptor.getValue(), 386 RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND); 387 } 388 389 @FlakyTest 390 @Test 391 public void testHangupForegroundResumeBackground() throws Exception { 392 mRILUnderTest.hangupForegroundResumeBackground(obtainMessage()); 393 verify(mRadioProxy).hangupForegroundResumeBackground(mSerialNumberCaptor.capture()); 394 verifyRILResponse( 395 mRILUnderTest, 396 mSerialNumberCaptor.getValue(), 397 RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND); 398 } 399 400 @FlakyTest 401 @Test 402 public void testHangupConnection() throws Exception { 403 int gsmIndex = 0; 404 mRILUnderTest.hangupConnection(gsmIndex, obtainMessage()); 405 verify(mRadioProxy).hangup(mSerialNumberCaptor.capture(), eq(gsmIndex)); 406 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_HANGUP); 407 } 408 409 @FlakyTest 410 @Test 411 public void testSwitchWaitingOrHoldingAndActive() throws Exception { 412 mRILUnderTest.switchWaitingOrHoldingAndActive(obtainMessage()); 413 verify(mRadioProxy).switchWaitingOrHoldingAndActive(mSerialNumberCaptor.capture()); 414 verifyRILResponse( 415 mRILUnderTest, 416 mSerialNumberCaptor.getValue(), 417 RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE); 418 } 419 420 @FlakyTest 421 @Test 422 public void testConference() throws Exception { 423 mRILUnderTest.conference(obtainMessage()); 424 verify(mRadioProxy).conference(mSerialNumberCaptor.capture()); 425 verifyRILResponse( 426 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_CONFERENCE); 427 } 428 429 @FlakyTest 430 @Test 431 public void testRejectCall() throws Exception { 432 mRILUnderTest.rejectCall(obtainMessage()); 433 verify(mRadioProxy).rejectCall(mSerialNumberCaptor.capture()); 434 verifyRILResponse( 435 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_UDUB); 436 } 437 438 @FlakyTest 439 @Test 440 public void testGetLastCallFailCause() throws Exception { 441 mRILUnderTest.getLastCallFailCause(obtainMessage()); 442 verify(mRadioProxy).getLastCallFailCause(mSerialNumberCaptor.capture()); 443 verifyRILResponse( 444 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_LAST_CALL_FAIL_CAUSE); 445 } 446 447 @FlakyTest 448 @Test 449 public void testGetSignalStrength() throws Exception { 450 mRILUnderTest.getSignalStrength(obtainMessage()); 451 verify(mRadioProxy).getSignalStrength(mSerialNumberCaptor.capture()); 452 verifyRILResponse( 453 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SIGNAL_STRENGTH); 454 } 455 456 @FlakyTest 457 @Test 458 public void testGetVoiceRegistrationState() throws Exception { 459 mRILUnderTest.getVoiceRegistrationState(obtainMessage()); 460 verify(mRadioProxy).getVoiceRegistrationState(mSerialNumberCaptor.capture()); 461 verifyRILResponse( 462 mRILUnderTest, 463 mSerialNumberCaptor.getValue(), 464 RIL_REQUEST_VOICE_REGISTRATION_STATE); 465 } 466 467 @FlakyTest 468 @Test 469 public void testGetDataRegistrationState() throws Exception { 470 mRILUnderTest.getDataRegistrationState(obtainMessage()); 471 verify(mRadioProxy).getDataRegistrationState(mSerialNumberCaptor.capture()); 472 verifyRILResponse( 473 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_DATA_REGISTRATION_STATE); 474 } 475 476 @FlakyTest 477 @Test 478 public void testGetOperator() throws Exception { 479 mRILUnderTest.getOperator(obtainMessage()); 480 verify(mRadioProxy).getOperator(mSerialNumberCaptor.capture()); 481 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_OPERATOR); 482 } 483 484 @FlakyTest 485 @Test 486 public void testSetRadioPower() throws Exception { 487 boolean on = true; 488 mRILUnderTest.setRadioPower(on, obtainMessage()); 489 verify(mRadioProxy).setRadioPower(mSerialNumberCaptor.capture(), eq(on)); 490 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_RADIO_POWER); 491 } 492 493 @FlakyTest 494 @Test 495 public void testSendDtmf() throws Exception { 496 char c = 'c'; 497 mRILUnderTest.sendDtmf(c, obtainMessage()); 498 verify(mRadioProxy).sendDtmf(mSerialNumberCaptor.capture(), eq(c + "")); 499 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_DTMF); 500 } 501 502 @FlakyTest 503 @Test 504 public void testSendSMS() throws Exception { 505 String smscPdu = "smscPdu"; 506 String pdu = "pdu"; 507 GsmSmsMessage msg = new GsmSmsMessage(); 508 msg.smscPdu = smscPdu; 509 msg.pdu = pdu; 510 mRILUnderTest.sendSMS(smscPdu, pdu, obtainMessage()); 511 verify(mRadioProxy).sendSms(mSerialNumberCaptor.capture(), eq(msg)); 512 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SEND_SMS); 513 } 514 515 @FlakyTest 516 @Test 517 public void testSendSMSExpectMore() throws Exception { 518 String smscPdu = "smscPdu"; 519 String pdu = "pdu"; 520 GsmSmsMessage msg = new GsmSmsMessage(); 521 msg.smscPdu = smscPdu; 522 msg.pdu = pdu; 523 mRILUnderTest.sendSMSExpectMore(smscPdu, pdu, obtainMessage()); 524 verify(mRadioProxy).sendSMSExpectMore(mSerialNumberCaptor.capture(), eq(msg)); 525 verifyRILResponse( 526 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SEND_SMS_EXPECT_MORE); 527 } 528 529 @FlakyTest 530 @Test 531 public void testWriteSmsToSim() throws Exception { 532 String smscPdu = "smscPdu"; 533 String pdu = "pdu"; 534 int status = SmsManager.STATUS_ON_ICC_READ; 535 SmsWriteArgs args = new SmsWriteArgs(); 536 args.status = 1; 537 args.smsc = smscPdu; 538 args.pdu = pdu; 539 mRILUnderTest.writeSmsToSim(status, smscPdu, pdu, obtainMessage()); 540 verify(mRadioProxy).writeSmsToSim(mSerialNumberCaptor.capture(), eq(args)); 541 verifyRILResponse( 542 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_WRITE_SMS_TO_SIM); 543 } 544 545 @FlakyTest 546 @Test 547 public void testDeleteSmsOnSim() throws Exception { 548 int index = 0; 549 mRILUnderTest.deleteSmsOnSim(index, obtainMessage()); 550 verify(mRadioProxy).deleteSmsOnSim(mSerialNumberCaptor.capture(), eq(index)); 551 verifyRILResponse( 552 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_DELETE_SMS_ON_SIM); 553 } 554 555 @FlakyTest 556 @Test 557 public void testGetDeviceIdentity() throws Exception { 558 mRILUnderTest.getDeviceIdentity(obtainMessage()); 559 verify(mRadioProxy).getDeviceIdentity(mSerialNumberCaptor.capture()); 560 verifyRILResponse( 561 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_DEVICE_IDENTITY); 562 } 563 564 @FlakyTest 565 @Test 566 public void testExitEmergencyCallbackMode() throws Exception { 567 mRILUnderTest.exitEmergencyCallbackMode(obtainMessage()); 568 verify(mRadioProxy).exitEmergencyCallbackMode(mSerialNumberCaptor.capture()); 569 verifyRILResponse( 570 mRILUnderTest, 571 mSerialNumberCaptor.getValue(), 572 RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE); 573 } 574 575 @FlakyTest 576 @Test 577 public void testGetSmscAddress() throws Exception { 578 mRILUnderTest.getSmscAddress(obtainMessage()); 579 verify(mRadioProxy).getSmscAddress(mSerialNumberCaptor.capture()); 580 verifyRILResponse( 581 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_GET_SMSC_ADDRESS); 582 } 583 584 @FlakyTest 585 @Test 586 public void testSetSmscAddress() throws Exception { 587 String address = "address"; 588 mRILUnderTest.setSmscAddress(address, obtainMessage()); 589 verify(mRadioProxy).setSmscAddress(mSerialNumberCaptor.capture(), eq(address)); 590 verifyRILResponse( 591 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SET_SMSC_ADDRESS); 592 } 593 594 @FlakyTest 595 @Test 596 public void testReportSmsMemoryStatus() throws Exception { 597 boolean available = true; 598 mRILUnderTest.reportSmsMemoryStatus(available, obtainMessage()); 599 verify(mRadioProxy).reportSmsMemoryStatus(mSerialNumberCaptor.capture(), eq(available)); 600 verifyRILResponse( 601 mRILUnderTest, 602 mSerialNumberCaptor.getValue(), 603 RIL_REQUEST_REPORT_SMS_MEMORY_STATUS); 604 } 605 606 @FlakyTest 607 @Test 608 public void testReportStkServiceIsRunning() throws Exception { 609 mRILUnderTest.reportStkServiceIsRunning(obtainMessage()); 610 verify(mRadioProxy).reportStkServiceIsRunning(mSerialNumberCaptor.capture()); 611 verifyRILResponse( 612 mRILUnderTest, 613 mSerialNumberCaptor.getValue(), 614 RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING); 615 } 616 617 @FlakyTest 618 @Test 619 public void testGetCdmaSubscriptionSource() throws Exception { 620 mRILUnderTest.getCdmaSubscriptionSource(obtainMessage()); 621 verify(mRadioProxy).getCdmaSubscriptionSource(mSerialNumberCaptor.capture()); 622 verifyRILResponse( 623 mRILUnderTest, 624 mSerialNumberCaptor.getValue(), 625 RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE); 626 } 627 628 @FlakyTest 629 @Test 630 public void testRequestIsimAuthentication() throws Exception { 631 String nonce = "nonce"; 632 mRILUnderTest.requestIsimAuthentication(nonce, obtainMessage()); 633 verify(mRadioProxy).requestIsimAuthentication(mSerialNumberCaptor.capture(), eq(nonce)); 634 verifyRILResponse( 635 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_ISIM_AUTHENTICATION); 636 } 637 638 @FlakyTest 639 @Test 640 public void testAcknowledgeIncomingGsmSmsWithPdu() throws Exception { 641 boolean success = true; 642 String ackPdu = "ackPdu"; 643 mRILUnderTest.acknowledgeIncomingGsmSmsWithPdu(success, ackPdu, obtainMessage()); 644 verify(mRadioProxy).acknowledgeIncomingGsmSmsWithPdu( 645 mSerialNumberCaptor.capture(), eq(success), eq(ackPdu)); 646 verifyRILResponse( 647 mRILUnderTest, 648 mSerialNumberCaptor.getValue(), 649 RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU); 650 } 651 652 @FlakyTest 653 @Test 654 public void testGetVoiceRadioTechnology() throws Exception { 655 mRILUnderTest.getVoiceRadioTechnology(obtainMessage()); 656 verify(mRadioProxy).getVoiceRadioTechnology(mSerialNumberCaptor.capture()); 657 verifyRILResponse( 658 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_VOICE_RADIO_TECH); 659 } 660 661 @FlakyTest 662 @Test 663 public void testGetCellInfoList() throws Exception { 664 mRILUnderTest.getCellInfoList(obtainMessage(), null); 665 verify(mRadioProxy).getCellInfoList(mSerialNumberCaptor.capture()); 666 verifyRILResponse( 667 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_GET_CELL_INFO_LIST); 668 } 669 670 @FlakyTest 671 @Test 672 public void testSetCellInfoListRate() throws Exception { 673 int rateInMillis = 1000; 674 mRILUnderTest.setCellInfoListRate(rateInMillis, obtainMessage(), null); 675 verify(mRadioProxy).setCellInfoListRate(mSerialNumberCaptor.capture(), eq(rateInMillis)); 676 verifyRILResponse( 677 mRILUnderTest, 678 mSerialNumberCaptor.getValue(), 679 RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE); 680 } 681 682 @FlakyTest 683 @Test 684 public void testSetInitialAttachApn() throws Exception { 685 ApnSetting apnSetting = new ApnSetting( 686 -1, "22210", "Vodafone IT", "web.omnitel.it", "", "", 687 "", "", "", "", "", 0, new String[]{"DUN"}, "IP", "IP", true, 0, 0, 688 0, false, 0, 0, 0, 0, "", ""); 689 DataProfile dataProfile = DcTracker.createDataProfile(apnSetting, apnSetting.profileId); 690 boolean isRoaming = false; 691 692 mRILUnderTest.setInitialAttachApn(dataProfile, isRoaming, obtainMessage()); 693 verify(mRadioProxy).setInitialAttachApn( 694 mSerialNumberCaptor.capture(), 695 eq((DataProfileInfo) invokeMethod( 696 mRILInstance, 697 "convertToHalDataProfile", 698 new Class<?>[] {DataProfile.class}, 699 new Object[] {dataProfile})), 700 eq(dataProfile.isModemCognitive()), 701 eq(isRoaming)); 702 verifyRILResponse( 703 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SET_INITIAL_ATTACH_APN); 704 } 705 706 @FlakyTest 707 @Test 708 public void testGetImsRegistrationState() throws Exception { 709 mRILUnderTest.getImsRegistrationState(obtainMessage()); 710 verify(mRadioProxy).getImsRegistrationState(mSerialNumberCaptor.capture()); 711 verifyRILResponse( 712 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_IMS_REGISTRATION_STATE); 713 } 714 715 @FlakyTest 716 @Test 717 public void testSendRetryImsGsmSms() throws Exception { 718 String smscPdu = "smscPdu"; 719 String pdu = "pdu"; 720 GsmSmsMessage gsmMsg = new GsmSmsMessage(); 721 gsmMsg.smscPdu = smscPdu; 722 gsmMsg.pdu = pdu; 723 724 ImsSmsMessage firstMsg = new ImsSmsMessage(); 725 firstMsg.tech = RILConstants.GSM_PHONE; 726 firstMsg.retry = false; 727 firstMsg.messageRef = 0; 728 firstMsg.gsmMessage.add(gsmMsg); 729 730 ImsSmsMessage retryMsg = new ImsSmsMessage(); 731 retryMsg.tech = RILConstants.GSM_PHONE; 732 retryMsg.retry = true; 733 retryMsg.messageRef = 0; 734 retryMsg.gsmMessage.add(gsmMsg); 735 736 int maxRetryCount = 3; 737 int firstTransmission = 0; 738 for (int i = 0; i <= maxRetryCount; i++) { 739 mRILUnderTest.sendImsGsmSms(smscPdu, pdu, i, 0, obtainMessage()); 740 if (i == firstTransmission) { 741 verify(mRadioProxy, times(1)).sendImsSms(mSerialNumberCaptor.capture(), 742 eq(firstMsg)); 743 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), 744 RIL_REQUEST_IMS_SEND_SMS); 745 } else { 746 verify(mRadioProxy, times(i)).sendImsSms(mSerialNumberCaptor.capture(), 747 eq(retryMsg)); 748 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), 749 RIL_REQUEST_IMS_SEND_SMS); 750 } 751 } 752 } 753 754 @FlakyTest 755 @Test 756 public void testSendRetryImsCdmaSms() throws Exception { 757 CdmaSmsMessage cdmaMsg = new CdmaSmsMessage(); 758 759 ImsSmsMessage firstMsg = new ImsSmsMessage(); 760 firstMsg.tech = RILConstants.CDMA_PHONE; 761 firstMsg.retry = false; 762 firstMsg.messageRef = 0; 763 firstMsg.cdmaMessage.add(cdmaMsg); 764 765 ImsSmsMessage retryMsg = new ImsSmsMessage(); 766 retryMsg.tech = RILConstants.CDMA_PHONE; 767 retryMsg.retry = true; 768 retryMsg.messageRef = 0; 769 retryMsg.cdmaMessage.add(cdmaMsg); 770 771 int maxRetryCount = 3; 772 int firstTransmission = 0; 773 byte pdu[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 774 for (int i = 0; i <= maxRetryCount; i++) { 775 mRILUnderTest.sendImsCdmaSms(pdu, i, 0, obtainMessage()); 776 if (i == firstTransmission) { 777 verify(mRadioProxy, times(1)).sendImsSms(mSerialNumberCaptor.capture(), 778 eq(firstMsg)); 779 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), 780 RIL_REQUEST_IMS_SEND_SMS); 781 } else { 782 verify(mRadioProxy, times(i)).sendImsSms(mSerialNumberCaptor.capture(), 783 eq(retryMsg)); 784 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), 785 RIL_REQUEST_IMS_SEND_SMS); 786 } 787 } 788 } 789 790 @FlakyTest 791 @Test 792 public void testIccOpenLogicalChannel() throws Exception { 793 String aid = "aid"; 794 int p2 = 0; 795 mRILUnderTest.iccOpenLogicalChannel(aid, p2, obtainMessage()); 796 verify(mRadioProxy).iccOpenLogicalChannel(mSerialNumberCaptor.capture(), eq(aid), eq(p2)); 797 verifyRILResponse( 798 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SIM_OPEN_CHANNEL); 799 } 800 801 @FlakyTest 802 @Test 803 public void testIccCloseLogicalChannel() throws Exception { 804 int channel = 1; 805 mRILUnderTest.iccCloseLogicalChannel(channel, obtainMessage()); 806 verify(mRadioProxy).iccCloseLogicalChannel(mSerialNumberCaptor.capture(), eq(channel)); 807 verifyRILResponse( 808 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SIM_CLOSE_CHANNEL); 809 } 810 811 @FlakyTest 812 @Test 813 public void testNvWriteItem() throws Exception { 814 int itemId = 1; 815 String itemValue = "value"; 816 mRILUnderTest.nvWriteItem(itemId, itemValue, obtainMessage()); 817 NvWriteItem item = new NvWriteItem(); 818 item.itemId = itemId; 819 item.value = itemValue; 820 verify(mRadioProxy).nvWriteItem(mSerialNumberCaptor.capture(), eq(item)); 821 verifyRILResponse( 822 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_NV_WRITE_ITEM); 823 } 824 825 @FlakyTest 826 @Test 827 public void testNvReadItem() throws Exception { 828 int itemId = 1; 829 mRILUnderTest.nvReadItem(itemId, obtainMessage()); 830 verify(mRadioProxy).nvReadItem(mSerialNumberCaptor.capture(), eq(itemId)); 831 verifyRILResponse( 832 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_NV_READ_ITEM); 833 } 834 835 @FlakyTest 836 @Test 837 public void testNvResetConfig() throws Exception { 838 int resetType = 1; 839 mRILUnderTest.nvResetConfig(resetType, obtainMessage()); 840 verify(mRadioProxy).nvResetConfig( 841 mSerialNumberCaptor.capture(), 842 eq((Integer) invokeMethod( 843 mRILInstance, 844 "convertToHalResetNvType", 845 new Class<?>[] {Integer.TYPE}, 846 new Object[] {resetType}))); 847 verifyRILResponse( 848 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_NV_RESET_CONFIG); 849 } 850 851 @FlakyTest 852 @Test 853 public void testSetDataAllowed() throws Exception { 854 boolean allowed = true; 855 mRILUnderTest.setDataAllowed(allowed, obtainMessage()); 856 verify(mRadioProxy).setDataAllowed(mSerialNumberCaptor.capture(), eq(allowed)); 857 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_ALLOW_DATA); 858 } 859 860 @FlakyTest 861 @Test 862 public void testGetHardwareConfig() throws Exception { 863 mRILUnderTest.getHardwareConfig(obtainMessage()); 864 verify(mRadioProxy).getHardwareConfig(mSerialNumberCaptor.capture()); 865 verifyRILResponse( 866 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_GET_HARDWARE_CONFIG); 867 } 868 869 @FlakyTest 870 @Test 871 public void testRequestIccSimAuthentication() throws Exception { 872 int authContext = 1; 873 String data = "data"; 874 String aid = "aid"; 875 mRILUnderTest.requestIccSimAuthentication(authContext, data, aid, obtainMessage()); 876 verify(mRadioProxy).requestIccSimAuthentication( 877 mSerialNumberCaptor.capture(), eq(authContext), eq(data), eq(aid)); 878 verifyRILResponse( 879 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SIM_AUTHENTICATION); 880 } 881 882 @FlakyTest 883 @Test 884 public void testRequestShutdown() throws Exception { 885 mRILUnderTest.requestShutdown(obtainMessage()); 886 verify(mRadioProxy).requestShutdown(mSerialNumberCaptor.capture()); 887 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SHUTDOWN); 888 } 889 890 @FlakyTest 891 @Test 892 public void testGetRadioCapability() throws Exception { 893 mRILUnderTest.getRadioCapability(obtainMessage()); 894 verify(mRadioProxy).getRadioCapability(mSerialNumberCaptor.capture()); 895 verifyRILResponse( 896 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_GET_RADIO_CAPABILITY); 897 } 898 899 @FlakyTest 900 @Test 901 public void testStartLceService() throws Exception { 902 int reportIntervalMs = 1000; 903 boolean pullMode = false; 904 mRILUnderTest.startLceService(reportIntervalMs, pullMode, obtainMessage()); 905 verify(mRadioProxy).startLceService( 906 mSerialNumberCaptor.capture(), eq(reportIntervalMs), eq(pullMode)); 907 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_START_LCE); 908 } 909 910 @FlakyTest 911 @Test 912 public void testStopLceService() throws Exception { 913 mRILUnderTest.stopLceService(obtainMessage()); 914 verify(mRadioProxy).stopLceService(mSerialNumberCaptor.capture()); 915 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_STOP_LCE); 916 } 917 918 @FlakyTest 919 @Test 920 public void testPullLceData() throws Exception { 921 mRILUnderTest.pullLceData(obtainMessage()); 922 verify(mRadioProxy).pullLceData(mSerialNumberCaptor.capture()); 923 verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_PULL_LCEDATA); 924 } 925 926 @FlakyTest 927 @Test 928 public void testGetModemActivityInfo() throws Exception { 929 mRILUnderTest.getModemActivityInfo(obtainMessage()); 930 verify(mRadioProxy).getModemActivityInfo(mSerialNumberCaptor.capture()); 931 verifyRILResponse( 932 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_GET_ACTIVITY_INFO); 933 } 934 935 @FlakyTest 936 @Test 937 public void testGetModemActivityInfoTimeout() { 938 mRILUnderTest.getModemActivityInfo(obtainMessage()); 939 assertEquals(1, mRILUnderTest.getRilRequestList().size()); 940 waitForHandlerActionDelayed(mRilHandler, 10, DEFAULT_BLOCKING_MESSAGE_RESPONSE_TIMEOUT_MS); 941 assertEquals(0, mRILUnderTest.getRilRequestList().size()); 942 } 943 944 @FlakyTest 945 @Test 946 public void testSendDeviceState() throws Exception { 947 int stateType = 1; 948 boolean state = false; 949 mRILUnderTest.sendDeviceState(stateType, state, obtainMessage()); 950 verify(mRadioProxy).sendDeviceState( 951 mSerialNumberCaptor.capture(), eq(stateType), eq(state)); 952 verifyRILResponse( 953 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SEND_DEVICE_STATE); 954 } 955 956 @FlakyTest 957 @Test 958 public void testSetUnsolResponseFilter() throws Exception { 959 int filter = 1; 960 mRILUnderTest.setUnsolResponseFilter(filter, obtainMessage()); 961 verify(mRadioProxy).setIndicationFilter(mSerialNumberCaptor.capture(), eq(filter)); 962 verifyRILResponse( 963 mRILUnderTest, 964 mSerialNumberCaptor.getValue(), 965 RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER); 966 } 967 968 @FlakyTest 969 @Test 970 public void testSetSimCardPowerForPowerDownState() throws Exception { 971 mRILUnderTest.setSimCardPower(TelephonyManager.CARD_POWER_DOWN, obtainMessage()); 972 verify(mRadioProxy).setSimCardPower(mSerialNumberCaptor.capture(), eq(false)); 973 verifyRILResponse( 974 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SET_SIM_CARD_POWER); 975 } 976 977 @FlakyTest 978 @Test 979 public void testSetSimCardPowerForPowerUpState() throws Exception { 980 mRILUnderTest.setSimCardPower(TelephonyManager.CARD_POWER_UP, obtainMessage()); 981 verify(mRadioProxy).setSimCardPower(mSerialNumberCaptor.capture(), eq(true)); 982 verifyRILResponse( 983 mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SET_SIM_CARD_POWER); 984 } 985 986 @FlakyTest 987 @Test 988 public void testHandleCallSetupRequestFromSim() throws Exception { 989 boolean accept = true; 990 mRILUnderTest.handleCallSetupRequestFromSim(accept, obtainMessage()); 991 verify(mRadioProxy).handleStkCallSetupRequestFromSim( 992 mSerialNumberCaptor.capture(), eq(accept)); 993 verifyRILResponse( 994 mRILUnderTest, 995 mSerialNumberCaptor.getValue(), 996 RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM); 997 } 998 999 @FlakyTest 1000 @Test 1001 public void testWakeLockTimeout() throws Exception { 1002 invokeMethod( 1003 mRILInstance, 1004 "obtainRequest", 1005 new Class<?>[] {Integer.TYPE, Message.class, WorkSource.class}, 1006 new Object[] {RIL_REQUEST_GET_SIM_STATUS, obtainMessage(), null}); 1007 1008 // The wake lock should be held when obtain a RIL request. 1009 assertTrue(mRILInstance.getWakeLock(RIL.FOR_WAKELOCK).isHeld()); 1010 1011 waitForHandlerActionDelayed(mRilHandler, 10, DEFAULT_WAKE_LOCK_TIMEOUT_MS); 1012 1013 // The wake lock should be released after processed the time out event. 1014 assertFalse(mRILInstance.getWakeLock(RIL.FOR_WAKELOCK).isHeld()); 1015 } 1016 1017 private Message obtainMessage() { 1018 return mTestHandler.getThreadHandler().obtainMessage(); 1019 } 1020 1021 private static void verifyRILResponse(RIL ril, int serial, int requestType) { 1022 RadioResponseInfo responseInfo = 1023 createFakeRadioResponseInfo(serial, RadioError.NONE, RadioResponseType.SOLICITED); 1024 1025 RILRequest rr = ril.processResponse(responseInfo); 1026 assertNotNull(rr); 1027 1028 assertEquals(serial, rr.getSerial()); 1029 assertEquals(requestType, rr.getRequest()); 1030 assertTrue(ril.getWakeLock(RIL.FOR_WAKELOCK).isHeld()); 1031 1032 ril.processResponseDone(rr, responseInfo, null); 1033 assertEquals(0, ril.getRilRequestList().size()); 1034 assertFalse(ril.getWakeLock(RIL.FOR_WAKELOCK).isHeld()); 1035 } 1036 1037 private static Object invokeMethod( 1038 Object instance, String methodName, Class<?>[] parameterClasses, Object[] parameters) { 1039 try { 1040 Method method = instance.getClass().getDeclaredMethod(methodName, parameterClasses); 1041 method.setAccessible(true); 1042 return method.invoke(instance, parameters); 1043 } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { 1044 fail(instance.getClass() + " " + methodName + " " + e.getClass().getName()); 1045 } 1046 return null; 1047 } 1048 1049 private static RadioResponseInfo createFakeRadioResponseInfo(int serial, int error, int type) { 1050 RadioResponseInfo respInfo = new RadioResponseInfo(); 1051 respInfo.serial = serial; 1052 respInfo.error = error; 1053 respInfo.type = type; 1054 return respInfo; 1055 } 1056 1057 @Test 1058 public void testConvertHalCellInfoListForLTE() throws Exception { 1059 android.hardware.radio.V1_0.CellInfoLte lte = new android.hardware.radio.V1_0.CellInfoLte(); 1060 lte.cellIdentityLte.ci = CI; 1061 lte.cellIdentityLte.pci = PCI; 1062 lte.cellIdentityLte.tac = TAC; 1063 lte.cellIdentityLte.earfcn = EARFCN; 1064 lte.cellIdentityLte.mcc = MCC_STR; 1065 lte.cellIdentityLte.mnc = MNC_STR; 1066 lte.signalStrengthLte.signalStrength = SIGNAL_STRENGTH; 1067 lte.signalStrengthLte.rsrp = RSRP; 1068 lte.signalStrengthLte.rsrq = RSRQ; 1069 lte.signalStrengthLte.rssnr = RSSNR; 1070 lte.signalStrengthLte.cqi = CQI; 1071 lte.signalStrengthLte.timingAdvance = TIME_ADVANCE; 1072 android.hardware.radio.V1_0.CellInfo record = new android.hardware.radio.V1_0.CellInfo(); 1073 record.cellInfoType = TYPE_LTE; 1074 record.registered = false; 1075 record.timeStampType = RIL_TIMESTAMP_TYPE_OEM_RIL; 1076 record.timeStamp = TIMESTAMP; 1077 record.lte.add(lte); 1078 ArrayList<android.hardware.radio.V1_0.CellInfo> records = 1079 new ArrayList<android.hardware.radio.V1_0.CellInfo>(); 1080 records.add(record); 1081 1082 ArrayList<CellInfo> ret = RIL.convertHalCellInfoList(records); 1083 1084 assertEquals(1, ret.size()); 1085 CellInfoLte cellInfoLte = (CellInfoLte) ret.get(0); 1086 CellInfoLte expected = new CellInfoLte(); 1087 expected.setRegistered(false); 1088 expected.setTimeStamp(TIMESTAMP); 1089 expected.setTimeStampType(RIL_TIMESTAMP_TYPE_OEM_RIL); 1090 CellIdentityLte cil = new CellIdentityLte( 1091 CI, PCI, TAC, EARFCN, MCC_STR, MNC_STR, EMPTY_ALPHA_LONG, EMPTY_ALPHA_SHORT); 1092 CellSignalStrengthLte css = new CellSignalStrengthLte( 1093 SIGNAL_STRENGTH, -RSRP, -RSRQ, RSSNR, CQI, TIME_ADVANCE); 1094 expected.setCellIdentity(cil); 1095 expected.setCellSignalStrength(css); 1096 assertEquals(expected, cellInfoLte); 1097 } 1098 1099 @Test 1100 public void testConvertHalCellInfoListForGSM() throws Exception { 1101 android.hardware.radio.V1_0.CellInfoGsm cellinfo = 1102 new android.hardware.radio.V1_0.CellInfoGsm(); 1103 cellinfo.cellIdentityGsm.lac = LAC; 1104 cellinfo.cellIdentityGsm.cid = CID; 1105 cellinfo.cellIdentityGsm.bsic = BSIC; 1106 cellinfo.cellIdentityGsm.arfcn = ARFCN; 1107 cellinfo.cellIdentityGsm.mcc = MCC_STR; 1108 cellinfo.cellIdentityGsm.mnc = MNC_STR; 1109 cellinfo.signalStrengthGsm.signalStrength = SIGNAL_STRENGTH; 1110 cellinfo.signalStrengthGsm.bitErrorRate = BIT_ERROR_RATE; 1111 cellinfo.signalStrengthGsm.timingAdvance = TIME_ADVANCE; 1112 android.hardware.radio.V1_0.CellInfo record = new android.hardware.radio.V1_0.CellInfo(); 1113 record.cellInfoType = TYPE_GSM; 1114 record.registered = false; 1115 record.timeStampType = RIL_TIMESTAMP_TYPE_OEM_RIL; 1116 record.timeStamp = TIMESTAMP; 1117 record.gsm.add(cellinfo); 1118 ArrayList<android.hardware.radio.V1_0.CellInfo> records = 1119 new ArrayList<android.hardware.radio.V1_0.CellInfo>(); 1120 records.add(record); 1121 1122 ArrayList<CellInfo> ret = RIL.convertHalCellInfoList(records); 1123 1124 assertEquals(1, ret.size()); 1125 CellInfoGsm cellInfoGsm = (CellInfoGsm) ret.get(0); 1126 CellInfoGsm expected = new CellInfoGsm(); 1127 expected.setRegistered(false); 1128 expected.setTimeStamp(TIMESTAMP); 1129 expected.setTimeStampType(RIL_TIMESTAMP_TYPE_OEM_RIL); 1130 CellIdentityGsm ci = new CellIdentityGsm( 1131 LAC, CID, ARFCN, BSIC, MCC_STR, MNC_STR, EMPTY_ALPHA_LONG, EMPTY_ALPHA_SHORT); 1132 CellSignalStrengthGsm cs = new CellSignalStrengthGsm(); 1133 cs.initialize(SIGNAL_STRENGTH, BIT_ERROR_RATE, TIME_ADVANCE); 1134 expected.setCellIdentity(ci); 1135 expected.setCellSignalStrength(cs); 1136 assertEquals(expected, cellInfoGsm); 1137 } 1138 1139 @Test 1140 public void testConvertHalCellInfoListForWcdma() throws Exception { 1141 android.hardware.radio.V1_0.CellInfoWcdma cellinfo = 1142 new android.hardware.radio.V1_0.CellInfoWcdma(); 1143 cellinfo.cellIdentityWcdma.lac = LAC; 1144 cellinfo.cellIdentityWcdma.cid = CID; 1145 cellinfo.cellIdentityWcdma.psc = PSC; 1146 cellinfo.cellIdentityWcdma.uarfcn = UARFCN; 1147 cellinfo.cellIdentityWcdma.mcc = MCC_STR; 1148 cellinfo.cellIdentityWcdma.mnc = MNC_STR; 1149 cellinfo.signalStrengthWcdma.signalStrength = SIGNAL_STRENGTH; 1150 cellinfo.signalStrengthWcdma.bitErrorRate = BIT_ERROR_RATE; 1151 android.hardware.radio.V1_0.CellInfo record = new android.hardware.radio.V1_0.CellInfo(); 1152 record.cellInfoType = TYPE_WCDMA; 1153 record.registered = false; 1154 record.timeStampType = RIL_TIMESTAMP_TYPE_OEM_RIL; 1155 record.timeStamp = TIMESTAMP; 1156 record.wcdma.add(cellinfo); 1157 ArrayList<android.hardware.radio.V1_0.CellInfo> records = 1158 new ArrayList<android.hardware.radio.V1_0.CellInfo>(); 1159 records.add(record); 1160 1161 ArrayList<CellInfo> ret = RIL.convertHalCellInfoList(records); 1162 1163 assertEquals(1, ret.size()); 1164 CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) ret.get(0); 1165 CellInfoWcdma expected = new CellInfoWcdma(); 1166 expected.setRegistered(false); 1167 expected.setTimeStamp(TIMESTAMP); 1168 expected.setTimeStampType(RIL_TIMESTAMP_TYPE_OEM_RIL); 1169 CellIdentityWcdma ci = new CellIdentityWcdma( 1170 LAC, CID, PSC, UARFCN, MCC_STR, MNC_STR, EMPTY_ALPHA_LONG, EMPTY_ALPHA_SHORT); 1171 CellSignalStrengthWcdma cs = new CellSignalStrengthWcdma(SIGNAL_STRENGTH, BIT_ERROR_RATE); 1172 expected.setCellIdentity(ci); 1173 expected.setCellSignalStrength(cs); 1174 assertEquals(expected, cellInfoWcdma); 1175 } 1176 1177 @Test 1178 public void testConvertHalCellInfoListForCdma() throws Exception { 1179 android.hardware.radio.V1_0.CellInfoCdma cellinfo = 1180 new android.hardware.radio.V1_0.CellInfoCdma(); 1181 cellinfo.cellIdentityCdma.networkId = NETWORK_ID; 1182 cellinfo.cellIdentityCdma.systemId = SYSTEM_ID; 1183 cellinfo.cellIdentityCdma.baseStationId = BASESTATION_ID; 1184 cellinfo.cellIdentityCdma.longitude = LONGITUDE; 1185 cellinfo.cellIdentityCdma.latitude = LATITUDE; 1186 cellinfo.signalStrengthCdma.dbm = DBM; 1187 cellinfo.signalStrengthCdma.ecio = ECIO; 1188 cellinfo.signalStrengthEvdo.dbm = DBM; 1189 cellinfo.signalStrengthEvdo.ecio = ECIO; 1190 cellinfo.signalStrengthEvdo.signalNoiseRatio = SIGNAL_NOICE_RATIO; 1191 android.hardware.radio.V1_0.CellInfo record = new android.hardware.radio.V1_0.CellInfo(); 1192 record.cellInfoType = TYPE_CDMA; 1193 record.registered = false; 1194 record.timeStampType = RIL_TIMESTAMP_TYPE_OEM_RIL; 1195 record.timeStamp = TIMESTAMP; 1196 record.cdma.add(cellinfo); 1197 ArrayList<android.hardware.radio.V1_0.CellInfo> records = 1198 new ArrayList<android.hardware.radio.V1_0.CellInfo>(); 1199 records.add(record); 1200 1201 ArrayList<CellInfo> ret = RIL.convertHalCellInfoList(records); 1202 1203 assertEquals(1, ret.size()); 1204 CellInfoCdma cellInfoCdma = (CellInfoCdma) ret.get(0); 1205 CellInfoCdma expected = new CellInfoCdma(); 1206 expected.setRegistered(false); 1207 expected.setTimeStamp(TIMESTAMP); 1208 expected.setTimeStampType(RIL_TIMESTAMP_TYPE_OEM_RIL); 1209 CellIdentityCdma ci = new CellIdentityCdma( 1210 NETWORK_ID, SYSTEM_ID, BASESTATION_ID, LONGITUDE, LATITUDE, 1211 EMPTY_ALPHA_LONG, EMPTY_ALPHA_SHORT); 1212 CellSignalStrengthCdma cs = new CellSignalStrengthCdma( 1213 -DBM, -ECIO, -DBM, -ECIO, SIGNAL_NOICE_RATIO); 1214 expected.setCellIdentity(ci); 1215 expected.setCellSignalStrength(cs); 1216 assertEquals(expected, cellInfoCdma); 1217 } 1218 1219 @Test 1220 public void testConvertHalCellInfoList_1_2ForLTE() throws Exception { 1221 ArrayList<CellInfo> ret = getCellInfoListForLTE(MCC_STR, MNC_STR, ALPHA_LONG, ALPHA_SHORT); 1222 1223 assertEquals(1, ret.size()); 1224 CellInfoLte cellInfoLte = (CellInfoLte) ret.get(0); 1225 CellInfoLte expected = new CellInfoLte(); 1226 expected.setRegistered(false); 1227 expected.setTimeStamp(TIMESTAMP); 1228 expected.setTimeStampType(RIL_TIMESTAMP_TYPE_OEM_RIL); 1229 CellIdentityLte cil = new CellIdentityLte( 1230 CI, PCI, TAC, EARFCN, MCC_STR, MNC_STR, ALPHA_LONG, ALPHA_SHORT); 1231 CellSignalStrengthLte css = new CellSignalStrengthLte( 1232 SIGNAL_STRENGTH, -RSRP, -RSRQ, RSSNR, CQI, TIME_ADVANCE); 1233 expected.setCellIdentity(cil); 1234 expected.setCellSignalStrength(css); 1235 assertEquals(expected, cellInfoLte); 1236 } 1237 1238 @Test 1239 public void testConvertHalCellInfoList_1_2_ForLTEWithEmptyOperatorInfo() throws Exception { 1240 ArrayList<CellInfo> ret = getCellInfoListForLTE( 1241 MCC_STR, MNC_STR, EMPTY_ALPHA_LONG, EMPTY_ALPHA_SHORT); 1242 1243 assertEquals(1, ret.size()); 1244 CellInfoLte cellInfoLte = (CellInfoLte) ret.get(0); 1245 CellInfoLte expected = new CellInfoLte(); 1246 expected.setRegistered(false); 1247 expected.setTimeStamp(TIMESTAMP); 1248 expected.setTimeStampType(RIL_TIMESTAMP_TYPE_OEM_RIL); 1249 CellIdentityLte cil = new CellIdentityLte( 1250 CI, PCI, TAC, EARFCN, MCC_STR, MNC_STR, EMPTY_ALPHA_LONG, EMPTY_ALPHA_SHORT); 1251 CellSignalStrengthLte css = new CellSignalStrengthLte( 1252 SIGNAL_STRENGTH, -RSRP, -RSRQ, RSSNR, CQI, TIME_ADVANCE); 1253 expected.setCellIdentity(cil); 1254 expected.setCellSignalStrength(css); 1255 assertEquals(expected, cellInfoLte); 1256 } 1257 1258 @Test 1259 public void testConvertHalCellInfoList_1_2ForLTEWithEmptyMccMnc() throws Exception { 1260 // MCC/MNC will be set as INT_MAX if unknown 1261 ArrayList<CellInfo> ret = getCellInfoListForLTE( 1262 String.valueOf(Integer.MAX_VALUE), String.valueOf(Integer.MAX_VALUE), 1263 ALPHA_LONG, ALPHA_SHORT); 1264 1265 assertEquals(1, ret.size()); 1266 CellInfoLte cellInfoLte = (CellInfoLte) ret.get(0); 1267 CellInfoLte expected = new CellInfoLte(); 1268 expected.setRegistered(false); 1269 expected.setTimeStamp(TIMESTAMP); 1270 expected.setTimeStampType(RIL_TIMESTAMP_TYPE_OEM_RIL); 1271 CellIdentityLte cil = new CellIdentityLte( 1272 CI, PCI, TAC, EARFCN, null, null, ALPHA_LONG, ALPHA_SHORT); 1273 CellSignalStrengthLte css = new CellSignalStrengthLte( 1274 SIGNAL_STRENGTH, -RSRP, -RSRQ, RSSNR, CQI, TIME_ADVANCE); 1275 expected.setCellIdentity(cil); 1276 expected.setCellSignalStrength(css); 1277 assertEquals(expected, cellInfoLte); 1278 } 1279 1280 @Test 1281 public void testConvertHalCellInfoList_1_2ForGSM() throws Exception { 1282 ArrayList<CellInfo> ret = getCellInfoListForGSM(MCC_STR, MNC_STR, ALPHA_LONG, ALPHA_SHORT); 1283 1284 assertEquals(1, ret.size()); 1285 CellInfoGsm cellInfoGsm = (CellInfoGsm) ret.get(0); 1286 CellInfoGsm expected = new CellInfoGsm(); 1287 expected.setRegistered(false); 1288 expected.setTimeStamp(TIMESTAMP); 1289 expected.setTimeStampType(RIL_TIMESTAMP_TYPE_OEM_RIL); 1290 CellIdentityGsm ci = new CellIdentityGsm( 1291 LAC, CID, ARFCN, BSIC, MCC_STR, MNC_STR, ALPHA_LONG, ALPHA_SHORT); 1292 CellSignalStrengthGsm cs = new CellSignalStrengthGsm(); 1293 cs.initialize(SIGNAL_STRENGTH, BIT_ERROR_RATE, TIME_ADVANCE); 1294 expected.setCellIdentity(ci); 1295 expected.setCellSignalStrength(cs); 1296 assertEquals(expected, cellInfoGsm); 1297 } 1298 1299 @Test 1300 public void testConvertHalCellInfoList_1_2ForGSMWithEmptyOperatorInfo() throws Exception { 1301 ArrayList<CellInfo> ret = getCellInfoListForGSM( 1302 MCC_STR, MNC_STR, EMPTY_ALPHA_LONG, EMPTY_ALPHA_SHORT); 1303 1304 assertEquals(1, ret.size()); 1305 CellInfoGsm cellInfoGsm = (CellInfoGsm) ret.get(0); 1306 CellInfoGsm expected = new CellInfoGsm(); 1307 expected.setRegistered(false); 1308 expected.setTimeStamp(TIMESTAMP); 1309 expected.setTimeStampType(RIL_TIMESTAMP_TYPE_OEM_RIL); 1310 CellIdentityGsm ci = new CellIdentityGsm( 1311 LAC, CID, ARFCN, BSIC, MCC_STR, MNC_STR, EMPTY_ALPHA_LONG, EMPTY_ALPHA_SHORT); 1312 CellSignalStrengthGsm cs = new CellSignalStrengthGsm(); 1313 cs.initialize(SIGNAL_STRENGTH, BIT_ERROR_RATE, TIME_ADVANCE); 1314 expected.setCellIdentity(ci); 1315 expected.setCellSignalStrength(cs); 1316 assertEquals(expected, cellInfoGsm); 1317 } 1318 1319 @Test 1320 public void testConvertHalCellInfoList_1_2ForGSMWithEmptyMccMnc() throws Exception { 1321 // MCC/MNC will be set as INT_MAX if unknown 1322 ArrayList<CellInfo> ret = getCellInfoListForGSM( 1323 String.valueOf(Integer.MAX_VALUE), String.valueOf(Integer.MAX_VALUE), 1324 ALPHA_LONG, ALPHA_SHORT); 1325 1326 assertEquals(1, ret.size()); 1327 CellInfoGsm cellInfoGsm = (CellInfoGsm) ret.get(0); 1328 CellInfoGsm expected = new CellInfoGsm(); 1329 expected.setRegistered(false); 1330 expected.setTimeStamp(TIMESTAMP); 1331 expected.setTimeStampType(RIL_TIMESTAMP_TYPE_OEM_RIL); 1332 CellIdentityGsm ci = new CellIdentityGsm( 1333 LAC, CID, ARFCN, BSIC, null, null, ALPHA_LONG, ALPHA_SHORT); 1334 CellSignalStrengthGsm cs = new CellSignalStrengthGsm(); 1335 cs.initialize(SIGNAL_STRENGTH, BIT_ERROR_RATE, TIME_ADVANCE); 1336 expected.setCellIdentity(ci); 1337 expected.setCellSignalStrength(cs); 1338 assertEquals(expected, cellInfoGsm); 1339 } 1340 1341 @Test 1342 public void testConvertHalCellInfoList_1_2ForWcdma() throws Exception { 1343 ArrayList<CellInfo> ret = getCellInfoListForWcdma( 1344 MCC_STR, MNC_STR, ALPHA_LONG, ALPHA_SHORT); 1345 1346 assertEquals(1, ret.size()); 1347 CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) ret.get(0); 1348 CellInfoWcdma expected = new CellInfoWcdma(); 1349 expected.setRegistered(false); 1350 expected.setTimeStamp(TIMESTAMP); 1351 expected.setTimeStampType(RIL_TIMESTAMP_TYPE_OEM_RIL); 1352 CellIdentityWcdma ci = new CellIdentityWcdma( 1353 LAC, CID, PSC, UARFCN, MCC_STR, MNC_STR, ALPHA_LONG, ALPHA_SHORT); 1354 CellSignalStrengthWcdma cs = new CellSignalStrengthWcdma(SIGNAL_STRENGTH, BIT_ERROR_RATE); 1355 expected.setCellIdentity(ci); 1356 expected.setCellSignalStrength(cs); 1357 assertEquals(expected, cellInfoWcdma); 1358 } 1359 1360 @Test 1361 public void testConvertHalCellInfoList_1_2ForWcdmaWithEmptyOperatorInfo() throws Exception { 1362 ArrayList<CellInfo> ret = getCellInfoListForWcdma( 1363 MCC_STR, MNC_STR, EMPTY_ALPHA_LONG, EMPTY_ALPHA_SHORT); 1364 1365 assertEquals(1, ret.size()); 1366 CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) ret.get(0); 1367 CellInfoWcdma expected = new CellInfoWcdma(); 1368 expected.setRegistered(false); 1369 expected.setTimeStamp(TIMESTAMP); 1370 expected.setTimeStampType(RIL_TIMESTAMP_TYPE_OEM_RIL); 1371 CellIdentityWcdma ci = new CellIdentityWcdma( 1372 LAC, CID, PSC, UARFCN, MCC_STR, MNC_STR, EMPTY_ALPHA_LONG, EMPTY_ALPHA_SHORT); 1373 CellSignalStrengthWcdma cs = new CellSignalStrengthWcdma(SIGNAL_STRENGTH, BIT_ERROR_RATE); 1374 expected.setCellIdentity(ci); 1375 expected.setCellSignalStrength(cs); 1376 assertEquals(expected, cellInfoWcdma); 1377 } 1378 1379 @Test 1380 public void testConvertHalCellInfoList_1_2ForWcdmaWithEmptyMccMnc() throws Exception { 1381 // MCC/MNC will be set as INT_MAX if unknown 1382 ArrayList<CellInfo> ret = getCellInfoListForWcdma( 1383 String.valueOf(Integer.MAX_VALUE), String.valueOf(Integer.MAX_VALUE), 1384 ALPHA_LONG, ALPHA_SHORT); 1385 1386 assertEquals(1, ret.size()); 1387 CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) ret.get(0); 1388 CellInfoWcdma expected = new CellInfoWcdma(); 1389 expected.setRegistered(false); 1390 expected.setTimeStamp(TIMESTAMP); 1391 expected.setTimeStampType(RIL_TIMESTAMP_TYPE_OEM_RIL); 1392 CellIdentityWcdma ci = new CellIdentityWcdma( 1393 LAC, CID, PSC, UARFCN, null, null, ALPHA_LONG, ALPHA_SHORT); 1394 CellSignalStrengthWcdma cs = new CellSignalStrengthWcdma(SIGNAL_STRENGTH, BIT_ERROR_RATE); 1395 expected.setCellIdentity(ci); 1396 expected.setCellSignalStrength(cs); 1397 assertEquals(expected, cellInfoWcdma); 1398 } 1399 1400 @Test 1401 public void testConvertHalCellInfoList_1_2ForCdma() throws Exception { 1402 ArrayList<CellInfo> ret = getCellInfoListForCdma(ALPHA_LONG, ALPHA_SHORT); 1403 1404 assertEquals(1, ret.size()); 1405 CellInfoCdma cellInfoCdma = (CellInfoCdma) ret.get(0); 1406 CellInfoCdma expected = new CellInfoCdma(); 1407 expected.setRegistered(false); 1408 expected.setTimeStamp(TIMESTAMP); 1409 expected.setTimeStampType(RIL_TIMESTAMP_TYPE_OEM_RIL); 1410 CellIdentityCdma ci = new CellIdentityCdma( 1411 NETWORK_ID, SYSTEM_ID, BASESTATION_ID, LONGITUDE, LATITUDE, 1412 ALPHA_LONG, ALPHA_SHORT); 1413 CellSignalStrengthCdma cs = new CellSignalStrengthCdma( 1414 -DBM, -ECIO, -DBM, -ECIO, SIGNAL_NOICE_RATIO); 1415 expected.setCellIdentity(ci); 1416 expected.setCellSignalStrength(cs); 1417 assertEquals(expected, cellInfoCdma); 1418 } 1419 1420 @Test 1421 public void testConvertHalCellInfoList_1_2ForCdmaWithEmptyOperatorInfd() throws Exception { 1422 ArrayList<CellInfo> ret = getCellInfoListForCdma(EMPTY_ALPHA_LONG, EMPTY_ALPHA_SHORT); 1423 1424 assertEquals(1, ret.size()); 1425 CellInfoCdma cellInfoCdma = (CellInfoCdma) ret.get(0); 1426 CellInfoCdma expected = new CellInfoCdma(); 1427 expected.setRegistered(false); 1428 expected.setTimeStamp(TIMESTAMP); 1429 expected.setTimeStampType(RIL_TIMESTAMP_TYPE_OEM_RIL); 1430 CellIdentityCdma ci = new CellIdentityCdma( 1431 NETWORK_ID, SYSTEM_ID, BASESTATION_ID, LONGITUDE, LATITUDE, 1432 EMPTY_ALPHA_LONG, EMPTY_ALPHA_SHORT); 1433 CellSignalStrengthCdma cs = new CellSignalStrengthCdma( 1434 -DBM, -ECIO, -DBM, -ECIO, SIGNAL_NOICE_RATIO); 1435 expected.setCellIdentity(ci); 1436 expected.setCellSignalStrength(cs); 1437 assertEquals(expected, cellInfoCdma); 1438 } 1439 1440 @Test 1441 public void testGetWorksourceClientId() { 1442 RILRequest request = RILRequest.obtain(0, null, null); 1443 assertEquals(null, request.getWorkSourceClientId()); 1444 1445 request = RILRequest.obtain(0, null, new WorkSource()); 1446 assertEquals(null, request.getWorkSourceClientId()); 1447 1448 WorkSource ws = new WorkSource(); 1449 ws.add(100); 1450 request = RILRequest.obtain(0, null, ws); 1451 assertEquals("100:null", request.getWorkSourceClientId()); 1452 1453 ws = new WorkSource(); 1454 ws.add(100, "foo"); 1455 request = RILRequest.obtain(0, null, ws); 1456 assertEquals("100:foo", request.getWorkSourceClientId()); 1457 1458 ws = new WorkSource(); 1459 ws.createWorkChain().addNode(100, "foo").addNode(200, "bar"); 1460 request = RILRequest.obtain(0, null, ws); 1461 assertEquals("100:foo", request.getWorkSourceClientId()); 1462 } 1463 1464 private ArrayList<CellInfo> getCellInfoListForLTE( 1465 String mcc, String mnc, String alphaLong, String alphaShort) { 1466 android.hardware.radio.V1_2.CellInfoLte lte = new android.hardware.radio.V1_2.CellInfoLte(); 1467 lte.cellIdentityLte.base.ci = CI; 1468 lte.cellIdentityLte.base.pci = PCI; 1469 lte.cellIdentityLte.base.tac = TAC; 1470 lte.cellIdentityLte.base.earfcn = EARFCN; 1471 lte.cellIdentityLte.base.mcc = mcc; 1472 lte.cellIdentityLte.base.mnc = mnc; 1473 lte.cellIdentityLte.operatorNames.alphaLong = alphaLong; 1474 lte.cellIdentityLte.operatorNames.alphaShort = alphaShort; 1475 lte.signalStrengthLte.signalStrength = SIGNAL_STRENGTH; 1476 lte.signalStrengthLte.rsrp = RSRP; 1477 lte.signalStrengthLte.rsrq = RSRQ; 1478 lte.signalStrengthLte.rssnr = RSSNR; 1479 lte.signalStrengthLte.cqi = CQI; 1480 lte.signalStrengthLte.timingAdvance = TIME_ADVANCE; 1481 android.hardware.radio.V1_2.CellInfo record = new android.hardware.radio.V1_2.CellInfo(); 1482 record.cellInfoType = TYPE_LTE; 1483 record.registered = false; 1484 record.timeStampType = RIL_TIMESTAMP_TYPE_OEM_RIL; 1485 record.timeStamp = TIMESTAMP; 1486 record.lte.add(lte); 1487 ArrayList<android.hardware.radio.V1_2.CellInfo> records = 1488 new ArrayList<android.hardware.radio.V1_2.CellInfo>(); 1489 records.add(record); 1490 return RIL.convertHalCellInfoList_1_2(records); 1491 } 1492 1493 private ArrayList<CellInfo> getCellInfoListForGSM( 1494 String mcc, String mnc, String alphaLong, String alphaShort) { 1495 android.hardware.radio.V1_2.CellInfoGsm cellinfo = 1496 new android.hardware.radio.V1_2.CellInfoGsm(); 1497 cellinfo.cellIdentityGsm.base.lac = LAC; 1498 cellinfo.cellIdentityGsm.base.cid = CID; 1499 cellinfo.cellIdentityGsm.base.bsic = BSIC; 1500 cellinfo.cellIdentityGsm.base.arfcn = ARFCN; 1501 cellinfo.cellIdentityGsm.base.mcc = mcc; 1502 cellinfo.cellIdentityGsm.base.mnc = mnc; 1503 cellinfo.cellIdentityGsm.operatorNames.alphaLong = alphaLong; 1504 cellinfo.cellIdentityGsm.operatorNames.alphaShort = alphaShort; 1505 cellinfo.signalStrengthGsm.signalStrength = SIGNAL_STRENGTH; 1506 cellinfo.signalStrengthGsm.bitErrorRate = BIT_ERROR_RATE; 1507 cellinfo.signalStrengthGsm.timingAdvance = TIME_ADVANCE; 1508 android.hardware.radio.V1_2.CellInfo record = new android.hardware.radio.V1_2.CellInfo(); 1509 record.cellInfoType = TYPE_GSM; 1510 record.registered = false; 1511 record.timeStampType = RIL_TIMESTAMP_TYPE_OEM_RIL; 1512 record.timeStamp = TIMESTAMP; 1513 record.gsm.add(cellinfo); 1514 ArrayList<android.hardware.radio.V1_2.CellInfo> records = 1515 new ArrayList<android.hardware.radio.V1_2.CellInfo>(); 1516 records.add(record); 1517 1518 return RIL.convertHalCellInfoList_1_2(records); 1519 } 1520 1521 private ArrayList<CellInfo> getCellInfoListForWcdma( 1522 String mcc, String mnc, String alphaLong, String alphaShort) { 1523 android.hardware.radio.V1_2.CellInfoWcdma cellinfo = 1524 new android.hardware.radio.V1_2.CellInfoWcdma(); 1525 cellinfo.cellIdentityWcdma.base.lac = LAC; 1526 cellinfo.cellIdentityWcdma.base.cid = CID; 1527 cellinfo.cellIdentityWcdma.base.psc = PSC; 1528 cellinfo.cellIdentityWcdma.base.uarfcn = UARFCN; 1529 cellinfo.cellIdentityWcdma.base.mcc = mcc; 1530 cellinfo.cellIdentityWcdma.base.mnc = mnc; 1531 cellinfo.cellIdentityWcdma.operatorNames.alphaLong = alphaLong; 1532 cellinfo.cellIdentityWcdma.operatorNames.alphaShort = alphaShort; 1533 cellinfo.signalStrengthWcdma.signalStrength = SIGNAL_STRENGTH; 1534 cellinfo.signalStrengthWcdma.bitErrorRate = BIT_ERROR_RATE; 1535 android.hardware.radio.V1_2.CellInfo record = new android.hardware.radio.V1_2.CellInfo(); 1536 record.cellInfoType = TYPE_WCDMA; 1537 record.registered = false; 1538 record.timeStampType = RIL_TIMESTAMP_TYPE_OEM_RIL; 1539 record.timeStamp = TIMESTAMP; 1540 record.wcdma.add(cellinfo); 1541 ArrayList<android.hardware.radio.V1_2.CellInfo> records = 1542 new ArrayList<android.hardware.radio.V1_2.CellInfo>(); 1543 records.add(record); 1544 1545 return RIL.convertHalCellInfoList_1_2(records); 1546 } 1547 1548 private ArrayList<CellInfo> getCellInfoListForCdma(String alphaLong, String alphaShort) { 1549 android.hardware.radio.V1_2.CellInfoCdma cellinfo = 1550 new android.hardware.radio.V1_2.CellInfoCdma(); 1551 cellinfo.cellIdentityCdma.base.networkId = NETWORK_ID; 1552 cellinfo.cellIdentityCdma.base.systemId = SYSTEM_ID; 1553 cellinfo.cellIdentityCdma.base.baseStationId = BASESTATION_ID; 1554 cellinfo.cellIdentityCdma.base.longitude = LONGITUDE; 1555 cellinfo.cellIdentityCdma.base.latitude = LATITUDE; 1556 cellinfo.cellIdentityCdma.operatorNames.alphaLong = alphaLong; 1557 cellinfo.cellIdentityCdma.operatorNames.alphaShort = alphaShort; 1558 cellinfo.signalStrengthCdma.dbm = DBM; 1559 cellinfo.signalStrengthCdma.ecio = ECIO; 1560 cellinfo.signalStrengthEvdo.dbm = DBM; 1561 cellinfo.signalStrengthEvdo.ecio = ECIO; 1562 cellinfo.signalStrengthEvdo.signalNoiseRatio = SIGNAL_NOICE_RATIO; 1563 android.hardware.radio.V1_2.CellInfo record = new android.hardware.radio.V1_2.CellInfo(); 1564 record.cellInfoType = TYPE_CDMA; 1565 record.registered = false; 1566 record.timeStampType = RIL_TIMESTAMP_TYPE_OEM_RIL; 1567 record.timeStamp = TIMESTAMP; 1568 record.cdma.add(cellinfo); 1569 ArrayList<android.hardware.radio.V1_2.CellInfo> records = 1570 new ArrayList<android.hardware.radio.V1_2.CellInfo>(); 1571 records.add(record); 1572 1573 return RIL.convertHalCellInfoList_1_2(records); 1574 } 1575 1576 @Test 1577 public void testConvertDataCallResult() throws Exception { 1578 1579 SetupDataCallResult result = new SetupDataCallResult(); 1580 result.status = 0; 1581 result.suggestedRetryTime = -1; 1582 result.cid = 1; 1583 result.active = 1; 1584 result.type = "IP"; 1585 result.ifname = "eth0"; 1586 result.addresses = "10.0.2.15"; 1587 result.dnses = "10.0.2.3"; 1588 result.gateways = "10.0.2.15 fe80::2"; 1589 result.pcscf = ""; 1590 result.mtu = 1500; 1591 1592 DataCallResponse response = new DataCallResponse(0, -1, 1, 1, "IP", 1593 "eth0", 1594 Arrays.asList(new LinkAddress(NetworkUtils.numericToInetAddress("10.0.2.15"), 32)), 1595 Arrays.asList(NetworkUtils.numericToInetAddress("10.0.2.3")), 1596 Arrays.asList(NetworkUtils.numericToInetAddress("10.0.2.15"), 1597 NetworkUtils.numericToInetAddress("fe80::2")), 1598 Arrays.asList(""), 1599 1500); 1600 1601 assertEquals(response, invokeMethod(mRILInstance, "convertDataCallResult", 1602 new Class<?>[] {SetupDataCallResult.class}, 1603 new Object[] {result})); 1604 1605 1606 result.status = 0; 1607 result.suggestedRetryTime = -1; 1608 result.cid = 0; 1609 result.active = 2; 1610 result.type = "IPV4V6"; 1611 result.ifname = "ifname"; 1612 result.addresses = "2607:fb90:a620:651d:eabe:f8da:c107:44be/64"; 1613 result.dnses = "fd00:976a::9 fd00:976a::10"; 1614 result.gateways = "fe80::4c61:1832:7b28:d36c 1.2.3.4"; 1615 result.pcscf = "fd00:976a:c206:20::6 fd00:976a:c206:20::9 fd00:976a:c202:1d::9"; 1616 result.mtu = 1500; 1617 1618 response = new DataCallResponse(0, -1, 0, 2, "IPV4V6", 1619 "ifname", 1620 Arrays.asList(new LinkAddress("2607:fb90:a620:651d:eabe:f8da:c107:44be/64")), 1621 Arrays.asList(NetworkUtils.numericToInetAddress("fd00:976a::9"), 1622 NetworkUtils.numericToInetAddress("fd00:976a::10")), 1623 Arrays.asList(NetworkUtils.numericToInetAddress("fe80::4c61:1832:7b28:d36c"), 1624 NetworkUtils.numericToInetAddress("1.2.3.4")), 1625 Arrays.asList("fd00:976a:c206:20::6", "fd00:976a:c206:20::9", 1626 "fd00:976a:c202:1d::9"), 1627 1500); 1628 1629 assertEquals(response, invokeMethod(mRILInstance, "convertDataCallResult", 1630 new Class<?>[] {SetupDataCallResult.class}, 1631 new Object[] {result})); 1632 } 1633} 1634