Merge "Update add network dialog to not make networks hidden by default" into pi-dev

This commit is contained in:
Salvador Martinez
2018-03-30 22:22:59 +00:00
committed by Android (Google) Code Review
5 changed files with 76 additions and 2 deletions

View File

@@ -15,6 +15,7 @@
--> -->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dialog_scrollview"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:fadeScrollbars="false" android:fadeScrollbars="false"
@@ -600,6 +601,33 @@
android:checked="true" /> android:checked="true" />
</LinearLayout> </LinearLayout>
</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>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>

View File

@@ -1075,6 +1075,11 @@
<item>Treat as unmetered</item> <item>Treat as unmetered</item>
</string-array> </string-array>
<string-array name="wifi_hidden_entries">
<item>No</item>
<item>Yes</item>
</string-array>
<string-array name="wifi_metered_values" translatable="false"> <string-array name="wifi_metered_values" translatable="false">
<item>0</item> <item>0</item>
<item>1</item> <item>1</item>

View File

@@ -1936,7 +1936,7 @@
<!-- Label for the hidden network status of this network --> <!-- Label for the hidden network status of this network -->
<string name="wifi_hidden_network">Hidden network</string> <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" --> <!-- 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 --> <!-- Label for the signal strength of the connection -->
<string name="wifi_signal">Signal strength</string> <string name="wifi_signal">Signal strength</string>
<!-- Label for the status of the connection --> <!-- Label for the status of the connection -->

View File

