• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (C) 2014 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 android.telephony;
18 
19 import android.os.Parcel;
20 import android.os.Parcelable;
21 
22 import com.android.internal.telephony.RILConstants;
23 
24 /**
25  * Object to indicate the phone radio type and access technology.
26  *
27  * @hide
28  */
29 public class RadioAccessFamily implements Parcelable {
30 
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);
50     public static final int RAF_LTE_CA = (1 << ServiceState.RIL_RADIO_TECHNOLOGY_LTE_CA);
51 
52     // Grouping of RAFs
53     private static final int GSM = RAF_GSM | RAF_GPRS | RAF_EDGE;
54     private static final int HS = RAF_HSUPA | RAF_HSDPA | RAF_HSPA | RAF_HSPAP;
55     private static final int CDMA = RAF_IS95A | RAF_IS95B | RAF_1xRTT;
56     private static final int EVDO = RAF_EVDO_0 | RAF_EVDO_A | RAF_EVDO_B | RAF_EHRPD;
57     private static final int WCDMA = HS | RAF_UMTS;
58     private static final int LTE = RAF_LTE | RAF_LTE_CA;
59 
60     /* Phone ID of phone */
61     private int mPhoneId;
62 
63     /* Radio Access Family */
64     private int mRadioAccessFamily;
65 
66     /**
67      * Constructor.
68      *
69      * @param phoneId the phone ID
70      * @param radioAccessFamily the phone radio access family defined
71      *        in RadioAccessFamily. It's a bit mask value to represent
72      *        the support type.
73      */
RadioAccessFamily(int phoneId, int radioAccessFamily)74     public RadioAccessFamily(int phoneId, int radioAccessFamily) {
75         mPhoneId = phoneId;
76         mRadioAccessFamily = radioAccessFamily;
77     }
78 
79     /**
80      * Get phone ID.
81      *
82      * @return phone ID
83      */
getPhoneId()84     public int getPhoneId() {
85         return mPhoneId;
86     }
87 
88     /**
89      * get radio access family.
90      *
91      * @return radio access family
92      */
getRadioAccessFamily()93     public int getRadioAccessFamily() {
94         return mRadioAccessFamily;
95     }
96 
97     @Override
toString()98     public String toString() {
99         String ret = "{ mPhoneId = " + mPhoneId
100                 + ", mRadioAccessFamily = " + mRadioAccessFamily
101                 + "}";
102         return ret;
103     }
104 
105     /**
106      * Implement the Parcelable interface.
107      *
108      * @return describe content
109      */
110     @Override
describeContents()111     public int describeContents() {
112         return 0;
113     }
114 
115     /**
116      * Implement the Parcelable interface.
117      *
118      * @param outParcel The Parcel in which the object should be written.
119      * @param flags Additional flags about how the object should be written.
120      */
121     @Override
writeToParcel(Parcel outParcel, int flags)122     public void writeToParcel(Parcel outParcel, int flags) {
123         outParcel.writeInt(mPhoneId);
124         outParcel.writeInt(mRadioAccessFamily);
125     }
126 
127     /**
128      * Implement the Parcelable interface.
129      */
130     public static final Creator<RadioAccessFamily> CREATOR =
131             new Creator<RadioAccessFamily>() {
132 
133         @Override
134         public RadioAccessFamily createFromParcel(Parcel in) {
135             int phoneId = in.readInt();
136             int radioAccessFamily = in.readInt();
137 
138             return new RadioAccessFamily(phoneId, radioAccessFamily);
139         }
140 
141         @Override
142         public RadioAccessFamily[] newArray(int size) {
143             return new RadioAccessFamily[size];
144         }
145     };
146 
getRafFromNetworkType(int type)147     public static int getRafFromNetworkType(int type) {
148         int raf;
149 
150         switch (type) {
151             case RILConstants.NETWORK_MODE_WCDMA_PREF:
152                 raf = GSM | WCDMA;
153                 break;
154             case RILConstants.NETWORK_MODE_GSM_ONLY:
155                 raf = GSM;
156                 break;
157             case RILConstants.NETWORK_MODE_WCDMA_ONLY:
158                 raf = WCDMA;
159                 break;
160             case RILConstants.NETWORK_MODE_GSM_UMTS:
161                 raf = GSM | WCDMA;
162                 break;
163             case RILConstants.NETWORK_MODE_CDMA:
164                 raf = CDMA | EVDO;
165                 break;
166             case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO:
167                 raf = LTE | CDMA | EVDO;
168                 break;
169             case RILConstants.NETWORK_MODE_LTE_GSM_WCDMA:
170                 raf = LTE | GSM | WCDMA;
171                 break;
172             case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
173                 raf = LTE | CDMA | EVDO | GSM | WCDMA;
174                 break;
175             case RILConstants.NETWORK_MODE_LTE_ONLY:
176                 raf = LTE;
177                 break;
178             case RILConstants.NETWORK_MODE_LTE_WCDMA:
179                 raf = LTE | WCDMA;
180                 break;
181             case RILConstants.NETWORK_MODE_CDMA_NO_EVDO:
182                 raf = CDMA;
183                 break;
184             case RILConstants.NETWORK_MODE_EVDO_NO_CDMA:
185                 raf = EVDO;
186                 break;
187             case RILConstants.NETWORK_MODE_GLOBAL:
188                 raf = GSM | WCDMA | CDMA | EVDO;
189                 break;
190             case RILConstants.NETWORK_MODE_TDSCDMA_ONLY:
191                 raf = RAF_TD_SCDMA;
192                 break;
193             case RILConstants.NETWORK_MODE_TDSCDMA_WCDMA:
194                 raf = RAF_TD_SCDMA | WCDMA;
195                 break;
196             case RILConstants.NETWORK_MODE_LTE_TDSCDMA:
197                 raf = LTE | RAF_TD_SCDMA;
198                 break;
199             case RILConstants.NETWORK_MODE_TDSCDMA_GSM:
200                 raf = RAF_TD_SCDMA | GSM;
201                 break;
202             case RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM:
203                 raf = LTE | RAF_TD_SCDMA | GSM;
204                 break;
205             case RILConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA:
206                 raf = RAF_TD_SCDMA | GSM | WCDMA;
207                 break;
208             case RILConstants.NETWORK_MODE_LTE_TDSCDMA_WCDMA:
209                 raf = LTE | RAF_TD_SCDMA | WCDMA;
210                 break;
211             case RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA:
212                 raf = LTE | RAF_TD_SCDMA | GSM | WCDMA;
213                 break;
214             case RILConstants.NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
215                 raf = RAF_TD_SCDMA | CDMA | EVDO | GSM | WCDMA;
216                 break;
217             case RILConstants.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA:
218                 raf = LTE | RAF_TD_SCDMA | CDMA | EVDO | GSM | WCDMA;
219                 break;
220             default:
221                 raf = RAF_UNKNOWN;
222                 break;
223         }
224 
225         return raf;
226     }
227 
228     /**
229      * if the raf includes ANY bit set for a group
230      * adjust it to contain ALL the bits for that group
231      */
getAdjustedRaf(int raf)232     private static int getAdjustedRaf(int raf) {
233         raf = ((GSM & raf) > 0) ? (GSM | raf) : raf;
234         raf = ((WCDMA & raf) > 0) ? (WCDMA | raf) : raf;
235         raf = ((CDMA & raf) > 0) ? (CDMA | raf) : raf;
236         raf = ((EVDO & raf) > 0) ? (EVDO | raf) : raf;
237         raf = ((LTE & raf) > 0) ? (LTE | raf) : raf;
238 
239         return raf;
240     }
241 
getNetworkTypeFromRaf(int raf)242     public static int getNetworkTypeFromRaf(int raf) {
243         int type;
244 
245         raf = getAdjustedRaf(raf);
246 
247         switch (raf) {
248             case (GSM | WCDMA):
249                 type = RILConstants.NETWORK_MODE_WCDMA_PREF;
250                 break;
251             case GSM:
252                 type = RILConstants.NETWORK_MODE_GSM_ONLY;
253                 break;
254             case WCDMA:
255                 type = RILConstants.NETWORK_MODE_WCDMA_ONLY;
256                 break;
257             case (CDMA | EVDO):
258                 type = RILConstants.NETWORK_MODE_CDMA;
259                 break;
260             case (LTE | CDMA | EVDO):
261                 type = RILConstants.NETWORK_MODE_LTE_CDMA_EVDO;
262                 break;
263             case (LTE | GSM | WCDMA):
264                 type = RILConstants.NETWORK_MODE_LTE_GSM_WCDMA;
265                 break;
266             case (LTE | CDMA | EVDO | GSM | WCDMA):
267                 type = RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA;
268                 break;
269             case LTE:
270                 type = RILConstants.NETWORK_MODE_LTE_ONLY;
271                 break;
272             case (LTE | WCDMA):
273                 type = RILConstants.NETWORK_MODE_LTE_WCDMA;
274                 break;
275             case CDMA:
276                 type = RILConstants.NETWORK_MODE_CDMA_NO_EVDO;
277                 break;
278             case EVDO:
279                 type = RILConstants.NETWORK_MODE_EVDO_NO_CDMA;
280                 break;
281             case (GSM | WCDMA | CDMA | EVDO):
282                 type = RILConstants.NETWORK_MODE_GLOBAL;
283                 break;
284             case RAF_TD_SCDMA:
285                 type = RILConstants.NETWORK_MODE_TDSCDMA_ONLY;
286                 break;
287             case (RAF_TD_SCDMA | WCDMA):
288                 type = RILConstants.NETWORK_MODE_TDSCDMA_WCDMA;
289                 break;
290             case (LTE | RAF_TD_SCDMA):
291                 type = RILConstants.NETWORK_MODE_LTE_TDSCDMA;
292                 break;
293             case (RAF_TD_SCDMA | GSM):
294                 type = RILConstants.NETWORK_MODE_TDSCDMA_GSM;
295                 break;
296             case (LTE | RAF_TD_SCDMA | GSM):
297                 type = RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM;
298                 break;
299             case (RAF_TD_SCDMA | GSM | WCDMA):
300                 type = RILConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA;
301                 break;
302             case (LTE | RAF_TD_SCDMA | WCDMA):
303                 type = RILConstants.NETWORK_MODE_LTE_TDSCDMA_WCDMA;
304                 break;
305             case (LTE | RAF_TD_SCDMA | GSM | WCDMA):
306                 type = RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA;
307                 break;
308             case (RAF_TD_SCDMA | CDMA | EVDO | GSM | WCDMA):
309                 type = RILConstants.NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA;
310                 break;
311             case (LTE | RAF_TD_SCDMA | CDMA | EVDO | GSM | WCDMA):
312                 type = RILConstants.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA;
313                 break;
314             default:
315                 type = RILConstants.PREFERRED_NETWORK_MODE ;
316                 break;
317         }
318 
319         return type;
320     }
321 
singleRafTypeFromString(String rafString)322     public static int singleRafTypeFromString(String rafString) {
323         switch (rafString) {
324             case "GPRS":    return RAF_GPRS;
325             case "EDGE":    return RAF_EDGE;
326             case "UMTS":    return RAF_UMTS;
327             case "IS95A":   return RAF_IS95A;
328             case "IS95B":   return RAF_IS95B;
329             case "1XRTT":   return RAF_1xRTT;
330             case "EVDO_0":  return RAF_EVDO_0;
331             case "EVDO_A":  return RAF_EVDO_A;
332             case "HSDPA":   return RAF_HSDPA;
333             case "HSUPA":   return RAF_HSUPA;
334             case "HSPA":    return RAF_HSPA;
335             case "EVDO_B":  return RAF_EVDO_B;
336             case "EHRPD":   return RAF_EHRPD;
337             case "LTE":     return RAF_LTE;
338             case "HSPAP":   return RAF_HSPAP;
339             case "GSM":     return RAF_GSM;
340             case "TD_SCDMA":return RAF_TD_SCDMA;
341             case "HS":      return HS;
342             case "CDMA":    return CDMA;
343             case "EVDO":    return EVDO;
344             case "WCDMA":   return WCDMA;
345             case "LTE_CA":  return RAF_LTE_CA;
346             default:        return RAF_UNKNOWN;
347         }
348     }
349 
rafTypeFromString(String rafList)350     public static int rafTypeFromString(String rafList) {
351         rafList = rafList.toUpperCase();
352         String[] rafs = rafList.split("\\|");
353         int result = 0;
354         for(String raf : rafs) {
355             int rafType = singleRafTypeFromString(raf.trim());
356             if (rafType == RAF_UNKNOWN) return rafType;
357             result |= rafType;
358         }
359         return result;
360     }
361 }
362