a9b2c2945eb75fce4309b6a146ecf263c1b72ec5
[android/platform/frameworks/opt/telephony.git] / src / java / com / android / internal / telephony / RIL.java
1 /*
2  * Copyright (C) 2006 The Android Open Source Project
3  * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 package com.android.internal.telephony;
19
20 import static com.android.internal.telephony.RILConstants.*;
21 import static android.telephony.TelephonyManager.NETWORK_TYPE_UNKNOWN;
22 import static android.telephony.TelephonyManager.NETWORK_TYPE_EDGE;
23 import static android.telephony.TelephonyManager.NETWORK_TYPE_GPRS;
24 import static android.telephony.TelephonyManager.NETWORK_TYPE_UMTS;
25 import static android.telephony.TelephonyManager.NETWORK_TYPE_HSDPA;
26 import static android.telephony.TelephonyManager.NETWORK_TYPE_HSUPA;
27 import static android.telephony.TelephonyManager.NETWORK_TYPE_HSPA;
28
29 import android.content.BroadcastReceiver;
30 import android.content.Context;
31 import android.content.Intent;
32 import android.content.IntentFilter;
33 import android.net.ConnectivityManager;
34 import android.net.LocalSocket;
35 import android.net.LocalSocketAddress;
36 import android.os.AsyncResult;
37 import android.os.Handler;
38 import android.os.HandlerThread;
39 import android.os.Looper;
40 import android.os.Message;
41 import android.os.Parcel;
42 import android.os.PowerManager;
43 import android.os.SystemProperties;
44 import android.os.PowerManager.WakeLock;
45 import android.telephony.CellInfo;
46 import android.telephony.NeighboringCellInfo;
47 import android.telephony.PhoneNumberUtils;
48 import android.telephony.Rlog;
49 import android.telephony.SignalStrength;
50 import android.telephony.SmsManager;
51 import android.telephony.SmsMessage;
52 import android.text.TextUtils;
53 import android.util.SparseArray;
54
55 import com.android.internal.telephony.gsm.SmsBroadcastConfigInfo;
56 import com.android.internal.telephony.gsm.SuppServiceNotification;
57 import com.android.internal.telephony.uicc.IccCardApplicationStatus;
58 import com.android.internal.telephony.uicc.IccCardStatus;
59 import com.android.internal.telephony.uicc.IccIoResult;
60 import com.android.internal.telephony.uicc.IccRefreshResponse;
61 import com.android.internal.telephony.uicc.IccUtils;
62 import com.android.internal.telephony.cdma.CdmaCallWaitingNotification;
63 import com.android.internal.telephony.cdma.CdmaInformationRecords;
64 import com.android.internal.telephony.cdma.CdmaSmsBroadcastConfigInfo;
65 import com.android.internal.telephony.dataconnection.DcFailCause;
66 import com.android.internal.telephony.dataconnection.DataCallResponse;
67
68 import java.io.ByteArrayInputStream;
69 import java.io.DataInputStream;
70 import java.io.FileDescriptor;
71 import java.io.IOException;
72 import java.io.InputStream;
73 import java.io.PrintWriter;
74 import java.util.ArrayList;
75 import java.util.Collections;
76 import java.util.concurrent.atomic.AtomicBoolean;
77 import java.util.concurrent.atomic.AtomicInteger;
78 import java.util.Random;
79
80 /**
81  * {@hide}
82  */
83 class RILRequest {
84     static final String LOG_TAG = "RilRequest";
85
86     //***** Class Variables
87     static Random sRandom = new Random();
88     static AtomicInteger sNextSerial = new AtomicInteger(0);
89     private static Object sPoolSync = new Object();
90     private static RILRequest sPool = null;
91     private static int sPoolSize = 0;
92     private static final int MAX_POOL_SIZE = 4;
93
94     //***** Instance Variables
95     int mSerial;
96     int mRequest;
97     Message mResult;
98     Parcel mParcel;
99     RILRequest mNext;
100
101     /**
102      * Retrieves a new RILRequest instance from the pool.
103      *
104      * @param request RIL_REQUEST_*
105      * @param result sent when operation completes
106      * @return a RILRequest instance from the pool.
107      */
108     static RILRequest obtain(int request, Message result) {
109         RILRequest rr = null;
110
111         synchronized(sPoolSync) {
112             if (sPool != null) {
113                 rr = sPool;
114                 sPool = rr.mNext;
115                 rr.mNext = null;
116                 sPoolSize--;
117             }
118         }
119
120         if (rr == null) {
121             rr = new RILRequest();
122         }
123
124         rr.mSerial = sNextSerial.getAndIncrement();
125
126         rr.mRequest = request;
127         rr.mResult = result;
128         rr.mParcel = Parcel.obtain();
129
130         if (result != null && result.getTarget() == null) {
131             throw new NullPointerException("Message target must not be null");
132         }
133
134         // first elements in any RIL Parcel
135         rr.mParcel.writeInt(request);
136         rr.mParcel.writeInt(rr.mSerial);
137
138         return rr;
139     }
140
141     /**
142      * Returns a RILRequest instance to the pool.
143      *
144      * Note: This should only be called once per use.
145      */
146     void release() {
147         synchronized (sPoolSync) {
148             if (sPoolSize < MAX_POOL_SIZE) {
149                 mNext = sPool;
150                 sPool = this;
151                 sPoolSize++;
152                 mResult = null;
153             }
154         }
155     }
156
157     private RILRequest() {
158     }
159
160     static void
161     resetSerial() {
162         // use a random so that on recovery we probably don't mix old requests
163         // with new.
164         sNextSerial.set(sRandom.nextInt());
165     }
166
167     String
168     serialString() {
169         //Cheesy way to do %04d
170         StringBuilder sb = new StringBuilder(8);
171         String sn;
172
173         long adjustedSerial = (((long)mSerial) - Integer.MIN_VALUE)%10000;
174
175         sn = Long.toString(adjustedSerial);
176
177         //sb.append("J[");
178         sb.append('[');
179         for (int i = 0, s = sn.length() ; i < 4 - s; i++) {
180             sb.append('0');
181         }
182
183         sb.append(sn);
184         sb.append(']');
185         return sb.toString();
186     }
187
188     void
189     onError(int error, Object ret) {
190         CommandException ex;
191
192         ex = CommandException.fromRilErrno(error);
193
194         if (RIL.RILJ_LOGD) Rlog.d(LOG_TAG, serialString() + "< "
195             + RIL.requestToString(mRequest)
196             + " error: " + ex);
197
198         if (mResult != null) {
199             AsyncResult.forMessage(mResult, ret, ex);
200             mResult.sendToTarget();
201         }
202
203         if (mParcel != null) {
204             mParcel.recycle();
205             mParcel = null;
206         }
207     }
208 }
209
210
211 /**
212  * RIL implementation of the CommandsInterface.
213  *
214  * {@hide}
215  */
216 public final class RIL extends BaseCommands implements CommandsInterface {
217     static final String RILJ_LOG_TAG = "RILJ";
218     static final boolean RILJ_LOGD = true;
219     static final boolean RILJ_LOGV = false; // STOPSHIP if true
220
221     /**
222      * Wake lock timeout should be longer than the longest timeout in
223      * the vendor ril.
224      */
225     private static final int DEFAULT_WAKE_LOCK_TIMEOUT = 60000;
226
227     //***** Instance Variables
228
229     LocalSocket mSocket;
230     HandlerThread mSenderThread;
231     RILSender mSender;
232     Thread mReceiverThread;
233     RILReceiver mReceiver;
234     WakeLock mWakeLock;
235     final int mWakeLockTimeout;
236     // The number of wakelock requests currently active.  Don't release the lock
237     // until dec'd to 0
238     int mWakeLockCount;
239
240     SparseArray<RILRequest> mRequestList = new SparseArray<RILRequest>();
241
242     Object     mLastNITZTimeInfo;
243
244     // When we are testing emergency calls
245     AtomicBoolean mTestingEmergencyCall = new AtomicBoolean(false);
246
247     //***** Events
248
249     static final int EVENT_SEND                 = 1;
250     static final int EVENT_WAKE_LOCK_TIMEOUT    = 2;
251
252     //***** Constants
253
254     // match with constant in ril.cpp
255     static final int RIL_MAX_COMMAND_BYTES = (8 * 1024);
256     static final int RESPONSE_SOLICITED = 0;
257     static final int RESPONSE_UNSOLICITED = 1;
258
259     static final String SOCKET_NAME_RIL = "rild";
260
261     static final int SOCKET_OPEN_RETRY_MILLIS = 4 * 1000;
262
263     // The number of the required config values for broadcast SMS stored in the C struct
264     // RIL_CDMA_BroadcastServiceInfo
265     private static final int CDMA_BSI_NO_OF_INTS_STRUCT = 3;
266
267     private static final int CDMA_BROADCAST_SMS_NO_OF_SERVICE_CATEGORIES = 31;
268
269     BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
270         @Override
271         public void onReceive(Context context, Intent intent) {
272             if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
273                 sendScreenState(true);
274             } else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
275                 sendScreenState(false);
276             } else {
277                 Rlog.w(RILJ_LOG_TAG, "RIL received unexpected Intent: " + intent.getAction());
278             }
279         }
280     };
281
282     class RILSender extends Handler implements Runnable {
283         public RILSender(Looper looper) {
284             super(looper);
285         }
286
287         // Only allocated once
288         byte[] dataLength = new byte[4];
289
290         //***** Runnable implementation
291         @Override
292         public void
293         run() {
294             //setup if needed
295         }
296
297
298         //***** Handler implementation
299         @Override public void
300         handleMessage(Message msg) {
301             RILRequest rr = (RILRequest)(msg.obj);
302             RILRequest req = null;
303
304             switch (msg.what) {
305                 case EVENT_SEND:
306                     try {
307                         LocalSocket s;
308
309                         s = mSocket;
310
311                         if (s == null) {
312                             rr.onError(RADIO_NOT_AVAILABLE, null);
313                             rr.release();
314                             decrementWakeLock();
315                             return;
316                         }
317
318                         synchronized (mRequestList) {
319                             mRequestList.append(rr.mSerial, rr);
320                         }
321
322                         byte[] data;
323
324                         data = rr.mParcel.marshall();
325                         rr.mParcel.recycle();
326                         rr.mParcel = null;
327
328                         if (data.length > RIL_MAX_COMMAND_BYTES) {
329                             throw new RuntimeException(
330                                     "Parcel larger than max bytes allowed! "
331                                                           + data.length);
332                         }
333
334                         // parcel length in big endian
335                         dataLength[0] = dataLength[1] = 0;
336                         dataLength[2] = (byte)((data.length >> 8) & 0xff);
337                         dataLength[3] = (byte)((data.length) & 0xff);
338
339                         //Rlog.v(RILJ_LOG_TAG, "writing packet: " + data.length + " bytes");
340
341                         s.getOutputStream().write(dataLength);
342                         s.getOutputStream().write(data);
343                     } catch (IOException ex) {
344                         Rlog.e(RILJ_LOG_TAG, "IOException", ex);
345                         req = findAndRemoveRequestFromList(rr.mSerial);
346                         // make sure this request has not already been handled,
347                         // eg, if RILReceiver cleared the list.
348                         if (req != null) {
349                             rr.onError(RADIO_NOT_AVAILABLE, null);
350                             rr.release();
351                             decrementWakeLock();
352                         }
353                     } catch (RuntimeException exc) {
354                         Rlog.e(RILJ_LOG_TAG, "Uncaught exception ", exc);
355                         req = findAndRemoveRequestFromList(rr.mSerial);
356                         // make sure this request has not already been handled,
357                         // eg, if RILReceiver cleared the list.
358                         if (req != null) {
359                             rr.onError(GENERIC_FAILURE, null);
360                             rr.release();
361                             decrementWakeLock();
362                         }
363                     }
364
365                     break;
366
367                 case EVENT_WAKE_LOCK_TIMEOUT:
368                     // Haven't heard back from the last request.  Assume we're
369                     // not getting a response and  release the wake lock.
370
371                     // The timer of WAKE_LOCK_TIMEOUT is reset with each
372                     // new send request. So when WAKE_LOCK_TIMEOUT occurs
373                     // all requests in mRequestList already waited at
374                     // least DEFAULT_WAKE_LOCK_TIMEOUT but no response.
375                     //
376                     // Note: Keep mRequestList so that delayed response
377                     // can still be handled when response finally comes.
378
379                     synchronized (mRequestList) {
380                         if (clearWakeLock()) {
381                             if (RILJ_LOGD) {
382                                 int count = mRequestList.size();
383                                 Rlog.d(RILJ_LOG_TAG, "WAKE_LOCK_TIMEOUT " +
384                                         " mRequestList=" + count);
385                                 for (int i = 0; i < count; i++) {
386                                     rr = mRequestList.valueAt(i);
387                                     Rlog.d(RILJ_LOG_TAG, i + ": [" + rr.mSerial + "] "
388                                             + requestToString(rr.mRequest));
389                                 }
390                             }
391                         }
392                     }
393                     break;
394             }
395         }
396     }
397
398     /**
399      * Reads in a single RIL message off the wire. A RIL message consists
400      * of a 4-byte little-endian length and a subsequent series of bytes.
401      * The final message (length header omitted) is read into
402      * <code>buffer</code> and the length of the final message (less header)
403      * is returned. A return value of -1 indicates end-of-stream.
404      *
405      * @param is non-null; Stream to read from
406      * @param buffer Buffer to fill in. Must be as large as maximum
407      * message size, or an ArrayOutOfBounds exception will be thrown.
408      * @return Length of message less header, or -1 on end of stream.
409      * @throws IOException
410      */
411     private static int readRilMessage(InputStream is, byte[] buffer)
412             throws IOException {
413         int countRead;
414         int offset;
415         int remaining;
416         int messageLength;
417
418         // First, read in the length of the message
419         offset = 0;
420         remaining = 4;
421         do {
422             countRead = is.read(buffer, offset, remaining);
423
424             if (countRead < 0 ) {
425                 Rlog.e(RILJ_LOG_TAG, "Hit EOS reading message length");
426                 return -1;
427             }
428
429             offset += countRead;
430             remaining -= countRead;
431         } while (remaining > 0);
432
433         messageLength = ((buffer[0] & 0xff) << 24)
434                 | ((buffer[1] & 0xff) << 16)
435                 | ((buffer[2] & 0xff) << 8)
436                 | (buffer[3] & 0xff);
437
438         // Then, re-use the buffer and read in the message itself
439         offset = 0;
440         remaining = messageLength;
441         do {
442             countRead = is.read(buffer, offset, remaining);
443
444             if (countRead < 0 ) {
445                 Rlog.e(RILJ_LOG_TAG, "Hit EOS reading message.  messageLength=" + messageLength
446                         + " remaining=" + remaining);
447                 return -1;
448             }
449
450             offset += countRead;
451             remaining -= countRead;
452         } while (remaining > 0);
453
454         return messageLength;
455     }
456
457     class RILReceiver implements Runnable {
458         byte[] buffer;
459
460         RILReceiver() {
461             buffer = new byte[RIL_MAX_COMMAND_BYTES];
462         }
463
464         @Override
465         public void
466         run() {
467             int retryCount = 0;
468
469             try {for (;;) {
470                 LocalSocket s = null;
471                 LocalSocketAddress l;
472
473                 try {
474                     s = new LocalSocket();
475                     l = new LocalSocketAddress(SOCKET_NAME_RIL,
476                             LocalSocketAddress.Namespace.RESERVED);
477                     s.connect(l);
478                 } catch (IOException ex){
479                     try {
480                         if (s != null) {
481                             s.close();
482                         }
483                     } catch (IOException ex2) {
484                         //ignore failure to close after failure to connect
485                     }
486
487                     // don't print an error message after the the first time
488                     // or after the 8th time
489
490                     if (retryCount == 8) {
491                         Rlog.e (RILJ_LOG_TAG,
492                             "Couldn't find '" + SOCKET_NAME_RIL
493                             + "' socket after " + retryCount
494                             + " times, continuing to retry silently");
495                     } else if (retryCount > 0 && retryCount < 8) {
496                         Rlog.i (RILJ_LOG_TAG,
497                             "Couldn't find '" + SOCKET_NAME_RIL
498                             + "' socket; retrying after timeout");
499                     }
500
501                     try {
502                         Thread.sleep(SOCKET_OPEN_RETRY_MILLIS);
503                     } catch (InterruptedException er) {
504                     }
505
506                     retryCount++;
507                     continue;
508                 }
509
510                 retryCount = 0;
511
512                 mSocket = s;
513                 Rlog.i(RILJ_LOG_TAG, "Connected to '" + SOCKET_NAME_RIL + "' socket");
514
515                 int length = 0;
516                 try {
517                     InputStream is = mSocket.getInputStream();
518
519                     for (;;) {
520                         Parcel p;
521
522                         length = readRilMessage(is, buffer);
523
524                         if (length < 0) {
525                             // End-of-stream reached
526                             break;
527                         }
528
529                         p = Parcel.obtain();
530                         p.unmarshall(buffer, 0, length);
531                         p.setDataPosition(0);
532
533                         //Rlog.v(RILJ_LOG_TAG, "Read packet: " + length + " bytes");
534
535                         processResponse(p);
536                         p.recycle();
537                     }
538                 } catch (java.io.IOException ex) {
539                     Rlog.i(RILJ_LOG_TAG, "'" + SOCKET_NAME_RIL + "' socket closed",
540                           ex);
541                 } catch (Throwable tr) {
542                     Rlog.e(RILJ_LOG_TAG, "Uncaught exception read length=" + length +
543                         "Exception:" + tr.toString());
544                 }
545
546                 Rlog.i(RILJ_LOG_TAG, "Disconnected from '" + SOCKET_NAME_RIL
547                       + "' socket");
548
549                 setRadioState (RadioState.RADIO_UNAVAILABLE);
550
551                 try {
552                     mSocket.close();
553                 } catch (IOException ex) {
554                 }
555
556                 mSocket = null;
557                 RILRequest.resetSerial();
558
559                 // Clear request list on close
560                 clearRequestList(RADIO_NOT_AVAILABLE, false);
561             }} catch (Throwable tr) {
562                 Rlog.e(RILJ_LOG_TAG,"Uncaught exception", tr);
563             }
564
565             /* We're disconnected so we don't know the ril version */
566             notifyRegistrantsRilConnectionChanged(-1);
567         }
568     }
569
570
571
572     //***** Constructors
573
574     public RIL(Context context, int preferredNetworkType, int cdmaSubscription) {
575         super(context);
576         if (RILJ_LOGD) {
577             riljLog("RIL(context, preferredNetworkType=" + preferredNetworkType +
578                     " cdmaSubscription=" + cdmaSubscription + ")");
579         }
580
581         mCdmaSubscription  = cdmaSubscription;
582         mPreferredNetworkType = preferredNetworkType;
583         mPhoneType = RILConstants.NO_PHONE;
584
585         PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
586         mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, RILJ_LOG_TAG);
587         mWakeLock.setReferenceCounted(false);
588         mWakeLockTimeout = SystemProperties.getInt(TelephonyProperties.PROPERTY_WAKE_LOCK_TIMEOUT,
589                 DEFAULT_WAKE_LOCK_TIMEOUT);
590         mWakeLockCount = 0;
591
592         mSenderThread = new HandlerThread("RILSender");
593         mSenderThread.start();
594
595         Looper looper = mSenderThread.getLooper();
596         mSender = new RILSender(looper);
597
598         ConnectivityManager cm = (ConnectivityManager)context.getSystemService(
599                 Context.CONNECTIVITY_SERVICE);
600         if (cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE) == false) {
601             riljLog("Not starting RILReceiver: wifi-only");
602         } else {
603             riljLog("Starting RILReceiver");
604             mReceiver = new RILReceiver();
605             mReceiverThread = new Thread(mReceiver, "RILReceiver");
606             mReceiverThread.start();
607
608             IntentFilter filter = new IntentFilter();
609             filter.addAction(Intent.ACTION_SCREEN_ON);
610             filter.addAction(Intent.ACTION_SCREEN_OFF);
611             context.registerReceiver(mIntentReceiver, filter);
612         }
613     }
614
615     //***** CommandsInterface implementation
616
617     @Override
618     public void getVoiceRadioTechnology(Message result) {
619         RILRequest rr = RILRequest.obtain(RIL_REQUEST_VOICE_RADIO_TECH, result);
620
621         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
622
623         send(rr);
624     }
625
626
627     public void getImsRegistrationState(Message result) {
628         RILRequest rr = RILRequest.obtain(RIL_REQUEST_IMS_REGISTRATION_STATE, result);
629
630         if (RILJ_LOGD) {
631             riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
632         }
633         send(rr);
634     }
635
636     @Override public void
637     setOnNITZTime(Handler h, int what, Object obj) {
638         super.setOnNITZTime(h, what, obj);
639
640         // Send the last NITZ time if we have it
641         if (mLastNITZTimeInfo != null) {
642             mNITZTimeRegistrant
643                 .notifyRegistrant(
644                     new AsyncResult (null, mLastNITZTimeInfo, null));
645             mLastNITZTimeInfo = null;
646         }
647     }
648
649     @Override
650     public void
651     getIccCardStatus(Message result) {
652         //Note: This RIL request has not been renamed to ICC,
653         //       but this request is also valid for SIM and RUIM
654         RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_SIM_STATUS, result);
655
656         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
657
658         send(rr);
659     }
660
661     @Override public void
662     supplyIccPin(String pin, Message result) {
663         supplyIccPinForApp(pin, null, result);
664     }
665
666     @Override public void
667     supplyIccPinForApp(String pin, String aid, Message result) {
668         //Note: This RIL request has not been renamed to ICC,
669         //       but this request is also valid for SIM and RUIM
670         RILRequest rr = RILRequest.obtain(RIL_REQUEST_ENTER_SIM_PIN, result);
671
672         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
673
674         rr.mParcel.writeInt(2);
675         rr.mParcel.writeString(pin);
676         rr.mParcel.writeString(aid);
677
678         send(rr);
679     }
680
681     @Override public void
682     supplyIccPuk(String puk, String newPin, Message result) {
683         supplyIccPukForApp(puk, newPin, null, result);
684     }
685
686     @Override public void
687     supplyIccPukForApp(String puk, String newPin, String aid, Message result) {
688         //Note: This RIL request has not been renamed to ICC,
689         //       but this request is also valid for SIM and RUIM
690         RILRequest rr = RILRequest.obtain(RIL_REQUEST_ENTER_SIM_PUK, result);
691
692         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
693
694         rr.mParcel.writeInt(3);
695         rr.mParcel.writeString(puk);
696         rr.mParcel.writeString(newPin);
697         rr.mParcel.writeString(aid);
698
699         send(rr);
700     }
701
702     @Override public void
703     supplyIccPin2(String pin, Message result) {
704         supplyIccPin2ForApp(pin, null, result);
705     }
706
707     @Override public void
708     supplyIccPin2ForApp(String pin, String aid, Message result) {
709         //Note: This RIL request has not been renamed to ICC,
710         //       but this request is also valid for SIM and RUIM
711         RILRequest rr = RILRequest.obtain(RIL_REQUEST_ENTER_SIM_PIN2, result);
712
713         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
714
715         rr.mParcel.writeInt(2);
716         rr.mParcel.writeString(pin);
717         rr.mParcel.writeString(aid);
718
719         send(rr);
720     }
721
722     @Override public void
723     supplyIccPuk2(String puk2, String newPin2, Message result) {
724         supplyIccPuk2ForApp(puk2, newPin2, null, result);
725     }
726
727     @Override public void
728     supplyIccPuk2ForApp(String puk, String newPin2, String aid, Message result) {
729         //Note: This RIL request has not been renamed to ICC,
730         //       but this request is also valid for SIM and RUIM
731         RILRequest rr = RILRequest.obtain(RIL_REQUEST_ENTER_SIM_PUK2, result);
732
733         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
734
735         rr.mParcel.writeInt(3);
736         rr.mParcel.writeString(puk);
737         rr.mParcel.writeString(newPin2);
738         rr.mParcel.writeString(aid);
739
740         send(rr);
741     }
742
743     @Override public void
744     changeIccPin(String oldPin, String newPin, Message result) {
745         changeIccPinForApp(oldPin, newPin, null, result);
746     }
747
748     @Override public void
749     changeIccPinForApp(String oldPin, String newPin, String aid, Message result) {
750         //Note: This RIL request has not been renamed to ICC,
751         //       but this request is also valid for SIM and RUIM
752         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CHANGE_SIM_PIN, result);
753
754         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
755
756         rr.mParcel.writeInt(3);
757         rr.mParcel.writeString(oldPin);
758         rr.mParcel.writeString(newPin);
759         rr.mParcel.writeString(aid);
760
761         send(rr);
762     }
763
764     @Override public void
765     changeIccPin2(String oldPin2, String newPin2, Message result) {
766         changeIccPin2ForApp(oldPin2, newPin2, null, result);
767     }
768
769     @Override public void
770     changeIccPin2ForApp(String oldPin2, String newPin2, String aid, Message result) {
771         //Note: This RIL request has not been renamed to ICC,
772         //       but this request is also valid for SIM and RUIM
773         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CHANGE_SIM_PIN2, result);
774
775         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
776
777         rr.mParcel.writeInt(3);
778         rr.mParcel.writeString(oldPin2);
779         rr.mParcel.writeString(newPin2);
780         rr.mParcel.writeString(aid);
781
782         send(rr);
783     }
784
785     @Override
786     public void
787     changeBarringPassword(String facility, String oldPwd, String newPwd, Message result) {
788         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CHANGE_BARRING_PASSWORD, result);
789
790         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
791
792         rr.mParcel.writeInt(3);
793         rr.mParcel.writeString(facility);
794         rr.mParcel.writeString(oldPwd);
795         rr.mParcel.writeString(newPwd);
796
797         send(rr);
798     }
799
800     @Override
801     public void
802     supplyNetworkDepersonalization(String netpin, Message result) {
803         RILRequest rr = RILRequest.obtain(RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION, result);
804
805         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
806
807         rr.mParcel.writeInt(1);
808         rr.mParcel.writeString(netpin);
809
810         send(rr);
811     }
812
813     @Override
814     public void
815     getCurrentCalls (Message result) {
816         RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_CURRENT_CALLS, result);
817
818         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
819
820         send(rr);
821     }
822
823     @Override
824     @Deprecated public void
825     getPDPContextList(Message result) {
826         getDataCallList(result);
827     }
828
829     @Override
830     public void
831     getDataCallList(Message result) {
832         RILRequest rr = RILRequest.obtain(RIL_REQUEST_DATA_CALL_LIST, result);
833
834         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
835
836         send(rr);
837     }
838
839     @Override
840     public void
841     dial (String address, int clirMode, Message result) {
842         dial(address, clirMode, null, result);
843     }
844
845     @Override
846     public void
847     dial(String address, int clirMode, UUSInfo uusInfo, Message result) {
848         RILRequest rr = RILRequest.obtain(RIL_REQUEST_DIAL, result);
849
850         rr.mParcel.writeString(address);
851         rr.mParcel.writeInt(clirMode);
852
853         if (uusInfo == null) {
854             rr.mParcel.writeInt(0); // UUS information is absent
855         } else {
856             rr.mParcel.writeInt(1); // UUS information is present
857             rr.mParcel.writeInt(uusInfo.getType());
858             rr.mParcel.writeInt(uusInfo.getDcs());
859             rr.mParcel.writeByteArray(uusInfo.getUserData());
860         }
861
862         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
863
864         send(rr);
865     }
866
867     @Override
868     public void
869     getIMSI(Message result) {
870         getIMSIForApp(null, result);
871     }
872
873     @Override
874     public void
875     getIMSIForApp(String aid, Message result) {
876         RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_IMSI, result);
877
878         rr.mParcel.writeInt(1);
879         rr.mParcel.writeString(aid);
880
881         if (RILJ_LOGD) riljLog(rr.serialString() +
882                               "> getIMSI: " + requestToString(rr.mRequest)
883                               + " aid: " + aid);
884
885         send(rr);
886     }
887
888     @Override
889     public void
890     getIMEI(Message result) {
891         RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_IMEI, result);
892
893         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
894
895         send(rr);
896     }
897
898     @Override
899     public void
900     getIMEISV(Message result) {
901         RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_IMEISV, result);
902
903         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
904
905         send(rr);
906     }
907
908
909     @Override
910     public void
911     hangupConnection (int gsmIndex, Message result) {
912         if (RILJ_LOGD) riljLog("hangupConnection: gsmIndex=" + gsmIndex);
913
914         RILRequest rr = RILRequest.obtain(RIL_REQUEST_HANGUP, result);
915
916         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " " +
917                 gsmIndex);
918
919         rr.mParcel.writeInt(1);
920         rr.mParcel.writeInt(gsmIndex);
921
922         send(rr);
923     }
924
925     @Override
926     public void
927     hangupWaitingOrBackground (Message result) {
928         RILRequest rr = RILRequest.obtain(RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND,
929                                         result);
930
931         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
932
933         send(rr);
934     }
935
936     @Override
937     public void
938     hangupForegroundResumeBackground (Message result) {
939         RILRequest rr
940                 = RILRequest.obtain(
941                         RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND,
942                                         result);
943         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
944
945         send(rr);
946     }
947
948     @Override
949     public void
950     switchWaitingOrHoldingAndActive (Message result) {
951         RILRequest rr
952                 = RILRequest.obtain(
953                         RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE,
954                                         result);
955         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
956
957         send(rr);
958     }
959
960     @Override
961     public void
962     conference (Message result) {
963         RILRequest rr
964                 = RILRequest.obtain(RIL_REQUEST_CONFERENCE, result);
965
966         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
967
968         send(rr);
969     }
970
971
972     @Override
973     public void setPreferredVoicePrivacy(boolean enable, Message result) {
974         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE,
975                 result);
976
977         rr.mParcel.writeInt(1);
978         rr.mParcel.writeInt(enable ? 1:0);
979
980         send(rr);
981     }
982
983     @Override
984     public void getPreferredVoicePrivacy(Message result) {
985         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE,
986                 result);
987         send(rr);
988     }
989
990     @Override
991     public void
992     separateConnection (int gsmIndex, Message result) {
993         RILRequest rr
994                 = RILRequest.obtain(RIL_REQUEST_SEPARATE_CONNECTION, result);
995
996         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
997                             + " " + gsmIndex);
998
999         rr.mParcel.writeInt(1);
1000         rr.mParcel.writeInt(gsmIndex);
1001
1002         send(rr);
1003     }
1004
1005     @Override
1006     public void
1007     acceptCall (Message result) {
1008         RILRequest rr
1009                 = RILRequest.obtain(RIL_REQUEST_ANSWER, result);
1010
1011         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1012
1013         send(rr);
1014     }
1015
1016     @Override
1017     public void
1018     rejectCall (Message result) {
1019         RILRequest rr
1020                 = RILRequest.obtain(RIL_REQUEST_UDUB, result);
1021
1022         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1023
1024         send(rr);
1025     }
1026
1027     @Override
1028     public void
1029     explicitCallTransfer (Message result) {
1030         RILRequest rr
1031                 = RILRequest.obtain(RIL_REQUEST_EXPLICIT_CALL_TRANSFER, result);
1032
1033         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1034
1035         send(rr);
1036     }
1037
1038     @Override
1039     public void
1040     getLastCallFailCause (Message result) {
1041         RILRequest rr
1042                 = RILRequest.obtain(RIL_REQUEST_LAST_CALL_FAIL_CAUSE, result);
1043
1044         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1045
1046         send(rr);
1047     }
1048
1049     /**
1050      * @deprecated
1051      */
1052     @Deprecated
1053     @Override
1054     public void
1055     getLastPdpFailCause (Message result) {
1056         getLastDataCallFailCause (result);
1057     }
1058
1059     /**
1060      * The preferred new alternative to getLastPdpFailCause
1061      */
1062     @Override
1063     public void
1064     getLastDataCallFailCause (Message result) {
1065         RILRequest rr
1066                 = RILRequest.obtain(RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE, result);
1067
1068         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1069
1070         send(rr);
1071     }
1072
1073     @Override
1074     public void
1075     setMute (boolean enableMute, Message response) {
1076         RILRequest rr
1077                 = RILRequest.obtain(RIL_REQUEST_SET_MUTE, response);
1078
1079         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1080                             + " " + enableMute);
1081
1082         rr.mParcel.writeInt(1);
1083         rr.mParcel.writeInt(enableMute ? 1 : 0);
1084
1085         send(rr);
1086     }
1087
1088     @Override
1089     public void
1090     getMute (Message response) {
1091         RILRequest rr
1092                 = RILRequest.obtain(RIL_REQUEST_GET_MUTE, response);
1093
1094         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1095
1096         send(rr);
1097     }
1098
1099     @Override
1100     public void
1101     getSignalStrength (Message result) {
1102         RILRequest rr
1103                 = RILRequest.obtain(RIL_REQUEST_SIGNAL_STRENGTH, result);
1104
1105         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1106
1107         send(rr);
1108     }
1109
1110     @Override
1111     public void
1112     getVoiceRegistrationState (Message result) {
1113         RILRequest rr
1114                 = RILRequest.obtain(RIL_REQUEST_VOICE_REGISTRATION_STATE, result);
1115
1116         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1117
1118         send(rr);
1119     }
1120
1121     @Override
1122     public void
1123     getDataRegistrationState (Message result) {
1124         RILRequest rr
1125                 = RILRequest.obtain(RIL_REQUEST_DATA_REGISTRATION_STATE, result);
1126
1127         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1128
1129         send(rr);
1130     }
1131
1132     @Override
1133     public void
1134     getOperator(Message result) {
1135         RILRequest rr
1136                 = RILRequest.obtain(RIL_REQUEST_OPERATOR, result);
1137
1138         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1139
1140         send(rr);
1141     }
1142
1143     @Override
1144     public void
1145     sendDtmf(char c, Message result) {
1146         RILRequest rr
1147                 = RILRequest.obtain(RIL_REQUEST_DTMF, result);
1148
1149         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1150
1151         rr.mParcel.writeString(Character.toString(c));
1152
1153         send(rr);
1154     }
1155
1156     @Override
1157     public void
1158     startDtmf(char c, Message result) {
1159         RILRequest rr
1160                 = RILRequest.obtain(RIL_REQUEST_DTMF_START, result);
1161
1162         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1163
1164         rr.mParcel.writeString(Character.toString(c));
1165
1166         send(rr);
1167     }
1168
1169     @Override
1170     public void
1171     stopDtmf(Message result) {
1172         RILRequest rr
1173                 = RILRequest.obtain(RIL_REQUEST_DTMF_STOP, result);
1174
1175         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1176
1177         send(rr);
1178     }
1179
1180     @Override
1181     public void
1182     sendBurstDtmf(String dtmfString, int on, int off, Message result) {
1183         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_BURST_DTMF, result);
1184
1185         rr.mParcel.writeInt(3);
1186         rr.mParcel.writeString(dtmfString);
1187         rr.mParcel.writeString(Integer.toString(on));
1188         rr.mParcel.writeString(Integer.toString(off));
1189
1190         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1191                 + " : " + dtmfString);
1192
1193         send(rr);
1194     }
1195
1196     private void
1197     constructGsmSendSmsRilRequest (RILRequest rr, String smscPDU, String pdu) {
1198         rr.mParcel.writeInt(2);
1199         rr.mParcel.writeString(smscPDU);
1200         rr.mParcel.writeString(pdu);
1201     }
1202
1203     public void
1204     sendSMS (String smscPDU, String pdu, Message result) {
1205         RILRequest rr
1206                 = RILRequest.obtain(RIL_REQUEST_SEND_SMS, result);
1207
1208         constructGsmSendSmsRilRequest(rr, smscPDU, pdu);
1209
1210         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1211
1212         send(rr);
1213     }
1214
1215     private void
1216     constructCdmaSendSmsRilRequest(RILRequest rr, byte[] pdu) {
1217         int address_nbr_of_digits;
1218         int subaddr_nbr_of_digits;
1219         int bearerDataLength;
1220         ByteArrayInputStream bais = new ByteArrayInputStream(pdu);
1221         DataInputStream dis = new DataInputStream(bais);
1222
1223         try {
1224             rr.mParcel.writeInt(dis.readInt()); //teleServiceId
1225             rr.mParcel.writeByte((byte) dis.readInt()); //servicePresent
1226             rr.mParcel.writeInt(dis.readInt()); //serviceCategory
1227             rr.mParcel.writeInt(dis.read()); //address_digit_mode
1228             rr.mParcel.writeInt(dis.read()); //address_nbr_mode
1229             rr.mParcel.writeInt(dis.read()); //address_ton
1230             rr.mParcel.writeInt(dis.read()); //address_nbr_plan
1231             address_nbr_of_digits = (byte) dis.read();
1232             rr.mParcel.writeByte((byte) address_nbr_of_digits);
1233             for(int i=0; i < address_nbr_of_digits; i++){
1234                 rr.mParcel.writeByte(dis.readByte()); // address_orig_bytes[i]
1235             }
1236             rr.mParcel.writeInt(dis.read()); //subaddressType
1237             rr.mParcel.writeByte((byte) dis.read()); //subaddr_odd
1238             subaddr_nbr_of_digits = (byte) dis.read();
1239             rr.mParcel.writeByte((byte) subaddr_nbr_of_digits);
1240             for(int i=0; i < subaddr_nbr_of_digits; i++){
1241                 rr.mParcel.writeByte(dis.readByte()); //subaddr_orig_bytes[i]
1242             }
1243
1244             bearerDataLength = dis.read();
1245             rr.mParcel.writeInt(bearerDataLength);
1246             for(int i=0; i < bearerDataLength; i++){
1247                 rr.mParcel.writeByte(dis.readByte()); //bearerData[i]
1248             }
1249         }catch (IOException ex){
1250             if (RILJ_LOGD) riljLog("sendSmsCdma: conversion from input stream to object failed: "
1251                     + ex);
1252         }
1253     }
1254
1255     public void
1256     sendCdmaSms(byte[] pdu, Message result) {
1257         RILRequest rr
1258                 = RILRequest.obtain(RIL_REQUEST_CDMA_SEND_SMS, result);
1259
1260         constructCdmaSendSmsRilRequest(rr, pdu);
1261
1262         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1263
1264         send(rr);
1265     }
1266
1267     public void
1268     sendImsGsmSms (String smscPDU, String pdu, int retry, int messageRef,
1269             Message result) {
1270         RILRequest rr = RILRequest.obtain(RIL_REQUEST_IMS_SEND_SMS, result);
1271
1272         rr.mParcel.writeInt(1); //RIL_IMS_SMS_Format.FORMAT_3GPP
1273         rr.mParcel.writeByte((byte)retry);
1274         rr.mParcel.writeInt(messageRef);
1275
1276         constructGsmSendSmsRilRequest(rr, smscPDU, pdu);
1277
1278         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1279
1280         send(rr);
1281     }
1282
1283     public void
1284     sendImsCdmaSms(byte[] pdu, int retry, int messageRef, Message result) {
1285         RILRequest rr = RILRequest.obtain(RIL_REQUEST_IMS_SEND_SMS, result);
1286
1287         rr.mParcel.writeInt(2); //RIL_IMS_SMS_Format.FORMAT_3GPP2
1288         rr.mParcel.writeByte((byte)retry);
1289         rr.mParcel.writeInt(messageRef);
1290
1291         constructCdmaSendSmsRilRequest(rr, pdu);
1292
1293         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1294
1295         send(rr);
1296     }
1297
1298     @Override
1299     public void deleteSmsOnSim(int index, Message response) {
1300         RILRequest rr = RILRequest.obtain(RIL_REQUEST_DELETE_SMS_ON_SIM,
1301                 response);
1302
1303         rr.mParcel.writeInt(1);
1304         rr.mParcel.writeInt(index);
1305
1306         if (RILJ_LOGV) riljLog(rr.serialString() + "> "
1307                 + requestToString(rr.mRequest)
1308                 + " " + index);
1309
1310         send(rr);
1311     }
1312
1313     @Override
1314     public void deleteSmsOnRuim(int index, Message response) {
1315         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM,
1316                 response);
1317
1318         rr.mParcel.writeInt(1);
1319         rr.mParcel.writeInt(index);
1320
1321         if (RILJ_LOGV) riljLog(rr.serialString() + "> "
1322                 + requestToString(rr.mRequest)
1323                 + " " + index);
1324
1325         send(rr);
1326     }
1327
1328     @Override
1329     public void writeSmsToSim(int status, String smsc, String pdu, Message response) {
1330         status = translateStatus(status);
1331
1332         RILRequest rr = RILRequest.obtain(RIL_REQUEST_WRITE_SMS_TO_SIM,
1333                 response);
1334
1335         rr.mParcel.writeInt(status);
1336         rr.mParcel.writeString(pdu);
1337         rr.mParcel.writeString(smsc);
1338
1339         if (RILJ_LOGV) riljLog(rr.serialString() + "> "
1340                 + requestToString(rr.mRequest)
1341                 + " " + status);
1342
1343         send(rr);
1344     }
1345
1346     @Override
1347     public void writeSmsToRuim(int status, String pdu, Message response) {
1348         status = translateStatus(status);
1349
1350         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM,
1351                 response);
1352
1353         rr.mParcel.writeInt(status);
1354         rr.mParcel.writeString(pdu);
1355
1356         if (RILJ_LOGV) riljLog(rr.serialString() + "> "
1357                 + requestToString(rr.mRequest)
1358                 + " " + status);
1359
1360         send(rr);
1361     }
1362
1363     /**
1364      *  Translates EF_SMS status bits to a status value compatible with
1365      *  SMS AT commands.  See TS 27.005 3.1.
1366      */
1367     private int translateStatus(int status) {
1368         switch(status & 0x7) {
1369             case SmsManager.STATUS_ON_ICC_READ:
1370                 return 1;
1371             case SmsManager.STATUS_ON_ICC_UNREAD:
1372                 return 0;
1373             case SmsManager.STATUS_ON_ICC_SENT:
1374                 return 3;
1375             case SmsManager.STATUS_ON_ICC_UNSENT:
1376                 return 2;
1377         }
1378
1379         // Default to READ.
1380         return 1;
1381     }
1382
1383     @Override
1384     public void
1385     setupDataCall(String radioTechnology, String profile, String apn,
1386             String user, String password, String authType, String protocol,
1387             Message result) {
1388         RILRequest rr
1389                 = RILRequest.obtain(RIL_REQUEST_SETUP_DATA_CALL, result);
1390
1391         rr.mParcel.writeInt(7);
1392
1393         rr.mParcel.writeString(radioTechnology);
1394         rr.mParcel.writeString(profile);
1395         rr.mParcel.writeString(apn);
1396         rr.mParcel.writeString(user);
1397         rr.mParcel.writeString(password);
1398         rr.mParcel.writeString(authType);
1399         rr.mParcel.writeString(protocol);
1400
1401         if (RILJ_LOGD) riljLog(rr.serialString() + "> "
1402                 + requestToString(rr.mRequest) + " " + radioTechnology + " "
1403                 + profile + " " + apn + " " + user + " "
1404                 + password + " " + authType + " " + protocol);
1405
1406         send(rr);
1407     }
1408
1409     @Override
1410     public void
1411     deactivateDataCall(int cid, int reason, Message result) {
1412         RILRequest rr
1413                 = RILRequest.obtain(RIL_REQUEST_DEACTIVATE_DATA_CALL, result);
1414
1415         rr.mParcel.writeInt(2);
1416         rr.mParcel.writeString(Integer.toString(cid));
1417         rr.mParcel.writeString(Integer.toString(reason));
1418
1419         if (RILJ_LOGD) riljLog(rr.serialString() + "> " +
1420                 requestToString(rr.mRequest) + " " + cid + " " + reason);
1421
1422         send(rr);
1423     }
1424
1425     @Override
1426     public void
1427     setRadioPower(boolean on, Message result) {
1428         RILRequest rr = RILRequest.obtain(RIL_REQUEST_RADIO_POWER, result);
1429
1430         rr.mParcel.writeInt(1);
1431         rr.mParcel.writeInt(on ? 1 : 0);
1432
1433         if (RILJ_LOGD) {
1434             riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1435                     + (on ? " on" : " off"));
1436         }
1437
1438         send(rr);
1439     }
1440
1441     @Override
1442     public void
1443     setSuppServiceNotifications(boolean enable, Message result) {
1444         RILRequest rr
1445                 = RILRequest.obtain(RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION, result);
1446
1447         rr.mParcel.writeInt(1);
1448         rr.mParcel.writeInt(enable ? 1 : 0);
1449
1450         if (RILJ_LOGD) riljLog(rr.serialString() + "> "
1451                 + requestToString(rr.mRequest));
1452
1453         send(rr);
1454     }
1455
1456     @Override
1457     public void
1458     acknowledgeLastIncomingGsmSms(boolean success, int cause, Message result) {
1459         RILRequest rr
1460                 = RILRequest.obtain(RIL_REQUEST_SMS_ACKNOWLEDGE, result);
1461
1462         rr.mParcel.writeInt(2);
1463         rr.mParcel.writeInt(success ? 1 : 0);
1464         rr.mParcel.writeInt(cause);
1465
1466         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1467                 + " " + success + " " + cause);
1468
1469         send(rr);
1470     }
1471
1472     @Override
1473     public void
1474     acknowledgeLastIncomingCdmaSms(boolean success, int cause, Message result) {
1475         RILRequest rr
1476                 = RILRequest.obtain(RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE, result);
1477
1478         rr.mParcel.writeInt(success ? 0 : 1); //RIL_CDMA_SMS_ErrorClass
1479         // cause code according to X.S004-550E
1480         rr.mParcel.writeInt(cause);
1481
1482         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1483                 + " " + success + " " + cause);
1484
1485         send(rr);
1486     }
1487
1488     @Override
1489     public void
1490     acknowledgeIncomingGsmSmsWithPdu(boolean success, String ackPdu, Message result) {
1491         RILRequest rr
1492                 = RILRequest.obtain(RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU, result);
1493
1494         rr.mParcel.writeInt(2);
1495         rr.mParcel.writeString(success ? "1" : "0");
1496         rr.mParcel.writeString(ackPdu);
1497
1498         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1499                 + ' ' + success + " [" + ackPdu + ']');
1500
1501         send(rr);
1502     }
1503
1504     @Override
1505     public void
1506     iccIO (int command, int fileid, String path, int p1, int p2, int p3,
1507             String data, String pin2, Message result) {
1508         iccIOForApp(command, fileid, path, p1, p2, p3, data, pin2, null, result);
1509     }
1510     @Override
1511     public void
1512     iccIOForApp (int command, int fileid, String path, int p1, int p2, int p3,
1513             String data, String pin2, String aid, Message result) {
1514         //Note: This RIL request has not been renamed to ICC,
1515         //       but this request is also valid for SIM and RUIM
1516         RILRequest rr
1517                 = RILRequest.obtain(RIL_REQUEST_SIM_IO, result);
1518
1519         rr.mParcel.writeInt(command);
1520         rr.mParcel.writeInt(fileid);
1521         rr.mParcel.writeString(path);
1522         rr.mParcel.writeInt(p1);
1523         rr.mParcel.writeInt(p2);
1524         rr.mParcel.writeInt(p3);
1525         rr.mParcel.writeString(data);
1526         rr.mParcel.writeString(pin2);
1527         rr.mParcel.writeString(aid);
1528
1529         if (RILJ_LOGD) riljLog(rr.serialString() + "> iccIO: "
1530                 + requestToString(rr.mRequest)
1531                 + " 0x" + Integer.toHexString(command)
1532                 + " 0x" + Integer.toHexString(fileid) + " "
1533                 + " path: " + path + ","
1534                 + p1 + "," + p2 + "," + p3
1535                 + " aid: " + aid);
1536
1537         send(rr);
1538     }
1539
1540     @Override
1541     public void
1542     getCLIR(Message result) {
1543         RILRequest rr
1544                 = RILRequest.obtain(RIL_REQUEST_GET_CLIR, result);
1545
1546         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1547
1548         send(rr);
1549     }
1550
1551     @Override
1552     public void
1553     setCLIR(int clirMode, Message result) {
1554         RILRequest rr
1555                 = RILRequest.obtain(RIL_REQUEST_SET_CLIR, result);
1556
1557         // count ints
1558         rr.mParcel.writeInt(1);
1559
1560         rr.mParcel.writeInt(clirMode);
1561
1562         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1563                     + " " + clirMode);
1564
1565         send(rr);
1566     }
1567
1568     @Override
1569     public void
1570     queryCallWaiting(int serviceClass, Message response) {
1571         RILRequest rr
1572                 = RILRequest.obtain(RIL_REQUEST_QUERY_CALL_WAITING, response);
1573
1574         rr.mParcel.writeInt(1);
1575         rr.mParcel.writeInt(serviceClass);
1576
1577         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1578                     + " " + serviceClass);
1579
1580         send(rr);
1581     }
1582
1583     @Override
1584     public void
1585     setCallWaiting(boolean enable, int serviceClass, Message response) {
1586         RILRequest rr
1587                 = RILRequest.obtain(RIL_REQUEST_SET_CALL_WAITING, response);
1588
1589         rr.mParcel.writeInt(2);
1590         rr.mParcel.writeInt(enable ? 1 : 0);
1591         rr.mParcel.writeInt(serviceClass);
1592
1593         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1594                 + " " + enable + ", " + serviceClass);
1595
1596         send(rr);
1597     }
1598
1599     @Override
1600     public void
1601     setNetworkSelectionModeAutomatic(Message response) {
1602         RILRequest rr
1603                 = RILRequest.obtain(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC,
1604                                     response);
1605
1606         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1607
1608         send(rr);
1609     }
1610
1611     @Override
1612     public void
1613     setNetworkSelectionModeManual(String operatorNumeric, Message response) {
1614         RILRequest rr
1615                 = RILRequest.obtain(RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL,
1616                                     response);
1617
1618         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1619                     + " " + operatorNumeric);
1620
1621         rr.mParcel.writeString(operatorNumeric);
1622
1623         send(rr);
1624     }
1625
1626     @Override
1627     public void
1628     getNetworkSelectionMode(Message response) {
1629         RILRequest rr
1630                 = RILRequest.obtain(RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE,
1631                                     response);
1632
1633         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1634
1635         send(rr);
1636     }
1637
1638     @Override
1639     public void
1640     getAvailableNetworks(Message response) {
1641         RILRequest rr
1642                 = RILRequest.obtain(RIL_REQUEST_QUERY_AVAILABLE_NETWORKS,
1643                                     response);
1644
1645         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1646
1647         send(rr);
1648     }
1649
1650     @Override
1651     public void
1652     setCallForward(int action, int cfReason, int serviceClass,
1653                 String number, int timeSeconds, Message response) {
1654         RILRequest rr
1655                 = RILRequest.obtain(RIL_REQUEST_SET_CALL_FORWARD, response);
1656
1657         rr.mParcel.writeInt(action);
1658         rr.mParcel.writeInt(cfReason);
1659         rr.mParcel.writeInt(serviceClass);
1660         rr.mParcel.writeInt(PhoneNumberUtils.toaFromString(number));
1661         rr.mParcel.writeString(number);
1662         rr.mParcel.writeInt (timeSeconds);
1663
1664         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1665                     + " " + action + " " + cfReason + " " + serviceClass
1666                     + timeSeconds);
1667
1668         send(rr);
1669     }
1670
1671     @Override
1672     public void
1673     queryCallForwardStatus(int cfReason, int serviceClass,
1674                 String number, Message response) {
1675         RILRequest rr
1676             = RILRequest.obtain(RIL_REQUEST_QUERY_CALL_FORWARD_STATUS, response);
1677
1678         rr.mParcel.writeInt(2); // 2 is for query action, not in used anyway
1679         rr.mParcel.writeInt(cfReason);
1680         rr.mParcel.writeInt(serviceClass);
1681         rr.mParcel.writeInt(PhoneNumberUtils.toaFromString(number));
1682         rr.mParcel.writeString(number);
1683         rr.mParcel.writeInt (0);
1684
1685         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1686                 + " " + cfReason + " " + serviceClass);
1687
1688         send(rr);
1689     }
1690
1691     @Override
1692     public void
1693     queryCLIP(Message response) {
1694         RILRequest rr
1695             = RILRequest.obtain(RIL_REQUEST_QUERY_CLIP, response);
1696
1697         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1698
1699         send(rr);
1700     }
1701
1702
1703     @Override
1704     public void
1705     getBasebandVersion (Message response) {
1706         RILRequest rr
1707                 = RILRequest.obtain(RIL_REQUEST_BASEBAND_VERSION, response);
1708
1709         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1710
1711         send(rr);
1712     }
1713
1714     @Override
1715     public void
1716     queryFacilityLock(String facility, String password, int serviceClass,
1717                             Message response) {
1718         queryFacilityLockForApp(facility, password, serviceClass, null, response);
1719     }
1720
1721     @Override
1722     public void
1723     queryFacilityLockForApp(String facility, String password, int serviceClass, String appId,
1724                             Message response) {
1725         RILRequest rr = RILRequest.obtain(RIL_REQUEST_QUERY_FACILITY_LOCK, response);
1726
1727         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1728                                                  + " [" + facility + " " + serviceClass
1729                                                  + " " + appId + "]");
1730
1731         // count strings
1732         rr.mParcel.writeInt(4);
1733
1734         rr.mParcel.writeString(facility);
1735         rr.mParcel.writeString(password);
1736
1737         rr.mParcel.writeString(Integer.toString(serviceClass));
1738         rr.mParcel.writeString(appId);
1739
1740         send(rr);
1741     }
1742
1743     @Override
1744     public void
1745     setFacilityLock (String facility, boolean lockState, String password,
1746                         int serviceClass, Message response) {
1747         setFacilityLockForApp(facility, lockState, password, serviceClass, null, response);
1748     }
1749
1750     @Override
1751     public void
1752     setFacilityLockForApp(String facility, boolean lockState, String password,
1753                         int serviceClass, String appId, Message response) {
1754         String lockString;
1755          RILRequest rr
1756                 = RILRequest.obtain(RIL_REQUEST_SET_FACILITY_LOCK, response);
1757
1758         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1759                                                         + " [" + facility + " " + lockState
1760                                                         + " " + serviceClass + " " + appId + "]");
1761
1762         // count strings
1763         rr.mParcel.writeInt(5);
1764
1765         rr.mParcel.writeString(facility);
1766         lockString = (lockState)?"1":"0";
1767         rr.mParcel.writeString(lockString);
1768         rr.mParcel.writeString(password);
1769         rr.mParcel.writeString(Integer.toString(serviceClass));
1770         rr.mParcel.writeString(appId);
1771
1772         send(rr);
1773
1774     }
1775
1776     @Override
1777     public void
1778     sendUSSD (String ussdString, Message response) {
1779         RILRequest rr
1780                 = RILRequest.obtain(RIL_REQUEST_SEND_USSD, response);
1781
1782         if (RILJ_LOGD) {
1783             String logUssdString = "*******";
1784             if (RILJ_LOGV) logUssdString = ussdString;
1785             riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1786                                    + " " + logUssdString);
1787         }
1788
1789         rr.mParcel.writeString(ussdString);
1790
1791         send(rr);
1792     }
1793
1794     // inherited javadoc suffices
1795     @Override
1796     public void cancelPendingUssd (Message response) {
1797         RILRequest rr
1798                 = RILRequest.obtain(RIL_REQUEST_CANCEL_USSD, response);
1799
1800         if (RILJ_LOGD) riljLog(rr.serialString()
1801                 + "> " + requestToString(rr.mRequest));
1802
1803         send(rr);
1804     }
1805
1806
1807     @Override
1808     public void resetRadio(Message result) {
1809         RILRequest rr
1810                 = RILRequest.obtain(RIL_REQUEST_RESET_RADIO, result);
1811
1812         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1813
1814         send(rr);
1815     }
1816
1817     @Override
1818     public void invokeOemRilRequestRaw(byte[] data, Message response) {
1819         RILRequest rr
1820                 = RILRequest.obtain(RIL_REQUEST_OEM_HOOK_RAW, response);
1821
1822         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1823                + "[" + IccUtils.bytesToHexString(data) + "]");
1824
1825         rr.mParcel.writeByteArray(data);
1826
1827         send(rr);
1828
1829     }
1830
1831     @Override
1832     public void invokeOemRilRequestStrings(String[] strings, Message response) {
1833         RILRequest rr
1834                 = RILRequest.obtain(RIL_REQUEST_OEM_HOOK_STRINGS, response);
1835
1836         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1837
1838         rr.mParcel.writeStringArray(strings);
1839
1840         send(rr);
1841     }
1842
1843      /**
1844      * Assign a specified band for RF configuration.
1845      *
1846      * @param bandMode one of BM_*_BAND
1847      * @param response is callback message
1848      */
1849     @Override
1850     public void setBandMode (int bandMode, Message response) {
1851         RILRequest rr
1852                 = RILRequest.obtain(RIL_REQUEST_SET_BAND_MODE, response);
1853
1854         rr.mParcel.writeInt(1);
1855         rr.mParcel.writeInt(bandMode);
1856
1857         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1858                  + " " + bandMode);
1859
1860         send(rr);
1861      }
1862
1863     /**
1864      * Query the list of band mode supported by RF.
1865      *
1866      * @param response is callback message
1867      *        ((AsyncResult)response.obj).result  is an int[] with every
1868      *        element representing one avialable BM_*_BAND
1869      */
1870     @Override
1871     public void queryAvailableBandMode (Message response) {
1872         RILRequest rr
1873                 = RILRequest.obtain(RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE,
1874                 response);
1875
1876         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1877
1878         send(rr);
1879     }
1880
1881     /**
1882      * {@inheritDoc}
1883      */
1884     @Override
1885     public void sendTerminalResponse(String contents, Message response) {
1886         RILRequest rr = RILRequest.obtain(
1887                 RILConstants.RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE, response);
1888
1889         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1890
1891         rr.mParcel.writeString(contents);
1892         send(rr);
1893     }
1894
1895     /**
1896      * {@inheritDoc}
1897      */
1898     @Override
1899     public void sendEnvelope(String contents, Message response) {
1900         RILRequest rr = RILRequest.obtain(
1901                 RILConstants.RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND, response);
1902
1903         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1904
1905         rr.mParcel.writeString(contents);
1906         send(rr);
1907     }
1908
1909     /**
1910      * {@inheritDoc}
1911      */
1912     @Override
1913     public void sendEnvelopeWithStatus(String contents, Message response) {
1914         RILRequest rr = RILRequest.obtain(
1915                 RILConstants.RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS, response);
1916
1917         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1918                 + '[' + contents + ']');
1919
1920         rr.mParcel.writeString(contents);
1921         send(rr);
1922     }
1923
1924     /**
1925      * {@inheritDoc}
1926      */
1927     @Override
1928     public void handleCallSetupRequestFromSim(
1929             boolean accept, Message response) {
1930
1931         RILRequest rr = RILRequest.obtain(
1932             RILConstants.RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM,
1933             response);
1934
1935         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1936
1937         int[] param = new int[1];
1938         param[0] = accept ? 1 : 0;
1939         rr.mParcel.writeIntArray(param);
1940         send(rr);
1941     }
1942
1943     /**
1944      * {@inheritDoc}
1945      */
1946     @Override
1947     public void setCurrentPreferredNetworkType() {
1948         if (RILJ_LOGD) riljLog("setCurrentPreferredNetworkType: " + mSetPreferredNetworkType);
1949         setPreferredNetworkType(mSetPreferredNetworkType, null);
1950     }
1951     private int mSetPreferredNetworkType;
1952
1953     /**
1954      * {@inheritDoc}
1955      */
1956     @Override
1957     public void setPreferredNetworkType(int networkType , Message response) {
1958         RILRequest rr = RILRequest.obtain(
1959                 RILConstants.RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE, response);
1960
1961         rr.mParcel.writeInt(1);
1962         rr.mParcel.writeInt(networkType);
1963
1964         mSetPreferredNetworkType = networkType;
1965         mPreferredNetworkType = networkType;
1966
1967         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1968                 + " : " + networkType);
1969
1970         send(rr);
1971     }
1972
1973     /**
1974      * {@inheritDoc}
1975      */
1976     @Override
1977     public void getPreferredNetworkType(Message response) {
1978         RILRequest rr = RILRequest.obtain(
1979                 RILConstants.RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE, response);
1980
1981         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1982
1983         send(rr);
1984     }
1985
1986     /**
1987      * {@inheritDoc}
1988      */
1989     @Override
1990     public void getNeighboringCids(Message response) {
1991         RILRequest rr = RILRequest.obtain(
1992                 RILConstants.RIL_REQUEST_GET_NEIGHBORING_CELL_IDS, response);
1993
1994         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1995
1996         send(rr);
1997     }
1998
1999     /**
2000      * {@inheritDoc}
2001      */
2002     @Override
2003     public void setLocationUpdates(boolean enable, Message response) {
2004         RILRequest rr = RILRequest.obtain(RIL_REQUEST_SET_LOCATION_UPDATES, response);
2005         rr.mParcel.writeInt(1);
2006         rr.mParcel.writeInt(enable ? 1 : 0);
2007
2008         if (RILJ_LOGD) riljLog(rr.serialString() + "> "
2009                 + requestToString(rr.mRequest) + ": " + enable);
2010
2011         send(rr);
2012     }
2013
2014     /**
2015      * {@inheritDoc}
2016      */
2017     @Override
2018     public void getSmscAddress(Message result) {
2019         RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_SMSC_ADDRESS, result);
2020
2021         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
2022
2023         send(rr);
2024     }
2025
2026     /**
2027      * {@inheritDoc}
2028      */
2029     @Override
2030     public void setSmscAddress(String address, Message result) {
2031         RILRequest rr = RILRequest.obtain(RIL_REQUEST_SET_SMSC_ADDRESS, result);
2032
2033         rr.mParcel.writeString(address);
2034
2035         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
2036                 + " : " + address);
2037
2038         send(rr);
2039     }
2040
2041     /**
2042      * {@inheritDoc}
2043      */
2044     @Override
2045     public void reportSmsMemoryStatus(boolean available, Message result) {
2046         RILRequest rr = RILRequest.obtain(RIL_REQUEST_REPORT_SMS_MEMORY_STATUS, result);
2047         rr.mParcel.writeInt(1);
2048         rr.mParcel.writeInt(available ? 1 : 0);
2049
2050         if (RILJ_LOGD) riljLog(rr.serialString() + "> "
2051                 + requestToString(rr.mRequest) + ": " + available);
2052
2053         send(rr);
2054     }
2055
2056     /**
2057      * {@inheritDoc}
2058      */
2059     @Override
2060     public void reportStkServiceIsRunning(Message result) {
2061         RILRequest rr = RILRequest.obtain(RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING, result);
2062
2063         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
2064
2065         send(rr);
2066     }
2067
2068     /**
2069      * {@inheritDoc}
2070      */
2071     @Override
2072     public void getGsmBroadcastConfig(Message response) {
2073         RILRequest rr = RILRequest.obtain(RIL_REQUEST_GSM_GET_BROADCAST_CONFIG, response);
2074
2075         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
2076
2077         send(rr);
2078     }
2079
2080     /**
2081      * {@inheritDoc}
2082      */
2083     @Override
2084     public void setGsmBroadcastConfig(SmsBroadcastConfigInfo[] config, Message response) {
2085         RILRequest rr = RILRequest.obtain(RIL_REQUEST_GSM_SET_BROADCAST_CONFIG, response);
2086
2087         int numOfConfig = config.length;
2088         rr.mParcel.writeInt(numOfConfig);
2089
2090         for(int i = 0; i < numOfConfig; i++) {
2091             rr.mParcel.writeInt(config[i].getFromServiceId());
2092             rr.mParcel.writeInt(config[i].getToServiceId());
2093             rr.mParcel.writeInt(config[i].getFromCodeScheme());
2094             rr.mParcel.writeInt(config[i].getToCodeScheme());
2095             rr.mParcel.writeInt(config[i].isSelected() ? 1 : 0);
2096         }
2097
2098         if (RILJ_LOGD) {
2099             riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
2100                     + " with " + numOfConfig + " configs : ");
2101             for (int i = 0; i < numOfConfig; i++) {
2102                 riljLog(config[i].toString());
2103             }
2104         }
2105
2106         send(rr);
2107     }
2108
2109     /**
2110      * {@inheritDoc}
2111      */
2112     @Override
2113     public void setGsmBroadcastActivation(boolean activate, Message response) {
2114         RILRequest rr = RILRequest.obtain(RIL_REQUEST_GSM_BROADCAST_ACTIVATION, response);
2115
2116         rr.mParcel.writeInt(1);
2117         rr.mParcel.writeInt(activate ? 0 : 1);
2118
2119         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
2120
2121         send(rr);
2122     }
2123
2124     //***** Private Methods
2125
2126     private void sendScreenState(boolean on) {
2127         RILRequest rr = RILRequest.obtain(RIL_REQUEST_SCREEN_STATE, null);
2128         rr.mParcel.writeInt(1);
2129         rr.mParcel.writeInt(on ? 1 : 0);
2130
2131         if (RILJ_LOGD) riljLog(rr.serialString()
2132                 + "> " + requestToString(rr.mRequest) + ": " + on);
2133
2134         send(rr);
2135     }
2136
2137     @Override
2138     protected void
2139     onRadioAvailable() {
2140         // In case screen state was lost (due to process crash),
2141         // this ensures that the RIL knows the correct screen state.
2142
2143         PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
2144         sendScreenState(pm.isScreenOn());
2145    }
2146
2147     private RadioState getRadioStateFromInt(int stateInt) {
2148         RadioState state;
2149
2150         /* RIL_RadioState ril.h */
2151         switch(stateInt) {
2152             case 0: state = RadioState.RADIO_OFF; break;
2153             case 1: state = RadioState.RADIO_UNAVAILABLE; break;
2154             case 10: state = RadioState.RADIO_ON; break;
2155
2156             default:
2157                 throw new RuntimeException(
2158                             "Unrecognized RIL_RadioState: " + stateInt);
2159         }
2160         return state;
2161     }
2162
2163     private void switchToRadioState(RadioState newState) {
2164         setRadioState(newState);
2165     }
2166
2167     /**
2168      * Holds a PARTIAL_WAKE_LOCK whenever
2169      * a) There is outstanding RIL request sent to RIL deamon and no replied
2170      * b) There is a request pending to be sent out.
2171      *
2172      * There is a WAKE_LOCK_TIMEOUT to release the lock, though it shouldn't
2173      * happen often.
2174      */
2175
2176     private void
2177     acquireWakeLock() {
2178         synchronized (mWakeLock) {
2179             mWakeLock.acquire();
2180             mWakeLockCount++;
2181
2182             mSender.removeMessages(EVENT_WAKE_LOCK_TIMEOUT);
2183             Message msg = mSender.obtainMessage(EVENT_WAKE_LOCK_TIMEOUT);
2184             mSender.sendMessageDelayed(msg, mWakeLockTimeout);
2185         }
2186     }
2187
2188     private void
2189     decrementWakeLock() {
2190         synchronized (mWakeLock) {
2191             if (mWakeLockCount > 1) {
2192                 mWakeLockCount--;
2193             } else {
2194                 mWakeLockCount = 0;
2195                 mWakeLock.release();
2196                 mSender.removeMessages(EVENT_WAKE_LOCK_TIMEOUT);
2197             }
2198         }
2199     }
2200
2201     // true if we had the wakelock
2202     private boolean
2203     clearWakeLock() {
2204         synchronized (mWakeLock) {
2205             if (mWakeLockCount == 0 && mWakeLock.isHeld() == false) return false;
2206             Rlog.d(RILJ_LOG_TAG, "NOTE: mWakeLockCount is " + mWakeLockCount + "at time of clearing");
2207             mWakeLockCount = 0;
2208             mWakeLock.release();
2209             mSender.removeMessages(EVENT_WAKE_LOCK_TIMEOUT);
2210             return true;
2211         }
2212     }
2213
2214     private void
2215     send(RILRequest rr) {
2216         Message msg;
2217
2218         if (mSocket == null) {
2219             rr.onError(RADIO_NOT_AVAILABLE, null);
2220             rr.release();
2221             return;
2222         }
2223
2224         msg = mSender.obtainMessage(EVENT_SEND, rr);
2225
2226         acquireWakeLock();
2227
2228         msg.sendToTarget();
2229     }
2230
2231     private void
2232     processResponse (Parcel p) {
2233         int type;
2234
2235         type = p.readInt();
2236
2237         if (type == RESPONSE_UNSOLICITED) {
2238             processUnsolicited (p);
2239         } else if (type == RESPONSE_SOLICITED) {
2240             RILRequest rr = processSolicited (p);
2241             if (rr != null) {
2242                 rr.release();
2243                 decrementWakeLock();
2244             }
2245         }
2246     }
2247
2248     /**
2249      * Release each request in mRequestList then clear the list
2250      * @param error is the RIL_Errno sent back
2251      * @param loggable true means to print all requests in mRequestList
2252      */
2253     private void clearRequestList(int error, boolean loggable) {
2254         RILRequest rr;
2255         synchronized (mRequestList) {
2256             int count = mRequestList.size();
2257             if (RILJ_LOGD && loggable) {
2258                 Rlog.d(RILJ_LOG_TAG, "clearRequestList " +
2259                         " mWakeLockCount=" + mWakeLockCount +
2260                         " mRequestList=" + count);
2261             }
2262
2263             for (int i = 0; i < count ; i++) {
2264                 rr = mRequestList.valueAt(i);
2265                 if (RILJ_LOGD && loggable) {
2266                     Rlog.d(RILJ_LOG_TAG, i + ": [" + rr.mSerial + "] " +
2267                             requestToString(rr.mRequest));
2268                 }
2269                 rr.onError(error, null);
2270                 rr.release();
2271                 decrementWakeLock();
2272             }
2273             mRequestList.clear();
2274         }
2275     }
2276
2277     private RILRequest findAndRemoveRequestFromList(int serial) {
2278         RILRequest rr = null;
2279         synchronized (mRequestList) {
2280             rr = mRequestList.get(serial);
2281             if (rr != null) {
2282                 mRequestList.remove(serial);
2283             }
2284         }
2285
2286         return rr;
2287     }
2288
2289     private RILRequest
2290     processSolicited (Parcel p) {
2291         int serial, error;
2292         boolean found = false;
2293
2294         serial = p.readInt();
2295         error = p.readInt();
2296
2297         RILRequest rr;
2298
2299         rr = findAndRemoveRequestFromList(serial);
2300
2301         if (rr == null) {
2302             Rlog.w(RILJ_LOG_TAG, "Unexpected solicited response! sn: "
2303                             + serial + " error: " + error);
2304             return null;
2305         }
2306
2307         Object ret = null;
2308
2309         if (error == 0 || p.dataAvail() > 0) {
2310             // either command succeeds or command fails but with data payload
2311             try {switch (rr.mRequest) {
2312             /*
2313  cat libs/telephony/ril_commands.h \
2314  | egrep "^ *{RIL_" \
2315  | sed -re 's/\{([^,]+),[^,]+,([^}]+).+/case \1: ret = \2(p); break;/'
2316              */
2317             case RIL_REQUEST_GET_SIM_STATUS: ret =  responseIccCardStatus(p); break;
2318             case RIL_REQUEST_ENTER_SIM_PIN: ret =  responseInts(p); break;
2319             case RIL_REQUEST_ENTER_SIM_PUK: ret =  responseInts(p); break;
2320             case RIL_REQUEST_ENTER_SIM_PIN2: ret =  responseInts(p); break;
2321             case RIL_REQUEST_ENTER_SIM_PUK2: ret =  responseInts(p); break;
2322             case RIL_REQUEST_CHANGE_SIM_PIN: ret =  responseInts(p); break;
2323             case RIL_REQUEST_CHANGE_SIM_PIN2: ret =  responseInts(p); break;
2324             case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: ret =  responseInts(p); break;
2325             case RIL_REQUEST_GET_CURRENT_CALLS: ret =  responseCallList(p); break;
2326             case RIL_REQUEST_DIAL: ret =  responseVoid(p); break;
2327             case RIL_REQUEST_GET_IMSI: ret =  responseString(p); break;
2328             case RIL_REQUEST_HANGUP: ret =  responseVoid(p); break;
2329             case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: ret =  responseVoid(p); break;
2330             case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: {
2331                 if (mTestingEmergencyCall.getAndSet(false)) {
2332                     if (mEmergencyCallbackModeRegistrant != null) {
2333                         riljLog("testing emergency call, notify ECM Registrants");
2334                         mEmergencyCallbackModeRegistrant.notifyRegistrant();
2335                     }
2336                 }
2337                 ret =  responseVoid(p);
2338                 break;
2339             }
2340             case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: ret =  responseVoid(p); break;
2341             case RIL_REQUEST_CONFERENCE: ret =  responseVoid(p); break;
2342             case RIL_REQUEST_UDUB: ret =  responseVoid(p); break;
2343             case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: ret =  responseInts(p); break;
2344             case RIL_REQUEST_SIGNAL_STRENGTH: ret =  responseSignalStrength(p); break;
2345             case RIL_REQUEST_VOICE_REGISTRATION_STATE: ret =  responseStrings(p); break;
2346             case RIL_REQUEST_DATA_REGISTRATION_STATE: ret =  responseStrings(p); break;
2347             case RIL_REQUEST_OPERATOR: ret =  responseStrings(p); break;
2348             case RIL_REQUEST_RADIO_POWER: ret =  responseVoid(p); break;
2349             case RIL_REQUEST_DTMF: ret =  responseVoid(p); break;
2350             case RIL_REQUEST_SEND_SMS: ret =  responseSMS(p); break;
2351             case RIL_REQUEST_SEND_SMS_EXPECT_MORE: ret =  responseSMS(p); break;
2352             case RIL_REQUEST_SETUP_DATA_CALL: ret =  responseSetupDataCall(p); break;
2353             case RIL_REQUEST_SIM_IO: ret =  responseICC_IO(p); break;
2354             case RIL_REQUEST_SEND_USSD: ret =  responseVoid(p); break;
2355             case RIL_REQUEST_CANCEL_USSD: ret =  responseVoid(p); break;
2356             case RIL_REQUEST_GET_CLIR: ret =  responseInts(p); break;
2357             case RIL_REQUEST_SET_CLIR: ret =  responseVoid(p); break;
2358             case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: ret =  responseCallForward(p); break;
2359             case RIL_REQUEST_SET_CALL_FORWARD: ret =  responseVoid(p); break;
2360             case RIL_REQUEST_QUERY_CALL_WAITING: ret =  responseInts(p); break;
2361             case RIL_REQUEST_SET_CALL_WAITING: ret =  responseVoid(p); break;
2362             case RIL_REQUEST_SMS_ACKNOWLEDGE: ret =  responseVoid(p); break;
2363             case RIL_REQUEST_GET_IMEI: ret =  responseString(p); break;
2364             case RIL_REQUEST_GET_IMEISV: ret =  responseString(p); break;
2365             case RIL_REQUEST_ANSWER: ret =  responseVoid(p); break;
2366             case RIL_REQUEST_DEACTIVATE_DATA_CALL: ret =  responseVoid(p); break;
2367             case RIL_REQUEST_QUERY_FACILITY_LOCK: ret =  responseInts(p); break;
2368             case RIL_REQUEST_SET_FACILITY_LOCK: ret =  responseInts(p); break;
2369             case RIL_REQUEST_CHANGE_BARRING_PASSWORD: ret =  responseVoid(p); break;
2370             case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: ret =  responseInts(p); break;
2371             case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: ret =  responseVoid(p); break;
2372             case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: ret =  responseVoid(p); break;
2373             case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : ret =  responseOperatorInfos(p); break;
2374             case RIL_REQUEST_DTMF_START: ret =  responseVoid(p); break;
2375             case RIL_REQUEST_DTMF_STOP: ret =  responseVoid(p); break;
2376             case RIL_REQUEST_BASEBAND_VERSION: ret =  responseString(p); break;
2377             case RIL_REQUEST_SEPARATE_CONNECTION: ret =  responseVoid(p); break;
2378             case RIL_REQUEST_SET_MUTE: ret =  responseVoid(p); break;
2379             case RIL_REQUEST_GET_MUTE: ret =  responseInts(p); break;
2380             case RIL_REQUEST_QUERY_CLIP: ret =  responseInts(p); break;
2381             case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: ret =  responseInts(p); break;
2382             case RIL_REQUEST_DATA_CALL_LIST: ret =  responseDataCallList(p); break;
2383             case RIL_REQUEST_RESET_RADIO: ret =  responseVoid(p); break;
2384             case RIL_REQUEST_OEM_HOOK_RAW: ret =  responseRaw(p); break;
2385             case RIL_REQUEST_OEM_HOOK_STRINGS: ret =  responseStrings(p); break;
2386             case RIL_REQUEST_SCREEN_STATE: ret =  responseVoid(p); break;
2387             case RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION: ret =  responseVoid(p); break;
2388             case RIL_REQUEST_WRITE_SMS_TO_SIM: ret =  responseInts(p); break;
2389             case RIL_REQUEST_DELETE_SMS_ON_SIM: ret =  responseVoid(p); break;
2390             case RIL_REQUEST_SET_BAND_MODE: ret =  responseVoid(p); break;
2391             case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: ret =  responseInts(p); break;
2392             case RIL_REQUEST_STK_GET_PROFILE: ret =  responseString(p); break;
2393             case RIL_REQUEST_STK_SET_PROFILE: ret =  responseVoid(p); break;
2394             case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: ret =  responseString(p); break;
2395             case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: ret =  responseVoid(p); break;
2396             case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: ret =  responseInts(p); break;
2397             case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: ret =  responseVoid(p); break;
2398             case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: ret =  responseVoid(p); break;
2399             case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: ret =  responseGetPreferredNetworkType(p); break;
2400             case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: ret = responseCellList(p); break;
2401             case RIL_REQUEST_SET_LOCATION_UPDATES: ret =  responseVoid(p); break;
2402             case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE: ret =  responseVoid(p); break;
2403             case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE: ret =  responseVoid(p); break;
2404             case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE: ret =  responseInts(p); break;
2405             case RIL_REQUEST_SET_TTY_MODE: ret =  responseVoid(p); break;
2406             case RIL_REQUEST_QUERY_TTY_MODE: ret =  responseInts(p); break;
2407             case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE: ret =  responseVoid(p); break;
2408             case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE: ret =  responseInts(p); break;
2409             case RIL_REQUEST_CDMA_FLASH: ret =  responseVoid(p); break;
2410             case RIL_REQUEST_CDMA_BURST_DTMF: ret =  responseVoid(p); break;
2411             case RIL_REQUEST_CDMA_SEND_SMS: ret =  responseSMS(p); break;
2412             case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE: ret =  responseVoid(p); break;
2413             case RIL_REQUEST_GSM_GET_BROADCAST_CONFIG: ret =  responseGmsBroadcastConfig(p); break;
2414             case RIL_REQUEST_GSM_SET_BROADCAST_CONFIG: ret =  responseVoid(p); break;
2415             case RIL_REQUEST_GSM_BROADCAST_ACTIVATION: ret =  responseVoid(p); break;
2416             case RIL_REQUEST_CDMA_GET_BROADCAST_CONFIG: ret =  responseCdmaBroadcastConfig(p); break;
2417             case RIL_REQUEST_CDMA_SET_BROADCAST_CONFIG: ret =  responseVoid(p); break;
2418             case RIL_REQUEST_CDMA_BROADCAST_ACTIVATION: ret =  responseVoid(p); break;
2419             case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: ret =  responseVoid(p); break;
2420             case RIL_REQUEST_CDMA_SUBSCRIPTION: ret =  responseStrings(p); break;
2421             case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: ret =  responseInts(p); break;
2422             case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: ret =  responseVoid(p); break;
2423             case RIL_REQUEST_DEVICE_IDENTITY: ret =  responseStrings(p); break;
2424             case RIL_REQUEST_GET_SMSC_ADDRESS: ret = responseString(p); break;
2425             case RIL_REQUEST_SET_SMSC_ADDRESS: ret = responseVoid(p); break;
2426             case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: ret = responseVoid(p); break;
2427             case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: ret = responseVoid(p); break;
2428             case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: ret = responseVoid(p); break;
2429             case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: ret =  responseInts(p); break;
2430             case RIL_REQUEST_ISIM_AUTHENTICATION: ret =  responseString(p); break;
2431             case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: ret = responseVoid(p); break;
2432             case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: ret = responseICC_IO(p); break;
2433             case RIL_REQUEST_VOICE_RADIO_TECH: ret = responseInts(p); break;
2434             case RIL_REQUEST_GET_CELL_INFO_LIST: ret = responseCellInfoList(p); break;
2435             case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: ret = responseVoid(p); break;
2436             case RIL_REQUEST_SET_INITIAL_ATTACH_APN: ret = responseVoid(p); break;
2437             case RIL_REQUEST_IMS_REGISTRATION_STATE: ret = responseInts(p); break;
2438             case RIL_REQUEST_IMS_SEND_SMS: ret =  responseSMS(p); break;
2439             default:
2440                 throw new RuntimeException("Unrecognized solicited response: " + rr.mRequest);
2441             //break;
2442             }} catch (Throwable tr) {
2443                 // Exceptions here usually mean invalid RIL responses
2444
2445                 Rlog.w(RILJ_LOG_TAG, rr.serialString() + "< "
2446                         + requestToString(rr.mRequest)
2447                         + " exception, possible invalid RIL response", tr);
2448
2449                 if (rr.mResult != null) {
2450                     AsyncResult.forMessage(rr.mResult, null, tr);
2451                     rr.mResult.sendToTarget();
2452                 }
2453                 return rr;
2454             }
2455         }
2456
2457         // Here and below fake RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, see b/7255789.
2458         // This is needed otherwise we don't automatically transition to the main lock
2459         // screen when the pin or puk is entered incorrectly.
2460         switch (rr.mRequest) {
2461             case RIL_REQUEST_ENTER_SIM_PUK:
2462             case RIL_REQUEST_ENTER_SIM_PUK2:
2463                 if (mIccStatusChangedRegistrants != null) {
2464                     if (RILJ_LOGD) {
2465                         riljLog("ON enter sim puk fakeSimStatusChanged: reg count="
2466                                 + mIccStatusChangedRegistrants.size());
2467                     }
2468                     mIccStatusChangedRegistrants.notifyRegistrants();
2469                 }
2470                 break;
2471         }
2472
2473         if (error != 0) {
2474             switch (rr.mRequest) {
2475                 case RIL_REQUEST_ENTER_SIM_PIN:
2476                 case RIL_REQUEST_ENTER_SIM_PIN2:
2477                 case RIL_REQUEST_CHANGE_SIM_PIN:
2478                 case RIL_REQUEST_CHANGE_SIM_PIN2:
2479                 case RIL_REQUEST_SET_FACILITY_LOCK:
2480                     if (mIccStatusChangedRegistrants != null) {
2481                         if (RILJ_LOGD) {
2482                             riljLog("ON some errors fakeSimStatusChanged: reg count="
2483                                     + mIccStatusChangedRegistrants.size());
2484                         }
2485                         mIccStatusChangedRegistrants.notifyRegistrants();
2486                     }
2487                     break;
2488             }
2489
2490             rr.onError(error, ret);
2491         } else {
2492
2493             if (RILJ_LOGD) riljLog(rr.serialString() + "< " + requestToString(rr.mRequest)
2494                     + " " + retToString(rr.mRequest, ret));
2495
2496             if (rr.mResult != null) {
2497                 AsyncResult.forMessage(rr.mResult, ret, null);
2498                 rr.mResult.sendToTarget();
2499             }
2500         }
2501         return rr;
2502     }
2503
2504     private String
2505     retToString(int req, Object ret) {
2506         if (ret == null) return "";
2507         switch (req) {
2508             // Don't log these return values, for privacy's sake.
2509             case RIL_REQUEST_GET_IMSI:
2510             case RIL_REQUEST_GET_IMEI:
2511             case RIL_REQUEST_GET_IMEISV:
2512                 if (!RILJ_LOGV) {
2513                     // If not versbose logging just return and don't display IMSI and IMEI, IMEISV
2514                     return "";
2515                 }
2516         }
2517
2518         StringBuilder sb;
2519         String s;
2520         int length;
2521         if (ret instanceof int[]){
2522             int[] intArray = (int[]) ret;
2523             length = intArray.length;
2524             sb = new StringBuilder("{");
2525             if (length > 0) {
2526                 int i = 0;
2527                 sb.append(intArray[i++]);
2528                 while ( i < length) {
2529                     sb.append(", ").append(intArray[i++]);
2530                 }
2531             }
2532             sb.append("}");
2533             s = sb.toString();
2534         } else if (ret instanceof String[]) {
2535             String[] strings = (String[]) ret;
2536             length = strings.length;
2537             sb = new StringBuilder("{");
2538             if (length > 0) {
2539                 int i = 0;
2540                 sb.append(strings[i++]);
2541                 while ( i < length) {
2542                     sb.append(", ").append(strings[i++]);
2543                 }
2544             }
2545             sb.append("}");
2546             s = sb.toString();
2547         }else if (req == RIL_REQUEST_GET_CURRENT_CALLS) {
2548             ArrayList<DriverCall> calls = (ArrayList<DriverCall>) ret;
2549             sb = new StringBuilder(" ");
2550             for (DriverCall dc : calls) {
2551                 sb.append("[").append(dc).append("] ");
2552             }
2553             s = sb.toString();
2554         } else if (req == RIL_REQUEST_GET_NEIGHBORING_CELL_IDS) {
2555             ArrayList<NeighboringCellInfo> cells;
2556             cells = (ArrayList<NeighboringCellInfo>) ret;
2557             sb = new StringBuilder(" ");
2558             for (NeighboringCellInfo cell : cells) {
2559                 sb.append(cell).append(" ");
2560             }
2561             s = sb.toString();
2562         } else {
2563             s = ret.toString();
2564         }
2565         return s;
2566     }
2567
2568     private void
2569     processUnsolicited (Parcel p) {
2570         int response;
2571         Object ret;
2572
2573         response = p.readInt();
2574
2575         try {switch(response) {
2576 /*
2577  cat libs/telephony/ril_unsol_commands.h \
2578  | egrep "^ *{RIL_" \
2579  | sed -re 's/\{([^,]+),[^,]+,([^}]+).+/case \1: \2(rr, p); break;/'
2580 */
2581
2582             case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: ret =  responseVoid(p); break;
2583             case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: ret =  responseVoid(p); break;
2584             case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: ret =  responseVoid(p); break;
2585             case RIL_UNSOL_RESPONSE_NEW_SMS: ret =  responseString(p); break;
2586             case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: ret =  responseString(p); break;
2587             case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: ret =  responseInts(p); break;
2588             case RIL_UNSOL_ON_USSD: ret =  responseStrings(p); break;
2589             case RIL_UNSOL_NITZ_TIME_RECEIVED: ret =  responseString(p); break;
2590             case RIL_UNSOL_SIGNAL_STRENGTH: ret = responseSignalStrength(p); break;
2591             case RIL_UNSOL_DATA_CALL_LIST_CHANGED: ret = responseDataCallList(p);break;
2592             case RIL_UNSOL_SUPP_SVC_NOTIFICATION: ret = responseSuppServiceNotification(p); break;
2593             case RIL_UNSOL_STK_SESSION_END: ret = responseVoid(p); break;
2594             case RIL_UNSOL_STK_PROACTIVE_COMMAND: ret = responseString(p); break;
2595             case RIL_UNSOL_STK_EVENT_NOTIFY: ret = responseString(p); break;
2596             case RIL_UNSOL_STK_CALL_SETUP: ret = responseInts(p); break;
2597             case RIL_UNSOL_SIM_SMS_STORAGE_FULL: ret =  responseVoid(p); break;
2598             case RIL_UNSOL_SIM_REFRESH: ret =  responseSimRefresh(p); break;
2599             case RIL_UNSOL_CALL_RING: ret =  responseCallRing(p); break;
2600             case RIL_UNSOL_RESTRICTED_STATE_CHANGED: ret = responseInts(p); break;
2601             case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED:  ret =  responseVoid(p); break;
2602             case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS:  ret =  responseCdmaSms(p); break;
2603             case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS:  ret =  responseRaw(p); break;
2604             case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL:  ret =  responseVoid(p); break;
2605             case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: ret = responseVoid(p); break;
2606             case RIL_UNSOL_CDMA_CALL_WAITING: ret = responseCdmaCallWaiting(p); break;
2607             case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: ret = responseInts(p); break;
2608             case RIL_UNSOL_CDMA_INFO_REC: ret = responseCdmaInformationRecord(p); break;
2609             case RIL_UNSOL_OEM_HOOK_RAW: ret = responseRaw(p); break;
2610             case RIL_UNSOL_RINGBACK_TONE: ret = responseInts(p); break;
2611             case RIL_UNSOL_RESEND_INCALL_MUTE: ret = responseVoid(p); break;
2612             case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: ret = responseInts(p); break;
2613             case RIL_UNSOl_CDMA_PRL_CHANGED: ret = responseInts(p); break;
2614             case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: ret = responseVoid(p); break;
2615             case RIL_UNSOL_RIL_CONNECTED: ret = responseInts(p); break;
2616             case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: ret =  responseInts(p); break;
2617             case RIL_UNSOL_CELL_INFO_LIST: ret = responseCellInfoList(p); break;
2618             case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: ret =  responseVoid(p); break;
2619
2620             default:
2621                 throw new RuntimeException("Unrecognized unsol response: " + response);
2622             //break; (implied)
2623         }} catch (Throwable tr) {
2624             Rlog.e(RILJ_LOG_TAG, "Exception processing unsol response: " + response +
2625                 "Exception:" + tr.toString());
2626             return;
2627         }
2628
2629         switch(response) {
2630             case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
2631                 /* has bonus radio state int */
2632                 RadioState newState = getRadioStateFromInt(p.readInt());
2633                 if (RILJ_LOGD) unsljLogMore(response, newState.toString());
2634
2635                 switchToRadioState(newState);
2636             break;
2637             case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED:
2638                 if (RILJ_LOGD) unsljLog(response);
2639
2640                 mImsNetworkStateChangedRegistrants
2641                     .notifyRegistrants(new AsyncResult(null, null, null));
2642             break;
2643             case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED:
2644                 if (RILJ_LOGD) unsljLog(response);
2645
2646                 mCallStateRegistrants
2647                     .notifyRegistrants(new AsyncResult(null, null, null));
2648             break;
2649             case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED:
2650                 if (RILJ_LOGD) unsljLog(response);
2651
2652                 mVoiceNetworkStateRegistrants
2653                     .notifyRegistrants(new AsyncResult(null, null, null));
2654             break;
2655             case RIL_UNSOL_RESPONSE_NEW_SMS: {
2656                 if (RILJ_LOGD) unsljLog(response);
2657
2658                 // FIXME this should move up a layer
2659                 String a[] = new String[2];
2660
2661                 a[1] = (String)ret;
2662
2663                 SmsMessage sms;
2664
2665                 sms = SmsMessage.newFromCMT(a);
2666                 if (mGsmSmsRegistrant != null) {
2667                     mGsmSmsRegistrant
2668                         .notifyRegistrant(new AsyncResult(null, sms, null));
2669                 }
2670             break;
2671             }
2672             case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT:
2673                 if (RILJ_LOGD) unsljLogRet(response, ret);
2674
2675                 if (mSmsStatusRegistrant != null) {
2676                     mSmsStatusRegistrant.notifyRegistrant(
2677                             new AsyncResult(null, ret, null));
2678                 }
2679             break;
2680             case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM:
2681                 if (RILJ_LOGD) unsljLogRet(response, ret);
2682
2683                 int[] smsIndex = (int[])ret;
2684
2685                 if(smsIndex.length == 1) {
2686                     if (mSmsOnSimRegistrant != null) {
2687                         mSmsOnSimRegistrant.
2688                                 notifyRegistrant(new AsyncResult(null, smsIndex, null));
2689                     }
2690                 } else {
2691                     if (RILJ_LOGD) riljLog(" NEW_SMS_ON_SIM ERROR with wrong length "
2692                             + smsIndex.length);
2693                 }
2694             break;
2695             case RIL_UNSOL_ON_USSD:
2696                 String[] resp = (String[])ret;
2697
2698                 if (resp.length < 2) {
2699                     resp = new String[2];
2700                     resp[0] = ((String[])ret)[0];
2701                     resp[1] = null;
2702                 }
2703                 if (RILJ_LOGD) unsljLogMore(response, resp[0]);
2704                 if (mUSSDRegistrant != null) {
2705                     mUSSDRegistrant.notifyRegistrant(
2706                         new AsyncResult (null, resp, null));
2707                 }
2708             break;
2709             case RIL_UNSOL_NITZ_TIME_RECEIVED:
2710                 if (RILJ_LOGD) unsljLogRet(response, ret);
2711
2712                 // has bonus long containing milliseconds since boot that the NITZ
2713                 // time was received
2714                 long nitzReceiveTime = p.readLong();
2715
2716                 Object[] result = new Object[2];
2717
2718                 result[0] = ret;
2719                 result[1] = Long.valueOf(nitzReceiveTime);
2720
2721                 boolean ignoreNitz = SystemProperties.getBoolean(
2722                         TelephonyProperties.PROPERTY_IGNORE_NITZ, false);
2723
2724                 if (ignoreNitz) {
2725                     if (RILJ_LOGD) riljLog("ignoring UNSOL_NITZ_TIME_RECEIVED");
2726                 } else {
2727                     if (mNITZTimeRegistrant != null) {
2728
2729                         mNITZTimeRegistrant
2730                             .notifyRegistrant(new AsyncResult (null, result, null));
2731                     } else {
2732                         // in case NITZ time registrant isnt registered yet
2733                         mLastNITZTimeInfo = result;
2734                     }
2735                 }
2736             break;
2737
2738             case RIL_UNSOL_SIGNAL_STRENGTH:
2739                 // Note this is set to "verbose" because it happens
2740                 // frequently
2741                 if (RILJ_LOGV) unsljLogvRet(response, ret);
2742
2743                 if (mSignalStrengthRegistrant != null) {
2744                     mSignalStrengthRegistrant.notifyRegistrant(
2745                                         new AsyncResult (null, ret, null));
2746                 }
2747             break;
2748             case RIL_UNSOL_DATA_CALL_LIST_CHANGED:
2749                 if (RILJ_LOGD) unsljLogRet(response, ret);
2750
2751                 mDataNetworkStateRegistrants.notifyRegistrants(new AsyncResult(null, ret, null));
2752             break;
2753
2754             case RIL_UNSOL_SUPP_SVC_NOTIFICATION:
2755                 if (RILJ_LOGD) unsljLogRet(response, ret);
2756
2757                 if (mSsnRegistrant != null) {
2758                     mSsnRegistrant.notifyRegistrant(
2759                                         new AsyncResult (null, ret, null));
2760                 }
2761                 break;
2762
2763             case RIL_UNSOL_STK_SESSION_END:
2764                 if (RILJ_LOGD) unsljLog(response);
2765
2766                 if (mCatSessionEndRegistrant != null) {
2767                     mCatSessionEndRegistrant.notifyRegistrant(
2768                                         new AsyncResult (null, ret, null));
2769                 }
2770                 break;
2771
2772             case RIL_UNSOL_STK_PROACTIVE_COMMAND:
2773                 if (RILJ_LOGD) unsljLogRet(response, ret);
2774
2775                 if (mCatProCmdRegistrant != null) {
2776                     mCatProCmdRegistrant.notifyRegistrant(
2777                                         new AsyncResult (null, ret, null));
2778                 }
2779                 break;
2780
2781             case RIL_UNSOL_STK_EVENT_NOTIFY:
2782                 if (RILJ_LOGD) unsljLogRet(response, ret);
2783
2784                 if (mCatEventRegistrant != null) {
2785                     mCatEventRegistrant.notifyRegistrant(
2786                                         new AsyncResult (null, ret, null));
2787                 }
2788                 break;
2789
2790             case RIL_UNSOL_STK_CALL_SETUP:
2791                 if (RILJ_LOGD) unsljLogRet(response, ret);
2792
2793                 if (mCatCallSetUpRegistrant != null) {
2794                     mCatCallSetUpRegistrant.notifyRegistrant(
2795                                         new AsyncResult (null, ret, null));
2796                 }
2797                 break;
2798
2799             case RIL_UNSOL_SIM_SMS_STORAGE_FULL:
2800                 if (RILJ_LOGD) unsljLog(response);
2801
2802                 if (mIccSmsFullRegistrant != null) {
2803                     mIccSmsFullRegistrant.notifyRegistrant();
2804                 }
2805                 break;
2806
2807             case RIL_UNSOL_SIM_REFRESH:
2808                 if (RILJ_LOGD) unsljLogRet(response, ret);
2809
2810                 if (mIccRefreshRegistrants != null) {
2811                     mIccRefreshRegistrants.notifyRegistrants(
2812                             new AsyncResult (null, ret, null));
2813                 }
2814                 break;
2815
2816             case RIL_UNSOL_CALL_RING:
2817                 if (RILJ_LOGD) unsljLogRet(response, ret);
2818
2819                 if (mRingRegistrant != null) {
2820                     mRingRegistrant.notifyRegistrant(
2821                             new AsyncResult (null, ret, null));
2822                 }
2823                 break;
2824
2825             case RIL_UNSOL_RESTRICTED_STATE_CHANGED:
2826                 if (RILJ_LOGD) unsljLogvRet(response, ret);
2827                 if (mRestrictedStateRegistrant != null) {
2828                     mRestrictedStateRegistrant.notifyRegistrant(
2829                                         new AsyncResult (null, ret, null));
2830                 }
2831                 break;
2832
2833             case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED:
2834                 if (RILJ_LOGD) unsljLog(response);
2835
2836                 if (mIccStatusChangedRegistrants != null) {
2837                     mIccStatusChangedRegistrants.notifyRegistrants();
2838                 }
2839                 break;
2840
2841             case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS:
2842                 if (RILJ_LOGD) unsljLog(response);
2843
2844                 SmsMessage sms = (SmsMessage) ret;
2845
2846                 if (mCdmaSmsRegistrant != null) {
2847                     mCdmaSmsRegistrant
2848                         .notifyRegistrant(new AsyncResult(null, sms, null));
2849                 }
2850                 break;
2851
2852             case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS:
2853                 if (RILJ_LOGD) unsljLog(response);
2854
2855                 if (mGsmBroadcastSmsRegistrant != null) {
2856                     mGsmBroadcastSmsRegistrant
2857                         .notifyRegistrant(new AsyncResult(null, ret, null));
2858                 }
2859                 break;
2860
2861             case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL:
2862                 if (RILJ_LOGD) unsljLog(response);
2863
2864                 if (mIccSmsFullRegistrant != null) {
2865                     mIccSmsFullRegistrant.notifyRegistrant();
2866                 }
2867                 break;
2868
2869             case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE:
2870                 if (RILJ_LOGD) unsljLog(response);
2871
2872                 if (mEmergencyCallbackModeRegistrant != null) {
2873                     mEmergencyCallbackModeRegistrant.notifyRegistrant();
2874                 }
2875                 break;
2876
2877             case RIL_UNSOL_CDMA_CALL_WAITING:
2878                 if (RILJ_LOGD) unsljLogRet(response, ret);
2879
2880                 if (mCallWaitingInfoRegistrants != null) {
2881                     mCallWaitingInfoRegistrants.notifyRegistrants(
2882                                         new AsyncResult (null, ret, null));
2883                 }
2884                 break;
2885
2886             case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS:
2887                 if (RILJ_LOGD) unsljLogRet(response, ret);
2888
2889                 if (mOtaProvisionRegistrants != null) {
2890                     mOtaProvisionRegistrants.notifyRegistrants(
2891                                         new AsyncResult (null, ret, null));
2892                 }
2893                 break;
2894
2895             case RIL_UNSOL_CDMA_INFO_REC:
2896                 ArrayList<CdmaInformationRecords> listInfoRecs;
2897
2898                 try {
2899                     listInfoRecs = (ArrayList<CdmaInformationRecords>)ret;
2900                 } catch (ClassCastException e) {
2901                     Rlog.e(RILJ_LOG_TAG, "Unexpected exception casting to listInfoRecs", e);
2902                     break;
2903                 }
2904
2905                 for (CdmaInformationRecords rec : listInfoRecs) {
2906                     if (RILJ_LOGD) unsljLogRet(response, rec);
2907                     notifyRegistrantsCdmaInfoRec(rec);
2908                 }
2909                 break;
2910
2911             case RIL_UNSOL_OEM_HOOK_RAW:
2912                 if (RILJ_LOGD) unsljLogvRet(response, IccUtils.bytesToHexString((byte[])ret));
2913                 if (mUnsolOemHookRawRegistrant != null) {
2914                     mUnsolOemHookRawRegistrant.notifyRegistrant(new AsyncResult(null, ret, null));
2915                 }
2916                 break;
2917
2918             case RIL_UNSOL_RINGBACK_TONE:
2919                 if (RILJ_LOGD) unsljLogvRet(response, ret);
2920                 if (mRingbackToneRegistrants != null) {
2921                     boolean playtone = (((int[])ret)[0] == 1);
2922                     mRingbackToneRegistrants.notifyRegistrants(
2923                                         new AsyncResult (null, playtone, null));
2924                 }
2925                 break;
2926
2927             case RIL_UNSOL_RESEND_INCALL_MUTE:
2928                 if (RILJ_LOGD) unsljLogRet(response, ret);
2929
2930                 if (mResendIncallMuteRegistrants != null) {
2931                     mResendIncallMuteRegistrants.notifyRegistrants(
2932                                         new AsyncResult (null, ret, null));
2933                 }
2934                 break;
2935
2936             case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED:
2937                 if (RILJ_LOGD) unsljLogRet(response, ret);
2938
2939                 if (mVoiceRadioTechChangedRegistrants != null) {
2940                     mVoiceRadioTechChangedRegistrants.notifyRegistrants(
2941                             new AsyncResult(null, ret, null));
2942                 }
2943                 break;
2944
2945             case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED:
2946                 if (RILJ_LOGD) unsljLogRet(response, ret);
2947
2948                 if (mCdmaSubscriptionChangedRegistrants != null) {
2949                     mCdmaSubscriptionChangedRegistrants.notifyRegistrants(
2950                                         new AsyncResult (null, ret, null));
2951                 }
2952                 break;
2953
2954             case RIL_UNSOl_CDMA_PRL_CHANGED:
2955                 if (RILJ_LOGD) unsljLogRet(response, ret);
2956
2957                 if (mCdmaPrlChangedRegistrants != null) {
2958                     mCdmaPrlChangedRegistrants.notifyRegistrants(
2959                                         new AsyncResult (null, ret, null));
2960                 }
2961                 break;
2962
2963             case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE:
2964                 if (RILJ_LOGD) unsljLogRet(response, ret);
2965
2966                 if (mExitEmergencyCallbackModeRegistrants != null) {
2967                     mExitEmergencyCallbackModeRegistrants.notifyRegistrants(
2968                                         new AsyncResult (null, null, null));
2969                 }
2970                 break;
2971
2972             case RIL_UNSOL_RIL_CONNECTED: {
2973                 if (RILJ_LOGD) unsljLogRet(response, ret);
2974
2975                 // Initial conditions
2976                 setRadioPower(false, null);
2977                 setPreferredNetworkType(mPreferredNetworkType, null);
2978                 setCdmaSubscriptionSource(mCdmaSubscription, null);
2979                 setCellInfoListRate(Integer.MAX_VALUE, null);
2980                 notifyRegistrantsRilConnectionChanged(((int[])ret)[0]);
2981                 break;
2982             }
2983             case RIL_UNSOL_CELL_INFO_LIST: {
2984                 if (RILJ_LOGD) unsljLogRet(response, ret);
2985
2986                 if (mRilCellInfoListRegistrants != null) {
2987                     mRilCellInfoListRegistrants.notifyRegistrants(
2988                                         new AsyncResult (null, ret, null));
2989                 }
2990                 break;
2991             }
2992         }
2993     }
2994
2995     /**
2996      * Notifiy all registrants that the ril has connected or disconnected.
2997      *
2998      * @param rilVer is the version of the ril or -1 if disconnected.
2999      */
3000     private void notifyRegistrantsRilConnectionChanged(int rilVer) {
3001         mRilVersion = rilVer;
3002         if (mRilConnectedRegistrants != null) {
3003             mRilConnectedRegistrants.notifyRegistrants(
3004                                 new AsyncResult (null, new Integer(rilVer), null));
3005         }
3006     }
3007
3008     private Object
3009     responseInts(Parcel p) {
3010         int numInts;
3011         int response[];
3012
3013         numInts = p.readInt();
3014
3015         response = new int[numInts];
3016
3017         for (int i = 0 ; i < numInts ; i++) {
3018             response[i] = p.readInt();
3019         }
3020
3021         return response;
3022     }
3023
3024
3025     private Object
3026     responseVoid(Parcel p) {
3027         return null;
3028     }
3029
3030     private Object
3031     responseCallForward(Parcel p) {
3032         int numInfos;
3033         CallForwardInfo infos[];
3034
3035         numInfos = p.readInt();
3036
3037         infos = new CallForwardInfo[numInfos];
3038
3039         for (int i = 0 ; i < numInfos ; i++) {
3040             infos[i] = new CallForwardInfo();
3041
3042             infos[i].status = p.readInt();
3043             infos[i].reason = p.readInt();
3044             infos[i].serviceClass = p.readInt();
3045             infos[i].toa = p.readInt();
3046             infos[i].number = p.readString();
3047             infos[i].timeSeconds = p.readInt();
3048         }
3049
3050         return infos;
3051     }
3052
3053     private Object
3054     responseSuppServiceNotification(Parcel p) {
3055         SuppServiceNotification notification = new SuppServiceNotification();
3056
3057         notification.notificationType = p.readInt();
3058         notification.code = p.readInt();
3059         notification.index = p.readInt();
3060         notification.type = p.readInt();
3061         notification.number = p.readString();
3062
3063         return notification;
3064     }
3065
3066     private Object
3067     responseCdmaSms(Parcel p) {
3068         SmsMessage sms;
3069         sms = SmsMessage.newFromParcel(p);
3070
3071         return sms;
3072     }
3073
3074     private Object
3075     responseString(Parcel p) {
3076         String response;
3077
3078         response = p.readString();
3079
3080         return response;
3081     }
3082
3083     private Object
3084     responseStrings(Parcel p) {
3085         int num;
3086         String response[];
3087
3088         response = p.readStringArray();
3089
3090         return response;
3091     }
3092
3093     private Object
3094     responseRaw(Parcel p) {
3095         int num;
3096         byte response[];
3097
3098         response = p.createByteArray();
3099
3100         return response;
3101     }
3102
3103     private Object
3104     responseSMS(Parcel p) {
3105         int messageRef, errorCode;
3106         String ackPDU;
3107
3108         messageRef = p.readInt();
3109         ackPDU = p.readString();
3110         errorCode = p.readInt();
3111
3112         SmsResponse response = new SmsResponse(messageRef, ackPDU, errorCode);
3113
3114         return response;
3115     }
3116
3117
3118     private Object
3119     responseICC_IO(Parcel p) {
3120         int sw1, sw2;
3121         Message ret;
3122
3123         sw1 = p.readInt();
3124         sw2 = p.readInt();
3125
3126         String s = p.readString();
3127
3128         if (RILJ_LOGV) riljLog("< iccIO: "
3129                 + " 0x" + Integer.toHexString(sw1)
3130                 + " 0x" + Integer.toHexString(sw2) + " "
3131                 + s);
3132
3133         return new IccIoResult(sw1, sw2, s);
3134     }
3135
3136     private Object
3137     responseIccCardStatus(Parcel p) {
3138         IccCardApplicationStatus appStatus;
3139
3140         IccCardStatus cardStatus = new IccCardStatus();
3141         cardStatus.setCardState(p.readInt());
3142         cardStatus.setUniversalPinState(p.readInt());
3143         cardStatus.mGsmUmtsSubscriptionAppIndex = p.readInt();
3144         cardStatus.mCdmaSubscriptionAppIndex = p.readInt();
3145         cardStatus.mImsSubscriptionAppIndex = p.readInt();
3146         int numApplications = p.readInt();
3147
3148         // limit to maximum allowed applications
3149         if (numApplications > IccCardStatus.CARD_MAX_APPS) {
3150             numApplications = IccCardStatus.CARD_MAX_APPS;
3151         }
3152         cardStatus.mApplications = new IccCardApplicationStatus[numApplications];
3153         for (int i = 0 ; i < numApplications ; i++) {
3154             appStatus = new IccCardApplicationStatus();
3155             appStatus.app_type       = appStatus.AppTypeFromRILInt(p.readInt());
3156             appStatus.app_state      = appStatus.AppStateFromRILInt(p.readInt());
3157             appStatus.perso_substate = appStatus.PersoSubstateFromRILInt(p.readInt());
3158             appStatus.aid            = p.readString();
3159             appStatus.app_label      = p.readString();
3160             appStatus.pin1_replaced  = p.readInt();
3161             appStatus.pin1           = appStatus.PinStateFromRILInt(p.readInt());
3162             appStatus.pin2           = appStatus.PinStateFromRILInt(p.readInt());
3163             cardStatus.mApplications[i] = appStatus;
3164         }
3165         return cardStatus;
3166     }
3167
3168     private Object
3169     responseSimRefresh(Parcel p) {
3170         IccRefreshResponse response = new IccRefreshResponse();
3171
3172         response.refreshResult = p.readInt();
3173         response.efId   = p.readInt();
3174         response.aid = p.readString();
3175         return response;
3176     }
3177
3178     private Object
3179     responseCallList(Parcel p) {
3180         int num;
3181         int voiceSettings;
3182         ArrayList<DriverCall> response;
3183         DriverCall dc;
3184
3185         num = p.readInt();
3186         response = new ArrayList<DriverCall>(num);
3187
3188         if (RILJ_LOGV) {
3189             riljLog("responseCallList: num=" + num +
3190                     " mEmergencyCallbackModeRegistrant=" + mEmergencyCallbackModeRegistrant +
3191                     " mTestingEmergencyCall=" + mTestingEmergencyCall.get());
3192         }
3193         for (int i = 0 ; i < num ; i++) {
3194             dc = new DriverCall();
3195
3196             dc.state = DriverCall.stateFromCLCC(p.readInt());
3197             dc.index = p.readInt();
3198             dc.TOA = p.readInt();
3199             dc.isMpty = (0 != p.readInt());
3200             dc.isMT = (0 != p.readInt());
3201             dc.als = p.readInt();
3202             voiceSettings = p.readInt();
3203             dc.isVoice = (0 == voiceSettings) ? false : true;
3204             dc.isVoicePrivacy = (0 != p.readInt());
3205             dc.number = p.readString();
3206             int np = p.readInt();
3207             dc.numberPresentation = DriverCall.presentationFromCLIP(np);
3208             dc.name = p.readString();
3209             dc.namePresentation = p.readInt();
3210             int uusInfoPresent = p.readInt();
3211             if (uusInfoPresent == 1) {
3212                 dc.uusInfo = new UUSInfo();
3213                 dc.uusInfo.setType(p.readInt());
3214                 dc.uusInfo.setDcs(p.readInt());
3215                 byte[] userData = p.createByteArray();
3216                 dc.uusInfo.setUserData(userData);
3217                 riljLogv(String.format("Incoming UUS : type=%d, dcs=%d, length=%d",
3218                                 dc.uusInfo.getType(), dc.uusInfo.getDcs(),
3219                                 dc.uusInfo.getUserData().length));
3220                 riljLogv("Incoming UUS : data (string)="
3221                         + new String(dc.uusInfo.getUserData()));
3222                 riljLogv("Incoming UUS : data (hex): "
3223                         + IccUtils.bytesToHexString(dc.uusInfo.getUserData()));
3224             } else {
3225                 riljLogv("Incoming UUS : NOT present!");
3226             }
3227
3228             // Make sure there's a leading + on addresses with a TOA of 145
3229             dc.number = PhoneNumberUtils.stringFromStringAndTOA(dc.number, dc.TOA);
3230
3231             response.add(dc);
3232
3233             if (dc.isVoicePrivacy) {
3234                 mVoicePrivacyOnRegistrants.notifyRegistrants();
3235                 riljLog("InCall VoicePrivacy is enabled");
3236             } else {
3237                 mVoicePrivacyOffRegistrants.notifyRegistrants();
3238                 riljLog("InCall VoicePrivacy is disabled");
3239             }
3240         }
3241
3242         Collections.sort(response);
3243
3244         if ((num == 0) && mTestingEmergencyCall.getAndSet(false)) {
3245             if (mEmergencyCallbackModeRegistrant != null) {
3246                 riljLog("responseCallList: call ended, testing emergency call," +
3247                             " notify ECM Registrants");
3248                 mEmergencyCallbackModeRegistrant.notifyRegistrant();
3249             }
3250         }
3251
3252         return response;
3253     }
3254
3255     private DataCallResponse getDataCallResponse(Parcel p, int version) {
3256         DataCallResponse dataCall = new DataCallResponse();
3257
3258         dataCall.version = version;
3259         if (version < 5) {
3260             dataCall.cid = p.readInt();
3261             dataCall.active = p.readInt();
3262             dataCall.type = p.readString();
3263             String addresses = p.readString();
3264             if (!TextUtils.isEmpty(addresses)) {
3265                 dataCall.addresses = addresses.split(" ");
3266             }
3267         } else {
3268             dataCall.status = p.readInt();
3269             dataCall.suggestedRetryTime = p.readInt();
3270             dataCall.cid = p.readInt();
3271             dataCall.active = p.readInt();
3272             dataCall.type = p.readString();
3273             dataCall.ifname = p.readString();
3274             if ((dataCall.status == DcFailCause.NONE.getErrorCode()) &&
3275                     TextUtils.isEmpty(dataCall.ifname)) {
3276               throw new RuntimeException("getDataCallResponse, no ifname");
3277             }
3278             String addresses = p.readString();
3279             if (!TextUtils.isEmpty(addresses)) {
3280                 dataCall.addresses = addresses.split(" ");
3281             }
3282             String dnses = p.readString();
3283             if (!TextUtils.isEmpty(dnses)) {
3284                 dataCall.dnses = dnses.split(" ");
3285             }
3286             String gateways = p.readString();
3287             if (!TextUtils.isEmpty(gateways)) {
3288                 dataCall.gateways = gateways.split(" ");
3289             }
3290         }
3291         return dataCall;
3292     }
3293
3294     private Object
3295     responseDataCallList(Parcel p) {
3296         ArrayList<DataCallResponse> response;
3297
3298         int ver = p.readInt();
3299         int num = p.readInt();
3300         riljLog("responseDataCallList ver=" + ver + " num=" + num);
3301
3302         response = new ArrayList<DataCallResponse>(num);
3303         for (int i = 0; i < num; i++) {
3304             response.add(getDataCallResponse(p, ver));
3305         }
3306
3307         return response;
3308     }
3309
3310     private Object
3311     responseSetupDataCall(Parcel p) {
3312         int ver = p.readInt();
3313         int num = p.readInt();
3314         if (RILJ_LOGV) riljLog("responseSetupDataCall ver=" + ver + " num=" + num);
3315
3316         DataCallResponse dataCall;
3317
3318         if (ver < 5) {
3319             dataCall = new DataCallResponse();
3320             dataCall.version = ver;
3321             dataCall.cid = Integer.parseInt(p.readString());
3322             dataCall.ifname = p.readString();
3323             if (TextUtils.isEmpty(dataCall.ifname)) {
3324                 throw new RuntimeException(
3325                         "RIL_REQUEST_SETUP_DATA_CALL response, no ifname");
3326             }
3327             String addresses = p.readString();
3328             if (!TextUtils.isEmpty(addresses)) {
3329               dataCall.addresses = addresses.split(" ");
3330             }
3331             if (num >= 4) {
3332                 String dnses = p.readString();
3333                 if (RILJ_LOGD) riljLog("responseSetupDataCall got dnses=" + dnses);
3334                 if (!TextUtils.isEmpty(dnses)) {
3335                     dataCall.dnses = dnses.split(" ");
3336                 }
3337             }
3338             if (num >= 5) {
3339                 String gateways = p.readString();
3340                 if (RILJ_LOGD) riljLog("responseSetupDataCall got gateways=" + gateways);
3341                 if (!TextUtils.isEmpty(gateways)) {
3342                     dataCall.gateways = gateways.split(" ");
3343                 }
3344             }
3345         } else {
3346             if (num != 1) {
3347                 throw new RuntimeException(
3348                         "RIL_REQUEST_SETUP_DATA_CALL response expecting 1 RIL_Data_Call_response_v5"
3349                         + " got " + num);
3350             }
3351             dataCall = getDataCallResponse(p, ver);
3352         }
3353
3354         return dataCall;
3355     }
3356
3357     private Object
3358     responseOperatorInfos(Parcel p) {
3359         String strings[] = (String [])responseStrings(p);
3360         ArrayList<OperatorInfo> ret;
3361
3362         if (strings.length % 4 != 0) {
3363             throw new RuntimeException(
3364                 "RIL_REQUEST_QUERY_AVAILABLE_NETWORKS: invalid response. Got "
3365                 + strings.length + " strings, expected multible of 4");
3366         }
3367
3368         ret = new ArrayList<OperatorInfo>(strings.length / 4);
3369
3370         for (int i = 0 ; i < strings.length ; i += 4) {
3371             ret.add (
3372                 new OperatorInfo(
3373                     strings[i+0],
3374                     strings[i+1],
3375                     strings[i+2],
3376                     strings[i+3]));
3377         }
3378
3379         return ret;
3380     }
3381
3382     private Object
3383     responseCellList(Parcel p) {
3384        int num, rssi;
3385        String location;
3386        ArrayList<NeighboringCellInfo> response;
3387        NeighboringCellInfo cell;
3388
3389        num = p.readInt();
3390        response = new ArrayList<NeighboringCellInfo>();
3391
3392        // Determine the radio access type
3393        String radioString = SystemProperties.get(
3394                TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE, "unknown");
3395        int radioType;
3396        if (radioString.equals("GPRS")) {
3397            radioType = NETWORK_TYPE_GPRS;
3398        } else if (radioString.equals("EDGE")) {
3399            radioType = NETWORK_TYPE_EDGE;
3400        } else if (radioString.equals("UMTS")) {
3401            radioType = NETWORK_TYPE_UMTS;
3402        } else if (radioString.equals("HSDPA")) {
3403            radioType = NETWORK_TYPE_HSDPA;
3404        } else if (radioString.equals("HSUPA")) {
3405            radioType = NETWORK_TYPE_HSUPA;
3406        } else if (radioString.equals("HSPA")) {
3407            radioType = NETWORK_TYPE_HSPA;
3408        } else {
3409            radioType = NETWORK_TYPE_UNKNOWN;
3410        }
3411
3412        // Interpret the location based on radio access type
3413        if (radioType != NETWORK_TYPE_UNKNOWN) {
3414            for (int i = 0 ; i < num ; i++) {
3415                rssi = p.readInt();
3416                location = p.readString();
3417                cell = new NeighboringCellInfo(rssi, location, radioType);
3418                response.add(cell);
3419            }
3420        }
3421        return response;
3422     }
3423
3424     private Object responseGetPreferredNetworkType(Parcel p) {
3425        int [] response = (int[]) responseInts(p);
3426
3427        if (response.length >= 1) {
3428            // Since this is the response for getPreferredNetworkType
3429            // we'll assume that it should be the value we want the
3430            // vendor ril to take if we reestablish a connection to it.
3431            mPreferredNetworkType = response[0];
3432        }
3433        return response;
3434     }
3435
3436     private Object responseGmsBroadcastConfig(Parcel p) {
3437         int num;
3438         ArrayList<SmsBroadcastConfigInfo> response;
3439         SmsBroadcastConfigInfo info;
3440
3441         num = p.readInt();
3442         response = new ArrayList<SmsBroadcastConfigInfo>(num);
3443
3444         for (int i = 0; i < num; i++) {
3445             int fromId = p.readInt();
3446             int toId = p.readInt();
3447             int fromScheme = p.readInt();
3448             int toScheme = p.readInt();
3449             boolean selected = (p.readInt() == 1);
3450
3451             info = new SmsBroadcastConfigInfo(fromId, toId, fromScheme,
3452                     toScheme, selected);
3453             response.add(info);
3454         }
3455         return response;
3456     }
3457
3458     private Object
3459     responseCdmaBroadcastConfig(Parcel p) {
3460         int numServiceCategories;
3461         int response[];
3462
3463         numServiceCategories = p.readInt();
3464
3465         if (numServiceCategories == 0) {
3466             // TODO: The logic of providing default values should
3467             // not be done by this transport layer. And needs to
3468             // be done by the vendor ril or application logic.
3469             int numInts;
3470             numInts = CDMA_BROADCAST_SMS_NO_OF_SERVICE_CATEGORIES * CDMA_BSI_NO_OF_INTS_STRUCT + 1;
3471             response = new int[numInts];
3472
3473             // Faking a default record for all possible records.
3474             response[0] = CDMA_BROADCAST_SMS_NO_OF_SERVICE_CATEGORIES;
3475
3476             // Loop over CDMA_BROADCAST_SMS_NO_OF_SERVICE_CATEGORIES set 'english' as
3477             // default language and selection status to false for all.
3478             for (int i = 1; i < numInts; i += CDMA_BSI_NO_OF_INTS_STRUCT ) {
3479                 response[i + 0] = i / CDMA_BSI_NO_OF_INTS_STRUCT;
3480                 response[i + 1] = 1;
3481                 response[i + 2] = 0;
3482             }
3483         } else {
3484             int numInts;
3485             numInts = (numServiceCategories * CDMA_BSI_NO_OF_INTS_STRUCT) + 1;
3486             response = new int[numInts];
3487
3488             response[0] = numServiceCategories;
3489             for (int i = 1 ; i < numInts; i++) {
3490                  response[i] = p.readInt();
3491              }
3492         }
3493
3494         return response;
3495     }
3496
3497     private Object
3498     responseSignalStrength(Parcel p) {
3499         // Assume this is gsm, but doesn't matter as ServiceStateTracker
3500         // sets the proper value.
3501         SignalStrength signalStrength = SignalStrength.makeSignalStrengthFromRilParcel(p);
3502         return signalStrength;
3503     }
3504
3505     private ArrayList<CdmaInformationRecords>
3506     responseCdmaInformationRecord(Parcel p) {
3507         int numberOfInfoRecs;
3508         ArrayList<CdmaInformationRecords> response;
3509
3510         /**
3511          * Loop through all of the information records unmarshalling them
3512          * and converting them to Java Objects.
3513          */
3514         numberOfInfoRecs = p.readInt();
3515         response = new ArrayList<CdmaInformationRecords>(numberOfInfoRecs);
3516
3517         for (int i = 0; i < numberOfInfoRecs; i++) {
3518             CdmaInformationRecords InfoRec = new CdmaInformationRecords(p);
3519             response.add(InfoRec);
3520         }
3521
3522         return response;
3523     }
3524
3525     private Object
3526     responseCdmaCallWaiting(Parcel p) {
3527         CdmaCallWaitingNotification notification = new CdmaCallWaitingNotification();
3528
3529         notification.number = p.readString();
3530         notification.numberPresentation =
3531                 CdmaCallWaitingNotification.presentationFromCLIP(p.readInt());
3532         notification.name = p.readString();
3533         notification.namePresentation = notification.numberPresentation;
3534         notification.isPresent = p.readInt();
3535         notification.signalType = p.readInt();
3536         notification.alertPitch = p.readInt();
3537         notification.signal = p.readInt();
3538         notification.numberType = p.readInt();
3539         notification.numberPlan = p.readInt();
3540
3541         return notification;
3542     }
3543
3544     private Object
3545     responseCallRing(Parcel p){
3546         char response[] = new char[4];
3547
3548         response[0] = (char) p.readInt();    // isPresent
3549         response[1] = (char) p.readInt();    // signalType
3550         response[2] = (char) p.readInt();    // alertPitch
3551         response[3] = (char) p.readInt();    // signal
3552
3553         return response;
3554     }
3555
3556     private void
3557     notifyRegistrantsCdmaInfoRec(CdmaInformationRecords infoRec) {
3558         int response = RIL_UNSOL_CDMA_INFO_REC;
3559         if (infoRec.record instanceof CdmaInformationRecords.CdmaDisplayInfoRec) {
3560             if (mDisplayInfoRegistrants != null) {
3561                 if (RILJ_LOGD) unsljLogRet(response, infoRec.record);
3562                 mDisplayInfoRegistrants.notifyRegistrants(
3563                         new AsyncResult (null, infoRec.record, null));
3564             }
3565         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaSignalInfoRec) {
3566             if (mSignalInfoRegistrants != null) {
3567                 if (RILJ_LOGD) unsljLogRet(response, infoRec.record);
3568                 mSignalInfoRegistrants.notifyRegistrants(
3569                         new AsyncResult (null, infoRec.record, null));
3570             }
3571         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaNumberInfoRec) {
3572             if (mNumberInfoRegistrants != null) {
3573                 if (RILJ_LOGD) unsljLogRet(response, infoRec.record);
3574                 mNumberInfoRegistrants.notifyRegistrants(
3575                         new AsyncResult (null, infoRec.record, null));
3576             }
3577         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaRedirectingNumberInfoRec) {
3578             if (mRedirNumInfoRegistrants != null) {
3579                 if (RILJ_LOGD) unsljLogRet(response, infoRec.record);
3580                 mRedirNumInfoRegistrants.notifyRegistrants(
3581                         new AsyncResult (null, infoRec.record, null));
3582             }
3583         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaLineControlInfoRec) {
3584             if (mLineControlInfoRegistrants != null) {
3585                 if (RILJ_LOGD) unsljLogRet(response, infoRec.record);
3586                 mLineControlInfoRegistrants.notifyRegistrants(
3587                         new AsyncResult (null, infoRec.record, null));
3588             }
3589         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaT53ClirInfoRec) {
3590             if (mT53ClirInfoRegistrants != null) {
3591                 if (RILJ_LOGD) unsljLogRet(response, infoRec.record);
3592                 mT53ClirInfoRegistrants.notifyRegistrants(
3593                         new AsyncResult (null, infoRec.record, null));
3594             }
3595         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaT53AudioControlInfoRec) {
3596             if (mT53AudCntrlInfoRegistrants != null) {
3597                if (RILJ_LOGD) unsljLogRet(response, infoRec.record);
3598                mT53AudCntrlInfoRegistrants.notifyRegistrants(
3599                        new AsyncResult (null, infoRec.record, null));
3600             }
3601         }
3602     }
3603
3604     private ArrayList<CellInfo> responseCellInfoList(Parcel p) {
3605         int numberOfInfoRecs;
3606         ArrayList<CellInfo> response;
3607
3608         /**
3609          * Loop through all of the information records unmarshalling them
3610          * and converting them to Java Objects.
3611          */
3612         numberOfInfoRecs = p.readInt();
3613         response = new ArrayList<CellInfo>(numberOfInfoRecs);
3614
3615         for (int i = 0; i < numberOfInfoRecs; i++) {
3616             CellInfo InfoRec = CellInfo.CREATOR.createFromParcel(p);
3617             response.add(InfoRec);
3618         }
3619
3620         return response;
3621     }
3622
3623     static String
3624     requestToString(int request) {
3625 /*
3626  cat libs/telephony/ril_commands.h \
3627  | egrep "^ *{RIL_" \
3628  | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
3629 */
3630         switch(request) {
3631             case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
3632             case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
3633             case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
3634             case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
3635             case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
3636             case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
3637             case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
3638             case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
3639             case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
3640             case RIL_REQUEST_DIAL: return "DIAL";
3641             case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
3642             case RIL_REQUEST_HANGUP: return "HANGUP";
3643             case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
3644             case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
3645             case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
3646             case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
3647             case RIL_REQUEST_UDUB: return "UDUB";
3648             case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
3649             case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
3650             case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
3651             case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
3652             case RIL_REQUEST_OPERATOR: return "OPERATOR";
3653             case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
3654             case RIL_REQUEST_DTMF: return "DTMF";
3655             case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
3656             case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
3657             case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
3658             case RIL_REQUEST_SIM_IO: return "SIM_IO";
3659             case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
3660             case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
3661             case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
3662             case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
3663             case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
3664             case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
3665             case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
3666             case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
3667             case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
3668             case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
3669             case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
3670             case RIL_REQUEST_ANSWER: return "ANSWER";
3671             case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
3672             case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
3673             case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
3674             case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
3675             case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
3676             case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
3677             case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
3678             case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
3679             case RIL_REQUEST_DTMF_START: return "DTMF_START";
3680             case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
3681             case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
3682             case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
3683             case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
3684             case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
3685             case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
3686             case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
3687             case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
3688             case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
3689             case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
3690             case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
3691             case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
3692             case RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION: return "SET_SUPP_SVC_NOTIFICATION";
3693             case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM";
3694             case RIL_REQUEST_DELETE_SMS_ON_SIM: return "DELETE_SMS_ON_SIM";
3695             case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
3696             case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
3697             case RIL_REQUEST_STK_GET_PROFILE: return "REQUEST_STK_GET_PROFILE";
3698             case RIL_REQUEST_STK_SET_PROFILE: return "REQUEST_STK_SET_PROFILE";
3699             case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "REQUEST_STK_SEND_ENVELOPE_COMMAND";
3700             case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "REQUEST_STK_SEND_TERMINAL_RESPONSE";
3701             case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
3702             case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "REQUEST_EXPLICIT_CALL_TRANSFER";
3703             case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "REQUEST_SET_PREFERRED_NETWORK_TYPE";
3704             case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "REQUEST_GET_PREFERRED_NETWORK_TYPE";
3705             case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "REQUEST_GET_NEIGHBORING_CELL_IDS";
3706             case RIL_REQUEST_SET_LOCATION_UPDATES: return "REQUEST_SET_LOCATION_UPDATES";
3707             case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE: return "RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE";
3708             case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE: return "RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE";
3709             case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE: return "RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE";
3710             case RIL_REQUEST_SET_TTY_MODE: return "RIL_REQUEST_SET_TTY_MODE";
3711             case RIL_REQUEST_QUERY_TTY_MODE: return "RIL_REQUEST_QUERY_TTY_MODE";
3712             case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE: return "RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
3713             case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE: return "RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
3714             case RIL_REQUEST_CDMA_FLASH: return "RIL_REQUEST_CDMA_FLASH";
3715             case RIL_REQUEST_CDMA_BURST_DTMF: return "RIL_REQUEST_CDMA_BURST_DTMF";
3716             case RIL_REQUEST_CDMA_SEND_SMS: return "RIL_REQUEST_CDMA_SEND_SMS";
3717             case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE: return "RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE";
3718             case RIL_REQUEST_GSM_GET_BROADCAST_CONFIG: return "RIL_REQUEST_GSM_GET_BROADCAST_CONFIG";
3719             case RIL_REQUEST_GSM_SET_BROADCAST_CONFIG: return "RIL_REQUEST_GSM_SET_BROADCAST_CONFIG";
3720             case RIL_REQUEST_CDMA_GET_BROADCAST_CONFIG: return "RIL_REQUEST_CDMA_GET_BROADCAST_CONFIG";
3721             case RIL_REQUEST_CDMA_SET_BROADCAST_CONFIG: return "RIL_REQUEST_CDMA_SET_BROADCAST_CONFIG";
3722             case RIL_REQUEST_GSM_BROADCAST_ACTIVATION: return "RIL_REQUEST_GSM_BROADCAST_ACTIVATION";
3723             case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return "RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY";
3724             case RIL_REQUEST_CDMA_BROADCAST_ACTIVATION: return "RIL_REQUEST_CDMA_BROADCAST_ACTIVATION";
3725             case RIL_REQUEST_CDMA_SUBSCRIPTION: return "RIL_REQUEST_CDMA_SUBSCRIPTION";
3726             case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM";
3727             case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM";
3728             case RIL_REQUEST_DEVICE_IDENTITY: return "RIL_REQUEST_DEVICE_IDENTITY";
3729             case RIL_REQUEST_GET_SMSC_ADDRESS: return "RIL_REQUEST_GET_SMSC_ADDRESS";
3730             case RIL_REQUEST_SET_SMSC_ADDRESS: return "RIL_REQUEST_SET_SMSC_ADDRESS";
3731             case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "REQUEST_EXIT_EMERGENCY_CALLBACK_MODE";
3732             case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "RIL_REQUEST_REPORT_SMS_MEMORY_STATUS";
3733             case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING";
3734             case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE";
3735             case RIL_REQUEST_ISIM_AUTHENTICATION: return "RIL_REQUEST_ISIM_AUTHENTICATION";
3736             case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
3737             case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
3738             case RIL_REQUEST_VOICE_RADIO_TECH: return "RIL_REQUEST_VOICE_RADIO_TECH";
3739             case RIL_REQUEST_GET_CELL_INFO_LIST: return "RIL_REQUEST_GET_CELL_INFO_LIST";
3740             case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return "RIL_REQUEST_SET_CELL_INFO_LIST_RATE";
3741             case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
3742             case RIL_REQUEST_IMS_REGISTRATION_STATE: return "RIL_REQUEST_IMS_REGISTRATION_STATE";
3743             case RIL_REQUEST_IMS_SEND_SMS: return "RIL_REQUEST_IMS_SEND_SMS";
3744             default: return "<unknown request>";
3745         }
3746     }
3747
3748     static String
3749     responseToString(int request)
3750     {
3751 /*
3752  cat libs/telephony/ril_unsol_commands.h \
3753  | egrep "^ *{RIL_" \
3754  | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
3755 */
3756         switch(request) {
3757             case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
3758             case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
3759             case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
3760             case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
3761             case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
3762             case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
3763             case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
3764             case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST";
3765             case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
3766             case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
3767             case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
3768             case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
3769             case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
3770             case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
3771             case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
3772             case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
3773             case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FULL";
3774             case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
3775             case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
3776             case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
3777             case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_RESPONSE_CDMA_NEW_SMS";
3778             case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_RESPONSE_NEW_BROADCAST_SMS";
3779             case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
3780             case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
3781             case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
3782             case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
3783             case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
3784             case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
3785             case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
3786             case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
3787             case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
3788             case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "CDMA_SUBSCRIPTION_SOURCE_CHANGED";
3789             case RIL_UNSOl_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
3790             case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
3791             case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
3792             case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
3793             case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
3794             case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED:
3795                 return "UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED";
3796             default: return "<unknown response>";
3797         }
3798     }
3799
3800     private void riljLog(String msg) {
3801         Rlog.d(RILJ_LOG_TAG, msg);
3802     }
3803
3804     private void riljLogv(String msg) {
3805         Rlog.v(RILJ_LOG_TAG, msg);
3806     }
3807
3808     private void unsljLog(int response) {
3809         riljLog("[UNSL]< " + responseToString(response));
3810     }
3811
3812     private void unsljLogMore(int response, String more) {
3813         riljLog("[UNSL]< " + responseToString(response) + " " + more);
3814     }
3815
3816     private void unsljLogRet(int response, Object ret) {
3817         riljLog("[UNSL]< " + responseToString(response) + " " + retToString(response, ret));
3818     }
3819
3820     private void unsljLogvRet(int response, Object ret) {
3821         riljLogv("[UNSL]< " + responseToString(response) + " " + retToString(response, ret));
3822     }
3823
3824
3825     // ***** Methods for CDMA support
3826     @Override
3827     public void
3828     getDeviceIdentity(Message response) {
3829         RILRequest rr = RILRequest.obtain(RIL_REQUEST_DEVICE_IDENTITY, response);
3830
3831         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
3832
3833         send(rr);
3834     }
3835
3836     @Override
3837     public void
3838     getCDMASubscription(Message response) {
3839         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_SUBSCRIPTION, response);
3840
3841         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
3842
3843         send(rr);
3844     }
3845
3846     @Override
3847     public void setPhoneType(int phoneType) { // Called by CDMAPhone and GSMPhone constructor
3848         if (RILJ_LOGD) riljLog("setPhoneType=" + phoneType + " old value=" + mPhoneType);
3849         mPhoneType = phoneType;
3850     }
3851
3852     /**
3853      * {@inheritDoc}
3854      */
3855     @Override
3856     public void queryCdmaRoamingPreference(Message response) {
3857         RILRequest rr = RILRequest.obtain(
3858                 RILConstants.RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE, response);
3859
3860         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
3861
3862         send(rr);
3863     }
3864
3865     /**
3866      * {@inheritDoc}
3867      */
3868     @Override
3869     public void setCdmaRoamingPreference(int cdmaRoamingType, Message response) {
3870         RILRequest rr = RILRequest.obtain(
3871                 RILConstants.RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE, response);
3872
3873         rr.mParcel.writeInt(1);
3874         rr.mParcel.writeInt(cdmaRoamingType);
3875
3876         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
3877                 + " : " + cdmaRoamingType);
3878
3879         send(rr);
3880     }
3881
3882     /**
3883      * {@inheritDoc}
3884      */
3885     @Override
3886     public void setCdmaSubscriptionSource(int cdmaSubscription , Message response) {
3887         RILRequest rr = RILRequest.obtain(
3888                 RILConstants.RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE, response);
3889
3890         rr.mParcel.writeInt(1);
3891         rr.mParcel.writeInt(cdmaSubscription);
3892
3893         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
3894                 + " : " + cdmaSubscription);
3895
3896         send(rr);
3897     }
3898
3899     /**
3900      * {@inheritDoc}
3901      */
3902     @Override
3903     public void getCdmaSubscriptionSource(Message response) {
3904         RILRequest rr = RILRequest.obtain(
3905                 RILConstants.RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE, response);
3906
3907         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
3908
3909         send(rr);
3910     }
3911
3912     /**
3913      * {@inheritDoc}
3914      */
3915     @Override
3916     public void queryTTYMode(Message response) {
3917         RILRequest rr = RILRequest.obtain(
3918                 RILConstants.RIL_REQUEST_QUERY_TTY_MODE, response);
3919
3920         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
3921
3922         send(rr);
3923     }
3924
3925     /**
3926      * {@inheritDoc}
3927      */
3928     @Override
3929     public void setTTYMode(int ttyMode, Message response) {
3930         RILRequest rr = RILRequest.obtain(
3931                 RILConstants.RIL_REQUEST_SET_TTY_MODE, response);
3932
3933         rr.mParcel.writeInt(1);
3934         rr.mParcel.writeInt(ttyMode);
3935
3936         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
3937                 + " : " + ttyMode);
3938
3939         send(rr);
3940     }
3941
3942     /**
3943      * {@inheritDoc}
3944      */
3945     @Override
3946     public void
3947     sendCDMAFeatureCode(String FeatureCode, Message response) {
3948         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_FLASH, response);
3949
3950         rr.mParcel.writeString(FeatureCode);
3951
3952         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
3953                 + " : " + FeatureCode);
3954
3955         send(rr);
3956     }
3957
3958     @Override
3959     public void getCdmaBroadcastConfig(Message response) {
3960         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_GET_BROADCAST_CONFIG, response);
3961
3962         send(rr);
3963     }
3964
3965     @Override
3966     public void setCdmaBroadcastConfig(CdmaSmsBroadcastConfigInfo[] configs, Message response) {
3967         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_SET_BROADCAST_CONFIG, response);
3968
3969         // Convert to 1 service category per config (the way RIL takes is)
3970         ArrayList<CdmaSmsBroadcastConfigInfo> processedConfigs =
3971             new ArrayList<CdmaSmsBroadcastConfigInfo>();
3972         for (CdmaSmsBroadcastConfigInfo config : configs) {
3973             for (int i = config.getFromServiceCategory(); i <= config.getToServiceCategory(); i++) {
3974                 processedConfigs.add(new CdmaSmsBroadcastConfigInfo(i,
3975                         i,
3976                         config.getLanguage(),
3977                         config.isSelected()));
3978             }
3979         }
3980
3981         CdmaSmsBroadcastConfigInfo[] rilConfigs = processedConfigs.toArray(configs);
3982         rr.mParcel.writeInt(rilConfigs.length);
3983         for(int i = 0; i < rilConfigs.length; i++) {
3984             rr.mParcel.writeInt(rilConfigs[i].getFromServiceCategory());
3985             rr.mParcel.writeInt(rilConfigs[i].getLanguage());
3986             rr.mParcel.writeInt(rilConfigs[i].isSelected() ? 1 : 0);
3987         }
3988
3989         if (RILJ_LOGD) {
3990             riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
3991                     + " with " + rilConfigs.length + " configs : ");
3992             for (int i = 0; i < rilConfigs.length; i++) {
3993                 riljLog(rilConfigs[i].toString());
3994             }
3995         }
3996
3997         send(rr);
3998     }
3999
4000     @Override
4001     public void setCdmaBroadcastActivation(boolean activate, Message response) {
4002         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_BROADCAST_ACTIVATION, response);
4003
4004         rr.mParcel.writeInt(1);
4005         rr.mParcel.writeInt(activate ? 0 :1);
4006
4007         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4008
4009         send(rr);
4010     }
4011
4012     /**
4013      * {@inheritDoc}
4014      */
4015     @Override
4016     public void exitEmergencyCallbackMode(Message response) {
4017         RILRequest rr = RILRequest.obtain(RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE, response);
4018
4019         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4020
4021         send(rr);
4022     }
4023
4024     @Override
4025     public void requestIsimAuthentication(String nonce, Message response) {
4026         RILRequest rr = RILRequest.obtain(RIL_REQUEST_ISIM_AUTHENTICATION, response);
4027
4028         rr.mParcel.writeString(nonce);
4029
4030         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4031
4032         send(rr);
4033     }
4034
4035     /**
4036      * {@inheritDoc}
4037      */
4038     @Override
4039     public void getCellInfoList(Message result) {
4040         RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_CELL_INFO_LIST, result);
4041
4042         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4043
4044         send(rr);
4045     }
4046
4047     /**
4048      * {@inheritDoc}
4049      */
4050     @Override
4051     public void setCellInfoListRate(int rateInMillis, Message response) {
4052         if (RILJ_LOGD) riljLog("setCellInfoListRate: " + rateInMillis);
4053         RILRequest rr = RILRequest.obtain(RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE, response);
4054
4055         rr.mParcel.writeInt(1);
4056         rr.mParcel.writeInt(rateInMillis);
4057
4058         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4059
4060         send(rr);
4061     }
4062
4063     public void setInitialAttachApn(String apn, String protocol, int authType, String username,
4064             String password, Message result) {
4065         RILRequest rr = RILRequest.obtain(RIL_REQUEST_SET_INITIAL_ATTACH_APN, null);
4066
4067         if (RILJ_LOGD) riljLog("Set RIL_REQUEST_SET_INITIAL_ATTACH_APN");
4068
4069         rr.mParcel.writeString(apn);
4070         rr.mParcel.writeString(protocol);
4071         rr.mParcel.writeInt(authType);
4072         rr.mParcel.writeString(username);
4073         rr.mParcel.writeString(password);
4074
4075         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4076                 + ", apn:" + apn + ", protocol:" + protocol + ", authType:" + authType
4077                 + ", username:" + username + ", password:" + password);
4078
4079         send(rr);
4080     }
4081
4082     /* (non-Javadoc)
4083      * @see com.android.internal.telephony.BaseCommands#testingEmergencyCall()
4084      */
4085     @Override
4086     public void testingEmergencyCall() {
4087         if (RILJ_LOGD) riljLog("testingEmergencyCall");
4088         mTestingEmergencyCall.set(true);
4089     }
4090
4091     public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
4092         pw.println("RIL: " + this);
4093         pw.println(" mSocket=" + mSocket);
4094         pw.println(" mSenderThread=" + mSenderThread);
4095         pw.println(" mSender=" + mSender);
4096         pw.println(" mReceiverThread=" + mReceiverThread);
4097         pw.println(" mReceiver=" + mReceiver);
4098         pw.println(" mWakeLock=" + mWakeLock);
4099         pw.println(" mWakeLockTimeout=" + mWakeLockTimeout);
4100         synchronized (mRequestList) {
4101             synchronized (mWakeLock) {
4102                 pw.println(" mWakeLockCount=" + mWakeLockCount);
4103             }
4104             int count = mRequestList.size();
4105             pw.println(" mRequestList count=" + count);
4106             for (int i = 0; i < count; i++) {
4107                 RILRequest rr = mRequestList.valueAt(i);
4108                 pw.println("  [" + rr.mSerial + "] " + requestToString(rr.mRequest));
4109             }
4110         }
4111         pw.println(" mLastNITZTimeInfo=" + mLastNITZTimeInfo);
4112         pw.println(" mTestingEmergencyCall=" + mTestingEmergencyCall.get());
4113     }
4114 }