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