Merge "Hide password for wifi tether" into pi-dev
diff --git a/src/com/android/settings/widget/ValidatedEditTextPreference.java b/src/com/android/settings/widget/ValidatedEditTextPreference.java
index 58c62eb..580eb58 100644
--- a/src/com/android/settings/widget/ValidatedEditTextPreference.java
+++ b/src/com/android/settings/widget/ValidatedEditTextPreference.java
@@ -19,6 +19,7 @@
 import android.app.AlertDialog;
 import android.content.Context;
 import android.support.annotation.VisibleForTesting;
+import android.support.v7.preference.PreferenceViewHolder;
 import android.text.Editable;
 import android.text.InputType;
 import android.text.TextUtils;
@@ -27,6 +28,7 @@
 import android.util.Log;
 import android.view.View;
 import android.widget.EditText;
+import android.widget.TextView;
 
 import com.android.settingslib.CustomEditTextPreference;
 
@@ -42,6 +44,7 @@
     private final EditTextWatcher mTextWatcher = new EditTextWatcher();
     private Validator mValidator;
     private boolean mIsPassword;
+    private boolean mIsSummaryPassword;
 
     public ValidatedEditTextPreference(Context context, AttributeSet attrs,
             int defStyleAttr, int defStyleRes) {
@@ -78,10 +81,25 @@
         }
     }
 
+    @Override
+    public void onBindViewHolder(PreferenceViewHolder holder) {
+        super.onBindViewHolder(holder);
+
+        final TextView textView = (TextView) holder.findViewById(android.R.id.summary);
+        if (textView != null && mIsSummaryPassword) {
+            textView.setInputType(
+                    InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
+        }
+    }
+
     public void setIsPassword(boolean isPassword) {
         mIsPassword = isPassword;
     }
 
+    public void setIsSummaryPassword(boolean isPassword) {
+        mIsSummaryPassword = isPassword;
+    }
+
     @VisibleForTesting(otherwise = VisibleForTesting.NONE)
     public boolean isPassword() {
         return mIsPassword;
diff --git a/src/com/android/settings/wifi/tether/WifiTetherPasswordPreferenceController.java b/src/com/android/settings/wifi/tether/WifiTetherPasswordPreferenceController.java
index eb65965..0e973ae 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherPasswordPreferenceController.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherPasswordPreferenceController.java
@@ -51,6 +51,7 @@
             Log.d(TAG, "Updating password in Preference, " + mPassword);
         }
         ((ValidatedEditTextPreference) mPreference).setValidator(this);
+        ((ValidatedEditTextPreference) mPreference).setIsSummaryPassword(true);
         updatePasswordDisplay((EditTextPreference) mPreference);
     }
 
diff --git a/tests/robotests/src/com/android/settings/widget/ValidatedEditTextPreferenceTest.java b/tests/robotests/src/com/android/settings/widget/ValidatedEditTextPreferenceTest.java
index c7cae0f..5ba9f8a 100644
--- a/tests/robotests/src/com/android/settings/widget/ValidatedEditTextPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/widget/ValidatedEditTextPreferenceTest.java
@@ -17,6 +17,7 @@
 package com.android.settings.widget;
 
 import static com.google.common.truth.Truth.assertThat;
+
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyInt;
 import static org.mockito.Mockito.never;
@@ -24,10 +25,12 @@
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
+import android.support.v7.preference.PreferenceViewHolder;
 import android.text.InputType;
 import android.text.TextWatcher;
 import android.view.View;
 import android.widget.EditText;
+import android.widget.TextView;
 
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 
@@ -37,6 +40,7 @@
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.RuntimeEnvironment;
+import org.robolectric.util.ReflectionHelpers;
 
 @RunWith(SettingsRobolectricTestRunner.class)
 public class ValidatedEditTextPreferenceTest {
@@ -46,11 +50,15 @@
     @Mock
     private ValidatedEditTextPreference.Validator mValidator;
 
+    private PreferenceViewHolder mViewHolder;
     private ValidatedEditTextPreference mPreference;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
+
+        mViewHolder = spy(PreferenceViewHolder.createInstanceForTests(
+                new View(RuntimeEnvironment.application)));
         mPreference = new ValidatedEditTextPreference(RuntimeEnvironment.application);
     }
 
@@ -111,4 +119,17 @@
                 & (InputType.TYPE_TEXT_VARIATION_PASSWORD | InputType.TYPE_CLASS_TEXT))
                 .isNotEqualTo(0);
     }
+
+    @Test
+    public void bindViewHolder_isPassword_shouldSetInputType() {
+        final TextView textView = spy(new TextView(RuntimeEnvironment.application));
+        when(mViewHolder.findViewById(android.R.id.summary)).thenReturn(textView);
+
+        mPreference.setIsSummaryPassword(true);
+        mPreference.onBindViewHolder(mViewHolder);
+
+        assertThat(textView.getInputType()
+                & (InputType.TYPE_TEXT_VARIATION_PASSWORD | InputType.TYPE_CLASS_TEXT))
+                .isNotEqualTo(0);
+    }
 }