Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0156a379 authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Android (Google) Code Review
Browse files

Merge "Allow saving to Downloads." into klp-dev

parents 85f77c2b b180a65d
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -149,6 +149,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.
     */
@@ -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);
    }

+2 −0
Original line number Diff line number Diff line
@@ -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.
+8 −1
Original line number Diff line number Diff line
@@ -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);