1 /* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.internal.telephony; 18 19 import static com.android.internal.telephony.RILConstants.*; 20 import static android.telephony.TelephonyManager.NETWORK_TYPE_UNKNOWN; 21 import static android.telephony.TelephonyManager.NETWORK_TYPE_EDGE; 22 import static android.telephony.TelephonyManager.NETWORK_TYPE_GPRS; 23 import static android.telephony.TelephonyManager.NETWORK_TYPE_UMTS; 24 import static android.telephony.TelephonyManager.NETWORK_TYPE_HSDPA; 25 import static android.telephony.TelephonyManager.NETWORK_TYPE_HSUPA; 26 import static android.telephony.TelephonyManager.NETWORK_TYPE_HSPA; 27 28 import android.content.BroadcastReceiver; 29 import android.content.Context; 30 import android.content.Intent; 31 import android.content.IntentFilter; 32 import android.hardware.display.DisplayManager; 33 import android.net.ConnectivityManager; 34 import android.net.LocalSocket; 35 import android.net.LocalSocketAddress; 36 import android.os.AsyncResult; 37 import android.os.Handler; 38 import android.os.HandlerThread; 39 import android.os.Looper; 40 import android.os.Message; 41 import android.os.Parcel; 42 import android.os.PowerManager; 43 import android.os.BatteryManager; 44 import android.os.SystemProperties; 45 import android.os.PowerManager.WakeLock; 46 import android.os.SystemClock; 47 import android.provider.Settings.SettingNotFoundException; 48 import android.service.carrier.CarrierIdentifier; 49 import android.telephony.CellInfo; 50 import android.telephony.NeighboringCellInfo; 51 import android.telephony.PcoData; 52 import android.telephony.PhoneNumberUtils; 53 import android.telephony.RadioAccessFamily; 54 import android.telephony.Rlog; 55 import android.telephony.SignalStrength; 56 import android.telephony.SmsManager; 57 import android.telephony.SmsMessage; 58 import android.telephony.SubscriptionManager; 59 import android.telephony.TelephonyManager; 60 import android.telephony.TelephonyHistogram; 61 import android.telephony.ModemActivityInfo; 62 import android.text.TextUtils; 63 import android.util.SparseArray; 64 import android.view.Display; 65 66 import com.android.internal.telephony.gsm.SmsBroadcastConfigInfo; 67 import com.android.internal.telephony.gsm.SsData; 68 import com.android.internal.telephony.gsm.SuppServiceNotification; 69 import com.android.internal.telephony.uicc.IccCardApplicationStatus; 70 import com.android.internal.telephony.uicc.IccCardStatus; 71 import com.android.internal.telephony.uicc.IccIoResult; 72 import com.android.internal.telephony.uicc.IccRefreshResponse; 73 import com.android.internal.telephony.uicc.IccUtils; 74 import com.android.internal.telephony.cdma.CdmaCallWaitingNotification; 75 import com.android.internal.telephony.cdma.CdmaInformationRecords; 76 import com.android.internal.telephony.cdma.CdmaSmsBroadcastConfigInfo; 77 import com.android.internal.telephony.dataconnection.DcFailCause; 78 import com.android.internal.telephony.dataconnection.DataCallResponse; 79 import com.android.internal.telephony.dataconnection.DataProfile; 80 import com.android.internal.telephony.RadioCapability; 81 import com.android.internal.telephony.TelephonyDevController; 82 import com.android.internal.telephony.HardwareConfig; 83 84 import java.io.ByteArrayInputStream; 85 import java.io.DataInputStream; 86 import java.io.FileDescriptor; 87 import java.io.IOException; 88 import java.io.InputStream; 89 import java.io.PrintWriter; 90 import java.util.ArrayList; 91 import java.util.Arrays; 92 import java.util.Collections; 93 import java.util.List; 94 import java.util.concurrent.atomic.AtomicBoolean; 95 import java.util.concurrent.atomic.AtomicInteger; 96 import java.util.List; 97 import java.util.Random; 98 99 /** 100 * {@hide} 101 */ 102 103 class RILRequest { 104 static final String LOG_TAG = "RilRequest"; 105 106 //***** Class Variables 107 static Random sRandom = new Random(); 108 static AtomicInteger sNextSerial = new AtomicInteger(0); 109 private static Object sPoolSync = new Object(); 110 private static RILRequest sPool = null; 111 private static int sPoolSize = 0; 112 private static final int MAX_POOL_SIZE = 4; 113 private Context mContext; 114 115 //***** Instance Variables 116 int mSerial; 117 int mRequest; 118 Message mResult; 119 Parcel mParcel; 120 RILRequest mNext; 121 int mWakeLockType; 122 // time in ms when RIL request was made 123 long mStartTimeMs; 124 125 /** 126 * Retrieves a new RILRequest instance from the pool. 127 * 128 * @param request RIL_REQUEST_* 129 * @param result sent when operation completes 130 * @return a RILRequest instance from the pool. 131 */ obtain(int request, Message result)132 static RILRequest obtain(int request, Message result) { 133 RILRequest rr = null; 134 135 synchronized(sPoolSync) { 136 if (sPool != null) { 137 rr = sPool; 138 sPool = rr.mNext; 139 rr.mNext = null; 140 sPoolSize--; 141 } 142 } 143 144 if (rr == null) { 145 rr = new RILRequest(); 146 } 147 148 rr.mSerial = sNextSerial.getAndIncrement(); 149 150 rr.mRequest = request; 151 rr.mResult = result; 152 rr.mParcel = Parcel.obtain(); 153 154 rr.mWakeLockType = RIL.INVALID_WAKELOCK; 155 rr.mStartTimeMs = SystemClock.elapsedRealtime(); 156 if (result != null && result.getTarget() == null) { 157 throw new NullPointerException("Message target must not be null"); 158 } 159 160 // first elements in any RIL Parcel 161 rr.mParcel.writeInt(request); 162 rr.mParcel.writeInt(rr.mSerial); 163 164 return rr; 165 } 166 167 /** 168 * Returns a RILRequest instance to the pool. 169 * 170 * Note: This should only be called once per use. 171 */ release()172 void release() { 173 synchronized (sPoolSync) { 174 if (sPoolSize < MAX_POOL_SIZE) { 175 mNext = sPool; 176 sPool = this; 177 sPoolSize++; 178 mResult = null; 179 if(mWakeLockType != RIL.INVALID_WAKELOCK) { 180 //This is OK for some wakelock types and not others 181 if(mWakeLockType == RIL.FOR_WAKELOCK) { 182 Rlog.e(LOG_TAG, "RILRequest releasing with held wake lock: " 183 + serialString()); 184 } 185 } 186 } 187 } 188 } 189 RILRequest()190 private RILRequest() { 191 } 192 193 static void resetSerial()194 resetSerial() { 195 // use a random so that on recovery we probably don't mix old requests 196 // with new. 197 sNextSerial.set(sRandom.nextInt()); 198 } 199 200 String serialString()201 serialString() { 202 //Cheesy way to do %04d 203 StringBuilder sb = new StringBuilder(8); 204 String sn; 205 206 long adjustedSerial = (((long)mSerial) - Integer.MIN_VALUE)%10000; 207 208 sn = Long.toString(adjustedSerial); 209 210 //sb.append("J["); 211 sb.append('['); 212 for (int i = 0, s = sn.length() ; i < 4 - s; i++) { 213 sb.append('0'); 214 } 215 216 sb.append(sn); 217 sb.append(']'); 218 return sb.toString(); 219 } 220 221 void onError(int error, Object ret)222 onError(int error, Object ret) { 223 CommandException ex; 224 225 ex = CommandException.fromRilErrno(error); 226 227 if (RIL.RILJ_LOGD) Rlog.d(LOG_TAG, serialString() + "< " 228 + RIL.requestToString(mRequest) 229 + " error: " + ex + " ret=" + RIL.retToString(mRequest, ret)); 230 231 if (mResult != null) { 232 AsyncResult.forMessage(mResult, ret, ex); 233 mResult.sendToTarget(); 234 } 235 236 if (mParcel != null) { 237 mParcel.recycle(); 238 mParcel = null; 239 } 240 } 241 } 242 243 244 /** 245 * RIL implementation of the CommandsInterface. 246 * 247 * {@hide} 248 */ 249 public final class RIL extends BaseCommands implements CommandsInterface { 250 static final String RILJ_LOG_TAG = "RILJ"; 251 // Have a separate wakelock instance for Ack 252 static final String RILJ_ACK_WAKELOCK_NAME = "RILJ_ACK_WL"; 253 static final boolean RILJ_LOGD = true; 254 static final boolean RILJ_LOGV = false; // STOPSHIP if true 255 static final int RADIO_SCREEN_UNSET = -1; 256 static final int RADIO_SCREEN_OFF = 0; 257 static final int RADIO_SCREEN_ON = 1; 258 static final int RIL_HISTOGRAM_BUCKET_COUNT = 5; 259 260 /** 261 * Wake lock timeout should be longer than the longest timeout in 262 * the vendor ril. 263 */ 264 private static final int DEFAULT_WAKE_LOCK_TIMEOUT_MS = 60000; 265 266 // Wake lock default timeout associated with ack 267 private static final int DEFAULT_ACK_WAKE_LOCK_TIMEOUT_MS = 200; 268 269 private static final int DEFAULT_BLOCKING_MESSAGE_RESPONSE_TIMEOUT_MS = 2000; 270 271 // Variables used to differentiate ack messages from request while calling clearWakeLock() 272 public static final int INVALID_WAKELOCK = -1; 273 public static final int FOR_WAKELOCK = 0; 274 public static final int FOR_ACK_WAKELOCK = 1; 275 276 //***** Instance Variables 277 278 LocalSocket mSocket; 279 HandlerThread mSenderThread; 280 RILSender mSender; 281 Thread mReceiverThread; 282 RILReceiver mReceiver; 283 Display mDefaultDisplay; 284 int mDefaultDisplayState = Display.STATE_UNKNOWN; 285 int mRadioScreenState = RADIO_SCREEN_UNSET; 286 boolean mIsDevicePlugged = false; 287 final WakeLock mWakeLock; // Wake lock associated with request/response 288 final WakeLock mAckWakeLock; // Wake lock associated with ack sent 289 final int mWakeLockTimeout; // Timeout associated with request/response 290 final int mAckWakeLockTimeout; // Timeout associated with ack sent 291 // The number of wakelock requests currently active. Don't release the lock 292 // until dec'd to 0 293 int mWakeLockCount; 294 295 // Variables used to identify releasing of WL on wakelock timeouts 296 volatile int mWlSequenceNum = 0; 297 volatile int mAckWlSequenceNum = 0; 298 299 SparseArray<RILRequest> mRequestList = new SparseArray<RILRequest>(); 300 static SparseArray<TelephonyHistogram> mRilTimeHistograms = new 301 SparseArray<TelephonyHistogram>(); 302 303 Object[] mLastNITZTimeInfo; 304 305 // When we are testing emergency calls 306 AtomicBoolean mTestingEmergencyCall = new AtomicBoolean(false); 307 308 private Integer mInstanceId; 309 310 private TelephonyEventLog mEventLog; 311 312 //***** Events 313 314 static final int EVENT_SEND = 1; 315 static final int EVENT_WAKE_LOCK_TIMEOUT = 2; 316 static final int EVENT_SEND_ACK = 3; 317 static final int EVENT_ACK_WAKE_LOCK_TIMEOUT = 4; 318 static final int EVENT_BLOCKING_RESPONSE_TIMEOUT = 5; 319 320 //***** Constants 321 322 // match with constant in ril.cpp 323 static final int RIL_MAX_COMMAND_BYTES = (8 * 1024); 324 static final int RESPONSE_SOLICITED = 0; 325 static final int RESPONSE_UNSOLICITED = 1; 326 static final int RESPONSE_SOLICITED_ACK = 2; 327 static final int RESPONSE_SOLICITED_ACK_EXP = 3; 328 static final int RESPONSE_UNSOLICITED_ACK_EXP = 4; 329 330 static final String[] SOCKET_NAME_RIL = {"rild", "rild2", "rild3"}; 331 332 static final int SOCKET_OPEN_RETRY_MILLIS = 4 * 1000; 333 334 // The number of the required config values for broadcast SMS stored in the C struct 335 // RIL_CDMA_BroadcastServiceInfo 336 private static final int CDMA_BSI_NO_OF_INTS_STRUCT = 3; 337 338 private static final int CDMA_BROADCAST_SMS_NO_OF_SERVICE_CATEGORIES = 31; 339 340 private final DisplayManager.DisplayListener mDisplayListener = 341 new DisplayManager.DisplayListener() { 342 @Override 343 public void onDisplayAdded(int displayId) { } 344 345 @Override 346 public void onDisplayRemoved(int displayId) { } 347 348 @Override 349 public void onDisplayChanged(int displayId) { 350 if (displayId == Display.DEFAULT_DISPLAY) { 351 final int oldState = mDefaultDisplayState; 352 mDefaultDisplayState = mDefaultDisplay.getState(); 353 if (mDefaultDisplayState != oldState) { 354 updateScreenState(); 355 } 356 } 357 } 358 }; 359 360 private final BroadcastReceiver mBatteryStateListener = new BroadcastReceiver() { 361 @Override 362 public void onReceive(Context context, Intent intent) { 363 boolean oldState = mIsDevicePlugged; 364 // 0 means it's on battery 365 mIsDevicePlugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0; 366 if (mIsDevicePlugged != oldState) { 367 updateScreenState(); 368 } 369 } 370 }; 371 getTelephonyRILTimingHistograms()372 public static List<TelephonyHistogram> getTelephonyRILTimingHistograms() { 373 List<TelephonyHistogram> list; 374 synchronized (mRilTimeHistograms) { 375 list = new ArrayList<>(mRilTimeHistograms.size()); 376 for (int i = 0; i < mRilTimeHistograms.size(); i++) { 377 TelephonyHistogram entry = new TelephonyHistogram(mRilTimeHistograms.valueAt(i)); 378 list.add(entry); 379 } 380 } 381 return list; 382 } 383 384 class RILSender extends Handler implements Runnable { RILSender(Looper looper)385 public RILSender(Looper looper) { 386 super(looper); 387 } 388 389 // Only allocated once 390 byte[] dataLength = new byte[4]; 391 392 //***** Runnable implementation 393 @Override 394 public void run()395 run() { 396 //setup if needed 397 } 398 399 400 //***** Handler implementation 401 @Override public void handleMessage(Message msg)402 handleMessage(Message msg) { 403 RILRequest rr = (RILRequest)(msg.obj); 404 RILRequest req = null; 405 406 switch (msg.what) { 407 case EVENT_SEND: 408 case EVENT_SEND_ACK: 409 try { 410 LocalSocket s; 411 412 s = mSocket; 413 414 if (s == null) { 415 rr.onError(RADIO_NOT_AVAILABLE, null); 416 decrementWakeLock(rr); 417 rr.release(); 418 return; 419 } 420 421 // Acks should not be stored in list before sending 422 if (msg.what != EVENT_SEND_ACK) { 423 synchronized (mRequestList) { 424 rr.mStartTimeMs = SystemClock.elapsedRealtime(); 425 mRequestList.append(rr.mSerial, rr); 426 } 427 } 428 429 byte[] data; 430 431 data = rr.mParcel.marshall(); 432 rr.mParcel.recycle(); 433 rr.mParcel = null; 434 435 if (data.length > RIL_MAX_COMMAND_BYTES) { 436 throw new RuntimeException( 437 "Parcel larger than max bytes allowed! " 438 + data.length); 439 } 440 441 // parcel length in big endian 442 dataLength[0] = dataLength[1] = 0; 443 dataLength[2] = (byte)((data.length >> 8) & 0xff); 444 dataLength[3] = (byte)((data.length) & 0xff); 445 446 //Rlog.v(RILJ_LOG_TAG, "writing packet: " + data.length + " bytes"); 447 448 s.getOutputStream().write(dataLength); 449 s.getOutputStream().write(data); 450 if (msg.what == EVENT_SEND_ACK) { 451 rr.release(); 452 return; 453 } 454 } catch (IOException ex) { 455 Rlog.e(RILJ_LOG_TAG, "IOException", ex); 456 req = findAndRemoveRequestFromList(rr.mSerial); 457 // make sure this request has not already been handled, 458 // eg, if RILReceiver cleared the list. 459 if (req != null) { 460 rr.onError(RADIO_NOT_AVAILABLE, null); 461 decrementWakeLock(rr); 462 rr.release(); 463 return; 464 } 465 } catch (RuntimeException exc) { 466 Rlog.e(RILJ_LOG_TAG, "Uncaught exception ", exc); 467 req = findAndRemoveRequestFromList(rr.mSerial); 468 // make sure this request has not already been handled, 469 // eg, if RILReceiver cleared the list. 470 if (req != null) { 471 rr.onError(GENERIC_FAILURE, null); 472 decrementWakeLock(rr); 473 rr.release(); 474 return; 475 } 476 } 477 478 break; 479 480 case EVENT_WAKE_LOCK_TIMEOUT: 481 // Haven't heard back from the last request. Assume we're 482 // not getting a response and release the wake lock. 483 484 // The timer of WAKE_LOCK_TIMEOUT is reset with each 485 // new send request. So when WAKE_LOCK_TIMEOUT occurs 486 // all requests in mRequestList already waited at 487 // least DEFAULT_WAKE_LOCK_TIMEOUT_MS but no response. 488 // 489 // Note: Keep mRequestList so that delayed response 490 // can still be handled when response finally comes. 491 492 synchronized (mRequestList) { 493 if (msg.arg1 == mWlSequenceNum && clearWakeLock(FOR_WAKELOCK)) { 494 if (RILJ_LOGD) { 495 int count = mRequestList.size(); 496 Rlog.d(RILJ_LOG_TAG, "WAKE_LOCK_TIMEOUT " + 497 " mRequestList=" + count); 498 for (int i = 0; i < count; i++) { 499 rr = mRequestList.valueAt(i); 500 Rlog.d(RILJ_LOG_TAG, i + ": [" + rr.mSerial + "] " 501 + requestToString(rr.mRequest)); 502 } 503 } 504 } 505 } 506 break; 507 508 case EVENT_ACK_WAKE_LOCK_TIMEOUT: 509 if (msg.arg1 == mAckWlSequenceNum && clearWakeLock(FOR_ACK_WAKELOCK)) { 510 if (RILJ_LOGV) { 511 Rlog.d(RILJ_LOG_TAG, "ACK_WAKE_LOCK_TIMEOUT"); 512 } 513 } 514 break; 515 516 case EVENT_BLOCKING_RESPONSE_TIMEOUT: 517 int serial = msg.arg1; 518 rr = findAndRemoveRequestFromList(serial); 519 // If the request has already been processed, do nothing 520 if(rr == null) { 521 break; 522 } 523 524 //build a response if expected 525 if (rr.mResult != null) { 526 Object timeoutResponse = getResponseForTimedOutRILRequest(rr); 527 AsyncResult.forMessage( rr.mResult, timeoutResponse, null); 528 rr.mResult.sendToTarget(); 529 mEventLog.writeOnRilTimeoutResponse(rr.mSerial, rr.mRequest); 530 } 531 532 decrementWakeLock(rr); 533 rr.release(); 534 break; 535 } 536 } 537 } 538 539 /** 540 * In order to prevent calls to Telephony from waiting indefinitely 541 * low-latency blocking calls will eventually time out. In the event of 542 * a timeout, this function generates a response that is returned to the 543 * higher layers to unblock the call. This is in lieu of a meaningful 544 * response. 545 * @param rr The RIL Request that has timed out. 546 * @return A default object, such as the one generated by a normal response 547 * that is returned to the higher layers. 548 **/ getResponseForTimedOutRILRequest(RILRequest rr)549 private static Object getResponseForTimedOutRILRequest(RILRequest rr) { 550 if (rr == null ) return null; 551 552 Object timeoutResponse = null; 553 switch(rr.mRequest) { 554 case RIL_REQUEST_GET_ACTIVITY_INFO: 555 timeoutResponse = new ModemActivityInfo( 556 0, 0, 0, new int [ModemActivityInfo.TX_POWER_LEVELS], 0, 0); 557 break; 558 }; 559 return timeoutResponse; 560 } 561 562 /** 563 * Reads in a single RIL message off the wire. A RIL message consists 564 * of a 4-byte little-endian length and a subsequent series of bytes. 565 * The final message (length header omitted) is read into 566 * <code>buffer</code> and the length of the final message (less header) 567 * is returned. A return value of -1 indicates end-of-stream. 568 * 569 * @param is non-null; Stream to read from 570 * @param buffer Buffer to fill in. Must be as large as maximum 571 * message size, or an ArrayOutOfBounds exception will be thrown. 572 * @return Length of message less header, or -1 on end of stream. 573 * @throws IOException 574 */ readRilMessage(InputStream is, byte[] buffer)575 private static int readRilMessage(InputStream is, byte[] buffer) 576 throws IOException { 577 int countRead; 578 int offset; 579 int remaining; 580 int messageLength; 581 582 // First, read in the length of the message 583 offset = 0; 584 remaining = 4; 585 do { 586 countRead = is.read(buffer, offset, remaining); 587 588 if (countRead < 0 ) { 589 Rlog.e(RILJ_LOG_TAG, "Hit EOS reading message length"); 590 return -1; 591 } 592 593 offset += countRead; 594 remaining -= countRead; 595 } while (remaining > 0); 596 597 messageLength = ((buffer[0] & 0xff) << 24) 598 | ((buffer[1] & 0xff) << 16) 599 | ((buffer[2] & 0xff) << 8) 600 | (buffer[3] & 0xff); 601 602 // Then, re-use the buffer and read in the message itself 603 offset = 0; 604 remaining = messageLength; 605 do { 606 countRead = is.read(buffer, offset, remaining); 607 608 if (countRead < 0 ) { 609 Rlog.e(RILJ_LOG_TAG, "Hit EOS reading message. messageLength=" + messageLength 610 + " remaining=" + remaining); 611 return -1; 612 } 613 614 offset += countRead; 615 remaining -= countRead; 616 } while (remaining > 0); 617 618 return messageLength; 619 } 620 621 class RILReceiver implements Runnable { 622 byte[] buffer; 623 RILReceiver()624 RILReceiver() { 625 buffer = new byte[RIL_MAX_COMMAND_BYTES]; 626 } 627 628 @Override 629 public void run()630 run() { 631 int retryCount = 0; 632 String rilSocket = "rild"; 633 634 try {for (;;) { 635 LocalSocket s = null; 636 LocalSocketAddress l; 637 638 if (mInstanceId == null || mInstanceId == 0 ) { 639 rilSocket = SOCKET_NAME_RIL[0]; 640 } else { 641 rilSocket = SOCKET_NAME_RIL[mInstanceId]; 642 } 643 644 try { 645 s = new LocalSocket(); 646 l = new LocalSocketAddress(rilSocket, 647 LocalSocketAddress.Namespace.RESERVED); 648 s.connect(l); 649 } catch (IOException ex){ 650 try { 651 if (s != null) { 652 s.close(); 653 } 654 } catch (IOException ex2) { 655 //ignore failure to close after failure to connect 656 } 657 658 // don't print an error message after the the first time 659 // or after the 8th time 660 661 if (retryCount == 8) { 662 Rlog.e (RILJ_LOG_TAG, 663 "Couldn't find '" + rilSocket 664 + "' socket after " + retryCount 665 + " times, continuing to retry silently"); 666 } else if (retryCount >= 0 && retryCount < 8) { 667 Rlog.i (RILJ_LOG_TAG, 668 "Couldn't find '" + rilSocket 669 + "' socket; retrying after timeout"); 670 } 671 672 try { 673 Thread.sleep(SOCKET_OPEN_RETRY_MILLIS); 674 } catch (InterruptedException er) { 675 } 676 677 retryCount++; 678 continue; 679 } 680 681 retryCount = 0; 682 683 mSocket = s; 684 Rlog.i(RILJ_LOG_TAG, "(" + mInstanceId + ") Connected to '" 685 + rilSocket + "' socket"); 686 687 int length = 0; 688 try { 689 InputStream is = mSocket.getInputStream(); 690 691 for (;;) { 692 Parcel p; 693 694 length = readRilMessage(is, buffer); 695 696 if (length < 0) { 697 // End-of-stream reached 698 break; 699 } 700 701 p = Parcel.obtain(); 702 p.unmarshall(buffer, 0, length); 703 p.setDataPosition(0); 704 705 //Rlog.v(RILJ_LOG_TAG, "Read packet: " + length + " bytes"); 706 707 processResponse(p); 708 p.recycle(); 709 } 710 } catch (java.io.IOException ex) { 711 Rlog.i(RILJ_LOG_TAG, "'" + rilSocket + "' socket closed", 712 ex); 713 } catch (Throwable tr) { 714 Rlog.e(RILJ_LOG_TAG, "Uncaught exception read length=" + length + 715 "Exception:" + tr.toString()); 716 } 717 718 Rlog.i(RILJ_LOG_TAG, "(" + mInstanceId + ") Disconnected from '" + rilSocket 719 + "' socket"); 720 721 setRadioState (RadioState.RADIO_UNAVAILABLE); 722 723 try { 724 mSocket.close(); 725 } catch (IOException ex) { 726 } 727 728 mSocket = null; 729 RILRequest.resetSerial(); 730 731 // Clear request list on close 732 clearRequestList(RADIO_NOT_AVAILABLE, false); 733 }} catch (Throwable tr) { 734 Rlog.e(RILJ_LOG_TAG,"Uncaught exception", tr); 735 } 736 737 /* We're disconnected so we don't know the ril version */ 738 notifyRegistrantsRilConnectionChanged(-1); 739 } 740 } 741 742 743 744 //***** Constructors 745 RIL(Context context, int preferredNetworkType, int cdmaSubscription)746 public RIL(Context context, int preferredNetworkType, int cdmaSubscription) { 747 this(context, preferredNetworkType, cdmaSubscription, null); 748 } 749 RIL(Context context, int preferredNetworkType, int cdmaSubscription, Integer instanceId)750 public RIL(Context context, int preferredNetworkType, 751 int cdmaSubscription, Integer instanceId) { 752 super(context); 753 if (RILJ_LOGD) { 754 riljLog("RIL(context, preferredNetworkType=" + preferredNetworkType + 755 " cdmaSubscription=" + cdmaSubscription + ")"); 756 } 757 758 mContext = context; 759 mCdmaSubscription = cdmaSubscription; 760 mPreferredNetworkType = preferredNetworkType; 761 mPhoneType = RILConstants.NO_PHONE; 762 mInstanceId = instanceId; 763 764 mEventLog = new TelephonyEventLog(mInstanceId); 765 PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE); 766 mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, RILJ_LOG_TAG); 767 mWakeLock.setReferenceCounted(false); 768 mAckWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, RILJ_ACK_WAKELOCK_NAME); 769 mAckWakeLock.setReferenceCounted(false); 770 mWakeLockTimeout = SystemProperties.getInt(TelephonyProperties.PROPERTY_WAKE_LOCK_TIMEOUT, 771 DEFAULT_WAKE_LOCK_TIMEOUT_MS); 772 mAckWakeLockTimeout = SystemProperties.getInt( 773 TelephonyProperties.PROPERTY_WAKE_LOCK_TIMEOUT, DEFAULT_ACK_WAKE_LOCK_TIMEOUT_MS); 774 mWakeLockCount = 0; 775 776 mSenderThread = new HandlerThread("RILSender" + mInstanceId); 777 mSenderThread.start(); 778 779 Looper looper = mSenderThread.getLooper(); 780 mSender = new RILSender(looper); 781 782 ConnectivityManager cm = (ConnectivityManager)context.getSystemService( 783 Context.CONNECTIVITY_SERVICE); 784 if (cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE) == false) { 785 riljLog("Not starting RILReceiver: wifi-only"); 786 } else { 787 riljLog("Starting RILReceiver" + mInstanceId); 788 mReceiver = new RILReceiver(); 789 mReceiverThread = new Thread(mReceiver, "RILReceiver" + mInstanceId); 790 mReceiverThread.start(); 791 792 DisplayManager dm = (DisplayManager)context.getSystemService( 793 Context.DISPLAY_SERVICE); 794 mDefaultDisplay = dm.getDisplay(Display.DEFAULT_DISPLAY); 795 dm.registerDisplayListener(mDisplayListener, null); 796 mDefaultDisplayState = mDefaultDisplay.getState(); 797 798 IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); 799 Intent batteryStatus = context.registerReceiver(mBatteryStateListener, filter); 800 if (batteryStatus != null) { 801 // 0 means it's on battery 802 mIsDevicePlugged = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0; 803 } 804 } 805 806 TelephonyDevController tdc = TelephonyDevController.getInstance(); 807 tdc.registerRIL(this); 808 } 809 810 //***** CommandsInterface implementation 811 812 @Override getVoiceRadioTechnology(Message result)813 public void getVoiceRadioTechnology(Message result) { 814 RILRequest rr = RILRequest.obtain(RIL_REQUEST_VOICE_RADIO_TECH, result); 815 816 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 817 818 send(rr); 819 } 820 821 getImsRegistrationState(Message result)822 public void getImsRegistrationState(Message result) { 823 RILRequest rr = RILRequest.obtain(RIL_REQUEST_IMS_REGISTRATION_STATE, result); 824 825 if (RILJ_LOGD) { 826 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 827 } 828 send(rr); 829 } 830 831 @Override public void setOnNITZTime(Handler h, int what, Object obj)832 setOnNITZTime(Handler h, int what, Object obj) { 833 super.setOnNITZTime(h, what, obj); 834 835 // Send the last NITZ time if we have it 836 if (mLastNITZTimeInfo != null) { 837 mNITZTimeRegistrant 838 .notifyRegistrant( 839 new AsyncResult (null, mLastNITZTimeInfo, null)); 840 } 841 } 842 843 @Override 844 public void getIccCardStatus(Message result)845 getIccCardStatus(Message result) { 846 //Note: This RIL request has not been renamed to ICC, 847 // but this request is also valid for SIM and RUIM 848 RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_SIM_STATUS, result); 849 850 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 851 852 send(rr); 853 } 854 setUiccSubscription(int slotId, int appIndex, int subId, int subStatus, Message result)855 public void setUiccSubscription(int slotId, int appIndex, int subId, 856 int subStatus, Message result) { 857 //Note: This RIL request is also valid for SIM and RUIM (ICC card) 858 RILRequest rr = RILRequest.obtain(RIL_REQUEST_SET_UICC_SUBSCRIPTION, result); 859 860 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 861 + " slot: " + slotId + " appIndex: " + appIndex 862 + " subId: " + subId + " subStatus: " + subStatus); 863 864 rr.mParcel.writeInt(slotId); 865 rr.mParcel.writeInt(appIndex); 866 rr.mParcel.writeInt(subId); 867 rr.mParcel.writeInt(subStatus); 868 869 send(rr); 870 } 871 872 // FIXME This API should take an AID and slot ID setDataAllowed(boolean allowed, Message result)873 public void setDataAllowed(boolean allowed, Message result) { 874 RILRequest rr = RILRequest.obtain(RIL_REQUEST_ALLOW_DATA, result); 875 if (RILJ_LOGD) { 876 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + 877 " allowed: " + allowed); 878 } 879 880 rr.mParcel.writeInt(1); 881 rr.mParcel.writeInt(allowed ? 1 : 0); 882 send(rr); 883 } 884 885 @Override public void supplyIccPin(String pin, Message result)886 supplyIccPin(String pin, Message result) { 887 supplyIccPinForApp(pin, null, result); 888 } 889 890 @Override public void supplyIccPinForApp(String pin, String aid, Message result)891 supplyIccPinForApp(String pin, String aid, Message result) { 892 //Note: This RIL request has not been renamed to ICC, 893 // but this request is also valid for SIM and RUIM 894 RILRequest rr = RILRequest.obtain(RIL_REQUEST_ENTER_SIM_PIN, result); 895 896 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 897 898 rr.mParcel.writeInt(2); 899 rr.mParcel.writeString(pin); 900 rr.mParcel.writeString(aid); 901 902 send(rr); 903 } 904 905 @Override public void supplyIccPuk(String puk, String newPin, Message result)906 supplyIccPuk(String puk, String newPin, Message result) { 907 supplyIccPukForApp(puk, newPin, null, result); 908 } 909 910 @Override public void supplyIccPukForApp(String puk, String newPin, String aid, Message result)911 supplyIccPukForApp(String puk, String newPin, String aid, Message result) { 912 //Note: This RIL request has not been renamed to ICC, 913 // but this request is also valid for SIM and RUIM 914 RILRequest rr = RILRequest.obtain(RIL_REQUEST_ENTER_SIM_PUK, result); 915 916 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 917 918 rr.mParcel.writeInt(3); 919 rr.mParcel.writeString(puk); 920 rr.mParcel.writeString(newPin); 921 rr.mParcel.writeString(aid); 922 923 send(rr); 924 } 925 926 @Override public void supplyIccPin2(String pin, Message result)927 supplyIccPin2(String pin, Message result) { 928 supplyIccPin2ForApp(pin, null, result); 929 } 930 931 @Override public void supplyIccPin2ForApp(String pin, String aid, Message result)932 supplyIccPin2ForApp(String pin, String aid, Message result) { 933 //Note: This RIL request has not been renamed to ICC, 934 // but this request is also valid for SIM and RUIM 935 RILRequest rr = RILRequest.obtain(RIL_REQUEST_ENTER_SIM_PIN2, result); 936 937 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 938 939 rr.mParcel.writeInt(2); 940 rr.mParcel.writeString(pin); 941 rr.mParcel.writeString(aid); 942 943 send(rr); 944 } 945 946 @Override public void supplyIccPuk2(String puk2, String newPin2, Message result)947 supplyIccPuk2(String puk2, String newPin2, Message result) { 948 supplyIccPuk2ForApp(puk2, newPin2, null, result); 949 } 950 951 @Override public void supplyIccPuk2ForApp(String puk, String newPin2, String aid, Message result)952 supplyIccPuk2ForApp(String puk, String newPin2, String aid, Message result) { 953 //Note: This RIL request has not been renamed to ICC, 954 // but this request is also valid for SIM and RUIM 955 RILRequest rr = RILRequest.obtain(RIL_REQUEST_ENTER_SIM_PUK2, result); 956 957 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 958 959 rr.mParcel.writeInt(3); 960 rr.mParcel.writeString(puk); 961 rr.mParcel.writeString(newPin2); 962 rr.mParcel.writeString(aid); 963 964 send(rr); 965 } 966 967 @Override public void changeIccPin(String oldPin, String newPin, Message result)968 changeIccPin(String oldPin, String newPin, Message result) { 969 changeIccPinForApp(oldPin, newPin, null, result); 970 } 971 972 @Override public void changeIccPinForApp(String oldPin, String newPin, String aid, Message result)973 changeIccPinForApp(String oldPin, String newPin, String aid, Message result) { 974 //Note: This RIL request has not been renamed to ICC, 975 // but this request is also valid for SIM and RUIM 976 RILRequest rr = RILRequest.obtain(RIL_REQUEST_CHANGE_SIM_PIN, result); 977 978 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 979 980 rr.mParcel.writeInt(3); 981 rr.mParcel.writeString(oldPin); 982 rr.mParcel.writeString(newPin); 983 rr.mParcel.writeString(aid); 984 985 send(rr); 986 } 987 988 @Override public void changeIccPin2(String oldPin2, String newPin2, Message result)989 changeIccPin2(String oldPin2, String newPin2, Message result) { 990 changeIccPin2ForApp(oldPin2, newPin2, null, result); 991 } 992 993 @Override public void changeIccPin2ForApp(String oldPin2, String newPin2, String aid, Message result)994 changeIccPin2ForApp(String oldPin2, String newPin2, String aid, Message result) { 995 //Note: This RIL request has not been renamed to ICC, 996 // but this request is also valid for SIM and RUIM 997 RILRequest rr = RILRequest.obtain(RIL_REQUEST_CHANGE_SIM_PIN2, result); 998 999 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1000 1001 rr.mParcel.writeInt(3); 1002 rr.mParcel.writeString(oldPin2); 1003 rr.mParcel.writeString(newPin2); 1004 rr.mParcel.writeString(aid); 1005 1006 send(rr); 1007 } 1008 1009 @Override 1010 public void changeBarringPassword(String facility, String oldPwd, String newPwd, Message result)1011 changeBarringPassword(String facility, String oldPwd, String newPwd, Message result) { 1012 RILRequest rr = RILRequest.obtain(RIL_REQUEST_CHANGE_BARRING_PASSWORD, result); 1013 1014 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1015 1016 rr.mParcel.writeInt(3); 1017 rr.mParcel.writeString(facility); 1018 rr.mParcel.writeString(oldPwd); 1019 rr.mParcel.writeString(newPwd); 1020 1021 send(rr); 1022 } 1023 1024 @Override 1025 public void supplyNetworkDepersonalization(String netpin, Message result)1026 supplyNetworkDepersonalization(String netpin, Message result) { 1027 RILRequest rr = RILRequest.obtain(RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION, result); 1028 1029 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1030 1031 rr.mParcel.writeInt(1); 1032 rr.mParcel.writeString(netpin); 1033 1034 send(rr); 1035 } 1036 1037 @Override 1038 public void getCurrentCalls(Message result)1039 getCurrentCalls (Message result) { 1040 RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_CURRENT_CALLS, result); 1041 1042 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1043 1044 send(rr); 1045 } 1046 1047 @Override 1048 @Deprecated public void getPDPContextList(Message result)1049 getPDPContextList(Message result) { 1050 getDataCallList(result); 1051 } 1052 1053 @Override 1054 public void getDataCallList(Message result)1055 getDataCallList(Message result) { 1056 RILRequest rr = RILRequest.obtain(RIL_REQUEST_DATA_CALL_LIST, result); 1057 1058 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1059 1060 send(rr); 1061 } 1062 1063 @Override 1064 public void dial(String address, int clirMode, Message result)1065 dial (String address, int clirMode, Message result) { 1066 dial(address, clirMode, null, result); 1067 } 1068 1069 @Override 1070 public void dial(String address, int clirMode, UUSInfo uusInfo, Message result)1071 dial(String address, int clirMode, UUSInfo uusInfo, Message result) { 1072 RILRequest rr = RILRequest.obtain(RIL_REQUEST_DIAL, result); 1073 1074 rr.mParcel.writeString(address); 1075 rr.mParcel.writeInt(clirMode); 1076 1077 if (uusInfo == null) { 1078 rr.mParcel.writeInt(0); // UUS information is absent 1079 } else { 1080 rr.mParcel.writeInt(1); // UUS information is present 1081 rr.mParcel.writeInt(uusInfo.getType()); 1082 rr.mParcel.writeInt(uusInfo.getDcs()); 1083 rr.mParcel.writeByteArray(uusInfo.getUserData()); 1084 } 1085 1086 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1087 1088 mEventLog.writeRilDial(rr.mSerial, clirMode, uusInfo); 1089 1090 send(rr); 1091 } 1092 1093 @Override 1094 public void getIMSI(Message result)1095 getIMSI(Message result) { 1096 getIMSIForApp(null, result); 1097 } 1098 1099 @Override 1100 public void getIMSIForApp(String aid, Message result)1101 getIMSIForApp(String aid, Message result) { 1102 RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_IMSI, result); 1103 1104 rr.mParcel.writeInt(1); 1105 rr.mParcel.writeString(aid); 1106 1107 if (RILJ_LOGD) riljLog(rr.serialString() + 1108 "> getIMSI: " + requestToString(rr.mRequest) 1109 + " aid: " + aid); 1110 1111 send(rr); 1112 } 1113 1114 @Override 1115 public void getIMEI(Message result)1116 getIMEI(Message result) { 1117 RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_IMEI, result); 1118 1119 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1120 1121 send(rr); 1122 } 1123 1124 @Override 1125 public void getIMEISV(Message result)1126 getIMEISV(Message result) { 1127 RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_IMEISV, result); 1128 1129 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1130 1131 send(rr); 1132 } 1133 1134 1135 @Override 1136 public void hangupConnection(int gsmIndex, Message result)1137 hangupConnection (int gsmIndex, Message result) { 1138 if (RILJ_LOGD) riljLog("hangupConnection: gsmIndex=" + gsmIndex); 1139 1140 RILRequest rr = RILRequest.obtain(RIL_REQUEST_HANGUP, result); 1141 1142 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " " + 1143 gsmIndex); 1144 1145 mEventLog.writeRilHangup(rr.mSerial, RIL_REQUEST_HANGUP, gsmIndex); 1146 1147 rr.mParcel.writeInt(1); 1148 rr.mParcel.writeInt(gsmIndex); 1149 1150 send(rr); 1151 } 1152 1153 @Override 1154 public void hangupWaitingOrBackground(Message result)1155 hangupWaitingOrBackground (Message result) { 1156 RILRequest rr = RILRequest.obtain(RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND, 1157 result); 1158 1159 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1160 1161 mEventLog.writeRilHangup(rr.mSerial, RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND, -1); 1162 1163 send(rr); 1164 } 1165 1166 @Override 1167 public void hangupForegroundResumeBackground(Message result)1168 hangupForegroundResumeBackground (Message result) { 1169 RILRequest rr 1170 = RILRequest.obtain( 1171 RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND, 1172 result); 1173 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1174 1175 mEventLog.writeRilHangup(rr.mSerial, RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND, -1); 1176 1177 send(rr); 1178 } 1179 1180 @Override 1181 public void switchWaitingOrHoldingAndActive(Message result)1182 switchWaitingOrHoldingAndActive (Message result) { 1183 RILRequest rr 1184 = RILRequest.obtain( 1185 RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE, 1186 result); 1187 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1188 1189 send(rr); 1190 } 1191 1192 @Override 1193 public void conference(Message result)1194 conference (Message result) { 1195 RILRequest rr 1196 = RILRequest.obtain(RIL_REQUEST_CONFERENCE, result); 1197 1198 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1199 1200 send(rr); 1201 } 1202 1203 1204 @Override setPreferredVoicePrivacy(boolean enable, Message result)1205 public void setPreferredVoicePrivacy(boolean enable, Message result) { 1206 RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE, 1207 result); 1208 1209 rr.mParcel.writeInt(1); 1210 rr.mParcel.writeInt(enable ? 1:0); 1211 1212 send(rr); 1213 } 1214 1215 @Override getPreferredVoicePrivacy(Message result)1216 public void getPreferredVoicePrivacy(Message result) { 1217 RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE, 1218 result); 1219 send(rr); 1220 } 1221 1222 @Override 1223 public void separateConnection(int gsmIndex, Message result)1224 separateConnection (int gsmIndex, Message result) { 1225 RILRequest rr 1226 = RILRequest.obtain(RIL_REQUEST_SEPARATE_CONNECTION, result); 1227 1228 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 1229 + " " + gsmIndex); 1230 1231 rr.mParcel.writeInt(1); 1232 rr.mParcel.writeInt(gsmIndex); 1233 1234 send(rr); 1235 } 1236 1237 @Override 1238 public void acceptCall(Message result)1239 acceptCall (Message result) { 1240 RILRequest rr 1241 = RILRequest.obtain(RIL_REQUEST_ANSWER, result); 1242 1243 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1244 1245 mEventLog.writeRilAnswer(rr.mSerial); 1246 1247 send(rr); 1248 } 1249 1250 @Override 1251 public void rejectCall(Message result)1252 rejectCall (Message result) { 1253 RILRequest rr 1254 = RILRequest.obtain(RIL_REQUEST_UDUB, result); 1255 1256 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1257 1258 send(rr); 1259 } 1260 1261 @Override 1262 public void explicitCallTransfer(Message result)1263 explicitCallTransfer (Message result) { 1264 RILRequest rr 1265 = RILRequest.obtain(RIL_REQUEST_EXPLICIT_CALL_TRANSFER, result); 1266 1267 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1268 1269 send(rr); 1270 } 1271 1272 @Override 1273 public void getLastCallFailCause(Message result)1274 getLastCallFailCause (Message result) { 1275 RILRequest rr 1276 = RILRequest.obtain(RIL_REQUEST_LAST_CALL_FAIL_CAUSE, result); 1277 1278 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1279 1280 send(rr); 1281 } 1282 1283 /** 1284 * @deprecated 1285 */ 1286 @Deprecated 1287 @Override 1288 public void getLastPdpFailCause(Message result)1289 getLastPdpFailCause (Message result) { 1290 getLastDataCallFailCause (result); 1291 } 1292 1293 /** 1294 * The preferred new alternative to getLastPdpFailCause 1295 */ 1296 @Override 1297 public void getLastDataCallFailCause(Message result)1298 getLastDataCallFailCause (Message result) { 1299 RILRequest rr 1300 = RILRequest.obtain(RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE, result); 1301 1302 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1303 1304 send(rr); 1305 } 1306 1307 @Override 1308 public void setMute(boolean enableMute, Message response)1309 setMute (boolean enableMute, Message response) { 1310 RILRequest rr 1311 = RILRequest.obtain(RIL_REQUEST_SET_MUTE, response); 1312 1313 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 1314 + " " + enableMute); 1315 1316 rr.mParcel.writeInt(1); 1317 rr.mParcel.writeInt(enableMute ? 1 : 0); 1318 1319 send(rr); 1320 } 1321 1322 @Override 1323 public void getMute(Message response)1324 getMute (Message response) { 1325 RILRequest rr 1326 = RILRequest.obtain(RIL_REQUEST_GET_MUTE, response); 1327 1328 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1329 1330 send(rr); 1331 } 1332 1333 @Override 1334 public void getSignalStrength(Message result)1335 getSignalStrength (Message result) { 1336 RILRequest rr 1337 = RILRequest.obtain(RIL_REQUEST_SIGNAL_STRENGTH, result); 1338 1339 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1340 1341 send(rr); 1342 } 1343 1344 @Override 1345 public void getVoiceRegistrationState(Message result)1346 getVoiceRegistrationState (Message result) { 1347 RILRequest rr 1348 = RILRequest.obtain(RIL_REQUEST_VOICE_REGISTRATION_STATE, result); 1349 1350 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1351 1352 send(rr); 1353 } 1354 1355 @Override 1356 public void getDataRegistrationState(Message result)1357 getDataRegistrationState (Message result) { 1358 RILRequest rr 1359 = RILRequest.obtain(RIL_REQUEST_DATA_REGISTRATION_STATE, result); 1360 1361 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1362 1363 send(rr); 1364 } 1365 1366 @Override 1367 public void getOperator(Message result)1368 getOperator(Message result) { 1369 RILRequest rr 1370 = RILRequest.obtain(RIL_REQUEST_OPERATOR, result); 1371 1372 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1373 1374 send(rr); 1375 } 1376 1377 @Override 1378 public void getHardwareConfig(Message result)1379 getHardwareConfig (Message result) { 1380 RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_HARDWARE_CONFIG, result); 1381 1382 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1383 1384 send(rr); 1385 } 1386 1387 @Override 1388 public void sendDtmf(char c, Message result)1389 sendDtmf(char c, Message result) { 1390 RILRequest rr 1391 = RILRequest.obtain(RIL_REQUEST_DTMF, result); 1392 1393 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1394 1395 rr.mParcel.writeString(Character.toString(c)); 1396 1397 send(rr); 1398 } 1399 1400 @Override 1401 public void startDtmf(char c, Message result)1402 startDtmf(char c, Message result) { 1403 RILRequest rr 1404 = RILRequest.obtain(RIL_REQUEST_DTMF_START, result); 1405 1406 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1407 1408 rr.mParcel.writeString(Character.toString(c)); 1409 1410 send(rr); 1411 } 1412 1413 @Override 1414 public void stopDtmf(Message result)1415 stopDtmf(Message result) { 1416 RILRequest rr 1417 = RILRequest.obtain(RIL_REQUEST_DTMF_STOP, result); 1418 1419 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1420 1421 send(rr); 1422 } 1423 1424 @Override 1425 public void sendBurstDtmf(String dtmfString, int on, int off, Message result)1426 sendBurstDtmf(String dtmfString, int on, int off, Message result) { 1427 RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_BURST_DTMF, result); 1428 1429 rr.mParcel.writeInt(3); 1430 rr.mParcel.writeString(dtmfString); 1431 rr.mParcel.writeString(Integer.toString(on)); 1432 rr.mParcel.writeString(Integer.toString(off)); 1433 1434 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 1435 + " : " + dtmfString); 1436 1437 send(rr); 1438 } 1439 1440 private void constructGsmSendSmsRilRequest(RILRequest rr, String smscPDU, String pdu)1441 constructGsmSendSmsRilRequest (RILRequest rr, String smscPDU, String pdu) { 1442 rr.mParcel.writeInt(2); 1443 rr.mParcel.writeString(smscPDU); 1444 rr.mParcel.writeString(pdu); 1445 } 1446 1447 public void sendSMS(String smscPDU, String pdu, Message result)1448 sendSMS (String smscPDU, String pdu, Message result) { 1449 RILRequest rr 1450 = RILRequest.obtain(RIL_REQUEST_SEND_SMS, result); 1451 1452 constructGsmSendSmsRilRequest(rr, smscPDU, pdu); 1453 1454 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1455 1456 mEventLog.writeRilSendSms(rr.mSerial, rr.mRequest); 1457 1458 send(rr); 1459 } 1460 1461 @Override 1462 public void sendSMSExpectMore(String smscPDU, String pdu, Message result)1463 sendSMSExpectMore (String smscPDU, String pdu, Message result) { 1464 RILRequest rr 1465 = RILRequest.obtain(RIL_REQUEST_SEND_SMS_EXPECT_MORE, result); 1466 1467 constructGsmSendSmsRilRequest(rr, smscPDU, pdu); 1468 1469 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1470 1471 mEventLog.writeRilSendSms(rr.mSerial, rr.mRequest); 1472 1473 send(rr); 1474 } 1475 1476 private void constructCdmaSendSmsRilRequest(RILRequest rr, byte[] pdu)1477 constructCdmaSendSmsRilRequest(RILRequest rr, byte[] pdu) { 1478 int address_nbr_of_digits; 1479 int subaddr_nbr_of_digits; 1480 int bearerDataLength; 1481 ByteArrayInputStream bais = new ByteArrayInputStream(pdu); 1482 DataInputStream dis = new DataInputStream(bais); 1483 1484 try { 1485 rr.mParcel.writeInt(dis.readInt()); //teleServiceId 1486 rr.mParcel.writeByte((byte) dis.readInt()); //servicePresent 1487 rr.mParcel.writeInt(dis.readInt()); //serviceCategory 1488 rr.mParcel.writeInt(dis.read()); //address_digit_mode 1489 rr.mParcel.writeInt(dis.read()); //address_nbr_mode 1490 rr.mParcel.writeInt(dis.read()); //address_ton 1491 rr.mParcel.writeInt(dis.read()); //address_nbr_plan 1492 address_nbr_of_digits = (byte) dis.read(); 1493 rr.mParcel.writeByte((byte) address_nbr_of_digits); 1494 for(int i=0; i < address_nbr_of_digits; i++){ 1495 rr.mParcel.writeByte(dis.readByte()); // address_orig_bytes[i] 1496 } 1497 rr.mParcel.writeInt(dis.read()); //subaddressType 1498 rr.mParcel.writeByte((byte) dis.read()); //subaddr_odd 1499 subaddr_nbr_of_digits = (byte) dis.read(); 1500 rr.mParcel.writeByte((byte) subaddr_nbr_of_digits); 1501 for(int i=0; i < subaddr_nbr_of_digits; i++){ 1502 rr.mParcel.writeByte(dis.readByte()); //subaddr_orig_bytes[i] 1503 } 1504 1505 bearerDataLength = dis.read(); 1506 rr.mParcel.writeInt(bearerDataLength); 1507 for(int i=0; i < bearerDataLength; i++){ 1508 rr.mParcel.writeByte(dis.readByte()); //bearerData[i] 1509 } 1510 }catch (IOException ex){ 1511 if (RILJ_LOGD) riljLog("sendSmsCdma: conversion from input stream to object failed: " 1512 + ex); 1513 } 1514 } 1515 1516 public void sendCdmaSms(byte[] pdu, Message result)1517 sendCdmaSms(byte[] pdu, Message result) { 1518 RILRequest rr 1519 = RILRequest.obtain(RIL_REQUEST_CDMA_SEND_SMS, result); 1520 1521 constructCdmaSendSmsRilRequest(rr, pdu); 1522 1523 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1524 1525 mEventLog.writeRilSendSms(rr.mSerial, rr.mRequest); 1526 1527 send(rr); 1528 } 1529 1530 public void sendImsGsmSms(String smscPDU, String pdu, int retry, int messageRef, Message result)1531 sendImsGsmSms (String smscPDU, String pdu, int retry, int messageRef, 1532 Message result) { 1533 RILRequest rr = RILRequest.obtain(RIL_REQUEST_IMS_SEND_SMS, result); 1534 1535 rr.mParcel.writeInt(RILConstants.GSM_PHONE); 1536 rr.mParcel.writeByte((byte)retry); 1537 rr.mParcel.writeInt(messageRef); 1538 1539 constructGsmSendSmsRilRequest(rr, smscPDU, pdu); 1540 1541 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1542 1543 mEventLog.writeRilSendSms(rr.mSerial, rr.mRequest); 1544 1545 send(rr); 1546 } 1547 1548 public void sendImsCdmaSms(byte[] pdu, int retry, int messageRef, Message result)1549 sendImsCdmaSms(byte[] pdu, int retry, int messageRef, Message result) { 1550 RILRequest rr = RILRequest.obtain(RIL_REQUEST_IMS_SEND_SMS, result); 1551 1552 rr.mParcel.writeInt(RILConstants.CDMA_PHONE); 1553 rr.mParcel.writeByte((byte)retry); 1554 rr.mParcel.writeInt(messageRef); 1555 1556 constructCdmaSendSmsRilRequest(rr, pdu); 1557 1558 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1559 1560 mEventLog.writeRilSendSms(rr.mSerial, rr.mRequest); 1561 1562 send(rr); 1563 } 1564 1565 @Override deleteSmsOnSim(int index, Message response)1566 public void deleteSmsOnSim(int index, Message response) { 1567 RILRequest rr = RILRequest.obtain(RIL_REQUEST_DELETE_SMS_ON_SIM, 1568 response); 1569 1570 rr.mParcel.writeInt(1); 1571 rr.mParcel.writeInt(index); 1572 1573 if (RILJ_LOGV) riljLog(rr.serialString() + "> " 1574 + requestToString(rr.mRequest) 1575 + " " + index); 1576 1577 send(rr); 1578 } 1579 1580 @Override deleteSmsOnRuim(int index, Message response)1581 public void deleteSmsOnRuim(int index, Message response) { 1582 RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM, 1583 response); 1584 1585 rr.mParcel.writeInt(1); 1586 rr.mParcel.writeInt(index); 1587 1588 if (RILJ_LOGV) riljLog(rr.serialString() + "> " 1589 + requestToString(rr.mRequest) 1590 + " " + index); 1591 1592 send(rr); 1593 } 1594 1595 @Override writeSmsToSim(int status, String smsc, String pdu, Message response)1596 public void writeSmsToSim(int status, String smsc, String pdu, Message response) { 1597 status = translateStatus(status); 1598 1599 RILRequest rr = RILRequest.obtain(RIL_REQUEST_WRITE_SMS_TO_SIM, 1600 response); 1601 1602 rr.mParcel.writeInt(status); 1603 rr.mParcel.writeString(pdu); 1604 rr.mParcel.writeString(smsc); 1605 1606 if (RILJ_LOGV) riljLog(rr.serialString() + "> " 1607 + requestToString(rr.mRequest) 1608 + " " + status); 1609 1610 send(rr); 1611 } 1612 1613 @Override writeSmsToRuim(int status, String pdu, Message response)1614 public void writeSmsToRuim(int status, String pdu, Message response) { 1615 status = translateStatus(status); 1616 1617 RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM, 1618 response); 1619 1620 rr.mParcel.writeInt(status); 1621 rr.mParcel.writeString(pdu); 1622 1623 if (RILJ_LOGV) riljLog(rr.serialString() + "> " 1624 + requestToString(rr.mRequest) 1625 + " " + status); 1626 1627 send(rr); 1628 } 1629 1630 /** 1631 * Translates EF_SMS status bits to a status value compatible with 1632 * SMS AT commands. See TS 27.005 3.1. 1633 */ translateStatus(int status)1634 private int translateStatus(int status) { 1635 switch(status & 0x7) { 1636 case SmsManager.STATUS_ON_ICC_READ: 1637 return 1; 1638 case SmsManager.STATUS_ON_ICC_UNREAD: 1639 return 0; 1640 case SmsManager.STATUS_ON_ICC_SENT: 1641 return 3; 1642 case SmsManager.STATUS_ON_ICC_UNSENT: 1643 return 2; 1644 } 1645 1646 // Default to READ. 1647 return 1; 1648 } 1649 1650 @Override 1651 public void setupDataCall(int radioTechnology, int profile, String apn, String user, String password, int authType, String protocol, Message result)1652 setupDataCall(int radioTechnology, int profile, String apn, 1653 String user, String password, int authType, String protocol, 1654 Message result) { 1655 RILRequest rr 1656 = RILRequest.obtain(RIL_REQUEST_SETUP_DATA_CALL, result); 1657 1658 rr.mParcel.writeInt(7); 1659 1660 rr.mParcel.writeString(Integer.toString(radioTechnology + 2)); 1661 rr.mParcel.writeString(Integer.toString(profile)); 1662 rr.mParcel.writeString(apn); 1663 rr.mParcel.writeString(user); 1664 rr.mParcel.writeString(password); 1665 rr.mParcel.writeString(Integer.toString(authType)); 1666 rr.mParcel.writeString(protocol); 1667 1668 if (RILJ_LOGD) riljLog(rr.serialString() + "> " 1669 + requestToString(rr.mRequest) + " " + radioTechnology + " " 1670 + profile + " " + apn + " " + user + " " 1671 + password + " " + authType + " " + protocol); 1672 1673 mEventLog.writeRilSetupDataCall(rr.mSerial, radioTechnology, profile, apn, 1674 user, password, authType, protocol); 1675 1676 send(rr); 1677 } 1678 1679 @Override 1680 public void deactivateDataCall(int cid, int reason, Message result)1681 deactivateDataCall(int cid, int reason, Message result) { 1682 RILRequest rr 1683 = RILRequest.obtain(RIL_REQUEST_DEACTIVATE_DATA_CALL, result); 1684 1685 rr.mParcel.writeInt(2); 1686 rr.mParcel.writeString(Integer.toString(cid)); 1687 rr.mParcel.writeString(Integer.toString(reason)); 1688 1689 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + 1690 requestToString(rr.mRequest) + " " + cid + " " + reason); 1691 1692 mEventLog.writeRilDeactivateDataCall(rr.mSerial, cid, reason); 1693 1694 send(rr); 1695 } 1696 1697 @Override 1698 public void setRadioPower(boolean on, Message result)1699 setRadioPower(boolean on, Message result) { 1700 RILRequest rr = RILRequest.obtain(RIL_REQUEST_RADIO_POWER, result); 1701 1702 rr.mParcel.writeInt(1); 1703 rr.mParcel.writeInt(on ? 1 : 0); 1704 1705 if (RILJ_LOGD) { 1706 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 1707 + (on ? " on" : " off")); 1708 } 1709 1710 send(rr); 1711 } 1712 1713 @Override requestShutdown(Message result)1714 public void requestShutdown(Message result) { 1715 RILRequest rr = RILRequest.obtain(RIL_REQUEST_SHUTDOWN, result); 1716 1717 if (RILJ_LOGD) 1718 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1719 1720 send(rr); 1721 } 1722 1723 @Override 1724 public void setSuppServiceNotifications(boolean enable, Message result)1725 setSuppServiceNotifications(boolean enable, Message result) { 1726 RILRequest rr 1727 = RILRequest.obtain(RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION, result); 1728 1729 rr.mParcel.writeInt(1); 1730 rr.mParcel.writeInt(enable ? 1 : 0); 1731 1732 if (RILJ_LOGD) riljLog(rr.serialString() + "> " 1733 + requestToString(rr.mRequest)); 1734 1735 send(rr); 1736 } 1737 1738 @Override 1739 public void acknowledgeLastIncomingGsmSms(boolean success, int cause, Message result)1740 acknowledgeLastIncomingGsmSms(boolean success, int cause, Message result) { 1741 RILRequest rr 1742 = RILRequest.obtain(RIL_REQUEST_SMS_ACKNOWLEDGE, result); 1743 1744 rr.mParcel.writeInt(2); 1745 rr.mParcel.writeInt(success ? 1 : 0); 1746 rr.mParcel.writeInt(cause); 1747 1748 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 1749 + " " + success + " " + cause); 1750 1751 send(rr); 1752 } 1753 1754 @Override 1755 public void acknowledgeLastIncomingCdmaSms(boolean success, int cause, Message result)1756 acknowledgeLastIncomingCdmaSms(boolean success, int cause, Message result) { 1757 RILRequest rr 1758 = RILRequest.obtain(RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE, result); 1759 1760 rr.mParcel.writeInt(success ? 0 : 1); //RIL_CDMA_SMS_ErrorClass 1761 // cause code according to X.S004-550E 1762 rr.mParcel.writeInt(cause); 1763 1764 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 1765 + " " + success + " " + cause); 1766 1767 send(rr); 1768 } 1769 1770 @Override 1771 public void acknowledgeIncomingGsmSmsWithPdu(boolean success, String ackPdu, Message result)1772 acknowledgeIncomingGsmSmsWithPdu(boolean success, String ackPdu, Message result) { 1773 RILRequest rr 1774 = RILRequest.obtain(RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU, result); 1775 1776 rr.mParcel.writeInt(2); 1777 rr.mParcel.writeString(success ? "1" : "0"); 1778 rr.mParcel.writeString(ackPdu); 1779 1780 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 1781 + ' ' + success + " [" + ackPdu + ']'); 1782 1783 send(rr); 1784 } 1785 1786 @Override 1787 public void iccIO(int command, int fileid, String path, int p1, int p2, int p3, String data, String pin2, Message result)1788 iccIO (int command, int fileid, String path, int p1, int p2, int p3, 1789 String data, String pin2, Message result) { 1790 iccIOForApp(command, fileid, path, p1, p2, p3, data, pin2, null, result); 1791 } 1792 @Override 1793 public void iccIOForApp(int command, int fileid, String path, int p1, int p2, int p3, String data, String pin2, String aid, Message result)1794 iccIOForApp (int command, int fileid, String path, int p1, int p2, int p3, 1795 String data, String pin2, String aid, Message result) { 1796 //Note: This RIL request has not been renamed to ICC, 1797 // but this request is also valid for SIM and RUIM 1798 RILRequest rr 1799 = RILRequest.obtain(RIL_REQUEST_SIM_IO, result); 1800 1801 rr.mParcel.writeInt(command); 1802 rr.mParcel.writeInt(fileid); 1803 rr.mParcel.writeString(path); 1804 rr.mParcel.writeInt(p1); 1805 rr.mParcel.writeInt(p2); 1806 rr.mParcel.writeInt(p3); 1807 rr.mParcel.writeString(data); 1808 rr.mParcel.writeString(pin2); 1809 rr.mParcel.writeString(aid); 1810 1811 if (RILJ_LOGD) riljLog(rr.serialString() + "> iccIO: " 1812 + requestToString(rr.mRequest) 1813 + " 0x" + Integer.toHexString(command) 1814 + " 0x" + Integer.toHexString(fileid) + " " 1815 + " path: " + path + "," 1816 + p1 + "," + p2 + "," + p3 1817 + " aid: " + aid); 1818 1819 send(rr); 1820 } 1821 1822 @Override 1823 public void getCLIR(Message result)1824 getCLIR(Message result) { 1825 RILRequest rr 1826 = RILRequest.obtain(RIL_REQUEST_GET_CLIR, result); 1827 1828 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1829 1830 send(rr); 1831 } 1832 1833 @Override 1834 public void setCLIR(int clirMode, Message result)1835 setCLIR(int clirMode, Message result) { 1836 RILRequest rr 1837 = RILRequest.obtain(RIL_REQUEST_SET_CLIR, result); 1838 1839 // count ints 1840 rr.mParcel.writeInt(1); 1841 1842 rr.mParcel.writeInt(clirMode); 1843 1844 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 1845 + " " + clirMode); 1846 1847 send(rr); 1848 } 1849 1850 @Override 1851 public void queryCallWaiting(int serviceClass, Message response)1852 queryCallWaiting(int serviceClass, Message response) { 1853 RILRequest rr 1854 = RILRequest.obtain(RIL_REQUEST_QUERY_CALL_WAITING, response); 1855 1856 rr.mParcel.writeInt(1); 1857 rr.mParcel.writeInt(serviceClass); 1858 1859 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 1860 + " " + serviceClass); 1861 1862 send(rr); 1863 } 1864 1865 @Override 1866 public void setCallWaiting(boolean enable, int serviceClass, Message response)1867 setCallWaiting(boolean enable, int serviceClass, Message response) { 1868 RILRequest rr 1869 = RILRequest.obtain(RIL_REQUEST_SET_CALL_WAITING, response); 1870 1871 rr.mParcel.writeInt(2); 1872 rr.mParcel.writeInt(enable ? 1 : 0); 1873 rr.mParcel.writeInt(serviceClass); 1874 1875 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 1876 + " " + enable + ", " + serviceClass); 1877 1878 send(rr); 1879 } 1880 1881 @Override 1882 public void setNetworkSelectionModeAutomatic(Message response)1883 setNetworkSelectionModeAutomatic(Message response) { 1884 RILRequest rr 1885 = RILRequest.obtain(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, 1886 response); 1887 1888 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1889 1890 send(rr); 1891 } 1892 1893 @Override 1894 public void setNetworkSelectionModeManual(String operatorNumeric, Message response)1895 setNetworkSelectionModeManual(String operatorNumeric, Message response) { 1896 RILRequest rr 1897 = RILRequest.obtain(RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL, 1898 response); 1899 1900 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 1901 + " " + operatorNumeric); 1902 1903 rr.mParcel.writeString(operatorNumeric); 1904 1905 send(rr); 1906 } 1907 1908 @Override 1909 public void getNetworkSelectionMode(Message response)1910 getNetworkSelectionMode(Message response) { 1911 RILRequest rr 1912 = RILRequest.obtain(RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE, 1913 response); 1914 1915 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1916 1917 send(rr); 1918 } 1919 1920 @Override 1921 public void getAvailableNetworks(Message response)1922 getAvailableNetworks(Message response) { 1923 RILRequest rr 1924 = RILRequest.obtain(RIL_REQUEST_QUERY_AVAILABLE_NETWORKS, 1925 response); 1926 1927 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1928 1929 send(rr); 1930 } 1931 1932 @Override 1933 public void setCallForward(int action, int cfReason, int serviceClass, String number, int timeSeconds, Message response)1934 setCallForward(int action, int cfReason, int serviceClass, 1935 String number, int timeSeconds, Message response) { 1936 RILRequest rr 1937 = RILRequest.obtain(RIL_REQUEST_SET_CALL_FORWARD, response); 1938 1939 rr.mParcel.writeInt(action); 1940 rr.mParcel.writeInt(cfReason); 1941 rr.mParcel.writeInt(serviceClass); 1942 rr.mParcel.writeInt(PhoneNumberUtils.toaFromString(number)); 1943 rr.mParcel.writeString(number); 1944 rr.mParcel.writeInt (timeSeconds); 1945 1946 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 1947 + " " + action + " " + cfReason + " " + serviceClass 1948 + timeSeconds); 1949 1950 send(rr); 1951 } 1952 1953 @Override 1954 public void queryCallForwardStatus(int cfReason, int serviceClass, String number, Message response)1955 queryCallForwardStatus(int cfReason, int serviceClass, 1956 String number, Message response) { 1957 RILRequest rr 1958 = RILRequest.obtain(RIL_REQUEST_QUERY_CALL_FORWARD_STATUS, response); 1959 1960 rr.mParcel.writeInt(2); // 2 is for query action, not in used anyway 1961 rr.mParcel.writeInt(cfReason); 1962 rr.mParcel.writeInt(serviceClass); 1963 rr.mParcel.writeInt(PhoneNumberUtils.toaFromString(number)); 1964 rr.mParcel.writeString(number); 1965 rr.mParcel.writeInt (0); 1966 1967 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 1968 + " " + cfReason + " " + serviceClass); 1969 1970 send(rr); 1971 } 1972 1973 @Override 1974 public void queryCLIP(Message response)1975 queryCLIP(Message response) { 1976 RILRequest rr 1977 = RILRequest.obtain(RIL_REQUEST_QUERY_CLIP, response); 1978 1979 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1980 1981 send(rr); 1982 } 1983 1984 1985 @Override 1986 public void getBasebandVersion(Message response)1987 getBasebandVersion (Message response) { 1988 RILRequest rr 1989 = RILRequest.obtain(RIL_REQUEST_BASEBAND_VERSION, response); 1990 1991 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 1992 1993 send(rr); 1994 } 1995 1996 @Override 1997 public void queryFacilityLock(String facility, String password, int serviceClass, Message response)1998 queryFacilityLock(String facility, String password, int serviceClass, 1999 Message response) { 2000 queryFacilityLockForApp(facility, password, serviceClass, null, response); 2001 } 2002 2003 @Override 2004 public void queryFacilityLockForApp(String facility, String password, int serviceClass, String appId, Message response)2005 queryFacilityLockForApp(String facility, String password, int serviceClass, String appId, 2006 Message response) { 2007 RILRequest rr = RILRequest.obtain(RIL_REQUEST_QUERY_FACILITY_LOCK, response); 2008 2009 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 2010 + " [" + facility + " " + serviceClass 2011 + " " + appId + "]"); 2012 2013 // count strings 2014 rr.mParcel.writeInt(4); 2015 2016 rr.mParcel.writeString(facility); 2017 rr.mParcel.writeString(password); 2018 2019 rr.mParcel.writeString(Integer.toString(serviceClass)); 2020 rr.mParcel.writeString(appId); 2021 2022 send(rr); 2023 } 2024 2025 @Override 2026 public void setFacilityLock(String facility, boolean lockState, String password, int serviceClass, Message response)2027 setFacilityLock (String facility, boolean lockState, String password, 2028 int serviceClass, Message response) { 2029 setFacilityLockForApp(facility, lockState, password, serviceClass, null, response); 2030 } 2031 2032 @Override 2033 public void setFacilityLockForApp(String facility, boolean lockState, String password, int serviceClass, String appId, Message response)2034 setFacilityLockForApp(String facility, boolean lockState, String password, 2035 int serviceClass, String appId, Message response) { 2036 String lockString; 2037 RILRequest rr 2038 = RILRequest.obtain(RIL_REQUEST_SET_FACILITY_LOCK, response); 2039 2040 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 2041 + " [" + facility + " " + lockState 2042 + " " + serviceClass + " " + appId + "]"); 2043 2044 // count strings 2045 rr.mParcel.writeInt(5); 2046 2047 rr.mParcel.writeString(facility); 2048 lockString = (lockState)?"1":"0"; 2049 rr.mParcel.writeString(lockString); 2050 rr.mParcel.writeString(password); 2051 rr.mParcel.writeString(Integer.toString(serviceClass)); 2052 rr.mParcel.writeString(appId); 2053 2054 send(rr); 2055 2056 } 2057 2058 @Override 2059 public void sendUSSD(String ussdString, Message response)2060 sendUSSD (String ussdString, Message response) { 2061 RILRequest rr 2062 = RILRequest.obtain(RIL_REQUEST_SEND_USSD, response); 2063 2064 if (RILJ_LOGD) { 2065 String logUssdString = "*******"; 2066 if (RILJ_LOGV) logUssdString = ussdString; 2067 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 2068 + " " + logUssdString); 2069 } 2070 2071 rr.mParcel.writeString(ussdString); 2072 2073 send(rr); 2074 } 2075 2076 // inherited javadoc suffices 2077 @Override cancelPendingUssd(Message response)2078 public void cancelPendingUssd (Message response) { 2079 RILRequest rr 2080 = RILRequest.obtain(RIL_REQUEST_CANCEL_USSD, response); 2081 2082 if (RILJ_LOGD) riljLog(rr.serialString() 2083 + "> " + requestToString(rr.mRequest)); 2084 2085 send(rr); 2086 } 2087 2088 2089 @Override resetRadio(Message result)2090 public void resetRadio(Message result) { 2091 RILRequest rr 2092 = RILRequest.obtain(RIL_REQUEST_RESET_RADIO, result); 2093 2094 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 2095 2096 send(rr); 2097 } 2098 2099 @Override invokeOemRilRequestRaw(byte[] data, Message response)2100 public void invokeOemRilRequestRaw(byte[] data, Message response) { 2101 RILRequest rr 2102 = RILRequest.obtain(RIL_REQUEST_OEM_HOOK_RAW, response); 2103 2104 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 2105 + "[" + IccUtils.bytesToHexString(data) + "]"); 2106 2107 rr.mParcel.writeByteArray(data); 2108 2109 send(rr); 2110 2111 } 2112 2113 @Override invokeOemRilRequestStrings(String[] strings, Message response)2114 public void invokeOemRilRequestStrings(String[] strings, Message response) { 2115 RILRequest rr 2116 = RILRequest.obtain(RIL_REQUEST_OEM_HOOK_STRINGS, response); 2117 2118 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 2119 2120 rr.mParcel.writeStringArray(strings); 2121 2122 send(rr); 2123 } 2124 2125 /** 2126 * Assign a specified band for RF configuration. 2127 * 2128 * @param bandMode one of BM_*_BAND 2129 * @param response is callback message 2130 */ 2131 @Override setBandMode(int bandMode, Message response)2132 public void setBandMode (int bandMode, Message response) { 2133 RILRequest rr 2134 = RILRequest.obtain(RIL_REQUEST_SET_BAND_MODE, response); 2135 2136 rr.mParcel.writeInt(1); 2137 rr.mParcel.writeInt(bandMode); 2138 2139 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 2140 + " " + bandMode); 2141 2142 send(rr); 2143 } 2144 2145 /** 2146 * Query the list of band mode supported by RF. 2147 * 2148 * @param response is callback message 2149 * ((AsyncResult)response.obj).result is an int[] where int[0] is 2150 * the size of the array and the rest of each element representing 2151 * one available BM_*_BAND 2152 */ 2153 @Override queryAvailableBandMode(Message response)2154 public void queryAvailableBandMode (Message response) { 2155 RILRequest rr 2156 = RILRequest.obtain(RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE, 2157 response); 2158 2159 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 2160 2161 send(rr); 2162 } 2163 2164 /** 2165 * {@inheritDoc} 2166 */ 2167 @Override sendTerminalResponse(String contents, Message response)2168 public void sendTerminalResponse(String contents, Message response) { 2169 RILRequest rr = RILRequest.obtain( 2170 RILConstants.RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE, response); 2171 2172 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 2173 2174 rr.mParcel.writeString(contents); 2175 send(rr); 2176 } 2177 2178 /** 2179 * {@inheritDoc} 2180 */ 2181 @Override sendEnvelope(String contents, Message response)2182 public void sendEnvelope(String contents, Message response) { 2183 RILRequest rr = RILRequest.obtain( 2184 RILConstants.RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND, response); 2185 2186 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 2187 2188 rr.mParcel.writeString(contents); 2189 send(rr); 2190 } 2191 2192 /** 2193 * {@inheritDoc} 2194 */ 2195 @Override sendEnvelopeWithStatus(String contents, Message response)2196 public void sendEnvelopeWithStatus(String contents, Message response) { 2197 RILRequest rr = RILRequest.obtain( 2198 RILConstants.RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS, response); 2199 2200 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 2201 + '[' + contents + ']'); 2202 2203 rr.mParcel.writeString(contents); 2204 send(rr); 2205 } 2206 2207 /** 2208 * {@inheritDoc} 2209 */ 2210 @Override handleCallSetupRequestFromSim( boolean accept, Message response)2211 public void handleCallSetupRequestFromSim( 2212 boolean accept, Message response) { 2213 2214 RILRequest rr = RILRequest.obtain( 2215 RILConstants.RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM, 2216 response); 2217 2218 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 2219 2220 int[] param = new int[1]; 2221 param[0] = accept ? 1 : 0; 2222 rr.mParcel.writeIntArray(param); 2223 send(rr); 2224 } 2225 2226 /** 2227 * {@inheritDoc} 2228 */ 2229 @Override setPreferredNetworkType(int networkType , Message response)2230 public void setPreferredNetworkType(int networkType , Message response) { 2231 RILRequest rr = RILRequest.obtain( 2232 RILConstants.RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE, response); 2233 2234 rr.mParcel.writeInt(1); 2235 rr.mParcel.writeInt(networkType); 2236 2237 mPreferredNetworkType = networkType; 2238 2239 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 2240 + " : " + networkType); 2241 2242 mEventLog.writeSetPreferredNetworkType(networkType); 2243 2244 send(rr); 2245 } 2246 2247 /** 2248 * {@inheritDoc} 2249 */ 2250 @Override getPreferredNetworkType(Message response)2251 public void getPreferredNetworkType(Message response) { 2252 RILRequest rr = RILRequest.obtain( 2253 RILConstants.RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE, response); 2254 2255 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 2256 2257 send(rr); 2258 } 2259 2260 /** 2261 * {@inheritDoc} 2262 */ 2263 @Override getNeighboringCids(Message response)2264 public void getNeighboringCids(Message response) { 2265 RILRequest rr = RILRequest.obtain( 2266 RILConstants.RIL_REQUEST_GET_NEIGHBORING_CELL_IDS, response); 2267 2268 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 2269 2270 send(rr); 2271 } 2272 2273 /** 2274 * {@inheritDoc} 2275 */ 2276 @Override setLocationUpdates(boolean enable, Message response)2277 public void setLocationUpdates(boolean enable, Message response) { 2278 RILRequest rr = RILRequest.obtain(RIL_REQUEST_SET_LOCATION_UPDATES, response); 2279 rr.mParcel.writeInt(1); 2280 rr.mParcel.writeInt(enable ? 1 : 0); 2281 2282 if (RILJ_LOGD) riljLog(rr.serialString() + "> " 2283 + requestToString(rr.mRequest) + ": " + enable); 2284 2285 send(rr); 2286 } 2287 2288 /** 2289 * {@inheritDoc} 2290 */ 2291 @Override getSmscAddress(Message result)2292 public void getSmscAddress(Message result) { 2293 RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_SMSC_ADDRESS, result); 2294 2295 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 2296 2297 send(rr); 2298 } 2299 2300 /** 2301 * {@inheritDoc} 2302 */ 2303 @Override setSmscAddress(String address, Message result)2304 public void setSmscAddress(String address, Message result) { 2305 RILRequest rr = RILRequest.obtain(RIL_REQUEST_SET_SMSC_ADDRESS, result); 2306 2307 rr.mParcel.writeString(address); 2308 2309 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 2310 + " : " + address); 2311 2312 send(rr); 2313 } 2314 2315 /** 2316 * {@inheritDoc} 2317 */ 2318 @Override reportSmsMemoryStatus(boolean available, Message result)2319 public void reportSmsMemoryStatus(boolean available, Message result) { 2320 RILRequest rr = RILRequest.obtain(RIL_REQUEST_REPORT_SMS_MEMORY_STATUS, result); 2321 rr.mParcel.writeInt(1); 2322 rr.mParcel.writeInt(available ? 1 : 0); 2323 2324 if (RILJ_LOGD) riljLog(rr.serialString() + "> " 2325 + requestToString(rr.mRequest) + ": " + available); 2326 2327 send(rr); 2328 } 2329 2330 /** 2331 * {@inheritDoc} 2332 */ 2333 @Override reportStkServiceIsRunning(Message result)2334 public void reportStkServiceIsRunning(Message result) { 2335 RILRequest rr = RILRequest.obtain(RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING, result); 2336 2337 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 2338 2339 send(rr); 2340 } 2341 2342 /** 2343 * {@inheritDoc} 2344 */ 2345 @Override getGsmBroadcastConfig(Message response)2346 public void getGsmBroadcastConfig(Message response) { 2347 RILRequest rr = RILRequest.obtain(RIL_REQUEST_GSM_GET_BROADCAST_CONFIG, response); 2348 2349 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 2350 2351 send(rr); 2352 } 2353 2354 /** 2355 * {@inheritDoc} 2356 */ 2357 @Override setGsmBroadcastConfig(SmsBroadcastConfigInfo[] config, Message response)2358 public void setGsmBroadcastConfig(SmsBroadcastConfigInfo[] config, Message response) { 2359 RILRequest rr = RILRequest.obtain(RIL_REQUEST_GSM_SET_BROADCAST_CONFIG, response); 2360 2361 int numOfConfig = config.length; 2362 rr.mParcel.writeInt(numOfConfig); 2363 2364 for(int i = 0; i < numOfConfig; i++) { 2365 rr.mParcel.writeInt(config[i].getFromServiceId()); 2366 rr.mParcel.writeInt(config[i].getToServiceId()); 2367 rr.mParcel.writeInt(config[i].getFromCodeScheme()); 2368 rr.mParcel.writeInt(config[i].getToCodeScheme()); 2369 rr.mParcel.writeInt(config[i].isSelected() ? 1 : 0); 2370 } 2371 2372 if (RILJ_LOGD) { 2373 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 2374 + " with " + numOfConfig + " configs : "); 2375 for (int i = 0; i < numOfConfig; i++) { 2376 riljLog(config[i].toString()); 2377 } 2378 } 2379 2380 send(rr); 2381 } 2382 2383 /** 2384 * {@inheritDoc} 2385 */ 2386 @Override setGsmBroadcastActivation(boolean activate, Message response)2387 public void setGsmBroadcastActivation(boolean activate, Message response) { 2388 RILRequest rr = RILRequest.obtain(RIL_REQUEST_GSM_BROADCAST_ACTIVATION, response); 2389 2390 rr.mParcel.writeInt(1); 2391 rr.mParcel.writeInt(activate ? 0 : 1); 2392 2393 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 2394 2395 send(rr); 2396 } 2397 2398 //***** Private Methods 2399 2400 // TODO(jeffbrown): Delete me. 2401 // The RIL should *not* be listening for screen state changes since they are 2402 // becoming increasingly ambiguous on our devices. The RIL_REQUEST_SCREEN_STATE 2403 // message should be deleted and replaced with more precise messages to control 2404 // behavior such as signal strength reporting or power managements based on 2405 // more robust signals. 2406 /** 2407 * Update the screen state. Send screen state ON if the default display is ON or the device 2408 * is plugged. 2409 */ updateScreenState()2410 private void updateScreenState() { 2411 final int oldState = mRadioScreenState; 2412 mRadioScreenState = (mDefaultDisplayState == Display.STATE_ON || mIsDevicePlugged) 2413 ? RADIO_SCREEN_ON : RADIO_SCREEN_OFF; 2414 if (mRadioScreenState != oldState) { 2415 if (RILJ_LOGV) { 2416 riljLog("defaultDisplayState: " + mDefaultDisplayState 2417 + ", isDevicePlugged: " + mIsDevicePlugged); 2418 } 2419 sendScreenState(mRadioScreenState == RADIO_SCREEN_ON); 2420 } 2421 } 2422 sendScreenState(boolean on)2423 private void sendScreenState(boolean on) { 2424 RILRequest rr = RILRequest.obtain(RIL_REQUEST_SCREEN_STATE, null); 2425 rr.mParcel.writeInt(1); 2426 rr.mParcel.writeInt(on ? 1 : 0); 2427 2428 if (RILJ_LOGD) riljLog(rr.serialString() 2429 + "> " + requestToString(rr.mRequest) + ": " + on); 2430 2431 send(rr); 2432 } 2433 2434 @Override 2435 protected void onRadioAvailable()2436 onRadioAvailable() { 2437 // In case screen state was lost (due to process crash), 2438 // this ensures that the RIL knows the correct screen state. 2439 updateScreenState(); 2440 } 2441 getRadioStateFromInt(int stateInt)2442 private RadioState getRadioStateFromInt(int stateInt) { 2443 RadioState state; 2444 2445 /* RIL_RadioState ril.h */ 2446 switch(stateInt) { 2447 case 0: state = RadioState.RADIO_OFF; break; 2448 case 1: state = RadioState.RADIO_UNAVAILABLE; break; 2449 case 10: state = RadioState.RADIO_ON; break; 2450 2451 default: 2452 throw new RuntimeException( 2453 "Unrecognized RIL_RadioState: " + stateInt); 2454 } 2455 return state; 2456 } 2457 switchToRadioState(RadioState newState)2458 private void switchToRadioState(RadioState newState) { 2459 setRadioState(newState); 2460 } 2461 2462 /** 2463 * Holds a PARTIAL_WAKE_LOCK whenever 2464 * a) There is outstanding RIL request sent to RIL deamon and no replied 2465 * b) There is a request pending to be sent out. 2466 * 2467 * There is a WAKE_LOCK_TIMEOUT to release the lock, though it shouldn't 2468 * happen often. 2469 */ 2470 2471 private void acquireWakeLock(RILRequest rr, int wakeLockType)2472 acquireWakeLock(RILRequest rr, int wakeLockType) { 2473 synchronized(rr) { 2474 if(rr.mWakeLockType != INVALID_WAKELOCK) { 2475 Rlog.d(RILJ_LOG_TAG, "Failed to aquire wakelock for " + rr.serialString()); 2476 return; 2477 } 2478 2479 switch(wakeLockType) { 2480 case FOR_WAKELOCK: 2481 synchronized (mWakeLock) { 2482 mWakeLock.acquire(); 2483 mWakeLockCount++; 2484 mWlSequenceNum++; 2485 2486 Message msg = mSender.obtainMessage(EVENT_WAKE_LOCK_TIMEOUT); 2487 msg.arg1 = mWlSequenceNum; 2488 mSender.sendMessageDelayed(msg, mWakeLockTimeout); 2489 } 2490 break; 2491 case FOR_ACK_WAKELOCK: 2492 synchronized (mAckWakeLock) { 2493 mAckWakeLock.acquire(); 2494 mAckWlSequenceNum++; 2495 2496 Message msg = mSender.obtainMessage(EVENT_ACK_WAKE_LOCK_TIMEOUT); 2497 msg.arg1 = mAckWlSequenceNum; 2498 mSender.sendMessageDelayed(msg, mAckWakeLockTimeout); 2499 } 2500 break; 2501 default: //WTF 2502 Rlog.w(RILJ_LOG_TAG, "Acquiring Invalid Wakelock type " + wakeLockType); 2503 return; 2504 } 2505 rr.mWakeLockType = wakeLockType; 2506 } 2507 } 2508 2509 private void decrementWakeLock(RILRequest rr)2510 decrementWakeLock(RILRequest rr) { 2511 synchronized(rr) { 2512 switch(rr.mWakeLockType) { 2513 case FOR_WAKELOCK: 2514 synchronized (mWakeLock) { 2515 if (mWakeLockCount > 1) { 2516 mWakeLockCount--; 2517 } else { 2518 mWakeLockCount = 0; 2519 mWakeLock.release(); 2520 } 2521 } 2522 break; 2523 case FOR_ACK_WAKELOCK: 2524 //We do not decrement the ACK wakelock 2525 break; 2526 case INVALID_WAKELOCK: 2527 break; 2528 default: 2529 Rlog.w(RILJ_LOG_TAG, "Decrementing Invalid Wakelock type " + rr.mWakeLockType); 2530 } 2531 rr.mWakeLockType = INVALID_WAKELOCK; 2532 } 2533 } 2534 2535 private boolean clearWakeLock(int wakeLockType)2536 clearWakeLock(int wakeLockType) { 2537 if (wakeLockType == FOR_WAKELOCK) { 2538 synchronized (mWakeLock) { 2539 if (mWakeLockCount == 0 && mWakeLock.isHeld() == false) return false; 2540 Rlog.d(RILJ_LOG_TAG, "NOTE: mWakeLockCount is " + mWakeLockCount 2541 + "at time of clearing"); 2542 mWakeLockCount = 0; 2543 mWakeLock.release(); 2544 return true; 2545 } 2546 } else { 2547 synchronized (mAckWakeLock) { 2548 if (mAckWakeLock.isHeld() == false) return false; 2549 mAckWakeLock.release(); 2550 return true; 2551 } 2552 } 2553 } 2554 2555 private void send(RILRequest rr)2556 send(RILRequest rr) { 2557 Message msg; 2558 2559 if (mSocket == null) { 2560 rr.onError(RADIO_NOT_AVAILABLE, null); 2561 rr.release(); 2562 return; 2563 } 2564 2565 msg = mSender.obtainMessage(EVENT_SEND, rr); 2566 acquireWakeLock(rr, FOR_WAKELOCK); 2567 msg.sendToTarget(); 2568 } 2569 2570 private void processResponse(Parcel p)2571 processResponse (Parcel p) { 2572 int type; 2573 2574 type = p.readInt(); 2575 2576 if (type == RESPONSE_UNSOLICITED || type == RESPONSE_UNSOLICITED_ACK_EXP) { 2577 processUnsolicited (p, type); 2578 } else if (type == RESPONSE_SOLICITED || type == RESPONSE_SOLICITED_ACK_EXP) { 2579 RILRequest rr = processSolicited (p, type); 2580 if (rr != null) { 2581 if (type == RESPONSE_SOLICITED) { 2582 decrementWakeLock(rr); 2583 } 2584 rr.release(); 2585 return; 2586 } 2587 } else if (type == RESPONSE_SOLICITED_ACK) { 2588 int serial; 2589 serial = p.readInt(); 2590 2591 RILRequest rr; 2592 synchronized (mRequestList) { 2593 rr = mRequestList.get(serial); 2594 } 2595 if (rr == null) { 2596 Rlog.w(RILJ_LOG_TAG, "Unexpected solicited ack response! sn: " + serial); 2597 } else { 2598 decrementWakeLock(rr); 2599 if (RILJ_LOGD) { 2600 riljLog(rr.serialString() + " Ack < " + requestToString(rr.mRequest)); 2601 } 2602 } 2603 } 2604 } 2605 2606 /** 2607 * Release each request in mRequestList then clear the list 2608 * @param error is the RIL_Errno sent back 2609 * @param loggable true means to print all requests in mRequestList 2610 */ clearRequestList(int error, boolean loggable)2611 private void clearRequestList(int error, boolean loggable) { 2612 RILRequest rr; 2613 synchronized (mRequestList) { 2614 int count = mRequestList.size(); 2615 if (RILJ_LOGD && loggable) { 2616 Rlog.d(RILJ_LOG_TAG, "clearRequestList " + 2617 " mWakeLockCount=" + mWakeLockCount + 2618 " mRequestList=" + count); 2619 } 2620 2621 for (int i = 0; i < count ; i++) { 2622 rr = mRequestList.valueAt(i); 2623 if (RILJ_LOGD && loggable) { 2624 Rlog.d(RILJ_LOG_TAG, i + ": [" + rr.mSerial + "] " + 2625 requestToString(rr.mRequest)); 2626 } 2627 rr.onError(error, null); 2628 decrementWakeLock(rr); 2629 rr.release(); 2630 } 2631 mRequestList.clear(); 2632 } 2633 } 2634 findAndRemoveRequestFromList(int serial)2635 private RILRequest findAndRemoveRequestFromList(int serial) { 2636 RILRequest rr = null; 2637 synchronized (mRequestList) { 2638 rr = mRequestList.get(serial); 2639 if (rr != null) { 2640 mRequestList.remove(serial); 2641 } 2642 } 2643 2644 return rr; 2645 } 2646 addToRilHistogram(RILRequest rr)2647 private void addToRilHistogram(RILRequest rr) { 2648 long endTime = SystemClock.elapsedRealtime(); 2649 int totalTime = (int)(endTime - rr.mStartTimeMs); 2650 2651 synchronized(mRilTimeHistograms) { 2652 TelephonyHistogram entry = mRilTimeHistograms.get(rr.mRequest); 2653 if (entry == null) { 2654 // We would have total #RIL_HISTOGRAM_BUCKET_COUNT range buckets for RIL commands 2655 entry = new TelephonyHistogram(TelephonyHistogram.TELEPHONY_CATEGORY_RIL, 2656 rr.mRequest, RIL_HISTOGRAM_BUCKET_COUNT); 2657 mRilTimeHistograms.put(rr.mRequest, entry); 2658 } 2659 entry.addTimeTaken(totalTime); 2660 } 2661 } 2662 2663 private RILRequest processSolicited(Parcel p, int type)2664 processSolicited (Parcel p, int type) { 2665 int serial, error; 2666 boolean found = false; 2667 2668 serial = p.readInt(); 2669 error = p.readInt(); 2670 2671 RILRequest rr; 2672 2673 rr = findAndRemoveRequestFromList(serial); 2674 2675 if (rr == null) { 2676 Rlog.w(RILJ_LOG_TAG, "Unexpected solicited response! sn: " 2677 + serial + " error: " + error); 2678 return null; 2679 } 2680 2681 // Time logging for RIL command and storing it in TelephonyHistogram. 2682 addToRilHistogram(rr); 2683 2684 if (getRilVersion() >= 13 && type == RESPONSE_SOLICITED_ACK_EXP) { 2685 Message msg; 2686 RILRequest response = RILRequest.obtain(RIL_RESPONSE_ACKNOWLEDGEMENT, null); 2687 msg = mSender.obtainMessage(EVENT_SEND_ACK, response); 2688 acquireWakeLock(rr, FOR_ACK_WAKELOCK); 2689 msg.sendToTarget(); 2690 if (RILJ_LOGD) { 2691 riljLog("Response received for " + rr.serialString() + " " + 2692 requestToString(rr.mRequest) + " Sending ack to ril.cpp"); 2693 } 2694 } 2695 2696 2697 Object ret = null; 2698 2699 if (error == 0 || p.dataAvail() > 0) { 2700 // either command succeeds or command fails but with data payload 2701 try {switch (rr.mRequest) { 2702 /* 2703 cat libs/telephony/ril_commands.h \ 2704 | egrep "^ *{RIL_" \ 2705 | sed -re 's/\{([^,]+),[^,]+,([^}]+).+/case \1: ret = \2(p); break;/' 2706 */ 2707 case RIL_REQUEST_GET_SIM_STATUS: ret = responseIccCardStatus(p); break; 2708 case RIL_REQUEST_ENTER_SIM_PIN: ret = responseInts(p); break; 2709 case RIL_REQUEST_ENTER_SIM_PUK: ret = responseInts(p); break; 2710 case RIL_REQUEST_ENTER_SIM_PIN2: ret = responseInts(p); break; 2711 case RIL_REQUEST_ENTER_SIM_PUK2: ret = responseInts(p); break; 2712 case RIL_REQUEST_CHANGE_SIM_PIN: ret = responseInts(p); break; 2713 case RIL_REQUEST_CHANGE_SIM_PIN2: ret = responseInts(p); break; 2714 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: ret = responseInts(p); break; 2715 case RIL_REQUEST_GET_CURRENT_CALLS: ret = responseCallList(p); break; 2716 case RIL_REQUEST_DIAL: ret = responseVoid(p); break; 2717 case RIL_REQUEST_GET_IMSI: ret = responseString(p); break; 2718 case RIL_REQUEST_HANGUP: ret = responseVoid(p); break; 2719 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: ret = responseVoid(p); break; 2720 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: { 2721 if (mTestingEmergencyCall.getAndSet(false)) { 2722 if (mEmergencyCallbackModeRegistrant != null) { 2723 riljLog("testing emergency call, notify ECM Registrants"); 2724 mEmergencyCallbackModeRegistrant.notifyRegistrant(); 2725 } 2726 } 2727 ret = responseVoid(p); 2728 break; 2729 } 2730 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: ret = responseVoid(p); break; 2731 case RIL_REQUEST_CONFERENCE: ret = responseVoid(p); break; 2732 case RIL_REQUEST_UDUB: ret = responseVoid(p); break; 2733 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: ret = responseFailCause(p); break; 2734 case RIL_REQUEST_SIGNAL_STRENGTH: ret = responseSignalStrength(p); break; 2735 case RIL_REQUEST_VOICE_REGISTRATION_STATE: ret = responseStrings(p); break; 2736 case RIL_REQUEST_DATA_REGISTRATION_STATE: ret = responseStrings(p); break; 2737 case RIL_REQUEST_OPERATOR: ret = responseStrings(p); break; 2738 case RIL_REQUEST_RADIO_POWER: ret = responseVoid(p); break; 2739 case RIL_REQUEST_DTMF: ret = responseVoid(p); break; 2740 case RIL_REQUEST_SEND_SMS: ret = responseSMS(p); break; 2741 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: ret = responseSMS(p); break; 2742 case RIL_REQUEST_SETUP_DATA_CALL: ret = responseSetupDataCall(p); break; 2743 case RIL_REQUEST_SIM_IO: ret = responseICC_IO(p); break; 2744 case RIL_REQUEST_SEND_USSD: ret = responseVoid(p); break; 2745 case RIL_REQUEST_CANCEL_USSD: ret = responseVoid(p); break; 2746 case RIL_REQUEST_GET_CLIR: ret = responseInts(p); break; 2747 case RIL_REQUEST_SET_CLIR: ret = responseVoid(p); break; 2748 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: ret = responseCallForward(p); break; 2749 case RIL_REQUEST_SET_CALL_FORWARD: ret = responseVoid(p); break; 2750 case RIL_REQUEST_QUERY_CALL_WAITING: ret = responseInts(p); break; 2751 case RIL_REQUEST_SET_CALL_WAITING: ret = responseVoid(p); break; 2752 case RIL_REQUEST_SMS_ACKNOWLEDGE: ret = responseVoid(p); break; 2753 case RIL_REQUEST_GET_IMEI: ret = responseString(p); break; 2754 case RIL_REQUEST_GET_IMEISV: ret = responseString(p); break; 2755 case RIL_REQUEST_ANSWER: ret = responseVoid(p); break; 2756 case RIL_REQUEST_DEACTIVATE_DATA_CALL: ret = responseVoid(p); break; 2757 case RIL_REQUEST_QUERY_FACILITY_LOCK: ret = responseInts(p); break; 2758 case RIL_REQUEST_SET_FACILITY_LOCK: ret = responseInts(p); break; 2759 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: ret = responseVoid(p); break; 2760 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: ret = responseInts(p); break; 2761 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: ret = responseVoid(p); break; 2762 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: ret = responseVoid(p); break; 2763 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : ret = responseOperatorInfos(p); break; 2764 case RIL_REQUEST_DTMF_START: ret = responseVoid(p); break; 2765 case RIL_REQUEST_DTMF_STOP: ret = responseVoid(p); break; 2766 case RIL_REQUEST_BASEBAND_VERSION: ret = responseString(p); break; 2767 case RIL_REQUEST_SEPARATE_CONNECTION: ret = responseVoid(p); break; 2768 case RIL_REQUEST_SET_MUTE: ret = responseVoid(p); break; 2769 case RIL_REQUEST_GET_MUTE: ret = responseInts(p); break; 2770 case RIL_REQUEST_QUERY_CLIP: ret = responseInts(p); break; 2771 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: ret = responseInts(p); break; 2772 case RIL_REQUEST_DATA_CALL_LIST: ret = responseDataCallList(p); break; 2773 case RIL_REQUEST_RESET_RADIO: ret = responseVoid(p); break; 2774 case RIL_REQUEST_OEM_HOOK_RAW: ret = responseRaw(p); break; 2775 case RIL_REQUEST_OEM_HOOK_STRINGS: ret = responseStrings(p); break; 2776 case RIL_REQUEST_SCREEN_STATE: ret = responseVoid(p); break; 2777 case RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION: ret = responseVoid(p); break; 2778 case RIL_REQUEST_WRITE_SMS_TO_SIM: ret = responseInts(p); break; 2779 case RIL_REQUEST_DELETE_SMS_ON_SIM: ret = responseVoid(p); break; 2780 case RIL_REQUEST_SET_BAND_MODE: ret = responseVoid(p); break; 2781 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: ret = responseInts(p); break; 2782 case RIL_REQUEST_STK_GET_PROFILE: ret = responseString(p); break; 2783 case RIL_REQUEST_STK_SET_PROFILE: ret = responseVoid(p); break; 2784 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: ret = responseString(p); break; 2785 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: ret = responseVoid(p); break; 2786 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: ret = responseInts(p); break; 2787 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: ret = responseVoid(p); break; 2788 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: ret = responseVoid(p); break; 2789 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: ret = responseGetPreferredNetworkType(p); break; 2790 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: ret = responseCellList(p); break; 2791 case RIL_REQUEST_SET_LOCATION_UPDATES: ret = responseVoid(p); break; 2792 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE: ret = responseVoid(p); break; 2793 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE: ret = responseVoid(p); break; 2794 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE: ret = responseInts(p); break; 2795 case RIL_REQUEST_SET_TTY_MODE: ret = responseVoid(p); break; 2796 case RIL_REQUEST_QUERY_TTY_MODE: ret = responseInts(p); break; 2797 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE: ret = responseVoid(p); break; 2798 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE: ret = responseInts(p); break; 2799 case RIL_REQUEST_CDMA_FLASH: ret = responseVoid(p); break; 2800 case RIL_REQUEST_CDMA_BURST_DTMF: ret = responseVoid(p); break; 2801 case RIL_REQUEST_CDMA_SEND_SMS: ret = responseSMS(p); break; 2802 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE: ret = responseVoid(p); break; 2803 case RIL_REQUEST_GSM_GET_BROADCAST_CONFIG: ret = responseGmsBroadcastConfig(p); break; 2804 case RIL_REQUEST_GSM_SET_BROADCAST_CONFIG: ret = responseVoid(p); break; 2805 case RIL_REQUEST_GSM_BROADCAST_ACTIVATION: ret = responseVoid(p); break; 2806 case RIL_REQUEST_CDMA_GET_BROADCAST_CONFIG: ret = responseCdmaBroadcastConfig(p); break; 2807 case RIL_REQUEST_CDMA_SET_BROADCAST_CONFIG: ret = responseVoid(p); break; 2808 case RIL_REQUEST_CDMA_BROADCAST_ACTIVATION: ret = responseVoid(p); break; 2809 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: ret = responseVoid(p); break; 2810 case RIL_REQUEST_CDMA_SUBSCRIPTION: ret = responseStrings(p); break; 2811 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: ret = responseInts(p); break; 2812 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: ret = responseVoid(p); break; 2813 case RIL_REQUEST_DEVICE_IDENTITY: ret = responseStrings(p); break; 2814 case RIL_REQUEST_GET_SMSC_ADDRESS: ret = responseString(p); break; 2815 case RIL_REQUEST_SET_SMSC_ADDRESS: ret = responseVoid(p); break; 2816 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: ret = responseVoid(p); break; 2817 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: ret = responseVoid(p); break; 2818 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: ret = responseVoid(p); break; 2819 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: ret = responseInts(p); break; 2820 case RIL_REQUEST_ISIM_AUTHENTICATION: ret = responseString(p); break; 2821 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: ret = responseVoid(p); break; 2822 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: ret = responseICC_IO(p); break; 2823 case RIL_REQUEST_VOICE_RADIO_TECH: ret = responseInts(p); break; 2824 case RIL_REQUEST_GET_CELL_INFO_LIST: ret = responseCellInfoList(p); break; 2825 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: ret = responseVoid(p); break; 2826 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: ret = responseVoid(p); break; 2827 case RIL_REQUEST_SET_DATA_PROFILE: ret = responseVoid(p); break; 2828 case RIL_REQUEST_IMS_REGISTRATION_STATE: ret = responseInts(p); break; 2829 case RIL_REQUEST_IMS_SEND_SMS: ret = responseSMS(p); break; 2830 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: ret = responseICC_IO(p); break; 2831 case RIL_REQUEST_SIM_OPEN_CHANNEL: ret = responseInts(p); break; 2832 case RIL_REQUEST_SIM_CLOSE_CHANNEL: ret = responseVoid(p); break; 2833 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: ret = responseICC_IO(p); break; 2834 case RIL_REQUEST_NV_READ_ITEM: ret = responseString(p); break; 2835 case RIL_REQUEST_NV_WRITE_ITEM: ret = responseVoid(p); break; 2836 case RIL_REQUEST_NV_WRITE_CDMA_PRL: ret = responseVoid(p); break; 2837 case RIL_REQUEST_NV_RESET_CONFIG: ret = responseVoid(p); break; 2838 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: ret = responseVoid(p); break; 2839 case RIL_REQUEST_ALLOW_DATA: ret = responseVoid(p); break; 2840 case RIL_REQUEST_GET_HARDWARE_CONFIG: ret = responseHardwareConfig(p); break; 2841 case RIL_REQUEST_SIM_AUTHENTICATION: ret = responseICC_IOBase64(p); break; 2842 case RIL_REQUEST_SHUTDOWN: ret = responseVoid(p); break; 2843 case RIL_REQUEST_GET_RADIO_CAPABILITY: ret = responseRadioCapability(p); break; 2844 case RIL_REQUEST_SET_RADIO_CAPABILITY: ret = responseRadioCapability(p); break; 2845 case RIL_REQUEST_START_LCE: ret = responseLceStatus(p); break; 2846 case RIL_REQUEST_STOP_LCE: ret = responseLceStatus(p); break; 2847 case RIL_REQUEST_PULL_LCEDATA: ret = responseLceData(p); break; 2848 case RIL_REQUEST_GET_ACTIVITY_INFO: ret = responseActivityData(p); break; 2849 case RIL_REQUEST_SET_ALLOWED_CARRIERS: ret = responseInts(p); break; 2850 case RIL_REQUEST_GET_ALLOWED_CARRIERS: ret = responseCarrierIdentifiers(p); break; 2851 default: 2852 throw new RuntimeException("Unrecognized solicited response: " + rr.mRequest); 2853 //break; 2854 }} catch (Throwable tr) { 2855 // Exceptions here usually mean invalid RIL responses 2856 2857 Rlog.w(RILJ_LOG_TAG, rr.serialString() + "< " 2858 + requestToString(rr.mRequest) 2859 + " exception, possible invalid RIL response", tr); 2860 2861 if (rr.mResult != null) { 2862 AsyncResult.forMessage(rr.mResult, null, tr); 2863 rr.mResult.sendToTarget(); 2864 } 2865 return rr; 2866 } 2867 } 2868 2869 if (rr.mRequest == RIL_REQUEST_SHUTDOWN) { 2870 // Set RADIO_STATE to RADIO_UNAVAILABLE to continue shutdown process 2871 // regardless of error code to continue shutdown procedure. 2872 riljLog("Response to RIL_REQUEST_SHUTDOWN received. Error is " + 2873 error + " Setting Radio State to Unavailable regardless of error."); 2874 setRadioState(RadioState.RADIO_UNAVAILABLE); 2875 } 2876 2877 // Here and below fake RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, see b/7255789. 2878 // This is needed otherwise we don't automatically transition to the main lock 2879 // screen when the pin or puk is entered incorrectly. 2880 switch (rr.mRequest) { 2881 case RIL_REQUEST_ENTER_SIM_PUK: 2882 case RIL_REQUEST_ENTER_SIM_PUK2: 2883 if (mIccStatusChangedRegistrants != null) { 2884 if (RILJ_LOGD) { 2885 riljLog("ON enter sim puk fakeSimStatusChanged: reg count=" 2886 + mIccStatusChangedRegistrants.size()); 2887 } 2888 mIccStatusChangedRegistrants.notifyRegistrants(); 2889 } 2890 break; 2891 } 2892 2893 if (error != 0) { 2894 switch (rr.mRequest) { 2895 case RIL_REQUEST_ENTER_SIM_PIN: 2896 case RIL_REQUEST_ENTER_SIM_PIN2: 2897 case RIL_REQUEST_CHANGE_SIM_PIN: 2898 case RIL_REQUEST_CHANGE_SIM_PIN2: 2899 case RIL_REQUEST_SET_FACILITY_LOCK: 2900 if (mIccStatusChangedRegistrants != null) { 2901 if (RILJ_LOGD) { 2902 riljLog("ON some errors fakeSimStatusChanged: reg count=" 2903 + mIccStatusChangedRegistrants.size()); 2904 } 2905 mIccStatusChangedRegistrants.notifyRegistrants(); 2906 } 2907 break; 2908 case RIL_REQUEST_GET_RADIO_CAPABILITY: { 2909 // Ideally RIL's would support this or at least give NOT_SUPPORTED 2910 // but the hammerhead RIL reports GENERIC :( 2911 // TODO - remove GENERIC_FAILURE catching: b/21079604 2912 if (REQUEST_NOT_SUPPORTED == error || 2913 GENERIC_FAILURE == error) { 2914 // we should construct the RAF bitmask the radio 2915 // supports based on preferred network bitmasks 2916 ret = makeStaticRadioCapability(); 2917 error = 0; 2918 } 2919 break; 2920 } 2921 case RIL_REQUEST_GET_ACTIVITY_INFO: 2922 ret = new ModemActivityInfo(0, 0, 0, 2923 new int [ModemActivityInfo.TX_POWER_LEVELS], 0, 0); 2924 error = 0; 2925 break; 2926 } 2927 2928 if (error != 0) rr.onError(error, ret); 2929 } 2930 if (error == 0) { 2931 2932 if (RILJ_LOGD) riljLog(rr.serialString() + "< " + requestToString(rr.mRequest) 2933 + " " + retToString(rr.mRequest, ret)); 2934 2935 if (rr.mResult != null) { 2936 AsyncResult.forMessage(rr.mResult, ret, null); 2937 rr.mResult.sendToTarget(); 2938 } 2939 } 2940 2941 mEventLog.writeOnRilSolicitedResponse(rr.mSerial, error, rr.mRequest, ret); 2942 2943 return rr; 2944 } 2945 makeStaticRadioCapability()2946 private RadioCapability makeStaticRadioCapability() { 2947 // default to UNKNOWN so we fail fast. 2948 int raf = RadioAccessFamily.RAF_UNKNOWN; 2949 2950 String rafString = mContext.getResources().getString( 2951 com.android.internal.R.string.config_radio_access_family); 2952 if (TextUtils.isEmpty(rafString) == false) { 2953 raf = RadioAccessFamily.rafTypeFromString(rafString); 2954 } 2955 RadioCapability rc = new RadioCapability(mInstanceId.intValue(), 0, 0, raf, 2956 "", RadioCapability.RC_STATUS_SUCCESS); 2957 if (RILJ_LOGD) riljLog("Faking RIL_REQUEST_GET_RADIO_CAPABILITY response using " + raf); 2958 return rc; 2959 } 2960 2961 static String retToString(int req, Object ret)2962 retToString(int req, Object ret) { 2963 if (ret == null) return ""; 2964 switch (req) { 2965 // Don't log these return values, for privacy's sake. 2966 case RIL_REQUEST_GET_IMSI: 2967 case RIL_REQUEST_GET_IMEI: 2968 case RIL_REQUEST_GET_IMEISV: 2969 case RIL_REQUEST_SIM_OPEN_CHANNEL: 2970 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: 2971 2972 if (!RILJ_LOGV) { 2973 // If not versbose logging just return and don't display IMSI and IMEI, IMEISV 2974 return ""; 2975 } 2976 } 2977 2978 StringBuilder sb; 2979 String s; 2980 int length; 2981 if (ret instanceof int[]){ 2982 int[] intArray = (int[]) ret; 2983 length = intArray.length; 2984 sb = new StringBuilder("{"); 2985 if (length > 0) { 2986 int i = 0; 2987 sb.append(intArray[i++]); 2988 while ( i < length) { 2989 sb.append(", ").append(intArray[i++]); 2990 } 2991 } 2992 sb.append("}"); 2993 s = sb.toString(); 2994 } else if (ret instanceof String[]) { 2995 String[] strings = (String[]) ret; 2996 length = strings.length; 2997 sb = new StringBuilder("{"); 2998 if (length > 0) { 2999 int i = 0; 3000 sb.append(strings[i++]); 3001 while ( i < length) { 3002 sb.append(", ").append(strings[i++]); 3003 } 3004 } 3005 sb.append("}"); 3006 s = sb.toString(); 3007 }else if (req == RIL_REQUEST_GET_CURRENT_CALLS) { 3008 ArrayList<DriverCall> calls = (ArrayList<DriverCall>) ret; 3009 sb = new StringBuilder("{"); 3010 for (DriverCall dc : calls) { 3011 sb.append("[").append(dc).append("] "); 3012 } 3013 sb.append("}"); 3014 s = sb.toString(); 3015 } else if (req == RIL_REQUEST_GET_NEIGHBORING_CELL_IDS) { 3016 ArrayList<NeighboringCellInfo> cells = (ArrayList<NeighboringCellInfo>) ret; 3017 sb = new StringBuilder("{"); 3018 for (NeighboringCellInfo cell : cells) { 3019 sb.append("[").append(cell).append("] "); 3020 } 3021 sb.append("}"); 3022 s = sb.toString(); 3023 } else if (req == RIL_REQUEST_QUERY_CALL_FORWARD_STATUS) { 3024 CallForwardInfo[] cinfo = (CallForwardInfo[]) ret; 3025 length = cinfo.length; 3026 sb = new StringBuilder("{"); 3027 for(int i = 0; i < length; i++) { 3028 sb.append("[").append(cinfo[i]).append("] "); 3029 } 3030 sb.append("}"); 3031 s = sb.toString(); 3032 } else if (req == RIL_REQUEST_GET_HARDWARE_CONFIG) { 3033 ArrayList<HardwareConfig> hwcfgs = (ArrayList<HardwareConfig>) ret; 3034 sb = new StringBuilder(" "); 3035 for (HardwareConfig hwcfg : hwcfgs) { 3036 sb.append("[").append(hwcfg).append("] "); 3037 } 3038 s = sb.toString(); 3039 } else { 3040 s = ret.toString(); 3041 } 3042 return s; 3043 } 3044 3045 private void processUnsolicited(Parcel p, int type)3046 processUnsolicited (Parcel p, int type) { 3047 int response; 3048 Object ret; 3049 3050 response = p.readInt(); 3051 3052 // Follow new symantics of sending an Ack starting from RIL version 13 3053 if (getRilVersion() >= 13 && type == RESPONSE_UNSOLICITED_ACK_EXP) { 3054 Message msg; 3055 RILRequest rr = RILRequest.obtain(RIL_RESPONSE_ACKNOWLEDGEMENT, null); 3056 msg = mSender.obtainMessage(EVENT_SEND_ACK, rr); 3057 acquireWakeLock(rr, FOR_ACK_WAKELOCK); 3058 msg.sendToTarget(); 3059 if (RILJ_LOGD) { 3060 riljLog("Unsol response received for " + responseToString(response) + 3061 " Sending ack to ril.cpp"); 3062 } 3063 } 3064 3065 try {switch(response) { 3066 /* 3067 cat libs/telephony/ril_unsol_commands.h \ 3068 | egrep "^ *{RIL_" \ 3069 | sed -re 's/\{([^,]+),[^,]+,([^}]+).+/case \1: \2(rr, p); break;/' 3070 */ 3071 3072 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: ret = responseVoid(p); break; 3073 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: ret = responseVoid(p); break; 3074 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: ret = responseVoid(p); break; 3075 case RIL_UNSOL_RESPONSE_NEW_SMS: ret = responseString(p); break; 3076 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: ret = responseString(p); break; 3077 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: ret = responseInts(p); break; 3078 case RIL_UNSOL_ON_USSD: ret = responseStrings(p); break; 3079 case RIL_UNSOL_NITZ_TIME_RECEIVED: ret = responseString(p); break; 3080 case RIL_UNSOL_SIGNAL_STRENGTH: ret = responseSignalStrength(p); break; 3081 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: ret = responseDataCallList(p);break; 3082 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: ret = responseSuppServiceNotification(p); break; 3083 case RIL_UNSOL_STK_SESSION_END: ret = responseVoid(p); break; 3084 case RIL_UNSOL_STK_PROACTIVE_COMMAND: ret = responseString(p); break; 3085 case RIL_UNSOL_STK_EVENT_NOTIFY: ret = responseString(p); break; 3086 case RIL_UNSOL_STK_CALL_SETUP: ret = responseInts(p); break; 3087 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: ret = responseVoid(p); break; 3088 case RIL_UNSOL_SIM_REFRESH: ret = responseSimRefresh(p); break; 3089 case RIL_UNSOL_CALL_RING: ret = responseCallRing(p); break; 3090 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: ret = responseInts(p); break; 3091 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: ret = responseVoid(p); break; 3092 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: ret = responseCdmaSms(p); break; 3093 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: ret = responseRaw(p); break; 3094 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: ret = responseVoid(p); break; 3095 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: ret = responseVoid(p); break; 3096 case RIL_UNSOL_CDMA_CALL_WAITING: ret = responseCdmaCallWaiting(p); break; 3097 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: ret = responseInts(p); break; 3098 case RIL_UNSOL_CDMA_INFO_REC: ret = responseCdmaInformationRecord(p); break; 3099 case RIL_UNSOL_OEM_HOOK_RAW: ret = responseRaw(p); break; 3100 case RIL_UNSOL_RINGBACK_TONE: ret = responseInts(p); break; 3101 case RIL_UNSOL_RESEND_INCALL_MUTE: ret = responseVoid(p); break; 3102 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: ret = responseInts(p); break; 3103 case RIL_UNSOl_CDMA_PRL_CHANGED: ret = responseInts(p); break; 3104 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: ret = responseVoid(p); break; 3105 case RIL_UNSOL_RIL_CONNECTED: ret = responseInts(p); break; 3106 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: ret = responseInts(p); break; 3107 case RIL_UNSOL_CELL_INFO_LIST: ret = responseCellInfoList(p); break; 3108 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: ret = responseVoid(p); break; 3109 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: ret = responseInts(p); break; 3110 case RIL_UNSOL_SRVCC_STATE_NOTIFY: ret = responseInts(p); break; 3111 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: ret = responseHardwareConfig(p); break; 3112 case RIL_UNSOL_RADIO_CAPABILITY: 3113 ret = responseRadioCapability(p); break; 3114 case RIL_UNSOL_ON_SS: ret = responseSsData(p); break; 3115 case RIL_UNSOL_STK_CC_ALPHA_NOTIFY: ret = responseString(p); break; 3116 case RIL_UNSOL_LCEDATA_RECV: ret = responseLceData(p); break; 3117 case RIL_UNSOL_PCO_DATA: ret = responsePcoData(p); break; 3118 3119 default: 3120 throw new RuntimeException("Unrecognized unsol response: " + response); 3121 //break; (implied) 3122 }} catch (Throwable tr) { 3123 Rlog.e(RILJ_LOG_TAG, "Exception processing unsol response: " + response + 3124 "Exception:" + tr.toString()); 3125 return; 3126 } 3127 3128 switch(response) { 3129 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: 3130 /* has bonus radio state int */ 3131 RadioState newState = getRadioStateFromInt(p.readInt()); 3132 if (RILJ_LOGD) unsljLogMore(response, newState.toString()); 3133 3134 switchToRadioState(newState); 3135 break; 3136 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: 3137 if (RILJ_LOGD) unsljLog(response); 3138 3139 mImsNetworkStateChangedRegistrants 3140 .notifyRegistrants(new AsyncResult(null, null, null)); 3141 break; 3142 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: 3143 if (RILJ_LOGD) unsljLog(response); 3144 3145 mCallStateRegistrants 3146 .notifyRegistrants(new AsyncResult(null, null, null)); 3147 break; 3148 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: 3149 if (RILJ_LOGD) unsljLog(response); 3150 3151 mVoiceNetworkStateRegistrants 3152 .notifyRegistrants(new AsyncResult(null, null, null)); 3153 break; 3154 case RIL_UNSOL_RESPONSE_NEW_SMS: { 3155 if (RILJ_LOGD) unsljLog(response); 3156 3157 mEventLog.writeRilNewSms(response); 3158 3159 // FIXME this should move up a layer 3160 String a[] = new String[2]; 3161 3162 a[1] = (String)ret; 3163 3164 SmsMessage sms; 3165 3166 sms = SmsMessage.newFromCMT(a); 3167 if (mGsmSmsRegistrant != null) { 3168 mGsmSmsRegistrant 3169 .notifyRegistrant(new AsyncResult(null, sms, null)); 3170 } 3171 break; 3172 } 3173 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: 3174 if (RILJ_LOGD) unsljLogRet(response, ret); 3175 3176 if (mSmsStatusRegistrant != null) { 3177 mSmsStatusRegistrant.notifyRegistrant( 3178 new AsyncResult(null, ret, null)); 3179 } 3180 break; 3181 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: 3182 if (RILJ_LOGD) unsljLogRet(response, ret); 3183 3184 int[] smsIndex = (int[])ret; 3185 3186 if(smsIndex.length == 1) { 3187 if (mSmsOnSimRegistrant != null) { 3188 mSmsOnSimRegistrant. 3189 notifyRegistrant(new AsyncResult(null, smsIndex, null)); 3190 } 3191 } else { 3192 if (RILJ_LOGD) riljLog(" NEW_SMS_ON_SIM ERROR with wrong length " 3193 + smsIndex.length); 3194 } 3195 break; 3196 case RIL_UNSOL_ON_USSD: 3197 String[] resp = (String[])ret; 3198 3199 if (resp.length < 2) { 3200 resp = new String[2]; 3201 resp[0] = ((String[])ret)[0]; 3202 resp[1] = null; 3203 } 3204 if (RILJ_LOGD) unsljLogMore(response, resp[0]); 3205 if (mUSSDRegistrant != null) { 3206 mUSSDRegistrant.notifyRegistrant( 3207 new AsyncResult (null, resp, null)); 3208 } 3209 break; 3210 case RIL_UNSOL_NITZ_TIME_RECEIVED: 3211 if (RILJ_LOGD) unsljLogRet(response, ret); 3212 3213 // has bonus long containing milliseconds since boot that the NITZ 3214 // time was received 3215 long nitzReceiveTime = p.readLong(); 3216 3217 Object[] result = new Object[2]; 3218 3219 result[0] = ret; 3220 result[1] = Long.valueOf(nitzReceiveTime); 3221 3222 boolean ignoreNitz = SystemProperties.getBoolean( 3223 TelephonyProperties.PROPERTY_IGNORE_NITZ, false); 3224 3225 if (ignoreNitz) { 3226 if (RILJ_LOGD) riljLog("ignoring UNSOL_NITZ_TIME_RECEIVED"); 3227 } else { 3228 if (mNITZTimeRegistrant != null) { 3229 3230 mNITZTimeRegistrant 3231 .notifyRegistrant(new AsyncResult (null, result, null)); 3232 } 3233 // in case NITZ time registrant isn't registered yet, or a new registrant 3234 // registers later 3235 mLastNITZTimeInfo = result; 3236 } 3237 break; 3238 3239 case RIL_UNSOL_SIGNAL_STRENGTH: 3240 // Note this is set to "verbose" because it happens 3241 // frequently 3242 if (RILJ_LOGV) unsljLogvRet(response, ret); 3243 3244 if (mSignalStrengthRegistrant != null) { 3245 mSignalStrengthRegistrant.notifyRegistrant( 3246 new AsyncResult (null, ret, null)); 3247 } 3248 break; 3249 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: 3250 if (RILJ_LOGD) unsljLogRet(response, ret); 3251 3252 mDataNetworkStateRegistrants.notifyRegistrants(new AsyncResult(null, ret, null)); 3253 break; 3254 3255 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: 3256 if (RILJ_LOGD) unsljLogRet(response, ret); 3257 3258 if (mSsnRegistrant != null) { 3259 mSsnRegistrant.notifyRegistrant( 3260 new AsyncResult (null, ret, null)); 3261 } 3262 break; 3263 3264 case RIL_UNSOL_STK_SESSION_END: 3265 if (RILJ_LOGD) unsljLog(response); 3266 3267 if (mCatSessionEndRegistrant != null) { 3268 mCatSessionEndRegistrant.notifyRegistrant( 3269 new AsyncResult (null, ret, null)); 3270 } 3271 break; 3272 3273 case RIL_UNSOL_STK_PROACTIVE_COMMAND: 3274 if (RILJ_LOGD) unsljLog(response); 3275 3276 if (mCatProCmdRegistrant != null) { 3277 mCatProCmdRegistrant.notifyRegistrant( 3278 new AsyncResult (null, ret, null)); 3279 } 3280 break; 3281 3282 case RIL_UNSOL_STK_EVENT_NOTIFY: 3283 if (RILJ_LOGD) unsljLog(response); 3284 3285 if (mCatEventRegistrant != null) { 3286 mCatEventRegistrant.notifyRegistrant( 3287 new AsyncResult (null, ret, null)); 3288 } 3289 break; 3290 3291 case RIL_UNSOL_STK_CALL_SETUP: 3292 if (RILJ_LOGD) unsljLogRet(response, ret); 3293 3294 if (mCatCallSetUpRegistrant != null) { 3295 mCatCallSetUpRegistrant.notifyRegistrant( 3296 new AsyncResult (null, ret, null)); 3297 } 3298 break; 3299 3300 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: 3301 if (RILJ_LOGD) unsljLog(response); 3302 3303 if (mIccSmsFullRegistrant != null) { 3304 mIccSmsFullRegistrant.notifyRegistrant(); 3305 } 3306 break; 3307 3308 case RIL_UNSOL_SIM_REFRESH: 3309 if (RILJ_LOGD) unsljLogRet(response, ret); 3310 3311 if (mIccRefreshRegistrants != null) { 3312 mIccRefreshRegistrants.notifyRegistrants( 3313 new AsyncResult (null, ret, null)); 3314 } 3315 break; 3316 3317 case RIL_UNSOL_CALL_RING: 3318 if (RILJ_LOGD) unsljLogRet(response, ret); 3319 3320 if (mRingRegistrant != null) { 3321 mRingRegistrant.notifyRegistrant( 3322 new AsyncResult (null, ret, null)); 3323 } 3324 break; 3325 3326 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: 3327 if (RILJ_LOGD) unsljLogvRet(response, ret); 3328 if (mRestrictedStateRegistrant != null) { 3329 mRestrictedStateRegistrant.notifyRegistrant( 3330 new AsyncResult (null, ret, null)); 3331 } 3332 break; 3333 3334 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: 3335 if (RILJ_LOGD) unsljLog(response); 3336 3337 if (mIccStatusChangedRegistrants != null) { 3338 mIccStatusChangedRegistrants.notifyRegistrants(); 3339 } 3340 break; 3341 3342 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: 3343 if (RILJ_LOGD) unsljLog(response); 3344 3345 mEventLog.writeRilNewSms(response); 3346 3347 SmsMessage sms = (SmsMessage) ret; 3348 3349 if (mCdmaSmsRegistrant != null) { 3350 mCdmaSmsRegistrant 3351 .notifyRegistrant(new AsyncResult(null, sms, null)); 3352 } 3353 break; 3354 3355 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: 3356 if (RILJ_LOGD) unsljLogvRet(response, IccUtils.bytesToHexString((byte[])ret)); 3357 3358 if (mGsmBroadcastSmsRegistrant != null) { 3359 mGsmBroadcastSmsRegistrant 3360 .notifyRegistrant(new AsyncResult(null, ret, null)); 3361 } 3362 break; 3363 3364 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: 3365 if (RILJ_LOGD) unsljLog(response); 3366 3367 if (mIccSmsFullRegistrant != null) { 3368 mIccSmsFullRegistrant.notifyRegistrant(); 3369 } 3370 break; 3371 3372 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: 3373 if (RILJ_LOGD) unsljLog(response); 3374 3375 if (mEmergencyCallbackModeRegistrant != null) { 3376 mEmergencyCallbackModeRegistrant.notifyRegistrant(); 3377 } 3378 break; 3379 3380 case RIL_UNSOL_CDMA_CALL_WAITING: 3381 if (RILJ_LOGD) unsljLogRet(response, ret); 3382 3383 if (mCallWaitingInfoRegistrants != null) { 3384 mCallWaitingInfoRegistrants.notifyRegistrants( 3385 new AsyncResult (null, ret, null)); 3386 } 3387 break; 3388 3389 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: 3390 if (RILJ_LOGD) unsljLogRet(response, ret); 3391 3392 if (mOtaProvisionRegistrants != null) { 3393 mOtaProvisionRegistrants.notifyRegistrants( 3394 new AsyncResult (null, ret, null)); 3395 } 3396 break; 3397 3398 case RIL_UNSOL_CDMA_INFO_REC: 3399 ArrayList<CdmaInformationRecords> listInfoRecs; 3400 3401 try { 3402 listInfoRecs = (ArrayList<CdmaInformationRecords>)ret; 3403 } catch (ClassCastException e) { 3404 Rlog.e(RILJ_LOG_TAG, "Unexpected exception casting to listInfoRecs", e); 3405 break; 3406 } 3407 3408 for (CdmaInformationRecords rec : listInfoRecs) { 3409 if (RILJ_LOGD) unsljLogRet(response, rec); 3410 notifyRegistrantsCdmaInfoRec(rec); 3411 } 3412 break; 3413 3414 case RIL_UNSOL_OEM_HOOK_RAW: 3415 if (RILJ_LOGD) unsljLogvRet(response, IccUtils.bytesToHexString((byte[]) ret)); 3416 if (mUnsolOemHookRawRegistrant != null) { 3417 mUnsolOemHookRawRegistrant.notifyRegistrant(new AsyncResult(null, ret, null)); 3418 } 3419 break; 3420 3421 case RIL_UNSOL_RINGBACK_TONE: 3422 if (RILJ_LOGD) unsljLogvRet(response, ret); 3423 if (mRingbackToneRegistrants != null) { 3424 boolean playtone = (((int[])ret)[0] == 1); 3425 mRingbackToneRegistrants.notifyRegistrants( 3426 new AsyncResult (null, playtone, null)); 3427 } 3428 break; 3429 3430 case RIL_UNSOL_RESEND_INCALL_MUTE: 3431 if (RILJ_LOGD) unsljLogRet(response, ret); 3432 3433 if (mResendIncallMuteRegistrants != null) { 3434 mResendIncallMuteRegistrants.notifyRegistrants( 3435 new AsyncResult (null, ret, null)); 3436 } 3437 break; 3438 3439 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: 3440 if (RILJ_LOGD) unsljLogRet(response, ret); 3441 3442 if (mVoiceRadioTechChangedRegistrants != null) { 3443 mVoiceRadioTechChangedRegistrants.notifyRegistrants( 3444 new AsyncResult(null, ret, null)); 3445 } 3446 break; 3447 3448 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: 3449 if (RILJ_LOGD) unsljLogRet(response, ret); 3450 3451 if (mCdmaSubscriptionChangedRegistrants != null) { 3452 mCdmaSubscriptionChangedRegistrants.notifyRegistrants( 3453 new AsyncResult (null, ret, null)); 3454 } 3455 break; 3456 3457 case RIL_UNSOl_CDMA_PRL_CHANGED: 3458 if (RILJ_LOGD) unsljLogRet(response, ret); 3459 3460 if (mCdmaPrlChangedRegistrants != null) { 3461 mCdmaPrlChangedRegistrants.notifyRegistrants( 3462 new AsyncResult (null, ret, null)); 3463 } 3464 break; 3465 3466 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: 3467 if (RILJ_LOGD) unsljLogRet(response, ret); 3468 3469 if (mExitEmergencyCallbackModeRegistrants != null) { 3470 mExitEmergencyCallbackModeRegistrants.notifyRegistrants( 3471 new AsyncResult (null, null, null)); 3472 } 3473 break; 3474 3475 case RIL_UNSOL_RIL_CONNECTED: { 3476 if (RILJ_LOGD) unsljLogRet(response, ret); 3477 3478 // Initial conditions 3479 setRadioPower(false, null); 3480 setCdmaSubscriptionSource(mCdmaSubscription, null); 3481 setCellInfoListRate(Integer.MAX_VALUE, null); 3482 notifyRegistrantsRilConnectionChanged(((int[])ret)[0]); 3483 break; 3484 } 3485 case RIL_UNSOL_CELL_INFO_LIST: { 3486 if (RILJ_LOGD) unsljLogRet(response, ret); 3487 3488 if (mRilCellInfoListRegistrants != null) { 3489 mRilCellInfoListRegistrants.notifyRegistrants( 3490 new AsyncResult (null, ret, null)); 3491 } 3492 break; 3493 } 3494 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: { 3495 if (RILJ_LOGD) unsljLogRet(response, ret); 3496 3497 if (mSubscriptionStatusRegistrants != null) { 3498 mSubscriptionStatusRegistrants.notifyRegistrants( 3499 new AsyncResult (null, ret, null)); 3500 } 3501 break; 3502 } 3503 case RIL_UNSOL_SRVCC_STATE_NOTIFY: { 3504 if (RILJ_LOGD) unsljLogRet(response, ret); 3505 3506 mEventLog.writeRilSrvcc(((int[])ret)[0]); 3507 3508 if (mSrvccStateRegistrants != null) { 3509 mSrvccStateRegistrants 3510 .notifyRegistrants(new AsyncResult(null, ret, null)); 3511 } 3512 break; 3513 } 3514 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: 3515 if (RILJ_LOGD) unsljLogRet(response, ret); 3516 3517 if (mHardwareConfigChangeRegistrants != null) { 3518 mHardwareConfigChangeRegistrants.notifyRegistrants( 3519 new AsyncResult (null, ret, null)); 3520 } 3521 break; 3522 case RIL_UNSOL_RADIO_CAPABILITY: 3523 if (RILJ_LOGD) unsljLogRet(response, ret); 3524 3525 if (mPhoneRadioCapabilityChangedRegistrants != null) { 3526 mPhoneRadioCapabilityChangedRegistrants.notifyRegistrants( 3527 new AsyncResult(null, ret, null)); 3528 } 3529 break; 3530 case RIL_UNSOL_ON_SS: 3531 if (RILJ_LOGD) unsljLogRet(response, ret); 3532 3533 if (mSsRegistrant != null) { 3534 mSsRegistrant.notifyRegistrant( 3535 new AsyncResult (null, ret, null)); 3536 } 3537 break; 3538 case RIL_UNSOL_STK_CC_ALPHA_NOTIFY: 3539 if (RILJ_LOGD) unsljLogRet(response, ret); 3540 3541 if (mCatCcAlphaRegistrant != null) { 3542 mCatCcAlphaRegistrant.notifyRegistrant( 3543 new AsyncResult (null, ret, null)); 3544 } 3545 break; 3546 case RIL_UNSOL_LCEDATA_RECV: 3547 if (RILJ_LOGD) unsljLogRet(response, ret); 3548 3549 if (mLceInfoRegistrant != null) { 3550 mLceInfoRegistrant.notifyRegistrant(new AsyncResult(null, ret, null)); 3551 } 3552 break; 3553 case RIL_UNSOL_PCO_DATA: 3554 if (RILJ_LOGD) unsljLogRet(response, ret); 3555 3556 mPcoDataRegistrants.notifyRegistrants(new AsyncResult(null, ret, null)); 3557 break; 3558 } 3559 } 3560 3561 /** 3562 * Notifiy all registrants that the ril has connected or disconnected. 3563 * 3564 * @param rilVer is the version of the ril or -1 if disconnected. 3565 */ notifyRegistrantsRilConnectionChanged(int rilVer)3566 private void notifyRegistrantsRilConnectionChanged(int rilVer) { 3567 mRilVersion = rilVer; 3568 if (mRilConnectedRegistrants != null) { 3569 mRilConnectedRegistrants.notifyRegistrants( 3570 new AsyncResult (null, new Integer(rilVer), null)); 3571 } 3572 } 3573 3574 private Object responseInts(Parcel p)3575 responseInts(Parcel p) { 3576 int numInts; 3577 int response[]; 3578 3579 numInts = p.readInt(); 3580 3581 response = new int[numInts]; 3582 3583 for (int i = 0 ; i < numInts ; i++) { 3584 response[i] = p.readInt(); 3585 } 3586 3587 return response; 3588 } 3589 3590 private Object responseFailCause(Parcel p)3591 responseFailCause(Parcel p) { 3592 LastCallFailCause failCause = new LastCallFailCause(); 3593 failCause.causeCode = p.readInt(); 3594 if (p.dataAvail() > 0) { 3595 failCause.vendorCause = p.readString(); 3596 } 3597 return failCause; 3598 } 3599 3600 private Object responseVoid(Parcel p)3601 responseVoid(Parcel p) { 3602 return null; 3603 } 3604 3605 private Object responseCallForward(Parcel p)3606 responseCallForward(Parcel p) { 3607 int numInfos; 3608 CallForwardInfo infos[]; 3609 3610 numInfos = p.readInt(); 3611 3612 infos = new CallForwardInfo[numInfos]; 3613 3614 for (int i = 0 ; i < numInfos ; i++) { 3615 infos[i] = new CallForwardInfo(); 3616 3617 infos[i].status = p.readInt(); 3618 infos[i].reason = p.readInt(); 3619 infos[i].serviceClass = p.readInt(); 3620 infos[i].toa = p.readInt(); 3621 infos[i].number = p.readString(); 3622 infos[i].timeSeconds = p.readInt(); 3623 } 3624 3625 return infos; 3626 } 3627 3628 private Object responseSuppServiceNotification(Parcel p)3629 responseSuppServiceNotification(Parcel p) { 3630 SuppServiceNotification notification = new SuppServiceNotification(); 3631 3632 notification.notificationType = p.readInt(); 3633 notification.code = p.readInt(); 3634 notification.index = p.readInt(); 3635 notification.type = p.readInt(); 3636 notification.number = p.readString(); 3637 3638 return notification; 3639 } 3640 3641 private Object responseCdmaSms(Parcel p)3642 responseCdmaSms(Parcel p) { 3643 SmsMessage sms; 3644 sms = SmsMessage.newFromParcel(p); 3645 3646 return sms; 3647 } 3648 3649 private Object responseString(Parcel p)3650 responseString(Parcel p) { 3651 String response; 3652 3653 response = p.readString(); 3654 3655 return response; 3656 } 3657 3658 private Object responseStrings(Parcel p)3659 responseStrings(Parcel p) { 3660 int num; 3661 String response[]; 3662 3663 response = p.readStringArray(); 3664 3665 return response; 3666 } 3667 3668 private Object responseRaw(Parcel p)3669 responseRaw(Parcel p) { 3670 int num; 3671 byte response[]; 3672 3673 response = p.createByteArray(); 3674 3675 return response; 3676 } 3677 3678 private Object responseSMS(Parcel p)3679 responseSMS(Parcel p) { 3680 int messageRef, errorCode; 3681 String ackPDU; 3682 3683 messageRef = p.readInt(); 3684 ackPDU = p.readString(); 3685 errorCode = p.readInt(); 3686 3687 SmsResponse response = new SmsResponse(messageRef, ackPDU, errorCode); 3688 3689 return response; 3690 } 3691 3692 3693 private Object responseICC_IO(Parcel p)3694 responseICC_IO(Parcel p) { 3695 int sw1, sw2; 3696 Message ret; 3697 3698 sw1 = p.readInt(); 3699 sw2 = p.readInt(); 3700 3701 String s = p.readString(); 3702 3703 if (RILJ_LOGV) riljLog("< iccIO: " 3704 + " 0x" + Integer.toHexString(sw1) 3705 + " 0x" + Integer.toHexString(sw2) + " " 3706 + s); 3707 3708 return new IccIoResult(sw1, sw2, s); 3709 } 3710 3711 private Object responseICC_IOBase64(Parcel p)3712 responseICC_IOBase64(Parcel p) { 3713 int sw1, sw2; 3714 Message ret; 3715 3716 sw1 = p.readInt(); 3717 sw2 = p.readInt(); 3718 3719 String s = p.readString(); 3720 3721 if (RILJ_LOGV) riljLog("< iccIO: " 3722 + " 0x" + Integer.toHexString(sw1) 3723 + " 0x" + Integer.toHexString(sw2) + " " 3724 + s); 3725 3726 return new IccIoResult(sw1, sw2, (s != null) 3727 ? android.util.Base64.decode(s, android.util.Base64.DEFAULT) : (byte[]) null); 3728 } 3729 3730 private Object responseIccCardStatus(Parcel p)3731 responseIccCardStatus(Parcel p) { 3732 IccCardApplicationStatus appStatus; 3733 3734 IccCardStatus cardStatus = new IccCardStatus(); 3735 cardStatus.setCardState(p.readInt()); 3736 cardStatus.setUniversalPinState(p.readInt()); 3737 cardStatus.mGsmUmtsSubscriptionAppIndex = p.readInt(); 3738 cardStatus.mCdmaSubscriptionAppIndex = p.readInt(); 3739 cardStatus.mImsSubscriptionAppIndex = p.readInt(); 3740 int numApplications = p.readInt(); 3741 3742 // limit to maximum allowed applications 3743 if (numApplications > IccCardStatus.CARD_MAX_APPS) { 3744 numApplications = IccCardStatus.CARD_MAX_APPS; 3745 } 3746 cardStatus.mApplications = new IccCardApplicationStatus[numApplications]; 3747 for (int i = 0 ; i < numApplications ; i++) { 3748 appStatus = new IccCardApplicationStatus(); 3749 appStatus.app_type = appStatus.AppTypeFromRILInt(p.readInt()); 3750 appStatus.app_state = appStatus.AppStateFromRILInt(p.readInt()); 3751 appStatus.perso_substate = appStatus.PersoSubstateFromRILInt(p.readInt()); 3752 appStatus.aid = p.readString(); 3753 appStatus.app_label = p.readString(); 3754 appStatus.pin1_replaced = p.readInt(); 3755 appStatus.pin1 = appStatus.PinStateFromRILInt(p.readInt()); 3756 appStatus.pin2 = appStatus.PinStateFromRILInt(p.readInt()); 3757 cardStatus.mApplications[i] = appStatus; 3758 } 3759 return cardStatus; 3760 } 3761 3762 private Object responseSimRefresh(Parcel p)3763 responseSimRefresh(Parcel p) { 3764 IccRefreshResponse response = new IccRefreshResponse(); 3765 3766 response.refreshResult = p.readInt(); 3767 response.efId = p.readInt(); 3768 response.aid = p.readString(); 3769 return response; 3770 } 3771 3772 private Object responseCallList(Parcel p)3773 responseCallList(Parcel p) { 3774 int num; 3775 int voiceSettings; 3776 ArrayList<DriverCall> response; 3777 DriverCall dc; 3778 3779 num = p.readInt(); 3780 response = new ArrayList<DriverCall>(num); 3781 3782 if (RILJ_LOGV) { 3783 riljLog("responseCallList: num=" + num + 3784 " mEmergencyCallbackModeRegistrant=" + mEmergencyCallbackModeRegistrant + 3785 " mTestingEmergencyCall=" + mTestingEmergencyCall.get()); 3786 } 3787 for (int i = 0 ; i < num ; i++) { 3788 dc = new DriverCall(); 3789 3790 dc.state = DriverCall.stateFromCLCC(p.readInt()); 3791 dc.index = p.readInt(); 3792 dc.TOA = p.readInt(); 3793 dc.isMpty = (0 != p.readInt()); 3794 dc.isMT = (0 != p.readInt()); 3795 dc.als = p.readInt(); 3796 voiceSettings = p.readInt(); 3797 dc.isVoice = (0 == voiceSettings) ? false : true; 3798 dc.isVoicePrivacy = (0 != p.readInt()); 3799 dc.number = p.readString(); 3800 int np = p.readInt(); 3801 dc.numberPresentation = DriverCall.presentationFromCLIP(np); 3802 dc.name = p.readString(); 3803 // according to ril.h, namePresentation should be handled as numberPresentation; 3804 dc.namePresentation = DriverCall.presentationFromCLIP(p.readInt()); 3805 int uusInfoPresent = p.readInt(); 3806 if (uusInfoPresent == 1) { 3807 dc.uusInfo = new UUSInfo(); 3808 dc.uusInfo.setType(p.readInt()); 3809 dc.uusInfo.setDcs(p.readInt()); 3810 byte[] userData = p.createByteArray(); 3811 dc.uusInfo.setUserData(userData); 3812 riljLogv(String.format("Incoming UUS : type=%d, dcs=%d, length=%d", 3813 dc.uusInfo.getType(), dc.uusInfo.getDcs(), 3814 dc.uusInfo.getUserData().length)); 3815 riljLogv("Incoming UUS : data (string)=" 3816 + new String(dc.uusInfo.getUserData())); 3817 riljLogv("Incoming UUS : data (hex): " 3818 + IccUtils.bytesToHexString(dc.uusInfo.getUserData())); 3819 } else { 3820 riljLogv("Incoming UUS : NOT present!"); 3821 } 3822 3823 // Make sure there's a leading + on addresses with a TOA of 145 3824 dc.number = PhoneNumberUtils.stringFromStringAndTOA(dc.number, dc.TOA); 3825 3826 response.add(dc); 3827 3828 if (dc.isVoicePrivacy) { 3829 mVoicePrivacyOnRegistrants.notifyRegistrants(); 3830 riljLog("InCall VoicePrivacy is enabled"); 3831 } else { 3832 mVoicePrivacyOffRegistrants.notifyRegistrants(); 3833 riljLog("InCall VoicePrivacy is disabled"); 3834 } 3835 } 3836 3837 Collections.sort(response); 3838 3839 if ((num == 0) && mTestingEmergencyCall.getAndSet(false)) { 3840 if (mEmergencyCallbackModeRegistrant != null) { 3841 riljLog("responseCallList: call ended, testing emergency call," + 3842 " notify ECM Registrants"); 3843 mEmergencyCallbackModeRegistrant.notifyRegistrant(); 3844 } 3845 } 3846 3847 return response; 3848 } 3849 getDataCallResponse(Parcel p, int version)3850 private DataCallResponse getDataCallResponse(Parcel p, int version) { 3851 DataCallResponse dataCall = new DataCallResponse(); 3852 3853 dataCall.version = version; 3854 if (version < 5) { 3855 dataCall.cid = p.readInt(); 3856 dataCall.active = p.readInt(); 3857 dataCall.type = p.readString(); 3858 String addresses = p.readString(); 3859 if (!TextUtils.isEmpty(addresses)) { 3860 dataCall.addresses = addresses.split(" "); 3861 } 3862 } else { 3863 dataCall.status = p.readInt(); 3864 dataCall.suggestedRetryTime = p.readInt(); 3865 dataCall.cid = p.readInt(); 3866 dataCall.active = p.readInt(); 3867 dataCall.type = p.readString(); 3868 dataCall.ifname = p.readString(); 3869 if ((dataCall.status == DcFailCause.NONE.getErrorCode()) && 3870 TextUtils.isEmpty(dataCall.ifname)) { 3871 throw new RuntimeException("getDataCallResponse, no ifname"); 3872 } 3873 String addresses = p.readString(); 3874 if (!TextUtils.isEmpty(addresses)) { 3875 dataCall.addresses = addresses.split(" "); 3876 } 3877 String dnses = p.readString(); 3878 if (!TextUtils.isEmpty(dnses)) { 3879 dataCall.dnses = dnses.split(" "); 3880 } 3881 String gateways = p.readString(); 3882 if (!TextUtils.isEmpty(gateways)) { 3883 dataCall.gateways = gateways.split(" "); 3884 } 3885 if (version >= 10) { 3886 String pcscf = p.readString(); 3887 if (!TextUtils.isEmpty(pcscf)) { 3888 dataCall.pcscf = pcscf.split(" "); 3889 } 3890 } 3891 if (version >= 11) { 3892 dataCall.mtu = p.readInt(); 3893 } 3894 } 3895 return dataCall; 3896 } 3897 3898 private Object responseDataCallList(Parcel p)3899 responseDataCallList(Parcel p) { 3900 ArrayList<DataCallResponse> response; 3901 3902 int ver = p.readInt(); 3903 int num = p.readInt(); 3904 riljLog("responseDataCallList ver=" + ver + " num=" + num); 3905 3906 response = new ArrayList<DataCallResponse>(num); 3907 for (int i = 0; i < num; i++) { 3908 response.add(getDataCallResponse(p, ver)); 3909 } 3910 3911 mEventLog.writeRilDataCallList(response); 3912 3913 return response; 3914 } 3915 3916 private Object responseSetupDataCall(Parcel p)3917 responseSetupDataCall(Parcel p) { 3918 int ver = p.readInt(); 3919 int num = p.readInt(); 3920 if (RILJ_LOGV) riljLog("responseSetupDataCall ver=" + ver + " num=" + num); 3921 3922 DataCallResponse dataCall; 3923 3924 if (ver < 5) { 3925 dataCall = new DataCallResponse(); 3926 dataCall.version = ver; 3927 dataCall.cid = Integer.parseInt(p.readString()); 3928 dataCall.ifname = p.readString(); 3929 if (TextUtils.isEmpty(dataCall.ifname)) { 3930 throw new RuntimeException( 3931 "RIL_REQUEST_SETUP_DATA_CALL response, no ifname"); 3932 } 3933 String addresses = p.readString(); 3934 if (!TextUtils.isEmpty(addresses)) { 3935 dataCall.addresses = addresses.split(" "); 3936 } 3937 if (num >= 4) { 3938 String dnses = p.readString(); 3939 if (RILJ_LOGD) riljLog("responseSetupDataCall got dnses=" + dnses); 3940 if (!TextUtils.isEmpty(dnses)) { 3941 dataCall.dnses = dnses.split(" "); 3942 } 3943 } 3944 if (num >= 5) { 3945 String gateways = p.readString(); 3946 if (RILJ_LOGD) riljLog("responseSetupDataCall got gateways=" + gateways); 3947 if (!TextUtils.isEmpty(gateways)) { 3948 dataCall.gateways = gateways.split(" "); 3949 } 3950 } 3951 if (num >= 6) { 3952 String pcscf = p.readString(); 3953 if (RILJ_LOGD) riljLog("responseSetupDataCall got pcscf=" + pcscf); 3954 if (!TextUtils.isEmpty(pcscf)) { 3955 dataCall.pcscf = pcscf.split(" "); 3956 } 3957 } 3958 } else { 3959 if (num != 1) { 3960 throw new RuntimeException( 3961 "RIL_REQUEST_SETUP_DATA_CALL response expecting 1 RIL_Data_Call_response_v5" 3962 + " got " + num); 3963 } 3964 dataCall = getDataCallResponse(p, ver); 3965 } 3966 3967 return dataCall; 3968 } 3969 3970 private Object responseOperatorInfos(Parcel p)3971 responseOperatorInfos(Parcel p) { 3972 String strings[] = (String [])responseStrings(p); 3973 ArrayList<OperatorInfo> ret; 3974 3975 if (strings.length % 4 != 0) { 3976 throw new RuntimeException( 3977 "RIL_REQUEST_QUERY_AVAILABLE_NETWORKS: invalid response. Got " 3978 + strings.length + " strings, expected multible of 4"); 3979 } 3980 3981 ret = new ArrayList<OperatorInfo>(strings.length / 4); 3982 3983 for (int i = 0 ; i < strings.length ; i += 4) { 3984 ret.add ( 3985 new OperatorInfo( 3986 strings[i+0], 3987 strings[i+1], 3988 strings[i+2], 3989 strings[i+3])); 3990 } 3991 3992 return ret; 3993 } 3994 3995 private Object responseCellList(Parcel p)3996 responseCellList(Parcel p) { 3997 int num, rssi; 3998 String location; 3999 ArrayList<NeighboringCellInfo> response; 4000 NeighboringCellInfo cell; 4001 4002 num = p.readInt(); 4003 response = new ArrayList<NeighboringCellInfo>(); 4004 4005 // Determine the radio access type 4006 int[] subId = SubscriptionManager.getSubId(mInstanceId); 4007 int radioType = 4008 ((TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE)). 4009 getDataNetworkType(subId[0]); 4010 4011 // Interpret the location based on radio access type 4012 if (radioType != NETWORK_TYPE_UNKNOWN) { 4013 for (int i = 0 ; i < num ; i++) { 4014 rssi = p.readInt(); 4015 location = p.readString(); 4016 cell = new NeighboringCellInfo(rssi, location, radioType); 4017 response.add(cell); 4018 } 4019 } 4020 return response; 4021 } 4022 responseGetPreferredNetworkType(Parcel p)4023 private Object responseGetPreferredNetworkType(Parcel p) { 4024 int [] response = (int[]) responseInts(p); 4025 4026 if (response.length >= 1) { 4027 // Since this is the response for getPreferredNetworkType 4028 // we'll assume that it should be the value we want the 4029 // vendor ril to take if we reestablish a connection to it. 4030 mPreferredNetworkType = response[0]; 4031 } 4032 return response; 4033 } 4034 responseGmsBroadcastConfig(Parcel p)4035 private Object responseGmsBroadcastConfig(Parcel p) { 4036 int num; 4037 ArrayList<SmsBroadcastConfigInfo> response; 4038 SmsBroadcastConfigInfo info; 4039 4040 num = p.readInt(); 4041 response = new ArrayList<SmsBroadcastConfigInfo>(num); 4042 4043 for (int i = 0; i < num; i++) { 4044 int fromId = p.readInt(); 4045 int toId = p.readInt(); 4046 int fromScheme = p.readInt(); 4047 int toScheme = p.readInt(); 4048 boolean selected = (p.readInt() == 1); 4049 4050 info = new SmsBroadcastConfigInfo(fromId, toId, fromScheme, 4051 toScheme, selected); 4052 response.add(info); 4053 } 4054 return response; 4055 } 4056 4057 private Object responseCdmaBroadcastConfig(Parcel p)4058 responseCdmaBroadcastConfig(Parcel p) { 4059 int numServiceCategories; 4060 int response[]; 4061 4062 numServiceCategories = p.readInt(); 4063 4064 if (numServiceCategories == 0) { 4065 // TODO: The logic of providing default values should 4066 // not be done by this transport layer. And needs to 4067 // be done by the vendor ril or application logic. 4068 int numInts; 4069 numInts = CDMA_BROADCAST_SMS_NO_OF_SERVICE_CATEGORIES * CDMA_BSI_NO_OF_INTS_STRUCT + 1; 4070 response = new int[numInts]; 4071 4072 // Faking a default record for all possible records. 4073 response[0] = CDMA_BROADCAST_SMS_NO_OF_SERVICE_CATEGORIES; 4074 4075 // Loop over CDMA_BROADCAST_SMS_NO_OF_SERVICE_CATEGORIES set 'english' as 4076 // default language and selection status to false for all. 4077 for (int i = 1; i < numInts; i += CDMA_BSI_NO_OF_INTS_STRUCT ) { 4078 response[i + 0] = i / CDMA_BSI_NO_OF_INTS_STRUCT; 4079 response[i + 1] = 1; 4080 response[i + 2] = 0; 4081 } 4082 } else { 4083 int numInts; 4084 numInts = (numServiceCategories * CDMA_BSI_NO_OF_INTS_STRUCT) + 1; 4085 response = new int[numInts]; 4086 4087 response[0] = numServiceCategories; 4088 for (int i = 1 ; i < numInts; i++) { 4089 response[i] = p.readInt(); 4090 } 4091 } 4092 4093 return response; 4094 } 4095 4096 private Object responseSignalStrength(Parcel p)4097 responseSignalStrength(Parcel p) { 4098 // Assume this is gsm, but doesn't matter as ServiceStateTracker 4099 // sets the proper value. 4100 SignalStrength signalStrength = SignalStrength.makeSignalStrengthFromRilParcel(p); 4101 return signalStrength; 4102 } 4103 4104 private ArrayList<CdmaInformationRecords> responseCdmaInformationRecord(Parcel p)4105 responseCdmaInformationRecord(Parcel p) { 4106 int numberOfInfoRecs; 4107 ArrayList<CdmaInformationRecords> response; 4108 4109 /** 4110 * Loop through all of the information records unmarshalling them 4111 * and converting them to Java Objects. 4112 */ 4113 numberOfInfoRecs = p.readInt(); 4114 response = new ArrayList<CdmaInformationRecords>(numberOfInfoRecs); 4115 4116 for (int i = 0; i < numberOfInfoRecs; i++) { 4117 CdmaInformationRecords InfoRec = new CdmaInformationRecords(p); 4118 response.add(InfoRec); 4119 } 4120 4121 return response; 4122 } 4123 4124 private Object responseCdmaCallWaiting(Parcel p)4125 responseCdmaCallWaiting(Parcel p) { 4126 CdmaCallWaitingNotification notification = new CdmaCallWaitingNotification(); 4127 4128 notification.number = p.readString(); 4129 notification.numberPresentation = 4130 CdmaCallWaitingNotification.presentationFromCLIP(p.readInt()); 4131 notification.name = p.readString(); 4132 notification.namePresentation = notification.numberPresentation; 4133 notification.isPresent = p.readInt(); 4134 notification.signalType = p.readInt(); 4135 notification.alertPitch = p.readInt(); 4136 notification.signal = p.readInt(); 4137 notification.numberType = p.readInt(); 4138 notification.numberPlan = p.readInt(); 4139 4140 return notification; 4141 } 4142 4143 private Object responseCallRing(Parcel p)4144 responseCallRing(Parcel p){ 4145 char response[] = new char[4]; 4146 4147 response[0] = (char) p.readInt(); // isPresent 4148 response[1] = (char) p.readInt(); // signalType 4149 response[2] = (char) p.readInt(); // alertPitch 4150 response[3] = (char) p.readInt(); // signal 4151 4152 mEventLog.writeRilCallRing(response); 4153 4154 return response; 4155 } 4156 4157 private void notifyRegistrantsCdmaInfoRec(CdmaInformationRecords infoRec)4158 notifyRegistrantsCdmaInfoRec(CdmaInformationRecords infoRec) { 4159 int response = RIL_UNSOL_CDMA_INFO_REC; 4160 if (infoRec.record instanceof CdmaInformationRecords.CdmaDisplayInfoRec) { 4161 if (mDisplayInfoRegistrants != null) { 4162 if (RILJ_LOGD) unsljLogRet(response, infoRec.record); 4163 mDisplayInfoRegistrants.notifyRegistrants( 4164 new AsyncResult (null, infoRec.record, null)); 4165 } 4166 } else if (infoRec.record instanceof CdmaInformationRecords.CdmaSignalInfoRec) { 4167 if (mSignalInfoRegistrants != null) { 4168 if (RILJ_LOGD) unsljLogRet(response, infoRec.record); 4169 mSignalInfoRegistrants.notifyRegistrants( 4170 new AsyncResult (null, infoRec.record, null)); 4171 } 4172 } else if (infoRec.record instanceof CdmaInformationRecords.CdmaNumberInfoRec) { 4173 if (mNumberInfoRegistrants != null) { 4174 if (RILJ_LOGD) unsljLogRet(response, infoRec.record); 4175 mNumberInfoRegistrants.notifyRegistrants( 4176 new AsyncResult (null, infoRec.record, null)); 4177 } 4178 } else if (infoRec.record instanceof CdmaInformationRecords.CdmaRedirectingNumberInfoRec) { 4179 if (mRedirNumInfoRegistrants != null) { 4180 if (RILJ_LOGD) unsljLogRet(response, infoRec.record); 4181 mRedirNumInfoRegistrants.notifyRegistrants( 4182 new AsyncResult (null, infoRec.record, null)); 4183 } 4184 } else if (infoRec.record instanceof CdmaInformationRecords.CdmaLineControlInfoRec) { 4185 if (mLineControlInfoRegistrants != null) { 4186 if (RILJ_LOGD) unsljLogRet(response, infoRec.record); 4187 mLineControlInfoRegistrants.notifyRegistrants( 4188 new AsyncResult (null, infoRec.record, null)); 4189 } 4190 } else if (infoRec.record instanceof CdmaInformationRecords.CdmaT53ClirInfoRec) { 4191 if (mT53ClirInfoRegistrants != null) { 4192 if (RILJ_LOGD) unsljLogRet(response, infoRec.record); 4193 mT53ClirInfoRegistrants.notifyRegistrants( 4194 new AsyncResult (null, infoRec.record, null)); 4195 } 4196 } else if (infoRec.record instanceof CdmaInformationRecords.CdmaT53AudioControlInfoRec) { 4197 if (mT53AudCntrlInfoRegistrants != null) { 4198 if (RILJ_LOGD) unsljLogRet(response, infoRec.record); 4199 mT53AudCntrlInfoRegistrants.notifyRegistrants( 4200 new AsyncResult (null, infoRec.record, null)); 4201 } 4202 } 4203 } 4204 responseCellInfoList(Parcel p)4205 private ArrayList<CellInfo> responseCellInfoList(Parcel p) { 4206 int numberOfInfoRecs; 4207 ArrayList<CellInfo> response; 4208 4209 /** 4210 * Loop through all of the information records unmarshalling them 4211 * and converting them to Java Objects. 4212 */ 4213 numberOfInfoRecs = p.readInt(); 4214 response = new ArrayList<CellInfo>(numberOfInfoRecs); 4215 4216 for (int i = 0; i < numberOfInfoRecs; i++) { 4217 CellInfo InfoRec = CellInfo.CREATOR.createFromParcel(p); 4218 response.add(InfoRec); 4219 } 4220 4221 return response; 4222 } 4223 4224 private Object responseHardwareConfig(Parcel p)4225 responseHardwareConfig(Parcel p) { 4226 int num; 4227 ArrayList<HardwareConfig> response; 4228 HardwareConfig hw; 4229 4230 num = p.readInt(); 4231 response = new ArrayList<HardwareConfig>(num); 4232 4233 if (RILJ_LOGV) { 4234 riljLog("responseHardwareConfig: num=" + num); 4235 } 4236 for (int i = 0 ; i < num ; i++) { 4237 int type = p.readInt(); 4238 switch(type) { 4239 case HardwareConfig.DEV_HARDWARE_TYPE_MODEM: { 4240 hw = new HardwareConfig(type); 4241 hw.assignModem(p.readString(), p.readInt(), p.readInt(), 4242 p.readInt(), p.readInt(), p.readInt(), p.readInt()); 4243 break; 4244 } 4245 case HardwareConfig.DEV_HARDWARE_TYPE_SIM: { 4246 hw = new HardwareConfig(type); 4247 hw.assignSim(p.readString(), p.readInt(), p.readString()); 4248 break; 4249 } 4250 default: { 4251 throw new RuntimeException( 4252 "RIL_REQUEST_GET_HARDWARE_CONFIG invalid hardward type:" + type); 4253 } 4254 } 4255 4256 response.add(hw); 4257 } 4258 4259 return response; 4260 } 4261 4262 private Object responseRadioCapability(Parcel p)4263 responseRadioCapability(Parcel p) { 4264 int version = p.readInt(); 4265 int session = p.readInt(); 4266 int phase = p.readInt(); 4267 int rat = p.readInt(); 4268 String logicModemUuid = p.readString(); 4269 int status = p.readInt(); 4270 4271 riljLog("responseRadioCapability: version= " + version + 4272 ", session=" + session + 4273 ", phase=" + phase + 4274 ", rat=" + rat + 4275 ", logicModemUuid=" + logicModemUuid + 4276 ", status=" + status); 4277 RadioCapability rc = new RadioCapability( 4278 mInstanceId.intValue(), session, phase, rat, logicModemUuid, status); 4279 return rc; 4280 } 4281 responseLceData(Parcel p)4282 private Object responseLceData(Parcel p) { 4283 final ArrayList<Integer> capacityResponse = new ArrayList<Integer>(); 4284 final int capacityDownKbps = p.readInt(); 4285 final int confidenceLevel = p.readByte(); 4286 final int lceSuspended = p.readByte(); 4287 4288 riljLog("LCE capacity information received:" + 4289 " capacity=" + capacityDownKbps + 4290 " confidence=" + confidenceLevel + 4291 " lceSuspended=" + lceSuspended); 4292 4293 capacityResponse.add(capacityDownKbps); 4294 capacityResponse.add(confidenceLevel); 4295 capacityResponse.add(lceSuspended); 4296 return capacityResponse; 4297 } 4298 responseLceStatus(Parcel p)4299 private Object responseLceStatus(Parcel p) { 4300 final ArrayList<Integer> statusResponse = new ArrayList<Integer>(); 4301 final int lceStatus = (int)p.readByte(); 4302 final int actualInterval = p.readInt(); 4303 4304 riljLog("LCE status information received:" + 4305 " lceStatus=" + lceStatus + 4306 " actualInterval=" + actualInterval); 4307 statusResponse.add(lceStatus); 4308 statusResponse.add(actualInterval); 4309 return statusResponse; 4310 } 4311 responseActivityData(Parcel p)4312 private Object responseActivityData(Parcel p) { 4313 final int sleepModeTimeMs = p.readInt(); 4314 final int idleModeTimeMs = p.readInt(); 4315 int [] txModeTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; 4316 for (int i = 0; i < ModemActivityInfo.TX_POWER_LEVELS; i++) { 4317 txModeTimeMs[i] = p.readInt(); 4318 } 4319 final int rxModeTimeMs = p.readInt(); 4320 4321 riljLog("Modem activity info received:" + 4322 " sleepModeTimeMs=" + sleepModeTimeMs + 4323 " idleModeTimeMs=" + idleModeTimeMs + 4324 " txModeTimeMs[]=" + Arrays.toString(txModeTimeMs) + 4325 " rxModeTimeMs=" + rxModeTimeMs); 4326 4327 return new ModemActivityInfo(SystemClock.elapsedRealtime(), sleepModeTimeMs, 4328 idleModeTimeMs, txModeTimeMs, rxModeTimeMs, 0); 4329 } 4330 responseCarrierIdentifiers(Parcel p)4331 private Object responseCarrierIdentifiers(Parcel p) { 4332 List<CarrierIdentifier> retVal = new ArrayList<CarrierIdentifier>(); 4333 int len_allowed_carriers = p.readInt(); 4334 int len_excluded_carriers = p.readInt(); 4335 for (int i = 0; i < len_allowed_carriers; i++) { 4336 String mcc = p.readString(); 4337 String mnc = p.readString(); 4338 String spn = null, imsi = null, gid1 = null, gid2 = null; 4339 int matchType = p.readInt(); 4340 String matchData = p.readString(); 4341 if (matchType == CarrierIdentifier.MatchType.SPN) { 4342 spn = matchData; 4343 } else if (matchType == CarrierIdentifier.MatchType.IMSI_PREFIX) { 4344 imsi = matchData; 4345 } else if (matchType == CarrierIdentifier.MatchType.GID1) { 4346 gid1 = matchData; 4347 } else if (matchType == CarrierIdentifier.MatchType.GID2) { 4348 gid2 = matchData; 4349 } 4350 retVal.add(new CarrierIdentifier(mcc, mnc, spn, imsi, gid1, gid2)); 4351 } 4352 /* TODO: Handle excluded carriers */ 4353 return retVal; 4354 } 4355 responsePcoData(Parcel p)4356 private Object responsePcoData(Parcel p) { 4357 return new PcoData(p); 4358 } 4359 4360 4361 static String requestToString(int request)4362 requestToString(int request) { 4363 /* 4364 cat libs/telephony/ril_commands.h \ 4365 | egrep "^ *{RIL_" \ 4366 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/' 4367 */ 4368 switch(request) { 4369 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS"; 4370 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN"; 4371 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK"; 4372 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2"; 4373 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2"; 4374 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN"; 4375 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2"; 4376 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION"; 4377 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS"; 4378 case RIL_REQUEST_DIAL: return "DIAL"; 4379 case RIL_REQUEST_GET_IMSI: return "GET_IMSI"; 4380 case RIL_REQUEST_HANGUP: return "HANGUP"; 4381 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND"; 4382 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND"; 4383 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE"; 4384 case RIL_REQUEST_CONFERENCE: return "CONFERENCE"; 4385 case RIL_REQUEST_UDUB: return "UDUB"; 4386 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE"; 4387 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH"; 4388 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE"; 4389 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE"; 4390 case RIL_REQUEST_OPERATOR: return "OPERATOR"; 4391 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER"; 4392 case RIL_REQUEST_DTMF: return "DTMF"; 4393 case RIL_REQUEST_SEND_SMS: return "SEND_SMS"; 4394 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE"; 4395 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL"; 4396 case RIL_REQUEST_SIM_IO: return "SIM_IO"; 4397 case RIL_REQUEST_SEND_USSD: return "SEND_USSD"; 4398 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD"; 4399 case RIL_REQUEST_GET_CLIR: return "GET_CLIR"; 4400 case RIL_REQUEST_SET_CLIR: return "SET_CLIR"; 4401 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS"; 4402 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD"; 4403 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING"; 4404 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING"; 4405 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE"; 4406 case RIL_REQUEST_GET_IMEI: return "GET_IMEI"; 4407 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV"; 4408 case RIL_REQUEST_ANSWER: return "ANSWER"; 4409 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL"; 4410 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK"; 4411 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK"; 4412 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD"; 4413 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE"; 4414 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC"; 4415 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL"; 4416 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS "; 4417 case RIL_REQUEST_DTMF_START: return "DTMF_START"; 4418 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP"; 4419 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION"; 4420 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION"; 4421 case RIL_REQUEST_SET_MUTE: return "SET_MUTE"; 4422 case RIL_REQUEST_GET_MUTE: return "GET_MUTE"; 4423 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP"; 4424 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE"; 4425 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST"; 4426 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO"; 4427 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW"; 4428 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS"; 4429 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE"; 4430 case RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION: return "SET_SUPP_SVC_NOTIFICATION"; 4431 case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM"; 4432 case RIL_REQUEST_DELETE_SMS_ON_SIM: return "DELETE_SMS_ON_SIM"; 4433 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE"; 4434 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE"; 4435 case RIL_REQUEST_STK_GET_PROFILE: return "REQUEST_STK_GET_PROFILE"; 4436 case RIL_REQUEST_STK_SET_PROFILE: return "REQUEST_STK_SET_PROFILE"; 4437 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "REQUEST_STK_SEND_ENVELOPE_COMMAND"; 4438 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "REQUEST_STK_SEND_TERMINAL_RESPONSE"; 4439 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM"; 4440 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "REQUEST_EXPLICIT_CALL_TRANSFER"; 4441 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "REQUEST_SET_PREFERRED_NETWORK_TYPE"; 4442 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "REQUEST_GET_PREFERRED_NETWORK_TYPE"; 4443 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "REQUEST_GET_NEIGHBORING_CELL_IDS"; 4444 case RIL_REQUEST_SET_LOCATION_UPDATES: return "REQUEST_SET_LOCATION_UPDATES"; 4445 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE: return "RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE"; 4446 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE: return "RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE"; 4447 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE: return "RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE"; 4448 case RIL_REQUEST_SET_TTY_MODE: return "RIL_REQUEST_SET_TTY_MODE"; 4449 case RIL_REQUEST_QUERY_TTY_MODE: return "RIL_REQUEST_QUERY_TTY_MODE"; 4450 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE: return "RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE"; 4451 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE: return "RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE"; 4452 case RIL_REQUEST_CDMA_FLASH: return "RIL_REQUEST_CDMA_FLASH"; 4453 case RIL_REQUEST_CDMA_BURST_DTMF: return "RIL_REQUEST_CDMA_BURST_DTMF"; 4454 case RIL_REQUEST_CDMA_SEND_SMS: return "RIL_REQUEST_CDMA_SEND_SMS"; 4455 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE: return "RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE"; 4456 case RIL_REQUEST_GSM_GET_BROADCAST_CONFIG: return "RIL_REQUEST_GSM_GET_BROADCAST_CONFIG"; 4457 case RIL_REQUEST_GSM_SET_BROADCAST_CONFIG: return "RIL_REQUEST_GSM_SET_BROADCAST_CONFIG"; 4458 case RIL_REQUEST_CDMA_GET_BROADCAST_CONFIG: return "RIL_REQUEST_CDMA_GET_BROADCAST_CONFIG"; 4459 case RIL_REQUEST_CDMA_SET_BROADCAST_CONFIG: return "RIL_REQUEST_CDMA_SET_BROADCAST_CONFIG"; 4460 case RIL_REQUEST_GSM_BROADCAST_ACTIVATION: return "RIL_REQUEST_GSM_BROADCAST_ACTIVATION"; 4461 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return "RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY"; 4462 case RIL_REQUEST_CDMA_BROADCAST_ACTIVATION: return "RIL_REQUEST_CDMA_BROADCAST_ACTIVATION"; 4463 case RIL_REQUEST_CDMA_SUBSCRIPTION: return "RIL_REQUEST_CDMA_SUBSCRIPTION"; 4464 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM"; 4465 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM"; 4466 case RIL_REQUEST_DEVICE_IDENTITY: return "RIL_REQUEST_DEVICE_IDENTITY"; 4467 case RIL_REQUEST_GET_SMSC_ADDRESS: return "RIL_REQUEST_GET_SMSC_ADDRESS"; 4468 case RIL_REQUEST_SET_SMSC_ADDRESS: return "RIL_REQUEST_SET_SMSC_ADDRESS"; 4469 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "REQUEST_EXIT_EMERGENCY_CALLBACK_MODE"; 4470 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "RIL_REQUEST_REPORT_SMS_MEMORY_STATUS"; 4471 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING"; 4472 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE"; 4473 case RIL_REQUEST_ISIM_AUTHENTICATION: return "RIL_REQUEST_ISIM_AUTHENTICATION"; 4474 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU"; 4475 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS"; 4476 case RIL_REQUEST_VOICE_RADIO_TECH: return "RIL_REQUEST_VOICE_RADIO_TECH"; 4477 case RIL_REQUEST_GET_CELL_INFO_LIST: return "RIL_REQUEST_GET_CELL_INFO_LIST"; 4478 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return "RIL_REQUEST_SET_CELL_INFO_LIST_RATE"; 4479 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN"; 4480 case RIL_REQUEST_SET_DATA_PROFILE: return "RIL_REQUEST_SET_DATA_PROFILE"; 4481 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "RIL_REQUEST_IMS_REGISTRATION_STATE"; 4482 case RIL_REQUEST_IMS_SEND_SMS: return "RIL_REQUEST_IMS_SEND_SMS"; 4483 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC"; 4484 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "RIL_REQUEST_SIM_OPEN_CHANNEL"; 4485 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "RIL_REQUEST_SIM_CLOSE_CHANNEL"; 4486 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL"; 4487 case RIL_REQUEST_NV_READ_ITEM: return "RIL_REQUEST_NV_READ_ITEM"; 4488 case RIL_REQUEST_NV_WRITE_ITEM: return "RIL_REQUEST_NV_WRITE_ITEM"; 4489 case RIL_REQUEST_NV_WRITE_CDMA_PRL: return "RIL_REQUEST_NV_WRITE_CDMA_PRL"; 4490 case RIL_REQUEST_NV_RESET_CONFIG: return "RIL_REQUEST_NV_RESET_CONFIG"; 4491 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "RIL_REQUEST_SET_UICC_SUBSCRIPTION"; 4492 case RIL_REQUEST_ALLOW_DATA: return "RIL_REQUEST_ALLOW_DATA"; 4493 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG"; 4494 case RIL_REQUEST_SIM_AUTHENTICATION: return "RIL_REQUEST_SIM_AUTHENTICATION"; 4495 case RIL_REQUEST_SHUTDOWN: return "RIL_REQUEST_SHUTDOWN"; 4496 case RIL_REQUEST_SET_RADIO_CAPABILITY: 4497 return "RIL_REQUEST_SET_RADIO_CAPABILITY"; 4498 case RIL_REQUEST_GET_RADIO_CAPABILITY: 4499 return "RIL_REQUEST_GET_RADIO_CAPABILITY"; 4500 case RIL_REQUEST_START_LCE: return "RIL_REQUEST_START_LCE"; 4501 case RIL_REQUEST_STOP_LCE: return "RIL_REQUEST_STOP_LCE"; 4502 case RIL_REQUEST_PULL_LCEDATA: return "RIL_REQUEST_PULL_LCEDATA"; 4503 case RIL_REQUEST_GET_ACTIVITY_INFO: return "RIL_REQUEST_GET_ACTIVITY_INFO"; 4504 case RIL_REQUEST_SET_ALLOWED_CARRIERS: return "RIL_REQUEST_SET_ALLOWED_CARRIERS"; 4505 case RIL_REQUEST_GET_ALLOWED_CARRIERS: return "RIL_REQUEST_GET_ALLOWED_CARRIERS"; 4506 case RIL_RESPONSE_ACKNOWLEDGEMENT: return "RIL_RESPONSE_ACKNOWLEDGEMENT"; 4507 default: return "<unknown request>"; 4508 } 4509 } 4510 4511 static String responseToString(int request)4512 responseToString(int request) 4513 { 4514 /* 4515 cat libs/telephony/ril_unsol_commands.h \ 4516 | egrep "^ *{RIL_" \ 4517 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/' 4518 */ 4519 switch(request) { 4520 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED"; 4521 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED"; 4522 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED"; 4523 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS"; 4524 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT"; 4525 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM"; 4526 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD"; 4527 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST"; 4528 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED"; 4529 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH"; 4530 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED"; 4531 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION"; 4532 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END"; 4533 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND"; 4534 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY"; 4535 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP"; 4536 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FULL"; 4537 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH"; 4538 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING"; 4539 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED"; 4540 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_RESPONSE_CDMA_NEW_SMS"; 4541 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_RESPONSE_NEW_BROADCAST_SMS"; 4542 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL"; 4543 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED"; 4544 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE"; 4545 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING"; 4546 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS"; 4547 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC"; 4548 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW"; 4549 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE"; 4550 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE"; 4551 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "CDMA_SUBSCRIPTION_SOURCE_CHANGED"; 4552 case RIL_UNSOl_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED"; 4553 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE"; 4554 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED"; 4555 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED"; 4556 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST"; 4557 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: 4558 return "UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED"; 4559 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: 4560 return "RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED"; 4561 case RIL_UNSOL_SRVCC_STATE_NOTIFY: 4562 return "UNSOL_SRVCC_STATE_NOTIFY"; 4563 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "RIL_UNSOL_HARDWARE_CONFIG_CHANGED"; 4564 case RIL_UNSOL_RADIO_CAPABILITY: 4565 return "RIL_UNSOL_RADIO_CAPABILITY"; 4566 case RIL_UNSOL_ON_SS: return "UNSOL_ON_SS"; 4567 case RIL_UNSOL_STK_CC_ALPHA_NOTIFY: return "UNSOL_STK_CC_ALPHA_NOTIFY"; 4568 case RIL_UNSOL_LCEDATA_RECV: return "UNSOL_LCE_INFO_RECV"; 4569 case RIL_UNSOL_PCO_DATA: return "UNSOL_PCO_DATA"; 4570 default: return "<unknown response>"; 4571 } 4572 } 4573 riljLog(String msg)4574 private void riljLog(String msg) { 4575 Rlog.d(RILJ_LOG_TAG, msg 4576 + (mInstanceId != null ? (" [SUB" + mInstanceId + "]") : "")); 4577 } 4578 riljLogv(String msg)4579 private void riljLogv(String msg) { 4580 Rlog.v(RILJ_LOG_TAG, msg 4581 + (mInstanceId != null ? (" [SUB" + mInstanceId + "]") : "")); 4582 } 4583 unsljLog(int response)4584 private void unsljLog(int response) { 4585 riljLog("[UNSL]< " + responseToString(response)); 4586 } 4587 unsljLogMore(int response, String more)4588 private void unsljLogMore(int response, String more) { 4589 riljLog("[UNSL]< " + responseToString(response) + " " + more); 4590 } 4591 unsljLogRet(int response, Object ret)4592 private void unsljLogRet(int response, Object ret) { 4593 riljLog("[UNSL]< " + responseToString(response) + " " + retToString(response, ret)); 4594 } 4595 unsljLogvRet(int response, Object ret)4596 private void unsljLogvRet(int response, Object ret) { 4597 riljLogv("[UNSL]< " + responseToString(response) + " " + retToString(response, ret)); 4598 } 4599 4600 private Object responseSsData(Parcel p)4601 responseSsData(Parcel p) { 4602 int num; 4603 SsData ssData = new SsData(); 4604 4605 ssData.serviceType = ssData.ServiceTypeFromRILInt(p.readInt()); 4606 ssData.requestType = ssData.RequestTypeFromRILInt(p.readInt()); 4607 ssData.teleserviceType = ssData.TeleserviceTypeFromRILInt(p.readInt()); 4608 ssData.serviceClass = p.readInt(); // This is service class sent in the SS request. 4609 ssData.result = p.readInt(); // This is the result of the SS request. 4610 num = p.readInt(); 4611 4612 if (ssData.serviceType.isTypeCF() && 4613 ssData.requestType.isTypeInterrogation()) { 4614 ssData.cfInfo = new CallForwardInfo[num]; 4615 4616 for (int i = 0; i < num; i++) { 4617 ssData.cfInfo[i] = new CallForwardInfo(); 4618 4619 ssData.cfInfo[i].status = p.readInt(); 4620 ssData.cfInfo[i].reason = p.readInt(); 4621 ssData.cfInfo[i].serviceClass = p.readInt(); 4622 ssData.cfInfo[i].toa = p.readInt(); 4623 ssData.cfInfo[i].number = p.readString(); 4624 ssData.cfInfo[i].timeSeconds = p.readInt(); 4625 4626 riljLog("[SS Data] CF Info " + i + " : " + ssData.cfInfo[i]); 4627 } 4628 } else { 4629 ssData.ssInfo = new int[num]; 4630 for (int i = 0; i < num; i++) { 4631 ssData.ssInfo[i] = p.readInt(); 4632 riljLog("[SS Data] SS Info " + i + " : " + ssData.ssInfo[i]); 4633 } 4634 } 4635 4636 return ssData; 4637 } 4638 4639 4640 // ***** Methods for CDMA support 4641 @Override 4642 public void getDeviceIdentity(Message response)4643 getDeviceIdentity(Message response) { 4644 RILRequest rr = RILRequest.obtain(RIL_REQUEST_DEVICE_IDENTITY, response); 4645 4646 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 4647 4648 send(rr); 4649 } 4650 4651 @Override 4652 public void getCDMASubscription(Message response)4653 getCDMASubscription(Message response) { 4654 RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_SUBSCRIPTION, response); 4655 4656 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 4657 4658 send(rr); 4659 } 4660 4661 @Override setPhoneType(int phoneType)4662 public void setPhoneType(int phoneType) { // Called by GsmCdmaPhone 4663 if (RILJ_LOGD) riljLog("setPhoneType=" + phoneType + " old value=" + mPhoneType); 4664 mPhoneType = phoneType; 4665 } 4666 4667 /** 4668 * {@inheritDoc} 4669 */ 4670 @Override queryCdmaRoamingPreference(Message response)4671 public void queryCdmaRoamingPreference(Message response) { 4672 RILRequest rr = RILRequest.obtain( 4673 RILConstants.RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE, response); 4674 4675 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 4676 4677 send(rr); 4678 } 4679 4680 /** 4681 * {@inheritDoc} 4682 */ 4683 @Override setCdmaRoamingPreference(int cdmaRoamingType, Message response)4684 public void setCdmaRoamingPreference(int cdmaRoamingType, Message response) { 4685 RILRequest rr = RILRequest.obtain( 4686 RILConstants.RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE, response); 4687 4688 rr.mParcel.writeInt(1); 4689 rr.mParcel.writeInt(cdmaRoamingType); 4690 4691 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 4692 + " : " + cdmaRoamingType); 4693 4694 send(rr); 4695 } 4696 4697 /** 4698 * {@inheritDoc} 4699 */ 4700 @Override setCdmaSubscriptionSource(int cdmaSubscription , Message response)4701 public void setCdmaSubscriptionSource(int cdmaSubscription , Message response) { 4702 RILRequest rr = RILRequest.obtain( 4703 RILConstants.RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE, response); 4704 4705 rr.mParcel.writeInt(1); 4706 rr.mParcel.writeInt(cdmaSubscription); 4707 4708 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 4709 + " : " + cdmaSubscription); 4710 4711 send(rr); 4712 } 4713 4714 /** 4715 * {@inheritDoc} 4716 */ 4717 @Override getCdmaSubscriptionSource(Message response)4718 public void getCdmaSubscriptionSource(Message response) { 4719 RILRequest rr = RILRequest.obtain( 4720 RILConstants.RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE, response); 4721 4722 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 4723 4724 send(rr); 4725 } 4726 4727 /** 4728 * {@inheritDoc} 4729 */ 4730 @Override queryTTYMode(Message response)4731 public void queryTTYMode(Message response) { 4732 RILRequest rr = RILRequest.obtain( 4733 RILConstants.RIL_REQUEST_QUERY_TTY_MODE, response); 4734 4735 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 4736 4737 send(rr); 4738 } 4739 4740 /** 4741 * {@inheritDoc} 4742 */ 4743 @Override setTTYMode(int ttyMode, Message response)4744 public void setTTYMode(int ttyMode, Message response) { 4745 RILRequest rr = RILRequest.obtain( 4746 RILConstants.RIL_REQUEST_SET_TTY_MODE, response); 4747 4748 rr.mParcel.writeInt(1); 4749 rr.mParcel.writeInt(ttyMode); 4750 4751 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 4752 + " : " + ttyMode); 4753 4754 send(rr); 4755 } 4756 4757 /** 4758 * {@inheritDoc} 4759 */ 4760 @Override 4761 public void sendCDMAFeatureCode(String FeatureCode, Message response)4762 sendCDMAFeatureCode(String FeatureCode, Message response) { 4763 RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_FLASH, response); 4764 4765 rr.mParcel.writeString(FeatureCode); 4766 4767 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 4768 + " : " + FeatureCode); 4769 4770 send(rr); 4771 } 4772 4773 @Override getCdmaBroadcastConfig(Message response)4774 public void getCdmaBroadcastConfig(Message response) { 4775 RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_GET_BROADCAST_CONFIG, response); 4776 4777 send(rr); 4778 } 4779 4780 @Override setCdmaBroadcastConfig(CdmaSmsBroadcastConfigInfo[] configs, Message response)4781 public void setCdmaBroadcastConfig(CdmaSmsBroadcastConfigInfo[] configs, Message response) { 4782 RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_SET_BROADCAST_CONFIG, response); 4783 4784 // Convert to 1 service category per config (the way RIL takes is) 4785 ArrayList<CdmaSmsBroadcastConfigInfo> processedConfigs = 4786 new ArrayList<CdmaSmsBroadcastConfigInfo>(); 4787 for (CdmaSmsBroadcastConfigInfo config : configs) { 4788 for (int i = config.getFromServiceCategory(); i <= config.getToServiceCategory(); i++) { 4789 processedConfigs.add(new CdmaSmsBroadcastConfigInfo(i, 4790 i, 4791 config.getLanguage(), 4792 config.isSelected())); 4793 } 4794 } 4795 4796 CdmaSmsBroadcastConfigInfo[] rilConfigs = processedConfigs.toArray(configs); 4797 rr.mParcel.writeInt(rilConfigs.length); 4798 for(int i = 0; i < rilConfigs.length; i++) { 4799 rr.mParcel.writeInt(rilConfigs[i].getFromServiceCategory()); 4800 rr.mParcel.writeInt(rilConfigs[i].getLanguage()); 4801 rr.mParcel.writeInt(rilConfigs[i].isSelected() ? 1 : 0); 4802 } 4803 4804 if (RILJ_LOGD) { 4805 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 4806 + " with " + rilConfigs.length + " configs : "); 4807 for (int i = 0; i < rilConfigs.length; i++) { 4808 riljLog(rilConfigs[i].toString()); 4809 } 4810 } 4811 4812 send(rr); 4813 } 4814 4815 @Override setCdmaBroadcastActivation(boolean activate, Message response)4816 public void setCdmaBroadcastActivation(boolean activate, Message response) { 4817 RILRequest rr = RILRequest.obtain(RIL_REQUEST_CDMA_BROADCAST_ACTIVATION, response); 4818 4819 rr.mParcel.writeInt(1); 4820 rr.mParcel.writeInt(activate ? 0 :1); 4821 4822 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 4823 4824 send(rr); 4825 } 4826 4827 /** 4828 * {@inheritDoc} 4829 */ 4830 @Override exitEmergencyCallbackMode(Message response)4831 public void exitEmergencyCallbackMode(Message response) { 4832 RILRequest rr = RILRequest.obtain(RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE, response); 4833 4834 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 4835 4836 send(rr); 4837 } 4838 4839 @Override requestIsimAuthentication(String nonce, Message response)4840 public void requestIsimAuthentication(String nonce, Message response) { 4841 RILRequest rr = RILRequest.obtain(RIL_REQUEST_ISIM_AUTHENTICATION, response); 4842 4843 rr.mParcel.writeString(nonce); 4844 4845 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 4846 4847 send(rr); 4848 } 4849 4850 @Override requestIccSimAuthentication(int authContext, String data, String aid, Message response)4851 public void requestIccSimAuthentication(int authContext, String data, String aid, 4852 Message response) { 4853 RILRequest rr = RILRequest.obtain(RIL_REQUEST_SIM_AUTHENTICATION, response); 4854 4855 rr.mParcel.writeInt(authContext); 4856 rr.mParcel.writeString(data); 4857 rr.mParcel.writeString(aid); 4858 4859 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 4860 4861 send(rr); 4862 } 4863 4864 /** 4865 * {@inheritDoc} 4866 */ 4867 @Override getCellInfoList(Message result)4868 public void getCellInfoList(Message result) { 4869 RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_CELL_INFO_LIST, result); 4870 4871 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 4872 4873 send(rr); 4874 } 4875 4876 /** 4877 * {@inheritDoc} 4878 */ 4879 @Override setCellInfoListRate(int rateInMillis, Message response)4880 public void setCellInfoListRate(int rateInMillis, Message response) { 4881 if (RILJ_LOGD) riljLog("setCellInfoListRate: " + rateInMillis); 4882 RILRequest rr = RILRequest.obtain(RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE, response); 4883 4884 rr.mParcel.writeInt(1); 4885 rr.mParcel.writeInt(rateInMillis); 4886 4887 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 4888 4889 send(rr); 4890 } 4891 setInitialAttachApn(String apn, String protocol, int authType, String username, String password, Message result)4892 public void setInitialAttachApn(String apn, String protocol, int authType, String username, 4893 String password, Message result) { 4894 RILRequest rr = RILRequest.obtain(RIL_REQUEST_SET_INITIAL_ATTACH_APN, result); 4895 4896 if (RILJ_LOGD) riljLog("Set RIL_REQUEST_SET_INITIAL_ATTACH_APN"); 4897 4898 rr.mParcel.writeString(apn); 4899 rr.mParcel.writeString(protocol); 4900 rr.mParcel.writeInt(authType); 4901 rr.mParcel.writeString(username); 4902 rr.mParcel.writeString(password); 4903 4904 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 4905 + ", apn:" + apn + ", protocol:" + protocol + ", authType:" + authType 4906 + ", username:" + username + ", password:" + password); 4907 4908 send(rr); 4909 } 4910 setDataProfile(DataProfile[] dps, Message result)4911 public void setDataProfile(DataProfile[] dps, Message result) { 4912 if (RILJ_LOGD) riljLog("Set RIL_REQUEST_SET_DATA_PROFILE"); 4913 4914 RILRequest rr = RILRequest.obtain(RIL_REQUEST_SET_DATA_PROFILE, null); 4915 DataProfile.toParcel(rr.mParcel, dps); 4916 4917 if (RILJ_LOGD) { 4918 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 4919 + " with " + dps + " Data Profiles : "); 4920 for (int i = 0; i < dps.length; i++) { 4921 riljLog(dps[i].toString()); 4922 } 4923 } 4924 4925 send(rr); 4926 } 4927 4928 /* (non-Javadoc) 4929 * @see com.android.internal.telephony.BaseCommands#testingEmergencyCall() 4930 */ 4931 @Override testingEmergencyCall()4932 public void testingEmergencyCall() { 4933 if (RILJ_LOGD) riljLog("testingEmergencyCall"); 4934 mTestingEmergencyCall.set(true); 4935 } 4936 dump(FileDescriptor fd, PrintWriter pw, String[] args)4937 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 4938 pw.println("RIL: " + this); 4939 pw.println(" mSocket=" + mSocket); 4940 pw.println(" mSenderThread=" + mSenderThread); 4941 pw.println(" mSender=" + mSender); 4942 pw.println(" mReceiverThread=" + mReceiverThread); 4943 pw.println(" mReceiver=" + mReceiver); 4944 pw.println(" mWakeLock=" + mWakeLock); 4945 pw.println(" mWakeLockTimeout=" + mWakeLockTimeout); 4946 synchronized (mRequestList) { 4947 synchronized (mWakeLock) { 4948 pw.println(" mWakeLockCount=" + mWakeLockCount); 4949 } 4950 int count = mRequestList.size(); 4951 pw.println(" mRequestList count=" + count); 4952 for (int i = 0; i < count; i++) { 4953 RILRequest rr = mRequestList.valueAt(i); 4954 pw.println(" [" + rr.mSerial + "] " + requestToString(rr.mRequest)); 4955 } 4956 } 4957 pw.println(" mLastNITZTimeInfo=" + Arrays.toString(mLastNITZTimeInfo)); 4958 pw.println(" mTestingEmergencyCall=" + mTestingEmergencyCall.get()); 4959 } 4960 4961 /** 4962 * {@inheritDoc} 4963 */ 4964 @Override iccOpenLogicalChannel(String AID, Message response)4965 public void iccOpenLogicalChannel(String AID, Message response) { 4966 RILRequest rr = RILRequest.obtain(RIL_REQUEST_SIM_OPEN_CHANNEL, response); 4967 rr.mParcel.writeString(AID); 4968 4969 if (RILJ_LOGD) 4970 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 4971 4972 send(rr); 4973 } 4974 4975 /** 4976 * {@inheritDoc} 4977 */ 4978 @Override iccCloseLogicalChannel(int channel, Message response)4979 public void iccCloseLogicalChannel(int channel, Message response) { 4980 RILRequest rr = RILRequest.obtain(RIL_REQUEST_SIM_CLOSE_CHANNEL, response); 4981 rr.mParcel.writeInt(1); 4982 rr.mParcel.writeInt(channel); 4983 4984 if (RILJ_LOGD) 4985 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 4986 4987 send(rr); 4988 } 4989 4990 /** 4991 * {@inheritDoc} 4992 */ 4993 @Override iccTransmitApduLogicalChannel(int channel, int cla, int instruction, int p1, int p2, int p3, String data, Message response)4994 public void iccTransmitApduLogicalChannel(int channel, int cla, int instruction, 4995 int p1, int p2, int p3, String data, Message response) { 4996 if (channel <= 0) { 4997 throw new RuntimeException( 4998 "Invalid channel in iccTransmitApduLogicalChannel: " + channel); 4999 } 5000 5001 iccTransmitApduHelper(RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL, channel, cla, 5002 instruction, p1, p2, p3, data, response); 5003 } 5004 5005 /** 5006 * {@inheritDoc} 5007 */ 5008 @Override iccTransmitApduBasicChannel(int cla, int instruction, int p1, int p2, int p3, String data, Message response)5009 public void iccTransmitApduBasicChannel(int cla, int instruction, int p1, int p2, 5010 int p3, String data, Message response) { 5011 iccTransmitApduHelper(RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC, 0, cla, instruction, 5012 p1, p2, p3, data, response); 5013 } 5014 5015 /* 5016 * Helper function for the iccTransmitApdu* commands above. 5017 */ iccTransmitApduHelper(int rilCommand, int channel, int cla, int instruction, int p1, int p2, int p3, String data, Message response)5018 private void iccTransmitApduHelper(int rilCommand, int channel, int cla, 5019 int instruction, int p1, int p2, int p3, String data, Message response) { 5020 RILRequest rr = RILRequest.obtain(rilCommand, response); 5021 rr.mParcel.writeInt(channel); 5022 rr.mParcel.writeInt(cla); 5023 rr.mParcel.writeInt(instruction); 5024 rr.mParcel.writeInt(p1); 5025 rr.mParcel.writeInt(p2); 5026 rr.mParcel.writeInt(p3); 5027 rr.mParcel.writeString(data); 5028 5029 if (RILJ_LOGD) 5030 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 5031 5032 send(rr); 5033 } 5034 5035 @Override nvReadItem(int itemID, Message response)5036 public void nvReadItem(int itemID, Message response) { 5037 RILRequest rr = RILRequest.obtain(RIL_REQUEST_NV_READ_ITEM, response); 5038 5039 rr.mParcel.writeInt(itemID); 5040 5041 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 5042 + ' ' + itemID); 5043 5044 send(rr); 5045 } 5046 5047 @Override nvWriteItem(int itemID, String itemValue, Message response)5048 public void nvWriteItem(int itemID, String itemValue, Message response) { 5049 RILRequest rr = RILRequest.obtain(RIL_REQUEST_NV_WRITE_ITEM, response); 5050 5051 rr.mParcel.writeInt(itemID); 5052 rr.mParcel.writeString(itemValue); 5053 5054 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 5055 + ' ' + itemID + ": " + itemValue); 5056 5057 send(rr); 5058 } 5059 5060 @Override nvWriteCdmaPrl(byte[] preferredRoamingList, Message response)5061 public void nvWriteCdmaPrl(byte[] preferredRoamingList, Message response) { 5062 RILRequest rr = RILRequest.obtain(RIL_REQUEST_NV_WRITE_CDMA_PRL, response); 5063 5064 rr.mParcel.writeByteArray(preferredRoamingList); 5065 5066 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 5067 + " (" + preferredRoamingList.length + " bytes)"); 5068 5069 send(rr); 5070 } 5071 5072 @Override nvResetConfig(int resetType, Message response)5073 public void nvResetConfig(int resetType, Message response) { 5074 RILRequest rr = RILRequest.obtain(RIL_REQUEST_NV_RESET_CONFIG, response); 5075 5076 rr.mParcel.writeInt(1); 5077 rr.mParcel.writeInt(resetType); 5078 5079 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 5080 + ' ' + resetType); 5081 5082 send(rr); 5083 } 5084 5085 @Override setRadioCapability(RadioCapability rc, Message response)5086 public void setRadioCapability(RadioCapability rc, Message response) { 5087 RILRequest rr = RILRequest.obtain( 5088 RIL_REQUEST_SET_RADIO_CAPABILITY, response); 5089 5090 rr.mParcel.writeInt(rc.getVersion()); 5091 rr.mParcel.writeInt(rc.getSession()); 5092 rr.mParcel.writeInt(rc.getPhase()); 5093 rr.mParcel.writeInt(rc.getRadioAccessFamily()); 5094 rr.mParcel.writeString(rc.getLogicalModemUuid()); 5095 rr.mParcel.writeInt(rc.getStatus()); 5096 5097 if (RILJ_LOGD) { 5098 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) 5099 + " " + rc.toString()); 5100 } 5101 5102 send(rr); 5103 } 5104 5105 @Override getRadioCapability(Message response)5106 public void getRadioCapability(Message response) { 5107 RILRequest rr = RILRequest.obtain( 5108 RIL_REQUEST_GET_RADIO_CAPABILITY, response); 5109 5110 if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 5111 5112 send(rr); 5113 } 5114 5115 @Override startLceService(int reportIntervalMs, boolean pullMode, Message response)5116 public void startLceService(int reportIntervalMs, boolean pullMode, Message response) { 5117 RILRequest rr = RILRequest.obtain(RIL_REQUEST_START_LCE, response); 5118 /** solicited command argument: reportIntervalMs, pullMode. */ 5119 rr.mParcel.writeInt(2); 5120 rr.mParcel.writeInt(reportIntervalMs); 5121 rr.mParcel.writeInt(pullMode ? 1: 0); // PULL mode: 1; PUSH mode: 0; 5122 5123 if (RILJ_LOGD) { 5124 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 5125 } 5126 5127 send(rr); 5128 } 5129 5130 @Override stopLceService(Message response)5131 public void stopLceService(Message response) { 5132 RILRequest rr = RILRequest.obtain(RIL_REQUEST_STOP_LCE, response); 5133 if (RILJ_LOGD) { 5134 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 5135 } 5136 send(rr); 5137 } 5138 5139 @Override pullLceData(Message response)5140 public void pullLceData(Message response) { 5141 RILRequest rr = RILRequest.obtain(RIL_REQUEST_PULL_LCEDATA, response); 5142 if (RILJ_LOGD) { 5143 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 5144 } 5145 send(rr); 5146 } 5147 5148 /** 5149 * @hide 5150 */ getModemActivityInfo(Message response)5151 public void getModemActivityInfo(Message response) { 5152 RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_ACTIVITY_INFO, response); 5153 if (RILJ_LOGD) { 5154 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 5155 } 5156 send(rr); 5157 5158 Message msg = mSender.obtainMessage(EVENT_BLOCKING_RESPONSE_TIMEOUT); 5159 msg.obj = null; 5160 msg.arg1 = rr.mSerial; 5161 mSender.sendMessageDelayed(msg, DEFAULT_BLOCKING_MESSAGE_RESPONSE_TIMEOUT_MS); 5162 } 5163 5164 @Override setAllowedCarriers(List<CarrierIdentifier> carriers, Message response)5165 public void setAllowedCarriers(List<CarrierIdentifier> carriers, Message response) { 5166 RILRequest rr = RILRequest.obtain(RIL_REQUEST_SET_ALLOWED_CARRIERS, response); 5167 rr.mParcel.writeInt(carriers.size()); /* len_allowed_carriers */ 5168 rr.mParcel.writeInt(0); /* len_excluded_carriers */ /* TODO: add excluded carriers */ 5169 for (CarrierIdentifier ci : carriers) { /* allowed carriers */ 5170 rr.mParcel.writeString(ci.getMcc()); 5171 rr.mParcel.writeString(ci.getMnc()); 5172 int matchType = CarrierIdentifier.MatchType.ALL; 5173 String matchData = null; 5174 if (!TextUtils.isEmpty(ci.getSpn())) { 5175 matchType = CarrierIdentifier.MatchType.SPN; 5176 matchData = ci.getSpn(); 5177 } else if (!TextUtils.isEmpty(ci.getImsi())) { 5178 matchType = CarrierIdentifier.MatchType.IMSI_PREFIX; 5179 matchData = ci.getImsi(); 5180 } else if (!TextUtils.isEmpty(ci.getGid1())) { 5181 matchType = CarrierIdentifier.MatchType.GID1; 5182 matchData = ci.getGid1(); 5183 } else if (!TextUtils.isEmpty(ci.getGid2())) { 5184 matchType = CarrierIdentifier.MatchType.GID2; 5185 matchData = ci.getGid2(); 5186 } 5187 rr.mParcel.writeInt(matchType); 5188 rr.mParcel.writeString(matchData); 5189 } 5190 /* TODO: add excluded carriers */ 5191 5192 if (RILJ_LOGD) { 5193 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 5194 } 5195 send(rr); 5196 } 5197 5198 @Override getAllowedCarriers(Message response)5199 public void getAllowedCarriers(Message response) { 5200 RILRequest rr = RILRequest.obtain(RIL_REQUEST_GET_ALLOWED_CARRIERS, response); 5201 if (RILJ_LOGD) { 5202 riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); 5203 } 5204 send(rr); 5205 } 5206 } 5207