Add NetworkProperties to DataConnection.

Since we have NetworkProperties we can remove the individual accessors
from Phone and its subclasses.

Change-Id: Id9969a880405900a63051b3ae4019d889afb1fe8
This commit is contained in:
Wink Saville
2010-08-27 11:15:18 -07:00
parent 0e30200ed1
commit 1f6408a96c
10 changed files with 87 additions and 247 deletions

View File

@@ -99,19 +99,20 @@ public class NetworkProperties implements Parcelable {
return 0;
}
@Override
public synchronized String toString() {
String ifaceName = (mIface == null ? "" : "InterfaceName: " + mIface.getName() + " ");
String ip = "IpAddresses: [";
for (InetAddress addr : mAddresses) ip += addr.toString() + ",";
for (InetAddress addr : mAddresses) ip += addr.getHostAddress() + ",";
ip += "] ";
String dns = "DnsAddresses: [";
for (InetAddress addr : mDnses) dns += addr.toString() + ",";
for (InetAddress addr : mDnses) dns += addr.getHostAddress() + ",";
dns += "] ";
String proxy = (mHttpProxy == null ? "" : "HttpProxy: " + mHttpProxy.toString() + " ");
String gateway = (mGateway == null ? "" : "Gateway: " + mGateway.toString() + " ");
String gateway = (mGateway == null ? "" : "Gateway: " + mGateway.getHostAddress() + " ");
return ifaceName + ip + gateway + dns + proxy;
}

View File

