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 column that is used to remember whether the media scanner was invoked */ 49 public static final String MEDIA_SCANNED = "scanned"; 50 51 /** The column that is used to count retries */ 52 public static final String FAILED_CONNECTIONS = "numfailed"; 53 54 /** The intent that gets sent when the service must wake up for a retry */ 55 public static final String ACTION_RETRY = "android.intent.action.DOWNLOAD_WAKEUP"; 56 57 /** the intent that gets sent when clicking a successful download */ 58 public static final String ACTION_OPEN = "android.intent.action.DOWNLOAD_OPEN"; 59 60 /** the intent that gets sent when clicking an incomplete/failed download */ 61 public static final String ACTION_LIST = "android.intent.action.DOWNLOAD_LIST"; 62 63 /** the intent that gets sent when deleting the notification of a completed download */ 64 public static final String ACTION_HIDE = "android.intent.action.DOWNLOAD_HIDE"; 65 66 /** The default base name for downloaded files if we can't get one at the HTTP level */ 67 public static final String DEFAULT_DL_FILENAME = "downloadfile"; 68 69 /** The default extension for html files if we can't get one at the HTTP level */ 70 public static final String DEFAULT_DL_HTML_EXTENSION = ".html"; 71 72 /** The default extension for text files if we can't get one at the HTTP level */ 73 public static final String DEFAULT_DL_TEXT_EXTENSION = ".txt"; 74 75 /** The default extension for binary files if we can't get one at the HTTP level */ 76 public static final String DEFAULT_DL_BINARY_EXTENSION = ".bin"; 77 78 /** 79 * When a number has to be appended to the filename, this string is used to separate the 80 * base filename from the sequence number 81 */ 82 public static final String FILENAME_SEQUENCE_SEPARATOR = "-"; 83 84 /** Where we store downloaded files on the external storage */ 85 public static final String DEFAULT_DL_SUBDIR = "/" + Environment.DIRECTORY_DOWNLOADS; 86 87 /** A magic filename that is allowed to exist within the system cache */ 88 public static final String RECOVERY_DIRECTORY = "recovery"; 89 90 /** The default user agent used for downloads */ 91 public static final String DEFAULT_USER_AGENT; 92 93 static { 94 final StringBuilder builder = new StringBuilder(); 95 96 final boolean validRelease = !TextUtils.isEmpty(Build.VERSION.RELEASE); 97 final boolean validId = !TextUtils.isEmpty(Build.ID); 98 final boolean includeModel = "REL".equals(Build.VERSION.CODENAME) 99 && !TextUtils.isEmpty(Build.MODEL); 100 101 builder.append("AndroidDownloadManager"); 102 if (validRelease) { 103 builder.append("/").append(Build.VERSION.RELEASE); 104 } 105 builder.append(" (Linux; U; Android"); 106 if (validRelease) { 107 builder.append(" ").append(Build.VERSION.RELEASE); 108 } 109 if (includeModel || validId) { 110 builder.append(";"); 111 if (includeModel) { 112 builder.append(" ").append(Build.MODEL); 113 } 114 if (validId) { 115 builder.append(" Build/").append(Build.ID); 116 } 117 } 118 builder.append(")"); 119 120 DEFAULT_USER_AGENT = builder.toString(); 121 } 122 123 /** The MIME type of APKs */ 124 public static final String MIMETYPE_APK = "application/vnd.android.package"; 125 126 /** The buffer size used to stream the data */ 127 public static final int BUFFER_SIZE = 4096; 128 129 /** The minimum amount of progress that has to be done before the progress bar gets updated */ 130 public static final int MIN_PROGRESS_STEP = 4096; 131 132 /** The minimum amount of time that has to elapse before the progress bar gets updated, in ms */ 133 public static final long MIN_PROGRESS_TIME = 1500; 134 135 /** The maximum number of rows in the database (FIFO) */ 136 public static final int MAX_DOWNLOADS = 1000; 137 138 /** 139 * The number of times that the download manager will retry its network 140 * operations when no progress is happening before it gives up. 141 */ 142 public static final int MAX_RETRIES = 5; 143 144 /** 145 * The minimum amount of time that the download manager accepts for 146 * a Retry-After response header with a parameter in delta-seconds. 147 */ 148 public static final int MIN_RETRY_AFTER = 30; // 30s 149 150 /** 151 * The maximum amount of time that the download manager accepts for 152 * a Retry-After response header with a parameter in delta-seconds. 153 */ 154 public static final int MAX_RETRY_AFTER = 24 * 60 * 60; // 24h 155 156 /** 157 * The maximum number of redirects. 158 */ 159 public static final int MAX_REDIRECTS = 5; // can't be more than 7. 160 161 /** 162 * The time between a failure and the first retry after an IOException. 163 * Each subsequent retry grows exponentially, doubling each time. 164 * The time is in seconds. 165 */ 166 public static final int RETRY_FIRST_DELAY = 30; 167 168 /** Enable separate connectivity logging */ 169 static final boolean LOGX = false; 170 171 /** Enable verbose logging - use with "setprop log.tag.DownloadManager VERBOSE" */ 172 private static final boolean LOCAL_LOGV = false; 173 public static final boolean LOGV = LOCAL_LOGV && Log.isLoggable(TAG, Log.VERBOSE); 174 175 /** Enable super-verbose logging */ 176 private static final boolean LOCAL_LOGVV = false; 177 public static final boolean LOGVV = LOCAL_LOGVV && LOGV; 178 } 179