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