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