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