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