ServiceState.java revision 5c868a2cd27b499928dfbadc0bf9a59169c6a35e
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.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 */ 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 /** @hide */ 150 public static final int RIL_RADIO_TECHNOLOGY_TD_SCDMA = 17; 151 /** 152 * IWLAN 153 * @hide 154 */ 155 public static final int RIL_RADIO_TECHNOLOGY_IWLAN = 18; 156 /** 157 * Available registration states for GSM, UMTS and CDMA. 158 */ 159 /** @hide */ 160 public static final int REGISTRATION_STATE_NOT_REGISTERED_AND_NOT_SEARCHING = 0; 161 /** @hide */ 162 public static final int REGISTRATION_STATE_HOME_NETWORK = 1; 163 /** @hide */ 164 public static final int REGISTRATION_STATE_NOT_REGISTERED_AND_SEARCHING = 2; 165 /** @hide */ 166 public static final int REGISTRATION_STATE_REGISTRATION_DENIED = 3; 167 /** @hide */ 168 public static final int REGISTRATION_STATE_UNKNOWN = 4; 169 /** @hide */ 170 public static final int REGISTRATION_STATE_ROAMING = 5; 171 172 private int mVoiceRegState = STATE_OUT_OF_SERVICE; 173 private int mDataRegState = STATE_OUT_OF_SERVICE; 174 175 /** 176 * Roaming type 177 * HOME : in home network 178 * @hide 179 */ 180 public static final int ROAMING_TYPE_NOT_ROAMING = 0; 181 /** 182 * Roaming type 183 * UNKNOWN : in a roaming network, but we can not tell if it's domestic or international 184 * @hide 185 */ 186 public static final int ROAMING_TYPE_UNKNOWN = 1; 187 /** 188 * Roaming type 189 * DOMESTIC : in domestic roaming network 190 * @hide 191 */ 192 public static final int ROAMING_TYPE_DOMESTIC = 2; 193 /** 194 * Roaming type 195 * INTERNATIONAL : in international roaming network 196 * @hide 197 */ 198 public static final int ROAMING_TYPE_INTERNATIONAL = 3; 199 200 private int mVoiceRoamingType; 201 private int mDataRoamingType; 202 private String mVoiceOperatorAlphaLong; 203 private String mVoiceOperatorAlphaShort; 204 private String mVoiceOperatorNumeric; 205 private String mDataOperatorAlphaLong; 206 private String mDataOperatorAlphaShort; 207 private String mDataOperatorNumeric; 208 private boolean mIsManualNetworkSelection; 209 210 private boolean mIsEmergencyOnly; 211 212 private int mRilVoiceRadioTechnology; 213 private int mRilDataRadioTechnology; 214 215 private boolean mCssIndicator; 216 private int mNetworkId; 217 private int mSystemId; 218 private int mCdmaRoamingIndicator; 219 private int mCdmaDefaultRoamingIndicator; 220 private int mCdmaEriIconIndex; 221 private int mCdmaEriIconMode; 222 223 /** 224 * get String description of roaming type 225 * @hide 226 */ 227 public static final String getRoamingLogString(int roamingType) { 228 switch (roamingType) { 229 case ROAMING_TYPE_NOT_ROAMING: 230 return "home"; 231 232 case ROAMING_TYPE_UNKNOWN: 233 return "roaming"; 234 235 case ROAMING_TYPE_DOMESTIC: 236 return "Domestic Roaming"; 237 238 case ROAMING_TYPE_INTERNATIONAL: 239 return "International Roaming"; 240 241 default: 242 return "UNKNOWN"; 243 } 244 } 245 246 /** 247 * Create a new ServiceState from a intent notifier Bundle 248 * 249 * This method is used by PhoneStateIntentReceiver and maybe by 250 * external applications. 251 * 252 * @param m Bundle from intent notifier 253 * @return newly created ServiceState 254 * @hide 255 */ 256 public static ServiceState newFromBundle(Bundle m) { 257 ServiceState ret; 258 ret = new ServiceState(); 259 ret.setFromNotifierBundle(m); 260 return ret; 261 } 262 263 /** 264 * Empty constructor 265 */ 266 public ServiceState() { 267 } 268 269 /** 270 * Copy constructors 271 * 272 * @param s Source service state 273 */ 274 public ServiceState(ServiceState s) { 275 copyFrom(s); 276 } 277 278 protected void copyFrom(ServiceState s) { 279 mVoiceRegState = s.mVoiceRegState; 280 mDataRegState = s.mDataRegState; 281 mVoiceRoamingType = s.mVoiceRoamingType; 282 mDataRoamingType = s.mDataRoamingType; 283 mVoiceOperatorAlphaLong = s.mVoiceOperatorAlphaLong; 284 mVoiceOperatorAlphaShort = s.mVoiceOperatorAlphaShort; 285 mVoiceOperatorNumeric = s.mVoiceOperatorNumeric; 286 mDataOperatorAlphaLong = s.mDataOperatorAlphaLong; 287 mDataOperatorAlphaShort = s.mDataOperatorAlphaShort; 288 mDataOperatorNumeric = s.mDataOperatorNumeric; 289 mIsManualNetworkSelection = s.mIsManualNetworkSelection; 290 mRilVoiceRadioTechnology = s.mRilVoiceRadioTechnology; 291 mRilDataRadioTechnology = s.mRilDataRadioTechnology; 292 mCssIndicator = s.mCssIndicator; 293 mNetworkId = s.mNetworkId; 294 mSystemId = s.mSystemId; 295 mCdmaRoamingIndicator = s.mCdmaRoamingIndicator; 296 mCdmaDefaultRoamingIndicator = s.mCdmaDefaultRoamingIndicator; 297 mCdmaEriIconIndex = s.mCdmaEriIconIndex; 298 mCdmaEriIconMode = s.mCdmaEriIconMode; 299 mIsEmergencyOnly = s.mIsEmergencyOnly; 300 } 301 302 /** 303 * Construct a ServiceState object from the given parcel. 304 */ 305 public ServiceState(Parcel in) { 306 mVoiceRegState = in.readInt(); 307 mDataRegState = in.readInt(); 308 mVoiceRoamingType = in.readInt(); 309 mDataRoamingType = in.readInt(); 310 mVoiceOperatorAlphaLong = in.readString(); 311 mVoiceOperatorAlphaShort = in.readString(); 312 mVoiceOperatorNumeric = in.readString(); 313 mDataOperatorAlphaLong = in.readString(); 314 mDataOperatorAlphaShort = in.readString(); 315 mDataOperatorNumeric = in.readString(); 316 mIsManualNetworkSelection = in.readInt() != 0; 317 mRilVoiceRadioTechnology = in.readInt(); 318 mRilDataRadioTechnology = in.readInt(); 319 mCssIndicator = (in.readInt() != 0); 320 mNetworkId = in.readInt(); 321 mSystemId = in.readInt(); 322 mCdmaRoamingIndicator = in.readInt(); 323 mCdmaDefaultRoamingIndicator = in.readInt(); 324 mCdmaEriIconIndex = in.readInt(); 325 mCdmaEriIconMode = in.readInt(); 326 mIsEmergencyOnly = in.readInt() != 0; 327 } 328 329 public void writeToParcel(Parcel out, int flags) { 330 out.writeInt(mVoiceRegState); 331 out.writeInt(mDataRegState); 332 out.writeInt(mVoiceRoamingType); 333 out.writeInt(mDataRoamingType); 334 out.writeString(mVoiceOperatorAlphaLong); 335 out.writeString(mVoiceOperatorAlphaShort); 336 out.writeString(mVoiceOperatorNumeric); 337 out.writeString(mDataOperatorAlphaLong); 338 out.writeString(mDataOperatorAlphaShort); 339 out.writeString(mDataOperatorNumeric); 340 out.writeInt(mIsManualNetworkSelection ? 1 : 0); 341 out.writeInt(mRilVoiceRadioTechnology); 342 out.writeInt(mRilDataRadioTechnology); 343 out.writeInt(mCssIndicator ? 1 : 0); 344 out.writeInt(mNetworkId); 345 out.writeInt(mSystemId); 346 out.writeInt(mCdmaRoamingIndicator); 347 out.writeInt(mCdmaDefaultRoamingIndicator); 348 out.writeInt(mCdmaEriIconIndex); 349 out.writeInt(mCdmaEriIconMode); 350 out.writeInt(mIsEmergencyOnly ? 1 : 0); 351 } 352 353 public int describeContents() { 354 return 0; 355 } 356 357 public static final Parcelable.Creator<ServiceState> CREATOR = 358 new Parcelable.Creator<ServiceState>() { 359 public ServiceState createFromParcel(Parcel in) { 360 return new ServiceState(in); 361 } 362 363 public ServiceState[] newArray(int size) { 364 return new ServiceState[size]; 365 } 366 }; 367 368 /** 369 * Get current voice service state 370 */ 371 public int getState() { 372 return getVoiceRegState(); 373 } 374 375 /** 376 * Get current voice service state 377 * 378 * @see #STATE_IN_SERVICE 379 * @see #STATE_OUT_OF_SERVICE 380 * @see #STATE_EMERGENCY_ONLY 381 * @see #STATE_POWER_OFF 382 * 383 * @hide 384 */ 385 public int getVoiceRegState() { 386 return mVoiceRegState; 387 } 388 389 /** 390 * Get current data service state 391 * 392 * @see #STATE_IN_SERVICE 393 * @see #STATE_OUT_OF_SERVICE 394 * @see #STATE_EMERGENCY_ONLY 395 * @see #STATE_POWER_OFF 396 * 397 * @hide 398 */ 399 public int getDataRegState() { 400 return mDataRegState; 401 } 402 403 /** 404 * Get current roaming indicator of phone 405 * (note: not just decoding from TS 27.007 7.2) 406 * 407 * @return true if TS 27.007 7.2 roaming is true 408 * and ONS is different from SPN 409 */ 410 public boolean getRoaming() { 411 return getVoiceRoaming() || getDataRoaming(); 412 } 413 414 /** 415 * Get current voice network roaming status 416 * @return roaming status 417 * @hide 418 */ 419 public boolean getVoiceRoaming() { 420 return mVoiceRoamingType != ROAMING_TYPE_NOT_ROAMING; 421 } 422 423 /** 424 * Get current voice network roaming type 425 * @return roaming type 426 * @hide 427 */ 428 public int getVoiceRoamingType() { 429 return mVoiceRoamingType; 430 } 431 432 /** 433 * Get current data network roaming type 434 * @return roaming type 435 * @hide 436 */ 437 public boolean getDataRoaming() { 438 return mDataRoamingType != ROAMING_TYPE_NOT_ROAMING; 439 } 440 441 /** 442 * Get current data network roaming type 443 * @return roaming type 444 * @hide 445 */ 446 public int getDataRoamingType() { 447 return mDataRoamingType; 448 } 449 450 /** 451 * @hide 452 */ 453 public boolean isEmergencyOnly() { 454 return mIsEmergencyOnly; 455 } 456 457 /** 458 * @hide 459 */ 460 public int getCdmaRoamingIndicator(){ 461 return this.mCdmaRoamingIndicator; 462 } 463 464 /** 465 * @hide 466 */ 467 public int getCdmaDefaultRoamingIndicator(){ 468 return this.mCdmaDefaultRoamingIndicator; 469 } 470 471 /** 472 * @hide 473 */ 474 public int getCdmaEriIconIndex() { 475 return this.mCdmaEriIconIndex; 476 } 477 478 /** 479 * @hide 480 */ 481 public int getCdmaEriIconMode() { 482 return this.mCdmaEriIconMode; 483 } 484 485 /** 486 * Get current registered operator name in long alphanumeric format. 487 * 488 * In GSM/UMTS, long format can be up to 16 characters long. 489 * In CDMA, returns the ERI text, if set. Otherwise, returns the ONS. 490 * 491 * @return long name of operator, null if unregistered or unknown 492 */ 493 public String getOperatorAlphaLong() { 494 return mVoiceOperatorAlphaLong; 495 } 496 497 /** 498 * Get current registered voice network operator name in long alphanumeric format. 499 * @return long name of operator 500 * @hide 501 */ 502 public String getVoiceOperatorAlphaLong() { 503 return mVoiceOperatorAlphaLong; 504 } 505 506 /** 507 * Get current registered data network operator name in long alphanumeric format. 508 * @return long name of voice operator 509 * @hide 510 */ 511 public String getDataOperatorAlphaLong() { 512 return mDataOperatorAlphaLong; 513 } 514 515 /** 516 * Get current registered operator name in short alphanumeric format. 517 * 518 * In GSM/UMTS, short format can be up to 8 characters long. 519 * 520 * @return short name of operator, null if unregistered or unknown 521 */ 522 public String getOperatorAlphaShort() { 523 return mVoiceOperatorAlphaShort; 524 } 525 526 /** 527 * Get current registered voice network operator name in short alphanumeric format. 528 * @return short name of operator, null if unregistered or unknown 529 * @hide 530 */ 531 public String getVoiceOperatorAlphaShort() { 532 return mVoiceOperatorAlphaShort; 533 } 534 535 /** 536 * Get current registered data network operator name in short alphanumeric format. 537 * @return short name of operator, null if unregistered or unknown 538 * @hide 539 */ 540 public String getDataOperatorAlphaShort() { 541 return mDataOperatorAlphaShort; 542 } 543 544 /** 545 * Get current registered operator numeric id. 546 * 547 * In GSM/UMTS, numeric format is 3 digit country code plus 2 or 3 digit 548 * network code. 549 * 550 * @return numeric format of operator, null if unregistered or unknown 551 */ 552 /* 553 * The country code can be decoded using 554 * {@link com.android.internal.telephony.MccTable#countryCodeForMcc(int)}. 555 */ 556 public String getOperatorNumeric() { 557 return mVoiceOperatorNumeric; 558 } 559 560 /** 561 * Get current registered voice network operator numeric id. 562 * @return numeric format of operator, null if unregistered or unknown 563 * @hide 564 */ 565 public String getVoiceOperatorNumeric() { 566 return mVoiceOperatorNumeric; 567 } 568 569 /** 570 * Get current registered data network operator numeric id. 571 * @return numeric format of operator, null if unregistered or unknown 572 * @hide 573 */ 574 public String getDataOperatorNumeric() { 575 return mDataOperatorNumeric; 576 } 577 578 /** 579 * Get current network selection mode. 580 * 581 * @return true if manual mode, false if automatic mode 582 */ 583 public boolean getIsManualSelection() { 584 return mIsManualNetworkSelection; 585 } 586 587 @Override 588 public int hashCode() { 589 return ((mVoiceRegState * 31) 590 + (mDataRegState * 37) 591 + mVoiceRoamingType 592 + mDataRoamingType 593 + (mIsManualNetworkSelection ? 1 : 0) 594 + ((null == mVoiceOperatorAlphaLong) ? 0 : mVoiceOperatorAlphaLong.hashCode()) 595 + ((null == mVoiceOperatorAlphaShort) ? 0 : mVoiceOperatorAlphaShort.hashCode()) 596 + ((null == mVoiceOperatorNumeric) ? 0 : mVoiceOperatorNumeric.hashCode()) 597 + ((null == mDataOperatorAlphaLong) ? 0 : mDataOperatorAlphaLong.hashCode()) 598 + ((null == mDataOperatorAlphaShort) ? 0 : mDataOperatorAlphaShort.hashCode()) 599 + ((null == mDataOperatorNumeric) ? 0 : mDataOperatorNumeric.hashCode()) 600 + mCdmaRoamingIndicator 601 + mCdmaDefaultRoamingIndicator 602 + (mIsEmergencyOnly ? 1 : 0)); 603 } 604 605 @Override 606 public boolean equals (Object o) { 607 ServiceState s; 608 609 try { 610 s = (ServiceState) o; 611 } catch (ClassCastException ex) { 612 return false; 613 } 614 615 if (o == null) { 616 return false; 617 } 618 619 return (mVoiceRegState == s.mVoiceRegState 620 && mDataRegState == s.mDataRegState 621 && mIsManualNetworkSelection == s.mIsManualNetworkSelection 622 && mVoiceRoamingType == s.mVoiceRoamingType 623 && mDataRoamingType == s.mDataRoamingType 624 && equalsHandlesNulls(mVoiceOperatorAlphaLong, s.mVoiceOperatorAlphaLong) 625 && equalsHandlesNulls(mVoiceOperatorAlphaShort, s.mVoiceOperatorAlphaShort) 626 && equalsHandlesNulls(mVoiceOperatorNumeric, s.mVoiceOperatorNumeric) 627 && equalsHandlesNulls(mDataOperatorAlphaLong, s.mDataOperatorAlphaLong) 628 && equalsHandlesNulls(mDataOperatorAlphaShort, s.mDataOperatorAlphaShort) 629 && equalsHandlesNulls(mDataOperatorNumeric, s.mDataOperatorNumeric) 630 && equalsHandlesNulls(mRilVoiceRadioTechnology, s.mRilVoiceRadioTechnology) 631 && equalsHandlesNulls(mRilDataRadioTechnology, s.mRilDataRadioTechnology) 632 && equalsHandlesNulls(mCssIndicator, s.mCssIndicator) 633 && equalsHandlesNulls(mNetworkId, s.mNetworkId) 634 && equalsHandlesNulls(mSystemId, s.mSystemId) 635 && equalsHandlesNulls(mCdmaRoamingIndicator, s.mCdmaRoamingIndicator) 636 && equalsHandlesNulls(mCdmaDefaultRoamingIndicator, 637 s.mCdmaDefaultRoamingIndicator) 638 && mIsEmergencyOnly == s.mIsEmergencyOnly); 639 } 640 641 /** 642 * Convert radio technology to String 643 * 644 * @param radioTechnology 645 * @return String representation of the RAT 646 * 647 * @hide 648 */ 649 public static String rilRadioTechnologyToString(int rt) { 650 String rtString; 651 652 switch(rt) { 653 case RIL_RADIO_TECHNOLOGY_UNKNOWN: 654 rtString = "Unknown"; 655 break; 656 case RIL_RADIO_TECHNOLOGY_GPRS: 657 rtString = "GPRS"; 658 break; 659 case RIL_RADIO_TECHNOLOGY_EDGE: 660 rtString = "EDGE"; 661 break; 662 case RIL_RADIO_TECHNOLOGY_UMTS: 663 rtString = "UMTS"; 664 break; 665 case RIL_RADIO_TECHNOLOGY_IS95A: 666 rtString = "CDMA-IS95A"; 667 break; 668 case RIL_RADIO_TECHNOLOGY_IS95B: 669 rtString = "CDMA-IS95B"; 670 break; 671 case RIL_RADIO_TECHNOLOGY_1xRTT: 672 rtString = "1xRTT"; 673 break; 674 case RIL_RADIO_TECHNOLOGY_EVDO_0: 675 rtString = "EvDo-rev.0"; 676 break; 677 case RIL_RADIO_TECHNOLOGY_EVDO_A: 678 rtString = "EvDo-rev.A"; 679 break; 680 case RIL_RADIO_TECHNOLOGY_HSDPA: 681 rtString = "HSDPA"; 682 break; 683 case RIL_RADIO_TECHNOLOGY_HSUPA: 684 rtString = "HSUPA"; 685 break; 686 case RIL_RADIO_TECHNOLOGY_HSPA: 687 rtString = "HSPA"; 688 break; 689 case RIL_RADIO_TECHNOLOGY_EVDO_B: 690 rtString = "EvDo-rev.B"; 691 break; 692 case RIL_RADIO_TECHNOLOGY_EHRPD: 693 rtString = "eHRPD"; 694 break; 695 case RIL_RADIO_TECHNOLOGY_LTE: 696 rtString = "LTE"; 697 break; 698 case RIL_RADIO_TECHNOLOGY_HSPAP: 699 rtString = "HSPAP"; 700 break; 701 case RIL_RADIO_TECHNOLOGY_GSM: 702 rtString = "GSM"; 703 break; 704 case RIL_RADIO_TECHNOLOGY_IWLAN: 705 rtString = "IWLAN"; 706 break; 707 default: 708 rtString = "Unexpected"; 709 Rlog.w(LOG_TAG, "Unexpected radioTechnology=" + rt); 710 break; 711 } 712 return rtString; 713 } 714 715 @Override 716 public String toString() { 717 String radioTechnology = rilRadioTechnologyToString(mRilVoiceRadioTechnology); 718 String dataRadioTechnology = rilRadioTechnologyToString(mRilDataRadioTechnology); 719 720 return (mVoiceRegState + " " + mDataRegState 721 + " " 722 + "voice " + getRoamingLogString(mVoiceRoamingType) 723 + " " 724 + "data " + getRoamingLogString(mDataRoamingType) 725 + " " + mVoiceOperatorAlphaLong 726 + " " + mVoiceOperatorAlphaShort 727 + " " + mVoiceOperatorNumeric 728 + " " + mDataOperatorAlphaLong 729 + " " + mDataOperatorAlphaShort 730 + " " + mDataOperatorNumeric 731 + " " + (mIsManualNetworkSelection ? "(manual)" : "") 732 + " " + radioTechnology 733 + " " + dataRadioTechnology 734 + " " + (mCssIndicator ? "CSS supported" : "CSS not supported") 735 + " " + mNetworkId 736 + " " + mSystemId 737 + " RoamInd=" + mCdmaRoamingIndicator 738 + " DefRoamInd=" + mCdmaDefaultRoamingIndicator 739 + " EmergOnly=" + mIsEmergencyOnly); 740 } 741 742 private void setNullState(int state) { 743 if (DBG) Rlog.d(LOG_TAG, "[ServiceState] setNullState=" + state); 744 mVoiceRegState = state; 745 mDataRegState = state; 746 mVoiceRoamingType = ROAMING_TYPE_NOT_ROAMING; 747 mDataRoamingType = ROAMING_TYPE_NOT_ROAMING; 748 mVoiceOperatorAlphaLong = null; 749 mVoiceOperatorAlphaShort = null; 750 mVoiceOperatorNumeric = null; 751 mDataOperatorAlphaLong = null; 752 mDataOperatorAlphaShort = null; 753 mDataOperatorNumeric = null; 754 mIsManualNetworkSelection = false; 755 mRilVoiceRadioTechnology = 0; 756 mRilDataRadioTechnology = 0; 757 mCssIndicator = false; 758 mNetworkId = -1; 759 mSystemId = -1; 760 mCdmaRoamingIndicator = -1; 761 mCdmaDefaultRoamingIndicator = -1; 762 mCdmaEriIconIndex = -1; 763 mCdmaEriIconMode = -1; 764 mIsEmergencyOnly = false; 765 } 766 767 public void setStateOutOfService() { 768 setNullState(STATE_OUT_OF_SERVICE); 769 } 770 771 public void setStateOff() { 772 setNullState(STATE_POWER_OFF); 773 } 774 775 public void setState(int state) { 776 setVoiceRegState(state); 777 if (DBG) Rlog.e(LOG_TAG, "[ServiceState] setState deprecated use setVoiceRegState()"); 778 } 779 780 /** @hide */ 781 public void setVoiceRegState(int state) { 782 mVoiceRegState = state; 783 if (DBG) Rlog.d(LOG_TAG, "[ServiceState] setVoiceRegState=" + mVoiceRegState); 784 } 785 786 /** @hide */ 787 public void setDataRegState(int state) { 788 mDataRegState = state; 789 if (DBG) Rlog.d(LOG_TAG, "[ServiceState] setDataRegState=" + mDataRegState); 790 } 791 792 public void setRoaming(boolean roaming) { 793 mVoiceRoamingType = (roaming ? ROAMING_TYPE_UNKNOWN : ROAMING_TYPE_NOT_ROAMING); 794 mDataRoamingType = mVoiceRoamingType; 795 } 796 797 /** @hide */ 798 public void setVoiceRoaming(boolean roaming) { 799 mVoiceRoamingType = (roaming ? ROAMING_TYPE_UNKNOWN : ROAMING_TYPE_NOT_ROAMING); 800 } 801 802 /** @hide */ 803 public void setVoiceRoamingType(int type) { 804 mVoiceRoamingType = type; 805 } 806 807 /** @hide */ 808 public void setDataRoaming(boolean dataRoaming) { 809 mDataRoamingType = (dataRoaming ? ROAMING_TYPE_UNKNOWN : ROAMING_TYPE_NOT_ROAMING); 810 } 811 812 /** @hide */ 813 public void setDataRoamingType(int type) { 814 mDataRoamingType = type; 815 } 816 817 /** 818 * @hide 819 */ 820 public void setEmergencyOnly(boolean emergencyOnly) { 821 mIsEmergencyOnly = emergencyOnly; 822 } 823 824 /** 825 * @hide 826 */ 827 public void setCdmaRoamingIndicator(int roaming) { 828 this.mCdmaRoamingIndicator = roaming; 829 } 830 831 /** 832 * @hide 833 */ 834 public void setCdmaDefaultRoamingIndicator (int roaming) { 835 this.mCdmaDefaultRoamingIndicator = roaming; 836 } 837 838 /** 839 * @hide 840 */ 841 public void setCdmaEriIconIndex(int index) { 842 this.mCdmaEriIconIndex = index; 843 } 844 845 /** 846 * @hide 847 */ 848 public void setCdmaEriIconMode(int mode) { 849 this.mCdmaEriIconMode = mode; 850 } 851 852 public void setOperatorName(String longName, String shortName, String numeric) { 853 mVoiceOperatorAlphaLong = longName; 854 mVoiceOperatorAlphaShort = shortName; 855 mVoiceOperatorNumeric = numeric; 856 mDataOperatorAlphaLong = longName; 857 mDataOperatorAlphaShort = shortName; 858 mDataOperatorNumeric = numeric; 859 } 860 861 /** @hide */ 862 public void setVoiceOperatorName(String longName, String shortName, String numeric) { 863 mVoiceOperatorAlphaLong = longName; 864 mVoiceOperatorAlphaShort = shortName; 865 mVoiceOperatorNumeric = numeric; 866 } 867 868 /** @hide */ 869 public void setDataOperatorName(String longName, String shortName, String numeric) { 870 mDataOperatorAlphaLong = longName; 871 mDataOperatorAlphaShort = shortName; 872 mDataOperatorNumeric = numeric; 873 } 874 875 /** 876 * In CDMA, mOperatorAlphaLong can be set from the ERI text. 877 * This is done from the CDMAPhone and not from the CdmaServiceStateTracker. 878 * 879 * @hide 880 */ 881 public void setOperatorAlphaLong(String longName) { 882 mVoiceOperatorAlphaLong = longName; 883 mDataOperatorAlphaLong = longName; 884 } 885 886 /** @hide */ 887 public void setVoiceOperatorAlphaLong(String longName) { 888 mVoiceOperatorAlphaLong = longName; 889 } 890 891 /** @hide */ 892 public void setDataOperatorAlphaLong(String longName) { 893 mDataOperatorAlphaLong = longName; 894 } 895 896 public void setIsManualSelection(boolean isManual) { 897 mIsManualNetworkSelection = isManual; 898 } 899 900 /** 901 * Test whether two objects hold the same data values or both are null. 902 * 903 * @param a first obj 904 * @param b second obj 905 * @return true if two objects equal or both are null 906 */ 907 private static boolean equalsHandlesNulls (Object a, Object b) { 908 return (a == null) ? (b == null) : a.equals (b); 909 } 910 911 /** 912 * Set ServiceState based on intent notifier map. 913 * 914 * @param m intent notifier map 915 * @hide 916 */ 917 private void setFromNotifierBundle(Bundle m) { 918 mVoiceRegState = m.getInt("voiceRegState"); 919 mDataRegState = m.getInt("dataRegState"); 920 mVoiceRoamingType = m.getInt("voiceRoamingType"); 921 mDataRoamingType = m.getInt("dataRoamingType"); 922 mVoiceOperatorAlphaLong = m.getString("operator-alpha-long"); 923 mVoiceOperatorAlphaShort = m.getString("operator-alpha-short"); 924 mVoiceOperatorNumeric = m.getString("operator-numeric"); 925 mDataOperatorAlphaLong = m.getString("data-operator-alpha-long"); 926 mDataOperatorAlphaShort = m.getString("data-operator-alpha-short"); 927 mDataOperatorNumeric = m.getString("data-operator-numeric"); 928 mIsManualNetworkSelection = m.getBoolean("manual"); 929 mRilVoiceRadioTechnology = m.getInt("radioTechnology"); 930 mRilDataRadioTechnology = m.getInt("dataRadioTechnology"); 931 mCssIndicator = m.getBoolean("cssIndicator"); 932 mNetworkId = m.getInt("networkId"); 933 mSystemId = m.getInt("systemId"); 934 mCdmaRoamingIndicator = m.getInt("cdmaRoamingIndicator"); 935 mCdmaDefaultRoamingIndicator = m.getInt("cdmaDefaultRoamingIndicator"); 936 mIsEmergencyOnly = m.getBoolean("emergencyOnly"); 937 } 938 939 /** 940 * Set intent notifier Bundle based on service state. 941 * 942 * @param m intent notifier Bundle 943 * @hide 944 */ 945 public void fillInNotifierBundle(Bundle m) { 946 m.putInt("voiceRegState", mVoiceRegState); 947 m.putInt("dataRegState", mDataRegState); 948 m.putInt("voiceRoamingType", mVoiceRoamingType); 949 m.putInt("dataRoamingType", mDataRoamingType); 950 m.putString("operator-alpha-long", mVoiceOperatorAlphaLong); 951 m.putString("operator-alpha-short", mVoiceOperatorAlphaShort); 952 m.putString("operator-numeric", mVoiceOperatorNumeric); 953 m.putString("data-operator-alpha-long", mDataOperatorAlphaLong); 954 m.putString("data-operator-alpha-short", mDataOperatorAlphaShort); 955 m.putString("data-operator-numeric", mDataOperatorNumeric); 956 m.putBoolean("manual", Boolean.valueOf(mIsManualNetworkSelection)); 957 m.putInt("radioTechnology", mRilVoiceRadioTechnology); 958 m.putInt("dataRadioTechnology", mRilDataRadioTechnology); 959 m.putBoolean("cssIndicator", mCssIndicator); 960 m.putInt("networkId", mNetworkId); 961 m.putInt("systemId", mSystemId); 962 m.putInt("cdmaRoamingIndicator", mCdmaRoamingIndicator); 963 m.putInt("cdmaDefaultRoamingIndicator", mCdmaDefaultRoamingIndicator); 964 m.putBoolean("emergencyOnly", Boolean.valueOf(mIsEmergencyOnly)); 965 } 966 967 /** @hide */ 968 public void setRilVoiceRadioTechnology(int rt) { 969 this.mRilVoiceRadioTechnology = rt; 970 } 971 972 /** @hide */ 973 public void setRilDataRadioTechnology(int rt) { 974 this.mRilDataRadioTechnology = rt; 975 if (DBG) Rlog.d(LOG_TAG, "[ServiceState] setDataRadioTechnology=" + mRilDataRadioTechnology); 976 } 977 978 /** @hide */ 979 public void setCssIndicator(int css) { 980 this.mCssIndicator = (css != 0); 981 } 982 983 /** @hide */ 984 public void setSystemAndNetworkId(int systemId, int networkId) { 985 this.mSystemId = systemId; 986 this.mNetworkId = networkId; 987 } 988 989 /** @hide */ 990 public int getRilVoiceRadioTechnology() { 991 return this.mRilVoiceRadioTechnology; 992 } 993 /** @hide */ 994 public int getRilDataRadioTechnology() { 995 return this.mRilDataRadioTechnology; 996 } 997 /** 998 * @hide 999 * @Deprecated to be removed Q3 2013 use {@link #getRilDataRadioTechnology} or 1000 * {@link #getRilVoiceRadioTechnology} 1001 */ 1002 public int getRadioTechnology() { 1003 Rlog.e(LOG_TAG, "ServiceState.getRadioTechnology() DEPRECATED will be removed *******"); 1004 return getRilDataRadioTechnology(); 1005 } 1006 1007 private int rilRadioTechnologyToNetworkType(int rt) { 1008 switch(rt) { 1009 case ServiceState.RIL_RADIO_TECHNOLOGY_GPRS: 1010 return TelephonyManager.NETWORK_TYPE_GPRS; 1011 case ServiceState.RIL_RADIO_TECHNOLOGY_EDGE: 1012 return TelephonyManager.NETWORK_TYPE_EDGE; 1013 case ServiceState.RIL_RADIO_TECHNOLOGY_UMTS: 1014 return TelephonyManager.NETWORK_TYPE_UMTS; 1015 case ServiceState.RIL_RADIO_TECHNOLOGY_HSDPA: 1016 return TelephonyManager.NETWORK_TYPE_HSDPA; 1017 case ServiceState.RIL_RADIO_TECHNOLOGY_HSUPA: 1018 return TelephonyManager.NETWORK_TYPE_HSUPA; 1019 case ServiceState.RIL_RADIO_TECHNOLOGY_HSPA: 1020 return TelephonyManager.NETWORK_TYPE_HSPA; 1021 case ServiceState.RIL_RADIO_TECHNOLOGY_IS95A: 1022 case ServiceState.RIL_RADIO_TECHNOLOGY_IS95B: 1023 return TelephonyManager.NETWORK_TYPE_CDMA; 1024 case ServiceState.RIL_RADIO_TECHNOLOGY_1xRTT: 1025 return TelephonyManager.NETWORK_TYPE_1xRTT; 1026 case ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_0: 1027 return TelephonyManager.NETWORK_TYPE_EVDO_0; 1028 case ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_A: 1029 return TelephonyManager.NETWORK_TYPE_EVDO_A; 1030 case ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_B: 1031 return TelephonyManager.NETWORK_TYPE_EVDO_B; 1032 case ServiceState.RIL_RADIO_TECHNOLOGY_EHRPD: 1033 return TelephonyManager.NETWORK_TYPE_EHRPD; 1034 case ServiceState.RIL_RADIO_TECHNOLOGY_LTE: 1035 return TelephonyManager.NETWORK_TYPE_LTE; 1036 case ServiceState.RIL_RADIO_TECHNOLOGY_HSPAP: 1037 return TelephonyManager.NETWORK_TYPE_HSPAP; 1038 case ServiceState.RIL_RADIO_TECHNOLOGY_GSM: 1039 return TelephonyManager.NETWORK_TYPE_GSM; 1040 case ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN: 1041 return TelephonyManager.NETWORK_TYPE_IWLAN; 1042 default: 1043 return TelephonyManager.NETWORK_TYPE_UNKNOWN; 1044 } 1045 } 1046 1047 /** 1048 * @Deprecated to be removed Q3 2013 use {@link #getVoiceNetworkType} 1049 * @hide 1050 */ 1051 public int getNetworkType() { 1052 Rlog.e(LOG_TAG, "ServiceState.getNetworkType() DEPRECATED will be removed *******"); 1053 return rilRadioTechnologyToNetworkType(mRilVoiceRadioTechnology); 1054 } 1055 1056 /** @hide */ 1057 public int getDataNetworkType() { 1058 return rilRadioTechnologyToNetworkType(mRilDataRadioTechnology); 1059 } 1060 1061 /** @hide */ 1062 public int getVoiceNetworkType() { 1063 return rilRadioTechnologyToNetworkType(mRilVoiceRadioTechnology); 1064 } 1065 1066 /** @hide */ 1067 public int getCssIndicator() { 1068 return this.mCssIndicator ? 1 : 0; 1069 } 1070 1071 /** @hide */ 1072 public int getNetworkId() { 1073 return this.mNetworkId; 1074 } 1075 1076 /** @hide */ 1077 public int getSystemId() { 1078 return this.mSystemId; 1079 } 1080 1081 /** @hide */ 1082 public static boolean isGsm(int radioTechnology) { 1083 return radioTechnology == RIL_RADIO_TECHNOLOGY_GPRS 1084 || radioTechnology == RIL_RADIO_TECHNOLOGY_EDGE 1085 || radioTechnology == RIL_RADIO_TECHNOLOGY_UMTS 1086 || radioTechnology == RIL_RADIO_TECHNOLOGY_HSDPA 1087 || radioTechnology == RIL_RADIO_TECHNOLOGY_HSUPA 1088 || radioTechnology == RIL_RADIO_TECHNOLOGY_HSPA 1089 || radioTechnology == RIL_RADIO_TECHNOLOGY_LTE 1090 || radioTechnology == RIL_RADIO_TECHNOLOGY_HSPAP 1091 || radioTechnology == RIL_RADIO_TECHNOLOGY_GSM 1092 || radioTechnology == RIL_RADIO_TECHNOLOGY_TD_SCDMA 1093 || radioTechnology == RIL_RADIO_TECHNOLOGY_IWLAN; 1094 } 1095 1096 /** @hide */ 1097 public static boolean isCdma(int radioTechnology) { 1098 return radioTechnology == RIL_RADIO_TECHNOLOGY_IS95A 1099 || radioTechnology == RIL_RADIO_TECHNOLOGY_IS95B 1100 || radioTechnology == RIL_RADIO_TECHNOLOGY_1xRTT 1101 || radioTechnology == RIL_RADIO_TECHNOLOGY_EVDO_0 1102 || radioTechnology == RIL_RADIO_TECHNOLOGY_EVDO_A 1103 || radioTechnology == RIL_RADIO_TECHNOLOGY_EVDO_B 1104 || radioTechnology == RIL_RADIO_TECHNOLOGY_EHRPD; 1105 } 1106 1107 /** @hide */ 1108 public static boolean hasCdma(int radioTechnologyBitmask) { 1109 int cdmaBitmask = (RIL_RADIO_TECHNOLOGY_IS95A 1110 | RIL_RADIO_TECHNOLOGY_IS95B 1111 | RIL_RADIO_TECHNOLOGY_1xRTT 1112 | RIL_RADIO_TECHNOLOGY_EVDO_0 1113 | RIL_RADIO_TECHNOLOGY_EVDO_A 1114 | RIL_RADIO_TECHNOLOGY_EVDO_B 1115 | RIL_RADIO_TECHNOLOGY_EHRPD); 1116 1117 return ((radioTechnologyBitmask & cdmaBitmask) != 0); 1118 } 1119 1120 /** @hide */ 1121 public static boolean bitmaskHasTech(int bearerBitmask, int radioTech) { 1122 if (bearerBitmask == 0) { 1123 return true; 1124 } else if (radioTech >= 1) { 1125 return ((bearerBitmask & (1 << (radioTech - 1))) != 0); 1126 } 1127 return false; 1128 } 1129 1130 /** @hide */ 1131 public static int getBitmaskForTech(int radioTech) { 1132 if (radioTech >= 1) { 1133 return (1 << (radioTech - 1)); 1134 } 1135 return 0; 1136 } 1137 1138 /** @hide */ 1139 public static int getBitmaskFromString(String bearerList) { 1140 String[] bearers = bearerList.split("\\|"); 1141 int bearerBitmask = 0; 1142 for (String bearer : bearers) { 1143 int bearerInt = 0; 1144 try { 1145 bearerInt = Integer.parseInt(bearer.trim()); 1146 } catch (NumberFormatException nfe) { 1147 return 0; 1148 } 1149 1150 if (bearerInt == 0) { 1151 return 0; 1152 } 1153 1154 bearerBitmask |= getBitmaskForTech(bearerInt); 1155 } 1156 return bearerBitmask; 1157 } 1158 1159 /** 1160 * Returns a merged ServiceState consisting of the base SS with voice settings from the 1161 * voice SS. The voice SS is only used if it is IN_SERVICE (otherwise the base SS is returned). 1162 * @hide 1163 * */ 1164 public static ServiceState mergeServiceStates(ServiceState baseSs, ServiceState voiceSs) { 1165 if (voiceSs.mVoiceRegState != STATE_IN_SERVICE) { 1166 return baseSs; 1167 } 1168 1169 ServiceState newSs = new ServiceState(baseSs); 1170 1171 // voice overrides 1172 newSs.mVoiceRegState = voiceSs.mVoiceRegState; 1173 newSs.mIsEmergencyOnly = false; // only get here if voice is IN_SERVICE 1174 1175 return newSs; 1176 } 1177} 1178