OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / frameworks / base / telephony / java / com / android / internal / telephony / gsm / ApnSetting.java
1 /*
2  * Copyright (C) 2006 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.gsm;
18
19 import com.android.internal.telephony.*;
20 /**
21  * This class represents a apn setting for create PDP link
22  */
23 public class ApnSetting {
24
25     String carrier;
26     String apn;
27     String proxy;
28     String port;
29     String mmsc;
30     String mmsProxy;
31     String mmsPort;
32     String user;
33     String password;
34     int authType;
35     public String[] types;
36     int id;
37     String numeric;
38
39
40     public ApnSetting(int id, String numeric, String carrier, String apn, String proxy, String port,
41             String mmsc, String mmsProxy, String mmsPort,
42             String user, String password, int authType, String[] types) {
43         this.id = id;
44         this.numeric = numeric;
45         this.carrier = carrier;
46         this.apn = apn;
47         this.proxy = proxy;
48         this.port = port;
49         this.mmsc = mmsc;
50         this.mmsProxy = mmsProxy;
51         this.mmsPort = mmsPort;
52         this.user = user;
53         this.password = password;
54         this.authType = authType;
55         this.types = types;
56     }
57
58     // data[0] = name
59     // data[1] = apn
60     // data[2] = proxy
61     // data[3] = port
62     // data[4] = username
63     // data[5] = password
64     // data[6] = server
65     // data[7] = mmsc
66     // data[8] = mmsproxy
67     // data[9] = mmsport
68     // data[10] = mcc
69     // data[11] = mnc
70     // data[12] = auth
71     // data[13] = first type...
72     public static ApnSetting fromString(String data) {
73         if (data == null) return null;
74         String[] a = data.split("\\s*,\\s*");
75         if (a.length < 14) return null;
76         int authType = 0;
77         try {
78             authType = Integer.parseInt(a[12]);
79         } catch (Exception e) {
80         }
81         String[] typeArray = new String[a.length - 13];
82         System.arraycopy(a, 13, typeArray, 0, a.length - 13);
83         return new ApnSetting(-1,a[10]+a[11],a[0],a[1],a[2],a[3],a[7],a[8],
84                 a[9],a[4],a[5],authType,typeArray);
85     }
86
87     public String toString() {
88         StringBuilder sb = new StringBuilder();
89         sb.append(carrier)
90         .append(", ").append(id)
91         .append(", ").append(numeric)
92         .append(", ").append(apn)
93         .append(", ").append(proxy)
94         .append(", ").append(mmsc)
95         .append(", ").append(mmsProxy)
96         .append(", ").append(mmsPort)
97         .append(", ").append(port)
98         .append(", ").append(authType);
99         for (String t : types) {
100             sb.append(", ").append(t);
101         }
102         return sb.toString();
103     }
104
105     public boolean canHandleType(String type) {
106         for (String t : types) {
107             // DEFAULT handles all, and HIPRI is handled by DEFAULT
108             if (t.equals(type) || t.equals(Phone.APN_TYPE_ALL) ||
109                     (t.equals(Phone.APN_TYPE_DEFAULT) &&
110                     type.equals(Phone.APN_TYPE_HIPRI))) {
111                 return true;
112             }
113         }
114         return false;
115     }
116 }