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