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