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.annotation.UnsupportedAppUsage; 20 import android.os.Build; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 /** 25 * @hide 26 */ 27 public class OperatorInfo implements Parcelable { 28 public enum State { 29 UNKNOWN, 30 AVAILABLE, 31 @UnsupportedAppUsage 32 CURRENT, 33 @UnsupportedAppUsage 34 FORBIDDEN; 35 } 36 37 @UnsupportedAppUsage 38 private String mOperatorAlphaLong; 39 @UnsupportedAppUsage 40 private String mOperatorAlphaShort; 41 @UnsupportedAppUsage 42 private String mOperatorNumeric; 43 44 @UnsupportedAppUsage 45 private State mState = State.UNKNOWN; 46 47 48 @UnsupportedAppUsage 49 public String getOperatorAlphaLong()50 getOperatorAlphaLong() { 51 return mOperatorAlphaLong; 52 } 53 54 @UnsupportedAppUsage 55 public String getOperatorAlphaShort()56 getOperatorAlphaShort() { 57 return mOperatorAlphaShort; 58 } 59 60 @UnsupportedAppUsage 61 public String getOperatorNumeric()62 getOperatorNumeric() { 63 return mOperatorNumeric; 64 } 65 66 @UnsupportedAppUsage 67 public State getState()68 getState() { 69 return mState; 70 } 71 72 @UnsupportedAppUsage OperatorInfo(String operatorAlphaLong, String operatorAlphaShort, String operatorNumeric, State state)73 OperatorInfo(String operatorAlphaLong, 74 String operatorAlphaShort, 75 String operatorNumeric, 76 State state) { 77 78 mOperatorAlphaLong = operatorAlphaLong; 79 mOperatorAlphaShort = operatorAlphaShort; 80 mOperatorNumeric = operatorNumeric; 81 82 mState = state; 83 } 84 85 86 @UnsupportedAppUsage OperatorInfo(String operatorAlphaLong, String operatorAlphaShort, String operatorNumeric, String stateString)87 public OperatorInfo(String operatorAlphaLong, 88 String operatorAlphaShort, 89 String operatorNumeric, 90 String stateString) { 91 this (operatorAlphaLong, operatorAlphaShort, 92 operatorNumeric, rilStateToState(stateString)); 93 } 94 95 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) OperatorInfo(String operatorAlphaLong, String operatorAlphaShort, String operatorNumeric)96 public OperatorInfo(String operatorAlphaLong, 97 String operatorAlphaShort, 98 String operatorNumeric) { 99 this(operatorAlphaLong, operatorAlphaShort, operatorNumeric, State.UNKNOWN); 100 } 101 102 /** 103 * See state strings defined in ril.h RIL_REQUEST_QUERY_AVAILABLE_NETWORKS 104 */ 105 @UnsupportedAppUsage rilStateToState(String s)106 private static State rilStateToState(String s) { 107 if (s.equals("unknown")) { 108 return State.UNKNOWN; 109 } else if (s.equals("available")) { 110 return State.AVAILABLE; 111 } else if (s.equals("current")) { 112 return State.CURRENT; 113 } else if (s.equals("forbidden")) { 114 return State.FORBIDDEN; 115 } else { 116 throw new RuntimeException( 117 "RIL impl error: Invalid network state '" + s + "'"); 118 } 119 } 120 121 122 @Override toString()123 public String toString() { 124 return "OperatorInfo " + mOperatorAlphaLong 125 + "/" + mOperatorAlphaShort 126 + "/" + mOperatorNumeric 127 + "/" + mState; 128 } 129 130 /** 131 * Parcelable interface implemented below. 132 * This is a simple effort to make OperatorInfo parcelable rather than 133 * trying to make the conventional containing object (AsyncResult), 134 * implement parcelable. This functionality is needed for the 135 * NetworkQueryService to fix 1128695. 136 */ 137 138 @Override describeContents()139 public int describeContents() { 140 return 0; 141 } 142 143 /** 144 * Implement the Parcelable interface. 145 * Method to serialize a OperatorInfo object. 146 */ 147 @Override writeToParcel(Parcel dest, int flags)148 public void writeToParcel(Parcel dest, int flags) { 149 dest.writeString(mOperatorAlphaLong); 150 dest.writeString(mOperatorAlphaShort); 151 dest.writeString(mOperatorNumeric); 152 dest.writeSerializable(mState); 153 } 154 155 /** 156 * Implement the Parcelable interface 157 * Method to deserialize a OperatorInfo object, or an array thereof. 158 */ 159 @UnsupportedAppUsage 160 public static final Creator<OperatorInfo> CREATOR = 161 new Creator<OperatorInfo>() { 162 @Override 163 public OperatorInfo createFromParcel(Parcel in) { 164 OperatorInfo opInfo = new OperatorInfo( 165 in.readString(), /*operatorAlphaLong*/ 166 in.readString(), /*operatorAlphaShort*/ 167 in.readString(), /*operatorNumeric*/ 168 (State) in.readSerializable()); /*state*/ 169 return opInfo; 170 } 171 172 @Override 173 public OperatorInfo[] newArray(int size) { 174 return new OperatorInfo[size]; 175 } 176 }; 177 } 178