From b180a65d41adc731cbff1536c7ede15174bc08e1 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Mon, 23 Sep 2013 14:23:41 -0700 Subject: [PATCH] Allow saving to Downloads. Uses new column to mark writability. Also filter file selection in create mode to only allow writable files. Bug: 10667164, 10893268 Change-Id: I90f74efbb7ac634fbdb3cc02a904a96a434d3605 --- core/java/android/app/DownloadManager.java | 20 +++++++++++++++++++- core/java/android/provider/Downloads.java | 2 ++ .../com/android/documentsui/DirectoryFragment.java | 9 ++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/core/java/android/app/DownloadManager.java b/core/java/android/app/DownloadManager.java index 165c3dbd3e0d..800ead9b8944 100644 --- a/core/java/android/app/DownloadManager.java +++ b/core/java/android/app/DownloadManager.java @@ -150,6 +150,11 @@ public class DownloadManager { public static final String COLUMN_MEDIAPROVIDER_URI = Downloads.Impl.COLUMN_MEDIAPROVIDER_URI; /** + * @hide + */ + public final static String COLUMN_ALLOW_WRITE = Downloads.Impl.COLUMN_ALLOW_WRITE; + + /** * Value of {@link #COLUMN_STATUS} when the download is waiting to start. */ public final static int STATUS_PENDING = 1 << 0; @@ -315,6 +320,7 @@ public class DownloadManager { Downloads.Impl.COLUMN_TOTAL_BYTES + " AS " + COLUMN_TOTAL_SIZE_BYTES, Downloads.Impl.COLUMN_LAST_MODIFICATION + " AS " + COLUMN_LAST_MODIFIED_TIMESTAMP, Downloads.Impl.COLUMN_CURRENT_BYTES + " AS " + COLUMN_BYTES_DOWNLOADED_SO_FAR, + Downloads.Impl.COLUMN_ALLOW_WRITE, /* add the following 'computed' columns to the cursor. * they are not 'returned' by the database, but their inclusion * eliminates need to have lot of methods in CursorTranslator @@ -1185,6 +1191,14 @@ public class DownloadManager { public long addCompletedDownload(String title, String description, boolean isMediaScannerScannable, String mimeType, String path, long length, boolean showNotification) { + return addCompletedDownload(title, description, isMediaScannerScannable, mimeType, path, + length, showNotification, false); + } + + /** {@hide} */ + public long addCompletedDownload(String title, String description, + boolean isMediaScannerScannable, String mimeType, String path, long length, + boolean showNotification, boolean allowWrite) { // make sure the input args are non-null/non-zero validateArgumentIsNonEmpty("title", title); validateArgumentIsNonEmpty("description", description); @@ -1210,12 +1224,14 @@ public class DownloadManager { Request.SCANNABLE_VALUE_NO); values.put(Downloads.Impl.COLUMN_VISIBILITY, (showNotification) ? Request.VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION : Request.VISIBILITY_HIDDEN); + values.put(Downloads.Impl.COLUMN_ALLOW_WRITE, allowWrite ? 1 : 0); Uri downloadUri = mResolver.insert(Downloads.Impl.CONTENT_URI, values); if (downloadUri == null) { return -1; } return Long.parseLong(downloadUri.getLastPathSegment()); } + private static final String NON_DOWNLOADMANAGER_DOWNLOAD = "non-dwnldmngr-download-dont-retry2download"; @@ -1227,8 +1243,10 @@ public class DownloadManager { /** * Get the DownloadProvider URI for the download with the given ID. + * + * @hide */ - Uri getDownloadUri(long id) { + public Uri getDownloadUri(long id) { return ContentUris.withAppendedId(mBaseUri, id); } diff --git a/core/java/android/provider/Downloads.java b/core/java/android/provider/Downloads.java index 99997605aa32..b2d9b934d79b 100644 --- a/core/java/android/provider/Downloads.java +++ b/core/java/android/provider/Downloads.java @@ -410,6 +410,8 @@ public final class Downloads { /** The column that is used to count retries */ public static final String COLUMN_FAILED_CONNECTIONS = "numfailed"; + public static final String COLUMN_ALLOW_WRITE = "allow_write"; + /** * default value for {@link #COLUMN_LAST_UPDATESRC}. * This value is used when this column's value is not relevant. diff --git a/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java b/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java index 8eb121ab519b..de1f13022bbd 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java +++ b/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java @@ -17,6 +17,7 @@ package com.android.documentsui; import static com.android.documentsui.DocumentsActivity.TAG; +import static com.android.documentsui.DocumentsActivity.State.ACTION_CREATE; import static com.android.documentsui.DocumentsActivity.State.ACTION_MANAGE; import static com.android.documentsui.DocumentsActivity.State.MODE_GRID; import static com.android.documentsui.DocumentsActivity.State.MODE_LIST; @@ -887,8 +888,14 @@ public class DirectoryFragment extends Fragment { line2.setVisibility(hasLine2 ? View.VISIBLE : View.GONE); } - final boolean enabled = Document.MIME_TYPE_DIR.equals(docMimeType) + boolean enabled = Document.MIME_TYPE_DIR.equals(docMimeType) || MimePredicate.mimeMatches(state.acceptMimes, docMimeType); + + // Read-only files aren't actually enabled when creating + if (state.action == ACTION_CREATE && (docFlags & Document.FLAG_SUPPORTS_WRITE) == 0) { + enabled = false; + } + if (enabled) { setEnabledRecursive(convertView, true); icon.setAlpha(1f); -- 2.11.0