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