Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7c9f3ff7 authored by Pengquan Meng's avatar Pengquan Meng
Browse files

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
parent 4ef7b5f9
Loading
Loading
Loading
Loading
+13 −6
Original line number Diff line number Diff line
@@ -1195,13 +1195,20 @@ public class ApnEditor extends SettingsPreferenceFragment
        }
    }

    private ApnData getApnDataFromUri(Uri uri) {
        ApnData apnData;
        try (Cursor cursor = getActivity().managedQuery(
                uri, sProjection, null /* selection */, null /* sortOrder */)) {
    @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) {
            Log.d(TAG, "Can't get apnData from Uri " + uri);
+19 −0
Original line number Diff line number Diff line
@@ -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