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 | |
parent | 36465c781519719a91d12bbe780db1180c06df57 (diff) | |
parent | 4717c261b2c670d5c0925e3527a864aa52db6ac0 (diff) | |
download | frameworks_base-321020b7e08215b813f15caaad1c59ac215831c6.zip frameworks_base-321020b7e08215b813f15caaad1c59ac215831c6.tar.gz frameworks_base-321020b7e08215b813f15caaad1c59ac215831c6.tar.bz2 |
Merge "Remove DhcpInfoInternal"
-rw-r--r-- | api/current.txt | 4 | ||||
-rw-r--r-- | core/java/android/bluetooth/BluetoothTetheringDataTracker.java | 1 | ||||
-rw-r--r-- | core/java/android/net/DhcpInfo.java | 5 | ||||
-rw-r--r-- | core/java/android/net/DhcpInfoInternal.java | 166 | ||||
-rw-r--r-- | core/java/android/net/DhcpResults.aidl | 19 | ||||
-rw-r--r-- | core/java/android/net/DhcpResults.java | 241 | ||||
-rw-r--r-- | core/java/android/net/DhcpStateMachine.java | 19 | ||||
-rw-r--r-- | core/java/android/net/EthernetDataTracker.java | 7 | ||||
-rw-r--r-- | core/java/android/net/LinkProperties.java | 13 | ||||
-rw-r--r-- | core/java/android/net/NetworkUtils.java | 13 | ||||
-rw-r--r-- | core/java/android/net/RouteInfo.java | 4 | ||||
-rw-r--r-- | core/jni/android_net_NetUtils.cpp | 123 | ||||
-rw-r--r-- | services/java/com/android/server/WifiService.java | 52 | ||||
-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 |
18 files changed, 480 insertions, 342 deletions
diff --git a/api/current.txt b/api/current.txt index 6164410..a54a0bc 100644 --- a/api/current.txt +++ b/api/current.txt @@ -12575,7 +12575,7 @@ package android.net { method public int getUid(); } - public class DhcpInfo implements android.os.Parcelable { + public deprecated class DhcpInfo implements android.os.Parcelable { ctor public DhcpInfo(); method public int describeContents(); method public void writeToParcel(android.os.Parcel, int); @@ -13442,7 +13442,7 @@ package android.net.wifi { method public boolean enableNetwork(int, boolean); method public java.util.List<android.net.wifi.WifiConfiguration> getConfiguredNetworks(); method public android.net.wifi.WifiInfo getConnectionInfo(); - method public android.net.DhcpInfo getDhcpInfo(); + method public deprecated android.net.DhcpInfo getDhcpInfo(); method public java.util.List<android.net.wifi.ScanResult> getScanResults(); method public int getWifiState(); method public boolean isWifiEnabled(); diff --git a/core/java/android/bluetooth/BluetoothTetheringDataTracker.java b/core/java/android/bluetooth/BluetoothTetheringDataTracker.java index 063e5a8..3ba4f26 100644 --- a/core/java/android/bluetooth/BluetoothTetheringDataTracker.java +++ b/core/java/android/bluetooth/BluetoothTetheringDataTracker.java @@ -21,7 +21,6 @@ import android.os.ServiceManager; import android.os.INetworkManagementService; import android.content.Context; import android.net.ConnectivityManager; -import android.net.DhcpInfoInternal; import android.net.LinkCapabilities; import android.net.LinkProperties; import android.net.NetworkInfo; diff --git a/core/java/android/net/DhcpInfo.java b/core/java/android/net/DhcpInfo.java index e2660e4..2b359eb 100644 --- a/core/java/android/net/DhcpInfo.java +++ b/core/java/android/net/DhcpInfo.java @@ -22,16 +22,17 @@ import java.net.InetAddress; /** * A simple object for retrieving the results of a DHCP request. + * @deprecated - use LinkProperties - To be removed 11/2013 + * STOPSHIP - make sure we expose LinkProperties through ConnectivityManager */ public class DhcpInfo implements Parcelable { public int ipAddress; public int gateway; public int netmask; - public int dns1; public int dns2; - public int serverAddress; + public int leaseDuration; public DhcpInfo() { diff --git a/core/java/android/net/DhcpInfoInternal.java b/core/java/android/net/DhcpInfoInternal.java deleted file mode 100644 index f3508c1..0000000 --- a/core/java/android/net/DhcpInfoInternal.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net; - -import android.text.TextUtils; -import android.util.Log; - -import java.net.Inet4Address; -import java.net.InetAddress; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; - -/** - * A simple object for retrieving the results of a DHCP request. - * Replaces (internally) the IPv4-only DhcpInfo class. - * @hide - */ -public class DhcpInfoInternal { - private final static String TAG = "DhcpInfoInternal"; - public String ipAddress; - public int prefixLength; - - public String dns1; - public String dns2; - - public String serverAddress; - public int leaseDuration; - - /** - * Vendor specific information (from RFC 2132). - */ - public String vendorInfo; - - private Collection<RouteInfo> mRoutes; - - public DhcpInfoInternal() { - mRoutes = new ArrayList<RouteInfo>(); - } - - public void addRoute(RouteInfo routeInfo) { - mRoutes.add(routeInfo); - } - - public Collection<RouteInfo> getRoutes() { - return Collections.unmodifiableCollection(mRoutes); - } - - private int convertToInt(String addr) { - if (addr != null) { - try { - InetAddress inetAddress = NetworkUtils.numericToInetAddress(addr); - if (inetAddress instanceof Inet4Address) { - return NetworkUtils.inetAddressToInt(inetAddress); - } - } catch (IllegalArgumentException e) {} - } - return 0; - } - - public DhcpInfo makeDhcpInfo() { - DhcpInfo info = new DhcpInfo(); - info.ipAddress = convertToInt(ipAddress); - for (RouteInfo route : mRoutes) { - if (route.isDefaultRoute()) { - info.gateway = convertToInt(route.getGateway().getHostAddress()); - break; - } - } - try { - InetAddress inetAddress = NetworkUtils.numericToInetAddress(ipAddress); - info.netmask = NetworkUtils.prefixLengthToNetmaskInt(prefixLength); - } catch (IllegalArgumentException e) {} - info.dns1 = convertToInt(dns1); - info.dns2 = convertToInt(dns2); - info.serverAddress = convertToInt(serverAddress); - info.leaseDuration = leaseDuration; - return info; - } - - public LinkAddress makeLinkAddress() { - if (TextUtils.isEmpty(ipAddress)) { - Log.e(TAG, "makeLinkAddress with empty ipAddress"); - return null; - } - return new LinkAddress(NetworkUtils.numericToInetAddress(ipAddress), prefixLength); - } - - public LinkProperties makeLinkProperties() { - LinkProperties p = new LinkProperties(); - p.addLinkAddress(makeLinkAddress()); - for (RouteInfo route : mRoutes) { - p.addRoute(route); - } - //if empty, connectivity configures default DNS - if (TextUtils.isEmpty(dns1) == false) { - p.addDns(NetworkUtils.numericToInetAddress(dns1)); - } else { - Log.d(TAG, "makeLinkProperties with empty dns1!"); - } - if (TextUtils.isEmpty(dns2) == false) { - p.addDns(NetworkUtils.numericToInetAddress(dns2)); - } else { - Log.d(TAG, "makeLinkProperties with empty dns2!"); - } - return p; - } - - /* Updates the DHCP fields that need to be retained from - * original DHCP request if the DHCP renewal shows them as - * being empty - */ - public void updateFromDhcpRequest(DhcpInfoInternal orig) { - if (orig == null) return; - - if (TextUtils.isEmpty(dns1)) { - dns1 = orig.dns1; - } - - if (TextUtils.isEmpty(dns2)) { - dns2 = orig.dns2; - } - - if (mRoutes.size() == 0) { - for (RouteInfo route : orig.getRoutes()) { - addRoute(route); - } - } - } - - /** - * Test if this DHCP lease includes vendor hint that network link is - * metered, and sensitive to heavy data transfers. - */ - public boolean hasMeteredHint() { - if (vendorInfo != null) { - return vendorInfo.contains("ANDROID_METERED"); - } else { - return false; - } - } - - public String toString() { - String routeString = ""; - for (RouteInfo route : mRoutes) routeString += route.toString() + " | "; - return "addr: " + ipAddress + "/" + prefixLength + - " mRoutes: " + routeString + - " dns: " + dns1 + "," + dns2 + - " dhcpServer: " + serverAddress + - " leaseDuration: " + leaseDuration; - } -} diff --git a/core/java/android/net/DhcpResults.aidl b/core/java/android/net/DhcpResults.aidl new file mode 100644 index 0000000..f4db3c3 --- /dev/null +++ b/core/java/android/net/DhcpResults.aidl @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2012, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net; + +parcelable DhcpResults; diff --git a/core/java/android/net/DhcpResults.java b/core/java/android/net/DhcpResults.java new file mode 100644 index 0000000..23297df --- /dev/null +++ b/core/java/android/net/DhcpResults.java @@ -0,0 +1,241 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net; + +import android.os.Parcelable; +import android.os.Parcel; +import android.util.Log; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; + +/** + * A simple object for retrieving the results of a DHCP request. + * Optimized (attempted) for that jni interface + * TODO - remove when DhcpInfo is deprecated. Move the remaining api to LinkProperties. + * @hide + */ +public class DhcpResults implements Parcelable { + private static final String TAG = "DhcpResults"; + + public final LinkProperties linkProperties; + + public InetAddress serverAddress; + + /** + * Vendor specific information (from RFC 2132). + */ + public String vendorInfo; + + public int leaseDuration; + + public DhcpResults() { + linkProperties = new LinkProperties(); + } + + /** copy constructor */ + public DhcpResults(DhcpResults source) { + if (source != null) { + linkProperties = new LinkProperties(source.linkProperties); + serverAddress = source.serverAddress; + leaseDuration = source.leaseDuration; + vendorInfo = source.vendorInfo; + } else { + linkProperties = new LinkProperties(); + } + } + + public DhcpResults(LinkProperties lp) { + linkProperties = new LinkProperties(lp); + } + + /** + * Updates the DHCP fields that need to be retained from + * original DHCP request if the current renewal shows them + * being empty. + */ + public void updateFromDhcpRequest(DhcpResults orig) { + if (orig == null || orig.linkProperties == null) return; + if (linkProperties.getRoutes().size() == 0) { + for (RouteInfo r : orig.linkProperties.getRoutes()) linkProperties.addRoute(r); + } + if (linkProperties.getDnses().size() == 0) { + for (InetAddress d : orig.linkProperties.getDnses()) linkProperties.addDns(d); + } + } + + /** + * Test if this DHCP lease includes vendor hint that network link is + * metered, and sensitive to heavy data transfers. + */ + public boolean hasMeteredHint() { + if (vendorInfo != null) { + return vendorInfo.contains("ANDROID_METERED"); + } else { + return false; + } + } + + public void clear() { + linkProperties.clear(); + serverAddress = null; + vendorInfo = null; + leaseDuration = 0; + } + + @Override + public String toString() { + StringBuffer str = new StringBuffer(linkProperties.toString()); + + str.append(" DHCP server ").append(serverAddress); + str.append(" Vendor info ").append(vendorInfo); + str.append(" lease ").append(leaseDuration).append(" seconds"); + + return str.toString(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + + if (!(obj instanceof DhcpResults)) return false; + + DhcpResults target = (DhcpResults)obj; + + if (linkProperties == null) { + if (target.linkProperties != null) return false; + } else if (!linkProperties.equals(target.linkProperties)) return false; + if (serverAddress == null) { + if (target.serverAddress != null) return false; + } else if (!serverAddress.equals(target.serverAddress)) return false; + if (vendorInfo == null) { + if (target.vendorInfo != null) return false; + } else if (!vendorInfo.equals(target.vendorInfo)) return false; + if (leaseDuration != target.leaseDuration) return false; + + return true; + } + + /** Implement the Parcelable interface */ + public int describeContents() { + return 0; + } + + /** Implement the Parcelable interface */ + public void writeToParcel(Parcel dest, int flags) { + linkProperties.writeToParcel(dest, flags); + + dest.writeInt(leaseDuration); + + if (serverAddress != null) { + dest.writeByte((byte)1); + dest.writeByteArray(serverAddress.getAddress()); + } else { + dest.writeByte((byte)0); + } + + dest.writeString(vendorInfo); + } + + /** Implement the Parcelable interface */ + public static final Creator<DhcpResults> CREATOR = + new Creator<DhcpResults>() { + public DhcpResults createFromParcel(Parcel in) { + DhcpResults prop = new DhcpResults((LinkProperties)in.readParcelable(null)); + + prop.leaseDuration = in.readInt(); + + if (in.readByte() == 1) { + try { + prop.serverAddress = InetAddress.getByAddress(in.createByteArray()); + } catch (UnknownHostException e) {} + } + + prop.vendorInfo = in.readString(); + + return prop; + } + + public DhcpResults[] newArray(int size) { + return new DhcpResults[size]; + } + }; + + // Utils for jni population - false on success + public void setInterfaceName(String interfaceName) { + linkProperties.setInterfaceName(interfaceName); + } + + public boolean addLinkAddress(String addrString, int prefixLength) { + InetAddress addr; + try { + addr = NetworkUtils.numericToInetAddress(addrString); + } catch (IllegalArgumentException e) { + Log.e(TAG, "addLinkAddress failed with addrString " + addrString); + return true; + } + + LinkAddress linkAddress = new LinkAddress(addr, prefixLength); + linkProperties.addLinkAddress(linkAddress); + + RouteInfo routeInfo = new RouteInfo(linkAddress); + linkProperties.addRoute(routeInfo); + return false; + } + + public boolean addGateway(String addrString) { + try { + linkProperties.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(addrString))); + } catch (IllegalArgumentException e) { + Log.e(TAG, "addGateway failed with addrString " + addrString); + return true; + } + return false; + } + + public boolean addDns(String addrString) { + try { + linkProperties.addDns(NetworkUtils.numericToInetAddress(addrString)); + } catch (IllegalArgumentException e) { + Log.e(TAG, "addDns failed with addrString " + addrString); + return true; + } + return false; + } + + public boolean setServerAddress(String addrString) { + try { + serverAddress = NetworkUtils.numericToInetAddress(addrString); + } catch (IllegalArgumentException e) { + Log.e(TAG, "setServerAddress failed with addrString " + addrString); + return true; + } + return false; + } + + public void setLeaseDuration(int duration) { + leaseDuration = duration; + } + + public void setVendorInfo(String info) { + vendorInfo = info; + } + +} diff --git a/core/java/android/net/DhcpStateMachine.java b/core/java/android/net/DhcpStateMachine.java index 8dc900e..fd22b10 100644 --- a/core/java/android/net/DhcpStateMachine.java +++ b/core/java/android/net/DhcpStateMachine.java @@ -26,7 +26,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.net.DhcpInfoInternal; +import android.net.DhcpResults; import android.net.NetworkUtils; import android.os.Message; import android.os.PowerManager; @@ -64,7 +64,7 @@ public class DhcpStateMachine extends StateMachine { private static final String WAKELOCK_TAG = "DHCP"; //Remember DHCP configuration from first request - private DhcpInfoInternal mDhcpInfo; + private DhcpResults mDhcpResults; private static final int DHCP_RENEW = 0; private static final String ACTION_DHCP_RENEW = "android.net.wifi.DHCP_RENEW"; @@ -348,23 +348,21 @@ public class DhcpStateMachine extends StateMachine { private boolean runDhcp(DhcpAction dhcpAction) { boolean success = false; - DhcpInfoInternal dhcpInfoInternal = new DhcpInfoInternal(); + DhcpResults dhcpResults = new DhcpResults(); if (dhcpAction == DhcpAction.START) { /* Stop any existing DHCP daemon before starting new */ NetworkUtils.stopDhcp(mInterfaceName); if (DBG) Log.d(TAG, "DHCP request on " + mInterfaceName); - success = NetworkUtils.runDhcp(mInterfaceName, dhcpInfoInternal); - mDhcpInfo = dhcpInfoInternal; + success = NetworkUtils.runDhcp(mInterfaceName, dhcpResults); } else if (dhcpAction == DhcpAction.RENEW) { if (DBG) Log.d(TAG, "DHCP renewal on " + mInterfaceName); - success = NetworkUtils.runDhcpRenew(mInterfaceName, dhcpInfoInternal); - dhcpInfoInternal.updateFromDhcpRequest(mDhcpInfo); + success = NetworkUtils.runDhcpRenew(mInterfaceName, dhcpResults); + dhcpResults.updateFromDhcpRequest(mDhcpResults); } - if (success) { if (DBG) Log.d(TAG, "DHCP succeeded on " + mInterfaceName); - long leaseDuration = dhcpInfoInternal.leaseDuration; //int to long conversion + long leaseDuration = dhcpResults.leaseDuration; //int to long conversion //Sanity check for renewal if (leaseDuration >= 0) { @@ -384,7 +382,8 @@ public class DhcpStateMachine extends StateMachine { //infinite lease time, no renewal needed } - mController.obtainMessage(CMD_POST_DHCP_ACTION, DHCP_SUCCESS, 0, dhcpInfoInternal) + mDhcpResults = dhcpResults; + mController.obtainMessage(CMD_POST_DHCP_ACTION, DHCP_SUCCESS, 0, dhcpResults) .sendToTarget(); } else { Log.e(TAG, "DHCP failed on " + mInterfaceName + ": " + diff --git a/core/java/android/net/EthernetDataTracker.java b/core/java/android/net/EthernetDataTracker.java index 3a06dc0..5b98b8f 100644 --- a/core/java/android/net/EthernetDataTracker.java +++ b/core/java/android/net/EthernetDataTracker.java @@ -170,13 +170,12 @@ public class EthernetDataTracker implements NetworkStateTracker { private void runDhcp() { Thread dhcpThread = new Thread(new Runnable() { public void run() { - DhcpInfoInternal dhcpInfoInternal = new DhcpInfoInternal(); - if (!NetworkUtils.runDhcp(mIface, dhcpInfoInternal)) { + DhcpResults dhcpResults = new DhcpResults(); + if (!NetworkUtils.runDhcp(mIface, dhcpResults)) { Log.e(TAG, "DHCP request error:" + NetworkUtils.getDhcpError()); return; } - mLinkProperties = dhcpInfoInternal.makeLinkProperties(); - mLinkProperties.setInterfaceName(mIface); + mLinkProperties = dhcpResults.linkProperties; mNetworkInfo.setDetailedState(DetailedState.CONNECTED, null, mHwAddr); Message msg = mCsHandler.obtainMessage(EVENT_STATE_CHANGED, mNetworkInfo); diff --git a/core/java/android/net/LinkProperties.java b/core/java/android/net/LinkProperties.java index 75646fd..60bf640 100644 --- a/core/java/android/net/LinkProperties.java +++ b/core/java/android/net/LinkProperties.java @@ -51,7 +51,7 @@ import java.util.Collections; */ public class LinkProperties implements Parcelable { - String mIfaceName; + private String mIfaceName; private Collection<LinkAddress> mLinkAddresses = new ArrayList<LinkAddress>(); private Collection<InetAddress> mDnses = new ArrayList<InetAddress>(); private Collection<RouteInfo> mRoutes = new ArrayList<RouteInfo>(); @@ -181,7 +181,7 @@ public class LinkProperties implements Parcelable { } /** - * Compares this {@code LinkProperties} interface name against the target + * Compares this {@code LinkProperties} interface addresses against the target * * @param target LinkProperties to compare. * @return {@code true} if both are identical, {@code false} otherwise. @@ -365,7 +365,6 @@ public class LinkProperties implements Parcelable { /** * Implement the Parcelable interface. - * @hide */ public void writeToParcel(Parcel dest, int flags) { dest.writeString(getInterfaceName()); @@ -394,19 +393,15 @@ public class LinkProperties implements Parcelable { /** * Implement the Parcelable interface. - * @hide */ public static final Creator<LinkProperties> CREATOR = new Creator<LinkProperties>() { public LinkProperties createFromParcel(Parcel in) { LinkProperties netProp = new LinkProperties(); + String iface = in.readString(); if (iface != null) { - try { - netProp.setInterfaceName(iface); - } catch (Exception e) { - return null; - } + netProp.setInterfaceName(iface); } int addressCount = in.readInt(); for (int i=0; i<addressCount; i++) { diff --git a/core/java/android/net/NetworkUtils.java b/core/java/android/net/NetworkUtils.java index d39e741..4ab479e 100644 --- a/core/java/android/net/NetworkUtils.java +++ b/core/java/android/net/NetworkUtils.java @@ -62,21 +62,21 @@ public class NetworkUtils { * addresses. This call blocks until it obtains a result (either success * or failure) from the daemon. * @param interfaceName the name of the interface to configure - * @param ipInfo if the request succeeds, this object is filled in with + * @param dhcpResults if the request succeeds, this object is filled in with * the IP address information. * @return {@code true} for success, {@code false} for failure */ - public native static boolean runDhcp(String interfaceName, DhcpInfoInternal ipInfo); + public native static boolean runDhcp(String interfaceName, DhcpResults dhcpResults); /** * Initiate renewal on the Dhcp client daemon. This call blocks until it obtains * a result (either success or failure) from the daemon. * @param interfaceName the name of the interface to configure - * @param ipInfo if the request succeeds, this object is filled in with + * @param dhcpResults if the request succeeds, this object is filled in with * the IP address information. * @return {@code true} for success, {@code false} for failure */ - public native static boolean runDhcpRenew(String interfaceName, DhcpInfoInternal ipInfo); + public native static boolean runDhcpRenew(String interfaceName, DhcpResults dhcpResults); /** * Shut down the DHCP client daemon. @@ -124,12 +124,9 @@ public class NetworkUtils { * @param inetAddr is an InetAddress corresponding to the IPv4 address * @return the IP address as an integer in network byte order */ - public static int inetAddressToInt(InetAddress inetAddr) + public static int inetAddressToInt(Inet4Address inetAddr) throws IllegalArgumentException { byte [] addr = inetAddr.getAddress(); - if (addr.length != 4) { - throw new IllegalArgumentException("Not an IPv4 address"); - } return ((addr[3] & 0xff) << 24) | ((addr[2] & 0xff) << 16) | ((addr[1] & 0xff) << 8) | (addr[0] & 0xff); } diff --git a/core/java/android/net/RouteInfo.java b/core/java/android/net/RouteInfo.java index 275f32a..112e143 100644 --- a/core/java/android/net/RouteInfo.java +++ b/core/java/android/net/RouteInfo.java @@ -76,6 +76,10 @@ public class RouteInfo implements Parcelable { this(null, gateway); } + public RouteInfo(LinkAddress host) { + this(host, null); + } + public static RouteInfo makeHostRoute(InetAddress host) { return makeHostRoute(host, null); } diff --git a/core/jni/android_net_NetUtils.cpp b/core/jni/android_net_NetUtils.cpp index 1f2b1ae..5bdaac6 100644 --- a/core/jni/android_net_NetUtils.cpp +++ b/core/jni/android_net_NetUtils.cpp @@ -63,15 +63,15 @@ namespace android { * to look them up every time. */ static struct fieldIds { - jmethodID constructorId; - jfieldID ipaddress; - jfieldID prefixLength; - jfieldID dns1; - jfieldID dns2; - jfieldID serverAddress; - jfieldID leaseDuration; - jfieldID vendorInfo; -} dhcpInfoInternalFieldIds; + jmethodID clear; + jmethodID setInterfaceName; + jmethodID addLinkAddress; + jmethodID addGateway; + jmethodID addDns; + jmethodID setServerAddress; + jmethodID setLeaseDuration; + jmethodID setVendorInfo; +} dhcpResultsFieldIds; static jint android_net_utils_enableInterface(JNIEnv* env, jobject clazz, jstring ifname) { @@ -109,7 +109,7 @@ static jint android_net_utils_resetConnections(JNIEnv* env, jobject clazz, } static jboolean android_net_utils_runDhcpCommon(JNIEnv* env, jobject clazz, jstring ifname, - jobject info, bool renew) + jobject dhcpResults, bool renew) { int result; char ipaddr[PROPERTY_VALUE_MAX]; @@ -134,42 +134,55 @@ static jboolean android_net_utils_runDhcpCommon(JNIEnv* env, jobject clazz, jstr env->ReleaseStringUTFChars(ifname, nameStr); if (result == 0) { - env->SetObjectField(info, dhcpInfoInternalFieldIds.ipaddress, env->NewStringUTF(ipaddr)); + env->CallVoidMethod(dhcpResults, dhcpResultsFieldIds.clear); + // set mIfaceName + // dhcpResults->setInterfaceName(ifname) + env->CallVoidMethod(dhcpResults, dhcpResultsFieldIds.setInterfaceName, ifname); + + // set the linkAddress + // dhcpResults->addLinkAddress(inetAddress, prefixLength) + result = env->CallBooleanMethod(dhcpResults, dhcpResultsFieldIds.addLinkAddress, + env->NewStringUTF(ipaddr), prefixLength); + } + + if (result == 0) { // set the gateway - jclass cls = env->FindClass("java/net/InetAddress"); - jmethodID method = env->GetStaticMethodID(cls, "getByName", - "(Ljava/lang/String;)Ljava/net/InetAddress;"); - jvalue args[1]; - args[0].l = env->NewStringUTF(gateway); - jobject inetAddressObject = env->CallStaticObjectMethodA(cls, method, args); - - if (!env->ExceptionOccurred()) { - cls = env->FindClass("android/net/RouteInfo"); - method = env->GetMethodID(cls, "<init>", "(Ljava/net/InetAddress;)V"); - args[0].l = inetAddressObject; - jobject routeInfoObject = env->NewObjectA(cls, method, args); - - cls = env->FindClass("android/net/DhcpInfoInternal"); - method = env->GetMethodID(cls, "addRoute", "(Landroid/net/RouteInfo;)V"); - args[0].l = routeInfoObject; - env->CallVoidMethodA(info, method, args); - } else { - // if we have an exception (host not found perhaps), just don't add the route - env->ExceptionClear(); - } - - env->SetIntField(info, dhcpInfoInternalFieldIds.prefixLength, prefixLength); - env->SetObjectField(info, dhcpInfoInternalFieldIds.dns1, env->NewStringUTF(dns1)); - env->SetObjectField(info, dhcpInfoInternalFieldIds.dns2, env->NewStringUTF(dns2)); - env->SetObjectField(info, dhcpInfoInternalFieldIds.serverAddress, + // dhcpResults->addGateway(gateway) + result = env->CallBooleanMethod(dhcpResults, + dhcpResultsFieldIds.addGateway, env->NewStringUTF(gateway)); + } + + if (result == 0) { + // dhcpResults->addDns(new InetAddress(dns1)) + result = env->CallBooleanMethod(dhcpResults, + dhcpResultsFieldIds.addDns, env->NewStringUTF(dns1)); + } + + if (result == 0) { + result = env->CallBooleanMethod(dhcpResults, + dhcpResultsFieldIds.addDns, env->NewStringUTF(dns2)); + } + + if (result == 0) { + // dhcpResults->setServerAddress(new InetAddress(server)) + result = env->CallBooleanMethod(dhcpResults, dhcpResultsFieldIds.setServerAddress, env->NewStringUTF(server)); - env->SetIntField(info, dhcpInfoInternalFieldIds.leaseDuration, lease); - env->SetObjectField(info, dhcpInfoInternalFieldIds.vendorInfo, env->NewStringUTF(vendorInfo)); + } + + if (result == 0) { + // dhcpResults->setLeaseDuration(lease) + env->CallVoidMethod(dhcpResults, + dhcpResultsFieldIds.setLeaseDuration, lease); + + // dhcpResults->setVendorInfo(vendorInfo) + env->CallVoidMethod(dhcpResults, dhcpResultsFieldIds.setVendorInfo, + env->NewStringUTF(vendorInfo)); } return (jboolean)(result == 0); } + static jboolean android_net_utils_runDhcp(JNIEnv* env, jobject clazz, jstring ifname, jobject info) { return android_net_utils_runDhcpCommon(env, clazz, ifname, info, false); @@ -217,8 +230,8 @@ static JNINativeMethod gNetworkUtilMethods[] = { { "enableInterface", "(Ljava/lang/String;)I", (void *)android_net_utils_enableInterface }, { "disableInterface", "(Ljava/lang/String;)I", (void *)android_net_utils_disableInterface }, { "resetConnections", "(Ljava/lang/String;I)I", (void *)android_net_utils_resetConnections }, - { "runDhcp", "(Ljava/lang/String;Landroid/net/DhcpInfoInternal;)Z", (void *)android_net_utils_runDhcp }, - { "runDhcpRenew", "(Ljava/lang/String;Landroid/net/DhcpInfoInternal;)Z", (void *)android_net_utils_runDhcpRenew }, + { "runDhcp", "(Ljava/lang/String;Landroid/net/DhcpResults;)Z", (void *)android_net_utils_runDhcp }, + { "runDhcpRenew", "(Ljava/lang/String;Landroid/net/DhcpResults;)Z", (void *)android_net_utils_runDhcpRenew }, { "stopDhcp", "(Ljava/lang/String;)Z", (void *)android_net_utils_stopDhcp }, { "releaseDhcpLease", "(Ljava/lang/String;)Z", (void *)android_net_utils_releaseDhcpLease }, { "getDhcpError", "()Ljava/lang/String;", (void*) android_net_utils_getDhcpError }, @@ -226,16 +239,24 @@ static JNINativeMethod gNetworkUtilMethods[] = { int register_android_net_NetworkUtils(JNIEnv* env) { - jclass dhcpInfoInternalClass = env->FindClass("android/net/DhcpInfoInternal"); - LOG_FATAL_IF(dhcpInfoInternalClass == NULL, "Unable to find class android/net/DhcpInfoInternal"); - dhcpInfoInternalFieldIds.constructorId = env->GetMethodID(dhcpInfoInternalClass, "<init>", "()V"); - dhcpInfoInternalFieldIds.ipaddress = env->GetFieldID(dhcpInfoInternalClass, "ipAddress", "Ljava/lang/String;"); - dhcpInfoInternalFieldIds.prefixLength = env->GetFieldID(dhcpInfoInternalClass, "prefixLength", "I"); - dhcpInfoInternalFieldIds.dns1 = env->GetFieldID(dhcpInfoInternalClass, "dns1", "Ljava/lang/String;"); - dhcpInfoInternalFieldIds.dns2 = env->GetFieldID(dhcpInfoInternalClass, "dns2", "Ljava/lang/String;"); - dhcpInfoInternalFieldIds.serverAddress = env->GetFieldID(dhcpInfoInternalClass, "serverAddress", "Ljava/lang/String;"); - dhcpInfoInternalFieldIds.leaseDuration = env->GetFieldID(dhcpInfoInternalClass, "leaseDuration", "I"); - dhcpInfoInternalFieldIds.vendorInfo = env->GetFieldID(dhcpInfoInternalClass, "vendorInfo", "Ljava/lang/String;"); + jclass dhcpResultsClass = env->FindClass("android/net/DhcpResults"); + LOG_FATAL_IF(dhcpResultsClass == NULL, "Unable to find class android/net/DhcpResults"); + dhcpResultsFieldIds.clear = + env->GetMethodID(dhcpResultsClass, "clear", "()V"); + dhcpResultsFieldIds.setInterfaceName = + env->GetMethodID(dhcpResultsClass, "setInterfaceName", "(Ljava/lang/String;)V"); + dhcpResultsFieldIds.addLinkAddress = + env->GetMethodID(dhcpResultsClass, "addLinkAddress", "(Ljava/lang/String;I)Z"); + dhcpResultsFieldIds.addGateway = + env->GetMethodID(dhcpResultsClass, "addGateway", "(Ljava/lang/String;)Z"); + dhcpResultsFieldIds.addDns = + env->GetMethodID(dhcpResultsClass, "addDns", "(Ljava/lang/String;)Z"); + dhcpResultsFieldIds.setServerAddress = + env->GetMethodID(dhcpResultsClass, "setServerAddress", "(Ljava/lang/String;)Z"); + dhcpResultsFieldIds.setLeaseDuration = + env->GetMethodID(dhcpResultsClass, "setLeaseDuration", "(I)V"); + dhcpResultsFieldIds.setVendorInfo = + env->GetMethodID(dhcpResultsClass, "setVendorInfo", "(Ljava/lang/String;)V"); return AndroidRuntime::registerNativeMethods(env, NETUTILS_PKG_NAME, gNetworkUtilMethods, NELEM(gNetworkUtilMethods)); diff --git a/services/java/com/android/server/WifiService.java b/services/java/com/android/server/WifiService.java index 98794c9..2da951e 100644 --- a/services/java/com/android/server/WifiService.java +++ b/services/java/com/android/server/WifiService.java @@ -43,9 +43,14 @@ import android.net.wifi.WpsInfo; import android.net.wifi.WpsResult; import android.net.ConnectivityManager; import android.net.DhcpInfo; +import android.net.DhcpResults; +import android.net.LinkAddress; +import android.net.LinkProperties; import android.net.NetworkInfo; import android.net.NetworkInfo.State; import android.net.NetworkInfo.DetailedState; +import android.net.NetworkUtils; +import android.net.RouteInfo; import android.net.TrafficStats; import android.os.Binder; import android.os.Handler; @@ -64,6 +69,8 @@ import android.text.TextUtils; import android.util.Log; import android.util.Slog; +import java.net.InetAddress; +import java.net.Inet4Address; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -923,10 +930,53 @@ public class WifiService extends IWifiManager.Stub { * Return the DHCP-assigned addresses from the last successful DHCP request, * if any. * @return the DHCP information + * @deprecated */ public DhcpInfo getDhcpInfo() { enforceAccessPermission(); - return mWifiStateMachine.syncGetDhcpInfo(); + DhcpResults dhcpResults = mWifiStateMachine.syncGetDhcpResults(); + if (dhcpResults.linkProperties == null) return null; + + DhcpInfo info = new DhcpInfo(); + for (LinkAddress la : dhcpResults.linkProperties.getLinkAddresses()) { + InetAddress addr = la.getAddress(); + if (addr instanceof Inet4Address) { + info.ipAddress = NetworkUtils.inetAddressToInt((Inet4Address)addr); + break; + } + } + for (RouteInfo r : dhcpResults.linkProperties.getRoutes()) { + if (r.isDefaultRoute()) { + InetAddress gateway = r.getGateway(); + if (gateway instanceof Inet4Address) { + info.gateway = NetworkUtils.inetAddressToInt((Inet4Address)gateway); + } + } else if (r.isHostRoute()) { + LinkAddress dest = r.getDestination(); + if (dest.getAddress() instanceof Inet4Address) { + info.netmask = NetworkUtils.prefixLengthToNetmaskInt( + dest.getNetworkPrefixLength()); + } + } + } + int dnsFound = 0; + for (InetAddress dns : dhcpResults.linkProperties.getDnses()) { + if (dns instanceof Inet4Address) { + if (dnsFound == 0) { + info.dns1 = NetworkUtils.inetAddressToInt((Inet4Address)dns); + } else { + info.dns2 = NetworkUtils.inetAddressToInt((Inet4Address)dns); + } + if (++dnsFound > 1) break; + } + } + InetAddress serverAddress = dhcpResults.serverAddress; + if (serverAddress instanceof Inet4Address) { + info.serverAddress = NetworkUtils.inetAddressToInt((Inet4Address)serverAddress); + } + info.leaseDuration = dhcpResults.leaseDuration; + + return info; } /** 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() { |