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