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
This commit is contained in:
Ecco Park
2018-03-12 11:37:51 -07:00
parent ec9606addb
commit bffd531aa3
2 changed files with 34 additions and 2 deletions

View File

@@ -20,11 +20,14 @@ import static com.google.common.truth.Truth.assertThat;
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 @@ public class WifiConfigControllerTest {
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 @@ public class WifiConfigControllerTest {
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 @@ public class WifiConfigControllerTest {
boolean isSplitSystemUser() {
return false;
}
@Override
KeyStore getKeyStore() { return mKeyStore; }
}
}