1/*
2 * Copyright (C) 2016 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 android.content.Context;
20import android.hardware.radio.V1_0.ActivityStatsInfo;
21import android.hardware.radio.V1_0.AppStatus;
22import android.hardware.radio.V1_0.CardStatus;
23import android.hardware.radio.V1_0.CarrierRestrictions;
24import android.hardware.radio.V1_0.CdmaBroadcastSmsConfigInfo;
25import android.hardware.radio.V1_0.DataRegStateResult;
26import android.hardware.radio.V1_0.GsmBroadcastSmsConfigInfo;
27import android.hardware.radio.V1_0.IRadioResponse;
28import android.hardware.radio.V1_0.LastCallFailCauseInfo;
29import android.hardware.radio.V1_0.LceDataInfo;
30import android.hardware.radio.V1_0.LceStatusInfo;
31import android.hardware.radio.V1_0.NeighboringCell;
32import android.hardware.radio.V1_0.RadioError;
33import android.hardware.radio.V1_0.RadioResponseInfo;
34import android.hardware.radio.V1_0.SendSmsResult;
35import android.hardware.radio.V1_0.SetupDataCallResult;
36import android.hardware.radio.V1_0.VoiceRegStateResult;
37import android.os.AsyncResult;
38import android.os.Message;
39import android.os.SystemClock;
40import android.service.carrier.CarrierIdentifier;
41import android.telephony.CellInfo;
42import android.telephony.ModemActivityInfo;
43import android.telephony.NeighboringCellInfo;
44import android.telephony.PhoneNumberUtils;
45import android.telephony.SignalStrength;
46import android.telephony.SubscriptionManager;
47import android.telephony.TelephonyManager;
48
49import com.android.internal.telephony.dataconnection.DataCallResponse;
50import com.android.internal.telephony.gsm.SmsBroadcastConfigInfo;
51import com.android.internal.telephony.uicc.IccCardApplicationStatus;
52import com.android.internal.telephony.uicc.IccCardStatus;
53import com.android.internal.telephony.uicc.IccIoResult;
54import com.android.internal.telephony.uicc.IccUtils;
55
56import java.util.ArrayList;
57import java.util.Collections;
58import java.util.List;
59
60public class RadioResponse extends IRadioResponse.Stub {
61    // The number of the required config values for broadcast SMS stored in the C struct
62    // RIL_CDMA_BroadcastServiceInfo
63    private static final int CDMA_BSI_NO_OF_INTS_STRUCT = 3;
64
65    private static final int CDMA_BROADCAST_SMS_NO_OF_SERVICE_CATEGORIES = 31;
66
67    RIL mRil;
68
69    public RadioResponse(RIL ril) {
70        mRil = ril;
71    }
72
73    /**
74     * Helper function to send response msg
75     * @param msg Response message to be sent
76     * @param ret Return object to be included in the response message
77     */
78    static void sendMessageResponse(Message msg, Object ret) {
79        if (msg != null) {
80            AsyncResult.forMessage(msg, ret, null);
81            msg.sendToTarget();
82        }
83    }
84
85    /**
86     * Acknowledge the receipt of radio request sent to the vendor. This must be sent only for
87     * radio request which take long time to respond.
88     * For more details, refer https://source.android.com/devices/tech/connect/ril.html
89     *
90     * @param serial Serial no. of the request whose acknowledgement is sent.
91     */
92    public void acknowledgeRequest(int serial) {
93        mRil.processRequestAck(serial);
94    }
95
96    /**
97     * @param responseInfo Response info struct containing response type, serial no. and error
98     * @param cardStatus ICC card status as defined by CardStatus in types.hal
99     */
100    public void getIccCardStatusResponse(RadioResponseInfo responseInfo, CardStatus cardStatus) {
101        responseIccCardStatus(responseInfo, cardStatus);
102    }
103
104    /**
105     * @param responseInfo Response info struct containing response type, serial no. and error
106     * @param remainingAttempts Number of retries remaining, must be equal to -1 if unknown.
107     */
108    public void supplyIccPinForAppResponse(RadioResponseInfo responseInfo, int remainingAttempts) {
109        responseInts(responseInfo, remainingAttempts);
110    }
111
112    /**
113     * @param responseInfo Response info struct containing response type, serial no. and error
114     * @param remainingAttempts Number of retries remaining, must be equal to -1 if unknown.
115     */
116    public void supplyIccPukForAppResponse(RadioResponseInfo responseInfo, int remainingAttempts) {
117        responseInts(responseInfo, remainingAttempts);
118    }
119
120    /**
121     * @param responseInfo Response info struct containing response type, serial no. and error
122     * @param remainingAttempts Number of retries remaining, must be equal to -1 if unknown.
123     */
124    public void supplyIccPin2ForAppResponse(RadioResponseInfo responseInfo, int remainingAttempts) {
125        responseInts(responseInfo, remainingAttempts);
126    }
127
128    /**
129     * @param responseInfo Response info struct containing response type, serial no. and error
130     * @param remainingAttempts Number of retries remaining, must be equal to -1 if unknown.
131     */
132    public void supplyIccPuk2ForAppResponse(RadioResponseInfo responseInfo, int remainingAttempts) {
133        responseInts(responseInfo, remainingAttempts);
134    }
135
136    /**
137     * @param responseInfo Response info struct containing response type, serial no. and error
138     * @param remainingAttempts Number of retries remaining, must be equal to -1 if unknown.
139     */
140    public void changeIccPinForAppResponse(RadioResponseInfo responseInfo, int remainingAttempts) {
141        responseInts(responseInfo, remainingAttempts);
142    }
143
144    /**
145     * @param responseInfo Response info struct containing response type, serial no. and error
146     * @param remainingAttempts Number of retries remaining, must be equal to -1 if unknown.
147     */
148    public void changeIccPin2ForAppResponse(RadioResponseInfo responseInfo, int remainingAttempts) {
149        responseInts(responseInfo, remainingAttempts);
150    }
151
152    /**
153     * @param responseInfo Response info struct containing response type, serial no. and error
154     * @param retriesRemaining Number of retries remaining, must be equal to -1 if unknown.
155     */
156    public void supplyNetworkDepersonalizationResponse(RadioResponseInfo responseInfo,
157                                                       int retriesRemaining) {
158        responseInts(responseInfo, retriesRemaining);
159    }
160
161    /**
162     * @param responseInfo Response info struct containing response type, serial no. and error
163     * @param calls Current call list
164     */
165    public void getCurrentCallsResponse(RadioResponseInfo responseInfo,
166                                        ArrayList<android.hardware.radio.V1_0.Call> calls) {
167        responseCurrentCalls(responseInfo, calls);
168    }
169
170    /**
171     * @param responseInfo Response info struct containing response type, serial no. and error
172     */
173    public void dialResponse(RadioResponseInfo responseInfo) {
174        responseVoid(responseInfo);
175    }
176
177    /**
178     * @param responseInfo Response info struct containing response type, serial no. and error
179     * @param imsi String containing the IMSI
180     */
181    public void getIMSIForAppResponse(RadioResponseInfo responseInfo, String imsi) {
182        responseString(responseInfo, imsi);
183    }
184
185    /**
186     * @param responseInfo Response info struct containing response type, serial no. and error
187     */
188    public void hangupConnectionResponse(RadioResponseInfo responseInfo) {
189        responseVoid(responseInfo);
190    }
191
192    /**
193     * @param responseInfo Response info struct containing response type, serial no. and error
194     */
195    public void hangupWaitingOrBackgroundResponse(RadioResponseInfo responseInfo) {
196        responseVoid(responseInfo);
197    }
198
199    /**
200     * @param responseInfo Response info struct containing response type, serial no. and error
201     */
202    public void hangupForegroundResumeBackgroundResponse(RadioResponseInfo responseInfo) {
203        responseVoid(responseInfo);
204    }
205
206    /**
207     * @param responseInfo Response info struct containing response type, serial no. and error
208     */
209    public void switchWaitingOrHoldingAndActiveResponse(RadioResponseInfo responseInfo) {
210        responseVoid(responseInfo);
211    }
212
213    /**
214     * @param responseInfo Response info struct containing response type, serial no. and error
215     */
216    public void conferenceResponse(RadioResponseInfo responseInfo) {
217        responseVoid(responseInfo);
218    }
219
220    /**
221     * @param responseInfo Response info struct containing response type, serial no. and error
222     */
223    public void rejectCallResponse(RadioResponseInfo responseInfo) {
224        responseVoid(responseInfo);
225    }
226
227    /**
228     * @param responseInfo Response info struct containing response type, serial no. and error
229     * @param fcInfo Contains LastCallFailCause and vendor cause code. GSM failure reasons
230     *        are mapped to cause codes defined in TS 24.008 Annex H where possible. CDMA
231     *        failure reasons are derived from the possible call failure scenarios
232     *        described in the "CDMA IS-2000 Release A (C.S0005-A v6.0)" standard.
233     */
234    public void getLastCallFailCauseResponse(RadioResponseInfo responseInfo,
235                                             LastCallFailCauseInfo fcInfo) {
236        responseLastCallFailCauseInfo(responseInfo, fcInfo);
237    }
238
239    public void getSignalStrengthResponse(RadioResponseInfo responseInfo,
240                                          android.hardware.radio.V1_0.SignalStrength sigStrength) {
241        responseSignalStrength(responseInfo, sigStrength);
242    }
243
244    /*
245     * @param responseInfo Response info struct containing response type, serial no. and error
246     * @param voiceRegResponse Current Voice registration response as defined by VoiceRegStateResult
247     *        in types.hal
248     */
249    public void getVoiceRegistrationStateResponse(RadioResponseInfo responseInfo,
250                                                  VoiceRegStateResult voiceRegResponse) {
251        RILRequest rr = mRil.processResponse(responseInfo);
252
253        if (rr != null) {
254            if (responseInfo.error == RadioError.NONE) {
255                sendMessageResponse(rr.mResult, voiceRegResponse);
256            }
257            mRil.processResponseDone(rr, responseInfo, voiceRegResponse);
258        }
259    }
260
261    /**
262     * @param responseInfo Response info struct containing response type, serial no. and error
263     * @param dataRegResponse Current Data registration response as defined by DataRegStateResult in
264     *        types.hal
265     */
266    public void getDataRegistrationStateResponse(RadioResponseInfo responseInfo,
267                                                 DataRegStateResult dataRegResponse) {
268        RILRequest rr = mRil.processResponse(responseInfo);
269
270        if (rr != null) {
271            if (responseInfo.error == RadioError.NONE) {
272                sendMessageResponse(rr.mResult, dataRegResponse);
273            }
274            mRil.processResponseDone(rr, responseInfo, dataRegResponse);
275        }
276    }
277
278    /**
279     * @param responseInfo Response info struct containing response type, serial no. and error
280     * @param longName is long alpha ONS or EONS or empty string if unregistered
281     * @param shortName is short alpha ONS or EONS or empty string if unregistered
282     * @param numeric is 5 or 6 digit numeric code (MCC + MNC) or empty string if unregistered
283     */
284    public void getOperatorResponse(RadioResponseInfo responseInfo,
285                                    String longName,
286                                    String shortName,
287                                    String numeric) {
288        responseStrings(responseInfo, longName, shortName, numeric);
289    }
290
291    /**
292     * @param responseInfo Response info struct containing response type, serial no. and error
293     */
294    public void setRadioPowerResponse(RadioResponseInfo responseInfo) {
295        responseVoid(responseInfo);
296    }
297
298    /**
299     * @param responseInfo Response info struct containing response type, serial no. and error
300     */
301    public void sendDtmfResponse(RadioResponseInfo responseInfo) {
302        responseVoid(responseInfo);
303    }
304
305    /**
306     * @param responseInfo Response info struct containing response type, serial no. and error
307     * @param sms Response to sms sent as defined by SendSmsResult in types.hal
308     */
309    public void sendSmsResponse(RadioResponseInfo responseInfo,
310                                SendSmsResult sms) {
311        responseSms(responseInfo, sms);
312    }
313
314    /**
315     * @param responseInfo Response info struct containing response type, serial no. and error
316     * @param sms Response to sms sent as defined by SendSmsResult in types.hal
317     */
318    public void sendSMSExpectMoreResponse(RadioResponseInfo responseInfo,
319                                          SendSmsResult sms) {
320        responseSms(responseInfo, sms);
321    }
322
323    /**
324     * @param responseInfo Response info struct containing response type, serial no. and error
325     * @param setupDataCallResult Response to data call setup as defined by setupDataCallResult in
326     *                            types.hal
327     */
328    public void setupDataCallResponse(RadioResponseInfo responseInfo,
329                                      SetupDataCallResult setupDataCallResult) {
330        responseSetupDataCall(responseInfo, setupDataCallResult);
331    }
332
333    /**
334     * @param responseInfo Response info struct containing response type, serial no. and error
335     * @param iccIo ICC io operation response as defined by IccIoResult in types.hal
336     */
337    public void iccIOForAppResponse(RadioResponseInfo responseInfo,
338                            android.hardware.radio.V1_0.IccIoResult iccIo) {
339        responseIccIo(responseInfo, iccIo);
340    }
341
342    /**
343     * @param responseInfo Response info struct containing response type, serial no. and error
344     */
345    public void sendUssdResponse(RadioResponseInfo responseInfo) {
346        responseVoid(responseInfo);
347    }
348
349    /**
350     * @param responseInfo Response info struct containing response type, serial no. and error
351     */
352    public void cancelPendingUssdResponse(RadioResponseInfo responseInfo) {
353        responseVoid(responseInfo);
354    }
355
356    /**
357     * @param responseInfo Response info struct containing response type, serial no. and error
358     * @param n is "n" parameter from TS 27.007 7.7
359     * @param m is "m" parameter from TS 27.007 7.7
360     */
361    public void getClirResponse(RadioResponseInfo responseInfo, int n, int m) {
362        responseInts(responseInfo, n, m);
363    }
364
365    /**
366     * @param responseInfo Response info struct containing response type, serial no. and error
367     */
368    public void setClirResponse(RadioResponseInfo responseInfo) {
369        responseVoid(responseInfo);
370    }
371
372    /**
373     * @param responseInfo Response info struct containing response type, serial no. and error
374     * @param callForwardInfos points to a vector of CallForwardInfo, one for
375     *        each distinct registered phone number.
376     */
377    public void getCallForwardStatusResponse(RadioResponseInfo responseInfo,
378                                             ArrayList<android.hardware.radio.V1_0.CallForwardInfo>
379                                                     callForwardInfos) {
380        responseCallForwardInfo(responseInfo, callForwardInfos);
381    }
382
383    /**
384     * @param responseInfo Response info struct containing response type, serial no. and error
385     */
386    public void setCallForwardResponse(RadioResponseInfo responseInfo) {
387        responseVoid(responseInfo);
388    }
389
390    /**
391     * @param responseInfo Response info struct containing response type, serial no. and error
392     * @param enable If current call waiting state is disabled, enable = false else true
393     * @param serviceClass If enable, then callWaitingResp[1]
394     *        must follow, with the TS 27.007 service class bit vector of services
395     *        for which call waiting is enabled.
396     *        For example, if callWaitingResp[0] is 1 and
397     *        callWaitingResp[1] is 3, then call waiting is enabled for data
398     *        and voice and disabled for everything else.
399     */
400    public void getCallWaitingResponse(RadioResponseInfo responseInfo,
401                                   boolean enable,
402                                   int serviceClass) {
403        responseInts(responseInfo, enable ? 1 : 0, serviceClass);
404    }
405
406    /**
407     * @param responseInfo Response info struct containing response type, serial no. and error
408     */
409    public void setCallWaitingResponse(RadioResponseInfo responseInfo) {
410        responseVoid(responseInfo);
411    }
412
413    /**
414     * @param responseInfo Response info struct containing response type, serial no. and error
415     */
416    public void acknowledgeLastIncomingGsmSmsResponse(RadioResponseInfo responseInfo) {
417        responseVoid(responseInfo);
418    }
419
420    /**
421     * @param responseInfo Response info struct containing response type, serial no. and error
422     */
423    public void acceptCallResponse(RadioResponseInfo responseInfo) {
424        responseVoid(responseInfo);
425    }
426
427    /**
428     * @param responseInfo Response info struct containing response type, serial no. and error
429     */
430    public void deactivateDataCallResponse(RadioResponseInfo responseInfo) {
431        responseVoid(responseInfo);
432    }
433
434    /**
435     *
436     * @param responseInfo Response info struct containing response type, serial no. and error
437     * @param response 0 is the TS 27.007 service class bit vector of
438     *        services for which the specified barring facility
439     *        is active. "0" means "disabled for all"
440     */
441    public void getFacilityLockForAppResponse(RadioResponseInfo responseInfo, int response) {
442        responseInts(responseInfo, response);
443    }
444
445    /**
446     *
447     * @param responseInfo Response info struct containing response type, serial no. and error
448     * @param retry 0 is the number of retries remaining, or -1 if unknown
449     */
450    public void setFacilityLockForAppResponse(RadioResponseInfo responseInfo, int retry) {
451        responseInts(responseInfo, retry);
452    }
453
454    /**
455     * @param responseInfo Response info struct containing response type, serial no. and error
456     */
457    public void setBarringPasswordResponse(RadioResponseInfo responseInfo) {
458        responseVoid(responseInfo);
459    }
460
461    /**
462     *
463     * @param responseInfo Response info struct containing response type, serial no. and error
464     * @param selection false for automatic selection, true for manual selection
465     */
466    public void getNetworkSelectionModeResponse(RadioResponseInfo responseInfo, boolean selection) {
467        responseInts(responseInfo, selection ? 1 : 0);
468    }
469
470    /**
471     * @param responseInfo Response info struct containing response type, serial no. and error
472     */
473    public void setNetworkSelectionModeAutomaticResponse(RadioResponseInfo responseInfo) {
474        responseVoid(responseInfo);
475    }
476
477    /**
478     * @param responseInfo Response info struct containing response type, serial no. and error
479     */
480    public void setNetworkSelectionModeManualResponse(RadioResponseInfo responseInfo) {
481        responseVoid(responseInfo);
482    }
483
484    /**
485     *
486     * @param responseInfo Response info struct containing response type, serial no. and error
487     * @param networkInfos List of network operator information as OperatorInfos defined in
488     *                     types.hal
489     */
490    public void getAvailableNetworksResponse(RadioResponseInfo responseInfo,
491                                             ArrayList<android.hardware.radio.V1_0.OperatorInfo>
492                                                     networkInfos) {
493        responseOperatorInfos(responseInfo, networkInfos);
494    }
495
496    /**
497     * @param responseInfo Response info struct containing response type, serial no. and error
498     */
499    public void startDtmfResponse(RadioResponseInfo responseInfo) {
500        responseVoid(responseInfo);
501    }
502
503    /**
504     * @param responseInfo Response info struct containing response type, serial no. and error
505     */
506    public void stopDtmfResponse(RadioResponseInfo responseInfo) {
507        responseVoid(responseInfo);
508    }
509
510    /**
511     *
512     * @param responseInfo Response info struct containing response type, serial no. and error
513     * @param version string containing version string for log reporting
514     */
515    public void getBasebandVersionResponse(RadioResponseInfo responseInfo, String version) {
516        responseString(responseInfo, version);
517    }
518
519    /**
520     * @param responseInfo Response info struct containing response type, serial no. and error
521     */
522    public void separateConnectionResponse(RadioResponseInfo responseInfo) {
523        responseVoid(responseInfo);
524    }
525
526    /**
527     * @param responseInfo Response info struct containing response type, serial no. and error
528     */
529    public void setMuteResponse(RadioResponseInfo responseInfo) {
530        responseVoid(responseInfo);
531    }
532
533    /**
534     *
535     * @param responseInfo Response info struct containing response type, serial no. and error
536     * @param enable true for "mute enabled" and false for "mute disabled"
537     */
538    public void getMuteResponse(RadioResponseInfo responseInfo, boolean enable) {
539        responseInts(responseInfo, enable ? 1 : 0);
540    }
541
542    /**
543     *
544     * @param responseInfo Response info struct containing response type, serial no. and error
545     * @param status indicates CLIP status
546     */
547    public void getClipResponse(RadioResponseInfo responseInfo, int status) {
548        responseInts(responseInfo, status);
549    }
550
551    /**
552     * @param responseInfo Response info struct containing response type, serial no. and error
553     * @param dataCallResultList Response to get data call list as defined by setupDataCallResult in
554     *                           types.hal
555     */
556    public void getDataCallListResponse(RadioResponseInfo responseInfo,
557                                        ArrayList<SetupDataCallResult> dataCallResultList) {
558        responseDataCallList(responseInfo, dataCallResultList);
559    }
560
561    public void sendOemRilRequestRawResponse(RadioResponseInfo responseInfo,
562                                             ArrayList<Byte> var2) {}
563
564    /**
565     * @param responseInfo Response info struct containing response type, serial no. and error
566     */
567    public void setSuppServiceNotificationsResponse(RadioResponseInfo responseInfo) {
568        responseVoid(responseInfo);
569    }
570
571    /**
572     * @param responseInfo Response info struct containing response type, serial no. and error
573     * @param index record index where the message is stored
574     */
575    public void writeSmsToSimResponse(RadioResponseInfo responseInfo, int index) {
576        responseInts(responseInfo, index);
577    }
578
579    /**
580     * @param responseInfo Response info struct containing response type, serial no. and error
581     */
582    public void deleteSmsOnSimResponse(RadioResponseInfo responseInfo) {
583        responseVoid(responseInfo);
584    }
585
586    /**
587     * @param responseInfo Response info struct containing response type, serial no. and error
588     */
589    public void setBandModeResponse(RadioResponseInfo responseInfo) {
590        responseVoid(responseInfo);
591    }
592
593    /**
594     *
595     * @param responseInfo Response info struct containing response type, serial no. and error
596     * @param bandModes List of RadioBandMode listing supported modes
597     */
598    public void getAvailableBandModesResponse(RadioResponseInfo responseInfo,
599                                              ArrayList<Integer> bandModes) {
600        responseIntArrayList(responseInfo, bandModes);
601    }
602
603    /**
604     *
605     * @param responseInfo Response info struct containing response type, serial no. and error
606     * @param commandResponse SAT/USAT response in hexadecimal format
607     *        string starting with first byte of response
608     */
609    public void sendEnvelopeResponse(RadioResponseInfo responseInfo, String commandResponse) {
610        responseString(responseInfo, commandResponse);
611    }
612
613    /**
614     * @param responseInfo Response info struct containing response type, serial no. and error
615     */
616    public void sendTerminalResponseToSimResponse(RadioResponseInfo responseInfo) {
617        responseVoid(responseInfo);
618    }
619
620    /**
621     * @param responseInfo Response info struct containing response type, serial no. and error
622     */
623    public void handleStkCallSetupRequestFromSimResponse(RadioResponseInfo responseInfo) {
624        responseVoid(responseInfo);
625    }
626
627    /**
628     * @param responseInfo Response info struct containing response type, serial no. and error
629     */
630    public void explicitCallTransferResponse(RadioResponseInfo responseInfo) {
631        responseVoid(responseInfo);
632    }
633
634    /**
635     * @param responseInfo Response info struct containing response type, serial no. and error
636     */
637    public void setPreferredNetworkTypeResponse(RadioResponseInfo responseInfo) {
638        responseVoid(responseInfo);
639    }
640
641    /**
642     *
643     * @param responseInfo Response info struct containing response type, serial no. and error
644     * @param nwType RadioPreferredNetworkType defined in types.hal
645     */
646    public void getPreferredNetworkTypeResponse(RadioResponseInfo responseInfo, int nwType) {
647        mRil.mPreferredNetworkType = nwType;
648        responseInts(responseInfo, nwType);
649    }
650
651    /**
652     *
653     * @param responseInfo Response info struct containing response type, serial no. and error
654     * @param cells Vector of neighboring radio cell information
655     */
656    public void getNeighboringCidsResponse(RadioResponseInfo responseInfo,
657                                           ArrayList<NeighboringCell> cells) {
658        responseCellList(responseInfo, cells);
659    }
660
661    /**
662     * @param responseInfo Response info struct containing response type, serial no. and error
663     */
664    public void setLocationUpdatesResponse(RadioResponseInfo responseInfo) {
665        responseVoid(responseInfo);
666    }
667
668    /**
669     * @param responseInfo Response info struct containing response type, serial no. and error
670     */
671    public void setCdmaSubscriptionSourceResponse(RadioResponseInfo responseInfo) {
672        responseVoid(responseInfo);
673    }
674
675    /**
676     * @param responseInfo Response info struct containing response type, serial no. and error
677     */
678    public void setCdmaRoamingPreferenceResponse(RadioResponseInfo responseInfo) {
679        responseVoid(responseInfo);
680    }
681
682    /**
683     *
684     * @param responseInfo Response info struct containing response type, serial no. and error
685     * @param type CdmaRoamingType defined in types.hal
686     */
687    public void getCdmaRoamingPreferenceResponse(RadioResponseInfo responseInfo, int type) {
688        responseInts(responseInfo, type);
689    }
690
691    /**
692     * @param responseInfo Response info struct containing response type, serial no. and error
693     */
694    public void setTTYModeResponse(RadioResponseInfo responseInfo) {
695        responseVoid(responseInfo);
696    }
697
698    /**
699     *
700     * @param responseInfo Response info struct containing response type, serial no. and error
701     * @param mode TTY mode
702     */
703    public void getTTYModeResponse(RadioResponseInfo responseInfo, int mode) {
704        responseInts(responseInfo, mode);
705    }
706
707    /**
708     * @param responseInfo Response info struct containing response type, serial no. and error
709     */
710    public void setPreferredVoicePrivacyResponse(RadioResponseInfo responseInfo) {
711        responseVoid(responseInfo);
712    }
713
714    /**
715     *
716     * @param responseInfo Response info struct containing response type, serial no. and error
717     * @param enable false for Standard Privacy Mode (Public Long Code Mask)
718     *        true for Enhanced Privacy Mode (Private Long Code Mask)
719     */
720    public void getPreferredVoicePrivacyResponse(RadioResponseInfo responseInfo,
721                                                 boolean enable) {
722        responseInts(responseInfo, enable ? 1 : 0);
723    }
724
725    /**
726     * @param responseInfo Response info struct containing response type, serial no. and error
727     */
728    public void sendCDMAFeatureCodeResponse(RadioResponseInfo responseInfo) {
729        responseVoid(responseInfo);
730    }
731
732    /**
733     * @param responseInfo Response info struct containing response type, serial no. and error
734     */
735    public void sendBurstDtmfResponse(RadioResponseInfo responseInfo) {
736        responseVoid(responseInfo);
737    }
738
739    /**
740     *
741     * @param responseInfo Response info struct containing response type, serial no. and error
742     * @param sms Sms result struct as defined by SendSmsResult in types.hal
743     */
744    public void sendCdmaSmsResponse(RadioResponseInfo responseInfo, SendSmsResult sms) {
745        responseSms(responseInfo, sms);
746    }
747
748    /**
749     * @param responseInfo Response info struct containing response type, serial no. and error
750     */
751    public void acknowledgeLastIncomingCdmaSmsResponse(RadioResponseInfo responseInfo) {
752        responseVoid(responseInfo);
753    }
754
755    /**
756     *
757     * @param responseInfo Response info struct containing response type, serial no. and error
758     * @param configs Vector of GSM/WCDMA Cell broadcast configs
759     */
760    public void getGsmBroadcastConfigResponse(RadioResponseInfo responseInfo,
761                                              ArrayList<GsmBroadcastSmsConfigInfo> configs) {
762        responseGmsBroadcastConfig(responseInfo, configs);
763    }
764
765    /**
766     * @param responseInfo Response info struct containing response type, serial no. and error
767     */
768    public void setGsmBroadcastConfigResponse(RadioResponseInfo responseInfo) {
769        responseVoid(responseInfo);
770    }
771
772    /**
773     * @param responseInfo Response info struct containing response type, serial no. and error
774     */
775    public void setGsmBroadcastActivationResponse(RadioResponseInfo responseInfo) {
776        responseVoid(responseInfo);
777    }
778
779    /**
780     *
781     * @param responseInfo Response info struct containing response type, serial no. and error
782     * @param configs Vector of CDMA Broadcast SMS configs.
783     */
784    public void getCdmaBroadcastConfigResponse(RadioResponseInfo responseInfo,
785                                               ArrayList<CdmaBroadcastSmsConfigInfo> configs) {
786        responseCdmaBroadcastConfig(responseInfo, configs);
787    }
788
789    /**
790     * @param responseInfo Response info struct containing response type, serial no. and error
791     */
792    public void setCdmaBroadcastConfigResponse(RadioResponseInfo responseInfo) {
793        responseVoid(responseInfo);
794    }
795
796    /**
797     * @param responseInfo Response info struct containing response type, serial no. and error
798     */
799    public void setCdmaBroadcastActivationResponse(RadioResponseInfo responseInfo) {
800        responseVoid(responseInfo);
801    }
802
803    /**
804     *
805     * @param responseInfo Response info struct containing response type, serial no. and error
806     * @param mdn MDN if CDMA subscription is available
807     * @param hSid is a comma separated list of H_SID (Home SID) if
808     *        CDMA subscription is available, in decimal format
809     * @param hNid is a comma separated list of H_NID (Home NID) if
810     *        CDMA subscription is available, in decimal format
811     * @param min MIN (10 digits, MIN2+MIN1) if CDMA subscription is available
812     * @param prl PRL version if CDMA subscription is available
813     */
814    public void getCDMASubscriptionResponse(RadioResponseInfo responseInfo, String mdn,
815                                            String hSid, String hNid, String min, String prl) {
816        responseStrings(responseInfo, mdn, hSid, hNid, min, prl);
817    }
818
819    /**
820     *
821     * @param responseInfo Response info struct containing response type, serial no. and error
822     * @param index record index where the cmda sms message is stored
823     */
824    public void writeSmsToRuimResponse(RadioResponseInfo responseInfo, int index) {
825        responseInts(responseInfo, index);
826    }
827
828    /**
829     * @param responseInfo Response info struct containing response type, serial no. and error
830     */
831    public void deleteSmsOnRuimResponse(RadioResponseInfo responseInfo) {
832        responseVoid(responseInfo);
833    }
834
835    /**
836     * @param responseInfo Response info struct containing response type, serial no. and error
837     * @param imei IMEI if GSM subscription is available
838     * @param imeisv IMEISV if GSM subscription is available
839     * @param esn ESN if CDMA subscription is available
840     * @param meid MEID if CDMA subscription is available
841     */
842    public void getDeviceIdentityResponse(RadioResponseInfo responseInfo, String imei,
843                                          String imeisv, String esn, String meid) {
844        responseStrings(responseInfo, imei, imeisv, esn, meid);
845    }
846
847    /**
848     * @param responseInfo Response info struct containing response type, serial no. and error
849     */
850    public void exitEmergencyCallbackModeResponse(RadioResponseInfo responseInfo) {
851        responseVoid(responseInfo);
852    }
853
854    /**
855     * @param responseInfo Response info struct containing response type, serial no. and error
856     * @param smsc Short Message Service Center address on the device
857     */
858    public void getSmscAddressResponse(RadioResponseInfo responseInfo, String smsc) {
859        responseString(responseInfo, smsc);
860    }
861
862    /**
863     * @param responseInfo Response info struct containing response type, serial no. and error
864     */
865    public void setSmscAddressResponse(RadioResponseInfo responseInfo) {
866        responseVoid(responseInfo);
867    }
868
869    /**
870     * @param responseInfo Response info struct containing response type, serial no. and error
871     */
872    public void reportSmsMemoryStatusResponse(RadioResponseInfo responseInfo) {
873        responseVoid(responseInfo);
874    }
875
876    /**
877     * @param responseInfo Response info struct containing response type, serial no. and error
878     */
879    public void reportStkServiceIsRunningResponse(RadioResponseInfo responseInfo) {
880        responseVoid(responseInfo);
881    }
882
883    /**
884     *
885     * @param responseInfo Response info struct containing response type, serial no. and error
886     * @param source CDMA subscription source
887     */
888    public void getCdmaSubscriptionSourceResponse(RadioResponseInfo responseInfo, int source) {
889        responseInts(responseInfo, source);
890    }
891
892    /**
893     *
894     * @param responseInfo Response info struct containing response type, serial no. and error
895     * @param response response string of the challenge/response algo for ISIM auth in base64 format
896     */
897    public void requestIsimAuthenticationResponse(RadioResponseInfo responseInfo, String response) {
898        responseString(responseInfo, response);
899    }
900
901    /**
902     * @param responseInfo Response info struct containing response type, serial no. and error
903     */
904    public void acknowledgeIncomingGsmSmsWithPduResponse(RadioResponseInfo responseInfo) {
905        responseVoid(responseInfo);
906    }
907
908    /**
909     *
910     * @param responseInfo Response info struct containing response type, serial no. and error
911     * @param iccIo IccIoResult as defined in types.hal corresponding to ICC IO response
912     */
913    public void sendEnvelopeWithStatusResponse(RadioResponseInfo responseInfo,
914                                               android.hardware.radio.V1_0.IccIoResult iccIo) {
915        responseIccIo(responseInfo, iccIo);
916    }
917
918    /**
919     *
920     * @param responseInfo Response info struct containing response type, serial no. and error
921     * @param rat Current voice RAT
922     */
923    public void getVoiceRadioTechnologyResponse(RadioResponseInfo responseInfo, int rat) {
924        responseInts(responseInfo, rat);
925    }
926
927    public void getCellInfoListResponse(RadioResponseInfo responseInfo,
928                                        ArrayList<android.hardware.radio.V1_0.CellInfo> cellInfo) {
929        responseCellInfoList(responseInfo, cellInfo);
930    }
931
932    /**
933     * @param responseInfo Response info struct containing response type, serial no. and error
934     */
935    public void setCellInfoListRateResponse(RadioResponseInfo responseInfo) {
936        responseVoid(responseInfo);
937    }
938
939    /**
940     * @param responseInfo Response info struct containing response type, serial no. and error
941     */
942    public void setInitialAttachApnResponse(RadioResponseInfo responseInfo) {
943        responseVoid(responseInfo);
944    }
945
946    /**
947     *
948     * @param responseInfo Response info struct containing response type, serial no. and error
949     * @param isRegistered false = not registered, true = registered
950     * @param ratFamily RadioTechnologyFamily as defined in types.hal. This value is valid only if
951     *        isRegistered is true.
952     */
953    public void getImsRegistrationStateResponse(RadioResponseInfo responseInfo,
954                                                boolean isRegistered, int ratFamily) {
955        responseInts(responseInfo, isRegistered ? 1 : 0, ratFamily);
956    }
957
958    /**
959     *
960     * @param responseInfo Response info struct containing response type, serial no. and error
961     * @param sms Response to sms sent as defined by SendSmsResult in types.hal
962     */
963    public void sendImsSmsResponse(RadioResponseInfo responseInfo, SendSmsResult sms) {
964        responseSms(responseInfo, sms);
965    }
966
967    /**
968     *
969     * @param responseInfo Response info struct containing response type, serial no. and error
970     * @param result IccIoResult as defined in types.hal
971     */
972    public void iccTransmitApduBasicChannelResponse(RadioResponseInfo responseInfo,
973                                                    android.hardware.radio.V1_0.IccIoResult
974                                                            result) {
975        responseIccIo(responseInfo, result);
976    }
977
978    /**
979     *
980     * @param responseInfo Response info struct containing response type, serial no. and error
981     * @param channelId session id of the logical channel.
982     * @param selectResponse Contains the select response for the open channel command with one
983     *        byte per integer
984     */
985    public void iccOpenLogicalChannelResponse(RadioResponseInfo responseInfo, int channelId,
986                                              ArrayList<Byte> selectResponse) {
987        ArrayList<Integer> arr = new ArrayList<>();
988        arr.add(channelId);
989        for (int i = 0; i < selectResponse.size(); i++) {
990            arr.add((int) selectResponse.get(i));
991        }
992        responseIntArrayList(responseInfo, arr);
993    }
994
995    /**
996     * @param responseInfo Response info struct containing response type, serial no. and error
997     */
998    public void iccCloseLogicalChannelResponse(RadioResponseInfo responseInfo) {
999        responseVoid(responseInfo);
1000    }
1001
1002    /**
1003     *
1004     * @param responseInfo Response info struct containing response type, serial no. and error
1005     * @param result IccIoResult as defined in types.hal
1006     */
1007    public void iccTransmitApduLogicalChannelResponse(
1008            RadioResponseInfo responseInfo,
1009            android.hardware.radio.V1_0.IccIoResult result) {
1010        responseIccIo(responseInfo, result);
1011    }
1012
1013    /**
1014     *
1015     * @param responseInfo Response info struct containing response type, serial no. and error
1016     * @param result string containing the contents of the NV item
1017     */
1018    public void nvReadItemResponse(RadioResponseInfo responseInfo, String result) {
1019        responseString(responseInfo, result);
1020    }
1021
1022    /**
1023     * @param responseInfo Response info struct containing response type, serial no. and error
1024     */
1025    public void nvWriteItemResponse(RadioResponseInfo responseInfo) {
1026        responseVoid(responseInfo);
1027    }
1028
1029    /**
1030     * @param responseInfo Response info struct containing response type, serial no. and error
1031     */
1032    public void nvWriteCdmaPrlResponse(RadioResponseInfo responseInfo) {
1033        responseVoid(responseInfo);
1034    }
1035
1036    /**
1037     * @param responseInfo Response info struct containing response type, serial no. and error
1038     */
1039    public void nvResetConfigResponse(RadioResponseInfo responseInfo) {
1040        responseVoid(responseInfo);
1041    }
1042
1043    /**
1044     * @param responseInfo Response info struct containing response type, serial no. and error
1045     */
1046    public void setUiccSubscriptionResponse(RadioResponseInfo responseInfo) {
1047        responseVoid(responseInfo);
1048    }
1049
1050    /**
1051     * @param responseInfo Response info struct containing response type, serial no. and error
1052     */
1053    public void setDataAllowedResponse(RadioResponseInfo responseInfo) {
1054        responseVoid(responseInfo);
1055    }
1056
1057    public void getHardwareConfigResponse(
1058            RadioResponseInfo responseInfo,
1059            ArrayList<android.hardware.radio.V1_0.HardwareConfig> config) {
1060        responseHardwareConfig(responseInfo, config);
1061    }
1062
1063    /**
1064     *
1065     * @param responseInfo Response info struct containing response type, serial no. and error
1066     * @param result IccIoResult as defined in types.hal
1067     */
1068    public void requestIccSimAuthenticationResponse(RadioResponseInfo responseInfo,
1069                                                    android.hardware.radio.V1_0.IccIoResult
1070                                                            result) {
1071        responseICC_IOBase64(responseInfo, result);
1072    }
1073
1074    /**
1075     * @param responseInfo Response info struct containing response type, serial no. and error
1076     */
1077    public void setDataProfileResponse(RadioResponseInfo responseInfo) {
1078        responseVoid(responseInfo);
1079    }
1080
1081    /**
1082     * @param responseInfo Response info struct containing response type, serial no. and error
1083     */
1084    public void requestShutdownResponse(RadioResponseInfo responseInfo) {
1085        responseVoid(responseInfo);
1086    }
1087
1088    public void getRadioCapabilityResponse(RadioResponseInfo responseInfo,
1089                                           android.hardware.radio.V1_0.RadioCapability rc) {
1090        RILRequest rr = mRil.processResponse(responseInfo);
1091
1092        if (rr != null) {
1093            RadioCapability ret = RIL.convertHalRadioCapability(rc, mRil);
1094            if (responseInfo.error == RadioError.REQUEST_NOT_SUPPORTED
1095                    || responseInfo.error == RadioError.GENERIC_FAILURE) {
1096                // we should construct the RAF bitmask the radio
1097                // supports based on preferred network bitmasks
1098                ret = mRil.makeStaticRadioCapability();
1099                responseInfo.error = RadioError.NONE;
1100            }
1101            if (responseInfo.error == RadioError.NONE) {
1102                sendMessageResponse(rr.mResult, ret);
1103            }
1104            mRil.processResponseDone(rr, responseInfo, ret);
1105        }
1106    }
1107
1108    public void setRadioCapabilityResponse(RadioResponseInfo responseInfo,
1109                                           android.hardware.radio.V1_0.RadioCapability rc) {
1110        responseRadioCapability(responseInfo, rc);
1111    }
1112
1113    /**
1114     *
1115     * @param responseInfo Response info struct containing response type, serial no. and error
1116     * @param statusInfo LceStatusInfo indicating LCE status
1117     */
1118    public void startLceServiceResponse(RadioResponseInfo responseInfo, LceStatusInfo statusInfo) {
1119        responseLceStatus(responseInfo, statusInfo);
1120    }
1121
1122    /**
1123     *
1124     * @param responseInfo Response info struct containing response type, serial no. and error
1125     * @param statusInfo LceStatusInfo indicating LCE status
1126     */
1127    public void stopLceServiceResponse(RadioResponseInfo responseInfo, LceStatusInfo statusInfo) {
1128        responseLceStatus(responseInfo, statusInfo);
1129    }
1130
1131    public void pullLceDataResponse(RadioResponseInfo responseInfo, LceDataInfo lceInfo) {
1132        responseLceData(responseInfo, lceInfo);
1133    }
1134
1135    /**
1136     *
1137     * @param responseInfo Response info struct containing response type, serial no. and error
1138     * @param activityInfo modem activity information
1139     */
1140    public void getModemActivityInfoResponse(RadioResponseInfo responseInfo,
1141                                             ActivityStatsInfo activityInfo) {
1142        responseActivityData(responseInfo, activityInfo);
1143    }
1144
1145    /**
1146     *
1147     * @param responseInfo Response info struct containing response type, serial no. and error
1148     * @param numAllowed number of allowed carriers which have been set correctly.
1149     *        On success, it must match the length of list Carriers->allowedCarriers.
1150     *        if Length of allowed carriers list is 0, numAllowed = 0.
1151     */
1152    public void setAllowedCarriersResponse(RadioResponseInfo responseInfo, int numAllowed) {
1153        responseInts(responseInfo, numAllowed);
1154    }
1155
1156    /**
1157     *
1158     * @param responseInfo Response info struct containing response type, serial no. and error
1159     * @param allAllowed true only when all carriers are allowed. Ignore "carriers" struct.
1160     *                   If false, consider "carriers" struct
1161     * @param carriers Carrier restriction information.
1162     */
1163    public void getAllowedCarriersResponse(RadioResponseInfo responseInfo, boolean allAllowed,
1164                                           CarrierRestrictions carriers) {
1165        responseCarrierIdentifiers(responseInfo, allAllowed, carriers);
1166    }
1167
1168    /**
1169     * @param responseInfo Response info struct containing response type, serial no. and error
1170     */
1171    public void sendDeviceStateResponse(RadioResponseInfo responseInfo) {
1172        responseVoid(responseInfo);
1173    }
1174
1175    /**
1176     * @param responseInfo Response info struct containing response type, serial no. and error
1177     */
1178    public void setIndicationFilterResponse(RadioResponseInfo responseInfo) {
1179        responseVoid(responseInfo);
1180    }
1181
1182    /**
1183     * @param responseInfo Response info struct containing response type, serial no. and error
1184     */
1185    public void setSimCardPowerResponse(RadioResponseInfo responseInfo) {
1186        responseVoid(responseInfo);
1187    }
1188
1189    private void responseIccCardStatus(RadioResponseInfo responseInfo, CardStatus cardStatus) {
1190        RILRequest rr = mRil.processResponse(responseInfo);
1191
1192        if (rr != null) {
1193            IccCardStatus iccCardStatus = new IccCardStatus();
1194            iccCardStatus.setCardState(cardStatus.cardState);
1195            iccCardStatus.setUniversalPinState(cardStatus.universalPinState);
1196            iccCardStatus.mGsmUmtsSubscriptionAppIndex = cardStatus.gsmUmtsSubscriptionAppIndex;
1197            iccCardStatus.mCdmaSubscriptionAppIndex = cardStatus.cdmaSubscriptionAppIndex;
1198            iccCardStatus.mImsSubscriptionAppIndex = cardStatus.imsSubscriptionAppIndex;
1199            int numApplications = cardStatus.applications.size();
1200
1201            // limit to maximum allowed applications
1202            if (numApplications
1203                    > com.android.internal.telephony.uicc.IccCardStatus.CARD_MAX_APPS) {
1204                numApplications =
1205                        com.android.internal.telephony.uicc.IccCardStatus.CARD_MAX_APPS;
1206            }
1207            iccCardStatus.mApplications = new IccCardApplicationStatus[numApplications];
1208            for (int i = 0; i < numApplications; i++) {
1209                AppStatus rilAppStatus = cardStatus.applications.get(i);
1210                IccCardApplicationStatus appStatus = new IccCardApplicationStatus();
1211                appStatus.app_type       = appStatus.AppTypeFromRILInt(rilAppStatus.appType);
1212                appStatus.app_state      = appStatus.AppStateFromRILInt(rilAppStatus.appState);
1213                appStatus.perso_substate = appStatus.PersoSubstateFromRILInt(
1214                        rilAppStatus.persoSubstate);
1215                appStatus.aid            = rilAppStatus.aidPtr;
1216                appStatus.app_label      = rilAppStatus.appLabelPtr;
1217                appStatus.pin1_replaced  = rilAppStatus.pin1Replaced;
1218                appStatus.pin1           = appStatus.PinStateFromRILInt(rilAppStatus.pin1);
1219                appStatus.pin2           = appStatus.PinStateFromRILInt(rilAppStatus.pin2);
1220                iccCardStatus.mApplications[i] = appStatus;
1221            }
1222            mRil.riljLog("responseIccCardStatus: from HIDL: " + iccCardStatus);
1223            if (responseInfo.error == RadioError.NONE) {
1224                sendMessageResponse(rr.mResult, iccCardStatus);
1225            }
1226            mRil.processResponseDone(rr, responseInfo, iccCardStatus);
1227        }
1228    }
1229
1230    private void responseInts(RadioResponseInfo responseInfo, int ...var) {
1231        final ArrayList<Integer> ints = new ArrayList<>();
1232        for (int i = 0; i < var.length; i++) {
1233            ints.add(var[i]);
1234        }
1235        responseIntArrayList(responseInfo, ints);
1236    }
1237
1238    private void responseIntArrayList(RadioResponseInfo responseInfo, ArrayList<Integer> var) {
1239        RILRequest rr = mRil.processResponse(responseInfo);
1240
1241        if (rr != null) {
1242            int[] ret = new int[var.size()];
1243            for (int i = 0; i < var.size(); i++) {
1244                ret[i] = var.get(i);
1245            }
1246            if (responseInfo.error == RadioError.NONE) {
1247                sendMessageResponse(rr.mResult, ret);
1248            }
1249            mRil.processResponseDone(rr, responseInfo, ret);
1250        }
1251    }
1252
1253    private void responseCurrentCalls(RadioResponseInfo responseInfo,
1254                                      ArrayList<android.hardware.radio.V1_0.Call> calls) {
1255        RILRequest rr = mRil.processResponse(responseInfo);
1256
1257        if (rr != null) {
1258            int num = calls.size();
1259            ArrayList<DriverCall> dcCalls = new ArrayList<DriverCall>(num);
1260            DriverCall dc;
1261
1262            for (int i = 0; i < num; i++) {
1263                dc = new DriverCall();
1264                // TODO: change name of function stateFromCLCC() in DriverCall.java to name
1265                // clarifying what is CLCC
1266                dc.state = DriverCall.stateFromCLCC((int) (calls.get(i).state));
1267                dc.index = calls.get(i).index;
1268                dc.TOA = calls.get(i).toa;
1269                dc.isMpty = calls.get(i).isMpty;
1270                dc.isMT = calls.get(i).isMT;
1271                dc.als = calls.get(i).als;
1272                dc.isVoice = calls.get(i).isVoice;
1273                dc.isVoicePrivacy = calls.get(i).isVoicePrivacy;
1274                dc.number = calls.get(i).number;
1275                dc.numberPresentation =
1276                        DriverCall.presentationFromCLIP(
1277                                (int) (calls.get(i).numberPresentation));
1278                dc.name = calls.get(i).name;
1279                dc.namePresentation =
1280                        DriverCall.presentationFromCLIP((int) (calls.get(i).namePresentation));
1281                if (calls.get(i).uusInfo.size() == 1) {
1282                    dc.uusInfo = new UUSInfo();
1283                    dc.uusInfo.setType(calls.get(i).uusInfo.get(0).uusType);
1284                    dc.uusInfo.setDcs(calls.get(i).uusInfo.get(0).uusDcs);
1285                    if (calls.get(i).uusInfo.get(0).uusData != null) {
1286                        byte[] userData = calls.get(i).uusInfo.get(0).uusData.getBytes();
1287                        dc.uusInfo.setUserData(userData);
1288                    } else {
1289                        mRil.riljLog("responseCurrentCalls: uusInfo data is null");
1290                    }
1291
1292                    mRil.riljLogv(String.format("Incoming UUS : type=%d, dcs=%d, length=%d",
1293                            dc.uusInfo.getType(), dc.uusInfo.getDcs(),
1294                            dc.uusInfo.getUserData().length));
1295                    mRil.riljLogv("Incoming UUS : data (hex): "
1296                            + IccUtils.bytesToHexString(dc.uusInfo.getUserData()));
1297                } else {
1298                    mRil.riljLogv("Incoming UUS : NOT present!");
1299                }
1300
1301                // Make sure there's a leading + on addresses with a TOA of 145
1302                dc.number = PhoneNumberUtils.stringFromStringAndTOA(dc.number, dc.TOA);
1303
1304                dcCalls.add(dc);
1305
1306                if (dc.isVoicePrivacy) {
1307                    mRil.mVoicePrivacyOnRegistrants.notifyRegistrants();
1308                    mRil.riljLog("InCall VoicePrivacy is enabled");
1309                } else {
1310                    mRil.mVoicePrivacyOffRegistrants.notifyRegistrants();
1311                    mRil.riljLog("InCall VoicePrivacy is disabled");
1312                }
1313            }
1314
1315            Collections.sort(dcCalls);
1316
1317            if ((num == 0) && mRil.mTestingEmergencyCall.getAndSet(false)) {
1318                if (mRil.mEmergencyCallbackModeRegistrant != null) {
1319                    mRil.riljLog("responseCurrentCalls: call ended, testing emergency call,"
1320                            + " notify ECM Registrants");
1321                    mRil.mEmergencyCallbackModeRegistrant.notifyRegistrant();
1322                }
1323            }
1324
1325            if (responseInfo.error == RadioError.NONE) {
1326                sendMessageResponse(rr.mResult, dcCalls);
1327            }
1328            mRil.processResponseDone(rr, responseInfo, dcCalls);
1329        }
1330    }
1331
1332    private void responseVoid(RadioResponseInfo responseInfo) {
1333        RILRequest rr = mRil.processResponse(responseInfo);
1334
1335        if (rr != null) {
1336            Object ret = null;
1337            if (responseInfo.error == RadioError.NONE) {
1338                sendMessageResponse(rr.mResult, ret);
1339            }
1340            mRil.processResponseDone(rr, responseInfo, ret);
1341        }
1342    }
1343
1344    private void responseString(RadioResponseInfo responseInfo, String str) {
1345        RILRequest rr = mRil.processResponse(responseInfo);
1346
1347        if (rr != null) {
1348            if (responseInfo.error == RadioError.NONE) {
1349                sendMessageResponse(rr.mResult, str);
1350            }
1351            mRil.processResponseDone(rr, responseInfo, str);
1352        }
1353    }
1354
1355    private void responseStrings(RadioResponseInfo responseInfo, String ...str) {
1356        ArrayList<String> strings = new ArrayList<>();
1357        for (int i = 0; i < str.length; i++) {
1358            strings.add(str[i]);
1359        }
1360        responseStringArrayList(mRil, responseInfo, strings);
1361    }
1362
1363    static void responseStringArrayList(RIL ril, RadioResponseInfo responseInfo,
1364                                        ArrayList<String> strings) {
1365        RILRequest rr = ril.processResponse(responseInfo);
1366
1367        if (rr != null) {
1368            String[] ret = new String[strings.size()];
1369            for (int i = 0; i < strings.size(); i++) {
1370                ret[i] = strings.get(i);
1371            }
1372            if (responseInfo.error == RadioError.NONE) {
1373                sendMessageResponse(rr.mResult, ret);
1374            }
1375            ril.processResponseDone(rr, responseInfo, ret);
1376        }
1377    }
1378
1379    private void responseLastCallFailCauseInfo(RadioResponseInfo responseInfo,
1380                                               LastCallFailCauseInfo fcInfo) {
1381        RILRequest rr = mRil.processResponse(responseInfo);
1382
1383        if (rr != null) {
1384            LastCallFailCause ret = new LastCallFailCause();
1385            ret.causeCode = fcInfo.causeCode;
1386            ret.vendorCause = fcInfo.vendorCause;
1387            if (responseInfo.error == RadioError.NONE) {
1388                sendMessageResponse(rr.mResult, ret);
1389            }
1390            mRil.processResponseDone(rr, responseInfo, ret);
1391        }
1392    }
1393
1394    private void responseSignalStrength(RadioResponseInfo responseInfo,
1395                                        android.hardware.radio.V1_0.SignalStrength sigStrength) {
1396        RILRequest rr = mRil.processResponse(responseInfo);
1397
1398        if (rr != null) {
1399            SignalStrength ret = RIL.convertHalSignalStrength(sigStrength);
1400            if (responseInfo.error == RadioError.NONE) {
1401                sendMessageResponse(rr.mResult, ret);
1402            }
1403            mRil.processResponseDone(rr, responseInfo, ret);
1404        }
1405    }
1406
1407    private void responseSms(RadioResponseInfo responseInfo, SendSmsResult sms) {
1408        RILRequest rr = mRil.processResponse(responseInfo);
1409
1410        if (rr != null) {
1411            SmsResponse ret = new SmsResponse(sms.messageRef, sms.ackPDU, sms.errorCode);
1412            if (responseInfo.error == RadioError.NONE) {
1413                sendMessageResponse(rr.mResult, ret);
1414            }
1415            mRil.processResponseDone(rr, responseInfo, ret);
1416        }
1417    }
1418
1419    private void responseSetupDataCall(RadioResponseInfo responseInfo,
1420                                       SetupDataCallResult setupDataCallResult) {
1421        RILRequest rr = mRil.processResponse(responseInfo);
1422
1423        if (rr != null) {
1424            DataCallResponse ret = RIL.convertDataCallResult(setupDataCallResult);
1425            if (responseInfo.error == RadioError.NONE) {
1426                sendMessageResponse(rr.mResult, ret);
1427            }
1428            mRil.processResponseDone(rr, responseInfo, ret);
1429        }
1430    }
1431
1432    private void responseIccIo(RadioResponseInfo responseInfo,
1433                               android.hardware.radio.V1_0.IccIoResult result) {
1434        RILRequest rr = mRil.processResponse(responseInfo);
1435
1436        if (rr != null) {
1437            IccIoResult ret = new IccIoResult(result.sw1, result.sw2, result.simResponse);
1438            if (responseInfo.error == RadioError.NONE) {
1439                sendMessageResponse(rr.mResult, ret);
1440            }
1441            mRil.processResponseDone(rr, responseInfo, ret);
1442        }
1443    }
1444
1445    private void responseCallForwardInfo(RadioResponseInfo responseInfo,
1446                                         ArrayList<android.hardware.radio.V1_0.CallForwardInfo>
1447                                                 callForwardInfos) {
1448        RILRequest rr = mRil.processResponse(responseInfo);
1449        if (rr != null) {
1450            CallForwardInfo[] ret = new CallForwardInfo[callForwardInfos.size()];
1451            for (int i = 0; i < callForwardInfos.size(); i++) {
1452                ret[i] = new CallForwardInfo();
1453                ret[i].status = callForwardInfos.get(i).status;
1454                ret[i].reason = callForwardInfos.get(i).reason;
1455                ret[i].serviceClass = callForwardInfos.get(i).serviceClass;
1456                ret[i].toa = callForwardInfos.get(i).toa;
1457                ret[i].number = callForwardInfos.get(i).number;
1458                ret[i].timeSeconds = callForwardInfos.get(i).timeSeconds;
1459            }
1460            if (responseInfo.error == RadioError.NONE) {
1461                sendMessageResponse(rr.mResult, ret);
1462            }
1463            mRil.processResponseDone(rr, responseInfo, ret);
1464        }
1465    }
1466
1467    private static String convertOpertatorInfoToString(int status) {
1468        if (status == android.hardware.radio.V1_0.OperatorStatus.UNKNOWN) {
1469            return "unknown";
1470        } else if (status == android.hardware.radio.V1_0.OperatorStatus.AVAILABLE) {
1471            return "available";
1472        } else if (status == android.hardware.radio.V1_0.OperatorStatus.CURRENT) {
1473            return "current";
1474        } else if (status == android.hardware.radio.V1_0.OperatorStatus.FORBIDDEN) {
1475            return "forbidden";
1476        } else {
1477            return "";
1478        }
1479    }
1480
1481    private void responseOperatorInfos(RadioResponseInfo responseInfo,
1482                                       ArrayList<android.hardware.radio.V1_0.OperatorInfo>
1483                                               networkInfos) {
1484        RILRequest rr = mRil.processResponse(responseInfo);
1485
1486        if (rr != null) {
1487            ArrayList<OperatorInfo> ret = new ArrayList<OperatorInfo>();
1488            for (int i = 0; i < networkInfos.size(); i++) {
1489                ret.add(new OperatorInfo(networkInfos.get(i).alphaLong,
1490                        networkInfos.get(i).alphaShort, networkInfos.get(i).operatorNumeric,
1491                        convertOpertatorInfoToString(networkInfos.get(i).status)));
1492            }
1493            if (responseInfo.error == RadioError.NONE) {
1494                sendMessageResponse(rr.mResult, ret);
1495            }
1496            mRil.processResponseDone(rr, responseInfo, ret);
1497        }
1498    }
1499
1500    private void responseDataCallList(RadioResponseInfo responseInfo,
1501                                      ArrayList<SetupDataCallResult> dataCallResultList) {
1502        RILRequest rr = mRil.processResponse(responseInfo);
1503
1504        if (rr != null) {
1505            ArrayList<DataCallResponse> dcResponseList = new ArrayList<>();
1506            for (SetupDataCallResult dcResult : dataCallResultList) {
1507                dcResponseList.add(RIL.convertDataCallResult(dcResult));
1508            }
1509            if (responseInfo.error == RadioError.NONE) {
1510                sendMessageResponse(rr.mResult, dcResponseList);
1511            }
1512            mRil.processResponseDone(rr, responseInfo, dcResponseList);
1513        }
1514    }
1515
1516    private void responseCellList(RadioResponseInfo responseInfo,
1517                                  ArrayList<NeighboringCell> cells) {
1518        RILRequest rr = mRil.processResponse(responseInfo);
1519
1520        if (rr != null) {
1521            int rssi;
1522            String location;
1523            ArrayList<NeighboringCellInfo> ret = new ArrayList<NeighboringCellInfo>();
1524            NeighboringCellInfo cell;
1525
1526            int[] subId = SubscriptionManager.getSubId(mRil.mPhoneId);
1527            int radioType =
1528                    ((TelephonyManager) mRil.mContext.getSystemService(
1529                            Context.TELEPHONY_SERVICE)).getDataNetworkType(subId[0]);
1530
1531            if (radioType != TelephonyManager.NETWORK_TYPE_UNKNOWN) {
1532                for (int i = 0; i < cells.size(); i++) {
1533                    rssi = cells.get(i).rssi;
1534                    location = cells.get(i).cid;
1535                    cell = new NeighboringCellInfo(rssi, location, radioType);
1536                    ret.add(cell);
1537                }
1538            }
1539            if (responseInfo.error == RadioError.NONE) {
1540                sendMessageResponse(rr.mResult, ret);
1541            }
1542            mRil.processResponseDone(rr, responseInfo, ret);
1543        }
1544    }
1545
1546    private void responseGmsBroadcastConfig(RadioResponseInfo responseInfo,
1547                                            ArrayList<GsmBroadcastSmsConfigInfo> configs) {
1548        RILRequest rr = mRil.processResponse(responseInfo);
1549
1550        if (rr != null) {
1551            ArrayList<SmsBroadcastConfigInfo> ret = new ArrayList<SmsBroadcastConfigInfo>();
1552            for (int i = 0; i < configs.size(); i++) {
1553                ret.add(new SmsBroadcastConfigInfo(configs.get(i).fromServiceId,
1554                        configs.get(i).toServiceId, configs.get(i).fromCodeScheme,
1555                        configs.get(i).toCodeScheme, configs.get(i).selected));
1556            }
1557            if (responseInfo.error == RadioError.NONE) {
1558                sendMessageResponse(rr.mResult, ret);
1559            }
1560            mRil.processResponseDone(rr, responseInfo, ret);
1561        }
1562    }
1563
1564    private void responseCdmaBroadcastConfig(RadioResponseInfo responseInfo,
1565                                            ArrayList<CdmaBroadcastSmsConfigInfo> configs) {
1566        RILRequest rr = mRil.processResponse(responseInfo);
1567
1568        if (rr != null) {
1569            int[] ret = null;
1570
1571            int numServiceCategories = configs.size();
1572
1573            if (numServiceCategories == 0) {
1574                // TODO: The logic of providing default values should
1575                // not be done by this transport layer. And needs to
1576                // be done by the vendor ril or application logic.
1577                int numInts;
1578                numInts = CDMA_BROADCAST_SMS_NO_OF_SERVICE_CATEGORIES
1579                        * CDMA_BSI_NO_OF_INTS_STRUCT + 1;
1580                ret = new int[numInts];
1581
1582                // Faking a default record for all possible records.
1583                ret[0] = CDMA_BROADCAST_SMS_NO_OF_SERVICE_CATEGORIES;
1584
1585                // Loop over CDMA_BROADCAST_SMS_NO_OF_SERVICE_CATEGORIES set 'english' as
1586                // default language and selection status to false for all.
1587                for (int i = 1; i < numInts; i += CDMA_BSI_NO_OF_INTS_STRUCT) {
1588                    ret[i + 0] = i / CDMA_BSI_NO_OF_INTS_STRUCT;
1589                    ret[i + 1] = 1;
1590                    ret[i + 2] = 0;
1591                }
1592            } else {
1593                int numInts;
1594                numInts = (numServiceCategories * CDMA_BSI_NO_OF_INTS_STRUCT) + 1;
1595                ret = new int[numInts];
1596
1597                ret[0] = numServiceCategories;
1598                for (int i = 1, j = 0; j < configs.size();
1599                        j++, i = i + CDMA_BSI_NO_OF_INTS_STRUCT) {
1600                    ret[i] = configs.get(j).serviceCategory;
1601                    ret[i + 1] = configs.get(j).language;
1602                    ret[i + 2] = configs.get(j).selected ? 1 : 0;
1603                }
1604            }
1605            if (responseInfo.error == RadioError.NONE) {
1606                sendMessageResponse(rr.mResult, ret);
1607            }
1608            mRil.processResponseDone(rr, responseInfo, ret);
1609        }
1610    }
1611
1612    private void responseCellInfoList(RadioResponseInfo responseInfo,
1613                                      ArrayList<android.hardware.radio.V1_0.CellInfo> cellInfo) {
1614        RILRequest rr = mRil.processResponse(responseInfo);
1615
1616        if (rr != null) {
1617            ArrayList<CellInfo> ret = RIL.convertHalCellInfoList(cellInfo);
1618            if (responseInfo.error == RadioError.NONE) {
1619                sendMessageResponse(rr.mResult, ret);
1620            }
1621            mRil.processResponseDone(rr, responseInfo, ret);
1622        }
1623    }
1624
1625    private void responseActivityData(RadioResponseInfo responseInfo,
1626                                      ActivityStatsInfo activityInfo) {
1627        RILRequest rr = mRil.processResponse(responseInfo);
1628
1629        if (rr != null) {
1630            ModemActivityInfo ret = null;
1631            if (responseInfo.error == RadioError.NONE) {
1632                final int sleepModeTimeMs = activityInfo.sleepModeTimeMs;
1633                final int idleModeTimeMs = activityInfo.idleModeTimeMs;
1634                int [] txModeTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1635                for (int i = 0; i < ModemActivityInfo.TX_POWER_LEVELS; i++) {
1636                    txModeTimeMs[i] = activityInfo.txmModetimeMs[i];
1637                }
1638                final int rxModeTimeMs = activityInfo.rxModeTimeMs;
1639                ret = new ModemActivityInfo(SystemClock.elapsedRealtime(), sleepModeTimeMs,
1640                        idleModeTimeMs, txModeTimeMs, rxModeTimeMs, 0);
1641            } else {
1642                ret = new ModemActivityInfo(0, 0, 0, new int [ModemActivityInfo.TX_POWER_LEVELS],
1643                        0, 0);
1644                responseInfo.error = RadioError.NONE;
1645            }
1646            sendMessageResponse(rr.mResult, ret);
1647            mRil.processResponseDone(rr, responseInfo, ret);
1648        }
1649    }
1650
1651    private void responseHardwareConfig(
1652            RadioResponseInfo responseInfo,
1653            ArrayList<android.hardware.radio.V1_0.HardwareConfig> config) {
1654        RILRequest rr = mRil.processResponse(responseInfo);
1655
1656        if (rr != null) {
1657            ArrayList<HardwareConfig> ret = RIL.convertHalHwConfigList(config, mRil);
1658            if (responseInfo.error == RadioError.NONE) {
1659                sendMessageResponse(rr.mResult, ret);
1660            }
1661            mRil.processResponseDone(rr, responseInfo, ret);
1662        }
1663    }
1664
1665    private void responseICC_IOBase64(RadioResponseInfo responseInfo,
1666                                      android.hardware.radio.V1_0.IccIoResult result) {
1667        RILRequest rr = mRil.processResponse(responseInfo);
1668
1669        if (rr != null) {
1670            IccIoResult ret = new IccIoResult(
1671                    result.sw1,
1672                    result.sw2,
1673                    (!(result.simResponse).equals(""))
1674                            ? android.util.Base64.decode(result.simResponse,
1675                            android.util.Base64.DEFAULT) : (byte[]) null);
1676            if (responseInfo.error == RadioError.NONE) {
1677                sendMessageResponse(rr.mResult, ret);
1678            }
1679            mRil.processResponseDone(rr, responseInfo, ret);
1680        }
1681    }
1682
1683    private void responseRadioCapability(RadioResponseInfo responseInfo,
1684                                         android.hardware.radio.V1_0.RadioCapability rc) {
1685        RILRequest rr = mRil.processResponse(responseInfo);
1686
1687        if (rr != null) {
1688            RadioCapability ret = RIL.convertHalRadioCapability(rc, mRil);
1689            if (responseInfo.error == RadioError.NONE) {
1690                sendMessageResponse(rr.mResult, ret);
1691            }
1692            mRil.processResponseDone(rr, responseInfo, ret);
1693        }
1694    }
1695
1696    private void responseLceStatus(RadioResponseInfo responseInfo, LceStatusInfo statusInfo) {
1697        RILRequest rr = mRil.processResponse(responseInfo);
1698
1699        if (rr != null) {
1700            ArrayList<Integer> ret = new ArrayList<Integer>();
1701            ret.add(statusInfo.lceStatus);
1702            ret.add(Byte.toUnsignedInt(statusInfo.actualIntervalMs));
1703            if (responseInfo.error == RadioError.NONE) {
1704                sendMessageResponse(rr.mResult, ret);
1705            }
1706            mRil.processResponseDone(rr, responseInfo, ret);
1707        }
1708    }
1709
1710    private void responseLceData(RadioResponseInfo responseInfo, LceDataInfo lceInfo) {
1711        RILRequest rr = mRil.processResponse(responseInfo);
1712
1713        if (rr != null) {
1714            ArrayList<Integer> ret = RIL.convertHalLceData(lceInfo, mRil);
1715            if (responseInfo.error == RadioError.NONE) {
1716                sendMessageResponse(rr.mResult, ret);
1717            }
1718            mRil.processResponseDone(rr, responseInfo, ret);
1719        }
1720    }
1721
1722    private void responseCarrierIdentifiers(RadioResponseInfo responseInfo, boolean allAllowed,
1723                                            CarrierRestrictions carriers) {
1724        RILRequest rr = mRil.processResponse(responseInfo);
1725
1726        if (rr != null) {
1727            List<CarrierIdentifier> ret = new ArrayList<CarrierIdentifier>();
1728            for (int i = 0; i < carriers.allowedCarriers.size(); i++) {
1729                String mcc = carriers.allowedCarriers.get(i).mcc;
1730                String mnc = carriers.allowedCarriers.get(i).mnc;
1731                String spn = null, imsi = null, gid1 = null, gid2 = null;
1732                int matchType = carriers.allowedCarriers.get(i).matchType;
1733                String matchData = carriers.allowedCarriers.get(i).matchData;
1734                if (matchType == CarrierIdentifier.MatchType.SPN) {
1735                    spn = matchData;
1736                } else if (matchType == CarrierIdentifier.MatchType.IMSI_PREFIX) {
1737                    imsi = matchData;
1738                } else if (matchType == CarrierIdentifier.MatchType.GID1) {
1739                    gid1 = matchData;
1740                } else if (matchType == CarrierIdentifier.MatchType.GID2) {
1741                    gid2 = matchData;
1742                }
1743                ret.add(new CarrierIdentifier(mcc, mnc, spn, imsi, gid1, gid2));
1744            }
1745            if (responseInfo.error == RadioError.NONE) {
1746                /* TODO: Handle excluded carriers */
1747                sendMessageResponse(rr.mResult, ret);
1748            }
1749            mRil.processResponseDone(rr, responseInfo, ret);
1750        }
1751    }
1752}
1753