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