• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

packages/apps/Settings


コミットメタ情報

リビジョン3b4744a6c1dfaf630c449d94bc23e79c94a7a757 (tree)
日時2020-11-14 15:32:55
作者Weng Su <wengsu@goog...>
コミッターAndroid (Google) Code Review

ログメッセージ

Merge "Fix the bug of losing Wi-Fi certificate when editing" into rvc-qpr-dev

変更サマリ

差分

--- a/src/com/android/settings/wifi/WifiConfigController2.java
+++ b/src/com/android/settings/wifi/WifiConfigController2.java
@@ -164,6 +164,7 @@ public class WifiConfigController2 implements TextWatcher,
164164 private ScrollView mDialogContainer;
165165 private Spinner mSecuritySpinner;
166166 @VisibleForTesting Spinner mEapMethodSpinner;
167+ private int mLastShownEapMethod;
167168 @VisibleForTesting Spinner mEapSimSpinner; // For EAP-SIM, EAP-AKA and EAP-AKA-PRIME.
168169 private Spinner mEapCaCertSpinner;
169170 private Spinner mEapOcspSpinner;
@@ -1057,6 +1058,7 @@ public class WifiConfigController2 implements TextWatcher,
10571058 final int eapMethod = enterpriseConfig.getEapMethod();
10581059 final int phase2Method = enterpriseConfig.getPhase2Method();
10591060 mEapMethodSpinner.setSelection(eapMethod);
1061+ mLastShownEapMethod = eapMethod;
10601062 showEapFieldsByMethod(eapMethod);
10611063 switch (eapMethod) {
10621064 case Eap.PEAP:
@@ -1627,7 +1629,11 @@ public class WifiConfigController2 implements TextWatcher,
16271629 mSsidScanButton.setVisibility(View.GONE);
16281630 }
16291631 } else if (parent == mEapMethodSpinner) {
1630- showSecurityFields(/* refreshEapMethods */ false, /* refreshCertificates */ true);
1632+ final int selectedItemPosition = mEapMethodSpinner.getSelectedItemPosition();
1633+ if (mLastShownEapMethod != selectedItemPosition) {
1634+ mLastShownEapMethod = selectedItemPosition;
1635+ showSecurityFields(/* refreshEapMethods */ false, /* refreshCertificates */ true);
1636+ }
16311637 } else if (parent == mEapCaCertSpinner) {
16321638 showSecurityFields(/* refreshEapMethods */ false, /* refreshCertificates */ false);
16331639 } else if (parent == mPhase2Spinner
--- a/tests/robotests/src/com/android/settings/wifi/WifiConfigController2Test.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiConfigController2Test.java
@@ -18,7 +18,9 @@ package com.android.settings.wifi;
1818
1919 import static com.google.common.truth.Truth.assertThat;
2020
21+import static org.mockito.Mockito.anyInt;
2122 import static org.mockito.Mockito.anyString;
23+import static org.mockito.Mockito.eq;
2224 import static org.mockito.Mockito.mock;
2325 import static org.mockito.Mockito.when;
2426 import static org.robolectric.Shadows.shadowOf;
@@ -32,6 +34,7 @@ import android.net.wifi.WifiEnterpriseConfig.Eap;
3234 import android.net.wifi.WifiEnterpriseConfig.Phase2;
3335 import android.net.wifi.WifiManager;
3436 import android.os.ServiceSpecificException;
37+import android.security.Credentials;
3538 import android.security.KeyStore;
3639 import android.telephony.SubscriptionInfo;
3740 import android.telephony.SubscriptionManager;
@@ -78,6 +81,10 @@ public class WifiConfigController2Test {
7881 private KeyStore mKeyStore;
7982 private View mView;
8083 private Spinner mHiddenSettingsSpinner;
84+ private Spinner mEapCaCertSpinner;
85+ private Spinner mEapUserCertSpinner;
86+ private String mUseSystemCertsString;
87+ private String mDoNotProvideEapUserCertString;
8188 private ShadowSubscriptionManager mShadowSubscriptionManager;
8289
8390 public WifiConfigController2 mController;
@@ -98,6 +105,9 @@ public class WifiConfigController2Test {
98105 private static final String NUMBER_AND_CHARACTER_KEY = "123456abcd";
99106 private static final String PARTIAL_NUMBER_AND_CHARACTER_KEY = "123456abc?";
100107 private static final int DHCP = 0;
108+ // Saved certificates
109+ private static final String SAVED_CA_CERT = "saved CA cert";
110+ private static final String SAVED_USER_CERT = "saved user cert";
101111
102112 @Before
103113 public void setUp() {
@@ -108,6 +118,11 @@ public class WifiConfigController2Test {
108118 mView = LayoutInflater.from(mContext).inflate(R.layout.wifi_dialog, null);
109119 final Spinner ipSettingsSpinner = mView.findViewById(R.id.ip_settings);
110120 mHiddenSettingsSpinner = mView.findViewById(R.id.hidden_settings);
121+ mEapCaCertSpinner = mView.findViewById(R.id.ca_cert);
122+ mEapUserCertSpinner = mView.findViewById(R.id.user_cert);
123+ mUseSystemCertsString = mContext.getString(R.string.wifi_use_system_certs);
124+ mDoNotProvideEapUserCertString =
125+ mContext.getString(R.string.wifi_do_not_provide_eap_user_cert);
111126 ipSettingsSpinner.setSelection(DHCP);
112127 mShadowSubscriptionManager = shadowOf(mContext.getSystemService(SubscriptionManager.class));
113128
@@ -835,4 +850,75 @@ public class WifiConfigController2Test {
835850 final WifiConfiguration wifiConfiguration = mController.getConfig();
836851 assertThat(wifiConfiguration.carrierId).isEqualTo(carrierId);
837852 }
853+
854+ @Test
855+ public void loadCaCertificateValue_shouldPersistentAsDefault() {
856+ setUpModifyingSavedCertificateConfigController(null, null);
857+
858+ assertThat(mEapCaCertSpinner.getSelectedItem()).isEqualTo(mUseSystemCertsString);
859+ }
860+
861+ @Test
862+ public void loadSavedCaCertificateValue_shouldBeCorrectValue() {
863+ setUpModifyingSavedCertificateConfigController(SAVED_CA_CERT, null);
864+
865+ assertThat(mEapCaCertSpinner.getSelectedItem()).isEqualTo(SAVED_CA_CERT);
866+ }
867+
868+ @Test
869+ public void loadUserCertificateValue_shouldPersistentAsDefault() {
870+ setUpModifyingSavedCertificateConfigController(null, null);
871+
872+ assertThat(mEapUserCertSpinner.getSelectedItem()).isEqualTo(mDoNotProvideEapUserCertString);
873+ }
874+
875+ @Test
876+ public void loadSavedUserCertificateValue_shouldBeCorrectValue() {
877+ setUpModifyingSavedCertificateConfigController(null, SAVED_USER_CERT);
878+
879+ assertThat(mEapUserCertSpinner.getSelectedItem()).isEqualTo(SAVED_USER_CERT);
880+ }
881+
882+ private void setUpModifyingSavedCertificateConfigController(String savedCaCertificate,
883+ String savedUserCertificate) {
884+ final WifiConfiguration mockWifiConfig = mock(WifiConfiguration.class);
885+ final WifiEnterpriseConfig mockWifiEnterpriseConfig = mock(WifiEnterpriseConfig.class);
886+ mockWifiConfig.enterpriseConfig = mockWifiEnterpriseConfig;
887+ when(mWifiEntry.isSaved()).thenReturn(true);
888+ when(mWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_EAP);
889+ when(mWifiEntry.getWifiConfiguration()).thenReturn(mockWifiConfig);
890+ when(mockWifiConfig.getIpConfiguration()).thenReturn(mock(IpConfiguration.class));
891+ when(mockWifiEnterpriseConfig.getEapMethod()).thenReturn(Eap.TLS);
892+ if (savedCaCertificate != null) {
893+ String[] savedCaCertificates = new String[]{savedCaCertificate};
894+ when(mockWifiEnterpriseConfig.getCaCertificateAliases())
895+ .thenReturn(savedCaCertificates);
896+ when(mKeyStore.list(eq(Credentials.CA_CERTIFICATE), anyInt()))
897+ .thenReturn(savedCaCertificates);
898+ }
899+ if (savedUserCertificate != null) {
900+ String[] savedUserCertificates = new String[]{savedUserCertificate};
901+ when(mockWifiEnterpriseConfig.getClientCertificateAlias())
902+ .thenReturn(savedUserCertificate);
903+ when(mKeyStore.list(eq(Credentials.USER_PRIVATE_KEY), anyInt()))
904+ .thenReturn(savedUserCertificates);
905+ }
906+
907+ mController = new TestWifiConfigController2(mConfigUiBase, mView, mWifiEntry,
908+ WifiConfigUiBase2.MODE_MODIFY);
909+
910+ // Because Robolectric has a different behavior from normal flow.
911+ //
912+ // Normal flow:
913+ // showSecurityFields start -> mEapMethodSpinner.setSelection
914+ // -> showSecurityFields end -> mController.onItemSelected
915+ //
916+ // Robolectric flow:
917+ // showSecurityFields start -> mEapMethodSpinner.setSelection
918+ // -> mController.onItemSelected -> showSecurityFields end
919+ //
920+ // We need to add a redundant mEapMethodSpinner.setSelection here to verify whether the
921+ // certificates are covered by mController.onItemSelected after showSecurityFields end.
922+ mController.mEapMethodSpinner.setSelection(Eap.TLS);
923+ }
838924 }