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

Commit 37b2b746 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 6799253 from d91a988a to sc-release

Change-Id: Ib03efaf948bc1546c766308858fac43fa9a0d48d
parents 5df64b9f d91a988a
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -279,10 +279,11 @@ public class DirectoryLoader extends AsyncTaskLoader<DirectoryResult> {

    @Override
    protected void onStartLoading() {
        if (mResult != null) {
        boolean isCursorStale = checkIfCursorStale(mResult);
        if (mResult != null && !isCursorStale) {
            deliverResult(mResult);
        }
        if (takeContentChanged() || mResult == null) {
        if (takeContentChanged() || mResult == null || isCursorStale) {
            forceLoad();
        }
    }
@@ -311,4 +312,22 @@ public class DirectoryLoader extends AsyncTaskLoader<DirectoryResult> {
        FileUtils.closeQuietly(mResult);
        mResult = null;
    }

    private boolean checkIfCursorStale(DirectoryResult result) {
        if (mResult == null) {
            return true;
        }
        Cursor cursor = result.cursor;
        cursor.moveToPosition(-1);
        for (int pos = 0; pos < cursor.getCount(); ++pos) {
            try {
                if (!cursor.moveToNext()) {
                    return true;
                }
            } catch (Exception e) {
                return true;
            }
        }
        return false;
    }
}
+21 −4
Original line number Diff line number Diff line
@@ -104,8 +104,6 @@ public abstract class MultiRootDocumentsLoader extends AsyncTaskLoader<Directory
     * @param state current state
     * @param executors the executors of authorities
     * @param fileTypeMap the map of mime types and file types.
     * @param lock the selection lock
     * @param contentChangedCallback callback when content changed
     */
    public MultiRootDocumentsLoader(Context context, ProvidersAccess providers, State state,
            Lookup<String, Executor> executors, Lookup<String, String> fileTypeMap) {
@@ -304,10 +302,11 @@ public abstract class MultiRootDocumentsLoader extends AsyncTaskLoader<Directory

    @Override
    protected void onStartLoading() {
        if (mResult != null) {
        boolean isCursorStale = checkIfCursorStale(mResult);
        if (mResult != null && !isCursorStale) {
            deliverResult(mResult);
        }
        if (takeContentChanged() || mResult == null) {
        if (takeContentChanged() || mResult == null || isCursorStale) {
            forceLoad();
        }
    }
@@ -457,4 +456,22 @@ public abstract class MultiRootDocumentsLoader extends AsyncTaskLoader<Directory
            mIsClosed = true;
        }
    }

    private boolean checkIfCursorStale(DirectoryResult result) {
        if (mResult == null) {
            return true;
        }
        Cursor cursor = result.cursor;
        cursor.moveToPosition(-1);
        for (int pos = 0; pos < cursor.getCount(); ++pos) {
            try {
                if (!cursor.moveToNext()) {
                    return true;
                }
            } catch (Exception e) {
                return true;
            }
        }
        return false;
    }
}
+6 −3
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import com.android.documentsui.MetricConsts;
import com.android.documentsui.R;
import com.android.documentsui.base.MimeTypes;
import com.android.documentsui.base.Shared;
import com.android.documentsui.util.VersionUtils;

import com.google.android.material.chip.Chip;
import com.google.common.primitives.Ints;
@@ -96,9 +97,11 @@ public class SearchChipViewManager {
    static {
        sMimeTypesChipItems.put(TYPE_IMAGES,
                new SearchChipData(TYPE_IMAGES, R.string.chip_title_images, IMAGES_MIMETYPES));
        if (VersionUtils.isAtLeastR()) {
            sMimeTypesChipItems.put(TYPE_DOCUMENTS,
                    new SearchChipData(TYPE_DOCUMENTS, R.string.chip_title_documents,
                            DOCUMENTS_MIMETYPES));
        }
        sMimeTypesChipItems.put(TYPE_AUDIO,
                new SearchChipData(TYPE_AUDIO, R.string.chip_title_audio, AUDIO_MIMETYPES));
        sMimeTypesChipItems.put(TYPE_VIDEOS,
+16 −6
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.documentsui.services;

import static android.content.ContentResolver.wrap;

import static com.android.documentsui.services.FileOperationService.OPERATION_MOVE;

import android.app.Notification;
@@ -45,6 +47,8 @@ final class CompressJob extends CopyJob {
    private static final String TAG = "CompressJob";
    private static final String NEW_ARCHIVE_EXTENSION = ".zip";

    private Uri mArchiveUri;

    /**
     * Moves files to a destination identified by {@code destination}.
     * Performs most work by delegating to CopyJob, then deleting
@@ -99,17 +103,16 @@ final class CompressJob extends CopyJob {
            displayName = service.getString(R.string.new_archive_file_name, NEW_ARCHIVE_EXTENSION);
        }

        Uri archiveUri;
        try {
            archiveUri = DocumentsContract.createDocument(
            mArchiveUri = DocumentsContract.createDocument(
                    resolver, mDstInfo.derivedUri, "application/zip", displayName);
        } catch (Exception e) {
            archiveUri = null;
            mArchiveUri = null;
        }

        try {
            mDstInfo = DocumentInfo.fromUri(resolver, ArchivesProvider.buildUriForArchive(
                    archiveUri, ParcelFileDescriptor.MODE_WRITE_ONLY), UserId.DEFAULT_USER);
                    mArchiveUri, ParcelFileDescriptor.MODE_WRITE_ONLY), UserId.DEFAULT_USER);
            ArchivesProvider.acquireArchive(getClient(mDstInfo), mDstInfo.derivedUri);
        } catch (FileNotFoundException e) {
            Log.e(TAG, "Failed to create dstInfo.", e);
@@ -132,7 +135,14 @@ final class CompressJob extends CopyJob {
            Log.e(TAG, "Failed to release the archive.");
        }

        // TODO: Remove the archive file in case of an error.
        // Remove the archive file in case of an error.
        try {
            if (!isFinished() || isCanceled()) {
                DocumentsContract.deleteDocument(wrap(getClient(mArchiveUri)), mArchiveUri);
            }
        } catch (RemoteException | FileNotFoundException e) {
            Log.w(TAG, "Failed to cleanup after compress error: " + mDstInfo.toString(), e);
        }

        super.finish();
    }
+15 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import androidx.test.runner.AndroidJUnit4;
import com.android.documentsui.R;
import com.android.documentsui.base.MimeTypes;
import com.android.documentsui.base.Shared;
import com.android.documentsui.util.VersionUtils;

import org.junit.Before;
import org.junit.Test;
@@ -49,6 +50,8 @@ public final class SearchChipViewManagerTest {

    private static final String LARGE_FILES_CHIP_MIME_TYPE = "";
    private static final String FROM_THIS_WEEK_CHIP_MIME_TYPE = "";
    private static final String[] TEST_MIME_TYPES_INCLUDING_DOCUMENT =
            new String[]{"image/*", "video/*", "text/*"};
    private static final String[] TEST_MIME_TYPES =
            new String[]{"image/*", "video/*"};
    private static final String[] TEST_OTHER_TYPES =
@@ -87,6 +90,18 @@ public final class SearchChipViewManagerTest {
        assertThat(mChipGroup.getChildCount()).isEqualTo(totalChipLength);
    }

    @Test
    public void testUpdateChips_documentsFilterOnlyAvailableAboveR() throws Exception {
        mSearchChipViewManager.updateChips(TEST_MIME_TYPES_INCLUDING_DOCUMENT);

        int totalChipLength = TEST_MIME_TYPES_INCLUDING_DOCUMENT.length + TEST_OTHER_TYPES.length;
        if (VersionUtils.isAtLeastR()) {
            assertThat(mChipGroup.getChildCount()).isEqualTo(totalChipLength);
        } else {
            assertThat(mChipGroup.getChildCount()).isEqualTo(totalChipLength - 1);
        }
    }

    @Test
    public void testUpdateChips_withSingleMimeType_hasCorrectChipCount() throws Exception {
        mSearchChipViewManager.updateChips(new String[]{"image/*"});