ServiceState.java revision b690ac3b27d9b782a23a5f9a82bb3421e88716e3
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 android.telephony; 18 19import android.os.Bundle; 20import android.os.Parcel; 21import android.os.Parcelable; 22import android.util.Log; 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 */ 36public 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 * @Deprecate remove 3Q 2013, use {@link #getVoiceState} 301 */ 302 public int getState() { 303 return getVoiceState(); 304 } 305 306 /** 307 * Get current voice service state 308 * 309 * @see #STATE_IN_SERVICE 310 * @see #STATE_OUT_OF_SERVICE 311 * @see #STATE_EMERGENCY_ONLY 312 * @see #STATE_POWER_OFF 313 */ 314 public int getVoiceState() { 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 public int getDataRegState() { 327 return mDataRegState; 328 } 329 330 /** 331 * Get current roaming indicator of phone 332 * (note: not just decoding from TS 27.007 7.2) 333 * 334 * @return true if TS 27.007 7.2 roaming is true 335 * and ONS is different from SPN 336 * 337 */ 338 public boolean getRoaming() { 339 return mRoaming; 340 } 341 342 /** 343 * @hide 344 */ 345 public boolean isEmergencyOnly() { 346 return mIsEmergencyOnly; 347 } 348 349 /** 350 * @hide 351 */ 352 public int getCdmaRoamingIndicator(){ 353 return this.mCdmaRoamingIndicator; 354 } 355 356 /** 357 * @hide 358 */ 359 public int getCdmaDefaultRoamingIndicator(){ 360 return this.mCdmaDefaultRoamingIndicator; 361 } 362 363 /** 364 * @hide 365 */ 366 public int getCdmaEriIconIndex() { 367 return this.mCdmaEriIconIndex; 368 } 369 370 /** 371 * @hide 372 */ 373 public int getCdmaEriIconMode() { 374 return this.mCdmaEriIconMode; 375 } 376 377 /** 378 * Get current registered operator name in long alphanumeric format. 379 * 380 * In GSM/UMTS, long format can be up to 16 characters long. 381 * In CDMA, returns the ERI text, if set. Otherwise, returns the ONS. 382 * 383 * @return long name of operator, null if unregistered or unknown 384 */ 385 public String getOperatorAlphaLong() { 386 return mOperatorAlphaLong; 387 } 388 389 /** 390 * Get current registered operator name in short alphanumeric format. 391 * 392 * In GSM/UMTS, short format can be up to 8 characters long. 393 * 394 * @return short name of operator, null if unregistered or unknown 395 */ 396 public String getOperatorAlphaShort() { 397 return mOperatorAlphaShort; 398 } 399 400 /** 401 * Get current registered operator numeric id. 402 * 403 * In GSM/UMTS, numeric format is 3 digit country code plus 2 or 3 digit 404 * network code. 405 * 406 * @return numeric format of operator, null if unregistered or unknown 407 */ 408 /* 409 * The country code can be decoded using 410 * {@link com.android.internal.telephony.MccTable#countryCodeForMcc(int)}. 411 */ 412 public String getOperatorNumeric() { 413 return mOperatorNumeric; 414 } 415 416 /** 417 * Get current network selection mode. 418 * 419 * @return true if manual mode, false if automatic mode 420 */ 421 public boolean getIsManualSelection() { 422 return mIsManualNetworkSelection; 423 } 424 425 @Override 426 public int hashCode() { 427 return ((mVoiceRegState * 31) 428 + (mDataRegState * 37) 429 + (mRoaming ? 1 : 0) 430 + (mIsManualNetworkSelection ? 1 : 0) 431 + ((null == mOperatorAlphaLong) ? 0 : mOperatorAlphaLong.hashCode()) 432 + ((null == mOperatorAlphaShort) ? 0 : mOperatorAlphaShort.hashCode()) 433 + ((null == mOperatorNumeric) ? 0 : mOperatorNumeric.hashCode()) 434 + mCdmaRoamingIndicator 435 + mCdmaDefaultRoamingIndicator 436 + (mIsEmergencyOnly ? 1 : 0)); 437 } 438 439 @Override 440 public boolean equals (Object o) { 441 ServiceState s; 442 443 try { 444 s = (ServiceState) o; 445 } catch (ClassCastException ex) { 446 return false; 447 } 448 449 if (o == null) { 450 return false; 451 } 452 453 return (mVoiceRegState == s.mVoiceRegState 454 && mDataRegState == s.mDataRegState 455 && mRoaming == s.mRoaming 456 && mIsManualNetworkSelection == s.mIsManualNetworkSelection 457 && equalsHandlesNulls(mOperatorAlphaLong, s.mOperatorAlphaLong) 458 && equalsHandlesNulls(mOperatorAlphaShort, s.mOperatorAlphaShort) 459 && equalsHandlesNulls(mOperatorNumeric, s.mOperatorNumeric) 460 && equalsHandlesNulls(mRilVoiceRadioTechnology, s.mRilVoiceRadioTechnology) 461 && equalsHandlesNulls(mRilDataRadioTechnology, s.mRilDataRadioTechnology) 462 && equalsHandlesNulls(mCssIndicator, s.mCssIndicator) 463 && equalsHandlesNulls(mNetworkId, s.mNetworkId) 464 && equalsHandlesNulls(mSystemId, s.mSystemId) 465 && equalsHandlesNulls(mCdmaRoamingIndicator, s.mCdmaRoamingIndicator) 466 && equalsHandlesNulls(mCdmaDefaultRoamingIndicator, 467 s.mCdmaDefaultRoamingIndicator) 468 && mIsEmergencyOnly == s.mIsEmergencyOnly); 469 } 470 471 /** 472 * Convert radio technology to String 473 * 474 * @param radioTechnology 475 * @return String representation of the RAT 476 * 477 * @hide 478 */ 479 public static String rilRadioTechnologyToString(int rt) { 480 String rtString; 481 482 switch(rt) { 483 case RIL_RADIO_TECHNOLOGY_UNKNOWN: 484 rtString = "Unknown"; 485 break; 486 case RIL_RADIO_TECHNOLOGY_GPRS: 487 rtString = "GPRS"; 488 break; 489 case RIL_RADIO_TECHNOLOGY_EDGE: 490 rtString = "EDGE"; 491 break; 492 case RIL_RADIO_TECHNOLOGY_UMTS: 493 rtString = "UMTS"; 494 break; 495 case RIL_RADIO_TECHNOLOGY_IS95A: 496 rtString = "CDMA-IS95A"; 497 break; 498 case RIL_RADIO_TECHNOLOGY_IS95B: 499 rtString = "CDMA-IS95B"; 500 break; 501 case RIL_RADIO_TECHNOLOGY_1xRTT: 502 rtString = "1xRTT"; 503 break; 504 case RIL_RADIO_TECHNOLOGY_EVDO_0: 505 rtString = "EvDo-rev.0"; 506 break; 507 case RIL_RADIO_TECHNOLOGY_EVDO_A: 508 rtString = "EvDo-rev.A"; 509 break; 510 case RIL_RADIO_TECHNOLOGY_HSDPA: 511 rtString = "HSDPA"; 512 break; 513 case RIL_RADIO_TECHNOLOGY_HSUPA: 514 rtString = "HSUPA"; 515 break; 516 case RIL_RADIO_TECHNOLOGY_HSPA: 517 rtString = "HSPA"; 518 break; 519 case RIL_RADIO_TECHNOLOGY_EVDO_B: 520 rtString = "EvDo-rev.B"; 521 break; 522 case RIL_RADIO_TECHNOLOGY_EHRPD: 523 rtString = "eHRPD"; 524 break; 525 case RIL_RADIO_TECHNOLOGY_LTE: 526 rtString = "LTE"; 527 break; 528 case RIL_RADIO_TECHNOLOGY_HSPAP: 529 rtString = "HSPAP"; 530 break; 531 case RIL_RADIO_TECHNOLOGY_GSM: 532 rtString = "GSM"; 533 break; 534 default: 535 rtString = "Unexpected"; 536 Log.w(LOG_TAG, "Unexpected radioTechnology=" + rt); 537 break; 538 } 539 return rtString; 540 } 541 542 @Override 543 public String toString() { 544 String radioTechnology = rilRadioTechnologyToString(mRilVoiceRadioTechnology); 545 String dataRadioTechnology = rilRadioTechnologyToString(mRilDataRadioTechnology); 546 547 return (mVoiceRegState + " " + mDataRegState + " " + (mRoaming ? "roaming" : "home") 548 + " " + mOperatorAlphaLong 549 + " " + mOperatorAlphaShort 550 + " " + mOperatorNumeric 551 + " " + (mIsManualNetworkSelection ? "(manual)" : "") 552 + " " + radioTechnology 553 + " " + dataRadioTechnology 554 + " " + (mCssIndicator ? "CSS supported" : "CSS not supported") 555 + " " + mNetworkId 556 + " " + mSystemId 557 + " RoamInd=" + mCdmaRoamingIndicator 558 + " DefRoamInd=" + mCdmaDefaultRoamingIndicator 559 + " EmergOnly=" + mIsEmergencyOnly); 560 } 561 562 private void setNullState(int state) { 563 if (DBG) Log.d(LOG_TAG, "[ServiceState] setNullState=" + state); 564 mVoiceRegState = state; 565 mDataRegState = state; 566 mRoaming = false; 567 mOperatorAlphaLong = null; 568 mOperatorAlphaShort = null; 569 mOperatorNumeric = null; 570 mIsManualNetworkSelection = false; 571 mRilVoiceRadioTechnology = 0; 572 mRilDataRadioTechnology = 0; 573 mCssIndicator = false; 574 mNetworkId = -1; 575 mSystemId = -1; 576 mCdmaRoamingIndicator = -1; 577 mCdmaDefaultRoamingIndicator = -1; 578 mCdmaEriIconIndex = -1; 579 mCdmaEriIconMode = -1; 580 mIsEmergencyOnly = false; 581 } 582 583 public void setStateOutOfService() { 584 setNullState(STATE_OUT_OF_SERVICE); 585 } 586 587 public void setStateOff() { 588 setNullState(STATE_POWER_OFF); 589 } 590 591 /** @Deprecated to be removed Q3 2013, use {@link #getVoiceState} */ 592 public void setState(int state) { 593 setVoiceState(state); 594 if (DBG) Log.e(LOG_TAG, "[ServiceState] setState deprecated use getVoiceState()"); 595 } 596 597 public void setVoiceState(int state) { 598 mVoiceRegState = state; 599 if (DBG) Log.d(LOG_TAG, "[ServiceState] setState=" + mVoiceRegState); 600 } 601 602 public void setDataRegState(int state) { 603 mDataRegState = state; 604 if (DBG) Log.d(LOG_TAG, "[ServiceState] setDataRegState=" + mDataRegState); 605 } 606 607 public void setRoaming(boolean roaming) { 608 mRoaming = roaming; 609 } 610 611 612 /** 613 * @hide 614 */ 615 public void setEmergencyOnly(boolean emergencyOnly) { 616 mIsEmergencyOnly = emergencyOnly; 617 } 618 619 /** 620 * @hide 621 */ 622 public void setCdmaRoamingIndicator(int roaming) { 623 this.mCdmaRoamingIndicator = roaming; 624 } 625 626 /** 627 * @hide 628 */ 629 public void setCdmaDefaultRoamingIndicator (int roaming) { 630 this.mCdmaDefaultRoamingIndicator = roaming; 631 } 632 633 /** 634 * @hide 635 */ 636 public void setCdmaEriIconIndex(int index) { 637 this.mCdmaEriIconIndex = index; 638 } 639 640 /** 641 * @hide 642 */ 643 public void setCdmaEriIconMode(int mode) { 644 this.mCdmaEriIconMode = mode; 645 } 646 647 public void setOperatorName(String longName, String shortName, String numeric) { 648 mOperatorAlphaLong = longName; 649 mOperatorAlphaShort = shortName; 650 mOperatorNumeric = numeric; 651 } 652 653 /** 654 * In CDMA, mOperatorAlphaLong can be set from the ERI text. 655 * This is done from the CDMAPhone and not from the CdmaServiceStateTracker. 656 * 657 * @hide 658 */ 659 public void setOperatorAlphaLong(String longName) { 660 mOperatorAlphaLong = longName; 661 } 662 663 public void setIsManualSelection(boolean isManual) { 664 mIsManualNetworkSelection = isManual; 665 } 666 667 /** 668 * Test whether two objects hold the same data values or both are null. 669 * 670 * @param a first obj 671 * @param b second obj 672 * @return true if two objects equal or both are null 673 */ 674 private static boolean equalsHandlesNulls (Object a, Object b) { 675 return (a == null) ? (b == null) : a.equals (b); 676 } 677 678 /** 679 * Set ServiceState based on intent notifier map. 680 * 681 * @param m intent notifier map 682 * @hide 683 */ 684 private void setFromNotifierBundle(Bundle m) { 685 mVoiceRegState = m.getInt("voiceRegState"); 686 mDataRegState = m.getInt("dataRegState"); 687 mRoaming = m.getBoolean("roaming"); 688 mOperatorAlphaLong = m.getString("operator-alpha-long"); 689 mOperatorAlphaShort = m.getString("operator-alpha-short"); 690 mOperatorNumeric = m.getString("operator-numeric"); 691 mIsManualNetworkSelection = m.getBoolean("manual"); 692 mRilVoiceRadioTechnology = m.getInt("radioTechnology"); 693 mRilVoiceRadioTechnology = m.getInt("dataRadioTechnology"); 694 mCssIndicator = m.getBoolean("cssIndicator"); 695 mNetworkId = m.getInt("networkId"); 696 mSystemId = m.getInt("systemId"); 697 mCdmaRoamingIndicator = m.getInt("cdmaRoamingIndicator"); 698 mCdmaDefaultRoamingIndicator = m.getInt("cdmaDefaultRoamingIndicator"); 699 mIsEmergencyOnly = m.getBoolean("emergencyOnly"); 700 } 701 702 /** 703 * Set intent notifier Bundle based on service state. 704 * 705 * @param m intent notifier Bundle 706 * @hide 707 */ 708 public void fillInNotifierBundle(Bundle m) { 709 m.putInt("voiceRegState", mVoiceRegState); 710 m.putInt("dataRegState", mDataRegState); 711 m.putBoolean("roaming", Boolean.valueOf(mRoaming)); 712 m.putString("operator-alpha-long", mOperatorAlphaLong); 713 m.putString("operator-alpha-short", mOperatorAlphaShort); 714 m.putString("operator-numeric", mOperatorNumeric); 715 m.putBoolean("manual", Boolean.valueOf(mIsManualNetworkSelection)); 716 m.putInt("radioTechnology", mRilVoiceRadioTechnology); 717 m.putInt("dataRadioTechnology", mRilDataRadioTechnology); 718 m.putBoolean("cssIndicator", mCssIndicator); 719 m.putInt("networkId", mNetworkId); 720 m.putInt("systemId", mSystemId); 721 m.putInt("cdmaRoamingIndicator", mCdmaRoamingIndicator); 722 m.putInt("cdmaDefaultRoamingIndicator", mCdmaDefaultRoamingIndicator); 723 m.putBoolean("emergencyOnly", Boolean.valueOf(mIsEmergencyOnly)); 724 } 725 726 /** @hide */ 727 public void setRilVoiceRadioTechnology(int rt) { 728 this.mRilVoiceRadioTechnology = rt; 729 } 730 731 /** @hide */ 732 public void setRilDataRadioTechnology(int rt) { 733 this.mRilDataRadioTechnology = rt; 734 if (DBG) Log.d(LOG_TAG, "[ServiceState] setDataRadioTechnology=" + mRilDataRadioTechnology); 735 } 736 737 /** @hide */ 738 public void setCssIndicator(int css) { 739 this.mCssIndicator = (css != 0); 740 } 741 742 /** @hide */ 743 public void setSystemAndNetworkId(int systemId, int networkId) { 744 this.mSystemId = systemId; 745 this.mNetworkId = networkId; 746 } 747 748 /** @hide */ 749 public int getRilVoiceRadioTechnology() { 750 return this.mRilVoiceRadioTechnology; 751 } 752 /** @hide */ 753 public int getRilDataRadioTechnology() { 754 return this.mRilDataRadioTechnology; 755 } 756 /** 757 * @hide 758 * @Deprecated to be removed Q3 2013 use {@link #getRilDataRadioTechnology} or 759 * {@link #getRilVoiceRadioTechnology} 760 */ 761 public int getRadioTechnology() { 762 Log.e(LOG_TAG, "ServiceState.getRadioTechnology() DEPRECATED will be removed *******"); 763 return getRilDataRadioTechnology(); 764 } 765 766 private int rilRadioTechnologyToNetworkType(int rt) { 767 switch(rt) { 768 case ServiceState.RIL_RADIO_TECHNOLOGY_GPRS: 769 return TelephonyManager.NETWORK_TYPE_GPRS; 770 case ServiceState.RIL_RADIO_TECHNOLOGY_EDGE: 771 return TelephonyManager.NETWORK_TYPE_EDGE; 772 case ServiceState.RIL_RADIO_TECHNOLOGY_UMTS: 773 return TelephonyManager.NETWORK_TYPE_UMTS; 774 case ServiceState.RIL_RADIO_TECHNOLOGY_HSDPA: 775 return TelephonyManager.NETWORK_TYPE_HSDPA; 776 case ServiceState.RIL_RADIO_TECHNOLOGY_HSUPA: 777 return TelephonyManager.NETWORK_TYPE_HSUPA; 778 case ServiceState.RIL_RADIO_TECHNOLOGY_HSPA: 779 return TelephonyManager.NETWORK_TYPE_HSPA; 780 case ServiceState.RIL_RADIO_TECHNOLOGY_IS95A: 781 case ServiceState.RIL_RADIO_TECHNOLOGY_IS95B: 782 return TelephonyManager.NETWORK_TYPE_CDMA; 783 case ServiceState.RIL_RADIO_TECHNOLOGY_1xRTT: 784 return TelephonyManager.NETWORK_TYPE_1xRTT; 785 case ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_0: 786 return TelephonyManager.NETWORK_TYPE_EVDO_0; 787 case ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_A: 788 return TelephonyManager.NETWORK_TYPE_EVDO_A; 789 case ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_B: 790 return TelephonyManager.NETWORK_TYPE_EVDO_B; 791 case ServiceState.RIL_RADIO_TECHNOLOGY_EHRPD: 792 return TelephonyManager.NETWORK_TYPE_EHRPD; 793 case ServiceState.RIL_RADIO_TECHNOLOGY_LTE: 794 return TelephonyManager.NETWORK_TYPE_LTE; 795 case ServiceState.RIL_RADIO_TECHNOLOGY_HSPAP: 796 return TelephonyManager.NETWORK_TYPE_HSPAP; 797 default: 798 return TelephonyManager.NETWORK_TYPE_UNKNOWN; 799 } 800 } 801 802 /** 803 * @Deprecated to be removed Q3 2013 use {@link #getVoiceNetworkType} 804 * @hide 805 */ 806 public int getNetworkType() { 807 Log.e(LOG_TAG, "ServiceState.getNetworkType() DEPRECATED will be removed *******"); 808 return rilRadioTechnologyToNetworkType(mRilVoiceRadioTechnology); 809 } 810 811 /** @hide */ 812 public int getDataNetworkType() { 813 return rilRadioTechnologyToNetworkType(mRilDataRadioTechnology); 814 } 815 816 /** @hide */ 817 public int getVoiceNetworkType() { 818 return rilRadioTechnologyToNetworkType(mRilVoiceRadioTechnology); 819 } 820 821 /** @hide */ 822 public int getCssIndicator() { 823 return this.mCssIndicator ? 1 : 0; 824 } 825 826 /** @hide */ 827 public int getNetworkId() { 828 return this.mNetworkId; 829 } 830 831 /** @hide */ 832 public int getSystemId() { 833 return this.mSystemId; 834 } 835 836 /** @hide */ 837 public static boolean isGsm(int radioTechnology) { 838 return radioTechnology == RIL_RADIO_TECHNOLOGY_GPRS 839 || radioTechnology == RIL_RADIO_TECHNOLOGY_EDGE 840 || radioTechnology == RIL_RADIO_TECHNOLOGY_UMTS 841 || radioTechnology == RIL_RADIO_TECHNOLOGY_HSDPA 842 || radioTechnology == RIL_RADIO_TECHNOLOGY_HSUPA 843 || radioTechnology == RIL_RADIO_TECHNOLOGY_HSPA 844 || radioTechnology == RIL_RADIO_TECHNOLOGY_LTE 845 || radioTechnology == RIL_RADIO_TECHNOLOGY_HSPAP 846 || radioTechnology == RIL_RADIO_TECHNOLOGY_GSM; 847 } 848 849 /** @hide */ 850 public static boolean isCdma(int radioTechnology) { 851 return radioTechnology == RIL_RADIO_TECHNOLOGY_IS95A 852 || radioTechnology == RIL_RADIO_TECHNOLOGY_IS95B 853 || radioTechnology == RIL_RADIO_TECHNOLOGY_1xRTT 854 || radioTechnology == RIL_RADIO_TECHNOLOGY_EVDO_0 855 || radioTechnology == RIL_RADIO_TECHNOLOGY_EVDO_A 856 || radioTechnology == RIL_RADIO_TECHNOLOGY_EVDO_B 857 || radioTechnology == RIL_RADIO_TECHNOLOGY_EHRPD; 858 } 859} 860