Merge "[Wi-Fi HotSpot] Improve Wi-Fi hotspot settings entries visibility problem"

This commit is contained in:
Goven Liu
2019-08-16 07:51:50 +00:00
committed by Android (Google) Code Review
10 changed files with 42 additions and 19 deletions

View File

@@ -20,8 +20,7 @@
xmlns:settings="http://schemas.android.com/apk/res-auto" xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="wifi_tether_settings_screen" android:key="wifi_tether_settings_screen"
android:title="@string/wifi_hotspot_checkbox_text" android:title="@string/wifi_hotspot_checkbox_text"
settings:searchable="false" settings:searchable="false">
settings:initialExpandedChildrenCount="3">
<com.android.settings.wifi.tether.WifiTetherSsidPreference <com.android.settings.wifi.tether.WifiTetherSsidPreference
android:key="wifi_tether_network_name" android:key="wifi_tether_network_name"

View File

@@ -90,7 +90,7 @@ public class WifiTetherApBandPreferenceController extends WifiTetherBasePreferen
mBandIndex = validateSelection(Integer.parseInt((String) newValue)); mBandIndex = validateSelection(Integer.parseInt((String) newValue));
Log.d(TAG, "Band preference changed, updating band index to " + mBandIndex); Log.d(TAG, "Band preference changed, updating band index to " + mBandIndex);
preference.setSummary(getConfigSummary()); preference.setSummary(getConfigSummary());
mListener.onTetherConfigUpdated(); mListener.onTetherConfigUpdated(this);
return true; return true;
} }

View File

@@ -30,7 +30,7 @@ public abstract class WifiTetherBasePreferenceController extends AbstractPrefere
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener { implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
public interface OnTetherConfigUpdateListener { public interface OnTetherConfigUpdateListener {
void onTetherConfigUpdated(); void onTetherConfigUpdated(AbstractPreferenceController context);
} }
protected final WifiManager mWifiManager; protected final WifiManager mWifiManager;

View File

@@ -65,7 +65,7 @@ public class WifiTetherPasswordPreferenceController extends WifiTetherBasePrefer
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
mPassword = (String) newValue; mPassword = (String) newValue;
updatePasswordDisplay((EditTextPreference) mPreference); updatePasswordDisplay((EditTextPreference) mPreference);
mListener.onTetherConfigUpdated(); mListener.onTetherConfigUpdated(this);
return true; return true;
} }

View File

@@ -93,7 +93,7 @@ public class WifiTetherSSIDPreferenceController extends WifiTetherBasePreference
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
mSSID = (String) newValue; mSSID = (String) newValue;
updateSsidDisplay((EditTextPreference) preference); updateSsidDisplay((EditTextPreference) preference);
mListener.onTetherConfigUpdated(); mListener.onTetherConfigUpdated(this);
return true; return true;
} }

View File

@@ -45,7 +45,7 @@ public class WifiTetherSecurityPreferenceController extends WifiTetherBasePrefer
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
mSecurityValue = Integer.parseInt((String) newValue); mSecurityValue = Integer.parseInt((String) newValue);
preference.setSummary(getSummaryForSecurityType(mSecurityValue)); preference.setSummary(getSummaryForSecurityType(mSecurityValue));
mListener.onTetherConfigUpdated(); mListener.onTetherConfigUpdated(this);
return true; return true;
} }

View File

