am e9b0fcbc: Merge "Telephony: Fix call forward info logging."
[android/platform/frameworks/opt/telephony.git] / src / java / com / android / internal / telephony / RIL.java
1 /*
2  * Copyright (C) 2006 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.android.internal.telephony;
18
19 import static com.android.internal.telephony.RILConstants.*;
20 import static android.telephony.TelephonyManager.NETWORK_TYPE_UNKNOWN;
21 import static android.telephony.TelephonyManager.NETWORK_TYPE_EDGE;
22 import static android.telephony.TelephonyManager.NETWORK_TYPE_GPRS;
23 import static android.telephony.TelephonyManager.NETWORK_TYPE_UMTS;
24 import static android.telephony.TelephonyManager.NETWORK_TYPE_HSDPA;
25 import static android.telephony.TelephonyManager.NETWORK_TYPE_HSUPA;
26 import static android.telephony.TelephonyManager.NETWORK_TYPE_HSPA;
27
28 import android.content.BroadcastReceiver;
29 import android.content.Context;
30 import android.content.Intent;
31 import android.content.IntentFilter;
32 import android.hardware.display.DisplayManager;
33 import android.net.ConnectivityManager;
34 import android.net.LocalSocket;
35 import android.net.LocalSocketAddress;
36 import android.os.AsyncResult;
37 import android.os.Handler;
38 import android.os.HandlerThread;
39 import android.os.Looper;
40 import android.os.Message;
41 import android.os.Parcel;
42 import android.os.PowerManager;
43 import android.os.SystemProperties;
44 import android.os.PowerManager.WakeLock;
45 import android.provider.Settings.SettingNotFoundException;
46 import android.telephony.CellInfo;
47 import android.telephony.NeighboringCellInfo;
48 import android.telephony.PhoneNumberUtils;
49 import android.telephony.Rlog;
50 import android.telephony.SignalStrength;
51 import android.telephony.SmsManager;
52 import android.telephony.SmsMessage;
53 import android.telephony.SubscriptionManager;
54 import android.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.cdma.CdmaCallWaitingNotification;
68 import com.android.internal.telephony.cdma.CdmaInformationRecords;
69 import com.android.internal.telephony.cdma.CdmaSmsBroadcastConfigInfo;
70 import com.android.internal.telephony.dataconnection.DcFailCause;
71 import com.android.internal.telephony.dataconnection.DataCallResponse;
72 import com.android.internal.telephony.dataconnection.DataProfile;
73 import com.android.internal.telephony.RadioCapability;
74 import com.android.internal.telephony.TelephonyDevController;
75 import com.android.internal.telephony.HardwareConfig;
76
77 import java.io.ByteArrayInputStream;
78 import java.io.DataInputStream;
79 import java.io.FileDescriptor;
80 import java.io.IOException;
81 import java.io.InputStream;
82 import java.io.PrintWriter;
83 import java.util.ArrayList;
84 import java.util.Collections;
85 import java.util.concurrent.atomic.AtomicBoolean;
86 import java.util.concurrent.atomic.AtomicInteger;
87 import java.util.Random;
88
89 /**
90  * {@hide}
91  */
92 class RILRequest {
93     static final String LOG_TAG = "RilRequest";
94
95     //***** Class Variables
96     static Random sRandom = new Random();
97     static AtomicInteger sNextSerial = new AtomicInteger(0);
98     private static Object sPoolSync = new Object();
99     private static RILRequest sPool = null;
100     private static int sPoolSize = 0;
101     private static final int MAX_POOL_SIZE = 4;
102     private Context mContext;
103
104     //***** Instance Variables
105     int mSerial;
106     int mRequest;
107     Message mResult;
108     Parcel mParcel;
109     RILRequest mNext;
110
111     /**
112      * Retrieves a new RILRequest instance from the pool.
113      *
114      * @param request RIL_REQUEST_*
115      * @param result sent when operation completes
116      * @return a RILRequest instance from the pool.
117      */
118     static RILRequest obtain(int request, Message result) {
119         RILRequest rr = null;
120
121         synchronized(sPoolSync) {
122             if (sPool != null) {
123                 rr = sPool;
124                 sPool = rr.mNext;
125                 rr.mNext = null;
126                 sPoolSize--;
127             }
128         }
129
130         if (rr == null) {
131             rr = new RILRequest();
132         }
133
134         rr.mSerial = sNextSerial.getAndIncrement();
135
136         rr.mRequest = request;
137         rr.mResult = result;
138         rr.mParcel = Parcel.obtain();
139
140         if (result != null && result.getTarget() == null) {
141             throw new NullPointerException("Message target must not be null");
142         }
143
144         // first elements in any RIL Parcel
145         rr.mParcel.writeInt(request);
146         rr.mParcel.writeInt(rr.mSerial);
147
148         return rr;
149     }
150
151     /**
152      * Returns a RILRequest instance to the pool.
153      *
154      * Note: This should only be called once per use.
155      */
156     void release() {
157         synchronized (sPoolSync) {
158             if (sPoolSize < MAX_POOL_SIZE) {
159                 mNext = sPool;
160                 sPool = this;
161                 sPoolSize++;
162                 mResult = null;
163             }
164         }
165     }
166
167     private RILRequest() {
168     }
169
170     static void
171     resetSerial() {
172         // use a random so that on recovery we probably don't mix old requests
173         // with new.
174         sNextSerial.set(sRandom.nextInt());
175     }
176
177     String
178     serialString() {
179         //Cheesy way to do %04d
180         StringBuilder sb = new StringBuilder(8);
181         String sn;
182
183         long adjustedSerial = (((long)mSerial) - Integer.MIN_VALUE)%10000;
184
185         sn = Long.toString(adjustedSerial);
186
187         //sb.append("J[");
188         sb.append('[');
189         for (int i = 0, s = sn.length() ; i < 4 - s; i++) {
190             sb.append('0');
191         }
192
193         sb.append(sn);
194         sb.append(']');
195         return sb.toString();
196     }
197
198     void
199     onError(int error, Object ret) {
200         CommandException ex;
201
202         ex = CommandException.fromRilErrno(error);
203
204         if (RIL.RILJ_LOGD) Rlog.d(LOG_TAG, serialString() + "< "
205             + RIL.requestToString(mRequest)
206             + " error: " + ex + " ret=" + RIL.retToString(mRequest, ret));
207
208         if (mResult != null) {
209             AsyncResult.forMessage(mResult, ret, ex);
210             mResult.sendToTarget();
211         }
212
213         if (mParcel != null) {
214             mParcel.recycle();
215             mParcel = null;
216         }
217     }
218 }
219
220
221 /**
222  * RIL implementation of the CommandsInterface.
223  *
224  * {@hide}
225  */
226 public final class RIL extends BaseCommands implements CommandsInterface {
227     static final String RILJ_LOG_TAG = "RILJ";
228     static final boolean RILJ_LOGD = true;
229     static final boolean RILJ_LOGV = false; // STOPSHIP if true
230
231     /**
232      * Wake lock timeout should be longer than the longest timeout in
233      * the vendor ril.
234      */
235     private static final int DEFAULT_WAKE_LOCK_TIMEOUT = 60000;
236
237     //***** Instance Variables
238
239     LocalSocket mSocket;
240     HandlerThread mSenderThread;
241     RILSender mSender;
242     Thread mReceiverThread;
243     RILReceiver mReceiver;
244     Display mDefaultDisplay;
245     int mDefaultDisplayState = Display.STATE_UNKNOWN;
246     WakeLock mWakeLock;
247     final int mWakeLockTimeout;
248     // The number of wakelock requests currently active.  Don't release the lock
249     // until dec'd to 0
250     int mWakeLockCount;
251
252     SparseArray<RILRequest> mRequestList = new SparseArray<RILRequest>();
253
254     Object     mLastNITZTimeInfo;
255
256     // When we are testing emergency calls
257     AtomicBoolean mTestingEmergencyCall = new AtomicBoolean(false);
258
259     private Integer mInstanceId;
260
261     //***** Events
262
263     static final int EVENT_SEND                 = 1;
264     static final int EVENT_WAKE_LOCK_TIMEOUT    = 2;
265
266     //***** Constants
267
268     // match with constant in ril.cpp
269     static final int RIL_MAX_COMMAND_BYTES = (8 * 1024);
270     static final int RESPONSE_SOLICITED = 0;
271     static final int RESPONSE_UNSOLICITED = 1;
272
273     static final String[] SOCKET_NAME_RIL = {"rild", "rild2", "rild3"};
274
275     static final int SOCKET_OPEN_RETRY_MILLIS = 4 * 1000;
276
277     // The number of the required config values for broadcast SMS stored in the C struct
278     // RIL_CDMA_BroadcastServiceInfo
279     private static final int CDMA_BSI_NO_OF_INTS_STRUCT = 3;
280
281     private static final int CDMA_BROADCAST_SMS_NO_OF_SERVICE_CATEGORIES = 31;
282
283     private final DisplayManager.DisplayListener mDisplayListener =
284             new DisplayManager.DisplayListener() {
285         @Override
286         public void onDisplayAdded(int displayId) { }
287
288         @Override
289         public void onDisplayRemoved(int displayId) { }
290
291         @Override
292         public void onDisplayChanged(int displayId) {
293             if (displayId == Display.DEFAULT_DISPLAY) {
294                 updateScreenState();
295             }
296         }
297     };
298
299     class RILSender extends Handler implements Runnable {
300         public RILSender(Looper looper) {
301             super(looper);
302         }
303
304         // Only allocated once
305         byte[] dataLength = new byte[4];
306
307         //***** Runnable implementation
308         @Override
309         public void
310         run() {
311             //setup if needed
312         }
313
314
315         //***** Handler implementation
316         @Override public void
317         handleMessage(Message msg) {
318             RILRequest rr = (RILRequest)(msg.obj);
319             RILRequest req = null;
320
321             switch (msg.what) {
322                 case EVENT_SEND:
323                     try {
324                         LocalSocket s;
325
326                         s = mSocket;
327
328                         if (s == null) {
329                             rr.onError(RADIO_NOT_AVAILABLE, null);
330                             rr.release();
331                             decrementWakeLock();
332                             return;
333                         }
334
335                         synchronized (mRequestList) {
336                             mRequestList.append(rr.mSerial, rr);
337                         }
338
339                         byte[] data;
340
341                         data = rr.mParcel.marshall();
342                         rr.mParcel.recycle();
343                         rr.mParcel = null;
344
345                         if (data.length > RIL_MAX_COMMAND_BYTES) {
346                             throw new RuntimeException(
347                                     "Parcel larger than max bytes allowed! "
348                                                           + data.length);
349                         }
350
351                         // parcel length in big endian
352                         dataLength[0] = dataLength[1] = 0;
353                         dataLength[2] = (byte)((data.length >> 8) & 0xff);
354                         dataLength[3] = (byte)((data.length) & 0xff);
355
356                         //Rlog.v(RILJ_LOG_TAG, "writing packet: " + data.length + " bytes");
357
358                         s.getOutputStream().write(dataLength);
359                         s.getOutputStream().write(data);
360                     } catch (IOException ex) {
361                         Rlog.e(RILJ_LOG_TAG, "IOException", ex);
362                         req = findAndRemoveRequestFromList(rr.mSerial);
363                         // make sure this request has not already been handled,
364                         // eg, if RILReceiver cleared the list.
365                         if (req != null) {
366                             rr.onError(RADIO_NOT_AVAILABLE, null);
367                             rr.release();
368                             decrementWakeLock();
369                         }
370                     } catch (RuntimeException exc) {
371                         Rlog.e(RILJ_LOG_TAG, "Uncaught exception ", exc);
372                         req = findAndRemoveRequestFromList(rr.mSerial);
373                         // make sure this request has not already been handled,
374                         // eg, if RILReceiver cleared the list.
375                         if (req != null) {
376                             rr.onError(GENERIC_FAILURE, null);
377                             rr.release();
378                             decrementWakeLock();
379                         }
380                     }
381
382                     break;
383
384                 case EVENT_WAKE_LOCK_TIMEOUT:
385                     // Haven't heard back from the last request.  Assume we're
386                     // not getting a response and  release the wake lock.
387
388                     // The timer of WAKE_LOCK_TIMEOUT is reset with each
389                     // new send request. So when WAKE_LOCK_TIMEOUT occurs
390                     // all requests in mRequestList already waited at
391                     // least DEFAULT_WAKE_LOCK_TIMEOUT but no response.
392                     //
393                     // Note: Keep mRequestList so that delayed response
394                     // can still be handled when response finally comes.
395
396                     synchronized (mRequestList) {
397                         if (clearWakeLock()) {
398                             if (RILJ_LOGD) {
399                                 int count = mRequestList.size();
400                                 Rlog.d(RILJ_LOG_TAG, "WAKE_LOCK_TIMEOUT " +
401                                         " mRequestList=" + count);
402                                 for (int i = 0; i < count; i++) {
403                                     rr = mRequestList.valueAt(i);
404                                     Rlog.d(RILJ_LOG_TAG, i + ": [" + rr.mSerial + "] "
405                                             + requestToString(rr.mRequest));
406                                 }
407                             }
408                         }
409                     }
410                     break;
411             }
412         }
413     }
414
415     /**
416      * Reads in a single RIL message off the wire. A RIL message consists
417      * of a 4-byte little-endian length and a subsequent series of bytes.
418      * The final message (length header omitted) is read into
419      * <code>buffer</code> and the length of the final message (less header)
420      * is returned. A return value of -1 indicates end-of-stream.
421      *
422      * @param is non-null; Stream to read from
423      * @param buffer Buffer to fill in. Must be as large as maximum
424      * message size, or an ArrayOutOfBounds exception will be thrown.
425      * @return Length of message less header, or -1 on end of stream.
426      * @throws IOException
427      */
428     private static int readRilMessage(InputStream is, byte[] buffer)
429             throws IOException {
430         int countRead;
431         int offset;
432         int remaining;
433         int messageLength;
434
435         // First, read in the length of the message
436         offset = 0;
437         remaining = 4;
438         do {
439             countRead = is.read(buffer, offset, remaining);
440
441             if (countRead < 0 ) {
442                 Rlog.e(RILJ_LOG_TAG, "Hit EOS reading message length");
443                 return -1;
444             }
445
446             offset += countRead;
447             remaining -= countRead;
448         } while (remaining > 0);
449
450         messageLength = ((buffer[0] & 0xff) << 24)
451                 | ((buffer[1] & 0xff) << 16)
452                 | ((buffer[2] & 0xff) << 8)
453                 | (buffer[3] & 0xff);
454
455         // Then, re-use the buffer and read in the message itself
456         offset = 0;
457         remaining = messageLength;
458         do {
459             countRead = is.read(buffer, offset, remaining);
460
461             if (countRead < 0 ) {
462                 Rlog.e(RILJ_LOG_TAG, "Hit EOS reading message.  messageLength=" + messageLength
463                         + " remaining=" + remaining);
464                 return -1;
465             }
466
467             offset += countRead;
468             remaining -= countRead;
469         } while (remaining > 0);
470
471         return messageLength;
472     }
473
474     class RILReceiver implements Runnable {
475         byte[] buffer;
476
477         RILReceiver() {
478             buffer = new byte[RIL_MAX_COMMAND_BYTES];
479         }
480
481         @Override
482         public void
483         run() {
484             int retryCount = 0;
485             String rilSocket = "rild";
486
487             try {for (;;) {
488                 LocalSocket s = null;
489                 LocalSocketAddress l;
490
491                 if (mInstanceId == null || mInstanceId == 0 ) {
492                     rilSocket = SOCKET_NAME_RIL[0];
493                 } else {
494                     rilSocket = SOCKET_NAME_RIL[mInstanceId];
495                 }
496
497                 try {
498                     s = new LocalSocket();
499                     l = new LocalSocketAddress(rilSocket,
500                             LocalSocketAddress.Namespace.RESERVED);
501                     s.connect(l);
502                 } catch (IOException ex){
503                     try {
504                         if (s != null) {
505                             s.close();
506                         }
507                     } catch (IOException ex2) {
508                         //ignore failure to close after failure to connect
509                     }
510
511                     // don't print an error message after the the first time
512                     // or after the 8th time
513
514                     if (retryCount == 8) {
515                         Rlog.e (RILJ_LOG_TAG,
516                             "Couldn't find '" + rilSocket
517                             + "' socket after " + retryCount
518                             + " times, continuing to retry silently");
519                     } else if (retryCount >= 0 && retryCount < 8) {
520                         Rlog.i (RILJ_LOG_TAG,
521                             "Couldn't find '" + rilSocket
522                             + "' socket; retrying after timeout");
523                     }
524
525                     try {
526                         Thread.sleep(SOCKET_OPEN_RETRY_MILLIS);
527                     } catch (InterruptedException er) {
528                     }
529
530                     retryCount++;
531                     continue;
532                 }
533
534                 retryCount = 0;
535
536                 mSocket = s;
537                 Rlog.i(RILJ_LOG_TAG, "(" + mInstanceId + ") Connected to '"
538                         + rilSocket + "' socket");
539
540                 int length = 0;
541                 try {
542                     InputStream is = mSocket.getInputStream();
543
544                     for (;;) {
545                         Parcel p;
546
547                         length = readRilMessage(is, buffer);
548
549                         if (length < 0) {
550                             // End-of-stream reached
551                             break;
552                         }
553
554                         p = Parcel.obtain();
555                         p.unmarshall(buffer, 0, length);
556                         p.setDataPosition(0);
557
558                         //Rlog.v(RILJ_LOG_TAG, "Read packet: " + length + " bytes");
559
560                         processResponse(p);
561                         p.recycle();
562                     }
563                 } catch (java.io.IOException ex) {
564                     Rlog.i(RILJ_LOG_TAG, "'" + rilSocket + "' socket closed",
565                           ex);
566                 } catch (Throwable tr) {
567                     Rlog.e(RILJ_LOG_TAG, "Uncaught exception read length=" + length +
568                         "Exception:" + tr.toString());
569                 }
570
571                 Rlog.i(RILJ_LOG_TAG, "(" + mInstanceId + ") Disconnected from '" + rilSocket
572                       + "' socket");
573
574                 setRadioState (RadioState.RADIO_UNAVAILABLE);
575
576                 try {
577                     mSocket.close();
578                 } catch (IOException ex) {
579                 }
580
581                 mSocket = null;
582                 RILRequest.resetSerial();
583
584                 // Clear request list on close
585                 clearRequestList(RADIO_NOT_AVAILABLE, false);
586             }} catch (Throwable tr) {
587                 Rlog.e(RILJ_LOG_TAG,"Uncaught exception", tr);
588             }
589
590             /* We're disconnected so we don't know the ril version */
591             notifyRegistrantsRilConnectionChanged(-1);
592         }
593     }
594
595
596
597     //***** Constructors
598
599     public RIL(Context context, int preferredNetworkType, int cdmaSubscription) {
600         this(context, preferredNetworkType, cdmaSubscription, null);
601     }
602
603     public RIL(Context context, int preferredNetworkType,
604             int cdmaSubscription, Integer instanceId) {
605         super(context);
606         if (RILJ_LOGD) {
607             riljLog("RIL(context, preferredNetworkType=" + preferredNetworkType +
608                     " cdmaSubscription=" + cdmaSubscription + ")");
609         }
610
611         mContext = context;
612         mCdmaSubscription  = cdmaSubscription;
613         mPreferredNetworkType = preferredNetworkType;
614         mPhoneType = RILConstants.NO_PHONE;
615         mInstanceId = instanceId;
616
617         PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
618         mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, RILJ_LOG_TAG);
619         mWakeLock.setReferenceCounted(false);
620         mWakeLockTimeout = SystemProperties.getInt(TelephonyProperties.PROPERTY_WAKE_LOCK_TIMEOUT,
621                 DEFAULT_WAKE_LOCK_TIMEOUT);
622         mWakeLockCount = 0;
623
624         mSenderThread = new HandlerThread("RILSender" + mInstanceId);
625         mSenderThread.start();
626
627         Looper looper = mSenderThread.getLooper();
628         mSender = new RILSender(looper);
629
630         ConnectivityManager cm = (ConnectivityManager)context.getSystemService(
631                 Context.CONNECTIVITY_SERVICE);
632         if (cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE) == false) {
633             riljLog("Not starting RILReceiver: wifi-only");
634         } else {
635             riljLog("Starting RILReceiver" + mInstanceId);
636             mReceiver = new RILReceiver();
637             mReceiverThread = new Thread(mReceiver, "RILReceiver" + mInstanceId);
638             mReceiverThread.start();
639
640             DisplayManager dm = (DisplayManager)context.getSystemService(
641                     Context.DISPLAY_SERVICE);
642             mDefaultDisplay = dm.getDisplay(Display.DEFAULT_DISPLAY);
643             dm.registerDisplayListener(mDisplayListener, null);
644         }
645
646         TelephonyDevController tdc = TelephonyDevController.getInstance();
647         tdc.registerRIL(this);
648     }
649
650     //***** CommandsInterface implementation
651
652     @Override
653     public void getVoiceRadioTechnology(Message result) {
654         RILRequest rr = RILRequest.obtain(RIL_REQUEST_VOICE_RADIO_TECH, result);
655
656         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
657
658         send(rr);
659     }
660
661
662     public void getImsRegistrationState(Message result) {
663         RILRequest rr = RILRequest.obtain(RIL_REQUEST_IMS_REGISTRATION_STATE, result);
664
665         if (RILJ_LOGD) {
666             riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
667         }
668         send(rr);
669     }
670
671     @Override public void
672     setOnNITZTime(Handler h, int what, Object obj) {
673         super.setOnNITZTime(h, what, obj);
674
675         // Send the last NITZ time if we have it
676         if (mLastNITZTimeInfo != null) {
677             mNITZTimeRegistrant
678                 .notifyRegistrant(
679                     new AsyncResult (null, mLastNITZTimeInfo, null));
680         }
681     }
682
683     @Override
684     public void
685     getIccCardStatus(Message result) {
686         //Note: This RIL request has not been renamed to ICC,
687         //       but this request is also valid for SIM and RUIM
688         RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_SIM_STATUS, result);
689
690         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
691
692         send(rr);
693     }
694
695     public void setUiccSubscription(int slotId, int appIndex, int subId,
696             int subStatus, Message result) {
697         //Note: This RIL request is also valid for SIM and RUIM (ICC card)
698         RILRequest rr = RILRequest.obtain(RIL_REQUEST_SET_UICC_SUBSCRIPTION, result);
699
700         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
701                 + " slot: " + slotId + " appIndex: " + appIndex
702                 + " subId: " + subId + " subStatus: " + subStatus);
703
704         rr.mParcel.writeInt(slotId);
705         rr.mParcel.writeInt(appIndex);
706         rr.mParcel.writeInt(subId);
707         rr.mParcel.writeInt(subStatus);
708
709         send(rr);
710     }
711
712     // FIXME This API should take an AID and slot ID
713     public void setDataAllowed(boolean allowed, Message result) {
714         RILRequest rr = RILRequest.obtain(RIL_REQUEST_ALLOW_DATA, result);
715         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
716
717         rr.mParcel.writeInt(1);
718         rr.mParcel.writeInt(allowed ? 1 : 0);
719         send(rr);
720     }
721
722     @Override public void
723     supplyIccPin(String pin, Message result) {
724         supplyIccPinForApp(pin, null, result);
725     }
726
727     @Override public void
728     supplyIccPinForApp(String pin, String aid, Message result) {
729         //Note: This RIL request has not been renamed to ICC,
730         //       but this request is also valid for SIM and RUIM
731         RILRequest rr = RILRequest.obtain(RIL_REQUEST_ENTER_SIM_PIN, result);
732
733         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
734
735         rr.mParcel.writeInt(2);
736         rr.mParcel.writeString(pin);
737         rr.mParcel.writeString(aid);
738
739         send(rr);
740     }
741
742     @Override public void
743     supplyIccPuk(String puk, String newPin, Message result) {
744         supplyIccPukForApp(puk, newPin, null, result);
745     }
746
747     @Override public void
748     supplyIccPukForApp(String puk, String newPin, String aid, Message result) {
749         //Note: This RIL request has not been renamed to ICC,
750         //       but this request is also valid for SIM and RUIM
751         RILRequest rr = RILRequest.obtain(RIL_REQUEST_ENTER_SIM_PUK, result);
752
753         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
754
755         rr.mParcel.writeInt(3);
756         rr.mParcel.writeString(puk);
757         rr.mParcel.writeString(newPin);
758         rr.mParcel.writeString(aid);
759
760         send(rr);
761     }
762
763     @Override public void
764     supplyIccPin2(String pin, Message result) {
765         supplyIccPin2ForApp(pin, null, result);
766     }
767
768     @Override public void
769     supplyIccPin2ForApp(String pin, String aid, Message result) {
770         //Note: This RIL request has not been renamed to ICC,
771         //       but this request is also valid for SIM and RUIM
772         RILRequest rr = RILRequest.obtain(RIL_REQUEST_ENTER_SIM_PIN2, result);
773
774         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
775
776         rr.mParcel.writeInt(2);
777         rr.mParcel.writeString(pin);
778         rr.mParcel.writeString(aid);
779
780         send(rr);
781     }
782
783     @Override public void
784     supplyIccPuk2(String puk2, String newPin2, Message result) {
785         supplyIccPuk2ForApp(puk2, newPin2, null, result);
786     }
787
788     @Override public void
789     supplyIccPuk2ForApp(String puk, String newPin2, String aid, Message result) {
790         //Note: This RIL request has not been renamed to ICC,
791         //       but this request is also valid for SIM and RUIM
792         RILRequest rr = RILRequest.obtain(RIL_REQUEST_ENTER_SIM_PUK2, result);
793
794         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
795
796         rr.mParcel.writeInt(3);
797         rr.mParcel.writeString(puk);
798         rr.mParcel.writeString(newPin2);
799         rr.mParcel.writeString(aid);
800
801         send(rr);
802     }
803
804     @Override public void
805     changeIccPin(String oldPin, String newPin, Message result) {
806         changeIccPinForApp(oldPin, newPin, null, result);
807     }
808
809     @Override public void
810     changeIccPinForApp(String oldPin, String newPin, String aid, Message result) {
811         //Note: This RIL request has not been renamed to ICC,
812         //       but this request is also valid for SIM and RUIM
813         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CHANGE_SIM_PIN, result);
814
815         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
816
817         rr.mParcel.writeInt(3);
818         rr.mParcel.writeString(oldPin);
819         rr.mParcel.writeString(newPin);
820         rr.mParcel.writeString(aid);
821
822         send(rr);
823     }
824
825     @Override public void
826     changeIccPin2(String oldPin2, String newPin2, Message result) {
827         changeIccPin2ForApp(oldPin2, newPin2, null, result);
828     }
829
830     @Override public void
831     changeIccPin2ForApp(String oldPin2, String newPin2, String aid, Message result) {
832         //Note: This RIL request has not been renamed to ICC,
833         //       but this request is also valid for SIM and RUIM
834         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CHANGE_SIM_PIN2, result);
835
836         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
837
838         rr.mParcel.writeInt(3);
839         rr.mParcel.writeString(oldPin2);
840         rr.mParcel.writeString(newPin2);
841         rr.mParcel.writeString(aid);
842
843         send(rr);
844     }
845
846     @Override
847     public void
848     changeBarringPassword(String facility, String oldPwd, String newPwd, Message result) {
849         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CHANGE_BARRING_PASSWORD, result);
850
851         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
852
853         rr.mParcel.writeInt(3);
854         rr.mParcel.writeString(facility);
855         rr.mParcel.writeString(oldPwd);
856         rr.mParcel.writeString(newPwd);
857
858         send(rr);
859     }
860
861     @Override
862     public void
863     supplyNetworkDepersonalization(String netpin, Message result) {
864         RILRequest rr = RILRequest.obtain(RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION, result);
865
866         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
867
868         rr.mParcel.writeInt(1);
869         rr.mParcel.writeString(netpin);
870
871         send(rr);
872     }
873
874     @Override
875     public void
876     getCurrentCalls (Message result) {
877         RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_CURRENT_CALLS, result);
878
879         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
880
881         send(rr);
882     }
883
884     @Override
885     @Deprecated public void
886     getPDPContextList(Message result) {
887         getDataCallList(result);
888     }
889
890     @Override
891     public void
892     getDataCallList(Message result) {
893         RILRequest rr = RILRequest.obtain(RIL_REQUEST_DATA_CALL_LIST, result);
894
895         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
896
897         send(rr);
898     }
899
900     @Override
901     public void
902     dial (String address, int clirMode, Message result) {
903         dial(address, clirMode, null, result);
904     }
905
906     @Override
907     public void
908     dial(String address, int clirMode, UUSInfo uusInfo, Message result) {
909         RILRequest rr = RILRequest.obtain(RIL_REQUEST_DIAL, result);
910
911         rr.mParcel.writeString(address);
912         rr.mParcel.writeInt(clirMode);
913
914         if (uusInfo == null) {
915             rr.mParcel.writeInt(0); // UUS information is absent
916         } else {
917             rr.mParcel.writeInt(1); // UUS information is present
918             rr.mParcel.writeInt(uusInfo.getType());
919             rr.mParcel.writeInt(uusInfo.getDcs());
920             rr.mParcel.writeByteArray(uusInfo.getUserData());
921         }
922
923         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
924
925         send(rr);
926     }
927
928     @Override
929     public void
930     getIMSI(Message result) {
931         getIMSIForApp(null, result);
932     }
933
934     @Override
935     public void
936     getIMSIForApp(String aid, Message result) {
937         RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_IMSI, result);
938
939         rr.mParcel.writeInt(1);
940         rr.mParcel.writeString(aid);
941
942         if (RILJ_LOGD) riljLog(rr.serialString() +
943                               "> getIMSI: " + requestToString(rr.mRequest)
944                               + " aid: " + aid);
945
946         send(rr);
947     }
948
949     @Override
950     public void
951     getIMEI(Message result) {
952         RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_IMEI, result);
953
954         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
955
956         send(rr);
957     }
958
959     @Override
960     public void
961     getIMEISV(Message result) {
962         RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_IMEISV, result);
963
964         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
965
966         send(rr);
967     }
968
969
970     @Override
971     public void
972     hangupConnection (int gsmIndex, Message result) {
973         if (RILJ_LOGD) riljLog("hangupConnection: gsmIndex=" + gsmIndex);
974
975         RILRequest rr = RILRequest.obtain(RIL_REQUEST_HANGUP, result);
976
977         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " " +
978                 gsmIndex);
979
980         rr.mParcel.writeInt(1);
981         rr.mParcel.writeInt(gsmIndex);
982
983         send(rr);
984     }
985
986     @Override
987     public void
988     hangupWaitingOrBackground (Message result) {
989         RILRequest rr = RILRequest.obtain(RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND,
990                                         result);
991
992         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
993
994         send(rr);
995     }
996
997     @Override
998     public void
999     hangupForegroundResumeBackground (Message result) {
1000         RILRequest rr
1001                 = RILRequest.obtain(
1002                         RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND,
1003                                         result);
1004         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1005
1006         send(rr);
1007     }
1008
1009     @Override
1010     public void
1011     switchWaitingOrHoldingAndActive (Message result) {
1012         RILRequest rr
1013                 = RILRequest.obtain(
1014                         RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE,
1015                                         result);
1016         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1017
1018         send(rr);
1019     }
1020
1021     @Override
1022     public void
1023     conference (Message result) {
1024         RILRequest rr
1025                 = RILRequest.obtain(RIL_REQUEST_CONFERENCE, result);
1026
1027         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1028
1029         send(rr);
1030     }
1031
1032
1033     @Override
1034     public void setPreferredVoicePrivacy(boolean enable, Message result) {
1035         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE,
1036                 result);
1037
1038         rr.mParcel.writeInt(1);
1039         rr.mParcel.writeInt(enable ? 1:0);
1040
1041         send(rr);
1042     }
1043
1044     @Override
1045     public void getPreferredVoicePrivacy(Message result) {
1046         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE,
1047                 result);
1048         send(rr);
1049     }
1050
1051     @Override
1052     public void
1053     separateConnection (int gsmIndex, Message result) {
1054         RILRequest rr
1055                 = RILRequest.obtain(RIL_REQUEST_SEPARATE_CONNECTION, result);
1056
1057         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1058                             + " " + gsmIndex);
1059
1060         rr.mParcel.writeInt(1);
1061         rr.mParcel.writeInt(gsmIndex);
1062
1063         send(rr);
1064     }
1065
1066     @Override
1067     public void
1068     acceptCall (Message result) {
1069         RILRequest rr
1070                 = RILRequest.obtain(RIL_REQUEST_ANSWER, result);
1071
1072         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1073
1074         send(rr);
1075     }
1076
1077     @Override
1078     public void
1079     rejectCall (Message result) {
1080         RILRequest rr
1081                 = RILRequest.obtain(RIL_REQUEST_UDUB, result);
1082
1083         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1084
1085         send(rr);
1086     }
1087
1088     @Override
1089     public void
1090     explicitCallTransfer (Message result) {
1091         RILRequest rr
1092                 = RILRequest.obtain(RIL_REQUEST_EXPLICIT_CALL_TRANSFER, result);
1093
1094         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1095
1096         send(rr);
1097     }
1098
1099     @Override
1100     public void
1101     getLastCallFailCause (Message result) {
1102         RILRequest rr
1103                 = RILRequest.obtain(RIL_REQUEST_LAST_CALL_FAIL_CAUSE, result);
1104
1105         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1106
1107         send(rr);
1108     }
1109
1110     /**
1111      * @deprecated
1112      */
1113     @Deprecated
1114     @Override
1115     public void
1116     getLastPdpFailCause (Message result) {
1117         getLastDataCallFailCause (result);
1118     }
1119
1120     /**
1121      * The preferred new alternative to getLastPdpFailCause
1122      */
1123     @Override
1124     public void
1125     getLastDataCallFailCause (Message result) {
1126         RILRequest rr
1127                 = RILRequest.obtain(RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE, result);
1128
1129         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1130
1131         send(rr);
1132     }
1133
1134     @Override
1135     public void
1136     setMute (boolean enableMute, Message response) {
1137         RILRequest rr
1138                 = RILRequest.obtain(RIL_REQUEST_SET_MUTE, response);
1139
1140         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1141                             + " " + enableMute);
1142
1143         rr.mParcel.writeInt(1);
1144         rr.mParcel.writeInt(enableMute ? 1 : 0);
1145
1146         send(rr);
1147     }
1148
1149     @Override
1150     public void
1151     getMute (Message response) {
1152         RILRequest rr
1153                 = RILRequest.obtain(RIL_REQUEST_GET_MUTE, response);
1154
1155         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1156
1157         send(rr);
1158     }
1159
1160     @Override
1161     public void
1162     getSignalStrength (Message result) {
1163         RILRequest rr
1164                 = RILRequest.obtain(RIL_REQUEST_SIGNAL_STRENGTH, result);
1165
1166         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1167
1168         send(rr);
1169     }
1170
1171     @Override
1172     public void
1173     getVoiceRegistrationState (Message result) {
1174         RILRequest rr
1175                 = RILRequest.obtain(RIL_REQUEST_VOICE_REGISTRATION_STATE, result);
1176
1177         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1178
1179         send(rr);
1180     }
1181
1182     @Override
1183     public void
1184     getDataRegistrationState (Message result) {
1185         RILRequest rr
1186                 = RILRequest.obtain(RIL_REQUEST_DATA_REGISTRATION_STATE, result);
1187
1188         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1189
1190         send(rr);
1191     }
1192
1193     @Override
1194     public void
1195     getOperator(Message result) {
1196         RILRequest rr
1197                 = RILRequest.obtain(RIL_REQUEST_OPERATOR, result);
1198
1199         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1200
1201         send(rr);
1202     }
1203
1204     @Override
1205     public void
1206     getHardwareConfig (Message result) {
1207         RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_HARDWARE_CONFIG, result);
1208
1209         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1210
1211         send(rr);
1212     }
1213
1214     @Override
1215     public void
1216     sendDtmf(char c, Message result) {
1217         RILRequest rr
1218                 = RILRequest.obtain(RIL_REQUEST_DTMF, result);
1219
1220         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1221
1222         rr.mParcel.writeString(Character.toString(c));
1223
1224         send(rr);
1225     }
1226
1227     @Override
1228     public void
1229     startDtmf(char c, Message result) {
1230         RILRequest rr
1231                 = RILRequest.obtain(RIL_REQUEST_DTMF_START, result);
1232
1233         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1234
1235         rr.mParcel.writeString(Character.toString(c));
1236
1237         send(rr);
1238     }
1239
1240     @Override
1241     public void
1242     stopDtmf(Message result) {
1243         RILRequest rr
1244                 = RILRequest.obtain(RIL_REQUEST_DTMF_STOP, result);
1245
1246         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1247
1248         send(rr);
1249     }
1250
1251     @Override
1252     public void
1253     sendBurstDtmf(String dtmfString, int on, int off, Message result) {
1254         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_BURST_DTMF, result);
1255
1256         rr.mParcel.writeInt(3);
1257         rr.mParcel.writeString(dtmfString);
1258         rr.mParcel.writeString(Integer.toString(on));
1259         rr.mParcel.writeString(Integer.toString(off));
1260
1261         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1262                 + " : " + dtmfString);
1263
1264         send(rr);
1265     }
1266
1267     private void
1268     constructGsmSendSmsRilRequest (RILRequest rr, String smscPDU, String pdu) {
1269         rr.mParcel.writeInt(2);
1270         rr.mParcel.writeString(smscPDU);
1271         rr.mParcel.writeString(pdu);
1272     }
1273
1274     public void
1275     sendSMS (String smscPDU, String pdu, Message result) {
1276         RILRequest rr
1277                 = RILRequest.obtain(RIL_REQUEST_SEND_SMS, result);
1278
1279         constructGsmSendSmsRilRequest(rr, smscPDU, pdu);
1280
1281         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1282
1283         send(rr);
1284     }
1285
1286     @Override
1287     public void
1288     sendSMSExpectMore (String smscPDU, String pdu, Message result) {
1289         RILRequest rr
1290                 = RILRequest.obtain(RIL_REQUEST_SEND_SMS_EXPECT_MORE, result);
1291
1292         constructGsmSendSmsRilRequest(rr, smscPDU, pdu);
1293
1294         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1295
1296         send(rr);
1297     }
1298
1299     private void
1300     constructCdmaSendSmsRilRequest(RILRequest rr, byte[] pdu) {
1301         int address_nbr_of_digits;
1302         int subaddr_nbr_of_digits;
1303         int bearerDataLength;
1304         ByteArrayInputStream bais = new ByteArrayInputStream(pdu);
1305         DataInputStream dis = new DataInputStream(bais);
1306
1307         try {
1308             rr.mParcel.writeInt(dis.readInt()); //teleServiceId
1309             rr.mParcel.writeByte((byte) dis.readInt()); //servicePresent
1310             rr.mParcel.writeInt(dis.readInt()); //serviceCategory
1311             rr.mParcel.writeInt(dis.read()); //address_digit_mode
1312             rr.mParcel.writeInt(dis.read()); //address_nbr_mode
1313             rr.mParcel.writeInt(dis.read()); //address_ton
1314             rr.mParcel.writeInt(dis.read()); //address_nbr_plan
1315             address_nbr_of_digits = (byte) dis.read();
1316             rr.mParcel.writeByte((byte) address_nbr_of_digits);
1317             for(int i=0; i < address_nbr_of_digits; i++){
1318                 rr.mParcel.writeByte(dis.readByte()); // address_orig_bytes[i]
1319             }
1320             rr.mParcel.writeInt(dis.read()); //subaddressType
1321             rr.mParcel.writeByte((byte) dis.read()); //subaddr_odd
1322             subaddr_nbr_of_digits = (byte) dis.read();
1323             rr.mParcel.writeByte((byte) subaddr_nbr_of_digits);
1324             for(int i=0; i < subaddr_nbr_of_digits; i++){
1325                 rr.mParcel.writeByte(dis.readByte()); //subaddr_orig_bytes[i]
1326             }
1327
1328             bearerDataLength = dis.read();
1329             rr.mParcel.writeInt(bearerDataLength);
1330             for(int i=0; i < bearerDataLength; i++){
1331                 rr.mParcel.writeByte(dis.readByte()); //bearerData[i]
1332             }
1333         }catch (IOException ex){
1334             if (RILJ_LOGD) riljLog("sendSmsCdma: conversion from input stream to object failed: "
1335                     + ex);
1336         }
1337     }
1338
1339     public void
1340     sendCdmaSms(byte[] pdu, Message result) {
1341         RILRequest rr
1342                 = RILRequest.obtain(RIL_REQUEST_CDMA_SEND_SMS, result);
1343
1344         constructCdmaSendSmsRilRequest(rr, pdu);
1345
1346         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1347
1348         send(rr);
1349     }
1350
1351     public void
1352     sendImsGsmSms (String smscPDU, String pdu, int retry, int messageRef,
1353             Message result) {
1354         RILRequest rr = RILRequest.obtain(RIL_REQUEST_IMS_SEND_SMS, result);
1355
1356         rr.mParcel.writeInt(RILConstants.GSM_PHONE);
1357         rr.mParcel.writeByte((byte)retry);
1358         rr.mParcel.writeInt(messageRef);
1359
1360         constructGsmSendSmsRilRequest(rr, smscPDU, pdu);
1361
1362         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1363
1364         send(rr);
1365     }
1366
1367     public void
1368     sendImsCdmaSms(byte[] pdu, int retry, int messageRef, Message result) {
1369         RILRequest rr = RILRequest.obtain(RIL_REQUEST_IMS_SEND_SMS, result);
1370
1371         rr.mParcel.writeInt(RILConstants.CDMA_PHONE);
1372         rr.mParcel.writeByte((byte)retry);
1373         rr.mParcel.writeInt(messageRef);
1374
1375         constructCdmaSendSmsRilRequest(rr, pdu);
1376
1377         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1378
1379         send(rr);
1380     }
1381
1382     @Override
1383     public void deleteSmsOnSim(int index, Message response) {
1384         RILRequest rr = RILRequest.obtain(RIL_REQUEST_DELETE_SMS_ON_SIM,
1385                 response);
1386
1387         rr.mParcel.writeInt(1);
1388         rr.mParcel.writeInt(index);
1389
1390         if (RILJ_LOGV) riljLog(rr.serialString() + "> "
1391                 + requestToString(rr.mRequest)
1392                 + " " + index);
1393
1394         send(rr);
1395     }
1396
1397     @Override
1398     public void deleteSmsOnRuim(int index, Message response) {
1399         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM,
1400                 response);
1401
1402         rr.mParcel.writeInt(1);
1403         rr.mParcel.writeInt(index);
1404
1405         if (RILJ_LOGV) riljLog(rr.serialString() + "> "
1406                 + requestToString(rr.mRequest)
1407                 + " " + index);
1408
1409         send(rr);
1410     }
1411
1412     @Override
1413     public void writeSmsToSim(int status, String smsc, String pdu, Message response) {
1414         status = translateStatus(status);
1415
1416         RILRequest rr = RILRequest.obtain(RIL_REQUEST_WRITE_SMS_TO_SIM,
1417                 response);
1418
1419         rr.mParcel.writeInt(status);
1420         rr.mParcel.writeString(pdu);
1421         rr.mParcel.writeString(smsc);
1422
1423         if (RILJ_LOGV) riljLog(rr.serialString() + "> "
1424                 + requestToString(rr.mRequest)
1425                 + " " + status);
1426
1427         send(rr);
1428     }
1429
1430     @Override
1431     public void writeSmsToRuim(int status, String pdu, Message response) {
1432         status = translateStatus(status);
1433
1434         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM,
1435                 response);
1436
1437         rr.mParcel.writeInt(status);
1438         rr.mParcel.writeString(pdu);
1439
1440         if (RILJ_LOGV) riljLog(rr.serialString() + "> "
1441                 + requestToString(rr.mRequest)
1442                 + " " + status);
1443
1444         send(rr);
1445     }
1446
1447     /**
1448      *  Translates EF_SMS status bits to a status value compatible with
1449      *  SMS AT commands.  See TS 27.005 3.1.
1450      */
1451     private int translateStatus(int status) {
1452         switch(status & 0x7) {
1453             case SmsManager.STATUS_ON_ICC_READ:
1454                 return 1;
1455             case SmsManager.STATUS_ON_ICC_UNREAD:
1456                 return 0;
1457             case SmsManager.STATUS_ON_ICC_SENT:
1458                 return 3;
1459             case SmsManager.STATUS_ON_ICC_UNSENT:
1460                 return 2;
1461         }
1462
1463         // Default to READ.
1464         return 1;
1465     }
1466
1467     @Override
1468     public void
1469     setupDataCall(String radioTechnology, String profile, String apn,
1470             String user, String password, String authType, String protocol,
1471             Message result) {
1472         RILRequest rr
1473                 = RILRequest.obtain(RIL_REQUEST_SETUP_DATA_CALL, result);
1474
1475         rr.mParcel.writeInt(7);
1476
1477         rr.mParcel.writeString(radioTechnology);
1478         rr.mParcel.writeString(profile);
1479         rr.mParcel.writeString(apn);
1480         rr.mParcel.writeString(user);
1481         rr.mParcel.writeString(password);
1482         rr.mParcel.writeString(authType);
1483         rr.mParcel.writeString(protocol);
1484
1485         if (RILJ_LOGD) riljLog(rr.serialString() + "> "
1486                 + requestToString(rr.mRequest) + " " + radioTechnology + " "
1487                 + profile + " " + apn + " " + user + " "
1488                 + password + " " + authType + " " + protocol);
1489
1490         send(rr);
1491     }
1492
1493     @Override
1494     public void
1495     deactivateDataCall(int cid, int reason, Message result) {
1496         RILRequest rr
1497                 = RILRequest.obtain(RIL_REQUEST_DEACTIVATE_DATA_CALL, result);
1498
1499         rr.mParcel.writeInt(2);
1500         rr.mParcel.writeString(Integer.toString(cid));
1501         rr.mParcel.writeString(Integer.toString(reason));
1502
1503         if (RILJ_LOGD) riljLog(rr.serialString() + "> " +
1504                 requestToString(rr.mRequest) + " " + cid + " " + reason);
1505
1506         send(rr);
1507     }
1508
1509     @Override
1510     public void
1511     setRadioPower(boolean on, Message result) {
1512         RILRequest rr = RILRequest.obtain(RIL_REQUEST_RADIO_POWER, result);
1513
1514         rr.mParcel.writeInt(1);
1515         rr.mParcel.writeInt(on ? 1 : 0);
1516
1517         if (RILJ_LOGD) {
1518             riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1519                     + (on ? " on" : " off"));
1520         }
1521
1522         send(rr);
1523     }
1524
1525     @Override
1526     public void requestShutdown(Message result) {
1527         RILRequest rr = RILRequest.obtain(RIL_REQUEST_SHUTDOWN, result);
1528
1529         if (RILJ_LOGD)
1530             riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1531
1532         send(rr);
1533     }
1534
1535     @Override
1536     public void
1537     setSuppServiceNotifications(boolean enable, Message result) {
1538         RILRequest rr
1539                 = RILRequest.obtain(RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION, result);
1540
1541         rr.mParcel.writeInt(1);
1542         rr.mParcel.writeInt(enable ? 1 : 0);
1543
1544         if (RILJ_LOGD) riljLog(rr.serialString() + "> "
1545                 + requestToString(rr.mRequest));
1546
1547         send(rr);
1548     }
1549
1550     @Override
1551     public void
1552     acknowledgeLastIncomingGsmSms(boolean success, int cause, Message result) {
1553         RILRequest rr
1554                 = RILRequest.obtain(RIL_REQUEST_SMS_ACKNOWLEDGE, result);
1555
1556         rr.mParcel.writeInt(2);
1557         rr.mParcel.writeInt(success ? 1 : 0);
1558         rr.mParcel.writeInt(cause);
1559
1560         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1561                 + " " + success + " " + cause);
1562
1563         send(rr);
1564     }
1565
1566     @Override
1567     public void
1568     acknowledgeLastIncomingCdmaSms(boolean success, int cause, Message result) {
1569         RILRequest rr
1570                 = RILRequest.obtain(RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE, result);
1571
1572         rr.mParcel.writeInt(success ? 0 : 1); //RIL_CDMA_SMS_ErrorClass
1573         // cause code according to X.S004-550E
1574         rr.mParcel.writeInt(cause);
1575
1576         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1577                 + " " + success + " " + cause);
1578
1579         send(rr);
1580     }
1581
1582     @Override
1583     public void
1584     acknowledgeIncomingGsmSmsWithPdu(boolean success, String ackPdu, Message result) {
1585         RILRequest rr
1586                 = RILRequest.obtain(RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU, result);
1587
1588         rr.mParcel.writeInt(2);
1589         rr.mParcel.writeString(success ? "1" : "0");
1590         rr.mParcel.writeString(ackPdu);
1591
1592         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1593                 + ' ' + success + " [" + ackPdu + ']');
1594
1595         send(rr);
1596     }
1597
1598     @Override
1599     public void
1600     iccIO (int command, int fileid, String path, int p1, int p2, int p3,
1601             String data, String pin2, Message result) {
1602         iccIOForApp(command, fileid, path, p1, p2, p3, data, pin2, null, result);
1603     }
1604     @Override
1605     public void
1606     iccIOForApp (int command, int fileid, String path, int p1, int p2, int p3,
1607             String data, String pin2, String aid, Message result) {
1608         //Note: This RIL request has not been renamed to ICC,
1609         //       but this request is also valid for SIM and RUIM
1610         RILRequest rr
1611                 = RILRequest.obtain(RIL_REQUEST_SIM_IO, result);
1612
1613         rr.mParcel.writeInt(command);
1614         rr.mParcel.writeInt(fileid);
1615         rr.mParcel.writeString(path);
1616         rr.mParcel.writeInt(p1);
1617         rr.mParcel.writeInt(p2);
1618         rr.mParcel.writeInt(p3);
1619         rr.mParcel.writeString(data);
1620         rr.mParcel.writeString(pin2);
1621         rr.mParcel.writeString(aid);
1622
1623         if (RILJ_LOGD) riljLog(rr.serialString() + "> iccIO: "
1624                 + requestToString(rr.mRequest)
1625                 + " 0x" + Integer.toHexString(command)
1626                 + " 0x" + Integer.toHexString(fileid) + " "
1627                 + " path: " + path + ","
1628                 + p1 + "," + p2 + "," + p3
1629                 + " aid: " + aid);
1630
1631         send(rr);
1632     }
1633
1634     @Override
1635     public void
1636     getCLIR(Message result) {
1637         RILRequest rr
1638                 = RILRequest.obtain(RIL_REQUEST_GET_CLIR, result);
1639
1640         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1641
1642         send(rr);
1643     }
1644
1645     @Override
1646     public void
1647     setCLIR(int clirMode, Message result) {
1648         RILRequest rr
1649                 = RILRequest.obtain(RIL_REQUEST_SET_CLIR, result);
1650
1651         // count ints
1652         rr.mParcel.writeInt(1);
1653
1654         rr.mParcel.writeInt(clirMode);
1655
1656         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1657                     + " " + clirMode);
1658
1659         send(rr);
1660     }
1661
1662     @Override
1663     public void
1664     queryCallWaiting(int serviceClass, Message response) {
1665         RILRequest rr
1666                 = RILRequest.obtain(RIL_REQUEST_QUERY_CALL_WAITING, response);
1667
1668         rr.mParcel.writeInt(1);
1669         rr.mParcel.writeInt(serviceClass);
1670
1671         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1672                     + " " + serviceClass);
1673
1674         send(rr);
1675     }
1676
1677     @Override
1678     public void
1679     setCallWaiting(boolean enable, int serviceClass, Message response) {
1680         RILRequest rr
1681                 = RILRequest.obtain(RIL_REQUEST_SET_CALL_WAITING, response);
1682
1683         rr.mParcel.writeInt(2);
1684         rr.mParcel.writeInt(enable ? 1 : 0);
1685         rr.mParcel.writeInt(serviceClass);
1686
1687         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1688                 + " " + enable + ", " + serviceClass);
1689
1690         send(rr);
1691     }
1692
1693     @Override
1694     public void
1695     setNetworkSelectionModeAutomatic(Message response) {
1696         RILRequest rr
1697                 = RILRequest.obtain(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC,
1698                                     response);
1699
1700         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1701
1702         send(rr);
1703     }
1704
1705     @Override
1706     public void
1707     setNetworkSelectionModeManual(String operatorNumeric, Message response) {
1708         RILRequest rr
1709                 = RILRequest.obtain(RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL,
1710                                     response);
1711
1712         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1713                     + " " + operatorNumeric);
1714
1715         rr.mParcel.writeString(operatorNumeric);
1716
1717         send(rr);
1718     }
1719
1720     @Override
1721     public void
1722     getNetworkSelectionMode(Message response) {
1723         RILRequest rr
1724                 = RILRequest.obtain(RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE,
1725                                     response);
1726
1727         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1728
1729         send(rr);
1730     }
1731
1732     @Override
1733     public void
1734     getAvailableNetworks(Message response) {
1735         RILRequest rr
1736                 = RILRequest.obtain(RIL_REQUEST_QUERY_AVAILABLE_NETWORKS,
1737                                     response);
1738
1739         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1740
1741         send(rr);
1742     }
1743
1744     @Override
1745     public void
1746     setCallForward(int action, int cfReason, int serviceClass,
1747                 String number, int timeSeconds, Message response) {
1748         RILRequest rr
1749                 = RILRequest.obtain(RIL_REQUEST_SET_CALL_FORWARD, response);
1750
1751         rr.mParcel.writeInt(action);
1752         rr.mParcel.writeInt(cfReason);
1753         rr.mParcel.writeInt(serviceClass);
1754         rr.mParcel.writeInt(PhoneNumberUtils.toaFromString(number));
1755         rr.mParcel.writeString(number);
1756         rr.mParcel.writeInt (timeSeconds);
1757
1758         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1759                     + " " + action + " " + cfReason + " " + serviceClass
1760                     + timeSeconds);
1761
1762         send(rr);
1763     }
1764
1765     @Override
1766     public void
1767     queryCallForwardStatus(int cfReason, int serviceClass,
1768                 String number, Message response) {
1769         RILRequest rr
1770             = RILRequest.obtain(RIL_REQUEST_QUERY_CALL_FORWARD_STATUS, response);
1771
1772         rr.mParcel.writeInt(2); // 2 is for query action, not in used anyway
1773         rr.mParcel.writeInt(cfReason);
1774         rr.mParcel.writeInt(serviceClass);
1775         rr.mParcel.writeInt(PhoneNumberUtils.toaFromString(number));
1776         rr.mParcel.writeString(number);
1777         rr.mParcel.writeInt (0);
1778
1779         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1780                 + " " + cfReason + " " + serviceClass);
1781
1782         send(rr);
1783     }
1784
1785     @Override
1786     public void
1787     queryCLIP(Message response) {
1788         RILRequest rr
1789             = RILRequest.obtain(RIL_REQUEST_QUERY_CLIP, response);
1790
1791         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1792
1793         send(rr);
1794     }
1795
1796
1797     @Override
1798     public void
1799     getBasebandVersion (Message response) {
1800         RILRequest rr
1801                 = RILRequest.obtain(RIL_REQUEST_BASEBAND_VERSION, response);
1802
1803         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1804
1805         send(rr);
1806     }
1807
1808     @Override
1809     public void
1810     queryFacilityLock(String facility, String password, int serviceClass,
1811                             Message response) {
1812         queryFacilityLockForApp(facility, password, serviceClass, null, response);
1813     }
1814
1815     @Override
1816     public void
1817     queryFacilityLockForApp(String facility, String password, int serviceClass, String appId,
1818                             Message response) {
1819         RILRequest rr = RILRequest.obtain(RIL_REQUEST_QUERY_FACILITY_LOCK, response);
1820
1821         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1822                                                  + " [" + facility + " " + serviceClass
1823                                                  + " " + appId + "]");
1824
1825         // count strings
1826         rr.mParcel.writeInt(4);
1827
1828         rr.mParcel.writeString(facility);
1829         rr.mParcel.writeString(password);
1830
1831         rr.mParcel.writeString(Integer.toString(serviceClass));
1832         rr.mParcel.writeString(appId);
1833
1834         send(rr);
1835     }
1836
1837     @Override
1838     public void
1839     setFacilityLock (String facility, boolean lockState, String password,
1840                         int serviceClass, Message response) {
1841         setFacilityLockForApp(facility, lockState, password, serviceClass, null, response);
1842     }
1843
1844     @Override
1845     public void
1846     setFacilityLockForApp(String facility, boolean lockState, String password,
1847                         int serviceClass, String appId, Message response) {
1848         String lockString;
1849          RILRequest rr
1850                 = RILRequest.obtain(RIL_REQUEST_SET_FACILITY_LOCK, response);
1851
1852         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1853                                                         + " [" + facility + " " + lockState
1854                                                         + " " + serviceClass + " " + appId + "]");
1855
1856         // count strings
1857         rr.mParcel.writeInt(5);
1858
1859         rr.mParcel.writeString(facility);
1860         lockString = (lockState)?"1":"0";
1861         rr.mParcel.writeString(lockString);
1862         rr.mParcel.writeString(password);
1863         rr.mParcel.writeString(Integer.toString(serviceClass));
1864         rr.mParcel.writeString(appId);
1865
1866         send(rr);
1867
1868     }
1869
1870     @Override
1871     public void
1872     sendUSSD (String ussdString, Message response) {
1873         RILRequest rr
1874                 = RILRequest.obtain(RIL_REQUEST_SEND_USSD, response);
1875
1876         if (RILJ_LOGD) {
1877             String logUssdString = "*******";
1878             if (RILJ_LOGV) logUssdString = ussdString;
1879             riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1880                                    + " " + logUssdString);
1881         }
1882
1883         rr.mParcel.writeString(ussdString);
1884
1885         send(rr);
1886     }
1887
1888     // inherited javadoc suffices
1889     @Override
1890     public void cancelPendingUssd (Message response) {
1891         RILRequest rr
1892                 = RILRequest.obtain(RIL_REQUEST_CANCEL_USSD, response);
1893
1894         if (RILJ_LOGD) riljLog(rr.serialString()
1895                 + "> " + requestToString(rr.mRequest));
1896
1897         send(rr);
1898     }
1899
1900
1901     @Override
1902     public void resetRadio(Message result) {
1903         RILRequest rr
1904                 = RILRequest.obtain(RIL_REQUEST_RESET_RADIO, result);
1905
1906         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1907
1908         send(rr);
1909     }
1910
1911     @Override
1912     public void invokeOemRilRequestRaw(byte[] data, Message response) {
1913         RILRequest rr
1914                 = RILRequest.obtain(RIL_REQUEST_OEM_HOOK_RAW, response);
1915
1916         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1917                + "[" + IccUtils.bytesToHexString(data) + "]");
1918
1919         rr.mParcel.writeByteArray(data);
1920
1921         send(rr);
1922
1923     }
1924
1925     @Override
1926     public void invokeOemRilRequestStrings(String[] strings, Message response) {
1927         RILRequest rr
1928                 = RILRequest.obtain(RIL_REQUEST_OEM_HOOK_STRINGS, response);
1929
1930         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1931
1932         rr.mParcel.writeStringArray(strings);
1933
1934         send(rr);
1935     }
1936
1937      /**
1938      * Assign a specified band for RF configuration.
1939      *
1940      * @param bandMode one of BM_*_BAND
1941      * @param response is callback message
1942      */
1943     @Override
1944     public void setBandMode (int bandMode, Message response) {
1945         RILRequest rr
1946                 = RILRequest.obtain(RIL_REQUEST_SET_BAND_MODE, response);
1947
1948         rr.mParcel.writeInt(1);
1949         rr.mParcel.writeInt(bandMode);
1950
1951         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
1952                  + " " + bandMode);
1953
1954         send(rr);
1955      }
1956
1957     /**
1958      * Query the list of band mode supported by RF.
1959      *
1960      * @param response is callback message
1961      *        ((AsyncResult)response.obj).result  is an int[] where int[0] is
1962      *        the size of the array and the rest of each element representing
1963      *        one available BM_*_BAND
1964      */
1965     @Override
1966     public void queryAvailableBandMode (Message response) {
1967         RILRequest rr
1968                 = RILRequest.obtain(RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE,
1969                 response);
1970
1971         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1972
1973         send(rr);
1974     }
1975
1976     /**
1977      * {@inheritDoc}
1978      */
1979     @Override
1980     public void sendTerminalResponse(String contents, Message response) {
1981         RILRequest rr = RILRequest.obtain(
1982                 RILConstants.RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE, response);
1983
1984         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1985
1986         rr.mParcel.writeString(contents);
1987         send(rr);
1988     }
1989
1990     /**
1991      * {@inheritDoc}
1992      */
1993     @Override
1994     public void sendEnvelope(String contents, Message response) {
1995         RILRequest rr = RILRequest.obtain(
1996                 RILConstants.RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND, response);
1997
1998         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
1999
2000         rr.mParcel.writeString(contents);
2001         send(rr);
2002     }
2003
2004     /**
2005      * {@inheritDoc}
2006      */
2007     @Override
2008     public void sendEnvelopeWithStatus(String contents, Message response) {
2009         RILRequest rr = RILRequest.obtain(
2010                 RILConstants.RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS, response);
2011
2012         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
2013                 + '[' + contents + ']');
2014
2015         rr.mParcel.writeString(contents);
2016         send(rr);
2017     }
2018
2019     /**
2020      * {@inheritDoc}
2021      */
2022     @Override
2023     public void handleCallSetupRequestFromSim(
2024             boolean accept, Message response) {
2025
2026         RILRequest rr = RILRequest.obtain(
2027             RILConstants.RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM,
2028             response);
2029
2030         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
2031
2032         int[] param = new int[1];
2033         param[0] = accept ? 1 : 0;
2034         rr.mParcel.writeIntArray(param);
2035         send(rr);
2036     }
2037
2038     /**
2039      * {@inheritDoc}
2040      */
2041     @Override
2042     public void setPreferredNetworkType(int networkType , Message response) {
2043         RILRequest rr = RILRequest.obtain(
2044                 RILConstants.RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE, response);
2045
2046         rr.mParcel.writeInt(1);
2047         rr.mParcel.writeInt(networkType);
2048
2049         mPreferredNetworkType = networkType;
2050
2051         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
2052                 + " : " + networkType);
2053
2054         send(rr);
2055     }
2056
2057     /**
2058      * {@inheritDoc}
2059      */
2060     @Override
2061     public void getPreferredNetworkType(Message response) {
2062         RILRequest rr = RILRequest.obtain(
2063                 RILConstants.RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE, response);
2064
2065         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
2066
2067         send(rr);
2068     }
2069
2070     /**
2071      * {@inheritDoc}
2072      */
2073     @Override
2074     public void getNeighboringCids(Message response) {
2075         RILRequest rr = RILRequest.obtain(
2076                 RILConstants.RIL_REQUEST_GET_NEIGHBORING_CELL_IDS, response);
2077
2078         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
2079
2080         send(rr);
2081     }
2082
2083     /**
2084      * {@inheritDoc}
2085      */
2086     @Override
2087     public void setLocationUpdates(boolean enable, Message response) {
2088         RILRequest rr = RILRequest.obtain(RIL_REQUEST_SET_LOCATION_UPDATES, response);
2089         rr.mParcel.writeInt(1);
2090         rr.mParcel.writeInt(enable ? 1 : 0);
2091
2092         if (RILJ_LOGD) riljLog(rr.serialString() + "> "
2093                 + requestToString(rr.mRequest) + ": " + enable);
2094
2095         send(rr);
2096     }
2097
2098     /**
2099      * {@inheritDoc}
2100      */
2101     @Override
2102     public void getSmscAddress(Message result) {
2103         RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_SMSC_ADDRESS, result);
2104
2105         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
2106
2107         send(rr);
2108     }
2109
2110     /**
2111      * {@inheritDoc}
2112      */
2113     @Override
2114     public void setSmscAddress(String address, Message result) {
2115         RILRequest rr = RILRequest.obtain(RIL_REQUEST_SET_SMSC_ADDRESS, result);
2116
2117         rr.mParcel.writeString(address);
2118
2119         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
2120                 + " : " + address);
2121
2122         send(rr);
2123     }
2124
2125     /**
2126      * {@inheritDoc}
2127      */
2128     @Override
2129     public void reportSmsMemoryStatus(boolean available, Message result) {
2130         RILRequest rr = RILRequest.obtain(RIL_REQUEST_REPORT_SMS_MEMORY_STATUS, result);
2131         rr.mParcel.writeInt(1);
2132         rr.mParcel.writeInt(available ? 1 : 0);
2133
2134         if (RILJ_LOGD) riljLog(rr.serialString() + "> "
2135                 + requestToString(rr.mRequest) + ": " + available);
2136
2137         send(rr);
2138     }
2139
2140     /**
2141      * {@inheritDoc}
2142      */
2143     @Override
2144     public void reportStkServiceIsRunning(Message result) {
2145         RILRequest rr = RILRequest.obtain(RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING, result);
2146
2147         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
2148
2149         send(rr);
2150     }
2151
2152     /**
2153      * {@inheritDoc}
2154      */
2155     @Override
2156     public void getGsmBroadcastConfig(Message response) {
2157         RILRequest rr = RILRequest.obtain(RIL_REQUEST_GSM_GET_BROADCAST_CONFIG, response);
2158
2159         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
2160
2161         send(rr);
2162     }
2163
2164     /**
2165      * {@inheritDoc}
2166      */
2167     @Override
2168     public void setGsmBroadcastConfig(SmsBroadcastConfigInfo[] config, Message response) {
2169         RILRequest rr = RILRequest.obtain(RIL_REQUEST_GSM_SET_BROADCAST_CONFIG, response);
2170
2171         int numOfConfig = config.length;
2172         rr.mParcel.writeInt(numOfConfig);
2173
2174         for(int i = 0; i < numOfConfig; i++) {
2175             rr.mParcel.writeInt(config[i].getFromServiceId());
2176             rr.mParcel.writeInt(config[i].getToServiceId());
2177             rr.mParcel.writeInt(config[i].getFromCodeScheme());
2178             rr.mParcel.writeInt(config[i].getToCodeScheme());
2179             rr.mParcel.writeInt(config[i].isSelected() ? 1 : 0);
2180         }
2181
2182         if (RILJ_LOGD) {
2183             riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
2184                     + " with " + numOfConfig + " configs : ");
2185             for (int i = 0; i < numOfConfig; i++) {
2186                 riljLog(config[i].toString());
2187             }
2188         }
2189
2190         send(rr);
2191     }
2192
2193     /**
2194      * {@inheritDoc}
2195      */
2196     @Override
2197     public void setGsmBroadcastActivation(boolean activate, Message response) {
2198         RILRequest rr = RILRequest.obtain(RIL_REQUEST_GSM_BROADCAST_ACTIVATION, response);
2199
2200         rr.mParcel.writeInt(1);
2201         rr.mParcel.writeInt(activate ? 0 : 1);
2202
2203         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
2204
2205         send(rr);
2206     }
2207
2208     //***** Private Methods
2209
2210     // TODO(jeffbrown): Delete me.
2211     // The RIL should *not* be listening for screen state changes since they are
2212     // becoming increasingly ambiguous on our devices.  The RIL_REQUEST_SCREEN_STATE
2213     // message should be deleted and replaced with more precise messages to control
2214     // behavior such as signal strength reporting or power managements based on
2215     // more robust signals.
2216     private void updateScreenState() {
2217         final int oldState = mDefaultDisplayState;
2218         mDefaultDisplayState = mDefaultDisplay.getState();
2219         if (mDefaultDisplayState != oldState) {
2220             if (oldState != Display.STATE_ON
2221                     && mDefaultDisplayState == Display.STATE_ON) {
2222                 sendScreenState(true);
2223             } else if ((oldState == Display.STATE_ON || oldState == Display.STATE_UNKNOWN)
2224                         && mDefaultDisplayState != Display.STATE_ON) {
2225                 sendScreenState(false);
2226             }
2227         }
2228     }
2229
2230     private void sendScreenState(boolean on) {
2231         RILRequest rr = RILRequest.obtain(RIL_REQUEST_SCREEN_STATE, null);
2232         rr.mParcel.writeInt(1);
2233         rr.mParcel.writeInt(on ? 1 : 0);
2234
2235         if (RILJ_LOGD) riljLog(rr.serialString()
2236                 + "> " + requestToString(rr.mRequest) + ": " + on);
2237
2238         send(rr);
2239     }
2240
2241     @Override
2242     protected void
2243     onRadioAvailable() {
2244         // In case screen state was lost (due to process crash),
2245         // this ensures that the RIL knows the correct screen state.
2246         updateScreenState();
2247    }
2248
2249     private RadioState getRadioStateFromInt(int stateInt) {
2250         RadioState state;
2251
2252         /* RIL_RadioState ril.h */
2253         switch(stateInt) {
2254             case 0: state = RadioState.RADIO_OFF; break;
2255             case 1: state = RadioState.RADIO_UNAVAILABLE; break;
2256             case 10: state = RadioState.RADIO_ON; break;
2257
2258             default:
2259                 throw new RuntimeException(
2260                             "Unrecognized RIL_RadioState: " + stateInt);
2261         }
2262         return state;
2263     }
2264
2265     private void switchToRadioState(RadioState newState) {
2266         setRadioState(newState);
2267     }
2268
2269     /**
2270      * Holds a PARTIAL_WAKE_LOCK whenever
2271      * a) There is outstanding RIL request sent to RIL deamon and no replied
2272      * b) There is a request pending to be sent out.
2273      *
2274      * There is a WAKE_LOCK_TIMEOUT to release the lock, though it shouldn't
2275      * happen often.
2276      */
2277
2278     private void
2279     acquireWakeLock() {
2280         synchronized (mWakeLock) {
2281             mWakeLock.acquire();
2282             mWakeLockCount++;
2283
2284             mSender.removeMessages(EVENT_WAKE_LOCK_TIMEOUT);
2285             Message msg = mSender.obtainMessage(EVENT_WAKE_LOCK_TIMEOUT);
2286             mSender.sendMessageDelayed(msg, mWakeLockTimeout);
2287         }
2288     }
2289
2290     private void
2291     decrementWakeLock() {
2292         synchronized (mWakeLock) {
2293             if (mWakeLockCount > 1) {
2294                 mWakeLockCount--;
2295             } else {
2296                 mWakeLockCount = 0;
2297                 mWakeLock.release();
2298                 mSender.removeMessages(EVENT_WAKE_LOCK_TIMEOUT);
2299             }
2300         }
2301     }
2302
2303     // true if we had the wakelock
2304     private boolean
2305     clearWakeLock() {
2306         synchronized (mWakeLock) {
2307             if (mWakeLockCount == 0 && mWakeLock.isHeld() == false) return false;
2308             Rlog.d(RILJ_LOG_TAG, "NOTE: mWakeLockCount is " + mWakeLockCount + "at time of clearing");
2309             mWakeLockCount = 0;
2310             mWakeLock.release();
2311             mSender.removeMessages(EVENT_WAKE_LOCK_TIMEOUT);
2312             return true;
2313         }
2314     }
2315
2316     private void
2317     send(RILRequest rr) {
2318         Message msg;
2319
2320         if (mSocket == null) {
2321             rr.onError(RADIO_NOT_AVAILABLE, null);
2322             rr.release();
2323             return;
2324         }
2325
2326         msg = mSender.obtainMessage(EVENT_SEND, rr);
2327
2328         acquireWakeLock();
2329
2330         msg.sendToTarget();
2331     }
2332
2333     private void
2334     processResponse (Parcel p) {
2335         int type;
2336
2337         type = p.readInt();
2338
2339         if (type == RESPONSE_UNSOLICITED) {
2340             processUnsolicited (p);
2341         } else if (type == RESPONSE_SOLICITED) {
2342             RILRequest rr = processSolicited (p);
2343             if (rr != null) {
2344                 rr.release();
2345                 decrementWakeLock();
2346             }
2347         }
2348     }
2349
2350     /**
2351      * Release each request in mRequestList then clear the list
2352      * @param error is the RIL_Errno sent back
2353      * @param loggable true means to print all requests in mRequestList
2354      */
2355     private void clearRequestList(int error, boolean loggable) {
2356         RILRequest rr;
2357         synchronized (mRequestList) {
2358             int count = mRequestList.size();
2359             if (RILJ_LOGD && loggable) {
2360                 Rlog.d(RILJ_LOG_TAG, "clearRequestList " +
2361                         " mWakeLockCount=" + mWakeLockCount +
2362                         " mRequestList=" + count);
2363             }
2364
2365             for (int i = 0; i < count ; i++) {
2366                 rr = mRequestList.valueAt(i);
2367                 if (RILJ_LOGD && loggable) {
2368                     Rlog.d(RILJ_LOG_TAG, i + ": [" + rr.mSerial + "] " +
2369                             requestToString(rr.mRequest));
2370                 }
2371                 rr.onError(error, null);
2372                 rr.release();
2373                 decrementWakeLock();
2374             }
2375             mRequestList.clear();
2376         }
2377     }
2378
2379     private RILRequest findAndRemoveRequestFromList(int serial) {
2380         RILRequest rr = null;
2381         synchronized (mRequestList) {
2382             rr = mRequestList.get(serial);
2383             if (rr != null) {
2384                 mRequestList.remove(serial);
2385             }
2386         }
2387
2388         return rr;
2389     }
2390
2391     private RILRequest
2392     processSolicited (Parcel p) {
2393         int serial, error;
2394         boolean found = false;
2395
2396         serial = p.readInt();
2397         error = p.readInt();
2398
2399         RILRequest rr;
2400
2401         rr = findAndRemoveRequestFromList(serial);
2402
2403         if (rr == null) {
2404             Rlog.w(RILJ_LOG_TAG, "Unexpected solicited response! sn: "
2405                             + serial + " error: " + error);
2406             return null;
2407         }
2408
2409         Object ret = null;
2410
2411         if (error == 0 || p.dataAvail() > 0) {
2412             // either command succeeds or command fails but with data payload
2413             try {switch (rr.mRequest) {
2414             /*
2415  cat libs/telephony/ril_commands.h \
2416  | egrep "^ *{RIL_" \
2417  | sed -re 's/\{([^,]+),[^,]+,([^}]+).+/case \1: ret = \2(p); break;/'
2418              */
2419             case RIL_REQUEST_GET_SIM_STATUS: ret =  responseIccCardStatus(p); break;
2420             case RIL_REQUEST_ENTER_SIM_PIN: ret =  responseInts(p); break;
2421             case RIL_REQUEST_ENTER_SIM_PUK: ret =  responseInts(p); break;
2422             case RIL_REQUEST_ENTER_SIM_PIN2: ret =  responseInts(p); break;
2423             case RIL_REQUEST_ENTER_SIM_PUK2: ret =  responseInts(p); break;
2424             case RIL_REQUEST_CHANGE_SIM_PIN: ret =  responseInts(p); break;
2425             case RIL_REQUEST_CHANGE_SIM_PIN2: ret =  responseInts(p); break;
2426             case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: ret =  responseInts(p); break;
2427             case RIL_REQUEST_GET_CURRENT_CALLS: ret =  responseCallList(p); break;
2428             case RIL_REQUEST_DIAL: ret =  responseVoid(p); break;
2429             case RIL_REQUEST_GET_IMSI: ret =  responseString(p); break;
2430             case RIL_REQUEST_HANGUP: ret =  responseVoid(p); break;
2431             case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: ret =  responseVoid(p); break;
2432             case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: {
2433                 if (mTestingEmergencyCall.getAndSet(false)) {
2434                     if (mEmergencyCallbackModeRegistrant != null) {
2435                         riljLog("testing emergency call, notify ECM Registrants");
2436                         mEmergencyCallbackModeRegistrant.notifyRegistrant();
2437                     }
2438                 }
2439                 ret =  responseVoid(p);
2440                 break;
2441             }
2442             case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: ret =  responseVoid(p); break;
2443             case RIL_REQUEST_CONFERENCE: ret =  responseVoid(p); break;
2444             case RIL_REQUEST_UDUB: ret =  responseVoid(p); break;
2445             case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: ret =  responseInts(p); break;
2446             case RIL_REQUEST_SIGNAL_STRENGTH: ret =  responseSignalStrength(p); break;
2447             case RIL_REQUEST_VOICE_REGISTRATION_STATE: ret =  responseStrings(p); break;
2448             case RIL_REQUEST_DATA_REGISTRATION_STATE: ret =  responseStrings(p); break;
2449             case RIL_REQUEST_OPERATOR: ret =  responseStrings(p); break;
2450             case RIL_REQUEST_RADIO_POWER: ret =  responseVoid(p); break;
2451             case RIL_REQUEST_DTMF: ret =  responseVoid(p); break;
2452             case RIL_REQUEST_SEND_SMS: ret =  responseSMS(p); break;
2453             case RIL_REQUEST_SEND_SMS_EXPECT_MORE: ret =  responseSMS(p); break;
2454             case RIL_REQUEST_SETUP_DATA_CALL: ret =  responseSetupDataCall(p); break;
2455             case RIL_REQUEST_SIM_IO: ret =  responseICC_IO(p); break;
2456             case RIL_REQUEST_SEND_USSD: ret =  responseVoid(p); break;
2457             case RIL_REQUEST_CANCEL_USSD: ret =  responseVoid(p); break;
2458             case RIL_REQUEST_GET_CLIR: ret =  responseInts(p); break;
2459             case RIL_REQUEST_SET_CLIR: ret =  responseVoid(p); break;
2460             case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: ret =  responseCallForward(p); break;
2461             case RIL_REQUEST_SET_CALL_FORWARD: ret =  responseVoid(p); break;
2462             case RIL_REQUEST_QUERY_CALL_WAITING: ret =  responseInts(p); break;
2463             case RIL_REQUEST_SET_CALL_WAITING: ret =  responseVoid(p); break;
2464             case RIL_REQUEST_SMS_ACKNOWLEDGE: ret =  responseVoid(p); break;
2465             case RIL_REQUEST_GET_IMEI: ret =  responseString(p); break;
2466             case RIL_REQUEST_GET_IMEISV: ret =  responseString(p); break;
2467             case RIL_REQUEST_ANSWER: ret =  responseVoid(p); break;
2468             case RIL_REQUEST_DEACTIVATE_DATA_CALL: ret =  responseVoid(p); break;
2469             case RIL_REQUEST_QUERY_FACILITY_LOCK: ret =  responseInts(p); break;
2470             case RIL_REQUEST_SET_FACILITY_LOCK: ret =  responseInts(p); break;
2471             case RIL_REQUEST_CHANGE_BARRING_PASSWORD: ret =  responseVoid(p); break;
2472             case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: ret =  responseInts(p); break;
2473             case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: ret =  responseVoid(p); break;
2474             case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: ret =  responseVoid(p); break;
2475             case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : ret =  responseOperatorInfos(p); break;
2476             case RIL_REQUEST_DTMF_START: ret =  responseVoid(p); break;
2477             case RIL_REQUEST_DTMF_STOP: ret =  responseVoid(p); break;
2478             case RIL_REQUEST_BASEBAND_VERSION: ret =  responseString(p); break;
2479             case RIL_REQUEST_SEPARATE_CONNECTION: ret =  responseVoid(p); break;
2480             case RIL_REQUEST_SET_MUTE: ret =  responseVoid(p); break;
2481             case RIL_REQUEST_GET_MUTE: ret =  responseInts(p); break;
2482             case RIL_REQUEST_QUERY_CLIP: ret =  responseInts(p); break;
2483             case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: ret =  responseInts(p); break;
2484             case RIL_REQUEST_DATA_CALL_LIST: ret =  responseDataCallList(p); break;
2485             case RIL_REQUEST_RESET_RADIO: ret =  responseVoid(p); break;
2486             case RIL_REQUEST_OEM_HOOK_RAW: ret =  responseRaw(p); break;
2487             case RIL_REQUEST_OEM_HOOK_STRINGS: ret =  responseStrings(p); break;
2488             case RIL_REQUEST_SCREEN_STATE: ret =  responseVoid(p); break;
2489             case RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION: ret =  responseVoid(p); break;
2490             case RIL_REQUEST_WRITE_SMS_TO_SIM: ret =  responseInts(p); break;
2491             case RIL_REQUEST_DELETE_SMS_ON_SIM: ret =  responseVoid(p); break;
2492             case RIL_REQUEST_SET_BAND_MODE: ret =  responseVoid(p); break;
2493             case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: ret =  responseInts(p); break;
2494             case RIL_REQUEST_STK_GET_PROFILE: ret =  responseString(p); break;
2495             case RIL_REQUEST_STK_SET_PROFILE: ret =  responseVoid(p); break;
2496             case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: ret =  responseString(p); break;
2497             case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: ret =  responseVoid(p); break;
2498             case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: ret =  responseInts(p); break;
2499             case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: ret =  responseVoid(p); break;
2500             case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: ret =  responseVoid(p); break;
2501             case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: ret =  responseGetPreferredNetworkType(p); break;
2502             case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: ret = responseCellList(p); break;
2503             case RIL_REQUEST_SET_LOCATION_UPDATES: ret =  responseVoid(p); break;
2504             case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE: ret =  responseVoid(p); break;
2505             case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE: ret =  responseVoid(p); break;
2506             case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE: ret =  responseInts(p); break;
2507             case RIL_REQUEST_SET_TTY_MODE: ret =  responseVoid(p); break;
2508             case RIL_REQUEST_QUERY_TTY_MODE: ret =  responseInts(p); break;
2509             case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE: ret =  responseVoid(p); break;
2510             case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE: ret =  responseInts(p); break;
2511             case RIL_REQUEST_CDMA_FLASH: ret =  responseVoid(p); break;
2512             case RIL_REQUEST_CDMA_BURST_DTMF: ret =  responseVoid(p); break;
2513             case RIL_REQUEST_CDMA_SEND_SMS: ret =  responseSMS(p); break;
2514             case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE: ret =  responseVoid(p); break;
2515             case RIL_REQUEST_GSM_GET_BROADCAST_CONFIG: ret =  responseGmsBroadcastConfig(p); break;
2516             case RIL_REQUEST_GSM_SET_BROADCAST_CONFIG: ret =  responseVoid(p); break;
2517             case RIL_REQUEST_GSM_BROADCAST_ACTIVATION: ret =  responseVoid(p); break;
2518             case RIL_REQUEST_CDMA_GET_BROADCAST_CONFIG: ret =  responseCdmaBroadcastConfig(p); break;
2519             case RIL_REQUEST_CDMA_SET_BROADCAST_CONFIG: ret =  responseVoid(p); break;
2520             case RIL_REQUEST_CDMA_BROADCAST_ACTIVATION: ret =  responseVoid(p); break;
2521             case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: ret =  responseVoid(p); break;
2522             case RIL_REQUEST_CDMA_SUBSCRIPTION: ret =  responseStrings(p); break;
2523             case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: ret =  responseInts(p); break;
2524             case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: ret =  responseVoid(p); break;
2525             case RIL_REQUEST_DEVICE_IDENTITY: ret =  responseStrings(p); break;
2526             case RIL_REQUEST_GET_SMSC_ADDRESS: ret = responseString(p); break;
2527             case RIL_REQUEST_SET_SMSC_ADDRESS: ret = responseVoid(p); break;
2528             case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: ret = responseVoid(p); break;
2529             case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: ret = responseVoid(p); break;
2530             case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: ret = responseVoid(p); break;
2531             case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: ret =  responseInts(p); break;
2532             case RIL_REQUEST_ISIM_AUTHENTICATION: ret =  responseString(p); break;
2533             case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: ret = responseVoid(p); break;
2534             case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: ret = responseICC_IO(p); break;
2535             case RIL_REQUEST_VOICE_RADIO_TECH: ret = responseInts(p); break;
2536             case RIL_REQUEST_GET_CELL_INFO_LIST: ret = responseCellInfoList(p); break;
2537             case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: ret = responseVoid(p); break;
2538             case RIL_REQUEST_SET_INITIAL_ATTACH_APN: ret = responseVoid(p); break;
2539             case RIL_REQUEST_SET_DATA_PROFILE: ret = responseVoid(p); break;
2540             case RIL_REQUEST_IMS_REGISTRATION_STATE: ret = responseInts(p); break;
2541             case RIL_REQUEST_IMS_SEND_SMS: ret =  responseSMS(p); break;
2542             case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: ret =  responseICC_IO(p); break;
2543             case RIL_REQUEST_SIM_OPEN_CHANNEL: ret  = responseInts(p); break;
2544             case RIL_REQUEST_SIM_CLOSE_CHANNEL: ret  = responseVoid(p); break;
2545             case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: ret = responseICC_IO(p); break;
2546             case RIL_REQUEST_NV_READ_ITEM: ret = responseString(p); break;
2547             case RIL_REQUEST_NV_WRITE_ITEM: ret = responseVoid(p); break;
2548             case RIL_REQUEST_NV_WRITE_CDMA_PRL: ret = responseVoid(p); break;
2549             case RIL_REQUEST_NV_RESET_CONFIG: ret = responseVoid(p); break;
2550             case RIL_REQUEST_SET_UICC_SUBSCRIPTION: ret = responseVoid(p); break;
2551             case RIL_REQUEST_ALLOW_DATA: ret = responseVoid(p); break;
2552             case RIL_REQUEST_GET_HARDWARE_CONFIG: ret = responseHardwareConfig(p); break;
2553             case RIL_REQUEST_SIM_AUTHENTICATION: ret =  responseICC_IOBase64(p); break;
2554             case RIL_REQUEST_SHUTDOWN: ret = responseVoid(p); break;
2555             case RIL_REQUEST_GET_RADIO_CAPABILITY: ret =  responseRadioCapability(p); break;
2556             case RIL_REQUEST_SET_RADIO_CAPABILITY: ret =  responseRadioCapability(p); break;
2557             default:
2558                 throw new RuntimeException("Unrecognized solicited response: " + rr.mRequest);
2559             //break;
2560             }} catch (Throwable tr) {
2561                 // Exceptions here usually mean invalid RIL responses
2562
2563                 Rlog.w(RILJ_LOG_TAG, rr.serialString() + "< "
2564                         + requestToString(rr.mRequest)
2565                         + " exception, possible invalid RIL response", tr);
2566
2567                 if (rr.mResult != null) {
2568                     AsyncResult.forMessage(rr.mResult, null, tr);
2569                     rr.mResult.sendToTarget();
2570                 }
2571                 return rr;
2572             }
2573         }
2574
2575         if (rr.mRequest == RIL_REQUEST_SHUTDOWN) {
2576             // Set RADIO_STATE to RADIO_UNAVAILABLE to continue shutdown process
2577             // regardless of error code to continue shutdown procedure.
2578             riljLog("Response to RIL_REQUEST_SHUTDOWN received. Error is " +
2579                     error + " Setting Radio State to Unavailable regardless of error.");
2580             setRadioState(RadioState.RADIO_UNAVAILABLE);
2581         }
2582
2583         // Here and below fake RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, see b/7255789.
2584         // This is needed otherwise we don't automatically transition to the main lock
2585         // screen when the pin or puk is entered incorrectly.
2586         switch (rr.mRequest) {
2587             case RIL_REQUEST_ENTER_SIM_PUK:
2588             case RIL_REQUEST_ENTER_SIM_PUK2:
2589                 if (mIccStatusChangedRegistrants != null) {
2590                     if (RILJ_LOGD) {
2591                         riljLog("ON enter sim puk fakeSimStatusChanged: reg count="
2592                                 + mIccStatusChangedRegistrants.size());
2593                     }
2594                     mIccStatusChangedRegistrants.notifyRegistrants();
2595                 }
2596                 break;
2597         }
2598
2599         if (error != 0) {
2600             switch (rr.mRequest) {
2601                 case RIL_REQUEST_ENTER_SIM_PIN:
2602                 case RIL_REQUEST_ENTER_SIM_PIN2:
2603                 case RIL_REQUEST_CHANGE_SIM_PIN:
2604                 case RIL_REQUEST_CHANGE_SIM_PIN2:
2605                 case RIL_REQUEST_SET_FACILITY_LOCK:
2606                     if (mIccStatusChangedRegistrants != null) {
2607                         if (RILJ_LOGD) {
2608                             riljLog("ON some errors fakeSimStatusChanged: reg count="
2609                                     + mIccStatusChangedRegistrants.size());
2610                         }
2611                         mIccStatusChangedRegistrants.notifyRegistrants();
2612                     }
2613                     break;
2614             }
2615
2616             rr.onError(error, ret);
2617         } else {
2618
2619             if (RILJ_LOGD) riljLog(rr.serialString() + "< " + requestToString(rr.mRequest)
2620                     + " " + retToString(rr.mRequest, ret));
2621
2622             if (rr.mResult != null) {
2623                 AsyncResult.forMessage(rr.mResult, ret, null);
2624                 rr.mResult.sendToTarget();
2625             }
2626         }
2627         return rr;
2628     }
2629
2630     static String
2631     retToString(int req, Object ret) {
2632         if (ret == null) return "";
2633         switch (req) {
2634             // Don't log these return values, for privacy's sake.
2635             case RIL_REQUEST_GET_IMSI:
2636             case RIL_REQUEST_GET_IMEI:
2637             case RIL_REQUEST_GET_IMEISV:
2638             case RIL_REQUEST_SIM_OPEN_CHANNEL:
2639             case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL:
2640
2641                 if (!RILJ_LOGV) {
2642                     // If not versbose logging just return and don't display IMSI and IMEI, IMEISV
2643                     return "";
2644                 }
2645         }
2646
2647         StringBuilder sb;
2648         String s;
2649         int length;
2650         if (ret instanceof int[]){
2651             int[] intArray = (int[]) ret;
2652             length = intArray.length;
2653             sb = new StringBuilder("{");
2654             if (length > 0) {
2655                 int i = 0;
2656                 sb.append(intArray[i++]);
2657                 while ( i < length) {
2658                     sb.append(", ").append(intArray[i++]);
2659                 }
2660             }
2661             sb.append("}");
2662             s = sb.toString();
2663         } else if (ret instanceof String[]) {
2664             String[] strings = (String[]) ret;
2665             length = strings.length;
2666             sb = new StringBuilder("{");
2667             if (length > 0) {
2668                 int i = 0;
2669                 sb.append(strings[i++]);
2670                 while ( i < length) {
2671                     sb.append(", ").append(strings[i++]);
2672                 }
2673             }
2674             sb.append("}");
2675             s = sb.toString();
2676         }else if (req == RIL_REQUEST_GET_CURRENT_CALLS) {
2677             ArrayList<DriverCall> calls = (ArrayList<DriverCall>) ret;
2678             sb = new StringBuilder("{");
2679             for (DriverCall dc : calls) {
2680                 sb.append("[").append(dc).append("] ");
2681             }
2682             sb.append("}");
2683             s = sb.toString();
2684         } else if (req == RIL_REQUEST_GET_NEIGHBORING_CELL_IDS) {
2685             ArrayList<NeighboringCellInfo> cells = (ArrayList<NeighboringCellInfo>) ret;
2686             sb = new StringBuilder("{");
2687             for (NeighboringCellInfo cell : cells) {
2688                 sb.append("[").append(cell).append("] ");
2689             }
2690             sb.append("}");
2691             s = sb.toString();
2692         } else if (req == RIL_REQUEST_QUERY_CALL_FORWARD_STATUS) {
2693             CallForwardInfo[] cinfo = (CallForwardInfo[]) ret;
2694             length = cinfo.length;
2695             sb = new StringBuilder("{");
2696             for(int i = 0; i < length; i++) {
2697                 sb.append("[").append(cinfo[i]).append("] ");
2698             }
2699             sb.append("}");
2700             s = sb.toString();
2701         } else if (req == RIL_REQUEST_GET_HARDWARE_CONFIG) {
2702             ArrayList<HardwareConfig> hwcfgs = (ArrayList<HardwareConfig>) ret;
2703             sb = new StringBuilder(" ");
2704             for (HardwareConfig hwcfg : hwcfgs) {
2705                 sb.append("[").append(hwcfg).append("] ");
2706             }
2707             s = sb.toString();
2708         } else {
2709             s = ret.toString();
2710         }
2711         return s;
2712     }
2713
2714     private void
2715     processUnsolicited (Parcel p) {
2716         int response;
2717         Object ret;
2718
2719         response = p.readInt();
2720
2721         try {switch(response) {
2722 /*
2723  cat libs/telephony/ril_unsol_commands.h \
2724  | egrep "^ *{RIL_" \
2725  | sed -re 's/\{([^,]+),[^,]+,([^}]+).+/case \1: \2(rr, p); break;/'
2726 */
2727
2728             case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: ret =  responseVoid(p); break;
2729             case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: ret =  responseVoid(p); break;
2730             case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: ret =  responseVoid(p); break;
2731             case RIL_UNSOL_RESPONSE_NEW_SMS: ret =  responseString(p); break;
2732             case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: ret =  responseString(p); break;
2733             case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: ret =  responseInts(p); break;
2734             case RIL_UNSOL_ON_USSD: ret =  responseStrings(p); break;
2735             case RIL_UNSOL_NITZ_TIME_RECEIVED: ret =  responseString(p); break;
2736             case RIL_UNSOL_SIGNAL_STRENGTH: ret = responseSignalStrength(p); break;
2737             case RIL_UNSOL_DATA_CALL_LIST_CHANGED: ret = responseDataCallList(p);break;
2738             case RIL_UNSOL_SUPP_SVC_NOTIFICATION: ret = responseSuppServiceNotification(p); break;
2739             case RIL_UNSOL_STK_SESSION_END: ret = responseVoid(p); break;
2740             case RIL_UNSOL_STK_PROACTIVE_COMMAND: ret = responseString(p); break;
2741             case RIL_UNSOL_STK_EVENT_NOTIFY: ret = responseString(p); break;
2742             case RIL_UNSOL_STK_CALL_SETUP: ret = responseInts(p); break;
2743             case RIL_UNSOL_SIM_SMS_STORAGE_FULL: ret =  responseVoid(p); break;
2744             case RIL_UNSOL_SIM_REFRESH: ret =  responseSimRefresh(p); break;
2745             case RIL_UNSOL_CALL_RING: ret =  responseCallRing(p); break;
2746             case RIL_UNSOL_RESTRICTED_STATE_CHANGED: ret = responseInts(p); break;
2747             case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED:  ret =  responseVoid(p); break;
2748             case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS:  ret =  responseCdmaSms(p); break;
2749             case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS:  ret =  responseRaw(p); break;
2750             case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL:  ret =  responseVoid(p); break;
2751             case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: ret = responseVoid(p); break;
2752             case RIL_UNSOL_CDMA_CALL_WAITING: ret = responseCdmaCallWaiting(p); break;
2753             case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: ret = responseInts(p); break;
2754             case RIL_UNSOL_CDMA_INFO_REC: ret = responseCdmaInformationRecord(p); break;
2755             case RIL_UNSOL_OEM_HOOK_RAW: ret = responseRaw(p); break;
2756             case RIL_UNSOL_RINGBACK_TONE: ret = responseInts(p); break;
2757             case RIL_UNSOL_RESEND_INCALL_MUTE: ret = responseVoid(p); break;
2758             case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: ret = responseInts(p); break;
2759             case RIL_UNSOl_CDMA_PRL_CHANGED: ret = responseInts(p); break;
2760             case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: ret = responseVoid(p); break;
2761             case RIL_UNSOL_RIL_CONNECTED: ret = responseInts(p); break;
2762             case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: ret =  responseInts(p); break;
2763             case RIL_UNSOL_CELL_INFO_LIST: ret = responseCellInfoList(p); break;
2764             case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: ret =  responseVoid(p); break;
2765             case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: ret =  responseInts(p); break;
2766             case RIL_UNSOL_SRVCC_STATE_NOTIFY: ret = responseInts(p); break;
2767             case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: ret = responseHardwareConfig(p); break;
2768             case RIL_UNSOL_RADIO_CAPABILITY:
2769                     ret = responseRadioCapability(p); break;
2770             case RIL_UNSOL_ON_SS: ret =  responseSsData(p); break;
2771             case RIL_UNSOL_STK_CC_ALPHA_NOTIFY: ret =  responseString(p); break;
2772
2773             default:
2774                 throw new RuntimeException("Unrecognized unsol response: " + response);
2775             //break; (implied)
2776         }} catch (Throwable tr) {
2777             Rlog.e(RILJ_LOG_TAG, "Exception processing unsol response: " + response +
2778                 "Exception:" + tr.toString());
2779             return;
2780         }
2781
2782         switch(response) {
2783             case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
2784                 /* has bonus radio state int */
2785                 RadioState newState = getRadioStateFromInt(p.readInt());
2786                 if (RILJ_LOGD) unsljLogMore(response, newState.toString());
2787
2788                 switchToRadioState(newState);
2789             break;
2790             case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED:
2791                 if (RILJ_LOGD) unsljLog(response);
2792
2793                 mImsNetworkStateChangedRegistrants
2794                     .notifyRegistrants(new AsyncResult(null, null, null));
2795             break;
2796             case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED:
2797                 if (RILJ_LOGD) unsljLog(response);
2798
2799                 mCallStateRegistrants
2800                     .notifyRegistrants(new AsyncResult(null, null, null));
2801             break;
2802             case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED:
2803                 if (RILJ_LOGD) unsljLog(response);
2804
2805                 mVoiceNetworkStateRegistrants
2806                     .notifyRegistrants(new AsyncResult(null, null, null));
2807             break;
2808             case RIL_UNSOL_RESPONSE_NEW_SMS: {
2809                 if (RILJ_LOGD) unsljLog(response);
2810
2811                 // FIXME this should move up a layer
2812                 String a[] = new String[2];
2813
2814                 a[1] = (String)ret;
2815
2816                 SmsMessage sms;
2817
2818                 sms = SmsMessage.newFromCMT(a);
2819                 if (mGsmSmsRegistrant != null) {
2820                     mGsmSmsRegistrant
2821                         .notifyRegistrant(new AsyncResult(null, sms, null));
2822                 }
2823             break;
2824             }
2825             case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT:
2826                 if (RILJ_LOGD) unsljLogRet(response, ret);
2827
2828                 if (mSmsStatusRegistrant != null) {
2829                     mSmsStatusRegistrant.notifyRegistrant(
2830                             new AsyncResult(null, ret, null));
2831                 }
2832             break;
2833             case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM:
2834                 if (RILJ_LOGD) unsljLogRet(response, ret);
2835
2836                 int[] smsIndex = (int[])ret;
2837
2838                 if(smsIndex.length == 1) {
2839                     if (mSmsOnSimRegistrant != null) {
2840                         mSmsOnSimRegistrant.
2841                                 notifyRegistrant(new AsyncResult(null, smsIndex, null));
2842                     }
2843                 } else {
2844                     if (RILJ_LOGD) riljLog(" NEW_SMS_ON_SIM ERROR with wrong length "
2845                             + smsIndex.length);
2846                 }
2847             break;
2848             case RIL_UNSOL_ON_USSD:
2849                 String[] resp = (String[])ret;
2850
2851                 if (resp.length < 2) {
2852                     resp = new String[2];
2853                     resp[0] = ((String[])ret)[0];
2854                     resp[1] = null;
2855                 }
2856                 if (RILJ_LOGD) unsljLogMore(response, resp[0]);
2857                 if (mUSSDRegistrant != null) {
2858                     mUSSDRegistrant.notifyRegistrant(
2859                         new AsyncResult (null, resp, null));
2860                 }
2861             break;
2862             case RIL_UNSOL_NITZ_TIME_RECEIVED:
2863                 if (RILJ_LOGD) unsljLogRet(response, ret);
2864
2865                 // has bonus long containing milliseconds since boot that the NITZ
2866                 // time was received
2867                 long nitzReceiveTime = p.readLong();
2868
2869                 Object[] result = new Object[2];
2870
2871                 result[0] = ret;
2872                 result[1] = Long.valueOf(nitzReceiveTime);
2873
2874                 boolean ignoreNitz = SystemProperties.getBoolean(
2875                         TelephonyProperties.PROPERTY_IGNORE_NITZ, false);
2876
2877                 if (ignoreNitz) {
2878                     if (RILJ_LOGD) riljLog("ignoring UNSOL_NITZ_TIME_RECEIVED");
2879                 } else {
2880                     if (mNITZTimeRegistrant != null) {
2881
2882                         mNITZTimeRegistrant
2883                             .notifyRegistrant(new AsyncResult (null, result, null));
2884                     }
2885                     // in case NITZ time registrant isn't registered yet, or a new registrant
2886                     // registers later
2887                     mLastNITZTimeInfo = result;
2888                 }
2889             break;
2890
2891             case RIL_UNSOL_SIGNAL_STRENGTH:
2892                 // Note this is set to "verbose" because it happens
2893                 // frequently
2894                 if (RILJ_LOGV) unsljLogvRet(response, ret);
2895
2896                 if (mSignalStrengthRegistrant != null) {
2897                     mSignalStrengthRegistrant.notifyRegistrant(
2898                                         new AsyncResult (null, ret, null));
2899                 }
2900             break;
2901             case RIL_UNSOL_DATA_CALL_LIST_CHANGED:
2902                 if (RILJ_LOGD) unsljLogRet(response, ret);
2903
2904                 mDataNetworkStateRegistrants.notifyRegistrants(new AsyncResult(null, ret, null));
2905             break;
2906
2907             case RIL_UNSOL_SUPP_SVC_NOTIFICATION:
2908                 if (RILJ_LOGD) unsljLogRet(response, ret);
2909
2910                 if (mSsnRegistrant != null) {
2911                     mSsnRegistrant.notifyRegistrant(
2912                                         new AsyncResult (null, ret, null));
2913                 }
2914                 break;
2915
2916             case RIL_UNSOL_STK_SESSION_END:
2917                 if (RILJ_LOGD) unsljLog(response);
2918
2919                 if (mCatSessionEndRegistrant != null) {
2920                     mCatSessionEndRegistrant.notifyRegistrant(
2921                                         new AsyncResult (null, ret, null));
2922                 }
2923                 break;
2924
2925             case RIL_UNSOL_STK_PROACTIVE_COMMAND:
2926                 if (RILJ_LOGD) unsljLog(response);
2927
2928                 if (mCatProCmdRegistrant != null) {
2929                     mCatProCmdRegistrant.notifyRegistrant(
2930                                         new AsyncResult (null, ret, null));
2931                 }
2932                 break;
2933
2934             case RIL_UNSOL_STK_EVENT_NOTIFY:
2935                 if (RILJ_LOGD) unsljLog(response);
2936
2937                 if (mCatEventRegistrant != null) {
2938                     mCatEventRegistrant.notifyRegistrant(
2939                                         new AsyncResult (null, ret, null));
2940                 }
2941                 break;
2942
2943             case RIL_UNSOL_STK_CALL_SETUP:
2944                 if (RILJ_LOGD) unsljLogRet(response, ret);
2945
2946                 if (mCatCallSetUpRegistrant != null) {
2947                     mCatCallSetUpRegistrant.notifyRegistrant(
2948                                         new AsyncResult (null, ret, null));
2949                 }
2950                 break;
2951
2952             case RIL_UNSOL_SIM_SMS_STORAGE_FULL:
2953                 if (RILJ_LOGD) unsljLog(response);
2954
2955                 if (mIccSmsFullRegistrant != null) {
2956                     mIccSmsFullRegistrant.notifyRegistrant();
2957                 }
2958                 break;
2959
2960             case RIL_UNSOL_SIM_REFRESH:
2961                 if (RILJ_LOGD) unsljLogRet(response, ret);
2962
2963                 if (mIccRefreshRegistrants != null) {
2964                     mIccRefreshRegistrants.notifyRegistrants(
2965                             new AsyncResult (null, ret, null));
2966                 }
2967                 break;
2968
2969             case RIL_UNSOL_CALL_RING:
2970                 if (RILJ_LOGD) unsljLogRet(response, ret);
2971
2972                 if (mRingRegistrant != null) {
2973                     mRingRegistrant.notifyRegistrant(
2974                             new AsyncResult (null, ret, null));
2975                 }
2976                 break;
2977
2978             case RIL_UNSOL_RESTRICTED_STATE_CHANGED:
2979                 if (RILJ_LOGD) unsljLogvRet(response, ret);
2980                 if (mRestrictedStateRegistrant != null) {
2981                     mRestrictedStateRegistrant.notifyRegistrant(
2982                                         new AsyncResult (null, ret, null));
2983                 }
2984                 break;
2985
2986             case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED:
2987                 if (RILJ_LOGD) unsljLog(response);
2988
2989                 if (mIccStatusChangedRegistrants != null) {
2990                     mIccStatusChangedRegistrants.notifyRegistrants();
2991                 }
2992                 break;
2993
2994             case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS:
2995                 if (RILJ_LOGD) unsljLog(response);
2996
2997                 SmsMessage sms = (SmsMessage) ret;
2998
2999                 if (mCdmaSmsRegistrant != null) {
3000                     mCdmaSmsRegistrant
3001                         .notifyRegistrant(new AsyncResult(null, sms, null));
3002                 }
3003                 break;
3004
3005             case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS:
3006                 if (RILJ_LOGD) unsljLogvRet(response, IccUtils.bytesToHexString((byte[])ret));
3007
3008                 if (mGsmBroadcastSmsRegistrant != null) {
3009                     mGsmBroadcastSmsRegistrant
3010                         .notifyRegistrant(new AsyncResult(null, ret, null));
3011                 }
3012                 break;
3013
3014             case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL:
3015                 if (RILJ_LOGD) unsljLog(response);
3016
3017                 if (mIccSmsFullRegistrant != null) {
3018                     mIccSmsFullRegistrant.notifyRegistrant();
3019                 }
3020                 break;
3021
3022             case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE:
3023                 if (RILJ_LOGD) unsljLog(response);
3024
3025                 if (mEmergencyCallbackModeRegistrant != null) {
3026                     mEmergencyCallbackModeRegistrant.notifyRegistrant();
3027                 }
3028                 break;
3029
3030             case RIL_UNSOL_CDMA_CALL_WAITING:
3031                 if (RILJ_LOGD) unsljLogRet(response, ret);
3032
3033                 if (mCallWaitingInfoRegistrants != null) {
3034                     mCallWaitingInfoRegistrants.notifyRegistrants(
3035                                         new AsyncResult (null, ret, null));
3036                 }
3037                 break;
3038
3039             case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS:
3040                 if (RILJ_LOGD) unsljLogRet(response, ret);
3041
3042                 if (mOtaProvisionRegistrants != null) {
3043                     mOtaProvisionRegistrants.notifyRegistrants(
3044                                         new AsyncResult (null, ret, null));
3045                 }
3046                 break;
3047
3048             case RIL_UNSOL_CDMA_INFO_REC:
3049                 ArrayList<CdmaInformationRecords> listInfoRecs;
3050
3051                 try {
3052                     listInfoRecs = (ArrayList<CdmaInformationRecords>)ret;
3053                 } catch (ClassCastException e) {
3054                     Rlog.e(RILJ_LOG_TAG, "Unexpected exception casting to listInfoRecs", e);
3055                     break;
3056                 }
3057
3058                 for (CdmaInformationRecords rec : listInfoRecs) {
3059                     if (RILJ_LOGD) unsljLogRet(response, rec);
3060                     notifyRegistrantsCdmaInfoRec(rec);
3061                 }
3062                 break;
3063
3064             case RIL_UNSOL_OEM_HOOK_RAW:
3065                 if (RILJ_LOGD) unsljLogvRet(response, IccUtils.bytesToHexString((byte[])ret));
3066                 if (mUnsolOemHookRawRegistrant != null) {
3067                     mUnsolOemHookRawRegistrant.notifyRegistrant(new AsyncResult(null, ret, null));
3068                 }
3069                 break;
3070
3071             case RIL_UNSOL_RINGBACK_TONE:
3072                 if (RILJ_LOGD) unsljLogvRet(response, ret);
3073                 if (mRingbackToneRegistrants != null) {
3074                     boolean playtone = (((int[])ret)[0] == 1);
3075                     mRingbackToneRegistrants.notifyRegistrants(
3076                                         new AsyncResult (null, playtone, null));
3077                 }
3078                 break;
3079
3080             case RIL_UNSOL_RESEND_INCALL_MUTE:
3081                 if (RILJ_LOGD) unsljLogRet(response, ret);
3082
3083                 if (mResendIncallMuteRegistrants != null) {
3084                     mResendIncallMuteRegistrants.notifyRegistrants(
3085                                         new AsyncResult (null, ret, null));
3086                 }
3087                 break;
3088
3089             case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED:
3090                 if (RILJ_LOGD) unsljLogRet(response, ret);
3091
3092                 if (mVoiceRadioTechChangedRegistrants != null) {
3093                     mVoiceRadioTechChangedRegistrants.notifyRegistrants(
3094                             new AsyncResult(null, ret, null));
3095                 }
3096                 break;
3097
3098             case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED:
3099                 if (RILJ_LOGD) unsljLogRet(response, ret);
3100
3101                 if (mCdmaSubscriptionChangedRegistrants != null) {
3102                     mCdmaSubscriptionChangedRegistrants.notifyRegistrants(
3103                                         new AsyncResult (null, ret, null));
3104                 }
3105                 break;
3106
3107             case RIL_UNSOl_CDMA_PRL_CHANGED:
3108                 if (RILJ_LOGD) unsljLogRet(response, ret);
3109
3110                 if (mCdmaPrlChangedRegistrants != null) {
3111                     mCdmaPrlChangedRegistrants.notifyRegistrants(
3112                                         new AsyncResult (null, ret, null));
3113                 }
3114                 break;
3115
3116             case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE:
3117                 if (RILJ_LOGD) unsljLogRet(response, ret);
3118
3119                 if (mExitEmergencyCallbackModeRegistrants != null) {
3120                     mExitEmergencyCallbackModeRegistrants.notifyRegistrants(
3121                                         new AsyncResult (null, null, null));
3122                 }
3123                 break;
3124
3125             case RIL_UNSOL_RIL_CONNECTED: {
3126                 if (RILJ_LOGD) unsljLogRet(response, ret);
3127
3128                 getRadioCapability(mSupportedRafHandler.obtainMessage());
3129
3130                 // Initial conditions
3131                 setRadioPower(false, null);
3132                 setPreferredNetworkType(mPreferredNetworkType, null);
3133                 setCdmaSubscriptionSource(mCdmaSubscription, null);
3134                 setCellInfoListRate(Integer.MAX_VALUE, null);
3135                 notifyRegistrantsRilConnectionChanged(((int[])ret)[0]);
3136                 break;
3137             }
3138             case RIL_UNSOL_CELL_INFO_LIST: {
3139                 if (RILJ_LOGD) unsljLogRet(response, ret);
3140
3141                 if (mRilCellInfoListRegistrants != null) {
3142                     mRilCellInfoListRegistrants.notifyRegistrants(
3143                                         new AsyncResult (null, ret, null));
3144                 }
3145                 break;
3146             }
3147             case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: {
3148                 if (RILJ_LOGD) unsljLogRet(response, ret);
3149
3150                 if (mSubscriptionStatusRegistrants != null) {
3151                     mSubscriptionStatusRegistrants.notifyRegistrants(
3152                                         new AsyncResult (null, ret, null));
3153                 }
3154                 break;
3155             }
3156             case RIL_UNSOL_SRVCC_STATE_NOTIFY: {
3157                 if (RILJ_LOGD) unsljLogRet(response, ret);
3158
3159                 if (mSrvccStateRegistrants != null) {
3160                     mSrvccStateRegistrants
3161                             .notifyRegistrants(new AsyncResult(null, ret, null));
3162                 }
3163                 break;
3164             }
3165             case RIL_UNSOL_HARDWARE_CONFIG_CHANGED:
3166                 if (RILJ_LOGD) unsljLogRet(response, ret);
3167
3168                 if (mHardwareConfigChangeRegistrants != null) {
3169                     mHardwareConfigChangeRegistrants.notifyRegistrants(
3170                                              new AsyncResult (null, ret, null));
3171                 }
3172                 break;
3173             case RIL_UNSOL_RADIO_CAPABILITY:
3174                 if (RILJ_LOGD) unsljLogRet(response, ret);
3175
3176                 if (mPhoneRadioCapabilityChangedRegistrants != null) {
3177                     mPhoneRadioCapabilityChangedRegistrants.notifyRegistrants(
3178                             new AsyncResult(null, ret, null));
3179                  }
3180                  break;
3181             case RIL_UNSOL_ON_SS:
3182                 if (RILJ_LOGD) unsljLogRet(response, ret);
3183
3184                 if (mSsRegistrant != null) {
3185                     mSsRegistrant.notifyRegistrant(
3186                                         new AsyncResult (null, ret, null));
3187                 }
3188                 break;
3189             case RIL_UNSOL_STK_CC_ALPHA_NOTIFY:
3190                 if (RILJ_LOGD) unsljLogRet(response, ret);
3191
3192                 if (mCatCcAlphaRegistrant != null) {
3193                     mCatCcAlphaRegistrant.notifyRegistrant(
3194                                         new AsyncResult (null, ret, null));
3195                 }
3196                 break;
3197         }
3198     }
3199
3200     /**
3201      * Receives and stores the capabilities supported by the modem.
3202      */
3203     private Handler mSupportedRafHandler = new Handler() {
3204         @Override
3205         public void handleMessage(Message msg) {
3206             AsyncResult ar = (AsyncResult) msg.obj;
3207             RadioCapability rc = (RadioCapability) ar.result;
3208             if (ar.exception != null) {
3209                 if (RILJ_LOGD) riljLog("Get supported radio access family fail");
3210             } else {
3211                 mSupportedRaf = rc.getRadioAccessFamily();
3212                 if (RILJ_LOGD) riljLog("Supported radio access family=" + mSupportedRaf);
3213             }
3214         }
3215     };
3216
3217     /**
3218      * Notifiy all registrants that the ril has connected or disconnected.
3219      *
3220      * @param rilVer is the version of the ril or -1 if disconnected.
3221      */
3222     private void notifyRegistrantsRilConnectionChanged(int rilVer) {
3223         mRilVersion = rilVer;
3224         if (mRilConnectedRegistrants != null) {
3225             mRilConnectedRegistrants.notifyRegistrants(
3226                                 new AsyncResult (null, new Integer(rilVer), null));
3227         }
3228     }
3229
3230     private Object
3231     responseInts(Parcel p) {
3232         int numInts;
3233         int response[];
3234
3235         numInts = p.readInt();
3236
3237         response = new int[numInts];
3238
3239         for (int i = 0 ; i < numInts ; i++) {
3240             response[i] = p.readInt();
3241         }
3242
3243         return response;
3244     }
3245
3246
3247     private Object
3248     responseVoid(Parcel p) {
3249         return null;
3250     }
3251
3252     private Object
3253     responseCallForward(Parcel p) {
3254         int numInfos;
3255         CallForwardInfo infos[];
3256
3257         numInfos = p.readInt();
3258
3259         infos = new CallForwardInfo[numInfos];
3260
3261         for (int i = 0 ; i < numInfos ; i++) {
3262             infos[i] = new CallForwardInfo();
3263
3264             infos[i].status = p.readInt();
3265             infos[i].reason = p.readInt();
3266             infos[i].serviceClass = p.readInt();
3267             infos[i].toa = p.readInt();
3268             infos[i].number = p.readString();
3269             infos[i].timeSeconds = p.readInt();
3270         }
3271
3272         return infos;
3273     }
3274
3275     private Object
3276     responseSuppServiceNotification(Parcel p) {
3277         SuppServiceNotification notification = new SuppServiceNotification();
3278
3279         notification.notificationType = p.readInt();
3280         notification.code = p.readInt();
3281         notification.index = p.readInt();
3282         notification.type = p.readInt();
3283         notification.number = p.readString();
3284
3285         return notification;
3286     }
3287
3288     private Object
3289     responseCdmaSms(Parcel p) {
3290         SmsMessage sms;
3291         sms = SmsMessage.newFromParcel(p);
3292
3293         return sms;
3294     }
3295
3296     private Object
3297     responseString(Parcel p) {
3298         String response;
3299
3300         response = p.readString();
3301
3302         return response;
3303     }
3304
3305     private Object
3306     responseStrings(Parcel p) {
3307         int num;
3308         String response[];
3309
3310         response = p.readStringArray();
3311
3312         return response;
3313     }
3314
3315     private Object
3316     responseRaw(Parcel p) {
3317         int num;
3318         byte response[];
3319
3320         response = p.createByteArray();
3321
3322         return response;
3323     }
3324
3325     private Object
3326     responseSMS(Parcel p) {
3327         int messageRef, errorCode;
3328         String ackPDU;
3329
3330         messageRef = p.readInt();
3331         ackPDU = p.readString();
3332         errorCode = p.readInt();
3333
3334         SmsResponse response = new SmsResponse(messageRef, ackPDU, errorCode);
3335
3336         return response;
3337     }
3338
3339
3340     private Object
3341     responseICC_IO(Parcel p) {
3342         int sw1, sw2;
3343         Message ret;
3344
3345         sw1 = p.readInt();
3346         sw2 = p.readInt();
3347
3348         String s = p.readString();
3349
3350         if (RILJ_LOGV) riljLog("< iccIO: "
3351                 + " 0x" + Integer.toHexString(sw1)
3352                 + " 0x" + Integer.toHexString(sw2) + " "
3353                 + s);
3354
3355         return new IccIoResult(sw1, sw2, s);
3356     }
3357
3358     private Object
3359     responseICC_IOBase64(Parcel p) {
3360         int sw1, sw2;
3361         Message ret;
3362
3363         sw1 = p.readInt();
3364         sw2 = p.readInt();
3365
3366         String s = p.readString();
3367
3368         if (RILJ_LOGV) riljLog("< iccIO: "
3369                 + " 0x" + Integer.toHexString(sw1)
3370                 + " 0x" + Integer.toHexString(sw2) + " "
3371                 + s);
3372
3373
3374         return new IccIoResult(sw1, sw2, android.util.Base64.decode(s, android.util.Base64.DEFAULT));
3375     }
3376
3377     private Object
3378     responseIccCardStatus(Parcel p) {
3379         IccCardApplicationStatus appStatus;
3380
3381         IccCardStatus cardStatus = new IccCardStatus();
3382         cardStatus.setCardState(p.readInt());
3383         cardStatus.setUniversalPinState(p.readInt());
3384         cardStatus.mGsmUmtsSubscriptionAppIndex = p.readInt();
3385         cardStatus.mCdmaSubscriptionAppIndex = p.readInt();
3386         cardStatus.mImsSubscriptionAppIndex = p.readInt();
3387         int numApplications = p.readInt();
3388
3389         // limit to maximum allowed applications
3390         if (numApplications > IccCardStatus.CARD_MAX_APPS) {
3391             numApplications = IccCardStatus.CARD_MAX_APPS;
3392         }
3393         cardStatus.mApplications = new IccCardApplicationStatus[numApplications];
3394         for (int i = 0 ; i < numApplications ; i++) {
3395             appStatus = new IccCardApplicationStatus();
3396             appStatus.app_type       = appStatus.AppTypeFromRILInt(p.readInt());
3397             appStatus.app_state      = appStatus.AppStateFromRILInt(p.readInt());
3398             appStatus.perso_substate = appStatus.PersoSubstateFromRILInt(p.readInt());
3399             appStatus.aid            = p.readString();
3400             appStatus.app_label      = p.readString();
3401             appStatus.pin1_replaced  = p.readInt();
3402             appStatus.pin1           = appStatus.PinStateFromRILInt(p.readInt());
3403             appStatus.pin2           = appStatus.PinStateFromRILInt(p.readInt());
3404             cardStatus.mApplications[i] = appStatus;
3405         }
3406         return cardStatus;
3407     }
3408
3409     private Object
3410     responseSimRefresh(Parcel p) {
3411         IccRefreshResponse response = new IccRefreshResponse();
3412
3413         response.refreshResult = p.readInt();
3414         response.efId   = p.readInt();
3415         response.aid = p.readString();
3416         return response;
3417     }
3418
3419     private Object
3420     responseCallList(Parcel p) {
3421         int num;
3422         int voiceSettings;
3423         ArrayList<DriverCall> response;
3424         DriverCall dc;
3425
3426         num = p.readInt();
3427         response = new ArrayList<DriverCall>(num);
3428
3429         if (RILJ_LOGV) {
3430             riljLog("responseCallList: num=" + num +
3431                     " mEmergencyCallbackModeRegistrant=" + mEmergencyCallbackModeRegistrant +
3432                     " mTestingEmergencyCall=" + mTestingEmergencyCall.get());
3433         }
3434         for (int i = 0 ; i < num ; i++) {
3435             dc = new DriverCall();
3436
3437             dc.state = DriverCall.stateFromCLCC(p.readInt());
3438             dc.index = p.readInt();
3439             dc.TOA = p.readInt();
3440             dc.isMpty = (0 != p.readInt());
3441             dc.isMT = (0 != p.readInt());
3442             dc.als = p.readInt();
3443             voiceSettings = p.readInt();
3444             dc.isVoice = (0 == voiceSettings) ? false : true;
3445             dc.isVoicePrivacy = (0 != p.readInt());
3446             dc.number = p.readString();
3447             int np = p.readInt();
3448             dc.numberPresentation = DriverCall.presentationFromCLIP(np);
3449             dc.name = p.readString();
3450             // according to ril.h, namePresentation should be handled as numberPresentation;
3451             dc.namePresentation = DriverCall.presentationFromCLIP(p.readInt());
3452             int uusInfoPresent = p.readInt();
3453             if (uusInfoPresent == 1) {
3454                 dc.uusInfo = new UUSInfo();
3455                 dc.uusInfo.setType(p.readInt());
3456                 dc.uusInfo.setDcs(p.readInt());
3457                 byte[] userData = p.createByteArray();
3458                 dc.uusInfo.setUserData(userData);
3459                 riljLogv(String.format("Incoming UUS : type=%d, dcs=%d, length=%d",
3460                                 dc.uusInfo.getType(), dc.uusInfo.getDcs(),
3461                                 dc.uusInfo.getUserData().length));
3462                 riljLogv("Incoming UUS : data (string)="
3463                         + new String(dc.uusInfo.getUserData()));
3464                 riljLogv("Incoming UUS : data (hex): "
3465                         + IccUtils.bytesToHexString(dc.uusInfo.getUserData()));
3466             } else {
3467                 riljLogv("Incoming UUS : NOT present!");
3468             }
3469
3470             // Make sure there's a leading + on addresses with a TOA of 145
3471             dc.number = PhoneNumberUtils.stringFromStringAndTOA(dc.number, dc.TOA);
3472
3473             response.add(dc);
3474
3475             if (dc.isVoicePrivacy) {
3476                 mVoicePrivacyOnRegistrants.notifyRegistrants();
3477                 riljLog("InCall VoicePrivacy is enabled");
3478             } else {
3479                 mVoicePrivacyOffRegistrants.notifyRegistrants();
3480                 riljLog("InCall VoicePrivacy is disabled");
3481             }
3482         }
3483
3484         Collections.sort(response);
3485
3486         if ((num == 0) && mTestingEmergencyCall.getAndSet(false)) {
3487             if (mEmergencyCallbackModeRegistrant != null) {
3488                 riljLog("responseCallList: call ended, testing emergency call," +
3489                             " notify ECM Registrants");
3490                 mEmergencyCallbackModeRegistrant.notifyRegistrant();
3491             }
3492         }
3493
3494         return response;
3495     }
3496
3497     private DataCallResponse getDataCallResponse(Parcel p, int version) {
3498         DataCallResponse dataCall = new DataCallResponse();
3499
3500         dataCall.version = version;
3501         if (version < 5) {
3502             dataCall.cid = p.readInt();
3503             dataCall.active = p.readInt();
3504             dataCall.type = p.readString();
3505             String addresses = p.readString();
3506             if (!TextUtils.isEmpty(addresses)) {
3507                 dataCall.addresses = addresses.split(" ");
3508             }
3509         } else {
3510             dataCall.status = p.readInt();
3511             dataCall.suggestedRetryTime = p.readInt();
3512             dataCall.cid = p.readInt();
3513             dataCall.active = p.readInt();
3514             dataCall.type = p.readString();
3515             dataCall.ifname = p.readString();
3516             if ((dataCall.status == DcFailCause.NONE.getErrorCode()) &&
3517                     TextUtils.isEmpty(dataCall.ifname)) {
3518               throw new RuntimeException("getDataCallResponse, no ifname");
3519             }
3520             String addresses = p.readString();
3521             if (!TextUtils.isEmpty(addresses)) {
3522                 dataCall.addresses = addresses.split(" ");
3523             }
3524             String dnses = p.readString();
3525             if (!TextUtils.isEmpty(dnses)) {
3526                 dataCall.dnses = dnses.split(" ");
3527             }
3528             String gateways = p.readString();
3529             if (!TextUtils.isEmpty(gateways)) {
3530                 dataCall.gateways = gateways.split(" ");
3531             }
3532             if (version >= 10) {
3533                 String pcscf = p.readString();
3534                 if (!TextUtils.isEmpty(pcscf)) {
3535                     dataCall.pcscf = pcscf.split(" ");
3536                 }
3537             }
3538             if (version >= 11) {
3539                 dataCall.mtu = p.readInt();
3540             }
3541         }
3542         return dataCall;
3543     }
3544
3545     private Object
3546     responseDataCallList(Parcel p) {
3547         ArrayList<DataCallResponse> response;
3548
3549         int ver = p.readInt();
3550         int num = p.readInt();
3551         riljLog("responseDataCallList ver=" + ver + " num=" + num);
3552
3553         response = new ArrayList<DataCallResponse>(num);
3554         for (int i = 0; i < num; i++) {
3555             response.add(getDataCallResponse(p, ver));
3556         }
3557
3558         return response;
3559     }
3560
3561     private Object
3562     responseSetupDataCall(Parcel p) {
3563         int ver = p.readInt();
3564         int num = p.readInt();
3565         if (RILJ_LOGV) riljLog("responseSetupDataCall ver=" + ver + " num=" + num);
3566
3567         DataCallResponse dataCall;
3568
3569         if (ver < 5) {
3570             dataCall = new DataCallResponse();
3571             dataCall.version = ver;
3572             dataCall.cid = Integer.parseInt(p.readString());
3573             dataCall.ifname = p.readString();
3574             if (TextUtils.isEmpty(dataCall.ifname)) {
3575                 throw new RuntimeException(
3576                         "RIL_REQUEST_SETUP_DATA_CALL response, no ifname");
3577             }
3578             String addresses = p.readString();
3579             if (!TextUtils.isEmpty(addresses)) {
3580               dataCall.addresses = addresses.split(" ");
3581             }
3582             if (num >= 4) {
3583                 String dnses = p.readString();
3584                 if (RILJ_LOGD) riljLog("responseSetupDataCall got dnses=" + dnses);
3585                 if (!TextUtils.isEmpty(dnses)) {
3586                     dataCall.dnses = dnses.split(" ");
3587                 }
3588             }
3589             if (num >= 5) {
3590                 String gateways = p.readString();
3591                 if (RILJ_LOGD) riljLog("responseSetupDataCall got gateways=" + gateways);
3592                 if (!TextUtils.isEmpty(gateways)) {
3593                     dataCall.gateways = gateways.split(" ");
3594                 }
3595             }
3596             if (num >= 6) {
3597                 String pcscf = p.readString();
3598                 if (RILJ_LOGD) riljLog("responseSetupDataCall got pcscf=" + pcscf);
3599                 if (!TextUtils.isEmpty(pcscf)) {
3600                     dataCall.pcscf = pcscf.split(" ");
3601                 }
3602             }
3603         } else {
3604             if (num != 1) {
3605                 throw new RuntimeException(
3606                         "RIL_REQUEST_SETUP_DATA_CALL response expecting 1 RIL_Data_Call_response_v5"
3607                         + " got " + num);
3608             }
3609             dataCall = getDataCallResponse(p, ver);
3610         }
3611
3612         return dataCall;
3613     }
3614
3615     private Object
3616     responseOperatorInfos(Parcel p) {
3617         String strings[] = (String [])responseStrings(p);
3618         ArrayList<OperatorInfo> ret;
3619
3620         if (strings.length % 4 != 0) {
3621             throw new RuntimeException(
3622                 "RIL_REQUEST_QUERY_AVAILABLE_NETWORKS: invalid response. Got "
3623                 + strings.length + " strings, expected multible of 4");
3624         }
3625
3626         ret = new ArrayList<OperatorInfo>(strings.length / 4);
3627
3628         for (int i = 0 ; i < strings.length ; i += 4) {
3629             ret.add (
3630                 new OperatorInfo(
3631                     strings[i+0],
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 }