diff options
Diffstat (limited to 'src/com/android/settings/wifi')
-rw-r--r-- | src/com/android/settings/wifi/AccessPoint.java | 43 | ||||
-rw-r--r-- | src/com/android/settings/wifi/AdvancedWifiSettings.java | 107 | ||||
-rw-r--r-- | src/com/android/settings/wifi/SavedAccessPointsWifiSettings.java | 29 | ||||
-rw-r--r-- | src/com/android/settings/wifi/WifiApEnabler.java | 56 | ||||
-rw-r--r-- | src/com/android/settings/wifi/WifiConfigController.java | 110 | ||||
-rw-r--r-- | src/com/android/settings/wifi/WifiSettings.java | 190 | ||||
-rw-r--r-- | src/com/android/settings/wifi/WifiSettingsForSetupWizard.java | 53 | ||||
-rw-r--r-- | src/com/android/settings/wifi/WifiSetupActivity.java | 1 | ||||
-rw-r--r-- | src/com/android/settings/wifi/WpsDialog.java | 12 |
9 files changed, 348 insertions, 253 deletions
diff --git a/src/com/android/settings/wifi/AccessPoint.java b/src/com/android/settings/wifi/AccessPoint.java index b3fafa4..ac818a7 100644 --- a/src/com/android/settings/wifi/AccessPoint.java +++ b/src/com/android/settings/wifi/AccessPoint.java @@ -20,6 +20,7 @@ import com.android.settings.R; import android.content.Context; import android.graphics.drawable.Drawable; +import android.graphics.drawable.StateListDrawable; import android.net.NetworkInfo.DetailedState; import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; @@ -266,14 +267,21 @@ class AccessPoint extends Preference { Drawable drawable = getIcon(); if (drawable == null) { - drawable = context.getTheme().obtainStyledAttributes( - wifi_signal_attributes).getDrawable(0); - setIcon(drawable); + // To avoid a drawing race condition, we first set the state (SECURE/NONE) and then + // set the icon (drawable) to that state's drawable. + StateListDrawable sld = (StateListDrawable) context.getTheme() + .obtainStyledAttributes(wifi_signal_attributes).getDrawable(0); + // If sld is null then we are indexing and therefore do not have access to + // (nor need to display) the drawable. + if (sld != null) { + sld.setState((security != SECURITY_NONE) ? STATE_SECURED : STATE_NONE); + drawable = sld.getCurrent(); + setIcon(drawable); + } } if (drawable != null) { drawable.setLevel(level); - drawable.setState((security != SECURITY_NONE) ? STATE_SECURED : STATE_NONE); } } } @@ -452,7 +460,7 @@ class AccessPoint extends Preference { if (result.seen == 0) continue; - if (result.status != ScanResult.ENABLED) + if (result.autoJoinStatus != ScanResult.ENABLED) numBlackListed++; if (result.frequency > LOWER_FREQ_5GHZ @@ -520,6 +528,10 @@ class AccessPoint extends Preference { final Context context = getContext(); updateIcon(getLevel(), context); + // Force new summary + setSummary(null); + + // Update to new summary StringBuilder summary = new StringBuilder(); if (mState != null) { // This is the active connection @@ -550,21 +562,6 @@ class AccessPoint extends Preference { if (mConfig != null) { // Is saved network summary.append(context.getString(R.string.wifi_remembered)); } - - if (security != SECURITY_NONE) { - String securityStrFormat; - if (summary.length() == 0) { - securityStrFormat = context.getString(R.string.wifi_secured_first_item); - } else { - securityStrFormat = context.getString(R.string.wifi_secured_second_item); - } - } - - } - - // This is a workaround, see bug report... - if (summary.length() < 1) { - summary.append(" "); } if (WifiSettings.mVerboseLogging > 0) { @@ -591,7 +588,11 @@ class AccessPoint extends Preference { } } - setSummary(summary.toString()); + if (summary.length() > 0) { + setSummary(summary.toString()); + } else { + showSummary = false; + } } /** diff --git a/src/com/android/settings/wifi/AdvancedWifiSettings.java b/src/com/android/settings/wifi/AdvancedWifiSettings.java index b7316d0..dfb86cc 100644 --- a/src/com/android/settings/wifi/AdvancedWifiSettings.java +++ b/src/com/android/settings/wifi/AdvancedWifiSettings.java @@ -20,6 +20,9 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.net.NetworkScoreManager; +import android.net.NetworkScorerAppManager; +import android.net.NetworkScorerAppManager.NetworkScorerAppData; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.net.wifi.WpsInfo; @@ -29,6 +32,7 @@ import android.preference.ListPreference; import android.preference.Preference; import android.preference.Preference.OnPreferenceClickListener; import android.preference.PreferenceScreen; +import android.preference.SwitchPreference; import android.provider.Settings; import android.provider.Settings.Global; import android.security.Credentials; @@ -40,6 +44,8 @@ import com.android.settings.R; import com.android.settings.SettingsPreferenceFragment; import com.android.settings.Utils; +import java.util.Collection; + public class AdvancedWifiSettings extends SettingsPreferenceFragment implements Preference.OnPreferenceChangeListener { @@ -49,15 +55,15 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment private static final String KEY_FREQUENCY_BAND = "frequency_band"; private static final String KEY_NOTIFY_OPEN_NETWORKS = "notify_open_networks"; private static final String KEY_SLEEP_POLICY = "sleep_policy"; - private static final String KEY_POOR_NETWORK_DETECTION = "wifi_poor_network_detection"; private static final String KEY_SCAN_ALWAYS_AVAILABLE = "wifi_scan_always_available"; private static final String KEY_INSTALL_CREDENTIALS = "install_credentials"; + private static final String KEY_WIFI_ASSISTANT = "wifi_assistant"; private static final String KEY_WIFI_DIRECT = "wifi_direct"; private static final String KEY_WPS_PUSH = "wps_push_button"; private static final String KEY_WPS_PIN = "wps_pin_entry"; - private static final String KEY_SUSPEND_OPTIMIZATIONS = "suspend_optimizations"; private WifiManager mWifiManager; + private NetworkScoreManager mNetworkScoreManager; private IntentFilter mFilter; private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @@ -84,6 +90,8 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment mFilter = new IntentFilter(); mFilter.addAction(WifiManager.LINK_CONFIGURATION_CHANGED_ACTION); mFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); + mNetworkScoreManager = + (NetworkScoreManager) getSystemService(Context.NETWORK_SCORE_SERVICE); } @Override @@ -102,27 +110,14 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment } private void initPreferences() { - CheckBoxPreference notifyOpenNetworks = - (CheckBoxPreference) findPreference(KEY_NOTIFY_OPEN_NETWORKS); + SwitchPreference notifyOpenNetworks = + (SwitchPreference) findPreference(KEY_NOTIFY_OPEN_NETWORKS); notifyOpenNetworks.setChecked(Settings.Global.getInt(getContentResolver(), Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 0) == 1); notifyOpenNetworks.setEnabled(mWifiManager.isWifiEnabled()); - CheckBoxPreference poorNetworkDetection = - (CheckBoxPreference) findPreference(KEY_POOR_NETWORK_DETECTION); - if (poorNetworkDetection != null) { - if (Utils.isWifiOnly(getActivity())) { - getPreferenceScreen().removePreference(poorNetworkDetection); - } else { - poorNetworkDetection.setChecked(Global.getInt(getContentResolver(), - Global.WIFI_WATCHDOG_POOR_NETWORK_TEST_ENABLED, - WifiManager.DEFAULT_POOR_NETWORK_AVOIDANCE_ENABLED ? - 1 : 0) == 1); - } - } - - CheckBoxPreference scanAlwaysAvailable = - (CheckBoxPreference) findPreference(KEY_SCAN_ALWAYS_AVAILABLE); + SwitchPreference scanAlwaysAvailable = + (SwitchPreference) findPreference(KEY_SCAN_ALWAYS_AVAILABLE); scanAlwaysAvailable.setChecked(Global.getInt(getContentResolver(), Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1); @@ -133,7 +128,22 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment Preference pref = findPreference(KEY_INSTALL_CREDENTIALS); pref.setIntent(intent); - Intent wifiDirectIntent = new Intent(getActivity(), + final Context context = getActivity(); + NetworkScorerAppData scorer = WifiSettings.getWifiAssistantApp(context); + SwitchPreference wifiAssistant = (SwitchPreference)findPreference(KEY_WIFI_ASSISTANT); + if (scorer != null) { + final boolean checked = NetworkScorerAppManager.getActiveScorer(context) != null; + wifiAssistant.setSummary(getResources().getString( + R.string.wifi_automatically_manage_summary, scorer.mScorerName)); + wifiAssistant.setOnPreferenceChangeListener(this); + wifiAssistant.setChecked(checked); + } else { + if (wifiAssistant != null) { + getPreferenceScreen().removePreference(wifiAssistant); + } + } + + Intent wifiDirectIntent = new Intent(context, com.android.settings.Settings.WifiP2pSettingsActivity.class); Preference wifiDirectPref = findPreference(KEY_WIFI_DIRECT); wifiDirectPref.setIntent(wifiDirectIntent); @@ -142,7 +152,7 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment Preference wpsPushPref = findPreference(KEY_WPS_PUSH); wpsPushPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference arg0) { - WpsDialog wpsDialog = new WpsDialog(getActivity(), WpsInfo.PBC); + WpsDialog wpsDialog = new WpsDialog(context, WpsInfo.PBC); wpsDialog.show(); return true; } @@ -152,17 +162,12 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment Preference wpsPinPref = findPreference(KEY_WPS_PIN); wpsPinPref.setOnPreferenceClickListener(new OnPreferenceClickListener(){ public boolean onPreferenceClick(Preference arg0) { - WpsDialog wpsDialog = new WpsDialog(getActivity(), WpsInfo.DISPLAY); + WpsDialog wpsDialog = new WpsDialog(context, WpsInfo.DISPLAY); wpsDialog.show(); return true; } }); - CheckBoxPreference suspendOptimizations = - (CheckBoxPreference) findPreference(KEY_SUSPEND_OPTIMIZATIONS); - suspendOptimizations.setChecked(Global.getInt(getContentResolver(), - Global.WIFI_SUSPEND_OPTIMIZATIONS_ENABLED, 1) == 1); - ListPreference frequencyPref = (ListPreference) findPreference(KEY_FREQUENCY_BAND); if (mWifiManager.isDualBandSupported()) { @@ -183,7 +188,7 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment ListPreference sleepPolicyPref = (ListPreference) findPreference(KEY_SLEEP_POLICY); if (sleepPolicyPref != null) { - if (Utils.isWifiOnly(getActivity())) { + if (Utils.isWifiOnly(context)) { sleepPolicyPref.setEntries(R.array.wifi_sleep_policy_entries_wifi_only); } sleepPolicyPref.setOnPreferenceChangeListener(this); @@ -228,19 +233,11 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment if (KEY_NOTIFY_OPEN_NETWORKS.equals(key)) { Global.putInt(getContentResolver(), Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, - ((CheckBoxPreference) preference).isChecked() ? 1 : 0); - } else if (KEY_POOR_NETWORK_DETECTION.equals(key)) { - Global.putInt(getContentResolver(), - Global.WIFI_WATCHDOG_POOR_NETWORK_TEST_ENABLED, - ((CheckBoxPreference) preference).isChecked() ? 1 : 0); - } else if (KEY_SUSPEND_OPTIMIZATIONS.equals(key)) { - Global.putInt(getContentResolver(), - Global.WIFI_SUSPEND_OPTIMIZATIONS_ENABLED, - ((CheckBoxPreference) preference).isChecked() ? 1 : 0); + ((SwitchPreference) preference).isChecked() ? 1 : 0); } else if (KEY_SCAN_ALWAYS_AVAILABLE.equals(key)) { Global.putInt(getContentResolver(), Global.WIFI_SCAN_ALWAYS_AVAILABLE, - ((CheckBoxPreference) preference).isChecked() ? 1 : 0); + ((SwitchPreference) preference).isChecked() ? 1 : 0); } else { return super.onPreferenceTreeClick(screen, preference); } @@ -249,6 +246,7 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment @Override public boolean onPreferenceChange(Preference preference, Object newValue) { + final Context context = getActivity(); String key = preference.getKey(); if (KEY_FREQUENCY_BAND.equals(key)) { @@ -257,10 +255,32 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment mWifiManager.setFrequencyBand(value, true); updateFrequencyBandSummary(preference, value); } catch (NumberFormatException e) { - Toast.makeText(getActivity(), R.string.wifi_setting_frequency_band_error, + Toast.makeText(context, R.string.wifi_setting_frequency_band_error, Toast.LENGTH_SHORT).show(); return false; } + } else if (KEY_WIFI_ASSISTANT.equals(key)) { + if (((Boolean)newValue).booleanValue() == false) { + mNetworkScoreManager.setActiveScorer(null); + return true; + } + + NetworkScorerAppData wifiAssistant = WifiSettings.getWifiAssistantApp(context); + Intent intent = new Intent(); + if (wifiAssistant.mConfigurationActivityClassName != null) { + // App has a custom configuration activity; launch that. + // This custom activity will be responsible for launching the system + // dialog. + intent.setClassName(wifiAssistant.mPackageName, + wifiAssistant.mConfigurationActivityClassName); + } else { + // Fall back on the system dialog. + intent.setAction(NetworkScoreManager.ACTION_CHANGE_ACTIVE); + intent.putExtra(NetworkScoreManager.EXTRA_PACKAGE_NAME, + wifiAssistant.mPackageName); + } + + startActivity(intent); } if (KEY_SLEEP_POLICY.equals(key)) { @@ -270,7 +290,7 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment Integer.parseInt(stringValue)); updateSleepPolicySummary(preference, stringValue); } catch (NumberFormatException e) { - Toast.makeText(getActivity(), R.string.wifi_setting_sleep_policy_error, + Toast.makeText(context, R.string.wifi_setting_sleep_policy_error, Toast.LENGTH_SHORT).show(); return false; } @@ -280,18 +300,19 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment } private void refreshWifiInfo() { + final Context context = getActivity(); WifiInfo wifiInfo = mWifiManager.getConnectionInfo(); Preference wifiMacAddressPref = findPreference(KEY_MAC_ADDRESS); String macAddress = wifiInfo == null ? null : wifiInfo.getMacAddress(); wifiMacAddressPref.setSummary(!TextUtils.isEmpty(macAddress) ? macAddress - : getActivity().getString(R.string.status_unavailable)); + : context.getString(R.string.status_unavailable)); wifiMacAddressPref.setSelectable(false); Preference wifiIpAddressPref = findPreference(KEY_CURRENT_IP_ADDRESS); - String ipAddress = Utils.getWifiIpAddresses(getActivity()); + String ipAddress = Utils.getWifiIpAddresses(context); wifiIpAddressPref.setSummary(ipAddress == null ? - getActivity().getString(R.string.status_unavailable) : ipAddress); + context.getString(R.string.status_unavailable) : ipAddress); wifiIpAddressPref.setSelectable(false); } diff --git a/src/com/android/settings/wifi/SavedAccessPointsWifiSettings.java b/src/com/android/settings/wifi/SavedAccessPointsWifiSettings.java index a91d153..10c86dc 100644 --- a/src/com/android/settings/wifi/SavedAccessPointsWifiSettings.java +++ b/src/com/android/settings/wifi/SavedAccessPointsWifiSettings.java @@ -53,6 +53,9 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment private Bundle mAccessPointSavedState; private AccessPoint mSelectedAccessPoint; + // Instance state key + private static final String SAVE_DIALOG_ACCESS_POINT_STATE = "wifi_ap_state"; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -69,6 +72,13 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); + + if (savedInstanceState != null) { + if (savedInstanceState.containsKey(SAVE_DIALOG_ACCESS_POINT_STATE)) { + mAccessPointSavedState = + savedInstanceState.getBundle(SAVE_DIALOG_ACCESS_POINT_STATE); + } + } } private void initPreferences() { @@ -150,6 +160,11 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment public Dialog onCreateDialog(int dialogId) { switch (dialogId) { case WifiSettings.WIFI_DIALOG_ID: + if (mDlgAccessPoint == null) { // For re-launch from saved state + mDlgAccessPoint = new AccessPoint(getActivity(), mAccessPointSavedState); + // Reset the saved access point data + mAccessPointSavedState = null; + } mSelectedAccessPoint = mDlgAccessPoint; mDialog = new WifiDialog(getActivity(), this, mDlgAccessPoint, false); return mDialog; @@ -159,6 +174,20 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment } @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + + // If the dialog is showing, save its state. + if (mDialog != null && mDialog.isShowing()) { + if (mDlgAccessPoint != null) { + mAccessPointSavedState = new Bundle(); + mDlgAccessPoint.saveWifiState(mAccessPointSavedState); + outState.putBundle(SAVE_DIALOG_ACCESS_POINT_STATE, mAccessPointSavedState); + } + } + } + + @Override public void onClick(DialogInterface dialogInterface, int button) { if (button == WifiDialog.BUTTON_FORGET && mSelectedAccessPoint != null) { mWifiManager.forget(mSelectedAccessPoint.networkId, null); diff --git a/src/com/android/settings/wifi/WifiApEnabler.java b/src/com/android/settings/wifi/WifiApEnabler.java index 9a3b49d..fc34f3b 100644 --- a/src/com/android/settings/wifi/WifiApEnabler.java +++ b/src/com/android/settings/wifi/WifiApEnabler.java @@ -33,7 +33,7 @@ import android.net.wifi.SupplicantState; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; -import android.preference.CheckBoxPreference; +import android.preference.SwitchPreference; import android.provider.Settings; import android.text.TextUtils; import android.util.Log; @@ -41,7 +41,7 @@ import android.widget.Toast; public class WifiApEnabler { private final Context mContext; - private final CheckBoxPreference mCheckBox; + private final SwitchPreference mSwitch; private final CharSequence mOriginalSummary; private WifiManager mWifiManager; @@ -66,17 +66,17 @@ public class WifiApEnabler { ConnectivityManager.EXTRA_ERRORED_TETHER); updateTetherState(available.toArray(), active.toArray(), errored.toArray()); } else if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(action)) { - enableWifiCheckBox(); + enableWifiSwitch(); } } }; - public WifiApEnabler(Context context, CheckBoxPreference checkBox) { + public WifiApEnabler(Context context, SwitchPreference switchPreference) { mContext = context; - mCheckBox = checkBox; - mOriginalSummary = checkBox.getSummary(); - checkBox.setPersistent(false); + mSwitch = switchPreference; + mOriginalSummary = switchPreference.getSummary(); + switchPreference.setPersistent(false); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); mCm = (ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE); @@ -90,21 +90,21 @@ public class WifiApEnabler { public void resume() { mContext.registerReceiver(mReceiver, mIntentFilter); - enableWifiCheckBox(); + enableWifiSwitch(); } public void pause() { mContext.unregisterReceiver(mReceiver); } - private void enableWifiCheckBox() { + private void enableWifiSwitch() { boolean isAirplaneMode = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0; if(!isAirplaneMode) { - mCheckBox.setEnabled(true); + mSwitch.setEnabled(true); } else { - mCheckBox.setSummary(mOriginalSummary); - mCheckBox.setEnabled(false); + mSwitch.setSummary(mOriginalSummary); + mSwitch.setEnabled(false); } } @@ -122,9 +122,9 @@ public class WifiApEnabler { if (mWifiManager.setWifiApEnabled(null, enable)) { /* Disable here, enabled on receiving success broadcast */ - mCheckBox.setEnabled(false); + mSwitch.setEnabled(false); } else { - mCheckBox.setSummary(R.string.wifi_error); + mSwitch.setSummary(R.string.wifi_error); } /** @@ -147,7 +147,7 @@ public class WifiApEnabler { public void updateConfigSummary(WifiConfiguration wifiConfig) { String s = mContext.getString( com.android.internal.R.string.wifi_tether_configure_ssid_default); - mCheckBox.setSummary(String.format( + mSwitch.setSummary(String.format( mContext.getString(R.string.wifi_tether_enabled_subtext), (wifiConfig == null) ? s : wifiConfig.SSID)); } @@ -173,38 +173,38 @@ public class WifiApEnabler { WifiConfiguration wifiConfig = mWifiManager.getWifiApConfiguration(); updateConfigSummary(wifiConfig); } else if (wifiErrored) { - mCheckBox.setSummary(R.string.wifi_error); + mSwitch.setSummary(R.string.wifi_error); } } private void handleWifiApStateChanged(int state) { switch (state) { case WifiManager.WIFI_AP_STATE_ENABLING: - mCheckBox.setSummary(R.string.wifi_tether_starting); - mCheckBox.setEnabled(false); + mSwitch.setSummary(R.string.wifi_tether_starting); + mSwitch.setEnabled(false); break; case WifiManager.WIFI_AP_STATE_ENABLED: /** * Summary on enable is handled by tether * broadcast notice */ - mCheckBox.setChecked(true); + mSwitch.setChecked(true); /* Doesnt need the airplane check */ - mCheckBox.setEnabled(true); + mSwitch.setEnabled(true); break; case WifiManager.WIFI_AP_STATE_DISABLING: - mCheckBox.setSummary(R.string.wifi_tether_stopping); - mCheckBox.setEnabled(false); + mSwitch.setSummary(R.string.wifi_tether_stopping); + mSwitch.setEnabled(false); break; case WifiManager.WIFI_AP_STATE_DISABLED: - mCheckBox.setChecked(false); - mCheckBox.setSummary(mOriginalSummary); - enableWifiCheckBox(); + mSwitch.setChecked(false); + mSwitch.setSummary(mOriginalSummary); + enableWifiSwitch(); break; default: - mCheckBox.setChecked(false); - mCheckBox.setSummary(R.string.wifi_error); - enableWifiCheckBox(); + mSwitch.setChecked(false); + mSwitch.setSummary(R.string.wifi_error); + enableWifiSwitch(); } } } diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java index fc2276a..3b07b9f 100644 --- a/src/com/android/settings/wifi/WifiConfigController.java +++ b/src/com/android/settings/wifi/WifiConfigController.java @@ -24,11 +24,11 @@ import android.net.IpConfiguration; import android.net.IpConfiguration.IpAssignment; import android.net.IpConfiguration.ProxySettings; import android.net.LinkAddress; -import android.net.LinkProperties; import android.net.NetworkInfo.DetailedState; import android.net.NetworkUtils; import android.net.ProxyInfo; import android.net.RouteInfo; +import android.net.StaticIpConfiguration; import android.net.Uri; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiConfiguration.AuthAlgorithm; @@ -61,6 +61,7 @@ import com.android.settings.ProxySelector; import com.android.settings.R; import java.net.InetAddress; +import java.net.Inet4Address; import java.util.Iterator; /** @@ -137,7 +138,8 @@ public class WifiConfigController implements TextWatcher, private IpAssignment mIpAssignment = IpAssignment.UNASSIGNED; private ProxySettings mProxySettings = ProxySettings.UNASSIGNED; - private LinkProperties mLinkProperties = new LinkProperties(); + private ProxyInfo mHttpProxy = null; + private StaticIpConfiguration mStaticIpConfiguration = null; private String[] mLevels; private boolean mEdit; @@ -216,13 +218,15 @@ public class WifiConfigController implements TextWatcher, if (config.getIpAssignment() == IpAssignment.STATIC) { mIpSettingsSpinner.setSelection(STATIC_IP); showAdvancedFields = true; + // Display IP address. + StaticIpConfiguration staticConfig = config.getStaticIpConfiguration(); + if (staticConfig != null && staticConfig.ipAddress != null) { + addRow(group, R.string.wifi_ip_address, + staticConfig.ipAddress.getAddress().getHostAddress()); + } } else { mIpSettingsSpinner.setSelection(DHCP); } - //Display IP addresses - for(InetAddress a : config.getLinkProperties().getAddresses()) { - addRow(group, R.string.wifi_ip_address, a.getHostAddress()); - } if (config.getProxySettings() == ProxySettings.STATIC) { @@ -462,19 +466,20 @@ public class WifiConfigController implements TextWatcher, } config.setIpConfiguration( - new IpConfiguration(mIpAssignment, mProxySettings, mLinkProperties)); + new IpConfiguration(mIpAssignment, mProxySettings, + mStaticIpConfiguration, mHttpProxy)); return config; } private boolean ipAndProxyFieldsAreValid() { - mLinkProperties.clear(); mIpAssignment = (mIpSettingsSpinner != null && mIpSettingsSpinner.getSelectedItemPosition() == STATIC_IP) ? IpAssignment.STATIC : IpAssignment.DHCP; if (mIpAssignment == IpAssignment.STATIC) { - int result = validateIpConfigFields(mLinkProperties); + mStaticIpConfiguration = new StaticIpConfiguration(); + int result = validateIpConfigFields(mStaticIpConfiguration); if (result != 0) { return false; } @@ -482,6 +487,7 @@ public class WifiConfigController implements TextWatcher, final int selectedPosition = mProxySettingsSpinner.getSelectedItemPosition(); mProxySettings = ProxySettings.NONE; + mHttpProxy = null; if (selectedPosition == PROXY_STATIC && mProxyHostView != null) { mProxySettings = ProxySettings.STATIC; String host = mProxyHostView.getText().toString(); @@ -496,8 +502,7 @@ public class WifiConfigController implements TextWatcher, result = R.string.proxy_error_invalid_port; } if (result == 0) { - ProxyInfo proxyProperties= new ProxyInfo(host, port, exclusionList); - mLinkProperties.setHttpProxy(proxyProperties); + mHttpProxy = new ProxyInfo(host, port, exclusionList); } else { return false; } @@ -511,22 +516,27 @@ public class WifiConfigController implements TextWatcher, if (uri == null) { return false; } - ProxyInfo proxyInfo = new ProxyInfo(uri); - mLinkProperties.setHttpProxy(proxyInfo); + mHttpProxy = new ProxyInfo(uri); } return true; } - private int validateIpConfigFields(LinkProperties linkProperties) { + private Inet4Address getIPv4Address(String text) { + try { + return (Inet4Address) NetworkUtils.numericToInetAddress(text); + } catch (IllegalArgumentException|ClassCastException e) { + return null; + } + } + + private int validateIpConfigFields(StaticIpConfiguration staticIpConfiguration) { if (mIpAddressView == null) return 0; String ipAddr = mIpAddressView.getText().toString(); if (TextUtils.isEmpty(ipAddr)) return R.string.wifi_ip_settings_invalid_ip_address; - InetAddress inetAddr = null; - try { - inetAddr = NetworkUtils.numericToInetAddress(ipAddr); - } catch (IllegalArgumentException e) { + Inet4Address inetAddr = getIPv4Address(ipAddr); + if (inetAddr == null) { return R.string.wifi_ip_settings_invalid_ip_address; } @@ -536,7 +546,7 @@ public class WifiConfigController implements TextWatcher, if (networkPrefixLength < 0 || networkPrefixLength > 32) { return R.string.wifi_ip_settings_invalid_network_prefix_length; } - linkProperties.addLinkAddress(new LinkAddress(inetAddr, networkPrefixLength)); + staticIpConfiguration.ipAddress = new LinkAddress(inetAddr, networkPrefixLength); } catch (NumberFormatException e) { // Set the hint as default after user types in ip address mNetworkPrefixLengthView.setText(mConfigUi.getContext().getString( @@ -555,13 +565,11 @@ public class WifiConfigController implements TextWatcher, } catch (java.net.UnknownHostException u) { } } else { - InetAddress gatewayAddr = null; - try { - gatewayAddr = NetworkUtils.numericToInetAddress(gateway); - } catch (IllegalArgumentException e) { + InetAddress gatewayAddr = getIPv4Address(gateway); + if (gatewayAddr == null) { return R.string.wifi_ip_settings_invalid_gateway; } - linkProperties.addRoute(new RouteInfo(gatewayAddr)); + staticIpConfiguration.gateway = gatewayAddr; } String dns = mDns1View.getText().toString(); @@ -571,22 +579,20 @@ public class WifiConfigController implements TextWatcher, //If everything else is valid, provide hint as a default option mDns1View.setText(mConfigUi.getContext().getString(R.string.wifi_dns1_hint)); } else { - try { - dnsAddr = NetworkUtils.numericToInetAddress(dns); - } catch (IllegalArgumentException e) { + dnsAddr = getIPv4Address(dns); + if (dnsAddr == null) { return R.string.wifi_ip_settings_invalid_dns; } - linkProperties.addDnsServer(dnsAddr); + staticIpConfiguration.dnsServers.add(dnsAddr); } if (mDns2View.length() > 0) { dns = mDns2View.getText().toString(); - try { - dnsAddr = NetworkUtils.numericToInetAddress(dns); - } catch (IllegalArgumentException e) { + dnsAddr = getIPv4Address(dns); + if (dnsAddr == null) { return R.string.wifi_ip_settings_invalid_dns; } - linkProperties.addDnsServer(dnsAddr); + staticIpConfiguration.dnsServers.add(dnsAddr); } return 0; } @@ -797,28 +803,26 @@ public class WifiConfigController implements TextWatcher, mDns2View.addTextChangedListener(this); } if (config != null) { - LinkProperties linkProperties = config.getLinkProperties(); - Iterator<LinkAddress> iterator = linkProperties.getLinkAddresses().iterator(); - if (iterator.hasNext()) { - LinkAddress linkAddress = iterator.next(); - mIpAddressView.setText(linkAddress.getAddress().getHostAddress()); - mNetworkPrefixLengthView.setText(Integer.toString(linkAddress - .getNetworkPrefixLength())); - } + StaticIpConfiguration staticConfig = config.getStaticIpConfiguration(); + if (staticConfig != null) { + if (staticConfig.ipAddress != null) { + mIpAddressView.setText( + staticConfig.ipAddress.getAddress().getHostAddress()); + mNetworkPrefixLengthView.setText(Integer.toString(staticConfig.ipAddress + .getNetworkPrefixLength())); + } - for (RouteInfo route : linkProperties.getRoutes()) { - if (route.isDefaultRoute()) { - mGatewayView.setText(route.getGateway().getHostAddress()); - break; + if (staticConfig.gateway != null) { + mGatewayView.setText(staticConfig.gateway.getHostAddress()); } - } - Iterator<InetAddress> dnsIterator = linkProperties.getDnsServers().iterator(); - if (dnsIterator.hasNext()) { - mDns1View.setText(dnsIterator.next().getHostAddress()); - } - if (dnsIterator.hasNext()) { - mDns2View.setText(dnsIterator.next().getHostAddress()); + Iterator<InetAddress> dnsIterator = staticConfig.dnsServers.iterator(); + if (dnsIterator.hasNext()) { + mDns1View.setText(dnsIterator.next().getHostAddress()); + } + if (dnsIterator.hasNext()) { + mDns2View.setText(dnsIterator.next().getHostAddress()); + } } } } else { @@ -848,7 +852,7 @@ public class WifiConfigController implements TextWatcher, mProxyExclusionListView.addTextChangedListener(this); } if (config != null) { - ProxyInfo proxyProperties = config.getLinkProperties().getHttpProxy(); + ProxyInfo proxyProperties = config.getHttpProxy(); if (proxyProperties != null) { mProxyHostView.setText(proxyProperties.getHost()); mProxyPortView.setText(Integer.toString(proxyProperties.getPort())); @@ -865,7 +869,7 @@ public class WifiConfigController implements TextWatcher, mProxyPacView.addTextChangedListener(this); } if (config != null) { - ProxyInfo proxyInfo = config.getLinkProperties().getHttpProxy(); + ProxyInfo proxyInfo = config.getHttpProxy(); if (proxyInfo != null) { mProxyPacView.setText(proxyInfo.getPacFileUrl().toString()); } diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java index e83cb06..50789b8 100644 --- a/src/com/android/settings/wifi/WifiSettings.java +++ b/src/com/android/settings/wifi/WifiSettings.java @@ -27,7 +27,6 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; -import android.content.pm.PackageManager; import android.content.res.Resources; import android.content.res.TypedArray; import android.location.LocationManager; @@ -42,6 +41,7 @@ import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.net.wifi.WpsInfo; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Message; @@ -50,6 +50,7 @@ import android.preference.PreferenceScreen; import android.util.Log; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; +import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -100,12 +101,7 @@ public class WifiSettings extends RestrictedSettingsFragment private static final int MENU_ID_MODIFY = Menu.FIRST + 8; private static final int MENU_ID_WRITE_NFC = Menu.FIRST + 9; - private static final String KEY_ASSISTANT_DISMISS_TIME = "wifi_assistant_dismiss_time"; - private static final String KEY_ASSISTANT_START_TIME = "wifi_assistant_start_time"; - - private static final long MILI_SECONDS_30_DAYS = 30L * 24L * 60L * 60L * 1000L; - private static final long MILI_SECONDS_90_DAYS = MILI_SECONDS_30_DAYS * 3L; - private static final long MILI_SECONDS_180_DAYS = MILI_SECONDS_90_DAYS * 2L; + private static final String KEY_ASSISTANT_DISMISS_PLATFORM = "assistant_dismiss_platform"; public static final int WIFI_DIALOG_ID = 1; /* package */ static final int WPS_PBC_DIALOG_ID = 2; @@ -129,7 +125,6 @@ public class WifiSettings extends RestrictedSettingsFragment private WifiManager.ActionListener mConnectListener; private WifiManager.ActionListener mSaveListener; private WifiManager.ActionListener mForgetListener; - private boolean mP2pSupported; private WifiEnabler mWifiEnabler; // An access point being editted is stored here. @@ -156,7 +151,7 @@ public class WifiSettings extends RestrictedSettingsFragment private boolean mDlgEdit; private AccessPoint mDlgAccessPoint; private Bundle mAccessPointSavedState; - private Preference mWifiAssistantPreference; + private View mWifiAssistantCard; private NetworkScorerAppData mWifiAssistantApp; /** verbose logging flag. this flag is set thru developer debugging options @@ -165,52 +160,6 @@ public class WifiSettings extends RestrictedSettingsFragment /* End of "used in Wifi Setup context" */ - /** Holds the Wifi Assistant Card. */ - private class WifiAssistantPreference extends Preference { - public WifiAssistantPreference() { - super(getActivity()); - setLayoutResource(R.layout.wifi_assistant_card); - } - - @Override - public void onBindView(View view) { - super.onBindView(view); - Button setup = (Button)view.findViewById(R.id.setup); - Button noThanks = (Button)view.findViewById(R.id.no_thanks_button); - - if (setup != null && noThanks != null) { - setup.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - Intent intent = new Intent(); - if (mWifiAssistantApp.mConfigurationActivityClassName != null) { - // App has a custom configuration activity; launch that. - // This custom activity will be responsible for launching the system - // dialog. - intent.setClassName(mWifiAssistantApp.mPackageName, - mWifiAssistantApp.mConfigurationActivityClassName); - } else { - // Fall back on the system dialog. - intent.setAction(NetworkScoreManager.ACTION_CHANGE_ACTIVE); - intent.putExtra(NetworkScoreManager.EXTRA_PACKAGE_NAME, - mWifiAssistantApp.mPackageName); - } - startActivityForResult(intent, REQUEST_ENABLE_WIFI_ASSISTANT); - } - }); - - noThanks.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - setWifiAssistantTimeout(); - getPreferenceScreen().removePreference(WifiAssistantPreference.this); - mWifiAssistantApp = null; - } - }); - } - } - } - /** A restricted multimap for use in constructAccessPoints */ private static class Multimap<K,V> { private final HashMap<K,List<V>> store = new HashMap<K,List<V>>(); @@ -285,7 +234,7 @@ public class WifiSettings extends RestrictedSettingsFragment mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - handleEvent(context, intent); + handleEvent(intent); } }; @@ -296,7 +245,6 @@ public class WifiSettings extends RestrictedSettingsFragment public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - mP2pSupported = getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI_DIRECT); mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); mConnectListener = new WifiManager.ActionListener() { @@ -347,7 +295,7 @@ public class WifiSettings extends RestrictedSettingsFragment if (savedInstanceState != null) { mDlgEdit = savedInstanceState.getBoolean(SAVE_DIALOG_EDIT_MODE); if (savedInstanceState.containsKey(SAVE_DIALOG_ACCESS_POINT_STATE)) { - mAccessPointSavedState = + mAccessPointSavedState = savedInstanceState.getBundle(SAVE_DIALOG_ACCESS_POINT_STATE); } } @@ -373,8 +321,7 @@ public class WifiSettings extends RestrictedSettingsFragment prepareWifiAssistantCard(); - mEmptyView = (TextView) getView().findViewById(android.R.id.empty); - getListView().setEmptyView(mEmptyView); + mEmptyView = initEmptyView(); registerForContextMenu(getListView()); setHasOptionsMenu(true); } @@ -383,8 +330,8 @@ public class WifiSettings extends RestrictedSettingsFragment public void onActivityResult(int requestCode, int resultCode, Intent resultData) { if (requestCode == REQUEST_ENABLE_WIFI_ASSISTANT) { if (resultCode == Activity.RESULT_OK) { - setWifiAssistantTimeout(); - getPreferenceScreen().removePreference(mWifiAssistantPreference); + disableWifiAssistantCardUntilPlatformUpgrade(); + getListView().removeHeaderView(mWifiAssistantCard); mWifiAssistantApp = null; } } else { @@ -706,8 +653,9 @@ public class WifiSettings extends RestrictedSettingsFragment addMessagePreference(R.string.wifi_empty_list_wifi_on); } + getListView().removeHeaderView(mWifiAssistantCard); if (mWifiAssistantApp != null) { - getPreferenceScreen().addPreference(mWifiAssistantPreference); + getListView().addHeaderView(mWifiAssistantCard); } for (AccessPoint accessPoint : accessPoints) { @@ -732,64 +680,106 @@ public class WifiSettings extends RestrictedSettingsFragment } } - private boolean prepareWifiAssistantCard() { - if (mWifiAssistantPreference == null) { - mWifiAssistantPreference = new WifiAssistantPreference(); + /** + * Returns the Network Scorer for the Wifi Assistant App. + */ + public static NetworkScorerAppData getWifiAssistantApp(Context context) { + Collection<NetworkScorerAppData> scorers = + NetworkScorerAppManager.getAllValidScorers(context); + + if (scorers.isEmpty()) { + return null; } + // TODO: b/13780935 - Implement proper scorer selection. Rather than pick the first + // scorer on the system, we should allow the user to select one. + return scorers.iterator().next(); + } + + private void prepareWifiAssistantCard() { if (getActivity() instanceof WifiPickerActivity) { - return false; + return; } if (NetworkScorerAppManager.getActiveScorer(getActivity()) != null) { // A scorer is already enabled; don't show the card. - return false; + return; } Collection<NetworkScorerAppData> scorers = NetworkScorerAppManager.getAllValidScorers(getActivity()); if (scorers.isEmpty()) { // No scorers are available to enable; don't show the card. - return false; + return; } SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences(); - long lastTimeoutEndTime = sharedPreferences.getLong(KEY_ASSISTANT_START_TIME, 0); - long dismissTime = sharedPreferences.getLong(KEY_ASSISTANT_DISMISS_TIME, 0); - - boolean shouldShow = ((System.currentTimeMillis() - lastTimeoutEndTime) > dismissTime); - if (shouldShow) { - // TODO: b/13780935 - Implement proper scorer selection. Rather than pick the first - // scorer on the system, we should allow the user to select one. - mWifiAssistantApp = scorers.iterator().next(); + int lastDismissPlatform = sharedPreferences.getInt(KEY_ASSISTANT_DISMISS_PLATFORM, 0); + + if (Build.VERSION.SDK_INT <= lastDismissPlatform) { + // User has dismissed the Wi-Fi assistant card on this SDK release. Suppress the card + // until the next major platform upgrade. + return; + } + + // TODO: b/13780935 - Implement proper scorer selection. Rather than pick the first + // scorer on the system, we should allow the user to select one. + mWifiAssistantApp = scorers.iterator().next(); + + if (mWifiAssistantCard == null) { + mWifiAssistantCard = LayoutInflater.from(getActivity()) + .inflate(R.layout.wifi_assistant_card, getListView(), false); + Button setup = (Button) mWifiAssistantCard.findViewById(R.id.setup); + Button noThanks = (Button) mWifiAssistantCard.findViewById(R.id.no_thanks_button); + + if (setup != null && noThanks != null) { + setup.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(); + if (mWifiAssistantApp.mConfigurationActivityClassName != null) { + // App has a custom configuration activity; launch that. + // This custom activity will be responsible for launching the system + // dialog. + intent.setClassName(mWifiAssistantApp.mPackageName, + mWifiAssistantApp.mConfigurationActivityClassName); + } else { + // Fall back on the system dialog. + intent.setAction(NetworkScoreManager.ACTION_CHANGE_ACTIVE); + intent.putExtra(NetworkScoreManager.EXTRA_PACKAGE_NAME, + mWifiAssistantApp.mPackageName); + } + startActivityForResult(intent, REQUEST_ENABLE_WIFI_ASSISTANT); + } + }); + + noThanks.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + disableWifiAssistantCardUntilPlatformUpgrade(); + getListView().removeHeaderView(mWifiAssistantCard); + mWifiAssistantApp = null; + } + }); + } } - return shouldShow; } - private void setWifiAssistantTimeout() { + private void disableWifiAssistantCardUntilPlatformUpgrade() { SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences(); SharedPreferences.Editor editor = sharedPreferences.edit(); - long dismissTime = sharedPreferences.getLong(KEY_ASSISTANT_DISMISS_TIME, 0); - - if (dismissTime == 0) { - dismissTime = MILI_SECONDS_30_DAYS; - } else if (dismissTime == MILI_SECONDS_30_DAYS) { - dismissTime = MILI_SECONDS_90_DAYS; - } else if (dismissTime == MILI_SECONDS_90_DAYS) { - dismissTime = MILI_SECONDS_180_DAYS; - } else if (dismissTime == MILI_SECONDS_180_DAYS) { - dismissTime = java.lang.Long.MAX_VALUE; - } - - editor.putLong(KEY_ASSISTANT_DISMISS_TIME, dismissTime); - editor.putLong(KEY_ASSISTANT_START_TIME, System.currentTimeMillis()); + editor.putInt(KEY_ASSISTANT_DISMISS_PLATFORM, Build.VERSION.SDK_INT); editor.apply(); } + protected TextView initEmptyView() { + TextView emptyView = (TextView) getActivity().findViewById(android.R.id.empty); + getListView().setEmptyView(emptyView); + return emptyView; + } + private void setOffMessage() { if (mEmptyView != null) { - mEmptyView.setCompoundDrawablesWithIntrinsicBounds(0, - R.drawable.ic_wifi_emptystate, 0, 0); mEmptyView.setText(R.string.wifi_empty_list_wifi_off); if (android.provider.Settings.Global.getInt(getActivity().getContentResolver(), android.provider.Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1) { @@ -823,7 +813,13 @@ public class WifiSettings extends RestrictedSettingsFragment final List<WifiConfiguration> configs = wifiManager.getConfiguredNetworks(); if (configs != null) { - savedNetworksExist = (configs.size() > 0); + // Update "Saved Networks" menu option. + if (savedNetworksExist != (configs.size() > 0)) { + savedNetworksExist = !savedNetworksExist; + if (context instanceof Activity) { + ((Activity) context).invalidateOptionsMenu(); + } + } for (WifiConfiguration config : configs) { AccessPoint accessPoint = new AccessPoint(context, config); if (lastInfo != null && lastState != null) { @@ -861,7 +857,7 @@ public class WifiSettings extends RestrictedSettingsFragment return accessPoints; } - private void handleEvent(Context context, Intent intent) { + private void handleEvent(Intent intent) { String action = intent.getAction(); if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) { updateWifiState(intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, diff --git a/src/com/android/settings/wifi/WifiSettingsForSetupWizard.java b/src/com/android/settings/wifi/WifiSettingsForSetupWizard.java index b52aaa7..c4a5c96 100644 --- a/src/com/android/settings/wifi/WifiSettingsForSetupWizard.java +++ b/src/com/android/settings/wifi/WifiSettingsForSetupWizard.java @@ -18,18 +18,19 @@ package com.android.settings.wifi; import android.content.Intent; import android.content.res.TypedArray; +import android.database.DataSetObserver; import android.net.wifi.WifiConfiguration; import android.os.Bundle; +import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; -import android.widget.ImageButton; +import android.widget.AbsListView.LayoutParams; +import android.widget.ListAdapter; import android.widget.ListView; -import android.widget.PopupMenu; -import android.widget.PopupMenu.OnMenuItemClickListener; import android.widget.TextView; import com.android.settings.R; @@ -47,6 +48,11 @@ public class WifiSettingsForSetupWizard extends WifiSettings { // show a text regarding data charges when wifi connection is required during setup wizard protected static final String EXTRA_SHOW_WIFI_REQUIRED_INFO = "wifi_show_wifi_required_info"; + private View mAddOtherNetworkItem; + private ListAdapter mAdapter; + private TextView mEmptyFooter; + private boolean mListLastEmpty = false; + @Override public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -60,9 +66,9 @@ public class WifiSettingsForSetupWizard extends WifiSettings { list.addHeaderView(header, null, false); } - final View other = inflater.inflate(R.layout.setup_wifi_add_network, list, false); - list.addFooterView(other, null, true); - other.setOnClickListener(new OnClickListener() { + mAddOtherNetworkItem = inflater.inflate(R.layout.setup_wifi_add_network, list, false); + list.addFooterView(mAddOtherNetworkItem, null, true); + mAddOtherNetworkItem.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mWifiManager.isWifiEnabled()) { @@ -92,6 +98,15 @@ public class WifiSettingsForSetupWizard extends WifiSettings { if (hasNextButton()) { getNextButton().setVisibility(View.GONE); } + + mAdapter = getPreferenceScreen().getRootAdapter(); + mAdapter.registerDataSetObserver(new DataSetObserver() { + @Override + public void onChanged() { + super.onChanged(); + updateFooter(); + } + }); } @Override @@ -133,4 +148,30 @@ public class WifiSettingsForSetupWizard extends WifiSettings { activity.networkSelected(); super.connect(networkId); } + + @Override + protected TextView initEmptyView() { + mEmptyFooter = new TextView(getActivity()); + mEmptyFooter.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, + LayoutParams.MATCH_PARENT)); + mEmptyFooter.setGravity(Gravity.CENTER); + mEmptyFooter.setCompoundDrawablesWithIntrinsicBounds(0, + R.drawable.ic_wifi_emptystate, 0,0); + return mEmptyFooter; + } + + protected void updateFooter() { + final boolean isEmpty = mAdapter.isEmpty(); + if (isEmpty != mListLastEmpty) { + final ListView list = getListView(); + if (isEmpty) { + list.removeFooterView(mAddOtherNetworkItem); + list.addFooterView(mEmptyFooter, null, false); + } else { + list.removeFooterView(mEmptyFooter); + list.addFooterView(mAddOtherNetworkItem, null, true); + } + mListLastEmpty = isEmpty; + } + } } diff --git a/src/com/android/settings/wifi/WifiSetupActivity.java b/src/com/android/settings/wifi/WifiSetupActivity.java index 3dd7a03..5452a03 100644 --- a/src/com/android/settings/wifi/WifiSetupActivity.java +++ b/src/com/android/settings/wifi/WifiSetupActivity.java @@ -218,6 +218,7 @@ public class WifiSetupActivity extends WifiPickerActivity final Intent nextIntent = new Intent(ACTION_NEXT); nextIntent.putExtra(EXTRA_SCRIPT_URI, intent.getStringExtra(EXTRA_SCRIPT_URI)); nextIntent.putExtra(EXTRA_ACTION_ID, intent.getStringExtra(EXTRA_ACTION_ID)); + nextIntent.putExtra(EXTRA_THEME, intent.getStringExtra(EXTRA_THEME)); nextIntent.putExtra(EXTRA_RESULT_CODE, resultCode); startActivityForResult(nextIntent, NEXT_REQUEST); } diff --git a/src/com/android/settings/wifi/WpsDialog.java b/src/com/android/settings/wifi/WpsDialog.java index 662d477..d0b116b 100644 --- a/src/com/android/settings/wifi/WpsDialog.java +++ b/src/com/android/settings/wifi/WpsDialog.java @@ -57,7 +57,7 @@ public class WpsDialog extends AlertDialog { private static final int WPS_TIMEOUT_S = 120; private WifiManager mWifiManager; - private WifiManager.WpsListener mWpsListener; + private WifiManager.WpsCallback mWpsListener; private int mWpsSetup; private final IntentFilter mFilter; @@ -81,8 +81,9 @@ public class WpsDialog extends AlertDialog { mContext = context; mWpsSetup = wpsSetup; - class WpsListener implements WifiManager.WpsListener { - public void onStartSuccess(String pin) { + class WpsListener extends WifiManager.WpsCallback { + + public void onStarted(String pin) { if (pin != null) { updateDialog(DialogState.WPS_START, String.format( mContext.getString(R.string.wifi_wps_onstart_pin), pin)); @@ -91,12 +92,13 @@ public class WpsDialog extends AlertDialog { R.string.wifi_wps_onstart_pbc)); } } - public void onCompletion() { + + public void onSucceeded() { updateDialog(DialogState.WPS_COMPLETE, mContext.getString(R.string.wifi_wps_complete)); } - public void onFailure(int reason) { + public void onFailed(int reason) { String msg; switch (reason) { case WifiManager.WPS_OVERLAP_ERROR: |