diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-02-20 07:38:31 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-02-20 07:38:31 -0800 |
commit | 15ab3eae2ec3d73b3e8aa60b33ae41445bf83f4b (patch) | |
tree | d03d027a7ed97af616904e02a7b420babf40d44f /wifi | |
parent | 3001a035439d8134a7d70d796376d1dfbff3cdcd (diff) | |
download | frameworks_base-15ab3eae2ec3d73b3e8aa60b33ae41445bf83f4b.zip frameworks_base-15ab3eae2ec3d73b3e8aa60b33ae41445bf83f4b.tar.gz frameworks_base-15ab3eae2ec3d73b3e8aa60b33ae41445bf83f4b.tar.bz2 |
auto import from //branches/cupcake/...@132569
Diffstat (limited to 'wifi')
-rw-r--r-- | wifi/java/android/net/wifi/WifiMonitor.java | 64 |
1 files changed, 25 insertions, 39 deletions
diff --git a/wifi/java/android/net/wifi/WifiMonitor.java b/wifi/java/android/net/wifi/WifiMonitor.java index 1799560..fc750e2 100644 --- a/wifi/java/android/net/wifi/WifiMonitor.java +++ b/wifi/java/android/net/wifi/WifiMonitor.java @@ -28,7 +28,7 @@ import java.util.regex.Matcher; * Listens for events from the wpa_supplicant server, and passes them on * to the {@link WifiStateTracker} for handling. Runs in its own thread. * - * {@hide} + * @hide */ public class WifiMonitor { @@ -119,14 +119,8 @@ public class WifiMonitor { private final WifiStateTracker mWifiStateTracker; - private boolean supplicantConnected; - - private boolean oneShot; - public WifiMonitor(WifiStateTracker tracker) { mWifiStateTracker = tracker; - supplicantConnected = false; - oneShot = true; } public void startMonitoring() { @@ -144,10 +138,17 @@ public class WifiMonitor { public void run() { + if (connectToSupplicant()) { + // Send a message indicating that it is now possible to send commands + // to the supplicant + mWifiStateTracker.notifySupplicantConnection(); + } else { + mWifiStateTracker.notifySupplicantLost(); + return; + } + //noinspection InfiniteLoopStatement for (;;) { - ensureSupplicantConnection(); - String eventStr = WifiNative.waitForEvent(); if (eventStr == null) { @@ -214,42 +215,32 @@ public class WifiMonitor { handleSupplicantStateChange(eventData); } else if (event == DRIVER_STATE) { handleDriverEvent(eventData); + } else if (event == TERMINATING) { + mWifiStateTracker.notifySupplicantLost(); + // If supplicant is gone, exit the thread + break; } else { handleEvent(event, eventData); - // If supplicant is gone, exit the thread - if (event == TERMINATING) { - break; - } } } } - private void ensureSupplicantConnection() { - while (!supplicantConnected) { - boolean connected; + private boolean connectToSupplicant() { + int connectTries = 0; + + while (true) { synchronized (mWifiStateTracker) { - connected = WifiNative.connectToSupplicant(); - } - if (!connected) { - /* - * If we fail to connect on the very first attempt, send a message - * indicating a lost connection to the supplicant, so that the - * receiver can initialize to the proper state. - */ - if (oneShot) { - oneShot = false; - mWifiStateTracker.notifySupplicantLost(); + if (WifiNative.connectToSupplicant()) { + return true; } + } + if (connectTries++ < 3) { nap(5); } else { - supplicantConnected = true; - oneShot = false; - // Send a message indicating that it is now possible to send commands - // to the supplicant - mWifiStateTracker.notifySupplicantConnection(); - + break; } } + return false; } private void handlePasswordKeyMayBeIncorrect() { @@ -287,11 +278,6 @@ public class WifiMonitor { mWifiStateTracker.notifyScanResultsAvailable(); break; - case TERMINATING: - supplicantConnected = false; - mWifiStateTracker.notifySupplicantLost(); - break; - case UNKNOWN: break; } @@ -370,7 +356,7 @@ public class WifiMonitor { private static void nap(int secs) { try { Thread.sleep(secs * 1000); - } catch (InterruptedException e) { + } catch (InterruptedException ignore) { } } } |