Fix advanced preferences behavior in AllInOneTetherSettings

In AllInOneTetherSettings, advanced preferences should not be hidden
again after user have expanded them.

Bug: 151954343
Test: CodeInspectionTest; AllInOneTetherSettingsTest; manually test oberved advanced preferences won't be hidden.
Change-Id: If2c7d99b7dcac4149f065eca73022a582924c90b
This commit is contained in:
Zhen Zhang
2020-03-25 13:33:45 -07:00
parent df338dd652
commit b1d19a8b35
2 changed files with 42 additions and 13 deletions

View File

@@ -91,8 +91,12 @@ public class AllInOneTetherSettings extends RestrictedDashboardFragment
private static final String KEY_DATA_SAVER_FOOTER = "disabled_on_data_saver" + DEDUP_POSTFIX; private static final String KEY_DATA_SAVER_FOOTER = "disabled_on_data_saver" + DEDUP_POSTFIX;
private static final String KEY_WIFI_TETHER_GROUP = "wifi_tether_settings_group"; private static final String KEY_WIFI_TETHER_GROUP = "wifi_tether_settings_group";
private static final int EXPANDED_CHILD_COUNT_WITH_SECURITY_NON = 2; @VisibleForTesting
private static final int EXPANDED_CHILD_COUNT_DEFAULT = 3; static final int EXPANDED_CHILD_COUNT_DEFAULT = 3;
@VisibleForTesting
static final int EXPANDED_CHILD_COUNT_WITH_SECURITY_NON = 2;
@VisibleForTesting
static final int EXPANDED_CHILD_COUNT_WITHOUT_WIFI_CONFIG = 3;
private static final String TAG = "AllInOneTetherSettings"; private static final String TAG = "AllInOneTetherSettings";
private boolean mUnavailable; private boolean mUnavailable;
@@ -120,7 +124,6 @@ public class AllInOneTetherSettings extends RestrictedDashboardFragment
mUsbTethering = TetherEnabler.isUsbTethering(state); mUsbTethering = TetherEnabler.isUsbTethering(state);
mWifiTethering = TetherEnabler.isWifiTethering(state); mWifiTethering = TetherEnabler.isWifiTethering(state);
mWifiTetherGroup.setVisible(shouldShowWifiConfig()); mWifiTetherGroup.setVisible(shouldShowWifiConfig());
reConfigInitialExpandedChildCount();
}; };
private final BroadcastReceiver mTetherChangeReceiver = new BroadcastReceiver() { private final BroadcastReceiver mTetherChangeReceiver = new BroadcastReceiver() {
@@ -354,10 +357,6 @@ public class AllInOneTetherSettings extends RestrictedDashboardFragment
mRestartWifiApAfterConfigChange = true; mRestartWifiApAfterConfigChange = true;
mTetherEnabler.stopTethering(TETHERING_WIFI); mTetherEnabler.stopTethering(TETHERING_WIFI);
} }
if (controller instanceof WifiTetherSecurityPreferenceController) {
reConfigInitialExpandedChildCount();
}
} }
private SoftApConfiguration buildNewConfig() { private SoftApConfiguration buildNewConfig() {
@@ -384,15 +383,10 @@ public class AllInOneTetherSettings extends RestrictedDashboardFragment
return mWifiTethering || (!mBluetoothTethering && !mUsbTethering); return mWifiTethering || (!mBluetoothTethering && !mUsbTethering);
} }
private void reConfigInitialExpandedChildCount() {
getPreferenceScreen().setInitialExpandedChildrenCount(getInitialExpandedChildCount());
}
@Override @Override
public int getInitialExpandedChildCount() { public int getInitialExpandedChildCount() {
if (!shouldShowWifiConfig()) { if (!shouldShowWifiConfig()) {
// Expand all preferences in the screen. return EXPANDED_CHILD_COUNT_WITHOUT_WIFI_CONFIG;
return getPreferenceScreen().getPreferenceCount();
} }
if (mSecurityPreferenceController == null) { if (mSecurityPreferenceController == null) {

View File

@@ -16,6 +16,9 @@
package com.android.settings; package com.android.settings;
import static com.android.settings.AllInOneTetherSettings.EXPANDED_CHILD_COUNT_DEFAULT;
import static com.android.settings.AllInOneTetherSettings.EXPANDED_CHILD_COUNT_WITHOUT_WIFI_CONFIG;
import static com.android.settings.AllInOneTetherSettings.EXPANDED_CHILD_COUNT_WITH_SECURITY_NON;
import static com.android.settings.network.TetherEnabler.BLUETOOTH_TETHER_KEY; import static com.android.settings.network.TetherEnabler.BLUETOOTH_TETHER_KEY;
import static com.android.settings.network.TetherEnabler.USB_TETHER_KEY; import static com.android.settings.network.TetherEnabler.USB_TETHER_KEY;
import static com.android.settings.network.TetherEnabler.WIFI_TETHER_DISABLE_KEY; import static com.android.settings.network.TetherEnabler.WIFI_TETHER_DISABLE_KEY;
@@ -29,6 +32,7 @@ import static org.mockito.Mockito.when;
import android.content.Context; import android.content.Context;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.wifi.SoftApConfiguration;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
import android.util.FeatureFlagUtils; import android.util.FeatureFlagUtils;
@@ -36,6 +40,7 @@ import android.util.FeatureFlagUtils;
import com.android.settings.core.FeatureFlags; import com.android.settings.core.FeatureFlags;
import com.android.settings.testutils.shadow.ShadowWifiManager; import com.android.settings.testutils.shadow.ShadowWifiManager;
import com.android.settings.wifi.tether.WifiTetherAutoOffPreferenceController; import com.android.settings.wifi.tether.WifiTetherAutoOffPreferenceController;
import com.android.settings.wifi.tether.WifiTetherSecurityPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before; import org.junit.Before;
@@ -65,6 +70,8 @@ public class AllInOneTetherSettingsTest {
private ConnectivityManager mConnectivityManager; private ConnectivityManager mConnectivityManager;
@Mock @Mock
private UserManager mUserManager; private UserManager mUserManager;
@Mock
private WifiTetherSecurityPreferenceController mSecurityPreferenceController;
@Before @Before
public void setUp() { public void setUp() {
@@ -82,6 +89,8 @@ public class AllInOneTetherSettingsTest {
mAllInOneTetherSettings = new AllInOneTetherSettings(); mAllInOneTetherSettings = new AllInOneTetherSettings();
ReflectionHelpers.setField(mAllInOneTetherSettings, "mLifecycle", mock(Lifecycle.class)); ReflectionHelpers.setField(mAllInOneTetherSettings, "mLifecycle", mock(Lifecycle.class));
ReflectionHelpers.setField(mAllInOneTetherSettings, "mSecurityPreferenceController",
mSecurityPreferenceController);
} }
@Test @Test
@@ -157,6 +166,32 @@ public class AllInOneTetherSettingsTest {
.isEqualTo(1); .isEqualTo(1);
} }
@Test
public void getInitialExpandedChildCount_shouldShowWifiConfigWithSecurity() {
ReflectionHelpers.setField(mAllInOneTetherSettings, "mWifiTethering", true);
when(mSecurityPreferenceController.getSecurityType())
.thenReturn(SoftApConfiguration.SECURITY_TYPE_WPA2_PSK);
assertThat(mAllInOneTetherSettings.getInitialExpandedChildCount())
.isEqualTo(EXPANDED_CHILD_COUNT_DEFAULT);
}
@Test
public void getInitialExpandedChildCount_shouldShowWifiConfigWithoutSecurity() {
ReflectionHelpers.setField(mAllInOneTetherSettings, "mWifiTethering", true);
when(mSecurityPreferenceController.getSecurityType())
.thenReturn(SoftApConfiguration.SECURITY_TYPE_OPEN);
assertThat(mAllInOneTetherSettings.getInitialExpandedChildCount())
.isEqualTo(EXPANDED_CHILD_COUNT_WITH_SECURITY_NON);
}
@Test
public void getInitialExpandedChildCount_shouldNotShowWifiConfig() {
ReflectionHelpers.setField(mAllInOneTetherSettings, "mWifiTethering", false);
ReflectionHelpers.setField(mAllInOneTetherSettings, "mBluetoothTethering", true);
assertThat(mAllInOneTetherSettings.getInitialExpandedChildCount())
.isEqualTo(EXPANDED_CHILD_COUNT_WITHOUT_WIFI_CONFIG);
}
private void setupIsTetherAvailable(boolean returnValue) { private void setupIsTetherAvailable(boolean returnValue) {
when(mConnectivityManager.isTetheringSupported()).thenReturn(true); when(mConnectivityManager.isTetheringSupported()).thenReturn(true);