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