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