Merge "Download manager support for file URIs + last modified time" into gingerbread
diff --git a/core/java/android/net/DownloadManager.java b/core/java/android/net/DownloadManager.java
index b2a214c..02b6210 100644
--- a/core/java/android/net/DownloadManager.java
+++ b/core/java/android/net/DownloadManager.java
@@ -24,6 +24,7 @@
 import android.provider.Downloads;
 import android.util.Log;
 
+import java.io.File;
 import java.io.FileNotFoundException;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -112,10 +113,10 @@
     public final static String COLUMN_BYTES_DOWNLOADED_SO_FAR = "bytes_so_far";
 
     /**
-     * Timestamp when the download was requested, in {@link System#currentTimeMillis
+     * Timestamp when the download was last modified, in {@link System#currentTimeMillis
      * System.currentTimeMillis()} (wall clock time in UTC).
      */
-    public final static String COLUMN_REQUESTED_TIMESTAMP = "requested_timestamp";
+    public final static String COLUMN_LAST_MODIFIED_TIMESTAMP = "last_modified_timestamp";
 
 
     /**
@@ -199,7 +200,7 @@
         COLUMN_STATUS,
         COLUMN_ERROR_CODE,
         COLUMN_BYTES_DOWNLOADED_SO_FAR,
-        COLUMN_REQUESTED_TIMESTAMP
+        COLUMN_LAST_MODIFIED_TIMESTAMP
     };
 
     // columns to request from DownloadProvider
@@ -212,12 +213,13 @@
         Downloads.COLUMN_TOTAL_BYTES,
         Downloads._DATA,
         Downloads.COLUMN_STATUS,
-        Downloads.COLUMN_CURRENT_BYTES
+        Downloads.COLUMN_CURRENT_BYTES,
+        Downloads.COLUMN_LAST_MODIFICATION,
     };
 
     private static final Set<String> LONG_COLUMNS = new HashSet<String>(
             Arrays.asList(COLUMN_ID, COLUMN_TOTAL_SIZE_BYTES, COLUMN_STATUS, COLUMN_ERROR_CODE,
-                          COLUMN_BYTES_DOWNLOADED_SO_FAR, COLUMN_REQUESTED_TIMESTAMP));
+                          COLUMN_BYTES_DOWNLOADED_SO_FAR, COLUMN_LAST_MODIFIED_TIMESTAMP));
 
     /**
      * This class contains all the information necessary to request a new download.  The URI is the
@@ -340,8 +342,8 @@
             values.put(Downloads.COLUMN_URI, mUri.toString());
 
             if (mDestinationUri != null) {
-                // TODO destination support
-                throw new UnsupportedOperationException();
+                values.put(Downloads.COLUMN_DESTINATION, Downloads.Impl.DESTINATION_FILE_URI);
+                values.put(Downloads.COLUMN_FILE_NAME_HINT, mDestinationUri.toString());
             } else {
                 values.put(Downloads.COLUMN_DESTINATION,
                            Downloads.DESTINATION_CACHE_PARTITION_PURGEABLE);
@@ -433,8 +435,8 @@
                 selection = joinStrings(" OR ", parts);
                 Log.w("DownloadManagerPublic", selection);
             }
-            // TODO: ordering
-            return resolver.query(uri, projection, selection, null, null);
+            String orderBy = Downloads.COLUMN_LAST_MODIFICATION + " DESC";
+            return resolver.query(uri, projection, selection, null, orderBy);
         }
 
         private String joinStrings(String joiner, Iterable<String> parts) {
@@ -625,7 +627,7 @@
                 return getUnderlyingString(Downloads.COLUMN_MIME_TYPE);
             }
             assert column.equals(COLUMN_LOCAL_URI);
-            return Uri.fromParts("file", getUnderlyingString(Downloads._DATA), null).toString();
+            return Uri.fromFile(new File(getUnderlyingString(Downloads._DATA))).toString();
         }
 
         private long translateLong(String column) {
@@ -649,8 +651,8 @@
             if (column.equals(COLUMN_BYTES_DOWNLOADED_SO_FAR)) {
                 return getUnderlyingLong(Downloads.COLUMN_CURRENT_BYTES);
             }
-            assert column.equals(COLUMN_REQUESTED_TIMESTAMP);
-            throw new UnsupportedOperationException(); // TODO
+            assert column.equals(COLUMN_LAST_MODIFIED_TIMESTAMP);
+            return getUnderlyingLong(Downloads.COLUMN_LAST_MODIFICATION);
         }
 
         private long translateErrorCode(int status) {
diff --git a/core/java/android/provider/Downloads.java b/core/java/android/provider/Downloads.java
index 348e9e8..1a4f8c0 100644
--- a/core/java/android/provider/Downloads.java
+++ b/core/java/android/provider/Downloads.java
@@ -899,6 +899,12 @@
         public static final int DESTINATION_CACHE_PARTITION_NOROAMING = 3;
 
         /**
+         * This download will be saved to the location given by the file URI in
+         * {@link #COLUMN_FILE_NAME_HINT}.
+         */
+        public static final int DESTINATION_FILE_URI = 4;
+
+        /**
          * This download is allowed to run.
          */
         public static final int CONTROL_RUN = 0;