diff options
author | d34d <clark@cyngn.com> | 2016-01-29 11:55:48 -0800 |
---|---|---|
committer | Gerrit Code Review <gerrit@cyanogenmod.org> | 2016-02-02 08:30:51 -0800 |
commit | d8eeaa93cc2a7767246e53d9df8a94e258f3bfbb (patch) | |
tree | ae3b78cba5979749a95771f0188c40a8f52b2a98 /src/com/android/settings/TetherSettings.java | |
parent | a6032a59de6438c5ff27cd21ca877527fd3ceb49 (diff) | |
download | packages_apps_Settings-d8eeaa93cc2a7767246e53d9df8a94e258f3bfbb.zip packages_apps_Settings-d8eeaa93cc2a7767246e53d9df8a94e258f3bfbb.tar.gz packages_apps_Settings-d8eeaa93cc2a7767246e53d9df8a94e258f3bfbb.tar.bz2 |
Tethering: Turn off Wi-Fi Hotspot after inactivity (3/3)
Turn off the Wi-Fi hotspot after a specified time of inactivity.
The hotspot is considered to be inactive when no clients are
connected to it.
Change-Id: I7030e702328726b72f394b2a64b93830dba54efc
Diffstat (limited to 'src/com/android/settings/TetherSettings.java')
-rw-r--r-- | src/com/android/settings/TetherSettings.java | 54 |
1 files changed, 47 insertions, 7 deletions
diff --git a/src/com/android/settings/TetherSettings.java b/src/com/android/settings/TetherSettings.java index a0cd4da..92ad580 100644 --- a/src/com/android/settings/TetherSettings.java +++ b/src/com/android/settings/TetherSettings.java @@ -40,6 +40,7 @@ import android.os.Bundle; import android.os.Environment; import android.os.UserHandle; import android.os.UserManager; +import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceScreen; import android.preference.SwitchPreference; @@ -64,6 +65,7 @@ public class TetherSettings extends SettingsPreferenceFragment private static final String ENABLE_WIFI_AP = "enable_wifi_ap"; private static final String ENABLE_BLUETOOTH_TETHERING = "enable_bluetooth_tethering"; private static final String TETHER_CHOICE = "TETHER_TYPE"; + private static final String HOTSPOT_TIMEOUT = "hotstpot_inactivity_timeout"; private static final int DIALOG_AP_SETTINGS = 1; @@ -74,6 +76,8 @@ public class TetherSettings extends SettingsPreferenceFragment private SwitchPreference mBluetoothTether; + private ListPreference mHotspotInactivityTimeout; + private BroadcastReceiver mTetherChangeReceiver; private String[] mUsbRegexs; @@ -143,6 +147,7 @@ public class TetherSettings extends SettingsPreferenceFragment Preference wifiApSettings = findPreference(WIFI_AP_SSID_AND_SECURITY); mUsbTether = (SwitchPreference) findPreference(USB_TETHER_SETTINGS); mBluetoothTether = (SwitchPreference) findPreference(ENABLE_BLUETOOTH_TETHERING); + mHotspotInactivityTimeout = (ListPreference) findPreference(HOTSPOT_TIMEOUT); ConnectivityManager cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); @@ -180,6 +185,7 @@ public class TetherSettings extends SettingsPreferenceFragment mProvisionApp = getResources().getStringArray( com.android.internal.R.array.config_mobile_hotspot_provision_app); + mHotspotInactivityTimeout.setOnPreferenceChangeListener(this); } @Override @@ -207,6 +213,25 @@ public class TetherSettings extends SettingsPreferenceFragment mWifiConfig.SSID, mSecurityType[index])); } + updateHotspotTimeoutSummary(mWifiConfig); + } + + private void updateHotspotTimeoutSummary(WifiConfiguration wifiConfig) { + if (wifiConfig == null) { + mHotspotInactivityTimeout.setValue("0"); + mHotspotInactivityTimeout.setSummary( + getString(R.string.hotstpot_inactivity_timeout_never_summary_text)); + } else { + mHotspotInactivityTimeout.setValue(Long.toString(wifiConfig.wifiApInactivityTimeout)); + if (wifiConfig.wifiApInactivityTimeout > 0) { + mHotspotInactivityTimeout.setSummary(String.format( + getString(R.string.hotstpot_inactivity_timeout_summary_text, + mHotspotInactivityTimeout.getEntry()))); + } else { + mHotspotInactivityTimeout.setSummary( + getString(R.string.hotstpot_inactivity_timeout_never_summary_text)); + } + } } private BluetoothProfile.ServiceListener mProfileServiceListener = @@ -458,15 +483,30 @@ public class TetherSettings extends SettingsPreferenceFragment } public boolean onPreferenceChange(Preference preference, Object value) { - boolean enable = (Boolean) value; + if (preference == mEnableWifiAp) { + boolean enable = (Boolean) value; - if (enable) { - startProvisioningIfNecessary(TETHERING_WIFI); - } else { - if (TetherUtil.isProvisioningNeeded(getActivity())) { - TetherService.cancelRecheckAlarmIfNecessary(getActivity(), TETHERING_WIFI); + if (enable) { + startProvisioningIfNecessary(TETHERING_WIFI); + } else { + if (TetherUtil.isProvisioningNeeded(getActivity())) { + TetherService.cancelRecheckAlarmIfNecessary(getActivity(), TETHERING_WIFI); + } + mWifiApEnabler.setSoftapEnabled(false); + } + return false; + } else if (preference == mHotspotInactivityTimeout) { + if (mWifiConfig != null) { + mWifiConfig.wifiApInactivityTimeout = Long.parseLong((String) value); + updateHotspotTimeoutSummary(mWifiConfig); + if (mWifiManager.getWifiApState() == WifiManager.WIFI_AP_STATE_ENABLED) { + mWifiManager.setWifiApEnabled(null, false); + mWifiManager.setWifiApEnabled(mWifiConfig, true); + } else { + mWifiManager.setWifiApConfiguration(mWifiConfig); + } + return true; } - mWifiApEnabler.setSoftapEnabled(false); } return false; } |