From 0ce5e177929bd9794667fa3b192d1dbcbf74feb7 Mon Sep 17 00:00:00 2001 From: pkanwar Date: Tue, 18 Jul 2017 13:39:53 -0700 Subject: [PATCH] Add support for carrier wifi in UI. Make changes to the UI, so that it does not ask for additional information while connecting to Carrier Wifi. Also, indicate in wifi picker if the wifi is a carrier network. Bug:30988281 Test: make RunSettingsRoboTests -j40 ROBOTEST_FILTER=WifiConfigControllerTest Test: manual Change-Id: Iecbcd77d400264aaaa16a6a95a2093d58f2748f9 --- .../settings/wifi/WifiConfigController.java | 19 +++++++++++- .../wifi/WifiConfigControllerTest.java | 31 ++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java index 6f873426db0..1aabe5c9688 100644 --- a/src/com/android/settings/wifi/WifiConfigController.java +++ b/src/com/android/settings/wifi/WifiConfigController.java @@ -281,11 +281,17 @@ public class WifiConfigController implements TextWatcher, showProxyFields(); final CheckBox advancedTogglebox = (CheckBox) mView.findViewById(R.id.wifi_advanced_togglebox); - mView.findViewById(R.id.wifi_advanced_toggle).setVisibility(View.VISIBLE); + mView.findViewById(R.id.wifi_advanced_toggle).setVisibility( + mAccessPoint.isCarrierAp() ? View.GONE : View.VISIBLE); advancedTogglebox.setOnCheckedChangeListener(this); advancedTogglebox.setChecked(showAdvancedFields); mView.findViewById(R.id.wifi_advanced_fields) .setVisibility(showAdvancedFields ? View.VISIBLE : View.GONE); + if (mAccessPoint.isCarrierAp()) { + addRow(group, R.string.wifi_carrier_connect, + String.format(mContext.getString(R.string.wifi_carrier_content), + mAccessPoint.getCarrierName())); + } } if (mMode == WifiConfigUiBase.MODE_MODIFY) { @@ -845,6 +851,10 @@ public class WifiConfigController implements TextWatcher, mEapIdentityView = (TextView) mView.findViewById(R.id.identity); mEapAnonymousView = (TextView) mView.findViewById(R.id.anonymous); + if (mAccessPoint.isCarrierAp()) { + mEapMethodSpinner.setSelection(mAccessPoint.getCarrierApEapType()); + } + loadCertificates( mEapCaCertSpinner, Credentials.CA_CERTIFICATE, @@ -1012,6 +1022,9 @@ public class WifiConfigController implements TextWatcher, setUserCertInvisible(); setPasswordInvisible(); setIdentityInvisible(); + if (mAccessPoint.isCarrierAp()) { + setEapMethodInvisible(); + } break; } @@ -1077,6 +1090,10 @@ public class WifiConfigController implements TextWatcher, mView.findViewById(R.id.show_password_layout).setVisibility(View.GONE); } + private void setEapMethodInvisible() { + mView.findViewById(R.id.eap).setVisibility(View.GONE); + } + private void showIpConfigFields() { WifiConfiguration config = null; diff --git a/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java index b45ea1edaed..3dcdc9175ee 100644 --- a/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java +++ b/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java @@ -19,6 +19,7 @@ package com.android.settings.wifi; import android.content.Context; import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.widget.Spinner; import android.widget.TextView; @@ -37,7 +38,7 @@ import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; import static com.google.common.truth.Truth.assertThat; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; @RunWith(SettingsRobolectricTestRunner.class) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, @@ -161,6 +162,34 @@ public class WifiConfigControllerTest { assertThat(mController.getSignalString()).isNull(); } + @Test + public void showForCarrierAp() { + // Setup the mock view for wifi dialog. + View view = mock(View.class); + TextView nameText = mock(TextView.class); + TextView valueText = mock(TextView.class); + when(view.findViewById(R.id.name)).thenReturn(nameText); + when(view.findViewById(R.id.value)).thenReturn(valueText); + LayoutInflater inflater = mock(LayoutInflater.class); + when(inflater.inflate(anyInt(), any(ViewGroup.class), anyBoolean())).thenReturn(view); + when(mConfigUiBase.getLayoutInflater()).thenReturn(inflater); + + String carrierName = "Test Carrier"; + when(mAccessPoint.isCarrierAp()).thenReturn(true); + when(mAccessPoint.getCarrierName()).thenReturn(carrierName); + mController = new TestWifiConfigController(mConfigUiBase, mView, mAccessPoint, + WifiConfigUiBase.MODE_CONNECT); + // Verify the content of the text fields. + verify(nameText).setText(R.string.wifi_carrier_connect); + verify(valueText).setText( + String.format(mContext.getString(R.string.wifi_carrier_content), carrierName)); + // Verify that the advance toggle is not visible. + assertThat(mView.findViewById(R.id.wifi_advanced_toggle).getVisibility()) + .isEqualTo(View.GONE); + // Verify that the EAP method menu is not visible. + assertThat(mView.findViewById(R.id.eap).getVisibility()).isEqualTo(View.GONE); + } + public class TestWifiConfigController extends WifiConfigController { public TestWifiConfigController(WifiConfigUiBase parent, View view,