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

Commit dab443bd authored by Tony Huang's avatar Tony Huang
Browse files

Do not close client after loader loading finished

MediaProvider send contents change notification to background process
with delay so DocsUI should not close provider client after loading
finished, and it will close automatically after application finished.

Fix: 141473235
Test: manual
Test: atest DocumentsUIGoogleTests
Change-Id: Icc2ad660a9ad8f215ef1cd6edba7a5f3498f7287
parent 7b216347
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -165,12 +165,11 @@ public class DirectoryLoader extends AsyncTaskLoader<DirectoryResult> {
        } catch (Exception e) {
            Log.w(TAG, "Failed to query", e);
            result.exception = e;
            FileUtils.closeQuietly(client);
        } finally {
            synchronized (this) {
                mSignal = null;
            }
            // TODO: Remove this call.
            FileUtils.closeQuietly(client);
        }

        return result;
+2 −3
Original line number Diff line number Diff line
@@ -17,14 +17,12 @@
package com.android.documentsui;

import android.content.ContentProviderClient;
import android.content.ContentResolver;
import android.database.Cursor;
import android.os.FileUtils;

import com.android.documentsui.archives.ArchivesProvider;
import com.android.documentsui.base.DocumentInfo;

import android.os.FileUtils;

public class DirectoryResult implements AutoCloseable {

    public Cursor cursor;
@@ -38,6 +36,7 @@ public class DirectoryResult implements AutoCloseable {
        if (client != null && doc.isInArchive()) {
            ArchivesProvider.releaseArchive(client, doc.derivedUri);
        }
        FileUtils.closeQuietly(client);
        cursor = null;
        client = null;
        doc = null;
+59 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.documentsui;

import android.content.ContentProviderClient;
import android.database.MatrixCursor;

import androidx.test.filters.MediumTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.documentsui.base.DocumentInfo;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;

@RunWith(AndroidJUnit4.class)
@MediumTest
public class DirectoryResultTest {

    private ContentProviderClient mClient;
    private MatrixCursor mCursor;

    @Before
    public void setUp() {
        mClient = Mockito.mock(ContentProviderClient.class);
        mCursor = Mockito.mock(MatrixCursor.class);
    }

    @Test
    public void testClose() {
        DirectoryResult result = new DirectoryResult();
        DocumentInfo doc = new DocumentInfo();

        result.client = mClient;
        result.cursor = mCursor;
        result.doc = doc;

        result.close();

        Mockito.verify(mClient).close();
        Mockito.verify(mCursor).close();
    }
}