From 8bc3fa0649a3ecff5e42fb0d14ddb8ff6f7f7507 Mon Sep 17 00:00:00 2001 From: Salvador Martinez Date: Thu, 29 Mar 2018 21:29:30 -0700 Subject: [PATCH] Update add network dialog to not make networks hidden by default This CL updates the add network dialog to use the provided value for the hidden state (from androids perspective) of the network. The default selected value will always be not hidden and if the user selects to mark it as hidden a warning will appear to inform the user of the privacy implications. Test: Robotests Bug: 29003359 Change-Id: Ifd4511e4d0af6eb01f4e951c22a91fc560393e8d --- res/layout/wifi_dialog.xml | 28 +++++++++++++++++ res/values/arrays.xml | 5 +++ res/values/strings.xml | 2 +- .../settings/wifi/WifiConfigController.java | 31 ++++++++++++++++++- .../wifi/WifiConfigControllerTest.java | 12 +++++++ 5 files changed, 76 insertions(+), 2 deletions(-) diff --git a/res/layout/wifi_dialog.xml b/res/layout/wifi_dialog.xml index 9f8d035cce1..16c8c22de38 100644 --- a/res/layout/wifi_dialog.xml +++ b/res/layout/wifi_dialog.xml @@ -15,6 +15,7 @@ --> + + + + + + + + + diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 4efd4e064a6..a477a1cb3b7 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -1075,6 +1075,11 @@ Treat as unmetered + + No + Yes + + 0 1 diff --git a/res/values/strings.xml b/res/values/strings.xml index 604a49f5f25..cda932c8027 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1936,7 +1936,7 @@ Hidden network - Hidden network might create privacy risk as this device has to broadcast this SSID name in order to connect. + If your router is not broadcasting a network ID but you would like to connect to it in the future, you can set the network as hidden.\n\nThis may create a security risk because your phone will regularly broadcast its signal to find the network.\n\nSetting the network as hidden will not change your router settings. Signal strength diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java index cf26f8a8ef5..db657f90149 100644 --- a/src/com/android/settings/wifi/WifiConfigController.java +++ b/src/com/android/settings/wifi/WifiConfigController.java @@ -55,6 +55,7 @@ import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.EditText; +import android.widget.ScrollView; import android.widget.Spinner; import android.widget.TextView; @@ -89,6 +90,10 @@ public class WifiConfigController implements TextWatcher, private static final int DHCP = 0; private static final int STATIC_IP = 1; + /* Constants used for referring to the hidden state of a network. */ + public static final int HIDDEN_NETWORK = 1; + public static final int NOT_HIDDEN_NETWORK = 0; + /* These values come from "wifi_proxy_settings" resource array */ public static final int PROXY_NONE = 0; public static final int PROXY_STATIC = 1; @@ -127,6 +132,7 @@ public class WifiConfigController implements TextWatcher, private String mDoNotProvideEapUserCertString; private String mDoNotValidateEapServerString; + private ScrollView mDialogContainer; private Spinner mSecuritySpinner; private Spinner mEapMethodSpinner; private Spinner mEapCaCertSpinner; @@ -147,6 +153,8 @@ public class WifiConfigController implements TextWatcher, private Spinner mProxySettingsSpinner; private Spinner mMeteredSettingsSpinner; + private Spinner mHiddenSettingsSpinner; + private TextView mHiddenWarningView; private TextView mProxyHostView; private TextView mProxyPortView; private TextView mProxyExclusionListView; @@ -203,12 +211,20 @@ public class WifiConfigController implements TextWatcher, mDoNotValidateEapServerString = mContext.getString(R.string.wifi_do_not_validate_eap_server); + mDialogContainer = mView.findViewById(R.id.dialog_scrollview); mIpSettingsSpinner = (Spinner) mView.findViewById(R.id.ip_settings); mIpSettingsSpinner.setOnItemSelectedListener(this); mProxySettingsSpinner = (Spinner) mView.findViewById(R.id.proxy_settings); mProxySettingsSpinner.setOnItemSelectedListener(this); mSharedCheckBox = (CheckBox) mView.findViewById(R.id.shared); mMeteredSettingsSpinner = mView.findViewById(R.id.metered_settings); + mHiddenSettingsSpinner = mView.findViewById(R.id.hidden_settings); + mHiddenSettingsSpinner.setOnItemSelectedListener(this); + mHiddenWarningView = mView.findViewById(R.id.hidden_settings_warning); + mHiddenWarningView.setVisibility( + mHiddenSettingsSpinner.getSelectedItemPosition() == NOT_HIDDEN_NETWORK + ? View.GONE + : View.VISIBLE); if (mAccessPoint == null) { // new network mConfigUi.setTitle(R.string.wifi_add_network); @@ -239,6 +255,9 @@ public class WifiConfigController implements TextWatcher, if (mAccessPoint.isSaved()) { WifiConfiguration config = mAccessPoint.getConfig(); mMeteredSettingsSpinner.setSelection(config.meteredOverride); + mHiddenSettingsSpinner.setSelection(config.hiddenSSID + ? HIDDEN_NETWORK + : NOT_HIDDEN_NETWORK); if (config.getIpAssignment() == IpAssignment.STATIC) { mIpSettingsSpinner.setSelection(STATIC_IP); showAdvancedFields = true; @@ -514,7 +533,7 @@ public class WifiConfigController implements TextWatcher, config.SSID = AccessPoint.convertToQuotedString( mSsidView.getText().toString()); // If the user adds a network manually, assume that it is hidden. - config.hiddenSSID = true; + config.hiddenSSID = mHiddenSettingsSpinner.getSelectedItemPosition() == HIDDEN_NETWORK; } else if (!mAccessPoint.isSaved()) { config.SSID = AccessPoint.convertToQuotedString( mAccessPoint.getSsidStr()); @@ -1350,6 +1369,16 @@ public class WifiConfigController implements TextWatcher, showPeapFields(); } else if (parent == mProxySettingsSpinner) { showProxyFields(); + } else if (parent == mHiddenSettingsSpinner) { + mHiddenWarningView.setVisibility( + position == NOT_HIDDEN_NETWORK + ? View.GONE + : View.VISIBLE); + if (position == HIDDEN_NETWORK) { + mDialogContainer.post(() -> { + mDialogContainer.fullScroll(View.FOCUS_DOWN); + }); + } } else { showIpConfigFields(); } diff --git a/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java index 559a9ea8882..3b41d3852b4 100644 --- a/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java +++ b/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java @@ -61,6 +61,7 @@ public class WifiConfigControllerTest { private AccessPoint mAccessPoint; @Mock private KeyStore mKeyStore; + private Spinner mHiddenSettingsSpinner; public WifiConfigController mController; private static final String HEX_PSK = "01234567012345670123456701234567012345670123456701234567" @@ -82,6 +83,7 @@ public class WifiConfigControllerTest { when(mAccessPoint.getSecurity()).thenReturn(AccessPoint.SECURITY_PSK); mView = LayoutInflater.from(mContext).inflate(R.layout.wifi_dialog, null); final Spinner ipSettingsSpinner = mView.findViewById(R.id.ip_settings); + mHiddenSettingsSpinner = mView.findViewById(R.id.hidden_settings); ipSettingsSpinner.setSelection(DHCP); mController = new TestWifiConfigController(mConfigUiBase, mView, mAccessPoint, @@ -246,6 +248,16 @@ public class WifiConfigControllerTest { assertThat(password.isFocused()).isTrue(); } + @Test + public void hiddenWarning_warningVisibilityProperlyUpdated() { + View warningView = mView.findViewById(R.id.hidden_settings_warning); + mController.onItemSelected(mHiddenSettingsSpinner, null, mController.HIDDEN_NETWORK, 0); + assertThat(warningView.getVisibility()).isEqualTo(View.VISIBLE); + + mController.onItemSelected(mHiddenSettingsSpinner, null, mController.NOT_HIDDEN_NETWORK, 0); + assertThat(warningView.getVisibility()).isEqualTo(View.GONE); + } + public class TestWifiConfigController extends WifiConfigController { private TestWifiConfigController(