Refresh Wifi AP Config display when config changes
Change-Id: I6fe284355223cbcedd82f95d6415c4d6b660f39f Fixes: 64757839 Test: robotests Test: rerun ACTS WifiTetheringTest:test_change_wifi_hotspot_ssid_when_hotspot_enabled
This commit is contained in:
@@ -23,12 +23,13 @@ import android.content.Context;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
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_2GHZ), String.valueOf(AP_BAND_5GHZ)};
|
||||
@@ -40,21 +41,23 @@ public class WifiTetherApBandPreferenceController extends WifiTetherBasePreferen
|
||||
OnTetherConfigUpdateListener listener) {
|
||||
super(context, listener);
|
||||
mBandEntries = mContext.getResources().getStringArray(R.array.wifi_ap_band_config_full);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDisplay() {
|
||||
final WifiConfiguration config = mWifiManager.getWifiApConfiguration();
|
||||
if (config == null) {
|
||||
mBandIndex = 0;
|
||||
Log.d(TAG, "Updating band index to 0 because no config");
|
||||
} else if (is5GhzBandSupported()) {
|
||||
mBandIndex = config.apBand;
|
||||
Log.d(TAG, "Updating band index to " + mBandIndex);
|
||||
} else {
|
||||
config.apBand = 0;
|
||||
mWifiManager.setWifiApConfiguration(config);
|
||||
mBandIndex = config.apBand;
|
||||
Log.d(TAG, "5Ghz not supported, updating band index to " + mBandIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
ListPreference preference = (ListPreference) mPreference;
|
||||
if (!is5GhzBandSupported()) {
|
||||
preference.setEnabled(false);
|
||||
|
@@ -57,5 +57,8 @@ public abstract class WifiTetherBasePreferenceController extends AbstractPrefere
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
updateDisplay();
|
||||
}
|
||||
|
||||
public abstract void updateDisplay();
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ import android.content.Context;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.support.v7.preference.EditTextPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.widget.ValidatedEditTextPreference;
|
||||
import com.android.settings.wifi.WifiUtils;
|
||||
@@ -28,6 +28,7 @@ import com.android.settings.wifi.WifiUtils;
|
||||
public class WifiTetherPasswordPreferenceController extends WifiTetherBasePreferenceController
|
||||
implements ValidatedEditTextPreference.Validator {
|
||||
|
||||
private static final String TAG = "WifiTetherPswdPref";
|
||||
private static final String PREF_KEY = "wifi_tether_network_password";
|
||||
|
||||
private String mPassword;
|
||||
@@ -35,10 +36,6 @@ public class WifiTetherPasswordPreferenceController extends WifiTetherBasePrefer
|
||||
public WifiTetherPasswordPreferenceController(Context context,
|
||||
OnTetherConfigUpdateListener listener) {
|
||||
super(context, listener);
|
||||
final WifiConfiguration config = mWifiManager.getWifiApConfiguration();
|
||||
if (config != null) {
|
||||
mPassword = config.preSharedKey;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,8 +44,12 @@ public class WifiTetherPasswordPreferenceController extends WifiTetherBasePrefer
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
public void updateDisplay() {
|
||||
final WifiConfiguration config = mWifiManager.getWifiApConfiguration();
|
||||
if (config != null) {
|
||||
mPassword = config.preSharedKey;
|
||||
Log.d(TAG, "Updating password in Preference, " + mPassword);
|
||||
}
|
||||
((ValidatedEditTextPreference) mPreference).setValidator(this);
|
||||
updatePasswordDisplay((EditTextPreference) mPreference);
|
||||
}
|
||||
|
@@ -21,7 +21,7 @@ import android.net.wifi.WifiConfiguration;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.EditTextPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.widget.ValidatedEditTextPreference;
|
||||
import com.android.settings.wifi.WifiUtils;
|
||||
@@ -29,6 +29,7 @@ import com.android.settings.wifi.WifiUtils;
|
||||
public class WifiTetherSSIDPreferenceController extends WifiTetherBasePreferenceController
|
||||
implements ValidatedEditTextPreference.Validator {
|
||||
|
||||
private static final String TAG = "WifiTetherSsidPref";
|
||||
private static final String PREF_KEY = "wifi_tether_network_name";
|
||||
@VisibleForTesting
|
||||
static final String DEFAULT_SSID = "AndroidAP";
|
||||
@@ -46,13 +47,14 @@ public class WifiTetherSSIDPreferenceController extends WifiTetherBasePreference
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
public void updateDisplay() {
|
||||
final WifiConfiguration config = mWifiManager.getWifiApConfiguration();
|
||||
if (config != null) {
|
||||
mSSID = config.SSID;
|
||||
Log.d(TAG, "Updating SSID in Preference, " + mSSID);
|
||||
} else {
|
||||
mSSID = DEFAULT_SSID;
|
||||
Log.d(TAG, "Updating to default SSID in Preference, " + mSSID);
|
||||
}
|
||||
((ValidatedEditTextPreference) mPreference).setValidator(this);
|
||||
updateSsidDisplay((EditTextPreference) mPreference);
|
||||
|
@@ -44,6 +44,7 @@ import java.util.List;
|
||||
public class WifiTetherSettings extends RestrictedDashboardFragment
|
||||
implements WifiTetherBasePreferenceController.OnTetherConfigUpdateListener {
|
||||
|
||||
private static final String TAG = "WifiTetherSettings";
|
||||
private static final IntentFilter TETHER_STATE_CHANGE_FILTER;
|
||||
|
||||
private WifiTetherSwitchBarController mSwitchBarController;
|
||||
@@ -161,27 +162,37 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
|
||||
return config;
|
||||
}
|
||||
|
||||
private void startTether() {
|
||||
mRestartWifiApAfterConfigChange = false;
|
||||
mSwitchBarController.startTether();
|
||||
}
|
||||
|
||||
private void updateDisplayWithNewConfig() {
|
||||
getPreferenceController(WifiTetherSSIDPreferenceController.class)
|
||||
.updateDisplay();
|
||||
getPreferenceController(WifiTetherPasswordPreferenceController.class)
|
||||
.updateDisplay();
|
||||
getPreferenceController(WifiTetherApBandPreferenceController.class)
|
||||
.updateDisplay();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
class TetherChangeReceiver extends BroadcastReceiver {
|
||||
private static final String TAG = "TetherChangeReceiver";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context content, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
Log.d(TAG, "updating display config due to receiving broadcast action " + action);
|
||||
updateDisplayWithNewConfig();
|
||||
if (action.equals(ACTION_TETHER_STATE_CHANGED)) {
|
||||
if (mWifiManager.getWifiApState() == WifiManager.WIFI_AP_STATE_DISABLED
|
||||
&& mRestartWifiApAfterConfigChange) {
|
||||
mRestartWifiApAfterConfigChange = false;
|
||||
Log.d(TAG, "Restarting WifiAp due to prior config change.");
|
||||
mSwitchBarController.startTether();
|
||||
startTether();
|
||||
}
|
||||
} else if (action.equals(WIFI_AP_STATE_CHANGED_ACTION)) {
|
||||
int state = intent.getIntExtra(WifiManager.EXTRA_WIFI_AP_STATE, 0);
|
||||
if (state == WifiManager.WIFI_AP_STATE_DISABLED
|
||||
&& mRestartWifiApAfterConfigChange) {
|
||||
mRestartWifiApAfterConfigChange = false;
|
||||
Log.d(TAG, "Restarting WifiAp due to prior config change.");
|
||||
mSwitchBarController.startTether();
|
||||
startTether();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user