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