1 package android.telephony;
2 
3 import static android.telephony.ServiceState.DUPLEX_MODE_FDD;
4 import static android.telephony.ServiceState.DUPLEX_MODE_TDD;
5 import static android.telephony.ServiceState.DUPLEX_MODE_UNKNOWN;
6 
7 import android.telephony.AccessNetworkConstants.EutranBand;
8 import android.telephony.ServiceState.DuplexMode;
9 
10 
11 /**
12  * Utilities to map between radio constants.
13  *
14  * @hide
15  */
16 public class AccessNetworkUtils {
17 
18     // do not instantiate
AccessNetworkUtils()19     private AccessNetworkUtils() {}
20 
21     public static final int INVALID_BAND = -1;
22 
23     /**
24      * Gets the duplex mode for the given EUTRAN operating band.
25      *
26      * <p>See 3GPP 36.101 sec 5.5-1 for calculation
27      *
28      * @param band The EUTRAN band number
29      * @return The duplex mode of the given EUTRAN band
30      */
31     @DuplexMode
getDuplexModeForEutranBand(int band)32     public static int getDuplexModeForEutranBand(int band) {
33         if (band == INVALID_BAND) {
34             return DUPLEX_MODE_UNKNOWN;
35         }
36 
37         if (band > EutranBand.BAND_88) {
38             return DUPLEX_MODE_UNKNOWN;
39         } else if (band >= EutranBand.BAND_65) {
40             return DUPLEX_MODE_FDD;
41         } else if (band >= EutranBand.BAND_33) {
42             return DUPLEX_MODE_TDD;
43         } else if (band >= EutranBand.BAND_1) {
44             return DUPLEX_MODE_FDD;
45         }
46 
47         return DUPLEX_MODE_UNKNOWN;
48     }
49 
50     /**
51      * Gets the EUTRAN Operating band for a given downlink EARFCN.
52      *
53      * <p>See 3GPP 36.101 sec 5.7.3-1 for calculation.
54      *
55      * @param earfcn The downlink EARFCN
56      * @return Operating band number, or {@link #INVALID_BAND} if no corresponding band exists
57      */
getOperatingBandForEarfcn(int earfcn)58     public static int getOperatingBandForEarfcn(int earfcn) {
59         if (earfcn > 70645) {
60             return INVALID_BAND;
61         } else if (earfcn >= 70596) {
62             return EutranBand.BAND_88;
63         } else if (earfcn >= 70546) {
64             return EutranBand.BAND_87;
65         } else if (earfcn >= 70366) {
66             return EutranBand.BAND_85;
67         } else if (earfcn > 69465) {
68             return INVALID_BAND;
69         } else if (earfcn >= 69036) {
70             return EutranBand.BAND_74;
71         } else if (earfcn >= 68986) {
72             return EutranBand.BAND_73;
73         } else if (earfcn >= 68936) {
74             return EutranBand.BAND_72;
75         } else if (earfcn >= 68586) {
76             return EutranBand.BAND_71;
77         } else if (earfcn >= 68336) {
78             return EutranBand.BAND_70;
79         } else if (earfcn > 67835) {
80             return INVALID_BAND;
81         } else if (earfcn >= 67536) {
82             return EutranBand.BAND_68;
83         } else if (earfcn >= 67366) {
84             return INVALID_BAND; // band 67 only for CarrierAgg
85         } else if (earfcn >= 66436) {
86             return EutranBand.BAND_66;
87         } else if (earfcn >= 65536) {
88             return EutranBand.BAND_65;
89         } else if (earfcn > 60254) {
90             return INVALID_BAND;
91         } else if (earfcn >= 60140) {
92             return EutranBand.BAND_53;
93         } else if (earfcn >= 59140) {
94             return EutranBand.BAND_52;
95         } else if (earfcn >= 59090) {
96             return EutranBand.BAND_51;
97         } else if (earfcn >= 58240) {
98             return EutranBand.BAND_50;
99         } else if (earfcn >= 56740) {
100             return EutranBand.BAND_49;
101         } else if (earfcn >= 55240) {
102             return EutranBand.BAND_48;
103         } else if (earfcn >= 54540) {
104             return EutranBand.BAND_47;
105         } else if (earfcn >= 46790) {
106             return EutranBand.BAND_46;
107         } else if (earfcn >= 46590) {
108             return EutranBand.BAND_45;
109         } else if (earfcn >= 45590) {
110             return EutranBand.BAND_44;
111         } else if (earfcn >= 43590) {
112             return EutranBand.BAND_43;
113         } else if (earfcn >= 41590) {
114             return EutranBand.BAND_42;
115         } else if (earfcn >= 39650) {
116             return EutranBand.BAND_41;
117         } else if (earfcn >= 38650) {
118             return EutranBand.BAND_40;
119         } else if (earfcn >= 38250) {
120             return EutranBand.BAND_39;
121         } else if (earfcn >= 37750) {
122             return EutranBand.BAND_38;
123         } else if (earfcn >= 37550) {
124             return EutranBand.BAND_37;
125         } else if (earfcn >= 36950) {
126             return EutranBand.BAND_36;
127         } else if (earfcn >= 36350) {
128             return EutranBand.BAND_35;
129         } else if (earfcn >= 36200) {
130             return EutranBand.BAND_34;
131         } else if (earfcn >= 36000) {
132             return EutranBand.BAND_33;
133         } else if (earfcn > 10359) {
134             return INVALID_BAND;
135         } else if (earfcn >= 9920) {
136             return INVALID_BAND; // band 32 only for CarrierAgg
137         } else if (earfcn >= 9870) {
138             return EutranBand.BAND_31;
139         } else if (earfcn >= 9770) {
140             return EutranBand.BAND_30;
141         } else if (earfcn >= 9660) {
142             return INVALID_BAND; // band 29 only for CarrierAgg
143         } else if (earfcn >= 9210) {
144             return EutranBand.BAND_28;
145         } else if (earfcn >= 9040) {
146             return EutranBand.BAND_27;
147         } else if (earfcn >= 8690) {
148             return EutranBand.BAND_26;
149         } else if (earfcn >= 8040) {
150             return EutranBand.BAND_25;
151         } else if (earfcn >= 7700) {
152             return EutranBand.BAND_24;
153         } else if (earfcn >= 7500) {
154             return EutranBand.BAND_23;
155         } else if (earfcn >= 6600) {
156             return EutranBand.BAND_22;
157         } else if (earfcn >= 6450) {
158             return EutranBand.BAND_21;
159         } else if (earfcn >= 6150) {
160             return EutranBand.BAND_20;
161         } else if (earfcn >= 6000) {
162             return EutranBand.BAND_19;
163         } else if (earfcn >= 5850) {
164             return EutranBand.BAND_18;
165         } else if (earfcn >= 5730) {
166             return EutranBand.BAND_17;
167         } else if (earfcn > 5379) {
168             return INVALID_BAND;
169         } else if (earfcn >= 5280) {
170             return EutranBand.BAND_14;
171         } else if (earfcn >= 5180) {
172             return EutranBand.BAND_13;
173         } else if (earfcn >= 5010) {
174             return EutranBand.BAND_12;
175         } else if (earfcn >= 4750) {
176             return EutranBand.BAND_11;
177         } else if (earfcn >= 4150) {
178             return EutranBand.BAND_10;
179         } else if (earfcn >= 3800) {
180             return EutranBand.BAND_9;
181         } else if (earfcn >= 3450) {
182             return EutranBand.BAND_8;
183         } else if (earfcn >= 2750) {
184             return EutranBand.BAND_7;
185         } else if (earfcn >= 2650) {
186             return EutranBand.BAND_6;
187         } else if (earfcn >= 2400) {
188             return EutranBand.BAND_5;
189         } else if (earfcn >= 1950) {
190             return EutranBand.BAND_4;
191         } else if (earfcn >= 1200) {
192             return EutranBand.BAND_3;
193         } else if (earfcn >= 600) {
194             return EutranBand.BAND_2;
195         } else if (earfcn >= 0) {
196             return EutranBand.BAND_1;
197         }
198 
199         return INVALID_BAND;
200     }
201 }
202