RadioAccessFamily.java revision b5f1e878d1bc245b676a1a2504c30d21a311bf6c
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
17package android.telephony;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21
22import com.android.internal.telephony.RILConstants;
23
24/**
25 * Object to indicate the phone radio type and access technology.
26 *
27 * @hide
28 */
29public 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
51    /* Phone ID of phone */
52    private int mPhoneId;
53
54    /* Radio Access Family */
55    private int mRadioAccessFamily;
56
57    /**
58     * Constructor.
59     *
60     * @param phoneId the phone ID
61     * @param radioAccessFamily the phone radio access family defined
62     *        in RadioAccessFamily. It's a bit mask value to represent
63     *        the support type.
64     */
65    public RadioAccessFamily(int phoneId, int radioAccessFamily) {
66        mPhoneId = phoneId;
67        mRadioAccessFamily = radioAccessFamily;
68    }
69
70    /**
71     * Get phone ID.
72     *
73     * @return phone ID
74     */
75    public int getPhoneId() {
76        return mPhoneId;
77    }
78
79    /**
80     * get radio access family.
81     *
82     * @return radio access family
83     */
84    public int getRadioAccessFamily() {
85        return mRadioAccessFamily;
86    }
87
88    @Override
89    public String toString() {
90        String ret = "{ mPhoneId = " + mPhoneId
91                + ", mRadioAccessFamily = " + mRadioAccessFamily
92                + "}";
93        return ret;
94    }
95
96    /**
97     * Implement the Parcelable interface.
98     *
99     * @return describe content
100     */
101    @Override
102    public int describeContents() {
103        return 0;
104    }
105
106    /**
107     * Implement the Parcelable interface.
108     *
109     * @param outParcel The Parcel in which the object should be written.
110     * @param flags Additional flags about how the object should be written.
111     */
112    @Override
113    public void writeToParcel(Parcel outParcel, int flags) {
114        outParcel.writeInt(mPhoneId);
115        outParcel.writeInt(mRadioAccessFamily);
116    }
117
118    /**
119     * Implement the Parcelable interface.
120     */
121    public static final Creator<RadioAccessFamily> CREATOR =
122            new Creator<RadioAccessFamily>() {
123
124        @Override
125        public RadioAccessFamily createFromParcel(Parcel in) {
126            int phoneId = in.readInt();
127            int radioAccessFamily = in.readInt();
128
129            return new RadioAccessFamily(phoneId, radioAccessFamily);
130        }
131
132        @Override
133        public RadioAccessFamily[] newArray(int size) {
134            return new RadioAccessFamily[size];
135        }
136    };
137
138    public static int getRafFromNetworkType(int type) {
139        final int GSM = RAF_GSM | RAF_GPRS | RAF_EDGE;
140        final int HS = RAF_HSUPA | RAF_HSDPA | RAF_HSPA | RAF_HSPAP;
141        final int CDMA = RAF_IS95A | RAF_IS95B | RAF_1xRTT;
142        final int EVDO = RAF_EVDO_0 | RAF_EVDO_A | RAF_EVDO_B;
143        final int WCDMA = HS | RAF_UMTS;
144
145        int raf;
146
147        switch (type) {
148            case RILConstants.NETWORK_MODE_WCDMA_PREF:
149                raf = GSM | WCDMA;
150                break;
151            case RILConstants.NETWORK_MODE_GSM_ONLY:
152                raf = GSM;
153                break;
154            case RILConstants.NETWORK_MODE_WCDMA_ONLY:
155                raf = WCDMA;
156                break;
157            case RILConstants.NETWORK_MODE_GSM_UMTS:
158                raf = GSM | WCDMA;
159                break;
160            case RILConstants.NETWORK_MODE_CDMA:
161                raf = CDMA;
162                break;
163            case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO:
164                raf = RAF_LTE | CDMA | EVDO;
165                break;
166            case RILConstants.NETWORK_MODE_LTE_GSM_WCDMA:
167                raf = RAF_LTE | GSM | WCDMA;
168                break;
169            case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA:
170                raf = RAF_LTE | CDMA | EVDO | GSM | WCDMA;
171                break;
172            case RILConstants.NETWORK_MODE_LTE_ONLY:
173                raf = RAF_LTE;
174                break;
175            case RILConstants.NETWORK_MODE_LTE_WCDMA:
176                raf = RAF_LTE | WCDMA;
177                break;
178            case RILConstants.NETWORK_MODE_CDMA_NO_EVDO:
179                raf = CDMA;
180                break;
181            case RILConstants.NETWORK_MODE_EVDO_NO_CDMA:
182                raf = EVDO;
183                break;
184            case RILConstants.NETWORK_MODE_GLOBAL:
185                raf = GSM | WCDMA | CDMA | EVDO;
186                break;
187            default:
188                raf = RAF_UNKNOWN;
189                break;
190        }
191        return raf;
192    }
193}
194
195