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