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

Commit 844989ea authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Make DocumentsContract methods more general.

Accepting only ContentResolver arguments was quite limiting, so use
the newly created super-interface ContentInterface, which lets
callers use a ContentResolver, and ContentProviderClient, or even a
specific ContentProvider.

This is a safe API change, since we're accepting a more-general
argument, and existing API users can continue passing ContentResolver
to these methods.

Bug: 117635768
Test: atest DocumentsUITests
Test: atest android.appsecurity.cts.DocumentsTest
Change-Id: I109af667d9bdabe4bf78fb35fa61dee6c429ed47
parent dc0d4417
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ public interface DocumentsAccess {
    @Nullable DocumentInfo getArchiveDocument(Uri uri);

    boolean isDocumentUri(Uri uri);
    @Nullable Path findDocumentPath(Uri uri) throws RemoteException;
    @Nullable Path findDocumentPath(Uri uri) throws RemoteException, FileNotFoundException;

    List<DocumentInfo> getDocuments(String authority, List<String> docIds) throws RemoteException;

@@ -120,7 +120,7 @@ public interface DocumentsAccess {
        }

        @Override
        public Path findDocumentPath(Uri docUri) throws RemoteException {
        public Path findDocumentPath(Uri docUri) throws RemoteException, FileNotFoundException {
            final ContentResolver resolver = mContext.getContentResolver();
            try (final ContentProviderClient client = DocumentsApplication
                    .acquireUnstableProviderOrThrow(resolver, docUri.getAuthority())) {
+2 −1
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import com.android.documentsui.services.FileOperationService;
import com.android.documentsui.services.FileOperationService.OpType;
import com.android.internal.logging.MetricsLogger;

import java.io.FileNotFoundException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
@@ -709,7 +710,7 @@ public final class Metrics {
            final RootInfo root = providers.getRootOneshot(
                    Providers.AUTHORITY_STORAGE, path.getRootId());
            isInternal = !root.supportsEject();
        } catch (RemoteException | RuntimeException e) {
        } catch (FileNotFoundException | RemoteException | RuntimeException e) {
            Log.e(TAG, "Failed to obtain its root info. Log the metrics as internal.", e);
            // It's not very likely to have an external storage so log it as internal.
            isInternal = true;
+3 −3
Original line number Diff line number Diff line
@@ -327,7 +327,7 @@ class CopyJob extends ResolvedResourcesJob {
                                appContext, operationType, Metrics.OPMODE_PROVIDER);
                        return;
                    }
                } catch (RemoteException | RuntimeException e) {
                } catch (FileNotFoundException | RemoteException | RuntimeException e) {
                    Log.e(TAG, "Provider side copy failed for: " + src.derivedUri
                            + " due to an exception.", e);
                    Metrics.logFileOperationFailure(
@@ -390,7 +390,7 @@ class CopyJob extends ResolvedResourcesJob {
        try {
            dstUri = DocumentsContract.createDocument(
                    getClient(dest), dest.derivedUri, dstMimeType, dstDisplayName);
        } catch (RemoteException | RuntimeException e) {
        } catch (FileNotFoundException | RemoteException | RuntimeException e) {
            Metrics.logFileOperationFailure(
                    appContext, Metrics.SUBFILEOP_CREATE_DOCUMENT, dest.derivedUri);
            throw new ResourceException(
@@ -783,7 +783,7 @@ class CopyJob extends ResolvedResourcesJob {
        if (parent.isDirectory() && doc.authority.equals(parent.authority)) {
            try {
                return isChildDocument(getClient(doc), doc.derivedUri, parent.derivedUri);
            } catch (RemoteException | RuntimeException e) {
            } catch (FileNotFoundException | RemoteException | RuntimeException e) {
                throw new ResourceException(
                        "Failed to check if %s is a child of %s due to an exception.",
                        doc.derivedUri, parent.derivedUri, e);
+2 −1
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import com.android.documentsui.clipping.UrisSupplier;
import com.android.documentsui.files.FilesActivity;
import com.android.documentsui.services.FileOperationService.OpType;

import java.io.FileNotFoundException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
@@ -264,7 +265,7 @@ abstract public class Job implements Runnable {
                throw new ResourceException("Unable to delete source document. "
                        + "File is not deletable or removable: %s.", doc.derivedUri);
            }
        } catch (RemoteException | RuntimeException e) {
        } catch (FileNotFoundException | RemoteException | RuntimeException e) {
            throw new ResourceException("Failed to delete file %s due to an exception.",
                    doc.derivedUri, e);
        }
+1 −1
Original line number Diff line number Diff line
@@ -153,7 +153,7 @@ final class MoveJob extends CopyJob {
                                appContext, operationType, Metrics.OPMODE_PROVIDER);
                        return;
                    }
                } catch (RemoteException | RuntimeException e) {
                } catch (FileNotFoundException | RemoteException | RuntimeException e) {
                    Metrics.logFileOperationFailure(
                            appContext, Metrics.SUBFILEOP_QUICK_MOVE, src.derivedUri);
                    Log.e(TAG, "Provider side move failed for: " + src.derivedUri
Loading