From 8fa99701491dee0ac18b8707e32252cb3c621af1 Mon Sep 17 00:00:00 2001 From: Tomasz Mikolajewski Date: Thu, 7 Apr 2016 18:00:08 +0900 Subject: [PATCH] Fix opening archives in Downloads. When opening an archive in Downloads we first want to use the ACTION_MANAGE_DOCUMENT intent, as it's a file on Downloads. However, for files within archives we don't want call this intent, as ACTION_MANAGE_DOCUMENT does not support files in archives. Finally, we actually need to call ACTION_MANAGE_DOCUMENT for archive files on Downloads, to give third party apps a chance to show up in the Intent choose (invoked by the Trampoline). This CL makes things work as they worked before merging DownloadsActivity with DocumentsActivity. Bug: 28033554 Change-Id: I287759aa8fc0457341ce6ece07d5c2ccf36f2c8c --- .../android/documentsui/FilesActivity.java | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/packages/DocumentsUI/src/com/android/documentsui/FilesActivity.java b/packages/DocumentsUI/src/com/android/documentsui/FilesActivity.java index d4439d8b480f5..ef57f7861defb 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/FilesActivity.java +++ b/packages/DocumentsUI/src/com/android/documentsui/FilesActivity.java @@ -98,7 +98,7 @@ public class FilesActivity extends BaseActivity { assert(uri == null || uri.getAuthority() == null || LauncherActivity.isLaunchUri(uri)); refreshCurrentRootAndDirectory(AnimationView.ANIM_NONE); - } else if (intent.getAction() == Intent.ACTION_VIEW) { + } else if (Intent.ACTION_VIEW.equals(intent.getAction())) { assert(uri != null); new OpenUriForViewTask(this).executeOnExecutor( ProviderExecutor.forAuthority(uri.getAuthority()), uri); @@ -274,18 +274,6 @@ public class FilesActivity extends BaseActivity { @Override public void onDocumentPicked(DocumentInfo doc, Model model) { - if (doc.isContainer()) { - openContainerDocument(doc); - } else { - openDocument(doc, model); - } - } - - /** - * Launches an intent to view the specified document. - */ - private void openDocument(DocumentInfo doc, Model model) { - // Anything on downloads goes through the back through downloads manager // (that's the MANAGE_DOCUMENT bit). // This is done for two reasons: @@ -295,7 +283,13 @@ public class FilesActivity extends BaseActivity { // like origin URL. // All other files not on downloads, event APKs, would get no benefit from this // treatment, thusly the "isDownloads" check. - if (getCurrentRoot().isDownloads()) { + + // Launch MANAGE_DOCUMENTS only for the root level files, so it's not called for + // files in archives. Also, if the activity is already browsing a ZIP from downloads, + // then skip MANAGE_DOCUMENTS. + final boolean isViewing = Intent.ACTION_VIEW.equals(getIntent().getAction()); + final boolean isInArchive = mState.stack.size() > 1; + if (getCurrentRoot().isDownloads() && !isInArchive && !isViewing) { // 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); @@ -309,6 +303,17 @@ public class FilesActivity extends BaseActivity { } } + if (doc.isContainer()) { + openContainerDocument(doc); + } else { + openDocument(doc, model); + } + } + + /** + * Launches an intent to view the specified document. + */ + private void openDocument(DocumentInfo doc, Model model) { Intent intent = new QuickViewIntentBuilder( getPackageManager(), getResources(), doc, model).build();