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
@@ -164,6 +164,7 @@ public class WifiConfigController2 implements TextWatcher, | ||
164 | 164 | private ScrollView mDialogContainer; |
165 | 165 | private Spinner mSecuritySpinner; |
166 | 166 | @VisibleForTesting Spinner mEapMethodSpinner; |
167 | + private int mLastShownEapMethod; | |
167 | 168 | @VisibleForTesting Spinner mEapSimSpinner; // For EAP-SIM, EAP-AKA and EAP-AKA-PRIME. |
168 | 169 | private Spinner mEapCaCertSpinner; |
169 | 170 | private Spinner mEapOcspSpinner; |
@@ -1057,6 +1058,7 @@ public class WifiConfigController2 implements TextWatcher, | ||
1057 | 1058 | final int eapMethod = enterpriseConfig.getEapMethod(); |
1058 | 1059 | final int phase2Method = enterpriseConfig.getPhase2Method(); |
1059 | 1060 | mEapMethodSpinner.setSelection(eapMethod); |
1061 | + mLastShownEapMethod = eapMethod; | |
1060 | 1062 | showEapFieldsByMethod(eapMethod); |
1061 | 1063 | switch (eapMethod) { |
1062 | 1064 | case Eap.PEAP: |
@@ -1627,7 +1629,11 @@ public class WifiConfigController2 implements TextWatcher, | ||
1627 | 1629 | mSsidScanButton.setVisibility(View.GONE); |
1628 | 1630 | } |
1629 | 1631 | } 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 | + } | |
1631 | 1637 | } else if (parent == mEapCaCertSpinner) { |
1632 | 1638 | showSecurityFields(/* refreshEapMethods */ false, /* refreshCertificates */ false); |
1633 | 1639 | } else if (parent == mPhase2Spinner |
@@ -18,7 +18,9 @@ package com.android.settings.wifi; | ||
18 | 18 | |
19 | 19 | import static com.google.common.truth.Truth.assertThat; |
20 | 20 | |
21 | +import static org.mockito.Mockito.anyInt; | |
21 | 22 | import static org.mockito.Mockito.anyString; |
23 | +import static org.mockito.Mockito.eq; | |
22 | 24 | import static org.mockito.Mockito.mock; |
23 | 25 | import static org.mockito.Mockito.when; |
24 | 26 | import static org.robolectric.Shadows.shadowOf; |
@@ -32,6 +34,7 @@ import android.net.wifi.WifiEnterpriseConfig.Eap; | ||
32 | 34 | import android.net.wifi.WifiEnterpriseConfig.Phase2; |
33 | 35 | import android.net.wifi.WifiManager; |
34 | 36 | import android.os.ServiceSpecificException; |
37 | +import android.security.Credentials; | |
35 | 38 | import android.security.KeyStore; |
36 | 39 | import android.telephony.SubscriptionInfo; |
37 | 40 | import android.telephony.SubscriptionManager; |
@@ -78,6 +81,10 @@ public class WifiConfigController2Test { | ||
78 | 81 | private KeyStore mKeyStore; |
79 | 82 | private View mView; |
80 | 83 | private Spinner mHiddenSettingsSpinner; |
84 | + private Spinner mEapCaCertSpinner; | |
85 | + private Spinner mEapUserCertSpinner; | |
86 | + private String mUseSystemCertsString; | |
87 | + private String mDoNotProvideEapUserCertString; | |
81 | 88 | private ShadowSubscriptionManager mShadowSubscriptionManager; |
82 | 89 | |
83 | 90 | public WifiConfigController2 mController; |
@@ -98,6 +105,9 @@ public class WifiConfigController2Test { | ||
98 | 105 | private static final String NUMBER_AND_CHARACTER_KEY = "123456abcd"; |
99 | 106 | private static final String PARTIAL_NUMBER_AND_CHARACTER_KEY = "123456abc?"; |
100 | 107 | 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"; | |
101 | 111 | |
102 | 112 | @Before |
103 | 113 | public void setUp() { |
@@ -108,6 +118,11 @@ public class WifiConfigController2Test { | ||
108 | 118 | mView = LayoutInflater.from(mContext).inflate(R.layout.wifi_dialog, null); |
109 | 119 | final Spinner ipSettingsSpinner = mView.findViewById(R.id.ip_settings); |
110 | 120 | 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); | |
111 | 126 | ipSettingsSpinner.setSelection(DHCP); |
112 | 127 | mShadowSubscriptionManager = shadowOf(mContext.getSystemService(SubscriptionManager.class)); |
113 | 128 |
@@ -835,4 +850,75 @@ public class WifiConfigController2Test { | ||
835 | 850 | final WifiConfiguration wifiConfiguration = mController.getConfig(); |
836 | 851 | assertThat(wifiConfiguration.carrierId).isEqualTo(carrierId); |
837 | 852 | } |
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 | + } | |
838 | 924 | } |