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

Commit 9420cb44 authored by Tony Huang's avatar Tony Huang Committed by Android (Google) Code Review
Browse files

Merge "Do not close client after loader loading finished"

parents 27329238 dab443bd
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();
    }
}