2 * Copyright (C) 2014 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.telephony;
19 import android.os.Parcel;
20 import android.os.Parcelable;
22 import com.android.internal.telephony.RILConstants;
25 * Object to indicate the phone radio type and access technology.
29 public class RadioAccessFamily implements Parcelable {
31 // Radio Access Family
32 public static final int RAF_UNKNOWN = (1 << ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN);
33 public static final int RAF_GPRS = (1 << ServiceState.RIL_RADIO_TECHNOLOGY_GPRS);
34 public static final int RAF_EDGE = (1 << ServiceState.RIL_RADIO_TECHNOLOGY_EDGE);
35 public static final int RAF_UMTS = (1 << ServiceState.RIL_RADIO_TECHNOLOGY_UMTS);
36 public static final int RAF_IS95A = (1 << ServiceState.RIL_RADIO_TECHNOLOGY_IS95A);
37 public static final int RAF_IS95B = (1 << ServiceState.RIL_RADIO_TECHNOLOGY_IS95B);
38 public static final int RAF_1xRTT = (1 << ServiceState.RIL_RADIO_TECHNOLOGY_1xRTT);
39 public static final int RAF_EVDO_0 = (1 << ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_0);
40 public static final int RAF_EVDO_A = (1 << ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_A);
41 public static final int RAF_HSDPA = (1 << ServiceState.RIL_RADIO_TECHNOLOGY_HSDPA);
42 public static final int RAF_HSUPA = (1 << ServiceState.RIL_RADIO_TECHNOLOGY_HSUPA);
43 public static final int RAF_HSPA = (1 << ServiceState.RIL_RADIO_TECHNOLOGY_HSPA);
44 public static final int RAF_EVDO_B = (1 << ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_B);
45 public static final int RAF_EHRPD = (1 << ServiceState.RIL_RADIO_TECHNOLOGY_EHRPD);
46 public static final int RAF_LTE = (1 << ServiceState.RIL_RADIO_TECHNOLOGY_LTE);
47 public static final int RAF_HSPAP = (1 << ServiceState.RIL_RADIO_TECHNOLOGY_HSPAP);
48 public static final int RAF_GSM = (1 << ServiceState.RIL_RADIO_TECHNOLOGY_GSM);
49 public static final int RAF_TD_SCDMA = (1 << ServiceState.RIL_RADIO_TECHNOLOGY_TD_SCDMA);
52 private static final int GSM = RAF_GSM | RAF_GPRS | RAF_EDGE;
53 private static final int HS = RAF_HSUPA | RAF_HSDPA | RAF_HSPA | RAF_HSPAP;
54 private static final int CDMA = RAF_IS95A | RAF_IS95B | RAF_1xRTT;
55 private static final int EVDO = RAF_EVDO_0 | RAF_EVDO_A | RAF_EVDO_B | RAF_EHRPD;
56 private static final int WCDMA = HS | RAF_UMTS;
58 /* Phone ID of phone */
61 /* Radio Access Family */
62 private int mRadioAccessFamily;
67 * @param phoneId the phone ID
68 * @param radioAccessFamily the phone radio access family defined
69 * in RadioAccessFamily. It's a bit mask value to represent
72 public RadioAccessFamily(int phoneId, int radioAccessFamily) {
74 mRadioAccessFamily = radioAccessFamily;
82 public int getPhoneId() {
87 * get radio access family.
89 * @return radio access family
91 public int getRadioAccessFamily() {
92 return mRadioAccessFamily;
96 public String toString() {
97 String ret = "{ mPhoneId = " + mPhoneId
98 + ", mRadioAccessFamily = " + mRadioAccessFamily
104 * Implement the Parcelable interface.
106 * @return describe content
109 public int describeContents() {
114 * Implement the Parcelable interface.
116 * @param outParcel The Parcel in which the object should be written.
117 * @param flags Additional flags about how the object should be written.
120 public void writeToParcel(Parcel outParcel, int flags) {
121 outParcel.writeInt(mPhoneId);
122 outParcel.writeInt(mRadioAccessFamily);
126 * Implement the Parcelable interface.
128 public static final Creator<RadioAccessFamily> CREATOR =
129 new Creator<RadioAccessFamily>() {
132 public RadioAccessFamily createFromParcel(Parcel in) {
133 int phoneId = in.readInt();
134 int radioAccessFamily = in.readInt();
136 return new RadioAccessFamily(phoneId, radioAccessFamily);
140 public RadioAccessFamily[] newArray(int size) {
141 return new RadioAccessFamily[size];
145 public static int getRafFromNetworkType(int type) {
149 case RILConstants.NETWORK_MODE_WCDMA_PREF:
152 case RILConstants.NETWORK_MODE_GSM_ONLY:
155 case RILConstants.NETWORK_MODE_WCDMA_ONLY:
158 case RILConstants.NETWORK_MODE_GSM_UMTS:
161 case RILConstants.NETWORK_MODE_CDMA:
164 case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO:
165 raf = RAF_LTE | CDMA | EVDO;
167 case RILConstants.NETWORK_MODE_LTE_GSM_WCDMA:
168 raf = RAF_LTE | GSM | WCDMA;
170 case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
171 raf = RAF_LTE | CDMA | EVDO | GSM | WCDMA;
173 case RILConstants.NETWORK_MODE_LTE_ONLY:
176 case RILConstants.NETWORK_MODE_LTE_WCDMA:
177 raf = RAF_LTE | WCDMA;
179 case RILConstants.NETWORK_MODE_CDMA_NO_EVDO:
182 case RILConstants.NETWORK_MODE_EVDO_NO_CDMA:
185 case RILConstants.NETWORK_MODE_GLOBAL:
186 raf = GSM | WCDMA | CDMA | EVDO;
188 case RILConstants.NETWORK_MODE_TDSCDMA_ONLY:
191 case RILConstants.NETWORK_MODE_TDSCDMA_WCDMA:
192 raf = RAF_TD_SCDMA | WCDMA;
194 case RILConstants.NETWORK_MODE_LTE_TDSCDMA:
195 raf = RAF_LTE | RAF_TD_SCDMA;
197 case RILConstants.NETWORK_MODE_TDSCDMA_GSM:
198 raf = RAF_TD_SCDMA | GSM;
200 case RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM:
201 raf = RAF_LTE | RAF_TD_SCDMA | GSM;
203 case RILConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA:
204 raf = RAF_TD_SCDMA | GSM | WCDMA;
206 case RILConstants.NETWORK_MODE_LTE_TDSCDMA_WCDMA:
207 raf = RAF_LTE | RAF_TD_SCDMA | WCDMA;
209 case RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA:
210 raf = RAF_LTE | RAF_TD_SCDMA | GSM | WCDMA;
212 case RILConstants.NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
213 raf = RAF_TD_SCDMA | CDMA | EVDO | GSM | WCDMA;
215 case RILConstants.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
216 raf = RAF_LTE | RAF_TD_SCDMA | CDMA | EVDO | GSM | WCDMA;
227 * if the raf includes ANY bit set for a group
228 * adjust it to contain ALL the bits for that group
230 private static int getAdjustedRaf(int raf) {
231 raf = ((GSM & raf) > 0) ? (GSM | raf) : raf;
232 raf = ((WCDMA & raf) > 0) ? (WCDMA | raf) : raf;
233 raf = ((CDMA & raf) > 0) ? (CDMA | raf) : raf;
234 raf = ((EVDO & raf) > 0) ? (EVDO | raf) : raf;
239 public static int getNetworkTypeFromRaf(int raf) {
242 raf = getAdjustedRaf(raf);
246 type = RILConstants.NETWORK_MODE_WCDMA_PREF;
249 type = RILConstants.NETWORK_MODE_GSM_ONLY;
252 type = RILConstants.NETWORK_MODE_WCDMA_ONLY;
255 type = RILConstants.NETWORK_MODE_CDMA;
257 case (RAF_LTE | CDMA | EVDO):
258 type = RILConstants.NETWORK_MODE_LTE_CDMA_EVDO;
260 case (RAF_LTE | GSM | WCDMA):
261 type = RILConstants.NETWORK_MODE_LTE_GSM_WCDMA;
263 case (RAF_LTE | CDMA | EVDO | GSM | WCDMA):
264 type = RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA;
267 type = RILConstants.NETWORK_MODE_LTE_ONLY;
269 case (RAF_LTE | WCDMA):
270 type = RILConstants.NETWORK_MODE_LTE_WCDMA;
273 type = RILConstants.NETWORK_MODE_CDMA_NO_EVDO;
276 type = RILConstants.NETWORK_MODE_EVDO_NO_CDMA;
278 case (GSM | WCDMA | CDMA | EVDO):
279 type = RILConstants.NETWORK_MODE_GLOBAL;
282 type = RILConstants.NETWORK_MODE_TDSCDMA_ONLY;
284 case (RAF_TD_SCDMA | WCDMA):
285 type = RILConstants.NETWORK_MODE_TDSCDMA_WCDMA;
287 case (RAF_LTE | RAF_TD_SCDMA):
288 type = RILConstants.NETWORK_MODE_LTE_TDSCDMA;
290 case (RAF_TD_SCDMA | GSM):
291 type = RILConstants.NETWORK_MODE_TDSCDMA_GSM;
293 case (RAF_LTE | RAF_TD_SCDMA | GSM):
294 type = RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM;
296 case (RAF_TD_SCDMA | GSM | WCDMA):
297 type = RILConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA;
299 case (RAF_LTE | RAF_TD_SCDMA | WCDMA):
300 type = RILConstants.NETWORK_MODE_LTE_TDSCDMA_WCDMA;
302 case (RAF_LTE | RAF_TD_SCDMA | GSM | WCDMA):
303 type = RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA;
305 case (RAF_TD_SCDMA | CDMA | EVDO | GSM | WCDMA):
306 type = RILConstants.NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA;
308 case (RAF_LTE | RAF_TD_SCDMA | RAF_LTE | CDMA | EVDO | GSM | WCDMA):
309 type = RILConstants.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA;
312 type = RILConstants.PREFERRED_NETWORK_MODE ;
319 public static int singleRafTypeFromString(String rafString) {
321 case "GPRS": return RAF_GPRS;
322 case "EDGE": return RAF_EDGE;
323 case "UMTS": return RAF_UMTS;
324 case "IS95A": return RAF_IS95A;
325 case "IS95B": return RAF_IS95B;
326 case "1XRTT": return RAF_1xRTT;
327 case "EVDO_0": return RAF_EVDO_0;
328 case "EVDO_A": return RAF_EVDO_A;
329 case "HSDPA": return RAF_HSDPA;
330 case "HSUPA": return RAF_HSUPA;
331 case "HSPA": return RAF_HSPA;
332 case "EVDO_B": return RAF_EVDO_B;
333 case "EHRPD": return RAF_EHRPD;
334 case "LTE": return RAF_LTE;
335 case "HSPAP": return RAF_HSPAP;
336 case "GSM": return RAF_GSM;
337 case "TD_SCDMA":return RAF_TD_SCDMA;
338 case "HS": return HS;
339 case "CDMA": return CDMA;
340 case "EVDO": return EVDO;
341 case "WCDMA": return WCDMA;
342 default: return RAF_UNKNOWN;
346 public static int rafTypeFromString(String rafList) {
347 rafList = rafList.toUpperCase();
348 String[] rafs = rafList.split("\\|");
350 for(String raf : rafs) {
351 int rafType = singleRafTypeFromString(raf.trim());
352 if (rafType == RAF_UNKNOWN) return rafType;