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