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 operatorAlphaLong; 34 private String operatorAlphaShort; 35 private String operatorNumeric; 36 37 private State state = State.UNKNOWN; 38 39 40 public String getOperatorAlphaLong()41 getOperatorAlphaLong() { 42 return operatorAlphaLong; 43 } 44 45 public String getOperatorAlphaShort()46 getOperatorAlphaShort() { 47 return operatorAlphaShort; 48 } 49 50 public String getOperatorNumeric()51 getOperatorNumeric() { 52 return operatorNumeric; 53 } 54 55 public State getState()56 getState() { 57 return state; 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 this.operatorAlphaLong = operatorAlphaLong; 66 this.operatorAlphaShort = operatorAlphaShort; 67 this.operatorNumeric = operatorNumeric; 68 69 this.state = 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 81 /** 82 * See state strings defined in ril.h RIL_REQUEST_QUERY_AVAILABLE_NETWORKS 83 */ rilStateToState(String s)84 private static State rilStateToState(String s) { 85 if (s.equals("unknown")) { 86 return State.UNKNOWN; 87 } else if (s.equals("available")) { 88 return State.AVAILABLE; 89 } else if (s.equals("current")) { 90 return State.CURRENT; 91 } else if (s.equals("forbidden")) { 92 return State.FORBIDDEN; 93 } else { 94 throw new RuntimeException( 95 "RIL impl error: Invalid network state '" + s + "'"); 96 } 97 } 98 99 toString()100 public String toString() { 101 return "OperatorInfo " + operatorAlphaLong 102 + "/" + operatorAlphaShort 103 + "/" + operatorNumeric 104 + "/" + state; 105 } 106 107 /** 108 * Parcelable interface implemented below. 109 * This is a simple effort to make OperatorInfo parcelable rather than 110 * trying to make the conventional containing object (AsyncResult), 111 * implement parcelable. This functionality is needed for the 112 * NetworkQueryService to fix 1128695. 113 */ 114 describeContents()115 public int describeContents() { 116 return 0; 117 } 118 119 /** 120 * Implement the Parcelable interface. 121 * Method to serialize a OperatorInfo object. 122 */ writeToParcel(Parcel dest, int flags)123 public void writeToParcel(Parcel dest, int flags) { 124 dest.writeString(operatorAlphaLong); 125 dest.writeString(operatorAlphaShort); 126 dest.writeString(operatorNumeric); 127 dest.writeSerializable(state); 128 } 129 130 /** 131 * Implement the Parcelable interface 132 * Method to deserialize a OperatorInfo object, or an array thereof. 133 */ 134 public static final Creator<OperatorInfo> CREATOR = 135 new Creator<OperatorInfo>() { 136 public OperatorInfo createFromParcel(Parcel in) { 137 OperatorInfo opInfo = new OperatorInfo( 138 in.readString(), /*operatorAlphaLong*/ 139 in.readString(), /*operatorAlphaShort*/ 140 in.readString(), /*operatorNumeric*/ 141 (State) in.readSerializable()); /*state*/ 142 return opInfo; 143 } 144 145 public OperatorInfo[] newArray(int size) { 146 return new OperatorInfo[size]; 147 } 148 }; 149 } 150