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 com.android.internal.telephony.dataconnection;
18
19import android.os.Parcel;
20import android.telephony.ServiceState;
21
22public 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
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
73    public DataProfile(ApnSetting apn, boolean isRoaming) {
74        this(apn.profileId, apn.apn, isRoaming? apn.roamingProtocol : apn.protocol,
75                apn.authType, apn.user, apn.password, apn.bearerBitmask == 0
76                        ? TYPE_COMMON : (ServiceState.bearerBitmapHasCdma(apn.bearerBitmask)
77                        ? TYPE_3GPP2 : TYPE_3GPP),
78                apn.maxConnsTime, apn.maxConns, apn.waitTime, apn.carrierEnabled);
79    }
80
81    public static Parcel toParcel(Parcel pc, DataProfile[] dps) {
82
83        if(pc == null) {
84            return null;
85        }
86
87        pc.writeInt(dps.length);
88        for(int i = 0; i < dps.length; i++) {
89            pc.writeInt(dps[i].profileId);
90            pc.writeString(dps[i].apn);
91            pc.writeString(dps[i].protocol);
92            pc.writeInt(dps[i].authType);
93            pc.writeString(dps[i].user);
94            pc.writeString(dps[i].password);
95            pc.writeInt(dps[i].type);
96            pc.writeInt(dps[i].maxConnsTime);
97            pc.writeInt(dps[i].maxConns);
98            pc.writeInt(dps[i].waitTime);
99            pc.writeInt(dps[i].enabled ? 1 : 0);
100        }
101        return pc;
102    }
103
104    @Override
105    public String toString() {
106        return "DataProfile " + profileId + "/" + apn + "/" + protocol + "/" + authType
107                + "/" + user + "/" + password + "/" + type + "/" + maxConnsTime
108                + "/" + maxConns + "/" + waitTime + "/" + enabled;
109    }
110
111    @Override
112    public boolean equals(Object o) {
113        if (o instanceof DataProfile == false) return false;
114        return (toString().equals(o.toString()));
115    }
116}
117