@@ -30,9 +30,8 @@ import android.os.Bundle;
import android.os.UserManager; import android.os.UserManager;
import android.provider.SearchIndexableResource; import android.provider.SearchIndexableResource;
import android.util.Log; import android.util.Log;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.preference.PreferenceGroup;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SettingsActivity; import com.android.settings.SettingsActivity;
import com.android.settings.dashboard.RestrictedDashboardFragment; import com.android.settings.dashboard.RestrictedDashboardFragment;
@@ -42,7 +41,6 @@ import com.android.settings.widget.SwitchBarController;
import com.android.settingslib.TetherUtil; import com.android.settingslib.TetherUtil;
import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.search.SearchIndexable; import com.android.settingslib.search.SearchIndexable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -54,6 +52,9 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
private static final String TAG = "WifiTetherSettings"; private static final String TAG = "WifiTetherSettings";
private static final IntentFilter TETHER_STATE_CHANGE_FILTER; private static final IntentFilter TETHER_STATE_CHANGE_FILTER;
private static final String KEY_WIFI_TETHER_SCREEN = "wifi_tether_settings_screen"; private static final String KEY_WIFI_TETHER_SCREEN = "wifi_tether_settings_screen";
private static final int EXPANDED_CHILD_COUNT_WITH_SECURITY_NON = 2;
private static final int EXPANDED_CHILD_COUNT_DEFAULT = 3;
@VisibleForTesting @VisibleForTesting
static final String KEY_WIFI_TETHER_NETWORK_NAME = "wifi_tether_network_name"; static final String KEY_WIFI_TETHER_NETWORK_NAME = "wifi_tether_network_name";
@VisibleForTesting @VisibleForTesting
@@ -185,7 +186,7 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
} }
@Override @Override
public void onTetherConfigUpdated() { public void onTetherConfigUpdated(AbstractPreferenceController context) {
final WifiConfiguration config = buildNewConfig(); final WifiConfiguration config = buildNewConfig();
mPasswordPreferenceController.updateVisibility(config.getAuthType()); mPasswordPreferenceController.updateVisibility(config.getAuthType());
@@ -201,6 +202,10 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
mSwitchBarController.stopTether(); mSwitchBarController.stopTether();
} }
mWifiManager.setWifiApConfiguration(config); mWifiManager.setWifiApConfiguration(config);
if (context instanceof WifiTetherSecurityPreferenceController) {
reConfigInitialExpandedChildCount();
}
} }
private WifiConfiguration buildNewConfig() { private WifiConfiguration buildNewConfig() {
@@ -285,4 +290,23 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
} }
} }
} }
private void reConfigInitialExpandedChildCount() {
final PreferenceGroup screen = getPreferenceScreen();
if (mSecurityPreferenceController.getSecurityType() == WifiConfiguration.KeyMgmt.NONE) {
screen.setInitialExpandedChildrenCount(EXPANDED_CHILD_COUNT_WITH_SECURITY_NON);
return;
}
screen.setInitialExpandedChildrenCount(EXPANDED_CHILD_COUNT_DEFAULT);
}
@Override
public int getInitialExpandedChildCount() {
if (mSecurityPreferenceController == null) {
return EXPANDED_CHILD_COUNT_DEFAULT;
}
return (mSecurityPreferenceController.getSecurityType() == WifiConfiguration.KeyMgmt.NONE) ?
EXPANDED_CHILD_COUNT_WITH_SECURITY_NON : EXPANDED_CHILD_COUNT_DEFAULT;
}
} }

View File

