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:
Pengquan Meng
2018-04-11 12:53:03 -07:00
parent 4ef7b5f97b
commit 7c9f3ff74e
2 changed files with 32 additions and 6 deletions

View File

@@ -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) {