• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.provider;
18 
19 import android.net.Uri;
20 
21 /**
22  * The Download Manager
23  *
24  * @pending
25  */
26 public final class Downloads {
27     /**
28      * @hide
29      */
Downloads()30     private Downloads() {}
31 
32     /**
33      * The permission to access the download manager
34      * @hide
35      */
36     public static final String PERMISSION_ACCESS = "android.permission.ACCESS_DOWNLOAD_MANAGER";
37 
38     /**
39      * The permission to access the download manager's advanced functions
40      * @hide
41      */
42     public static final String PERMISSION_ACCESS_ADVANCED =
43             "android.permission.ACCESS_DOWNLOAD_MANAGER_ADVANCED";
44 
45     /**
46      * The permission to directly access the download manager's cache directory
47      * @hide
48      */
49     public static final String PERMISSION_CACHE = "android.permission.ACCESS_CACHE_FILESYSTEM";
50 
51     /**
52      * The permission to send broadcasts on download completion
53      * @hide
54      */
55     public static final String PERMISSION_SEND_INTENTS =
56             "android.permission.SEND_DOWNLOAD_COMPLETED_INTENTS";
57 
58     /**
59      * The content:// URI for the data table in the provider
60      * @hide
61      */
62     public static final Uri CONTENT_URI =
63         Uri.parse("content://downloads/my_downloads");
64 
65     /**
66      * Broadcast Action: this is sent by the download manager to the app
67      * that had initiated a download when that download completes. The
68      * download's content: uri is specified in the intent's data.
69      * @hide
70      */
71     public static final String ACTION_DOWNLOAD_COMPLETED =
72             "android.intent.action.DOWNLOAD_COMPLETED";
73 
74     /**
75      * Broadcast Action: this is sent by the download manager to the app
76      * that had initiated a download when the user selects the notification
77      * associated with that download. The download's content: uri is specified
78      * in the intent's data if the click is associated with a single download,
79      * or Downloads.CONTENT_URI if the notification is associated with
80      * multiple downloads.
81      * Note: this is not currently sent for downloads that have completed
82      * successfully.
83      * @hide
84      */
85     public static final String ACTION_NOTIFICATION_CLICKED =
86             "android.intent.action.DOWNLOAD_NOTIFICATION_CLICKED";
87 
88     /**
89      * The name of the column containing the URI of the data being downloaded.
90      * <P>Type: TEXT</P>
91      * <P>Owner can Init/Read</P>
92      * @hide
93      */
94     public static final String COLUMN_URI = "uri";
95 
96     /**
97      * The name of the column containing application-specific data.
98      * <P>Type: TEXT</P>
99      * <P>Owner can Init/Read/Write</P>
100      * @hide
101      */
102     public static final String COLUMN_APP_DATA = "entity";
103 
104     /**
105      * The name of the column containing the flags that indicates whether
106      * the initiating application is capable of verifying the integrity of
107      * the downloaded file. When this flag is set, the download manager
108      * performs downloads and reports success even in some situations where
109      * it can't guarantee that the download has completed (e.g. when doing
110      * a byte-range request without an ETag, or when it can't determine
111      * whether a download fully completed).
112      * <P>Type: BOOLEAN</P>
113      * <P>Owner can Init</P>
114      * @hide
115      */
116     public static final String COLUMN_NO_INTEGRITY = "no_integrity";
117 
118     /**
119      * The name of the column containing the filename that the initiating
120      * application recommends. When possible, the download manager will attempt
121      * to use this filename, or a variation, as the actual name for the file.
122      * <P>Type: TEXT</P>
123      * <P>Owner can Init</P>
124      * @hide
125      */
126     public static final String COLUMN_FILE_NAME_HINT = "hint";
127 
128     /**
129      * The name of the column containing the filename where the downloaded data
130      * was actually stored.
131      * <P>Type: TEXT</P>
132      * <P>Owner can Read</P>
133      * @hide
134      */
135     public static final String _DATA = "_data";
136 
137     /**
138      * The name of the column containing the MIME type of the downloaded data.
139      * <P>Type: TEXT</P>
140      * <P>Owner can Init/Read</P>
141      * @hide
142      */
143     public static final String COLUMN_MIME_TYPE = "mimetype";
144 
145     /**
146      * The name of the column containing the flag that controls the destination
147      * of the download. See the DESTINATION_* constants for a list of legal values.
148      * <P>Type: INTEGER</P>
149      * <P>Owner can Init</P>
150      * @hide
151      */
152     public static final String COLUMN_DESTINATION = "destination";
153 
154     /**
155      * The name of the column containing the flags that controls whether the
156      * download is displayed by the UI. See the VISIBILITY_* constants for
157      * a list of legal values.
158      * <P>Type: INTEGER</P>
159      * <P>Owner can Init/Read/Write</P>
160      * @hide
161      */
162     public static final String COLUMN_VISIBILITY = "visibility";
163 
164     /**
165      * The name of the column containing the current control state  of the download.
166      * Applications can write to this to control (pause/resume) the download.
167      * the CONTROL_* constants for a list of legal values.
168      * <P>Type: INTEGER</P>
169      * <P>Owner can Read</P>
170      * @hide
171      */
172     public static final String COLUMN_CONTROL = "control";
173 
174     /**
175      * The name of the column containing the current status of the download.
176      * Applications can read this to follow the progress of each download. See
177      * the STATUS_* constants for a list of legal values.
178      * <P>Type: INTEGER</P>
179      * <P>Owner can Read</P>
180      * @hide
181      */
182     public static final String COLUMN_STATUS = "status";
183 
184     /**
185      * The name of the column containing the date at which some interesting
186      * status changed in the download. Stored as a System.currentTimeMillis()
187      * value.
188      * <P>Type: BIGINT</P>
189      * <P>Owner can Read</P>
190      * @hide
191      */
192     public static final String COLUMN_LAST_MODIFICATION = "lastmod";
193 
194     /**
195      * The name of the column containing the package name of the application
196      * that initiating the download. The download manager will send
197      * notifications to a component in this package when the download completes.
198      * <P>Type: TEXT</P>
199      * <P>Owner can Init/Read</P>
200      * @hide
201      */
202     public static final String COLUMN_NOTIFICATION_PACKAGE = "notificationpackage";
203 
204     /**
205      * The name of the column containing the component name of the class that
206      * will receive notifications associated with the download. The
207      * package/class combination is passed to
208      * Intent.setClassName(String,String).
209      * <P>Type: TEXT</P>
210      * <P>Owner can Init/Read</P>
211      * @hide
212      */
213     public static final String COLUMN_NOTIFICATION_CLASS = "notificationclass";
214 
215     /**
216      * If extras are specified when requesting a download they will be provided in the intent that
217      * is sent to the specified class and package when a download has finished.
218      * <P>Type: TEXT</P>
219      * <P>Owner can Init</P>
220      * @hide
221      */
222     public static final String COLUMN_NOTIFICATION_EXTRAS = "notificationextras";
223 
224     /**
225      * The name of the column contain the values of the cookie to be used for
226      * the download. This is used directly as the value for the Cookie: HTTP
227      * header that gets sent with the request.
228      * <P>Type: TEXT</P>
229      * <P>Owner can Init</P>
230      * @hide
231      */
232     public static final String COLUMN_COOKIE_DATA = "cookiedata";
233 
234     /**
235      * The name of the column containing the user agent that the initiating
236      * application wants the download manager to use for this download.
237      * <P>Type: TEXT</P>
238      * <P>Owner can Init</P>
239      * @hide
240      */
241     public static final String COLUMN_USER_AGENT = "useragent";
242 
243     /**
244      * The name of the column containing the referer (sic) that the initiating
245      * application wants the download manager to use for this download.
246      * <P>Type: TEXT</P>
247      * <P>Owner can Init</P>
248      * @hide
249      */
250     public static final String COLUMN_REFERER = "referer";
251 
252     /**
253      * The name of the column containing the total size of the file being
254      * downloaded.
255      * <P>Type: INTEGER</P>
256      * <P>Owner can Read</P>
257      * @hide
258      */
259     public static final String COLUMN_TOTAL_BYTES = "total_bytes";
260 
261     /**
262      * The name of the column containing the size of the part of the file that
263      * has been downloaded so far.
264      * <P>Type: INTEGER</P>
265      * <P>Owner can Read</P>
266      * @hide
267      */
268     public static final String COLUMN_CURRENT_BYTES = "current_bytes";
269 
270     /**
271      * The name of the column where the initiating application can provide the
272      * UID of another application that is allowed to access this download. If
273      * multiple applications share the same UID, all those applications will be
274      * allowed to access this download. This column can be updated after the
275      * download is initiated. This requires the permission
276      * android.permission.ACCESS_DOWNLOAD_MANAGER_ADVANCED.
277      * <P>Type: INTEGER</P>
278      * <P>Owner can Init</P>
279      * @hide
280      */
281     public static final String COLUMN_OTHER_UID = "otheruid";
282 
283     /**
284      * The name of the column where the initiating application can provided the
285      * title of this download. The title will be displayed ito the user in the
286      * list of downloads.
287      * <P>Type: TEXT</P>
288      * <P>Owner can Init/Read/Write</P>
289      * @hide
290      */
291     public static final String COLUMN_TITLE = "title";
292 
293     /**
294      * The name of the column where the initiating application can provide the
295      * description of this download. The description will be displayed to the
296      * user in the list of downloads.
297      * <P>Type: TEXT</P>
298      * <P>Owner can Init/Read/Write</P>
299      * @hide
300      */
301     public static final String COLUMN_DESCRIPTION = "description";
302 
303     /**
304      * Set to true if this download is deleted. It is completely removed from the database
305      * when MediaProvider database also deletes the metadata asociated with this downloaded file.
306      * <P>Type: BOOLEAN</P>
307      * <P>Owner can Read</P>
308      * @hide
309      */
310     public static final String COLUMN_DELETED = "deleted";
311 
312     /*
313      * Lists the destinations that an application can specify for a download.
314      */
315 
316     /**
317      * This download will be saved to the external storage. This is the
318      * default behavior, and should be used for any file that the user
319      * can freely access, copy, delete. Even with that destination,
320      * unencrypted DRM files are saved in secure internal storage.
321      * Downloads to the external destination only write files for which
322      * there is a registered handler. The resulting files are accessible
323      * by filename to all applications.
324      * @hide
325      */
326     public static final int DESTINATION_EXTERNAL = 0;
327 
328     /**
329      * This download will be saved to the download manager's private
330      * partition. This is the behavior used by applications that want to
331      * download private files that are used and deleted soon after they
332      * get downloaded. All file types are allowed, and only the initiating
333      * application can access the file (indirectly through a content
334      * provider). This requires the
335      * android.permission.ACCESS_DOWNLOAD_MANAGER_ADVANCED permission.
336      * @hide
337      */
338     public static final int DESTINATION_CACHE_PARTITION = 1;
339 
340     /**
341      * This download will be saved to the download manager's private
342      * partition and will be purged as necessary to make space. This is
343      * for private files (similar to CACHE_PARTITION) that aren't deleted
344      * immediately after they are used, and are kept around by the download
345      * manager as long as space is available.
346      * @hide
347      */
348     public static final int DESTINATION_CACHE_PARTITION_PURGEABLE = 2;
349 
350     /**
351      * This download will be saved to the download manager's private
352      * partition, as with DESTINATION_CACHE_PARTITION, but the download
353      * will not proceed if the user is on a roaming data connection.
354      * @hide
355      */
356     public static final int DESTINATION_CACHE_PARTITION_NOROAMING = 3;
357 
358     /**
359      * This download is allowed to run.
360      * @hide
361      */
362     public static final int CONTROL_RUN = 0;
363 
364     /**
365      * This download must pause at the first opportunity.
366      * @hide
367      */
368     public static final int CONTROL_PAUSED = 1;
369 
370     /*
371      * Lists the states that the download manager can set on a download
372      * to notify applications of the download progress.
373      * The codes follow the HTTP families:<br>
374      * 1xx: informational<br>
375      * 2xx: success<br>
376      * 3xx: redirects (not used by the download manager)<br>
377      * 4xx: client errors<br>
378      * 5xx: server errors
379      */
380 
381     /**
382      * Returns whether the status is informational (i.e. 1xx).
383      * @hide
384      */
isStatusInformational(int status)385     public static boolean isStatusInformational(int status) {
386         return (status >= 100 && status < 200);
387     }
388 
389     /**
390      * Returns whether the status is a success (i.e. 2xx).
391      * @hide
392      */
isStatusSuccess(int status)393     public static boolean isStatusSuccess(int status) {
394         return (status >= 200 && status < 300);
395     }
396 
397     /**
398      * Returns whether the status is an error (i.e. 4xx or 5xx).
399      * @hide
400      */
isStatusError(int status)401     public static boolean isStatusError(int status) {
402         return (status >= 400 && status < 600);
403     }
404 
405     /**
406      * Returns whether the status is a client error (i.e. 4xx).
407      * @hide
408      */
isStatusClientError(int status)409     public static boolean isStatusClientError(int status) {
410         return (status >= 400 && status < 500);
411     }
412 
413     /**
414      * Returns whether the status is a server error (i.e. 5xx).
415      * @hide
416      */
isStatusServerError(int status)417     public static boolean isStatusServerError(int status) {
418         return (status >= 500 && status < 600);
419     }
420 
421     /**
422      * Returns whether the download has completed (either with success or
423      * error).
424      * @hide
425      */
isStatusCompleted(int status)426     public static boolean isStatusCompleted(int status) {
427         return (status >= 200 && status < 300) || (status >= 400 && status < 600);
428     }
429 
430     /**
431      * This download hasn't stated yet
432      * @hide
433      */
434     public static final int STATUS_PENDING = 190;
435 
436     /**
437      * This download has started
438      * @hide
439      */
440     public static final int STATUS_RUNNING = 192;
441 
442     /**
443      * This download has successfully completed.
444      * Warning: there might be other status values that indicate success
445      * in the future.
446      * Use isSucccess() to capture the entire category.
447      * @hide
448      */
449     public static final int STATUS_SUCCESS = 200;
450 
451     /**
452      * This request couldn't be parsed. This is also used when processing
453      * requests with unknown/unsupported URI schemes.
454      * @hide
455      */
456     public static final int STATUS_BAD_REQUEST = 400;
457 
458     /**
459      * This download can't be performed because the content type cannot be
460      * handled.
461      * @hide
462      */
463     public static final int STATUS_NOT_ACCEPTABLE = 406;
464 
465     /**
466      * This download cannot be performed because the length cannot be
467      * determined accurately. This is the code for the HTTP error "Length
468      * Required", which is typically used when making requests that require
469      * a content length but don't have one, and it is also used in the
470      * client when a response is received whose length cannot be determined
471      * accurately (therefore making it impossible to know when a download
472      * completes).
473      * @hide
474      */
475     public static final int STATUS_LENGTH_REQUIRED = 411;
476 
477     /**
478      * This download was interrupted and cannot be resumed.
479      * This is the code for the HTTP error "Precondition Failed", and it is
480      * also used in situations where the client doesn't have an ETag at all.
481      * @hide
482      */
483     public static final int STATUS_PRECONDITION_FAILED = 412;
484 
485     /**
486      * This download was canceled
487      * @hide
488      */
489     public static final int STATUS_CANCELED = 490;
490 
491     /**
492      * This download has completed with an error.
493      * Warning: there will be other status values that indicate errors in
494      * the future. Use isStatusError() to capture the entire category.
495      * @hide
496      */
497     public static final int STATUS_UNKNOWN_ERROR = 491;
498 
499     /**
500      * This download couldn't be completed because of a storage issue.
501      * Typically, that's because the filesystem is missing or full.
502      * Use the more specific {@link #STATUS_INSUFFICIENT_SPACE_ERROR}
503      * and {@link #STATUS_DEVICE_NOT_FOUND_ERROR} when appropriate.
504      * @hide
505      */
506     public static final int STATUS_FILE_ERROR = 492;
507 
508     /**
509      * This download couldn't be completed because of an HTTP
510      * redirect response that the download manager couldn't
511      * handle.
512      * @hide
513      */
514     public static final int STATUS_UNHANDLED_REDIRECT = 493;
515 
516     /**
517      * This download couldn't be completed because of an
518      * unspecified unhandled HTTP code.
519      * @hide
520      */
521     public static final int STATUS_UNHANDLED_HTTP_CODE = 494;
522 
523     /**
524      * This download couldn't be completed because of an
525      * error receiving or processing data at the HTTP level.
526      * @hide
527      */
528     public static final int STATUS_HTTP_DATA_ERROR = 495;
529 
530     /**
531      * This download couldn't be completed because of an
532      * HttpException while setting up the request.
533      * @hide
534      */
535     public static final int STATUS_HTTP_EXCEPTION = 496;
536 
537     /**
538      * This download couldn't be completed because there were
539      * too many redirects.
540      * @hide
541      */
542     public static final int STATUS_TOO_MANY_REDIRECTS = 497;
543 
544     /**
545      * This download couldn't be completed due to insufficient storage
546      * space.  Typically, this is because the SD card is full.
547      * @hide
548      */
549     public static final int STATUS_INSUFFICIENT_SPACE_ERROR = 498;
550 
551     /**
552      * This download couldn't be completed because no external storage
553      * device was found.  Typically, this is because the SD card is not
554      * mounted.
555      * @hide
556      */
557     public static final int STATUS_DEVICE_NOT_FOUND_ERROR = 499;
558 
559     /**
560      * This download is visible but only shows in the notifications
561      * while it's in progress.
562      * @hide
563      */
564     public static final int VISIBILITY_VISIBLE = 0;
565 
566     /**
567      * This download is visible and shows in the notifications while
568      * in progress and after completion.
569      * @hide
570      */
571     public static final int VISIBILITY_VISIBLE_NOTIFY_COMPLETED = 1;
572 
573     /**
574      * This download doesn't show in the UI or in the notifications.
575      * @hide
576      */
577     public static final int VISIBILITY_HIDDEN = 2;
578 
579     /**
580      * Implementation details
581      *
582      * Exposes constants used to interact with the download manager's
583      * content provider.
584      * The constants URI ... STATUS are the names of columns in the downloads table.
585      *
586      * @hide
587      */
588     public static final class Impl implements BaseColumns {
Impl()589         private Impl() {}
590 
591         /**
592          * The permission to access the download manager
593          */
594         public static final String PERMISSION_ACCESS = "android.permission.ACCESS_DOWNLOAD_MANAGER";
595 
596         /**
597          * The permission to access the download manager's advanced functions
598          */
599         public static final String PERMISSION_ACCESS_ADVANCED =
600                 "android.permission.ACCESS_DOWNLOAD_MANAGER_ADVANCED";
601 
602         /**
603          * The permission to access the all the downloads in the manager.
604          */
605         public static final String PERMISSION_ACCESS_ALL =
606                 "android.permission.ACCESS_ALL_DOWNLOADS";
607 
608         /**
609          * The permission to directly access the download manager's cache
610          * directory
611          */
612         public static final String PERMISSION_CACHE = "android.permission.ACCESS_CACHE_FILESYSTEM";
613 
614         /**
615          * The permission to send broadcasts on download completion
616          */
617         public static final String PERMISSION_SEND_INTENTS =
618                 "android.permission.SEND_DOWNLOAD_COMPLETED_INTENTS";
619 
620         /**
621          * The permission to download files to the cache partition that won't be automatically
622          * purged when space is needed.
623          */
624         public static final String PERMISSION_CACHE_NON_PURGEABLE =
625                 "android.permission.DOWNLOAD_CACHE_NON_PURGEABLE";
626 
627         /**
628          * The permission to download files without any system notification being shown.
629          */
630         public static final String PERMISSION_NO_NOTIFICATION =
631                 "android.permission.DOWNLOAD_WITHOUT_NOTIFICATION";
632 
633         /**
634          * The content:// URI to access downloads owned by the caller's UID.
635          */
636         public static final Uri CONTENT_URI =
637                 Uri.parse("content://downloads/my_downloads");
638 
639         /**
640          * The content URI for accessing all downloads across all UIDs (requires the
641          * ACCESS_ALL_DOWNLOADS permission).
642          */
643         public static final Uri ALL_DOWNLOADS_CONTENT_URI =
644                 Uri.parse("content://downloads/all_downloads");
645 
646         /**
647          * Broadcast Action: this is sent by the download manager to the app
648          * that had initiated a download when that download completes. The
649          * download's content: uri is specified in the intent's data.
650          */
651         public static final String ACTION_DOWNLOAD_COMPLETED =
652                 "android.intent.action.DOWNLOAD_COMPLETED";
653 
654         /**
655          * Broadcast Action: this is sent by the download manager to the app
656          * that had initiated a download when the user selects the notification
657          * associated with that download. The download's content: uri is specified
658          * in the intent's data if the click is associated with a single download,
659          * or Downloads.CONTENT_URI if the notification is associated with
660          * multiple downloads.
661          * Note: this is not currently sent for downloads that have completed
662          * successfully.
663          */
664         public static final String ACTION_NOTIFICATION_CLICKED =
665                 "android.intent.action.DOWNLOAD_NOTIFICATION_CLICKED";
666 
667         /**
668          * The name of the column containing the URI of the data being downloaded.
669          * <P>Type: TEXT</P>
670          * <P>Owner can Init/Read</P>
671          */
672         public static final String COLUMN_URI = "uri";
673 
674         /**
675          * The name of the column containing application-specific data.
676          * <P>Type: TEXT</P>
677          * <P>Owner can Init/Read/Write</P>
678          */
679         public static final String COLUMN_APP_DATA = "entity";
680 
681         /**
682          * The name of the column containing the flags that indicates whether
683          * the initiating application is capable of verifying the integrity of
684          * the downloaded file. When this flag is set, the download manager
685          * performs downloads and reports success even in some situations where
686          * it can't guarantee that the download has completed (e.g. when doing
687          * a byte-range request without an ETag, or when it can't determine
688          * whether a download fully completed).
689          * <P>Type: BOOLEAN</P>
690          * <P>Owner can Init</P>
691          */
692         public static final String COLUMN_NO_INTEGRITY = "no_integrity";
693 
694         /**
695          * The name of the column containing the filename that the initiating
696          * application recommends. When possible, the download manager will attempt
697          * to use this filename, or a variation, as the actual name for the file.
698          * <P>Type: TEXT</P>
699          * <P>Owner can Init</P>
700          */
701         public static final String COLUMN_FILE_NAME_HINT = "hint";
702 
703         /**
704          * The name of the column containing the filename where the downloaded data
705          * was actually stored.
706          * <P>Type: TEXT</P>
707          * <P>Owner can Read</P>
708          */
709         public static final String _DATA = "_data";
710 
711         /**
712          * The name of the column containing the MIME type of the downloaded data.
713          * <P>Type: TEXT</P>
714          * <P>Owner can Init/Read</P>
715          */
716         public static final String COLUMN_MIME_TYPE = "mimetype";
717 
718         /**
719          * The name of the column containing the flag that controls the destination
720          * of the download. See the DESTINATION_* constants for a list of legal values.
721          * <P>Type: INTEGER</P>
722          * <P>Owner can Init</P>
723          */
724         public static final String COLUMN_DESTINATION = "destination";
725 
726         /**
727          * The name of the column containing the flags that controls whether the
728          * download is displayed by the UI. See the VISIBILITY_* constants for
729          * a list of legal values.
730          * <P>Type: INTEGER</P>
731          * <P>Owner can Init/Read/Write</P>
732          */
733         public static final String COLUMN_VISIBILITY = "visibility";
734 
735         /**
736          * The name of the column containing the current control state  of the download.
737          * Applications can write to this to control (pause/resume) the download.
738          * the CONTROL_* constants for a list of legal values.
739          * <P>Type: INTEGER</P>
740          * <P>Owner can Read</P>
741          */
742         public static final String COLUMN_CONTROL = "control";
743 
744         /**
745          * The name of the column containing the current status of the download.
746          * Applications can read this to follow the progress of each download. See
747          * the STATUS_* constants for a list of legal values.
748          * <P>Type: INTEGER</P>
749          * <P>Owner can Read</P>
750          */
751         public static final String COLUMN_STATUS = "status";
752 
753         /**
754          * The name of the column containing the date at which some interesting
755          * status changed in the download. Stored as a System.currentTimeMillis()
756          * value.
757          * <P>Type: BIGINT</P>
758          * <P>Owner can Read</P>
759          */
760         public static final String COLUMN_LAST_MODIFICATION = "lastmod";
761 
762         /**
763          * The name of the column containing the package name of the application
764          * that initiating the download. The download manager will send
765          * notifications to a component in this package when the download completes.
766          * <P>Type: TEXT</P>
767          * <P>Owner can Init/Read</P>
768          */
769         public static final String COLUMN_NOTIFICATION_PACKAGE = "notificationpackage";
770 
771         /**
772          * The name of the column containing the component name of the class that
773          * will receive notifications associated with the download. The
774          * package/class combination is passed to
775          * Intent.setClassName(String,String).
776          * <P>Type: TEXT</P>
777          * <P>Owner can Init/Read</P>
778          */
779         public static final String COLUMN_NOTIFICATION_CLASS = "notificationclass";
780 
781         /**
782          * If extras are specified when requesting a download they will be provided in the intent that
783          * is sent to the specified class and package when a download has finished.
784          * <P>Type: TEXT</P>
785          * <P>Owner can Init</P>
786          */
787         public static final String COLUMN_NOTIFICATION_EXTRAS = "notificationextras";
788 
789         /**
790          * The name of the column contain the values of the cookie to be used for
791          * the download. This is used directly as the value for the Cookie: HTTP
792          * header that gets sent with the request.
793          * <P>Type: TEXT</P>
794          * <P>Owner can Init</P>
795          */
796         public static final String COLUMN_COOKIE_DATA = "cookiedata";
797 
798         /**
799          * The name of the column containing the user agent that the initiating
800          * application wants the download manager to use for this download.
801          * <P>Type: TEXT</P>
802          * <P>Owner can Init</P>
803          */
804         public static final String COLUMN_USER_AGENT = "useragent";
805 
806         /**
807          * The name of the column containing the referer (sic) that the initiating
808          * application wants the download manager to use for this download.
809          * <P>Type: TEXT</P>
810          * <P>Owner can Init</P>
811          */
812         public static final String COLUMN_REFERER = "referer";
813 
814         /**
815          * The name of the column containing the total size of the file being
816          * downloaded.
817          * <P>Type: INTEGER</P>
818          * <P>Owner can Read</P>
819          */
820         public static final String COLUMN_TOTAL_BYTES = "total_bytes";
821 
822         /**
823          * The name of the column containing the size of the part of the file that
824          * has been downloaded so far.
825          * <P>Type: INTEGER</P>
826          * <P>Owner can Read</P>
827          */
828         public static final String COLUMN_CURRENT_BYTES = "current_bytes";
829 
830         /**
831          * The name of the column where the initiating application can provide the
832          * UID of another application that is allowed to access this download. If
833          * multiple applications share the same UID, all those applications will be
834          * allowed to access this download. This column can be updated after the
835          * download is initiated. This requires the permission
836          * android.permission.ACCESS_DOWNLOAD_MANAGER_ADVANCED.
837          * <P>Type: INTEGER</P>
838          * <P>Owner can Init</P>
839          */
840         public static final String COLUMN_OTHER_UID = "otheruid";
841 
842         /**
843          * The name of the column where the initiating application can provided the
844          * title of this download. The title will be displayed ito the user in the
845          * list of downloads.
846          * <P>Type: TEXT</P>
847          * <P>Owner can Init/Read/Write</P>
848          */
849         public static final String COLUMN_TITLE = "title";
850 
851         /**
852          * The name of the column where the initiating application can provide the
853          * description of this download. The description will be displayed to the
854          * user in the list of downloads.
855          * <P>Type: TEXT</P>
856          * <P>Owner can Init/Read/Write</P>
857          */
858         public static final String COLUMN_DESCRIPTION = "description";
859 
860         /**
861          * The name of the column indicating whether the download was requesting through the public
862          * API.  This controls some differences in behavior.
863          * <P>Type: BOOLEAN</P>
864          * <P>Owner can Init/Read</P>
865          */
866         public static final String COLUMN_IS_PUBLIC_API = "is_public_api";
867 
868         /**
869          * The name of the column indicating whether roaming connections can be used.  This is only
870          * used for public API downloads.
871          * <P>Type: BOOLEAN</P>
872          * <P>Owner can Init/Read</P>
873          */
874         public static final String COLUMN_ALLOW_ROAMING = "allow_roaming";
875 
876         /**
877          * The name of the column holding a bitmask of allowed network types.  This is only used for
878          * public API downloads.
879          * <P>Type: INTEGER</P>
880          * <P>Owner can Init/Read</P>
881          */
882         public static final String COLUMN_ALLOWED_NETWORK_TYPES = "allowed_network_types";
883 
884         /**
885          * Whether or not this download should be displayed in the system's Downloads UI.  Defaults
886          * to true.
887          * <P>Type: INTEGER</P>
888          * <P>Owner can Init/Read</P>
889          */
890         public static final String COLUMN_IS_VISIBLE_IN_DOWNLOADS_UI = "is_visible_in_downloads_ui";
891 
892         /**
893          * If true, the user has confirmed that this download can proceed over the mobile network
894          * even though it exceeds the recommended maximum size.
895          * <P>Type: BOOLEAN</P>
896          */
897         public static final String COLUMN_BYPASS_RECOMMENDED_SIZE_LIMIT =
898             "bypass_recommended_size_limit";
899 
900         /**
901          * Set to true if this download is deleted. It is completely removed from the database
902          * when MediaProvider database also deletes the metadata asociated with this downloaded file.
903          * <P>Type: BOOLEAN</P>
904          * <P>Owner can Read</P>
905          */
906         public static final String COLUMN_DELETED = "deleted";
907 
908         /**
909          * The URI to the corresponding entry in MediaProvider for this downloaded entry. It is
910          * used to delete the entries from MediaProvider database when it is deleted from the
911          * downloaded list.
912          * <P>Type: TEXT</P>
913          * <P>Owner can Read</P>
914          */
915         public static final String COLUMN_MEDIAPROVIDER_URI = "mediaprovider_uri";
916 
917         /*
918          * Lists the destinations that an application can specify for a download.
919          */
920 
921         /**
922          * This download will be saved to the external storage. This is the
923          * default behavior, and should be used for any file that the user
924          * can freely access, copy, delete. Even with that destination,
925          * unencrypted DRM files are saved in secure internal storage.
926          * Downloads to the external destination only write files for which
927          * there is a registered handler. The resulting files are accessible
928          * by filename to all applications.
929          */
930         public static final int DESTINATION_EXTERNAL = 0;
931 
932         /**
933          * This download will be saved to the download manager's private
934          * partition. This is the behavior used by applications that want to
935          * download private files that are used and deleted soon after they
936          * get downloaded. All file types are allowed, and only the initiating
937          * application can access the file (indirectly through a content
938          * provider). This requires the
939          * android.permission.ACCESS_DOWNLOAD_MANAGER_ADVANCED permission.
940          */
941         public static final int DESTINATION_CACHE_PARTITION = 1;
942 
943         /**
944          * This download will be saved to the download manager's private
945          * partition and will be purged as necessary to make space. This is
946          * for private files (similar to CACHE_PARTITION) that aren't deleted
947          * immediately after they are used, and are kept around by the download
948          * manager as long as space is available.
949          */
950         public static final int DESTINATION_CACHE_PARTITION_PURGEABLE = 2;
951 
952         /**
953          * This download will be saved to the download manager's private
954          * partition, as with DESTINATION_CACHE_PARTITION, but the download
955          * will not proceed if the user is on a roaming data connection.
956          */
957         public static final int DESTINATION_CACHE_PARTITION_NOROAMING = 3;
958 
959         /**
960          * This download will be saved to the location given by the file URI in
961          * {@link #COLUMN_FILE_NAME_HINT}.
962          */
963         public static final int DESTINATION_FILE_URI = 4;
964 
965         /**
966          * This download is allowed to run.
967          */
968         public static final int CONTROL_RUN = 0;
969 
970         /**
971          * This download must pause at the first opportunity.
972          */
973         public static final int CONTROL_PAUSED = 1;
974 
975         /*
976          * Lists the states that the download manager can set on a download
977          * to notify applications of the download progress.
978          * The codes follow the HTTP families:<br>
979          * 1xx: informational<br>
980          * 2xx: success<br>
981          * 3xx: redirects (not used by the download manager)<br>
982          * 4xx: client errors<br>
983          * 5xx: server errors
984          */
985 
986         /**
987          * Returns whether the status is informational (i.e. 1xx).
988          */
isStatusInformational(int status)989         public static boolean isStatusInformational(int status) {
990             return (status >= 100 && status < 200);
991         }
992 
993         /**
994          * Returns whether the status is a success (i.e. 2xx).
995          */
isStatusSuccess(int status)996         public static boolean isStatusSuccess(int status) {
997             return (status >= 200 && status < 300);
998         }
999 
1000         /**
1001          * Returns whether the status is an error (i.e. 4xx or 5xx).
1002          */
isStatusError(int status)1003         public static boolean isStatusError(int status) {
1004             return (status >= 400 && status < 600);
1005         }
1006 
1007         /**
1008          * Returns whether the status is a client error (i.e. 4xx).
1009          */
isStatusClientError(int status)1010         public static boolean isStatusClientError(int status) {
1011             return (status >= 400 && status < 500);
1012         }
1013 
1014         /**
1015          * Returns whether the status is a server error (i.e. 5xx).
1016          */
isStatusServerError(int status)1017         public static boolean isStatusServerError(int status) {
1018             return (status >= 500 && status < 600);
1019         }
1020 
1021         /**
1022          * Returns whether the download has completed (either with success or
1023          * error).
1024          */
isStatusCompleted(int status)1025         public static boolean isStatusCompleted(int status) {
1026             return (status >= 200 && status < 300) || (status >= 400 && status < 600);
1027         }
1028 
1029         /**
1030          * This download hasn't stated yet
1031          */
1032         public static final int STATUS_PENDING = 190;
1033 
1034         /**
1035          * This download has started
1036          */
1037         public static final int STATUS_RUNNING = 192;
1038 
1039         /**
1040          * This download has been paused by the owning app.
1041          */
1042         public static final int STATUS_PAUSED_BY_APP = 193;
1043 
1044         /**
1045          * This download encountered some network error and is waiting before retrying the request.
1046          */
1047         public static final int STATUS_WAITING_TO_RETRY = 194;
1048 
1049         /**
1050          * This download is waiting for network connectivity to proceed.
1051          */
1052         public static final int STATUS_WAITING_FOR_NETWORK = 195;
1053 
1054         /**
1055          * This download exceeded a size limit for mobile networks and is waiting for a Wi-Fi
1056          * connection to proceed.
1057          */
1058         public static final int STATUS_QUEUED_FOR_WIFI = 196;
1059 
1060         /**
1061          * This download has successfully completed.
1062          * Warning: there might be other status values that indicate success
1063          * in the future.
1064          * Use isSucccess() to capture the entire category.
1065          */
1066         public static final int STATUS_SUCCESS = 200;
1067 
1068         /**
1069          * This request couldn't be parsed. This is also used when processing
1070          * requests with unknown/unsupported URI schemes.
1071          */
1072         public static final int STATUS_BAD_REQUEST = 400;
1073 
1074         /**
1075          * This download can't be performed because the content type cannot be
1076          * handled.
1077          */
1078         public static final int STATUS_NOT_ACCEPTABLE = 406;
1079 
1080         /**
1081          * This download cannot be performed because the length cannot be
1082          * determined accurately. This is the code for the HTTP error "Length
1083          * Required", which is typically used when making requests that require
1084          * a content length but don't have one, and it is also used in the
1085          * client when a response is received whose length cannot be determined
1086          * accurately (therefore making it impossible to know when a download
1087          * completes).
1088          */
1089         public static final int STATUS_LENGTH_REQUIRED = 411;
1090 
1091         /**
1092          * This download was interrupted and cannot be resumed.
1093          * This is the code for the HTTP error "Precondition Failed", and it is
1094          * also used in situations where the client doesn't have an ETag at all.
1095          */
1096         public static final int STATUS_PRECONDITION_FAILED = 412;
1097 
1098         /**
1099          * The lowest-valued error status that is not an actual HTTP status code.
1100          */
1101         public static final int MIN_ARTIFICIAL_ERROR_STATUS = 488;
1102 
1103         /**
1104          * The requested destination file already exists.
1105          */
1106         public static final int STATUS_FILE_ALREADY_EXISTS_ERROR = 488;
1107 
1108         /**
1109          * Some possibly transient error occurred, but we can't resume the download.
1110          */
1111         public static final int STATUS_CANNOT_RESUME = 489;
1112 
1113         /**
1114          * This download was canceled
1115          */
1116         public static final int STATUS_CANCELED = 490;
1117 
1118         /**
1119          * This download has completed with an error.
1120          * Warning: there will be other status values that indicate errors in
1121          * the future. Use isStatusError() to capture the entire category.
1122          */
1123         public static final int STATUS_UNKNOWN_ERROR = 491;
1124 
1125         /**
1126          * This download couldn't be completed because of a storage issue.
1127          * Typically, that's because the filesystem is missing or full.
1128          * Use the more specific {@link #STATUS_INSUFFICIENT_SPACE_ERROR}
1129          * and {@link #STATUS_DEVICE_NOT_FOUND_ERROR} when appropriate.
1130          */
1131         public static final int STATUS_FILE_ERROR = 492;
1132 
1133         /**
1134          * This download couldn't be completed because of an HTTP
1135          * redirect response that the download manager couldn't
1136          * handle.
1137          */
1138         public static final int STATUS_UNHANDLED_REDIRECT = 493;
1139 
1140         /**
1141          * This download couldn't be completed because of an
1142          * unspecified unhandled HTTP code.
1143          */
1144         public static final int STATUS_UNHANDLED_HTTP_CODE = 494;
1145 
1146         /**
1147          * This download couldn't be completed because of an
1148          * error receiving or processing data at the HTTP level.
1149          */
1150         public static final int STATUS_HTTP_DATA_ERROR = 495;
1151 
1152         /**
1153          * This download couldn't be completed because of an
1154          * HttpException while setting up the request.
1155          */
1156         public static final int STATUS_HTTP_EXCEPTION = 496;
1157 
1158         /**
1159          * This download couldn't be completed because there were
1160          * too many redirects.
1161          */
1162         public static final int STATUS_TOO_MANY_REDIRECTS = 497;
1163 
1164         /**
1165          * This download couldn't be completed due to insufficient storage
1166          * space.  Typically, this is because the SD card is full.
1167          */
1168         public static final int STATUS_INSUFFICIENT_SPACE_ERROR = 498;
1169 
1170         /**
1171          * This download couldn't be completed because no external storage
1172          * device was found.  Typically, this is because the SD card is not
1173          * mounted.
1174          */
1175         public static final int STATUS_DEVICE_NOT_FOUND_ERROR = 499;
1176 
1177         /**
1178          * This download is visible but only shows in the notifications
1179          * while it's in progress.
1180          */
1181         public static final int VISIBILITY_VISIBLE = 0;
1182 
1183         /**
1184          * This download is visible and shows in the notifications while
1185          * in progress and after completion.
1186          */
1187         public static final int VISIBILITY_VISIBLE_NOTIFY_COMPLETED = 1;
1188 
1189         /**
1190          * This download doesn't show in the UI or in the notifications.
1191          */
1192         public static final int VISIBILITY_HIDDEN = 2;
1193 
1194         /**
1195          * Constants related to HTTP request headers associated with each download.
1196          */
1197         public static class RequestHeaders {
1198             public static final String HEADERS_DB_TABLE = "request_headers";
1199             public static final String COLUMN_DOWNLOAD_ID = "download_id";
1200             public static final String COLUMN_HEADER = "header";
1201             public static final String COLUMN_VALUE = "value";
1202 
1203             /**
1204              * Path segment to add to a download URI to retrieve request headers
1205              */
1206             public static final String URI_SEGMENT = "headers";
1207 
1208             /**
1209              * Prefix for ContentValues keys that contain HTTP header lines, to be passed to
1210              * DownloadProvider.insert().
1211              */
1212             public static final String INSERT_KEY_PREFIX = "http_header_";
1213         }
1214     }
1215 }
1216