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