Fixed ApnEditor crash issue
This root caused is that we closed the managed cursor which lifecycle is managed by Activity. Actually, we don't need the managed cursor in this case, just use the normal cursor and close it after we got the apn data from the database. Bug: 77894798 Test: make ROBOTEST_FILTER=ApnEditorTest -j40 RunSettingsRoboTests Change-Id: I6eb80bbd53354e00e871e974f520668dcbceac63
This commit is contained in:
@@ -1195,12 +1195,19 @@ public class ApnEditor extends SettingsPreferenceFragment
|
||||
}
|
||||
}
|
||||
|
||||
private ApnData getApnDataFromUri(Uri uri) {
|
||||
ApnData apnData;
|
||||
try (Cursor cursor = getActivity().managedQuery(
|
||||
uri, sProjection, null /* selection */, null /* sortOrder */)) {
|
||||
cursor.moveToFirst();
|
||||
apnData = new ApnData(uri, cursor);
|
||||
@VisibleForTesting
|
||||
ApnData getApnDataFromUri(Uri uri) {
|
||||
ApnData apnData = null;
|
||||
try (Cursor cursor = getContentResolver().query(
|
||||
uri,
|
||||
sProjection,
|
||||
null /* selection */,
|
||||
null /* selectionArgs */,
|
||||
null /* sortOrder */)) {
|
||||
if (cursor != null) {
|
||||
cursor.moveToFirst();
|
||||
apnData = new ApnData(uri, cursor);
|
||||
}
|
||||
}
|
||||
|
||||
if (apnData == null) {
|
||||
|
@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
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;
|
||||
|
||||
@@ -115,6 +116,24 @@ public class ApnEditorTest {
|
||||
mApnEditorUT.sNotSet = "Not Set";
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApnEditor_doesNotUseManagedQuery() {
|
||||
mApnEditorUT.getApnDataFromUri(Mockito.mock(Uri.class));
|
||||
|
||||
verify(mActivity, never()).managedQuery(
|
||||
any(Uri.class),
|
||||
any(String[].class),
|
||||
any(String.class),
|
||||
any(String.class));
|
||||
|
||||
verify(mActivity, never()).managedQuery(
|
||||
any(Uri.class),
|
||||
any(String[].class),
|
||||
any(String.class),
|
||||
any(String[].class),
|
||||
any(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetStringValue_valueChanged_shouldSetValue() {
|
||||
// GIVEN an APN value which is different than the APN value in database
|
||||
|
Reference in New Issue
Block a user