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 com.android.providers.downloads;
18 
19 import android.os.Build;
20 import android.os.Environment;
21 import android.text.TextUtils;
22 import android.util.Log;
23 
24 /**
25  * Contains the internal constants that are used in the download manager.
26  * As a general rule, modifying these constants should be done with care.
27  */
28 public class Constants {
29 
30     /** Tag used for debugging/logging */
31     public static final String TAG = "DownloadManager";
32 
33     /** The column that used to be used for the HTTP method of the request */
34     public static final String RETRY_AFTER_X_REDIRECT_COUNT = "method";
35 
36     /** The column that used to be used for the magic OTA update filename */
37     public static final String OTA_UPDATE = "otaupdate";
38 
39     /** The column that used to be used to reject system filetypes */
40     public static final String NO_SYSTEM_FILES = "no_system";
41 
42     /** The column that is used for the downloads's ETag */
43     public static final String ETAG = "etag";
44 
45     /** The column that is used for the initiating app's UID */
46     public static final String UID = "uid";
47 
48     /** the intent that gets sent when clicking a successful download */
49     public static final String ACTION_OPEN = "android.intent.action.DOWNLOAD_OPEN";
50 
51     /** the intent that gets sent when clicking an incomplete/failed download  */
52     public static final String ACTION_LIST = "android.intent.action.DOWNLOAD_LIST";
53 
54     /** the intent that gets sent when canceling a download  */
55     public static final String ACTION_CANCEL = "android.intent.action.DOWNLOAD_CANCEL";
56 
57     /** the intent that gets sent when deleting the notification of a completed download */
58     public static final String ACTION_HIDE = "android.intent.action.DOWNLOAD_HIDE";
59 
60     /** The default base name for downloaded files if we can't get one at the HTTP level */
61     public static final String DEFAULT_DL_FILENAME = "downloadfile";
62 
63     /** The default extension for html files if we can't get one at the HTTP level */
64     public static final String DEFAULT_DL_HTML_EXTENSION = ".html";
65 
66     /** The default extension for text files if we can't get one at the HTTP level */
67     public static final String DEFAULT_DL_TEXT_EXTENSION = ".txt";
68 
69     /** The default extension for binary files if we can't get one at the HTTP level */
70     public static final String DEFAULT_DL_BINARY_EXTENSION = ".bin";
71 
72     public static final String PROVIDER_PACKAGE_NAME = "com.android.providers.downloads";
73 
74     /**
75      * When a number has to be appended to the filename, this string is used to separate the
76      * base filename from the sequence number
77      */
78     public static final String FILENAME_SEQUENCE_SEPARATOR = "-";
79 
80     /** A magic filename that is allowed to exist within the system cache */
81     public static final String RECOVERY_DIRECTORY = "recovery";
82 
83     /** The default user agent used for downloads */
84     public static final String DEFAULT_USER_AGENT;
85 
86     static {
87         final StringBuilder builder = new StringBuilder();
88 
89         final boolean validRelease = !TextUtils.isEmpty(Build.VERSION.RELEASE);
90         final boolean validId = !TextUtils.isEmpty(Build.ID);
91         final boolean includeModel = "REL".equals(Build.VERSION.CODENAME)
92                 && !TextUtils.isEmpty(Build.MODEL);
93 
94         builder.append("AndroidDownloadManager");
95         if (validRelease) {
96             builder.append("/").append(Build.VERSION.RELEASE);
97         }
98         builder.append(" (Linux; U; Android");
99         if (validRelease) {
100             builder.append(" ").append(Build.VERSION.RELEASE);
101         }
102         if (includeModel || validId) {
103             builder.append(";");
104             if (includeModel) {
105                 builder.append(" ").append(Build.MODEL);
106             }
107             if (validId) {
108                 builder.append(" Build/").append(Build.ID);
109             }
110         }
111         builder.append(")");
112 
113         DEFAULT_USER_AGENT = builder.toString();
114     }
115 
116     /** The MIME type of APKs */
117     public static final String MIMETYPE_APK = "application/vnd.android.package";
118 
119     /** The buffer size used to stream the data */
120     public static final int BUFFER_SIZE = 8192;
121 
122     /** The minimum amount of progress that has to be done before the progress bar gets updated */
123     public static final int MIN_PROGRESS_STEP = 65536;
124 
125     /** The minimum amount of time that has to elapse before the progress bar gets updated, in ms */
126     public static final long MIN_PROGRESS_TIME = 2000;
127 
128     /**
129      * The number of times that the download manager will retry its network
130      * operations when no progress is happening before it gives up.
131      */
132     public static final int MAX_RETRIES = 5;
133 
134     /**
135      * The minimum amount of time that the download manager accepts for
136      * a Retry-After response header with a parameter in delta-seconds.
137      */
138     public static final int MIN_RETRY_AFTER = 30; // 30s
139 
140     /**
141      * The maximum amount of time that the download manager accepts for
142      * a Retry-After response header with a parameter in delta-seconds.
143      */
144     public static final int MAX_RETRY_AFTER = 24 * 60 * 60; // 24h
145 
146     /**
147      * The maximum number of redirects.
148      */
149     public static final int MAX_REDIRECTS = 5; // can't be more than 7.
150 
151     /**
152      * The time between a failure and the first retry after an IOException.
153      * Each subsequent retry grows exponentially, doubling each time.
154      * The time is in seconds.
155      */
156     public static final int RETRY_FIRST_DELAY = 30;
157 
158     /** Enable separate connectivity logging */
159     static final boolean LOGX = false;
160 
161     /** Enable verbose logging - use with "setprop log.tag.DownloadManager VERBOSE" */
162     private static final boolean LOCAL_LOGV = false;
163     public static final boolean LOGV = LOCAL_LOGV && Log.isLoggable(TAG, Log.VERBOSE);
164 
165     /** Enable super-verbose logging */
166     private static final boolean LOCAL_LOGVV = false;
167     public static final boolean LOGVV = LOCAL_LOGVV && LOGV;
168 
169     public static final String STORAGE_AUTHORITY = "com.android.providers.downloads.documents";
170     public static final String STORAGE_ROOT_ID = "downloads";
171 
172     /**
173      * Name of directory on cache partition containing in-progress downloads.
174      */
175     public static final String DIRECTORY_CACHE_RUNNING = "partial_downloads";
176 }
177