diff options
Diffstat (limited to 'wifi')
| -rw-r--r-- | wifi/java/android/net/wifi/WifiNative.java | 6 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/WifiStateTracker.java | 131 |
2 files changed, 113 insertions, 24 deletions
diff --git a/wifi/java/android/net/wifi/WifiNative.java b/wifi/java/android/net/wifi/WifiNative.java index e08f857..7a3282c 100644 --- a/wifi/java/android/net/wifi/WifiNative.java +++ b/wifi/java/android/net/wifi/WifiNative.java @@ -16,6 +16,8 @@ package android.net.wifi; +import android.net.DhcpInfo; + /** * Native calls for sending requests to the supplicant daemon, and for * receiving asynchronous events. All methods of the form "xxxxCommand()" @@ -143,6 +145,10 @@ public class WifiNative { public native static boolean clearBlacklistCommand(); + public native static boolean doDhcpRequest(DhcpInfo results); + + public native static String getDhcpError(); + /** * Wait for the supplicant to send an event, returning the event string. * @return the event string sent by the supplicant. diff --git a/wifi/java/android/net/wifi/WifiStateTracker.java b/wifi/java/android/net/wifi/WifiStateTracker.java index 99f3d06..5b4faf9 100644 --- a/wifi/java/android/net/wifi/WifiStateTracker.java +++ b/wifi/java/android/net/wifi/WifiStateTracker.java @@ -66,7 +66,7 @@ import java.util.concurrent.atomic.AtomicInteger; * * @hide */ -public class WifiStateTracker extends NetworkStateTracker { +public class WifiStateTracker extends Handler implements NetworkStateTracker { private static final boolean LOCAL_LOGD = Config.LOGD || false; @@ -197,6 +197,8 @@ public class WifiStateTracker extends NetworkStateTracker { private boolean mHaveIpAddress; private boolean mObtainingIpAddress; private boolean mTornDownByConnMgr; + private NetworkInfo mNetworkInfo; + private boolean mTeardownRequested = false; /** * A DISCONNECT event has been received, but processing it * is being deferred. @@ -314,7 +316,11 @@ public class WifiStateTracker extends NetworkStateTracker { private static String LS = System.getProperty("line.separator"); private static String[] sDnsPropNames; - private Runnable mReleaseWakeLockCallback; + private Handler mTarget; + private Context mContext; + private boolean mPrivateDnsRouteSet = false; + private int mDefaultGatewayAddr = 0; + private boolean mDefaultRouteSet = false; /** * A structure for supplying information about a supplicant state @@ -350,8 +356,9 @@ public class WifiStateTracker extends NetworkStateTracker { } public WifiStateTracker(Context context, Handler target) { - super(context, target, ConnectivityManager.TYPE_WIFI, 0, "WIFI", ""); - + mTarget = target; + mContext = context; + mNetworkInfo = new NetworkInfo(ConnectivityManager.TYPE_WIFI, 0, "WIFI", ""); mWifiInfo = new WifiInfo(); mWifiMonitor = new WifiMonitor(this); mHaveIpAddress = false; @@ -372,9 +379,9 @@ public class WifiStateTracker extends NetworkStateTracker { mSettingsObserver = new SettingsObserver(new Handler()); mInterfaceName = SystemProperties.get("wifi.interface", "tiwlan0"); - mDnsPropNames = new String[] { - "net." + mInterfaceName + ".dns1", - "net." + mInterfaceName + ".dns2" + sDnsPropNames = new String[] { + "dhcp." + mInterfaceName + ".dns1", + "dhcp." + mInterfaceName + ".dns2" }; mBatteryStats = IBatteryStats.Stub.asInterface(ServiceManager.getService("batteryinfo")); @@ -407,6 +414,57 @@ public class WifiStateTracker extends NetworkStateTracker { } /** + * Record the detailed state of a network, and if it is a + * change from the previous state, send a notification to + * any listeners. + * @param state the new @{code DetailedState} + */ + private void setDetailedState(NetworkInfo.DetailedState state) { + setDetailedState(state, null, null); + } + + /** + * Record the detailed state of a network, and if it is a + * change from the previous state, send a notification to + * any listeners. + * @param state the new @{code DetailedState} + * @param reason a {@code String} indicating a reason for the state change, + * if one was supplied. May be {@code null}. + * @param extraInfo optional {@code String} providing extra information about the state change + */ + private void setDetailedState(NetworkInfo.DetailedState state, String reason, String extraInfo) { + if (LOCAL_LOGD) Log.d(TAG, "setDetailed state, old =" + + mNetworkInfo.getDetailedState() + " and new state=" + state); + if (state != mNetworkInfo.getDetailedState()) { + boolean wasConnecting = (mNetworkInfo.getState() == NetworkInfo.State.CONNECTING); + String lastReason = mNetworkInfo.getReason(); + /* + * If a reason was supplied when the CONNECTING state was entered, and no + * reason was supplied for entering the CONNECTED state, then retain the + * reason that was supplied when going to CONNECTING. + */ + if (wasConnecting && state == NetworkInfo.DetailedState.CONNECTED && reason == null + && lastReason != null) + reason = lastReason; + mNetworkInfo.setDetailedState(state, reason, extraInfo); + Message msg = mTarget.obtainMessage(EVENT_STATE_CHANGED, mNetworkInfo); + msg.sendToTarget(); + } + } + + private void setDetailedStateInternal(NetworkInfo.DetailedState state) { + mNetworkInfo.setDetailedState(state, null, null); + } + + public void setTeardownRequested(boolean isRequested) { + mTeardownRequested = isRequested; + } + + public boolean isTeardownRequested() { + return mTeardownRequested; + } + + /** * Helper method: sets the boolean indicating that the connection * manager asked the network to be torn down (and so only the connection * manager can set it up again). @@ -419,6 +477,15 @@ public class WifiStateTracker extends NetworkStateTracker { } /** + * Return the IP addresses of the DNS servers available for the WLAN + * network interface. + * @return a list of DNS addresses, with no holes. + */ + public String[] getDnsPropNames() { + return sDnsPropNames; + } + + /** * Return the name of our WLAN network interface. * @return the name of our interface. */ @@ -426,6 +493,30 @@ public class WifiStateTracker extends NetworkStateTracker { return mInterfaceName; } + public boolean isPrivateDnsRouteSet() { + return mPrivateDnsRouteSet; + } + + public void privateDnsRouteSet(boolean enabled) { + mPrivateDnsRouteSet = enabled; + } + + public NetworkInfo getNetworkInfo() { + return mNetworkInfo; + } + + public int getDefaultGatewayAddr() { + return mDefaultGatewayAddr; + } + + public boolean isDefaultRouteSet() { + return mDefaultRouteSet; + } + + public void defaultRouteSet(boolean enabled) { + mDefaultRouteSet = enabled; + } + /** * Return the system properties name associated with the tcp buffer sizes * for this network. @@ -673,22 +764,6 @@ public class WifiStateTracker extends NetworkStateTracker { } /** - * We release the wakelock in WifiService - * using a timer. - * - * TODO: - * Releasing wakelock using both timer and - * a call from ConnectivityService requires - * a rethink. We had problems where WifiService - * could keep a wakelock forever if we delete - * messages in the asynchronous call - * from ConnectivityService - */ - @Override - public void releaseWakeLock() { - } - - /** * Tracks the WPA supplicant states to detect "loop" situations. * @param newSupplicantState The new WPA supplicant state. * @return {@code true} if the supplicant loop should be stopped @@ -2076,7 +2151,6 @@ public class WifiStateTracker extends NetworkStateTracker { return -1; } - @Override public void interpretScanResultsAvailable() { // If we shouldn't place a notification on available networks, then @@ -2122,6 +2196,15 @@ public class WifiStateTracker extends NetworkStateTracker { } /** + * Send a notification that the results of a scan for network access + * points has completed, and results are available. + */ + private void sendScanResultsAvailable() { + Message msg = mTarget.obtainMessage(EVENT_SCAN_RESULTS_AVAILABLE, mNetworkInfo); + msg.sendToTarget(); + } + + /** * Display or don't display a notification that there are open Wi-Fi networks. * @param visible {@code true} if notification should be visible, {@code false} otherwise * @param numNetworks the number networks seen |