@@ -55,6 +55,7 @@ import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ScrollView;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
@@ -89,6 +90,10 @@ public class WifiConfigController implements TextWatcher,
private static final int DHCP = 0; private static final int DHCP = 0;
private static final int STATIC_IP = 1; 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 */ /* These values come from "wifi_proxy_settings" resource array */
public static final int PROXY_NONE = 0; public static final int PROXY_NONE = 0;
public static final int PROXY_STATIC = 1; public static final int PROXY_STATIC = 1;
@@ -127,6 +132,7 @@ public class WifiConfigController implements TextWatcher,
private String mDoNotProvideEapUserCertString; private String mDoNotProvideEapUserCertString;
private String mDoNotValidateEapServerString; private String mDoNotValidateEapServerString;
private ScrollView mDialogContainer;
private Spinner mSecuritySpinner; private Spinner mSecuritySpinner;
private Spinner mEapMethodSpinner; private Spinner mEapMethodSpinner;
private Spinner mEapCaCertSpinner; private Spinner mEapCaCertSpinner;
@@ -147,6 +153,8 @@ public class WifiConfigController implements TextWatcher,
private Spinner mProxySettingsSpinner; private Spinner mProxySettingsSpinner;
private Spinner mMeteredSettingsSpinner; private Spinner mMeteredSettingsSpinner;
private Spinner mHiddenSettingsSpinner;
private TextView mHiddenWarningView;
private TextView mProxyHostView; private TextView mProxyHostView;
private TextView mProxyPortView; private TextView mProxyPortView;
private TextView mProxyExclusionListView; private TextView mProxyExclusionListView;
@@ -203,12 +211,20 @@ public class WifiConfigController implements TextWatcher,
mDoNotValidateEapServerString = mDoNotValidateEapServerString =
mContext.getString(R.string.wifi_do_not_validate_eap_server); 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 = (Spinner) mView.findViewById(R.id.ip_settings);
mIpSettingsSpinner.setOnItemSelectedListener(this); mIpSettingsSpinner.setOnItemSelectedListener(this);
mProxySettingsSpinner = (Spinner) mView.findViewById(R.id.proxy_settings); mProxySettingsSpinner = (Spinner) mView.findViewById(R.id.proxy_settings);
mProxySettingsSpinner.setOnItemSelectedListener(this); mProxySettingsSpinner.setOnItemSelectedListener(this);
mSharedCheckBox = (CheckBox) mView.findViewById(R.id.shared); mSharedCheckBox = (CheckBox) mView.findViewById(R.id.shared);
mMeteredSettingsSpinner = mView.findViewById(R.id.metered_settings); 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 if (mAccessPoint == null) { // new network
mConfigUi.setTitle(R.string.wifi_add_network); mConfigUi.setTitle(R.string.wifi_add_network);
@@ -239,6 +255,9 @@ public class WifiConfigController implements TextWatcher,
if (mAccessPoint.isSaved()) { if (mAccessPoint.isSaved()) {
WifiConfiguration config = mAccessPoint.getConfig(); WifiConfiguration config = mAccessPoint.getConfig();
mMeteredSettingsSpinner.setSelection(config.meteredOverride); mMeteredSettingsSpinner.setSelection(config.meteredOverride);
mHiddenSettingsSpinner.setSelection(config.hiddenSSID
? HIDDEN_NETWORK
: NOT_HIDDEN_NETWORK);
if (config.getIpAssignment() == IpAssignment.STATIC) { if (config.getIpAssignment() == IpAssignment.STATIC) {
mIpSettingsSpinner.setSelection(STATIC_IP); mIpSettingsSpinner.setSelection(STATIC_IP);
showAdvancedFields = true; showAdvancedFields = true;
@@ -514,7 +533,7 @@ public class WifiConfigController implements TextWatcher,
config.SSID = AccessPoint.convertToQuotedString( config.SSID = AccessPoint.convertToQuotedString(
mSsidView.getText().toString()); mSsidView.getText().toString());
// If the user adds a network manually, assume that it is hidden. // 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()) { } else if (!mAccessPoint.isSaved()) {
config.SSID = AccessPoint.convertToQuotedString( config.SSID = AccessPoint.convertToQuotedString(
mAccessPoint.getSsidStr()); mAccessPoint.getSsidStr());
@@ -1350,6 +1369,16 @@ public class WifiConfigController implements TextWatcher,
showPeapFields(); showPeapFields();
} else if (parent == mProxySettingsSpinner) { } else if (parent == mProxySettingsSpinner) {
showProxyFields(); 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 { } else {
showIpConfigFields(); showIpConfigFields();
} }

View File

@@ -61,6 +61,7 @@ public class WifiConfigControllerTest {
private AccessPoint mAccessPoint; private AccessPoint mAccessPoint;
@Mock @Mock
private KeyStore mKeyStore; private KeyStore mKeyStore;
private Spinner mHiddenSettingsSpinner;
public WifiConfigController mController; public WifiConfigController mController;
private static final String HEX_PSK = "01234567012345670123456701234567012345670123456701234567" private static final String HEX_PSK = "01234567012345670123456701234567012345670123456701234567"
@@ -82,6 +83,7 @@ public class WifiConfigControllerTest {
when(mAccessPoint.getSecurity()).thenReturn(AccessPoint.SECURITY_PSK); when(mAccessPoint.getSecurity()).thenReturn(AccessPoint.SECURITY_PSK);
mView = LayoutInflater.from(mContext).inflate(R.layout.wifi_dialog, null); mView = LayoutInflater.from(mContext).inflate(R.layout.wifi_dialog, null);
final Spinner ipSettingsSpinner = mView.findViewById(R.id.ip_settings); final Spinner ipSettingsSpinner = mView.findViewById(R.id.ip_settings);
mHiddenSettingsSpinner = mView.findViewById(R.id.hidden_settings);
ipSettingsSpinner.setSelection(DHCP); ipSettingsSpinner.setSelection(DHCP);
mController = new TestWifiConfigController(mConfigUiBase, mView, mAccessPoint, mController = new TestWifiConfigController(mConfigUiBase, mView, mAccessPoint,
@@ -246,6 +248,16 @@ public class WifiConfigControllerTest {
assertThat(password.isFocused()).isTrue(); 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 { public class TestWifiConfigController extends WifiConfigController {
private TestWifiConfigController( private TestWifiConfigController(