Home | History | Annotate | Download | only in telephony
      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 
     53 import com.android.internal.telephony.gsm.SmsBroadcastConfigInfo;
     54 import com.android.internal.telephony.gsm.SuppServiceNotification;
     55 import com.android.internal.telephony.uicc.IccCardApplicationStatus;
     56 import com.android.internal.telephony.uicc.IccCardStatus;
     57 import com.android.internal.telephony.uicc.IccIoResult;
     58 import com.android.internal.telephony.uicc.IccRefreshResponse;
     59 import com.android.internal.telephony.uicc.IccUtils;
     60 import com.android.internal.telephony.cdma.CdmaCallWaitingNotification;
     61 import com.android.internal.telephony.cdma.CdmaInformationRecords;
     62 import com.android.internal.telephony.cdma.CdmaSmsBroadcastConfigInfo;
     63 import com.android.internal.telephony.dataconnection.DcFailCause;
     64 import com.android.internal.telephony.dataconnection.DataCallResponse;
     65 
     66 import java.io.ByteArrayInputStream;
     67 import java.io.DataInputStream;
     68 import java.io.FileDescriptor;
     69 import java.io.IOException;
     70 import java.io.InputStream;
     71 import java.io.PrintWriter;
     72 import java.util.ArrayList;
     73 import java.util.Collections;
     74 import java.util.concurrent.atomic.AtomicBoolean;
     75 
     76 /**
     77  * {@hide}
     78  */
     79 class RILRequest {
     80     static final String LOG_TAG = "RilRequest";
     81 
     82     //***** Class Variables
     83     static int sNextSerial = 0;
     84     static Object sSerialMonitor = new Object();
     85     private static Object sPoolSync = new Object();
     86     private static RILRequest sPool = null;
     87     private static int sPoolSize = 0;
     88     private static final int MAX_POOL_SIZE = 4;
     89 
     90     //***** Instance Variables
     91     int mSerial;
     92     int mRequest;
     93     Message mResult;
     94     Parcel mParcel;
     95     RILRequest mNext;
     96 
     97     /**
     98      * Retrieves a new RILRequest instance from the pool.
     99      *
    100      * @param request RIL_REQUEST_*
    101      * @param result sent when operation completes
    102      * @return a RILRequest instance from the pool.
    103      */
    104     static RILRequest obtain(int request, Message result) {
    105         RILRequest rr = null;
    106 
    107         synchronized(sPoolSync) {
    108             if (sPool != null) {
    109                 rr = sPool;
    110                 sPool = rr.mNext;
    111                 rr.mNext = null;
    112                 sPoolSize--;
    113             }
    114         }
    115 
    116         if (rr == null) {
    117             rr = new RILRequest();
    118         }
    119 
    120         synchronized(sSerialMonitor) {
    121             rr.mSerial = sNextSerial++;
    122         }
    123         rr.mRequest = request;
    124         rr.mResult = result;
    125         rr.mParcel = Parcel.obtain();
    126 
    127         if (result != null && result.getTarget() == null) {
    128             throw new NullPointerException("Message target must not be null");
    129         }
    130 
    131         // first elements in any RIL Parcel
    132         rr.mParcel.writeInt(request);
    133         rr.mParcel.writeInt(rr.mSerial);
    134 
    135         return rr;
    136     }
    137 
    138     /**
    139      * Returns a RILRequest instance to the pool.
    140      *
    141      * Note: This should only be called once per use.
    142      */
    143     void release() {
    144         synchronized (sPoolSync) {
    145             if (sPoolSize < MAX_POOL_SIZE) {
    146                 mNext = sPool;
    147                 sPool = this;
    148                 sPoolSize++;
    149                 mResult = null;
    150             }
    151         }
    152     }
    153 
    154     private RILRequest() {
    155     }
    156 
    157     static void
    158     resetSerial() {
    159         synchronized(sSerialMonitor) {
    160             sNextSerial = 0;
    161         }
    162     }
    163 
    164     String
    165     serialString() {
    166         //Cheesy way to do %04d
    167         StringBuilder sb = new StringBuilder(8);
    168         String sn;
    169 
    170         sn = Integer.toString(mSerial);
    171 
    172         //sb.append("J[");
    173         sb.append('[');
    174         for (int i = 0, s = sn.length() ; i < 4 - s; i++) {
    175             sb.append('0');
    176         }
    177 
    178         sb.append(sn);
    179         sb.append(']');
    180         return sb.toString();
    181     }
    182 
    183     void
    184     onError(int error, Object ret) {
    185         CommandException ex;
    186 
    187         ex = CommandException.fromRilErrno(error);
    188 
    189         if (RIL.RILJ_LOGD) Rlog.d(LOG_TAG, serialString() + "< "
    190             + RIL.requestToString(mRequest)
    191             + " error: " + ex);
    192 
    193         if (mResult != null) {
    194             AsyncResult.forMessage(mResult, ret, ex);
    195             mResult.sendToTarget();
    196         }
    197 
    198         if (mParcel != null) {
    199             mParcel.recycle();
    200             mParcel = null;
    201         }
    202     }
    203 }
    204 
    205 
    206 /**
    207  * RIL implementation of the CommandsInterface.
    208  *
    209  * {@hide}
    210  */
    211 public final class RIL extends BaseCommands implements CommandsInterface {
    212     static final String RILJ_LOG_TAG = "RILJ";
    213     static final boolean RILJ_LOGD = true;
    214     static final boolean RILJ_LOGV = false; // STOPSHIP if true
    215 
    216     /**
    217      * Wake lock timeout should be longer than the longest timeout in
    218      * the vendor ril.
    219      */
    220     private static final int DEFAULT_WAKE_LOCK_TIMEOUT = 60000;
    221 
    222     //***** Instance Variables
    223 
    224     LocalSocket mSocket;
    225     HandlerThread mSenderThread;
    226     RILSender mSender;
    227     Thread mReceiverThread;
    228     RILReceiver mReceiver;
    229     WakeLock mWakeLock;
    230     int mWakeLockTimeout;
    231     // The number of requests pending to be sent out, it increases before calling
    232     // EVENT_SEND and decreases while handling EVENT_SEND. It gets cleared while
    233     // WAKE_LOCK_TIMEOUT occurs.
    234     int mRequestMessagesPending;
    235     // The number of requests sent out but waiting for response. It increases while
    236     // sending request and decreases while handling response. It should match
    237     // mRequestList.size() unless there are requests no replied while
    238     // WAKE_LOCK_TIMEOUT occurs.
    239     int mRequestMessagesWaiting;
    240 
    241     //I'd rather this be LinkedList or something
    242     ArrayList<RILRequest> mRequestList = new ArrayList<RILRequest>();
    243 
    244     Object     mLastNITZTimeInfo;
    245 
    246     // When we are testing emergency calls
    247     AtomicBoolean mTestingEmergencyCall = new AtomicBoolean(false);
    248 
    249     //***** Events
    250 
    251     static final int EVENT_SEND                 = 1;
    252     static final int EVENT_WAKE_LOCK_TIMEOUT    = 2;
    253 
    254     //***** Constants
    255 
    256     // match with constant in ril.cpp
    257     static final int RIL_MAX_COMMAND_BYTES = (8 * 1024);
    258     static final int RESPONSE_SOLICITED = 0;
    259     static final int RESPONSE_UNSOLICITED = 1;
    260 
    261     static final String SOCKET_NAME_RIL = "rild";
    262 
    263     static final int SOCKET_OPEN_RETRY_MILLIS = 4 * 1000;
    264 
    265     // The number of the required config values for broadcast SMS stored in the C struct
    266     // RIL_CDMA_BroadcastServiceInfo
    267     private static final int CDMA_BSI_NO_OF_INTS_STRUCT = 3;
    268 
    269     private static final int CDMA_BROADCAST_SMS_NO_OF_SERVICE_CATEGORIES = 31;
    270 
    271     BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
    272         @Override
    273         public void onReceive(Context context, Intent intent) {
    274             if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
    275                 sendScreenState(true);
    276             } else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
    277                 sendScreenState(false);
    278             } else {
    279                 Rlog.w(RILJ_LOG_TAG, "RIL received unexpected Intent: " + intent.getAction());
    280             }
    281         }
    282     };
    283 
    284     class RILSender extends Handler implements Runnable {
    285         public RILSender(Looper looper) {
    286             super(looper);
    287         }
    288 
    289         // Only allocated once
    290         byte[] dataLength = new byte[4];
    291 
    292         //***** Runnable implementation
    293         @Override
    294         public void
    295         run() {
    296             //setup if needed
    297         }
    298 
    299 
    300         //***** Handler implementation
    301         @Override public void
    302         handleMessage(Message msg) {
    303             RILRequest rr = (RILRequest)(msg.obj);
    304             RILRequest req = null;
    305 
    306             switch (msg.what) {
    307                 case EVENT_SEND:
    308                     /**
    309                      * mRequestMessagePending++ already happened for every
    310                      * EVENT_SEND, thus we must make sure
    311                      * mRequestMessagePending-- happens once and only once
    312                      */
    313                     boolean alreadySubtracted = false;
    314                     try {
    315                         LocalSocket s;
    316 
    317                         s = mSocket;
    318 
    319                         if (s == null) {
    320                             rr.onError(RADIO_NOT_AVAILABLE, null);
    321                             rr.release();
    322                             if (mRequestMessagesPending > 0)
    323                                 mRequestMessagesPending--;
    324                             alreadySubtracted = true;
    325                             return;
    326                         }
    327 
    328                         synchronized (mRequestList) {
    329                             mRequestList.add(rr);
    330                             mRequestMessagesWaiting++;
    331                         }
    332 
    333                         if (mRequestMessagesPending > 0)
    334                             mRequestMessagesPending--;
    335                         alreadySubtracted = true;
    336 
    337                         byte[] data;
    338 
    339                         data = rr.mParcel.marshall();
    340                         rr.mParcel.recycle();
    341                         rr.mParcel = null;
    342 
    343                         if (data.length > RIL_MAX_COMMAND_BYTES) {
    344                             throw new RuntimeException(
    345                                     "Parcel larger than max bytes allowed! "
    346                                                           + data.length);
    347                         }
    348 
    349                         // parcel length in big endian
    350                         dataLength[0] = dataLength[1] = 0;
    351                         dataLength[2] = (byte)((data.length >> 8) & 0xff);
    352                         dataLength[3] = (byte)((data.length) & 0xff);
    353 
    354                         //Rlog.v(RILJ_LOG_TAG, "writing packet: " + data.length + " bytes");
    355 
    356                         s.getOutputStream().write(dataLength);
    357                         s.getOutputStream().write(data);
    358                     } catch (IOException ex) {
    359                         Rlog.e(RILJ_LOG_TAG, "IOException", ex);
    360                         req = findAndRemoveRequestFromList(rr.mSerial);
    361                         // make sure this request has not already been handled,
    362                         // eg, if RILReceiver cleared the list.
    363                         if (req != null || !alreadySubtracted) {
    364                             rr.onError(RADIO_NOT_AVAILABLE, null);
    365                             rr.release();
    366                         }
    367                     } catch (RuntimeException exc) {
    368                         Rlog.e(RILJ_LOG_TAG, "Uncaught exception ", exc);
    369                         req = findAndRemoveRequestFromList(rr.mSerial);
    370                         // make sure this request has not already been handled,
    371                         // eg, if RILReceiver cleared the list.
    372                         if (req != null || !alreadySubtracted) {
    373                             rr.onError(GENERIC_FAILURE, null);
    374                             rr.release();
    375                         }
    376                     } finally {
    377                         // Note: We are "Done" only if there are no outstanding
    378                         // requests or replies. Thus this code path will only release
    379                         // the wake lock on errors.
    380                         releaseWakeLockIfDone();
    381                     }
    382 
    383                     if (!alreadySubtracted && mRequestMessagesPending > 0) {
    384                         mRequestMessagesPending--;
    385                     }
    386 
    387                     break;
    388 
    389                 case EVENT_WAKE_LOCK_TIMEOUT:
    390                     // Haven't heard back from the last request.  Assume we're
    391                     // not getting a response and  release the wake lock.
    392                     synchronized (mWakeLock) {
    393                         if (mWakeLock.isHeld()) {
    394                             // The timer of WAKE_LOCK_TIMEOUT is reset with each
    395                             // new send request. So when WAKE_LOCK_TIMEOUT occurs
    396                             // all requests in mRequestList already waited at
    397                             // least DEFAULT_WAKE_LOCK_TIMEOUT but no response.
    398                             // Reset mRequestMessagesWaiting to enable
    399                             // releaseWakeLockIfDone().
    400                             //
    401                             // Note: Keep mRequestList so that delayed response
    402                             // can still be handled when response finally comes.
    403                             if (mRequestMessagesWaiting != 0) {
    404                                 Rlog.d(RILJ_LOG_TAG, "NOTE: mReqWaiting is NOT 0 but"
    405                                         + mRequestMessagesWaiting + " at TIMEOUT, reset!"
    406                                         + " There still msg waitng for response");
    407 
    408                                 mRequestMessagesWaiting = 0;
    409 
    410                                 if (RILJ_LOGD) {
    411                                     synchronized (mRequestList) {
    412                                         int count = mRequestList.size();
    413                                         Rlog.d(RILJ_LOG_TAG, "WAKE_LOCK_TIMEOUT " +
    414                                                 " mRequestList=" + count);
    415 
    416                                         for (int i = 0; i < count; i++) {
    417                                             rr = mRequestList.get(i);
    418                                             Rlog.d(RILJ_LOG_TAG, i + ": [" + rr.mSerial + "] "
    419                                                     + requestToString(rr.mRequest));
    420                                         }
    421                                     }
    422                                 }
    423                             }
    424                             // mRequestMessagesPending shows how many
    425                             // requests are waiting to be sent (and before
    426                             // to be added in request list) since star the
    427                             // WAKE_LOCK_TIMEOUT timer. Since WAKE_LOCK_TIMEOUT
    428                             // is the expected time to get response, all requests
    429                             // should already sent out (i.e.
    430                             // mRequestMessagesPending is 0 )while TIMEOUT occurs.
    431                             if (mRequestMessagesPending != 0) {
    432                                 Rlog.e(RILJ_LOG_TAG, "ERROR: mReqPending is NOT 0 but"
    433                                         + mRequestMessagesPending + " at TIMEOUT, reset!");
    434                                 mRequestMessagesPending = 0;
    435 
    436                             }
    437                             mWakeLock.release();
    438                         }
    439                     }
    440                     break;
    441             }
    442         }
    443     }
    444 
    445     /**
    446      * Reads in a single RIL message off the wire. A RIL message consists
    447      * of a 4-byte little-endian length and a subsequent series of bytes.
    448      * The final message (length header omitted) is read into
    449      * <code>buffer</code> and the length of the final message (less header)
    450      * is returned. A return value of -1 indicates end-of-stream.
    451      *
    452      * @param is non-null; Stream to read from
    453      * @param buffer Buffer to fill in. Must be as large as maximum
    454      * message size, or an ArrayOutOfBounds exception will be thrown.
    455      * @return Length of message less header, or -1 on end of stream.
    456      * @throws IOException
    457      */
    458     private static int readRilMessage(InputStream is, byte[] buffer)
    459             throws IOException {
    460         int countRead;
    461         int offset;
    462         int remaining;
    463         int messageLength;
    464 
    465         // First, read in the length of the message
    466         offset = 0;
    467         remaining = 4;
    468         do {
    469             countRead = is.read(buffer, offset, remaining);
    470 
    471             if (countRead < 0 ) {
    472                 Rlog.e(RILJ_LOG_TAG, "Hit EOS reading message length");
    473                 return -1;
    474             }
    475 
    476             offset += countRead;
    477             remaining -= countRead;
    478         } while (remaining > 0);
    479 
    480         messageLength = ((buffer[0] & 0xff) << 24)
    481                 | ((buffer[1] & 0xff) << 16)
    482                 | ((buffer[2] & 0xff) << 8)
    483                 | (buffer[3] & 0xff);
    484 
    485         // Then, re-use the buffer and read in the message itself
    486         offset = 0;
    487         remaining = messageLength;
    488         do {
    489             countRead = is.read(buffer, offset, remaining);
    490 
    491             if (countRead < 0 ) {
    492                 Rlog.e(RILJ_LOG_TAG, "Hit EOS reading message.  messageLength=" + messageLength
    493                         + " remaining=" + remaining);
    494                 return -1;
    495             }
    496 
    497             offset += countRead;
    498             remaining -= countRead;
    499         } while (remaining > 0);
    500 
    501         return messageLength;
    502     }
    503 
    504     class RILReceiver implements Runnable {
    505         byte[] buffer;
    506 
    507         RILReceiver() {
    508             buffer = new byte[RIL_MAX_COMMAND_BYTES];
    509         }
    510 
    511         @Override
    512         public void
    513         run() {
    514             int retryCount = 0;
    515 
    516             try {for (;;) {
    517                 LocalSocket s = null;
    518                 LocalSocketAddress l;
    519 
    520                 try {
    521                     s = new LocalSocket();
    522                     l = new LocalSocketAddress(SOCKET_NAME_RIL,
    523                             LocalSocketAddress.Namespace.RESERVED);
    524                     s.connect(l);
    525                 } catch (IOException ex){
    526                     try {
    527                         if (s != null) {
    528                             s.close();
    529                         }
    530                     } catch (IOException ex2) {
    531                         //ignore failure to close after failure to connect
    532                     }
    533 
    534                     // don't print an error message after the the first time
    535                     // or after the 8th time
    536 
    537                     if (retryCount == 8) {
    538                         Rlog.e (RILJ_LOG_TAG,
    539                             "Couldn't find '" + SOCKET_NAME_RIL
    540                             + "' socket after " + retryCount
    541                             + " times, continuing to retry silently");
    542                     } else if (retryCount > 0 && retryCount < 8) {
    543                         Rlog.i (RILJ_LOG_TAG,
    544                             "Couldn't find '" + SOCKET_NAME_RIL
    545                             + "' socket; retrying after timeout");
    546                     }
    547 
    548                     try {
    549                         Thread.sleep(SOCKET_OPEN_RETRY_MILLIS);
    550                     } catch (InterruptedException er) {
    551                     }
    552 
    553                     retryCount++;
    554                     continue;
    555                 }
    556 
    557                 retryCount = 0;
    558 
    559                 mSocket = s;
    560                 Rlog.i(RILJ_LOG_TAG, "Connected to '" + SOCKET_NAME_RIL + "' socket");
    561 
    562                 int length = 0;
    563                 try {
    564                     InputStream is = mSocket.getInputStream();
    565 
    566                     for (;;) {
    567                         Parcel p;
    568 
    569                         length = readRilMessage(is, buffer);
    570 
    571                         if (length < 0) {
    572                             // End-of-stream reached
    573                             break;
    574                         }
    575 
    576                         p = Parcel.obtain();
    577                         p.unmarshall(buffer, 0, length);
    578                         p.setDataPosition(0);
    579 
    580                         //Rlog.v(RILJ_LOG_TAG, "Read packet: " + length + " bytes");
    581 
    582                         processResponse(p);
    583                         p.recycle();
    584                     }
    585                 } catch (java.io.IOException ex) {
    586                     Rlog.i(RILJ_LOG_TAG, "'" + SOCKET_NAME_RIL + "' socket closed",
    587                           ex);
    588                 } catch (Throwable tr) {
    589                     Rlog.e(RILJ_LOG_TAG, "Uncaught exception read length=" + length +
    590                         "Exception:" + tr.toString());
    591                 }
    592 
    593                 Rlog.i(RILJ_LOG_TAG, "Disconnected from '" + SOCKET_NAME_RIL
    594                       + "' socket");
    595 
    596                 setRadioState (RadioState.RADIO_UNAVAILABLE);
    597 
    598                 try {
    599                     mSocket.close();
    600                 } catch (IOException ex) {
    601                 }
    602 
    603                 mSocket = null;
    604                 RILRequest.resetSerial();
    605 
    606                 // Clear request list on close
    607                 clearRequestList(RADIO_NOT_AVAILABLE, false);
    608             }} catch (Throwable tr) {
    609                 Rlog.e(RILJ_LOG_TAG,"Uncaught exception", tr);
    610             }
    611 
    612             /* We're disconnected so we don't know the ril version */
    613             notifyRegistrantsRilConnectionChanged(-1);
    614         }
    615     }
    616 
    617 
    618 
    619     //***** Constructors
    620 
    621     public RIL(Context context, int preferredNetworkType, int cdmaSubscription) {
    622         super(context);
    623         if (RILJ_LOGD) {
    624             riljLog("RIL(context, preferredNetworkType=" + preferredNetworkType +
    625                     " cdmaSubscription=" + cdmaSubscription + ")");
    626         }
    627         mCdmaSubscription  = cdmaSubscription;
    628         mPreferredNetworkType = preferredNetworkType;
    629         mPhoneType = RILConstants.NO_PHONE;
    630 
    631         PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
    632         mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, RILJ_LOG_TAG);
    633         mWakeLock.setReferenceCounted(false);
    634         mWakeLockTimeout = SystemProperties.getInt(TelephonyProperties.PROPERTY_WAKE_LOCK_TIMEOUT,
    635                 DEFAULT_WAKE_LOCK_TIMEOUT);
    636         mRequestMessagesPending = 0;
    637         mRequestMessagesWaiting = 0;
    638 
    639         mSenderThread = new HandlerThread("RILSender");
    640         mSenderThread.start();
    641 
    642         Looper looper = mSenderThread.getLooper();
    643         mSender = new RILSender(looper);
    644 
    645         ConnectivityManager cm = (ConnectivityManager)context.getSystemService(
    646                 Context.CONNECTIVITY_SERVICE);
    647         if (cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE) == false) {
    648             riljLog("Not starting RILReceiver: wifi-only");
    649         } else {
    650             riljLog("Starting RILReceiver");
    651             mReceiver = new RILReceiver();
    652             mReceiverThread = new Thread(mReceiver, "RILReceiver");
    653             mReceiverThread.start();
    654 
    655             IntentFilter filter = new IntentFilter();
    656             filter.addAction(Intent.ACTION_SCREEN_ON);
    657             filter.addAction(Intent.ACTION_SCREEN_OFF);
    658             context.registerReceiver(mIntentReceiver, filter);
    659         }
    660     }
    661 
    662     //***** CommandsInterface implementation
    663 
    664     @Override
    665     public void getVoiceRadioTechnology(Message result) {
    666         RILRequest rr = RILRequest.obtain(RIL_REQUEST_VOICE_RADIO_TECH, result);
    667 
    668         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
    669 
    670         send(rr);
    671     }
    672 
    673 
    674     @Override public void
    675     setOnNITZTime(Handler h, int what, Object obj) {
    676         super.setOnNITZTime(h, what, obj);
    677 
    678         // Send the last NITZ time if we have it
    679         if (mLastNITZTimeInfo != null) {
    680             mNITZTimeRegistrant
    681                 .notifyRegistrant(
    682                     new AsyncResult (null, mLastNITZTimeInfo, null));
    683             mLastNITZTimeInfo = null;
    684         }
    685     }
    686 
    687     @Override
    688     public void
    689     getIccCardStatus(Message result) {
    690         //Note: This RIL request has not been renamed to ICC,
    691         //       but this request is also valid for SIM and RUIM
    692         RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_SIM_STATUS, result);
    693 
    694         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
    695 
    696         send(rr);
    697     }
    698 
    699     @Override public void
    700     supplyIccPin(String pin, Message result) {
    701         supplyIccPinForApp(pin, null, result);
    702     }
    703 
    704     @Override public void
    705     supplyIccPinForApp(String pin, String aid, Message result) {
    706         //Note: This RIL request has not been renamed to ICC,
    707         //       but this request is also valid for SIM and RUIM
    708         RILRequest rr = RILRequest.obtain(RIL_REQUEST_ENTER_SIM_PIN, result);
    709 
    710         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
    711 
    712         rr.mParcel.writeInt(2);
    713         rr.mParcel.writeString(pin);
    714         rr.mParcel.writeString(aid);
    715 
    716         send(rr);
    717     }
    718 
    719     @Override public void
    720     supplyIccPuk(String puk, String newPin, Message result) {
    721         supplyIccPukForApp(puk, newPin, null, result);
    722     }
    723 
    724     @Override public void
    725     supplyIccPukForApp(String puk, String newPin, String aid, Message result) {
    726         //Note: This RIL request has not been renamed to ICC,
    727         //       but this request is also valid for SIM and RUIM
    728         RILRequest rr = RILRequest.obtain(RIL_REQUEST_ENTER_SIM_PUK, result);
    729 
    730         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
    731 
    732         rr.mParcel.writeInt(3);
    733         rr.mParcel.writeString(puk);
    734         rr.mParcel.writeString(newPin);
    735         rr.mParcel.writeString(aid);
    736 
    737         send(rr);
    738     }
    739 
    740     @Override public void
    741     supplyIccPin2(String pin, Message result) {
    742         supplyIccPin2ForApp(pin, null, result);
    743     }
    744 
    745     @Override public void
    746     supplyIccPin2ForApp(String pin, String aid, Message result) {
    747         //Note: This RIL request has not been renamed to ICC,
    748         //       but this request is also valid for SIM and RUIM
    749         RILRequest rr = RILRequest.obtain(RIL_REQUEST_ENTER_SIM_PIN2, result);
    750 
    751         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
    752 
    753         rr.mParcel.writeInt(2);
    754         rr.mParcel.writeString(pin);
    755         rr.mParcel.writeString(aid);
    756 
    757         send(rr);
    758     }
    759 
    760     @Override public void
    761     supplyIccPuk2(String puk2, String newPin2, Message result) {
    762         supplyIccPuk2ForApp(puk2, newPin2, null, result);
    763     }
    764 
    765     @Override public void
    766     supplyIccPuk2ForApp(String puk, String newPin2, String aid, Message result) {
    767         //Note: This RIL request has not been renamed to ICC,
    768         //       but this request is also valid for SIM and RUIM
    769         RILRequest rr = RILRequest.obtain(RIL_REQUEST_ENTER_SIM_PUK2, result);
    770 
    771         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
    772 
    773         rr.mParcel.writeInt(3);
    774         rr.mParcel.writeString(puk);
    775         rr.mParcel.writeString(newPin2);
    776         rr.mParcel.writeString(aid);
    777 
    778         send(rr);
    779     }
    780 
    781     @Override public void
    782     changeIccPin(String oldPin, String newPin, Message result) {
    783         changeIccPinForApp(oldPin, newPin, null, result);
    784     }
    785 
    786     @Override public void
    787     changeIccPinForApp(String oldPin, String newPin, String aid, Message result) {
    788         //Note: This RIL request has not been renamed to ICC,
    789         //       but this request is also valid for SIM and RUIM
    790         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CHANGE_SIM_PIN, result);
    791 
    792         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
    793 
    794         rr.mParcel.writeInt(3);
    795         rr.mParcel.writeString(oldPin);
    796         rr.mParcel.writeString(newPin);
    797         rr.mParcel.writeString(aid);
    798 
    799         send(rr);
    800     }
    801 
    802     @Override public void
    803     changeIccPin2(String oldPin2, String newPin2, Message result) {
    804         changeIccPin2ForApp(oldPin2, newPin2, null, result);
    805     }
    806 
    807     @Override public void
    808     changeIccPin2ForApp(String oldPin2, String newPin2, String aid, Message result) {
    809         //Note: This RIL request has not been renamed to ICC,
    810         //       but this request is also valid for SIM and RUIM
    811         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CHANGE_SIM_PIN2, result);
    812 
    813         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
    814 
    815         rr.mParcel.writeInt(3);
    816         rr.mParcel.writeString(oldPin2);
    817         rr.mParcel.writeString(newPin2);
    818         rr.mParcel.writeString(aid);
    819 
    820         send(rr);
    821     }
    822 
    823     @Override
    824     public void
    825     changeBarringPassword(String facility, String oldPwd, String newPwd, Message result) {
    826         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CHANGE_BARRING_PASSWORD, result);
    827 
    828         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
    829 
    830         rr.mParcel.writeInt(3);
    831         rr.mParcel.writeString(facility);
    832         rr.mParcel.writeString(oldPwd);
    833         rr.mParcel.writeString(newPwd);
    834 
    835         send(rr);
    836     }
    837 
    838     @Override
    839     public void
    840     supplyNetworkDepersonalization(String netpin, Message result) {
    841         RILRequest rr = RILRequest.obtain(RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION, result);
    842 
    843         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
    844 
    845         rr.mParcel.writeInt(1);
    846         rr.mParcel.writeString(netpin);
    847 
    848         send(rr);
    849     }
    850 
    851     @Override
    852     public void
    853     getCurrentCalls (Message result) {
    854         RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_CURRENT_CALLS, result);
    855 
    856         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
    857 
    858         send(rr);
    859     }
    860 
    861     @Override
    862     @Deprecated public void
    863     getPDPContextList(Message result) {
    864         getDataCallList(result);
    865     }
    866 
    867     @Override
    868     public void
    869     getDataCallList(Message result) {
    870         RILRequest rr = RILRequest.obtain(RIL_REQUEST_DATA_CALL_LIST, result);
    871 
    872         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
    873 
    874         send(rr);
    875     }
    876 
    877     @Override
    878     public void
    879     dial (String address, int clirMode, Message result) {
    880         dial(address, clirMode, null, result);
    881     }
    882 
    883     @Override
    884     public void
    885     dial(String address, int clirMode, UUSInfo uusInfo, Message result) {
    886         RILRequest rr = RILRequest.obtain(RIL_REQUEST_DIAL, result);
    887 
    888         rr.mParcel.writeString(address);
    889         rr.mParcel.writeInt(clirMode);
    890 
    891         if (uusInfo == null) {
    892             rr.mParcel.writeInt(0); // UUS information is absent
    893         } else {
    894             rr.mParcel.writeInt(1); // UUS information is present
    895             rr.mParcel.writeInt(uusInfo.getType());
    896             rr.mParcel.writeInt(uusInfo.getDcs());
    897             rr.mParcel.writeByteArray(uusInfo.getUserData());
    898         }
    899 
    900         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
    901 
    902         send(rr);
    903     }
    904 
    905     @Override
    906     public void
    907     getIMSI(Message result) {
    908         getIMSIForApp(null, result);
    909     }
    910 
    911     @Override
    912     public void
    913     getIMSIForApp(String aid, Message result) {
    914         RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_IMSI, result);
    915 
    916         rr.mParcel.writeInt(1);
    917         rr.mParcel.writeString(aid);
    918 
    919         if (RILJ_LOGD) riljLog(rr.serialString() +
    920                               "> getIMSI: " + requestToString(rr.mRequest)
    921                               + " aid: " + aid);
    922 
    923         send(rr);
    924     }
    925 
    926     @Override
    927     public void
    928     getIMEI(Message result) {
    929         RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_IMEI, result);
    930 
    931         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
    932 
    933         send(rr);
    934     }
    935 
    936     @Override
    937     public void
    938     getIMEISV(Message result) {
    939         RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_IMEISV, result);
    940 
    941         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
    942 
    943         send(rr);
    944     }
    945 
    946 
    947     @Override
    948     public void
    949     hangupConnection (int gsmIndex, Message result) {
    950         if (RILJ_LOGD) riljLog("hangupConnection: gsmIndex=" + gsmIndex);
    951 
    952         RILRequest rr = RILRequest.obtain(RIL_REQUEST_HANGUP, result);
    953 
    954         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " " +
    955                 gsmIndex);
    956 
    957         rr.mParcel.writeInt(1);
    958         rr.mParcel.writeInt(gsmIndex);
    959 
    960         send(rr);
    961     }
    962 
    963     @Override
    964     public void
    965     hangupWaitingOrBackground (Message result) {
    966         RILRequest rr = RILRequest.obtain(RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND,
    967                                         result);
    968 
    969         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
    970 
    971         send(rr);
    972     }
    973 
    974     @Override
    975     public void
    976     hangupForegroundResumeBackground (Message result) {
    977         RILRequest rr
    978                 = RILRequest.obtain(
    979                         RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND,
    980                                         result);
    981         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
    982 
    983         send(rr);
    984     }
    985 
    986     @Override
    987     public void
    988     switchWaitingOrHoldingAndActive (Message result) {
    989         RILRequest rr
    990                 = RILRequest.obtain(
    991                         RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE,
    992                                         result);
    993         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
    994 
    995         send(rr);
    996     }
    997 
    998     @Override
    999     public void
   1000     conference (Message result) {
   1001         RILRequest rr
   1002                 = RILRequest.obtain(RIL_REQUEST_CONFERENCE, result);
   1003 
   1004         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
   1005 
   1006         send(rr);
   1007     }
   1008 
   1009 
   1010     @Override
   1011     public void setPreferredVoicePrivacy(boolean enable, Message result) {
   1012         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE,
   1013                 result);
   1014 
   1015         rr.mParcel.writeInt(1);
   1016         rr.mParcel.writeInt(enable ? 1:0);
   1017 
   1018         send(rr);
   1019     }
   1020 
   1021     @Override
   1022     public void getPreferredVoicePrivacy(Message result) {
   1023         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE,
   1024                 result);
   1025         send(rr);
   1026     }
   1027 
   1028     @Override
   1029     public void
   1030     separateConnection (int gsmIndex, Message result) {
   1031         RILRequest rr
   1032                 = RILRequest.obtain(RIL_REQUEST_SEPARATE_CONNECTION, result);
   1033 
   1034         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
   1035                             + " " + gsmIndex);
   1036 
   1037         rr.mParcel.writeInt(1);
   1038         rr.mParcel.writeInt(gsmIndex);
   1039 
   1040         send(rr);
   1041     }
   1042 
   1043     @Override
   1044     public void
   1045     acceptCall (Message result) {
   1046         RILRequest rr
   1047                 = RILRequest.obtain(RIL_REQUEST_ANSWER, result);
   1048 
   1049         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
   1050 
   1051         send(rr);
   1052     }
   1053 
   1054     @Override
   1055     public void
   1056     rejectCall (Message result) {
   1057         RILRequest rr
   1058                 = RILRequest.obtain(RIL_REQUEST_UDUB, result);
   1059 
   1060         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
   1061 
   1062         send(rr);
   1063     }
   1064 
   1065     @Override
   1066     public void
   1067     explicitCallTransfer (Message result) {
   1068         RILRequest rr
   1069                 = RILRequest.obtain(RIL_REQUEST_EXPLICIT_CALL_TRANSFER, result);
   1070 
   1071         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
   1072 
   1073         send(rr);
   1074     }
   1075 
   1076     @Override
   1077     public void
   1078     getLastCallFailCause (Message result) {
   1079         RILRequest rr
   1080                 = RILRequest.obtain(RIL_REQUEST_LAST_CALL_FAIL_CAUSE, result);
   1081 
   1082         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
   1083 
   1084         send(rr);
   1085     }
   1086 
   1087     /**
   1088      * @deprecated
   1089      */
   1090     @Deprecated
   1091     @Override
   1092     public void
   1093     getLastPdpFailCause (Message result) {
   1094         getLastDataCallFailCause (result);
   1095     }
   1096 
   1097     /**
   1098      * The preferred new alternative to getLastPdpFailCause
   1099      */
   1100     @Override
   1101     public void
   1102     getLastDataCallFailCause (Message result) {
   1103         RILRequest rr
   1104                 = RILRequest.obtain(RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE, result);
   1105 
   1106         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
   1107 
   1108         send(rr);
   1109     }
   1110 
   1111     @Override
   1112     public void
   1113     setMute (boolean enableMute, Message response) {
   1114         RILRequest rr
   1115                 = RILRequest.obtain(RIL_REQUEST_SET_MUTE, response);
   1116 
   1117         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
   1118                             + " " + enableMute);
   1119 
   1120         rr.mParcel.writeInt(1);
   1121         rr.mParcel.writeInt(enableMute ? 1 : 0);
   1122 
   1123         send(rr);
   1124     }
   1125 
   1126     @Override
   1127     public void
   1128     getMute (Message response) {
   1129         RILRequest rr
   1130                 = RILRequest.obtain(RIL_REQUEST_GET_MUTE, response);
   1131 
   1132         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
   1133 
   1134         send(rr);
   1135     }
   1136 
   1137     @Override
   1138     public void
   1139     getSignalStrength (Message result) {
   1140         RILRequest rr
   1141                 = RILRequest.obtain(RIL_REQUEST_SIGNAL_STRENGTH, result);
   1142 
   1143         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
   1144 
   1145         send(rr);
   1146     }
   1147 
   1148     @Override
   1149     public void
   1150     getVoiceRegistrationState (Message result) {
   1151         RILRequest rr
   1152                 = RILRequest.obtain(RIL_REQUEST_VOICE_REGISTRATION_STATE, result);
   1153 
   1154         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
   1155 
   1156         send(rr);
   1157     }
   1158 
   1159     @Override
   1160     public void
   1161     getDataRegistrationState (Message result) {
   1162         RILRequest rr
   1163                 = RILRequest.obtain(RIL_REQUEST_DATA_REGISTRATION_STATE, result);
   1164 
   1165         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
   1166 
   1167         send(rr);
   1168     }
   1169 
   1170     @Override
   1171     public void
   1172     getOperator(Message result) {
   1173         RILRequest rr
   1174                 = RILRequest.obtain(RIL_REQUEST_OPERATOR, result);
   1175 
   1176         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
   1177 
   1178         send(rr);
   1179     }
   1180 
   1181     @Override
   1182     public void
   1183     sendDtmf(char c, Message result) {
   1184         RILRequest rr
   1185                 = RILRequest.obtain(RIL_REQUEST_DTMF, result);
   1186 
   1187         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
   1188 
   1189         rr.mParcel.writeString(Character.toString(c));
   1190 
   1191         send(rr);
   1192     }
   1193 
   1194     @Override
   1195     public void
   1196     startDtmf(char c, Message result) {
   1197         RILRequest rr
   1198                 = RILRequest.obtain(RIL_REQUEST_DTMF_START, result);
   1199 
   1200         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
   1201 
   1202         rr.mParcel.writeString(Character.toString(c));
   1203 
   1204         send(rr);
   1205     }
   1206 
   1207     @Override
   1208     public void
   1209     stopDtmf(Message result) {
   1210         RILRequest rr
   1211                 = RILRequest.obtain(RIL_REQUEST_DTMF_STOP, result);
   1212 
   1213         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
   1214 
   1215         send(rr);
   1216     }
   1217 
   1218     @Override
   1219     public void
   1220     sendBurstDtmf(String dtmfString, int on, int off, Message result) {
   1221         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_BURST_DTMF, result);
   1222 
   1223         rr.mParcel.writeInt(3);
   1224         rr.mParcel.writeString(dtmfString);
   1225         rr.mParcel.writeString(Integer.toString(on));
   1226         rr.mParcel.writeString(Integer.toString(off));
   1227 
   1228         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
   1229                 + " : " + dtmfString);
   1230 
   1231         send(rr);
   1232     }
   1233 
   1234     @Override
   1235     public void
   1236     sendSMS (String smscPDU, String pdu, Message result) {
   1237         RILRequest rr
   1238                 = RILRequest.obtain(RIL_REQUEST_SEND_SMS, result);
   1239 
   1240         rr.mParcel.writeInt(2);
   1241         rr.mParcel.writeString(smscPDU);
   1242         rr.mParcel.writeString(pdu);
   1243 
   1244         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
   1245 
   1246         send(rr);
   1247     }
   1248 
   1249     @Override
   1250     public void
   1251     sendCdmaSms(byte[] pdu, Message result) {
   1252         int address_nbr_of_digits;
   1253         int subaddr_nbr_of_digits;
   1254         int bearerDataLength;
   1255         ByteArrayInputStream bais = new ByteArrayInputStream(pdu);
   1256         DataInputStream dis = new DataInputStream(bais);
   1257 
   1258         RILRequest rr
   1259                 = RILRequest.obtain(RIL_REQUEST_CDMA_SEND_SMS, result);
   1260 
   1261         try {
   1262             rr.mParcel.writeInt(dis.readInt()); //teleServiceId
   1263             rr.mParcel.writeByte((byte) dis.readInt()); //servicePresent
   1264             rr.mParcel.writeInt(dis.readInt()); //serviceCategory
   1265             rr.mParcel.writeInt(dis.read()); //address_digit_mode
   1266             rr.mParcel.writeInt(dis.read()); //address_nbr_mode
   1267             rr.mParcel.writeInt(dis.read()); //address_ton
   1268             rr.mParcel.writeInt(dis.read()); //address_nbr_plan
   1269             address_nbr_of_digits = (byte) dis.read();
   1270             rr.mParcel.writeByte((byte) address_nbr_of_digits);
   1271             for(int i=0; i < address_nbr_of_digits; i++){
   1272                 rr.mParcel.writeByte(dis.readByte()); // address_orig_bytes[i]
   1273             }
   1274             rr.mParcel.writeInt(dis.read()); //subaddressType
   1275             rr.mParcel.writeByte((byte) dis.read()); //subaddr_odd
   1276             subaddr_nbr_of_digits = (byte) dis.read();
   1277             rr.mParcel.writeByte((byte) subaddr_nbr_of_digits);
   1278             for(int i=0; i < subaddr_nbr_of_digits; i++){
   1279                 rr.mParcel.writeByte(dis.readByte()); //subaddr_orig_bytes[i]
   1280             }
   1281 
   1282             bearerDataLength = dis.read();
   1283             rr.mParcel.writeInt(bearerDataLength);
   1284             for(int i=0; i < bearerDataLength; i++){
   1285                 rr.mParcel.writeByte(dis.readByte()); //bearerData[i]
   1286             }
   1287         }catch (IOException ex){
   1288             if (RILJ_LOGD) riljLog("sendSmsCdma: conversion from input stream to object failed: "
   1289                     + ex);
   1290         }
   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             mRequestMessagesPending++;
   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     releaseWakeLockIfDone() {
   2189         synchronized (mWakeLock) {
   2190             if (mWakeLock.isHeld() &&
   2191                 (mRequestMessagesPending == 0) &&
   2192                 (mRequestMessagesWaiting == 0)) {
   2193                 mSender.removeMessages(EVENT_WAKE_LOCK_TIMEOUT);
   2194                 mWakeLock.release();
   2195             }
   2196         }
   2197     }
   2198 
   2199     private void
   2200     send(RILRequest rr) {
   2201         Message msg;
   2202 
   2203         if (mSocket == null) {
   2204             rr.onError(RADIO_NOT_AVAILABLE, null);
   2205             rr.release();
   2206             return;
   2207         }
   2208 
   2209         msg = mSender.obtainMessage(EVENT_SEND, rr);
   2210 
   2211         acquireWakeLock();
   2212 
   2213         msg.sendToTarget();
   2214     }
   2215 
   2216     private void
   2217     processResponse (Parcel p) {
   2218         int type;
   2219 
   2220         type = p.readInt();
   2221 
   2222         if (type == RESPONSE_UNSOLICITED) {
   2223             processUnsolicited (p);
   2224         } else if (type == RESPONSE_SOLICITED) {
   2225             processSolicited (p);
   2226         }
   2227 
   2228         releaseWakeLockIfDone();
   2229     }
   2230 
   2231     /**
   2232      * Release each request in mRequestList then clear the list
   2233      * @param error is the RIL_Errno sent back
   2234      * @param loggable true means to print all requests in mRequestList
   2235      */
   2236     private void clearRequestList(int error, boolean loggable) {
   2237         RILRequest rr;
   2238         synchronized (mRequestList) {
   2239             int count = mRequestList.size();
   2240             if (RILJ_LOGD && loggable) {
   2241                 Rlog.d(RILJ_LOG_TAG, "WAKE_LOCK_TIMEOUT " +
   2242                         " mReqPending=" + mRequestMessagesPending +
   2243                         " mRequestList=" + count);
   2244             }
   2245 
   2246             for (int i = 0; i < count ; i++) {
   2247                 rr = mRequestList.get(i);
   2248                 if (RILJ_LOGD && loggable) {
   2249                     Rlog.d(RILJ_LOG_TAG, i + ": [" + rr.mSerial + "] " +
   2250                             requestToString(rr.mRequest));
   2251                 }
   2252                 rr.onError(error, null);
   2253                 rr.release();
   2254             }
   2255             mRequestList.clear();
   2256             mRequestMessagesWaiting = 0;
   2257         }
   2258     }
   2259 
   2260     private RILRequest findAndRemoveRequestFromList(int serial) {
   2261         synchronized (mRequestList) {
   2262             for (int i = 0, s = mRequestList.size() ; i < s ; i++) {
   2263                 RILRequest rr = mRequestList.get(i);
   2264 
   2265                 if (rr.mSerial == serial) {
   2266                     mRequestList.remove(i);
   2267                     if (mRequestMessagesWaiting > 0)
   2268                         mRequestMessagesWaiting--;
   2269                     return rr;
   2270                 }
   2271             }
   2272         }
   2273 
   2274         return null;
   2275     }
   2276 
   2277     private void
   2278     processSolicited (Parcel p) {
   2279         int serial, error;
   2280         boolean found = false;
   2281 
   2282         serial = p.readInt();
   2283         error = p.readInt();
   2284 
   2285         RILRequest rr;
   2286 
   2287         rr = findAndRemoveRequestFromList(serial);
   2288 
   2289         if (rr == null) {
   2290             Rlog.w(RILJ_LOG_TAG, "Unexpected solicited response! sn: "
   2291                             + serial + " error: " + error);
   2292             return;
   2293         }
   2294 
   2295         Object ret = null;
   2296 
   2297         if (error == 0 || p.dataAvail() > 0) {
   2298             // either command succeeds or command fails but with data payload
   2299             try {switch (rr.mRequest) {
   2300             /*
   2301  cat libs/telephony/ril_commands.h \
   2302  | egrep "^ *{RIL_" \
   2303  | sed -re 's/\{([^,]+),[^,]+,([^}]+).+/case \1: ret = \2(p); break;/'
   2304              */
   2305             case RIL_REQUEST_GET_SIM_STATUS: ret =  responseIccCardStatus(p); break;
   2306             case RIL_REQUEST_ENTER_SIM_PIN: ret =  responseInts(p); break;
   2307             case RIL_REQUEST_ENTER_SIM_PUK: ret =  responseInts(p); break;
   2308             case RIL_REQUEST_ENTER_SIM_PIN2: ret =  responseInts(p); break;
   2309             case RIL_REQUEST_ENTER_SIM_PUK2: ret =  responseInts(p); break;
   2310             case RIL_REQUEST_CHANGE_SIM_PIN: ret =  responseInts(p); break;
   2311             case RIL_REQUEST_CHANGE_SIM_PIN2: ret =  responseInts(p); break;
   2312             case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: ret =  responseInts(p); break;
   2313             case RIL_REQUEST_GET_CURRENT_CALLS: ret =  responseCallList(p); break;
   2314             case RIL_REQUEST_DIAL: ret =  responseVoid(p); break;
   2315             case RIL_REQUEST_GET_IMSI: ret =  responseString(p); break;
   2316             case RIL_REQUEST_HANGUP: ret =  responseVoid(p); break;
   2317             case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: ret =  responseVoid(p); break;
   2318             case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: {
   2319                 if (mTestingEmergencyCall.getAndSet(false)) {
   2320                     if (mEmergencyCallbackModeRegistrant != null) {
   2321                         riljLog("testing emergency call, notify ECM Registrants");
   2322                         mEmergencyCallbackModeRegistrant.notifyRegistrant();
   2323                     }
   2324                 }
   2325                 ret =  responseVoid(p);
   2326                 break;
   2327             }
   2328             case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: ret =  responseVoid(p); break;
   2329             case RIL_REQUEST_CONFERENCE: ret =  responseVoid(p); break;
   2330             case RIL_REQUEST_UDUB: ret =  responseVoid(p); break;
   2331             case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: ret =  responseInts(p); break;
   2332             case RIL_REQUEST_SIGNAL_STRENGTH: ret =  responseSignalStrength(p); break;
   2333             case RIL_REQUEST_VOICE_REGISTRATION_STATE: ret =  responseStrings(p); break;
   2334             case RIL_REQUEST_DATA_REGISTRATION_STATE: ret =  responseStrings(p); break;
   2335             case RIL_REQUEST_OPERATOR: ret =  responseStrings(p); break;
   2336             case RIL_REQUEST_RADIO_POWER: ret =  responseVoid(p); break;
   2337             case RIL_REQUEST_DTMF: ret =  responseVoid(p); break;
   2338             case RIL_REQUEST_SEND_SMS: ret =  responseSMS(p); break;
   2339             case RIL_REQUEST_SEND_SMS_EXPECT_MORE: ret =  responseSMS(p); break;
   2340             case RIL_REQUEST_SETUP_DATA_CALL: ret =  responseSetupDataCall(p); break;
   2341             case RIL_REQUEST_SIM_IO: ret =  responseICC_IO(p); break;
   2342             case RIL_REQUEST_SEND_USSD: ret =  responseVoid(p); break;
   2343             case RIL_REQUEST_CANCEL_USSD: ret =  responseVoid(p); break;
   2344             case RIL_REQUEST_GET_CLIR: ret =  responseInts(p); break;
   2345             case RIL_REQUEST_SET_CLIR: ret =  responseVoid(p); break;
   2346             case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: ret =  responseCallForward(p); break;
   2347             case RIL_REQUEST_SET_CALL_FORWARD: ret =  responseVoid(p); break;
   2348             case RIL_REQUEST_QUERY_CALL_WAITING: ret =  responseInts(p); break;
   2349             case RIL_REQUEST_SET_CALL_WAITING: ret =  responseVoid(p); break;
   2350             case RIL_REQUEST_SMS_ACKNOWLEDGE: ret =  responseVoid(p); break;
   2351             case RIL_REQUEST_GET_IMEI: ret =  responseString(p); break;
   2352             case RIL_REQUEST_GET_IMEISV: ret =  responseString(p); break;
   2353             case RIL_REQUEST_ANSWER: ret =  responseVoid(p); break;
   2354             case RIL_REQUEST_DEACTIVATE_DATA_CALL: ret =  responseVoid(p); break;
   2355             case RIL_REQUEST_QUERY_FACILITY_LOCK: ret =  responseInts(p); break;
   2356             case RIL_REQUEST_SET_FACILITY_LOCK: ret =  responseInts(p); break;
   2357             case RIL_REQUEST_CHANGE_BARRING_PASSWORD: ret =  responseVoid(p); break;
   2358             case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: ret =  responseInts(p); break;
   2359             case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: ret =  responseVoid(p); break;
   2360             case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: ret =  responseVoid(p); break;
   2361             case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : ret =  responseOperatorInfos(p); break;
   2362             case RIL_REQUEST_DTMF_START: ret =  responseVoid(p); break;
   2363             case RIL_REQUEST_DTMF_STOP: ret =  responseVoid(p); break;
   2364             case RIL_REQUEST_BASEBAND_VERSION: ret =  responseString(p); break;
   2365             case RIL_REQUEST_SEPARATE_CONNECTION: ret =  responseVoid(p); break;
   2366             case RIL_REQUEST_SET_MUTE: ret =  responseVoid(p); break;
   2367             case RIL_REQUEST_GET_MUTE: ret =  responseInts(p); break;
   2368             case RIL_REQUEST_QUERY_CLIP: ret =  responseInts(p); break;
   2369             case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: ret =  responseInts(p); break;
   2370             case RIL_REQUEST_DATA_CALL_LIST: ret =  responseDataCallList(p); break;
   2371             case RIL_REQUEST_RESET_RADIO: ret =  responseVoid(p); break;
   2372             case RIL_REQUEST_OEM_HOOK_RAW: ret =  responseRaw(p); break;
   2373             case RIL_REQUEST_OEM_HOOK_STRINGS: ret =  responseStrings(p); break;
   2374             case RIL_REQUEST_SCREEN_STATE: ret =  responseVoid(p); break;
   2375             case RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION: ret =  responseVoid(p); break;
   2376             case RIL_REQUEST_WRITE_SMS_TO_SIM: ret =  responseInts(p); break;
   2377             case RIL_REQUEST_DELETE_SMS_ON_SIM: ret =  responseVoid(p); break;
   2378             case RIL_REQUEST_SET_BAND_MODE: ret =  responseVoid(p); break;
   2379             case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: ret =  responseInts(p); break;
   2380             case RIL_REQUEST_STK_GET_PROFILE: ret =  responseString(p); break;
   2381             case RIL_REQUEST_STK_SET_PROFILE: ret =  responseVoid(p); break;
   2382             case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: ret =  responseString(p); break;
   2383             case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: ret =  responseVoid(p); break;
   2384             case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: ret =  responseInts(p); break;
   2385             case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: ret =  responseVoid(p); break;
   2386             case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: ret =  responseVoid(p); break;
   2387             case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: ret =  responseGetPreferredNetworkType(p); break;
   2388             case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: ret = responseCellList(p); break;
   2389             case RIL_REQUEST_SET_LOCATION_UPDATES: ret =  responseVoid(p); break;
   2390             case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE: ret =  responseVoid(p); break;
   2391             case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE: ret =  responseVoid(p); break;
   2392             case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE: ret =  responseInts(p); break;
   2393             case RIL_REQUEST_SET_TTY_MODE: ret =  responseVoid(p); break;
   2394             case RIL_REQUEST_QUERY_TTY_MODE: ret =  responseInts(p); break;
   2395             case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE: ret =  responseVoid(p); break;
   2396             case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE: ret =  responseInts(p); break;
   2397             case RIL_REQUEST_CDMA_FLASH: ret =  responseVoid(p); break;
   2398             case RIL_REQUEST_CDMA_BURST_DTMF: ret =  responseVoid(p); break;
   2399             case RIL_REQUEST_CDMA_SEND_SMS: ret =  responseSMS(p); break;
   2400             case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE: ret =  responseVoid(p); break;
   2401             case RIL_REQUEST_GSM_GET_BROADCAST_CONFIG: ret =  responseGmsBroadcastConfig(p); break;
   2402             case RIL_REQUEST_GSM_SET_BROADCAST_CONFIG: ret =  responseVoid(p); break;
   2403             case RIL_REQUEST_GSM_BROADCAST_ACTIVATION: ret =  responseVoid(p); break;
   2404             case RIL_REQUEST_CDMA_GET_BROADCAST_CONFIG: ret =  responseCdmaBroadcastConfig(p); break;
   2405             case RIL_REQUEST_CDMA_SET_BROADCAST_CONFIG: ret =  responseVoid(p); break;
   2406             case RIL_REQUEST_CDMA_BROADCAST_ACTIVATION: ret =  responseVoid(p); break;
   2407             case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: ret =  responseVoid(p); break;
   2408             case RIL_REQUEST_CDMA_SUBSCRIPTION: ret =  responseStrings(p); break;
   2409             case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: ret =  responseInts(p); break;
   2410             case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: ret =  responseVoid(p); break;
   2411             case RIL_REQUEST_DEVICE_IDENTITY: ret =  responseStrings(p); break;
   2412             case RIL_REQUEST_GET_SMSC_ADDRESS: ret = responseString(p); break;
   2413             case RIL_REQUEST_SET_SMSC_ADDRESS: ret = responseVoid(p); break;
   2414             case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: ret = responseVoid(p); break;
   2415             case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: ret = responseVoid(p); break;
   2416             case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: ret = responseVoid(p); break;
   2417             case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: ret =  responseInts(p); break;
   2418             case RIL_REQUEST_ISIM_AUTHENTICATION: ret =  responseString(p); break;
   2419             case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: ret = responseVoid(p); break;
   2420             case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: ret = responseICC_IO(p); break;
   2421             case RIL_REQUEST_VOICE_RADIO_TECH: ret = responseInts(p); break;
   2422             case RIL_REQUEST_GET_CELL_INFO_LIST: ret = responseCellInfoList(p); break;
   2423             case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: ret = responseVoid(p); break;
   2424             default:
   2425                 throw new RuntimeException("Unrecognized solicited response: " + rr.mRequest);
   2426             //break;
   2427             }} catch (Throwable tr) {
   2428                 // Exceptions here usually mean invalid RIL responses
   2429 
   2430                 Rlog.w(RILJ_LOG_TAG, rr.serialString() + "< "
   2431                         + requestToString(rr.mRequest)
   2432                         + " exception, possible invalid RIL response", tr);
   2433 
   2434                 if (rr.mResult != null) {
   2435                     AsyncResult.forMessage(rr.mResult, null, tr);
   2436                     rr.mResult.sendToTarget();
   2437                 }
   2438                 rr.release();
   2439                 return;
   2440             }
   2441         }
   2442 
   2443         // Here and below fake RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, see b/7255789.
   2444         // This is needed otherwise we don't automatically transition to the main lock
   2445         // screen when the pin or puk is entered incorrectly.
   2446         switch (rr.mRequest) {
   2447             case RIL_REQUEST_ENTER_SIM_PUK:
   2448             case RIL_REQUEST_ENTER_SIM_PUK2:
   2449                 if (mIccStatusChangedRegistrants != null) {
   2450                     if (RILJ_LOGD) {
   2451                         riljLog("ON enter sim puk fakeSimStatusChanged: reg count="
   2452                                 + mIccStatusChangedRegistrants.size());
   2453                     }
   2454                     mIccStatusChangedRegistrants.notifyRegistrants();
   2455                 }
   2456                 break;
   2457         }
   2458 
   2459         if (error != 0) {
   2460             switch (rr.mRequest) {
   2461                 case RIL_REQUEST_ENTER_SIM_PIN:
   2462                 case RIL_REQUEST_ENTER_SIM_PIN2:
   2463                 case RIL_REQUEST_CHANGE_SIM_PIN:
   2464                 case RIL_REQUEST_CHANGE_SIM_PIN2:
   2465                 case RIL_REQUEST_SET_FACILITY_LOCK:
   2466                     if (mIccStatusChangedRegistrants != null) {
   2467                         if (RILJ_LOGD) {
   2468                             riljLog("ON some errors fakeSimStatusChanged: reg count="
   2469                                     + mIccStatusChangedRegistrants.size());
   2470                         }
   2471                         mIccStatusChangedRegistrants.notifyRegistrants();
   2472                     }
   2473                     break;
   2474             }
   2475 
   2476             rr.onError(error, ret);
   2477             rr.release();
   2478             return;
   2479         }
   2480 
   2481         if (RILJ_LOGD) riljLog(rr.serialString() + "< " + requestToString(rr.mRequest)
   2482             + " " + retToString(rr.mRequest, ret));
   2483 
   2484         if (rr.mResult != null) {
   2485             AsyncResult.forMessage(rr.mResult, ret, null);
   2486             rr.mResult.sendToTarget();
   2487         }
   2488 
   2489         rr.release();
   2490     }
   2491 
   2492     private String
   2493     retToString(int req, Object ret) {
   2494         if (ret == null) return "";
   2495         switch (req) {
   2496             // Don't log these return values, for privacy's sake.
   2497             case RIL_REQUEST_GET_IMSI:
   2498             case RIL_REQUEST_GET_IMEI:
   2499             case RIL_REQUEST_GET_IMEISV:
   2500                 if (!RILJ_LOGV) {
   2501                     // If not versbose logging just return and don't display IMSI and IMEI, IMEISV
   2502                     return "";
   2503                 }
   2504         }
   2505 
   2506         StringBuilder sb;
   2507         String s;
   2508         int length;
   2509         if (ret instanceof int[]){
   2510             int[] intArray = (int[]) ret;
   2511             length = intArray.length;
   2512             sb = new StringBuilder("{");
   2513             if (length > 0) {
   2514                 int i = 0;
   2515                 sb.append(intArray[i++]);
   2516                 while ( i < length) {
   2517                     sb.append(", ").append(intArray[i++]);
   2518                 }
   2519             }
   2520             sb.append("}");
   2521             s = sb.toString();
   2522         } else if (ret instanceof String[]) {
   2523             String[] strings = (String[]) ret;
   2524             length = strings.length;
   2525             sb = new StringBuilder("{");
   2526             if (length > 0) {
   2527                 int i = 0;
   2528                 sb.append(strings[i++]);
   2529                 while ( i < length) {
   2530                     sb.append(", ").append(strings[i++]);
   2531                 }
   2532             }
   2533             sb.append("}");
   2534             s = sb.toString();
   2535         }else if (req == RIL_REQUEST_GET_CURRENT_CALLS) {
   2536             ArrayList<DriverCall> calls = (ArrayList<DriverCall>) ret;
   2537             sb = new StringBuilder(" ");
   2538             for (DriverCall dc : calls) {
   2539                 sb.append("[").append(dc).append("] ");
   2540             }
   2541             s = sb.toString();
   2542         } else if (req == RIL_REQUEST_GET_NEIGHBORING_CELL_IDS) {
   2543             ArrayList<NeighboringCellInfo> cells;
   2544             cells = (ArrayList<NeighboringCellInfo>) ret;
   2545             sb = new StringBuilder(" ");
   2546             for (NeighboringCellInfo cell : cells) {
   2547                 sb.append(cell).append(" ");
   2548             }
   2549             s = sb.toString();
   2550         } else {
   2551             s = ret.toString();
   2552         }
   2553         return s;
   2554     }
   2555 
   2556     private void
   2557     processUnsolicited (Parcel p) {
   2558         int response;
   2559         Object ret;
   2560 
   2561         response = p.readInt();
   2562 
   2563         try {switch(response) {
   2564 /*
   2565  cat libs/telephony/ril_unsol_commands.h \
   2566  | egrep "^ *{RIL_" \
   2567  | sed -re 's/\{([^,]+),[^,]+,([^}]+).+/case \1: \2(rr, p); break;/'
   2568 */
   2569 
   2570             case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: ret =  responseVoid(p); break;
   2571             case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: ret =  responseVoid(p); break;
   2572             case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: ret =  responseVoid(p); break;
   2573             case RIL_UNSOL_RESPONSE_NEW_SMS: ret =  responseString(p); break;
   2574             case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: ret =  responseString(p); break;
   2575             case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: ret =  responseInts(p); break;
   2576             case RIL_UNSOL_ON_USSD: ret =  responseStrings(p); break;
   2577             case RIL_UNSOL_NITZ_TIME_RECEIVED: ret =  responseString(p); break;
   2578             case RIL_UNSOL_SIGNAL_STRENGTH: ret = responseSignalStrength(p); break;
   2579             case RIL_UNSOL_DATA_CALL_LIST_CHANGED: ret = responseDataCallList(p);break;
   2580             case RIL_UNSOL_SUPP_SVC_NOTIFICATION: ret = responseSuppServiceNotification(p); break;
   2581             case RIL_UNSOL_STK_SESSION_END: ret = responseVoid(p); break;
   2582             case RIL_UNSOL_STK_PROACTIVE_COMMAND: ret = responseString(p); break;
   2583             case RIL_UNSOL_STK_EVENT_NOTIFY: ret = responseString(p); break;
   2584             case RIL_UNSOL_STK_CALL_SETUP: ret = responseInts(p); break;
   2585             case RIL_UNSOL_SIM_SMS_STORAGE_FULL: ret =  responseVoid(p); break;
   2586             case RIL_UNSOL_SIM_REFRESH: ret =  responseSimRefresh(p); break;
   2587             case RIL_UNSOL_CALL_RING: ret =  responseCallRing(p); break;
   2588             case RIL_UNSOL_RESTRICTED_STATE_CHANGED: ret = responseInts(p); break;
   2589             case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED:  ret =  responseVoid(p); break;
   2590             case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS:  ret =  responseCdmaSms(p); break;
   2591             case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS:  ret =  responseRaw(p); break;
   2592             case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL:  ret =  responseVoid(p); break;
   2593             case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: ret = responseVoid(p); break;
   2594             case RIL_UNSOL_CDMA_CALL_WAITING: ret = responseCdmaCallWaiting(p); break;
   2595             case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: ret = responseInts(p); break;
   2596             case RIL_UNSOL_CDMA_INFO_REC: ret = responseCdmaInformationRecord(p); break;
   2597             case RIL_UNSOL_OEM_HOOK_RAW: ret = responseRaw(p); break;
   2598             case RIL_UNSOL_RINGBACK_TONE: ret = responseInts(p); break;
   2599             case RIL_UNSOL_RESEND_INCALL_MUTE: ret = responseVoid(p); break;
   2600             case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: ret = responseInts(p); break;
   2601             case RIL_UNSOl_CDMA_PRL_CHANGED: ret = responseInts(p); break;
   2602             case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: ret = responseVoid(p); break;
   2603             case RIL_UNSOL_RIL_CONNECTED: ret = responseInts(p); break;
   2604             case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: ret =  responseInts(p); break;
   2605             case RIL_UNSOL_CELL_INFO_LIST: ret = responseCellInfoList(p); break;
   2606 
   2607             default:
   2608                 throw new RuntimeException("Unrecognized unsol response: " + response);
   2609             //break; (implied)
   2610         }} catch (Throwable tr) {
   2611             Rlog.e(RILJ_LOG_TAG, "Exception processing unsol response: " + response +
   2612                 "Exception:" + tr.toString());
   2613             return;
   2614         }
   2615 
   2616         switch(response) {
   2617             case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
   2618                 /* has bonus radio state int */
   2619                 RadioState newState = getRadioStateFromInt(p.readInt());
   2620                 if (RILJ_LOGD) unsljLogMore(response, newState.toString());
   2621 
   2622                 switchToRadioState(newState);
   2623             break;
   2624             case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED:
   2625                 if (RILJ_LOGD) unsljLog(response);
   2626 
   2627                 mCallStateRegistrants
   2628                     .notifyRegistrants(new AsyncResult(null, null, null));
   2629             break;
   2630             case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED:
   2631                 if (RILJ_LOGD) unsljLog(response);
   2632 
   2633                 mVoiceNetworkStateRegistrants
   2634                     .notifyRegistrants(new AsyncResult(null, null, null));
   2635             break;
   2636             case RIL_UNSOL_RESPONSE_NEW_SMS: {
   2637                 if (RILJ_LOGD) unsljLog(response);
   2638 
   2639                 // FIXME this should move up a layer
   2640                 String a[] = new String[2];
   2641 
   2642                 a[1] = (String)ret;
   2643 
   2644                 SmsMessage sms;
   2645 
   2646                 sms = SmsMessage.newFromCMT(a);
   2647                 if (mGsmSmsRegistrant != null) {
   2648                     mGsmSmsRegistrant
   2649                         .notifyRegistrant(new AsyncResult(null, sms, null));
   2650                 }
   2651             break;
   2652             }
   2653             case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT:
   2654                 if (RILJ_LOGD) unsljLogRet(response, ret);
   2655 
   2656                 if (mSmsStatusRegistrant != null) {
   2657                     mSmsStatusRegistrant.notifyRegistrant(
   2658                             new AsyncResult(null, ret, null));
   2659                 }
   2660             break;
   2661             case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM:
   2662                 if (RILJ_LOGD) unsljLogRet(response, ret);
   2663 
   2664                 int[] smsIndex = (int[])ret;
   2665 
   2666                 if(smsIndex.length == 1) {
   2667                     if (mSmsOnSimRegistrant != null) {
   2668                         mSmsOnSimRegistrant.
   2669                                 notifyRegistrant(new AsyncResult(null, smsIndex, null));
   2670                     }
   2671                 } else {
   2672                     if (RILJ_LOGD) riljLog(" NEW_SMS_ON_SIM ERROR with wrong length "
   2673                             + smsIndex.length);
   2674                 }
   2675             break;
   2676             case RIL_UNSOL_ON_USSD:
   2677                 String[] resp = (String[])ret;
   2678 
   2679                 if (resp.length < 2) {
   2680                     resp = new String[2];
   2681                     resp[0] = ((String[])ret)[0];
   2682                     resp[1] = null;
   2683                 }
   2684                 if (RILJ_LOGD) unsljLogMore(response, resp[0]);
   2685                 if (mUSSDRegistrant != null) {
   2686                     mUSSDRegistrant.notifyRegistrant(
   2687                         new AsyncResult (null, resp, null));
   2688                 }
   2689             break;
   2690             case RIL_UNSOL_NITZ_TIME_RECEIVED:
   2691                 if (RILJ_LOGD) unsljLogRet(response, ret);
   2692 
   2693                 // has bonus long containing milliseconds since boot that the NITZ
   2694                 // time was received
   2695                 long nitzReceiveTime = p.readLong();
   2696 
   2697                 Object[] result = new Object[2];
   2698 
   2699                 result[0] = ret;
   2700                 result[1] = Long.valueOf(nitzReceiveTime);
   2701 
   2702                 boolean ignoreNitz = SystemProperties.getBoolean(
   2703                         TelephonyProperties.PROPERTY_IGNORE_NITZ, false);
   2704 
   2705                 if (ignoreNitz) {
   2706                     if (RILJ_LOGD) riljLog("ignoring UNSOL_NITZ_TIME_RECEIVED");
   2707                 } else {
   2708                     if (mNITZTimeRegistrant != null) {
   2709 
   2710                         mNITZTimeRegistrant
   2711                             .notifyRegistrant(new AsyncResult (null, result, null));
   2712                     } else {
   2713                         // in case NITZ time registrant isnt registered yet
   2714                         mLastNITZTimeInfo = result;
   2715                     }
   2716                 }
   2717             break;
   2718 
   2719             case RIL_UNSOL_SIGNAL_STRENGTH:
   2720                 // Note this is set to "verbose" because it happens
   2721                 // frequently
   2722                 if (RILJ_LOGV) unsljLogvRet(response, ret);
   2723 
   2724                 if (mSignalStrengthRegistrant != null) {
   2725                     mSignalStrengthRegistrant.notifyRegistrant(
   2726                                         new AsyncResult (null, ret, null));
   2727                 }
   2728             break;
   2729             case RIL_UNSOL_DATA_CALL_LIST_CHANGED:
   2730                 if (RILJ_LOGD) unsljLogRet(response, ret);
   2731 
   2732                 mDataNetworkStateRegistrants.notifyRegistrants(new AsyncResult(null, ret, null));
   2733             break;
   2734 
   2735             case RIL_UNSOL_SUPP_SVC_NOTIFICATION:
   2736                 if (RILJ_LOGD) unsljLogRet(response, ret);
   2737 
   2738                 if (mSsnRegistrant != null) {
   2739                     mSsnRegistrant.notifyRegistrant(
   2740                                         new AsyncResult (null, ret, null));
   2741                 }
   2742                 break;
   2743 
   2744             case RIL_UNSOL_STK_SESSION_END:
   2745                 if (RILJ_LOGD) unsljLog(response);
   2746 
   2747                 if (mCatSessionEndRegistrant != null) {
   2748                     mCatSessionEndRegistrant.notifyRegistrant(
   2749                                         new AsyncResult (null, ret, null));
   2750                 }
   2751                 break;
   2752 
   2753             case RIL_UNSOL_STK_PROACTIVE_COMMAND:
   2754                 if (RILJ_LOGD) unsljLogRet(response, ret);
   2755 
   2756                 if (mCatProCmdRegistrant != null) {
   2757                     mCatProCmdRegistrant.notifyRegistrant(
   2758                                         new AsyncResult (null, ret, null));
   2759                 }
   2760                 break;
   2761 
   2762             case RIL_UNSOL_STK_EVENT_NOTIFY:
   2763                 if (RILJ_LOGD) unsljLogRet(response, ret);
   2764 
   2765                 if (mCatEventRegistrant != null) {
   2766                     mCatEventRegistrant.notifyRegistrant(
   2767                                         new AsyncResult (null, ret, null));
   2768                 }
   2769                 break;
   2770 
   2771             case RIL_UNSOL_STK_CALL_SETUP:
   2772                 if (RILJ_LOGD) unsljLogRet(response, ret);
   2773 
   2774                 if (mCatCallSetUpRegistrant != null) {
   2775                     mCatCallSetUpRegistrant.notifyRegistrant(
   2776                                         new AsyncResult (null, ret, null));
   2777                 }
   2778                 break;
   2779 
   2780             case RIL_UNSOL_SIM_SMS_STORAGE_FULL:
   2781                 if (RILJ_LOGD) unsljLog(response);
   2782 
   2783                 if (mIccSmsFullRegistrant != null) {
   2784                     mIccSmsFullRegistrant.notifyRegistrant();
   2785                 }
   2786                 break;
   2787 
   2788             case RIL_UNSOL_SIM_REFRESH:
   2789                 if (RILJ_LOGD) unsljLogRet(response, ret);
   2790 
   2791                 if (mIccRefreshRegistrants != null) {
   2792                     mIccRefreshRegistrants.notifyRegistrants(
   2793                             new AsyncResult (null, ret, null));
   2794                 }
   2795                 break;
   2796 
   2797             case RIL_UNSOL_CALL_RING:
   2798                 if (RILJ_LOGD) unsljLogRet(response, ret);
   2799 
   2800                 if (mRingRegistrant != null) {
   2801                     mRingRegistrant.notifyRegistrant(
   2802                             new AsyncResult (null, ret, null));
   2803                 }
   2804                 break;
   2805 
   2806             case RIL_UNSOL_RESTRICTED_STATE_CHANGED:
   2807                 if (RILJ_LOGD) unsljLogvRet(response, ret);
   2808                 if (mRestrictedStateRegistrant != null) {
   2809                     mRestrictedStateRegistrant.notifyRegistrant(
   2810                                         new AsyncResult (null, ret, null));
   2811                 }
   2812                 break;
   2813 
   2814             case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED:
   2815                 if (RILJ_LOGD) unsljLog(response);
   2816 
   2817                 if (mIccStatusChangedRegistrants != null) {
   2818                     mIccStatusChangedRegistrants.notifyRegistrants();
   2819                 }
   2820                 break;
   2821 
   2822             case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS:
   2823                 if (RILJ_LOGD) unsljLog(response);
   2824 
   2825                 SmsMessage sms = (SmsMessage) ret;
   2826 
   2827                 if (mCdmaSmsRegistrant != null) {
   2828                     mCdmaSmsRegistrant
   2829                         .notifyRegistrant(new AsyncResult(null, sms, null));
   2830                 }
   2831                 break;
   2832 
   2833             case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS:
   2834                 if (RILJ_LOGD) unsljLog(response);
   2835 
   2836                 if (mGsmBroadcastSmsRegistrant != null) {
   2837                     mGsmBroadcastSmsRegistrant
   2838                         .notifyRegistrant(new AsyncResult(null, ret, null));
   2839                 }
   2840                 break;
   2841 
   2842             case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL:
   2843                 if (RILJ_LOGD) unsljLog(response);
   2844 
   2845                 if (mIccSmsFullRegistrant != null) {
   2846                     mIccSmsFullRegistrant.notifyRegistrant();
   2847                 }
   2848                 break;
   2849 
   2850             case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE:
   2851                 if (RILJ_LOGD) unsljLog(response);
   2852 
   2853                 if (mEmergencyCallbackModeRegistrant != null) {
   2854                     mEmergencyCallbackModeRegistrant.notifyRegistrant();
   2855                 }
   2856                 break;
   2857 
   2858             case RIL_UNSOL_CDMA_CALL_WAITING:
   2859                 if (RILJ_LOGD) unsljLogRet(response, ret);
   2860 
   2861                 if (mCallWaitingInfoRegistrants != null) {
   2862                     mCallWaitingInfoRegistrants.notifyRegistrants(
   2863                                         new AsyncResult (null, ret, null));
   2864                 }
   2865                 break;
   2866 
   2867             case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS:
   2868                 if (RILJ_LOGD) unsljLogRet(response, ret);
   2869 
   2870                 if (mOtaProvisionRegistrants != null) {
   2871                     mOtaProvisionRegistrants.notifyRegistrants(
   2872                                         new AsyncResult (null, ret, null));
   2873                 }
   2874                 break;
   2875 
   2876             case RIL_UNSOL_CDMA_INFO_REC:
   2877                 ArrayList<CdmaInformationRecords> listInfoRecs;
   2878 
   2879                 try {
   2880                     listInfoRecs = (ArrayList<CdmaInformationRecords>)ret;
   2881                 } catch (ClassCastException e) {
   2882                     Rlog.e(RILJ_LOG_TAG, "Unexpected exception casting to listInfoRecs", e);
   2883                     break;
   2884                 }
   2885 
   2886                 for (CdmaInformationRecords rec : listInfoRecs) {
   2887                     if (RILJ_LOGD) unsljLogRet(response, rec);
   2888                     notifyRegistrantsCdmaInfoRec(rec);
   2889                 }
   2890                 break;
   2891 
   2892             case RIL_UNSOL_OEM_HOOK_RAW:
   2893                 if (RILJ_LOGD) unsljLogvRet(response, IccUtils.bytesToHexString((byte[])ret));
   2894                 if (mUnsolOemHookRawRegistrant != null) {
   2895                     mUnsolOemHookRawRegistrant.notifyRegistrant(new AsyncResult(null, ret, null));
   2896                 }
   2897                 break;
   2898 
   2899             case RIL_UNSOL_RINGBACK_TONE:
   2900                 if (RILJ_LOGD) unsljLogvRet(response, ret);
   2901                 if (mRingbackToneRegistrants != null) {
   2902                     boolean playtone = (((int[])ret)[0] == 1);
   2903                     mRingbackToneRegistrants.notifyRegistrants(
   2904                                         new AsyncResult (null, playtone, null));
   2905                 }
   2906                 break;
   2907 
   2908             case RIL_UNSOL_RESEND_INCALL_MUTE:
   2909                 if (RILJ_LOGD) unsljLogRet(response, ret);
   2910 
   2911                 if (mResendIncallMuteRegistrants != null) {
   2912                     mResendIncallMuteRegistrants.notifyRegistrants(
   2913                                         new AsyncResult (null, ret, null));
   2914                 }
   2915                 break;
   2916 
   2917             case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED:
   2918                 if (RILJ_LOGD) unsljLogRet(response, ret);
   2919 
   2920                 if (mVoiceRadioTechChangedRegistrants != null) {
   2921                     mVoiceRadioTechChangedRegistrants.notifyRegistrants(
   2922                             new AsyncResult(null, ret, null));
   2923                 }
   2924                 break;
   2925 
   2926             case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED:
   2927                 if (RILJ_LOGD) unsljLogRet(response, ret);
   2928 
   2929                 if (mCdmaSubscriptionChangedRegistrants != null) {
   2930                     mCdmaSubscriptionChangedRegistrants.notifyRegistrants(
   2931                                         new AsyncResult (null, ret, null));
   2932                 }
   2933                 break;
   2934 
   2935             case RIL_UNSOl_CDMA_PRL_CHANGED:
   2936                 if (RILJ_LOGD) unsljLogRet(response, ret);
   2937 
   2938                 if (mCdmaPrlChangedRegistrants != null) {
   2939                     mCdmaPrlChangedRegistrants.notifyRegistrants(
   2940                                         new AsyncResult (null, ret, null));
   2941                 }
   2942                 break;
   2943 
   2944             case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE:
   2945                 if (RILJ_LOGD) unsljLogRet(response, ret);
   2946 
   2947                 if (mExitEmergencyCallbackModeRegistrants != null) {
   2948                     mExitEmergencyCallbackModeRegistrants.notifyRegistrants(
   2949                                         new AsyncResult (null, null, null));
   2950                 }
   2951                 break;
   2952 
   2953             case RIL_UNSOL_RIL_CONNECTED: {
   2954                 if (RILJ_LOGD) unsljLogRet(response, ret);
   2955 
   2956                 // Initial conditions
   2957                 setRadioPower(false, null);
   2958                 setPreferredNetworkType(mPreferredNetworkType, null);
   2959                 setCdmaSubscriptionSource(mCdmaSubscription, null);
   2960                 setCellInfoListRate(Integer.MAX_VALUE, null);
   2961                 notifyRegistrantsRilConnectionChanged(((int[])ret)[0]);
   2962                 break;
   2963             }
   2964             case RIL_UNSOL_CELL_INFO_LIST: {
   2965                 if (RILJ_LOGD) unsljLogRet(response, ret);
   2966 
   2967                 if (mRilCellInfoListRegistrants != null) {
   2968                     mRilCellInfoListRegistrants.notifyRegistrants(
   2969                                         new AsyncResult (null, ret, null));
   2970                 }
   2971                 break;
   2972             }
   2973         }
   2974     }
   2975 
   2976     /**
   2977      * Notifiy all registrants that the ril has connected or disconnected.
   2978      *
   2979      * @param rilVer is the version of the ril or -1 if disconnected.
   2980      */
   2981     private void notifyRegistrantsRilConnectionChanged(int rilVer) {
   2982         mRilVersion = rilVer;
   2983         if (mRilConnectedRegistrants != null) {
   2984             mRilConnectedRegistrants.notifyRegistrants(
   2985                                 new AsyncResult (null, new Integer(rilVer), null));
   2986         }
   2987     }
   2988 
   2989     private Object
   2990     responseInts(Parcel p) {
   2991         int numInts;
   2992         int response[];
   2993 
   2994         numInts = p.readInt();
   2995 
   2996         response = new int[numInts];
   2997 
   2998         for (int i = 0 ; i < numInts ; i++) {
   2999             response[i] = p.readInt();
   3000         }
   3001 
   3002         return response;
   3003     }
   3004 
   3005 
   3006     private Object
   3007     responseVoid(Parcel p) {
   3008         return null;
   3009     }
   3010 
   3011     private Object
   3012     responseCallForward(Parcel p) {
   3013         int numInfos;
   3014         CallForwardInfo infos[];
   3015 
   3016         numInfos = p.readInt();
   3017 
   3018         infos = new CallForwardInfo[numInfos];
   3019 
   3020         for (int i = 0 ; i < numInfos ; i++) {
   3021             infos[i] = new CallForwardInfo();
   3022 
   3023             infos[i].status = p.readInt();
   3024             infos[i].reason = p.readInt();
   3025             infos[i].serviceClass = p.readInt();
   3026             infos[i].toa = p.readInt();
   3027             infos[i].number = p.readString();
   3028             infos[i].timeSeconds = p.readInt();
   3029         }
   3030 
   3031         return infos;
   3032     }
   3033 
   3034     private Object
   3035     responseSuppServiceNotification(Parcel p) {
   3036         SuppServiceNotification notification = new SuppServiceNotification();
   3037 
   3038         notification.notificationType = p.readInt();
   3039         notification.code = p.readInt();
   3040         notification.index = p.readInt();
   3041         notification.type = p.readInt();
   3042         notification.number = p.readString();
   3043 
   3044         return notification;
   3045     }
   3046 
   3047     private Object
   3048     responseCdmaSms(Parcel p) {
   3049         SmsMessage sms;
   3050         sms = SmsMessage.newFromParcel(p);
   3051 
   3052         return sms;
   3053     }
   3054 
   3055     private Object
   3056     responseString(Parcel p) {
   3057         String response;
   3058 
   3059         response = p.readString();
   3060 
   3061         return response;
   3062     }
   3063 
   3064     private Object
   3065     responseStrings(Parcel p) {
   3066         int num;
   3067         String response[];
   3068 
   3069         response = p.readStringArray();
   3070 
   3071         return response;
   3072     }
   3073 
   3074     private Object
   3075     responseRaw(Parcel p) {
   3076         int num;
   3077         byte response[];
   3078 
   3079         response = p.createByteArray();
   3080 
   3081         return response;
   3082     }
   3083 
   3084     private Object
   3085     responseSMS(Parcel p) {
   3086         int messageRef, errorCode;
   3087         String ackPDU;
   3088 
   3089         messageRef = p.readInt();
   3090         ackPDU = p.readString();
   3091         errorCode = p.readInt();
   3092 
   3093         SmsResponse response = new SmsResponse(messageRef, ackPDU, errorCode);
   3094 
   3095         return response;
   3096     }
   3097 
   3098 
   3099     private Object
   3100     responseICC_IO(Parcel p) {
   3101         int sw1, sw2;
   3102         byte data[] = null;
   3103         Message ret;
   3104 
   3105         sw1 = p.readInt();
   3106         sw2 = p.readInt();
   3107 
   3108         String s = p.readString();
   3109 
   3110         if (RILJ_LOGV) riljLog("< iccIO: "
   3111                 + " 0x" + Integer.toHexString(sw1)
   3112                 + " 0x" + Integer.toHexString(sw2) + " "
   3113                 + s);
   3114 
   3115         return new IccIoResult(sw1, sw2, s);
   3116     }
   3117 
   3118     private Object
   3119     responseIccCardStatus(Parcel p) {
   3120         IccCardApplicationStatus appStatus;
   3121 
   3122         IccCardStatus cardStatus = new IccCardStatus();
   3123         cardStatus.setCardState(p.readInt());
   3124         cardStatus.setUniversalPinState(p.readInt());
   3125         cardStatus.mGsmUmtsSubscriptionAppIndex = p.readInt();
   3126         cardStatus.mCdmaSubscriptionAppIndex = p.readInt();
   3127         cardStatus.mImsSubscriptionAppIndex = p.readInt();
   3128         int numApplications = p.readInt();
   3129 
   3130         // limit to maximum allowed applications
   3131         if (numApplications > IccCardStatus.CARD_MAX_APPS) {
   3132             numApplications = IccCardStatus.CARD_MAX_APPS;
   3133         }
   3134         cardStatus.mApplications = new IccCardApplicationStatus[numApplications];
   3135         for (int i = 0 ; i < numApplications ; i++) {
   3136             appStatus = new IccCardApplicationStatus();
   3137             appStatus.app_type       = appStatus.AppTypeFromRILInt(p.readInt());
   3138             appStatus.app_state      = appStatus.AppStateFromRILInt(p.readInt());
   3139             appStatus.perso_substate = appStatus.PersoSubstateFromRILInt(p.readInt());
   3140             appStatus.aid            = p.readString();
   3141             appStatus.app_label      = p.readString();
   3142             appStatus.pin1_replaced  = p.readInt();
   3143             appStatus.pin1           = appStatus.PinStateFromRILInt(p.readInt());
   3144             appStatus.pin2           = appStatus.PinStateFromRILInt(p.readInt());
   3145             cardStatus.mApplications[i] = appStatus;
   3146         }
   3147         return cardStatus;
   3148     }
   3149 
   3150     private Object
   3151     responseSimRefresh(Parcel p) {
   3152         IccRefreshResponse response = new IccRefreshResponse();
   3153 
   3154         response.refreshResult = p.readInt();
   3155         response.efId   = p.readInt();
   3156         response.aid = p.readString();
   3157         return response;
   3158     }
   3159 
   3160     private Object
   3161     responseCallList(Parcel p) {
   3162         int num;
   3163         int voiceSettings;
   3164         ArrayList<DriverCall> response;
   3165         DriverCall dc;
   3166 
   3167         num = p.readInt();
   3168         response = new ArrayList<DriverCall>(num);
   3169 
   3170         if (RILJ_LOGV) {
   3171             riljLog("responseCallList: num=" + num +
   3172                     " mEmergencyCallbackModeRegistrant=" + mEmergencyCallbackModeRegistrant +
   3173                     " mTestingEmergencyCall=" + mTestingEmergencyCall.get());
   3174         }
   3175         for (int i = 0 ; i < num ; i++) {
   3176             dc = new DriverCall();
   3177 
   3178             dc.state = DriverCall.stateFromCLCC(p.readInt());
   3179             dc.index = p.readInt();
   3180             dc.TOA = p.readInt();
   3181             dc.isMpty = (0 != p.readInt());
   3182             dc.isMT = (0 != p.readInt());
   3183             dc.als = p.readInt();
   3184             voiceSettings = p.readInt();
   3185             dc.isVoice = (0 == voiceSettings) ? false : true;
   3186             dc.isVoicePrivacy = (0 != p.readInt());
   3187             dc.number = p.readString();
   3188             int np = p.readInt();
   3189             dc.numberPresentation = DriverCall.presentationFromCLIP(np);
   3190             dc.name = p.readString();
   3191             dc.namePresentation = p.readInt();
   3192             int uusInfoPresent = p.readInt();
   3193             if (uusInfoPresent == 1) {
   3194                 dc.uusInfo = new UUSInfo();
   3195                 dc.uusInfo.setType(p.readInt());
   3196                 dc.uusInfo.setDcs(p.readInt());
   3197                 byte[] userData = p.createByteArray();
   3198                 dc.uusInfo.setUserData(userData);
   3199                 riljLogv(String.format("Incoming UUS : type=%d, dcs=%d, length=%d",
   3200                                 dc.uusInfo.getType(), dc.uusInfo.getDcs(),
   3201                                 dc.uusInfo.getUserData().length));
   3202                 riljLogv("Incoming UUS : data (string)="
   3203                         + new String(dc.uusInfo.getUserData()));
   3204                 riljLogv("Incoming UUS : data (hex): "
   3205                         + IccUtils.bytesToHexString(dc.uusInfo.getUserData()));
   3206             } else {
   3207                 riljLogv("Incoming UUS : NOT present!");
   3208             }
   3209 
   3210             // Make sure there's a leading + on addresses with a TOA of 145
   3211             dc.number = PhoneNumberUtils.stringFromStringAndTOA(dc.number, dc.TOA);
   3212 
   3213             response.add(dc);
   3214 
   3215             if (dc.isVoicePrivacy) {
   3216                 mVoicePrivacyOnRegistrants.notifyRegistrants();
   3217                 riljLog("InCall VoicePrivacy is enabled");
   3218             } else {
   3219                 mVoicePrivacyOffRegistrants.notifyRegistrants();
   3220                 riljLog("InCall VoicePrivacy is disabled");
   3221             }
   3222         }
   3223 
   3224         Collections.sort(response);
   3225 
   3226         if ((num == 0) && mTestingEmergencyCall.getAndSet(false)) {
   3227             if (mEmergencyCallbackModeRegistrant != null) {
   3228                 riljLog("responseCallList: call ended, testing emergency call," +
   3229                             " notify ECM Registrants");
   3230                 mEmergencyCallbackModeRegistrant.notifyRegistrant();
   3231             }
   3232         }
   3233 
   3234         return response;
   3235     }
   3236 
   3237     private DataCallResponse getDataCallResponse(Parcel p, int version) {
   3238         DataCallResponse dataCall = new DataCallResponse();
   3239 
   3240         dataCall.version = version;
   3241         if (version < 5) {
   3242             dataCall.cid = p.readInt();
   3243             dataCall.active = p.readInt();
   3244             dataCall.type = p.readString();
   3245             String addresses = p.readString();
   3246             if (!TextUtils.isEmpty(addresses)) {
   3247                 dataCall.addresses = addresses.split(" ");
   3248             }
   3249         } else {
   3250             dataCall.status = p.readInt();
   3251             dataCall.suggestedRetryTime = p.readInt();
   3252             dataCall.cid = p.readInt();
   3253             dataCall.active = p.readInt();
   3254             dataCall.type = p.readString();
   3255             dataCall.ifname = p.readString();
   3256             if ((dataCall.status == DcFailCause.NONE.getErrorCode()) &&
   3257                     TextUtils.isEmpty(dataCall.ifname)) {
   3258               throw new RuntimeException("getDataCallResponse, no ifname");
   3259             }
   3260             String addresses = p.readString();
   3261             if (!TextUtils.isEmpty(addresses)) {
   3262                 dataCall.addresses = addresses.split(" ");
   3263             }
   3264             String dnses = p.readString();
   3265             if (!TextUtils.isEmpty(dnses)) {
   3266                 dataCall.dnses = dnses.split(" ");
   3267             }
   3268             String gateways = p.readString();
   3269             if (!TextUtils.isEmpty(gateways)) {
   3270                 dataCall.gateways = gateways.split(" ");
   3271             }
   3272         }
   3273         return dataCall;
   3274     }
   3275 
   3276     private Object
   3277     responseDataCallList(Parcel p) {
   3278         ArrayList<DataCallResponse> response;
   3279 
   3280         int ver = p.readInt();
   3281         int num = p.readInt();
   3282         riljLog("responseDataCallList ver=" + ver + " num=" + num);
   3283 
   3284         response = new ArrayList<DataCallResponse>(num);
   3285         for (int i = 0; i < num; i++) {
   3286             response.add(getDataCallResponse(p, ver));
   3287         }
   3288 
   3289         return response;
   3290     }
   3291 
   3292     private Object
   3293     responseSetupDataCall(Parcel p) {
   3294         int ver = p.readInt();
   3295         int num = p.readInt();
   3296         if (RILJ_LOGV) riljLog("responseSetupDataCall ver=" + ver + " num=" + num);
   3297 
   3298         DataCallResponse dataCall;
   3299 
   3300         if (ver < 5) {
   3301             dataCall = new DataCallResponse();
   3302             dataCall.version = ver;
   3303             dataCall.cid = Integer.parseInt(p.readString());
   3304             dataCall.ifname = p.readString();
   3305             if (TextUtils.isEmpty(dataCall.ifname)) {
   3306                 throw new RuntimeException(
   3307                         "RIL_REQUEST_SETUP_DATA_CALL response, no ifname");
   3308             }
   3309             String addresses = p.readString();
   3310             if (!TextUtils.isEmpty(addresses)) {
   3311               dataCall.addresses = addresses.split(" ");
   3312             }
   3313             if (num >= 4) {
   3314                 String dnses = p.readString();
   3315                 if (RILJ_LOGD) riljLog("responseSetupDataCall got dnses=" + dnses);
   3316                 if (!TextUtils.isEmpty(dnses)) {
   3317                     dataCall.dnses = dnses.split(" ");
   3318                 }
   3319             }
   3320             if (num >= 5) {
   3321                 String gateways = p.readString();
   3322                 if (RILJ_LOGD) riljLog("responseSetupDataCall got gateways=" + gateways);
   3323                 if (!TextUtils.isEmpty(gateways)) {
   3324                     dataCall.gateways = gateways.split(" ");
   3325                 }
   3326             }
   3327         } else {
   3328             if (num != 1) {
   3329                 throw new RuntimeException(
   3330                         "RIL_REQUEST_SETUP_DATA_CALL response expecting 1 RIL_Data_Call_response_v5"
   3331                         + " got " + num);
   3332             }
   3333             dataCall = getDataCallResponse(p, ver);
   3334         }
   3335 
   3336         return dataCall;
   3337     }
   3338 
   3339     private Object
   3340     responseOperatorInfos(Parcel p) {
   3341         String strings[] = (String [])responseStrings(p);
   3342         ArrayList<OperatorInfo> ret;
   3343 
   3344         if (strings.length % 4 != 0) {
   3345             throw new RuntimeException(
   3346                 "RIL_REQUEST_QUERY_AVAILABLE_NETWORKS: invalid response. Got "
   3347                 + strings.length + " strings, expected multible of 4");
   3348         }
   3349 
   3350         ret = new ArrayList<OperatorInfo>(strings.length / 4);
   3351 
   3352         for (int i = 0 ; i < strings.length ; i += 4) {
   3353             ret.add (
   3354                 new OperatorInfo(
   3355                     strings[i+0],
   3356                     strings[i+1],
   3357                     strings[i+2],
   3358                     strings[i+3]));
   3359         }
   3360 
   3361         return ret;
   3362     }
   3363 
   3364     private Object
   3365     responseCellList(Parcel p) {
   3366        int num, rssi;
   3367        String location;
   3368        ArrayList<NeighboringCellInfo> response;
   3369        NeighboringCellInfo cell;
   3370 
   3371        num = p.readInt();
   3372        response = new ArrayList<NeighboringCellInfo>();
   3373 
   3374        // Determine the radio access type
   3375        String radioString = SystemProperties.get(
   3376                TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE, "unknown");
   3377        int radioType;
   3378        if (radioString.equals("GPRS")) {
   3379            radioType = NETWORK_TYPE_GPRS;
   3380        } else if (radioString.equals("EDGE")) {
   3381            radioType = NETWORK_TYPE_EDGE;
   3382        } else if (radioString.equals("UMTS")) {
   3383            radioType = NETWORK_TYPE_UMTS;
   3384        } else if (radioString.equals("HSDPA")) {
   3385            radioType = NETWORK_TYPE_HSDPA;
   3386        } else if (radioString.equals("HSUPA")) {
   3387            radioType = NETWORK_TYPE_HSUPA;
   3388        } else if (radioString.equals("HSPA")) {
   3389            radioType = NETWORK_TYPE_HSPA;
   3390        } else {
   3391            radioType = NETWORK_TYPE_UNKNOWN;
   3392        }
   3393 
   3394        // Interpret the location based on radio access type
   3395        if (radioType != NETWORK_TYPE_UNKNOWN) {
   3396            for (int i = 0 ; i < num ; i++) {
   3397                rssi = p.readInt();
   3398                location = p.readString();
   3399                cell = new NeighboringCellInfo(rssi, location, radioType);
   3400                response.add(cell);
   3401            }
   3402        }
   3403        return response;
   3404     }
   3405 
   3406     private Object responseGetPreferredNetworkType(Parcel p) {
   3407        int [] response = (int[]) responseInts(p);
   3408 
   3409        if (response.length >= 1) {
   3410            // Since this is the response for getPreferredNetworkType
   3411            // we'll assume that it should be the value we want the
   3412            // vendor ril to take if we reestablish a connection to it.
   3413            mPreferredNetworkType = response[0];
   3414        }
   3415        return response;
   3416     }
   3417 
   3418     private Object responseGmsBroadcastConfig(Parcel p) {
   3419         int num;
   3420         ArrayList<SmsBroadcastConfigInfo> response;
   3421         SmsBroadcastConfigInfo info;
   3422 
   3423         num = p.readInt();
   3424         response = new ArrayList<SmsBroadcastConfigInfo>(num);
   3425 
   3426         for (int i = 0; i < num; i++) {
   3427             int fromId = p.readInt();
   3428             int toId = p.readInt();
   3429             int fromScheme = p.readInt();
   3430             int toScheme = p.readInt();
   3431             boolean selected = (p.readInt() == 1);
   3432 
   3433             info = new SmsBroadcastConfigInfo(fromId, toId, fromScheme,
   3434                     toScheme, selected);
   3435             response.add(info);
   3436         }
   3437         return response;
   3438     }
   3439 
   3440     private Object
   3441     responseCdmaBroadcastConfig(Parcel p) {
   3442         int numServiceCategories;
   3443         int response[];
   3444 
   3445         numServiceCategories = p.readInt();
   3446 
   3447         if (numServiceCategories == 0) {
   3448             // TODO: The logic of providing default values should
   3449             // not be done by this transport layer. And needs to
   3450             // be done by the vendor ril or application logic.
   3451             int numInts;
   3452             numInts = CDMA_BROADCAST_SMS_NO_OF_SERVICE_CATEGORIES * CDMA_BSI_NO_OF_INTS_STRUCT + 1;
   3453             response = new int[numInts];
   3454 
   3455             // Faking a default record for all possible records.
   3456             response[0] = CDMA_BROADCAST_SMS_NO_OF_SERVICE_CATEGORIES;
   3457 
   3458             // Loop over CDMA_BROADCAST_SMS_NO_OF_SERVICE_CATEGORIES set 'english' as
   3459             // default language and selection status to false for all.
   3460             for (int i = 1; i < numInts; i += CDMA_BSI_NO_OF_INTS_STRUCT ) {
   3461                 response[i + 0] = i / CDMA_BSI_NO_OF_INTS_STRUCT;
   3462                 response[i + 1] = 1;
   3463                 response[i + 2] = 0;
   3464             }
   3465         } else {
   3466             int numInts;
   3467             numInts = (numServiceCategories * CDMA_BSI_NO_OF_INTS_STRUCT) + 1;
   3468             response = new int[numInts];
   3469 
   3470             response[0] = numServiceCategories;
   3471             for (int i = 1 ; i < numInts; i++) {
   3472                  response[i] = p.readInt();
   3473              }
   3474         }
   3475 
   3476         return response;
   3477     }
   3478 
   3479     private Object
   3480     responseSignalStrength(Parcel p) {
   3481         // Assume this is gsm, but doesn't matter as ServiceStateTracker
   3482         // sets the proper value.
   3483         SignalStrength signalStrength = SignalStrength.makeSignalStrengthFromRilParcel(p);
   3484         return signalStrength;
   3485     }
   3486 
   3487     private ArrayList<CdmaInformationRecords>
   3488     responseCdmaInformationRecord(Parcel p) {
   3489         int numberOfInfoRecs;
   3490         ArrayList<CdmaInformationRecords> response;
   3491 
   3492         /**
   3493          * Loop through all of the information records unmarshalling them
   3494          * and converting them to Java Objects.
   3495          */
   3496         numberOfInfoRecs = p.readInt();
   3497         response = new ArrayList<CdmaInformationRecords>(numberOfInfoRecs);
   3498 
   3499         for (int i = 0; i < numberOfInfoRecs; i++) {
   3500             CdmaInformationRecords InfoRec = new CdmaInformationRecords(p);
   3501             response.add(InfoRec);
   3502         }
   3503 
   3504         return response;
   3505     }
   3506 
   3507     private Object
   3508     responseCdmaCallWaiting(Parcel p) {
   3509         CdmaCallWaitingNotification notification = new CdmaCallWaitingNotification();
   3510 
   3511         notification.number = p.readString();
   3512         notification.numberPresentation =
   3513                 CdmaCallWaitingNotification.presentationFromCLIP(p.readInt());
   3514         notification.name = p.readString();
   3515         notification.namePresentation = notification.numberPresentation;
   3516         notification.isPresent = p.readInt();
   3517         notification.signalType = p.readInt();
   3518         notification.alertPitch = p.readInt();
   3519         notification.signal = p.readInt();
   3520         notification.numberType = p.readInt();
   3521         notification.numberPlan = p.readInt();
   3522 
   3523         return notification;
   3524     }
   3525 
   3526     private Object
   3527     responseCallRing(Parcel p){
   3528         char response[] = new char[4];
   3529 
   3530         response[0] = (char) p.readInt();    // isPresent
   3531         response[1] = (char) p.readInt();    // signalType
   3532         response[2] = (char) p.readInt();    // alertPitch
   3533         response[3] = (char) p.readInt();    // signal
   3534 
   3535         return response;
   3536     }
   3537 
   3538     private void
   3539     notifyRegistrantsCdmaInfoRec(CdmaInformationRecords infoRec) {
   3540         int response = RIL_UNSOL_CDMA_INFO_REC;
   3541         if (infoRec.record instanceof CdmaInformationRecords.CdmaDisplayInfoRec) {
   3542             if (mDisplayInfoRegistrants != null) {
   3543                 if (RILJ_LOGD) unsljLogRet(response, infoRec.record);
   3544                 mDisplayInfoRegistrants.notifyRegistrants(
   3545                         new AsyncResult (null, infoRec.record, null));
   3546             }
   3547         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaSignalInfoRec) {
   3548             if (mSignalInfoRegistrants != null) {
   3549                 if (RILJ_LOGD) unsljLogRet(response, infoRec.record);
   3550                 mSignalInfoRegistrants.notifyRegistrants(
   3551                         new AsyncResult (null, infoRec.record, null));
   3552             }
   3553         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaNumberInfoRec) {
   3554             if (mNumberInfoRegistrants != null) {
   3555                 if (RILJ_LOGD) unsljLogRet(response, infoRec.record);
   3556                 mNumberInfoRegistrants.notifyRegistrants(
   3557                         new AsyncResult (null, infoRec.record, null));
   3558             }
   3559         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaRedirectingNumberInfoRec) {
   3560             if (mRedirNumInfoRegistrants != null) {
   3561                 if (RILJ_LOGD) unsljLogRet(response, infoRec.record);
   3562                 mRedirNumInfoRegistrants.notifyRegistrants(
   3563                         new AsyncResult (null, infoRec.record, null));
   3564             }
   3565         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaLineControlInfoRec) {
   3566             if (mLineControlInfoRegistrants != null) {
   3567                 if (RILJ_LOGD) unsljLogRet(response, infoRec.record);
   3568                 mLineControlInfoRegistrants.notifyRegistrants(
   3569                         new AsyncResult (null, infoRec.record, null));
   3570             }
   3571         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaT53ClirInfoRec) {
   3572             if (mT53ClirInfoRegistrants != null) {
   3573                 if (RILJ_LOGD) unsljLogRet(response, infoRec.record);
   3574                 mT53ClirInfoRegistrants.notifyRegistrants(
   3575                         new AsyncResult (null, infoRec.record, null));
   3576             }
   3577         } else if (infoRec.record instanceof CdmaInformationRecords.CdmaT53AudioControlInfoRec) {
   3578             if (mT53AudCntrlInfoRegistrants != null) {
   3579                if (RILJ_LOGD) unsljLogRet(response, infoRec.record);
   3580                mT53AudCntrlInfoRegistrants.notifyRegistrants(
   3581                        new AsyncResult (null, infoRec.record, null));
   3582             }
   3583         }
   3584     }
   3585 
   3586     private ArrayList<CellInfo> responseCellInfoList(Parcel p) {
   3587         int numberOfInfoRecs;
   3588         ArrayList<CellInfo> response;
   3589 
   3590         /**
   3591          * Loop through all of the information records unmarshalling them
   3592          * and converting them to Java Objects.
   3593          */
   3594         numberOfInfoRecs = p.readInt();
   3595         response = new ArrayList<CellInfo>(numberOfInfoRecs);
   3596 
   3597         for (int i = 0; i < numberOfInfoRecs; i++) {
   3598             CellInfo InfoRec = CellInfo.CREATOR.createFromParcel(p);
   3599             response.add(InfoRec);
   3600         }
   3601 
   3602         return response;
   3603     }
   3604 
   3605     static String
   3606     requestToString(int request) {
   3607 /*
   3608  cat libs/telephony/ril_commands.h \
   3609  | egrep "^ *{RIL_" \
   3610  | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
   3611 */
   3612         switch(request) {
   3613             case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
   3614             case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
   3615             case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
   3616             case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
   3617             case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
   3618             case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
   3619             case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
   3620             case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
   3621             case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
   3622             case RIL_REQUEST_DIAL: return "DIAL";
   3623             case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
   3624             case RIL_REQUEST_HANGUP: return "HANGUP";
   3625             case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
   3626             case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
   3627             case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
   3628             case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
   3629             case RIL_REQUEST_UDUB: return "UDUB";
   3630             case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
   3631             case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
   3632             case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
   3633             case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
   3634             case RIL_REQUEST_OPERATOR: return "OPERATOR";
   3635             case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
   3636             case RIL_REQUEST_DTMF: return "DTMF";
   3637             case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
   3638             case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
   3639             case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
   3640             case RIL_REQUEST_SIM_IO: return "SIM_IO";
   3641             case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
   3642             case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
   3643             case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
   3644             case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
   3645             case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
   3646             case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
   3647             case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
   3648             case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
   3649             case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
   3650             case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
   3651             case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
   3652             case RIL_REQUEST_ANSWER: return "ANSWER";
   3653             case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
   3654             case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
   3655             case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
   3656             case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
   3657             case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
   3658             case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
   3659             case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
   3660             case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
   3661             case RIL_REQUEST_DTMF_START: return "DTMF_START";
   3662             case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
   3663             case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
   3664             case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
   3665             case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
   3666             case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
   3667             case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
   3668             case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
   3669             case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
   3670             case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
   3671             case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
   3672             case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
   3673             case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
   3674             case RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION: return "SET_SUPP_SVC_NOTIFICATION";
   3675             case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM";
   3676             case RIL_REQUEST_DELETE_SMS_ON_SIM: return "DELETE_SMS_ON_SIM";
   3677             case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
   3678             case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
   3679             case RIL_REQUEST_STK_GET_PROFILE: return "REQUEST_STK_GET_PROFILE";
   3680             case RIL_REQUEST_STK_SET_PROFILE: return "REQUEST_STK_SET_PROFILE";
   3681             case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "REQUEST_STK_SEND_ENVELOPE_COMMAND";
   3682             case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "REQUEST_STK_SEND_TERMINAL_RESPONSE";
   3683             case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
   3684             case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "REQUEST_EXPLICIT_CALL_TRANSFER";
   3685             case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "REQUEST_SET_PREFERRED_NETWORK_TYPE";
   3686             case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "REQUEST_GET_PREFERRED_NETWORK_TYPE";
   3687             case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "REQUEST_GET_NEIGHBORING_CELL_IDS";
   3688             case RIL_REQUEST_SET_LOCATION_UPDATES: return "REQUEST_SET_LOCATION_UPDATES";
   3689             case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE: return "RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE";
   3690             case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE: return "RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE";
   3691             case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE: return "RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE";
   3692             case RIL_REQUEST_SET_TTY_MODE: return "RIL_REQUEST_SET_TTY_MODE";
   3693             case RIL_REQUEST_QUERY_TTY_MODE: return "RIL_REQUEST_QUERY_TTY_MODE";
   3694             case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE: return "RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
   3695             case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE: return "RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
   3696             case RIL_REQUEST_CDMA_FLASH: return "RIL_REQUEST_CDMA_FLASH";
   3697             case RIL_REQUEST_CDMA_BURST_DTMF: return "RIL_REQUEST_CDMA_BURST_DTMF";
   3698             case RIL_REQUEST_CDMA_SEND_SMS: return "RIL_REQUEST_CDMA_SEND_SMS";
   3699             case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE: return "RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE";
   3700             case RIL_REQUEST_GSM_GET_BROADCAST_CONFIG: return "RIL_REQUEST_GSM_GET_BROADCAST_CONFIG";
   3701             case RIL_REQUEST_GSM_SET_BROADCAST_CONFIG: return "RIL_REQUEST_GSM_SET_BROADCAST_CONFIG";
   3702             case RIL_REQUEST_CDMA_GET_BROADCAST_CONFIG: return "RIL_REQUEST_CDMA_GET_BROADCAST_CONFIG";
   3703             case RIL_REQUEST_CDMA_SET_BROADCAST_CONFIG: return "RIL_REQUEST_CDMA_SET_BROADCAST_CONFIG";
   3704             case RIL_REQUEST_GSM_BROADCAST_ACTIVATION: return "RIL_REQUEST_GSM_BROADCAST_ACTIVATION";
   3705             case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return "RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY";
   3706             case RIL_REQUEST_CDMA_BROADCAST_ACTIVATION: return "RIL_REQUEST_CDMA_BROADCAST_ACTIVATION";
   3707             case RIL_REQUEST_CDMA_SUBSCRIPTION: return "RIL_REQUEST_CDMA_SUBSCRIPTION";
   3708             case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM";
   3709             case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM";
   3710             case RIL_REQUEST_DEVICE_IDENTITY: return "RIL_REQUEST_DEVICE_IDENTITY";
   3711             case RIL_REQUEST_GET_SMSC_ADDRESS: return "RIL_REQUEST_GET_SMSC_ADDRESS";
   3712             case RIL_REQUEST_SET_SMSC_ADDRESS: return "RIL_REQUEST_SET_SMSC_ADDRESS";
   3713             case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "REQUEST_EXIT_EMERGENCY_CALLBACK_MODE";
   3714             case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "RIL_REQUEST_REPORT_SMS_MEMORY_STATUS";
   3715             case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING";
   3716             case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE";
   3717             case RIL_REQUEST_ISIM_AUTHENTICATION: return "RIL_REQUEST_ISIM_AUTHENTICATION";
   3718             case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
   3719             case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
   3720             case RIL_REQUEST_VOICE_RADIO_TECH: return "RIL_REQUEST_VOICE_RADIO_TECH";
   3721             case RIL_REQUEST_GET_CELL_INFO_LIST: return "RIL_REQUEST_GET_CELL_INFO_LIST";
   3722             case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return "RIL_REQUEST_SET_CELL_INFO_LIST_RATE";
   3723             default: return "<unknown request>";
   3724         }
   3725     }
   3726 
   3727     static String
   3728     responseToString(int request)
   3729     {
   3730 /*
   3731  cat libs/telephony/ril_unsol_commands.h \
   3732  | egrep "^ *{RIL_" \
   3733  | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
   3734 */
   3735         switch(request) {
   3736             case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
   3737             case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
   3738             case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
   3739             case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
   3740             case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
   3741             case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
   3742             case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
   3743             case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST";
   3744             case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
   3745             case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
   3746             case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
   3747             case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
   3748             case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
   3749             case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
   3750             case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
   3751             case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
   3752             case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FULL";
   3753             case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
   3754             case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
   3755             case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
   3756             case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_RESPONSE_CDMA_NEW_SMS";
   3757             case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_RESPONSE_NEW_BROADCAST_SMS";
   3758             case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
   3759             case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
   3760             case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
   3761             case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
   3762             case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
   3763             case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
   3764             case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
   3765             case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
   3766             case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
   3767             case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "CDMA_SUBSCRIPTION_SOURCE_CHANGED";
   3768             case RIL_UNSOl_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
   3769             case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
   3770             case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
   3771             case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
   3772             case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
   3773             default: return "<unknown reponse>";
   3774         }
   3775     }
   3776 
   3777     private void riljLog(String msg) {
   3778         Rlog.d(RILJ_LOG_TAG, msg);
   3779     }
   3780 
   3781     private void riljLogv(String msg) {
   3782         Rlog.v(RILJ_LOG_TAG, msg);
   3783     }
   3784 
   3785     private void unsljLog(int response) {
   3786         riljLog("[UNSL]< " + responseToString(response));
   3787     }
   3788 
   3789     private void unsljLogMore(int response, String more) {
   3790         riljLog("[UNSL]< " + responseToString(response) + " " + more);
   3791     }
   3792 
   3793     private void unsljLogRet(int response, Object ret) {
   3794         riljLog("[UNSL]< " + responseToString(response) + " " + retToString(response, ret));
   3795     }
   3796 
   3797     private void unsljLogvRet(int response, Object ret) {
   3798         riljLogv("[UNSL]< " + responseToString(response) + " " + retToString(response, ret));
   3799     }
   3800 
   3801 
   3802     // ***** Methods for CDMA support
   3803     @Override
   3804     public void
   3805     getDeviceIdentity(Message response) {
   3806         RILRequest rr = RILRequest.obtain(RIL_REQUEST_DEVICE_IDENTITY, response);
   3807 
   3808         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
   3809 
   3810         send(rr);
   3811     }
   3812 
   3813     @Override
   3814     public void
   3815     getCDMASubscription(Message response) {
   3816         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_SUBSCRIPTION, response);
   3817 
   3818         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
   3819 
   3820         send(rr);
   3821     }
   3822 
   3823     @Override
   3824     public void setPhoneType(int phoneType) { // Called by CDMAPhone and GSMPhone constructor
   3825         if (RILJ_LOGD) riljLog("setPhoneType=" + phoneType + " old value=" + mPhoneType);
   3826         mPhoneType = phoneType;
   3827     }
   3828 
   3829     /**
   3830      * {@inheritDoc}
   3831      */
   3832     @Override
   3833     public void queryCdmaRoamingPreference(Message response) {
   3834         RILRequest rr = RILRequest.obtain(
   3835                 RILConstants.RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE, response);
   3836 
   3837         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
   3838 
   3839         send(rr);
   3840     }
   3841 
   3842     /**
   3843      * {@inheritDoc}
   3844      */
   3845     @Override
   3846     public void setCdmaRoamingPreference(int cdmaRoamingType, Message response) {
   3847         RILRequest rr = RILRequest.obtain(
   3848                 RILConstants.RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE, response);
   3849 
   3850         rr.mParcel.writeInt(1);
   3851         rr.mParcel.writeInt(cdmaRoamingType);
   3852 
   3853         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
   3854                 + " : " + cdmaRoamingType);
   3855 
   3856         send(rr);
   3857     }
   3858 
   3859     /**
   3860      * {@inheritDoc}
   3861      */
   3862     @Override
   3863     public void setCdmaSubscriptionSource(int cdmaSubscription , Message response) {
   3864         RILRequest rr = RILRequest.obtain(
   3865                 RILConstants.RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE, response);
   3866 
   3867         rr.mParcel.writeInt(1);
   3868         rr.mParcel.writeInt(cdmaSubscription);
   3869 
   3870         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
   3871                 + " : " + cdmaSubscription);
   3872 
   3873         send(rr);
   3874     }
   3875 
   3876     /**
   3877      * {@inheritDoc}
   3878      */
   3879     @Override
   3880     public void getCdmaSubscriptionSource(Message response) {
   3881         RILRequest rr = RILRequest.obtain(
   3882                 RILConstants.RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE, response);
   3883 
   3884         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
   3885 
   3886         send(rr);
   3887     }
   3888 
   3889     /**
   3890      * {@inheritDoc}
   3891      */
   3892     @Override
   3893     public void queryTTYMode(Message response) {
   3894         RILRequest rr = RILRequest.obtain(
   3895                 RILConstants.RIL_REQUEST_QUERY_TTY_MODE, response);
   3896 
   3897         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
   3898 
   3899         send(rr);
   3900     }
   3901 
   3902     /**
   3903      * {@inheritDoc}
   3904      */
   3905     @Override
   3906     public void setTTYMode(int ttyMode, Message response) {
   3907         RILRequest rr = RILRequest.obtain(
   3908                 RILConstants.RIL_REQUEST_SET_TTY_MODE, response);
   3909 
   3910         rr.mParcel.writeInt(1);
   3911         rr.mParcel.writeInt(ttyMode);
   3912 
   3913         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
   3914                 + " : " + ttyMode);
   3915 
   3916         send(rr);
   3917     }
   3918 
   3919     /**
   3920      * {@inheritDoc}
   3921      */
   3922     @Override
   3923     public void
   3924     sendCDMAFeatureCode(String FeatureCode, Message response) {
   3925         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_FLASH, response);
   3926 
   3927         rr.mParcel.writeString(FeatureCode);
   3928 
   3929         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
   3930                 + " : " + FeatureCode);
   3931 
   3932         send(rr);
   3933     }
   3934 
   3935     @Override
   3936     public void getCdmaBroadcastConfig(Message response) {
   3937         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_GET_BROADCAST_CONFIG, response);
   3938 
   3939         send(rr);
   3940     }
   3941 
   3942     @Override
   3943     public void setCdmaBroadcastConfig(CdmaSmsBroadcastConfigInfo[] configs, Message response) {
   3944         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_SET_BROADCAST_CONFIG, response);
   3945 
   3946         // Convert to 1 service category per config (the way RIL takes is)
   3947         ArrayList<CdmaSmsBroadcastConfigInfo> processedConfigs =
   3948             new ArrayList<CdmaSmsBroadcastConfigInfo>();
   3949         for (CdmaSmsBroadcastConfigInfo config : configs) {
   3950             for (int i = config.getFromServiceCategory(); i <= config.getToServiceCategory(); i++) {
   3951                 processedConfigs.add(new CdmaSmsBroadcastConfigInfo(i,
   3952                         i,
   3953                         config.getLanguage(),
   3954                         config.isSelected()));
   3955             }
   3956         }
   3957 
   3958         CdmaSmsBroadcastConfigInfo[] rilConfigs = processedConfigs.toArray(configs);
   3959         rr.mParcel.writeInt(rilConfigs.length);
   3960         for(int i = 0; i < rilConfigs.length; i++) {
   3961             rr.mParcel.writeInt(rilConfigs[i].getFromServiceCategory());
   3962             rr.mParcel.writeInt(rilConfigs[i].getLanguage());
   3963             rr.mParcel.writeInt(rilConfigs[i].isSelected() ? 1 : 0);
   3964         }
   3965 
   3966         if (RILJ_LOGD) {
   3967             riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
   3968                     + " with " + rilConfigs.length + " configs : ");
   3969             for (int i = 0; i < rilConfigs.length; i++) {
   3970                 riljLog(rilConfigs[i].toString());
   3971             }
   3972         }
   3973 
   3974         send(rr);
   3975     }
   3976 
   3977     @Override
   3978     public void setCdmaBroadcastActivation(boolean activate, Message response) {
   3979         RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_BROADCAST_ACTIVATION, response);
   3980 
   3981         rr.mParcel.writeInt(1);
   3982         rr.mParcel.writeInt(activate ? 0 :1);
   3983 
   3984         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
   3985 
   3986         send(rr);
   3987     }
   3988 
   3989     /**
   3990      * {@inheritDoc}
   3991      */
   3992     @Override
   3993     public void exitEmergencyCallbackMode(Message response) {
   3994         RILRequest rr = RILRequest.obtain(RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE, response);
   3995 
   3996         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
   3997 
   3998         send(rr);
   3999     }
   4000 
   4001     @Override
   4002     public void requestIsimAuthentication(String nonce, Message response) {
   4003         RILRequest rr = RILRequest.obtain(RIL_REQUEST_ISIM_AUTHENTICATION, response);
   4004 
   4005         rr.mParcel.writeString(nonce);
   4006 
   4007         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
   4008 
   4009         send(rr);
   4010     }
   4011 
   4012     /**
   4013      * {@inheritDoc}
   4014      */
   4015     @Override
   4016     public void getCellInfoList(Message result) {
   4017         RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_CELL_INFO_LIST, result);
   4018 
   4019         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
   4020 
   4021         send(rr);
   4022     }
   4023 
   4024     /**
   4025      * {@inheritDoc}
   4026      */
   4027     @Override
   4028     public void setCellInfoListRate(int rateInMillis, Message response) {
   4029         if (RILJ_LOGD) riljLog("setCellInfoListRate: " + rateInMillis);
   4030         RILRequest rr = RILRequest.obtain(RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE, response);
   4031 
   4032         rr.mParcel.writeInt(1);
   4033         rr.mParcel.writeInt(rateInMillis);
   4034 
   4035         if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
   4036 
   4037         send(rr);
   4038     }
   4039 
   4040     /* (non-Javadoc)
   4041      * @see com.android.internal.telephony.BaseCommands#testingEmergencyCall()
   4042      */
   4043     @Override
   4044     public void testingEmergencyCall() {
   4045         if (RILJ_LOGD) riljLog("testingEmergencyCall");
   4046         mTestingEmergencyCall.set(true);
   4047     }
   4048 
   4049     public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
   4050         pw.println("RIL: " + this);
   4051         pw.println(" mSocket=" + mSocket);
   4052         pw.println(" mSenderThread=" + mSenderThread);
   4053         pw.println(" mSender=" + mSender);
   4054         pw.println(" mReceiverThread=" + mReceiverThread);
   4055         pw.println(" mReceiver=" + mReceiver);
   4056         pw.println(" mWakeLock=" + mWakeLock);
   4057         pw.println(" mWakeLockTimeout=" + mWakeLockTimeout);
   4058         synchronized (mRequestList) {
   4059           pw.println(" mRequestMessagesPending=" + mRequestMessagesPending);
   4060           pw.println(" mRequestMessagesWaiting=" + mRequestMessagesWaiting);
   4061             int count = mRequestList.size();
   4062             pw.println(" mRequestList count=" + count);
   4063             for (int i = 0; i < count; i++) {
   4064                 RILRequest rr = mRequestList.get(i);
   4065                 pw.println("  [" + rr.mSerial + "] " + requestToString(rr.mRequest));
   4066             }
   4067         }
   4068         pw.println(" mLastNITZTimeInfo=" + mLastNITZTimeInfo);
   4069         pw.println(" mTestingEmergencyCall=" + mTestingEmergencyCall.get());
   4070     }
   4071 }
   4072