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