Remember Wifi state prior to tethering
We now remember whether Wifi was enabled prior to enabling tethering. This will allow us to restore Wifi when tethering is disabled. Bug: 2537983 Change-Id: Ia530563bd5647856d62cd59b67ae5156de6fd5d9
This commit is contained in:
@@ -23,6 +23,7 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
@@ -95,24 +96,44 @@ public class WifiApEnabler implements Preference.OnPreferenceChangeListener {
|
|||||||
mCheckBox.setOnPreferenceChangeListener(null);
|
mCheckBox.setOnPreferenceChangeListener(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onPreferenceChange(Preference preference, Object enable) {
|
public boolean onPreferenceChange(Preference preference, Object value) {
|
||||||
|
|
||||||
|
final ContentResolver cr = mContext.getContentResolver();
|
||||||
|
boolean enable = (Boolean)value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disable Wifi if enabling tethering
|
* Disable Wifi if enabling tethering
|
||||||
*/
|
*/
|
||||||
int wifiState = mWifiManager.getWifiState();
|
int wifiState = mWifiManager.getWifiState();
|
||||||
if ((Boolean)enable && ((wifiState == WifiManager.WIFI_STATE_ENABLING) ||
|
if (enable && ((wifiState == WifiManager.WIFI_STATE_ENABLING) ||
|
||||||
(wifiState == WifiManager.WIFI_STATE_ENABLED))) {
|
(wifiState == WifiManager.WIFI_STATE_ENABLED))) {
|
||||||
mWifiManager.setWifiEnabled(false);
|
mWifiManager.setWifiEnabled(false);
|
||||||
|
Settings.Secure.putInt(cr, Settings.Secure.WIFI_SAVED_STATE, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mWifiManager.setWifiApEnabled(null, (Boolean)enable)) {
|
if (mWifiManager.setWifiApEnabled(null, enable)) {
|
||||||
/* Disable here, enabled on receiving success broadcast */
|
/* Disable here, enabled on receiving success broadcast */
|
||||||
mCheckBox.setEnabled(false);
|
mCheckBox.setEnabled(false);
|
||||||
} else {
|
} else {
|
||||||
mCheckBox.setSummary(R.string.wifi_error);
|
mCheckBox.setSummary(R.string.wifi_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If needed, restore Wifi on tether disable
|
||||||
|
*/
|
||||||
|
if (!enable) {
|
||||||
|
int wifiSavedState = 0;
|
||||||
|
try {
|
||||||
|
wifiSavedState = Settings.Secure.getInt(cr, Settings.Secure.WIFI_SAVED_STATE);
|
||||||
|
} catch (Settings.SettingNotFoundException e) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
if (wifiSavedState == 1) {
|
||||||
|
mWifiManager.setWifiEnabled(true);
|
||||||
|
Settings.Secure.putInt(cr, Settings.Secure.WIFI_SAVED_STATE, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user