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

Commit 91a101cd authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Separate root and document management.

Two hidden intents for managing roots and documents, used to support
Downloads UI.  Touching an item tries launching as MANAGE_DOCUMENT
first before falling back to VIEW.  Provide MIME type for roots.

Bug: 10446265, 10531347, 10599641
Change-Id: Ia5584bd6ce3e5a9b0048e8caf1447e3053664413
parent 183d320a
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -30,11 +30,10 @@
                <category android:name="android.intent.category.OPENABLE" />
                <data android:mimeType="*/*" />
            </intent-filter>
            <!-- data expected to point at existing root to manage -->
            <intent-filter>
                <action android:name="android.provider.action.MANAGE_DOCUMENTS" />
                <action android:name="android.provider.action.MANAGE_ROOT" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="vnd.android.document/directory" />
                <data android:mimeType="vnd.android.document/root" />
            </intent-filter>
        </activity>

+21 −10
Original line number Diff line number Diff line
@@ -145,7 +145,7 @@ public class DocumentsActivity extends Activity {
            mState.action = ACTION_CREATE;
        } else if (Intent.ACTION_GET_CONTENT.equals(action)) {
            mState.action = ACTION_GET_CONTENT;
        } else if (DocumentsContract.ACTION_MANAGE_DOCUMENTS.equals(action)) {
        } else if (DocumentsContract.ACTION_MANAGE_ROOT.equals(action)) {
            mState.action = ACTION_MANAGE;
        }

@@ -171,12 +171,13 @@ public class DocumentsActivity extends Activity {
        }

        if (mState.action == ACTION_MANAGE) {
            final Uri rootUri = intent.getData();
            final RootInfo root = mRoots.findRoot(rootUri);
            final Uri uri = intent.getData();
            final String rootId = DocumentsContract.getRootId(uri);
            final RootInfo root = mRoots.getRoot(uri.getAuthority(), rootId);
            if (root != null) {
                onRootPicked(root, true);
            } else {
                Log.w(TAG, "Failed to find root: " + rootUri);
                Log.w(TAG, "Failed to find root: " + uri);
                finish();
            }

@@ -626,17 +627,27 @@ public class DocumentsActivity extends Activity {
            // Replace selected file
            SaveFragment.get(fm).setReplaceTarget(doc);
        } else if (mState.action == ACTION_MANAGE) {
            // Open the document
            final Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            intent.setData(doc.uri);
            // First try managing the document; we expect manager to filter
            // based on authority, so we don't grant.
            final Intent manage = new Intent(DocumentsContract.ACTION_MANAGE_DOCUMENT);
            manage.setData(doc.uri);

            try {
                startActivity(intent);
                startActivity(manage);
            } catch (ActivityNotFoundException ex) {
                // Fall back to viewing
                final Intent view = new Intent(Intent.ACTION_VIEW);
                view.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                view.setData(doc.uri);

                try {
                    startActivity(view);
                } catch (ActivityNotFoundException ex2) {
                    Toast.makeText(this, R.string.toast_no_application, Toast.LENGTH_SHORT).show();
                }
            }
        }
    }

    public void onDocumentsPicked(List<DocumentInfo> docs) {
        if (mState.action == ACTION_OPEN || mState.action == ACTION_GET_CONTENT) {
+0 −4
Original line number Diff line number Diff line
@@ -16,13 +16,9 @@

package com.android.documentsui;

import android.util.Log;

import com.android.documentsui.model.DocumentInfo;
import com.android.internal.util.Predicate;

import java.util.Arrays;

public class MimePredicate implements Predicate<DocumentInfo> {
    private final String[] mFilters;