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