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