1 /*
2  * Copyright 2017 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.data;
18 
19 import android.os.Build;
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 import android.text.TextUtils;
23 
24 import com.android.internal.telephony.RILConstants;
25 
26 /**
27  * Description of a mobile data profile used for establishing
28  * data connections.
29  *
30  * @hide
31  */
32 public final class DataProfile implements Parcelable {
33 
34     // The types indicating the data profile is used on GSM (3GPP) or CDMA (3GPP2) network.
35     public static final int TYPE_COMMON = 0;
36     public static final int TYPE_3GPP = 1;
37     public static final int TYPE_3GPP2 = 2;
38 
39     private final int mProfileId;
40 
41     private final String mApn;
42 
43     private final String mProtocol;
44 
45     private final int mAuthType;
46 
47     private final String mUserName;
48 
49     private final String mPassword;
50 
51     private final int mType;
52 
53     private final int mMaxConnsTime;
54 
55     private final int mMaxConns;
56 
57     private final int mWaitTime;
58 
59     private final boolean mEnabled;
60 
61     private final int mSupportedApnTypesBitmap;
62 
63     private final String mRoamingProtocol;
64 
65     private final int mBearerBitmap;
66 
67     private final int mMtu;
68 
69     private final String mMvnoType;
70 
71     private final String mMvnoMatchData;
72 
73     private final boolean mModemCognitive;
74 
DataProfile(int profileId, String apn, String protocol, int authType, String userName, String password, int type, int maxConnsTime, int maxConns, int waitTime, boolean enabled, int supportedApnTypesBitmap, String roamingProtocol, int bearerBitmap, int mtu, String mvnoType, String mvnoMatchData, boolean modemCognitive)75     public DataProfile(int profileId, String apn, String protocol, int authType,
76                 String userName, String password, int type, int maxConnsTime, int maxConns,
77                 int waitTime, boolean enabled, int supportedApnTypesBitmap, String roamingProtocol,
78                 int bearerBitmap, int mtu, String mvnoType, String mvnoMatchData,
79                 boolean modemCognitive) {
80 
81         this.mProfileId = profileId;
82         this.mApn = apn;
83         this.mProtocol = protocol;
84         if (authType == -1) {
85             authType = TextUtils.isEmpty(userName) ? RILConstants.SETUP_DATA_AUTH_NONE
86                     : RILConstants.SETUP_DATA_AUTH_PAP_CHAP;
87         }
88         this.mAuthType = authType;
89         this.mUserName = userName;
90         this.mPassword = password;
91         this.mType = type;
92         this.mMaxConnsTime = maxConnsTime;
93         this.mMaxConns = maxConns;
94         this.mWaitTime = waitTime;
95         this.mEnabled = enabled;
96 
97         this.mSupportedApnTypesBitmap = supportedApnTypesBitmap;
98         this.mRoamingProtocol = roamingProtocol;
99         this.mBearerBitmap = bearerBitmap;
100         this.mMtu = mtu;
101         this.mMvnoType = mvnoType;
102         this.mMvnoMatchData = mvnoMatchData;
103         this.mModemCognitive = modemCognitive;
104     }
105 
DataProfile(Parcel source)106     public DataProfile(Parcel source) {
107         mProfileId = source.readInt();
108         mApn = source.readString();
109         mProtocol = source.readString();
110         mAuthType = source.readInt();
111         mUserName = source.readString();
112         mPassword = source.readString();
113         mType = source.readInt();
114         mMaxConnsTime = source.readInt();
115         mMaxConns = source.readInt();
116         mWaitTime = source.readInt();
117         mEnabled = source.readBoolean();
118         mSupportedApnTypesBitmap = source.readInt();
119         mRoamingProtocol = source.readString();
120         mBearerBitmap = source.readInt();
121         mMtu = source.readInt();
122         mMvnoType = source.readString();
123         mMvnoMatchData = source.readString();
124         mModemCognitive = source.readBoolean();
125     }
126 
127     /**
128      * @return Id of the data profile.
129      */
getProfileId()130     public int getProfileId() { return mProfileId; }
131 
132     /**
133      * @return The APN to establish data connection.
134      */
getApn()135     public String getApn() { return mApn; }
136 
137     /**
138      * @return The connection protocol, should be one of the PDP_type values in TS 27.007 section
139      * 10.1.1. For example, "IP", "IPV6", "IPV4V6", or "PPP".
140      */
getProtocol()141     public String getProtocol() { return mProtocol; }
142 
143     /**
144      * @return The authentication protocol used for this PDP context
145      * (None: 0, PAP: 1, CHAP: 2, PAP&CHAP: 3)
146      */
getAuthType()147     public int getAuthType() { return mAuthType; }
148 
149     /**
150      * @return The username for APN. Can be null.
151      */
getUserName()152     public String getUserName() { return mUserName; }
153 
154     /**
155      * @return The password for APN. Can be null.
156      */
getPassword()157     public String getPassword() { return mPassword; }
158 
159     /**
160      * @return The profile type. Could be one of TYPE_COMMON, TYPE_3GPP, or TYPE_3GPP2.
161      */
getType()162     public int getType() { return mType; }
163 
164     /**
165      * @return The period in seconds to limit the maximum connections.
166      */
getMaxConnsTime()167     public int getMaxConnsTime() { return mMaxConnsTime; }
168 
169     /**
170      * @return The maximum connections allowed.
171      */
getMaxConns()172     public int getMaxConns() { return mMaxConns; }
173 
174     /**
175      * @return The required wait time in seconds after a successful UE initiated disconnect of a
176      * given PDN connection before the device can send a new PDN connection request for that given
177      * PDN.
178      */
getWaitTime()179     public int getWaitTime() { return mWaitTime; }
180 
181     /**
182      * @return True if the profile is enabled.
183      */
isEnabled()184     public boolean isEnabled() { return mEnabled; }
185 
186     /**
187      * @return The supported APN types bitmap. See RIL_ApnTypes for the value of each bit.
188      */
getSupportedApnTypesBitmap()189     public int getSupportedApnTypesBitmap() { return mSupportedApnTypesBitmap; }
190 
191     /**
192      * @return  The connection protocol on roaming network, should be one of the PDP_type values in
193      * TS 27.007 section 10.1.1. For example, "IP", "IPV6", "IPV4V6", or "PPP".
194      */
getRoamingProtocol()195     public String getRoamingProtocol() { return mRoamingProtocol; }
196 
197     /**
198      * @return The bearer bitmap. See RIL_RadioAccessFamily for the value of each bit.
199      */
getBearerBitmap()200     public int getBearerBitmap() { return mBearerBitmap; }
201 
202     /**
203      * @return The maximum transmission unit (MTU) size in bytes.
204      */
getMtu()205     public int getMtu() { return mMtu; }
206 
207     /**
208      * @return The MVNO type: possible values are "imsi", "gid", "spn".
209      */
getMvnoType()210     public String getMvnoType() { return mMvnoType; }
211 
212     /**
213      * @return The MVNO match data. For example,
214      * SPN: A MOBILE, BEN NL, ...
215      * IMSI: 302720x94, 2060188, ...
216      * GID: 4E, 33, ...
217      */
getMvnoMatchData()218     public String getMvnoMatchData() { return mMvnoMatchData; }
219 
220     /**
221      * @return True if the data profile was sent to the modem through setDataProfile earlier.
222      */
isModemCognitive()223     public boolean isModemCognitive() { return mModemCognitive; }
224 
225     @Override
describeContents()226     public int describeContents() {
227         return 0;
228     }
229 
230     @Override
toString()231     public String toString() {
232         return "DataProfile=" + mProfileId + "/" + mProtocol + "/" + mAuthType
233                 + "/" + (Build.IS_USER ? "***/***/***" :
234                          (mApn + "/" + mUserName + "/" + mPassword))
235                 + "/" + mType + "/" + mMaxConnsTime
236                 + "/" + mMaxConns + "/" + mWaitTime + "/" + mEnabled + "/"
237                 + mSupportedApnTypesBitmap + "/" + mRoamingProtocol + "/" + mBearerBitmap + "/"
238                 + mMtu + "/" + mMvnoType + "/" + mMvnoMatchData + "/" + mModemCognitive;
239     }
240 
241     @Override
equals(Object o)242     public boolean equals(Object o) {
243         if (o instanceof DataProfile == false) return false;
244         return (o == this || toString().equals(o.toString()));
245     }
246 
247     @Override
writeToParcel(Parcel dest, int flags)248     public void writeToParcel(Parcel dest, int flags) {
249         dest.writeInt(mProfileId);
250         dest.writeString(mApn);
251         dest.writeString(mProtocol);
252         dest.writeInt(mAuthType);
253         dest.writeString(mUserName);
254         dest.writeString(mPassword);
255         dest.writeInt(mType);
256         dest.writeInt(mMaxConnsTime);
257         dest.writeInt(mMaxConns);
258         dest.writeInt(mWaitTime);
259         dest.writeBoolean(mEnabled);
260         dest.writeInt(mSupportedApnTypesBitmap);
261         dest.writeString(mRoamingProtocol);
262         dest.writeInt(mBearerBitmap);
263         dest.writeInt(mMtu);
264         dest.writeString(mMvnoType);
265         dest.writeString(mMvnoMatchData);
266         dest.writeBoolean(mModemCognitive);
267     }
268 
269     public static final Parcelable.Creator<DataProfile> CREATOR =
270             new Parcelable.Creator<DataProfile>() {
271         @Override
272         public DataProfile createFromParcel(Parcel source) {
273             return new DataProfile(source);
274         }
275 
276         @Override
277         public DataProfile[] newArray(int size) {
278             return new DataProfile[size];
279         }
280     };
281 }
282