1 /* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.internal.telephony; 18 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 22 /** 23 * {@hide} 24 */ 25 public class OperatorInfo implements Parcelable { 26 public enum State { 27 UNKNOWN, 28 AVAILABLE, 29 CURRENT, 30 FORBIDDEN; 31 } 32 33 private String mOperatorAlphaLong; 34 private String mOperatorAlphaShort; 35 private String mOperatorNumeric; 36 37 private State mState = State.UNKNOWN; 38 39 40 public String getOperatorAlphaLong()41 getOperatorAlphaLong() { 42 return mOperatorAlphaLong; 43 } 44 45 public String getOperatorAlphaShort()46 getOperatorAlphaShort() { 47 return mOperatorAlphaShort; 48 } 49 50 public String getOperatorNumeric()51 getOperatorNumeric() { 52 return mOperatorNumeric; 53 } 54 55 public State getState()56 getState() { 57 return mState; 58 } 59 OperatorInfo(String operatorAlphaLong, String operatorAlphaShort, String operatorNumeric, State state)60 OperatorInfo(String operatorAlphaLong, 61 String operatorAlphaShort, 62 String operatorNumeric, 63 State state) { 64 65 mOperatorAlphaLong = operatorAlphaLong; 66 mOperatorAlphaShort = operatorAlphaShort; 67 mOperatorNumeric = operatorNumeric; 68 69 mState = state; 70 } 71 72 OperatorInfo(String operatorAlphaLong, String operatorAlphaShort, String operatorNumeric, String stateString)73 public OperatorInfo(String operatorAlphaLong, 74 String operatorAlphaShort, 75 String operatorNumeric, 76 String stateString) { 77 this (operatorAlphaLong, operatorAlphaShort, 78 operatorNumeric, rilStateToState(stateString)); 79 } 80 OperatorInfo(String operatorAlphaLong, String operatorAlphaShort, String operatorNumeric)81 public OperatorInfo(String operatorAlphaLong, 82 String operatorAlphaShort, 83 String operatorNumeric) { 84 this(operatorAlphaLong, operatorAlphaShort, operatorNumeric, State.UNKNOWN); 85 } 86 87 /** 88 * See state strings defined in ril.h RIL_REQUEST_QUERY_AVAILABLE_NETWORKS 89 */ rilStateToState(String s)90 private static State rilStateToState(String s) { 91 if (s.equals("unknown")) { 92 return State.UNKNOWN; 93 } else if (s.equals("available")) { 94 return State.AVAILABLE; 95 } else if (s.equals("current")) { 96 return State.CURRENT; 97 } else if (s.equals("forbidden")) { 98 return State.FORBIDDEN; 99 } else { 100 throw new RuntimeException( 101 "RIL impl error: Invalid network state '" + s + "'"); 102 } 103 } 104 105 106 @Override toString()107 public String toString() { 108 return "OperatorInfo " + mOperatorAlphaLong 109 + "/" + mOperatorAlphaShort 110 + "/" + mOperatorNumeric 111 + "/" + mState; 112 } 113 114 /** 115 * Parcelable interface implemented below. 116 * This is a simple effort to make OperatorInfo parcelable rather than 117 * trying to make the conventional containing object (AsyncResult), 118 * implement parcelable. This functionality is needed for the 119 * NetworkQueryService to fix 1128695. 120 */ 121 122 @Override describeContents()123 public int describeContents() { 124 return 0; 125 } 126 127 /** 128 * Implement the Parcelable interface. 129 * Method to serialize a OperatorInfo object. 130 */ 131 @Override writeToParcel(Parcel dest, int flags)132 public void writeToParcel(Parcel dest, int flags) { 133 dest.writeString(mOperatorAlphaLong); 134 dest.writeString(mOperatorAlphaShort); 135 dest.writeString(mOperatorNumeric); 136 dest.writeSerializable(mState); 137 } 138 139 /** 140 * Implement the Parcelable interface 141 * Method to deserialize a OperatorInfo object, or an array thereof. 142 */ 143 public static final Creator<OperatorInfo> CREATOR = 144 new Creator<OperatorInfo>() { 145 @Override 146 public OperatorInfo createFromParcel(Parcel in) { 147 OperatorInfo opInfo = new OperatorInfo( 148 in.readString(), /*operatorAlphaLong*/ 149 in.readString(), /*operatorAlphaShort*/ 150 in.readString(), /*operatorNumeric*/ 151 (State) in.readSerializable()); /*state*/ 152 return opInfo; 153 } 154 155 @Override 156 public OperatorInfo[] newArray(int size) { 157 return new OperatorInfo[size]; 158 } 159 }; 160 } 161