OSDN Git Service

Allow saving to Downloads.
authorJeff Sharkey <jsharkey@android.com>
Mon, 23 Sep 2013 21:23:41 +0000 (14:23 -0700)
committerJeff Sharkey <jsharkey@android.com>
Mon, 23 Sep 2013 21:23:45 +0000 (14:23 -0700)
Uses new column to mark writability.  Also filter file selection in
create mode to only allow writable files.

Bug: 1066716410893268
Change-Id: I90f74efbb7ac634fbdb3cc02a904a96a434d3605

core/java/android/app/DownloadManager.java
core/java/android/provider/Downloads.java
packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java

index 165c3db..800ead9 100644 (file)
@@ -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);
     }
 
index 9999760..b2d9b93 100644 (file)
@@ -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.
index 8eb121a..de1f130 100644 (file)
@@ -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);