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