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