[Wi-Fi HotSpot] Improve Wi-Fi hotspot settings entries visibility problem
When the security type of hotspot changed, the hidden item will showed because of the Expanded child list is set as constant. To improve it, dynamicall adjust the Expanded child count according to the security type. Bug: 138594907 Test: Manually 1. Enter Settings APP -> Network & internet -> Hotspot & tethering ->Wi-Fi hotspot 2. Check if there are only two expanded items if the Security type is None, or three expaned items if the Security type is WPA2-personal 3. Change the Security type and back to check item 2 match or not. Change-Id: I84d1c5dca94d6a218cfc7ecd57e201e1cffdd878
This commit is contained in:
@@ -20,8 +20,7 @@
|
||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||
android:key="wifi_tether_settings_screen"
|
||||
android:title="@string/wifi_hotspot_checkbox_text"
|
||||
settings:searchable="false"
|
||||
settings:initialExpandedChildrenCount="3">
|
||||
settings:searchable="false">
|
||||
|
||||
<com.android.settings.wifi.tether.WifiTetherSsidPreference
|
||||
android:key="wifi_tether_network_name"
|
||||
|
@@ -90,7 +90,7 @@ public class WifiTetherApBandPreferenceController extends WifiTetherBasePreferen
|
||||
mBandIndex = validateSelection(Integer.parseInt((String) newValue));
|
||||
Log.d(TAG, "Band preference changed, updating band index to " + mBandIndex);
|
||||
preference.setSummary(getConfigSummary());
|
||||
mListener.onTetherConfigUpdated();
|
||||
mListener.onTetherConfigUpdated(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -30,7 +30,7 @@ public abstract class WifiTetherBasePreferenceController extends AbstractPrefere
|
||||
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
|
||||
|
||||
public interface OnTetherConfigUpdateListener {
|
||||
void onTetherConfigUpdated();
|
||||
void onTetherConfigUpdated(AbstractPreferenceController context);
|
||||
}
|
||||
|
||||
protected final WifiManager mWifiManager;
|
||||
|
@@ -65,7 +65,7 @@ public class WifiTetherPasswordPreferenceController extends WifiTetherBasePrefer
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
mPassword = (String) newValue;
|
||||
updatePasswordDisplay((EditTextPreference) mPreference);
|
||||
mListener.onTetherConfigUpdated();
|
||||
mListener.onTetherConfigUpdated(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -93,7 +93,7 @@ public class WifiTetherSSIDPreferenceController extends WifiTetherBasePreference
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
mSSID = (String) newValue;
|
||||
updateSsidDisplay((EditTextPreference) preference);
|
||||
mListener.onTetherConfigUpdated();
|
||||
mListener.onTetherConfigUpdated(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -45,7 +45,7 @@ public class WifiTetherSecurityPreferenceController extends WifiTetherBasePrefer
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
mSecurityValue = Integer.parseInt((String) newValue);
|
||||
preference.setSummary(getSummaryForSecurityType(mSecurityValue));
|
||||
mListener.onTetherConfigUpdated();
|
||||
mListener.onTetherConfigUpdated(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -30,9 +30,8 @@ import android.os.Bundle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import androidx.preference.PreferenceGroup;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
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.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -54,6 +52,9 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
|
||||
private static final String TAG = "WifiTetherSettings";
|
||||
private static final IntentFilter TETHER_STATE_CHANGE_FILTER;
|
||||
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
|
||||
static final String KEY_WIFI_TETHER_NETWORK_NAME = "wifi_tether_network_name";
|
||||
@VisibleForTesting
|
||||
@@ -185,7 +186,7 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTetherConfigUpdated() {
|
||||
public void onTetherConfigUpdated(AbstractPreferenceController context) {
|
||||
final WifiConfiguration config = buildNewConfig();
|
||||
mPasswordPreferenceController.updateVisibility(config.getAuthType());
|
||||
|
||||
@@ -201,6 +202,10 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
|
||||
mSwitchBarController.stopTether();
|
||||
}
|
||||
mWifiManager.setWifiApConfiguration(config);
|
||||
|
||||
if (context instanceof WifiTetherSecurityPreferenceController) {
|
||||
reConfigInitialExpandedChildCount();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -128,19 +128,19 @@ public class WifiTetherApBandPreferenceControllerTest {
|
||||
mController.onPreferenceChange(mPreference, "-1");
|
||||
assertThat(mController.getBandIndex()).isEqualTo(1);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(FIVE_GHZ_STRING);
|
||||
verify(mListener, times(1)).onTetherConfigUpdated();
|
||||
verify(mListener, times(1)).onTetherConfigUpdated(mController);
|
||||
|
||||
// set to 5 Ghz
|
||||
mController.onPreferenceChange(mPreference, "1");
|
||||
assertThat(mController.getBandIndex()).isEqualTo(1);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(FIVE_GHZ_STRING);
|
||||
verify(mListener, times(2)).onTetherConfigUpdated();
|
||||
verify(mListener, times(2)).onTetherConfigUpdated(mController);
|
||||
|
||||
// set to 2 Ghz
|
||||
mController.onPreferenceChange(mPreference, "0");
|
||||
assertThat(mController.getBandIndex()).isEqualTo(0);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(TWO_GHZ_STRING);
|
||||
verify(mListener, times(3)).onTetherConfigUpdated();
|
||||
verify(mListener, times(3)).onTetherConfigUpdated(mController);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -155,19 +155,19 @@ public class WifiTetherApBandPreferenceControllerTest {
|
||||
mController.onPreferenceChange(mPreference, "-1");
|
||||
assertThat(mController.getBandIndex()).isEqualTo(-1);
|
||||
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
|
||||
mController.onPreferenceChange(mPreference, "1");
|
||||
assertThat(mController.getBandIndex()).isEqualTo(-1);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(ALL_BANDS);
|
||||
verify(mListener, times(2)).onTetherConfigUpdated();
|
||||
verify(mListener, times(2)).onTetherConfigUpdated(mController);
|
||||
|
||||
// set to 2 Ghz
|
||||
mController.onPreferenceChange(mPreference, "0");
|
||||
assertThat(mController.getBandIndex()).isEqualTo(0);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(TWO_GHZ_STRING);
|
||||
verify(mListener, times(3)).onTetherConfigUpdated();
|
||||
verify(mListener, times(3)).onTetherConfigUpdated(mController);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -99,7 +99,7 @@ public class WifiTetherPasswordPreferenceControllerTest {
|
||||
assertThat(mController.getPasswordValidated(WifiConfiguration.KeyMgmt.WPA2_PSK))
|
||||
.isEqualTo(VALID_PASS2);
|
||||
|
||||
verify(mListener, times(2)).onTetherConfigUpdated();
|
||||
verify(mListener, times(2)).onTetherConfigUpdated(mController);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -102,7 +102,7 @@ public class WifiTetherSSIDPreferenceControllerTest {
|
||||
mController.onPreferenceChange(mPreference, "0");
|
||||
assertThat(mController.getSSID()).isEqualTo("0");
|
||||
|
||||
verify(mListener, times(2)).onTetherConfigUpdated();
|
||||
verify(mListener, times(2)).onTetherConfigUpdated(mController);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user