CDMAPhone.java revision 454b1dfd508844b42eb775e4ab2359be74d3672b
1/* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.internal.telephony.cdma; 18 19import android.app.ActivityManagerNative; 20import android.content.ContentValues; 21import android.content.Context; 22import android.content.Intent; 23import android.content.SharedPreferences; 24import android.database.SQLException; 25import android.net.Uri; 26import android.os.AsyncResult; 27import android.os.Handler; 28import android.os.Message; 29import android.os.PowerManager; 30import android.os.PowerManager.WakeLock; 31import android.os.Registrant; 32import android.os.RegistrantList; 33import android.os.SystemProperties; 34import android.os.UserHandle; 35import android.preference.PreferenceManager; 36import android.provider.Telephony; 37import android.telephony.CellLocation; 38import android.telephony.PhoneNumberUtils; 39import android.telephony.ServiceState; 40import android.text.TextUtils; 41import android.telephony.Rlog; 42 43import com.android.internal.telephony.CallStateException; 44import com.android.internal.telephony.CallTracker; 45import com.android.internal.telephony.CommandException; 46import com.android.internal.telephony.CommandsInterface; 47import com.android.internal.telephony.Connection; 48import com.android.internal.telephony.IccPhoneBookInterfaceManager; 49import com.android.internal.telephony.IccSmsInterfaceManager; 50import com.android.internal.telephony.MccTable; 51import com.android.internal.telephony.MmiCode; 52import com.android.internal.telephony.OperatorInfo; 53import com.android.internal.telephony.PhoneBase; 54import com.android.internal.telephony.PhoneConstants; 55import com.android.internal.telephony.PhoneNotifier; 56import com.android.internal.telephony.PhoneProxy; 57import com.android.internal.telephony.PhoneSubInfo; 58import com.android.internal.telephony.ServiceStateTracker; 59import com.android.internal.telephony.TelephonyIntents; 60import com.android.internal.telephony.TelephonyProperties; 61import com.android.internal.telephony.UUSInfo; 62import com.android.internal.telephony.dataconnection.DcTracker; 63import com.android.internal.telephony.uicc.IccException; 64import com.android.internal.telephony.uicc.IccRecords; 65import com.android.internal.telephony.uicc.RuimRecords; 66import com.android.internal.telephony.uicc.UiccCardApplication; 67import com.android.internal.telephony.uicc.UiccController; 68import java.io.FileDescriptor; 69import java.io.PrintWriter; 70import java.util.ArrayList; 71import java.util.List; 72import java.util.regex.Matcher; 73import java.util.regex.Pattern; 74 75import static com.android.internal.telephony.TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA; 76import static com.android.internal.telephony.TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY; 77import static com.android.internal.telephony.TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC; 78 79/** 80 * {@hide} 81 */ 82public class CDMAPhone extends PhoneBase { 83 static final String LOG_TAG = "CDMAPhone"; 84 private static final boolean DBG = true; 85 private static final boolean VDBG = false; /* STOP SHIP if true */ 86 87 // Default Emergency Callback Mode exit timer 88 private static final int DEFAULT_ECM_EXIT_TIMER_VALUE = 300000; 89 90 static final String VM_COUNT_CDMA = "vm_count_key_cdma"; 91 private static final String VM_NUMBER_CDMA = "vm_number_key_cdma"; 92 private String mVmNumber = null; 93 94 static final int RESTART_ECM_TIMER = 0; // restart Ecm timer 95 static final int CANCEL_ECM_TIMER = 1; // cancel Ecm timer 96 97 // Instance Variables 98 CdmaCallTracker mCT; 99 CdmaServiceStateTracker mSST; 100 CdmaSubscriptionSourceManager mCdmaSSM; 101 ArrayList <CdmaMmiCode> mPendingMmis = new ArrayList<CdmaMmiCode>(); 102 RuimPhoneBookInterfaceManager mRuimPhoneBookInterfaceManager; 103 RuimSmsInterfaceManager mRuimSmsInterfaceManager; 104 int mCdmaSubscriptionSource = CdmaSubscriptionSourceManager.SUBSCRIPTION_SOURCE_UNKNOWN; 105 PhoneSubInfo mSubInfo; 106 EriManager mEriManager; 107 WakeLock mWakeLock; 108 109 // mEriFileLoadedRegistrants are informed after the ERI text has been loaded 110 private final RegistrantList mEriFileLoadedRegistrants = new RegistrantList(); 111 112 // mEcmTimerResetRegistrants are informed after Ecm timer is canceled or re-started 113 private final RegistrantList mEcmTimerResetRegistrants = new RegistrantList(); 114 115 // mEcmExitRespRegistrant is informed after the phone has been exited 116 //the emergency callback mode 117 //keep track of if phone is in emergency callback mode 118 private boolean mIsPhoneInEcmState; 119 private Registrant mEcmExitRespRegistrant; 120 protected String mImei; 121 protected String mImeiSv; 122 private String mEsn; 123 private String mMeid; 124 // string to define how the carrier specifies its own ota sp number 125 private String mCarrierOtaSpNumSchema; 126 127 // A runnable which is used to automatically exit from Ecm after a period of time. 128 private Runnable mExitEcmRunnable = new Runnable() { 129 @Override 130 public void run() { 131 exitEmergencyCallbackMode(); 132 } 133 }; 134 135 Registrant mPostDialHandler; 136 137 static String PROPERTY_CDMA_HOME_OPERATOR_NUMERIC = "ro.cdma.home.operator.numeric"; 138 139 // Constructors 140 public CDMAPhone(Context context, CommandsInterface ci, PhoneNotifier notifier) { 141 super("CDMA", notifier, context, ci, false); 142 initSstIcc(); 143 init(context, notifier); 144 } 145 146 public CDMAPhone(Context context, CommandsInterface ci, PhoneNotifier notifier, 147 boolean unitTestMode) { 148 super("CDMA", notifier, context, ci, unitTestMode); 149 initSstIcc(); 150 init(context, notifier); 151 } 152 153 protected void initSstIcc() { 154 mSST = new CdmaServiceStateTracker(this); 155 } 156 157 protected void init(Context context, PhoneNotifier notifier) { 158 mCi.setPhoneType(PhoneConstants.PHONE_TYPE_CDMA); 159 mCT = new CdmaCallTracker(this); 160 mCdmaSSM = CdmaSubscriptionSourceManager.getInstance(context, mCi, this, 161 EVENT_CDMA_SUBSCRIPTION_SOURCE_CHANGED, null); 162 mSMS = new CdmaSMSDispatcher(this, mSmsStorageMonitor, mSmsUsageMonitor); 163 mDcTracker = new DcTracker(this); 164 mRuimPhoneBookInterfaceManager = new RuimPhoneBookInterfaceManager(this); 165 mRuimSmsInterfaceManager = new RuimSmsInterfaceManager(this, mSMS); 166 mSubInfo = new PhoneSubInfo(this); 167 mEriManager = new EriManager(this, context, EriManager.ERI_FROM_XML); 168 169 mCi.registerForAvailable(this, EVENT_RADIO_AVAILABLE, null); 170 mCi.registerForOffOrNotAvailable(this, EVENT_RADIO_OFF_OR_NOT_AVAILABLE, null); 171 mCi.registerForOn(this, EVENT_RADIO_ON, null); 172 mCi.setOnSuppServiceNotification(this, EVENT_SSN, null); 173 mSST.registerForNetworkAttached(this, EVENT_REGISTERED_TO_NETWORK, null); 174 mCi.setEmergencyCallbackMode(this, EVENT_EMERGENCY_CALLBACK_MODE_ENTER, null); 175 176 PowerManager pm 177 = (PowerManager) context.getSystemService(Context.POWER_SERVICE); 178 mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,LOG_TAG); 179 180 //Change the system setting 181 SystemProperties.set(TelephonyProperties.CURRENT_ACTIVE_PHONE, 182 Integer.toString(PhoneConstants.PHONE_TYPE_CDMA)); 183 184 // This is needed to handle phone process crashes 185 String inEcm=SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE, "false"); 186 mIsPhoneInEcmState = inEcm.equals("true"); 187 if (mIsPhoneInEcmState) { 188 // Send a message which will invoke handleExitEmergencyCallbackMode 189 mCi.exitEmergencyCallbackMode(obtainMessage(EVENT_EXIT_EMERGENCY_CALLBACK_RESPONSE)); 190 } 191 192 // get the string that specifies the carrier OTA Sp number 193 mCarrierOtaSpNumSchema = SystemProperties.get( 194 TelephonyProperties.PROPERTY_OTASP_NUM_SCHEMA,""); 195 196 // Sets operator alpha property by retrieving from build-time system property 197 String operatorAlpha = SystemProperties.get("ro.cdma.home.operator.alpha"); 198 setSystemProperty(PROPERTY_ICC_OPERATOR_ALPHA, operatorAlpha); 199 200 // Sets operator numeric property by retrieving from build-time system property 201 String operatorNumeric = SystemProperties.get(PROPERTY_CDMA_HOME_OPERATOR_NUMERIC); 202 log("CDMAPhone: init set 'gsm.sim.operator.numeric' to operator='" + 203 operatorNumeric + "'"); 204 setSystemProperty(PROPERTY_ICC_OPERATOR_NUMERIC, operatorNumeric); 205 206 // Sets iso country property by retrieving from build-time system property 207 setIsoCountryProperty(operatorNumeric); 208 209 // Sets current entry in the telephony carrier table 210 updateCurrentCarrierInProvider(operatorNumeric); 211 212 // Notify voicemails. 213 notifier.notifyMessageWaitingChanged(this); 214 } 215 216 @Override 217 public void dispose() { 218 synchronized(PhoneProxy.lockForRadioTechnologyChange) { 219 super.dispose(); 220 log("dispose"); 221 222 //Unregister from all former registered events 223 unregisterForRuimRecordEvents(); 224 mCi.unregisterForAvailable(this); //EVENT_RADIO_AVAILABLE 225 mCi.unregisterForOffOrNotAvailable(this); //EVENT_RADIO_OFF_OR_NOT_AVAILABLE 226 mCi.unregisterForOn(this); //EVENT_RADIO_ON 227 mSST.unregisterForNetworkAttached(this); //EVENT_REGISTERED_TO_NETWORK 228 mCi.unSetOnSuppServiceNotification(this); 229 removeCallbacks(mExitEcmRunnable); 230 231 mPendingMmis.clear(); 232 233 //Force all referenced classes to unregister their former registered events 234 mCT.dispose(); 235 mDcTracker.dispose(); 236 mSST.dispose(); 237 mCdmaSSM.dispose(this); 238 mSMS.dispose(); 239 mRuimPhoneBookInterfaceManager.dispose(); 240 mRuimSmsInterfaceManager.dispose(); 241 mSubInfo.dispose(); 242 mEriManager.dispose(); 243 } 244 } 245 246 @Override 247 public void removeReferences() { 248 log("removeReferences"); 249 mRuimPhoneBookInterfaceManager = null; 250 mRuimSmsInterfaceManager = null; 251 mSubInfo = null; 252 mCT = null; 253 mSST = null; 254 mEriManager = null; 255 mExitEcmRunnable = null; 256 super.removeReferences(); 257 } 258 259 @Override 260 protected void finalize() { 261 if(DBG) Rlog.d(LOG_TAG, "CDMAPhone finalized"); 262 if (mWakeLock.isHeld()) { 263 Rlog.e(LOG_TAG, "UNEXPECTED; mWakeLock is held when finalizing."); 264 mWakeLock.release(); 265 } 266 } 267 268 @Override 269 public ServiceState getServiceState() { 270 return mSST.mSS; 271 } 272 273 @Override 274 public CallTracker getCallTracker() { 275 return mCT; 276 } 277 278 @Override 279 public PhoneConstants.State getState() { 280 return mCT.mState; 281 } 282 283 @Override 284 public ServiceStateTracker getServiceStateTracker() { 285 return mSST; 286 } 287 288 @Override 289 public int getPhoneType() { 290 return PhoneConstants.PHONE_TYPE_CDMA; 291 } 292 293 @Override 294 public boolean canTransfer() { 295 Rlog.e(LOG_TAG, "canTransfer: not possible in CDMA"); 296 return false; 297 } 298 299 @Override 300 public CdmaCall getRingingCall() { 301 return mCT.mRingingCall; 302 } 303 304 @Override 305 public void setMute(boolean muted) { 306 mCT.setMute(muted); 307 } 308 309 @Override 310 public boolean getMute() { 311 return mCT.getMute(); 312 } 313 314 @Override 315 public void conference() { 316 // three way calls in CDMA will be handled by feature codes 317 Rlog.e(LOG_TAG, "conference: not possible in CDMA"); 318 } 319 320 @Override 321 public void enableEnhancedVoicePrivacy(boolean enable, Message onComplete) { 322 mCi.setPreferredVoicePrivacy(enable, onComplete); 323 } 324 325 @Override 326 public void getEnhancedVoicePrivacy(Message onComplete) { 327 mCi.getPreferredVoicePrivacy(onComplete); 328 } 329 330 @Override 331 public void clearDisconnected() { 332 mCT.clearDisconnected(); 333 } 334 335 @Override 336 public DataActivityState getDataActivityState() { 337 DataActivityState ret = DataActivityState.NONE; 338 339 if (mSST.getCurrentDataConnectionState() == ServiceState.STATE_IN_SERVICE) { 340 341 switch (mDcTracker.getActivity()) { 342 case DATAIN: 343 ret = DataActivityState.DATAIN; 344 break; 345 346 case DATAOUT: 347 ret = DataActivityState.DATAOUT; 348 break; 349 350 case DATAINANDOUT: 351 ret = DataActivityState.DATAINANDOUT; 352 break; 353 354 case DORMANT: 355 ret = DataActivityState.DORMANT; 356 break; 357 358 default: 359 ret = DataActivityState.NONE; 360 break; 361 } 362 } 363 return ret; 364 } 365 366 @Override 367 public Connection 368 dial (String dialString) throws CallStateException { 369 // Need to make sure dialString gets parsed properly 370 String newDialString = PhoneNumberUtils.stripSeparators(dialString); 371 return mCT.dial(newDialString); 372 } 373 374 @Override 375 public Connection dial(String dialString, UUSInfo uusInfo) throws CallStateException { 376 throw new CallStateException("Sending UUS information NOT supported in CDMA!"); 377 } 378 379 @Override 380 public boolean 381 getMessageWaitingIndicator() { 382 return (getVoiceMessageCount() > 0); 383 } 384 385 @Override 386 public List<? extends MmiCode> 387 getPendingMmiCodes() { 388 return mPendingMmis; 389 } 390 391 @Override 392 public void registerForSuppServiceNotification( 393 Handler h, int what, Object obj) { 394 Rlog.e(LOG_TAG, "method registerForSuppServiceNotification is NOT supported in CDMA!"); 395 } 396 397 @Override 398 public CdmaCall getBackgroundCall() { 399 return mCT.mBackgroundCall; 400 } 401 402 @Override 403 public boolean handleInCallMmiCommands(String dialString) { 404 Rlog.e(LOG_TAG, "method handleInCallMmiCommands is NOT supported in CDMA!"); 405 return false; 406 } 407 408 boolean isInCall() { 409 CdmaCall.State foregroundCallState = getForegroundCall().getState(); 410 CdmaCall.State backgroundCallState = getBackgroundCall().getState(); 411 CdmaCall.State ringingCallState = getRingingCall().getState(); 412 413 return (foregroundCallState.isAlive() || backgroundCallState.isAlive() || ringingCallState 414 .isAlive()); 415 } 416 417 @Override 418 public void 419 setNetworkSelectionModeAutomatic(Message response) { 420 Rlog.e(LOG_TAG, "method setNetworkSelectionModeAutomatic is NOT supported in CDMA!"); 421 } 422 423 @Override 424 public void unregisterForSuppServiceNotification(Handler h) { 425 Rlog.e(LOG_TAG, "method unregisterForSuppServiceNotification is NOT supported in CDMA!"); 426 } 427 428 @Override 429 public void 430 acceptCall() throws CallStateException { 431 mCT.acceptCall(); 432 } 433 434 @Override 435 public void 436 rejectCall() throws CallStateException { 437 mCT.rejectCall(); 438 } 439 440 @Override 441 public void 442 switchHoldingAndActive() throws CallStateException { 443 mCT.switchWaitingOrHoldingAndActive(); 444 } 445 446 @Override 447 public String getLine1Number() { 448 return mSST.getMdnNumber(); 449 } 450 451 @Override 452 public String getCdmaPrlVersion(){ 453 return mSST.getPrlVersion(); 454 } 455 456 @Override 457 public String getCdmaMin() { 458 return mSST.getCdmaMin(); 459 } 460 461 @Override 462 public boolean isMinInfoReady() { 463 return mSST.isMinInfoReady(); 464 } 465 466 @Override 467 public void getCallWaiting(Message onComplete) { 468 mCi.queryCallWaiting(CommandsInterface.SERVICE_CLASS_VOICE, onComplete); 469 } 470 471 @Override 472 public void 473 setRadioPower(boolean power) { 474 mSST.setRadioPower(power); 475 } 476 477 @Override 478 public String getEsn() { 479 return mEsn; 480 } 481 482 @Override 483 public String getMeid() { 484 return mMeid; 485 } 486 487 //returns MEID or ESN in CDMA 488 @Override 489 public String getDeviceId() { 490 String id = getMeid(); 491 if ((id == null) || id.matches("^0*$")) { 492 Rlog.d(LOG_TAG, "getDeviceId(): MEID is not initialized use ESN"); 493 id = getEsn(); 494 } 495 return id; 496 } 497 498 @Override 499 public String getDeviceSvn() { 500 Rlog.d(LOG_TAG, "getDeviceSvn(): return 0"); 501 return "0"; 502 } 503 504 @Override 505 public String getSubscriberId() { 506 return mSST.getImsi(); 507 } 508 509 @Override 510 public String getImei() { 511 Rlog.e(LOG_TAG, "IMEI is not available in CDMA"); 512 return null; 513 } 514 515 @Override 516 public boolean canConference() { 517 Rlog.e(LOG_TAG, "canConference: not possible in CDMA"); 518 return false; 519 } 520 521 @Override 522 public CellLocation getCellLocation() { 523 return mSST.mCellLoc; 524 } 525 526 @Override 527 public CdmaCall getForegroundCall() { 528 return mCT.mForegroundCall; 529 } 530 531 @Override 532 public void 533 selectNetworkManually(OperatorInfo network, 534 Message response) { 535 Rlog.e(LOG_TAG, "selectNetworkManually: not possible in CDMA"); 536 } 537 538 @Override 539 public void setOnPostDialCharacter(Handler h, int what, Object obj) { 540 mPostDialHandler = new Registrant(h, what, obj); 541 } 542 543 @Override 544 public boolean handlePinMmi(String dialString) { 545 CdmaMmiCode mmi = CdmaMmiCode.newFromDialString(dialString, this); 546 547 if (mmi == null) { 548 Rlog.e(LOG_TAG, "Mmi is NULL!"); 549 return false; 550 } else if (mmi.isPukCommand()) { 551 mPendingMmis.add(mmi); 552 mMmiRegistrants.notifyRegistrants(new AsyncResult(null, mmi, null)); 553 mmi.processCode(); 554 return true; 555 } 556 Rlog.e(LOG_TAG, "Unrecognized mmi!"); 557 return false; 558 } 559 560 /** 561 * Removes the given MMI from the pending list and notifies registrants that 562 * it is complete. 563 * 564 * @param mmi MMI that is done 565 */ 566 void onMMIDone(CdmaMmiCode mmi) { 567 /* 568 * Only notify complete if it's on the pending list. Otherwise, it's 569 * already been handled (eg, previously canceled). 570 */ 571 if (mPendingMmis.remove(mmi)) { 572 mMmiCompleteRegistrants.notifyRegistrants(new AsyncResult(null, mmi, null)); 573 } 574 } 575 576 @Override 577 public void setLine1Number(String alphaTag, String number, Message onComplete) { 578 Rlog.e(LOG_TAG, "setLine1Number: not possible in CDMA"); 579 } 580 581 @Override 582 public void setCallWaiting(boolean enable, Message onComplete) { 583 Rlog.e(LOG_TAG, "method setCallWaiting is NOT supported in CDMA!"); 584 } 585 586 @Override 587 public void updateServiceLocation() { 588 mSST.enableSingleLocationUpdate(); 589 } 590 591 @Override 592 public void setDataRoamingEnabled(boolean enable) { 593 mDcTracker.setDataOnRoamingEnabled(enable); 594 } 595 596 @Override 597 public void registerForCdmaOtaStatusChange(Handler h, int what, Object obj) { 598 mCi.registerForCdmaOtaProvision(h, what, obj); 599 } 600 601 @Override 602 public void unregisterForCdmaOtaStatusChange(Handler h) { 603 mCi.unregisterForCdmaOtaProvision(h); 604 } 605 606 @Override 607 public void registerForSubscriptionInfoReady(Handler h, int what, Object obj) { 608 mSST.registerForSubscriptionInfoReady(h, what, obj); 609 } 610 611 @Override 612 public void unregisterForSubscriptionInfoReady(Handler h) { 613 mSST.unregisterForSubscriptionInfoReady(h); 614 } 615 616 @Override 617 public void setOnEcbModeExitResponse(Handler h, int what, Object obj) { 618 mEcmExitRespRegistrant = new Registrant (h, what, obj); 619 } 620 621 @Override 622 public void unsetOnEcbModeExitResponse(Handler h) { 623 mEcmExitRespRegistrant.clear(); 624 } 625 626 @Override 627 public void registerForCallWaiting(Handler h, int what, Object obj) { 628 mCT.registerForCallWaiting(h, what, obj); 629 } 630 631 @Override 632 public void unregisterForCallWaiting(Handler h) { 633 mCT.unregisterForCallWaiting(h); 634 } 635 636 @Override 637 public void 638 getNeighboringCids(Message response) { 639 /* 640 * This is currently not implemented. At least as of June 641 * 2009, there is no neighbor cell information available for 642 * CDMA because some party is resisting making this 643 * information readily available. Consequently, calling this 644 * function can have no useful effect. This situation may 645 * (and hopefully will) change in the future. 646 */ 647 if (response != null) { 648 CommandException ce = new CommandException( 649 CommandException.Error.REQUEST_NOT_SUPPORTED); 650 AsyncResult.forMessage(response).exception = ce; 651 response.sendToTarget(); 652 } 653 } 654 655 @Override 656 public PhoneConstants.DataState getDataConnectionState(String apnType) { 657 PhoneConstants.DataState ret = PhoneConstants.DataState.DISCONNECTED; 658 659 if (mSST == null) { 660 // Radio Technology Change is ongoning, dispose() and removeReferences() have 661 // already been called 662 663 ret = PhoneConstants.DataState.DISCONNECTED; 664 } else if (mSST.getCurrentDataConnectionState() != ServiceState.STATE_IN_SERVICE) { 665 // If we're out of service, open TCP sockets may still work 666 // but no data will flow 667 ret = PhoneConstants.DataState.DISCONNECTED; 668 } else if (mDcTracker.isApnTypeEnabled(apnType) == false || 669 mDcTracker.isApnTypeActive(apnType) == false) { 670 ret = PhoneConstants.DataState.DISCONNECTED; 671 } else { 672 switch (mDcTracker.getState(apnType)) { 673 case FAILED: 674 case IDLE: 675 ret = PhoneConstants.DataState.DISCONNECTED; 676 break; 677 678 case CONNECTED: 679 case DISCONNECTING: 680 if ( mCT.mState != PhoneConstants.State.IDLE 681 && !mSST.isConcurrentVoiceAndDataAllowed()) { 682 ret = PhoneConstants.DataState.SUSPENDED; 683 } else { 684 ret = PhoneConstants.DataState.CONNECTED; 685 } 686 break; 687 688 case RETRYING: 689 case CONNECTING: 690 case SCANNING: 691 ret = PhoneConstants.DataState.CONNECTING; 692 break; 693 } 694 } 695 696 log("getDataConnectionState apnType=" + apnType + " ret=" + ret); 697 return ret; 698 } 699 700 @Override 701 public void sendUssdResponse(String ussdMessge) { 702 Rlog.e(LOG_TAG, "sendUssdResponse: not possible in CDMA"); 703 } 704 705 @Override 706 public void sendDtmf(char c) { 707 if (!PhoneNumberUtils.is12Key(c)) { 708 Rlog.e(LOG_TAG, 709 "sendDtmf called with invalid character '" + c + "'"); 710 } else { 711 if (mCT.mState == PhoneConstants.State.OFFHOOK) { 712 mCi.sendDtmf(c, null); 713 } 714 } 715 } 716 717 @Override 718 public void startDtmf(char c) { 719 if (!PhoneNumberUtils.is12Key(c)) { 720 Rlog.e(LOG_TAG, 721 "startDtmf called with invalid character '" + c + "'"); 722 } else { 723 mCi.startDtmf(c, null); 724 } 725 } 726 727 @Override 728 public void stopDtmf() { 729 mCi.stopDtmf(null); 730 } 731 732 @Override 733 public void sendBurstDtmf(String dtmfString, int on, int off, Message onComplete) { 734 boolean check = true; 735 for (int itr = 0;itr < dtmfString.length(); itr++) { 736 if (!PhoneNumberUtils.is12Key(dtmfString.charAt(itr))) { 737 Rlog.e(LOG_TAG, 738 "sendDtmf called with invalid character '" + dtmfString.charAt(itr)+ "'"); 739 check = false; 740 break; 741 } 742 } 743 if ((mCT.mState == PhoneConstants.State.OFFHOOK)&&(check)) { 744 mCi.sendBurstDtmf(dtmfString, on, off, onComplete); 745 } 746 } 747 748 @Override 749 public void getAvailableNetworks(Message response) { 750 Rlog.e(LOG_TAG, "getAvailableNetworks: not possible in CDMA"); 751 } 752 753 @Override 754 public void setOutgoingCallerIdDisplay(int commandInterfaceCLIRMode, Message onComplete) { 755 Rlog.e(LOG_TAG, "setOutgoingCallerIdDisplay: not possible in CDMA"); 756 } 757 758 @Override 759 public void enableLocationUpdates() { 760 mSST.enableLocationUpdates(); 761 } 762 763 @Override 764 public void disableLocationUpdates() { 765 mSST.disableLocationUpdates(); 766 } 767 768 @Override 769 public void getDataCallList(Message response) { 770 mCi.getDataCallList(response); 771 } 772 773 @Override 774 public boolean getDataRoamingEnabled() { 775 return mDcTracker.getDataOnRoamingEnabled(); 776 } 777 778 @Override 779 public void setVoiceMailNumber(String alphaTag, 780 String voiceMailNumber, 781 Message onComplete) { 782 Message resp; 783 mVmNumber = voiceMailNumber; 784 resp = obtainMessage(EVENT_SET_VM_NUMBER_DONE, 0, 0, onComplete); 785 IccRecords r = mIccRecords.get(); 786 if (r != null) { 787 r.setVoiceMailNumber(alphaTag, mVmNumber, resp); 788 } 789 } 790 791 @Override 792 public String getVoiceMailNumber() { 793 String number = null; 794 SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext()); 795 // TODO: The default value of voicemail number should be read from a system property 796 797 // Read platform settings for dynamic voicemail number 798 if (getContext().getResources().getBoolean(com.android.internal 799 .R.bool.config_telephony_use_own_number_for_voicemail)) { 800 number = sp.getString(VM_NUMBER_CDMA, getLine1Number()); 801 } else { 802 number = sp.getString(VM_NUMBER_CDMA, "*86"); 803 } 804 return number; 805 } 806 807 /* Returns Number of Voicemails 808 * @hide 809 */ 810 @Override 811 public int getVoiceMessageCount() { 812 IccRecords r = mIccRecords.get(); 813 int voicemailCount = (r != null) ? r.getVoiceMessageCount() : 0; 814 // If mRuimRecords.getVoiceMessageCount returns zero, then there is possibility 815 // that phone was power cycled and would have lost the voicemail count. 816 // So get the count from preferences. 817 if (voicemailCount == 0) { 818 SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext()); 819 voicemailCount = sp.getInt(VM_COUNT_CDMA, 0); 820 } 821 return voicemailCount; 822 } 823 824 @Override 825 public String getVoiceMailAlphaTag() { 826 // TODO: Where can we get this value has to be clarified with QC. 827 String ret = "";//TODO: Remove = "", if we know where to get this value. 828 829 //ret = mSIMRecords.getVoiceMailAlphaTag(); 830 831 if (ret == null || ret.length() == 0) { 832 return mContext.getText( 833 com.android.internal.R.string.defaultVoiceMailAlphaTag).toString(); 834 } 835 836 return ret; 837 } 838 839 @Override 840 public void getCallForwardingOption(int commandInterfaceCFReason, Message onComplete) { 841 Rlog.e(LOG_TAG, "getCallForwardingOption: not possible in CDMA"); 842 } 843 844 @Override 845 public void setCallForwardingOption(int commandInterfaceCFAction, 846 int commandInterfaceCFReason, 847 String dialingNumber, 848 int timerSeconds, 849 Message onComplete) { 850 Rlog.e(LOG_TAG, "setCallForwardingOption: not possible in CDMA"); 851 } 852 853 @Override 854 public void 855 getOutgoingCallerIdDisplay(Message onComplete) { 856 Rlog.e(LOG_TAG, "getOutgoingCallerIdDisplay: not possible in CDMA"); 857 } 858 859 @Override 860 public boolean 861 getCallForwardingIndicator() { 862 Rlog.e(LOG_TAG, "getCallForwardingIndicator: not possible in CDMA"); 863 return false; 864 } 865 866 @Override 867 public void explicitCallTransfer() { 868 Rlog.e(LOG_TAG, "explicitCallTransfer: not possible in CDMA"); 869 } 870 871 @Override 872 public String getLine1AlphaTag() { 873 Rlog.e(LOG_TAG, "getLine1AlphaTag: not possible in CDMA"); 874 return null; 875 } 876 877 /** 878 * Notify any interested party of a Phone state change 879 * {@link com.android.internal.telephony.PhoneConstants.State} 880 */ 881 /*package*/ void notifyPhoneStateChanged() { 882 mNotifier.notifyPhoneState(this); 883 } 884 885 /** 886 * Notify registrants of a change in the call state. This notifies changes in 887 * {@link com.android.internal.telephony.Call.State}. Use this when changes 888 * in the precise call state are needed, else use notifyPhoneStateChanged. 889 */ 890 /*package*/ void notifyPreciseCallStateChanged() { 891 /* we'd love it if this was package-scoped*/ 892 super.notifyPreciseCallStateChangedP(); 893 } 894 895 void notifyServiceStateChanged(ServiceState ss) { 896 super.notifyServiceStateChangedP(ss); 897 } 898 899 void notifyLocationChanged() { 900 mNotifier.notifyCellLocation(this); 901 } 902 903 /*package*/ void notifyNewRingingConnection(Connection c) { 904 /* we'd love it if this was package-scoped*/ 905 super.notifyNewRingingConnectionP(c); 906 } 907 908 /*package*/ void notifyDisconnect(Connection cn) { 909 mDisconnectRegistrants.notifyResult(cn); 910 } 911 912 void notifyUnknownConnection() { 913 mUnknownConnectionRegistrants.notifyResult(this); 914 } 915 916 @Override 917 public boolean isInEmergencyCall() { 918 return mCT.isInEmergencyCall(); 919 } 920 921 @Override 922 public boolean isInEcm() { 923 return mIsPhoneInEcmState; 924 } 925 926 void sendEmergencyCallbackModeChange(){ 927 //Send an Intent 928 Intent intent = new Intent(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED); 929 intent.putExtra(PhoneConstants.PHONE_IN_ECM_STATE, mIsPhoneInEcmState); 930 ActivityManagerNative.broadcastStickyIntent(intent,null,UserHandle.USER_ALL); 931 if (DBG) Rlog.d(LOG_TAG, "sendEmergencyCallbackModeChange"); 932 } 933 934 @Override 935 public void exitEmergencyCallbackMode() { 936 if (mWakeLock.isHeld()) { 937 mWakeLock.release(); 938 } 939 // Send a message which will invoke handleExitEmergencyCallbackMode 940 mCi.exitEmergencyCallbackMode(obtainMessage(EVENT_EXIT_EMERGENCY_CALLBACK_RESPONSE)); 941 } 942 943 private void handleEnterEmergencyCallbackMode(Message msg) { 944 if (DBG) { 945 Rlog.d(LOG_TAG, "handleEnterEmergencyCallbackMode,mIsPhoneInEcmState= " 946 + mIsPhoneInEcmState); 947 } 948 // if phone is not in Ecm mode, and it's changed to Ecm mode 949 if (mIsPhoneInEcmState == false) { 950 mIsPhoneInEcmState = true; 951 // notify change 952 sendEmergencyCallbackModeChange(); 953 setSystemProperty(TelephonyProperties.PROPERTY_INECM_MODE, "true"); 954 955 // Post this runnable so we will automatically exit 956 // if no one invokes exitEmergencyCallbackMode() directly. 957 long delayInMillis = SystemProperties.getLong( 958 TelephonyProperties.PROPERTY_ECM_EXIT_TIMER, DEFAULT_ECM_EXIT_TIMER_VALUE); 959 postDelayed(mExitEcmRunnable, delayInMillis); 960 // We don't want to go to sleep while in Ecm 961 mWakeLock.acquire(); 962 } 963 } 964 965 private void handleExitEmergencyCallbackMode(Message msg) { 966 AsyncResult ar = (AsyncResult)msg.obj; 967 if (DBG) { 968 Rlog.d(LOG_TAG, "handleExitEmergencyCallbackMode,ar.exception , mIsPhoneInEcmState " 969 + ar.exception + mIsPhoneInEcmState); 970 } 971 // Remove pending exit Ecm runnable, if any 972 removeCallbacks(mExitEcmRunnable); 973 974 if (mEcmExitRespRegistrant != null) { 975 mEcmExitRespRegistrant.notifyRegistrant(ar); 976 } 977 // if exiting ecm success 978 if (ar.exception == null) { 979 if (mIsPhoneInEcmState) { 980 mIsPhoneInEcmState = false; 981 setSystemProperty(TelephonyProperties.PROPERTY_INECM_MODE, "false"); 982 } 983 // send an Intent 984 sendEmergencyCallbackModeChange(); 985 // Re-initiate data connection 986 mDcTracker.setInternalDataEnabled(true); 987 } 988 } 989 990 /** 991 * Handle to cancel or restart Ecm timer in emergency call back mode 992 * if action is CANCEL_ECM_TIMER, cancel Ecm timer and notify apps the timer is canceled; 993 * otherwise, restart Ecm timer and notify apps the timer is restarted. 994 */ 995 void handleTimerInEmergencyCallbackMode(int action) { 996 switch(action) { 997 case CANCEL_ECM_TIMER: 998 removeCallbacks(mExitEcmRunnable); 999 mEcmTimerResetRegistrants.notifyResult(Boolean.TRUE); 1000 break; 1001 case RESTART_ECM_TIMER: 1002 long delayInMillis = SystemProperties.getLong( 1003 TelephonyProperties.PROPERTY_ECM_EXIT_TIMER, DEFAULT_ECM_EXIT_TIMER_VALUE); 1004 postDelayed(mExitEcmRunnable, delayInMillis); 1005 mEcmTimerResetRegistrants.notifyResult(Boolean.FALSE); 1006 break; 1007 default: 1008 Rlog.e(LOG_TAG, "handleTimerInEmergencyCallbackMode, unsupported action " + action); 1009 } 1010 } 1011 1012 /** 1013 * Registration point for Ecm timer reset 1014 * @param h handler to notify 1015 * @param what User-defined message code 1016 * @param obj placed in Message.obj 1017 */ 1018 @Override 1019 public void registerForEcmTimerReset(Handler h, int what, Object obj) { 1020 mEcmTimerResetRegistrants.addUnique(h, what, obj); 1021 } 1022 1023 @Override 1024 public void unregisterForEcmTimerReset(Handler h) { 1025 mEcmTimerResetRegistrants.remove(h); 1026 } 1027 1028 @Override 1029 public void handleMessage(Message msg) { 1030 AsyncResult ar; 1031 Message onComplete; 1032 1033 switch(msg.what) { 1034 case EVENT_RADIO_AVAILABLE: { 1035 mCi.getBasebandVersion(obtainMessage(EVENT_GET_BASEBAND_VERSION_DONE)); 1036 1037 mCi.getDeviceIdentity(obtainMessage(EVENT_GET_DEVICE_IDENTITY_DONE)); 1038 } 1039 break; 1040 1041 case EVENT_GET_BASEBAND_VERSION_DONE:{ 1042 ar = (AsyncResult)msg.obj; 1043 1044 if (ar.exception != null) { 1045 break; 1046 } 1047 1048 if (DBG) Rlog.d(LOG_TAG, "Baseband version: " + ar.result); 1049 setSystemProperty(TelephonyProperties.PROPERTY_BASEBAND_VERSION, (String)ar.result); 1050 } 1051 break; 1052 1053 case EVENT_GET_DEVICE_IDENTITY_DONE:{ 1054 ar = (AsyncResult)msg.obj; 1055 1056 if (ar.exception != null) { 1057 break; 1058 } 1059 String[] respId = (String[])ar.result; 1060 mImei = respId[0]; 1061 mImeiSv = respId[1]; 1062 mEsn = respId[2]; 1063 mMeid = respId[3]; 1064 } 1065 break; 1066 1067 case EVENT_EMERGENCY_CALLBACK_MODE_ENTER:{ 1068 handleEnterEmergencyCallbackMode(msg); 1069 } 1070 break; 1071 1072 case EVENT_ICC_RECORD_EVENTS: 1073 ar = (AsyncResult)msg.obj; 1074 processIccRecordEvents((Integer)ar.result); 1075 break; 1076 1077 case EVENT_EXIT_EMERGENCY_CALLBACK_RESPONSE:{ 1078 handleExitEmergencyCallbackMode(msg); 1079 } 1080 break; 1081 1082 case EVENT_RUIM_RECORDS_LOADED:{ 1083 Rlog.d(LOG_TAG, "Event EVENT_RUIM_RECORDS_LOADED Received"); 1084 updateCurrentCarrierInProvider(); 1085 } 1086 break; 1087 1088 case EVENT_RADIO_OFF_OR_NOT_AVAILABLE:{ 1089 Rlog.d(LOG_TAG, "Event EVENT_RADIO_OFF_OR_NOT_AVAILABLE Received"); 1090 } 1091 break; 1092 1093 case EVENT_RADIO_ON:{ 1094 Rlog.d(LOG_TAG, "Event EVENT_RADIO_ON Received"); 1095 handleCdmaSubscriptionSource(mCdmaSSM.getCdmaSubscriptionSource()); 1096 } 1097 break; 1098 1099 case EVENT_CDMA_SUBSCRIPTION_SOURCE_CHANGED:{ 1100 Rlog.d(LOG_TAG, "EVENT_CDMA_SUBSCRIPTION_SOURCE_CHANGED"); 1101 handleCdmaSubscriptionSource(mCdmaSSM.getCdmaSubscriptionSource()); 1102 } 1103 break; 1104 1105 case EVENT_SSN:{ 1106 Rlog.d(LOG_TAG, "Event EVENT_SSN Received"); 1107 } 1108 break; 1109 1110 case EVENT_REGISTERED_TO_NETWORK:{ 1111 Rlog.d(LOG_TAG, "Event EVENT_REGISTERED_TO_NETWORK Received"); 1112 } 1113 break; 1114 1115 case EVENT_NV_READY:{ 1116 Rlog.d(LOG_TAG, "Event EVENT_NV_READY Received"); 1117 prepareEri(); 1118 } 1119 break; 1120 1121 case EVENT_SET_VM_NUMBER_DONE:{ 1122 ar = (AsyncResult)msg.obj; 1123 if (IccException.class.isInstance(ar.exception)) { 1124 storeVoiceMailNumber(mVmNumber); 1125 ar.exception = null; 1126 } 1127 onComplete = (Message) ar.userObj; 1128 if (onComplete != null) { 1129 AsyncResult.forMessage(onComplete, ar.result, ar.exception); 1130 onComplete.sendToTarget(); 1131 } 1132 } 1133 break; 1134 1135 default:{ 1136 super.handleMessage(msg); 1137 } 1138 } 1139 } 1140 1141 @Override 1142 protected void onUpdateIccAvailability() { 1143 if (mUiccController == null ) { 1144 return; 1145 } 1146 1147 UiccCardApplication newUiccApplication = 1148 mUiccController.getUiccCardApplication(UiccController.APP_FAM_3GPP2); 1149 1150 UiccCardApplication app = mUiccApplication.get(); 1151 if (app != newUiccApplication) { 1152 if (app != null) { 1153 log("Removing stale icc objects."); 1154 if (mIccRecords.get() != null) { 1155 unregisterForRuimRecordEvents(); 1156 mRuimPhoneBookInterfaceManager.updateIccRecords(null); 1157 } 1158 mIccRecords.set(null); 1159 mUiccApplication.set(null); 1160 } 1161 if (newUiccApplication != null) { 1162 log("New Uicc application found"); 1163 mUiccApplication.set(newUiccApplication); 1164 mIccRecords.set(newUiccApplication.getIccRecords()); 1165 registerForRuimRecordEvents(); 1166 mRuimPhoneBookInterfaceManager.updateIccRecords(mIccRecords.get()); 1167 } 1168 } 1169 } 1170 1171 private void processIccRecordEvents(int eventCode) { 1172 switch (eventCode) { 1173 case RuimRecords.EVENT_MWI: 1174 notifyMessageWaitingIndicator(); 1175 break; 1176 1177 default: 1178 Rlog.e(LOG_TAG,"Unknown icc records event code " + eventCode); 1179 break; 1180 } 1181 } 1182 1183 /** 1184 * Handles the call to get the subscription source 1185 * 1186 * @param newSubscriptionSource holds the new CDMA subscription source value 1187 */ 1188 private void handleCdmaSubscriptionSource(int newSubscriptionSource) { 1189 if (newSubscriptionSource != mCdmaSubscriptionSource) { 1190 mCdmaSubscriptionSource = newSubscriptionSource; 1191 if (newSubscriptionSource == CDMA_SUBSCRIPTION_NV) { 1192 // NV is ready when subscription source is NV 1193 sendMessage(obtainMessage(EVENT_NV_READY)); 1194 } 1195 } 1196 } 1197 1198 /** 1199 * Retrieves the PhoneSubInfo of the CDMAPhone 1200 */ 1201 @Override 1202 public PhoneSubInfo getPhoneSubInfo() { 1203 return mSubInfo; 1204 } 1205 1206 /** 1207 * Retrieves the IccSmsInterfaceManager of the CDMAPhone 1208 */ 1209 @Override 1210 public IccSmsInterfaceManager getIccSmsInterfaceManager() { 1211 return mRuimSmsInterfaceManager; 1212 } 1213 1214 /** 1215 * Retrieves the IccPhoneBookInterfaceManager of the CDMAPhone 1216 */ 1217 @Override 1218 public IccPhoneBookInterfaceManager getIccPhoneBookInterfaceManager() { 1219 return mRuimPhoneBookInterfaceManager; 1220 } 1221 1222 public void registerForEriFileLoaded(Handler h, int what, Object obj) { 1223 Registrant r = new Registrant (h, what, obj); 1224 mEriFileLoadedRegistrants.add(r); 1225 } 1226 1227 public void unregisterForEriFileLoaded(Handler h) { 1228 mEriFileLoadedRegistrants.remove(h); 1229 } 1230 1231 // override for allowing access from other classes of this package 1232 /** 1233 * {@inheritDoc} 1234 */ 1235 @Override 1236 public final void setSystemProperty(String property, String value) { 1237 super.setSystemProperty(property, value); 1238 } 1239 1240 /** 1241 * Activate or deactivate cell broadcast SMS. 1242 * 1243 * @param activate 0 = activate, 1 = deactivate 1244 * @param response Callback message is empty on completion 1245 */ 1246 @Override 1247 public void activateCellBroadcastSms(int activate, Message response) { 1248 Rlog.e(LOG_TAG, "[CDMAPhone] activateCellBroadcastSms() is obsolete; use SmsManager"); 1249 response.sendToTarget(); 1250 } 1251 1252 /** 1253 * Query the current configuration of cdma cell broadcast SMS. 1254 * 1255 * @param response Callback message is empty on completion 1256 */ 1257 @Override 1258 public void getCellBroadcastSmsConfig(Message response) { 1259 Rlog.e(LOG_TAG, "[CDMAPhone] getCellBroadcastSmsConfig() is obsolete; use SmsManager"); 1260 response.sendToTarget(); 1261 } 1262 1263 /** 1264 * Configure cdma cell broadcast SMS. 1265 * 1266 * @param response Callback message is empty on completion 1267 */ 1268 @Override 1269 public void setCellBroadcastSmsConfig(int[] configValuesArray, Message response) { 1270 Rlog.e(LOG_TAG, "[CDMAPhone] setCellBroadcastSmsConfig() is obsolete; use SmsManager"); 1271 response.sendToTarget(); 1272 } 1273 1274 /** 1275 * Returns true if OTA Service Provisioning needs to be performed. 1276 */ 1277 @Override 1278 public boolean needsOtaServiceProvisioning() { 1279 return mSST.getOtasp() != ServiceStateTracker.OTASP_NOT_NEEDED; 1280 } 1281 1282 private static final String IS683A_FEATURE_CODE = "*228"; 1283 private static final int IS683A_FEATURE_CODE_NUM_DIGITS = 4; 1284 private static final int IS683A_SYS_SEL_CODE_NUM_DIGITS = 2; 1285 private static final int IS683A_SYS_SEL_CODE_OFFSET = 4; 1286 1287 private static final int IS683_CONST_800MHZ_A_BAND = 0; 1288 private static final int IS683_CONST_800MHZ_B_BAND = 1; 1289 private static final int IS683_CONST_1900MHZ_A_BLOCK = 2; 1290 private static final int IS683_CONST_1900MHZ_B_BLOCK = 3; 1291 private static final int IS683_CONST_1900MHZ_C_BLOCK = 4; 1292 private static final int IS683_CONST_1900MHZ_D_BLOCK = 5; 1293 private static final int IS683_CONST_1900MHZ_E_BLOCK = 6; 1294 private static final int IS683_CONST_1900MHZ_F_BLOCK = 7; 1295 private static final int INVALID_SYSTEM_SELECTION_CODE = -1; 1296 1297 private static boolean isIs683OtaSpDialStr(String dialStr) { 1298 int sysSelCodeInt; 1299 boolean isOtaspDialString = false; 1300 int dialStrLen = dialStr.length(); 1301 1302 if (dialStrLen == IS683A_FEATURE_CODE_NUM_DIGITS) { 1303 if (dialStr.equals(IS683A_FEATURE_CODE)) { 1304 isOtaspDialString = true; 1305 } 1306 } else { 1307 sysSelCodeInt = extractSelCodeFromOtaSpNum(dialStr); 1308 switch (sysSelCodeInt) { 1309 case IS683_CONST_800MHZ_A_BAND: 1310 case IS683_CONST_800MHZ_B_BAND: 1311 case IS683_CONST_1900MHZ_A_BLOCK: 1312 case IS683_CONST_1900MHZ_B_BLOCK: 1313 case IS683_CONST_1900MHZ_C_BLOCK: 1314 case IS683_CONST_1900MHZ_D_BLOCK: 1315 case IS683_CONST_1900MHZ_E_BLOCK: 1316 case IS683_CONST_1900MHZ_F_BLOCK: 1317 isOtaspDialString = true; 1318 break; 1319 default: 1320 break; 1321 } 1322 } 1323 return isOtaspDialString; 1324 } 1325 /** 1326 * This function extracts the system selection code from the dial string. 1327 */ 1328 private static int extractSelCodeFromOtaSpNum(String dialStr) { 1329 int dialStrLen = dialStr.length(); 1330 int sysSelCodeInt = INVALID_SYSTEM_SELECTION_CODE; 1331 1332 if ((dialStr.regionMatches(0, IS683A_FEATURE_CODE, 1333 0, IS683A_FEATURE_CODE_NUM_DIGITS)) && 1334 (dialStrLen >= (IS683A_FEATURE_CODE_NUM_DIGITS + 1335 IS683A_SYS_SEL_CODE_NUM_DIGITS))) { 1336 // Since we checked the condition above, the system selection code 1337 // extracted from dialStr will not cause any exception 1338 sysSelCodeInt = Integer.parseInt ( 1339 dialStr.substring (IS683A_FEATURE_CODE_NUM_DIGITS, 1340 IS683A_FEATURE_CODE_NUM_DIGITS + IS683A_SYS_SEL_CODE_NUM_DIGITS)); 1341 } 1342 if (DBG) Rlog.d(LOG_TAG, "extractSelCodeFromOtaSpNum " + sysSelCodeInt); 1343 return sysSelCodeInt; 1344 } 1345 1346 /** 1347 * This function checks if the system selection code extracted from 1348 * the dial string "sysSelCodeInt' is the system selection code specified 1349 * in the carrier ota sp number schema "sch". 1350 */ 1351 private static boolean 1352 checkOtaSpNumBasedOnSysSelCode (int sysSelCodeInt, String sch[]) { 1353 boolean isOtaSpNum = false; 1354 try { 1355 // Get how many number of system selection code ranges 1356 int selRc = Integer.parseInt(sch[1]); 1357 for (int i = 0; i < selRc; i++) { 1358 if (!TextUtils.isEmpty(sch[i+2]) && !TextUtils.isEmpty(sch[i+3])) { 1359 int selMin = Integer.parseInt(sch[i+2]); 1360 int selMax = Integer.parseInt(sch[i+3]); 1361 // Check if the selection code extracted from the dial string falls 1362 // within any of the range pairs specified in the schema. 1363 if ((sysSelCodeInt >= selMin) && (sysSelCodeInt <= selMax)) { 1364 isOtaSpNum = true; 1365 break; 1366 } 1367 } 1368 } 1369 } catch (NumberFormatException ex) { 1370 // If the carrier ota sp number schema is not correct, we still allow dial 1371 // and only log the error: 1372 Rlog.e(LOG_TAG, "checkOtaSpNumBasedOnSysSelCode, error", ex); 1373 } 1374 return isOtaSpNum; 1375 } 1376 1377 // Define the pattern/format for carrier specified OTASP number schema. 1378 // It separates by comma and/or whitespace. 1379 private static Pattern pOtaSpNumSchema = Pattern.compile("[,\\s]+"); 1380 1381 /** 1382 * The following function checks if a dial string is a carrier specified 1383 * OTASP number or not by checking against the OTASP number schema stored 1384 * in PROPERTY_OTASP_NUM_SCHEMA. 1385 * 1386 * Currently, there are 2 schemas for carriers to specify the OTASP number: 1387 * 1) Use system selection code: 1388 * The schema is: 1389 * SELC,the # of code pairs,min1,max1,min2,max2,... 1390 * e.g "SELC,3,10,20,30,40,60,70" indicates that there are 3 pairs of 1391 * selection codes, and they are {10,20}, {30,40} and {60,70} respectively. 1392 * 1393 * 2) Use feature code: 1394 * The schema is: 1395 * "FC,length of feature code,feature code". 1396 * e.g "FC,2,*2" indicates that the length of the feature code is 2, 1397 * and the code itself is "*2". 1398 */ 1399 private boolean isCarrierOtaSpNum(String dialStr) { 1400 boolean isOtaSpNum = false; 1401 int sysSelCodeInt = extractSelCodeFromOtaSpNum(dialStr); 1402 if (sysSelCodeInt == INVALID_SYSTEM_SELECTION_CODE) { 1403 return isOtaSpNum; 1404 } 1405 // mCarrierOtaSpNumSchema is retrieved from PROPERTY_OTASP_NUM_SCHEMA: 1406 if (!TextUtils.isEmpty(mCarrierOtaSpNumSchema)) { 1407 Matcher m = pOtaSpNumSchema.matcher(mCarrierOtaSpNumSchema); 1408 if (DBG) { 1409 Rlog.d(LOG_TAG, "isCarrierOtaSpNum,schema" + mCarrierOtaSpNumSchema); 1410 } 1411 1412 if (m.find()) { 1413 String sch[] = pOtaSpNumSchema.split(mCarrierOtaSpNumSchema); 1414 // If carrier uses system selection code mechanism 1415 if (!TextUtils.isEmpty(sch[0]) && sch[0].equals("SELC")) { 1416 if (sysSelCodeInt!=INVALID_SYSTEM_SELECTION_CODE) { 1417 isOtaSpNum=checkOtaSpNumBasedOnSysSelCode(sysSelCodeInt,sch); 1418 } else { 1419 if (DBG) { 1420 Rlog.d(LOG_TAG, "isCarrierOtaSpNum,sysSelCodeInt is invalid"); 1421 } 1422 } 1423 } else if (!TextUtils.isEmpty(sch[0]) && sch[0].equals("FC")) { 1424 int fcLen = Integer.parseInt(sch[1]); 1425 String fc = sch[2]; 1426 if (dialStr.regionMatches(0,fc,0,fcLen)) { 1427 isOtaSpNum = true; 1428 } else { 1429 if (DBG) Rlog.d(LOG_TAG, "isCarrierOtaSpNum,not otasp number"); 1430 } 1431 } else { 1432 if (DBG) { 1433 Rlog.d(LOG_TAG, "isCarrierOtaSpNum,ota schema not supported" + sch[0]); 1434 } 1435 } 1436 } else { 1437 if (DBG) { 1438 Rlog.d(LOG_TAG, "isCarrierOtaSpNum,ota schema pattern not right" + 1439 mCarrierOtaSpNumSchema); 1440 } 1441 } 1442 } else { 1443 if (DBG) Rlog.d(LOG_TAG, "isCarrierOtaSpNum,ota schema pattern empty"); 1444 } 1445 return isOtaSpNum; 1446 } 1447 1448 /** 1449 * isOTASPNumber: checks a given number against the IS-683A OTASP dial string and carrier 1450 * OTASP dial string. 1451 * 1452 * @param dialStr the number to look up. 1453 * @return true if the number is in IS-683A OTASP dial string or carrier OTASP dial string 1454 */ 1455 @Override 1456 public boolean isOtaSpNumber(String dialStr){ 1457 boolean isOtaSpNum = false; 1458 String dialableStr = PhoneNumberUtils.extractNetworkPortionAlt(dialStr); 1459 if (dialableStr != null) { 1460 isOtaSpNum = isIs683OtaSpDialStr(dialableStr); 1461 if (isOtaSpNum == false) { 1462 isOtaSpNum = isCarrierOtaSpNum(dialableStr); 1463 } 1464 } 1465 if (DBG) Rlog.d(LOG_TAG, "isOtaSpNumber " + isOtaSpNum); 1466 return isOtaSpNum; 1467 } 1468 1469 @Override 1470 public int getCdmaEriIconIndex() { 1471 return getServiceState().getCdmaEriIconIndex(); 1472 } 1473 1474 /** 1475 * Returns the CDMA ERI icon mode, 1476 * 0 - ON 1477 * 1 - FLASHING 1478 */ 1479 @Override 1480 public int getCdmaEriIconMode() { 1481 return getServiceState().getCdmaEriIconMode(); 1482 } 1483 1484 /** 1485 * Returns the CDMA ERI text, 1486 */ 1487 @Override 1488 public String getCdmaEriText() { 1489 int roamInd = getServiceState().getCdmaRoamingIndicator(); 1490 int defRoamInd = getServiceState().getCdmaDefaultRoamingIndicator(); 1491 return mEriManager.getCdmaEriText(roamInd, defRoamInd); 1492 } 1493 1494 /** 1495 * Store the voicemail number in preferences 1496 */ 1497 private void storeVoiceMailNumber(String number) { 1498 // Update the preference value of voicemail number 1499 SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext()); 1500 SharedPreferences.Editor editor = sp.edit(); 1501 editor.putString(VM_NUMBER_CDMA, number); 1502 editor.apply(); 1503 } 1504 1505 /** 1506 * Sets PROPERTY_ICC_OPERATOR_ISO_COUNTRY property 1507 * 1508 */ 1509 private void setIsoCountryProperty(String operatorNumeric) { 1510 if (TextUtils.isEmpty(operatorNumeric)) { 1511 setSystemProperty(PROPERTY_ICC_OPERATOR_ISO_COUNTRY, ""); 1512 } else { 1513 String iso = ""; 1514 try { 1515 iso = MccTable.countryCodeForMcc(Integer.parseInt( 1516 operatorNumeric.substring(0,3))); 1517 } catch (NumberFormatException ex) { 1518 Rlog.w(LOG_TAG, "countryCodeForMcc error" + ex); 1519 } catch (StringIndexOutOfBoundsException ex) { 1520 Rlog.w(LOG_TAG, "countryCodeForMcc error" + ex); 1521 } 1522 1523 setSystemProperty(PROPERTY_ICC_OPERATOR_ISO_COUNTRY, iso); 1524 } 1525 } 1526 1527 /** 1528 * Sets the "current" field in the telephony provider according to the 1529 * build-time operator numeric property 1530 * 1531 * @return true for success; false otherwise. 1532 */ 1533 boolean updateCurrentCarrierInProvider(String operatorNumeric) { 1534 if (!TextUtils.isEmpty(operatorNumeric)) { 1535 try { 1536 Uri uri = Uri.withAppendedPath(Telephony.Carriers.CONTENT_URI, "current"); 1537 ContentValues map = new ContentValues(); 1538 map.put(Telephony.Carriers.NUMERIC, operatorNumeric); 1539 log("updateCurrentCarrierInProvider from system: numeric=" + operatorNumeric); 1540 getContext().getContentResolver().insert(uri, map); 1541 1542 // Updates MCC MNC device configuration information 1543 MccTable.updateMccMncConfiguration(mContext, operatorNumeric); 1544 1545 return true; 1546 } catch (SQLException e) { 1547 Rlog.e(LOG_TAG, "Can't store current operator", e); 1548 } 1549 } 1550 return false; 1551 } 1552 1553 /** 1554 * Sets the "current" field in the telephony provider according to the SIM's operator. 1555 * Implemented in {@link CDMALTEPhone} for CDMA/LTE devices. 1556 * 1557 * @return true for success; false otherwise. 1558 */ 1559 boolean updateCurrentCarrierInProvider() { 1560 return true; 1561 } 1562 1563 public void prepareEri() { 1564 mEriManager.loadEriFile(); 1565 if(mEriManager.isEriFileLoaded()) { 1566 // when the ERI file is loaded 1567 log("ERI read, notify registrants"); 1568 mEriFileLoadedRegistrants.notifyRegistrants(); 1569 } 1570 } 1571 1572 public boolean isEriFileLoaded() { 1573 return mEriManager.isEriFileLoaded(); 1574 } 1575 1576 protected void registerForRuimRecordEvents() { 1577 IccRecords r = mIccRecords.get(); 1578 if (r == null) { 1579 return; 1580 } 1581 r.registerForRecordsEvents(this, EVENT_ICC_RECORD_EVENTS, null); 1582 r.registerForRecordsLoaded(this, EVENT_RUIM_RECORDS_LOADED, null); 1583 } 1584 1585 protected void unregisterForRuimRecordEvents() { 1586 IccRecords r = mIccRecords.get(); 1587 if (r == null) { 1588 return; 1589 } 1590 r.unregisterForRecordsEvents(this); 1591 r.unregisterForRecordsLoaded(this); 1592 } 1593 1594 protected void log(String s) { 1595 if (DBG) 1596 Rlog.d(LOG_TAG, s); 1597 } 1598 1599 @Override 1600 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 1601 pw.println("CDMAPhone extends:"); 1602 super.dump(fd, pw, args); 1603 pw.println(" mVmNumber=" + mVmNumber); 1604 pw.println(" mCT=" + mCT); 1605 pw.println(" mSST=" + mSST); 1606 pw.println(" mCdmaSSM=" + mCdmaSSM); 1607 pw.println(" mPendingMmis=" + mPendingMmis); 1608 pw.println(" mRuimPhoneBookInterfaceManager=" + mRuimPhoneBookInterfaceManager); 1609 pw.println(" mRuimSmsInterfaceManager=" + mRuimSmsInterfaceManager); 1610 pw.println(" mCdmaSubscriptionSource=" + mCdmaSubscriptionSource); 1611 pw.println(" mSubInfo=" + mSubInfo); 1612 pw.println(" mEriManager=" + mEriManager); 1613 pw.println(" mWakeLock=" + mWakeLock); 1614 pw.println(" mIsPhoneInEcmState=" + mIsPhoneInEcmState); 1615 if (VDBG) pw.println(" mImei=" + mImei); 1616 if (VDBG) pw.println(" mImeiSv=" + mImeiSv); 1617 if (VDBG) pw.println(" mEsn=" + mEsn); 1618 if (VDBG) pw.println(" mMeid=" + mMeid); 1619 pw.println(" mCarrierOtaSpNumSchema=" + mCarrierOtaSpNumSchema); 1620 pw.println(" getCdmaEriIconIndex()=" + getCdmaEriIconIndex()); 1621 pw.println(" getCdmaEriIconMode()=" + getCdmaEriIconMode()); 1622 pw.println(" getCdmaEriText()=" + getCdmaEriText()); 1623 pw.println(" isMinInfoReady()=" + isMinInfoReady()); 1624 pw.println(" isCspPlmnEnabled()=" + isCspPlmnEnabled()); 1625 } 1626} 1627