diff options
author | Nalla Kartheek <karthe@codeaurora.org> | 2015-07-28 19:03:41 +0530 |
---|---|---|
committer | Linux Build Service Account <lnxbuild@localhost> | 2015-10-06 03:21:06 -0600 |
commit | 87acb935056cc463c2531b8e1815fd95a94aafd5 (patch) | |
tree | 3d4bd5c266d712b45e0cb69845a6b570dbe4e125 | |
parent | b304df20e5d06f5f4c6b259d6ac761e79dc0999b (diff) | |
download | packages_apps_Settings-87acb935056cc463c2531b8e1815fd95a94aafd5.zip packages_apps_Settings-87acb935056cc463c2531b8e1815fd95a94aafd5.tar.gz packages_apps_Settings-87acb935056cc463c2531b8e1815fd95a94aafd5.tar.bz2 |
Wi-Fi: Fix for SoftAP turn ON/OFF fails issue.
Turnig ON/OFF SAP repeatedly when WIFI is ON results in to command
CMD_SET_AP being received in WifiStaEnabledState of the state machine,
which will not be handled and because of this SoftAP is not turned ON and we
receive no events thus the check box remains greyed out/disabled.
To resolve this wait for WIFI_STATE_CHANGED intent before
re-enabling the SAP.
Change-Id: Ifc330309c7919f2efc2916573353d0764b5e1f9e
-rw-r--r-- | src/com/android/settings/wifi/WifiApEnabler.java | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/src/com/android/settings/wifi/WifiApEnabler.java b/src/com/android/settings/wifi/WifiApEnabler.java index 741c4a7..92d605a 100644 --- a/src/com/android/settings/wifi/WifiApEnabler.java +++ b/src/com/android/settings/wifi/WifiApEnabler.java @@ -41,6 +41,8 @@ public class WifiApEnabler { ConnectivityManager mCm; private String[] mWifiRegexs; + /* Indicates if we have to wait for WIFI_STATE_CHANGED intent */ + private boolean mWaitForWifiStateChange = false; private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override @@ -56,6 +58,11 @@ public class WifiApEnabler { } else { handleWifiApStateChanged(state, WifiManager.SAP_START_FAILURE_GENERAL); } + } else if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) { + if (mWaitForWifiStateChange == true) { + handleWifiStateChanged(intent.getIntExtra( + WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN)); + } } else if (ConnectivityManager.ACTION_TETHER_STATE_CHANGED.equals(action)) { ArrayList<String> available = intent.getStringArrayListExtra( ConnectivityManager.EXTRA_AVAILABLE_TETHER); @@ -84,6 +91,7 @@ public class WifiApEnabler { mIntentFilter = new IntentFilter(WifiManager.WIFI_AP_STATE_CHANGED_ACTION); mIntentFilter.addAction(ConnectivityManager.ACTION_TETHER_STATE_CHANGED); mIntentFilter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED); + mIntentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); } public void resume() { @@ -107,6 +115,27 @@ public class WifiApEnabler { } public void setSoftapEnabled(boolean enable) { + int wifiSavedState = 0; + /** + * Check if we have to wait for the WIFI_STATE_CHANGED intent + * before we re-enable the Checkbox. + */ + if (!enable) { + try { + wifiSavedState = Settings.Global.getInt(mContext.getContentResolver(), + Settings.Global.WIFI_SAVED_STATE); + } catch (Settings.SettingNotFoundException e) { + ; + } + /** + * If Wi-Fi is turned of as part of SoftAp turn on process, + * we need to restore, Wi-Fi state after SoftAp turn Off. + * WIFI_SAVED_STATE inficates the state. + */ + if (wifiSavedState == 1) { + mWaitForWifiStateChange = true; + } + } if (TetherUtil.setWifiTethering(enable, mContext)) { /* Disable here, enabled on receiving success broadcast */ mSwitch.setEnabled(false); @@ -172,7 +201,9 @@ public class WifiApEnabler { case WifiManager.WIFI_AP_STATE_DISABLED: mSwitch.setChecked(false); mSwitch.setSummary(mOriginalSummary); - enableWifiSwitch(); + if (mWaitForWifiStateChange == false) { + enableWifiSwitch(); + } break; default: mSwitch.setChecked(false); @@ -184,4 +215,15 @@ public class WifiApEnabler { enableWifiSwitch(); } } + + private void handleWifiStateChanged(int state) { + switch (state) { + case WifiManager.WIFI_STATE_ENABLED: + case WifiManager.WIFI_STATE_UNKNOWN: + enableWifiSwitch(); + mWaitForWifiStateChange = false; + break; + default: + } + } } |