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