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