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