Update Wifi Tether band selection UI

This CL updates the preference for selecting the enabled tether bands
to allow individual selection of multiple bands instead of forcing
a single selection. Note that while this makes the UI theoretically
support new bands in the future, the wifi backend only supports
selecting a single band or all bands which this CL does not address.

Test: robotests
Bug: 73102003
Change-Id: Ib2d4a2834c5cd11875515d308f7b20bfc8471959
This commit is contained in:
Salvador Martinez
2018-04-12 17:21:06 -07:00
parent 8a3bcaa3e3
commit 10ba9c1786
9 changed files with 501 additions and 31 deletions

View File

@@ -18,31 +18,34 @@ package com.android.settings.wifi.tether;
import static android.net.wifi.WifiConfiguration.AP_BAND_2GHZ;
import static android.net.wifi.WifiConfiguration.AP_BAND_5GHZ;
import static android.net.wifi.WifiConfiguration.AP_BAND_ANY;
import android.content.Context;
import android.content.res.Resources;
import android.icu.text.ListFormatter;
import android.net.wifi.WifiConfiguration;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference;
import android.util.Log;
import com.android.settings.R;
import com.android.settings.widget.HotspotApBandSelectionPreference;
public class WifiTetherApBandPreferenceController extends WifiTetherBasePreferenceController {
private static final String TAG = "WifiTetherApBandPref";
private static final String PREF_KEY = "wifi_tether_network_ap_band";
private static final String[] BAND_VALUES =
{String.valueOf(AP_BAND_ANY), String.valueOf(AP_BAND_2GHZ),
String.valueOf(AP_BAND_5GHZ)};
public static final String[] BAND_VALUES =
{String.valueOf(AP_BAND_2GHZ), String.valueOf(AP_BAND_5GHZ)};
private final String[] mBandEntries;
private final String[] mBandSummaries;
private int mBandIndex;
public WifiTetherApBandPreferenceController(Context context,
OnTetherConfigUpdateListener listener) {
super(context, listener);
mBandEntries = mContext.getResources().getStringArray(R.array.wifi_ap_band_config_full);
Resources res = mContext.getResources();
mBandEntries = res.getStringArray(R.array.wifi_ap_band_config_full);
mBandSummaries = res.getStringArray(R.array.wifi_ap_band_summary_full);
}
@Override
@@ -60,18 +63,25 @@ public class WifiTetherApBandPreferenceController extends WifiTetherBasePreferen
mBandIndex = config.apBand;
Log.d(TAG, "5Ghz not supported, updating band index to " + mBandIndex);
}
ListPreference preference = (ListPreference) mPreference;
HotspotApBandSelectionPreference preference =
(HotspotApBandSelectionPreference) mPreference;
if (!is5GhzBandSupported()) {
preference.setEnabled(false);
preference.setSummary(R.string.wifi_ap_choose_2G);
} else {
preference.setEntries(mBandEntries);
preference.setEntryValues(BAND_VALUES);
preference.setSummary(mBandEntries[mBandIndex + 1]);
preference.setValue(String.valueOf(mBandIndex));
preference.setExistingConfigValue(config.apBand);
preference.setSummary(getConfigSummary());
}
}
String getConfigSummary() {
if (mBandIndex == WifiConfiguration.AP_BAND_ANY) {
return ListFormatter.getInstance().format((Object[]) mBandSummaries);
}
return mBandSummaries[mBandIndex];
}
@Override
public String getPreferenceKey() {
return PREF_KEY;
@@ -79,9 +89,9 @@ public class WifiTetherApBandPreferenceController extends WifiTetherBasePreferen
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mBandIndex = Integer.parseInt((String) newValue);
mBandIndex = (Integer) newValue;
Log.d(TAG, "Band preference changed, updating band index to " + mBandIndex);
preference.setSummary(mBandEntries[mBandIndex + 1]);
preference.setSummary(getConfigSummary());
mListener.onTetherConfigUpdated();
return true;
}