diff options
author | Robert Greenwalt <rgreenwalt@google.com> | 2012-11-09 09:51:21 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-11-09 09:51:21 -0800 |
commit | 321020b7e08215b813f15caaad1c59ac215831c6 (patch) | |
tree | 522d0b6b00219957aaf0db9d15012d4396e92052 /wifi/java/android/net | |
parent | 36465c781519719a91d12bbe780db1180c06df57 (diff) | |
parent | 4717c261b2c670d5c0925e3527a864aa52db6ac0 (diff) | |
download | frameworks_base-321020b7e08215b813f15caaad1c59ac215831c6.zip frameworks_base-321020b7e08215b813f15caaad1c59ac215831c6.tar.gz frameworks_base-321020b7e08215b813f15caaad1c59ac215831c6.tar.bz2 |
Merge "Remove DhcpInfoInternal"
Diffstat (limited to 'wifi/java/android/net')
-rw-r--r-- | wifi/java/android/net/wifi/WifiConfigStore.java | 40 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/WifiInfo.java | 9 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/WifiManager.java | 2 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/WifiStateMachine.java | 87 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/p2p/WifiP2pService.java | 17 |
5 files changed, 67 insertions, 88 deletions
diff --git a/wifi/java/android/net/wifi/WifiConfigStore.java b/wifi/java/android/net/wifi/WifiConfigStore.java index 84506b6..c3278a9 100644 --- a/wifi/java/android/net/wifi/WifiConfigStore.java +++ b/wifi/java/android/net/wifi/WifiConfigStore.java @@ -18,7 +18,6 @@ package android.net.wifi; import android.content.Context; import android.content.Intent; -import android.net.DhcpInfoInternal; import android.net.LinkAddress; import android.net.LinkProperties; import android.net.NetworkUtils; @@ -502,45 +501,12 @@ class WifiConfigStore { } /** - * get IP configuration for a given network id - * TODO: We cannot handle IPv6 addresses for configuration - * right now until NetworkUtils is fixed. When we do - * that, we should remove handling DhcpInfo and move - * to using LinkProperties - * @return DhcpInfoInternal for the given network id - */ - DhcpInfoInternal getIpConfiguration(int netId) { - DhcpInfoInternal dhcpInfoInternal = new DhcpInfoInternal(); - LinkProperties linkProperties = getLinkProperties(netId); - - if (linkProperties != null) { - Iterator<LinkAddress> iter = linkProperties.getLinkAddresses().iterator(); - if (iter.hasNext()) { - LinkAddress linkAddress = iter.next(); - dhcpInfoInternal.ipAddress = linkAddress.getAddress().getHostAddress(); - for (RouteInfo route : linkProperties.getRoutes()) { - dhcpInfoInternal.addRoute(route); - } - dhcpInfoInternal.prefixLength = linkAddress.getNetworkPrefixLength(); - Iterator<InetAddress> dnsIterator = linkProperties.getDnses().iterator(); - dhcpInfoInternal.dns1 = dnsIterator.next().getHostAddress(); - if (dnsIterator.hasNext()) { - dhcpInfoInternal.dns2 = dnsIterator.next().getHostAddress(); - } - } - } - return dhcpInfoInternal; - } - - /** * set IP configuration for a given network id */ - void setIpConfiguration(int netId, DhcpInfoInternal dhcpInfo) { - LinkProperties linkProperties = dhcpInfo.makeLinkProperties(); - + void setLinkProperties(int netId, LinkProperties linkProperties) { WifiConfiguration config = mConfiguredNetworks.get(netId); if (config != null) { - // add old proxy details + // add old proxy details - TODO - is this still needed? if(config.linkProperties != null) { linkProperties.setHttpProxy(config.linkProperties.getHttpProxy()); } @@ -552,7 +518,7 @@ class WifiConfigStore { * clear IP configuration for a given network id * @param network id */ - void clearIpConfiguration(int netId) { + void clearLinkProperties(int netId) { WifiConfiguration config = mConfiguredNetworks.get(netId); if (config != null && config.linkProperties != null) { // Clear everything except proxy diff --git a/wifi/java/android/net/wifi/WifiInfo.java b/wifi/java/android/net/wifi/WifiInfo.java index 05db571..502d1ab 100644 --- a/wifi/java/android/net/wifi/WifiInfo.java +++ b/wifi/java/android/net/wifi/WifiInfo.java @@ -23,7 +23,7 @@ import android.net.NetworkUtils; import android.text.TextUtils; import java.net.InetAddress; -import java.net.Inet6Address; +import java.net.Inet4Address; import java.net.UnknownHostException; import java.util.EnumMap; @@ -231,8 +231,11 @@ public class WifiInfo implements Parcelable { } public int getIpAddress() { - if (mIpAddress == null || mIpAddress instanceof Inet6Address) return 0; - return NetworkUtils.inetAddressToInt(mIpAddress); + int result = 0; + if (mIpAddress instanceof Inet4Address) { + result = NetworkUtils.inetAddressToInt((Inet4Address)mIpAddress); + } + return result; } /** diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java index 0e29882..4861759 100644 --- a/wifi/java/android/net/wifi/WifiManager.java +++ b/wifi/java/android/net/wifi/WifiManager.java @@ -862,6 +862,7 @@ public class WifiManager { * Return the DHCP-assigned addresses from the last successful DHCP request, * if any. * @return the DHCP information + * @deprecated - use ConnectivityManager.getLinkProperties instead. TODO - remove 11/2013 */ public DhcpInfo getDhcpInfo() { try { @@ -871,7 +872,6 @@ public class WifiManager { } } - /** * Enable or disable Wi-Fi. * @param enabled {@code true} to enable, {@code false} to disable. diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java index dafa8e8..b6fcbd1 100644 --- a/wifi/java/android/net/wifi/WifiStateMachine.java +++ b/wifi/java/android/net/wifi/WifiStateMachine.java @@ -43,8 +43,7 @@ import android.content.IntentFilter; import android.content.pm.PackageManager; import android.database.ContentObserver; import android.net.ConnectivityManager; -import android.net.DhcpInfo; -import android.net.DhcpInfoInternal; +import android.net.DhcpResults; import android.net.DhcpStateMachine; import android.net.InterfaceConfiguration; import android.net.LinkAddress; @@ -87,6 +86,7 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.Iterator; import java.util.regex.Pattern; /** @@ -196,7 +196,8 @@ public class WifiStateMachine extends StateMachine { private Context mContext; - private DhcpInfoInternal mDhcpInfoInternal; + private final Object mDhcpResultsLock = new Object(); + private DhcpResults mDhcpResults; private WifiInfo mWifiInfo; private NetworkInfo mNetworkInfo; private SupplicantStateTracker mSupplicantStateTracker; @@ -585,7 +586,6 @@ public class WifiStateMachine extends StateMachine { mWifiNative = new WifiNative(mInterfaceName); mWifiConfigStore = new WifiConfigStore(context, mWifiNative); mWifiMonitor = new WifiMonitor(this, mWifiNative); - mDhcpInfoInternal = new DhcpInfoInternal(); mWifiInfo = new WifiInfo(); mSupplicantStateTracker = new SupplicantStateTracker(context, this, mWifiConfigStore, getHandler()); @@ -858,9 +858,9 @@ public class WifiStateMachine extends StateMachine { return mWifiInfo; } - public DhcpInfo syncGetDhcpInfo() { - synchronized (mDhcpInfoInternal) { - return mDhcpInfoInternal.makeDhcpInfo(); + public DhcpResults syncGetDhcpResults() { + synchronized (mDhcpResultsLock) { + return new DhcpResults(mDhcpResults); } } @@ -1169,7 +1169,7 @@ public class WifiStateMachine extends StateMachine { sb.append("current HSM state: ").append(getCurrentState().getName()).append(LS); sb.append("mLinkProperties ").append(mLinkProperties).append(LS); sb.append("mWifiInfo ").append(mWifiInfo).append(LS); - sb.append("mDhcpInfoInternal ").append(mDhcpInfoInternal).append(LS); + sb.append("mDhcpResults ").append(mDhcpResults).append(LS); sb.append("mNetworkInfo ").append(mNetworkInfo).append(LS); sb.append("mLastSignalLevel ").append(mLastSignalLevel).append(LS); sb.append("mLastBssid ").append(mLastBssid).append(LS); @@ -1607,16 +1607,15 @@ public class WifiStateMachine extends StateMachine { if (mWifiConfigStore.isUsingStaticIp(mLastNetworkId)) { mLinkProperties = mWifiConfigStore.getLinkProperties(mLastNetworkId); } else { - synchronized (mDhcpInfoInternal) { - mLinkProperties = mDhcpInfoInternal.makeLinkProperties(); + synchronized (mDhcpResultsLock) { + if ((mDhcpResults != null) && (mDhcpResults.linkProperties != null)) { + mLinkProperties = mDhcpResults.linkProperties; + } } mLinkProperties.setHttpProxy(mWifiConfigStore.getProxyProperties(mLastNetworkId)); } mLinkProperties.setInterfaceName(mInterfaceName); - if (DBG) { - log("netId=" + mLastNetworkId + " Link configured: " + - mLinkProperties.toString()); - } + if (DBG) log("netId=" + mLastNetworkId + " Link configured: " + mLinkProperties); } private int getMaxDhcpRetries() { @@ -1751,9 +1750,10 @@ public class WifiStateMachine extends StateMachine { /* Clear network properties */ mLinkProperties.clear(); + /* Clear IP settings if the network used DHCP */ if (!mWifiConfigStore.isUsingStaticIp(mLastNetworkId)) { - mWifiConfigStore.clearIpConfiguration(mLastNetworkId); + mWifiConfigStore.clearLinkProperties(mLastNetworkId); } mLastBssid= null; @@ -1802,21 +1802,21 @@ public class WifiStateMachine extends StateMachine { mWifiNative.BLUETOOTH_COEXISTENCE_MODE_SENSE); } - private void handleSuccessfulIpConfiguration(DhcpInfoInternal dhcpInfoInternal) { - synchronized (mDhcpInfoInternal) { - mDhcpInfoInternal = dhcpInfoInternal; - } + private void handleSuccessfulIpConfiguration(DhcpResults dhcpResults) { mLastSignalLevel = -1; // force update of signal strength mReconnectCount = 0; //Reset IP failure tracking - mWifiConfigStore.setIpConfiguration(mLastNetworkId, dhcpInfoInternal); - InetAddress addr = NetworkUtils.numericToInetAddress(dhcpInfoInternal.ipAddress); + LinkProperties linkProperties = dhcpResults.linkProperties; + mWifiConfigStore.setLinkProperties(mLastNetworkId, linkProperties); + InetAddress addr = null; + Iterator<InetAddress> addrs = linkProperties.getAddresses().iterator(); + if (addrs.hasNext()) { + addr = addrs.next(); + } mWifiInfo.setInetAddress(addr); - mWifiInfo.setMeteredHint(dhcpInfoInternal.hasMeteredHint()); + mWifiInfo.setMeteredHint(dhcpResults.hasMeteredHint()); if (getNetworkDetailedState() == DetailedState.CONNECTED) { //DHCP renewal in connected state - LinkProperties linkProperties = dhcpInfoInternal.makeLinkProperties(); linkProperties.setHttpProxy(mWifiConfigStore.getProxyProperties(mLastNetworkId)); - linkProperties.setInterfaceName(mInterfaceName); if (!linkProperties.equals(mLinkProperties)) { if (DBG) { log("Link configuration changed for netId: " + mLastNetworkId @@ -1826,6 +1826,7 @@ public class WifiStateMachine extends StateMachine { sendLinkConfigurationChangedBroadcast(); } } else { + mLinkProperties = linkProperties; configureLinkProperties(); } } @@ -3247,7 +3248,7 @@ public class WifiStateMachine extends StateMachine { handlePostDhcpSetup(); if (message.arg1 == DhcpStateMachine.DHCP_SUCCESS) { if (DBG) log("DHCP successful"); - handleSuccessfulIpConfiguration((DhcpInfoInternal) message.obj); + handleSuccessfulIpConfiguration((DhcpResults) message.obj); transitionTo(mVerifyingLinkState); } else if (message.arg1 == DhcpStateMachine.DHCP_FAILURE) { if (DBG) log("DHCP failed"); @@ -3375,21 +3376,29 @@ public class WifiStateMachine extends StateMachine { mDhcpStateMachine.registerForPreDhcpNotification(); mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_START_DHCP); } else { - DhcpInfoInternal dhcpInfoInternal = mWifiConfigStore.getIpConfiguration( - mLastNetworkId); + DhcpResults dhcpResults = new DhcpResults( + mWifiConfigStore.getLinkProperties(mLastNetworkId)); + dhcpResults.linkProperties.setInterfaceName(mInterfaceName); InterfaceConfiguration ifcg = new InterfaceConfiguration(); - ifcg.setLinkAddress(dhcpInfoInternal.makeLinkAddress()); - ifcg.setInterfaceUp(); - try { - mNwService.setInterfaceConfig(mInterfaceName, ifcg); - if (DBG) log("Static IP configuration succeeded"); - sendMessage(CMD_STATIC_IP_SUCCESS, dhcpInfoInternal); - } catch (RemoteException re) { - loge("Static IP configuration failed: " + re); - sendMessage(CMD_STATIC_IP_FAILURE); - } catch (IllegalStateException e) { - loge("Static IP configuration failed: " + e); + Iterator<LinkAddress> addrs = + dhcpResults.linkProperties.getLinkAddresses().iterator(); + if (!addrs.hasNext()) { + loge("Static IP lacks address"); sendMessage(CMD_STATIC_IP_FAILURE); + } else { + ifcg.setLinkAddress(addrs.next()); + ifcg.setInterfaceUp(); + try { + mNwService.setInterfaceConfig(mInterfaceName, ifcg); + if (DBG) log("Static IP configuration succeeded"); + sendMessage(CMD_STATIC_IP_SUCCESS, dhcpResults); + } catch (RemoteException re) { + loge("Static IP configuration failed: " + re); + sendMessage(CMD_STATIC_IP_FAILURE); + } catch (IllegalStateException e) { + loge("Static IP configuration failed: " + e); + sendMessage(CMD_STATIC_IP_FAILURE); + } } } } @@ -3398,7 +3407,7 @@ public class WifiStateMachine extends StateMachine { if (DBG) log(getName() + message.toString() + "\n"); switch(message.what) { case CMD_STATIC_IP_SUCCESS: - handleSuccessfulIpConfiguration((DhcpInfoInternal) message.obj); + handleSuccessfulIpConfiguration((DhcpResults) message.obj); transitionTo(mVerifyingLinkState); break; case CMD_STATIC_IP_FAILURE: diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pService.java b/wifi/java/android/net/wifi/p2p/WifiP2pService.java index 4a4320c..fdb21ad 100644 --- a/wifi/java/android/net/wifi/p2p/WifiP2pService.java +++ b/wifi/java/android/net/wifi/p2p/WifiP2pService.java @@ -34,7 +34,7 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.net.IConnectivityManager; import android.net.ConnectivityManager; -import android.net.DhcpInfoInternal; +import android.net.DhcpResults; import android.net.DhcpStateMachine; import android.net.InterfaceConfiguration; import android.net.LinkAddress; @@ -86,6 +86,7 @@ import com.android.internal.util.StateMachine; import java.io.FileDescriptor; import java.io.PrintWriter; +import java.net.InetAddress; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -1479,7 +1480,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub { //DHCP server has already been started if I am a group owner if (mGroup.isGroupOwner()) { - setWifiP2pInfoOnGroupFormation(SERVER_ADDRESS); + setWifiP2pInfoOnGroupFormation(NetworkUtils.numericToInetAddress(SERVER_ADDRESS)); } // In case of a negotiation group, connection changed is sent @@ -1543,11 +1544,11 @@ public class WifiP2pService extends IWifiP2pManager.Stub { } break; case DhcpStateMachine.CMD_POST_DHCP_ACTION: - DhcpInfoInternal dhcpInfo = (DhcpInfoInternal) message.obj; + DhcpResults dhcpResults = (DhcpResults) message.obj; if (message.arg1 == DhcpStateMachine.DHCP_SUCCESS && - dhcpInfo != null) { - if (DBG) logd("DhcpInfo: " + dhcpInfo); - setWifiP2pInfoOnGroupFormation(dhcpInfo.serverAddress); + dhcpResults != null) { + if (DBG) logd("DhcpResults: " + dhcpResults); + setWifiP2pInfoOnGroupFormation(dhcpResults.serverAddress); sendP2pConnectionChangedBroadcast(); //Turn on power save on client mWifiNative.setP2pPowerSave(mGroup.getInterface(), true); @@ -2221,10 +2222,10 @@ public class WifiP2pService extends IWifiP2pManager.Stub { return true; } - private void setWifiP2pInfoOnGroupFormation(String serverAddress) { + private void setWifiP2pInfoOnGroupFormation(InetAddress serverInetAddress) { mWifiP2pInfo.groupFormed = true; mWifiP2pInfo.isGroupOwner = mGroup.isGroupOwner(); - mWifiP2pInfo.groupOwnerAddress = NetworkUtils.numericToInetAddress(serverAddress); + mWifiP2pInfo.groupOwnerAddress = serverInetAddress; } private void resetWifiP2pInfo() { |