blob: 89d1c447a7095150b45f44f3e70be81984b0b498 [file] [log] [blame]
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001/*
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
17package android.provider;
18
Mathew Inwood6750f2e2018-08-10 09:29:25 +010019import android.annotation.UnsupportedAppUsage;
Vasu Nori4c6e5df2010-10-26 17:00:16 -070020import android.app.DownloadManager;
Jeff Sharkey948eef82012-03-20 17:44:42 -070021import android.content.Context;
Jeff Sharkey1a303952011-06-16 13:04:20 -070022import android.net.NetworkPolicyManager;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070023import android.net.Uri;
24
25/**
Jean-Baptiste Querue99f41f2010-01-14 11:58:14 -080026 * The Download Manager
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070027 *
Jean-Baptiste Querue99f41f2010-01-14 11:58:14 -080028 * @pending
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070029 */
Jean-Baptiste Queru843e8972010-01-14 11:56:11 -080030public final class Downloads {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070031 private Downloads() {}
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -080032
33 /**
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -080034 * Implementation details
Jean-Baptiste Querue99f41f2010-01-14 11:58:14 -080035 *
36 * Exposes constants used to interact with the download manager's
37 * content provider.
38 * The constants URI ... STATUS are the names of columns in the downloads table.
39 *
40 * @hide
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -080041 */
42 public static final class Impl implements BaseColumns {
43 private Impl() {}
44
Jeff Sharkey0a17db12016-11-04 11:23:46 -060045 public static final String AUTHORITY = "downloads";
46
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -080047 /**
48 * The permission to access the download manager
49 */
50 public static final String PERMISSION_ACCESS = "android.permission.ACCESS_DOWNLOAD_MANAGER";
51
52 /**
53 * The permission to access the download manager's advanced functions
54 */
55 public static final String PERMISSION_ACCESS_ADVANCED =
56 "android.permission.ACCESS_DOWNLOAD_MANAGER_ADVANCED";
57
58 /**
Kenny Root1de2eac2010-12-01 11:37:36 -080059 * The permission to access the all the downloads in the manager.
60 */
61 public static final String PERMISSION_ACCESS_ALL =
62 "android.permission.ACCESS_ALL_DOWNLOADS";
63
64 /**
65 * The permission to directly access the download manager's cache
66 * directory
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -080067 */
68 public static final String PERMISSION_CACHE = "android.permission.ACCESS_CACHE_FILESYSTEM";
69
70 /**
71 * The permission to send broadcasts on download completion
72 */
73 public static final String PERMISSION_SEND_INTENTS =
74 "android.permission.SEND_DOWNLOAD_COMPLETED_INTENTS";
75
76 /**
Steve Howard8e15afe2010-07-28 17:12:40 -070077 * The permission to download files to the cache partition that won't be automatically
Steve Howarda13a02c2010-07-23 14:58:15 -070078 * purged when space is needed.
79 */
80 public static final String PERMISSION_CACHE_NON_PURGEABLE =
81 "android.permission.DOWNLOAD_CACHE_NON_PURGEABLE";
82
83 /**
Steve Howard8e15afe2010-07-28 17:12:40 -070084 * The permission to download files without any system notification being shown.
85 */
86 public static final String PERMISSION_NO_NOTIFICATION =
87 "android.permission.DOWNLOAD_WITHOUT_NOTIFICATION";
88
89 /**
Steve Howardeca77fc2010-09-12 18:49:08 -070090 * The content:// URI to access downloads owned by the caller's UID.
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -080091 */
Mathew Inwood6750f2e2018-08-10 09:29:25 +010092 @UnsupportedAppUsage
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -080093 public static final Uri CONTENT_URI =
Steve Howardeca77fc2010-09-12 18:49:08 -070094 Uri.parse("content://downloads/my_downloads");
95
96 /**
97 * The content URI for accessing all downloads across all UIDs (requires the
98 * ACCESS_ALL_DOWNLOADS permission).
99 */
Mathew Inwood6750f2e2018-08-10 09:29:25 +0100100 @UnsupportedAppUsage
Steve Howardeca77fc2010-09-12 18:49:08 -0700101 public static final Uri ALL_DOWNLOADS_CONTENT_URI =
102 Uri.parse("content://downloads/all_downloads");
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800103
Vasu Nori5be894e2010-11-02 21:55:30 -0700104 /** URI segment to access a publicly accessible downloaded file */
105 public static final String PUBLICLY_ACCESSIBLE_DOWNLOADS_URI_SEGMENT = "public_downloads";
106
107 /**
108 * The content URI for accessing publicly accessible downloads (i.e., it requires no
109 * permissions to access this downloaded file)
110 */
Mathew Inwood6750f2e2018-08-10 09:29:25 +0100111 @UnsupportedAppUsage
Vasu Nori5be894e2010-11-02 21:55:30 -0700112 public static final Uri PUBLICLY_ACCESSIBLE_DOWNLOADS_URI =
113 Uri.parse("content://downloads/" + PUBLICLY_ACCESSIBLE_DOWNLOADS_URI_SEGMENT);
114
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800115 /**
116 * Broadcast Action: this is sent by the download manager to the app
117 * that had initiated a download when that download completes. The
118 * download's content: uri is specified in the intent's data.
119 */
120 public static final String ACTION_DOWNLOAD_COMPLETED =
Jeff Sharkey8d5d0652017-04-04 14:38:39 -0600121 DownloadManager.ACTION_DOWNLOAD_COMPLETED;
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800122
123 /**
124 * Broadcast Action: this is sent by the download manager to the app
125 * that had initiated a download when the user selects the notification
126 * associated with that download. The download's content: uri is specified
127 * in the intent's data if the click is associated with a single download,
128 * or Downloads.CONTENT_URI if the notification is associated with
129 * multiple downloads.
130 * Note: this is not currently sent for downloads that have completed
131 * successfully.
132 */
133 public static final String ACTION_NOTIFICATION_CLICKED =
Jeff Sharkey8d5d0652017-04-04 14:38:39 -0600134 DownloadManager.ACTION_NOTIFICATION_CLICKED;
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800135
136 /**
137 * The name of the column containing the URI of the data being downloaded.
138 * <P>Type: TEXT</P>
139 * <P>Owner can Init/Read</P>
140 */
Mathew Inwood6750f2e2018-08-10 09:29:25 +0100141 @UnsupportedAppUsage
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800142 public static final String COLUMN_URI = "uri";
143
144 /**
145 * The name of the column containing application-specific data.
146 * <P>Type: TEXT</P>
147 * <P>Owner can Init/Read/Write</P>
148 */
149 public static final String COLUMN_APP_DATA = "entity";
150
151 /**
152 * The name of the column containing the flags that indicates whether
153 * the initiating application is capable of verifying the integrity of
154 * the downloaded file. When this flag is set, the download manager
155 * performs downloads and reports success even in some situations where
156 * it can't guarantee that the download has completed (e.g. when doing
157 * a byte-range request without an ETag, or when it can't determine
158 * whether a download fully completed).
159 * <P>Type: BOOLEAN</P>
160 * <P>Owner can Init</P>
161 */
162 public static final String COLUMN_NO_INTEGRITY = "no_integrity";
163
164 /**
165 * The name of the column containing the filename that the initiating
166 * application recommends. When possible, the download manager will attempt
167 * to use this filename, or a variation, as the actual name for the file.
168 * <P>Type: TEXT</P>
169 * <P>Owner can Init</P>
170 */
Mathew Inwood6750f2e2018-08-10 09:29:25 +0100171 @UnsupportedAppUsage
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800172 public static final String COLUMN_FILE_NAME_HINT = "hint";
173
174 /**
175 * The name of the column containing the filename where the downloaded data
176 * was actually stored.
177 * <P>Type: TEXT</P>
178 * <P>Owner can Read</P>
179 */
180 public static final String _DATA = "_data";
181
182 /**
183 * The name of the column containing the MIME type of the downloaded data.
184 * <P>Type: TEXT</P>
185 * <P>Owner can Init/Read</P>
186 */
Mathew Inwood6750f2e2018-08-10 09:29:25 +0100187 @UnsupportedAppUsage
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800188 public static final String COLUMN_MIME_TYPE = "mimetype";
189
190 /**
191 * The name of the column containing the flag that controls the destination
192 * of the download. See the DESTINATION_* constants for a list of legal values.
193 * <P>Type: INTEGER</P>
194 * <P>Owner can Init</P>
195 */
Mathew Inwood6750f2e2018-08-10 09:29:25 +0100196 @UnsupportedAppUsage
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800197 public static final String COLUMN_DESTINATION = "destination";
198
199 /**
200 * The name of the column containing the flags that controls whether the
201 * download is displayed by the UI. See the VISIBILITY_* constants for
202 * a list of legal values.
203 * <P>Type: INTEGER</P>
204 * <P>Owner can Init/Read/Write</P>
205 */
Mathew Inwood6750f2e2018-08-10 09:29:25 +0100206 @UnsupportedAppUsage
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800207 public static final String COLUMN_VISIBILITY = "visibility";
208
209 /**
210 * The name of the column containing the current control state of the download.
211 * Applications can write to this to control (pause/resume) the download.
212 * the CONTROL_* constants for a list of legal values.
213 * <P>Type: INTEGER</P>
214 * <P>Owner can Read</P>
215 */
216 public static final String COLUMN_CONTROL = "control";
217
218 /**
219 * The name of the column containing the current status of the download.
220 * Applications can read this to follow the progress of each download. See
221 * the STATUS_* constants for a list of legal values.
222 * <P>Type: INTEGER</P>
223 * <P>Owner can Read</P>
224 */
225 public static final String COLUMN_STATUS = "status";
226
227 /**
228 * The name of the column containing the date at which some interesting
229 * status changed in the download. Stored as a System.currentTimeMillis()
230 * value.
231 * <P>Type: BIGINT</P>
232 * <P>Owner can Read</P>
233 */
234 public static final String COLUMN_LAST_MODIFICATION = "lastmod";
235
236 /**
237 * The name of the column containing the package name of the application
238 * that initiating the download. The download manager will send
239 * notifications to a component in this package when the download completes.
240 * <P>Type: TEXT</P>
241 * <P>Owner can Init/Read</P>
242 */
Mathew Inwood6750f2e2018-08-10 09:29:25 +0100243 @UnsupportedAppUsage
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800244 public static final String COLUMN_NOTIFICATION_PACKAGE = "notificationpackage";
245
246 /**
247 * The name of the column containing the component name of the class that
248 * will receive notifications associated with the download. The
249 * package/class combination is passed to
250 * Intent.setClassName(String,String).
251 * <P>Type: TEXT</P>
252 * <P>Owner can Init/Read</P>
253 */
Mathew Inwood6750f2e2018-08-10 09:29:25 +0100254 @UnsupportedAppUsage
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800255 public static final String COLUMN_NOTIFICATION_CLASS = "notificationclass";
256
257 /**
258 * If extras are specified when requesting a download they will be provided in the intent that
259 * is sent to the specified class and package when a download has finished.
260 * <P>Type: TEXT</P>
261 * <P>Owner can Init</P>
262 */
Mathew Inwood6750f2e2018-08-10 09:29:25 +0100263 @UnsupportedAppUsage
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800264 public static final String COLUMN_NOTIFICATION_EXTRAS = "notificationextras";
265
266 /**
267 * The name of the column contain the values of the cookie to be used for
268 * the download. This is used directly as the value for the Cookie: HTTP
269 * header that gets sent with the request.
270 * <P>Type: TEXT</P>
271 * <P>Owner can Init</P>
272 */
Mathew Inwood6750f2e2018-08-10 09:29:25 +0100273 @UnsupportedAppUsage
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800274 public static final String COLUMN_COOKIE_DATA = "cookiedata";
275
276 /**
277 * The name of the column containing the user agent that the initiating
278 * application wants the download manager to use for this download.
279 * <P>Type: TEXT</P>
280 * <P>Owner can Init</P>
281 */
282 public static final String COLUMN_USER_AGENT = "useragent";
283
284 /**
285 * The name of the column containing the referer (sic) that the initiating
286 * application wants the download manager to use for this download.
287 * <P>Type: TEXT</P>
288 * <P>Owner can Init</P>
289 */
Mathew Inwood6750f2e2018-08-10 09:29:25 +0100290 @UnsupportedAppUsage
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800291 public static final String COLUMN_REFERER = "referer";
292
293 /**
294 * The name of the column containing the total size of the file being
295 * downloaded.
296 * <P>Type: INTEGER</P>
297 * <P>Owner can Read</P>
298 */
299 public static final String COLUMN_TOTAL_BYTES = "total_bytes";
300
301 /**
302 * The name of the column containing the size of the part of the file that
303 * has been downloaded so far.
304 * <P>Type: INTEGER</P>
305 * <P>Owner can Read</P>
306 */
307 public static final String COLUMN_CURRENT_BYTES = "current_bytes";
308
309 /**
310 * The name of the column where the initiating application can provide the
311 * UID of another application that is allowed to access this download. If
312 * multiple applications share the same UID, all those applications will be
313 * allowed to access this download. This column can be updated after the
314 * download is initiated. This requires the permission
315 * android.permission.ACCESS_DOWNLOAD_MANAGER_ADVANCED.
316 * <P>Type: INTEGER</P>
317 * <P>Owner can Init</P>
318 */
319 public static final String COLUMN_OTHER_UID = "otheruid";
320
321 /**
322 * The name of the column where the initiating application can provided the
323 * title of this download. The title will be displayed ito the user in the
324 * list of downloads.
325 * <P>Type: TEXT</P>
326 * <P>Owner can Init/Read/Write</P>
327 */
Mathew Inwood6750f2e2018-08-10 09:29:25 +0100328 @UnsupportedAppUsage
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800329 public static final String COLUMN_TITLE = "title";
330
331 /**
332 * The name of the column where the initiating application can provide the
333 * description of this download. The description will be displayed to the
334 * user in the list of downloads.
335 * <P>Type: TEXT</P>
336 * <P>Owner can Init/Read/Write</P>
337 */
Mathew Inwood6750f2e2018-08-10 09:29:25 +0100338 @UnsupportedAppUsage
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800339 public static final String COLUMN_DESCRIPTION = "description";
340
Steve Howardb8e07a52010-07-21 14:53:21 -0700341 /**
342 * The name of the column indicating whether the download was requesting through the public
343 * API. This controls some differences in behavior.
344 * <P>Type: BOOLEAN</P>
345 * <P>Owner can Init/Read</P>
346 */
Mathew Inwood6750f2e2018-08-10 09:29:25 +0100347 @UnsupportedAppUsage
Steve Howardb8e07a52010-07-21 14:53:21 -0700348 public static final String COLUMN_IS_PUBLIC_API = "is_public_api";
349
350 /**
Jeff Sharkey15ec7d62012-04-17 12:23:40 -0700351 * The name of the column holding a bitmask of allowed network types. This is only used for
352 * public API downloads.
353 * <P>Type: INTEGER</P>
354 * <P>Owner can Init/Read</P>
355 */
Mathew Inwood6750f2e2018-08-10 09:29:25 +0100356 @UnsupportedAppUsage
Jeff Sharkey15ec7d62012-04-17 12:23:40 -0700357 public static final String COLUMN_ALLOWED_NETWORK_TYPES = "allowed_network_types";
358
359 /**
Steve Howardb8e07a52010-07-21 14:53:21 -0700360 * The name of the column indicating whether roaming connections can be used. This is only
361 * used for public API downloads.
362 * <P>Type: BOOLEAN</P>
363 * <P>Owner can Init/Read</P>
364 */
Mathew Inwood6750f2e2018-08-10 09:29:25 +0100365 @UnsupportedAppUsage
Steve Howardb8e07a52010-07-21 14:53:21 -0700366 public static final String COLUMN_ALLOW_ROAMING = "allow_roaming";
367
368 /**
Jeff Sharkey15ec7d62012-04-17 12:23:40 -0700369 * The name of the column indicating whether metered connections can be used. This is only
370 * used for public API downloads.
371 * <P>Type: BOOLEAN</P>
Steve Howardb8e07a52010-07-21 14:53:21 -0700372 * <P>Owner can Init/Read</P>
373 */
Jeff Sharkey15ec7d62012-04-17 12:23:40 -0700374 public static final String COLUMN_ALLOW_METERED = "allow_metered";
Steve Howardb8e07a52010-07-21 14:53:21 -0700375
Steve Howard90fb15a2010-09-09 16:13:41 -0700376 /**
377 * Whether or not this download should be displayed in the system's Downloads UI. Defaults
378 * to true.
379 * <P>Type: INTEGER</P>
380 * <P>Owner can Init/Read</P>
381 */
Mathew Inwood6750f2e2018-08-10 09:29:25 +0100382 @UnsupportedAppUsage
Steve Howard90fb15a2010-09-09 16:13:41 -0700383 public static final String COLUMN_IS_VISIBLE_IN_DOWNLOADS_UI = "is_visible_in_downloads_ui";
384
Steve Howardf1766812010-09-17 16:46:19 -0700385 /**
386 * If true, the user has confirmed that this download can proceed over the mobile network
387 * even though it exceeds the recommended maximum size.
388 * <P>Type: BOOLEAN</P>
389 */
390 public static final String COLUMN_BYPASS_RECOMMENDED_SIZE_LIMIT =
391 "bypass_recommended_size_limit";
392
Vasu Nori216fa222010-10-12 23:08:13 -0700393 /**
394 * Set to true if this download is deleted. It is completely removed from the database
395 * when MediaProvider database also deletes the metadata asociated with this downloaded file.
396 * <P>Type: BOOLEAN</P>
397 * <P>Owner can Read</P>
398 */
Mathew Inwood6750f2e2018-08-10 09:29:25 +0100399 @UnsupportedAppUsage
Vasu Nori216fa222010-10-12 23:08:13 -0700400 public static final String COLUMN_DELETED = "deleted";
401
402 /**
403 * The URI to the corresponding entry in MediaProvider for this downloaded entry. It is
404 * used to delete the entries from MediaProvider database when it is deleted from the
405 * downloaded list.
406 * <P>Type: TEXT</P>
407 * <P>Owner can Read</P>
408 */
409 public static final String COLUMN_MEDIAPROVIDER_URI = "mediaprovider_uri";
410
Vasu Nori5be894e2010-11-02 21:55:30 -0700411 /**
Sudheer Shankafe7668a2018-12-16 15:52:33 -0800412 * Similar to {@link #COLUMN_MEDIAPROVIDER_URI}, except this cannot be updated/queried
413 * by apps and will be the source of truth when updating/deleting download entries in
414 * MediaProvider database.
415 *
416 * <P>Type: TEXT</P>
417 */
418 public static final String COLUMN_MEDIASTORE_URI = "mediastore_uri";
419
420 /**
Vasu Nori5be894e2010-11-02 21:55:30 -0700421 * The column that is used to remember whether the media scanner was invoked.
Sudheer Shanka684c02a2019-01-29 17:41:15 -0800422 * It can take the values: {@link #MEDIA_NOT_SCANNED}, {@link #MEDIA_SCANNED} or
423 * {@link #MEDIA_NOT_SCANNABLE} or {@code null}. If it's value is {@code null}, it will be
424 * treated as {@link #MEDIA_NOT_SCANNED}.
425 *
Vasu Nori5be894e2010-11-02 21:55:30 -0700426 * <P>Type: TEXT</P>
427 */
Mathew Inwood6750f2e2018-08-10 09:29:25 +0100428 @UnsupportedAppUsage
Vasu Nori5be894e2010-11-02 21:55:30 -0700429 public static final String COLUMN_MEDIA_SCANNED = "scanned";
430
Sudheer Shanka684c02a2019-01-29 17:41:15 -0800431 /** Possible values for column {@link #COLUMN_MEDIA_SCANNED} */
432 public static final int MEDIA_NOT_SCANNED = 0;
433 public static final int MEDIA_SCANNED = 1;
434 public static final int MEDIA_NOT_SCANNABLE = 2;
435
Vasu Nori4015de22010-11-11 15:19:37 -0800436 /**
437 * The column with errorMsg for a failed downloaded.
438 * Used only for debugging purposes.
439 * <P>Type: TEXT</P>
440 */
441 public static final String COLUMN_ERROR_MSG = "errorMsg";
442
Vasu Nori8da7a4e2010-11-17 17:14:49 -0800443 /**
444 * This column stores the source of the last update to this row.
445 * This column is only for internal use.
446 * Valid values are indicated by LAST_UPDATESRC_* constants.
447 * <P>Type: INT</P>
448 */
449 public static final String COLUMN_LAST_UPDATESRC = "lastUpdateSrc";
450
Jeff Sharkey54781202013-01-17 17:27:33 -0800451 /** The column that is used to count retries */
452 public static final String COLUMN_FAILED_CONNECTIONS = "numfailed";
453
Jeff Sharkeyb180a652013-09-23 14:23:41 -0700454 public static final String COLUMN_ALLOW_WRITE = "allow_write";
455
Jeff Sharkeyf07c7b92016-04-22 09:50:16 -0600456 public static final int FLAG_REQUIRES_CHARGING = 1 << 0;
457 public static final int FLAG_REQUIRES_DEVICE_IDLE = 1 << 1;
458
459 public static final String COLUMN_FLAGS = "flags";
460
Vasu Nori8da7a4e2010-11-17 17:14:49 -0800461 /**
462 * default value for {@link #COLUMN_LAST_UPDATESRC}.
463 * This value is used when this column's value is not relevant.
464 */
465 public static final int LAST_UPDATESRC_NOT_RELEVANT = 0;
466
467 /**
468 * One of the values taken by {@link #COLUMN_LAST_UPDATESRC}.
469 * This value is used when the update is NOT to be relayed to the DownloadService
470 * (and thus spare DownloadService from scanning the database when this change occurs)
471 */
472 public static final int LAST_UPDATESRC_DONT_NOTIFY_DOWNLOADSVC = 1;
473
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800474 /*
475 * Lists the destinations that an application can specify for a download.
476 */
477
478 /**
479 * This download will be saved to the external storage. This is the
480 * default behavior, and should be used for any file that the user
481 * can freely access, copy, delete. Even with that destination,
482 * unencrypted DRM files are saved in secure internal storage.
483 * Downloads to the external destination only write files for which
484 * there is a registered handler. The resulting files are accessible
485 * by filename to all applications.
486 */
487 public static final int DESTINATION_EXTERNAL = 0;
488
489 /**
490 * This download will be saved to the download manager's private
491 * partition. This is the behavior used by applications that want to
492 * download private files that are used and deleted soon after they
493 * get downloaded. All file types are allowed, and only the initiating
494 * application can access the file (indirectly through a content
495 * provider). This requires the
496 * android.permission.ACCESS_DOWNLOAD_MANAGER_ADVANCED permission.
497 */
498 public static final int DESTINATION_CACHE_PARTITION = 1;
499
500 /**
501 * This download will be saved to the download manager's private
502 * partition and will be purged as necessary to make space. This is
503 * for private files (similar to CACHE_PARTITION) that aren't deleted
504 * immediately after they are used, and are kept around by the download
505 * manager as long as space is available.
506 */
Mathew Inwood6750f2e2018-08-10 09:29:25 +0100507 @UnsupportedAppUsage
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800508 public static final int DESTINATION_CACHE_PARTITION_PURGEABLE = 2;
509
510 /**
511 * This download will be saved to the download manager's private
512 * partition, as with DESTINATION_CACHE_PARTITION, but the download
513 * will not proceed if the user is on a roaming data connection.
514 */
515 public static final int DESTINATION_CACHE_PARTITION_NOROAMING = 3;
516
517 /**
Steve Howardadcb6972010-07-12 17:09:25 -0700518 * This download will be saved to the location given by the file URI in
519 * {@link #COLUMN_FILE_NAME_HINT}.
520 */
Mathew Inwood6750f2e2018-08-10 09:29:25 +0100521 @UnsupportedAppUsage
Steve Howardadcb6972010-07-12 17:09:25 -0700522 public static final int DESTINATION_FILE_URI = 4;
523
524 /**
Vasu Norif83e6e42010-12-13 16:28:31 -0800525 * This download will be saved to the system cache ("/cache")
526 * partition. This option is only used by system apps and so it requires
527 * android.permission.ACCESS_CACHE_FILESYSTEM permission.
528 */
Jeff Sharkey4233f032017-07-15 12:58:38 -0600529 @Deprecated
Vasu Norif83e6e42010-12-13 16:28:31 -0800530 public static final int DESTINATION_SYSTEMCACHE_PARTITION = 5;
531
532 /**
Vasu Noric0e50752011-01-20 17:57:54 -0800533 * This download was completed by the caller (i.e., NOT downloadmanager)
534 * and caller wants to have this download displayed in Downloads App.
535 */
536 public static final int DESTINATION_NON_DOWNLOADMANAGER_DOWNLOAD = 6;
537
538 /**
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800539 * This download is allowed to run.
540 */
541 public static final int CONTROL_RUN = 0;
542
543 /**
544 * This download must pause at the first opportunity.
545 */
546 public static final int CONTROL_PAUSED = 1;
547
548 /*
549 * Lists the states that the download manager can set on a download
550 * to notify applications of the download progress.
551 * The codes follow the HTTP families:<br>
552 * 1xx: informational<br>
553 * 2xx: success<br>
554 * 3xx: redirects (not used by the download manager)<br>
555 * 4xx: client errors<br>
556 * 5xx: server errors
557 */
558
559 /**
560 * Returns whether the status is informational (i.e. 1xx).
561 */
562 public static boolean isStatusInformational(int status) {
563 return (status >= 100 && status < 200);
564 }
565
566 /**
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800567 * Returns whether the status is a success (i.e. 2xx).
568 */
Mathew Inwood6750f2e2018-08-10 09:29:25 +0100569 @UnsupportedAppUsage
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800570 public static boolean isStatusSuccess(int status) {
571 return (status >= 200 && status < 300);
572 }
573
574 /**
575 * Returns whether the status is an error (i.e. 4xx or 5xx).
576 */
Mathew Inwood6750f2e2018-08-10 09:29:25 +0100577 @UnsupportedAppUsage
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800578 public static boolean isStatusError(int status) {
579 return (status >= 400 && status < 600);
580 }
581
582 /**
583 * Returns whether the status is a client error (i.e. 4xx).
584 */
585 public static boolean isStatusClientError(int status) {
586 return (status >= 400 && status < 500);
587 }
588
589 /**
590 * Returns whether the status is a server error (i.e. 5xx).
591 */
592 public static boolean isStatusServerError(int status) {
593 return (status >= 500 && status < 600);
594 }
595
596 /**
Vasu Norif9e85232011-02-10 14:59:54 -0800597 * this method determines if a notification should be displayed for a
598 * given {@link #COLUMN_VISIBILITY} value
599 * @param visibility the value of {@link #COLUMN_VISIBILITY}.
600 * @return true if the notification should be displayed. false otherwise.
601 */
Mathew Inwood6750f2e2018-08-10 09:29:25 +0100602 @UnsupportedAppUsage
Vasu Norif9e85232011-02-10 14:59:54 -0800603 public static boolean isNotificationToBeDisplayed(int visibility) {
604 return visibility == DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED ||
605 visibility == DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION;
606 }
607
608 /**
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800609 * Returns whether the download has completed (either with success or
610 * error).
611 */
Mathew Inwood6750f2e2018-08-10 09:29:25 +0100612 @UnsupportedAppUsage
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800613 public static boolean isStatusCompleted(int status) {
614 return (status >= 200 && status < 300) || (status >= 400 && status < 600);
615 }
616
617 /**
618 * This download hasn't stated yet
619 */
620 public static final int STATUS_PENDING = 190;
621
622 /**
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800623 * This download has started
624 */
625 public static final int STATUS_RUNNING = 192;
626
627 /**
Steve Howard3e8c1d32010-09-29 17:03:32 -0700628 * This download has been paused by the owning app.
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800629 */
Steve Howard3e8c1d32010-09-29 17:03:32 -0700630 public static final int STATUS_PAUSED_BY_APP = 193;
631
632 /**
633 * This download encountered some network error and is waiting before retrying the request.
634 */
635 public static final int STATUS_WAITING_TO_RETRY = 194;
636
637 /**
638 * This download is waiting for network connectivity to proceed.
639 */
640 public static final int STATUS_WAITING_FOR_NETWORK = 195;
641
642 /**
643 * This download exceeded a size limit for mobile networks and is waiting for a Wi-Fi
644 * connection to proceed.
645 */
646 public static final int STATUS_QUEUED_FOR_WIFI = 196;
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800647
648 /**
Vasu Nori0ba30552011-02-08 17:18:27 -0800649 * This download couldn't be completed due to insufficient storage
650 * space. Typically, this is because the SD card is full.
651 */
652 public static final int STATUS_INSUFFICIENT_SPACE_ERROR = 198;
653
654 /**
655 * This download couldn't be completed because no external storage
656 * device was found. Typically, this is because the SD card is not
657 * mounted.
658 */
659 public static final int STATUS_DEVICE_NOT_FOUND_ERROR = 199;
660
661 /**
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800662 * This download has successfully completed.
663 * Warning: there might be other status values that indicate success
664 * in the future.
Steve McKay996dab22016-01-17 08:32:20 -0800665 * Use isStatusSuccess() to capture the entire category.
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800666 */
667 public static final int STATUS_SUCCESS = 200;
668
669 /**
670 * This request couldn't be parsed. This is also used when processing
671 * requests with unknown/unsupported URI schemes.
672 */
673 public static final int STATUS_BAD_REQUEST = 400;
674
675 /**
676 * This download can't be performed because the content type cannot be
677 * handled.
678 */
679 public static final int STATUS_NOT_ACCEPTABLE = 406;
680
681 /**
682 * This download cannot be performed because the length cannot be
683 * determined accurately. This is the code for the HTTP error "Length
684 * Required", which is typically used when making requests that require
685 * a content length but don't have one, and it is also used in the
686 * client when a response is received whose length cannot be determined
687 * accurately (therefore making it impossible to know when a download
688 * completes).
689 */
690 public static final int STATUS_LENGTH_REQUIRED = 411;
691
692 /**
693 * This download was interrupted and cannot be resumed.
694 * This is the code for the HTTP error "Precondition Failed", and it is
695 * also used in situations where the client doesn't have an ETag at all.
696 */
697 public static final int STATUS_PRECONDITION_FAILED = 412;
698
699 /**
Steve Howard33bbd122010-08-02 17:51:29 -0700700 * The lowest-valued error status that is not an actual HTTP status code.
701 */
Steve Howarda9e87c92010-09-16 12:02:03 -0700702 public static final int MIN_ARTIFICIAL_ERROR_STATUS = 488;
703
704 /**
705 * The requested destination file already exists.
706 */
707 public static final int STATUS_FILE_ALREADY_EXISTS_ERROR = 488;
Steve Howard33bbd122010-08-02 17:51:29 -0700708
709 /**
710 * Some possibly transient error occurred, but we can't resume the download.
711 */
712 public static final int STATUS_CANNOT_RESUME = 489;
713
714 /**
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800715 * This download was canceled
716 */
717 public static final int STATUS_CANCELED = 490;
718
719 /**
720 * This download has completed with an error.
721 * Warning: there will be other status values that indicate errors in
722 * the future. Use isStatusError() to capture the entire category.
723 */
724 public static final int STATUS_UNKNOWN_ERROR = 491;
725
726 /**
727 * This download couldn't be completed because of a storage issue.
728 * Typically, that's because the filesystem is missing or full.
Attila Bodisf238ad72010-01-26 14:52:32 -0800729 * Use the more specific {@link #STATUS_INSUFFICIENT_SPACE_ERROR}
730 * and {@link #STATUS_DEVICE_NOT_FOUND_ERROR} when appropriate.
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800731 */
732 public static final int STATUS_FILE_ERROR = 492;
733
734 /**
735 * This download couldn't be completed because of an HTTP
736 * redirect response that the download manager couldn't
737 * handle.
738 */
739 public static final int STATUS_UNHANDLED_REDIRECT = 493;
740
741 /**
742 * This download couldn't be completed because of an
743 * unspecified unhandled HTTP code.
744 */
745 public static final int STATUS_UNHANDLED_HTTP_CODE = 494;
746
747 /**
748 * This download couldn't be completed because of an
749 * error receiving or processing data at the HTTP level.
750 */
751 public static final int STATUS_HTTP_DATA_ERROR = 495;
752
753 /**
754 * This download couldn't be completed because of an
755 * HttpException while setting up the request.
756 */
757 public static final int STATUS_HTTP_EXCEPTION = 496;
758
759 /**
760 * This download couldn't be completed because there were
761 * too many redirects.
762 */
763 public static final int STATUS_TOO_MANY_REDIRECTS = 497;
764
765 /**
Jeff Sharkeyfdfef572011-06-16 15:07:48 -0700766 * This download has failed because requesting application has been
767 * blocked by {@link NetworkPolicyManager}.
768 *
769 * @hide
Jeff Sharkey15ec7d62012-04-17 12:23:40 -0700770 * @deprecated since behavior now uses
771 * {@link #STATUS_WAITING_FOR_NETWORK}
Jeff Sharkeyfdfef572011-06-16 15:07:48 -0700772 */
Jeff Sharkey15ec7d62012-04-17 12:23:40 -0700773 @Deprecated
Jeff Sharkeyfdfef572011-06-16 15:07:48 -0700774 public static final int STATUS_BLOCKED = 498;
775
Jeff Sharkey58d9fb62012-04-13 14:42:50 -0700776 /** {@hide} */
777 public static String statusToString(int status) {
778 switch (status) {
779 case STATUS_PENDING: return "PENDING";
780 case STATUS_RUNNING: return "RUNNING";
781 case STATUS_PAUSED_BY_APP: return "PAUSED_BY_APP";
782 case STATUS_WAITING_TO_RETRY: return "WAITING_TO_RETRY";
783 case STATUS_WAITING_FOR_NETWORK: return "WAITING_FOR_NETWORK";
784 case STATUS_QUEUED_FOR_WIFI: return "QUEUED_FOR_WIFI";
785 case STATUS_INSUFFICIENT_SPACE_ERROR: return "INSUFFICIENT_SPACE_ERROR";
786 case STATUS_DEVICE_NOT_FOUND_ERROR: return "DEVICE_NOT_FOUND_ERROR";
787 case STATUS_SUCCESS: return "SUCCESS";
788 case STATUS_BAD_REQUEST: return "BAD_REQUEST";
789 case STATUS_NOT_ACCEPTABLE: return "NOT_ACCEPTABLE";
790 case STATUS_LENGTH_REQUIRED: return "LENGTH_REQUIRED";
791 case STATUS_PRECONDITION_FAILED: return "PRECONDITION_FAILED";
792 case STATUS_FILE_ALREADY_EXISTS_ERROR: return "FILE_ALREADY_EXISTS_ERROR";
793 case STATUS_CANNOT_RESUME: return "CANNOT_RESUME";
794 case STATUS_CANCELED: return "CANCELED";
795 case STATUS_UNKNOWN_ERROR: return "UNKNOWN_ERROR";
796 case STATUS_FILE_ERROR: return "FILE_ERROR";
797 case STATUS_UNHANDLED_REDIRECT: return "UNHANDLED_REDIRECT";
798 case STATUS_UNHANDLED_HTTP_CODE: return "UNHANDLED_HTTP_CODE";
799 case STATUS_HTTP_DATA_ERROR: return "HTTP_DATA_ERROR";
800 case STATUS_HTTP_EXCEPTION: return "HTTP_EXCEPTION";
801 case STATUS_TOO_MANY_REDIRECTS: return "TOO_MANY_REDIRECTS";
802 case STATUS_BLOCKED: return "BLOCKED";
803 default: return Integer.toString(status);
804 }
805 }
806
Jeff Sharkeyfdfef572011-06-16 15:07:48 -0700807 /**
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800808 * This download is visible but only shows in the notifications
809 * while it's in progress.
810 */
Vasu Nori4c6e5df2010-10-26 17:00:16 -0700811 public static final int VISIBILITY_VISIBLE = DownloadManager.Request.VISIBILITY_VISIBLE;
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800812
813 /**
814 * This download is visible and shows in the notifications while
815 * in progress and after completion.
816 */
Vasu Nori4c6e5df2010-10-26 17:00:16 -0700817 public static final int VISIBILITY_VISIBLE_NOTIFY_COMPLETED =
818 DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED;
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800819
820 /**
821 * This download doesn't show in the UI or in the notifications.
822 */
Vasu Nori4c6e5df2010-10-26 17:00:16 -0700823 public static final int VISIBILITY_HIDDEN = DownloadManager.Request.VISIBILITY_HIDDEN;
Steve Howardea9147d2010-07-13 19:02:45 -0700824
825 /**
826 * Constants related to HTTP request headers associated with each download.
827 */
828 public static class RequestHeaders {
829 public static final String HEADERS_DB_TABLE = "request_headers";
830 public static final String COLUMN_DOWNLOAD_ID = "download_id";
831 public static final String COLUMN_HEADER = "header";
832 public static final String COLUMN_VALUE = "value";
833
834 /**
835 * Path segment to add to a download URI to retrieve request headers
836 */
837 public static final String URI_SEGMENT = "headers";
838
839 /**
840 * Prefix for ContentValues keys that contain HTTP header lines, to be passed to
841 * DownloadProvider.insert().
842 */
Mathew Inwood6750f2e2018-08-10 09:29:25 +0100843 @UnsupportedAppUsage
Steve Howardea9147d2010-07-13 19:02:45 -0700844 public static final String INSERT_KEY_PREFIX = "http_header_";
845 }
Jean-Baptiste Queru32d80bf2010-01-13 15:49:16 -0800846 }
Jeff Sharkey948eef82012-03-20 17:44:42 -0700847
Sudheer Shankae93db512019-01-11 16:05:28 -0800848 /** @hide */
849 public static final String MEDIASTORE_DOWNLOADS_DELETED_CALL = "mediastore_downloads_deleted";
850
851 /** @hide */
852 public static final String EXTRA_IDS = "ids";
853 /** @hide */
854 public static final String EXTRA_MIME_TYPES = "mime_types";
855
Jeff Sharkey948eef82012-03-20 17:44:42 -0700856 /**
857 * Query where clause for general querying.
858 */
859 private static final String QUERY_WHERE_CLAUSE = Impl.COLUMN_NOTIFICATION_PACKAGE + "=? AND "
860 + Impl.COLUMN_NOTIFICATION_CLASS + "=?";
861
862 /**
863 * Delete all the downloads for a package/class pair.
864 */
865 public static final void removeAllDownloadsByPackage(
866 Context context, String notification_package, String notification_class) {
867 context.getContentResolver().delete(Impl.CONTENT_URI, QUERY_WHERE_CLAUSE,
868 new String[] { notification_package, notification_class });
869 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700870}