Fix the system crash issue when secondary user clicks any 802.1x AP on
Wifi Picker.
Catch the exception when keystore failed to list the certs
Bug: 73794111
Test: test it with clicking the Google-A on Wifi Picker.
Test: make ROBOTEST_FILTER="(WifiConfigControllerTest)"
RunSettingsRoboTests -j32
RunSettingsRoboTests: OK (12 tests)
Change-Id: I0db66730261c72ef35d1b299bacd2aed7710d247
diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java
index d7b4299..4bdc0a4 100644
--- a/src/com/android/settings/wifi/WifiConfigController.java
+++ b/src/com/android/settings/wifi/WifiConfigController.java
@@ -1216,6 +1216,11 @@
}
}
+ @VisibleForTesting
+ KeyStore getKeyStore() {
+ return KeyStore.getInstance();
+ }
+
private void loadCertificates(
Spinner spinner,
String prefix,
@@ -1232,8 +1237,12 @@
if (showUsePreinstalledCertOption) {
certs.add(mUseSystemCertsString);
}
- certs.addAll(
- Arrays.asList(KeyStore.getInstance().list(prefix, android.os.Process.WIFI_UID)));
+ try {
+ certs.addAll(
+ Arrays.asList(getKeyStore().list(prefix, android.os.Process.WIFI_UID)));
+ } catch (Exception e) {
+ Log.e(TAG, "can't get the certificate list from KeyStore");
+ }
certs.add(noCertificateString);
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java
index bbe104c..1654d6d 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java
@@ -20,11 +20,14 @@
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Mockito.anyInt;
+import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
+import android.os.ServiceSpecificException;
+import android.security.KeyStore;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -56,6 +59,8 @@
private View mView;
@Mock
private AccessPoint mAccessPoint;
+ @Mock
+ private KeyStore mKeyStore;
public WifiConfigController mController;
private static final String HEX_PSK = "01234567012345670123456701234567012345670123456701234567"
@@ -210,6 +215,21 @@
assertThat(mView.findViewById(R.id.eap).getVisibility()).isEqualTo(View.GONE);
}
+ @Test
+ public void loadCertificates_keyStoreListFail_shouldNotCrash() {
+ // Set up
+ when(mAccessPoint.getSecurity()).thenReturn(AccessPoint.SECURITY_EAP);
+ when(mKeyStore.list(anyString()))
+ .thenThrow(new ServiceSpecificException(-1, "permission error"));
+
+ mController = new TestWifiConfigController(mConfigUiBase, mView, mAccessPoint,
+ WifiConfigUiBase.MODE_CONNECT);
+
+ // Verify that the EAP method menu is visible.
+ assertThat(mView.findViewById(R.id.eap).getVisibility()).isEqualTo(View.VISIBLE);
+ // No Crash
+ }
+
public class TestWifiConfigController extends WifiConfigController {
private TestWifiConfigController(
@@ -221,5 +241,8 @@
boolean isSplitSystemUser() {
return false;
}
+
+ @Override
+ KeyStore getKeyStore() { return mKeyStore; }
}
}