OSDN Git Service

Update add network dialog to not make networks hidden by default
authorSalvador Martinez <dehboxturtle@google.com>
Fri, 30 Mar 2018 04:29:30 +0000 (21:29 -0700)
committerSalvador Martinez <dehboxturtle@google.com>
Fri, 30 Mar 2018 06:01:24 +0000 (23:01 -0700)
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
res/values/arrays.xml
res/values/strings.xml
src/com/android/settings/wifi/WifiConfigController.java
tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java

index 9f8d035..16c8c22 100644 (file)
@@ -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"
                             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>
index 4efd4e0..a477a1c 100644 (file)
         <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>
index 604a49f..cda932c 100644 (file)
     <!-- 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 -->
index cf26f8a..db657f9 100644 (file)
@@ -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();
         }
index 559a9ea..3b41d38 100644 (file)
@@ -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(