@@ -57,6 +57,14 @@ public class ProxyProperties implements Parcelable {
mExclusionList = exclusionList;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(mProxy.getHostAddress()).append(":").append(mPort)
.append(" xl=").append(mExclusionList);
return sb.toString();
}
/**
* Implement the Parcelable interface
* @hide

View File

@@ -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 interfaceName = response[1];
result = SetupResult.SUCCESS;
String prefix = "net." + interfaceName + ".";
gatewayAddress = SystemProperties.get(prefix + "gw");
dnsServers[0] = SystemProperties.get(prefix + "dns1");
dnsServers[1] = SystemProperties.get(prefix + "dns2");
try {
String prefix = "net." + interfaceName + ".";
if (response.length > 2) {
ipAddress = response[2];
mNetworkProperties.setInterface(NetworkInterface.getByName(interfaceName));
if (isDnsOk(dnsServers)) {
result = SetupResult.SUCCESS;
} else {
result = SetupResult.ERR_BadDns;
// 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.
* @return the connections NetworkProperties
*/
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.
*/
public String[] getDnsServers() {
return dnsServers;
public NetworkProperties getNetworkProperties() {
return mNetworkProperties;
}
/**

View File

@@ -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<DataConnection> 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<dnsStrings.length; i++) {
properties.addDns(InetAddress.getByName(dnsStrings[i]));
}
} catch (UnknownHostException e) {
Log.e(LOG_TAG, "UnknownHostException setting DnsAddress: " + e);
} catch (SecurityException e) {
Log.e(LOG_TAG, "SecurityException setting DnsAddress: " + e);
}
// TODO - set Proxy info
return properties;
protected NetworkProperties getNetworkProperties(DataConnection connection) {
return connection.getNetworkProperties();
}
}

View File

@@ -17,11 +17,9 @@
package com.android.internal.telephony;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.NetworkProperties;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.telephony.CellLocation;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
@@ -29,7 +27,6 @@ import android.telephony.SignalStrength;
import com.android.internal.telephony.DataConnection;
import com.android.internal.telephony.gsm.NetworkInfo;
import com.android.internal.telephony.gsm.GsmDataConnection;
import com.android.internal.telephony.test.SimulatedRadioControl;
import java.util.List;
@@ -1381,29 +1378,6 @@ public interface Phone {
*/
boolean isDataConnectivityPossible();
/**
* Returns the name of the network interface used by the specified APN type.
*/
String getInterfaceName(String apnType);
/**
* Returns the IP address of the network interface used by the specified
* APN type.
*/
String getIpAddress(String apnType);
/**
* Returns the gateway for the network interface used by the specified APN
* type.
*/
String getGateway(String apnType);
/**
* Returns the DNS servers for the network interface used by the specified
* APN type.
*/
public String[] getDnsServers(String apnType);
/**
* Retrieves the unique device ID, e.g., IMEI for GSM phones and MEID for CDMA phones.
*/

View File

@@ -36,10 +36,8 @@ import android.text.TextUtils;
import android.util.Log;
import com.android.internal.R;
import com.android.internal.telephony.gsm.GsmDataConnection;
import com.android.internal.telephony.test.SimulatedRadioControl;
import java.util.List;
import java.util.Locale;
@@ -932,26 +930,10 @@ public abstract class PhoneBase extends Handler implements Phone {
logUnexpectedCdmaMethodCall("unsetOnEcbModeExitResponse");
}
public String getInterfaceName(String apnType) {
return mDataConnection.getInterfaceName(apnType);
}
public String getIpAddress(String apnType) {
return mDataConnection.getIpAddress(apnType);
}
public boolean isDataConnectivityEnabled() {
return mDataConnection.getDataEnabled();
}
public String getGateway(String apnType) {
return mDataConnection.getGateway(apnType);
}
public String[] getDnsServers(String apnType) {
return mDataConnection.getDnsServers(apnType);
}
public String[] getActiveApnTypes() {
return mDataConnection.getActiveApnTypes();
}

View File

@@ -20,14 +20,11 @@ package com.android.internal.telephony;
import android.app.ActivityManagerNative;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.NetworkProperties;
import android.os.Handler;
import android.os.Message;
import android.os.SystemProperties;
import android.preference.PreferenceManager;
import android.telephony.CellLocation;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
import android.util.Log;
@@ -35,7 +32,6 @@ import android.util.Log;
import com.android.internal.telephony.cdma.CDMAPhone;
import com.android.internal.telephony.gsm.GSMPhone;
import com.android.internal.telephony.gsm.NetworkInfo;
import com.android.internal.telephony.gsm.GsmDataConnection;
import com.android.internal.telephony.test.SimulatedRadioControl;
import java.util.List;
@@ -669,22 +665,6 @@ public class PhoneProxy extends Handler implements Phone {
return mActivePhone.isDataConnectivityPossible();
}
public String getInterfaceName(String apnType) {
return mActivePhone.getInterfaceName(apnType);
}
public String getIpAddress(String apnType) {
return mActivePhone.getIpAddress(apnType);
}
public String getGateway(String apnType) {
return mActivePhone.getGateway(apnType);
}
public String[] getDnsServers(String apnType) {
return mActivePhone.getDnsServers(apnType);
}
public String getDeviceId() {
return mActivePhone.getDeviceId();
}

View File

@@ -23,14 +23,12 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.IConnectivityManager;
import android.net.NetworkInfo;
import android.net.TrafficStats;
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;
@@ -50,10 +48,7 @@ import com.android.internal.telephony.DataConnectionTracker;
import com.android.internal.telephony.EventLogTags;
import com.android.internal.telephony.gsm.ApnSetting;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.RetryManager;
import com.android.internal.telephony.ServiceStateTracker;
import java.net.NetworkInterface;
import java.util.ArrayList;
/**
@@ -737,7 +732,7 @@ public final class CdmaDataConnectionTracker extends DataConnectionTracker {
}
if (ar.exception == null) {
mNetworkProperties = makeNetworkProperties(mActiveDataConnection);
mNetworkProperties = getNetworkProperties(mActiveDataConnection);
// everything is setup
notifyDefaultData(reason);
@@ -967,34 +962,6 @@ public final class CdmaDataConnectionTracker extends DataConnectionTracker {
}
}
protected String getInterfaceName(String apnType) {
if (mActiveDataConnection != null) {
return mActiveDataConnection.getInterface();
}
return null;
}
protected String getIpAddress(String apnType) {
if (mActiveDataConnection != null) {
return mActiveDataConnection.getIpAddress();
}
return null;
}
protected String getGateway(String apnType) {
if (mActiveDataConnection != null) {
return mActiveDataConnection.getGatewayAddress();
}
return null;
}
protected String[] getDnsServers(String apnType) {
if (mActiveDataConnection != null) {
return mActiveDataConnection.getDnsServers();
}
return null;
}
public ArrayList<DataConnection> getAllDataConnections() {
return dataConnectionList;
}

View File

@@ -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;
}
}

View File

@@ -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<DataCallState> 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) {