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 17 package android.telephony; 18 19 import android.os.Bundle; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 import android.telephony.Rlog; 23 24 /** 25 * Contains phone state and service related information. 26 * 27 * The following phone information is included in returned ServiceState: 28 * 29 * <ul> 30 * <li>Service state: IN_SERVICE, OUT_OF_SERVICE, EMERGENCY_ONLY, POWER_OFF 31 * <li>Roaming indicator 32 * <li>Operator name, short name and numeric id 33 * <li>Network selection mode 34 * </ul> 35 */ 36 public class ServiceState implements Parcelable { 37 38 static final String LOG_TAG = "PHONE"; 39 static final boolean DBG = true; 40 41 /** 42 * Normal operation condition, the phone is registered 43 * with an operator either in home network or in roaming. 44 */ 45 public static final int STATE_IN_SERVICE = 0; 46 47 /** 48 * Phone is not registered with any operator, the phone 49 * can be currently searching a new operator to register to, or not 50 * searching to registration at all, or registration is denied, or radio 51 * signal is not available. 52 */ 53 public static final int STATE_OUT_OF_SERVICE = 1; 54 55 /** 56 * The phone is registered and locked. Only emergency numbers are allowed. {@more} 57 */ 58 public static final int STATE_EMERGENCY_ONLY = 2; 59 60 /** 61 * Radio of telephony is explicitly powered off. 62 */ 63 public static final int STATE_POWER_OFF = 3; 64 65 /** 66 * RIL level registration state values from ril.h 67 * ((const char **)response)[0] is registration state 0-6, 68 * 0 - Not registered, MT is not currently searching 69 * a new operator to register 70 * 1 - Registered, home network 71 * 2 - Not registered, but MT is currently searching 72 * a new operator to register 73 * 3 - Registration denied 74 * 4 - Unknown 75 * 5 - Registered, roaming 76 * 10 - Same as 0, but indicates that emergency calls 77 * are enabled. 78 * 12 - Same as 2, but indicates that emergency calls 79 * are enabled. 80 * 13 - Same as 3, but indicates that emergency calls 81 * are enabled. 82 * 14 - Same as 4, but indicates that emergency calls 83 * are enabled. 84 * @hide 85 */ 86 public static final int RIL_REG_STATE_NOT_REG = 0; 87 /** @hide */ 88 public static final int RIL_REG_STATE_HOME = 1; 89 /** @hide */ 90 public static final int RIL_REG_STATE_SEARCHING = 2; 91 /** @hide */ 92 public static final int RIL_REG_STATE_DENIED = 3; 93 /** @hide */ 94 public static final int RIL_REG_STATE_UNKNOWN = 4; 95 /** @hide */ 96 public static final int RIL_REG_STATE_ROAMING = 5; 97 /** @hide */ 98 public static final int RIL_REG_STATE_NOT_REG_EMERGENCY_CALL_ENABLED = 10; 99 /** @hide */ 100 public static final int RIL_REG_STATE_SEARCHING_EMERGENCY_CALL_ENABLED = 12; 101 /** @hide */ 102 public static final int RIL_REG_STATE_DENIED_EMERGENCY_CALL_ENABLED = 13; 103 /** @hide */ 104 public static final int RIL_REG_STATE_UNKNOWN_EMERGENCY_CALL_ENABLED = 14; 105 106 /** 107 * Available radio technologies for GSM, UMTS and CDMA. 108 * Duplicates the constants from hardware/radio/include/ril.h 109 * This should only be used by agents working with the ril. Others 110 * should use the equivalent TelephonyManager.NETWORK_TYPE_* 111 */ 112 /** @hide */ 113 public static final int RIL_RADIO_TECHNOLOGY_UNKNOWN = 0; 114 /** @hide */ 115 public static final int RIL_RADIO_TECHNOLOGY_GPRS = 1; 116 /** @hide */ 117 public static final int RIL_RADIO_TECHNOLOGY_EDGE = 2; 118 /** @hide */ 119 public static final int RIL_RADIO_TECHNOLOGY_UMTS = 3; 120 /** @hide */ 121 public static final int RIL_RADIO_TECHNOLOGY_IS95A = 4; 122 /** @hide */ 123 public static final int RIL_RADIO_TECHNOLOGY_IS95B = 5; 124 /** @hide */ 125 public static final int RIL_RADIO_TECHNOLOGY_1xRTT = 6; 126 /** @hide */ 127 public static final int RIL_RADIO_TECHNOLOGY_EVDO_0 = 7; 128 /** @hide */ 129 public static final int RIL_RADIO_TECHNOLOGY_EVDO_A = 8; 130 /** @hide */ 131 public static final int RIL_RADIO_TECHNOLOGY_HSDPA = 9; 132 /** @hide */ 133 public static final int RIL_RADIO_TECHNOLOGY_HSUPA = 10; 134 /** @hide */ 135 public static final int RIL_RADIO_TECHNOLOGY_HSPA = 11; 136 /** @hide */ 137 public static final int RIL_RADIO_TECHNOLOGY_EVDO_B = 12; 138 /** @hide */ 139 public static final int RIL_RADIO_TECHNOLOGY_EHRPD = 13; 140 /** @hide */ 141 public static final int RIL_RADIO_TECHNOLOGY_LTE = 14; 142 /** @hide */ 143 public static final int RIL_RADIO_TECHNOLOGY_HSPAP = 15; 144 /** 145 * GSM radio technology only supports voice. It does not support data. 146 * @hide 147 */ 148 public static final int RIL_RADIO_TECHNOLOGY_GSM = 16; 149 150 /** 151 * Available registration states for GSM, UMTS and CDMA. 152 */ 153 /** @hide */ 154 public static final int REGISTRATION_STATE_NOT_REGISTERED_AND_NOT_SEARCHING = 0; 155 /** @hide */ 156 public static final int REGISTRATION_STATE_HOME_NETWORK = 1; 157 /** @hide */ 158 public static final int REGISTRATION_STATE_NOT_REGISTERED_AND_SEARCHING = 2; 159 /** @hide */ 160 public static final int REGISTRATION_STATE_REGISTRATION_DENIED = 3; 161 /** @hide */ 162 public static final int REGISTRATION_STATE_UNKNOWN = 4; 163 /** @hide */ 164 public static final int REGISTRATION_STATE_ROAMING = 5; 165 166 private int mVoiceRegState = STATE_OUT_OF_SERVICE; 167 private int mDataRegState = STATE_OUT_OF_SERVICE; 168 private boolean mRoaming; 169 private String mOperatorAlphaLong; 170 private String mOperatorAlphaShort; 171 private String mOperatorNumeric; 172 private boolean mIsManualNetworkSelection; 173 174 private boolean mIsEmergencyOnly; 175 176 private int mRilVoiceRadioTechnology; 177 private int mRilDataRadioTechnology; 178 179 private boolean mCssIndicator; 180 private int mNetworkId; 181 private int mSystemId; 182 private int mCdmaRoamingIndicator; 183 private int mCdmaDefaultRoamingIndicator; 184 private int mCdmaEriIconIndex; 185 private int mCdmaEriIconMode; 186 187 /** 188 * Create a new ServiceState from a intent notifier Bundle 189 * 190 * This method is used by PhoneStateIntentReceiver and maybe by 191 * external applications. 192 * 193 * @param m Bundle from intent notifier 194 * @return newly created ServiceState 195 * @hide 196 */ 197 public static ServiceState newFromBundle(Bundle m) { 198 ServiceState ret; 199 ret = new ServiceState(); 200 ret.setFromNotifierBundle(m); 201 return ret; 202 } 203 204 /** 205 * Empty constructor 206 */ 207 public ServiceState() { 208 } 209 210 /** 211 * Copy constructors 212 * 213 * @param s Source service state 214 */ 215 public ServiceState(ServiceState s) { 216 copyFrom(s); 217 } 218 219 protected void copyFrom(ServiceState s) { 220 mVoiceRegState = s.mVoiceRegState; 221 mDataRegState = s.mDataRegState; 222 mRoaming = s.mRoaming; 223 mOperatorAlphaLong = s.mOperatorAlphaLong; 224 mOperatorAlphaShort = s.mOperatorAlphaShort; 225 mOperatorNumeric = s.mOperatorNumeric; 226 mIsManualNetworkSelection = s.mIsManualNetworkSelection; 227 mRilVoiceRadioTechnology = s.mRilVoiceRadioTechnology; 228 mRilDataRadioTechnology = s.mRilDataRadioTechnology; 229 mCssIndicator = s.mCssIndicator; 230 mNetworkId = s.mNetworkId; 231 mSystemId = s.mSystemId; 232 mCdmaRoamingIndicator = s.mCdmaRoamingIndicator; 233 mCdmaDefaultRoamingIndicator = s.mCdmaDefaultRoamingIndicator; 234 mCdmaEriIconIndex = s.mCdmaEriIconIndex; 235 mCdmaEriIconMode = s.mCdmaEriIconMode; 236 mIsEmergencyOnly = s.mIsEmergencyOnly; 237 } 238 239 /** 240 * Construct a ServiceState object from the given parcel. 241 */ 242 public ServiceState(Parcel in) { 243 mVoiceRegState = in.readInt(); 244 mDataRegState = in.readInt(); 245 mRoaming = in.readInt() != 0; 246 mOperatorAlphaLong = in.readString(); 247 mOperatorAlphaShort = in.readString(); 248 mOperatorNumeric = in.readString(); 249 mIsManualNetworkSelection = in.readInt() != 0; 250 mRilVoiceRadioTechnology = in.readInt(); 251 mRilDataRadioTechnology = in.readInt(); 252 mCssIndicator = (in.readInt() != 0); 253 mNetworkId = in.readInt(); 254 mSystemId = in.readInt(); 255 mCdmaRoamingIndicator = in.readInt(); 256 mCdmaDefaultRoamingIndicator = in.readInt(); 257 mCdmaEriIconIndex = in.readInt(); 258 mCdmaEriIconMode = in.readInt(); 259 mIsEmergencyOnly = in.readInt() != 0; 260 } 261 262 public void writeToParcel(Parcel out, int flags) { 263 out.writeInt(mVoiceRegState); 264 out.writeInt(mDataRegState); 265 out.writeInt(mRoaming ? 1 : 0); 266 out.writeString(mOperatorAlphaLong); 267 out.writeString(mOperatorAlphaShort); 268 out.writeString(mOperatorNumeric); 269 out.writeInt(mIsManualNetworkSelection ? 1 : 0); 270 out.writeInt(mRilVoiceRadioTechnology); 271 out.writeInt(mRilDataRadioTechnology); 272 out.writeInt(mCssIndicator ? 1 : 0); 273 out.writeInt(mNetworkId); 274 out.writeInt(mSystemId); 275 out.writeInt(mCdmaRoamingIndicator); 276 out.writeInt(mCdmaDefaultRoamingIndicator); 277 out.writeInt(mCdmaEriIconIndex); 278 out.writeInt(mCdmaEriIconMode); 279 out.writeInt(mIsEmergencyOnly ? 1 : 0); 280 } 281 282 public int describeContents() { 283 return 0; 284 } 285 286 public static final Parcelable.Creator<ServiceState> CREATOR = 287 new Parcelable.Creator<ServiceState>() { 288 public ServiceState createFromParcel(Parcel in) { 289 return new ServiceState(in); 290 } 291 292 public ServiceState[] newArray(int size) { 293 return new ServiceState[size]; 294 } 295 }; 296 297 /** 298 * Get current voice service state 299 */ 300 public int getState() { 301 return getVoiceRegState(); 302 } 303 304 /** 305 * Get current voice service state 306 * 307 * @see #STATE_IN_SERVICE 308 * @see #STATE_OUT_OF_SERVICE 309 * @see #STATE_EMERGENCY_ONLY 310 * @see #STATE_POWER_OFF 311 * 312 * @hide 313 */ 314 public int getVoiceRegState() { 315 return mVoiceRegState; 316 } 317 318 /** 319 * Get current data service state 320 * 321 * @see #STATE_IN_SERVICE 322 * @see #STATE_OUT_OF_SERVICE 323 * @see #STATE_EMERGENCY_ONLY 324 * @see #STATE_POWER_OFF 325 * 326 * @hide 327 */ 328 public int getDataRegState() { 329 return mDataRegState; 330 } 331 332 /** 333 * Get current roaming indicator of phone 334 * (note: not just decoding from TS 27.007 7.2) 335 * 336 * @return true if TS 27.007 7.2 roaming is true 337 * and ONS is different from SPN 338 * 339 */ 340 public boolean getRoaming() { 341 return mRoaming; 342 } 343 344 /** 345 * @hide 346 */ 347 public boolean isEmergencyOnly() { 348 return mIsEmergencyOnly; 349 } 350 351 /** 352 * @hide 353 */ 354 public int getCdmaRoamingIndicator(){ 355 return this.mCdmaRoamingIndicator; 356 } 357 358 /** 359 * @hide 360 */ 361 public int getCdmaDefaultRoamingIndicator(){ 362 return this.mCdmaDefaultRoamingIndicator; 363 } 364 365 /** 366 * @hide 367 */ 368 public int getCdmaEriIconIndex() { 369 return this.mCdmaEriIconIndex; 370 } 371 372 /** 373 * @hide 374 */ 375 public int getCdmaEriIconMode() { 376 return this.mCdmaEriIconMode; 377 } 378 379 /** 380 * Get current registered operator name in long alphanumeric format. 381 * 382 * In GSM/UMTS, long format can be up to 16 characters long. 383 * In CDMA, returns the ERI text, if set. Otherwise, returns the ONS. 384 * 385 * @return long name of operator, null if unregistered or unknown 386 */ 387 public String getOperatorAlphaLong() { 388 return mOperatorAlphaLong; 389 } 390 391 /** 392 * Get current registered operator name in short alphanumeric format. 393 * 394 * In GSM/UMTS, short format can be up to 8 characters long. 395 * 396 * @return short name of operator, null if unregistered or unknown 397 */ 398 public String getOperatorAlphaShort() { 399 return mOperatorAlphaShort; 400 } 401 402 /** 403 * Get current registered operator numeric id. 404 * 405 * In GSM/UMTS, numeric format is 3 digit country code plus 2 or 3 digit 406 * network code. 407 * 408 * @return numeric format of operator, null if unregistered or unknown 409 */ 410 /* 411 * The country code can be decoded using 412 * {@link com.android.internal.telephony.MccTable#countryCodeForMcc(int)}. 413 */ 414 public String getOperatorNumeric() { 415 return mOperatorNumeric; 416 } 417 418 /** 419 * Get current network selection mode. 420 * 421 * @return true if manual mode, false if automatic mode 422 */ 423 public boolean getIsManualSelection() { 424 return mIsManualNetworkSelection; 425 } 426 427 @Override 428 public int hashCode() { 429 return ((mVoiceRegState * 31) 430 + (mDataRegState * 37) 431 + (mRoaming ? 1 : 0) 432 + (mIsManualNetworkSelection ? 1 : 0) 433 + ((null == mOperatorAlphaLong) ? 0 : mOperatorAlphaLong.hashCode()) 434 + ((null == mOperatorAlphaShort) ? 0 : mOperatorAlphaShort.hashCode()) 435 + ((null == mOperatorNumeric) ? 0 : mOperatorNumeric.hashCode()) 436 + mCdmaRoamingIndicator 437 + mCdmaDefaultRoamingIndicator 438 + (mIsEmergencyOnly ? 1 : 0)); 439 } 440 441 @Override 442 public boolean equals (Object o) { 443 ServiceState s; 444 445 try { 446 s = (ServiceState) o; 447 } catch (ClassCastException ex) { 448 return false; 449 } 450 451 if (o == null) { 452 return false; 453 } 454 455 return (mVoiceRegState == s.mVoiceRegState 456 && mDataRegState == s.mDataRegState 457 && mRoaming == s.mRoaming 458 && mIsManualNetworkSelection == s.mIsManualNetworkSelection 459 && equalsHandlesNulls(mOperatorAlphaLong, s.mOperatorAlphaLong) 460 && equalsHandlesNulls(mOperatorAlphaShort, s.mOperatorAlphaShort) 461 && equalsHandlesNulls(mOperatorNumeric, s.mOperatorNumeric) 462 && equalsHandlesNulls(mRilVoiceRadioTechnology, s.mRilVoiceRadioTechnology) 463 && equalsHandlesNulls(mRilDataRadioTechnology, s.mRilDataRadioTechnology) 464 && equalsHandlesNulls(mCssIndicator, s.mCssIndicator) 465 && equalsHandlesNulls(mNetworkId, s.mNetworkId) 466 && equalsHandlesNulls(mSystemId, s.mSystemId) 467 && equalsHandlesNulls(mCdmaRoamingIndicator, s.mCdmaRoamingIndicator) 468 && equalsHandlesNulls(mCdmaDefaultRoamingIndicator, 469 s.mCdmaDefaultRoamingIndicator) 470 && mIsEmergencyOnly == s.mIsEmergencyOnly); 471 } 472 473 /** 474 * Convert radio technology to String 475 * 476 * @param radioTechnology 477 * @return String representation of the RAT 478 * 479 * @hide 480 */ 481 public static String rilRadioTechnologyToString(int rt) { 482 String rtString; 483 484 switch(rt) { 485 case RIL_RADIO_TECHNOLOGY_UNKNOWN: 486 rtString = "Unknown"; 487 break; 488 case RIL_RADIO_TECHNOLOGY_GPRS: 489 rtString = "GPRS"; 490 break; 491 case RIL_RADIO_TECHNOLOGY_EDGE: 492 rtString = "EDGE"; 493 break; 494 case RIL_RADIO_TECHNOLOGY_UMTS: 495 rtString = "UMTS"; 496 break; 497 case RIL_RADIO_TECHNOLOGY_IS95A: 498 rtString = "CDMA-IS95A"; 499 break; 500 case RIL_RADIO_TECHNOLOGY_IS95B: 501 rtString = "CDMA-IS95B"; 502 break; 503 case RIL_RADIO_TECHNOLOGY_1xRTT: 504 rtString = "1xRTT"; 505 break; 506 case RIL_RADIO_TECHNOLOGY_EVDO_0: 507 rtString = "EvDo-rev.0"; 508 break; 509 case RIL_RADIO_TECHNOLOGY_EVDO_A: 510 rtString = "EvDo-rev.A"; 511 break; 512 case RIL_RADIO_TECHNOLOGY_HSDPA: 513 rtString = "HSDPA"; 514 break; 515 case RIL_RADIO_TECHNOLOGY_HSUPA: 516 rtString = "HSUPA"; 517 break; 518 case RIL_RADIO_TECHNOLOGY_HSPA: 519 rtString = "HSPA"; 520 break; 521 case RIL_RADIO_TECHNOLOGY_EVDO_B: 522 rtString = "EvDo-rev.B"; 523 break; 524 case RIL_RADIO_TECHNOLOGY_EHRPD: 525 rtString = "eHRPD"; 526 break; 527 case RIL_RADIO_TECHNOLOGY_LTE: 528 rtString = "LTE"; 529 break; 530 case RIL_RADIO_TECHNOLOGY_HSPAP: 531 rtString = "HSPAP"; 532 break; 533 case RIL_RADIO_TECHNOLOGY_GSM: 534 rtString = "GSM"; 535 break; 536 default: 537 rtString = "Unexpected"; 538 Rlog.w(LOG_TAG, "Unexpected radioTechnology=" + rt); 539 break; 540 } 541 return rtString; 542 } 543 544 @Override 545 public String toString() { 546 String radioTechnology = rilRadioTechnologyToString(mRilVoiceRadioTechnology); 547 String dataRadioTechnology = rilRadioTechnologyToString(mRilDataRadioTechnology); 548 549 return (mVoiceRegState + " " + mDataRegState + " " + (mRoaming ? "roaming" : "home") 550 + " " + mOperatorAlphaLong 551 + " " + mOperatorAlphaShort 552 + " " + mOperatorNumeric 553 + " " + (mIsManualNetworkSelection ? "(manual)" : "") 554 + " " + radioTechnology 555 + " " + dataRadioTechnology 556 + " " + (mCssIndicator ? "CSS supported" : "CSS not supported") 557 + " " + mNetworkId 558 + " " + mSystemId 559 + " RoamInd=" + mCdmaRoamingIndicator 560 + " DefRoamInd=" + mCdmaDefaultRoamingIndicator 561 + " EmergOnly=" + mIsEmergencyOnly); 562 } 563 564 private void setNullState(int state) { 565 if (DBG) Rlog.d(LOG_TAG, "[ServiceState] setNullState=" + state); 566 mVoiceRegState = state; 567 mDataRegState = state; 568 mRoaming = false; 569 mOperatorAlphaLong = null; 570 mOperatorAlphaShort = null; 571 mOperatorNumeric = null; 572 mIsManualNetworkSelection = false; 573 mRilVoiceRadioTechnology = 0; 574 mRilDataRadioTechnology = 0; 575 mCssIndicator = false; 576 mNetworkId = -1; 577 mSystemId = -1; 578 mCdmaRoamingIndicator = -1; 579 mCdmaDefaultRoamingIndicator = -1; 580 mCdmaEriIconIndex = -1; 581 mCdmaEriIconMode = -1; 582 mIsEmergencyOnly = false; 583 } 584 585 public void setStateOutOfService() { 586 setNullState(STATE_OUT_OF_SERVICE); 587 } 588 589 public void setStateOff() { 590 setNullState(STATE_POWER_OFF); 591 } 592 593 public void setState(int state) { 594 setVoiceRegState(state); 595 if (DBG) Rlog.e(LOG_TAG, "[ServiceState] setState deprecated use setVoiceRegState()"); 596 } 597 598 /** @hide */ 599 public void setVoiceRegState(int state) { 600 mVoiceRegState = state; 601 if (DBG) Rlog.d(LOG_TAG, "[ServiceState] setVoiceRegState=" + mVoiceRegState); 602 } 603 604 /** @hide */ 605 public void setDataRegState(int state) { 606 mDataRegState = state; 607 if (DBG) Rlog.d(LOG_TAG, "[ServiceState] setDataRegState=" + mDataRegState); 608 } 609 610 public void setRoaming(boolean roaming) { 611 mRoaming = roaming; 612 } 613 614 615 /** 616 * @hide 617 */ 618 public void setEmergencyOnly(boolean emergencyOnly) { 619 mIsEmergencyOnly = emergencyOnly; 620 } 621 622 /** 623 * @hide 624 */ 625 public void setCdmaRoamingIndicator(int roaming) { 626 this.mCdmaRoamingIndicator = roaming; 627 } 628 629 /** 630 * @hide 631 */ 632 public void setCdmaDefaultRoamingIndicator (int roaming) { 633 this.mCdmaDefaultRoamingIndicator = roaming; 634 } 635 636 /** 637 * @hide 638 */ 639 public void setCdmaEriIconIndex(int index) { 640 this.mCdmaEriIconIndex = index; 641 } 642 643 /** 644 * @hide 645 */ 646 public void setCdmaEriIconMode(int mode) { 647 this.mCdmaEriIconMode = mode; 648 } 649 650 public void setOperatorName(String longName, String shortName, String numeric) { 651 mOperatorAlphaLong = longName; 652 mOperatorAlphaShort = shortName; 653 mOperatorNumeric = numeric; 654 } 655 656 /** 657 * In CDMA, mOperatorAlphaLong can be set from the ERI text. 658 * This is done from the CDMAPhone and not from the CdmaServiceStateTracker. 659 * 660 * @hide 661 */ 662 public void setOperatorAlphaLong(String longName) { 663 mOperatorAlphaLong = longName; 664 } 665 666 public void setIsManualSelection(boolean isManual) { 667 mIsManualNetworkSelection = isManual; 668 } 669 670 /** 671 * Test whether two objects hold the same data values or both are null. 672 * 673 * @param a first obj 674 * @param b second obj 675 * @return true if two objects equal or both are null 676 */ 677 private static boolean equalsHandlesNulls (Object a, Object b) { 678 return (a == null) ? (b == null) : a.equals (b); 679 } 680 681 /** 682 * Set ServiceState based on intent notifier map. 683 * 684 * @param m intent notifier map 685 * @hide 686 */ 687 private void setFromNotifierBundle(Bundle m) { 688 mVoiceRegState = m.getInt("voiceRegState"); 689 mDataRegState = m.getInt("dataRegState"); 690 mRoaming = m.getBoolean("roaming"); 691 mOperatorAlphaLong = m.getString("operator-alpha-long"); 692 mOperatorAlphaShort = m.getString("operator-alpha-short"); 693 mOperatorNumeric = m.getString("operator-numeric"); 694 mIsManualNetworkSelection = m.getBoolean("manual"); 695 mRilVoiceRadioTechnology = m.getInt("radioTechnology"); 696 mRilDataRadioTechnology = m.getInt("dataRadioTechnology"); 697 mCssIndicator = m.getBoolean("cssIndicator"); 698 mNetworkId = m.getInt("networkId"); 699 mSystemId = m.getInt("systemId"); 700 mCdmaRoamingIndicator = m.getInt("cdmaRoamingIndicator"); 701 mCdmaDefaultRoamingIndicator = m.getInt("cdmaDefaultRoamingIndicator"); 702 mIsEmergencyOnly = m.getBoolean("emergencyOnly"); 703 } 704 705 /** 706 * Set intent notifier Bundle based on service state. 707 * 708 * @param m intent notifier Bundle 709 * @hide 710 */ 711 public void fillInNotifierBundle(Bundle m) { 712 m.putInt("voiceRegState", mVoiceRegState); 713 m.putInt("dataRegState", mDataRegState); 714 m.putBoolean("roaming", Boolean.valueOf(mRoaming)); 715 m.putString("operator-alpha-long", mOperatorAlphaLong); 716 m.putString("operator-alpha-short", mOperatorAlphaShort); 717 m.putString("operator-numeric", mOperatorNumeric); 718 m.putBoolean("manual", Boolean.valueOf(mIsManualNetworkSelection)); 719 m.putInt("radioTechnology", mRilVoiceRadioTechnology); 720 m.putInt("dataRadioTechnology", mRilDataRadioTechnology); 721 m.putBoolean("cssIndicator", mCssIndicator); 722 m.putInt("networkId", mNetworkId); 723 m.putInt("systemId", mSystemId); 724 m.putInt("cdmaRoamingIndicator", mCdmaRoamingIndicator); 725 m.putInt("cdmaDefaultRoamingIndicator", mCdmaDefaultRoamingIndicator); 726 m.putBoolean("emergencyOnly", Boolean.valueOf(mIsEmergencyOnly)); 727 } 728 729 /** @hide */ 730 public void setRilVoiceRadioTechnology(int rt) { 731 this.mRilVoiceRadioTechnology = rt; 732 } 733 734 /** @hide */ 735 public void setRilDataRadioTechnology(int rt) { 736 this.mRilDataRadioTechnology = rt; 737 if (DBG) Rlog.d(LOG_TAG, "[ServiceState] setDataRadioTechnology=" + mRilDataRadioTechnology); 738 } 739 740 /** @hide */ 741 public void setCssIndicator(int css) { 742 this.mCssIndicator = (css != 0); 743 } 744 745 /** @hide */ 746 public void setSystemAndNetworkId(int systemId, int networkId) { 747 this.mSystemId = systemId; 748 this.mNetworkId = networkId; 749 } 750 751 /** @hide */ 752 public int getRilVoiceRadioTechnology() { 753 return this.mRilVoiceRadioTechnology; 754 } 755 /** @hide */ 756 public int getRilDataRadioTechnology() { 757 return this.mRilDataRadioTechnology; 758 } 759 /** 760 * @hide 761 * @Deprecated to be removed Q3 2013 use {@link #getRilDataRadioTechnology} or 762 * {@link #getRilVoiceRadioTechnology} 763 */ 764 public int getRadioTechnology() { 765 Rlog.e(LOG_TAG, "ServiceState.getRadioTechnology() DEPRECATED will be removed *******"); 766 return getRilDataRadioTechnology(); 767 } 768 769 private int rilRadioTechnologyToNetworkType(int rt) { 770 switch(rt) { 771 case ServiceState.RIL_RADIO_TECHNOLOGY_GPRS: 772 return TelephonyManager.NETWORK_TYPE_GPRS; 773 case ServiceState.RIL_RADIO_TECHNOLOGY_EDGE: 774 return TelephonyManager.NETWORK_TYPE_EDGE; 775 case ServiceState.RIL_RADIO_TECHNOLOGY_UMTS: 776 return TelephonyManager.NETWORK_TYPE_UMTS; 777 case ServiceState.RIL_RADIO_TECHNOLOGY_HSDPA: 778 return TelephonyManager.NETWORK_TYPE_HSDPA; 779 case ServiceState.RIL_RADIO_TECHNOLOGY_HSUPA: 780 return TelephonyManager.NETWORK_TYPE_HSUPA; 781 case ServiceState.RIL_RADIO_TECHNOLOGY_HSPA: 782 return TelephonyManager.NETWORK_TYPE_HSPA; 783 case ServiceState.RIL_RADIO_TECHNOLOGY_IS95A: 784 case ServiceState.RIL_RADIO_TECHNOLOGY_IS95B: 785 return TelephonyManager.NETWORK_TYPE_CDMA; 786 case ServiceState.RIL_RADIO_TECHNOLOGY_1xRTT: 787 return TelephonyManager.NETWORK_TYPE_1xRTT; 788 case ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_0: 789 return TelephonyManager.NETWORK_TYPE_EVDO_0; 790 case ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_A: 791 return TelephonyManager.NETWORK_TYPE_EVDO_A; 792 case ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_B: 793 return TelephonyManager.NETWORK_TYPE_EVDO_B; 794 case ServiceState.RIL_RADIO_TECHNOLOGY_EHRPD: 795 return TelephonyManager.NETWORK_TYPE_EHRPD; 796 case ServiceState.RIL_RADIO_TECHNOLOGY_LTE: 797 return TelephonyManager.NETWORK_TYPE_LTE; 798 case ServiceState.RIL_RADIO_TECHNOLOGY_HSPAP: 799 return TelephonyManager.NETWORK_TYPE_HSPAP; 800 default: 801 return TelephonyManager.NETWORK_TYPE_UNKNOWN; 802 } 803 } 804 805 /** 806 * @Deprecated to be removed Q3 2013 use {@link #getVoiceNetworkType} 807 * @hide 808 */ 809 public int getNetworkType() { 810 Rlog.e(LOG_TAG, "ServiceState.getNetworkType() DEPRECATED will be removed *******"); 811 return rilRadioTechnologyToNetworkType(mRilVoiceRadioTechnology); 812 } 813 814 /** @hide */ 815 public int getDataNetworkType() { 816 return rilRadioTechnologyToNetworkType(mRilDataRadioTechnology); 817 } 818 819 /** @hide */ 820 public int getVoiceNetworkType() { 821 return rilRadioTechnologyToNetworkType(mRilVoiceRadioTechnology); 822 } 823 824 /** @hide */ 825 public int getCssIndicator() { 826 return this.mCssIndicator ? 1 : 0; 827 } 828 829 /** @hide */ 830 public int getNetworkId() { 831 return this.mNetworkId; 832 } 833 834 /** @hide */ 835 public int getSystemId() { 836 return this.mSystemId; 837 } 838 839 /** @hide */ 840 public static boolean isGsm(int radioTechnology) { 841 return radioTechnology == RIL_RADIO_TECHNOLOGY_GPRS 842 || radioTechnology == RIL_RADIO_TECHNOLOGY_EDGE 843 || radioTechnology == RIL_RADIO_TECHNOLOGY_UMTS 844 || radioTechnology == RIL_RADIO_TECHNOLOGY_HSDPA 845 || radioTechnology == RIL_RADIO_TECHNOLOGY_HSUPA 846 || radioTechnology == RIL_RADIO_TECHNOLOGY_HSPA 847 || radioTechnology == RIL_RADIO_TECHNOLOGY_LTE 848 || radioTechnology == RIL_RADIO_TECHNOLOGY_HSPAP 849 || radioTechnology == RIL_RADIO_TECHNOLOGY_GSM; 850 } 851 852 /** @hide */ 853 public static boolean isCdma(int radioTechnology) { 854 return radioTechnology == RIL_RADIO_TECHNOLOGY_IS95A 855 || radioTechnology == RIL_RADIO_TECHNOLOGY_IS95B 856 || radioTechnology == RIL_RADIO_TECHNOLOGY_1xRTT 857 || radioTechnology == RIL_RADIO_TECHNOLOGY_EVDO_0 858 || radioTechnology == RIL_RADIO_TECHNOLOGY_EVDO_A 859 || radioTechnology == RIL_RADIO_TECHNOLOGY_EVDO_B 860 || radioTechnology == RIL_RADIO_TECHNOLOGY_EHRPD; 861 } 862 } 863