SubscriptionController uses RAT families to control default data
[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.SsData;
60 import com.android.internal.telephony.gsm.SuppServiceNotification;
61 import com.android.internal.telephony.uicc.IccCardApplicationStatus;
62 import com.android.internal.telephony.uicc.IccCardStatus;
63 import com.android.internal.telephony.uicc.IccIoResult;
64 import com.android.internal.telephony.uicc.IccRefreshResponse;
65 import com.android.internal.telephony.uicc.IccUtils;
66 import com.android.internal.telephony.uicc.SpnOverride;
67 import com.android.internal.telephony.cdma.CdmaCallWaitingNotification;
68 import com.android.internal.telephony.cdma.CdmaInformationRecords;
69 import com.android.internal.telephony.cdma.CdmaSmsBroadcastConfigInfo;
70 import com.android.internal.telephony.dataconnection.DcFailCause;
71 import com.android.internal.telephony.dataconnection.DataCallResponse;
72 import com.android.internal.telephony.dataconnection.DataProfile;
73 import com.android.internal.telephony.RadioCapability;
74 import com.android.internal.telephony.TelephonyDevController;
75 import com.android.internal.telephony.HardwareConfig;
76
77 import java.io.ByteArrayInputStream;
78 import java.io.DataInputStream;
79 import java.io.FileDescriptor;
80 import java.io.IOException;
81 import java.io.InputStream;
82 import java.io.PrintWriter;
83 import java.util.ArrayList;
84 import java.util.Collections;
85 import java.util.concurrent.atomic.AtomicBoolean;
86 import java.util.concurrent.atomic.AtomicInteger;
87 import java.util.Random;
88
89 /**
90  * {@hide}
91  */
92 class RILRequest {
93     static final String LOG_TAG = "RilRequest";
94
95     //***** Class Variables
96     static Random sRandom = new Random();
97     static AtomicInteger sNextSerial = new AtomicInteger(0);
98     private static Object sPoolSync = new Object();
99     private static RILRequest sPool = null;
100     private static int sPoolSize = 0;
101     private static final int MAX_POOL_SIZE = 4;
102     private Context mContext;
103
104     //***** Instance Variables
105     int mSerial;
106     int mRequest;
107     Message mResult;
108     Parcel mParcel;
109     RILRequest mNext;
110
111     /**
112      * Retrieves a new RILRequest instance from the pool.
113      *
114      * @param request RIL_REQUEST_*
115      * @param result sent when operation completes
116      * @return a RILRequest instance from the pool.
117      */
118     static RILRequest obtain(int request, Message result) {
119         RILRequest rr = null;
120
121         synchronized(sPoolSync) {
122             if (sPool != null) {
123                 rr = sPool;
124                 sPool = rr.mNext;
125                 rr.mNext = null;
126                 sPoolSize--;
127             }
128         }
129
130         if (rr == null) {
131             rr = new RILRequest();
132         }
133
134         rr.mSerial = sNextSerial.getAndIncrement();
135
136         rr.mRequest = request;
137         rr.mResult = result;
138         rr.mParcel = Parcel.obtain();
139
140         if (result != null && result.getTarget() == null) {
141             throw new NullPointerException("Message target must not be null");
142         }
143
144         // first elements in any RIL Parcel
145         rr.mParcel.writeInt(request);
146         rr.mParcel.writeInt(rr.mSerial);
147
148         return rr;
149     }
150
151     /**
152      * Returns a RILRequest instance to the pool.
153      *
154      * Note: This should only be called once per use.
155      */
156     void release() {
157         synchronized (sPoolSync) {
158             if (sPoolSize < MAX_POOL_SIZE) {
159                 mNext = sPool;
160                 sPool = this;
161                 sPoolSize++;
162                 mResult = null;
163             }
164         }
165     }
166
167     private RILRequest() {
168     }
169
170     static void
171     resetSerial() {
172         // use a random so that on recovery we probably don't mix old requests
173         // with new.
174         sNextSerial.set(sRandom.nextInt());
175     }
176
177     String
178     serialString() {
179         //Cheesy way to do %04d
180         StringBuilder sb = new StringBuilder(8);
181         String sn;
182
183         long adjustedSerial = (((long)mSerial) - Integer.MIN_VALUE)%10000;
184
185         sn = Long.toString(adjustedSerial);
186
187         //sb.append("J[");
188         sb.append('[');
189         for (int i = 0, s = sn.length() ; i < 4 - s; i++) {
190             sb.append('0');
191         }
192
193         sb.append(sn);
194         sb.append(']');
195         return sb.toString();
196     }
197
198     void
199     onError(int error, Object ret) {
200         CommandException ex;
201
202         ex = CommandException.fromRilErrno(error);
203
204         if (RIL.RILJ_LOGD) Rlog.d(LOG_TAG, serialString() + "< "
205             + RIL.requestToString(mRequest)
206             + " error: " + ex + " ret=" + RIL.retToString(mRequest, ret));
207
208         if (mResult != null) {
209             AsyncResult.forMessage(mResult, ret, ex);
210             mResult.sendToTarget();
211         }
212
213         if (mParcel != null) {
214             mParcel.recycle();
215             mParcel = null;
216         }
217     }
218 }
219
220
221 /**
222  * RIL implementation of the CommandsInterface.
223  *
224  * {@hide}
225  */
226 public final class RIL extends BaseCommands implements CommandsInterface {
227     static final String RILJ_LOG_TAG = "RILJ";
228     static final boolean RILJ_LOGD = true;
229     static final boolean RILJ_LOGV = false; // STOPSHIP if true
230
231     /**
232      * Wake lock timeout should be longer than the longest timeout in
233      * the vendor ril.
234      */
235     private static final int DEFAULT_WAKE_LOCK_TIMEOUT = 60000;
236
237     //***** Instance Variables
238
239     LocalSocket mSocket;
240     HandlerThread mSenderThread;
241     RILSender mSender;
242     Thread mReceiverThread;
243     RILReceiver mReceiver;
244     Display mDefaultDisplay;
245     int mDefaultDisplayState = Display.STATE_UNKNOWN;
246     WakeLock mWakeLock;
247     final int mWakeLockTimeout;
248     // The number of wakelock requests currently active.  Don't release the lock
249     // until dec'd to 0
250     int mWakeLockCount;
251
252     SparseArray<RILRequest> mRequestList = new SparseArray<RILRequest>();
253
254     Object     mLastNITZTimeInfo;
255
256     // When we are testing emergency calls
257     AtomicBoolean mTestingEmergencyCall = new AtomicBoolean(false);
258
259     private Integer mInstanceId;
260
261     //***** Events
262
263     static final int EVENT_SEND                 = 1;
264     static final int EVENT_WAKE_LOCK_TIMEOUT    = 2;
265
266     //***** Constants
267
268     // match with constant in ril.cpp
269     static final int RIL_MAX_COMMAND_BYTES = (8 * 1024);
270     static final int RESPONSE_SOLICITED = 0;
271     static final int RESPONSE_UNSOLICITED = 1;
272
273     static final String[] SOCKET_NAME_RIL = {"rild", "rild2", "rild3"};
274
275     static final int SOCKET_OPEN_RETRY_MILLIS = 4 * 1000;
276
277     // The number of the required config values for broadcast SMS stored in the C struct
278     // RIL_CDMA_BroadcastServiceInfo
279     private static final int CDMA_BSI_NO_OF_INTS_STRUCT = 3;
280
281     private static final int CDMA_BROADCAST_SMS_NO_OF_SERVICE_CATEGORIES = 31;
282
283     private final DisplayManager.DisplayListener mDisplayListener =
284             new DisplayManager.DisplayListener() {
285         @Override
286         public void onDisplayAdded(int displayId) { }
287
288         @Override
289         public void onDisplayRemoved(int displayId) { }
290
291         @Override
292         public void onDisplayChanged(int displayId) {
293             if (displayId == Display.DEFAULT_DISPLAY) {
294                 updateScreenState();
295             }
296         }
297     };
298
299     class RILSender extends Handler implements Runnable {
300         public RILSender(Looper looper) {
301             super(looper);
302         }
303
304         // Only allocated once
305         byte[] dataLength = new byte[4];
306
307         //***** Runnable implementation
308         @Override
309         public void
310         run() {
311             //setup if needed
312         }
313
314
315         //***** Handler implementation
316         @Override public void
317         handleMessage(Message msg) {
318             RILRequest rr = (RILRequest)(msg.obj);
319             RILRequest req = null;
320
321             switch (msg.what) {
322                 case EVENT_SEND:
323                     try {
324                         LocalSocket s;
325
326                         s = mSocket;
327
328                         if (s == null) {
329                             rr.onError(RADIO_NOT_AVAILABLE, null);
330                             rr.release();
331                             decrementWakeLock();
332                             return;
333                         }
334
335                         synchronized (mRequestList) {
336                             mRequestList.append(rr.mSerial, rr);
337                         }
338
339                         byte[] data;
340
341                         data = rr.mParcel.marshall();
342                         rr.mParcel.recycle();
343                         rr.mParcel = null;
344
345                         if (data.length > RIL_MAX_COMMAND_BYTES) {
346                             throw new RuntimeException(
347                                     "Parcel larger than max bytes allowed! "
348                                                           + data.length);
349                         }
350
351                         // parcel length in big endian
352                         dataLength[0] = dataLength[1] = 0;
353                         dataLength[2] = (byte)((data.length >> 8) & 0xff);
354                         dataLength[3] = (byte)((data.length) & 0xff);
355
356                         //Rlog.v(RILJ_LOG_TAG, "writing packet: " + data.length + " bytes");
357
358                         s.getOutputStream().write(dataLength);
359                         s.getOutputStream().write(data);
360                     } catch (IOException ex) {
361                         Rlog.e(RILJ_LOG_TAG, "IOException", ex);
362                         req = findAndRemoveRequestFromList(rr.mSerial);
363                         // make sure this request has not already been handled,
364                         // eg, if RILReceiver cleared the list.
365                         if (req != null) {
366                             rr.onError(RADIO_NOT_AVAILABLE, null);
367                             rr.release();
368                             decrementWakeLock();
369                         }
370                     } catch (RuntimeException exc) {
371                         Rlog.e(RILJ_LOG_TAG, "Uncaught exception ", exc);
372                         req = findAndRemoveRequestFromList(rr.mSerial);
373                         // make sure this request has not already been handled,
374                         // eg, if RILReceiver cleared the list.
375                         if (req != null) {
376                             rr.onError(GENERIC_FAILURE, null);
377                             rr.release();
378                             decrementWakeLock();
379                         }
380                     }
381
382                     break;
383
384                 case EVENT_WAKE_LOCK_TIMEOUT:
385                     // Haven't heard back from the last request.  Assume we're
386                     // not getting a response and  release the wake lock.
387
388                     // The timer of WAKE_LOCK_TIMEOUT is reset with each
389                     // new send request. So when WAKE_LOCK_TIMEOUT occurs
390                     // all requests in mRequestList already waited at
391                     // least DEFAULT_WAKE_LOCK_TIMEOUT but no response.
392                     //
393                     // Note: Keep mRequestList so that delayed response
394                     // can still be handled when response finally comes.
395
396                     synchronized (mRequestList) {
397                         if (clearWakeLock()) {
398                             if (RILJ_LOGD) {
399                                 int count = mRequestList.size();
400                                 Rlog.d(RILJ_LOG_TAG, "WAKE_LOCK_TIMEOUT " +
401                                         " mRequestList=" + count);
402                                 for (int i = 0; i < count; i++) {
403                                     rr = mRequestList.valueAt(i);
404                                     Rlog.d(RILJ_LOG_TAG, i + ": [" + rr.mSerial + "] "
405                                             + requestToString(rr.mRequest));
406                                 }
407                             }
408                         }
409                     }
410                     break;
411             }
412         }
413     }
414
415     /**
416      * Reads in a single RIL message off the wire. A RIL message consists
417      * of a 4-byte little-endian length and a subsequent series of bytes.
418      * The final message (length header omitted) is read into
419      * <code>buffer</code> and the length of the final message (less header)
420      * is returned. A return value of -1 indicates end-of-stream.
421      *
422      * @param is non-null; Stream to read from
423      * @param buffer Buffer to fill in. Must be as large as maximum
424      * message size, or an ArrayOutOfBounds exception will be thrown.
425      * @return Length of message less header, or -1 on end of stream.
426      * @throws IOException
427      */
428     private static int readRilMessage(InputStream is, byte[] buffer)
429             throws IOException {
430         int countRead;
431         int offset;
432         int remaining;
433         int messageLength;
434
435         // First, read in the length of the message
436         offset = 0;
437         remaining = 4;
438         do {
439             countRead = is.read(buffer, offset, remaining);
440
441             if (countRead < 0 ) {
442                 Rlog.e(RILJ_LOG_TAG, "Hit EOS reading message length");
443                 return -1;
444             }
445
446             offset += countRead;
447             remaining -= countRead;
448         } while (remaining > 0);
449
450         messageLength = ((buffer[0] & 0xff) << 24)
451                 | ((buffer[1] & 0xff) << 16)
452                 | ((buffer[2] & 0xff) << 8)
453                 | (buffer[3] & 0xff);
454
455         // Then, re-use the buffer and read in the message itself
456         offset = 0;
457         remaining = messageLength;
458         do {
459             countRead = is.read(buffer, offset, remaining);
460
461             if (countRead < 0 ) {
462                 Rlog.e(RILJ_LOG_TAG, "Hit EOS reading message.  messageLength=" + messageLength
463                         + " remaining=" + remaining);
464                 return -1;
465             }
466
467             offset += countRead;
468             remaining -= countRead;
469         } while (remaining > 0);
470
471         return messageLength;
472     }
473
474     class RILReceiver implements Runnable {
475         byte[] buffer;
476
477         RILReceiver() {
478             buffer = new byte[RIL_MAX_COMMAND_BYTES];
479         }
480
481         @Override
482         public void
483         run() {
484             int retryCount = 0;
485             String rilSocket = "rild";
486
487             try {for (;;) {
488                 LocalSocket s = null;
489                 LocalSocketAddress l;
490
491                 if (mInstanceId == null || mInstanceId == 0 ) {
492                     rilSocket = SOCKET_NAME_RIL[0];
493                 } else {
494                     rilSocket = SOCKET_NAME_RIL[mInstanceId];
495                 }
496
497                 try {
498                     s = new LocalSocket();
499                     l = new LocalSocketAddress(rilSocket,
500                             LocalSocketAddress.Namespace.RESERVED);
501                     s.connect(l);
502                 } catch (IOException ex){
503                     try {
504                         if (s != null) {
505                             s.close();
506                         }
507                     } catch (IOException ex2) {
508                         //ignore failure to close after failure to connect
509                     }
510
511                     // don't print an error message after the the first time
512                     // or after the 8th time
513
514                     if (retryCount == 8) {
515                         Rlog.e (RILJ_LOG_TAG,
516                             "Couldn't find '" + rilSocket
517                             + "' socket after " + retryCount
518                             + " times, continuing to retry silently");
519                     } else if (retryCount >= 0 && retryCount < 8) {
520                         Rlog.i (RILJ_LOG_TAG,
521                             "Couldn't find '" + rilSocket
522                             + "' socket; retrying after timeout");
523                     }
524
525                     try {
526                         Thread.sleep(SOCKET_OPEN_RETRY_MILLIS);
527                     } catch (InterruptedException er) {
528                     }
529
530                     retryCount++;
531                     continue;
532                 }
533
534                 retryCount = 0;
535
536                 mSocket = s;
537                 Rlog.i(RILJ_LOG_TAG, "(" + mInstanceId + ") Connected to '"
538                         + rilSocket + "' socket");
539
540                 int length = 0;
541                 try {
542                     InputStream is = mSocket.getInputStream();
543
544                     for (;;) {
545                         Parcel p;
546
547                         length = readRilMessage(is, buffer);
548
549                         if (length < 0) {
550                             // End-of-stream reached
551                             break;
552                         }
553
554                         p = Parcel.obtain();
555                         p.unmarshall(buffer, 0, length);
556                         p.setDataPosition(0);
557
558                         //Rlog.v(RILJ_LOG_TAG, "Read packet: " + length + " bytes");
559
560                         processResponse(p);
561                         p.recycle();
562                     }
563                 } catch (java.io.IOException ex) {
564                     Rlog.i(RILJ_LOG_TAG, "'" + rilSocket + "' socket closed",
565                           ex);
566                 } catch (Throwable tr) {
567                     Rlog.e(RILJ_LOG_TAG, "Uncaught exception read length=" + length +
568                         "Exception:" + tr.toString());
569                 }
570
571                 Rlog.i(RILJ_LOG_TAG, "(" + mInstanceId + ") Disconnected from '" + rilSocket
572                       + "' socket");
573
574                 setRadioState (RadioState.RADIO_UNAVAILABLE);
575
576                 try {
577                     mSocket.close();
578                 } catch (IOException ex) {
579                 }
580
581                 mSocket = null;
582                 RILRequest.resetSerial();
583
584                 // Clear request list on close
585                 clearRequestList(RADIO_NOT_AVAILABLE, false);
586             }} catch (Throwable tr) {
587                 Rlog.e(RILJ_LOG_TAG,"Uncaught exception", tr);
588             }
589
590             /* We're disconnected so we don't know the ril version */
591             notifyRegistrantsRilConnectionChanged(-1);
592         }
593     }
594
595
596
597     //***** Constructors
598
599     public RIL(Context context, int preferredNetworkType, int cdmaSubscription) {
600         this(context, preferredNetworkType, cdmaSubscription, null);
601     }
602
603     public RIL(Context context, int preferredNetworkType,
604             int cdmaSubscription, Integer instanceId) {
605         super(context);
606         if (RILJ_LOGD) {
607             riljLog("RIL(context, preferredNetworkType=" + preferredNetworkType +
608                     " cdmaSubscription=" + cdmaSubscription + ")");
609         }
610
611         mContext = context;
612         mCdmaSubscription  = cdmaSubscription;
613         mPreferredNetworkType = preferredNetworkType;
614         mPhoneType = RILConstants.NO_PHONE;
615         mInstanceId = instanceId;
616
617         PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
618         mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, RILJ_LOG_TAG);
619         mWakeLock.setReferenceCounted(false);
620         mWakeLockTimeout = SystemProperties.getInt(TelephonyProperties.PROPERTY_WAKE_LOCK_TIMEOUT,
621                 DEFAULT_WAKE_LOCK_TIMEOUT);
622         mWakeLockCount = 0;
623
624         mSenderThread = new HandlerThread("RILSender" + mInstanceId);
625         mSenderThread.start();
626
627         Looper looper = mSenderThread.getLooper();
628         mSender = new RILSender(looper);
629
630         ConnectivityManager cm = (ConnectivityManager)context.getSystemService(
631                 Context.CONNECTIVITY_SERVICE);
632         if (cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE) == false) {
633             riljLog("Not starting RILReceiver: wifi-only");
634         } else {
635             riljLog("Starting RILReceiver" + mInstanceId);
636             mReceiver = new RILReceiver();
637             mReceiverThread = new Thread(mReceiver, "RILReceiver" + mInstanceId);
638             mReceiverThread.start();
639
640             DisplayManager dm = (DisplayManager)context.getSystemService(
641                     Context.DISPLAY_SERVICE);
642             mDefaultDisplay = dm.getDisplay(Display.DEFAULT_DISPLAY);
643             dm.registerDisplayListener(mDisplayListener, null);
644         }
645
646         TelephonyDevController tdc = TelephonyDevController.getInstance();
647         tdc.registerRIL(this);
648     }
649
650     //***** CommandsInterface implementation
651
652     @Override
653     public void getVoiceRadioTechnology(Message result) {
654         RILRequest rr = RILRequest.obtain(RIL_REQUEST_VOICE_RADIO_TECH, result);
655
656         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
657
658         send(rr);
659     }
660
661
662     public void getImsRegistrationState(Message result) {
663         RILRequest rr = RILRequest.obtain(RIL_REQUEST_IMS_REGISTRATION_STATE, result);
664
665         if (RILJ_LOGD) {
666             riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
667         }
668         send(rr);
669     }
670
671     @Override public void
672     setOnNITZTime(Handler h, int what, Object obj) {
673         super.setOnNITZTime(h, what, obj);
674
675         // Send the last NITZ time if we have it
676         if (mLastNITZTimeInfo != null) {
677             mNITZTimeRegistrant
678                 .notifyRegistrant(
679                     new AsyncResult (null, 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             case RIL_UNSOL_ON_SS: ret =  responseSsData(p); break;
2761             case RIL_UNSOL_STK_CC_ALPHA_NOTIFY: ret =  responseString(p); break;
2762
2763             default:
2764                 throw new RuntimeException("Unrecognized unsol response: " + response);
2765             //break; (implied)
2766         }} catch (Throwable tr) {
2767             Rlog.e(RILJ_LOG_TAG, "Exception processing unsol response: " + response +
2768                 "Exception:" + tr.toString());
2769             return;
2770         }
2771
2772         switch(response) {
2773             case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
2774                 /* has bonus radio state int */
2775                 RadioState newState = getRadioStateFromInt(p.readInt());
2776                 if (RILJ_LOGD) unsljLogMore(response, newState.toString());
2777
2778                 switchToRadioState(newState);
2779             break;
2780             case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED:
2781                 if (RILJ_LOGD) unsljLog(response);
2782
2783                 mImsNetworkStateChangedRegistrants
2784                     .notifyRegistrants(new AsyncResult(null, null, null));
2785             break;
2786             case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED:
2787                 if (RILJ_LOGD) unsljLog(response);
2788
2789                 mCallStateRegistrants
2790                     .notifyRegistrants(new AsyncResult(null, null, null));
2791             break;
2792             case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED:
2793                 if (RILJ_LOGD) unsljLog(response);
2794
2795                 mVoiceNetworkStateRegistrants
2796                     .notifyRegistrants(new AsyncResult(null, null, null));
2797             break;
2798             case RIL_UNSOL_RESPONSE_NEW_SMS: {
2799                 if (RILJ_LOGD) unsljLog(response);
2800
2801                 // FIXME this should move up a layer
2802                 String a[] = new String[2];
2803
2804                 a[1] = (String)ret;
2805
2806                 SmsMessage sms;
2807
2808                 sms = SmsMessage.newFromCMT(a);
2809                 if (mGsmSmsRegistrant != null) {
2810                     mGsmSmsRegistrant
2811                         .notifyRegistrant(new AsyncResult(null, sms, null));
2812                 }
2813             break;
2814             }
2815             case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT:
2816                 if (RILJ_LOGD) unsljLogRet(response, ret);
2817
2818                 if (mSmsStatusRegistrant != null) {
2819                     mSmsStatusRegistrant.notifyRegistrant(
2820                             new AsyncResult(null, ret, null));
2821                 }
2822             break;
2823             case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM:
2824                 if (RILJ_LOGD) unsljLogRet(response, ret);
2825
2826                 int[] smsIndex = (int[])ret;
2827
2828                 if(smsIndex.length == 1) {
2829                     if (mSmsOnSimRegistrant != null) {
2830                         mSmsOnSimRegistrant.
2831                                 notifyRegistrant(new AsyncResult(null, smsIndex, null));
2832                     }
2833                 } else {
2834                     if (RILJ_LOGD) riljLog(" NEW_SMS_ON_SIM ERROR with wrong length "
2835                             + smsIndex.length);
2836                 }
2837             break;
2838             case RIL_UNSOL_ON_USSD:
2839                 String[] resp = (String[])ret;
2840
2841                 if (resp.length < 2) {
2842                     resp = new String[2];
2843                     resp[0] = ((String[])ret)[0];
2844                     resp[1] = null;
2845                 }
2846                 if (RILJ_LOGD) unsljLogMore(response, resp[0]);
2847                 if (mUSSDRegistrant != null) {
2848                     mUSSDRegistrant.notifyRegistrant(
2849                         new AsyncResult (null, resp, null));
2850                 }
2851             break;
2852             case RIL_UNSOL_NITZ_TIME_RECEIVED:
2853                 if (RILJ_LOGD) unsljLogRet(response, ret);
2854
2855                 // has bonus long containing milliseconds since boot that the NITZ
2856                 // time was received
2857                 long nitzReceiveTime = p.readLong();
2858
2859                 Object[] result = new Object[2];
2860
2861                 result[0] = ret;
2862                 result[1] = Long.valueOf(nitzReceiveTime);
2863
2864                 boolean ignoreNitz = SystemProperties.getBoolean(
2865                         TelephonyProperties.PROPERTY_IGNORE_NITZ, false);
2866
2867                 if (ignoreNitz) {
2868                     if (RILJ_LOGD) riljLog("ignoring UNSOL_NITZ_TIME_RECEIVED");
2869                 } else {
2870                     if (mNITZTimeRegistrant != null) {
2871
2872                         mNITZTimeRegistrant
2873                             .notifyRegistrant(new AsyncResult (null, result, null));
2874                     }
2875                     // in case NITZ time registrant isn't registered yet, or a new registrant
2876                     // registers later
2877                     mLastNITZTimeInfo = result;
2878                 }
2879             break;
2880
2881             case RIL_UNSOL_SIGNAL_STRENGTH:
2882                 // Note this is set to "verbose" because it happens
2883                 // frequently
2884                 if (RILJ_LOGV) unsljLogvRet(response, ret);
2885
2886                 if (mSignalStrengthRegistrant != null) {
2887                     mSignalStrengthRegistrant.notifyRegistrant(
2888                                         new AsyncResult (null, ret, null));
2889                 }
2890             break;
2891             case RIL_UNSOL_DATA_CALL_LIST_CHANGED:
2892                 if (RILJ_LOGD) unsljLogRet(response, ret);
2893
2894                 mDataNetworkStateRegistrants.notifyRegistrants(new AsyncResult(null, ret, null));
2895             break;
2896
2897             case RIL_UNSOL_SUPP_SVC_NOTIFICATION:
2898                 if (RILJ_LOGD) unsljLogRet(response, ret);
2899
2900                 if (mSsnRegistrant != null) {
2901                     mSsnRegistrant.notifyRegistrant(
2902                                         new AsyncResult (null, ret, null));
2903                 }
2904                 break;
2905
2906             case RIL_UNSOL_STK_SESSION_END:
2907                 if (RILJ_LOGD) unsljLog(response);
2908
2909                 if (mCatSessionEndRegistrant != null) {
2910                     mCatSessionEndRegistrant.notifyRegistrant(
2911                                         new AsyncResult (null, ret, null));
2912                 }
2913                 break;
2914
2915             case RIL_UNSOL_STK_PROACTIVE_COMMAND:
2916                 if (RILJ_LOGD) unsljLog(response);
2917
2918                 if (mCatProCmdRegistrant != null) {
2919                     mCatProCmdRegistrant.notifyRegistrant(
2920                                         new AsyncResult (null, ret, null));
2921                 }
2922                 break;
2923
2924             case RIL_UNSOL_STK_EVENT_NOTIFY:
2925                 if (RILJ_LOGD) unsljLog(response);
2926
2927                 if (mCatEventRegistrant != null) {
2928                     mCatEventRegistrant.notifyRegistrant(
2929                                         new AsyncResult (null, ret, null));
2930                 }
2931                 break;
2932
2933             case RIL_UNSOL_STK_CALL_SETUP:
2934                 if (RILJ_LOGD) unsljLogRet(response, ret);
2935
2936                 if (mCatCallSetUpRegistrant != null) {
2937                     mCatCallSetUpRegistrant.notifyRegistrant(
2938                                         new AsyncResult (null, ret, null));
2939                 }
2940                 break;
2941
2942             case RIL_UNSOL_SIM_SMS_STORAGE_FULL:
2943                 if (RILJ_LOGD) unsljLog(response);
2944
2945                 if (mIccSmsFullRegistrant != null) {
2946                     mIccSmsFullRegistrant.notifyRegistrant();
2947                 }
2948                 break;
2949
2950             case RIL_UNSOL_SIM_REFRESH:
2951                 if (RILJ_LOGD) unsljLogRet(response, ret);
2952
2953                 if (mIccRefreshRegistrants != null) {
2954                     mIccRefreshRegistrants.notifyRegistrants(
2955                             new AsyncResult (null, ret, null));
2956                 }
2957                 break;
2958
2959             case RIL_UNSOL_CALL_RING:
2960                 if (RILJ_LOGD) unsljLogRet(response, ret);
2961
2962                 if (mRingRegistrant != null) {
2963                     mRingRegistrant.notifyRegistrant(
2964                             new AsyncResult (null, ret, null));
2965                 }
2966                 break;
2967
2968             case RIL_UNSOL_RESTRICTED_STATE_CHANGED:
2969                 if (RILJ_LOGD) unsljLogvRet(response, ret);
2970                 if (mRestrictedStateRegistrant != null) {
2971                     mRestrictedStateRegistrant.notifyRegistrant(
2972                                         new AsyncResult (null, ret, null));
2973                 }
2974                 break;
2975
2976             case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED:
2977                 if (RILJ_LOGD) unsljLog(response);
2978
2979                 if (mIccStatusChangedRegistrants != null) {
2980                     mIccStatusChangedRegistrants.notifyRegistrants();
2981                 }
2982                 break;
2983
2984             case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS:
2985                 if (RILJ_LOGD) unsljLog(response);
2986
2987                 SmsMessage sms = (SmsMessage) ret;
2988
2989                 if (mCdmaSmsRegistrant != null) {
2990                     mCdmaSmsRegistrant
2991                         .notifyRegistrant(new AsyncResult(null, sms, null));
2992                 }
2993                 break;
2994
2995             case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS:
2996                 if (RILJ_LOGD) unsljLogvRet(response, IccUtils.bytesToHexString((byte[])ret));
2997
2998                 if (mGsmBroadcastSmsRegistrant != null) {
2999                     mGsmBroadcastSmsRegistrant
3000                         .notifyRegistrant(new AsyncResult(null, ret, null));
3001                 }
3002                 break;
3003
3004             case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL:
3005                 if (RILJ_LOGD) unsljLog(response);
3006
3007                 if (mIccSmsFullRegistrant != null) {
3008                     mIccSmsFullRegistrant.notifyRegistrant();
3009                 }
3010                 break;
3011
3012             case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE:
3013                 if (RILJ_LOGD) unsljLog(response);
3014
3015                 if (mEmergencyCallbackModeRegistrant != null) {
3016                     mEmergencyCallbackModeRegistrant.notifyRegistrant();
3017                 }
3018                 break;
3019
3020             case RIL_UNSOL_CDMA_CALL_WAITING:
3021                 if (RILJ_LOGD) unsljLogRet(response, ret);
3022
3023                 if (mCallWaitingInfoRegistrants != null) {
3024                     mCallWaitingInfoRegistrants.notifyRegistrants(
3025                                         new AsyncResult (null, ret, null));
3026                 }
3027                 break;
3028
3029             case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS:
3030                 if (RILJ_LOGD) unsljLogRet(response, ret);
3031
3032                 if (mOtaProvisionRegistrants != null) {
3033                     mOtaProvisionRegistrants.notifyRegistrants(
3034                                         new AsyncResult (null, ret, null));
3035                 }
3036                 break;
3037
3038             case RIL_UNSOL_CDMA_INFO_REC:
3039                 ArrayList<CdmaInformationRecords> listInfoRecs;
3040
3041                 try {
3042                     listInfoRecs = (ArrayList<CdmaInformationRecords>)ret;
3043                 } catch (ClassCastException e) {
3044                     Rlog.e(RILJ_LOG_TAG, "Unexpected exception casting to listInfoRecs", e);
3045                     break;
3046                 }
3047
3048                 for (CdmaInformationRecords rec : listInfoRecs) {
3049                     if (RILJ_LOGD) unsljLogRet(response, rec);
3050                     notifyRegistrantsCdmaInfoRec(rec);
3051                 }
3052                 break;
3053
3054             case RIL_UNSOL_OEM_HOOK_RAW:
3055                 if (RILJ_LOGD) unsljLogvRet(response, IccUtils.bytesToHexString((byte[])ret));
3056                 if (mUnsolOemHookRawRegistrant != null) {
3057                     mUnsolOemHookRawRegistrant.notifyRegistrant(new AsyncResult(null, ret, null));
3058                 }
3059                 break;
3060
3061             case RIL_UNSOL_RINGBACK_TONE:
3062                 if (RILJ_LOGD) unsljLogvRet(response, ret);
3063                 if (mRingbackToneRegistrants != null) {
3064                     boolean playtone = (((int[])ret)[0] == 1);
3065                     mRingbackToneRegistrants.notifyRegistrants(
3066                                         new AsyncResult (null, playtone, null));
3067                 }
3068                 break;
3069
3070             case RIL_UNSOL_RESEND_INCALL_MUTE:
3071                 if (RILJ_LOGD) unsljLogRet(response, ret);
3072
3073                 if (mResendIncallMuteRegistrants != null) {
3074                     mResendIncallMuteRegistrants.notifyRegistrants(
3075                                         new AsyncResult (null, ret, null));
3076                 }
3077                 break;
3078
3079             case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED:
3080                 if (RILJ_LOGD) unsljLogRet(response, ret);
3081
3082                 if (mVoiceRadioTechChangedRegistrants != null) {
3083                     mVoiceRadioTechChangedRegistrants.notifyRegistrants(
3084                             new AsyncResult(null, ret, null));
3085                 }
3086                 break;
3087
3088             case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED:
3089                 if (RILJ_LOGD) unsljLogRet(response, ret);
3090
3091                 if (mCdmaSubscriptionChangedRegistrants != null) {
3092                     mCdmaSubscriptionChangedRegistrants.notifyRegistrants(
3093                                         new AsyncResult (null, ret, null));
3094                 }
3095                 break;
3096
3097             case RIL_UNSOl_CDMA_PRL_CHANGED:
3098                 if (RILJ_LOGD) unsljLogRet(response, ret);
3099
3100                 if (mCdmaPrlChangedRegistrants != null) {
3101                     mCdmaPrlChangedRegistrants.notifyRegistrants(
3102                                         new AsyncResult (null, ret, null));
3103                 }
3104                 break;
3105
3106             case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE:
3107                 if (RILJ_LOGD) unsljLogRet(response, ret);
3108
3109                 if (mExitEmergencyCallbackModeRegistrants != null) {
3110                     mExitEmergencyCallbackModeRegistrants.notifyRegistrants(
3111                                         new AsyncResult (null, null, null));
3112                 }
3113                 break;
3114
3115             case RIL_UNSOL_RIL_CONNECTED: {
3116                 if (RILJ_LOGD) unsljLogRet(response, ret);
3117
3118                 // Initial conditions
3119                 setRadioPower(false, null);
3120                 setPreferredNetworkType(mPreferredNetworkType, null);
3121                 setCdmaSubscriptionSource(mCdmaSubscription, null);
3122                 setCellInfoListRate(Integer.MAX_VALUE, null);
3123                 notifyRegistrantsRilConnectionChanged(((int[])ret)[0]);
3124
3125                 getRadioCapability(null);
3126                 break;
3127             }
3128             case RIL_UNSOL_CELL_INFO_LIST: {
3129                 if (RILJ_LOGD) unsljLogRet(response, ret);
3130
3131                 if (mRilCellInfoListRegistrants != null) {
3132                     mRilCellInfoListRegistrants.notifyRegistrants(
3133                                         new AsyncResult (null, ret, null));
3134                 }
3135                 break;
3136             }
3137             case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: {
3138                 if (RILJ_LOGD) unsljLogRet(response, ret);
3139
3140                 if (mSubscriptionStatusRegistrants != null) {
3141                     mSubscriptionStatusRegistrants.notifyRegistrants(
3142                                         new AsyncResult (null, ret, null));
3143                 }
3144                 break;
3145             }
3146             case RIL_UNSOL_SRVCC_STATE_NOTIFY: {
3147                 if (RILJ_LOGD) unsljLogRet(response, ret);
3148
3149                 if (mSrvccStateRegistrants != null) {
3150                     mSrvccStateRegistrants
3151                             .notifyRegistrants(new AsyncResult(null, ret, null));
3152                 }
3153                 break;
3154             }
3155             case RIL_UNSOL_HARDWARE_CONFIG_CHANGED:
3156                 if (RILJ_LOGD) unsljLogRet(response, ret);
3157
3158                 if (mHardwareConfigChangeRegistrants != null) {
3159                     mHardwareConfigChangeRegistrants.notifyRegistrants(
3160                                              new AsyncResult (null, ret, null));
3161                 }
3162                 break;
3163             case RIL_UNSOL_RADIO_CAPABILITY:
3164                 if (RILJ_LOGD) unsljLogRet(response, ret);
3165
3166                 if (mPhoneRadioCapabilityChangedRegistrants != null) {
3167                     mPhoneRadioCapabilityChangedRegistrants.notifyRegistrants(
3168                             new AsyncResult(null, ret, null));
3169                  }
3170                  break;
3171             case RIL_UNSOL_ON_SS:
3172                 if (RILJ_LOGD) unsljLogRet(response, ret);
3173
3174                 if (mSsRegistrant != null) {
3175                     mSsRegistrant.notifyRegistrant(
3176                                         new AsyncResult (null, ret, null));
3177                 }
3178                 break;
3179             case RIL_UNSOL_STK_CC_ALPHA_NOTIFY:
3180                 if (RILJ_LOGD) unsljLogRet(response, ret);
3181
3182                 if (mCatCcAlphaRegistrant != null) {
3183                     mCatCcAlphaRegistrant.notifyRegistrant(
3184                                         new AsyncResult (null, ret, null));
3185                 }
3186                 break;
3187         }
3188     }
3189
3190     /**
3191      * Notifiy all registrants that the ril has connected or disconnected.
3192      *
3193      * @param rilVer is the version of the ril or -1 if disconnected.
3194      */
3195     private void notifyRegistrantsRilConnectionChanged(int rilVer) {
3196         mRilVersion = rilVer;
3197         if (mRilConnectedRegistrants != null) {
3198             mRilConnectedRegistrants.notifyRegistrants(
3199                                 new AsyncResult (null, new Integer(rilVer), null));
3200         }
3201     }
3202
3203     private Object
3204     responseInts(Parcel p) {
3205         int numInts;
3206         int response[];
3207
3208         numInts = p.readInt();
3209
3210         response = new int[numInts];
3211
3212         for (int i = 0 ; i < numInts ; i++) {
3213             response[i] = p.readInt();
3214         }
3215
3216         return response;
3217     }
3218
3219
3220     private Object
3221     responseVoid(Parcel p) {
3222         return null;
3223     }
3224
3225     private Object
3226     responseCallForward(Parcel p) {
3227         int numInfos;
3228         CallForwardInfo infos[];
3229
3230         numInfos = p.readInt();
3231
3232         infos = new CallForwardInfo[numInfos];
3233
3234         for (int i = 0 ; i < numInfos ; i++) {
3235             infos[i] = new CallForwardInfo();
3236
3237             infos[i].status = p.readInt();
3238             infos[i].reason = p.readInt();
3239             infos[i].serviceClass = p.readInt();
3240             infos[i].toa = p.readInt();
3241             infos[i].number = p.readString();
3242             infos[i].timeSeconds = p.readInt();
3243         }
3244
3245         return infos;
3246     }
3247
3248     private Object
3249     responseSuppServiceNotification(Parcel p) {
3250         SuppServiceNotification notification = new SuppServiceNotification();
3251
3252         notification.notificationType = p.readInt();
3253         notification.code = p.readInt();
3254         notification.index = p.readInt();
3255         notification.type = p.readInt();
3256         notification.number = p.readString();
3257
3258         return notification;
3259     }
3260
3261     private Object
3262     responseCdmaSms(Parcel p) {
3263         SmsMessage sms;
3264         sms = SmsMessage.newFromParcel(p);
3265
3266         return sms;
3267     }
3268
3269     private Object
3270     responseString(Parcel p) {
3271         String response;
3272
3273         response = p.readString();
3274
3275         return response;
3276     }
3277
3278     private Object
3279     responseStrings(Parcel p) {
3280         int num;
3281         String response[];
3282
3283         response = p.readStringArray();
3284
3285         return response;
3286     }
3287
3288     private Object
3289     responseRaw(Parcel p) {
3290         int num;
3291         byte response[];
3292
3293         response = p.createByteArray();
3294
3295         return response;
3296     }
3297
3298     private Object
3299     responseSMS(Parcel p) {
3300         int messageRef, errorCode;
3301         String ackPDU;
3302
3303         messageRef = p.readInt();
3304         ackPDU = p.readString();
3305         errorCode = p.readInt();
3306
3307         SmsResponse response = new SmsResponse(messageRef, ackPDU, errorCode);
3308
3309         return response;
3310     }
3311
3312
3313     private Object
3314     responseICC_IO(Parcel p) {
3315         int sw1, sw2;
3316         Message ret;
3317
3318         sw1 = p.readInt();
3319         sw2 = p.readInt();
3320
3321         String s = p.readString();
3322
3323         if (RILJ_LOGV) riljLog("< iccIO: "
3324                 + " 0x" + Integer.toHexString(sw1)
3325                 + " 0x" + Integer.toHexString(sw2) + " "
3326                 + s);
3327
3328         return new IccIoResult(sw1, sw2, s);
3329     }
3330
3331     private Object
3332     responseICC_IOBase64(Parcel p) {
3333         int sw1, sw2;
3334         Message ret;
3335
3336         sw1 = p.readInt();
3337         sw2 = p.readInt();
3338
3339         String s = p.readString();
3340
3341         if (RILJ_LOGV) riljLog("< iccIO: "
3342                 + " 0x" + Integer.toHexString(sw1)
3343                 + " 0x" + Integer.toHexString(sw2) + " "
3344                 + s);
3345
3346
3347         return new IccIoResult(sw1, sw2, android.util.Base64.decode(s, android.util.Base64.DEFAULT));
3348     }
3349
3350     private Object
3351     responseIccCardStatus(Parcel p) {
3352         IccCardApplicationStatus appStatus;
3353
3354         IccCardStatus cardStatus = new IccCardStatus();
3355         cardStatus.setCardState(p.readInt());
3356         cardStatus.setUniversalPinState(p.readInt());
3357         cardStatus.mGsmUmtsSubscriptionAppIndex = p.readInt();
3358         cardStatus.mCdmaSubscriptionAppIndex = p.readInt();
3359         cardStatus.mImsSubscriptionAppIndex = p.readInt();
3360         int numApplications = p.readInt();
3361
3362         // limit to maximum allowed applications
3363         if (numApplications > IccCardStatus.CARD_MAX_APPS) {
3364             numApplications = IccCardStatus.CARD_MAX_APPS;
3365         }
3366         cardStatus.mApplications = new IccCardApplicationStatus[numApplications];
3367         for (int i = 0 ; i < numApplications ; i++) {
3368             appStatus = new IccCardApplicationStatus();
3369             appStatus.app_type       = appStatus.AppTypeFromRILInt(p.readInt());
3370             appStatus.app_state      = appStatus.AppStateFromRILInt(p.readInt());
3371             appStatus.perso_substate = appStatus.PersoSubstateFromRILInt(p.readInt());
3372             appStatus.aid            = p.readString();
3373             appStatus.app_label      = p.readString();
3374             appStatus.pin1_replaced  = p.readInt();
3375             appStatus.pin1           = appStatus.PinStateFromRILInt(p.readInt());
3376             appStatus.pin2           = appStatus.PinStateFromRILInt(p.readInt());
3377             cardStatus.mApplications[i] = appStatus;
3378         }
3379         return cardStatus;
3380     }
3381
3382     private Object
3383     responseSimRefresh(Parcel p) {
3384         IccRefreshResponse response = new IccRefreshResponse();
3385
3386         response.refreshResult = p.readInt();
3387         response.efId   = p.readInt();
3388         response.aid = p.readString();
3389         return response;
3390     }
3391
3392     private Object
3393     responseCallList(Parcel p) {
3394         int num;
3395         int voiceSettings;
3396         ArrayList<DriverCall> response;
3397         DriverCall dc;
3398
3399         num = p.readInt();
3400         response = new ArrayList<DriverCall>(num);
3401
3402         if (RILJ_LOGV) {
3403             riljLog("responseCallList: num=" + num +
3404                     " mEmergencyCallbackModeRegistrant=" + mEmergencyCallbackModeRegistrant +
3405                     " mTestingEmergencyCall=" + mTestingEmergencyCall.get());
3406         }
3407         for (int i = 0 ; i < num ; i++) {
3408             dc = new DriverCall();
3409
3410             dc.state = DriverCall.stateFromCLCC(p.readInt());
3411             dc.index = p.readInt();
3412             dc.TOA = p.readInt();
3413             dc.isMpty = (0 != p.readInt());
3414             dc.isMT = (0 != p.readInt());
3415             dc.als = p.readInt();
3416             voiceSettings = p.readInt();
3417             dc.isVoice = (0 == voiceSettings) ? false : true;
3418             dc.isVoicePrivacy = (0 != p.readInt());
3419             dc.number = p.readString();
3420             int np = p.readInt();
3421             dc.numberPresentation = DriverCall.presentationFromCLIP(np);
3422             dc.name = p.readString();
3423             // according to ril.h, namePresentation should be handled as numberPresentation;
3424             dc.namePresentation = DriverCall.presentationFromCLIP(p.readInt());
3425             int uusInfoPresent = p.readInt();
3426             if (uusInfoPresent == 1) {
3427                 dc.uusInfo = new UUSInfo();
3428                 dc.uusInfo.setType(p.readInt());
3429                 dc.uusInfo.setDcs(p.readInt());
3430                 byte[] userData = p.createByteArray();
3431                 dc.uusInfo.setUserData(userData);
3432                 riljLogv(String.format("Incoming UUS : type=%d, dcs=%d, length=%d",
3433                                 dc.uusInfo.getType(), dc.uusInfo.getDcs(),
3434                                 dc.uusInfo.getUserData().length));
3435                 riljLogv("Incoming UUS : data (string)="
3436                         + new String(dc.uusInfo.getUserData()));
3437                 riljLogv("Incoming UUS : data (hex): "
3438                         + IccUtils.bytesToHexString(dc.uusInfo.getUserData()));
3439             } else {
3440                 riljLogv("Incoming UUS : NOT present!");
3441             }
3442
3443             // Make sure there's a leading + on addresses with a TOA of 145
3444             dc.number = PhoneNumberUtils.stringFromStringAndTOA(dc.number, dc.TOA);
3445
3446             response.add(dc);
3447
3448             if (dc.isVoicePrivacy) {
3449                 mVoicePrivacyOnRegistrants.notifyRegistrants();
3450                 riljLog("InCall VoicePrivacy is enabled");
3451             } else {
3452                 mVoicePrivacyOffRegistrants.notifyRegistrants();
3453                 riljLog("InCall VoicePrivacy is disabled");
3454             }
3455         }
3456
3457         Collections.sort(response);
3458
3459         if ((num == 0) && mTestingEmergencyCall.getAndSet(false)) {
3460             if (mEmergencyCallbackModeRegistrant != null) {
3461                 riljLog("responseCallList: call ended, testing emergency call," +
3462                             " notify ECM Registrants");
3463                 mEmergencyCallbackModeRegistrant.notifyRegistrant();
3464             }
3465         }
3466
3467         return response;
3468     }
3469
3470     private DataCallResponse getDataCallResponse(Parcel p, int version) {
3471         DataCallResponse dataCall = new DataCallResponse();
3472
3473         dataCall.version = version;
3474         if (version < 5) {
3475             dataCall.cid = p.readInt();
3476             dataCall.active = p.readInt();
3477             dataCall.type = p.readString();
3478             String addresses = p.readString();
3479             if (!TextUtils.isEmpty(addresses)) {
3480                 dataCall.addresses = addresses.split(" ");
3481             }
3482         } else {
3483             dataCall.status = p.readInt();
3484             dataCall.suggestedRetryTime = p.readInt();
3485             dataCall.cid = p.readInt();
3486             dataCall.active = p.readInt();
3487             dataCall.type = p.readString();
3488             dataCall.ifname = p.readString();
3489             if ((dataCall.status == DcFailCause.NONE.getErrorCode()) &&
3490                     TextUtils.isEmpty(dataCall.ifname)) {
3491               throw new RuntimeException("getDataCallResponse, no ifname");
3492             }
3493             String addresses = p.readString();
3494             if (!TextUtils.isEmpty(addresses)) {
3495                 dataCall.addresses = addresses.split(" ");
3496             }
3497             String dnses = p.readString();
3498             if (!TextUtils.isEmpty(dnses)) {
3499                 dataCall.dnses = dnses.split(" ");
3500             }
3501             String gateways = p.readString();
3502             if (!TextUtils.isEmpty(gateways)) {
3503                 dataCall.gateways = gateways.split(" ");
3504             }
3505             if (version >= 10) {
3506                 String pcscf = p.readString();
3507                 if (!TextUtils.isEmpty(pcscf)) {
3508                     dataCall.pcscf = pcscf.split(" ");
3509                 }
3510             }
3511             if (version >= 11) {
3512                 dataCall.mtu = p.readInt();
3513             }
3514         }
3515         return dataCall;
3516     }
3517
3518     private Object
3519     responseDataCallList(Parcel p) {
3520         ArrayList<DataCallResponse> response;
3521
3522         int ver = p.readInt();
3523         int num = p.readInt();
3524         riljLog("responseDataCallList ver=" + ver + " num=" + num);
3525
3526         response = new ArrayList<DataCallResponse>(num);
3527         for (int i = 0; i < num; i++) {
3528             response.add(getDataCallResponse(p, ver));
3529         }
3530
3531         return response;
3532     }
3533
3534     private Object
3535     responseSetupDataCall(Parcel p) {
3536         int ver = p.readInt();
3537         int num = p.readInt();
3538         if (RILJ_LOGV) riljLog("responseSetupDataCall ver=" + ver + " num=" + num);
3539
3540         DataCallResponse dataCall;
3541
3542         if (ver < 5) {
3543             dataCall = new DataCallResponse();
3544             dataCall.version = ver;
3545             dataCall.cid = Integer.parseInt(p.readString());
3546             dataCall.ifname = p.readString();
3547             if (TextUtils.isEmpty(dataCall.ifname)) {
3548                 throw new RuntimeException(
3549                         "RIL_REQUEST_SETUP_DATA_CALL response, no ifname");
3550             }
3551             String addresses = p.readString();
3552             if (!TextUtils.isEmpty(addresses)) {
3553               dataCall.addresses = addresses.split(" ");
3554             }
3555             if (num >= 4) {
3556                 String dnses = p.readString();
3557                 if (RILJ_LOGD) riljLog("responseSetupDataCall got dnses=" + dnses);
3558                 if (!TextUtils.isEmpty(dnses)) {
3559                     dataCall.dnses = dnses.split(" ");
3560                 }
3561             }
3562             if (num >= 5) {
3563                 String gateways = p.readString();
3564                 if (RILJ_LOGD) riljLog("responseSetupDataCall got gateways=" + gateways);
3565                 if (!TextUtils.isEmpty(gateways)) {
3566                     dataCall.gateways = gateways.split(" ");
3567                 }
3568             }
3569             if (num >= 6) {
3570                 String pcscf = p.readString();
3571                 if (RILJ_LOGD) riljLog("responseSetupDataCall got pcscf=" + pcscf);
3572                 if (!TextUtils.isEmpty(pcscf)) {
3573                     dataCall.pcscf = pcscf.split(" ");
3574                 }
3575             }
3576         } else {
3577             if (num != 1) {
3578                 throw new RuntimeException(
3579                         "RIL_REQUEST_SETUP_DATA_CALL response expecting 1 RIL_Data_Call_response_v5"
3580                         + " got " + num);
3581             }
3582             dataCall = getDataCallResponse(p, ver);
3583         }
3584
3585         return dataCall;
3586     }
3587
3588     private Object
3589     responseOperatorInfos(Parcel p) {
3590         String strings[] = (String [])responseStrings(p);
3591         ArrayList<OperatorInfo> ret;
3592
3593         // FIXME: What is this really doing
3594         SpnOverride spnOverride = new SpnOverride();
3595
3596         if (strings.length % 4 != 0) {
3597             throw new RuntimeException(
3598                 "RIL_REQUEST_QUERY_AVAILABLE_NETWORKS: invalid response. Got "
3599                 + strings.length + " strings, expected multible of 4");
3600         }
3601
3602         ret = new ArrayList<OperatorInfo>(strings.length / 4);
3603
3604         for (int i = 0 ; i < strings.length ; i += 4) {
3605             String strOperatorLong = null;
3606             if (spnOverride.containsCarrier(strings[i+2])) {
3607                 strOperatorLong = spnOverride.getSpn(strings[i+2]);
3608             } else {
3609                 strOperatorLong = strings[i+0];
3610             }
3611             ret.add (
3612                 new OperatorInfo(
3613                     strOperatorLong,
3614                     strings[i+1],
3615                     strings[i+2],
3616                     strings[i+3]));
3617         }
3618
3619         return ret;
3620     }
3621
3622     private Object
3623     responseCellList(Parcel p) {
3624        int num, rssi;
3625        String location;
3626        ArrayList<NeighboringCellInfo> response;
3627        NeighboringCellInfo cell;
3628
3629        num = p.readInt();
3630        response = new ArrayList<NeighboringCellInfo>();
3631
3632        // Determine the radio access type
3633        String radioString = SystemProperties.get(
3634                TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE, "unknown");
3635        int radioType;
3636        if (radioString.equals("GPRS")) {
3637            radioType = NETWORK_TYPE_GPRS;
3638        } else if (radioString.equals("EDGE")) {
3639            radioType = NETWORK_TYPE_EDGE;
3640        } else if (radioString.equals("UMTS")) {
3641            radioType = NETWORK_TYPE_UMTS;
3642        } else if (radioString.equals("HSDPA")) {
3643            radioType = NETWORK_TYPE_HSDPA;
3644        } else if (radioString.equals("HSUPA")) {
3645            radioType = NETWORK_TYPE_HSUPA;
3646        } else if (radioString.equals("HSPA")) {
3647            radioType = NETWORK_TYPE_HSPA;
3648        } else {
3649            radioType = NETWORK_TYPE_UNKNOWN;
3650        }
3651
3652        // Interpret the location based on radio access type
3653        if (radioType != NETWORK_TYPE_UNKNOWN) {
3654            for (int i = 0 ; i < num ; i++) {
3655                rssi = p.readInt();
3656                location = p.readString();
3657                cell = new NeighboringCellInfo(rssi, location, radioType);
3658                response.add(cell);
3659            }
3660        }
3661        return response;
3662     }
3663
3664     private Object responseGetPreferredNetworkType(Parcel p) {
3665        int [] response = (int[]) responseInts(p);
3666
3667        if (response.length >= 1) {
3668            // Since this is the response for getPreferredNetworkType
3669            // we'll assume that it should be the value we want the
3670            // vendor ril to take if we reestablish a connection to it.
3671            mPreferredNetworkType = response[0];
3672        }
3673        return response;
3674     }
3675
3676     private Object responseGmsBroadcastConfig(Parcel p) {
3677         int num;
3678         ArrayList<SmsBroadcastConfigInfo> response;
3679         SmsBroadcastConfigInfo info;
3680
3681         num = p.readInt();
3682         response = new ArrayList<SmsBroadcastConfigInfo>(num);
3683
3684         for (int i = 0; i < num; i++) {
3685             int fromId = p.readInt();
3686             int toId = p.readInt();
3687             int fromScheme = p.readInt();
3688             int toScheme = p.readInt();
3689             boolean selected = (p.readInt() == 1);
3690
3691             info = new SmsBroadcastConfigInfo(fromId, toId, fromScheme,
3692                     toScheme, selected);
3693             response.add(info);
3694         }
3695         return response;
3696     }
3697
3698     private Object
3699     responseCdmaBroadcastConfig(Parcel p) {
3700         int numServiceCategories;
3701         int response[];
3702
3703         numServiceCategories = p.readInt();
3704
3705         if (numServiceCategories == 0) {
3706             // TODO: The logic of providing default values should
3707             // not be done by this transport layer. And needs to
3708             // be done by the vendor ril or application logic.
3709             int numInts;
3710             numInts = CDMA_BROADCAST_SMS_NO_OF_SERVICE_CATEGORIES * CDMA_BSI_NO_OF_INTS_STRUCT + 1;
3711             response = new int[numInts];
3712
3713             // Faking a default record for all possible records.
3714             response[0] = CDMA_BROADCAST_SMS_NO_OF_SERVICE_CATEGORIES;
3715
3716             // Loop over CDMA_BROADCAST_SMS_NO_OF_SERVICE_CATEGORIES set 'english' as
3717             // default language and selection status to false for all.
3718             for (int i = 1; i < numInts; i += CDMA_BSI_NO_OF_INTS_STRUCT ) {
3719                 response[i + 0] = i / CDMA_BSI_NO_OF_INTS_STRUCT;
3720                 response[i + 1] = 1;
3721                 response[i + 2] = 0;
3722             }
3723         } else {
3724             int numInts;
3725             numInts = (numServiceCategories * CDMA_BSI_NO_OF_INTS_STRUCT) + 1;
3726             response = new int[numInts];
3727
3728             response[0] = numServiceCategories;
3729             for (int i = 1 ; i < numInts; i++) {
3730                  response[i] = p.readInt();
3731              }
3732         }
3733
3734         return response;
3735     }
3736
3737     private Object
3738     responseSignalStrength(Parcel p) {
3739         // Assume this is gsm, but doesn't matter as ServiceStateTracker
3740         // sets the proper value.
3741         SignalStrength signalStrength = SignalStrength.makeSignalStrengthFromRilParcel(p);
3742         return signalStrength;
3743     }
3744
3745     private ArrayList<CdmaInformationRecords>
3746     responseCdmaInformationRecord(Parcel p) {
3747         int numberOfInfoRecs;
3748         ArrayList<CdmaInformationRecords> response;
3749
3750         /**
3751          * Loop through all of the information records unmarshalling them
3752          * and converting them to Java Objects.
3753          */
3754         numberOfInfoRecs = p.readInt();
3755         response = new ArrayList<CdmaInformationRecords>(numberOfInfoRecs);
3756
3757         for (int i = 0; i < numberOfInfoRecs; i++) {
3758             CdmaInformationRecords InfoRec = new CdmaInformationRecords(p);
3759             response.add(InfoRec);
3760         }
3761
3762         return response;
3763     }
3764
3765     private Object
3766     responseCdmaCallWaiting(Parcel p) {
3767         CdmaCallWaitingNotification notification = new CdmaCallWaitingNotification();
3768
3769         notification.number = p.readString();
3770         notification.numberPresentation =
3771                 CdmaCallWaitingNotification.presentationFromCLIP(p.readInt());
3772         notification.name = p.readString();
3773         notification.namePresentation = notification.numberPresentation;
3774         notification.isPresent = p.readInt();
3775         notification.signalType = p.readInt();
3776         notification.alertPitch = p.readInt();
3777         notification.signal = p.readInt();
3778         notification.numberType = p.readInt();
3779         notification.numberPlan = p.readInt();
3780
3781         return notification;
3782     }
3783
3784     private Object
3785     responseCallRing(Parcel p){
3786         char response[] = new char[4];
3787
3788         response[0] = (char) p.readInt();    // isPresent
3789         response[1] = (char) p.readInt();    // signalType
3790         response[2] = (char) p.readInt();    // alertPitch
3791         response[3] = (char) p.readInt();    // signal
3792
3793         return response;
3794     }
3795
3796     private void
3797     notifyRegistrantsCdmaInfoRec(CdmaInformationRecords infoRec) {
3798         int response = RIL_UNSOL_CDMA_INFO_REC;
3799         if (infoRec.record instanceof CdmaInformationRecords.CdmaDisplayInfoRec) {
3800             if (mDisplayInfoRegistrants != null) {
3801                 if (RILJ_LOGD) unsljLogRet(response, infoRec.record);
3802                 mDisplayInfoRegistrants.notifyRegistrants(
3803                         new AsyncResult (null, infoRec.record, null));
3804             }
3805         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaSignalInfoRec) {
3806             if (mSignalInfoRegistrants != null) {
3807                 if (RILJ_LOGD) unsljLogRet(response, infoRec.record);
3808                 mSignalInfoRegistrants.notifyRegistrants(
3809                         new AsyncResult (null, infoRec.record, null));
3810             }
3811         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaNumberInfoRec) {
3812             if (mNumberInfoRegistrants != null) {
3813                 if (RILJ_LOGD) unsljLogRet(response, infoRec.record);
3814                 mNumberInfoRegistrants.notifyRegistrants(
3815                         new AsyncResult (null, infoRec.record, null));
3816             }
3817         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaRedirectingNumberInfoRec) {
3818             if (mRedirNumInfoRegistrants != null) {
3819                 if (RILJ_LOGD) unsljLogRet(response, infoRec.record);
3820                 mRedirNumInfoRegistrants.notifyRegistrants(
3821                         new AsyncResult (null, infoRec.record, null));
3822             }
3823         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaLineControlInfoRec) {
3824             if (mLineControlInfoRegistrants != null) {
3825                 if (RILJ_LOGD) unsljLogRet(response, infoRec.record);
3826                 mLineControlInfoRegistrants.notifyRegistrants(
3827                         new AsyncResult (null, infoRec.record, null));
3828             }
3829         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaT53ClirInfoRec) {
3830             if (mT53ClirInfoRegistrants != null) {
3831                 if (RILJ_LOGD) unsljLogRet(response, infoRec.record);
3832                 mT53ClirInfoRegistrants.notifyRegistrants(
3833                         new AsyncResult (null, infoRec.record, null));
3834             }
3835         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaT53AudioControlInfoRec) {
3836             if (mT53AudCntrlInfoRegistrants != null) {
3837                if (RILJ_LOGD) unsljLogRet(response, infoRec.record);
3838                mT53AudCntrlInfoRegistrants.notifyRegistrants(
3839                        new AsyncResult (null, infoRec.record, null));
3840             }
3841         }
3842     }
3843
3844     private ArrayList<CellInfo> responseCellInfoList(Parcel p) {
3845         int numberOfInfoRecs;
3846         ArrayList<CellInfo> response;
3847
3848         /**
3849          * Loop through all of the information records unmarshalling them
3850          * and converting them to Java Objects.
3851          */
3852         numberOfInfoRecs = p.readInt();
3853         response = new ArrayList<CellInfo>(numberOfInfoRecs);
3854
3855         for (int i = 0; i < numberOfInfoRecs; i++) {
3856             CellInfo InfoRec = CellInfo.CREATOR.createFromParcel(p);
3857             response.add(InfoRec);
3858         }
3859
3860         return response;
3861     }
3862
3863    private Object
3864    responseHardwareConfig(Parcel p) {
3865       int num;
3866       ArrayList<HardwareConfig> response;
3867       HardwareConfig hw;
3868
3869       num = p.readInt();
3870       response = new ArrayList<HardwareConfig>(num);
3871
3872       if (RILJ_LOGV) {
3873          riljLog("responseHardwareConfig: num=" + num);
3874       }
3875       for (int i = 0 ; i < num ; i++) {
3876          int type = p.readInt();
3877          switch(type) {
3878             case HardwareConfig.DEV_HARDWARE_TYPE_MODEM: {
3879                hw = new HardwareConfig(type);
3880                hw.assignModem(p.readString(), p.readInt(), p.readInt(),
3881                   p.readInt(), p.readInt(), p.readInt(), p.readInt());
3882                break;
3883             }
3884             case HardwareConfig.DEV_HARDWARE_TYPE_SIM: {
3885                hw = new HardwareConfig(type);
3886                hw.assignSim(p.readString(), p.readInt(), p.readString());
3887                break;
3888             }
3889             default: {
3890                throw new RuntimeException(
3891                   "RIL_REQUEST_GET_HARDWARE_CONFIG invalid hardward type:" + type);
3892             }
3893          }
3894
3895          response.add(hw);
3896       }
3897
3898       return response;
3899    }
3900
3901     private Object
3902     responseRadioCapability(Parcel p) {
3903         int version = p.readInt();
3904         int session = p.readInt();
3905         int phase = p.readInt();
3906         int rat = p.readInt();
3907         String logicModemUuid = p.readString();
3908         int status = p.readInt();
3909
3910         riljLog("responseRadioCapability: version= " + version +
3911                 ", session=" + session +
3912                 ", phase=" + phase +
3913                 ", rat=" + rat +
3914                 ", logicModemUuid=" + logicModemUuid +
3915                 ", status=" + status);
3916         RadioCapability rc = new RadioCapability(
3917                 mInstanceId.intValue(), session, phase, rat, logicModemUuid, status);
3918         return rc;
3919     }
3920
3921     static String
3922     requestToString(int request) {
3923 /*
3924  cat libs/telephony/ril_commands.h \
3925  | egrep "^ *{RIL_" \
3926  | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
3927 */
3928         switch(request) {
3929             case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
3930             case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
3931             case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
3932             case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
3933             case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
3934             case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
3935             case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
3936             case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
3937             case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
3938             case RIL_REQUEST_DIAL: return "DIAL";
3939             case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
3940             case RIL_REQUEST_HANGUP: return "HANGUP";
3941             case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
3942             case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
3943             case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
3944             case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
3945             case RIL_REQUEST_UDUB: return "UDUB";
3946             case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
3947             case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
3948             case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
3949             case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
3950             case RIL_REQUEST_OPERATOR: return "OPERATOR";
3951             case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
3952             case RIL_REQUEST_DTMF: return "DTMF";
3953             case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
3954             case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
3955             case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
3956             case RIL_REQUEST_SIM_IO: return "SIM_IO";
3957             case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
3958             case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
3959             case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
3960             case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
3961             case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
3962             case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
3963             case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
3964             case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
3965             case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
3966             case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
3967             case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
3968             case RIL_REQUEST_ANSWER: return "ANSWER";
3969             case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
3970             case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
3971             case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
3972             case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
3973             case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
3974             case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
3975             case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
3976             case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
3977             case RIL_REQUEST_DTMF_START: return "DTMF_START";
3978             case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
3979             case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
3980             case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
3981             case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
3982             case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
3983             case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
3984             case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
3985             case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
3986             case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
3987             case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
3988             case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
3989             case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
3990             case RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION: return "SET_SUPP_SVC_NOTIFICATION";
3991             case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM";
3992             case RIL_REQUEST_DELETE_SMS_ON_SIM: return "DELETE_SMS_ON_SIM";
3993             case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
3994             case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
3995             case RIL_REQUEST_STK_GET_PROFILE: return "REQUEST_STK_GET_PROFILE";
3996             case RIL_REQUEST_STK_SET_PROFILE: return "REQUEST_STK_SET_PROFILE";
3997             case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "REQUEST_STK_SEND_ENVELOPE_COMMAND";
3998             case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "REQUEST_STK_SEND_TERMINAL_RESPONSE";
3999             case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
4000             case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "REQUEST_EXPLICIT_CALL_TRANSFER";
4001             case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "REQUEST_SET_PREFERRED_NETWORK_TYPE";
4002             case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "REQUEST_GET_PREFERRED_NETWORK_TYPE";
4003             case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "REQUEST_GET_NEIGHBORING_CELL_IDS";
4004             case RIL_REQUEST_SET_LOCATION_UPDATES: return "REQUEST_SET_LOCATION_UPDATES";
4005             case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE: return "RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE";
4006             case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE: return "RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE";
4007             case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE: return "RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE";
4008             case RIL_REQUEST_SET_TTY_MODE: return "RIL_REQUEST_SET_TTY_MODE";
4009             case RIL_REQUEST_QUERY_TTY_MODE: return "RIL_REQUEST_QUERY_TTY_MODE";
4010             case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE: return "RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
4011             case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE: return "RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
4012             case RIL_REQUEST_CDMA_FLASH: return "RIL_REQUEST_CDMA_FLASH";
4013             case RIL_REQUEST_CDMA_BURST_DTMF: return "RIL_REQUEST_CDMA_BURST_DTMF";
4014             case RIL_REQUEST_CDMA_SEND_SMS: return "RIL_REQUEST_CDMA_SEND_SMS";
4015             case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE: return "RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE";
4016             case RIL_REQUEST_GSM_GET_BROADCAST_CONFIG: return "RIL_REQUEST_GSM_GET_BROADCAST_CONFIG";
4017             case RIL_REQUEST_GSM_SET_BROADCAST_CONFIG: return "RIL_REQUEST_GSM_SET_BROADCAST_CONFIG";
4018             case RIL_REQUEST_CDMA_GET_BROADCAST_CONFIG: return "RIL_REQUEST_CDMA_GET_BROADCAST_CONFIG";
4019             case RIL_REQUEST_CDMA_SET_BROADCAST_CONFIG: return "RIL_REQUEST_CDMA_SET_BROADCAST_CONFIG";
4020             case RIL_REQUEST_GSM_BROADCAST_ACTIVATION: return "RIL_REQUEST_GSM_BROADCAST_ACTIVATION";
4021             case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return "RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY";
4022             case RIL_REQUEST_CDMA_BROADCAST_ACTIVATION: return "RIL_REQUEST_CDMA_BROADCAST_ACTIVATION";
4023             case RIL_REQUEST_CDMA_SUBSCRIPTION: return "RIL_REQUEST_CDMA_SUBSCRIPTION";
4024             case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM";
4025             case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM";
4026             case RIL_REQUEST_DEVICE_IDENTITY: return "RIL_REQUEST_DEVICE_IDENTITY";
4027             case RIL_REQUEST_GET_SMSC_ADDRESS: return "RIL_REQUEST_GET_SMSC_ADDRESS";
4028             case RIL_REQUEST_SET_SMSC_ADDRESS: return "RIL_REQUEST_SET_SMSC_ADDRESS";
4029             case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "REQUEST_EXIT_EMERGENCY_CALLBACK_MODE";
4030             case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "RIL_REQUEST_REPORT_SMS_MEMORY_STATUS";
4031             case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING";
4032             case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE";
4033             case RIL_REQUEST_ISIM_AUTHENTICATION: return "RIL_REQUEST_ISIM_AUTHENTICATION";
4034             case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
4035             case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
4036             case RIL_REQUEST_VOICE_RADIO_TECH: return "RIL_REQUEST_VOICE_RADIO_TECH";
4037             case RIL_REQUEST_GET_CELL_INFO_LIST: return "RIL_REQUEST_GET_CELL_INFO_LIST";
4038             case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return "RIL_REQUEST_SET_CELL_INFO_LIST_RATE";
4039             case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
4040             case RIL_REQUEST_SET_DATA_PROFILE: return "RIL_REQUEST_SET_DATA_PROFILE";
4041             case RIL_REQUEST_IMS_REGISTRATION_STATE: return "RIL_REQUEST_IMS_REGISTRATION_STATE";
4042             case RIL_REQUEST_IMS_SEND_SMS: return "RIL_REQUEST_IMS_SEND_SMS";
4043             case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC";
4044             case RIL_REQUEST_SIM_OPEN_CHANNEL: return "RIL_REQUEST_SIM_OPEN_CHANNEL";
4045             case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "RIL_REQUEST_SIM_CLOSE_CHANNEL";
4046             case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL";
4047             case RIL_REQUEST_NV_READ_ITEM: return "RIL_REQUEST_NV_READ_ITEM";
4048             case RIL_REQUEST_NV_WRITE_ITEM: return "RIL_REQUEST_NV_WRITE_ITEM";
4049             case RIL_REQUEST_NV_WRITE_CDMA_PRL: return "RIL_REQUEST_NV_WRITE_CDMA_PRL";
4050             case RIL_REQUEST_NV_RESET_CONFIG: return "RIL_REQUEST_NV_RESET_CONFIG";
4051             case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "RIL_REQUEST_SET_UICC_SUBSCRIPTION";
4052             case RIL_REQUEST_ALLOW_DATA: return "RIL_REQUEST_ALLOW_DATA";
4053             case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
4054             case RIL_REQUEST_SIM_AUTHENTICATION: return "RIL_REQUEST_SIM_AUTHENTICATION";
4055             case RIL_REQUEST_SHUTDOWN: return "RIL_REQUEST_SHUTDOWN";
4056             case RIL_REQUEST_SET_RADIO_CAPABILITY:
4057                     return "RIL_REQUEST_SET_RADIO_CAPABILITY";
4058             case RIL_REQUEST_GET_RADIO_CAPABILITY:
4059                     return "RIL_REQUEST_GET_RADIO_CAPABILITY";
4060             default: return "<unknown request>";
4061         }
4062     }
4063
4064     static String
4065     responseToString(int request)
4066     {
4067 /*
4068  cat libs/telephony/ril_unsol_commands.h \
4069  | egrep "^ *{RIL_" \
4070  | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
4071 */
4072         switch(request) {
4073             case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
4074             case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
4075             case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
4076             case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
4077             case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
4078             case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
4079             case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
4080             case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST";
4081             case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
4082             case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
4083             case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
4084             case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
4085             case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
4086             case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
4087             case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
4088             case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
4089             case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FULL";
4090             case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
4091             case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
4092             case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
4093             case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_RESPONSE_CDMA_NEW_SMS";
4094             case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_RESPONSE_NEW_BROADCAST_SMS";
4095             case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
4096             case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
4097             case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
4098             case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
4099             case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
4100             case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
4101             case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
4102             case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
4103             case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
4104             case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "CDMA_SUBSCRIPTION_SOURCE_CHANGED";
4105             case RIL_UNSOl_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
4106             case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
4107             case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
4108             case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
4109             case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
4110             case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED:
4111                 return "UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED";
4112             case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED:
4113                     return "RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
4114             case RIL_UNSOL_SRVCC_STATE_NOTIFY:
4115                     return "UNSOL_SRVCC_STATE_NOTIFY";
4116             case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "RIL_UNSOL_HARDWARE_CONFIG_CHANGED";
4117             case RIL_UNSOL_RADIO_CAPABILITY:
4118                     return "RIL_UNSOL_RADIO_CAPABILITY";
4119             case RIL_UNSOL_ON_SS: return "UNSOL_ON_SS";
4120             case RIL_UNSOL_STK_CC_ALPHA_NOTIFY: return "UNSOL_STK_CC_ALPHA_NOTIFY";
4121             default: return "<unknown response>";
4122         }
4123     }
4124
4125     private void riljLog(String msg) {
4126         Rlog.d(RILJ_LOG_TAG, msg
4127                 + (mInstanceId != null ? (" [SUB" + mInstanceId + "]") : ""));
4128     }
4129
4130     private void riljLogv(String msg) {
4131         Rlog.v(RILJ_LOG_TAG, msg
4132                 + (mInstanceId != null ? (" [SUB" + mInstanceId + "]") : ""));
4133     }
4134
4135     private void unsljLog(int response) {
4136         riljLog("[UNSL]< " + responseToString(response));
4137     }
4138
4139     private void unsljLogMore(int response, String more) {
4140         riljLog("[UNSL]< " + responseToString(response) + " " + more);
4141     }
4142
4143     private void unsljLogRet(int response, Object ret) {
4144         riljLog("[UNSL]< " + responseToString(response) + " " + retToString(response, ret));
4145     }
4146
4147     private void unsljLogvRet(int response, Object ret) {
4148         riljLogv("[UNSL]< " + responseToString(response) + " " + retToString(response, ret));
4149     }
4150
4151     private Object
4152     responseSsData(Parcel p) {
4153         int num;
4154         SsData ssData = new SsData();
4155
4156         ssData.serviceType = ssData.ServiceTypeFromRILInt(p.readInt());
4157         ssData.requestType = ssData.RequestTypeFromRILInt(p.readInt());
4158         ssData.teleserviceType = ssData.TeleserviceTypeFromRILInt(p.readInt());
4159         ssData.serviceClass = p.readInt(); // This is service class sent in the SS request.
4160         ssData.result = p.readInt(); // This is the result of the SS request.
4161         num = p.readInt();
4162
4163         if (ssData.serviceType.isTypeCF() &&
4164             ssData.requestType.isTypeInterrogation()) {
4165             ssData.cfInfo = new CallForwardInfo[num];
4166
4167             for (int i = 0; i < num; i++) {
4168                 ssData.cfInfo[i] = new CallForwardInfo();
4169
4170                 ssData.cfInfo[i].status = p.readInt();
4171                 ssData.cfInfo[i].reason = p.readInt();
4172                 ssData.cfInfo[i].serviceClass = p.readInt();
4173                 ssData.cfInfo[i].toa = p.readInt();
4174                 ssData.cfInfo[i].number = p.readString();
4175                 ssData.cfInfo[i].timeSeconds = p.readInt();
4176
4177                 riljLog("[SS Data] CF Info " + i + " : " +  ssData.cfInfo[i]);
4178             }
4179         } else {
4180             ssData.ssInfo = new int[num];
4181             for (int i = 0; i < num; i++) {
4182                 ssData.ssInfo[i] = p.readInt();
4183                 riljLog("[SS Data] SS Info " + i + " : " +  ssData.ssInfo[i]);
4184             }
4185         }
4186
4187         return ssData;
4188     }
4189
4190
4191     // ***** Methods for CDMA support
4192     @Override
4193     public void
4194     getDeviceIdentity(Message response) {
4195         RILRequest rr = RILRequest.obtain(RIL_REQUEST_DEVICE_IDENTITY, response);
4196
4197         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4198
4199         send(rr);
4200     }
4201
4202     @Override
4203     public void
4204     getCDMASubscription(Message response) {
4205         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_SUBSCRIPTION, response);
4206
4207         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4208
4209         send(rr);
4210     }
4211
4212     @Override
4213     public void setPhoneType(int phoneType) { // Called by CDMAPhone and GSMPhone constructor
4214         if (RILJ_LOGD) riljLog("setPhoneType=" + phoneType + " old value=" + mPhoneType);
4215         mPhoneType = phoneType;
4216     }
4217
4218     /**
4219      * {@inheritDoc}
4220      */
4221     @Override
4222     public void queryCdmaRoamingPreference(Message response) {
4223         RILRequest rr = RILRequest.obtain(
4224                 RILConstants.RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE, response);
4225
4226         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4227
4228         send(rr);
4229     }
4230
4231     /**
4232      * {@inheritDoc}
4233      */
4234     @Override
4235     public void setCdmaRoamingPreference(int cdmaRoamingType, Message response) {
4236         RILRequest rr = RILRequest.obtain(
4237                 RILConstants.RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE, response);
4238
4239         rr.mParcel.writeInt(1);
4240         rr.mParcel.writeInt(cdmaRoamingType);
4241
4242         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4243                 + " : " + cdmaRoamingType);
4244
4245         send(rr);
4246     }
4247
4248     /**
4249      * {@inheritDoc}
4250      */
4251     @Override
4252     public void setCdmaSubscriptionSource(int cdmaSubscription , Message response) {
4253         RILRequest rr = RILRequest.obtain(
4254                 RILConstants.RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE, response);
4255
4256         rr.mParcel.writeInt(1);
4257         rr.mParcel.writeInt(cdmaSubscription);
4258
4259         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4260                 + " : " + cdmaSubscription);
4261
4262         send(rr);
4263     }
4264
4265     /**
4266      * {@inheritDoc}
4267      */
4268     @Override
4269     public void getCdmaSubscriptionSource(Message response) {
4270         RILRequest rr = RILRequest.obtain(
4271                 RILConstants.RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE, response);
4272
4273         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4274
4275         send(rr);
4276     }
4277
4278     /**
4279      * {@inheritDoc}
4280      */
4281     @Override
4282     public void queryTTYMode(Message response) {
4283         RILRequest rr = RILRequest.obtain(
4284                 RILConstants.RIL_REQUEST_QUERY_TTY_MODE, response);
4285
4286         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4287
4288         send(rr);
4289     }
4290
4291     /**
4292      * {@inheritDoc}
4293      */
4294     @Override
4295     public void setTTYMode(int ttyMode, Message response) {
4296         RILRequest rr = RILRequest.obtain(
4297                 RILConstants.RIL_REQUEST_SET_TTY_MODE, response);
4298
4299         rr.mParcel.writeInt(1);
4300         rr.mParcel.writeInt(ttyMode);
4301
4302         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4303                 + " : " + ttyMode);
4304
4305         send(rr);
4306     }
4307
4308     /**
4309      * {@inheritDoc}
4310      */
4311     @Override
4312     public void
4313     sendCDMAFeatureCode(String FeatureCode, Message response) {
4314         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_FLASH, response);
4315
4316         rr.mParcel.writeString(FeatureCode);
4317
4318         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4319                 + " : " + FeatureCode);
4320
4321         send(rr);
4322     }
4323
4324     @Override
4325     public void getCdmaBroadcastConfig(Message response) {
4326         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_GET_BROADCAST_CONFIG, response);
4327
4328         send(rr);
4329     }
4330
4331     @Override
4332     public void setCdmaBroadcastConfig(CdmaSmsBroadcastConfigInfo[] configs, Message response) {
4333         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_SET_BROADCAST_CONFIG, response);
4334
4335         // Convert to 1 service category per config (the way RIL takes is)
4336         ArrayList<CdmaSmsBroadcastConfigInfo> processedConfigs =
4337             new ArrayList<CdmaSmsBroadcastConfigInfo>();
4338         for (CdmaSmsBroadcastConfigInfo config : configs) {
4339             for (int i = config.getFromServiceCategory(); i <= config.getToServiceCategory(); i++) {
4340                 processedConfigs.add(new CdmaSmsBroadcastConfigInfo(i,
4341                         i,
4342                         config.getLanguage(),
4343                         config.isSelected()));
4344             }
4345         }
4346
4347         CdmaSmsBroadcastConfigInfo[] rilConfigs = processedConfigs.toArray(configs);
4348         rr.mParcel.writeInt(rilConfigs.length);
4349         for(int i = 0; i < rilConfigs.length; i++) {
4350             rr.mParcel.writeInt(rilConfigs[i].getFromServiceCategory());
4351             rr.mParcel.writeInt(rilConfigs[i].getLanguage());
4352             rr.mParcel.writeInt(rilConfigs[i].isSelected() ? 1 : 0);
4353         }
4354
4355         if (RILJ_LOGD) {
4356             riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4357                     + " with " + rilConfigs.length + " configs : ");
4358             for (int i = 0; i < rilConfigs.length; i++) {
4359                 riljLog(rilConfigs[i].toString());
4360             }
4361         }
4362
4363         send(rr);
4364     }
4365
4366     @Override
4367     public void setCdmaBroadcastActivation(boolean activate, Message response) {
4368         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_BROADCAST_ACTIVATION, response);
4369
4370         rr.mParcel.writeInt(1);
4371         rr.mParcel.writeInt(activate ? 0 :1);
4372
4373         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4374
4375         send(rr);
4376     }
4377
4378     /**
4379      * {@inheritDoc}
4380      */
4381     @Override
4382     public void exitEmergencyCallbackMode(Message response) {
4383         RILRequest rr = RILRequest.obtain(RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE, response);
4384
4385         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4386
4387         send(rr);
4388     }
4389
4390     @Override
4391     public void requestIsimAuthentication(String nonce, Message response) {
4392         RILRequest rr = RILRequest.obtain(RIL_REQUEST_ISIM_AUTHENTICATION, response);
4393
4394         rr.mParcel.writeString(nonce);
4395
4396         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4397
4398         send(rr);
4399     }
4400
4401     @Override
4402     public void requestIccSimAuthentication(int authContext, String data, String aid,
4403                                             Message response) {
4404         RILRequest rr = RILRequest.obtain(RIL_REQUEST_SIM_AUTHENTICATION, response);
4405
4406         rr.mParcel.writeInt(authContext);
4407         rr.mParcel.writeString(data);
4408         rr.mParcel.writeString(aid);
4409
4410         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4411
4412         send(rr);
4413     }
4414
4415     /**
4416      * {@inheritDoc}
4417      */
4418     @Override
4419     public void getCellInfoList(Message result) {
4420         RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_CELL_INFO_LIST, result);
4421
4422         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4423
4424         send(rr);
4425     }
4426
4427     /**
4428      * {@inheritDoc}
4429      */
4430     @Override
4431     public void setCellInfoListRate(int rateInMillis, Message response) {
4432         if (RILJ_LOGD) riljLog("setCellInfoListRate: " + rateInMillis);
4433         RILRequest rr = RILRequest.obtain(RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE, response);
4434
4435         rr.mParcel.writeInt(1);
4436         rr.mParcel.writeInt(rateInMillis);
4437
4438         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4439
4440         send(rr);
4441     }
4442
4443     public void setInitialAttachApn(String apn, String protocol, int authType, String username,
4444             String password, Message result) {
4445         RILRequest rr = RILRequest.obtain(RIL_REQUEST_SET_INITIAL_ATTACH_APN, null);
4446
4447         if (RILJ_LOGD) riljLog("Set RIL_REQUEST_SET_INITIAL_ATTACH_APN");
4448
4449         rr.mParcel.writeString(apn);
4450         rr.mParcel.writeString(protocol);
4451         rr.mParcel.writeInt(authType);
4452         rr.mParcel.writeString(username);
4453         rr.mParcel.writeString(password);
4454
4455         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4456                 + ", apn:" + apn + ", protocol:" + protocol + ", authType:" + authType
4457                 + ", username:" + username + ", password:" + password);
4458
4459         send(rr);
4460     }
4461
4462     public void setDataProfile(DataProfile[] dps, Message result) {
4463         if (RILJ_LOGD) riljLog("Set RIL_REQUEST_SET_DATA_PROFILE");
4464
4465         RILRequest rr = RILRequest.obtain(RIL_REQUEST_SET_DATA_PROFILE, null);
4466         DataProfile.toParcel(rr.mParcel, dps);
4467
4468         if (RILJ_LOGD) {
4469             riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4470                     + " with " + dps + " Data Profiles : ");
4471             for (int i = 0; i < dps.length; i++) {
4472                 riljLog(dps[i].toString());
4473             }
4474         }
4475
4476         send(rr);
4477     }
4478
4479     /* (non-Javadoc)
4480      * @see com.android.internal.telephony.BaseCommands#testingEmergencyCall()
4481      */
4482     @Override
4483     public void testingEmergencyCall() {
4484         if (RILJ_LOGD) riljLog("testingEmergencyCall");
4485         mTestingEmergencyCall.set(true);
4486     }
4487
4488     public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
4489         pw.println("RIL: " + this);
4490         pw.println(" mSocket=" + mSocket);
4491         pw.println(" mSenderThread=" + mSenderThread);
4492         pw.println(" mSender=" + mSender);
4493         pw.println(" mReceiverThread=" + mReceiverThread);
4494         pw.println(" mReceiver=" + mReceiver);
4495         pw.println(" mWakeLock=" + mWakeLock);
4496         pw.println(" mWakeLockTimeout=" + mWakeLockTimeout);
4497         synchronized (mRequestList) {
4498             synchronized (mWakeLock) {
4499                 pw.println(" mWakeLockCount=" + mWakeLockCount);
4500             }
4501             int count = mRequestList.size();
4502             pw.println(" mRequestList count=" + count);
4503             for (int i = 0; i < count; i++) {
4504                 RILRequest rr = mRequestList.valueAt(i);
4505                 pw.println("  [" + rr.mSerial + "] " + requestToString(rr.mRequest));
4506             }
4507         }
4508         pw.println(" mLastNITZTimeInfo=" + mLastNITZTimeInfo);
4509         pw.println(" mTestingEmergencyCall=" + mTestingEmergencyCall.get());
4510     }
4511
4512     /**
4513      * {@inheritDoc}
4514      */
4515     @Override
4516     public void iccOpenLogicalChannel(String AID, Message response) {
4517         RILRequest rr = RILRequest.obtain(RIL_REQUEST_SIM_OPEN_CHANNEL, response);
4518         rr.mParcel.writeString(AID);
4519
4520         if (RILJ_LOGD)
4521             riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4522
4523         send(rr);
4524     }
4525
4526     /**
4527      * {@inheritDoc}
4528      */
4529     @Override
4530     public void iccCloseLogicalChannel(int channel, Message response) {
4531         RILRequest rr = RILRequest.obtain(RIL_REQUEST_SIM_CLOSE_CHANNEL, response);
4532         rr.mParcel.writeInt(1);
4533         rr.mParcel.writeInt(channel);
4534
4535         if (RILJ_LOGD)
4536             riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4537
4538         send(rr);
4539     }
4540
4541     /**
4542      * {@inheritDoc}
4543      */
4544     @Override
4545     public void iccTransmitApduLogicalChannel(int channel, int cla, int instruction,
4546             int p1, int p2, int p3, String data, Message response) {
4547         if (channel <= 0) {
4548             throw new RuntimeException(
4549                 "Invalid channel in iccTransmitApduLogicalChannel: " + channel);
4550         }
4551
4552         iccTransmitApduHelper(RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL, channel, cla,
4553                 instruction, p1, p2, p3, data, response);
4554     }
4555
4556     /**
4557      * {@inheritDoc}
4558      */
4559     @Override
4560     public void iccTransmitApduBasicChannel(int cla, int instruction, int p1, int p2,
4561             int p3, String data, Message response) {
4562         iccTransmitApduHelper(RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC, 0, cla, instruction,
4563                 p1, p2, p3, data, response);
4564     }
4565
4566     /*
4567      * Helper function for the iccTransmitApdu* commands above.
4568      */
4569     private void iccTransmitApduHelper(int rilCommand, int channel, int cla,
4570             int instruction, int p1, int p2, int p3, String data, Message response) {
4571         RILRequest rr = RILRequest.obtain(rilCommand, response);
4572         rr.mParcel.writeInt(channel);
4573         rr.mParcel.writeInt(cla);
4574         rr.mParcel.writeInt(instruction);
4575         rr.mParcel.writeInt(p1);
4576         rr.mParcel.writeInt(p2);
4577         rr.mParcel.writeInt(p3);
4578         rr.mParcel.writeString(data);
4579
4580         if (RILJ_LOGD)
4581             riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4582
4583         send(rr);
4584     }
4585
4586     @Override
4587     public void nvReadItem(int itemID, Message response) {
4588         RILRequest rr = RILRequest.obtain(RIL_REQUEST_NV_READ_ITEM, response);
4589
4590         rr.mParcel.writeInt(itemID);
4591
4592         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4593                 + ' ' + itemID);
4594
4595         send(rr);
4596     }
4597
4598     @Override
4599     public void nvWriteItem(int itemID, String itemValue, Message response) {
4600         RILRequest rr = RILRequest.obtain(RIL_REQUEST_NV_WRITE_ITEM, response);
4601
4602         rr.mParcel.writeInt(itemID);
4603         rr.mParcel.writeString(itemValue);
4604
4605         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4606                 + ' ' + itemID + ": " + itemValue);
4607
4608         send(rr);
4609     }
4610
4611     @Override
4612     public void nvWriteCdmaPrl(byte[] preferredRoamingList, Message response) {
4613         RILRequest rr = RILRequest.obtain(RIL_REQUEST_NV_WRITE_CDMA_PRL, response);
4614
4615         rr.mParcel.writeByteArray(preferredRoamingList);
4616
4617         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4618                 + " (" + preferredRoamingList.length + " bytes)");
4619
4620         send(rr);
4621     }
4622
4623     @Override
4624     public void nvResetConfig(int resetType, Message response) {
4625         RILRequest rr = RILRequest.obtain(RIL_REQUEST_NV_RESET_CONFIG, response);
4626
4627         rr.mParcel.writeInt(1);
4628         rr.mParcel.writeInt(resetType);
4629
4630         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4631                 + ' ' + resetType);
4632
4633         send(rr);
4634     }
4635
4636     @Override
4637     public void setRadioCapability(RadioCapability rc, Message response) {
4638         RILRequest rr = RILRequest.obtain(
4639                 RIL_REQUEST_SET_RADIO_CAPABILITY, response);
4640
4641         rr.mParcel.writeInt(rc.getVersion());
4642         rr.mParcel.writeInt(rc.getSession());
4643         rr.mParcel.writeInt(rc.getPhase());
4644         rr.mParcel.writeInt(rc.getRadioAccessFamily());
4645         rr.mParcel.writeString(rc.getLogicalModemUuid());
4646         rr.mParcel.writeInt(rc.getStatus());
4647
4648         if (RILJ_LOGD) {
4649             riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
4650                     + " " + rc.toString());
4651         }
4652
4653         send(rr);
4654     }
4655
4656     @Override
4657     public void getRadioCapability(Message response) {
4658         RILRequest rr = RILRequest.obtain(
4659                 RIL_REQUEST_GET_RADIO_CAPABILITY, response);
4660
4661         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
4662
4663         send(rr);
4664     }
4665 }