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