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 com.android.internal.telephony.dataconnection;
18 
19 import android.os.Parcel;
20 import android.telephony.ServiceState;
21 
22 public class DataProfile {
23 
24     static final int TYPE_COMMON = 0;
25     static final int TYPE_3GPP = 1;
26     static final int TYPE_3GPP2 = 2;
27 
28     //id of the data profile
29     public final int profileId;
30     //the APN to connect to
31     public final String apn;
32     //one of the PDP_type values in TS 27.007 section 10.1.1.
33     //For example, "IP", "IPV6", "IPV4V6", or "PPP".
34     public final String protocol;
35     //authentication protocol used for this PDP context
36     //(None: 0, PAP: 1, CHAP: 2, PAP&CHAP: 3)
37     public final int authType;
38     //the username for APN, or NULL
39     public final String user;
40     //the password for APN, or NULL
41     public final String password;
42     //the profile type, TYPE_COMMON, TYPE_3GPP, TYPE_3GPP2
43     public final int type;
44     //the period in seconds to limit the maximum connections
45     public final int maxConnsTime;
46     //the maximum connections during maxConnsTime
47     public final int maxConns;
48     //the required wait time in seconds after a successful UE initiated
49     //disconnect of a given PDN connection before the device can send
50     //a new PDN connection request for that given PDN
51     public final int waitTime;
52     //true to enable the profile, false to disable
53     public final boolean enabled;
54 
55 
DataProfile(int profileId, String apn, String protocol, int authType, String user, String password, int type, int maxConnsTime, int maxConns, int waitTime, boolean enabled)56     DataProfile(int profileId, String apn, String protocol, int authType,
57             String user, String password, int type, int maxConnsTime, int maxConns,
58             int waitTime, boolean enabled) {
59 
60         this.profileId = profileId;
61         this.apn = apn;
62         this.protocol = protocol;
63         this.authType = authType;
64         this.user = user;
65         this.password = password;
66         this.type = type;
67         this.maxConnsTime = maxConnsTime;
68         this.maxConns = maxConns;
69         this.waitTime = waitTime;
70         this.enabled = enabled;
71     }
72 
DataProfile(ApnSetting apn, boolean isRoaming)73     DataProfile(ApnSetting apn, boolean isRoaming) {
74         this(apn.profileId, apn.apn, isRoaming? apn.protocol : apn.roamingProtocol,
75                 apn.authType, apn.user, apn.password, apn.bearerBitmask == 0 ? TYPE_COMMON :
76                         (ServiceState.hasCdma(apn.bearerBitmask) ? TYPE_3GPP2 : TYPE_3GPP),
77                 apn.maxConnsTime, apn.maxConns, apn.waitTime, apn.carrierEnabled);
78     }
79 
toParcel(Parcel pc, DataProfile[] dps)80     public static Parcel toParcel(Parcel pc, DataProfile[] dps) {
81 
82         if(pc == null) {
83             return null;
84         }
85 
86         pc.writeInt(dps.length);
87         for(int i = 0; i < dps.length; i++) {
88             pc.writeInt(dps[i].profileId);
89             pc.writeString(dps[i].apn);
90             pc.writeString(dps[i].protocol);
91             pc.writeInt(dps[i].authType);
92             pc.writeString(dps[i].user);
93             pc.writeString(dps[i].password);
94             pc.writeInt(dps[i].type);
95             pc.writeInt(dps[i].maxConnsTime);
96             pc.writeInt(dps[i].maxConns);
97             pc.writeInt(dps[i].waitTime);
98             pc.writeInt(dps[i].enabled ? 1 : 0);
99         }
100         return pc;
101     }
102 
103     @Override
toString()104     public String toString() {
105         return "DataProfile " + profileId + "/" + apn + "/" + protocol + "/" + authType
106                 + "/" + user + "/" + password + "/" + type + "/" + maxConnsTime
107                 + "/" + maxConns + "/" + waitTime + "/" + enabled;
108     }
109 
110     @Override
equals(Object o)111     public boolean equals(Object o) {
112         if (o instanceof DataProfile == false) return false;
113         return (toString().equals(o.toString()));
114     }
115 }
116