diff options
-rw-r--r-- | res/values/cm_arrays.xml | 15 | ||||
-rw-r--r-- | res/values/cm_strings.xml | 11 | ||||
-rw-r--r-- | res/xml/tether_prefs.xml | 26 | ||||
-rw-r--r-- | src/com/android/settings/TetherSettings.java | 54 |
4 files changed, 92 insertions, 14 deletions
diff --git a/res/values/cm_arrays.xml b/res/values/cm_arrays.xml index 7982fb1..e219da5 100644 --- a/res/values/cm_arrays.xml +++ b/res/values/cm_arrays.xml @@ -608,4 +608,19 @@ <item>2</item> </string-array> + <!-- Wi-Fi tethering inactivity shut off --> + <string-array name="hotstpot_inactivity_timeout_entries" translatable="false"> + <item>@string/hotstpot_inactivity_timeout_never</item> + <item>@string/hotstpot_inactivity_timeout_1_minute</item> + <item>@string/hotstpot_inactivity_timeout_5_minutes</item> + <item>@string/hotstpot_inactivity_timeout_10_minutes</item> + </string-array> + + <string-array name="hotstpot_inactivity_timeout_values" translatable="false"> + <item>0</item> + <item>60000</item> + <item>300000</item> + <item>600000</item> + </string-array> + </resources> diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml index 7bdb474..0ab1a9e 100644 --- a/res/values/cm_strings.xml +++ b/res/values/cm_strings.xml @@ -1116,4 +1116,15 @@ <string name="factory_reset_erase_sd_card_summary">Erase all data on the SD card, including music and photos</string> <string name="factory_reset_warning_text_reset_now">RESET NOW</string> <string name="factory_reset_warning_text_message">All your accounts, apps, app data, and system settings will be removed from this device. This cannot be reversed.</string> + + <!-- Tethering & portable hotspot other category --> + <string name="tethering_other_category_text">Other</string> + <!-- Wi-Fi tethering inactivity timeout --> + <string name="hotstpot_inactivity_timeout_text">Wi\u2011Fi hotspot timeout</string> + <string name="hotstpot_inactivity_timeout_never">Never</string> + <string name="hotstpot_inactivity_timeout_1_minute">1 minute</string> + <string name="hotstpot_inactivity_timeout_5_minutes">5 minutes</string> + <string name="hotstpot_inactivity_timeout_10_minutes">10 minutes</string> + <string name="hotstpot_inactivity_timeout_never_summary_text">Portable Wi\u2011Fi hotspot timeout never</string> + <string name="hotstpot_inactivity_timeout_summary_text">Portable Wi\u2011Fi hotspot timeout after <xliff:g id="timeout">%1$s</xliff:g></string> </resources> diff --git a/res/xml/tether_prefs.xml b/res/xml/tether_prefs.xml index 2f67dc4..5c5c080 100644 --- a/res/xml/tether_prefs.xml +++ b/res/xml/tether_prefs.xml @@ -26,14 +26,26 @@ android:title="@string/wifi_tether_configure_ap_text" android:persistent="false" /> - <SwitchPreference - android:key="usb_tether_settings" - android:title="@string/usb_tethering_button_text" + <ListPreference + android:key="hotstpot_inactivity_timeout" + android:title="@string/hotstpot_inactivity_timeout_text" + android:entries="@array/hotstpot_inactivity_timeout_entries" + android:entryValues="@array/hotstpot_inactivity_timeout_values" android:persistent="false" /> - <SwitchPreference - android:key="enable_bluetooth_tethering" - android:title="@string/bluetooth_tether_checkbox_text" - android:persistent="false" /> + <PreferenceCategory + android:title="@string/tethering_other_category_text"> + + <SwitchPreference + android:key="usb_tether_settings" + android:title="@string/usb_tethering_button_text" + android:persistent="false" /> + + <SwitchPreference + android:key="enable_bluetooth_tethering" + android:title="@string/bluetooth_tether_checkbox_text" + android:persistent="false" /> + + </PreferenceCategory> </PreferenceScreen> 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; } |