Loading res/values/arrays.xml +16 −0 Original line number Original line Diff line number Diff line Loading @@ -235,6 +235,22 @@ <item>@string/wifi_security_psk_generic</item> <item>@string/wifi_security_psk_generic</item> </string-array> </string-array> <!-- Security types for wireless tether --> <string-array name="wifi_tether_security"> <!-- Do not translate. --> <item>@string/wifi_security_wpa2</item> <!-- Do not translate. --> <item>@string/wifi_security_none</item> </string-array> <!-- Values for security type for wireless tether --> <string-array name="wifi_tether_security_values"> <!-- Do not translate. --> <item>4</item> <!-- Do not translate. --> <item>0</item> </string-array> <!-- Match this with the constants in WifiDialog. --> <skip /> <!-- Match this with the constants in WifiDialog. --> <skip /> <!-- Wi-Fi settings. The type of EAP method a Wi-Fi network has. --> <!-- Wi-Fi settings. The type of EAP method a Wi-Fi network has. --> <string-array name="wifi_eap_method"> <string-array name="wifi_eap_method"> Loading res/xml/wifi_tether_settings.xml +10 −3 Original line number Original line Diff line number Diff line Loading @@ -19,13 +19,20 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:settings="http://schemas.android.com/apk/res-auto" xmlns:settings="http://schemas.android.com/apk/res-auto" android:title="@string/wifi_hotspot_checkbox_text" android:title="@string/wifi_hotspot_checkbox_text" settings:initialExpandedChildrenCount="2"> settings:initialExpandedChildrenCount="3"> <com.android.settings.widget.ValidatedEditTextPreference <com.android.settings.widget.ValidatedEditTextPreference android:key="wifi_tether_network_name" android:key="wifi_tether_network_name" android:title="@string/wifi_hotspot_name_title" android:title="@string/wifi_hotspot_name_title" android:summary="@string/summary_placeholder" /> android:summary="@string/summary_placeholder" /> <ListPreference android:key="wifi_tether_security" android:title="@string/wifi_security" android:summary="@string/summary_placeholder" android:entries="@array/wifi_tether_security" android:entryValues="@array/wifi_tether_security_values" /> <com.android.settings.widget.ValidatedEditTextPreference <com.android.settings.widget.ValidatedEditTextPreference android:key="wifi_tether_network_password" android:key="wifi_tether_network_password" android:persistent="false" android:persistent="false" Loading src/com/android/settings/wifi/WifiUtils.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -52,7 +52,7 @@ public class WifiUtils { public static boolean isHotspotPasswordValid(String password) { public static boolean isHotspotPasswordValid(String password) { if (TextUtils.isEmpty(password)) { if (TextUtils.isEmpty(password)) { return true; return false; } } final int length = password.length(); final int length = password.length(); Loading src/com/android/settings/wifi/tether/WifiTetherPasswordPreferenceController.java +24 −12 Original line number Original line Diff line number Diff line Loading @@ -31,7 +31,6 @@ import java.util.UUID; public class WifiTetherPasswordPreferenceController extends WifiTetherBasePreferenceController public class WifiTetherPasswordPreferenceController extends WifiTetherBasePreferenceController implements ValidatedEditTextPreference.Validator { implements ValidatedEditTextPreference.Validator { private static final String TAG = "WifiTetherPswdPref"; private static final String PREF_KEY = "wifi_tether_network_password"; private static final String PREF_KEY = "wifi_tether_network_password"; private String mPassword; private String mPassword; Loading @@ -49,10 +48,11 @@ public class WifiTetherPasswordPreferenceController extends WifiTetherBasePrefer @Override @Override public void updateDisplay() { public void updateDisplay() { final WifiConfiguration config = mWifiManager.getWifiApConfiguration(); final WifiConfiguration config = mWifiManager.getWifiApConfiguration(); if (config != null) { if (config == null || (config.getAuthType() == WifiConfiguration.KeyMgmt.WPA2_PSK mPassword = config.preSharedKey; && TextUtils.isEmpty(config.preSharedKey))) { } else { mPassword = generateRandomPassword(); mPassword = generateRandomPassword(); } else { mPassword = config.preSharedKey; } } ((ValidatedEditTextPreference) mPreference).setValidator(this); ((ValidatedEditTextPreference) mPreference).setValidator(this); ((ValidatedEditTextPreference) mPreference).setIsPassword(true); ((ValidatedEditTextPreference) mPreference).setIsPassword(true); Loading @@ -68,17 +68,27 @@ public class WifiTetherPasswordPreferenceController extends WifiTetherBasePrefer return true; return true; } } public String getPassword() { /** * This method returns the current password if it is valid for the indicated security type. If * the password currently set is invalid it will forcefully set a random password that is valid. * * @param securityType The security type for the password. * @return The current password if it is valid for the indicated security type. A new randomly * generated password if it is not. */ public String getPasswordValidated(int securityType) { // don't actually overwrite unless we get a new config in case it was accidentally toggled. if (securityType == WifiConfiguration.KeyMgmt.NONE) { return ""; } else if (!isTextValid(mPassword)) { mPassword = generateRandomPassword(); updatePasswordDisplay((EditTextPreference) mPreference); } return mPassword; return mPassword; } } public int getSecuritySettingForPassword() { public void updateVisibility(int securityType) { // We should return NONE when no password is set mPreference.setVisible(securityType != WifiConfiguration.KeyMgmt.NONE); if (TextUtils.isEmpty(mPassword)) { return WifiConfiguration.KeyMgmt.NONE; } // Only other currently supported type is WPA2 so we'll try that return WifiConfiguration.KeyMgmt.WPA2_PSK; } } @Override @Override Loading @@ -98,9 +108,11 @@ public class WifiTetherPasswordPreferenceController extends WifiTetherBasePrefer if (!TextUtils.isEmpty(mPassword)) { if (!TextUtils.isEmpty(mPassword)) { pref.setIsSummaryPassword(true); pref.setIsSummaryPassword(true); pref.setSummary(mPassword); pref.setSummary(mPassword); pref.setVisible(true); } else { } else { pref.setIsSummaryPassword(false); pref.setIsSummaryPassword(false); pref.setSummary(R.string.wifi_hotspot_no_password_subtext); pref.setSummary(R.string.wifi_hotspot_no_password_subtext); pref.setVisible(false); } } } } } } src/com/android/settings/wifi/tether/WifiTetherSecurityPreferenceController.java 0 → 100644 +63 −0 Original line number Original line Diff line number Diff line package com.android.settings.wifi.tether; import android.content.Context; import android.content.res.Resources; import android.net.wifi.WifiConfiguration; import android.support.v7.preference.ListPreference; import android.support.v7.preference.Preference; import com.android.settings.R; public class WifiTetherSecurityPreferenceController extends WifiTetherBasePreferenceController { private static final String PREF_KEY = "wifi_tether_security"; private final String[] mSecurityEntries; private int mSecurityValue; public WifiTetherSecurityPreferenceController(Context context, OnTetherConfigUpdateListener listener) { super(context, listener); mSecurityEntries = mContext.getResources().getStringArray(R.array.wifi_tether_security); } @Override public String getPreferenceKey() { return PREF_KEY; } @Override public void updateDisplay() { final WifiConfiguration config = mWifiManager.getWifiApConfiguration(); if (config != null && config.getAuthType() == WifiConfiguration.KeyMgmt.NONE) { mSecurityValue = WifiConfiguration.KeyMgmt.NONE; } else { mSecurityValue = WifiConfiguration.KeyMgmt.WPA2_PSK; } final ListPreference preference = (ListPreference) mPreference; preference.setSummary(getSummaryForSecurityType(mSecurityValue)); preference.setValue(String.valueOf(mSecurityValue)); } @Override public boolean onPreferenceChange(Preference preference, Object newValue) { mSecurityValue = Integer.parseInt((String) newValue); preference.setSummary(getSummaryForSecurityType(mSecurityValue)); mListener.onTetherConfigUpdated(); return true; } public int getSecurityType() { return mSecurityValue; } private String getSummaryForSecurityType(int securityType) { if (securityType == WifiConfiguration.KeyMgmt.NONE) { return mSecurityEntries[1]; } // WPA2 PSK return mSecurityEntries[0]; } } Loading
res/values/arrays.xml +16 −0 Original line number Original line Diff line number Diff line Loading @@ -235,6 +235,22 @@ <item>@string/wifi_security_psk_generic</item> <item>@string/wifi_security_psk_generic</item> </string-array> </string-array> <!-- Security types for wireless tether --> <string-array name="wifi_tether_security"> <!-- Do not translate. --> <item>@string/wifi_security_wpa2</item> <!-- Do not translate. --> <item>@string/wifi_security_none</item> </string-array> <!-- Values for security type for wireless tether --> <string-array name="wifi_tether_security_values"> <!-- Do not translate. --> <item>4</item> <!-- Do not translate. --> <item>0</item> </string-array> <!-- Match this with the constants in WifiDialog. --> <skip /> <!-- Match this with the constants in WifiDialog. --> <skip /> <!-- Wi-Fi settings. The type of EAP method a Wi-Fi network has. --> <!-- Wi-Fi settings. The type of EAP method a Wi-Fi network has. --> <string-array name="wifi_eap_method"> <string-array name="wifi_eap_method"> Loading
res/xml/wifi_tether_settings.xml +10 −3 Original line number Original line Diff line number Diff line Loading @@ -19,13 +19,20 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:settings="http://schemas.android.com/apk/res-auto" xmlns:settings="http://schemas.android.com/apk/res-auto" android:title="@string/wifi_hotspot_checkbox_text" android:title="@string/wifi_hotspot_checkbox_text" settings:initialExpandedChildrenCount="2"> settings:initialExpandedChildrenCount="3"> <com.android.settings.widget.ValidatedEditTextPreference <com.android.settings.widget.ValidatedEditTextPreference android:key="wifi_tether_network_name" android:key="wifi_tether_network_name" android:title="@string/wifi_hotspot_name_title" android:title="@string/wifi_hotspot_name_title" android:summary="@string/summary_placeholder" /> android:summary="@string/summary_placeholder" /> <ListPreference android:key="wifi_tether_security" android:title="@string/wifi_security" android:summary="@string/summary_placeholder" android:entries="@array/wifi_tether_security" android:entryValues="@array/wifi_tether_security_values" /> <com.android.settings.widget.ValidatedEditTextPreference <com.android.settings.widget.ValidatedEditTextPreference android:key="wifi_tether_network_password" android:key="wifi_tether_network_password" android:persistent="false" android:persistent="false" Loading
src/com/android/settings/wifi/WifiUtils.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -52,7 +52,7 @@ public class WifiUtils { public static boolean isHotspotPasswordValid(String password) { public static boolean isHotspotPasswordValid(String password) { if (TextUtils.isEmpty(password)) { if (TextUtils.isEmpty(password)) { return true; return false; } } final int length = password.length(); final int length = password.length(); Loading
src/com/android/settings/wifi/tether/WifiTetherPasswordPreferenceController.java +24 −12 Original line number Original line Diff line number Diff line Loading @@ -31,7 +31,6 @@ import java.util.UUID; public class WifiTetherPasswordPreferenceController extends WifiTetherBasePreferenceController public class WifiTetherPasswordPreferenceController extends WifiTetherBasePreferenceController implements ValidatedEditTextPreference.Validator { implements ValidatedEditTextPreference.Validator { private static final String TAG = "WifiTetherPswdPref"; private static final String PREF_KEY = "wifi_tether_network_password"; private static final String PREF_KEY = "wifi_tether_network_password"; private String mPassword; private String mPassword; Loading @@ -49,10 +48,11 @@ public class WifiTetherPasswordPreferenceController extends WifiTetherBasePrefer @Override @Override public void updateDisplay() { public void updateDisplay() { final WifiConfiguration config = mWifiManager.getWifiApConfiguration(); final WifiConfiguration config = mWifiManager.getWifiApConfiguration(); if (config != null) { if (config == null || (config.getAuthType() == WifiConfiguration.KeyMgmt.WPA2_PSK mPassword = config.preSharedKey; && TextUtils.isEmpty(config.preSharedKey))) { } else { mPassword = generateRandomPassword(); mPassword = generateRandomPassword(); } else { mPassword = config.preSharedKey; } } ((ValidatedEditTextPreference) mPreference).setValidator(this); ((ValidatedEditTextPreference) mPreference).setValidator(this); ((ValidatedEditTextPreference) mPreference).setIsPassword(true); ((ValidatedEditTextPreference) mPreference).setIsPassword(true); Loading @@ -68,17 +68,27 @@ public class WifiTetherPasswordPreferenceController extends WifiTetherBasePrefer return true; return true; } } public String getPassword() { /** * This method returns the current password if it is valid for the indicated security type. If * the password currently set is invalid it will forcefully set a random password that is valid. * * @param securityType The security type for the password. * @return The current password if it is valid for the indicated security type. A new randomly * generated password if it is not. */ public String getPasswordValidated(int securityType) { // don't actually overwrite unless we get a new config in case it was accidentally toggled. if (securityType == WifiConfiguration.KeyMgmt.NONE) { return ""; } else if (!isTextValid(mPassword)) { mPassword = generateRandomPassword(); updatePasswordDisplay((EditTextPreference) mPreference); } return mPassword; return mPassword; } } public int getSecuritySettingForPassword() { public void updateVisibility(int securityType) { // We should return NONE when no password is set mPreference.setVisible(securityType != WifiConfiguration.KeyMgmt.NONE); if (TextUtils.isEmpty(mPassword)) { return WifiConfiguration.KeyMgmt.NONE; } // Only other currently supported type is WPA2 so we'll try that return WifiConfiguration.KeyMgmt.WPA2_PSK; } } @Override @Override Loading @@ -98,9 +108,11 @@ public class WifiTetherPasswordPreferenceController extends WifiTetherBasePrefer if (!TextUtils.isEmpty(mPassword)) { if (!TextUtils.isEmpty(mPassword)) { pref.setIsSummaryPassword(true); pref.setIsSummaryPassword(true); pref.setSummary(mPassword); pref.setSummary(mPassword); pref.setVisible(true); } else { } else { pref.setIsSummaryPassword(false); pref.setIsSummaryPassword(false); pref.setSummary(R.string.wifi_hotspot_no_password_subtext); pref.setSummary(R.string.wifi_hotspot_no_password_subtext); pref.setVisible(false); } } } } } }
src/com/android/settings/wifi/tether/WifiTetherSecurityPreferenceController.java 0 → 100644 +63 −0 Original line number Original line Diff line number Diff line package com.android.settings.wifi.tether; import android.content.Context; import android.content.res.Resources; import android.net.wifi.WifiConfiguration; import android.support.v7.preference.ListPreference; import android.support.v7.preference.Preference; import com.android.settings.R; public class WifiTetherSecurityPreferenceController extends WifiTetherBasePreferenceController { private static final String PREF_KEY = "wifi_tether_security"; private final String[] mSecurityEntries; private int mSecurityValue; public WifiTetherSecurityPreferenceController(Context context, OnTetherConfigUpdateListener listener) { super(context, listener); mSecurityEntries = mContext.getResources().getStringArray(R.array.wifi_tether_security); } @Override public String getPreferenceKey() { return PREF_KEY; } @Override public void updateDisplay() { final WifiConfiguration config = mWifiManager.getWifiApConfiguration(); if (config != null && config.getAuthType() == WifiConfiguration.KeyMgmt.NONE) { mSecurityValue = WifiConfiguration.KeyMgmt.NONE; } else { mSecurityValue = WifiConfiguration.KeyMgmt.WPA2_PSK; } final ListPreference preference = (ListPreference) mPreference; preference.setSummary(getSummaryForSecurityType(mSecurityValue)); preference.setValue(String.valueOf(mSecurityValue)); } @Override public boolean onPreferenceChange(Preference preference, Object newValue) { mSecurityValue = Integer.parseInt((String) newValue); preference.setSummary(getSummaryForSecurityType(mSecurityValue)); mListener.onTetherConfigUpdated(); return true; } public int getSecurityType() { return mSecurityValue; } private String getSummaryForSecurityType(int securityType) { if (securityType == WifiConfiguration.KeyMgmt.NONE) { return mSecurityEntries[1]; } // WPA2 PSK return mSecurityEntries[0]; } }