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