Application accepts null intents causing a crash
Change-Id: Ia7f98f43567f25ae7abc6e5ac7e07323e75d9047 Fixes: 116869239 Test: adb shell am start -n com.android.settings/com.android.settings.Settings\\\$ApnEditorActivity Test: make RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.network"
This commit is contained in:
@@ -231,9 +231,13 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
|
||||
final Intent intent = getIntent();
|
||||
final String action = intent.getAction();
|
||||
if (TextUtils.isEmpty(action)) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
mSubId = intent.getIntExtra(ApnSettings.SUB_ID,
|
||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
|
||||
mReadOnlyApn = false;
|
||||
mReadOnlyApnTypes = null;
|
||||
mReadOnlyApnFields = null;
|
||||
|
@@ -19,11 +19,13 @@ package com.android.settings.network;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
@@ -450,6 +452,15 @@ public class ApnEditorTest {
|
||||
assertThat(ApnEditor.formatInteger("not an int")).isEqualTo("not an int");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreate_noAction_shouldFinishAndNoCrash() {
|
||||
doNothing().when(mApnEditorUT).addPreferencesFromResource(anyInt());
|
||||
|
||||
mApnEditorUT.onCreate(null);
|
||||
|
||||
verify(mApnEditorUT).finish();
|
||||
}
|
||||
|
||||
private void initCursor() {
|
||||
doReturn(2).when(mCursor).getColumnCount();
|
||||
doReturn(Integer.valueOf(2)).when(mCursor).getInt(CURSOR_INTEGER_INDEX);
|
||||
|
Reference in New Issue
Block a user