From 1f6408a96c757b3001c553f8f34ef0bda00a224d Mon Sep 17 00:00:00 2001 From: Wink Saville Date: Fri, 27 Aug 2010 11:15:18 -0700 Subject: Add NetworkProperties to DataConnection. Since we have NetworkProperties we can remove the individual accessors from Phone and its subclasses. Change-Id: Id9969a880405900a63051b3ae4019d889afb1fe8 --- .../android/internal/telephony/DataConnection.java | 123 ++++++++++++--------- .../internal/telephony/DataConnectionTracker.java | 54 +-------- .../java/com/android/internal/telephony/Phone.java | 26 ----- .../com/android/internal/telephony/PhoneBase.java | 18 --- .../com/android/internal/telephony/PhoneProxy.java | 20 ---- .../telephony/cdma/CdmaDataConnectionTracker.java | 35 +----- .../internal/telephony/gsm/GsmDataConnection.java | 7 +- .../telephony/gsm/GsmDataConnectionTracker.java | 42 +------ 8 files changed, 78 insertions(+), 247 deletions(-) (limited to 'telephony') diff --git a/telephony/java/com/android/internal/telephony/DataConnection.java b/telephony/java/com/android/internal/telephony/DataConnection.java index 13c76e5..7e722cb 100644 --- a/telephony/java/com/android/internal/telephony/DataConnection.java +++ b/telephony/java/com/android/internal/telephony/DataConnection.java @@ -21,11 +21,17 @@ import com.android.internal.telephony.gsm.ApnSetting; import com.android.internal.util.HierarchicalState; import com.android.internal.util.HierarchicalStateMachine; +import android.net.NetworkProperties; import android.os.AsyncResult; import android.os.Message; import android.os.SystemProperties; import android.util.EventLog; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.net.UnknownHostException; + /** * {@hide} * @@ -255,10 +261,7 @@ public abstract class DataConnection extends HierarchicalStateMachine { protected int mTag; protected PhoneBase phone; protected int cid; - protected String interfaceName; - protected String ipAddress; - protected String gatewayAddress; - protected String[] dnsServers; + protected NetworkProperties mNetworkProperties = new NetworkProperties(); protected long createTime; protected long lastFailTime; protected FailCause lastFailCause; @@ -283,8 +286,6 @@ public abstract class DataConnection extends HierarchicalStateMachine { if (DBG) log("DataConnection constructor E"); this.phone = phone; this.cid = -1; - this.dnsServers = new String[2]; - clearSettings(); setDbg(false); @@ -377,11 +378,7 @@ public abstract class DataConnection extends HierarchicalStateMachine { this.lastFailTime = -1; this.lastFailCause = FailCause.NONE; - interfaceName = null; - ipAddress = null; - gatewayAddress = null; - dnsServers[0] = null; - dnsServers[1] = null; + mNetworkProperties.clear(); } /** @@ -416,37 +413,65 @@ public abstract class DataConnection extends HierarchicalStateMachine { // for (int i = 0; i < response.length; i++) { // log(" response[" + i + "]='" + response[i] + "'"); // } + + // Start with clean network properties and if we have + // a failure we'll clear again at the bottom of this code. + mNetworkProperties.clear(); if (response.length >= 2) { cid = Integer.parseInt(response[0]); - interfaceName = response[1]; - - String prefix = "net." + interfaceName + "."; - gatewayAddress = SystemProperties.get(prefix + "gw"); - dnsServers[0] = SystemProperties.get(prefix + "dns1"); - dnsServers[1] = SystemProperties.get(prefix + "dns2"); - - if (response.length > 2) { - ipAddress = response[2]; - - if (isDnsOk(dnsServers)) { - result = SetupResult.SUCCESS; - } else { - result = SetupResult.ERR_BadDns; + String interfaceName = response[1]; + result = SetupResult.SUCCESS; + + try { + String prefix = "net." + interfaceName + "."; + + mNetworkProperties.setInterface(NetworkInterface.getByName(interfaceName)); + + // TODO: Get gateway and dns via RIL interface not property? + String gatewayAddress = SystemProperties.get(prefix + "gw"); + mNetworkProperties.setGateway(InetAddress.getByName(gatewayAddress)); + + if (response.length > 2) { + String ipAddress = response[2]; + mNetworkProperties.addAddress(InetAddress.getByName(ipAddress)); + + // TODO: Get gateway and dns via RIL interface not property? + String dnsServers[] = new String[2]; + dnsServers[0] = SystemProperties.get(prefix + "dns1"); + dnsServers[1] = SystemProperties.get(prefix + "dns2"); + if (isDnsOk(dnsServers)) { + mNetworkProperties.addDns(InetAddress.getByName(dnsServers[0])); + mNetworkProperties.addDns(InetAddress.getByName(dnsServers[1])); + } else { + result = SetupResult.ERR_BadDns; + } } - } else { - result = SetupResult.SUCCESS; + } catch (UnknownHostException e1) { + log("onSetupCompleted: UnknowHostException " + e1); + e1.printStackTrace(); + result = SetupResult.ERR_Other; + } catch (SocketException e2) { + log("onSetupCompleted: SocketException " + e2); + e2.printStackTrace(); + result = SetupResult.ERR_Other; } } else { + log("onSetupCompleted: error; expected number of responses >= 2 was " + + response.length); result = SetupResult.ERR_Other; } + + // An error occurred so clear properties + if (result != SetupResult.SUCCESS) { + log("onSetupCompleted with an error clearing NetworkProperties"); + mNetworkProperties.clear(); + } } if (DBG) { log("DataConnection setup result='" + result + "' on cid=" + cid); if (result == SetupResult.SUCCESS) { - log("interface=" + interfaceName + " ipAddress=" + ipAddress - + " gateway=" + gatewayAddress + " DNS1=" + dnsServers[0] - + " DNS2=" + dnsServers[1]); + log("NetworkProperties: " + mNetworkProperties.toString()); } } return result; @@ -610,7 +635,16 @@ public abstract class DataConnection extends HierarchicalStateMachine { break; case ERR_BadDns: // Connection succeeded but DNS info is bad so disconnect - EventLog.writeEvent(EventLogTags.PDP_BAD_DNS_ADDRESS, dnsServers[0]); + StringBuilder dnsAddressesSb = new StringBuilder(); + for (InetAddress addr : mNetworkProperties.getDnses()) { + if (dnsAddressesSb.length() != 0) dnsAddressesSb.append(" "); + dnsAddressesSb.append(addr.toString()); + } + if (dnsAddressesSb.length() == 0) { + dnsAddressesSb.append("no-dns-addresses"); + } + EventLog.writeEvent(EventLogTags.PDP_BAD_DNS_ADDRESS, + dnsAddressesSb.toString()); tearDownData(cp); transitionTo(mDisconnectingBadDnsState); break; @@ -877,31 +911,10 @@ public abstract class DataConnection extends HierarchicalStateMachine { } /** - * @return the interface name as a string. - */ - public String getInterface() { - return interfaceName; - } - - /** - * @return the ip address as a string. - */ - public String getIpAddress() { - return ipAddress; - } - - /** - * @return the gateway address as a string. - */ - public String getGatewayAddress() { - return gatewayAddress; - } - - /** - * @return an array of associated DNS addresses. + * @return the connections NetworkProperties */ - public String[] getDnsServers() { - return dnsServers; + public NetworkProperties getNetworkProperties() { + return mNetworkProperties; } /** diff --git a/telephony/java/com/android/internal/telephony/DataConnectionTracker.java b/telephony/java/com/android/internal/telephony/DataConnectionTracker.java index 06807c6..14cb584 100644 --- a/telephony/java/com/android/internal/telephony/DataConnectionTracker.java +++ b/telephony/java/com/android/internal/telephony/DataConnectionTracker.java @@ -21,18 +21,14 @@ import android.net.NetworkProperties; import android.os.AsyncResult; import android.os.Handler; import android.os.Message; -import android.os.RemoteException; import android.provider.Settings; import android.provider.Settings.SettingNotFoundException; import android.text.TextUtils; import android.util.Log; -import java.net.InetAddress; -import java.net.NetworkInterface; -import java.net.SocketException; -import java.net.UnknownHostException; import java.util.ArrayList; + /** * {@hide} * @@ -422,14 +418,6 @@ public abstract class DataConnectionTracker extends Handler { public abstract ArrayList getAllDataConnections(); - protected abstract String getInterfaceName(String apnType); - - protected abstract String getIpAddress(String apnType); - - protected abstract String getGateway(String apnType); - - protected abstract String[] getDnsServers(String apnType); - protected abstract void setState(State s); protected NetworkProperties getNetworkProperties(String apnType) { @@ -685,43 +673,7 @@ public abstract class DataConnectionTracker extends Handler { } } - protected NetworkProperties makeNetworkProperties(DataConnection connection) { - NetworkProperties properties = new NetworkProperties(); - try { - properties.setInterface(NetworkInterface.getByName(connection.getInterface())); - } catch (SocketException e) { - Log.e(LOG_TAG, "SocketException creating NetworkInterface: " + e); - } catch (NullPointerException e) { - Log.e(LOG_TAG, "NPE trying to makeNetworkProperties: " + e); - } - - try { - properties.addAddress(InetAddress.getByName(connection.getIpAddress())); - } catch (UnknownHostException e) { - Log.e(LOG_TAG, "UnknownHostException setting IpAddress: " + e); - } catch (SecurityException e) { - Log.e(LOG_TAG, "SecurityException setting IpAddress: " + e); - } - - try { - properties.setGateway(InetAddress.getByName(connection.getGatewayAddress())); - } catch (UnknownHostException e) { - Log.e(LOG_TAG, "UnknownHostException setting GatewayAddress: " + e); - } catch (SecurityException e) { - Log.e(LOG_TAG, "SecurityException setting GatewayAddress: " + e); - } - - try { - String[] dnsStrings = connection.getDnsServers(); - for (int i = 0; i getAllDataConnections() { return dataConnectionList; } diff --git a/telephony/java/com/android/internal/telephony/gsm/GsmDataConnection.java b/telephony/java/com/android/internal/telephony/gsm/GsmDataConnection.java index 09d46dd..1572f09 100644 --- a/telephony/java/com/android/internal/telephony/gsm/GsmDataConnection.java +++ b/telephony/java/com/android/internal/telephony/gsm/GsmDataConnection.java @@ -180,8 +180,8 @@ public class GsmDataConnection extends DataConnection { @Override protected boolean isDnsOk(String[] domainNameServers) { - if (NULL_IP.equals(dnsServers[0]) && NULL_IP.equals(dnsServers[1]) - && !((GSMPhone) phone).isDnsCheckDisabled()) { + if (NULL_IP.equals(domainNameServers[0]) && NULL_IP.equals(domainNameServers[1]) + && !((GSMPhone) phone).isDnsCheckDisabled()) { // Work around a race condition where QMI does not fill in DNS: // Deactivate PDP and let DataConnectionTracker retry. // Do not apply the race condition workaround for MMS APN @@ -189,6 +189,9 @@ public class GsmDataConnection extends DataConnection { // Otherwise, the default APN will not be restored anymore. if (!apn.types[0].equals(Phone.APN_TYPE_MMS) || !isIpAddress(apn.mmsProxy)) { + log(String.format( + "isDnsOk: return false apn.types[0]=%s APN_TYPE_MMS=%s isIpAddress(%s)=%s", + apn.types[0], Phone.APN_TYPE_MMS, apn.mmsProxy, isIpAddress(apn.mmsProxy))); return false; } } diff --git a/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java b/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java index c76da80..face581 100644 --- a/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java +++ b/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java @@ -27,17 +27,14 @@ import android.content.IntentFilter; import android.content.SharedPreferences; import android.database.ContentObserver; import android.database.Cursor; -import android.net.ConnectivityManager; import android.net.IConnectivityManager; import android.net.NetworkInfo; -import android.net.NetworkProperties; import android.net.ProxyProperties; import android.net.TrafficStats; import android.net.Uri; import android.net.wifi.WifiManager; import android.os.AsyncResult; import android.os.Message; -import android.os.RemoteException; import android.os.ServiceManager; import android.os.SystemClock; import android.os.SystemProperties; @@ -61,7 +58,6 @@ import com.android.internal.telephony.DataConnection.FailCause; import java.io.IOException; import java.net.InetAddress; -import java.net.NetworkInterface; import java.net.UnknownHostException; import java.util.ArrayList; @@ -612,42 +608,6 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker { return true; } - protected String getInterfaceName(String apnType) { - if (mActivePdp != null && - (apnType == null || - (mActiveApn != null && mActiveApn.canHandleType(apnType)))) { - return mActivePdp.getInterface(); - } - return null; - } - - protected String getIpAddress(String apnType) { - if (mActivePdp != null && - (apnType == null || - (mActiveApn != null && mActiveApn.canHandleType(apnType)))) { - return mActivePdp.getIpAddress(); - } - return null; - } - - public String getGateway(String apnType) { - if (mActivePdp != null && - (apnType == null || - (mActiveApn != null && mActiveApn.canHandleType(apnType)))) { - return mActivePdp.getGatewayAddress(); - } - return null; - } - - protected String[] getDnsServers(String apnType) { - if (mActivePdp != null && - (apnType == null || - (mActiveApn != null && mActiveApn.canHandleType(apnType)))) { - return mActivePdp.getDnsServers(); - } - return null; - } - private boolean pdpStatesHasCID (ArrayList states, int cid) { for (int i = 0, s = states.size() ; i < s ; i++) { @@ -1138,7 +1098,7 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker { } if (ar.exception == null) { - mNetworkProperties = makeNetworkProperties(mActivePdp); + mNetworkProperties = getNetworkProperties(mActivePdp); ApnSetting apn = mActivePdp.getApn(); if (apn.proxy != null && apn.proxy.length() != 0) { -- cgit v1.1