@@ -128,19 +128,19 @@ public class WifiTetherApBandPreferenceControllerTest {
mController.onPreferenceChange(mPreference, "-1"); mController.onPreferenceChange(mPreference, "-1");
assertThat(mController.getBandIndex()).isEqualTo(1); assertThat(mController.getBandIndex()).isEqualTo(1);
assertThat(mPreference.getSummary()).isEqualTo(FIVE_GHZ_STRING); assertThat(mPreference.getSummary()).isEqualTo(FIVE_GHZ_STRING);
verify(mListener, times(1)).onTetherConfigUpdated(); verify(mListener, times(1)).onTetherConfigUpdated(mController);
// set to 5 Ghz // set to 5 Ghz
mController.onPreferenceChange(mPreference, "1"); mController.onPreferenceChange(mPreference, "1");
assertThat(mController.getBandIndex()).isEqualTo(1); assertThat(mController.getBandIndex()).isEqualTo(1);
assertThat(mPreference.getSummary()).isEqualTo(FIVE_GHZ_STRING); assertThat(mPreference.getSummary()).isEqualTo(FIVE_GHZ_STRING);
verify(mListener, times(2)).onTetherConfigUpdated(); verify(mListener, times(2)).onTetherConfigUpdated(mController);
// set to 2 Ghz // set to 2 Ghz
mController.onPreferenceChange(mPreference, "0"); mController.onPreferenceChange(mPreference, "0");
assertThat(mController.getBandIndex()).isEqualTo(0); assertThat(mController.getBandIndex()).isEqualTo(0);
assertThat(mPreference.getSummary()).isEqualTo(TWO_GHZ_STRING); assertThat(mPreference.getSummary()).isEqualTo(TWO_GHZ_STRING);
verify(mListener, times(3)).onTetherConfigUpdated(); verify(mListener, times(3)).onTetherConfigUpdated(mController);
} }
@Test @Test
@@ -155,19 +155,19 @@ public class WifiTetherApBandPreferenceControllerTest {
mController.onPreferenceChange(mPreference, "-1"); mController.onPreferenceChange(mPreference, "-1");
assertThat(mController.getBandIndex()).isEqualTo(-1); assertThat(mController.getBandIndex()).isEqualTo(-1);
assertThat(mPreference.getSummary()).isEqualTo(ALL_BANDS); assertThat(mPreference.getSummary()).isEqualTo(ALL_BANDS);
verify(mListener, times(1)).onTetherConfigUpdated(); verify(mListener, times(1)).onTetherConfigUpdated(mController);
// should revert to the default for 5 Ghz only since this is not supported with this config // should revert to the default for 5 Ghz only since this is not supported with this config
mController.onPreferenceChange(mPreference, "1"); mController.onPreferenceChange(mPreference, "1");
assertThat(mController.getBandIndex()).isEqualTo(-1); assertThat(mController.getBandIndex()).isEqualTo(-1);
assertThat(mPreference.getSummary()).isEqualTo(ALL_BANDS); assertThat(mPreference.getSummary()).isEqualTo(ALL_BANDS);
verify(mListener, times(2)).onTetherConfigUpdated(); verify(mListener, times(2)).onTetherConfigUpdated(mController);
// set to 2 Ghz // set to 2 Ghz
mController.onPreferenceChange(mPreference, "0"); mController.onPreferenceChange(mPreference, "0");
assertThat(mController.getBandIndex()).isEqualTo(0); assertThat(mController.getBandIndex()).isEqualTo(0);
assertThat(mPreference.getSummary()).isEqualTo(TWO_GHZ_STRING); assertThat(mPreference.getSummary()).isEqualTo(TWO_GHZ_STRING);
verify(mListener, times(3)).onTetherConfigUpdated(); verify(mListener, times(3)).onTetherConfigUpdated(mController);
} }
@Test @Test

View File

@@ -99,7 +99,7 @@ public class WifiTetherPasswordPreferenceControllerTest {
assertThat(mController.getPasswordValidated(WifiConfiguration.KeyMgmt.WPA2_PSK)) assertThat(mController.getPasswordValidated(WifiConfiguration.KeyMgmt.WPA2_PSK))
.isEqualTo(VALID_PASS2); .isEqualTo(VALID_PASS2);
verify(mListener, times(2)).onTetherConfigUpdated(); verify(mListener, times(2)).onTetherConfigUpdated(mController);
} }
@Test @Test

View File

@@ -102,7 +102,7 @@ public class WifiTetherSSIDPreferenceControllerTest {
mController.onPreferenceChange(mPreference, "0"); mController.onPreferenceChange(mPreference, "0");
assertThat(mController.getSSID()).isEqualTo("0"); assertThat(mController.getSSID()).isEqualTo("0");
verify(mListener, times(2)).onTetherConfigUpdated(); verify(mListener, times(2)).onTetherConfigUpdated(mController);
} }
@Test @Test