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 17package com.android.internal.telephony.cdma; 18 19import android.os.Message; 20import android.util.Log; 21 22import com.android.internal.telephony.DataConnection; 23import com.android.internal.telephony.DataConnectionTracker; 24import com.android.internal.telephony.Phone; 25import com.android.internal.telephony.PhoneConstants; 26import com.android.internal.telephony.RILConstants; 27import com.android.internal.telephony.RetryManager; 28 29import java.io.FileDescriptor; 30import java.io.PrintWriter; 31 32/** 33 * {@hide} 34 */ 35public class CdmaDataConnection extends DataConnection { 36 37 private static final String LOG_TAG = "CDMA"; 38 39 // ***** Constructor 40 private CdmaDataConnection(CDMAPhone phone, String name, int id, RetryManager rm, 41 DataConnectionTracker dct) { 42 super(phone, name, id, rm, dct); 43 } 44 45 /** 46 * Create the connection object 47 * 48 * @param phone the Phone 49 * @param id the connection id 50 * @param rm the RetryManager 51 * @return CdmaDataConnection that was created. 52 */ 53 static CdmaDataConnection makeDataConnection(CDMAPhone phone, int id, RetryManager rm, 54 DataConnectionTracker dct) { 55 CdmaDataConnection cdmaDc = new CdmaDataConnection(phone, 56 "CdmaDC-" + mCount.incrementAndGet(), id, rm, dct); 57 cdmaDc.start(); 58 if (DBG) cdmaDc.log("Made " + cdmaDc.getName()); 59 return cdmaDc; 60 } 61 62 /** 63 * Begin setting up a data connection, calls setupDataCall 64 * and the ConnectionParams will be returned with the 65 * EVENT_SETUP_DATA_CONNECTION_DONE AsyncResul.userObj. 66 * 67 * @param cp is the connection parameters 68 */ 69 @Override 70 protected void onConnect(ConnectionParams cp) { 71 if (DBG) log("CdmaDataConnection Connecting..."); 72 73 mApn = cp.apn; 74 createTime = -1; 75 lastFailTime = -1; 76 lastFailCause = FailCause.NONE; 77 int dataProfile; 78 if ((cp.apn != null) && (cp.apn.types.length > 0) && (cp.apn.types[0] != null) && 79 (cp.apn.types[0].equals(PhoneConstants.APN_TYPE_DUN))) { 80 if (DBG) log("CdmaDataConnection using DUN"); 81 dataProfile = RILConstants.DATA_PROFILE_TETHERED; 82 } else { 83 dataProfile = RILConstants.DATA_PROFILE_DEFAULT; 84 } 85 86 // msg.obj will be returned in AsyncResult.userObj; 87 Message msg = obtainMessage(EVENT_SETUP_DATA_CONNECTION_DONE, cp); 88 msg.obj = cp; 89 phone.mCM.setupDataCall( 90 Integer.toString(getRilRadioTechnology(RILConstants.SETUP_DATA_TECH_CDMA)), 91 Integer.toString(dataProfile), 92 null, null, null, 93 Integer.toString(RILConstants.SETUP_DATA_AUTH_PAP_CHAP), 94 RILConstants.SETUP_DATA_PROTOCOL_IP, msg); 95 } 96 97 @Override 98 public String toString() { 99 return "State=" + getCurrentState().getName() + " create=" + createTime + " lastFail=" 100 + lastFailTime + " lastFasilCause=" + lastFailCause; 101 } 102 103 @Override 104 protected boolean isDnsOk(String[] domainNameServers) { 105 if (NULL_IP.equals(domainNameServers[0]) 106 && NULL_IP.equals(domainNameServers[1]) 107 && !phone.isDnsCheckDisabled()) { 108 return false; 109 } else { 110 return true; 111 } 112 } 113 114 @Override 115 protected void log(String s) { 116 Log.d(LOG_TAG, "[" + getName() + "] " + s); 117 } 118 119 @Override 120 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 121 pw.println("CdmaDataConnection extends:"); 122 super.dump(fd, pw, args); 123 } 124} 125