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.gsm;
19 import android.os.Message;
20 import android.telephony.Rlog;
21 import android.util.Patterns;
22 import android.text.TextUtils;
24 import com.android.internal.telephony.DataConnection;
25 import com.android.internal.telephony.DataConnectionTracker;
26 import com.android.internal.telephony.PhoneBase;
27 import com.android.internal.telephony.PhoneConstants;
28 import com.android.internal.telephony.RILConstants;
29 import com.android.internal.telephony.RetryManager;
31 import java.io.FileDescriptor;
32 import java.io.PrintWriter;
37 public class GsmDataConnection extends DataConnection {
39 private static final String LOG_TAG = "GSM";
41 //***** Instance Variables
42 protected int mProfileId = RILConstants.DATA_PROFILE_DEFAULT;
44 private GsmDataConnection(PhoneBase phone, String name, int id, RetryManager rm,
45 DataConnectionTracker dct) {
46 super(phone, name, id, rm, dct);
50 * Create the connection object
52 * @param phone the Phone
53 * @param id the connection id
54 * @param rm the RetryManager
55 * @return GsmDataConnection that was created.
57 static GsmDataConnection makeDataConnection(PhoneBase phone, int id, RetryManager rm,
58 DataConnectionTracker dct) {
59 GsmDataConnection gsmDc = new GsmDataConnection(phone,
60 "GsmDC-" + mCount.incrementAndGet(), id, rm, dct);
62 if (DBG) gsmDc.log("Made " + gsmDc.getName());
67 * Begin setting up a data connection, calls setupDataCall
68 * and the ConnectionParams will be returned with the
69 * EVENT_SETUP_DATA_CONNECTION_DONE AsyncResul.userObj.
71 * @param cp is the connection parameters
75 void onConnect(ConnectionParams cp) {
78 if (DBG) log("Connecting to carrier: '" + mApn.carrier
79 + "' APN: '" + mApn.apn
80 + "' proxy: '" + mApn.proxy + "' port: '" + mApn.port);
84 lastFailCause = FailCause.NONE;
86 // msg.obj will be returned in AsyncResult.userObj;
87 Message msg = obtainMessage(EVENT_SETUP_DATA_CONNECTION_DONE, cp);
90 int authType = mApn.authType;
92 authType = TextUtils.isEmpty(mApn.user) ? RILConstants.SETUP_DATA_AUTH_NONE
93 : RILConstants.SETUP_DATA_AUTH_PAP_CHAP;
97 if (phone.getServiceState().getRoaming()) {
98 protocol = mApn.roamingProtocol;
100 protocol = mApn.protocol;
103 phone.mCM.setupDataCall(
104 Integer.toString(getRilRadioTechnology(RILConstants.SETUP_DATA_TECH_GSM)),
105 Integer.toString(mProfileId),
106 mApn.apn, mApn.user, mApn.password,
107 Integer.toString(authType),
111 public void setProfileId(int profileId) {
112 mProfileId = profileId;
115 public int getProfileId() {
120 public String toString() {
121 return "{" + getName() + ": State=" + getCurrentState().getName() +
122 " apnSetting=" + mApn + " apnList= " + mApnList + " RefCount=" + mRefCount +
123 " cid=" + cid + " create=" + createTime + " lastFail=" + lastFailTime +
124 " lastFailCause=" + lastFailCause + "}";
128 protected boolean isDnsOk(String[] domainNameServers) {
129 if (NULL_IP.equals(domainNameServers[0]) && NULL_IP.equals(domainNameServers[1])
130 && !phone.isDnsCheckDisabled()) {
131 // Work around a race condition where QMI does not fill in DNS:
132 // Deactivate PDP and let DataConnectionTracker retry.
133 // Do not apply the race condition workaround for MMS APN
134 // if Proxy is an IP-address.
135 // Otherwise, the default APN will not be restored anymore.
136 if (!mApn.types[0].equals(PhoneConstants.APN_TYPE_MMS)
137 || !isIpAddress(mApn.mmsProxy)) {
139 "isDnsOk: return false apn.types[0]=%s APN_TYPE_MMS=%s isIpAddress(%s)=%s",
140 mApn.types[0], PhoneConstants.APN_TYPE_MMS, mApn.mmsProxy,
141 isIpAddress(mApn.mmsProxy)));
149 protected void log(String s) {
150 Rlog.d(LOG_TAG, "[" + getName() + "] " + s);
153 private boolean isIpAddress(String address) {
154 if (address == null) return false;
156 return Patterns.IP_ADDRESS.matcher(address).matches();
160 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
161 pw.println("GsmDataConnection extends:");
162 super.dump(fd, pw, args);
163 pw.println(" mProfileId=" + mProfileId);