Merge "Update add network dialog to not make networks hidden by default" into pi-dev
diff --git a/res/layout/wifi_dialog.xml b/res/layout/wifi_dialog.xml
index 9f8d035..16c8c22 100644
--- a/res/layout/wifi_dialog.xml
+++ b/res/layout/wifi_dialog.xml
@@ -15,6 +15,7 @@
-->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/dialog_scrollview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fadeScrollbars="false"
@@ -600,6 +601,33 @@
android:checked="true" />
</LinearLayout>
</LinearLayout>
+
+ <LinearLayout android:id="@+id/hidden_settings_field"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ style="@style/wifi_item">
+
+ <TextView android:id="@+id/hidden_settings_title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ style="@style/wifi_item_label"
+ android:text="@string/wifi_hidden_network" />
+
+ <Spinner android:id="@+id/hidden_settings"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ style="@style/wifi_item_spinner"
+ android:prompt="@string/wifi_hidden_network"
+ android:entries="@array/wifi_hidden_entries"/>
+
+ <TextView android:id="@+id/hidden_settings_warning"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:padding="8dp"
+ android:text="@string/wifi_hidden_network_warning"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:visibility="gone"/>
+ </LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index 4efd4e0..a477a1c 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -1075,6 +1075,11 @@
<item>Treat as unmetered</item>
</string-array>
+ <string-array name="wifi_hidden_entries">
+ <item>No</item>
+ <item>Yes</item>
+ </string-array>
+
<string-array name="wifi_metered_values" translatable="false">
<item>0</item>
<item>1</item>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 2857e6d..5638091 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1936,7 +1936,7 @@
<!-- Label for the hidden network status of this network -->
<string name="wifi_hidden_network">Hidden network</string>
<!-- Label for the warning shown to users if they try to connect to a network as "hidden" -->
- <string name="wifi_hidden_network_warning">Hidden network might create privacy risk as this device has to broadcast this SSID name in order to connect.</string>
+ <string name="wifi_hidden_network_warning">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.</string>
<!-- Label for the signal strength of the connection -->
<string name="wifi_signal">Signal strength</string>
<!-- Label for the status of the connection -->
diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java
index cf26f8a..db657f9 100644
--- a/src/com/android/settings/wifi/WifiConfigController.java
+++ b/src/com/android/settings/wifi/WifiConfigController.java
@@ -55,6 +55,7 @@
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 @@
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 @@
private String mDoNotProvideEapUserCertString;
private String mDoNotValidateEapServerString;
+ private ScrollView mDialogContainer;
private Spinner mSecuritySpinner;
private Spinner mEapMethodSpinner;
private Spinner mEapCaCertSpinner;
@@ -147,6 +153,8 @@
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 @@
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 @@
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 @@
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 @@
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 559a9ea..3b41d38 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 @@
private AccessPoint mAccessPoint;
@Mock
private KeyStore mKeyStore;
+ private Spinner mHiddenSettingsSpinner;
public WifiConfigController mController;
private static final String HEX_PSK = "01234567012345670123456701234567012345670123456701234567"
@@ -82,6 +83,7 @@
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 @@
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(