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