2 * Copyright (C) 2006 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.internal.telephony;
20 * This class represents a apn setting for create PDP link
22 public class ApnSetting {
24 static final String V2_FORMAT_REGEX = "^\\[ApnSettingV2\\]\\s*";
26 public String carrier;
31 public String mmsProxy;
32 public String mmsPort;
34 public String password;
36 public String[] types;
38 public String numeric;
39 public String protocol;
40 public String roamingProtocol;
42 public ApnSetting(int id, String numeric, String carrier, String apn,
43 String proxy, String port,
44 String mmsc, String mmsProxy, String mmsPort,
45 String user, String password, int authType, String[] types,
46 String protocol, String roamingProtocol) {
48 this.numeric = numeric;
49 this.carrier = carrier;
54 this.mmsProxy = mmsProxy;
55 this.mmsPort = mmsPort;
57 this.password = password;
58 this.authType = authType;
60 this.protocol = protocol;
61 this.roamingProtocol = roamingProtocol;
65 * Creates an ApnSetting object from a string.
67 * @param data the string to read.
69 * The string must be in one of two formats (newlines added for clarity,
70 * spaces are optional):
73 * <carrier>, <apn>, <proxy>, <port>, <mmsc>, <mmsproxy>,
74 * <mmsport>, <user>, <password>, <authtype>, <mcc>,<mnc>,
78 * [ApnSettingV2] <carrier>, <apn>, <proxy>, <port>, <mmsc>, <mmsproxy>,
79 * <mmsport>, <user>, <password, <authtype>, <mcc>, <mnc>,
80 * <type>[| <type>...], <protocol>, <roaming_protocol>
82 * Note that the strings generated by toString() do not contain the username
83 * and password and thus cannot be read by this method.
87 public static ApnSetting fromString(String data) {
88 if (data == null) return null;
91 // matches() operates on the whole string, so append .* to the regex.
92 if (data.matches(V2_FORMAT_REGEX + ".*")) {
94 data = data.replaceFirst(V2_FORMAT_REGEX, "");
99 String[] a = data.split("\\s*,\\s*");
106 authType = Integer.parseInt(a[12]);
107 } catch (Exception e) {
112 String protocol, roamingProtocol;
114 typeArray = new String[a.length - 13];
115 System.arraycopy(a, 13, typeArray, 0, a.length - 13);
116 protocol = RILConstants.SETUP_DATA_PROTOCOL_IP;
117 roamingProtocol = RILConstants.SETUP_DATA_PROTOCOL_IP;
122 typeArray = a[13].split("\\s*\\|\\s*");
124 roamingProtocol = a[15];
127 return new ApnSetting(-1,a[10]+a[11],a[0],a[1],a[2],a[3],a[7],a[8],
128 a[9],a[4],a[5],authType,typeArray,protocol,roamingProtocol);
131 public String toString() {
132 StringBuilder sb = new StringBuilder();
133 sb.append("[ApnSettingV2] ")
135 .append(", ").append(id)
136 .append(", ").append(numeric)
137 .append(", ").append(apn)
138 .append(", ").append(proxy)
139 .append(", ").append(mmsc)
140 .append(", ").append(mmsProxy)
141 .append(", ").append(mmsPort)
142 .append(", ").append(port)
143 .append(", ").append(authType).append(", ");
144 for (int i = 0; i < types.length; i++) {
146 if (i < types.length - 1) {
150 sb.append(", ").append(protocol);
151 sb.append(", ").append(roamingProtocol);
152 return sb.toString();
155 public boolean canHandleType(String type) {
156 for (String t : types) {
157 // DEFAULT handles all, and HIPRI is handled by DEFAULT
158 if (t.equals(type) || t.equals(Phone.APN_TYPE_ALL) ||
159 (t.equals(Phone.APN_TYPE_DEFAULT) &&
160 type.equals(Phone.APN_TYPE_HIPRI))) {