diff options
author | Jason Monk <jmonk@google.com> | 2015-02-11 13:30:41 -0500 |
---|---|---|
committer | Jason Monk <jmonk@google.com> | 2015-02-12 10:33:40 -0500 |
commit | 4896c01729df9f2e33d045e2d4ea3d843870ffb7 (patch) | |
tree | e90ed14394db9df11e1eaf32ad405aa341e8a1b3 /src/com/android/settings/wifi/WifiApEnabler.java | |
parent | b8331548d12f308a65b63bdafbc18b6e61a40ce0 (diff) | |
download | packages_apps_Settings-4896c01729df9f2e33d045e2d4ea3d843870ffb7.zip packages_apps_Settings-4896c01729df9f2e33d045e2d4ea3d843870ffb7.tar.gz packages_apps_Settings-4896c01729df9f2e33d045e2d4ea3d843870ffb7.tar.bz2 |
Move some Tethering code to SettingsLib to share
Change-Id: I43a356f2a14af4a15d1827919c39bbd1a04d3a94
Diffstat (limited to 'src/com/android/settings/wifi/WifiApEnabler.java')
-rw-r--r-- | src/com/android/settings/wifi/WifiApEnabler.java | 62 |
1 files changed, 11 insertions, 51 deletions
diff --git a/src/com/android/settings/wifi/WifiApEnabler.java b/src/com/android/settings/wifi/WifiApEnabler.java index 6aecf1f..bf2fa38 100644 --- a/src/com/android/settings/wifi/WifiApEnabler.java +++ b/src/com/android/settings/wifi/WifiApEnabler.java @@ -16,28 +16,20 @@ package com.android.settings.wifi; -import com.android.settings.R; -import com.android.settings.WirelessSettings; - -import java.util.ArrayList; - -import android.app.AlertDialog; import android.content.BroadcastReceiver; -import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.net.ConnectivityManager; -import android.net.NetworkInfo; -import android.net.wifi.SupplicantState; import android.net.wifi.WifiConfiguration; -import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.preference.SwitchPreference; import android.provider.Settings; -import android.text.TextUtils; -import android.util.Log; -import android.widget.Toast; + +import com.android.settings.R; +import com.android.settingslib.TetherUtil; + +import java.util.ArrayList; public class WifiApEnabler { private final Context mContext; @@ -74,10 +66,8 @@ public class WifiApEnabler { public WifiApEnabler(Context context, SwitchPreference switchPreference) { mContext = context; mSwitch = switchPreference; - mOriginalSummary = switchPreference != null ? switchPreference.getSummary() : ""; - if (switchPreference != null) { - switchPreference.setPersistent(false); - } + mOriginalSummary = switchPreference.getSummary(); + switchPreference.setPersistent(false); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); mCm = (ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE); @@ -110,43 +100,13 @@ public class WifiApEnabler { } public void setSoftapEnabled(boolean enable) { - final ContentResolver cr = mContext.getContentResolver(); - /** - * Disable Wifi if enabling tethering - */ - int wifiState = mWifiManager.getWifiState(); - if (enable && ((wifiState == WifiManager.WIFI_STATE_ENABLING) || - (wifiState == WifiManager.WIFI_STATE_ENABLED))) { - mWifiManager.setWifiEnabled(false); - Settings.Global.putInt(cr, Settings.Global.WIFI_SAVED_STATE, 1); - } - - if (mWifiManager.setWifiApEnabled(null, enable)) { - if (mSwitch != null) { - /* Disable here, enabled on receiving success broadcast */ - mSwitch.setEnabled(false); - } + if (TetherUtil.setWifiTethering(enable, mContext)) { + /* Disable here, enabled on receiving success broadcast */ + mSwitch.setEnabled(false); } else { - if (mSwitch != null) { - mSwitch.setSummary(R.string.wifi_error); - } + mSwitch.setSummary(R.string.wifi_error); } - /** - * If needed, restore Wifi on tether disable - */ - if (!enable) { - int wifiSavedState = 0; - try { - wifiSavedState = Settings.Global.getInt(cr, Settings.Global.WIFI_SAVED_STATE); - } catch (Settings.SettingNotFoundException e) { - ; - } - if (wifiSavedState == 1) { - mWifiManager.setWifiEnabled(true); - Settings.Global.putInt(cr, Settings.Global.WIFI_SAVED_STATE, 0); - } - } } public void updateConfigSummary(WifiConfiguration wifiConfig) { |