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 /** 87 * Job id for the periodic service to clean-up stale and orphan downloads. 88 */ 89 public static final int IDLE_JOB_ID = -100; 90 91 /** 92 * Job id for a one-time clean-up job to trigger mediascan on files which should have been 93 * mediascanned earlier when they were downloaded but didn't get scanned. 94 */ 95 public static final int MEDIA_SCAN_TRIGGER_JOB_ID = -101; 96 97 static { 98 final StringBuilder builder = new StringBuilder(); 99 100 final boolean validRelease = !TextUtils.isEmpty(Build.VERSION.RELEASE_OR_CODENAME); 101 final boolean validId = !TextUtils.isEmpty(Build.ID); 102 final boolean includeModel = "REL".equals(Build.VERSION.CODENAME) 103 && !TextUtils.isEmpty(Build.MODEL); 104 105 builder.append("AndroidDownloadManager"); 106 if (validRelease) { 107 builder.append("/").append(Build.VERSION.RELEASE_OR_CODENAME); 108 } 109 builder.append(" (Linux; U; Android"); 110 if (validRelease) { 111 builder.append(" ").append(Build.VERSION.RELEASE_OR_CODENAME); 112 } 113 if (includeModel || validId) { 114 builder.append(";"); 115 if (includeModel) { 116 builder.append(" ").append(Build.MODEL); 117 } 118 if (validId) { 119 builder.append(" Build/").append(Build.ID); 120 } 121 } 122 builder.append(")"); 123 124 DEFAULT_USER_AGENT = builder.toString(); 125 } 126 127 /** The MIME type of APKs */ 128 public static final String MIMETYPE_APK = "application/vnd.android.package"; 129 130 /** The buffer size used to stream the data */ 131 public static final int BUFFER_SIZE = 8192; 132 133 /** The minimum amount of progress that has to be done before the progress bar gets updated */ 134 public static final int MIN_PROGRESS_STEP = 65536; 135 136 /** The minimum amount of time that has to elapse before the progress bar gets updated, in ms */ 137 public static final long MIN_PROGRESS_TIME = 2000; 138 139 /** 140 * The number of times that the download manager will retry its network 141 * operations when no progress is happening before it gives up. 142 */ 143 public static final int MAX_RETRIES = 5; 144 145 /** 146 * The minimum amount of time that the download manager accepts for 147 * a Retry-After response header with a parameter in delta-seconds. 148 */ 149 public static final int MIN_RETRY_AFTER = 30; // 30s 150 151 /** 152 * The maximum amount of time that the download manager accepts for 153 * a Retry-After response header with a parameter in delta-seconds. 154 */ 155 public static final int MAX_RETRY_AFTER = 24 * 60 * 60; // 24h 156 157 /** 158 * The maximum number of redirects. 159 */ 160 public static final int MAX_REDIRECTS = 5; // can't be more than 7. 161 162 /** 163 * The time between a failure and the first retry after an IOException. 164 * Each subsequent retry grows exponentially, doubling each time. 165 * The time is in seconds. 166 */ 167 public static final int RETRY_FIRST_DELAY = 30; 168 169 /** Enable separate connectivity logging */ 170 static final boolean LOGX = false; 171 172 /** Enable verbose logging - use with "setprop log.tag.DownloadManager VERBOSE" */ 173 private static final boolean LOCAL_LOGV = false; 174 public static final boolean LOGV = LOCAL_LOGV && Log.isLoggable(TAG, Log.VERBOSE); 175 176 /** Enable super-verbose logging */ 177 private static final boolean LOCAL_LOGVV = false; 178 public static final boolean LOGVV = LOCAL_LOGVV && LOGV; 179 180 public static final String STORAGE_AUTHORITY = "com.android.providers.downloads.documents"; 181 public static final String STORAGE_ROOT_ID = "downloads"; 182 183 /** 184 * Name of directory on cache partition containing in-progress downloads. 185 */ 186 public static final String DIRECTORY_CACHE_RUNNING = "partial_downloads"; 187 } 188