From 3f5885918b60824d98386f9c31b7dd189b7f426c Mon Sep 17 00:00:00 2001 From: Steve McKay Date: Fri, 2 Sep 2016 16:38:41 -0700 Subject: [PATCH] DO NOT MERGE: Accurately emulate historic Downloads ACTION_VIEW behavior. Add write permision to VIEW intent (don't regress bahavior). Add (already known) mimetype when creating intent. Test: Download a CSV file to Downloads *root*. Install Sheets from play store. Navigate to Settings > Storage > Explore > (device name) > Download Tap CSV file. It should open. NOTE: This is a (manual) cherrypick from master. Manual part necessary as DocumentsUI has moved to a new repo in master. https://googleplex-android.googlesource.com/platform/frameworks/base/+/a4e765f16e3c0031343af55df65380df44672825 Bug: 31245151 Change-Id: Ic64c655d33182e559f9645c1e173b2fe4b601d6c --- .../src/com/android/documentsui/FilesActivity.java | 14 ++++++++++++-- .../android/documentsui/model/DocumentInfo.java | 4 ++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/DocumentsUI/src/com/android/documentsui/FilesActivity.java b/packages/DocumentsUI/src/com/android/documentsui/FilesActivity.java index ae8938de1e3dc..728d98f56e382 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/FilesActivity.java +++ b/packages/DocumentsUI/src/com/android/documentsui/FilesActivity.java @@ -341,8 +341,18 @@ public class FilesActivity extends BaseActivity { // Fall back to traditional VIEW action... intent = new Intent(Intent.ACTION_VIEW); - intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - intent.setData(doc.derivedUri); + intent.setDataAndType(doc.derivedUri, doc.mimeType); + + // Downloads has traditionally added the WRITE permission + // in the TrampolineActivity. Since this behavior is long + // established, we set the same permission for non-managed files + // This ensures consistent behavior between the Downloads root + // and other roots. + int flags = Intent.FLAG_GRANT_READ_URI_PERMISSION; + if (doc.isWriteSupported()) { + flags |= Intent.FLAG_GRANT_WRITE_URI_PERMISSION; + } + intent.setFlags(flags); if (DEBUG && intent.getClipData() != null) { Log.d(TAG, "Starting intent w/ clip data: " + intent.getClipData()); diff --git a/packages/DocumentsUI/src/com/android/documentsui/model/DocumentInfo.java b/packages/DocumentsUI/src/com/android/documentsui/model/DocumentInfo.java index 3a86a51b2d188..63f66de9ad842 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/model/DocumentInfo.java +++ b/packages/DocumentsUI/src/com/android/documentsui/model/DocumentInfo.java @@ -235,6 +235,10 @@ public class DocumentInfo implements Durable, Parcelable { return (flags & Document.FLAG_DIR_PREFERS_GRID) != 0; } + public boolean isWriteSupported() { + return (flags & Document.FLAG_SUPPORTS_WRITE) != 0; + } + public boolean isDeleteSupported() { return (flags & Document.FLAG_SUPPORTS_DELETE) != 0; }